eNB_scheduler_primitives.c 156 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
Cedric Roux's avatar
Cedric Roux committed
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

nikaeinn's avatar
nikaeinn committed
22 23
/*! \file eNB_scheduler_primitives.c
 * \brief primitives used by eNB for BCH, RACH, ULSCH, DLSCH scheduling
24 25 26
 * \author  Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
 * \email: navid.nikaein@eurecom.fr
nikaeinn's avatar
nikaeinn committed
27
 * \version 1.0
28 29 30 31 32 33
 * @ingroup _mac

 */

#include "assertions.h"

34 35
#include "LAYER2/MAC/mac.h"
#include "LAYER2/MAC/mac_extern.h"
36

37
#include "LAYER2/MAC/mac_proto.h"
38 39
#include "common/utils/LOG/log.h"
#include "common/utils/LOG/vcd_signal_dumper.h"
40 41 42 43
#include "UTIL/OPT/opt.h"
#include "OCG.h"
#include "OCG_extern.h"

44
#include "RRC/LTE/rrc_extern.h"
45 46 47 48 49 50
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"

//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"

#if defined(ENABLE_ITTI)
51
#include "intertask_interface.h"
52 53
#endif

Cedric Roux's avatar
Cedric Roux committed
54 55
#include "T.h"

56 57
#define ENABLE_MAC_PAYLOAD_DEBUG
#define DEBUG_eNB_SCHEDULER 1
jftt_wangshanshan's avatar
jftt_wangshanshan committed
58
extern uint16_t frame_cnt;
59

60
#include "common/ran_context.h"
61
#include "SCHED/sched_common.h"
62 63 64

extern RAN_CONTEXT_t RC;

65 66
extern int n_active_slices;

67
int choose(int n, int k)
Cedric Roux's avatar
Cedric Roux committed
68
{
69 70 71
  int res = 1;
  int res2 = 1;
  int i;
72

73 74 75 76
  if (k > n)
    return (0);
  if (n == k)
    return (1);
77

78 79 80 81
  for (i = n; i > k; i--)
    res *= i;
  for (i = 2; i <= (n - k); i++)
    res2 *= i;
82

83
  return (res / res2);
84 85 86
}

// Patented algorithm from Yang et al, US Patent 2009, "Channel Quality Indexing and Reverse Indexing"
87 88
void reverse_index(int N, int M, int r, int *v)
{
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
  int BaseValue = 0;
  int IncreaseValue, ThresholdValue;
  int sumV;
  int i;

  r = choose(N, M) - 1 - r;
  memset((void *) v, 0, M * sizeof(int));

  sumV = 0;
  i = M;
  while (i > 0 && r > 0) {
    IncreaseValue = choose(N - M + 1 - sumV - v[i - 1] + i - 2, i - 1);
    ThresholdValue = BaseValue + IncreaseValue;
    if (r >= ThresholdValue) {
      v[i - 1]++;
      BaseValue = ThresholdValue;
    } else {
      r = r - BaseValue;
      sumV += v[i - 1];
      i--;
      BaseValue = 0;
110
    }
111
  }
112
}
Cedric Roux's avatar
Cedric Roux committed
113 114 115

int to_prb(int dl_Bandwidth)
{
116
  int prbmap[6] = { 6, 15, 25, 50, 75, 100 };
117

118 119
  AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth is 0..5\n");
  return (prbmap[dl_Bandwidth]);
knopp's avatar
knopp committed
120 121
}

Cedric Roux's avatar
Cedric Roux committed
122 123
int to_rbg(int dl_Bandwidth)
{
124
  int rbgmap[6] = { 6, 8, 13, 17, 19, 25 };
knopp's avatar
knopp committed
125

126 127
  AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth is 0..5\n");
  return (rbgmap[dl_Bandwidth]);
knopp's avatar
knopp committed
128
}
129

130
int get_phich_resource_times6(COMMON_channels_t * cc)
Cedric Roux's avatar
Cedric Roux committed
131
{
132 133 134 135 136 137 138 139 140
  int phichmap[4] = { 1, 3, 6, 12 };
  AssertFatal(cc != NULL, "cc is null\n");
  AssertFatal(cc->mib != NULL, "cc->mib is null\n");
  AssertFatal((cc->mib->message.phich_Config.phich_Resource >= 0) &&
	      (cc->mib->message.phich_Config.phich_Resource < 4),
	      "phich_Resource %d not in 0..3\n",
	      (int) cc->mib->message.phich_Config.phich_Resource);

  return (phichmap[cc->mib->message.phich_Config.phich_Resource]);
141 142
}

143
uint16_t mac_computeRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs)
Cedric Roux's avatar
Cedric Roux committed
144
{
145
  uint16_t RIV;
146

147 148
  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);
149

150
  return (RIV);
151 152
}

Cedric Roux's avatar
Cedric Roux committed
153 154
uint8_t getQm(uint8_t mcs)
{
155 156 157
  if (mcs < 10)      return (2);
  else if (mcs < 17) return (4);
  else               return (6);
158 159
}

160
void
161 162 163 164 165
get_Msg3alloc(COMMON_channels_t *cc,
	      sub_frame_t       current_subframe,
	      frame_t           current_frame, 
	      frame_t           *frame,
	      sub_frame_t       *subframe)
