dci_tools.c 193 KB
Newer Older
1
/*******************************************************************************
ghaddab's avatar
ghaddab committed
2 3
    OpenAirInterface 
    Copyright(c) 1999 - 2014 Eurecom
4

ghaddab's avatar
ghaddab committed
5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


ghaddab's avatar
ghaddab committed
11 12 13 14
    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
15

ghaddab's avatar
ghaddab committed
16 17 18 19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is 
   included in this distribution in the file called "COPYING". If not, 
   see <http://www.gnu.org/licenses/>.
20 21

  Contact Information
ghaddab's avatar
ghaddab committed
22 23 24 25
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr
  
ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

ghaddab's avatar
ghaddab committed
28
 *******************************************************************************/
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

/*! \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
 */
#include "PHY/defs.h"
#include "PHY/extern.h"
#include "SCHED/defs.h"
#include "MAC_INTERFACE/defs.h"
#include "MAC_INTERFACE/extern.h"
#ifdef DEBUG_DCI_TOOLS
#include "PHY/vars.h"
#endif
winckel's avatar
winckel committed
48
#include "assertions.h"
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 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 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

//#define DEBUG_DCI

uint32_t  localRIV2alloc_LUT6[32];
uint32_t  distRIV2alloc_LUT6[32];
uint16_t RIV2nb_rb_LUT6[32];
uint16_t RIV2first_rb_LUT6[32];
uint16_t RIV_max6=0;

uint32_t  localRIV2alloc_LUT25[512];
uint32_t  distRIV2alloc_LUT25[512];
uint16_t RIV2nb_rb_LUT25[512];
uint16_t RIV2first_rb_LUT25[512];
uint16_t RIV_max25=0;


uint32_t  localRIV2alloc_LUT50_0[1600];
uint32_t  distRIV2alloc_LUT50_0[1600];
uint32_t  localRIV2alloc_LUT50_1[1600];
uint32_t  distRIV2alloc_LUT50_1[1600];
uint16_t RIV2nb_rb_LUT50[1600];
uint16_t RIV2first_rb_LUT50[1600];
uint16_t RIV_max50=0;

uint32_t  localRIV2alloc_LUT100_0[6000];
uint32_t  distRIV2alloc_LUT100_0[6000];
uint32_t  localRIV2alloc_LUT100_1[6000];
uint32_t  distRIV2alloc_LUT100_1[6000];
uint32_t  localRIV2alloc_LUT100_2[6000];
uint32_t  distRIV2alloc_LUT100_2[6000];
uint32_t  localRIV2alloc_LUT100_3[6000];
uint32_t  distRIV2alloc_LUT100_3[6000];
uint16_t RIV2nb_rb_LUT100[6000];
uint16_t RIV2first_rb_LUT100[6000];
uint16_t RIV_max100=0;


extern uint32_t current_dlsch_cqi;

// Table 8.6.3-3 36.213
uint16_t beta_cqi[16] = {0,   //reserved
			 0,   //reserved
			 9,   //1.125
			 10,  //1.250
			 11,  //1.375
			 13,  //1.625
			 14,  //1.750
			 16,  //2.000
			 18,  //2.250
			 20,  //2.500
			 23,  //2.875
			 25,  //3.125
			 28,  //3.500
			 32,  //4.000
			 40,  //5.000
			 50}; //6.250

// Table 8.6.3-2 36.213
uint16_t beta_ri[16] = {10,   //1.250
			13,   //1.625
			16,   //2.000
			20,   //2.500
			25,   //3.125
			32,   //4.000
			40,   //5.000
			50,   //6.250
			64,   //8.000
			80,   //10.000
			101,  //12.625
			127,  //15.875
			160,  //20.000
			0,    //reserved 
			0,    //reserved
			0};   //reserved

// Table 8.6.3-2 36.213
uint16_t beta_ack[16] = {16,  //2.000
			 20,  //2.500
			 25,  //3.125
			 32,  //4.000
			 40,  //5.000
			 50,  //6.250
			 64,  //8.000
			 80,  //10.000
			 101, //12.625
			 127, //15.875
			 160, //20.000
			 248, //31.000
			 400, //50.000
			 640, //80.000
			 808};//126.00

int8_t delta_PUSCH_abs[4] = {-4,-1,1,4};
int8_t delta_PUSCH_acc[4] = {-1,0,1,3};

int8_t *delta_PUCCH_lut = delta_PUSCH_acc;
		    
void conv_rballoc(uint8_t ra_header,uint32_t rb_alloc,uint32_t N_RB_DL,uint32_t *rb_alloc2) {

  uint32_t i,shift,subset;
  rb_alloc2[0] = 0; rb_alloc2[1] = 0; rb_alloc2[2] = 0; rb_alloc2[3] = 0;

  //  printf("N_RB_DL %d, ra_header %d, rb_alloc %x\n",N_RB_DL,ra_header,rb_alloc);

  switch (N_RB_DL) {

  case 6:
    rb_alloc2[0] = rb_alloc&0x3f;
    break;

  case 25:
    if (ra_header == 0) {// Type 0 Allocation
      
      for (i=12;i>0;i--) {
163 164 165
	if ((rb_alloc&(1<<i)) != 0)
	  rb_alloc2[0] |= (3<<((2*(12-i))));
	//      printf("rb_alloc2 (type 0) %x\n",rb_alloc2);
166 167
      }
      if ((rb_alloc&1) != 0)
168
	rb_alloc2[0] |= (1<<24);
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    }
    else {
      subset = rb_alloc&1;
      shift  = (rb_alloc>>1)&1;
      for (i=0;i<11;i++) {
	if ((rb_alloc&(1<<(i+2))) != 0)
	  rb_alloc2[0] |= (1<<(2*i));
	//printf("rb_alloc2 (type 1) %x\n",rb_alloc2);
      }
      if ((shift == 0) && (subset == 1))
	rb_alloc2[0]<<=1;
      else if ((shift == 1) && (subset == 0))
	rb_alloc2[0]<<=4;
      else if ((shift == 1) && (subset == 1))
	rb_alloc2[0]<<=3;
    }
    break;
  case 50:
    if (ra_header == 0) {// Type 0 Allocation

      for (i=16; i>0; i--) {
        if ((rb_alloc&(1<<i)) != 0)
          rb_alloc2[(3*(16-i))>>5] |= (7<<((3*(16-i))%32));
      }
      /*
194
	for (i=1;i<=16;i++) {
195
        if ((rb_alloc&(1<<(16-i))) != 0) 
196 197
	rb_alloc2[(3*i)>>5] |= (7<<((3*i)%32));
	}
198 199 200 201 202
      */
      // bit mask across 
      if ((rb_alloc2[0]>>31)==1)
        rb_alloc2[1] |= 1;
      if ((rb_alloc&1) != 0)
203
	rb_alloc2[1] |= (3<<16);
204
      /*      
205 206 207 208 209 210
	      for (i=0;i<16;i++) {
	      if (((rb_alloc>>(16-i))&1) != 0)
	      rb_alloc2[(3*i)>>5] |= (7<<((3*i)%32));
	      if ((i==10)&&((rb_alloc&(1<<6))!=0))
	      rb_alloc2[1] = 1;
	      //	printf("rb_alloc2[%d] (type 0) %x ((%x>>%d)&1=%d)\n",(3*i)>>5,rb_alloc2[(3*i)>>5],rb_alloc,i,(rb_alloc>>i)&1);
211

212 213 214 215 216 217
	      }
	      // fill in 2 from last bit instead of 3
	      if ((rb_alloc&1) != 0)
	      rb_alloc2[1] |= (3<<i);
	      //    printf("rb_alloc2[%d] (type 0) %x ((%x>>%d)&1=%d)\n",(3*i)>>5,rb_alloc2[(3*i)>>5],rb_alloc,i,(rb_alloc>>i)&1);
	      */
218
      //      printf("rb_alloc[1]=%x,rb_alloc[0]=%x\n",rb_alloc2[1],rb_alloc2[0]);
219 220 221
    }
    else {
      LOG_E(PHY,"resource type 1 not supported for  N_RB_DL=100\n");
Florian Kaltenberger's avatar
Florian Kaltenberger committed
222
      mac_xface->macphy_exit("resource type 1 not supported for  N_RB_DL=100\n");
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
      /*
	subset = rb_alloc&1;
	shift  = (rb_alloc>>1)&1;
	for (i=0;i<11;i++) {
	if ((rb_alloc&(1<<(i+2))) != 0)
	rb_alloc2 |= (1<<(2*i));
	//      printf("rb_alloc2 (type 1) %x\n",rb_alloc2);
	}
	if ((shift == 0) && (subset == 1))
	rb_alloc2<<=1;
	else if ((shift == 1) && (subset == 0))
	rb_alloc2<<=4;
	else if ((shift == 1) && (subset == 1))
	rb_alloc2<<=3;
      */
    }
    break;

  case 100:
    if (ra_header == 0) {// Type 0 Allocation
      for (i=0;i<25;i++) {
	if ((rb_alloc&(1<<(24-i))) != 0)
	  rb_alloc2[(4*i)>>5] |= (0xf<<((4*i)%32));
	//	printf("rb_alloc2[%d] (type 0) %x (%d)\n",(4*i)>>5,rb_alloc2[(4*i)>>5],rb_alloc&(1<<i));
      }
    }
    else {
      LOG_E(PHY,"resource type 1 not supported for  N_RB_DL=100\n");
Florian Kaltenberger's avatar
Florian Kaltenberger committed
251
      mac_xface->macphy_exit("resource type 1 not supported for  N_RB_DL=100\n");
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
      /*
	subset = rb_alloc&1;
	shift  = (rb_alloc>>1)&1;
	for (i=0;i<11;i++) {
	if ((rb_alloc&(1<<(i+2))) != 0)
	rb_alloc2 |= (1<<(2*i));
	//      printf("rb_alloc2 (type 1) %x\n",rb_alloc2);
	}
	if ((shift == 0) && (subset == 1))
	rb_alloc2<<=1;
	else if ((shift == 1) && (subset == 0))
	rb_alloc2<<=4;
	else if ((shift == 1) && (subset == 1))
	rb_alloc2<<=3;
      */
    }
    break;

  default:
winckel's avatar
winckel committed
271 272
    LOG_E(PHY,"Invalid N_RB_DL %d\n", N_RB_DL);
    DevParam (N_RB_DL, 0, 0);
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
    break;
  }

}



uint32_t conv_nprb(uint8_t ra_header,uint32_t rb_alloc,int N_RB_DL) {

  uint32_t nprb=0,i;

  switch (N_RB_DL) {
  case 6:
    for (i=0;i<6;i++) {
      if ((rb_alloc&(1<<i)) != 0)
	nprb += 1;
    }
    break;
  case 25:
    if (ra_header == 0) {// Type 0 Allocation
      
294 295 296 297 298 299
      for (i=12;i>0;i--) {
	if ((rb_alloc&(1<<i)) != 0)
	  nprb += 2;
      }
      if ((rb_alloc&1) != 0)
	nprb += 1;
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
    }
    else {
      for (i=0;i<11;i++) {
	if ((rb_alloc&(1<<(i+2))) != 0)
	  nprb += 1;
      }
    }
    break;
  case 50:
    if (ra_header == 0) {// Type 0 Allocation
            
      for (i=0;i<16;i++) {
	if ((rb_alloc&(1<<(16-i))) != 0)
	  nprb += 3;
      }
      if ((rb_alloc&1) != 0)
	nprb += 2;

    }
    else {
      for (i=0;i<17;i++) {
	if ((rb_alloc&(1<<(i+2))) != 0)
	  nprb += 1;
      }
    }
    break;
  case 100:
    if (ra_header == 0) {// Type 0 Allocation
      
      for (i=0;i<25;i++) {
	if ((rb_alloc&(1<<(24-i))) != 0)
	  nprb += 4;
      }
    }
    else {
      for (i=0;i<25;i++) {
	if ((rb_alloc&(1<<(i+2))) != 0)
	  nprb += 1;
      }
    }
    break;
winckel's avatar
winckel committed
341 342 343 344 345

  default:
    LOG_E(PHY,"Invalide N_RB_DL %d\n", N_RB_DL);
    DevParam (N_RB_DL, 0, 0);
    break;
346 347 348 349 350 351 352
  }

  return(nprb);
}

uint16_t computeRIV(uint16_t N_RB_DL,uint16_t RBstart,uint16_t Lcrbs) {

353
  uint16_t RIV;
354
    
355 356 357 358
  if (Lcrbs<=(1+(N_RB_DL>>1)))
    RIV = (N_RB_DL*(Lcrbs-1)) + RBstart;
  else
    RIV = (N_RB_DL*(N_RB_DL+1-Lcrbs)) + (N_RB_DL-1-RBstart);
359
    
360
  return(RIV);
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
}

int dist6[6]={0,2,3,5,1,4};
int dist50[50]={};
int dist100[100]={};

void generate_RIV_tables() {

  // 6RBs localized RIV
  uint8_t Lcrbs,RBstart;
  uint8_t distpos;
  uint16_t RIV;
  uint32_t alloc0,alloc_dist0;
  uint32_t alloc1,alloc_dist1;
  uint32_t alloc2,alloc_dist2;
  uint32_t alloc3,alloc_dist3;

  for (RBstart=0;RBstart<6;RBstart++) {
    alloc0 = 0;
    alloc_dist0 = 0;
    for (Lcrbs=1;Lcrbs<=(6-RBstart);Lcrbs++) {
      //printf("RBstart %d, len %d --> ",RBstart,Lcrbs);
      alloc0 |= (1<<(RBstart+Lcrbs-1));
      // This is the RB<->VRB relationship for N_RB_DL=25
      alloc_dist0 |= (1<<dist6[RBstart+Lcrbs-1]);

      RIV=computeRIV(6,RBstart,Lcrbs);
      if (RIV>RIV_max6)
	RIV_max6 = RIV;

      //      printf("RIV %d (%d) : first_rb %d NBRB %d\n",RIV,localRIV2alloc_LUT25[RIV],RBstart,Lcrbs);
      localRIV2alloc_LUT6[RIV] = alloc0;
      distRIV2alloc_LUT6[RIV]  = alloc_dist0;
      RIV2nb_rb_LUT6[RIV]      = Lcrbs;
      RIV2first_rb_LUT6[RIV]   = RBstart;
    }
  }


  for (RBstart=0;RBstart<25;RBstart++) {
401 402 403 404 405 406 407 408 409 410
    alloc0 = 0;
    alloc_dist0 = 0;
    for (Lcrbs=1;Lcrbs<=(25-RBstart);Lcrbs++) {
      //      printf("RBstart %d, len %d --> ",RBstart,Lcrbs);
      alloc0 |= (1<<(RBstart+Lcrbs-1));
      // This is the RB<->VRB relationship for N_RB_DL=25
      distpos = ((RBstart+Lcrbs-1)*6)%23;
      if (distpos == 0)
	distpos = 23;
      alloc_dist0 |= (1<<distpos);
411
          
412 413 414
      RIV=computeRIV(25,RBstart,Lcrbs);
      if (RIV>RIV_max25)
	RIV_max25 = RIV;
415
          
416 417 418 419 420 421
      //      printf("RIV %d (%d) : first_rb %d NBRB %d\n",RIV,localRIV2alloc_LUT25[RIV],RBstart,Lcrbs);
      localRIV2alloc_LUT25[RIV] = alloc0;
      distRIV2alloc_LUT25[RIV]  = alloc_dist0;
      RIV2nb_rb_LUT25[RIV]      = Lcrbs;
      RIV2first_rb_LUT25[RIV]   = RBstart;
    }
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 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 516 517 518 519 520 521 522 523 524 525 526
  }


  for (RBstart=0;RBstart<50;RBstart++) {
    alloc0 = 0;
    alloc_dist0 = 0;
    alloc1 = 0;
    alloc_dist1 = 0;
    for (Lcrbs=1;Lcrbs<=(50-RBstart);Lcrbs++) {
      //      printf("RBstart %d, len %d --> ",RBstart,Lcrbs);

      if ((RBstart+Lcrbs-1)<32)
	alloc0 |= (1<<(RBstart+Lcrbs-1));
      else
	alloc1 |= (1<<(RBstart+Lcrbs-33));

      if (dist50[RBstart+Lcrbs-1]<32)
	alloc_dist0 |= (1<<dist50[RBstart+Lcrbs-1]);
      else
	alloc_dist1 |= (1<<dist50[RBstart+Lcrbs-33]);

      RIV=computeRIV(50,RBstart,Lcrbs);
      if (RIV>RIV_max50)
	RIV_max50 = RIV;

      //      printf("RIV %d : first_rb %d NBRB %d\n",RIV,RBstart,Lcrbs);
      localRIV2alloc_LUT50_0[RIV] = alloc0;
      localRIV2alloc_LUT50_1[RIV] = alloc1;
      distRIV2alloc_LUT50_0[RIV]  = alloc_dist0;
      distRIV2alloc_LUT50_1[RIV]  = alloc_dist1;
      RIV2nb_rb_LUT50[RIV]        = Lcrbs;
      RIV2first_rb_LUT50[RIV]     = RBstart;
    }
  }


  for (RBstart=0;RBstart<100;RBstart++) {
    alloc0 = 0;
    alloc_dist0 = 0;
    alloc1 = 0;
    alloc_dist1 = 0;
    alloc2 = 0;
    alloc_dist2 = 0;
    alloc3 = 0;
    alloc_dist3 = 0;

    for (Lcrbs=1;Lcrbs<=(100-RBstart);Lcrbs++) {

      if ((RBstart+Lcrbs-1)<32)
	alloc0 |= (1<<(RBstart+Lcrbs-1));
      else if ((RBstart+Lcrbs-1)<64)
	alloc1 |= (1<<(RBstart+Lcrbs-33));
      else if ((RBstart+Lcrbs-1)<96)
	alloc2 |= (1<<(RBstart+Lcrbs-65));
      else
	alloc3 |= (1<<(RBstart+Lcrbs-97));

      if (dist100[RBstart+Lcrbs-1]<32)
	alloc_dist0 |= (1<<dist100[RBstart+Lcrbs-1]);
      else if (dist100[RBstart+Lcrbs-1]<64)
	alloc_dist1 |= (1<<dist100[RBstart+Lcrbs-33]);
      else if (dist100[RBstart+Lcrbs-1]<64)
	alloc_dist2 |= (1<<dist100[RBstart+Lcrbs-65]);
      else
	alloc_dist3 |= (1<<dist100[RBstart+Lcrbs-97]);

      RIV=computeRIV(100,RBstart,Lcrbs);
      if (RIV>RIV_max100)
	RIV_max100 = RIV;

      //      printf("RIV %d : first_rb %d NBRB %d\n",RIV,RBstart,Lcrbs);
      localRIV2alloc_LUT100_0[RIV] = alloc0;
      distRIV2alloc_LUT100_0[RIV]  = alloc_dist0;
      localRIV2alloc_LUT100_1[RIV] = alloc1;
      distRIV2alloc_LUT100_1[RIV]  = alloc_dist1;
      localRIV2alloc_LUT100_2[RIV] = alloc2;
      distRIV2alloc_LUT100_2[RIV]  = alloc_dist2;
      localRIV2alloc_LUT100_3[RIV] = alloc3;
      distRIV2alloc_LUT100_3[RIV]  = alloc_dist3;
      RIV2nb_rb_LUT100[RIV]      = Lcrbs;
      RIV2first_rb_LUT100[RIV]   = RBstart;
    }
  }
}

// Ngap = 3, N_VRB_DL=6, P=1, N_row=2, N_null=4*2-6=2
// permutation for even slots :
//    n_PRB'(0,2,4) = (0,1,2), n_PRB'(1,3,5) = (4,5,6)
//    n_PRB''(0,1,2,3) = (0,2,4,6)
//    => n_tilde_PRB(5) = (4)
//       n_tilde_PRB(4) = (1)
//       n_tilde_PRB(2,3) = (3,5)
//       n_tilde_PRB(0,1) = (0,2)


 
uint32_t get_rballoc(uint8_t vrb_type,uint16_t rb_alloc_dci) {

  if (vrb_type == 0)
    return(localRIV2alloc_LUT25[rb_alloc_dci]);
  else
    return(distRIV2alloc_LUT25[rb_alloc_dci]);

}

527
uint8_t get_transmission_mode(uint16_t Mod_id, uint8_t CC_id, uint16_t rnti) {
528 529 530
  unsigned char UE_id;

  // find the UE_index corresponding to rnti
531
  UE_id = find_ue(rnti,PHY_vars_eNB_g[Mod_id][CC_id]);
532

533
  return(PHY_vars_eNB_g[Mod_id][CC_id]->transmission_mode[UE_id]);
534 535 536 537 538 539 540 541 542 543 544 545 546 547
}