166
{
167
  // Fill in other TDD Configuration!!!!
168

169 170
  if (cc->tdd_Config == NULL) {	// FDD
    *subframe = current_subframe + 6;
171

172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
    if (*subframe > 9) {
      *subframe = *subframe - 10;
      *frame = (current_frame + 1) & 1023;
    } else {
      *frame = current_frame;
    }
  } else {			// TDD
    if (cc->tdd_Config->subframeAssignment == 1) {
      switch (current_subframe) {
	  
      case 0:
	*subframe = 7;
	*frame = current_frame;
	break;

      case 4:
	*subframe = 2;
	*frame = (current_frame + 1) & 1023;
	break;

      case 5:
	*subframe = 2;
	*frame = (current_frame + 1) & 1023;
	break;

      case 9:
	*subframe = 7;
	*frame = (current_frame + 1) & 1023;
	break;
      }
    } else if (cc->tdd_Config->subframeAssignment == 3) {
      switch (current_subframe) {

      case 0:
      case 5:
      case 6:
	*subframe = 2;
	*frame = (current_frame + 1) & 1023;
	break;

      case 7:
	*subframe = 3;
	*frame = (current_frame + 1) & 1023;
	break;

      case 8:
	*subframe = 4;
	*frame = (current_frame + 1) & 1023;
	break;

      case 9:
	*subframe = 2;
	*frame = (current_frame + 2) & 1023;
	break;
      }
    } else if (cc->tdd_Config->subframeAssignment == 4) {
      switch (current_subframe) {

      case 0:
      case 4:
      case 5:
      case 6:
	*subframe = 2;
	*frame = (current_frame + 1) & 1023;
	break;

      case 7:
	*subframe = 3;
	*frame = (current_frame + 1) & 1023;
	break;

      case 8:
      case 9:
	*subframe = 2;
	*frame = (current_frame + 2) & 1023;
	break;
      }
    } else if (cc->tdd_Config->subframeAssignment == 5) {
      switch (current_subframe) {

      case 0:
      case 4:
      case 5:
      case 6:
	*subframe = 2;
	*frame = (current_frame + 1) & 1023;
	break;

      case 7:
      case 8:
      case 9:
	*subframe = 2;
	*frame = (current_frame + 2) & 1023;
	break;
      }
Cedric Roux's avatar
Cedric Roux committed
267
    }
268
  }
269 270
}

271 272


273 274 275 276 277
void
get_Msg3allocret(COMMON_channels_t * cc,
		 sub_frame_t current_subframe,
		 frame_t current_frame,
		 frame_t * frame, sub_frame_t * subframe)
278
{
279 280 281
  if (cc->tdd_Config == NULL) {	//FDD
    /* always retransmit in n+8 */
    *subframe = current_subframe + 8;
282

283 284 285
    if (*subframe > 9) {
      *subframe = *subframe - 10;
      *frame = (current_frame + 1) & 1023;
286
    } else {
287
      *frame = current_frame;
288
    }
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
  } else {
    if (cc->tdd_Config->subframeAssignment == 1) {
      // original PUSCH in 2, PHICH in 6 (S), ret in 2
      // original PUSCH in 3, PHICH in 9, ret in 3
      // original PUSCH in 7, PHICH in 1 (S), ret in 7
      // original PUSCH in 8, PHICH in 4, ret in 8
      *frame = (current_frame + 1) & 1023;
    } else if (cc->tdd_Config->subframeAssignment == 3) {
      // original PUSCH in 2, PHICH in 8, ret in 2 next frame
      // original PUSCH in 3, PHICH in 9, ret in 3 next frame
      // original PUSCH in 4, PHICH in 0, ret in 4 next frame
      *frame = (current_frame + 1) & 1023;
    } else if (cc->tdd_Config->subframeAssignment == 4) {
      // original PUSCH in 2, PHICH in 8, ret in 2 next frame
      // original PUSCH in 3, PHICH in 9, ret in 3 next frame
      *frame = (current_frame + 1) & 1023;
    } else if (cc->tdd_Config->subframeAssignment == 5) {
      // original PUSCH in 2, PHICH in 8, ret in 2 next frame
      *frame = (current_frame + 1) & 1023;
    }
  }
310 311
}

312 313 314
uint8_t
subframe2harqpid(COMMON_channels_t * cc, frame_t frame,
		 sub_frame_t subframe)
315
{
316
  uint8_t ret = 255;
317

318
  AssertFatal(cc != NULL, "cc is null\n");
319

320 321 322 323 324 325 326 327
  if (cc->tdd_Config == NULL) {	// FDD
    ret = (((frame << 1) + subframe) & 7);
  } else {
    switch (cc->tdd_Config->subframeAssignment) {
    case 1:
      if ((subframe == 2) ||
	  (subframe == 3) || (subframe == 7) || (subframe == 8))
	switch (subframe) {
328 329
	case 2:
	case 3:
330 331 332 333 334 335
	  ret = (subframe - 2);
	  break;
	case 7:
	case 8:
	  ret = (subframe - 5);
	  break;
336
	default:
337 338 339 340 341
	  AssertFatal(1 == 0,
		      "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
		      subframe,
		      (int) cc->tdd_Config->subframeAssignment);
	  break;
342
	}
343

344
      break;
345

346 347 348 349 350
    case 2:
      AssertFatal((subframe == 2) || (subframe == 7),
		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
		  subframe,
		  (int) cc->tdd_Config->subframeAssignment);
351

352 353
      ret = (subframe / 7);
      break;
354

355 356 357 358 359 360 361
    case 3:
      AssertFatal((subframe > 1) && (subframe < 5),
		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
		  subframe,
		  (int) cc->tdd_Config->subframeAssignment);
      ret = (subframe - 2);
      break;
362

363 364 365 366 367 368 369
    case 4:
      AssertFatal((subframe > 1) && (subframe < 4),
		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
		  subframe,
		  (int) cc->tdd_Config->subframeAssignment);
      ret = (subframe - 2);
      break;
370

371 372 373 374
    case 5:
      AssertFatal(subframe == 2,
		  "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",
		  subframe,
375
		  (int) cc->tdd_Config->subframeAssignment);
376 377 378 379 380 381 382
      ret = (subframe - 2);
      break;

    default:
      AssertFatal(1 == 0,
		  "subframe2_harq_pid, Unsupported TDD mode %d\n",
		  (int) cc->tdd_Config->subframeAssignment);
383
    }
384 385
  }
  return ret;
386
}
387