int generate_eNB_dlsch_params_from_dci(uint8_t subframe,
				       void *dci_pdu,
				       uint16_t rnti,
				       DCI_format_t dci_format,
				       LTE_eNB_DLSCH_t **dlsch,
				       LTE_DL_FRAME_PARMS *frame_parms,
				       PDSCH_CONFIG_DEDICATED *pdsch_config_dedicated,
				       uint16_t si_rnti,
				       uint16_t ra_rnti,
				       uint16_t p_rnti,
				       uint16_t DL_pmi_single) {

winckel's avatar
winckel committed
548 549 550
  uint8_t harq_pid = UINT8_MAX;
  uint32_t rballoc = UINT32_MAX;
  uint32_t RIV_max = 0;
551 552 553 554
  uint8_t NPRB,tbswap,tpmi=0;
  LTE_eNB_DLSCH_t *dlsch0=NULL,*dlsch1;
  uint8_t frame_type=frame_parms->frame_type;
  uint8_t vrb_type=0;
Raymond Knopp's avatar
 
Raymond Knopp committed
555
  uint8_t mcs=0,mcs1=0,mcs2=0;
556
  uint8_t I_mcs = 0;
Raymond Knopp's avatar
 
Raymond Knopp committed
557
  uint8_t rv=0,rv1=0,rv2=0;
558 559
  uint8_t rah=0;
  uint8_t TPC=0;
Raymond Knopp's avatar
 
Raymond Knopp committed
560

561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
  //   printf("Generate eNB DCI, format %d, rnti %x (pdu %p)\n",dci_format,rnti,dci_pdu);

  switch (dci_format) {

  case format0:
    return(-1);
    break;
  case format1A:  // This is DLSCH allocation for control traffic

 

    dlsch[0]->subframe_tx[subframe] = 1;

    switch (frame_parms->N_RB_DL) {
    case 6:
      if (frame_type == TDD) {
	vrb_type = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->rv;
	TPC      = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->harq_pid;

584
	//	      printf("TDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
      }
      else {
	vrb_type = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->rv;
	TPC      = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->harq_pid;

	//      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
      }
      
      if (vrb_type == 0)
	dlsch[0]->rb_alloc[0]                       = localRIV2alloc_LUT6[rballoc];
      else
	dlsch[0]->rb_alloc[0]                       = distRIV2alloc_LUT6[rballoc];
      
      dlsch[0]->nb_rb                               = RIV2nb_rb_LUT6[rballoc];//NPRB;
      RIV_max = RIV_max6;

      
      break;
    case 25:
      if (frame_type == TDD) {
	vrb_type = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->rv;
	TPC      = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->harq_pid;

	//      printf("TDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
      }
      else {
	vrb_type = ((DCI1A_5MHz_FDD_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_5MHz_FDD_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_5MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_5MHz_FDD_t *)dci_pdu)->rv;
	TPC      = ((DCI1A_5MHz_FDD_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_5MHz_FDD_t *)dci_pdu)->harq_pid;

	//      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
      }

      if (vrb_type == 0)
	dlsch[0]->rb_alloc[0]                       = localRIV2alloc_LUT25[rballoc];
      else
	dlsch[0]->rb_alloc[0]                       = distRIV2alloc_LUT25[rballoc];
      
      dlsch[0]->nb_rb                               = RIV2nb_rb_LUT25[rballoc];//NPRB;
      RIV_max = RIV_max25;      
      break;
    case 50:
      if (frame_type == TDD) {
	vrb_type = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->rv;
	TPC      = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->harq_pid;

	//      printf("TDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
      }
      else {
	vrb_type = ((DCI1A_10MHz_FDD_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_10MHz_FDD_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_10MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_10MHz_FDD_t *)dci_pdu)->rv;
	TPC      = ((DCI1A_10MHz_FDD_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_10MHz_FDD_t *)dci_pdu)->harq_pid;
	//      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
      }

      if (vrb_type == 0) {
	dlsch[0]->rb_alloc[0]                       = localRIV2alloc_LUT50_0[rballoc];
	dlsch[0]->rb_alloc[1]                       = localRIV2alloc_LUT50_1[rballoc];
      }
      else {
	dlsch[0]->rb_alloc[0]                       = distRIV2alloc_LUT50_0[rballoc];
	dlsch[0]->rb_alloc[1]                       = distRIV2alloc_LUT50_1[rballoc];
      }
      dlsch[0]->nb_rb                               = RIV2nb_rb_LUT50[rballoc];//NPRB;
      RIV_max = RIV_max50;
      break;
    case 100:
      if (frame_type == TDD) {
	vrb_type = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->rv;
	TPC      = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->harq_pid;
	//      printf("TDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
      }
      else {
	vrb_type = ((DCI1A_20MHz_FDD_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_20MHz_FDD_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_20MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_20MHz_FDD_t *)dci_pdu)->rv;
	TPC      = ((DCI1A_20MHz_FDD_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_20MHz_FDD_t *)dci_pdu)->harq_pid;
	//      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
      }

      if (vrb_type == 0) {
	dlsch[0]->rb_alloc[0]                       = localRIV2alloc_LUT100_0[rballoc];
	dlsch[0]->rb_alloc[1]                       = localRIV2alloc_LUT100_1[rballoc];
	dlsch[0]->rb_alloc[2]                       = localRIV2alloc_LUT100_2[rballoc];
	dlsch[0]->rb_alloc[3]                       = localRIV2alloc_LUT100_3[rballoc];
      }
      else {
	dlsch[0]->rb_alloc[0]                       = distRIV2alloc_LUT100_0[rballoc];
	dlsch[0]->rb_alloc[1]                       = distRIV2alloc_LUT100_1[rballoc];
	dlsch[0]->rb_alloc[2]                       = distRIV2alloc_LUT100_2[rballoc];
	dlsch[0]->rb_alloc[3]                       = distRIV2alloc_LUT100_3[rballoc];
      }
      dlsch[0]->nb_rb                               = RIV2nb_rb_LUT100[rballoc];//NPRB;
      RIV_max = RIV_max100;
      break;
winckel's avatar
winckel committed
704 705 706 707 708

      default:
        LOG_E(PHY,"Invalid N_RB_D %dL\n", frame_parms->N_RB_DL);
        DevParam (frame_parms->N_RB_DL, 0, 0);
        break;
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
    }

    // harq_pid field is reserved
    if ((rnti==si_rnti) || (rnti==ra_rnti) || (rnti==p_rnti)){  //
      harq_pid=0;
      // see 36-212 V8.6.0 p. 45
      NPRB      = (TPC&1)+2;
      // 36-213 sec.7.1.7.2 p.26
      I_mcs     = mcs;
    }
    else {
      if (harq_pid>1) {
	LOG_E(PHY,"ERROR: Format 1A: harq_pid > 1\n");
	return(-1);
      }
      if (rballoc>RIV_max) {
	LOG_E(PHY,"ERROR: Format 1A: rb_alloc (%x) > RIV_max (%x)\n",rballoc,RIV_max);
	return(-1);
      }
      NPRB      = dlsch[0]->nb_rb;
      I_mcs     = get_I_TBS(mcs);
    }

    if (NPRB==0)
      return(-1);

    //  printf("NPRB %d, nb_rb %d, ndi %d\n",NPRB,dlsch[0]->nb_rb,ndi);
    dlsch[0]->harq_processes[harq_pid]->rvidx     = rv; 

    dlsch[0]->harq_processes[harq_pid]->Nl          = 1;
    dlsch[0]->layer_index = 0;
    dlsch[0]->harq_processes[harq_pid]->mimo_mode   = (frame_parms->mode1_flag == 1) ? SISO : ALAMOUTI;

742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
    /*   
	 if ((rnti!=si_rnti)&&(rnti!=ra_rnti)&&(rnti!=p_rnti)) {  //handle toggling for C-RNTI
	 if (dlsch[0]->harq_processes[harq_pid]->first_tx == 1) {
	 LOG_D(PHY,"First TX for TC-RNTI %x, clearing first_tx flag\n",rnti);
	 dlsch[0]->harq_processes[harq_pid]->first_tx=0;
	 dlsch[0]->harq_processes[harq_pid]->Ndi = 1;
	 } 
	 else {
	 if (ndi == dlsch[0]->harq_processes[harq_pid]->DCINdi)
	 dlsch[0]->harq_processes[harq_pid]->Ndi         = 0;
	 else
	 dlsch[0]->harq_processes[harq_pid]->Ndi         = 1;
	 }
    
	 dlsch[0]->harq_processes[harq_pid]->DCINdi=ndi;
	 }
	 else {
	 dlsch[0]->harq_processes[harq_pid]->Ndi         = 1;
	 }
    */
    dlsch[0]->dl_power_off = 1;
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777



    dlsch[0]->harq_processes[harq_pid]->mcs         = mcs;
    dlsch[0]->harq_processes[harq_pid]->TBS         = TBStable[I_mcs][NPRB-1];

    dlsch[0]->current_harq_pid = harq_pid;
    dlsch[0]->harq_ids[subframe] = harq_pid;

    dlsch[0]->active = 1;
    dlsch0 = dlsch[0];

    dlsch[0]->rnti = rnti;

    dlsch[0]->harq_ids[subframe] = harq_pid;
778
    if (dlsch[0]->harq_processes[harq_pid]->round == 0)
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
      dlsch[0]->harq_processes[harq_pid]->status = ACTIVE;

    break;
  case format1:

    switch (frame_parms->N_RB_DL) {

    case 6:
      if (frame_type == TDD) {
	mcs       = ((DCI1_1_5MHz_TDD_t *)dci_pdu)->mcs;
	rballoc   = ((DCI1_1_5MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI1_1_5MHz_TDD_t *)dci_pdu)->rah;
	rv        = ((DCI1_1_5MHz_TDD_t *)dci_pdu)->rv;
	harq_pid  = ((DCI1_1_5MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs      = ((DCI1_1_5MHz_FDD_t *)dci_pdu)->mcs;
	rah      = ((DCI1_1_5MHz_FDD_t *)dci_pdu)->rah;
	rballoc  = ((DCI1_1_5MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1_1_5MHz_FDD_t *)dci_pdu)->rv;
	harq_pid = ((DCI1_1_5MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;
    case 25:
      
      if (frame_type == TDD) {
	mcs       = ((DCI1_5MHz_TDD_t *)dci_pdu)->mcs;
	rballoc   = ((DCI1_5MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI1_5MHz_TDD_t *)dci_pdu)->rah;
	rv        = ((DCI1_5MHz_TDD_t *)dci_pdu)->rv;
	harq_pid  = ((DCI1_5MHz_TDD_t *)dci_pdu)->harq_pid;
810
	LOG_D(PHY,"eNB: subframe %d UE %x, Format1 DCI: ndi %d, harq_pid %d\n",subframe,rnti,((DCI1_5MHz_TDD_t *)dci_pdu)->ndi,harq_pid);
811 812 813 814 815 816 817
      }
      else {
	mcs      = ((DCI1_5MHz_FDD_t *)dci_pdu)->mcs;
	rah      = ((DCI1_5MHz_FDD_t *)dci_pdu)->rah;
	rballoc  = ((DCI1_5MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1_5MHz_FDD_t *)dci_pdu)->rv;
	harq_pid = ((DCI1_5MHz_FDD_t *)dci_pdu)->harq_pid;
818 819
	LOG_D(PHY,"eNB: subframe %d UE %x, Format1 DCI: ndi %d, harq_pid %d\n",subframe,rnti,((DCI1_5MHz_FDD_t *)dci_pdu)->ndi,harq_pid);

820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
      }
      break;
    case 50:
      if (frame_type == TDD) {
	mcs       = ((DCI1_10MHz_TDD_t *)dci_pdu)->mcs;
	rballoc   = ((DCI1_10MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI1_10MHz_TDD_t *)dci_pdu)->rah;
	rv        = ((DCI1_10MHz_TDD_t *)dci_pdu)->rv;
	harq_pid  = ((DCI1_10MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs      = ((DCI1_10MHz_FDD_t *)dci_pdu)->mcs;
	rah      = ((DCI1_10MHz_FDD_t *)dci_pdu)->rah;
	rballoc  = ((DCI1_10MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1_10MHz_FDD_t *)dci_pdu)->rv;
	harq_pid = ((DCI1_10MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;

    case 100:
      if (frame_type == TDD) {
	mcs       = ((DCI1_20MHz_TDD_t *)dci_pdu)->mcs;
	rballoc   = ((DCI1_20MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI1_20MHz_TDD_t *)dci_pdu)->rah;
	rv        = ((DCI1_20MHz_TDD_t *)dci_pdu)->rv;
	harq_pid  = ((DCI1_20MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs      = ((DCI1_20MHz_FDD_t *)dci_pdu)->mcs;
	rah      = ((DCI1_20MHz_FDD_t *)dci_pdu)->rah;
	rballoc  = ((DCI1_20MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1_20MHz_FDD_t *)dci_pdu)->rv;
	harq_pid = ((DCI1_20MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;

    }

    if (harq_pid>=8) {
      LOG_E(PHY,"ERROR: Format 1: harq_pid >= 8\n");
      return(-1);
    }

    // msg("DCI: Setting subframe_tx for subframe %d\n",subframe);
    dlsch[0]->subframe_tx[subframe] = 1;

    conv_rballoc(rah,
		 rballoc,frame_parms->N_RB_DL,
		 dlsch[0]->rb_alloc);

    dlsch[0]->nb_rb = conv_nprb(rah,
				rballoc,
				frame_parms->N_RB_DL);

    NPRB      = dlsch[0]->nb_rb;


    if (NPRB==0)
      return(-1);


    dlsch[0]->harq_processes[harq_pid]->rvidx       = rv;

    dlsch[0]->harq_processes[harq_pid]->Nl          = 1;
    dlsch[0]->layer_index = 0;
    dlsch[0]->harq_processes[harq_pid]->mimo_mode   = (frame_parms->mode1_flag == 1) ? SISO : ALAMOUTI;
    dlsch[0]->dl_power_off = 1;
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
    /*
      if (dlsch[0]->harq_processes[harq_pid]->first_tx == 1) {
      LOG_D(PHY,"First TX for C-RNTI %x, clearing first_tx flag, shouldn't happen!\n",rnti);
      dlsch[0]->harq_processes[harq_pid]->first_tx=0;
      dlsch[0]->harq_processes[harq_pid]->Ndi = 1;
      } 
      else {
      LOG_D(PHY,"Checking for Toggled Ndi for C-RNTI %x, old value %d, DCINdi %d\n",rnti,dlsch[0]->harq_processes[harq_pid]->DCINdi,ndi);
      if (ndi == dlsch[0]->harq_processes[harq_pid]->DCINdi)
      dlsch[0]->harq_processes[harq_pid]->Ndi         = 0;
      else
      dlsch[0]->harq_processes[harq_pid]->Ndi         = 1;
      }
      dlsch[0]->harq_processes[harq_pid]->DCINdi=ndi;
    */
902 903 904

    dlsch[0]->active = 1;

905 906 907


    if (dlsch[0]->harq_processes[harq_pid]->round == 0) {
908 909 910
      dlsch[0]->harq_processes[harq_pid]->status = ACTIVE;
      //            printf("Setting DLSCH process %d to ACTIVE\n",harq_pid);
      // MCS and TBS don't change across HARQ rounds
911 912
      dlsch[0]->harq_processes[harq_pid]->mcs         = mcs;
      dlsch[0]->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch[0]->harq_processes[harq_pid]->mcs)][NPRB-1];
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928

    }


    dlsch[0]->current_harq_pid = harq_pid;
    dlsch[0]->harq_ids[subframe] = harq_pid;



    dlsch0 = dlsch[0];

    dlsch[0]->rnti = rnti;


    break;

Raymond Knopp's avatar
 
Raymond Knopp committed
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
  case format2:

    switch (frame_parms->N_RB_DL) {

    case 6:
      if (frame_parms->nb_antennas_tx == 2) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->rballoc;
	  rv1       = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->rballoc;
	  rv1       = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else if (frame_parms->nb_antennas_tx == 4) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->rballoc;
	  rv1       = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->rballoc;
	  rv1       = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else {
	LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",frame_parms->nb_antennas_tx);
      }
      break;
    case 25:
      if (frame_parms->nb_antennas_tx == 2) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else if (frame_parms->nb_antennas_tx == 4) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else {
	LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",frame_parms->nb_antennas_tx);
      }      
      break;
    case 50:
      if (frame_parms->nb_antennas_tx == 2) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else if (frame_parms->nb_antennas_tx == 4) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else {
	LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",frame_parms->nb_antennas_tx);
      }
      break;

    case 100:
      if (frame_parms->nb_antennas_tx == 2) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else if (frame_parms->nb_antennas_tx == 4) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else {
	LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",frame_parms->nb_antennas_tx);
      }
      break;
    }

1144 1145

    if (harq_pid>=8) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1146
      LOG_E(PHY,"ERROR: Format 2_2A: harq_pid >= 8\n");
1147 1148 1149 1150
      return(-1);
    }


Raymond Knopp's avatar
 
Raymond Knopp committed
1151 1152
    // Flip the TB to codeword mapping as described in 5.3.3.1.5 of 36-212 V11.3.0
    // note that we must set tbswap=0 in eNB scheduler if one TB is deactivated
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
    if (tbswap == 0) {
      dlsch0 = dlsch[0];
      dlsch1 = dlsch[1];
    }
    else{
      dlsch0 = dlsch[1];
      dlsch1 = dlsch[0];
    }

    dlsch0->subframe_tx[subframe] = 1;

    dlsch0->current_harq_pid = harq_pid;
    dlsch1->current_harq_pid = harq_pid;
    dlsch0->harq_ids[subframe] = harq_pid;
    dlsch1->harq_ids[subframe] = harq_pid;
    //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);


Raymond Knopp's avatar
 
Raymond Knopp committed
1171 1172 1173
    conv_rballoc(rah,
		 rballoc,
		 frame_parms->N_RB_DL,
1174
		 dlsch0->rb_alloc);
Raymond Knopp's avatar
 
Raymond Knopp committed
1175

1176
    dlsch1->rb_alloc[0]                         = dlsch0->rb_alloc[0];
Raymond Knopp's avatar
 
Raymond Knopp committed
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
    dlsch0->nb_rb                               = conv_nprb(rah,
							    rballoc,
							    frame_parms->N_RB_DL);
    dlsch1->nb_rb                               = dlsch0->nb_rb;

    if (dlsch0->nb_rb == 0)
      return(-1);

    dlsch0->harq_processes[harq_pid]->mcs       = mcs1;
    dlsch1->harq_processes[harq_pid]->mcs       = mcs2;
    dlsch0->harq_processes[harq_pid]->rvidx     = rv1;
    dlsch1->harq_processes[harq_pid]->rvidx     = rv2;

    // assume both TBs are active
    dlsch0->harq_processes[harq_pid]->Nl        = 1;
    dlsch1->harq_processes[harq_pid]->Nl        = 1;
    dlsch0->active = 1;
    dlsch1->active = 1;


    // check if either TB is disabled (see 36-213 V11.3 Section )
    if ((dlsch0->harq_processes[harq_pid]->rvidx == 1) && (dlsch0->harq_processes[harq_pid]->mcs == 0)) {
      dlsch0->active = 0;
    }
    if ((dlsch1->harq_processes[harq_pid]->rvidx == 1) && (dlsch1->harq_processes[harq_pid]->mcs == 0)) {
      dlsch1->active = 0;
    }

    if (frame_parms->nb_antennas_tx == 2) {
      if (dlsch1->active == 1) { // both TBs are active
	dlsch0->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch0->harq_processes[harq_pid]->mcs)][dlsch0->nb_rb-1];
	dlsch1->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch1->harq_processes[harq_pid]->mcs)][dlsch0->nb_rb-1];
	switch (tpmi) {
	case 0:
	  dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING11;
	  dlsch1->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1m1;
	  dlsch0->pmi_alloc                             = pmi_extend(frame_parms,0);
	  dlsch1->pmi_alloc                             = pmi_extend(frame_parms,1);
	  break;
	case 1:
	  dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1j;
	  dlsch1->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1mj;
	  dlsch0->pmi_alloc                             = pmi_extend(frame_parms,2);
	  dlsch0->pmi_alloc                             = pmi_extend(frame_parms,3);
	  break;
	case 2: // PUSCH precoding
	  dlsch0->harq_processes[harq_pid]->mimo_mode   = DUALSTREAM_PUSCH_PRECODING;
	  dlsch0->pmi_alloc                             = DL_pmi_single;
	  dlsch1->harq_processes[harq_pid]->mimo_mode   = DUALSTREAM_PUSCH_PRECODING;
	  dlsch1->pmi_alloc                             = DL_pmi_single;
	  break;
	default:
	  break;
	}
	dlsch0->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch0->harq_processes[harq_pid]->mcs)][dlsch0->nb_rb-1];
	dlsch1->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch1->harq_processes[harq_pid]->mcs)][dlsch1->nb_rb-1];
      }
      else { // only one is active
	switch (tpmi) {
	case 0 :
	  dlsch0->harq_processes[harq_pid]->mimo_mode   = ALAMOUTI;
	  break;
	case 1:
	  dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING11;
	  dlsch0->pmi_alloc                             = pmi_extend(frame_parms,0);
	  break;
	case 2:
	  dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1m1;
	  dlsch0->pmi_alloc                             = pmi_extend(frame_parms,1);
	  break;
	case 3:
	  dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1j;
	  dlsch0->pmi_alloc                             = pmi_extend(frame_parms,2);
	  break;
	case 4:
	  dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1mj;
	  dlsch0->pmi_alloc                             = pmi_extend(frame_parms,3);
	  break;
	case 5:
	  dlsch0->harq_processes[harq_pid]->mimo_mode   = PUSCH_PRECODING0;
	  dlsch0->pmi_alloc                             = DL_pmi_single;
	  break;
	case 6:
	  dlsch0->harq_processes[harq_pid]->mimo_mode   = PUSCH_PRECODING1;
	  dlsch0->pmi_alloc                             = DL_pmi_single;
	  break;
	}
	dlsch0->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch0->harq_processes[harq_pid]->mcs)][dlsch0->nb_rb-1];
      }
    }
    else if (frame_parms->nb_antennas_tx == 4) {
      // fill in later
    }
1270

Raymond Knopp's avatar
 
Raymond Knopp committed
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399
    // reset HARQ process if this is the first transmission
    if (dlsch0->harq_processes[harq_pid]->round == 0) {
      dlsch0->harq_processes[harq_pid]->status = ACTIVE;
    }
    if (dlsch1->harq_processes[harq_pid]->round == 0) {
      dlsch1->harq_processes[harq_pid]->status = ACTIVE;
    }

    dlsch0->rnti = rnti;
    dlsch1->rnti = rnti;

    dlsch0->dl_power_off = 0;
    dlsch1->dl_power_off = 0;

    break;

  case format2B:

    switch (frame_parms->N_RB_DL) {

    case 6:
      if (frame_type == TDD) {
	mcs1      = ((DCI2B_1_5MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2B_1_5MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2B_1_5MHz_TDD_t *)dci_pdu)->rballoc;
	rv1       = ((DCI2B_1_5MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2B_1_5MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2B_1_5MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2B_1_5MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2B_1_5MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2B_1_5MHz_FDD_t *)dci_pdu)->rballoc;
	rv1       = ((DCI2B_1_5MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2B_1_5MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2B_1_5MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;
    case 25:
      if (frame_type == TDD) {
	mcs1      = ((DCI2B_5MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2B_5MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2B_5MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2B_5MHz_TDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2B_5MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2B_5MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2B_5MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2B_5MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2B_5MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2B_5MHz_FDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2B_5MHz_FDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2B_5MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2B_5MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2B_5MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;
    case 50:
      if (frame_type == TDD) {
	mcs1      = ((DCI2B_10MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2B_10MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2B_10MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2B_10MHz_TDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2B_10MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2B_10MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2B_10MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2B_10MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2B_10MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2B_10MHz_FDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2B_10MHz_FDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2B_10MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2B_10MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2B_10MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;

    case 100:
      if (frame_type == TDD) {
	mcs1      = ((DCI2B_20MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2B_20MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2B_20MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2B_20MHz_TDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2B_20MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2B_20MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2B_20MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2B_20MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2B_20MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2B_20MHz_FDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2B_20MHz_FDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2B_20MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2B_20MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2B_20MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;
    }


    if (harq_pid>=8) {
      LOG_E(PHY,"ERROR: Format 2_2A: harq_pid >= 8\n");
      return(-1);
    }



    dlsch0 = dlsch[0];
    dlsch1 = dlsch[1];

    dlsch0->subframe_tx[subframe] = 1;

    dlsch0->current_harq_pid = harq_pid;
    dlsch1->current_harq_pid = harq_pid;
    dlsch0->harq_ids[subframe] = harq_pid;
    dlsch1->harq_ids[subframe] = harq_pid;
    //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);


    conv_rballoc(rah,
		 rballoc,
		 frame_parms->N_RB_DL,
		 dlsch0->rb_alloc);
    dlsch1->rb_alloc[0]                         = dlsch0->rb_alloc[0];

    dlsch0->nb_rb                               = conv_nprb(rah,
							    rballoc,
1400 1401 1402
							    frame_parms->N_RB_DL);
    dlsch1->nb_rb                               = dlsch0->nb_rb;

Raymond Knopp's avatar
 
Raymond Knopp committed
1403 1404 1405 1406
    dlsch0->harq_processes[harq_pid]->mcs       = mcs1;
    dlsch1->harq_processes[harq_pid]->mcs       = mcs2;
    dlsch0->harq_processes[harq_pid]->rvidx     = rv1;
    dlsch1->harq_processes[harq_pid]->rvidx     = rv2;
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419

    // check if either TB is disabled (see 36-213 V8.6 p. 26)


    if ((dlsch0->harq_processes[harq_pid]->rvidx == 1) && (dlsch0->harq_processes[harq_pid]->mcs == 0))
      dlsch0->harq_processes[harq_pid]->status = DISABLED;

    if ((dlsch1->harq_processes[harq_pid]->rvidx == 1) && (dlsch1->harq_processes[harq_pid]->mcs == 0))
      dlsch1->harq_processes[harq_pid]->status = DISABLED;

    dlsch0->harq_processes[harq_pid]->Nl        = 1;


Raymond Knopp's avatar
 
Raymond Knopp committed
1420 1421 1422 1423
    if (dlsch0->harq_processes[harq_pid]->round == 0) {
      dlsch0->harq_processes[harq_pid]->status = ACTIVE;
      //      printf("Setting DLSCH process %d to ACTIVE\n",harq_pid);
    }
1424

Raymond Knopp's avatar
 
Raymond Knopp committed
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463
    dlsch0->harq_processes[harq_pid]->mcs         = mcs1;
    if (dlsch0->nb_rb > 0) {
      dlsch0->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch0->harq_processes[harq_pid]->mcs)][dlsch0->nb_rb-1];
    }
    else {
      dlsch0->harq_processes[harq_pid]->TBS = 0;
    }

    dlsch0->active = 1;

    dlsch0->rnti = rnti;
    dlsch1->rnti = rnti;

    dlsch0->dl_power_off = 1;
    dlsch1->dl_power_off = 1;

    break;

  case format2C:

    switch (frame_parms->N_RB_DL) {

    case 6:
      if (frame_type == TDD) {
	mcs1      = ((DCI2C_1_5MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2C_1_5MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2C_1_5MHz_TDD_t *)dci_pdu)->rballoc;
	rv1       = ((DCI2C_1_5MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2C_1_5MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2C_1_5MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2C_1_5MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2C_1_5MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2C_1_5MHz_FDD_t *)dci_pdu)->rballoc;
	rv1       = ((DCI2C_1_5MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2C_1_5MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2C_1_5MHz_FDD_t *)dci_pdu)->harq_pid;
      }
1464
      break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
    case 25:
      if (frame_type == TDD) {
	mcs1      = ((DCI2C_5MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2C_5MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2C_5MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2C_5MHz_TDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2C_5MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2C_5MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2C_5MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2C_5MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2C_5MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2C_5MHz_FDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2C_5MHz_FDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2C_5MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2C_5MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2C_5MHz_FDD_t *)dci_pdu)->harq_pid;
      }
1484
      break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503
    case 50:
      if (frame_type == TDD) {
	mcs1      = ((DCI2C_10MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2C_10MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2C_10MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2C_10MHz_TDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2C_10MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2C_10MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2C_10MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2C_10MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2C_10MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2C_10MHz_FDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2C_10MHz_FDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2C_10MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2C_10MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2C_10MHz_FDD_t *)dci_pdu)->harq_pid;
      }
1504
      break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524

    case 100:
      if (frame_type == TDD) {
	mcs1      = ((DCI2C_20MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2C_20MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2C_20MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2C_20MHz_TDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2C_20MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2C_20MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2C_20MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2C_20MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2C_20MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2C_20MHz_FDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2C_20MHz_FDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2C_20MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2C_20MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2C_20MHz_FDD_t *)dci_pdu)->harq_pid;
      }
1525
      break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
    }


    if (harq_pid>=8) {
      LOG_E(PHY,"ERROR: Format 2_2A: harq_pid >= 8\n");
      return(-1);
    }



    dlsch0 = dlsch[0];
    dlsch1 = dlsch[1];

    dlsch0->subframe_tx[subframe] = 1;

    dlsch0->current_harq_pid = harq_pid;
    dlsch1->current_harq_pid = harq_pid;
    dlsch0->harq_ids[subframe] = harq_pid;
    dlsch1->harq_ids[subframe] = harq_pid;
    //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);


    conv_rballoc(rah,
		 rballoc,
		 frame_parms->N_RB_DL,
		 dlsch0->rb_alloc);
    dlsch1->rb_alloc[0]                         = dlsch0->rb_alloc[0];

    dlsch0->nb_rb                               = conv_nprb(rah,
							    rballoc,
							    frame_parms->N_RB_DL);
    dlsch1->nb_rb                               = dlsch0->nb_rb;

    if (dlsch0->nb_rb == 0)
      return(-1);

    dlsch0->harq_processes[harq_pid]->mcs       = mcs1;
    dlsch1->harq_processes[harq_pid]->mcs       = mcs2;
    dlsch0->harq_processes[harq_pid]->rvidx     = rv1;
    dlsch1->harq_processes[harq_pid]->rvidx     = rv2;

    // check if either TB is disabled (see 36-213 V8.6 p. 26)


    if ((dlsch0->harq_processes[harq_pid]->rvidx == 1) && (dlsch0->harq_processes[harq_pid]->mcs == 0)) {
      dlsch0->active = 0;
    }
    if ((dlsch1->harq_processes[harq_pid]->rvidx == 1) && (dlsch1->harq_processes[harq_pid]->mcs == 0)) {
      dlsch1->active = 0;
    }



    if ((dlsch0->harq_processes[harq_pid]->round == 0) && (dlsch0->active == 1) ) {
      dlsch0->harq_processes[harq_pid]->status      = ACTIVE;
      dlsch0->harq_processes[harq_pid]->mcs         = mcs1;
    }

    if ((dlsch1->harq_processes[harq_pid]->round == 0) && (dlsch1->active == 1) ) {
      dlsch1->harq_processes[harq_pid]->status      = ACTIVE;
      dlsch1->harq_processes[harq_pid]->mcs         = mcs2;
    }

    // check TPMI information to compute TBS
    if (frame_parms->nb_antennas_tx == 2) {
      if (dlsch1->active == 1) { // both TBs are active
	dlsch0->harq_processes[harq_pid]->TBS           = TBStable[get_I_TBS(dlsch0->harq_processes[harq_pid]->mcs)][dlsch0->nb_rb-1];
	dlsch1->harq_processes[harq_pid]->TBS           = TBStable[get_I_TBS(dlsch1->harq_processes[harq_pid]->mcs)][dlsch0->nb_rb-1];
      }
      else {
	dlsch0->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch0->harq_processes[harq_pid]->mcs)][dlsch0->nb_rb-1];
      }
    }
    else if (frame_parms->nb_antennas_tx == 4) {

    }

    dlsch0->rnti = rnti;
    dlsch1->rnti = rnti;

    dlsch0->dl_power_off = 1;
    dlsch1->dl_power_off = 1;

    break;

  case format2D:

    switch (frame_parms->N_RB_DL) {

    case 6:
      if (frame_type == TDD) {
	mcs1      = ((DCI2D_1_5MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2D_1_5MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2D_1_5MHz_TDD_t *)dci_pdu)->rballoc;
	rv1       = ((DCI2D_1_5MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2D_1_5MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2D_1_5MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2D_1_5MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2D_1_5MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2D_1_5MHz_FDD_t *)dci_pdu)->rballoc;
	rv1       = ((DCI2D_1_5MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2D_1_5MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2D_1_5MHz_FDD_t *)dci_pdu)->harq_pid;
      }
1632
      break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
    case 25:
      if (frame_type == TDD) {
	mcs1      = ((DCI2D_5MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2D_5MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2D_5MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2D_5MHz_TDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2D_5MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2D_5MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2D_5MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2D_5MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2D_5MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2D_5MHz_FDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2D_5MHz_FDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2D_5MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2D_5MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2D_5MHz_FDD_t *)dci_pdu)->harq_pid;
      }
1652
      break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692
    case 50:
      if (frame_type == TDD) {
	mcs1      = ((DCI2D_10MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2D_10MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2D_10MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2D_10MHz_TDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2D_10MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2D_10MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2D_10MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2D_10MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2D_10MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2D_10MHz_FDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2D_10MHz_FDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2D_10MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2D_10MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2D_10MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;

    case 100:
      if (frame_type == TDD) {
	mcs1      = ((DCI2D_20MHz_TDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2D_20MHz_TDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2D_20MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2D_20MHz_TDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2D_20MHz_TDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2D_20MHz_TDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2D_20MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs1      = ((DCI2D_20MHz_FDD_t *)dci_pdu)->mcs1;
	mcs2      = ((DCI2D_20MHz_FDD_t *)dci_pdu)->mcs2;
	rballoc   = ((DCI2D_20MHz_FDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI2D_20MHz_FDD_t *)dci_pdu)->rah;
	rv1       = ((DCI2D_20MHz_FDD_t *)dci_pdu)->rv1;
	rv2       = ((DCI2D_20MHz_FDD_t *)dci_pdu)->rv2;
	harq_pid  = ((DCI2D_20MHz_FDD_t *)dci_pdu)->harq_pid;
      }
1693 1694 1695 1696
      break;
    }


Raymond Knopp's avatar
 
Raymond Knopp committed
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
    if (harq_pid>=8) {
      LOG_E(PHY,"ERROR: Format 2_2A: harq_pid >= 8\n");
      return(-1);
    }



    dlsch0 = dlsch[0];
    dlsch1 = dlsch[1];

    dlsch0->subframe_tx[subframe] = 1;

    dlsch0->current_harq_pid = harq_pid;
    dlsch1->current_harq_pid = harq_pid;
    dlsch0->harq_ids[subframe] = harq_pid;
    dlsch1->harq_ids[subframe] = harq_pid;
    //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);


    conv_rballoc(rah,
		 rballoc,
		 frame_parms->N_RB_DL,
		 dlsch0->rb_alloc);
    dlsch1->rb_alloc[0]                         = dlsch0->rb_alloc[0];

    dlsch0->nb_rb                               = conv_nprb(rah,
							    rballoc,
							    frame_parms->N_RB_DL);
    dlsch1->nb_rb                               = dlsch0->nb_rb;

    dlsch0->harq_processes[harq_pid]->mcs       = mcs1;
    dlsch1->harq_processes[harq_pid]->mcs       = mcs2;
    dlsch0->harq_processes[harq_pid]->rvidx     = rv1;
    dlsch1->harq_processes[harq_pid]->rvidx     = rv2;

    // check if either TB is disabled (see 36-213 V8.6 p. 26)


    if ((dlsch0->harq_processes[harq_pid]->rvidx == 1) && (dlsch0->harq_processes[harq_pid]->mcs == 0))
      dlsch0->harq_processes[harq_pid]->status = DISABLED;

    if ((dlsch1->harq_processes[harq_pid]->rvidx == 1) && (dlsch1->harq_processes[harq_pid]->mcs == 0))
      dlsch1->harq_processes[harq_pid]->status = DISABLED;

    dlsch0->harq_processes[harq_pid]->Nl        = 1;
1742 1743


1744
    if (dlsch0->harq_processes[harq_pid]->round == 0) {
1745 1746 1747 1748
      dlsch0->harq_processes[harq_pid]->status = ACTIVE;
      //      printf("Setting DLSCH process %d to ACTIVE\n",harq_pid);
    }

Raymond Knopp's avatar
 
Raymond Knopp committed
1749
    dlsch0->harq_processes[harq_pid]->mcs         = mcs1;
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765
    if (dlsch0->nb_rb > 0) {
      dlsch0->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch0->harq_processes[harq_pid]->mcs)][dlsch0->nb_rb-1];
    }
    else {
      dlsch0->harq_processes[harq_pid]->TBS = 0;
    }

    dlsch0->active = 1;

    dlsch0->rnti = rnti;
    dlsch1->rnti = rnti;

    dlsch0->dl_power_off = 1;
    dlsch1->dl_power_off = 1;

    break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1766 1767


1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863
  case format1E_2A_M10PRB:

    harq_pid  = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->harq_pid;
    if (harq_pid>=8) {
      LOG_E(PHY,"ERROR: Format 1E_2A_M10PRB: harq_pid >= 8\n");
      return(-1);
    }

    /*
      tbswap = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->tb_swap;
      if (tbswap == 0) {
      dlsch0 = dlsch[0];
      dlsch1 = dlsch[1];
      }
      else{
      dlsch0 = dlsch[1];
      dlsch1 = dlsch[0];
      }
    */
    dlsch0 = dlsch[0];
    dlsch0->subframe_tx[subframe] = 1;

    dlsch0->current_harq_pid = harq_pid;
    //dlsch1->current_harq_pid = harq_pid;
    dlsch0->harq_ids[subframe] = harq_pid;
    //dlsch1->harq_ids[subframe] = harq_pid;
    //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);

    conv_rballoc(((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rah,
		 ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rballoc,frame_parms->N_RB_DL,
		 dlsch0->rb_alloc);
		 
    //dlsch1->rb_alloc[0]                         = dlsch0->rb_alloc[0];

    dlsch0->nb_rb                               = conv_nprb(((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rah,
							    ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rballoc,
							    frame_parms->N_RB_DL);
    //dlsch1->nb_rb                               = dlsch0->nb_rb;

    dlsch0->harq_processes[harq_pid]->mcs       = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->mcs;
    //dlsch1->harq_processes[harq_pid]->mcs       = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->mcs2;
    dlsch0->harq_processes[harq_pid]->rvidx     = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rv;
    //dlsch1->harq_processes[harq_pid]->rvidx     = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rv2;

    // check if either TB is disabled (see 36-213 V8.6 p. 26) --> only for format 2 and 2A

    //if ((dlsch0->harq_processes[harq_pid]->rvidx == 1) && (dlsch0->harq_processes[harq_pid]->mcs == 0))
    //  dlsch0->harq_processes[harq_pid]->status = DISABLED;

    //if ((dlsch1->harq_processes[harq_pid]->rvidx == 1) && (dlsch1->harq_processes[harq_pid]->mcs == 0))
    // dlsch1->harq_processes[harq_pid]->status = DISABLED;

    dlsch0->harq_processes[harq_pid]->Nl        = 1;

    //dlsch0->layer_index                         = tbswap;
    //dlsch1->layer_index                         = 1-tbswap;

    // Fix this
    tpmi = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->tpmi;

    switch (tpmi) {
    case 0 :
      dlsch0->harq_processes[harq_pid]->mimo_mode   = ALAMOUTI;
      break;
    case 1:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING11;
      dlsch0->pmi_alloc                             = pmi_extend(frame_parms,0);
      break;
    case 2:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1m1;
      dlsch0->pmi_alloc                             = pmi_extend(frame_parms,1);
      break;
    case 3:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1j;
      dlsch0->pmi_alloc                             = pmi_extend(frame_parms,2);
      break;
    case 4:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1mj;
      dlsch0->pmi_alloc                             = pmi_extend(frame_parms,3);
      break;
    case 5:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = PUSCH_PRECODING0;
      dlsch0->pmi_alloc                             = DL_pmi_single;
      break;
    case 6:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = PUSCH_PRECODING1;
      return(-1);
      break;
    }

    //    printf("Set pmi %x (tpmi %d)\n",dlsch0->pmi_alloc,tpmi);


    if (frame_parms->mode1_flag == 1)
      dlsch0->harq_processes[harq_pid]->mimo_mode   = SISO;

1864 1865
    //    dlsch0->harq_processes[harq_pid]->Ndi         = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->ndi;
    if (dlsch0->harq_processes[harq_pid]->round == 0) {
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894
      dlsch0->harq_processes[harq_pid]->status = ACTIVE;
      //      printf("Setting DLSCH process %d to ACTIVE\n",harq_pid);
    }

    dlsch0->harq_processes[harq_pid]->mcs         = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->mcs;
    if (dlsch0->nb_rb > 0) {
      dlsch0->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch0->harq_processes[harq_pid]->mcs)][dlsch0->nb_rb-1];
    }
    else {
      dlsch0->harq_processes[harq_pid]->TBS = 0;
    }

    dlsch0->active = 1;

    dlsch0->rnti = rnti;
    //dlsch1->rnti = rnti;

    //    dlsch0->dl_power_off = 1;
    dlsch0->dl_power_off = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->dl_power_off;
    //dlsch1->dl_power_off = 1;

    break;
  default:
    LOG_E(PHY,"Unknown DCI format\n");
    return(-1);
    break;
  }
#ifdef DEBUG_DCI
  if (dlsch0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1895
    msg("dlsch0 eNB: dlsch0   %p\n",dlsch0);
1896 1897 1898 1899
    msg("dlsch0 eNB: rnti     %x\n",dlsch0->rnti);
    msg("dlsch0 eNB: NBRB     %d\n",dlsch0->nb_rb);
    msg("dlsch0 eNB: rballoc  %x\n",dlsch0->rb_alloc[0]);
    msg("dlsch0 eNB: harq_pid %d\n",harq_pid);
1900
    msg("dlsch0 eNB: round    %d\n",dlsch0->harq_processes[harq_pid]->round);
1901
    msg("dlsch0 eNB: rvidx    %d\n",dlsch0->harq_processes[harq_pid]->rvidx);
1902
    msg("dlsch0 eNB: TBS      %d (NPRB %d)\n",dlsch0->harq_processes[harq_pid]->TBS,NPRB);
1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927
    msg("dlsch0 eNB: mcs      %d\n",dlsch0->harq_processes[harq_pid]->mcs);
    msg("dlsch0 eNB: tpmi %d\n",tpmi);
    msg("dlsch0 eNB: mimo_mode %d\n",dlsch0->harq_processes[harq_pid]->mimo_mode);
  }
#endif

  // compute DL power control parameters   
  computeRhoA_eNB(pdsch_config_dedicated, dlsch[0]);
  
  computeRhoB_eNB(pdsch_config_dedicated,&(frame_parms->pdsch_config_common),frame_parms->nb_antennas_tx_eNB,dlsch[0]);

  return(0);
}


int dump_dci(LTE_DL_FRAME_PARMS *frame_parms, DCI_ALLOC_t *dci) {

  switch (dci->format) {

  case format0:   // This is an UL SCH allocation so nothing here, inform MAC
    if ((frame_parms->frame_type == TDD) &&
	(frame_parms->tdd_config>0))
      switch(frame_parms->N_RB_DL) {
      case 6:
	LOG_D(PHY,"DCI format0 (TDD, 1.5MHz), rnti %x (%x): hopping %d, rb_alloc %x, mcs %d, ndi %d, TPC %d, cshift %d, dai %d, cqi_req %d\n",
1928 1929 1930 1931 1932 1933 1934 1935 1936 1937
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu[0])[0],
	      ((DCI0_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->hopping,
	      ((DCI0_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI0_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI0_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI0_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI0_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->cshift,
	      ((DCI0_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->dai,
	      ((DCI0_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->cqi_req);
1938 1939 1940
	break;
      case 25:
	LOG_D(PHY,"DCI format0 (TDD1-6, 5MHz), rnti %x (%x): hopping %d, rb_alloc %x, mcs %d, ndi %d, TPC %d, cshift %d, dai %d, cqi_req %d\n",
1941 1942 1943 1944 1945 1946 1947 1948 1949 1950
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu[0])[0],
	      ((DCI0_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->hopping,
	      ((DCI0_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI0_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI0_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI0_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI0_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->cshift,
	      ((DCI0_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->dai,
	      ((DCI0_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->cqi_req);
1951 1952 1953
	break;
      case 50:
	LOG_D(PHY,"DCI format0 (TDD1-6, 10MHz), rnti %x (%x): hopping %d, rb_alloc %x, mcs %d, ndi %d, TPC %d, cshift %d, dai %d, cqi_req %d\n",
1954 1955 1956 1957 1958 1959 1960 1961 1962 1963
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu[0])[0],
	      ((DCI0_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->hopping,
	      ((DCI0_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI0_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI0_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI0_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI0_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->cshift,
	      ((DCI0_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->dai,
	      ((DCI0_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->cqi_req);
1964 1965 1966
	break;
      case 100:
	LOG_D(PHY,"DCI format0 (TDD1-6, 20MHz), rnti %x (%x): hopping %d, rb_alloc %x, mcs %d, ndi %d, TPC %d, cshift %d, dai %d, cqi_req %d\n",
1967 1968 1969 1970 1971 1972 1973 1974 1975 1976
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu[0])[0],
	      ((DCI0_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->hopping,
	      ((DCI0_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI0_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI0_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI0_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI0_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->cshift,
	      ((DCI0_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->dai,
	      ((DCI0_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->cqi_req);
1977 1978
	break;
      default:
winckel's avatar
winckel committed
1979 1980
        LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
        DevParam (frame_parms->N_RB_DL, 0, 0);
1981 1982 1983 1984 1985 1986
	break;
      }
    else if (frame_parms->frame_type == FDD)
      switch(frame_parms->N_RB_DL) {
      case 6:
	LOG_D(PHY,"DCI format0 (FDD, 1.5MHz), rnti %x (%x): hopping %d, rb_alloc %x, mcs %d, ndi %d, TPC %d, cshift %d, cqi_req %d\n",
1987 1988 1989 1990 1991 1992 1993 1994 1995
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu[0])[0],
	      ((DCI0_1_5MHz_FDD_t *)&dci->dci_pdu[0])->hopping,
	      ((DCI0_1_5MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI0_1_5MHz_FDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI0_1_5MHz_FDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI0_1_5MHz_FDD_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI0_1_5MHz_FDD_t *)&dci->dci_pdu[0])->cshift,
	      ((DCI0_1_5MHz_FDD_t *)&dci->dci_pdu[0])->cqi_req);
1996 1997 1998
	break;
      case 25:
	LOG_D(PHY,"DCI format0 (FDD, 5MHz), rnti %x (%x): hopping %d, rb_alloc %x, mcs %d, ndi %d, TPC %d, cshift %d, cqi_req %d\n",
1999 2000 2001 2002 2003 2004 2005 2006 2007
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu[0])[0],
	      ((DCI0_5MHz_FDD_t *)&dci->dci_pdu[0])->hopping,
	      ((DCI0_5MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI0_5MHz_FDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI0_5MHz_FDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI0_5MHz_FDD_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI0_5MHz_FDD_t *)&dci->dci_pdu[0])->cshift,
	      ((DCI0_5MHz_FDD_t *)&dci->dci_pdu[0])->cqi_req);
2008 2009 2010
	break;
      case 50:
	LOG_D(PHY,"DCI format0 (FDD, 10MHz), rnti %x (%x): hopping %d, rb_alloc %x, mcs %d, ndi %d, TPC %d, cshift %d, cqi_req %d\n",
2011 2012 2013 2014 2015 2016 2017 2018 2019
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu[0])[0],
	      ((DCI0_10MHz_FDD_t *)&dci->dci_pdu[0])->hopping,
	      ((DCI0_10MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI0_10MHz_FDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI0_10MHz_FDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI0_10MHz_FDD_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI0_10MHz_FDD_t *)&dci->dci_pdu[0])->cshift,
	      ((DCI0_10MHz_FDD_t *)&dci->dci_pdu[0])->cqi_req);
2020 2021 2022
	break;
      case 100:
	LOG_D(PHY,"DCI format0 (FDD, 20MHz), rnti %x (%x): hopping %d, rb_alloc %x, mcs %d, ndi %d, TPC %d, cshift %d, cqi_req %d\n",
2023 2024 2025 2026 2027 2028 2029 2030 2031
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu[0])[0],
	      ((DCI0_20MHz_FDD_t *)&dci->dci_pdu[0])->hopping,
	      ((DCI0_20MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI0_20MHz_FDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI0_20MHz_FDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI0_20MHz_FDD_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI0_20MHz_FDD_t *)&dci->dci_pdu[0])->cshift,
	      ((DCI0_20MHz_FDD_t *)&dci->dci_pdu[0])->cqi_req);
2032 2033
	break;
      default:
winckel's avatar
winckel committed
2034 2035
        LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
        DevParam (frame_parms->N_RB_DL, 0, 0);
2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048
	break;
      }
    else
      LOG_E(PHY,"Don't know how to handle TDD format 0 yet\n");
    break;

  case format1:
    if ((frame_parms->frame_type == TDD) &&
	(frame_parms->tdd_config>0))

      switch(frame_parms->N_RB_DL) {
      case 6:
	LOG_D(PHY,"DCI format1 (TDD 1.5 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d\n",
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu)[0],
	      ((DCI1_1_5MHz_TDD_t *)&dci->dci_pdu[0])->rah,
	      ((DCI1_1_5MHz_TDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI1_1_5MHz_TDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI1_1_5MHz_TDD_t *)&dci->dci_pdu[0])->harq_pid,
	      ((DCI1_1_5MHz_TDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI1_1_5MHz_TDD_t *)&dci->dci_pdu[0])->rv,
	      ((DCI1_1_5MHz_TDD_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI1_1_5MHz_TDD_t *)&dci->dci_pdu[0])->dai);
2059 2060 2061
	break;
      case 25:
	LOG_D(PHY,"DCI format1 (TDD 5 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d\n",
2062 2063 2064 2065 2066 2067 2068 2069 2070 2071
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu)[0],
	      ((DCI1_5MHz_TDD_t *)&dci->dci_pdu[0])->rah,
	      ((DCI1_5MHz_TDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI1_5MHz_TDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI1_5MHz_TDD_t *)&dci->dci_pdu[0])->harq_pid,
	      ((DCI1_5MHz_TDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI1_5MHz_TDD_t *)&dci->dci_pdu[0])->rv,
	      ((DCI1_5MHz_TDD_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI1_5MHz_TDD_t *)&dci->dci_pdu[0])->dai);
2072 2073 2074
	break;
      case 50:
	LOG_D(PHY,"DCI format1 (TDD 10 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d\n",
2075 2076 2077 2078 2079 2080 2081 2082 2083 2084
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu)[0],
	      ((DCI1_10MHz_TDD_t *)&dci->dci_pdu[0])->rah,
	      ((DCI1_10MHz_TDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI1_10MHz_TDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI1_10MHz_TDD_t *)&dci->dci_pdu[0])->harq_pid,
	      ((DCI1_10MHz_TDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI1_10MHz_TDD_t *)&dci->dci_pdu[0])->rv,
	      ((DCI1_10MHz_TDD_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI1_10MHz_TDD_t *)&dci->dci_pdu[0])->dai);
2085 2086 2087
	break;
      case 100:
	LOG_D(PHY,"DCI format1 (TDD 20 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d\n",
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu)[0],
	      ((DCI1_20MHz_TDD_t *)&dci->dci_pdu[0])->rah,
	      ((DCI1_20MHz_TDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI1_20MHz_TDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI1_20MHz_TDD_t *)&dci->dci_pdu[0])->harq_pid,
	      ((DCI1_20MHz_TDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI1_20MHz_TDD_t *)&dci->dci_pdu[0])->rv,
	      ((DCI1_20MHz_TDD_t *)&dci->dci_pdu[0])->TPC,
	      ((DCI1_20MHz_TDD_t *)&dci->dci_pdu[0])->dai);
2098 2099
	break;
      default:
winckel's avatar
winckel committed
2100 2101
        LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
        DevParam (frame_parms->N_RB_DL, 0, 0);
2102 2103 2104 2105 2106 2107
	break;
      }
    else if (frame_parms->frame_type == FDD) {
      switch(frame_parms->N_RB_DL) {
      case 6:
	LOG_D(PHY,"DCI format1 (FDD, 1.5 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d\n",
2108 2109 2110 2111 2112 2113 2114 2115 2116
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu)[0],
	      ((DCI1_1_5MHz_FDD_t *)&dci->dci_pdu[0])->rah,
	      ((DCI1_1_5MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI1_1_5MHz_FDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI1_1_5MHz_FDD_t *)&dci->dci_pdu[0])->harq_pid,
	      ((DCI1_1_5MHz_FDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI1_1_5MHz_FDD_t *)&dci->dci_pdu[0])->rv,
	      ((DCI1_1_5MHz_FDD_t *)&dci->dci_pdu[0])->TPC);
2117 2118 2119
	break;
      case 25:
	LOG_D(PHY,"DCI format1 (FDD, 5 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d\n",
2120 2121 2122 2123 2124 2125 2126 2127 2128
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu)[0],
	      ((DCI1_5MHz_FDD_t *)&dci->dci_pdu[0])->rah,
	      ((DCI1_5MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI1_5MHz_FDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI1_5MHz_FDD_t *)&dci->dci_pdu[0])->harq_pid,
	      ((DCI1_5MHz_FDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI1_5MHz_FDD_t *)&dci->dci_pdu[0])->rv,
	      ((DCI1_5MHz_FDD_t *)&dci->dci_pdu[0])->TPC);
2129 2130 2131
	break;
      case 50:
	LOG_D(PHY,"DCI format1 (FDD, 10 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d\n",
2132 2133 2134 2135 2136 2137 2138 2139 2140
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu)[0],
	      ((DCI1_10MHz_FDD_t *)&dci->dci_pdu[0])->rah,
	      ((DCI1_10MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI1_10MHz_FDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI1_10MHz_FDD_t *)&dci->dci_pdu[0])->harq_pid,
	      ((DCI1_10MHz_FDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI1_10MHz_FDD_t *)&dci->dci_pdu[0])->rv,
	      ((DCI1_10MHz_FDD_t *)&dci->dci_pdu[0])->TPC);
2141 2142 2143
	break;
      case 100:
	LOG_D(PHY,"DCI format1 (FDD, 20 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d\n",
2144 2145 2146 2147 2148 2149 2150 2151 2152
	      dci->rnti,
	      ((uint32_t*)&dci->dci_pdu)[0],
	      ((DCI1_20MHz_FDD_t *)&dci->dci_pdu[0])->rah,
	      ((DCI1_20MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,
	      ((DCI1_20MHz_FDD_t *)&dci->dci_pdu[0])->mcs,
	      ((DCI1_20MHz_FDD_t *)&dci->dci_pdu[0])->harq_pid,
	      ((DCI1_20MHz_FDD_t *)&dci->dci_pdu[0])->ndi,
	      ((DCI1_20MHz_FDD_t *)&dci->dci_pdu[0])->rv,
	      ((DCI1_20MHz_FDD_t *)&dci->dci_pdu[0])->TPC);
2153 2154
	break;
      default:
winckel's avatar
winckel committed
2155 2156
        LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
        DevParam (frame_parms->N_RB_DL, 0, 0);
2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212
	break;
      }
    }

    else 
      LOG_E(PHY,"Don't know how to handle TDD format 0 yet\n");
    break;
  case format1A:  // This is DLSCH allocation for control traffic
    if ((frame_parms->frame_type == TDD) &&
	(frame_parms->tdd_config>0)) {
      switch (frame_parms->N_RB_DL) {
      case 6:
	msg("DCI format1A (TDD1-6, 1_5MHz), rnti %x (%x)\n",dci->rnti,((uint32_t*)&dci->dci_pdu[0])[0]);
	msg("VRB_TYPE %d\n",((DCI1A_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->vrb_type);
	msg("RB_ALLOC %x (NB_RB %d)\n",((DCI1A_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc,RIV2nb_rb_LUT25[((DCI1A_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc]);
	msg("MCS %d\n",((DCI1A_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->mcs);
	msg("HARQ_PID %d\n",((DCI1A_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->harq_pid);
	msg("NDI %d\n",((DCI1A_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->ndi);
	msg("RV %d\n",((DCI1A_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rv);
	msg("TPC %d\n",((DCI1A_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->TPC);
	msg("DAI %d\n",((DCI1A_1_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->dai);
	break;
      case 25:
	msg("DCI format1A (TDD1-6, 5MHz), rnti %x (%x)\n",dci->rnti,((uint32_t*)&dci->dci_pdu[0])[0]);
	msg("VRB_TYPE %d\n",((DCI1A_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->vrb_type);
	msg("RB_ALLOC %d (NB_RB %d)\n",((DCI1A_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc,RIV2nb_rb_LUT25[((DCI1A_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc]);
	msg("MCS %d\n",((DCI1A_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->mcs);
	msg("HARQ_PID %d\n",((DCI1A_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->harq_pid);
	msg("NDI %d\n",((DCI1A_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->ndi);
	msg("RV %d\n",((DCI1A_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rv);
	msg("TPC %d\n",((DCI1A_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->TPC);
	msg("DAI %d\n",((DCI1A_5MHz_TDD_1_6_t *)&dci->dci_pdu[0])->dai);
	break;
      case 50:
	msg("DCI format1A (TDD1-6, 10MHz), rnti %x (%x)\n",dci->rnti,((uint32_t*)&dci->dci_pdu[0])[0]);
	msg("VRB_TYPE %d\n",((DCI1A_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->vrb_type);
	msg("RB_ALLOC %x (NB_RB %d)\n",((DCI1A_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc,RIV2nb_rb_LUT25[((DCI1A_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc]);
	msg("MCS %d\n",((DCI1A_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->mcs);
	msg("HARQ_PID %d\n",((DCI1A_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->harq_pid);
	msg("NDI %d\n",((DCI1A_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->ndi);
	msg("RV %d\n",((DCI1A_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rv);
	msg("TPC %d\n",((DCI1A_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->TPC);
	msg("DAI %d\n",((DCI1A_10MHz_TDD_1_6_t *)&dci->dci_pdu[0])->dai);
	break;
      case 100:
	msg("DCI format1A (TDD1-6, 20MHz), rnti %x (%x)\n",dci->rnti,((uint32_t*)&dci->dci_pdu[0])[0]);
	msg("VRB_TYPE %d\n",((DCI1A_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->vrb_type);
	msg("RB_ALLOC %x (NB_RB %d)\n",((DCI1A_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc,RIV2nb_rb_LUT25[((DCI1A_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rballoc]);
	msg("MCS %d\n",((DCI1A_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->mcs);
	msg("HARQ_PID %d\n",((DCI1A_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->harq_pid);
	msg("NDI %d\n",((DCI1A_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->ndi);
	msg("RV %d\n",((DCI1A_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->rv);
	msg("TPC %d\n",((DCI1A_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->TPC);
	msg("DAI %d\n",((DCI1A_20MHz_TDD_1_6_t *)&dci->dci_pdu[0])->dai);
	break;
      default:
winckel's avatar
winckel committed
2213 2214
        LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
        DevParam (frame_parms->N_RB_DL, 0, 0);
2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261
	break;
      }
	
    }
    else if (frame_parms->frame_type == FDD) {
      switch (frame_parms->N_RB_DL) {
      case 6:
	msg("DCI format1A(FDD, 1.5MHz), rnti %x (%x)\n",dci->rnti,((uint32_t*)&dci->dci_pdu[0])[0]);
	msg("VRB_TYPE %d\n",((DCI1A_1_5MHz_FDD_t *)&dci->dci_pdu[0])->vrb_type);
	msg("RB_ALLOC %x (NB_RB %d)\n",((DCI1A_1_5MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,RIV2nb_rb_LUT25[((DCI1A_1_5MHz_FDD_t *)&dci->dci_pdu[0])->rballoc]);
	msg("MCS %d\n",((DCI1A_1_5MHz_FDD_t *)&dci->dci_pdu[0])->mcs);
	msg("HARQ_PID %d\n",((DCI1A_1_5MHz_FDD_t *)&dci->dci_pdu[0])->harq_pid);
	msg("NDI %d\n",((DCI1A_1_5MHz_FDD_t *)&dci->dci_pdu[0])->ndi);
	msg("RV %d\n",((DCI1A_1_5MHz_FDD_t *)&dci->dci_pdu[0])->rv);
	msg("TPC %d\n",((DCI1A_1_5MHz_FDD_t *)&dci->dci_pdu[0])->TPC);
	break;
      case 25:
	msg("DCI format1A(FDD, 5MHz), rnti %x (%x)\n",dci->rnti,((uint32_t*)&dci->dci_pdu[0])[0]);
	msg("VRB_TYPE %d\n",((DCI1A_5MHz_FDD_t *)&dci->dci_pdu[0])->vrb_type);
	msg("RB_ALLOC %x (NB_RB %d)\n",((DCI1A_5MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,RIV2nb_rb_LUT25[((DCI1A_5MHz_FDD_t *)&dci->dci_pdu[0])->rballoc]);
	msg("MCS %d\n",((DCI1A_5MHz_FDD_t *)&dci->dci_pdu[0])->mcs);
	msg("HARQ_PID %d\n",((DCI1A_5MHz_FDD_t *)&dci->dci_pdu[0])->harq_pid);
	msg("NDI %d\n",((DCI1A_5MHz_FDD_t *)&dci->dci_pdu[0])->ndi);
	msg("RV %d\n",((DCI1A_5MHz_FDD_t *)&dci->dci_pdu[0])->rv);
	msg("TPC %d\n",((DCI1A_5MHz_FDD_t *)&dci->dci_pdu[0])->TPC);
	break;
      case 50:
	msg("DCI format1A(FDD, 10MHz), rnti %x (%x)\n",dci->rnti,((uint32_t*)&dci->dci_pdu[0])[0]);
	msg("VRB_TYPE %d\n",((DCI1A_10MHz_FDD_t *)&dci->dci_pdu[0])->vrb_type);
	msg("RB_ALLOC %x (NB_RB %d)\n",((DCI1A_10MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,RIV2nb_rb_LUT25[((DCI1A_10MHz_FDD_t *)&dci->dci_pdu[0])->rballoc]);
	msg("MCS %d\n",((DCI1A_10MHz_FDD_t *)&dci->dci_pdu[0])->mcs);
	msg("HARQ_PID %d\n",((DCI1A_10MHz_FDD_t *)&dci->dci_pdu[0])->harq_pid);
	msg("NDI %d\n",((DCI1A_10MHz_FDD_t *)&dci->dci_pdu[0])->ndi);
	msg("RV %d\n",((DCI1A_10MHz_FDD_t *)&dci->dci_pdu[0])->rv);
	msg("TPC %d\n",((DCI1A_10MHz_FDD_t *)&dci->dci_pdu[0])->TPC);
	break;
      case 100:
	msg("DCI format1A(FDD, 20MHz), rnti %x (%x)\n",dci->rnti,((uint32_t*)&dci->dci_pdu[0])[0]);
	msg("VRB_TYPE %d\n",((DCI1A_20MHz_FDD_t *)&dci->dci_pdu[0])->vrb_type);
	msg("RB_ALLOC %x (NB_RB %d)\n",((DCI1A_20MHz_FDD_t *)&dci->dci_pdu[0])->rballoc,RIV2nb_rb_LUT25[((DCI1A_20MHz_FDD_t *)&dci->dci_pdu[0])->rballoc]);
	msg("MCS %d\n",((DCI1A_20MHz_FDD_t *)&dci->dci_pdu[0])->mcs);
	msg("HARQ_PID %d\n",((DCI1A_20MHz_FDD_t *)&dci->dci_pdu[0])->harq_pid);
	msg("NDI %d\n",((DCI1A_20MHz_FDD_t *)&dci->dci_pdu[0])->ndi);
	msg("RV %d\n",((DCI1A_20MHz_FDD_t *)&dci->dci_pdu[0])->rv);
	msg("TPC %d\n",((DCI1A_20MHz_FDD_t *)&dci->dci_pdu[0])->TPC);
	break;
      default:
winckel's avatar
winckel committed
2262 2263
        LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
        DevParam (frame_parms->N_RB_DL, 0, 0);
2264 2265 2266 2267
	break;
      }
    }
    break;
Raymond Knopp's avatar
 
Raymond Knopp committed
2268
  case format2:
2269

Raymond Knopp's avatar
 
Raymond Knopp committed
2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585
    if ((frame_parms->frame_type == TDD) &&
	(frame_parms->tdd_config>0)) {
      if (frame_parms->nb_antennas_tx == 2) {
	switch(frame_parms->N_RB_DL) {
	case 6:
	  LOG_D(PHY,"DCI format2 2 antennas (TDD 1.5 MHz), rnti %x (%x): rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d, tbswap %d, tpmi %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->TPC,
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->dai,
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_1_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->tpmi
		);
	  break;
	case 25:
	  LOG_D(PHY,"DCI format2 2 antennas (TDD 5 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d, tb_swap %d, tpmi %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->TPC,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->dai,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_5MHz_2A_TDD_t *)&dci->dci_pdu[0])->tpmi);
	  break;
	case 50:
	  LOG_D(PHY,"DCI format2 2 antennas (TDD 10 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->TPC,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->dai,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_10MHz_2A_TDD_t *)&dci->dci_pdu[0])->tpmi);
	  break;
	case 100:
	  LOG_D(PHY,"DCI format2 2 antennas (TDD 20 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d, tb_swap %d, tpmi %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->TPC,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->dai,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_20MHz_2A_TDD_t *)&dci->dci_pdu[0])->tpmi);
	  break;
	default:
	  LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
	  DevParam (frame_parms->N_RB_DL, 0, 0);
	  break;
	}
      }
      else if (frame_parms->nb_antennas_tx == 4) {
	switch(frame_parms->N_RB_DL) {
	case 6:
	  LOG_D(PHY,"DCI format2 2 antennas (TDD 1.5 MHz), rnti %x (%x): rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d, tbswap %d, tpmi %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->TPC,
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->dai,
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_1_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->tpmi
		);
	  break;
	case 25:
	  LOG_D(PHY,"DCI format2 2 antennas (TDD 5 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d, tb_swap %d, tpmi %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->TPC,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->dai,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_5MHz_4A_TDD_t *)&dci->dci_pdu[0])->tpmi);
	  break;
	case 50:
	  LOG_D(PHY,"DCI format2 2 antennas (TDD 10 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->TPC,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->dai,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_10MHz_4A_TDD_t *)&dci->dci_pdu[0])->tpmi);
	  break;
	case 100:
	  LOG_D(PHY,"DCI format2 2 antennas (TDD 20 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d, dai %d, tb_swap %d, tpmi %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->TPC,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->dai,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_20MHz_4A_TDD_t *)&dci->dci_pdu[0])->tpmi);
	  break;
	default:
	  LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
	  DevParam (frame_parms->N_RB_DL, 0, 0);
	  break;
	}
      }
    }
    else if (frame_parms->frame_type == FDD) {
      if (frame_parms->nb_antennas_tx == 2) {
	switch(frame_parms->N_RB_DL) {
	case 6:
	  LOG_D(PHY,"DCI format2 2 antennas (FDD, 1.5 MHz), rnti %x (%x):  rb_alloc %x, mcs1 %d, mcs2 %d, harq_pid %d, ndi1 %d, ndi2 %d, RV1 %d, RV2 %d, tb_swap %d, tpmi %d, TPC %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_1_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_1_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_1_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_1_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_1_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_1_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_1_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_1_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_1_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_1_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->tpmi,
		((DCI2_1_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->TPC);
	  break;
	case 25:
	  LOG_D(PHY,"DCI format2 2 antennas (FDD, 5 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->tpmi,
		((DCI2_5MHz_2A_FDD_t *)&dci->dci_pdu[0])->TPC);
	  break;
	case 50:
	  LOG_D(PHY,"DCI format2 2 antennas (FDD, 10 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->tpmi,
		((DCI2_10MHz_2A_FDD_t *)&dci->dci_pdu[0])->TPC);
	  break;
	case 100:
	  LOG_D(PHY,"DCI format2 2 antennas (FDD, 20 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->tpmi,
		((DCI2_20MHz_2A_FDD_t *)&dci->dci_pdu[0])->TPC);
	  break;
	default:
	  LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
	  DevParam (frame_parms->N_RB_DL, 0, 0);
	  break;
	}
      }
      else if (frame_parms->nb_antennas_tx == 4) {
	switch(frame_parms->N_RB_DL) {
	  
	case 6:
	  LOG_D(PHY,"DCI format2 4 antennas (FDD, 1.5 MHz), rnti %x (%x): rb_alloc %x, mcs1 %d, mcs2 %d, harq_pid %d, ndi1 %d, ndi2 %d, RV1 %d, RV2 %d, tb_swap %d, tpmi %d, TPC %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_1_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_1_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_1_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_1_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_1_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_1_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_1_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_1_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_1_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_1_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->tpmi,
		((DCI2_1_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->TPC);
	  break;
	case 25:
	  LOG_D(PHY,"DCI format2 4 antennas (FDD, 5 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->tpmi,
		((DCI2_5MHz_4A_FDD_t *)&dci->dci_pdu[0])->TPC);
	  break;
	case 50:
	  LOG_D(PHY,"DCI format2 4 antennas (FDD, 10 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->tpmi,
		((DCI2_10MHz_4A_FDD_t *)&dci->dci_pdu[0])->TPC);
	  break;
	case 100:
	  LOG_D(PHY,"DCI format2 4 antennas (FDD, 20 MHz), rnti %x (%x): rah %d, rb_alloc %x, mcs %d, harq_pid %d, ndi %d, RV %d, TPC %d\n",
		dci->rnti,
		((uint32_t*)&dci->dci_pdu)[0],
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->rah,
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->rballoc,
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->mcs1,
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->mcs2,
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->harq_pid,
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->ndi1,
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->ndi2,
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->rv1,
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->rv2,
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->tb_swap,
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->tpmi,
		((DCI2_20MHz_4A_FDD_t *)&dci->dci_pdu[0])->TPC);
	  break;
	default:
	  LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
	  DevParam (frame_parms->N_RB_DL, 0, 0);
	  break;
	}
      }
    }
2586

Raymond Knopp's avatar
 
Raymond Knopp committed
2587 2588
    else 
      LOG_E(PHY,"Don't know how to handle TDD format 0 yet\n");
2589
    break;
Raymond Knopp's avatar
 
Raymond Knopp committed
2590

2591 2592
  case format1E_2A_M10PRB:

2593
    LOG_D(PHY,"DCI format1E_2A_M10PRB, rnti %x (%8x): harq_pid %d, rah %d, rb_alloc %x, mcs %d, rv %d, tpmi %d, ndi %d, dl_power_offset %d\n",
2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626
	dci->rnti,
	((uint32_t *)&dci->dci_pdu)[0],
	((DCI1E_5MHz_2A_M10PRB_TDD_t *)&dci->dci_pdu[0])->harq_pid,
	//((DCI1E_5MHz_2A_M10PRB_TDD_t *)&dci->dci_pdu[0])->tb_swap,
	((DCI1E_5MHz_2A_M10PRB_TDD_t *)&dci->dci_pdu[0])->rah,
	((DCI1E_5MHz_2A_M10PRB_TDD_t *)&dci->dci_pdu[0])->rballoc,
	((DCI1E_5MHz_2A_M10PRB_TDD_t *)&dci->dci_pdu[0])->mcs,
	((DCI1E_5MHz_2A_M10PRB_TDD_t *)&dci->dci_pdu[0])->rv,
	((DCI1E_5MHz_2A_M10PRB_TDD_t *)&dci->dci_pdu[0])->tpmi,
	((DCI1E_5MHz_2A_M10PRB_TDD_t *)&dci->dci_pdu[0])->ndi,
	((DCI1E_5MHz_2A_M10PRB_TDD_t *)&dci->dci_pdu[0])->dl_power_off
	);

    break;
  default:
    LOG_E(PHY,"dci_tools.c: dump_dci, unknown format %d\n",dci->format);
    return(-1);
  }
  return(0);
}


int generate_ue_dlsch_params_from_dci(uint8_t subframe,
                                      void *dci_pdu,
                                      uint16_t rnti,
                                      DCI_format_t dci_format,
                                      LTE_UE_DLSCH_t **dlsch,
                                      LTE_DL_FRAME_PARMS *frame_parms,
                                      PDSCH_CONFIG_DEDICATED *pdsch_config_dedicated,
                                      uint16_t si_rnti,
                                      uint16_t ra_rnti,
                                      uint16_t p_rnti) {

2627 2628 2629 2630
  uint8_t harq_pid=0;
  uint32_t rballoc=0,RIV_max;
  uint8_t frame_type=frame_parms->frame_type;
  uint8_t vrb_type=0;
Raymond Knopp's avatar
 
Raymond Knopp committed
2631 2632 2633
  uint8_t mcs=0,mcs1=0,mcs2=0;
  uint8_t rv=0,rv1=0,rv2=0;
  uint8_t ndi=0,ndi1=0,ndi2=0;
2634 2635 2636 2637
  uint8_t rah=0;
  uint8_t TPC=0;
  uint8_t NPRB=0,tbswap=0,tpmi=0;
  LTE_UE_DLSCH_t *dlsch0=NULL,*dlsch1=NULL;
2638 2639

#ifdef DEBUG_DCI
2640
  msg("dci_tools.c: Filling ue dlsch params -> rnti %x, dci_format %d\n",rnti,dci_format);
2641 2642
#endif

2643
  switch (dci_format) {
2644

2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679
  case format0:   // This is an UL SACH allocation so nothing here, inform MAC
    LOG_E(PHY,"format0 not possible\n");
    return(-1);
    break;
  case format1A:

    switch (frame_parms->N_RB_DL) {
    case 6:
      if (frame_type == TDD) {
	vrb_type = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->rv;
	ndi      = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->ndi;
	TPC      = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->harq_pid;
	//	printf("TDD 1A: mcs %d, rballoc %x,rv %d, TPC %d\n",mcs,rballoc,rv,TPC);
      }
      else {
	vrb_type = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->rv;
	ndi      = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->ndi;
	TPC      = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->TPC; 
	harq_pid  = ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->harq_pid;
	//printf("FDD 1A: mcs %d, rballoc %x,rv %d, TPC %d\n",mcs,rballoc,rv,TPC);
      }

      if ((rnti==si_rnti) || (rnti==p_rnti) || (rnti==ra_rnti)){  //
	harq_pid = 0;
	// see 36-212 V8.6.0 p. 45
	NPRB = (TPC&1) + 2;
      }
      else {
2680
                
2681 2682 2683 2684
	if (harq_pid>1) {
	  LOG_E(PHY,"Format 1A: harq_pid > 1\n");
	  return(-1);
	}
2685
                
2686 2687 2688
	NPRB = RIV2nb_rb_LUT6[rballoc];            
	dlsch[0]->harq_processes[harq_pid]->delta_PUCCH = delta_PUCCH_lut[TPC&3];      
      }
2689
            
2690 2691 2692 2693
      if (vrb_type == 0)
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[0] = localRIV2alloc_LUT6[rballoc];
      else
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[0] = distRIV2alloc_LUT6[rballoc];
2694
            
2695 2696
      dlsch[0]->harq_processes[harq_pid]->nb_rb = RIV2nb_rb_LUT6[rballoc];//NPRB;
      RIV_max = RIV_max6;
2697
            
2698 2699
      break;
    case 25:
2700
            
2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727
      if (frame_type == TDD) {
	vrb_type = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->rv;
	ndi      = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->ndi;
	TPC      = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->harq_pid;
	//printf("TDD 1A: mcs %d, rballoc %x,rv %d, TPC %d\n",mcs,rballoc,rv,TPC);
      }
      else {
	vrb_type = ((DCI1A_5MHz_FDD_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_5MHz_FDD_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_5MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_5MHz_FDD_t *)dci_pdu)->rv;
	ndi      = ((DCI1A_5MHz_FDD_t *)dci_pdu)->ndi;
	TPC      = ((DCI1A_5MHz_FDD_t *)dci_pdu)->TPC; 
	harq_pid  = ((DCI1A_5MHz_FDD_t *)dci_pdu)->harq_pid;
	//printf("FDD 1A: mcs %d, rballoc %x,rv %d, TPC %d\n",mcs,rballoc,rv,TPC);
      }

      if ((rnti==si_rnti) || (rnti==p_rnti) || (rnti==ra_rnti)){  //
	harq_pid = 0;
	// see 36-212 V8.6.0 p. 45
	NPRB = (TPC&1) + 2;
      }
      else {
2728
                
2729 2730 2731 2732
	if (harq_pid>1) {
	  LOG_E(PHY,"Format 1A: harq_pid > 1\n");
	  return(-1);
	}
2733
                
2734 2735 2736 2737 2738 2739 2740 2741
	NPRB = RIV2nb_rb_LUT25[rballoc];            
	dlsch[0]->harq_processes[harq_pid]->delta_PUCCH = delta_PUCCH_lut[TPC&3];      
      }

      if (vrb_type == 0)
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[0] = localRIV2alloc_LUT25[rballoc];
      else
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[0] = distRIV2alloc_LUT25[rballoc];
2742
            
2743 2744
      dlsch[0]->harq_processes[harq_pid]->nb_rb = RIV2nb_rb_LUT25[rballoc];//NPRB;
      RIV_max = RIV_max25;    
2745
            
2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767
      break;
    case 50:
      if (frame_type == TDD) {
	vrb_type = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->rv;
	ndi      = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->ndi;
	TPC      = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->harq_pid;
	//	printf("TDD 1A: mcs %d, rballoc %x,rv %d, TPC %d\n",mcs,rballoc,rv,TPC);
      }
      else {
	vrb_type = ((DCI1A_10MHz_FDD_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_10MHz_FDD_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_10MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_10MHz_FDD_t *)dci_pdu)->rv;
	ndi      = ((DCI1A_10MHz_FDD_t *)dci_pdu)->ndi;
	TPC      = ((DCI1A_10MHz_FDD_t *)dci_pdu)->TPC; 
	harq_pid  = ((DCI1A_10MHz_FDD_t *)dci_pdu)->harq_pid;
	//printf("FDD 1A: mcs %d, rballoc %x,rv %d, TPC %d\n",mcs,rballoc,rv,TPC);
      }
2768
            
2769 2770 2771 2772 2773 2774
      if ((rnti==si_rnti) || (rnti==p_rnti) || (rnti==ra_rnti)){  //
	harq_pid = 0;
	// see 36-212 V8.6.0 p. 45
	NPRB = (TPC&1) + 2;
      }
      else {
2775
                
2776 2777 2778 2779
	if (harq_pid>1) {
	  LOG_E(PHY,"Format 1A: harq_pid > 1\n");
	  return(-1);
	}
2780
                
2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824
	NPRB = RIV2nb_rb_LUT50[rballoc];            
	dlsch[0]->harq_processes[harq_pid]->delta_PUCCH = delta_PUCCH_lut[TPC&3];      
      }

      if (vrb_type == 0) {
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[0] = localRIV2alloc_LUT50_0[rballoc];
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[1] = localRIV2alloc_LUT50_1[rballoc];
      }
      else {
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[0] = distRIV2alloc_LUT50_0[rballoc];
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[1] = distRIV2alloc_LUT50_1[rballoc];
      }
      dlsch[0]->harq_processes[harq_pid]->nb_rb  = RIV2nb_rb_LUT50[rballoc];//NPRB;
      RIV_max = RIV_max50;
      break;
    case 100:
      if (frame_type == TDD) {
	vrb_type = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->rv;
	ndi      = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->ndi;
	TPC      = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->harq_pid;
	//	printf("TDD 1A: mcs %d, rballoc %x,rv %d, TPC %d\n",mcs,rballoc,rv,TPC);
      }
      else {
	vrb_type = ((DCI1A_20MHz_FDD_t *)dci_pdu)->vrb_type;
	mcs      = ((DCI1A_20MHz_FDD_t *)dci_pdu)->mcs;
	rballoc  = ((DCI1A_20MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1A_20MHz_FDD_t *)dci_pdu)->rv;
	ndi      = ((DCI1A_20MHz_FDD_t *)dci_pdu)->ndi;
	TPC      = ((DCI1A_20MHz_FDD_t *)dci_pdu)->TPC; 
	harq_pid = ((DCI1A_20MHz_FDD_t *)dci_pdu)->harq_pid;
	//printf("FDD 1A: mcs %d, rballoc %x,rv %d, TPC %d\n",mcs,rballoc,rv,TPC);
      }

      if ((rnti==si_rnti) || (rnti==p_rnti) || (rnti==ra_rnti)){  //
	harq_pid = 0;
	// see 36-212 V8.6.0 p. 45
	NPRB = (TPC&1) + 2;
	// toggle the ndi 
      }
      else {
2825
                
2826 2827 2828 2829
	if (harq_pid>1) {
	  LOG_E(PHY,"Format 1A: harq_pid > 1\n");
	  return(-1);
	}
2830
                
2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850
	NPRB = RIV2nb_rb_LUT100[rballoc];            
	dlsch[0]->harq_processes[harq_pid]->delta_PUCCH = delta_PUCCH_lut[TPC&3];      
      }

      if (vrb_type == 0) {
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[0] = localRIV2alloc_LUT100_0[rballoc];
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[1] = localRIV2alloc_LUT100_1[rballoc];
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[2] = localRIV2alloc_LUT100_2[rballoc];
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[3] = localRIV2alloc_LUT100_3[rballoc];
      }
      else {
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[0] = distRIV2alloc_LUT100_0[rballoc];
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[1] = distRIV2alloc_LUT100_1[rballoc];
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[2] = distRIV2alloc_LUT100_2[rballoc];
	dlsch[0]->harq_processes[harq_pid]->rb_alloc[3] = distRIV2alloc_LUT100_3[rballoc];
      }
      dlsch[0]->harq_processes[harq_pid]->nb_rb = RIV2nb_rb_LUT100[rballoc];//NPRB;
      RIV_max = RIV_max100;
      break;
    }
2851
        
2852 2853 2854 2855
    if (rballoc>RIV_max) {
      LOG_E(PHY,"Format 1A: rb_alloc > RIV_max\n");
      return(-1);
    }
2856
            
2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879
    if (NPRB==0) {
      LOG_E(PHY,"Format 1A: NPRB=0\n");
      return(-1);
    }
    // change the mcs limit from 7 to 8, supported by MAC
    if (mcs > 8) {
      LOG_E(PHY,"Format 1A: unlikely mcs for format 1A (%d)\n",mcs);
      return(-1);
    } 

    if ((rnti==si_rnti) || (rnti==p_rnti) || (rnti==ra_rnti)){  //
      // toggle the ndi, always toggled for si,p and ra 
      ndi  = 1-dlsch[0]->harq_processes[harq_pid]->DCINdi;
    }

    dlsch[0]->current_harq_pid = harq_pid;
    //    msg("Format 1A: harq_pid %d\n",harq_pid);        
    dlsch[0]->harq_processes[harq_pid]->rvidx = rv;        
    dlsch[0]->harq_processes[harq_pid]->Nl = 1;
    dlsch[0]->layer_index = 0;
    dlsch[0]->harq_processes[harq_pid]->mimo_mode = frame_parms->mode1_flag == 1 ?SISO : ALAMOUTI;
    dlsch[0]->harq_processes[harq_pid]->dl_power_off = 1; //no power offset

Raymond Knopp's avatar
 
Raymond Knopp committed
2880 2881 2882
    LOG_D(PHY,"UE (%x/%d): Subframe %d Format1A DCI: ndi %d, old_ndi %d (first tx %d) harq_status %d\n",dlsch[0]->rnti,harq_pid,subframe,ndi,dlsch[0]->harq_processes[harq_pid]->DCINdi,
	  dlsch[0]->harq_processes[harq_pid]->first_tx,dlsch[0]->harq_processes[harq_pid]->status);

2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896
    if ((ndi!=dlsch[0]->harq_processes[harq_pid]->DCINdi)||  // DCI has been toggled or this is the first transmission
	(dlsch[0]->harq_processes[harq_pid]->first_tx==1)) {
      dlsch[0]->harq_processes[harq_pid]->round = 0;
      if (dlsch[0]->harq_processes[harq_pid]->first_tx==1)
	LOG_D(PHY,"[PDSCH %x/%d] Format 1A DCI First TX: Clearing flag\n");
      dlsch[0]->harq_processes[harq_pid]->first_tx = 0;
    }
    dlsch[0]->harq_processes[harq_pid]->DCINdi = ndi;

    dlsch[0]->harq_processes[harq_pid]->mcs = mcs;        
    dlsch[0]->harq_processes[harq_pid]->TBS = TBStable[get_I_TBS(mcs)][NPRB-1];        
    dlsch[0]->rnti = rnti;        
    dlsch0 = dlsch[0];
    break;
2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983

  case format1:

    switch (frame_parms->N_RB_DL) {
    case 6:
      if (frame_type == TDD) {
	mcs       = ((DCI1_1_5MHz_TDD_t *)dci_pdu)->mcs;
	rballoc   = ((DCI1_1_5MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI1_1_5MHz_TDD_t *)dci_pdu)->rah;
	rv        = ((DCI1_1_5MHz_TDD_t *)dci_pdu)->rv;
	ndi       = ((DCI1_1_5MHz_TDD_t *)dci_pdu)->ndi;
	harq_pid  = ((DCI1_1_5MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs      = ((DCI1_1_5MHz_FDD_t *)dci_pdu)->mcs;
	rah      = ((DCI1_1_5MHz_FDD_t *)dci_pdu)->rah;
	rballoc  = ((DCI1_1_5MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1_1_5MHz_FDD_t *)dci_pdu)->rv;
	ndi      = ((DCI1_1_5MHz_FDD_t *)dci_pdu)->ndi;
	harq_pid = ((DCI1_1_5MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;
    case 25:
      if (frame_type == TDD) {
	mcs       = ((DCI1_5MHz_TDD_t *)dci_pdu)->mcs;
	rballoc   = ((DCI1_5MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI1_5MHz_TDD_t *)dci_pdu)->rah;
	rv        = ((DCI1_5MHz_TDD_t *)dci_pdu)->rv;
	ndi       = ((DCI1_5MHz_TDD_t *)dci_pdu)->ndi;
	harq_pid  = ((DCI1_5MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs      = ((DCI1_5MHz_FDD_t *)dci_pdu)->mcs;
	rah      = ((DCI1_5MHz_FDD_t *)dci_pdu)->rah;
	rballoc  = ((DCI1_5MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1_5MHz_FDD_t *)dci_pdu)->rv;
	ndi      = ((DCI1_5MHz_FDD_t *)dci_pdu)->ndi;
	harq_pid = ((DCI1_5MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;
    case 50:
      if (frame_type == TDD) {
	mcs       = ((DCI1_10MHz_TDD_t *)dci_pdu)->mcs;
	rballoc   = ((DCI1_10MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI1_10MHz_TDD_t *)dci_pdu)->rah;
	rv        = ((DCI1_10MHz_TDD_t *)dci_pdu)->rv;
	ndi       = ((DCI1_10MHz_TDD_t *)dci_pdu)->ndi;
	harq_pid  = ((DCI1_10MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs      = ((DCI1_10MHz_FDD_t *)dci_pdu)->mcs;
	rah      = ((DCI1_10MHz_FDD_t *)dci_pdu)->rah;
	rballoc  = ((DCI1_10MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1_10MHz_FDD_t *)dci_pdu)->rv;
	ndi      = ((DCI1_10MHz_FDD_t *)dci_pdu)->ndi;
	harq_pid = ((DCI1_10MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;
    case 100:
      if (frame_type == TDD) {
	mcs       = ((DCI1_20MHz_TDD_t *)dci_pdu)->mcs;
	rballoc   = ((DCI1_20MHz_TDD_t *)dci_pdu)->rballoc;
	rah       = ((DCI1_20MHz_TDD_t *)dci_pdu)->rah;
	rv        = ((DCI1_20MHz_TDD_t *)dci_pdu)->rv;
	ndi       = ((DCI1_20MHz_TDD_t *)dci_pdu)->ndi;
	harq_pid  = ((DCI1_20MHz_TDD_t *)dci_pdu)->harq_pid;
      }
      else {
	mcs      = ((DCI1_20MHz_FDD_t *)dci_pdu)->mcs;
	rah      = ((DCI1_20MHz_FDD_t *)dci_pdu)->rah;
	rballoc  = ((DCI1_20MHz_FDD_t *)dci_pdu)->rballoc;
	rv       = ((DCI1_20MHz_FDD_t *)dci_pdu)->rv;
	ndi      = ((DCI1_20MHz_FDD_t *)dci_pdu)->ndi;
	harq_pid = ((DCI1_20MHz_FDD_t *)dci_pdu)->harq_pid;
      }
      break;
    }
    if (harq_pid>=8) {
      LOG_E(PHY,"Format 1: harq_pid >= 8\n");
      return(-1);
    }
    dlsch[0]->current_harq_pid = harq_pid;
    dlsch[0]->harq_ack[subframe].harq_id = harq_pid;

    conv_rballoc(rah,rballoc,frame_parms->N_RB_DL,dlsch[0]->harq_processes[harq_pid]->rb_alloc);

    dlsch[0]->harq_processes[harq_pid]->nb_rb = conv_nprb(rah,
2984 2985
							  rballoc,
							  frame_parms->N_RB_DL);
2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005

    NPRB = dlsch[0]->harq_processes[harq_pid]->nb_rb;

    //    printf("test PDSCH NPRB %d, rah %d, rballoc %x, rballoc2 %x\n",NPRB,rah,rballoc,dlsch[0]->harq_processes[harq_pid]->rb_alloc[0]);

    if (NPRB==0) {
      LOG_E(PHY,"Format 1: NPRB=0 (rballoc %x,mcs %d, frame_type %d N_RB_DL %d)\n",rballoc,mcs,frame_parms->frame_type,frame_parms->N_RB_DL);
      return(-1);
    }

    //    printf("NPRB %d\n",NPRB);
    dlsch[0]->harq_processes[harq_pid]->delta_PUCCH     = delta_PUCCH_lut[TPC&3];      

    dlsch[0]->harq_processes[harq_pid]->rvidx     = rv;

    dlsch[0]->harq_processes[harq_pid]->Nl          = 1;
    dlsch[0]->layer_index = 0;
    dlsch[0]->harq_processes[harq_pid]->mimo_mode   = (frame_parms->mode1_flag == 1) ? SISO : ALAMOUTI;
    dlsch[0]->harq_processes[harq_pid]->dl_power_off = 1; //no power offset

Raymond Knopp's avatar
 
Raymond Knopp committed
3006 3007
    LOG_D(PHY,"UE (%x/%d): Subframe %d Format1 DCI: ndi %d, old_ndi %d (first tx %d) harq_status %d\n",dlsch[0]->rnti,harq_pid,subframe,ndi,dlsch[0]->harq_processes[harq_pid]->DCINdi,
	  dlsch[0]->harq_processes[harq_pid]->first_tx,dlsch[0]->harq_processes[harq_pid]->status);
3008

Raymond Knopp's avatar
 
Raymond Knopp committed
3009 3010
    //    printf("Format1 DCI (UE, hard pid %d): ndi %d, old_ndi %d (first tx %d)\n",harq_pid,ndi,dlsch[0]->harq_processes[harq_pid]->DCINdi,
    //	  dlsch[0]->harq_processes[harq_pid]->first_tx);
3011 3012 3013 3014
    
    if ((ndi!=dlsch[0]->harq_processes[harq_pid]->DCINdi)||
	(dlsch[0]->harq_processes[harq_pid]->first_tx==1)) {
      dlsch[0]->harq_processes[harq_pid]->round=0;
3015
      dlsch[0]->harq_processes[harq_pid]->status = ACTIVE;
3016 3017 3018 3019
      dlsch[0]->harq_processes[harq_pid]->DCINdi = ndi;
      if (dlsch[0]->harq_processes[harq_pid]->first_tx==1)
	LOG_D(PHY,"[PDSCH %x/%d] Format 1 DCI First TX: Clearing flag\n");
      dlsch[0]->harq_processes[harq_pid]->first_tx = 0;
3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045
    }
    else if (dlsch[0]->harq_processes[harq_pid]->status == SCH_IDLE) {  // we got an Ndi = 0 for a previously decoded process,
      // this happens if either another harq process in the same
      // is NAK or an ACK was not received

      dlsch[0]->harq_ack[subframe].ack              = 1;
      dlsch[0]->harq_ack[subframe].harq_id          = harq_pid;
      dlsch[0]->harq_ack[subframe].send_harq_status = 1;
      dlsch[0]->active = 0;
      //     printf("Got NDI=0 for correctly decoded SDU (harq_pid %d) subframe %d\n",harq_pid,subframe);
      return(0);
    }
    dlsch[0]->harq_processes[harq_pid]->mcs         = mcs;

    dlsch[0]->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(mcs)][NPRB-1];
    //    msg("test: MCS %d, NPRB %d, TBS %d\n",mcs,NPRB,dlsch[0]->harq_processes[harq_pid]->TBS);
    dlsch[0]->current_harq_pid = harq_pid;

    dlsch[0]->active = 1;

    dlsch[0]->rnti = rnti;

    dlsch0 = dlsch[0];

    break;

Raymond Knopp's avatar
 
Raymond Knopp committed
3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258
  case format2:
    switch (frame_parms->N_RB_DL) {

    case 6:
      if (frame_parms->nb_antennas_tx == 2) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->rballoc;
	  rv1       = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->rballoc;
	  rv1       = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else if (frame_parms->nb_antennas_tx == 4) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->rballoc;
	  rv1       = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->rballoc;
	  rv1       = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else {
	LOG_E(PHY,"UE: subframe %d Format2 DCI: unsupported number of TX antennas %d\n",subframe,frame_parms->nb_antennas_tx);
      }
      break;
    case 25:
      if (frame_parms->nb_antennas_tx == 2) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else if (frame_parms->nb_antennas_tx == 4) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else {
	LOG_E(PHY,"UE: Format2 DCI: unsupported number of TX antennas %d\n",frame_parms->nb_antennas_tx);
      }      
      break;
    case 50:
      if (frame_parms->nb_antennas_tx == 2) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else if (frame_parms->nb_antennas_tx == 4) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else {
	LOG_E(PHY,"UE: Format2 DCI: unsupported number of TX antennas %d\n",frame_parms->nb_antennas_tx);
      }
      break;

    case 100:
      if (frame_parms->nb_antennas_tx == 2) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else if (frame_parms->nb_antennas_tx == 4) {
	if (frame_type == TDD) {
	  mcs1      = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->tpmi;
	}
	else {
	  mcs1      = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->mcs1;
	  mcs2      = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->mcs2;
	  rballoc   = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->rballoc;
	  rah       = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->rah;
	  rv1       = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->rv1;
	  rv2       = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->rv2;
	  harq_pid  = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->harq_pid;
	  tbswap    = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->tb_swap;
	  tpmi      = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->tpmi;
	}
      }
      else {
	LOG_E(PHY,"UE: Format2 DCI: unsupported number of TX antennas %d\n",frame_parms->nb_antennas_tx);
      }
      break;
    }
3259 3260 3261 3262 3263 3264 3265 3266

    if (harq_pid>=8) {
      LOG_E(PHY,"Format 2_2A_M10PRB: harq_pid >= 8\n");
      return(-1);
    }
    dlsch[0]->current_harq_pid = harq_pid;
    dlsch[0]->harq_ack[subframe].harq_id = harq_pid;

Raymond Knopp's avatar
 
Raymond Knopp committed
3267
    tbswap = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->tb_swap;
3268 3269 3270 3271 3272 3273 3274 3275 3276
    if (tbswap == 0) {
      dlsch0 = dlsch[0];
      dlsch1 = dlsch[1];
    }
    else{
      dlsch0 = dlsch[1];
      dlsch1 = dlsch[0];
    }

Raymond Knopp's avatar
 
Raymond Knopp committed
3277 3278 3279
    conv_rballoc(rah,
		 rballoc,
		 frame_parms->N_RB_DL,
3280 3281 3282
		 dlsch0->harq_processes[harq_pid]->rb_alloc);
    dlsch1->harq_processes[harq_pid]->rb_alloc[0]                         = dlsch0->harq_processes[harq_pid]->rb_alloc[0];

Raymond Knopp's avatar
 
Raymond Knopp committed
3283 3284
    dlsch0->harq_processes[harq_pid]->nb_rb                               = conv_nprb(rah,
										      rballoc,
3285
										      frame_parms->N_RB_DL);
3286 3287
    dlsch1->harq_processes[harq_pid]->nb_rb                               = dlsch0->harq_processes[harq_pid]->nb_rb;

Raymond Knopp's avatar
 
Raymond Knopp committed
3288
    dlsch0->harq_processes[harq_pid]->mcs       = mcs1;
3289

Raymond Knopp's avatar
 
Raymond Knopp committed
3290
    dlsch0->harq_processes[harq_pid]->delta_PUCCH     = delta_PUCCH_lut[TPC&3];      
3291 3292 3293 3294 3295 3296 3297
    /*
      if (dlsch0->harq_processes[harq_pid]->mcs>20) {
      msg("dci_tools.c: mcs > 20 disabled for now (asked %d)\n",dlsch0->harq_processes[harq_pid]->mcs);
      return(-1);
      }
    */

Raymond Knopp's avatar
 
Raymond Knopp committed
3298 3299 3300
    dlsch1->harq_processes[harq_pid]->mcs       = mcs2;
    dlsch0->harq_processes[harq_pid]->rvidx     = rv1;
    dlsch1->harq_processes[harq_pid]->rvidx     = rv2;
3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337

    // check if either TB is disabled (see 36-213 V8.6 p. 26)

    if ((dlsch0->harq_processes[harq_pid]->rvidx == 1) && (dlsch0->harq_processes[harq_pid]->mcs == 0)) {
      dlsch0->harq_processes[harq_pid]->status = DISABLED;
    }
    if ((dlsch1->harq_processes[harq_pid]->rvidx == 1) && (dlsch1->harq_processes[harq_pid]->mcs == 0)) {
      dlsch1->harq_processes[harq_pid]->status = DISABLED;
    }
    dlsch0->harq_processes[harq_pid]->Nl        = 1;

    dlsch0->layer_index                         = tbswap;
    dlsch1->layer_index                         = 1-tbswap;

    switch (tpmi) {
    case 0 :
      dlsch0->harq_processes[harq_pid]->mimo_mode   = ALAMOUTI;
      break;
    case 1:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING11;
      dlsch0->harq_processes[harq_pid]->pmi_alloc                             = pmi_extend(frame_parms,0);
      break;
    case 2:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1m1;
      dlsch0->harq_processes[harq_pid]->pmi_alloc                             = pmi_extend(frame_parms,1);
      break;
    case 3:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1j;
      dlsch0->harq_processes[harq_pid]->pmi_alloc                             = pmi_extend(frame_parms,2);
      break;
    case 4:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1mj;
      dlsch0->harq_processes[harq_pid]->pmi_alloc                             = pmi_extend(frame_parms,3);
      break;
    case 5:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = PUSCH_PRECODING0;
      // pmi stored from ulsch allocation routine
3338 3339
      dlsch0->harq_processes[harq_pid]->pmi_alloc                             = dlsch0->pmi_alloc;
      //LOG_I(PHY,"XXX using PMI %x\n",pmi2hex_2Ar1(dlsch0->harq_processes[harq_pid]->pmi_alloc));
3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350
      break;
    case 6:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = PUSCH_PRECODING1;
      LOG_E(PHY,"Unsupported TPMI\n");
      return(-1);
      break;
    }


    if (frame_parms->mode1_flag == 1)
      dlsch0->harq_processes[harq_pid]->mimo_mode   = SISO;
Raymond Knopp's avatar
 
Raymond Knopp committed
3351
    if (ndi1!=dlsch0->harq_processes[harq_pid]->DCINdi) {
3352
      dlsch0->harq_processes[harq_pid]->round = 0;
3353
      dlsch0->harq_processes[harq_pid]->status = ACTIVE;
Raymond Knopp's avatar
 
Raymond Knopp committed
3354
      dlsch0->harq_processes[harq_pid]->DCINdi         = ndi1;
3355
    }      
3356 3357 3358 3359 3360 3361 3362 3363 3364 3365
    else if (dlsch0->harq_processes[harq_pid]->status == SCH_IDLE) {  // we got an Ndi = 0 for a previously decoded process,
      // this happens if either another harq process in the same
      // is NAK or an ACK was not received

      dlsch0->harq_ack[subframe].ack              = 1;
      dlsch0->harq_ack[subframe].harq_id          = harq_pid;
      dlsch0->harq_ack[subframe].send_harq_status = 1;
      dlsch0->active = 0;
      return(0);
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
3366
    dlsch0->harq_processes[harq_pid]->mcs         = mcs1;
3367 3368 3369 3370 3371 3372 3373 3374 3375
    if (dlsch0->harq_processes[harq_pid]->nb_rb>1) {
      dlsch0->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch0->harq_processes[harq_pid]->mcs)][dlsch0->harq_processes[harq_pid]->nb_rb-1];
    }
    else
      dlsch0->harq_processes[harq_pid]->TBS         =0;
    /*
      if (dlsch0->harq_processes[harq_pid]->mcs > 18)
      printf("mcs %d, TBS %d\n",dlsch0->harq_processes[harq_pid]->mcs,dlsch0->harq_processes[harq_pid]->TBS);
    */
3376

Raymond Knopp's avatar
 
Raymond Knopp committed
3377
    if (dlsch1->harq_processes[harq_pid]->DCINdi != ndi2) {
3378
      dlsch1->harq_processes[harq_pid]->round=0;
3379
      dlsch1->harq_processes[harq_pid]->status = ACTIVE;
3380
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
3381 3382
    dlsch1->harq_processes[harq_pid]->DCINdi      = ndi2;
    dlsch1->harq_processes[harq_pid]->mcs         = mcs2;
3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427
    if (dlsch1->harq_processes[harq_pid]->nb_rb>1) {
      dlsch1->harq_processes[harq_pid]->TBS       = TBStable[dlsch1->harq_processes[harq_pid]->mcs][dlsch1->harq_processes[harq_pid]->nb_rb-1];
    }
    else
      dlsch1->harq_processes[harq_pid]->TBS         = 0;

    dlsch0->rnti = rnti;
    dlsch1->rnti = rnti;

    dlsch0->harq_processes[harq_pid]->dl_power_off = 1; //no power offset
    dlsch1->harq_processes[harq_pid]->dl_power_off = 1; //no power offset

    dlsch0->active = 1;
    dlsch1->active = 1;

    break;
  case format1E_2A_M10PRB:

    harq_pid  = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->harq_pid;
    if (harq_pid>=8) {
      LOG_E(PHY,"Format 1E_2A_M10PRB: harq_pid >= 8\n");
      return(-1);
    }
    dlsch[0]->current_harq_pid = harq_pid;
    dlsch[0]->harq_ack[subframe].harq_id = harq_pid;

    /*
      tbswap = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->tb_swap;
      if (tbswap == 0) {
      dlsch0 = dlsch[0];
      dlsch1 = dlsch[1];
      }
      else{
      dlsch0 = dlsch[1];
      dlsch1 = dlsch[0];
      }
    */
    dlsch0 = dlsch[0];

    conv_rballoc(((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rah,
		 ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rballoc,frame_parms->N_RB_DL,
		 dlsch0->harq_processes[harq_pid]->rb_alloc);
    //dlsch1->harq_processes[harq_pid]->rb_alloc[0]                         = dlsch0->harq_processes[harq_pid]->rb_alloc[0];

    dlsch0->harq_processes[harq_pid]->nb_rb                               = conv_nprb(((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rah,
3428 3429
										      ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rballoc,
										      frame_parms->N_RB_DL);
3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488
    //dlsch1->harq_processes[harq_pid]->nb_rb                               = dlsch0->harq_processes[harq_pid]->nb_rb;

    dlsch0->harq_processes[harq_pid]->mcs             = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->mcs;
    dlsch0->harq_processes[harq_pid]->delta_PUCCH     = delta_PUCCH_lut[((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->TPC&3];      



    /*
      if (dlsch0->harq_processes[harq_pid]->mcs>20) {
      msg("dci_tools.c: mcs > 20 disabled for now (asked %d)\n",dlsch0->harq_processes[harq_pid]->mcs);
      return(-1);
      }
    */

    //dlsch1->harq_processes[harq_pid]->mcs       = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->mcs2;
    dlsch0->harq_processes[harq_pid]->rvidx     = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rv;
    //dlsch1->harq_processes[harq_pid]->rvidx     = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rv2;

    // check if either TB is disabled (see 36-213 V8.6 p. 26)

    if ((dlsch0->harq_processes[harq_pid]->rvidx == 1) && (dlsch0->harq_processes[harq_pid]->mcs == 0)) {
      dlsch0->harq_processes[harq_pid]->status = DISABLED;
    }
    //if ((dlsch1->harq_processes[harq_pid]->rvidx == 1) && (dlsch1->harq_processes[harq_pid]->mcs == 0)) {
    //dlsch1->harq_processes[harq_pid]->status = DISABLED;
    //}
    dlsch0->harq_processes[harq_pid]->Nl        = 1;

    //dlsch0->layer_index                         = tbswap;
    //dlsch1->layer_index                         = 1-tbswap;

    
    // Fix this
    tpmi = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->tpmi;
    //    msg("ue: tpmi %d\n",tpmi);

    switch (tpmi) {
    case 0 :
      dlsch0->harq_processes[harq_pid]->mimo_mode   = ALAMOUTI;
      break;
    case 1:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING11;
      dlsch0->harq_processes[harq_pid]->pmi_alloc   = pmi_extend(frame_parms,0);
      break;
    case 2:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1m1;
      dlsch0->harq_processes[harq_pid]->pmi_alloc   = pmi_extend(frame_parms,1);
      break;
    case 3:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1j;
      dlsch0->harq_processes[harq_pid]->pmi_alloc   = pmi_extend(frame_parms,2);
      break;
    case 4:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = UNIFORM_PRECODING1mj;
      dlsch0->harq_processes[harq_pid]->pmi_alloc   = pmi_extend(frame_parms,3);
      break;
    case 5:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = PUSCH_PRECODING0;
      // pmi stored from ulsch allocation routine
3489 3490 3491
      dlsch0->harq_processes[harq_pid]->pmi_alloc                             = dlsch0->pmi_alloc;
      //LOG_I(PHY,"XXX using PMI %x\n",pmi2hex_2Ar1(dlsch0->harq_processes[harq_pid]->pmi_alloc));
     break;
3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502
    case 6:
      dlsch0->harq_processes[harq_pid]->mimo_mode   = PUSCH_PRECODING1;
      LOG_E(PHY,"Unsupported TPMI\n");
      return(-1);
      break;
    }

    
    if (frame_parms->mode1_flag == 1)
      dlsch0->harq_processes[harq_pid]->mimo_mode   = SISO;

3503 3504 3505 3506

    if (dlsch0->harq_processes[harq_pid]->DCINdi != ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->ndi) {
      
      dlsch0->harq_processes[harq_pid]->round = 0;
3507
      dlsch0->harq_processes[harq_pid]->status = ACTIVE;
3508
    }
3509 3510 3511 3512 3513 3514 3515 3516 3517 3518
    else if (dlsch0->harq_processes[harq_pid]->status == SCH_IDLE) {  // we got an Ndi = 0 for a previously decoded process,
      // this happens if either another harq process in the same
      // is NAK or an ACK was not received

      dlsch0->harq_ack[subframe].ack              = 1;
      dlsch0->harq_ack[subframe].harq_id          = harq_pid;
      dlsch0->harq_ack[subframe].send_harq_status = 1;
      dlsch0->active = 0;
      return(0);
    }
3519 3520 3521

    dlsch0->harq_processes[harq_pid]->DCINdi = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->ndi;
    dlsch0->harq_processes[harq_pid]->mcs    = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->mcs;
3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550
    if (dlsch0->harq_processes[harq_pid]->nb_rb>1) {
      dlsch0->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS(dlsch0->harq_processes[harq_pid]->mcs)][dlsch0->harq_processes[harq_pid]->nb_rb-1];
    }
    else
      dlsch0->harq_processes[harq_pid]->TBS         =0;
    dlsch0->rnti = rnti;
    //dlsch1->rnti = rnti;

    dlsch0->active = 1;
    //dlsch1->active = 1;

    dlsch0->harq_processes[harq_pid]->dl_power_off = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->dl_power_off;
    //dlsch1->harq_processes[harq_pid]->dl_power_off = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->dl_power_off;


    break;
  default:
    LOG_E(PHY,"format %d not yet implemented\n",dci_format);
    return(-1);
    break;
  }


#ifdef DEBUG_DCI
  if (dlsch[0]) {
    msg("PDSCH dlsch0 UE: rnti     %x\n",dlsch[0]->rnti);
    msg("PDSCH dlsch0 UE: NBRB     %d\n",dlsch[0]->harq_processes[harq_pid]->nb_rb);
    msg("PDSCH dlsch0 UE: rballoc  %x\n",dlsch[0]->harq_processes[harq_pid]->rb_alloc[0]);
    msg("PDSCH dlsch0 UE: harq_pid %d\n",harq_pid);
3551
    msg("PDSCH dlsch0 UE: DCINdi   %d\n",dlsch[0]->harq_processes[harq_pid]->DCINdi);
3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569
    msg("PDSCH dlsch0 UE: rvidx    %d\n",dlsch[0]->harq_processes[harq_pid]->rvidx);
    msg("PDSCH dlsch0 UE: TBS      %d\n",dlsch[0]->harq_processes[harq_pid]->TBS);
    msg("PDSCH dlsch0 UE: mcs      %d\n",dlsch[0]->harq_processes[harq_pid]->mcs);
    msg("PDSCH dlsch0 UE: pwr_off  %d\n",dlsch[0]->harq_processes[harq_pid]->dl_power_off);
  }
#endif
  dlsch[0]->active=1;

  // compute DL power control parameters   
  computeRhoA_UE(pdsch_config_dedicated, dlsch[0],dlsch[0]->harq_processes[harq_pid]->dl_power_off);

  computeRhoB_UE(pdsch_config_dedicated,&(frame_parms->pdsch_config_common),frame_parms->nb_antennas_tx_eNB,dlsch[0],dlsch[0]->harq_processes[harq_pid]->dl_power_off);

  return(0);
}


uint8_t subframe2harq_pid(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame,uint8_t subframe) {
3570 3571 3572
  /*
    #ifdef DEBUG_DCI
    if (frame_parms->frame_type == TDD)
3573
    msg("dci_tools.c: subframe2_harq_pid, subframe %d for TDD configuration %d\n",subframe,frame_parms->tdd_config);
3574
    else
3575
    msg("dci_tools.c: subframe2_harq_pid, subframe %d for FDD \n",subframe);
3576 3577
    #endif
  */
3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607
  if (frame_parms->frame_type == FDD) {
    return(((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:
	  return(subframe-2);
	  break;
	case 7:
	case 8:
	  return(subframe-5);
	  break;
	default:
	  LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
	  return(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);
Lionel Gauthier's avatar
Lionel Gauthier committed
3608
	mac_xface->macphy_exit("subframe2_harq_pid, Illegal subframe");
3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680
	return(255);
      }
      return(subframe/7);
      break;
    case 3:
      if ((subframe<2) || (subframe>4)) {
	LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
	return(255);
      }
      return(subframe-2);
      break;
    case 4:
      if ((subframe<2) || (subframe>3)) {
	LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
	return(255);
      }
      return(subframe-2);
      break;
    case 5:
      if (subframe!=2) {
	LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
	return(255);
      }
      return(subframe-2);
      break;
    default:
      LOG_E(PHY,"subframe2_harq_pid, Unsupported TDD mode %d\n",frame_parms->tdd_config);
      return(255);

    }
  }
  return(255);
}

uint8_t pdcch_alloc2ul_subframe(LTE_DL_FRAME_PARMS *frame_parms,uint8_t n){

  if ((frame_parms->frame_type == TDD) && 
      (frame_parms->tdd_config == 1) &&
      ((n==1)||(n==6))) // tdd_config 0,1 SF 1,5
    return((n+6)%10);
  else if ((frame_parms->frame_type == TDD) && 
	   (frame_parms->tdd_config == 6) &&
	   ((n==0)||(n==1)||(n==5)||(n==6)))  
    return((n+7)%10);
  else if ((frame_parms->frame_type == TDD) && 
	   (frame_parms->tdd_config == 6) &&
	   (n==9)) // tdd_config 6 SF 9
    return((n+5)%10);
  else
    return((n+4)%10);

}

uint8_t ul_subframe2pdcch_alloc_subframe(LTE_DL_FRAME_PARMS *frame_parms,uint8_t n){

  if ((frame_parms->frame_type == TDD) && 
      (frame_parms->tdd_config == 1) &&
      ((n==7)||(n==2))) // tdd_config 0,1 SF 1,5
    return((n==7)? 1 : 6);
  else if ((frame_parms->frame_type == TDD) && 
	   (frame_parms->tdd_config == 6) &&
	   ((n==7)||(n==8)||(n==2)||(n==3)))  
    return((n+3)%10);
  else if ((frame_parms->frame_type == TDD) && 
	   (frame_parms->tdd_config == 6) &&
	   (n==4)) // tdd_config 6 SF 9
    return(9);
  else
    return((n+6)%10);

}

Raymond Knopp's avatar
 
Raymond Knopp committed
3681
uint32_t pdcch_alloc2ul_frame(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame, uint8_t n){
3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815

  if ((frame_parms->frame_type == TDD) && 
      (frame_parms->tdd_config == 1) &&
      ((n==1)||(n==6))) // tdd_config 0,1 SF 1,5
    return(frame + (n==1 ? 0 : 1));
  else if ((frame_parms->frame_type == TDD) && 
	   (frame_parms->tdd_config == 6) &&
	   ((n==0)||(n==1)||(n==5)||(n==6)))  
    return(frame + (n>=5 ? 1 : 0));
  else if ((frame_parms->frame_type == TDD) && 
	   (frame_parms->tdd_config == 6) &&
	   (n==9)) // tdd_config 6 SF 9
    return(frame+1);
  else
    return(frame+(n>=6 ? 1 : 0));

}

uint16_t quantize_subband_pmi(PHY_MEASUREMENTS *meas,uint8_t eNB_id) {

  int i, aarx;
  uint16_t pmiq=0;
  uint16_t pmivect = 0;
  uint8_t rank = meas->rank[eNB_id];
  int pmi_re,pmi_im;

  for (i=0;i<NUMBER_OF_SUBBANDS;i++) {
    pmi_re = 0;
    pmi_im = 0;

    if (rank == 0) {
      for (aarx=0; aarx<meas->nb_antennas_rx; aarx++) {
	pmi_re += meas->subband_pmi_re[eNB_id][i][aarx];
	pmi_im += meas->subband_pmi_im[eNB_id][i][aarx];
      }

      //  pmi_re = meas->subband_pmi_re[eNB_id][i][meas->selected_rx_antennas[eNB_id][i]];
      //  pmi_im = meas->subband_pmi_im[eNB_id][i][meas->selected_rx_antennas[eNB_id][i]];

      //      printf("pmi => (%d,%d)\n",pmi_re,pmi_im);
      if ((pmi_re > pmi_im) && (pmi_re > -pmi_im))
	pmiq = PMI_2A_11;
      else if ((pmi_re < pmi_im) && (pmi_re > -pmi_im))
	pmiq = PMI_2A_1j;
      else if ((pmi_re < pmi_im) && (pmi_re < -pmi_im))
	pmiq = PMI_2A_1m1;
      else if ((pmi_re > pmi_im) && (pmi_re < -pmi_im))
	pmiq = PMI_2A_1mj;
      //      printf("subband %d, pmi%d \n",i,pmiq);
      pmivect |= (pmiq<<(2*i));
    }
    else {
      // This needs to be done properly!!!
      msg("PMI feedback for rank>1 not supported!\n");
      pmivect = 0;
    }
  }

  return(pmivect);
}

uint16_t quantize_subband_pmi2(PHY_MEASUREMENTS *meas,uint8_t eNB_id,uint8_t a_id) {

  uint8_t i;
  uint16_t pmiq=0;
  uint16_t pmivect = 0;
  uint8_t rank = meas->rank[eNB_id];
  int pmi_re,pmi_im;

  for (i=0;i<NUMBER_OF_SUBBANDS;i++) {

    if (rank == 0) {
      pmi_re = meas->subband_pmi_re[eNB_id][i][a_id];
      pmi_im = meas->subband_pmi_im[eNB_id][i][a_id];

      if ((pmi_re > pmi_im) && (pmi_re > -pmi_im))
	pmiq = PMI_2A_11;
      else if ((pmi_re < pmi_im) && (pmi_re > -pmi_im))
	pmiq = PMI_2A_1j;
      else if ((pmi_re < pmi_im) && (pmi_re < -pmi_im))
	pmiq = PMI_2A_1m1;
      else if ((pmi_re > pmi_im) && (pmi_re < -pmi_im))
	pmiq = PMI_2A_1mj;
      pmivect |= (pmiq<<(2*i));
    }
    else {
      // This needs to be done properly!!!
      pmivect = 0;
    }
  }

  return(pmivect);
}

uint16_t quantize_wideband_pmi(PHY_MEASUREMENTS *meas,uint8_t eNB_id) {

  uint16_t pmiq=0;
  uint8_t rank = meas->rank[eNB_id];
  //int pmi;
  int pmi_re,pmi_im;

  if (rank == 1) {
    //pmi =
    pmi_re = meas->wideband_pmi_re[eNB_id][meas->selected_rx_antennas[eNB_id][0]];
    pmi_im = meas->wideband_pmi_im[eNB_id][meas->selected_rx_antennas[eNB_id][0]];
    if ((pmi_re > pmi_im) && (pmi_re > -pmi_im))
      pmiq = PMI_2A_11;
    else if ((pmi_re < pmi_im) && (pmi_re > -pmi_im))
      pmiq = PMI_2A_1j;
    else if ((pmi_re < pmi_im) && (pmi_re < -pmi_im))
      pmiq = PMI_2A_1m1;
    else if ((pmi_re > pmi_im) && (pmi_re < -pmi_im))
      pmiq = PMI_2A_1mj;

  }
  else {
    // This needs to be done properly!
    pmiq = PMI_2A_11;
  }


  return(pmiq);
}
/*
  uint8_t sinr2cqi(int sinr) {
  if (sinr<-3)
  return(0);
  if (sinr>14)
  return(10);
  else
  return(3+(sinr>>1));
  }
*/
 
3816
uint8_t sinr2cqi(double sinr,uint8_t trans_mode) {
3817
  // int flag_LA=0;
3818

3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848
  if(flag_LA==0){
    // Ideal Channel Estimation
    if (sinr<=-4.89)
      return(0);
    else if (sinr < -3.53)
      return(3);
    else if (sinr <= -1.93)
      return(4);
    else if (sinr <= -0.43)
      return(5);
    else if (sinr <= 1.11)
      return(6);
    else if (sinr <= 3.26)
      return(7);
    else if (sinr <= 5)
      return(8);
    else if (sinr <= 7)
      return(9);
    else if (sinr <= 9)
      return(10);
    else if (sinr <= 11)
      return(11);
    else if (sinr <= 13)
      return(12);
    else if (sinr <= 15.5)
      return(13);
    else if (sinr <= 17.5)
      return(14);
    else if (sinr > 19.5)
      return(15);
3849
  }
3850 3851 3852 3853 3854 3855 3856 3857 3858 3859
  else{
    int h=0;
    int trans_mode_tmp;
    if (trans_mode ==5)
      trans_mode_tmp=2;
    else 
      if(trans_mode ==6)
	trans_mode_tmp=3;
      else
	trans_mode_tmp = trans_mode-1;
3860
   
3861 3862 3863 3864 3865 3866
    for(h=0;h<16;h++){
      if(sinr<=sinr_to_cqi[trans_mode_tmp][h])
	return(h);
    }
  }
  return(0);
3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930
}
//uint32_t fill_subband_cqi(PHY_MEASUREMENTS *meas,uint8_t eNB_id) {
//
//	uint8_t i;
////	uint16_t cqivect = 0;
//	uint32_t cqivect = 0;
//
////	char diff_cqi;
//	int diff_cqi=0;
//
//	for (i=0;i<NUMBER_OF_SUBBANDS;i++) {
//
//		diff_cqi = -sinr2cqi(meas->wideband_cqi_dB[eNB_id][0]) + sinr2cqi(meas->subband_cqi_dB[eNB_id][0][i]);
//
//		// Note, this is Table 7.2.1-2 from 36.213
//		if (diff_cqi<=-1)
//			diff_cqi = 3;
//		else if (diff_cqi>2)
//			diff_cqi = 2;
//		cqivect |= (diff_cqi<<(2*i));
//
//	}
//
//	return(cqivect);
//}


uint32_t fill_subband_cqi(PHY_MEASUREMENTS *meas,uint8_t eNB_id,uint8_t trans_mode) {

  uint8_t i;

  uint32_t cqivect = 0,offset=0;


  int diff_cqi=0;

  for (i=0;i<NUMBER_OF_SUBBANDS;i++) {

    diff_cqi = -sinr2cqi(meas->wideband_cqi_avg[eNB_id],trans_mode) + sinr2cqi(meas->subband_cqi_tot_dB[eNB_id][i],trans_mode);

    // Note, this is Table 7.2.1-2 from 36.213
    if (diff_cqi<=-1)
      offset = 3;
    else
      if (diff_cqi>=2)
	offset = 2;
      else
	offset=(uint32_t)diff_cqi;

    cqivect |= (offset<<(2*i));

  }

  return(cqivect);
}

void fill_CQI(void *o,UCI_format_t uci_format,PHY_MEASUREMENTS *meas,uint8_t eNB_id,uint16_t rnti, uint8_t trans_mode, double sinr_eff) {
  
  //  msg("[PHY][UE] Filling CQI for eNB %d, meas->wideband_cqi_tot[%d] %d\n",
  //      eNB_id,eNB_id,meas->wideband_cqi_tot[eNB_id]);
  double sinr_tmp;
  if(flag_LA==1)
    sinr_tmp = sinr_eff;
  else
3931 3932
    sinr_tmp = (double) meas->wideband_cqi_avg[eNB_id];

Raymond Knopp's avatar
 
Raymond Knopp committed
3933
  //LOG_I(PHY,"Filling CQI %f for eNB %d\n",sinr_tmp,eNB_id);
3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965

  switch (uci_format) {
  case wideband_cqi_rank1_2A:
    ((wideband_cqi_rank1_2A_5MHz *)o)->cqi1 = sinr2cqi(sinr_tmp,trans_mode);
    ((wideband_cqi_rank1_2A_5MHz *)o)->pmi  = quantize_subband_pmi(meas,eNB_id);
    break;
  case wideband_cqi_rank2_2A:
    ((wideband_cqi_rank2_2A_5MHz *)o)->cqi1 = sinr2cqi(sinr_tmp,trans_mode); //FIXME: calculate rank2 cqi
    ((wideband_cqi_rank2_2A_5MHz *)o)->cqi2 = sinr2cqi(sinr_tmp,trans_mode); //FIXME: calculate rank2 cqi
    ((wideband_cqi_rank2_2A_5MHz *)o)->pmi  = quantize_subband_pmi(meas,eNB_id);
    break;
  case HLC_subband_cqi_nopmi:
    ((HLC_subband_cqi_nopmi_5MHz *)o)->cqi1     = sinr2cqi(sinr_tmp,trans_mode);
    ((HLC_subband_cqi_nopmi_5MHz *)o)->diffcqi1 = fill_subband_cqi(meas,eNB_id,trans_mode);
    break;
  case HLC_subband_cqi_rank1_2A:
    ((HLC_subband_cqi_rank1_2A_5MHz *)o)->cqi1     = sinr2cqi(sinr_tmp,trans_mode);
    ((HLC_subband_cqi_rank1_2A_5MHz *)o)->diffcqi1 = fill_subband_cqi(meas,eNB_id,trans_mode);
    ((HLC_subband_cqi_rank1_2A_5MHz *)o)->pmi      = quantize_wideband_pmi(meas,eNB_id);
    break;
  case HLC_subband_cqi_rank2_2A:
    // This has to be improved!!!
    ((HLC_subband_cqi_rank2_2A_5MHz *)o)->cqi1     = sinr2cqi(sinr_tmp,trans_mode);
    ((HLC_subband_cqi_rank2_2A_5MHz *)o)->diffcqi1 = fill_subband_cqi(meas,eNB_id,trans_mode);
    ((HLC_subband_cqi_rank2_2A_5MHz *)o)->cqi2     = sinr2cqi(sinr_tmp,trans_mode);
    ((HLC_subband_cqi_rank2_2A_5MHz *)o)->diffcqi2 = fill_subband_cqi(meas,eNB_id,trans_mode);
    ((HLC_subband_cqi_rank2_2A_5MHz *)o)->pmi      = quantize_subband_pmi(meas,eNB_id);
    break;
  case HLC_subband_cqi_mcs_CBA:
    // this is the cba mcs uci for cba transmission 
    ((HLC_subband_cqi_mcs_CBA_5MHz *)o)->mcs     = 2; //fixme
    ((HLC_subband_cqi_mcs_CBA_5MHz *)o)->crnti  = rnti;
Raymond Knopp's avatar
 
Raymond Knopp committed
3966
    LOG_D(PHY,"fill uci for cba rnti %x, mcs %d \n", rnti, 2);
3967 3968 3969
    break;
  case ue_selected:
    LOG_E(PHY,"fill_CQI ue_selected CQI not supported yet!!!\n");
Lionel Gauthier's avatar
Lionel Gauthier committed
3970
    mac_xface->macphy_exit("fill_CQI ue_selected CQI not supported yet!!!");
3971 3972 3973
    break;
  default:
    LOG_E(PHY,"unsupported CQI mode (%d)!!!\n",uci_format);
Lionel Gauthier's avatar
Lionel Gauthier committed
3974
    mac_xface->macphy_exit("unsupported CQI mode !!!");
3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034
    break;

  }
}

void reset_cba_uci(void *o) {
  // this is the cba mcs uci for cba transmission 
  ((HLC_subband_cqi_mcs_CBA_5MHz *)o)->mcs     = 0; //fixme
  ((HLC_subband_cqi_mcs_CBA_5MHz *)o)->crnti  = 0x0;
}

uint32_t pmi_extend(LTE_DL_FRAME_PARMS *frame_parms,uint8_t wideband_pmi) {

  uint8_t i,wideband_pmi2=wideband_pmi&3;
  uint32_t pmi_ex = 0;

  for (i=0;i<14;i+=2)
    pmi_ex|=(wideband_pmi2<<i);

  return(pmi_ex);
}


int generate_ue_ulsch_params_from_dci(void *dci_pdu,
				      uint16_t rnti,
				      uint8_t subframe,
				      DCI_format_t dci_format,
				      PHY_VARS_UE *phy_vars_ue,
				      uint16_t si_rnti,
				      uint16_t ra_rnti,
				      uint16_t p_rnti,
				      uint16_t cba_rnti,
				      uint8_t eNB_id,
				      uint8_t use_srs) {

  uint8_t harq_pid;
  uint8_t transmission_mode = phy_vars_ue->transmission_mode[eNB_id];
  ANFBmode_t AckNackFBMode = phy_vars_ue->pucch_config_dedicated[eNB_id].tdd_AckNackFeedbackMode;
  LTE_UE_ULSCH_t *ulsch = phy_vars_ue->ulsch_ue[eNB_id];
  //  LTE_UE_DLSCH_t **dlsch = phy_vars_ue->dlsch_ue[0];
  PHY_MEASUREMENTS *meas = &phy_vars_ue->PHY_measurements;
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_ue->lte_frame_parms;
  //  uint32_t current_dlsch_cqi = phy_vars_ue->current_dlsch_cqi[eNB_id];

  uint32_t cqi_req;
  uint32_t dai;
  uint32_t cshift;
  uint32_t TPC;
  uint32_t ndi;
  uint32_t mcs;
  uint32_t rballoc,RIV_max;
  //  uint32_t hopping;
  //  uint32_t type;

  if (dci_format == format0) {

    if (rnti == ra_rnti)
      harq_pid = 0;
    else
      harq_pid = subframe2harq_pid(frame_parms,
Raymond Knopp's avatar
 
Raymond Knopp committed
4035
				   pdcch_alloc2ul_frame(frame_parms,phy_vars_ue->frame_rx,subframe),
4036
				   pdcch_alloc2ul_subframe(frame_parms,subframe));
Raymond Knopp's avatar
 
Raymond Knopp committed
4037
    
4038 4039
    if (harq_pid == 255) {
      LOG_E(PHY, "frame %d, subframe %d, rnti %x, format %d: illegal harq_pid!\n",
Raymond Knopp's avatar
 
Raymond Knopp committed
4040
	    phy_vars_ue->frame_rx, subframe, rnti, dci_format);
4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159
      return(-1);
    }

    switch (frame_parms->N_RB_DL) {
    case 6:
      if (frame_parms->frame_type == TDD) {
	cqi_req = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->cqi_req;
	dai     = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->dai;
	cshift  = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->type;
      }
      else {
	cqi_req = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->cqi_req;
	cshift  = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->type;
      }
      RIV_max = RIV_max6;
      ulsch->harq_processes[harq_pid]->first_rb                              = RIV2first_rb_LUT6[rballoc];
      ulsch->harq_processes[harq_pid]->nb_rb                                 = RIV2nb_rb_LUT6[rballoc];

      break;

    case 25:
      if (frame_parms->frame_type == TDD) {
	cqi_req = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->cqi_req;
	dai     = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->dai;
	cshift  = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->type;
      }
      else {
	cqi_req = ((DCI0_5MHz_FDD_t *)dci_pdu)->cqi_req;
	cshift  = ((DCI0_5MHz_FDD_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_5MHz_FDD_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_5MHz_FDD_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_5MHz_FDD_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_5MHz_FDD_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_5MHz_FDD_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_5MHz_FDD_t *)dci_pdu)->type;
      }
      RIV_max = RIV_max25;
      ulsch->harq_processes[harq_pid]->first_rb                              = RIV2first_rb_LUT25[rballoc];
      ulsch->harq_processes[harq_pid]->nb_rb                                 = RIV2nb_rb_LUT25[rballoc];
      //      printf("***********rballoc %d, first_rb %d, nb_rb %d\n",rballoc,ulsch->harq_processes[harq_pid]->first_rb,ulsch->harq_processes[harq_pid]->nb_rb);
      break;

    case 50:
      if (frame_parms->frame_type == TDD) {
	cqi_req = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->cqi_req;
	dai     = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->dai;
	cshift  = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->type;
      }
      else {
	cqi_req = ((DCI0_10MHz_FDD_t *)dci_pdu)->cqi_req;
	cshift  = ((DCI0_10MHz_FDD_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_10MHz_FDD_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_10MHz_FDD_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_10MHz_FDD_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_10MHz_FDD_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_10MHz_FDD_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_10MHz_FDD_t *)dci_pdu)->type;
      }

      RIV_max = RIV_max50;
      ulsch->harq_processes[harq_pid]->first_rb = RIV2first_rb_LUT50[rballoc];
      ulsch->harq_processes[harq_pid]->nb_rb    = RIV2nb_rb_LUT50[rballoc];

      break;
      
    case 100:
      if (frame_parms->frame_type == TDD) {
	cqi_req = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->cqi_req;
	dai     = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->dai;
	cshift  = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->type;
      }
      else {
	cqi_req = ((DCI0_20MHz_FDD_t *)dci_pdu)->cqi_req;
	cshift  = ((DCI0_20MHz_FDD_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_20MHz_FDD_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_20MHz_FDD_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_20MHz_FDD_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_20MHz_FDD_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_20MHz_FDD_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_20MHz_FDD_t *)dci_pdu)->type;
      }
      RIV_max = RIV_max100;
      ulsch->harq_processes[harq_pid]->first_rb                              = RIV2first_rb_LUT100[rballoc];
      ulsch->harq_processes[harq_pid]->nb_rb                                 = RIV2nb_rb_LUT100[rballoc];

      printf("rb_alloc (20 MHz dci) %d\n",rballoc);
      break;

    default:
winckel's avatar
winckel committed
4160 4161
      LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
      DevParam (frame_parms->N_RB_DL, 0, 0);
4162 4163 4164 4165 4166 4167
      break;
    }


    if (rballoc > RIV_max) {
      LOG_E(PHY,"frame %d, subframe %d, rnti %x, format %d: FATAL ERROR: generate_ue_ulsch_params_from_dci, rb_alloc > RIV_max\n", 	  
Raymond Knopp's avatar
 
Raymond Knopp committed
4168
	    phy_vars_ue->frame_rx, subframe, rnti, dci_format);
4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181
      return(-1);
    }


    // indicate that this process is to be serviced in subframe n+4
    if ((rnti >= cba_rnti) && (rnti < p_rnti))
      ulsch->harq_processes[harq_pid]->subframe_cba_scheduling_flag = 1;
    else 
      ulsch->harq_processes[harq_pid]->subframe_scheduling_flag = 1;
    
    ulsch->harq_processes[harq_pid]->TPC                                   = TPC;

    if (phy_vars_ue->ul_power_control_dedicated[eNB_id].accumulationEnabled == 1) {
4182 4183
      LOG_D(PHY,"[UE %d][PUSCH %d] Frame %d subframe %d: f_pusch (ACC) %d, adjusting by %d (TPC %d)\n",
	phy_vars_ue->Mod_id,harq_pid,phy_vars_ue->frame_rx,subframe,ulsch->f_pusch,
4184 4185 4186 4187 4188
	delta_PUSCH_acc[phy_vars_ue->ulsch_ue[eNB_id]->harq_processes[harq_pid]->TPC],
	phy_vars_ue->ulsch_ue[eNB_id]->harq_processes[harq_pid]->TPC);
      ulsch->f_pusch += delta_PUSCH_acc[phy_vars_ue->ulsch_ue[eNB_id]->harq_processes[harq_pid]->TPC];
    }
    else {
4189 4190
      LOG_D(PHY,"[UE %d][PUSCH %d] Frame %d subframe %d: f_pusch (ABS) %d, adjusting to %d (TPC %d)\n",
	phy_vars_ue->Mod_id,harq_pid,phy_vars_ue->frame_rx,subframe,ulsch->f_pusch,
4191 4192 4193 4194
	delta_PUSCH_abs[phy_vars_ue->ulsch_ue[eNB_id]->harq_processes[harq_pid]->TPC],
	phy_vars_ue->ulsch_ue[eNB_id]->harq_processes[harq_pid]->TPC);
      ulsch->f_pusch = delta_PUSCH_abs[phy_vars_ue->ulsch_ue[eNB_id]->harq_processes[harq_pid]->TPC];
    }
4195 4196 4197
    if (ulsch->harq_processes[harq_pid]->first_tx==1) {
      //      ulsch->harq_processes[harq_pid]->Ndi                                   = 1;
      ulsch->harq_processes[harq_pid]->first_tx=0;
Raymond Knopp's avatar
 
Raymond Knopp committed
4198
      ulsch->harq_processes[harq_pid]->round = 0;
4199 4200 4201 4202 4203
    }
    else {
      if (ulsch->harq_processes[harq_pid]->DCINdi!=ndi) { // new SDU opportunity
	//	ulsch->harq_processes[harq_pid]->Ndi = 1;
	ulsch->harq_processes[harq_pid]->DCINdi= ndi;
Raymond Knopp's avatar
 
Raymond Knopp committed
4204
	ulsch->harq_processes[harq_pid]->round = 0;
4205 4206 4207
      }
      else {
	//	ulsch->harq_processes[harq_pid]->Ndi = 0;
Raymond Knopp's avatar
 
Raymond Knopp committed
4208
	// ulsch->harq_processes[harq_pid]->round++;  // This is done in phich RX
4209 4210
      }
    }
4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399
    ulsch->harq_processes[harq_pid]->n_DMRS                                = cshift;     

    //printf("nb_rb %d, first_rb %d (RIV %d)\n",ulsch->harq_processes[harq_pid]->nb_rb,ulsch->harq_processes[harq_pid]->first_rb,rballoc);
    if ((rnti >= cba_rnti) && (rnti < p_rnti)){
      // ulsch->cba_rnti[0]=rnti;
    } else {
      ulsch->rnti = rnti;
    }
    //    msg("[PHY][UE] DCI format 0: harq_pid %d nb_rb %d, rballoc %d\n",harq_pid,ulsch->harq_processes[harq_pid]->nb_rb,
    //	   ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->rballoc);
    //Mapping of cyclic shift field in DCI format0 to n_DMRS2 (3GPP 36.211, Table 5.5.2.1.1-1)
    if(cshift == 0)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 0;
    else if(cshift == 1)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 6;
    else if(cshift == 2)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 3;
    else if(cshift == 3)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 4;
    else if(cshift == 4)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 2;
    else if(cshift == 5)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 8;
    else if(cshift == 6)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 10;
    else if(cshift == 7)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 9;


    //reserved for cooperative communication
    /*
      if(ulsch->n_DMRS2 == 6)
      ulsch->cooperation_flag = 2;
      else
      ulsch->cooperation_flag = 0;
    */

    if ((ulsch->harq_processes[harq_pid]->nb_rb>0) && (ulsch->harq_processes[harq_pid]->nb_rb < 25))
      ulsch->power_offset = ue_power_offsets[ulsch->harq_processes[harq_pid]->nb_rb-1];

    //    if (ulsch->harq_processes[harq_pid]->Ndi == 1)
    //    ulsch->harq_processes[harq_pid]->status = ACTIVE;


    if (cqi_req == 1) {
      ulsch->O_RI = 1; //we only support 2 antenna ports, so this is always 1 according to 3GPP 36.213 Table 
      switch(transmission_mode){ 
	// The aperiodic CQI reporting mode is fixed for every transmission mode instead of being configured by higher layer signaling
      case 1:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){
	  ulsch->O                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_mcs_CBA;
	  ulsch->o_RI[0]                             = 0;
	}
	else  if(meas->rank[eNB_id] == 0){
	  ulsch->O                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_nopmi;
	  ulsch->o_RI[0]                             = 0;
	}
	else{
	  ulsch->O                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_nopmi;
	  ulsch->o_RI[0]                             = 1;
	}
	break;
      case 2:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){
	  ulsch->O                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_mcs_CBA;
	  ulsch->o_RI[0]                             = 0;
	} 
	else if(meas->rank[eNB_id] == 0){
	  ulsch->O                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_nopmi;
	  ulsch->o_RI[0]                             = 0;
	}
	else{
	  ulsch->O                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_nopmi;
	  ulsch->o_RI[0]                             = 1;
	}
	break;
      case 3:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){
	  ulsch->O                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_mcs_CBA;
	  ulsch->o_RI[0]                             = 0;
	} 
	else if(meas->rank[eNB_id] == 0){
	  ulsch->O                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_nopmi;
	  ulsch->o_RI[0]                             = 0;
	}
	else{
	  ulsch->O                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_nopmi;
	  ulsch->o_RI[0]                             = 1;
	}
	break;
      case 4:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){
	  ulsch->O                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_mcs_CBA;
	  ulsch->o_RI[0]                             = 0;
	}
	else if(meas->rank[eNB_id] == 0){
	  ulsch->O                                   = sizeof_wideband_cqi_rank1_2A_5MHz;
	  ulsch->uci_format                          = wideband_cqi_rank1_2A;
	  ulsch->o_RI[0]                             = 0;
	}
	else{
	  ulsch->O                                   = sizeof_wideband_cqi_rank2_2A_5MHz;
	  ulsch->uci_format                          = wideband_cqi_rank2_2A;
	  ulsch->o_RI[0]                             = 1;
	}
	break;
      case 5:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){
	  ulsch->O                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_mcs_CBA;
	  ulsch->o_RI[0]                             = 0;
	}
	else if(meas->rank[eNB_id] == 0){
	  ulsch->O                                   = sizeof_wideband_cqi_rank1_2A_5MHz;
	  ulsch->uci_format                          = wideband_cqi_rank1_2A;
	  ulsch->o_RI[0]                             = 0;
	}
	else{
	  ulsch->O                                   = sizeof_wideband_cqi_rank2_2A_5MHz;
	  ulsch->uci_format                          = wideband_cqi_rank2_2A;
	  ulsch->o_RI[0]                             = 1;
	}
	break;
      case 6:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){
	  ulsch->O                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_mcs_CBA;
	  ulsch->o_RI[0]                             = 0;
	}
	else if(meas->rank[eNB_id] == 0){
	  ulsch->O                                   = sizeof_wideband_cqi_rank1_2A_5MHz;
	  ulsch->uci_format                          = wideband_cqi_rank1_2A;
	  ulsch->o_RI[0]                             = 0;
	}
	else{
	  ulsch->O                                   = sizeof_wideband_cqi_rank2_2A_5MHz;
	  ulsch->uci_format                          = wideband_cqi_rank2_2A;
	  ulsch->o_RI[0]                             = 1;
	}
	break;
      case 7:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){
	  ulsch->O                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_mcs_CBA;
	  ulsch->o_RI[0]                             = 0;
	}
	else if(meas->rank[eNB_id] == 0){
	  ulsch->O                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_nopmi;
	  ulsch->o_RI[0]                             = 0;
	}
	else{
	  ulsch->O                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	  ulsch->uci_format                          = HLC_subband_cqi_nopmi;
	  ulsch->o_RI[0]                             = 1;
	}
	break;
      default:
	LOG_E(PHY,"Incorrect Transmission Mode \n");
	break;
      }
    }
    else {
      ulsch->O_RI = 0;
      ulsch->O                                   = 0;
      ulsch->uci_format                          = HLC_subband_cqi_nopmi;
    }
    
    print_CQI(ulsch->o,ulsch->uci_format,eNB_id);

    //FK: moved this part to ulsch_coding to be more recent
    /*
      fill_CQI(ulsch->o,ulsch->uci_format,meas,eNB_id,transmission_mode);
      print_CQI(ulsch->o,ulsch->uci_format,eNB_id);
   
      // save PUSCH pmi for later (transmission modes 4,5,6)
      // msg("ulsch: saving pmi for DL %x\n",pmi2hex_2Ar1(((wideband_cqi_rank1_2A_5MHz *)ulsch->o)->pmi));
      dlsch[0]->pmi_alloc = ((wideband_cqi_rank1_2A_5MHz *)ulsch->o)->pmi;
    */
Raymond Knopp's avatar
 
Raymond Knopp committed
4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417

        // check this (see comment in generate_ue_ulsch_params_from_dci)
    if (frame_parms->frame_type == FDD) {
      int dl_subframe = (subframe<4) ? (subframe+6) : (subframe-4);
      if (phy_vars_ue->dlsch_ue[eNB_id][0]->harq_ack[dl_subframe].send_harq_status>0) { // we have downlink transmission
	ulsch->harq_processes[harq_pid]->O_ACK = 1;
      }
      else {
	ulsch->harq_processes[harq_pid]->O_ACK = 0;
      }
    } else {
      if (ulsch->bundling)
	ulsch->harq_processes[harq_pid]->O_ACK = (dai == 3)? 0 : 1;
      else
	ulsch->harq_processes[harq_pid]->O_ACK = (dai+1)&3;
      
      //      ulsch->harq_processes[harq_pid]->V_UL_DAI = dai+1;
    }
4418 4419 4420 4421 4422 4423 4424 4425 4426

    ulsch->beta_offset_cqi_times8                = beta_cqi[phy_vars_ue->pusch_config_dedicated[eNB_id].betaOffset_CQI_Index];//18;
    ulsch->beta_offset_ri_times8                 = beta_ri[phy_vars_ue->pusch_config_dedicated[eNB_id].betaOffset_RI_Index];//10;
    ulsch->beta_offset_harqack_times8            = beta_ack[phy_vars_ue->pusch_config_dedicated[eNB_id].betaOffset_ACK_Index];//16;

    ulsch->Nsymb_pusch                             = 12-(frame_parms->Ncp<<1)-(use_srs==0?0:1);
    ulsch->srs_active                              = use_srs;
    ulsch->bundling = 1-AckNackFBMode;

4427
    if (ulsch->harq_processes[harq_pid]->round == 0) {
4428
      if ((rnti >= cba_rnti) && (rnti < p_rnti))
4429
	ulsch->harq_processes[harq_pid]->status = CBA_ACTIVE;
4430
      else 
4431
	ulsch->harq_processes[harq_pid]->status = ACTIVE;
4432 4433 4434 4435 4436
      ulsch->harq_processes[harq_pid]->rvidx = 0;
      ulsch->harq_processes[harq_pid]->mcs         = mcs;
      //      ulsch->harq_processes[harq_pid]->calibration_flag =0;
      if (ulsch->harq_processes[harq_pid]->mcs < 29)
	ulsch->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS_UL(ulsch->harq_processes[harq_pid]->mcs)][ulsch->harq_processes[harq_pid]->nb_rb-1];
Raymond Knopp's avatar
 
Raymond Knopp committed
4437 4438
      else
	LOG_E(PHY,"Fatal: mcs > 28!!! and round == 0\n");
4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452
      /*
	else if (ulsch->harq_processes[harq_pid]->mcs == 29) {
	ulsch->harq_processes[harq_pid]->mcs = 4;
	ulsch->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS_UL(ulsch->harq_processes[harq_pid]->mcs)][ulsch->harq_processes[harq_pid]->nb_rb-1];
	//	ulsch->harq_processes[harq_pid]->calibration_flag =1;
	//	printf("Auto-Calibration (UE): mcs %d, TBS %d, nb_rb %d\n",ulsch->harq_processes[harq_pid]->mcs,ulsch->harq_processes[harq_pid]->TBS,ulsch->harq_processes[harq_pid]->nb_rb);
	}*/
      ulsch->harq_processes[harq_pid]->Msc_initial   = 12*ulsch->harq_processes[harq_pid]->nb_rb;
      ulsch->harq_processes[harq_pid]->Nsymb_initial = ulsch->Nsymb_pusch;
      ulsch->harq_processes[harq_pid]->round = 0;

      // a Ndi=1 automatically acknowledges previous PUSCH transmission
      if (phy_vars_ue->ulsch_ue_Msg3_active[eNB_id] == 1) 
	phy_vars_ue->ulsch_ue_Msg3_active[eNB_id] = 0;  
Raymond Knopp's avatar
 
Raymond Knopp committed
4453
    } 
4454 4455
    else {
      //      printf("Ndi = 0 : Setting RVidx from mcs %d\n",((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->mcs);
Raymond Knopp's avatar
 
Raymond Knopp committed
4456
      if (mcs>28) ulsch->harq_processes[harq_pid]->rvidx = mcs - 28;
4457 4458 4459
      //      ulsch->harq_processes[harq_pid]->round++;
    }

Raymond Knopp's avatar
 
Raymond Knopp committed
4460 4461
    LOG_D(PHY,"[UE %d][PUSCH %d] Frame %d, subframe %d : Programming PUSCH with n_DMRS2 %d (cshift %d), nb_rb %d, first_rb %d, mcs %d, round %d, rv %d\n",
	  phy_vars_ue->Mod_id,harq_pid,phy_vars_ue->frame_rx,subframe,ulsch->harq_processes[harq_pid]->n_DMRS2,cshift,ulsch->harq_processes[harq_pid]->nb_rb,ulsch->harq_processes[harq_pid]->first_rb,ulsch->harq_processes[harq_pid]->mcs,ulsch->harq_processes[harq_pid]->round,ulsch->harq_processes[harq_pid]->rvidx);
Raymond Knopp's avatar
 
Raymond Knopp committed
4462

4463 4464 4465 4466 4467 4468
    // ulsch->n_DMRS2 = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->cshift;

#ifdef DEBUG_DCI
    msg("Format 0 DCI : ulsch (ue): NBRB        %d\n",ulsch->harq_processes[harq_pid]->nb_rb);
    msg("Format 0 DCI :ulsch (ue): first_rb    %d\n",ulsch->harq_processes[harq_pid]->first_rb);
    msg("Format 0 DCI :ulsch (ue): harq_pid    %d\n",harq_pid);
4469
    msg("Format 0 DCI :ulsch (ue): round       %d\n",ulsch->harq_processes[harq_pid]->round);
4470 4471 4472 4473 4474 4475 4476 4477 4478 4479
    msg("Format 0 DCI :ulsch (ue): TBS         %d\n",ulsch->harq_processes[harq_pid]->TBS);
    msg("Format 0 DCI :ulsch (ue): mcs         %d\n",ulsch->harq_processes[harq_pid]->mcs);
    msg("Format 0 DCI :ulsch (ue): O           %d\n",ulsch->O);
    if (frame_parms->frame_type == TDD)
      msg("Format 0 DCI :ulsch (ue): O_ACK/DAI   %d/%d\n",ulsch->harq_processes[harq_pid]->O_ACK,dai);
    else      
      msg("Format 0 DCI :ulsch (ue): O_ACK       %d\n",ulsch->harq_processes[harq_pid]->O_ACK);

    msg("Format 0 DCI :ulsch (ue): Nsymb_pusch   %d\n",ulsch->Nsymb_pusch);
    msg("Format 0 DCI :ulsch (ue): cshift        %d\n",ulsch->harq_processes[harq_pid]->n_DMRS2);
4480 4481
#else
    UNUSED_VARIABLE(dai);
4482 4483 4484 4485 4486
#endif
    return(0);
  }
  else {
    LOG_E(PHY,"frame %d, subframe %d: FATAL ERROR, generate_ue_ulsch_params_from_dci, Illegal dci_format %d\n",
Raymond Knopp's avatar
 
Raymond Knopp committed
4487
	  phy_vars_ue->frame_rx, subframe,dci_format);
4488 4489 4490 4491 4492 4493 4494
    return(-1);
  }

}

int generate_eNB_ulsch_params_from_dci(void *dci_pdu,
				       uint16_t rnti,
Raymond Knopp's avatar
 
Raymond Knopp committed
4495
				       uint8_t sched_subframe,
4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510
				       DCI_format_t dci_format,
				       uint8_t UE_id,
				       PHY_VARS_eNB *phy_vars_eNB,
				       uint16_t si_rnti,
				       uint16_t ra_rnti,
				       uint16_t p_rnti,
				       uint16_t cba_rnti,
				       uint8_t use_srs) {

  uint8_t harq_pid;
  uint32_t rb_alloc;
  uint8_t transmission_mode=phy_vars_eNB->transmission_mode[UE_id];
  ANFBmode_t AckNackFBMode = phy_vars_eNB->pucch_config_dedicated[UE_id].tdd_AckNackFeedbackMode;
  LTE_eNB_ULSCH_t *ulsch=phy_vars_eNB->ulsch_eNB[UE_id];
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->lte_frame_parms;
Raymond Knopp's avatar
 
Raymond Knopp committed
4511
  int subframe = phy_vars_eNB->proc[sched_subframe].subframe_tx;
4512

winckel's avatar
winckel committed
4513 4514 4515 4516 4517 4518 4519 4520
  uint32_t cqi_req = 0;
  uint32_t dai = 0;
  uint32_t cshift = 0;
  uint32_t TPC = 0;
  uint32_t ndi = 0;
  uint32_t mcs = 0;
  uint32_t rballoc = UINT32_MAX;
  uint32_t RIV_max = 0;
4521 4522 4523
  //  uint32_t hopping;
  //  uint32_t type;

Raymond Knopp's avatar
 
Raymond Knopp committed
4524 4525
#ifdef DEBUG_DCI
  LOG_D(PHY,"filling eNB ulsch params for rnti %x, dci format %d, dci %x, subframe %d\n",
4526
      rnti,dci_format,*(uint32_t*)dci_pdu,subframe);
Raymond Knopp's avatar
 
Raymond Knopp committed
4527
#endif
4528 4529 4530 4531 4532

  if (dci_format == format0) {

    harq_pid = subframe2harq_pid(frame_parms,			      
				 pdcch_alloc2ul_frame(frame_parms,
Raymond Knopp's avatar
 
Raymond Knopp committed
4533
						      phy_vars_eNB->proc[sched_subframe].frame_tx,
4534 4535 4536
						      subframe),
				 pdcch_alloc2ul_subframe(frame_parms,subframe));

Raymond Knopp's avatar
 
Raymond Knopp committed
4537
    //    printf("eNB: sched_subframe %d, subframe %d, frame_tx %d\n",sched_subframe,subframe,phy_vars_eNB->proc[sched_subframe].frame_tx);
4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646

    switch (frame_parms->N_RB_DL) {
    case 6:
      if (frame_parms->frame_type == TDD) {
	cqi_req = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->cqi_req;
	dai     = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->dai;
	cshift  = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_1_5MHz_TDD_1_6_t *)dci_pdu)->type;
      }
      else {
	cqi_req = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->cqi_req;
	cshift  = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_1_5MHz_FDD_t *)dci_pdu)->type;
      }
      RIV_max = RIV_max6;
      ulsch->harq_processes[harq_pid]->first_rb                              = RIV2first_rb_LUT6[rballoc];
      ulsch->harq_processes[harq_pid]->nb_rb                                 = RIV2nb_rb_LUT6[rballoc];

      break;
    case 25:
      if (frame_parms->frame_type == TDD) {
	cqi_req = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->cqi_req;
	dai     = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->dai;
	cshift  = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_5MHz_TDD_1_6_t *)dci_pdu)->type;
      }
      else {
	cqi_req = ((DCI0_5MHz_FDD_t *)dci_pdu)->cqi_req;
	cshift  = ((DCI0_5MHz_FDD_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_5MHz_FDD_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_5MHz_FDD_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_5MHz_FDD_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_5MHz_FDD_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_5MHz_FDD_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_5MHz_FDD_t *)dci_pdu)->type;
      }
      RIV_max = RIV_max25;
      ulsch->harq_processes[harq_pid]->first_rb                              = RIV2first_rb_LUT25[rballoc];
      ulsch->harq_processes[harq_pid]->nb_rb                                 = RIV2nb_rb_LUT25[rballoc];

      break;
    case 50:
      if (frame_parms->frame_type == TDD) {
	cqi_req = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->cqi_req;
	dai     = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->dai;
	cshift  = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_10MHz_TDD_1_6_t *)dci_pdu)->type;
      }
      else {
	cqi_req = ((DCI0_10MHz_FDD_t *)dci_pdu)->cqi_req;
	cshift  = ((DCI0_10MHz_FDD_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_10MHz_FDD_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_10MHz_FDD_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_10MHz_FDD_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_10MHz_FDD_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_10MHz_FDD_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_10MHz_FDD_t *)dci_pdu)->type;
      }
      RIV_max = RIV_max50;
      ulsch->harq_processes[harq_pid]->first_rb                              = RIV2first_rb_LUT50[rballoc];
      ulsch->harq_processes[harq_pid]->nb_rb                                 = RIV2nb_rb_LUT50[rballoc];

      break;
    case 100:
      if (frame_parms->frame_type == TDD) {
	cqi_req = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->cqi_req;
	dai     = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->dai;
	cshift  = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_20MHz_TDD_1_6_t *)dci_pdu)->type;
      }
      else {
	cqi_req = ((DCI0_20MHz_FDD_t *)dci_pdu)->cqi_req;
	cshift  = ((DCI0_20MHz_FDD_t *)dci_pdu)->cshift;
	TPC     = ((DCI0_20MHz_FDD_t *)dci_pdu)->TPC;
	ndi     = ((DCI0_20MHz_FDD_t *)dci_pdu)->ndi;
	mcs     = ((DCI0_20MHz_FDD_t *)dci_pdu)->mcs;
	rballoc = ((DCI0_20MHz_FDD_t *)dci_pdu)->rballoc;
	//	hopping = ((DCI0_20MHz_FDD_t *)dci_pdu)->hopping;
	//	type    = ((DCI0_20MHz_FDD_t *)dci_pdu)->type;
      }
      RIV_max = RIV_max100;
      ulsch->harq_processes[harq_pid]->first_rb                              = RIV2first_rb_LUT100[rballoc];
      ulsch->harq_processes[harq_pid]->nb_rb                                 = RIV2nb_rb_LUT100[rballoc];

winckel's avatar
winckel committed
4647 4648 4649 4650 4651 4652
      printf("eNB: rb_alloc (20 MHz dci) %d\n",rballoc);
      break;

    default:
      LOG_E(PHY,"Invalid N_RB_DL %d\n", frame_parms->N_RB_DL);
      DevParam (frame_parms->N_RB_DL, 0, 0);
4653 4654 4655 4656 4657 4658
      break;
    }
      
    rb_alloc = rballoc;
    if (rb_alloc>RIV_max) {
      LOG_E(PHY,"Format 0: rb_alloc > RIV_max\n");
Raymond Knopp's avatar
 
Raymond Knopp committed
4659
      mac_xface->macphy_exit("Format 0: rb_alloc > RIV_max\n");
4660 4661 4662
      return(-1);
    }

Raymond Knopp's avatar
 
Raymond Knopp committed
4663 4664 4665
#ifdef DEBUG_DCI
    LOG_D(PHY,"generate_eNB_ulsch_params_from_dci: subframe %d, rnti %x,harq_pid %d,ndi %d,cqi_req %d\n",subframe,rnti,harq_pid,ndi,cqi_req);
#endif
4666 4667 4668 4669

    ulsch->harq_processes[harq_pid]->dci_alloc                             = 1;
    ulsch->harq_processes[harq_pid]->rar_alloc                             = 0;
    ulsch->harq_processes[harq_pid]->TPC                                   = TPC;
4670
    //    ulsch->harq_processes[harq_pid]->Ndi                                   = ndi;
4671 4672 4673 4674 4675

    ulsch->harq_processes[harq_pid]->n_DMRS                                = cshift;                               


    if (cqi_req == 1) {
Raymond Knopp's avatar
 
Raymond Knopp committed
4676
      ulsch->harq_processes[harq_pid]->O_RI = 1; //we only support 2 antenna ports, so this is always 1 according to 3GPP 36.213 Table 
4677 4678 4679 4680
      switch(transmission_mode){ 
	// The aperiodic CQI reporting mode is fixed for every transmission mode instead of being configured by higher layer signaling
      case 1:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){ 
Raymond Knopp's avatar
 
Raymond Knopp committed
4681 4682 4683
	  ulsch->harq_processes[harq_pid]->Or2                                   = 0;
	  ulsch->harq_processes[harq_pid]->Or1                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_mcs_CBA;
4684 4685
	}
	else {
Raymond Knopp's avatar
 
Raymond Knopp committed
4686 4687 4688
	  ulsch->harq_processes[harq_pid]->Or2                                   = 0;
	  ulsch->harq_processes[harq_pid]->Or1                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_nopmi;
4689 4690 4691 4692
	}
	break;
      case 2:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){ 
Raymond Knopp's avatar
 
Raymond Knopp committed
4693 4694 4695
	  ulsch->harq_processes[harq_pid]->Or2                                   = 0;
	  ulsch->harq_processes[harq_pid]->Or1                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_mcs_CBA;
4696 4697
	}
	else {
Raymond Knopp's avatar
 
Raymond Knopp committed
4698 4699 4700
	  ulsch->harq_processes[harq_pid]->Or2                                   = 0;
	  ulsch->harq_processes[harq_pid]->Or1                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_nopmi;
4701 4702 4703 4704
	}
	break;
      case 3:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){ 
Raymond Knopp's avatar
 
Raymond Knopp committed
4705 4706 4707
	  ulsch->harq_processes[harq_pid]->Or2                                   = 0;
	  ulsch->harq_processes[harq_pid]->Or1                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_mcs_CBA;
4708 4709
	}
	else {
Raymond Knopp's avatar
 
Raymond Knopp committed
4710 4711 4712
	  ulsch->harq_processes[harq_pid]->Or2                                   = 0;
	  ulsch->harq_processes[harq_pid]->Or1                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_nopmi;
4713 4714 4715 4716
	}
	break;
      case 4:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){ 
Raymond Knopp's avatar
 
Raymond Knopp committed
4717 4718 4719
	  ulsch->harq_processes[harq_pid]->Or2                                   = 0;
	  ulsch->harq_processes[harq_pid]->Or1                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_mcs_CBA;
4720 4721
	}
	else {
Raymond Knopp's avatar
 
Raymond Knopp committed
4722 4723 4724
	  ulsch->harq_processes[harq_pid]->Or2                                 = sizeof_wideband_cqi_rank2_2A_5MHz;
	  ulsch->harq_processes[harq_pid]->Or1                                 = sizeof_wideband_cqi_rank1_2A_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                          = wideband_cqi_rank1_2A;
4725 4726 4727 4728
	}
	break;
      case 5:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){ 
Raymond Knopp's avatar
 
Raymond Knopp committed
4729 4730 4731
	  ulsch->harq_processes[harq_pid]->Or2                                   = 0;
	  ulsch->harq_processes[harq_pid]->Or1                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_mcs_CBA;
4732 4733
	}
	else {
Raymond Knopp's avatar
 
Raymond Knopp committed
4734 4735 4736
	  ulsch->harq_processes[harq_pid]->Or2                                 = sizeof_wideband_cqi_rank2_2A_5MHz;
	  ulsch->harq_processes[harq_pid]->Or1                                 = sizeof_wideband_cqi_rank1_2A_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                          = wideband_cqi_rank1_2A;
4737 4738 4739 4740
	}
	break;
      case 6:
	if ((rnti >= cba_rnti) && (rnti < p_rnti)){ 
Raymond Knopp's avatar
 
Raymond Knopp committed
4741 4742 4743
	  ulsch->harq_processes[harq_pid]->Or2                                   = 0;
	  ulsch->harq_processes[harq_pid]->Or1                                   = sizeof_HLC_subband_cqi_mcs_CBA_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_mcs_CBA;
4744 4745
	}
	else {
Raymond Knopp's avatar
 
Raymond Knopp committed
4746 4747 4748
	  ulsch->harq_processes[harq_pid]->Or2                                 = sizeof_wideband_cqi_rank2_2A_5MHz;
	  ulsch->harq_processes[harq_pid]->Or1                                 = sizeof_wideband_cqi_rank1_2A_5MHz;
	  ulsch->harq_processes[harq_pid]->uci_format                          = wideband_cqi_rank1_2A;
4749 4750 4751
	}
	break;
      case 7:
Raymond Knopp's avatar
 
Raymond Knopp committed
4752 4753 4754
	ulsch->harq_processes[harq_pid]->Or2                                   = 0;
	ulsch->harq_processes[harq_pid]->Or1                                   = sizeof_HLC_subband_cqi_nopmi_5MHz;
	ulsch->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_nopmi;
4755 4756 4757 4758 4759 4760 4761
	break;
      default:
	LOG_E(PHY,"Incorrect Transmission Mode \n");
	break;
      }
    }
    else {
Raymond Knopp's avatar
 
Raymond Knopp committed
4762 4763 4764 4765
      ulsch->harq_processes[harq_pid]->O_RI = 0;//1;
      ulsch->harq_processes[harq_pid]->Or2                                   = 0;
      ulsch->harq_processes[harq_pid]->Or1                                   = 0;//sizeof_HLC_subband_cqi_nopmi_5MHz;
      ulsch->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_nopmi;
4766 4767
    }

Raymond Knopp's avatar
 
Raymond Knopp committed
4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783
    if (frame_parms->frame_type == FDD) {
      int dl_subframe = (subframe<4) ? (subframe+6) : (subframe-4);
      if (phy_vars_eNB->dlsch_eNB[UE_id][0]->subframe_tx[dl_subframe]>0) { // we have downlink transmission
	ulsch->harq_processes[harq_pid]->O_ACK = 1;
      }
      else {
	ulsch->harq_processes[harq_pid]->O_ACK = 0;
      }
    } else {
      if (ulsch->bundling)
	ulsch->harq_processes[harq_pid]->O_ACK = (dai == 3)? 0 : 1;
      else
	ulsch->harq_processes[harq_pid]->O_ACK = (dai+1)&3;
      
      ulsch->harq_processes[harq_pid]->V_UL_DAI = dai+1;
    }
4784 4785 4786 4787 4788

    ulsch->beta_offset_cqi_times8                = beta_cqi[phy_vars_eNB->pusch_config_dedicated[UE_id].betaOffset_CQI_Index];//18;
    ulsch->beta_offset_ri_times8                 = beta_ri[phy_vars_eNB->pusch_config_dedicated[UE_id].betaOffset_RI_Index];//10;
    ulsch->beta_offset_harqack_times8            = beta_ack[phy_vars_eNB->pusch_config_dedicated[UE_id].betaOffset_ACK_Index];//16;

Raymond Knopp's avatar
 
Raymond Knopp committed
4789 4790
    ulsch->harq_processes[harq_pid]->Nsymb_pusch                             = 12-(frame_parms->Ncp<<1)-(use_srs==0?0:1);
    ulsch->harq_processes[harq_pid]->srs_active                            = use_srs;
4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811
    ulsch->bundling = 1-AckNackFBMode;
    //Mapping of cyclic shift field in DCI format0 to n_DMRS2 (3GPP 36.211, Table 5.5.2.1.1-1)
    if(cshift == 0)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 0;
    else if(cshift == 1)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 6;
    else if(cshift == 2)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 3;
    else if(cshift == 3)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 4;
    else if(cshift == 4)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 2;
    else if(cshift == 5)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 8;
    else if(cshift == 6)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 10;
    else if(cshift == 7)
      ulsch->harq_processes[harq_pid]->n_DMRS2 = 9;


    LOG_D(PHY,"[eNB %d][PUSCH %d] Frame %d, subframe %d : Programming PUSCH with n_DMRS2 %d (cshift %d)\n",
Raymond Knopp's avatar
 
Raymond Knopp committed
4812
	  phy_vars_eNB->Mod_id,harq_pid,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,ulsch->harq_processes[harq_pid]->n_DMRS2,cshift);
4813 4814 4815



4816
    if (ulsch->harq_processes[harq_pid]->round == 0) {
4817
      if ((rnti >= cba_rnti) && (rnti < p_rnti))
4818
	ulsch->harq_processes[harq_pid]->status = CBA_ACTIVE;
4819
      else 
4820
	ulsch->harq_processes[harq_pid]->status = ACTIVE;
4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834
      ulsch->harq_processes[harq_pid]->rvidx = 0;
      ulsch->harq_processes[harq_pid]->mcs         = mcs;
      //      ulsch->harq_processes[harq_pid]->calibration_flag = 0;
      //if (ulsch->harq_processes[harq_pid]->mcs)
      /*
	if (ulsch->harq_processes[harq_pid]->mcs == 29) {
	ulsch->harq_processes[harq_pid]->mcs = 4;
	//	ulsch->harq_processes[harq_pid]->calibration_flag = 1;
	//	printf("Auto-Calibration (eNB): mcs %d, nb_rb %d\n",ulsch->harq_processes[harq_pid]->mcs,ulsch->harq_processes[harq_pid]->nb_rb);
	}
      */
      ulsch->harq_processes[harq_pid]->TBS         = TBStable[get_I_TBS_UL(ulsch->harq_processes[harq_pid]->mcs)][ulsch->harq_processes[harq_pid]->nb_rb-1];
     
      ulsch->harq_processes[harq_pid]->Msc_initial   = 12*ulsch->harq_processes[harq_pid]->nb_rb;
Raymond Knopp's avatar
 
Raymond Knopp committed
4835
      ulsch->harq_processes[harq_pid]->Nsymb_initial = ulsch->harq_processes[harq_pid]->Nsymb_pusch;
4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857
      ulsch->harq_processes[harq_pid]->round = 0;
    }
    else {
      if (mcs>28)
	ulsch->harq_processes[harq_pid]->rvidx = mcs - 28;
      else {
	ulsch->harq_processes[harq_pid]->rvidx = 0;
	ulsch->harq_processes[harq_pid]->mcs = mcs;
      }
      //      ulsch->harq_processes[harq_pid]->round++;
    }
    if ((rnti >= cba_rnti) && (rnti < p_rnti)){ 
      ulsch->cba_rnti[0] = rnti;
    }else{
      ulsch->rnti = rnti;      
    }
    //ulsch->n_DMRS2 = cshift;

#ifdef DEBUG_DCI
    msg("ulsch (eNB): NBRB          %d\n",ulsch->harq_processes[harq_pid]->nb_rb);
    msg("ulsch (eNB): first_rb      %d\n",ulsch->harq_processes[harq_pid]->first_rb);
    msg("ulsch (eNB): harq_pid      %d\n",harq_pid);
4858
    msg("ulsch (eNB): round         %d\n",ulsch->harq_processes[harq_pid]->round);
4859 4860
    msg("ulsch (eNB): TBS           %d\n",ulsch->harq_processes[harq_pid]->TBS);
    msg("ulsch (eNB): mcs           %d\n",ulsch->harq_processes[harq_pid]->mcs);
Raymond Knopp's avatar
 
Raymond Knopp committed
4861 4862
    msg("ulsch (eNB): Or1           %d\n",ulsch->harq_processes[harq_pid]->Or1);
    msg("ulsch (eNB): Nsymb_pusch   %d\n",ulsch->harq_processes[harq_pid]->Nsymb_pusch);
4863
    msg("ulsch (eNB): cshift        %d\n",ulsch->harq_processes[harq_pid]->n_DMRS2);
4864 4865
#else
    UNUSED_VARIABLE(dai);
4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876
#endif
    return(0);
  }
  else {
    LOG_E(PHY,"generate_eNB_ulsch_params_from_dci, Illegal dci_format %d\n",dci_format);
    return(-1);
  }

}


4877 4878
double sinr_eff_cqi_calc(PHY_VARS_UE *phy_vars_ue, uint8_t eNB_id){
  uint8_t transmission_mode = phy_vars_ue->transmission_mode[eNB_id];
4879 4880
  PHY_MEASUREMENTS *meas = &phy_vars_ue->PHY_measurements;
  LTE_DL_FRAME_PARMS *frame_parms =  &phy_vars_ue->lte_frame_parms;
4881
  int32_t **dl_channel_est = phy_vars_ue->lte_ue_common_vars.dl_ch_estimates[eNB_id];
4882 4883 4884 4885 4886
  double *s_dB;
  s_dB = phy_vars_ue->sinr_CQI_dB;   
  //  LTE_UE_ULSCH_t *ulsch  = phy_vars_ue->ulsch_ue[eNB_id]; 
  //for the calculation of SINR_eff for CQI calculation
  int count,a_rx,a_tx;
4887 4888 4889 4890 4891
  double abs_channel=0;
  double channelx=0;
  double channely=0;
  double channelx_i=0;
  double channely_i=0;
4892 4893
  uint16_t q = quantize_subband_pmi(meas,eNB_id);
  uint8_t qq;
4894 4895 4896 4897 4898
  
  switch(transmission_mode){
  case 1:
    for (count=0;count<frame_parms->N_RB_DL*12;count++)
      {
4899
	for(a_tx=0;a_tx<frame_parms->nb_antennas_tx_eNB;a_tx++)
4900 4901 4902
	  { 
	    for (a_rx=0;a_rx<frame_parms->nb_antennas_rx;a_rx++)
	      {
4903
		s_dB[count] = 10*log10(pow(((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2],2) + pow(((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2],2)) - meas->n0_power_avg_dB;    
4904 4905 4906
	      }
	  }
      }
4907 4908 4909 4910 4911 4912 4913
    break;
  case 2:
    for (count=0;count<frame_parms->N_RB_DL*12;count++)
      {abs_channel=0;
	for(a_tx=0;a_tx<frame_parms->nb_antennas_tx_eNB;a_tx++)
	  { 
	    for (a_rx=0;a_rx<frame_parms->nb_antennas_rx;a_rx++)
4914
	      {
4915
		abs_channel += (pow(((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2],2) + pow(((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2],2)); 
4916
	      }
4917 4918 4919 4920
	  }
	s_dB[count] = 10*log10(abs_channel/2) - meas->n0_power_avg_dB;
      }
    break;
4921 4922
  case 5:
    for (count=0;count<frame_parms->N_RB_DL*12;count++){
4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935
      channelx=0;
      channely=0;
      channelx_i=0;
      channely_i=0;
      qq = (q>>(((count/12)>>2)<<1))&3;
      //printf("pmi_alloc %d: rb %d, pmi %d\n",q,count/12,qq);
      for(a_tx=0;a_tx<frame_parms->nb_antennas_tx_eNB;a_tx++)
	{ 
	  for (a_rx=0;a_rx<frame_parms->nb_antennas_rx;a_rx++)
	    {
	      switch(qq){
	      case 0:
		if (channelx==0 || channely==0){
4936 4937 4938 4939
		  channelx = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		  channelx_i = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely_i = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];	
4940 4941 4942
		}
		else
		  {
4943 4944 4945 4946
		    channelx += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		    channely += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		    channelx_i -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		    channely_i -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];	
4947
		  }
4948 4949 4950
		break;
	      case 1:
		if (channelx==0 || channely==0){
4951 4952 4953 4954
		  channelx = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		  channelx_i = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely_i = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];	
4955 4956 4957
		}
		else
		  {
4958 4959 4960 4961
		    channelx -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		    channely -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		    channelx_i += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		    channely_i += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];	
4962
		  }
4963 4964 4965
		break;
	      case 2:
		if (channelx==0 || channely==0){
4966 4967 4968 4969
		  channelx = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		  channelx_i = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely_i = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];	
4970 4971 4972
		}
		else
		  {
4973 4974 4975 4976
		    channelx -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		    channely += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		    channelx_i += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		    channely_i -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];	
4977
		  }
4978 4979 4980
		break;
	      case 3:
		if (channelx==0 || channely==0){
4981 4982 4983 4984
		  channelx = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		  channelx_i = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely_i = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];	
4985 4986 4987
		}
		else
		  {
4988 4989 4990 4991
		    channelx += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		    channely -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		    channelx_i -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		    channely_i += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];	
4992
		  }
4993 4994 4995 4996 4997 4998 4999
		break;
	      default:
		msg("Problem in SINR Calculation for TM5 \n");
		break;
	      }//switch(qq)
	    }//a_rx
	}//a_tx
5000
	
5001
      s_dB[count] =  10 * log10 ((pow(channelx,2) + pow(channely,2))/2) - 10 * log10 ((pow(channelx_i,2) + pow(channely_i,2))/2) - meas->n0_power_avg_dB;
5002 5003 5004
    }//count
    break;
  case 6:
5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016
    for (count=0;count<frame_parms->N_RB_DL*12;count++){
      channelx=0;
      channely=0;
      qq = (q>>(((count/12)>>2)<<1))&3;
      //printf("pmi_alloc %d: rb %d, pmi %d\n",q,count/12,qq);
      for(a_tx=0;a_tx<frame_parms->nb_antennas_tx_eNB;a_tx++)
	{ 
	  for (a_rx=0;a_rx<frame_parms->nb_antennas_rx;a_rx++)
	    {
	      switch(qq){
	      case 0:
		if (channelx==0 || channely==0){
5017 5018
		  channelx = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
5019 5020 5021
		}
		else
		  {
5022 5023
		    channelx += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		    channely += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
5024
		  }
5025 5026 5027
		break; 
	      case 1:
		if (channelx==0 || channely==0){
5028 5029
		  channelx = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
5030 5031 5032
		}
		else
		  {
5033 5034
		    channelx -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		    channely -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
5035
		  }
5036 5037 5038
		break;
	      case 2:
		if (channelx==0 || channely==0){
5039 5040
		  channelx = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
5041 5042 5043
		}
		else
		  {
5044 5045
		    channelx -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		    channely += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
5046
		  }
5047 5048 5049
		break;
	      case 3:
		if (channelx==0 || channely==0){
5050 5051
		  channelx = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
		  channely = ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
5052 5053 5054
		}
		else
		  {
5055 5056
		    channelx += ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+1+(LTE_CE_FILTER_LENGTH)*2];
		    channely -= ((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count+(LTE_CE_FILTER_LENGTH)*2];
5057
		  }
5058 5059 5060 5061 5062 5063 5064
		break;
	      default:
		msg("Problem in SINR Calculation for TM6 \n");
		break;
	      }//switch(qq)
	    }//a_rx
	}//a_tx
5065
	
5066
      s_dB[count] =  10 * log10 ((pow(channelx,2) + pow(channely,2))/2) - meas->n0_power_avg_dB;
5067
    }//count
5068 5069 5070 5071
    break;
  default:
    msg("Problem in SINR Calculation for CQI \n");
    break;
5072
  }
5073
  int ii;
5074
  double sinr_eff = 0;
5075 5076 5077
  double sinr_eff_qpsk=0;
  double sinr_eff_qam16=0;
  double sinr_eff_qam64=0;
5078
  double x = 0;
5079 5080 5081 5082 5083 5084
  double I_qpsk=0;
  double I_qam16=0;
  double I_qam64=0;
  double I_qpsk_avg=0;
  double I_qam16_avg=0;
  double I_qam64_avg=0;
5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120
  double qpsk_max=12.2;
  double qam16_max=19.2;
  double qam64_max=25.2;
  double sinr_min = -20;
  int offset=0;
  
  
  for (offset = 0; offset <= 24; offset++) {
    for(ii=0;ii<12;ii++){
      //x is the sinr_dB in dB
      x = s_dB[(offset*12)+ii];
      if(x<sinr_min){
	I_qpsk +=0;
	I_qam16 +=0;
	I_qam64 +=0;
      }
      else{
	if(x>qpsk_max)
	  I_qpsk += 1;
	else
	  I_qpsk += (q_qpsk[0]*pow(x,7) + q_qpsk[1]*pow(x,6) + q_qpsk[2]*pow(x,5) + q_qpsk[3]*pow(x,4) + q_qpsk[4]*pow(x,3) + q_qpsk[5]*pow(x,2) + q_qpsk[6]*x + q_qpsk[7]);
	
	if(x>qam16_max)
	  I_qam16 += 1;
	else
	  I_qam16 += (q_qam16[0]*pow(x,7) + q_qam16[1]*pow(x,6) + q_qam16[2]*pow(x,5) + q_qam16[3]*pow(x,4) + q_qam16[4]*pow(x,3) + q_qam16[5]*pow(x,2) + q_qam16[6]*x + q_qam16[7]);
	
	if(x>qam64_max)
	  I_qam64 += 1;
	else
	  I_qam64 += (q_qam64[0]*pow(x,7) + q_qam64[1]*pow(x,6) + q_qam64[2]*pow(x,5) + q_qam64[3]*pow(x,4) + q_qam64[4]*pow(x,3) + q_qam64[5]*pow(x,2) + q_qam64[6]*x + q_qam64[7]);
	
      }
    }
  }
  
5121
  // averaging of accumulated MI 
5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134
  I_qpsk_avg = I_qpsk/(12*frame_parms->N_RB_DL);  
  I_qam16_avg = I_qam16/(12*frame_parms->N_RB_DL);  
  I_qam64_avg = I_qam64/(12*frame_parms->N_RB_DL);  
  
  // I->SINR_effective Mapping
  
  sinr_eff_qpsk = (p_qpsk[0]*pow(I_qpsk_avg,7) + p_qpsk[1]*pow(I_qpsk_avg,6) + p_qpsk[2]*pow(I_qpsk_avg,5) + p_qpsk[3]*pow(I_qpsk_avg,4) + p_qpsk[4]*pow(I_qpsk_avg,3) + p_qpsk[5]*pow(I_qpsk_avg,2) + p_qpsk[6]*I_qpsk_avg + p_qpsk[7]);
  
  sinr_eff_qam16 = (p_qam16[0]*pow(I_qam16_avg,7) + p_qam16[1]*pow(I_qam16_avg,6) + p_qam16[2]*pow(I_qam16_avg,5) + p_qam16[3]*pow(I_qam16_avg,4) + p_qam16[4]*pow(I_qam16_avg,3) + p_qam16[5]*pow(I_qam16_avg,2) + p_qam16[6]*I_qam16_avg + p_qam16[7]);
  
  sinr_eff_qam64 = (p_qam64[0]*pow(I_qam64_avg,7) + p_qam64[1]*pow(I_qam64_avg,6) + p_qam64[2]*pow(I_qam64_avg,5) + p_qam64[3]*pow(I_qam64_avg,4) + p_qam64[4]*pow(I_qam64_avg,3) + p_qam64[5]*pow(I_qam64_avg,2) + p_qam64[6]*I_qam64_avg + p_qam64[7]);
  sinr_eff = cmax3(sinr_eff_qpsk,sinr_eff_qam16,sinr_eff_qam64);
  
5135
  //msg("SINR_Eff = %e\n",sinr_eff);
5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179
  
  return(sinr_eff);
}
//


#ifdef DEBUG_DLSCH_TOOLS
main() {

  int i;
  uint8_t rah;
  uint32_t rballoc;

  generate_RIV_tables();

  for (i=0;i<512;i++) {
    msg("RIV %d: nb_rb %d, alloc %x, alloc_dist %x\n",
	i,
	RIV2nb_rb_LUT25[i],
	localRIV2alloc_LUT25[i],
	distRIV2alloc_LUT25[i]);

  }

  rah = 0;
  rballoc = 0x1fff;
  msg("rballoc 0 %x => %x\n",rballoc,conv_rballoc(rah,rballoc));
  rah = 1;

  rballoc = 0x1678;
  msg("rballoc 1 %x => %x\n",rballoc,conv_rballoc(rah,rballoc));

  rballoc = 0xfffc;
  msg("rballoc 1 %x => %x\n",rballoc,conv_rballoc(rah,rballoc));
  rballoc = 0xfffd;
  msg("rballoc 1 %x => %x\n",rballoc,conv_rballoc(rah,rballoc));
  rballoc = 0xffff;
  msg("rballoc 1 %x => %x\n",rballoc,conv_rballoc(rah,rballoc));
  rballoc = 0xfffe;
  msg("rballoc 1 %x => %x\n",rballoc,conv_rballoc(rah,rballoc));
}

#endif