388 389 390 391
uint8_t
get_Msg3harqpid(COMMON_channels_t * cc,
		frame_t frame, sub_frame_t current_subframe)
{
392 393
  uint8_t ul_subframe = 0;
  uint32_t ul_frame = 0;
394

395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 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
  if (cc->tdd_Config == NULL) {	// FDD
    ul_subframe =
      (current_subframe >
       3) ? (current_subframe - 4) : (current_subframe + 6);
    ul_frame = (current_subframe > 3) ? ((frame + 1) & 1023) : frame;
  } else {
    switch (cc->tdd_Config->subframeAssignment) {
    case 1:
      switch (current_subframe) {
      case 9:
      case 0:
	ul_subframe = 7;
	break;
      case 5:
      case 7:
	ul_subframe = 2;
	break;
      }
      break;
    case 3:
      switch (current_subframe) {
      case 0:
      case 5:
      case 6:
	ul_subframe = 2;
	break;
      case 7:
	ul_subframe = 3;
	break;
      case 8:
	ul_subframe = 4;
	break;
      case 9:
	ul_subframe = 2;
	break;
      }
      break;
    case 4:
      switch (current_subframe) {
      case 0:
      case 5:
      case 6:
      case 8:
      case 9:
	ul_subframe = 2;
	break;
      case 7:
	ul_subframe = 3;
	break;
      }
      break;
    case 5:
      ul_subframe = 2;
      break;
    default:
      LOG_E(PHY,
	    "get_Msg3_harq_pid: Unsupported TDD configuration %d\n",
	    (int) cc->tdd_Config->subframeAssignment);
      AssertFatal(1 == 0,
		  "get_Msg3_harq_pid: Unsupported TDD configuration");
      break;
456
    }
457
  }
Cedric Roux's avatar
Cedric Roux committed
458

459
  return (subframe2harqpid(cc, ul_frame, ul_subframe));
460
}
461

462 463 464
uint32_t
pdcchalloc2ulframe(COMMON_channels_t * ccP, uint32_t frame, uint8_t n)
{
465
  uint32_t ul_frame;
466

467 468 469 470 471 472 473 474 475 476
  if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6)))	// tdd_config 0,1 SF 1,5
    ul_frame = (frame + (n == 1 ? 0 : 1));
  else if ((ccP->tdd_Config) &&
	   (ccP->tdd_Config->subframeAssignment == 6) &&
	   ((n == 0) || (n == 1) || (n == 5) || (n == 6)))
    ul_frame = (frame + (n >= 5 ? 1 : 0));
  else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9))	// tdd_config 6 SF 9
    ul_frame = (frame + 1);
  else
    ul_frame = (frame + (n >= 6 ? 1 : 0));
477

478 479 480
  LOG_D(PHY, "frame %d subframe %d: PUSCH frame = %d\n", frame, n,
	ul_frame);
  return ul_frame;
481
}
482

483 484
uint8_t pdcchalloc2ulsubframe(COMMON_channels_t * ccP, uint8_t n)
{
485
  uint8_t ul_subframe;
486

487 488 489 490 491 492 493 494 495 496
  if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6)))	// tdd_config 0,1 SF 1,5
    ul_subframe = ((n + 6) % 10);
  else if ((ccP->tdd_Config) &&
	   (ccP->tdd_Config->subframeAssignment == 6) &&
	   ((n == 0) || (n == 1) || (n == 5) || (n == 6)))
    ul_subframe = ((n + 7) % 10);
  else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9))	// tdd_config 6 SF 9
    ul_subframe = ((n + 5) % 10);
  else
    ul_subframe = ((n + 4) % 10);
497

498 499
  LOG_D(PHY, "subframe %d: PUSCH subframe = %d\n", n, ul_subframe);
  return ul_subframe;
500 501
}

502
int is_UL_sf(COMMON_channels_t * ccP, sub_frame_t subframeP)
503
{
504 505 506
  // if FDD return dummy value
  if (ccP->tdd_Config == NULL)
    return (0);
507

508 509 510 511
  switch (ccP->tdd_Config->subframeAssignment) {
  case 1:
    switch (subframeP) {
    case 0:
512 513
    case 4:
    case 5:
514 515 516 517 518 519 520 521 522
    case 9:
      return (0);
      break;
    case 2:
    case 3:
    case 7:
    case 8:
      return (1);
      break;
523
    default:
524 525
      return (0);
      break;
526
    }
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
    break;
  case 3:
    if ((subframeP <= 1) || (subframeP >= 5))
      return (0);
    else if ((subframeP > 1) && (subframeP < 5))
      return (1);
    else
      AssertFatal(1 == 0, "Unknown subframe number\n");
    break;
  case 4:
    if ((subframeP <= 1) || (subframeP >= 4))
      return (0);
    else if ((subframeP > 1) && (subframeP < 4))
      return (1);
    else
      AssertFatal(1 == 0, "Unknown subframe number\n");
    break;
  case 5:
    if ((subframeP <= 1) || (subframeP >= 3))
      return (0);
    else if ((subframeP > 1) && (subframeP < 3))
      return (1);
    else
      AssertFatal(1 == 0, "Unknown subframe number\n");
    break;
  default:
    AssertFatal(1 == 0,
		"subframe %d Unsupported TDD configuration %d\n",
		subframeP, (int) ccP->tdd_Config->subframeAssignment);
    break;
  }
558 559
}

560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
int is_S_sf(COMMON_channels_t * ccP, sub_frame_t subframeP)
{
    // if FDD return dummy value
    if (ccP->tdd_Config == NULL)
    return (0);

    switch (subframeP) {
    case 1:
        return (1);
        break;

    case 6:
        if(ccP->tdd_Config->subframeAssignment == 0 || ccP->tdd_Config->subframeAssignment == 1
                || ccP->tdd_Config->subframeAssignment == 2 || ccP->tdd_Config->subframeAssignment == 6)
        return (1);
        break;

    default:
        return (0);
        break;
    }
    return 0;
}

jftt_wangshanshan's avatar
jftt_wangshanshan committed
584 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
uint8_t ul_subframe2_k_phich(COMMON_channels_t * cc, sub_frame_t ul_subframe){

    if(cc->tdd_Config){//TODO fill other tdd config
        switch(cc->tdd_Config->subframeAssignment){
        case 0:
            break;
        case 1:
            if(ul_subframe == 2 || ul_subframe == 7)
                return 4;
            else if(ul_subframe == 3 || ul_subframe == 8)
                return 6;
            else return 255;
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            break;
        case 5:
            break;
        }
    }
    return 4; //idk  sf_ahead?
}

610
uint16_t get_pucch1_absSF(COMMON_channels_t * cc, uint16_t dlsch_absSF)
611
{
612
  uint16_t sf, f, nextf;
613

614
  if (cc->tdd_Config == NULL) { //FDD n+4
615 616 617 618 619 620 621 622
    return ((dlsch_absSF + 4) % 10240);
  } else {
    sf = dlsch_absSF % 10;
    f = dlsch_absSF / 10;
    nextf = (f + 1) & 1023;

    switch (cc->tdd_Config->subframeAssignment) {
    case 0:
623 624 625 626 627 628 629 630 631 632 633
      if ((sf == 0) || (sf == 5))
        return ((10 * f) + sf + 4)% 10240;  // ACK/NAK in SF 4,9 same frame
      else if (sf == 6)
        return ((10 * nextf) + 2)% 10240;  // ACK/NAK in SF 2 next frame
      else if (sf == 1)
        return ((10 * f) + 7)% 10240;  // ACK/NAK in SF 7 same frame
      else
        AssertFatal(1 == 0,
                   "Impossible dlsch subframe %d for TDD configuration 0\n",
                   sf);

634 635 636
      break;
    case 1:
      if ((sf == 5) || (sf == 6))
637
        return ((10 * nextf) + 2)% 10240;        // ACK/NAK in SF 2 next frame
638
      else if (sf == 9)
639
        return ((10 * nextf) + 3)% 10240;        // ACK/NAK in SF 3 next frame
640
      else if ((sf == 0) || (sf == 1))
641 642
        return ((10 * f) + 7)% 10240;        // ACK/NAK in SF 7 same frame
      else if (sf == 4)
jftt_wangshanshan's avatar
jftt_wangshanshan committed
643
        return ((10 * f) + 8)% 10240;  // ACK/NAK in SF 8 same frame
644
      else
645 646 647
        AssertFatal(1 == 0,
                    "Impossible dlsch subframe %d for TDD configuration 1\n",
                    sf);
648 649 650
      break;
    case 2:
      if ((sf == 4) || (sf == 5) || (sf == 6) || (sf == 8))
651
        return ((10 * nextf) + 2)% 10240;        // ACK/NAK in SF 2 next frame
652
      else if (sf == 9)
653
        return ((10 * nextf) + 7)% 10240;        // ACK/NAK in SF 7 next frame
654
      else if ((sf == 0) || (sf == 1) || (sf == 3))
655
        return ((10 * f) + 7)% 10240;        // ACK/NAK in SF 7 same frame
656
      else
657 658 659
        AssertFatal(1 == 0,
                    "Impossible dlsch subframe %d for TDD configuration 2\n",
                    sf);
660 661 662
      break;
    case 3:
      if ((sf == 5) || (sf == 6) || (sf == 7) || (sf == 8)
663 664
          || (sf == 9))
        return ((10 * nextf) + ((sf-1) >> 1))% 10240;   // ACK/NAK in 2,3,4 resp. next frame
665
      else if (sf == 1)
666
        return ((10 * nextf) + 2)% 10240;         // ACK/NAK in 2 next frame
667
      else if (sf == 0)
668
        return ((10 * f) + 4)% 10240;        // ACK/NAK in 4 same frame
669
      else
670 671 672
        AssertFatal(1 == 0,
                    "Impossible dlsch subframe %d for TDD configuration 3\n",
                    sf);
673 674 675
      break;
    case 4:
      if ((sf == 6) || (sf == 7) || (sf == 8) || (sf == 9))
676
        return (((10 * nextf) + 3) % 10240);        // ACK/NAK in SF 3 next frame
677
      else if ((sf == 0) || (sf == 1) || (sf == 4) || (sf == 5))
678
        return (((10 * nextf) + 2) % 10240);        // ACK/NAK in SF 2 next frame
679
      else
680 681 682
        AssertFatal(1 == 0,
                    "Impossible dlsch subframe %d for TDD configuration 4\n",
                    sf);
683 684 685
      break;
    case 5:
      if ((sf == 0) || (sf == 1) || (sf == 3) || (sf == 4)
686 687
          || (sf == 5) || (sf == 6) || (sf == 7) || (sf == 8))
        return (((10 * nextf) + 2) % 10240);        // ACK/NAK in SF 3 next frame
688
      else if (sf == 9)
689
        return (((10 * (1 + nextf)) + 2) % 10240);        // ACK/NAK in SF 2 next frame
690
      else
691 692 693
        AssertFatal(1 == 0,
                    "Impossible dlsch subframe %d for TDD configuration 5\n",
                    sf);
694 695
      break;
    case 6:
696 697 698 699 700 701 702 703 704 705
      if ((sf == 5) || (sf == 6))
        return ((10 * f) + sf + 7)% 10240;  // ACK/NAK in SF 2,3 next frame
      else if (sf == 9)
        return ((10 * nextf) + 4)% 10240;  // ACK/NAK in SF 4 next frame
      else if ((sf == 1) || (sf == 0))
        return ((10 * f) + sf + 7)% 10240;  // ACK/NAK in SF 7 same frame
      else
        AssertFatal(1 == 0,
                "Impossible dlsch subframe %d for TDD configuration 6\n",
                sf);
706 707 708
      break;
    default:
      AssertFatal(1 == 0, "Illegal TDD subframe Assigment %d\n",
709
                  (int) cc->tdd_Config->subframeAssignment);
710
      break;
711
    }
712 713
  }
  AssertFatal(1 == 0, "Shouldn't get here\n");
714 715
}

716 717 718
void
get_srs_pos(COMMON_channels_t * cc, uint16_t isrs,
	    uint16_t * psrsPeriodicity, uint16_t * psrsOffset)
Cedric Roux's avatar
Cedric Roux committed
719
{
720 721
  if (cc->tdd_Config) {	// TDD
    AssertFatal(isrs >= 10, "2 ms SRS periodicity not supported");
722

723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
    if ((isrs > 9) && (isrs < 15)) {
      *psrsPeriodicity = 5;
      *psrsOffset = isrs - 10;
    }
    if ((isrs > 14) && (isrs < 25)) {
      *psrsPeriodicity = 10;
      *psrsOffset = isrs - 15;
    }
    if ((isrs > 24) && (isrs < 45)) {
      *psrsPeriodicity = 20;
      *psrsOffset = isrs - 25;
    }
    if ((isrs > 44) && (isrs < 85)) {
      *psrsPeriodicity = 40;
      *psrsOffset = isrs - 45;
    }
    if ((isrs > 84) && (isrs < 165)) {
      *psrsPeriodicity = 80;
      *psrsOffset = isrs - 85;
    }
    if ((isrs > 164) && (isrs < 325)) {
      *psrsPeriodicity = 160;
      *psrsOffset = isrs - 165;
    }
    if ((isrs > 324) && (isrs < 645)) {
      *psrsPeriodicity = 320;
      *psrsOffset = isrs - 325;
    }
751

752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
    AssertFatal(isrs <= 644, "Isrs out of range %d>644\n", isrs);
  }				// TDD
  else {			// FDD
    if (isrs < 2) {
      *psrsPeriodicity = 2;
      *psrsOffset = isrs;
    }
    if ((isrs > 1) && (isrs < 7)) {
      *psrsPeriodicity = 5;
      *psrsOffset = isrs - 2;
    }
    if ((isrs > 6) && (isrs < 17)) {
      *psrsPeriodicity = 10;
      *psrsOffset = isrs - 7;
    }
    if ((isrs > 16) && (isrs < 37)) {
      *psrsPeriodicity = 20;
      *psrsOffset = isrs - 17;
    }
    if ((isrs > 36) && (isrs < 77)) {
      *psrsPeriodicity = 40;
      *psrsOffset = isrs - 37;
774
    }
775 776 777
    if ((isrs > 76) && (isrs < 157)) {
      *psrsPeriodicity = 80;
      *psrsOffset = isrs - 77;
778
    }
779 780 781 782 783 784 785
    if ((isrs > 156) && (isrs < 317)) {
      *psrsPeriodicity = 160;
      *psrsOffset = isrs - 157;
    }
    if ((isrs > 316) && (isrs < 637)) {
      *psrsPeriodicity = 320;
      *psrsOffset = isrs - 317;
786
    }
787 788
    AssertFatal(isrs <= 636, "Isrs out of range %d>636\n", isrs);
  }
789 790
}

791 792 793 794
void
get_csi_params(COMMON_channels_t * cc,
	       struct CQI_ReportPeriodic *cqi_ReportPeriodic,
	       uint16_t * Npd, uint16_t * N_OFFSET_CQI, int *H)
795
{
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
  uint16_t cqi_PMI_ConfigIndex =
    cqi_ReportPeriodic->choice.setup.cqi_pmi_ConfigIndex;
  uint8_t Jtab[6] = { 0, 2, 2, 3, 4, 4 };

  AssertFatal(cqi_ReportPeriodic != NULL,
	      "cqi_ReportPeriodic is null!\n");

  if (cc->tdd_Config == NULL) {	//FDD
    if (cqi_PMI_ConfigIndex <= 1) {	// 2 ms CQI_PMI period
      *Npd = 2;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex;
    } else if (cqi_PMI_ConfigIndex <= 6) {	// 5 ms CQI_PMI period
      *Npd = 5;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 2;
    } else if (cqi_PMI_ConfigIndex <= 16) {	// 10ms CQI_PMI period
      *Npd = 10;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 7;
    } else if (cqi_PMI_ConfigIndex <= 36) {	// 20 ms CQI_PMI period
      *Npd = 20;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 17;
    } else if (cqi_PMI_ConfigIndex <= 76) {	// 40 ms CQI_PMI period
      *Npd = 40;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 37;
    } else if (cqi_PMI_ConfigIndex <= 156) {	// 80 ms CQI_PMI period
      *Npd = 80;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 77;
    } else if (cqi_PMI_ConfigIndex <= 316) {	// 160 ms CQI_PMI period
      *Npd = 160;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 157;
    } else if (cqi_PMI_ConfigIndex > 317) {

      if (cqi_PMI_ConfigIndex <= 349) {	// 32 ms CQI_PMI period
	*Npd = 32;
	*N_OFFSET_CQI = cqi_PMI_ConfigIndex - 318;
      } else if (cqi_PMI_ConfigIndex <= 413) {	// 64 ms CQI_PMI period
	*Npd = 64;
	*N_OFFSET_CQI = cqi_PMI_ConfigIndex - 350;
      } else if (cqi_PMI_ConfigIndex <= 541) {	// 128 ms CQI_PMI period
	*Npd = 128;
	*N_OFFSET_CQI = cqi_PMI_ConfigIndex - 414;
      }
837
    }
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
  } else {			// TDD
    if (cqi_PMI_ConfigIndex == 0) {	// all UL subframes
      *Npd = 1;
      *N_OFFSET_CQI = 0;
    } else if (cqi_PMI_ConfigIndex <= 6) {	// 5 ms CQI_PMI period
      *Npd = 5;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 1;
    } else if (cqi_PMI_ConfigIndex <= 16) {	// 10ms CQI_PMI period
      *Npd = 10;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 6;
    } else if (cqi_PMI_ConfigIndex <= 36) {	// 20 ms CQI_PMI period
      *Npd = 20;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 16;
    } else if (cqi_PMI_ConfigIndex <= 76) {	// 40 ms CQI_PMI period
      *Npd = 40;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 36;
    } else if (cqi_PMI_ConfigIndex <= 156) {	// 80 ms CQI_PMI period
      *Npd = 80;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 76;
    } else if (cqi_PMI_ConfigIndex <= 316) {	// 160 ms CQI_PMI period
      *Npd = 160;
      *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 156;
860
    }
861
  }
862

863 864 865 866 867 868 869 870 871 872
  // get H
  if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.
      present ==
      CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI)
    *H = 1 +
      (Jtab[cc->mib->message.dl_Bandwidth] *
       cqi_ReportPeriodic->choice.setup.
       cqi_FormatIndicatorPeriodic.choice.subbandCQI.k);
  else
    *H = 1;
873 874
}

875 876 877 878 879
uint8_t
get_dl_cqi_pmi_size_pusch(COMMON_channels_t * cc, uint8_t tmode,
			  uint8_t ri,
			  CQI_ReportModeAperiodic_t *
			  cqi_ReportModeAperiodic)
Cedric Roux's avatar
Cedric Roux committed
880
{
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 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
  int Ntab[6] = { 0, 4, 7, 9, 10, 13 };
  int N = Ntab[cc->mib->message.dl_Bandwidth];
  int Ltab_uesel[6] = { 0, 6, 9, 13, 15, 18 };
  int L = Ltab_uesel[cc->mib->message.dl_Bandwidth];

  AssertFatal(cqi_ReportModeAperiodic != NULL,
	      "cqi_ReportPeriodic is null!\n");

  switch (*cqi_ReportModeAperiodic) {
  case CQI_ReportModeAperiodic_rm12:
    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
		|| tmode == 10,
		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm12\n",
		tmode);
    AssertFatal(cc->p_eNB <= 4,
		"only up to 4 antenna ports supported here\n");
    if (ri == 1 && cc->p_eNB == 2)
      return (4 + (N << 1));
    else if (ri == 2 && cc->p_eNB == 2)
      return (8 + N);
    else if (ri == 1 && cc->p_eNB == 4)
      return (4 + (N << 2));
    else if (ri > 1 && cc->p_eNB == 4)
      return (8 + (N << 2));
    break;
  case CQI_ReportModeAperiodic_rm20:
    // Table 5.2.2.6.3-1 (36.212)
    AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7
		|| tmode == 9
		|| tmode == 10,
		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm20\n",
		tmode);
    AssertFatal(tmode != 9
		&& tmode != 10,
		"TM9/10 will be handled later for CQI_ReportModeAperiodic_rm20\n");
    return (4 + 2 + L);
    break;
  case CQI_ReportModeAperiodic_rm22:
    // Table 5.2.2.6.3-2 (36.212)
    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
		|| tmode == 10,
		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm22\n",
		tmode);
    AssertFatal(tmode != 9
		&& tmode != 10,
		"TM9/10 will be handled later for CQI_ReportModeAperiodic_rm22\n");
    if (ri == 1 && cc->p_eNB == 2)
      return (4 + 2 + 0 + 0 + L + 4);
    if (ri == 2 && cc->p_eNB == 2)
      return (4 + 2 + 4 + 2 + L + 2);
    if (ri == 1 && cc->p_eNB == 4)
      return (4 + 2 + 0 + 0 + L + 8);
    if (ri >= 2 && cc->p_eNB == 4)
      return (4 + 2 + 4 + 2 + L + 8);
    break;
  case CQI_ReportModeAperiodic_rm30:
    // Table 5.2.2.6.2-1 (36.212)
    AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7
		|| tmode == 8 || tmode == 9
		|| tmode == 10,
		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm30\n",
		tmode);
    AssertFatal(tmode != 8 && tmode != 9
		&& tmode != 10,
		"TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm30\n");
    return (4 + (N << 1));
    break;
  case CQI_ReportModeAperiodic_rm31:
    // Table 5.2.2.6.2-2 (36.212)
    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
		|| tmode == 10,
		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm31\n",
		tmode);
    AssertFatal(tmode != 8 && tmode != 9
		&& tmode != 10,
		"TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm31\n");
    if (ri == 1 && cc->p_eNB == 2)
      return (4 + (N << 1) + 0 + 0 + 2);
    else if (ri == 2 && cc->p_eNB == 2)
      return (4 + (N << 1) + 4 + (N << 1) + 1);
    else if (ri == 1 && cc->p_eNB == 4)
      return (4 + (N << 1) + 0 + 0 + 4);
    else if (ri >= 2 && cc->p_eNB == 4)
      return (4 + (N << 1) + 4 + (N << 1) + 4);
    break;
966
#if (RRC_VERSION >= MAKE_VERSION(12, 5, 0))
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
  case CQI_ReportModeAperiodic_rm32_v1250:
    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
		|| tmode == 10,
		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm32\n",
		tmode);
    AssertFatal(1 == 0,
		"CQI_ReportModeAperiodic_rm32_v1250 not supported yet\n");
    break;
  case CQI_ReportModeAperiodic_rm10_v1310:
    // Table 5.2.2.6.1-1F/G (36.212)
    if (ri == 1)
      return (4);		// F
    else
      return (7);		// G
    break;
  case CQI_ReportModeAperiodic_rm11_v1310:
    // Table 5.2.2.6.1-1H (36.212)
    AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9
		|| tmode == 10,
		"Illegal TM (%d) for CQI_ReportModeAperiodic_rm11\n",
		tmode);
    AssertFatal(cc->p_eNB <= 4,
		"only up to 4 antenna ports supported here\n");
    if (ri == 1 && cc->p_eNB == 2)
      return (4 + 0 + 2);
    else if (ri == 2 && cc->p_eNB == 2)
      return (4 + 4 + 1);
    else if (ri == 1 && cc->p_eNB == 4)
      return (4 + 0 + 4);
    else if (ri > 1 && cc->p_eNB == 4)
      return (4 + 4 + 4);
998

999
    break;
1000
#endif /* #if (RRC_VERSION >= MAKE_VERSION(12, 5, 0)) */
1001 1002 1003
  }
  AssertFatal(1 == 0, "Shouldn't get here\n");
  return (0);
1004
}
1005

1006 1007 1008 1009 1010
uint8_t
get_rel8_dl_cqi_pmi_size(UE_sched_ctrl * sched_ctl, int CC_idP,
			 COMMON_channels_t * cc, uint8_t tmode,
			 struct CQI_ReportPeriodic * cqi_ReportPeriodic)
{
1011 1012
  int no_pmi = 0;
  //    Ltab[6] = {0,log2(15/4/2),log2(25/4/2),log2(50/6/3),log2(75/8/4),log2(100/8/4)};
1013

1014 1015
  uint8_t Ltab[6] = { 0, 1, 2, 2, 2, 2 };
  uint8_t ri = sched_ctl->periodic_ri_received[CC_idP];
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
  AssertFatal(cqi_ReportPeriodic != NULL,
	      "cqi_ReportPeriodic is null!\n");
  AssertFatal(cqi_ReportPeriodic->present != CQI_ReportPeriodic_PR_NOTHING,
	      "cqi_ReportPeriodic->present == CQI_ReportPeriodic_PR_NOTHING!\n");
  AssertFatal(cqi_ReportPeriodic->choice.
	      setup.cqi_FormatIndicatorPeriodic.present != CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING,
	      "cqi_ReportPeriodic->cqi_FormatIndicatorPeriodic.choice.setup.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING!\n");

  switch (tmode) {
  case 1:
  case 2:
  case 5:
  case 6:
  case 7:
    no_pmi = 1;
    break;
  default:
    no_pmi = 0;
  }

  if ((cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_widebandCQI)
      || (sched_ctl->feedback_cnt[CC_idP] == 0)) {
    // send wideband report every opportunity if wideband reporting mode is selected, else every H opportunities
    if (no_pmi == 1)                        return (4);
    else if ((cc->p_eNB == 2) && (ri == 1)) return (6);
    else if ((cc->p_eNB == 2) && (ri == 2)) return (8);
    else if ((cc->p_eNB == 4) && (ri == 1)) return (8);
    else if ((cc->p_eNB == 4) && (ri == 2)) return (11);
    else
      AssertFatal(1 == 0,
		  "illegal combination p %d, ri %d, no_pmi %d\n",
		  cc->p_eNB, ri, no_pmi);
  } else if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) {
    if ((no_pmi == 1) || ri == 1) return (4 + Ltab[cc->mib->message.dl_Bandwidth]);
    else                          return (7 + Ltab[cc->mib->message.dl_Bandwidth]);
  }

  AssertFatal(1 == 0,
	      "Shouldn't get here : cqi_ReportPeriodic->present %d\n",
	      cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present);
1057 1058
}

1059 1060


1061
void
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
fill_nfapi_dl_dci_1A(nfapi_dl_config_request_pdu_t *dl_config_pdu,
		     uint8_t                       aggregation_level,
		     uint16_t                      rnti,
		     uint8_t                       rnti_type,
		     uint8_t                       harq_process,
		     uint8_t                       tpc,
		     uint16_t                      resource_block_coding,
		     uint8_t                       mcs, 
		     uint8_t                       ndi, 
		     uint8_t                       rv,
		     uint8_t                       vrb_flag)
{
  memset((void *) dl_config_pdu, 0,
	 sizeof(nfapi_dl_config_request_pdu_t));
  dl_config_pdu->pdu_type                                                          = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
  dl_config_pdu->pdu_size                                                          = (uint8_t) (2 + sizeof(nfapi_dl_config_dci_dl_pdu));
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag                                 = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG;
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format                             = NFAPI_DL_DCI_FORMAT_1A;
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level                      = aggregation_level;
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                                   = rnti;
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                              = rnti_type;
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power                     = 6000;	// equal to RS power
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                           = harq_process;
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                                    = tpc;
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding                  = resource_block_coding;
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                                  = mcs;
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1                   = ndi;
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1                   = rv;
  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = vrb_flag;
1091 1092
}

1093 1094 1095 1096
void
program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP,
		     frame_t frameP, sub_frame_t subframeP,
		     uint8_t cce_idx)
Cedric Roux's avatar
Cedric Roux committed
1097
{
1098 1099 1100 1101 1102 1103 1104 1105 1106
  eNB_MAC_INST                           *eNB                         = RC.mac[module_idP];
  COMMON_channels_t                      *cc                          = eNB->common_channels;
  UE_list_t                              *UE_list                     = &eNB->UE_list;
  rnti_t                                 rnti                         = UE_RNTI(module_idP, UE_idP);
  nfapi_ul_config_request_body_t         *ul_req;
  nfapi_ul_config_request_pdu_t          *ul_config_pdu;
  int                                    use_simultaneous_pucch_pusch = 0;
  nfapi_ul_config_ulsch_harq_information *ulsch_harq_information      = NULL;
  nfapi_ul_config_harq_information       *harq_information            = NULL;
Cedric Roux's avatar
Cedric Roux committed
1107

1108
#if (RRC_VERSION >= MAKE_VERSION(10, 2, 0))
Cedric Roux's avatar
Cedric Roux committed
1109

1110 1111 1112 1113 1114
  if ((UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2)
      && (UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020)
      && (UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020->simultaneousPUCCH_PUSCH_r10)
      && (*UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020->simultaneousPUCCH_PUSCH_r10 == PUCCH_ConfigDedicated_v1020__simultaneousPUCCH_PUSCH_r10_true))
    use_simultaneous_pucch_pusch = 1;
1115
#endif
Cedric Roux's avatar
Cedric Roux committed
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 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
  // pucch1 and pusch feedback is similar, namely in n+k subframes from now
  // This is used in the following "if/else" condition to check if there isn't or is already an UL grant in n+k
  int16_t ul_absSF = get_pucch1_absSF(&cc[CC_idP], subframeP + (10 * frameP));

  if ((ul_config_pdu = has_ul_grant(module_idP, CC_idP,ul_absSF, rnti)) == NULL) {
    // no UL grant so
    // Program ACK/NAK alone Format 1a/b or 3

    ul_req        = &RC.mac[module_idP]->UL_req_tmp[CC_idP][ul_absSF %10].ul_config_request_body;
    ul_config_pdu = &ul_req->ul_config_pdu_list[ul_req->number_of_pdus];
    // Do PUCCH
    fill_nfapi_uci_acknak(module_idP,
			  CC_idP,
			  rnti, (frameP * 10) + subframeP, cce_idx);
  } else {
    /* there is already an existing UL grant so update it if needed
     * on top of some other UL resource (PUSCH,combined SR/CQI/HARQ on PUCCH, etc)
     */
    switch (ul_config_pdu->pdu_type) {
      
      /* [ulsch] to [ulsch + harq] or [ulsch + harq on pucch] */
      
    case NFAPI_UL_CONFIG_ULSCH_PDU_TYPE:
      if (use_simultaneous_pucch_pusch == 1) {
	// Convert it to an NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE
	harq_information        = &ul_config_pdu->ulsch_uci_harq_pdu.harq_information;
	ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE;
	LOG_D(MAC,
	      "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH UCI HARQ\n",
	      frameP, subframeP);
      } else {
	// Convert it to an NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE
	ulsch_harq_information                                                                                                               = &ul_config_pdu->ulsch_harq_pdu.harq_information;
	ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE;
	ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag                            = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG;
	ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial                     = 0;	// last symbol not punctured
	ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks;	// we don't change the number of resource blocks across retransmissions yet
	LOG_D(MAC,
	      "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH HARQ\n",
	      frameP, subframeP);
      }
      break;
    case NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE:
Cedric Roux's avatar
Cedric Roux committed
1160
      AssertFatal(use_simultaneous_pucch_pusch == 0,
1161 1162 1163
		  "Cannot be NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE, simultaneous_pucch_pusch is active");
      break;
    case NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE:
Cedric Roux's avatar
Cedric Roux committed
1164
      AssertFatal(use_simultaneous_pucch_pusch == 1,
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180