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

/*! \file phy_procedures_lte_eNB.c
 * \brief Implementation of eNB procedures from 36.213 LTE specifications
24
 * \author R. Knopp, F. Kaltenberger, N. Nikaein, X. Foukas
25 26 27
 * \date 2011
 * \version 0.1
 * \company Eurecom
28
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr,navid.nikaein@eurecom.fr, x.foukas@sms.ed.ac.uk
29 30 31 32 33 34 35 36
 * \note
 * \warning
 */

#include "PHY/defs.h"
#include "PHY/extern.h"
#include "SCHED/defs.h"
#include "SCHED/extern.h"
37
#include "nfapi_interface.h"
38

39
#include "PHY/LTE_TRANSPORT/if4_tools.h"
Sandeep Kumar's avatar
Sandeep Kumar committed
40
#include "PHY/LTE_TRANSPORT/if5_tools.h"
41

42
//#define DEBUG_PHY_PROC (Already defined in cmake)
43 44 45 46
//#define DEBUG_ULSCH

#include "LAYER2/MAC/extern.h"
#include "LAYER2/MAC/defs.h"
47

48 49 50
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"

51 52
#include "T.h"

53
#include "assertions.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
54
#include "msc.h"
55

56 57
#include <time.h>

58
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
Lionel Gauthier committed
59
#   include "intertask_interface.h"
60 61
#endif

62

63
#if defined(FLEXRAN_AGENT_SB_IF)
64
//Agent-related headers
65
#include "ENB_APP/flexran_agent_extern.h"
66
#include "ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.h"
67
#include "LAYER2/MAC/flexran_agent_mac_proto.h"
68
#endif
69

70 71 72 73 74

#define NS_PER_SLOT 500000

#define PUCCH 1

75 76
void exit_fun(const char* s);

77
extern int exit_openair;
78 79
struct timespec start_fh, start_fh_prev;
int start_fh_sf, start_fh_prev_sf;
80 81
// Fix per CC openair rf/if device update
// extern openair0_device openair0;
82

83 84 85
unsigned char dlsch_input_buffer[2700] __attribute__ ((aligned(32)));
int eNB_sync_buffer0[640*6] __attribute__ ((aligned(32)));
int eNB_sync_buffer1[640*6] __attribute__ ((aligned(32)));
86 87
int *eNB_sync_buffer[2] = {eNB_sync_buffer0, eNB_sync_buffer1};

88
extern uint16_t hundred_times_log10_NPRB[100];
89

90
unsigned int max_peak_val;
91
int max_sync_pos;
92

93 94 95
int harq_pid_updated[NUMBER_OF_UE_MAX][8] = {{0}};
int harq_pid_round[NUMBER_OF_UE_MAX][8] = {{0}};

96 97
//DCI_ALLOC_t dci_alloc[8];

98
uint8_t is_SR_subframe(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,uint8_t UE_id)
99
{
Raymond Knopp's avatar
 
Raymond Knopp committed
100

101 102
  const int subframe = proc->subframe_rx;
  const int frame = proc->frame_rx;
103

104
  LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Checking for SR TXOp(sr_ConfigIndex %d)\n",
105 106
        eNB->Mod_id,eNB->ulsch[UE_id]->rnti,frame,subframe,
        eNB->scheduling_request_config[UE_id].sr_ConfigIndex);
107

108 109
  if (eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 4) {        // 5 ms SR period
    if ((subframe%5) == eNB->scheduling_request_config[UE_id].sr_ConfigIndex)
110
      return(1);
111 112
  } else if (eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 14) { // 10 ms SR period
    if (subframe==(eNB->scheduling_request_config[UE_id].sr_ConfigIndex-5))
113
      return(1);
114 115
  } else if (eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 34) { // 20 ms SR period
    if ((10*(frame&1)+subframe) == (eNB->scheduling_request_config[UE_id].sr_ConfigIndex-15))
116
      return(1);
117 118
  } else if (eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 74) { // 40 ms SR period
    if ((10*(frame&3)+subframe) == (eNB->scheduling_request_config[UE_id].sr_ConfigIndex-35))
119
      return(1);
120 121
  } else if (eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 154) { // 80 ms SR period
    if ((10*(frame&7)+subframe) == (eNB->scheduling_request_config[UE_id].sr_ConfigIndex-75))
122
      return(1);
123 124 125 126
  }

  return(0);
}
127

128

129
int32_t add_ue(int16_t rnti, PHY_VARS_eNB *eNB)
130
{
131
  uint8_t i;
132

133 134

  LOG_D(PHY,"[eNB %d/%d] Adding UE with rnti %x\n",
135 136
        eNB->Mod_id,
        eNB->CC_id,
137
        (uint16_t)rnti);
138 139

  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
140
    if ((eNB->dlsch[i]==NULL) || (eNB->ulsch[i]==NULL)) {
141
      MSC_LOG_EVENT(MSC_PHY_ENB, "0 Failed add ue %"PRIx16" (ENOMEM)", rnti);
142 143
      LOG_E(PHY,"Can't add UE, not enough memory allocated\n");
      return(-1);
144
    } else {
145
      if (eNB->UE_stats[i].crnti==0) {
146
        MSC_LOG_EVENT(MSC_PHY_ENB, "0 Add ue %"PRIx16" ", rnti);
147
        LOG_D(PHY,"UE_id %d associated with rnti %x\n",i, (uint16_t)rnti);
148 149 150
        eNB->dlsch[i][0]->rnti = rnti;
        eNB->ulsch[i]->rnti = rnti;
        eNB->UE_stats[i].crnti = rnti;
151

152 153 154
	eNB->UE_stats[i].Po_PUCCH1_below = 0;
	eNB->UE_stats[i].Po_PUCCH1_above = (int32_t)pow(10.0,.1*(eNB->frame_parms.ul_power_control_config_common.p0_NominalPUCCH+eNB->rx_total_gain_dB));
	eNB->UE_stats[i].Po_PUCCH        = (int32_t)pow(10.0,.1*(eNB->frame_parms.ul_power_control_config_common.p0_NominalPUCCH+eNB->rx_total_gain_dB));
155
	LOG_D(PHY,"Initializing Po_PUCCH: p0_NominalPUCCH %d, gain %d => %d\n",
156 157 158
	      eNB->frame_parms.ul_power_control_config_common.p0_NominalPUCCH,
	      eNB->rx_total_gain_dB,
	      eNB->UE_stats[i].Po_PUCCH);
159
  
160
        return(i);
161
      }
162
    }
163 164 165 166
  }
  return(-1);
}

167
int mac_phy_remove_ue(module_id_t Mod_idP,rnti_t rntiP) {
168
  uint8_t i;
169
  int CC_id;
170
  PHY_VARS_eNB *eNB;
171 172

  for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
173
    eNB = RC.eNB[Mod_idP][CC_id];
174
    for (i=0; i<NUMBER_OF_UE_MAX; i++) {
175
      if ((eNB->dlsch[i]==NULL) || (eNB->ulsch[i]==NULL)) {
Wilson Thong's avatar
Wilson Thong committed
176
	MSC_LOG_EVENT(MSC_PHY_ENB, "0 Failed remove ue %"PRIx16" (ENOMEM)", rntiP);
177 178 179
	LOG_E(PHY,"Can't remove UE, not enough memory allocated\n");
	return(-1);
      } else {
180
	if (eNB->UE_stats[i].crnti==rntiP) {
181
	  MSC_LOG_EVENT(MSC_PHY_ENB, "0 Removed ue %"PRIx16" ", rntiP);
182 183 184

	  LOG_D(PHY,"eNB %d removing UE %d with rnti %x\n",eNB->Mod_id,i,rntiP);

185
	  //LOG_D(PHY,("[PHY] UE_id %d\n",i);
186 187 188 189
	  clean_eNb_dlsch(eNB->dlsch[i][0]);
	  clean_eNb_ulsch(eNB->ulsch[i]);
	  //eNB->UE_stats[i].crnti = 0;
	  memset(&eNB->UE_stats[i],0,sizeof(LTE_eNB_UE_stats));
190 191
	  //  mac_exit_wrapper("Removing UE");
	  
192

193 194
	  return(i);
	}
195
      }
196
    }
197
  }
198
  MSC_LOG_EVENT(MSC_PHY_ENB, "0 Failed remove ue %"PRIx16" (not found)", rntiP);
199 200 201
  return(-1);
}

202
/*
203
int8_t find_next_ue_index(PHY_VARS_eNB *eNB)
204
{
205
  uint8_t i;
206

207
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
208
    if (eNB->UE_stats[i].crnti==0) {
209
	(eNB->dlsch[i][0]->rnti==0))
210 211 212
      LOG_D(PHY,"Next free UE id is %d\n",i);
      return(i);
    }
213
  }
214

215 216
  return(-1);
}
217
*/
218

219
/*
220
int get_ue_active_harq_pid(const uint8_t Mod_id,const uint8_t CC_id,const uint16_t rnti, const int frame, const uint8_t subframe,uint8_t *harq_pid,uint8_t *round,const uint8_t harq_flag)
221 222 223 224
{
  LTE_eNB_DLSCH_t *DLSCH_ptr;
  LTE_eNB_ULSCH_t *ULSCH_ptr;
  uint8_t ulsch_subframe,ulsch_frame;
225
  int i;
226
  int8_t UE_id = find_ue(rnti,RC.eNB[Mod_id][CC_id]);
227 228

  if (UE_id==-1) {
229
    LOG_D(PHY,"Cannot find UE with rnti %x (Mod_id %d, CC_id %d)\n",rnti, Mod_id, CC_id);
230 231
    *round=0;
    return(-1);
232 233
  }

234 235
  if ((harq_flag == openair_harq_DL) || (harq_flag == openair_harq_RA))  {// this is a DL request

236
    DLSCH_ptr = RC.eNB[Mod_id][CC_id]->dlsch[(uint32_t)UE_id][0];
237

238 239 240 241 242 243 244 245 246 247
    if (harq_flag == openair_harq_RA) {
      if (DLSCH_ptr->harq_processes[0] != NULL) {
	*harq_pid = 0;
	*round = DLSCH_ptr->harq_processes[0]->round;
	return 0;
      } else {
	return -1;
      }
    }

248
    // let's go synchronous for the moment - maybe we can change at some point
249
    i = (frame * 10 + subframe) % 8;
250

251 252 253 254 255
    if (DLSCH_ptr->harq_processes[i]->status == ACTIVE) {
      *harq_pid = i;
      *round = DLSCH_ptr->harq_processes[i]->round;
    } else if (DLSCH_ptr->harq_processes[i]->status == SCH_IDLE) {
      *harq_pid = i;
256
      *round = 0;
257 258 259
    } else {
      printf("%s:%d: bad state for harq process - PLEASE REPORT!!\n", __FILE__, __LINE__);
      abort();
260
    }
261
  } else { // This is a UL request
262

263 264 265
    ULSCH_ptr = RC.eNB[Mod_id][CC_id]->ulsch[(uint32_t)UE_id];
    ulsch_subframe = pdcch_alloc2ul_subframe(&RC.eNB[Mod_id][CC_id]->frame_parms,subframe);
    ulsch_frame    = pdcch_alloc2ul_frame(&RC.eNB[Mod_id][CC_id]->frame_parms,frame,subframe);
266
    // Note this is for TDD configuration 3,4,5 only
267
    *harq_pid = subframe2harq_pid(&RC.eNB[Mod_id][CC_id]->frame_parms,
268 269
                                  ulsch_frame,
                                  ulsch_subframe);
270
    *round    = ULSCH_ptr->harq_processes[*harq_pid]->round;
271
    LOG_T(PHY,"[eNB %d][PUSCH %d] Frame %d subframe %d Checking HARQ, round %d\n",Mod_id,*harq_pid,frame,subframe,*round);
272
  }
273

274 275
  return(0);
}
276
*/
277

278
int16_t get_target_pusch_rx_power(const module_id_t module_idP, const uint8_t CC_id)
279
{
280
  return RC.eNB[module_idP][CC_id]->frame_parms.ul_power_control_config_common.p0_NominalPUSCH;
281 282
}

283 284
int16_t get_target_pucch_rx_power(const module_id_t module_idP, const uint8_t CC_id)
{
285
  return RC.eNB[module_idP][CC_id]->frame_parms.ul_power_control_config_common.p0_NominalPUCCH;
286 287
}

288
void phy_procedures_eNB_S_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,relaying_type_t r_type)
289 290
{
  UNUSED(r_type);
291
  int subframe = proc->subframe_rx;
292

293
#ifdef DEBUG_PHY_PROC
294
  LOG_D(PHY,"[eNB %d] Frame %d: Doing phy_procedures_eNB_S_RX(%d)\n", eNB->Mod_id,proc->frame_rx, subframe);
295
#endif
296

297

298 299 300 301
  lte_eNB_I0_measurements(eNB,
			  subframe,
			  0,
			  eNB->first_run_I0_measurements);
302

303 304
}

Raymond Knopp's avatar
 
Raymond Knopp committed
305 306


307 308
#define AMP_OVER_SQRT2 ((AMP*ONE_OVER_SQRT2_Q15)>>15)
#define AMP_OVER_2 (AMP>>1)
309 310
int QPSK[4]= {AMP_OVER_SQRT2|(AMP_OVER_SQRT2<<16),AMP_OVER_SQRT2|((65536-AMP_OVER_SQRT2)<<16),((65536-AMP_OVER_SQRT2)<<16)|AMP_OVER_SQRT2,((65536-AMP_OVER_SQRT2)<<16)|(65536-AMP_OVER_SQRT2)};
int QPSK2[4]= {AMP_OVER_2|(AMP_OVER_2<<16),AMP_OVER_2|((65536-AMP_OVER_2)<<16),((65536-AMP_OVER_2)<<16)|AMP_OVER_2,((65536-AMP_OVER_2)<<16)|(65536-AMP_OVER_2)};
311

Lionel Gauthier's avatar
Lionel Gauthier committed
312

Raymond Knopp's avatar
 
Raymond Knopp committed
313

Cedric Roux's avatar
Cedric Roux committed
314
unsigned int taus(void);
Raymond Knopp's avatar
 
Raymond Knopp committed
315

316

317
void pmch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,PHY_VARS_RN *rn,relaying_type_t r_type) {
318 319


Cedric Roux's avatar
Cedric Roux committed
320
#if defined(Rel10) || defined(Rel14)
321 322
  MCH_PDU *mch_pduP;
  MCH_PDU  mch_pdu;
323
  //  uint8_t sync_area=255;
324
#endif
325

326
  int subframe = proc->subframe_tx;
327

328 329 330 331 332 333
  // This is DL-Cell spec pilots in Control region
  generate_pilots_slot(eNB,
		       eNB->common_vars.txdataF,
		       AMP,
		       subframe<<1,1);

334
  
Cedric Roux's avatar
Cedric Roux committed
335
#if defined(Rel10) || defined(Rel14)
336 337
  // if mcch is active, send regardless of the node type: eNB or RN
  // when mcch is active, MAC sched does not allow MCCH and MTCH multiplexing
338
  /*
339 340
  mch_pduP = mac_xface->get_mch_sdu(eNB->Mod_id,
				    eNB->CC_id,
341
				    proc->frame_tx,
342
				    subframe);
343
  */
344 345 346 347
  switch (r_type) {
  case no_relay:
    if ((mch_pduP->Pdu_size > 0) && (mch_pduP->sync_area == 0)) // TEST: only transmit mcch for sync area 0
      LOG_I(PHY,"[eNB%"PRIu8"] Frame %d subframe %d : Got MCH pdu for MBSFN (MCS %"PRIu8", TBS %d) \n",
348 349
	    eNB->Mod_id,proc->frame_tx,subframe,mch_pduP->mcs,
	    eNB->dlsch_MCH->harq_processes[0]->TBS>>3);
350 351
    else {
      LOG_D(PHY,"[DeNB %"PRIu8"] Frame %d subframe %d : Do not transmit MCH pdu for MBSFN sync area %"PRIu8" (%s)\n",
352
	    eNB->Mod_id,proc->frame_tx,subframe,mch_pduP->sync_area,
353 354
	    (mch_pduP->Pdu_size == 0)? "Empty MCH PDU":"Let RN transmit for the moment");
      mch_pduP = NULL;
Lionel Gauthier's avatar
Lionel Gauthier committed
355
    }
356
    
Raymond Knopp's avatar
 
Raymond Knopp committed
357
    break;
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
    
  case multicast_relay:
    if ((mch_pduP->Pdu_size > 0) && ((mch_pduP->mcch_active == 1) || mch_pduP->msi_active==1)) {
      LOG_I(PHY,"[RN %"PRIu8"] Frame %d subframe %d: Got the MCH PDU for MBSFN  sync area %"PRIu8" (MCS %"PRIu8", TBS %"PRIu16")\n",
	    rn->Mod_id,rn->frame, subframe,
	    mch_pduP->sync_area,mch_pduP->mcs,mch_pduP->Pdu_size);
    } else if (rn->mch_avtive[subframe%5] == 1) { // SF2 -> SF7, SF3 -> SF8
      mch_pduP= &mch_pdu;
      memcpy(&mch_pduP->payload, // could be a simple copy
	     rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->b,
	     rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->TBS>>3);
      mch_pduP->Pdu_size = (uint16_t) (rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->TBS>>3);
      mch_pduP->mcs = rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->mcs;
      LOG_I(PHY,"[RN %"PRIu8"] Frame %d subframe %d: Forward the MCH PDU for MBSFN received on SF %d sync area %"PRIu8" (MCS %"PRIu8", TBS %"PRIu16")\n",
	    rn->Mod_id,rn->frame, subframe,subframe%5,
	    rn->sync_area[subframe%5],mch_pduP->mcs,mch_pduP->Pdu_size);
Raymond Knopp's avatar
 
Raymond Knopp committed
374
    } else {
375
      mch_pduP=NULL;
Raymond Knopp's avatar
 
Raymond Knopp committed
376
    }
377 378
    
    rn->mch_avtive[subframe]=0;
Raymond Knopp's avatar
 
Raymond Knopp committed
379
    break;
380
    
381
  default:
382
    LOG_W(PHY,"[eNB %"PRIu8"] Frame %d subframe %d: unknown relaying type %d \n",
383
	  eNB->Mod_id,proc->frame_tx,subframe,r_type);
384 385 386 387 388
    mch_pduP=NULL;
    break;
  }// switch
  
  if (mch_pduP) {
389
    fill_eNB_dlsch_MCH(eNB,mch_pduP->mcs,1,0);
390
    // Generate PMCH
391
    generate_mch(eNB,proc,(uint8_t*)mch_pduP->payload);
392
  } else {
393
    LOG_D(PHY,"[eNB/RN] Frame %d subframe %d: MCH not generated \n",proc->frame_tx,subframe);
Raymond Knopp's avatar
 
Raymond Knopp committed
394
  }
395
  
396
#endif
397
}
398

399
void common_signal_procedures (PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
400

401
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
402
  int **txdataF = eNB->common_vars.txdataF;
403
  uint8_t *pbch_pdu=&eNB->pbch_pdu[0];
404 405
  int subframe = proc->subframe_tx;
  int frame = proc->frame_tx;
406

407 408
  LOG_D(PHY,"common_signal_procedures: frame %d, subframe %d\n",frame,subframe); 

409
  // generate Cell-Specific Reference Signals for both slots
410 411 412 413 414 415 416
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,1);
  generate_pilots_slot(eNB,
		       txdataF,
		       AMP,
		       subframe<<1,0);
  // check that 2nd slot is for DL
  if (subframe_select(fp,subframe) == SF_DL)
417 418 419
    generate_pilots_slot(eNB,
			 txdataF,
			 AMP,
420 421 422 423
			 (subframe<<1)+1,0);
  
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,0);
      
424

425
  // First half of PSS/SSS (FDD, slot 0)
Raymond Knopp's avatar
 
Raymond Knopp committed
426
  if (subframe == 0) {
427
    if (fp->frame_type == FDD) {
428 429 430 431 432 433 434 435 436 437 438
      generate_pss(txdataF,
		   AMP,
		   fp,
		   (fp->Ncp==NORMAL) ? 6 : 5,
		   0);
      generate_sss(txdataF,
		   AMP,
		   fp,
		   (fp->Ncp==NORMAL) ? 5 : 4,
		   0);
      
439
    }
440
    
441 442


443 444 445
      
    /// First half of SSS (TDD, slot 1)
    
446
    if (fp->frame_type == TDD) {
447 448 449 450 451 452
      generate_sss(txdataF,
		   AMP,
		   fp,
		   (fp->Ncp==NORMAL) ? 6 : 5,
		   1);
    }
453

454 455
    // generate PBCH (Physical Broadcast CHannel) info

456
    /// generate PBCH
457 458 459
    if ((frame&3)==0) {
      AssertFatal(eNB->pbch_configured==1,"PBCH was not configured by MAC\n");
      eNB->pbch_configured=0;
460
    }
461 462 463 464 465 466 467
    generate_pbch(&eNB->pbch,
		  txdataF,
		  AMP,
		  fp,
		  pbch_pdu,
		  frame&3);
  
468
  }
469
  else if ((subframe == 1) &&
470
	   (fp->frame_type == TDD)){
471 472 473 474 475
    generate_pss(txdataF,
		 AMP,
		 fp,
		 2,
		 2);
476
  }
477 478 479
  
  // Second half of PSS/SSS (FDD, slot 10)
  else if ((subframe == 5) && 
480
	   (fp->frame_type == FDD)) {
481 482 483 484 485 486 487 488 489 490
    generate_pss(txdataF,
		 AMP,
		 &eNB->frame_parms,
		 (fp->Ncp==NORMAL) ? 6 : 5,
		 10);
    generate_sss(txdataF,
		 AMP,
		 &eNB->frame_parms,
		 (fp->Ncp==NORMAL) ? 5 : 4,
		 10);
491

492
  }
493

494 495
  //  Second-half of SSS (TDD, slot 11)
  else if ((subframe == 5) &&
496
	   (fp->frame_type == TDD)) {
497 498 499 500 501
    generate_sss(txdataF,
		 AMP,
		 fp,
		 (fp->Ncp==NORMAL) ? 6 : 5,
		 11);
Raymond Knopp's avatar
 
Raymond Knopp committed
502
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
503

504 505
  // Second half of PSS (TDD, slot 12)
  else if ((subframe == 6) &&
506
	   (fp->frame_type == TDD)) { 
507 508 509 510 511 512
    generate_pss(txdataF,
		 AMP,
		 fp,
		 2,
		 12);
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
513

514
}
Raymond Knopp's avatar
 
Raymond Knopp committed
515

516
/*
517
void generate_eNB_dlsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,const int UE_id) {
518

519
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
520 521
  int frame = proc->frame_tx;
  int subframe = proc->subframe_tx;
522 523 524 525

  // if we have SI_RNTI, configure dlsch parameters and CCE index
  if (dci_alloc->rnti == SI_RNTI) {
    LOG_D(PHY,"Generating dlsch params for SI_RNTI\n");
526
    
527 528 529 530 531
    generate_eNB_dlsch_params_from_dci(frame,
				       subframe,
				       &dci_alloc->dci_pdu[0],
				       dci_alloc->rnti,
				       dci_alloc->format,
532
				       &eNB->dlsch_SI,
533
				       fp,
534
				       NULL,
535 536 537
				       SI_RNTI,
				       0,
				       P_RNTI,
538 539
				       eNB->UE_stats[0].DL_pmi_single,
				       0);
540
    LOG_I(PHY,"frame %d, subframe %d : SI with mcs %d\n",frame,subframe,eNB->dlsch_SI->harq_processes[0]->mcs);
541
    
542
    eNB->dlsch_SI->nCCE[subframe] = dci_alloc->firstCCE;
543 544 545
   
    LOG_I(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for common DCI (SI)  => %"PRIu8", aggregation %d\n",eNB->Mod_id,frame,subframe,
	  eNB->dlsch_SI->nCCE[subframe],1<<dci_alloc->L);
546 547 548 549
    
  } else if (dci_alloc->ra_flag == 1) {  // This is format 1A allocation for RA
    // configure dlsch parameters and CCE index
    LOG_D(PHY,"Generating dlsch params for RA_RNTI\n");    
550
    
551 552 553 554 555
    generate_eNB_dlsch_params_from_dci(frame,
				       subframe,
				       &dci_alloc->dci_pdu[0],
				       dci_alloc->rnti,
				       dci_alloc->format,
556
				       &eNB->dlsch_ra,
557
				       fp,
558
				       NULL,
559 560 561
				       SI_RNTI,
				       dci_alloc->rnti,
				       P_RNTI,
562 563
				       eNB->UE_stats[0].DL_pmi_single,
				       0);
564
    
565
        
566
    eNB->dlsch_ra->nCCE[subframe] = dci_alloc->firstCCE;
567
    
568 569 570
    LOG_I(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for common DCI (RA)  => %"PRIu8" length %d bits\n",eNB->Mod_id,frame,subframe,
	  eNB->dlsch_ra->nCCE[subframe],
	  dci_alloc->dci_length);
571 572 573 574 575 576 577
  }
  
  else if ((dci_alloc->format != format0)&&
	   (dci_alloc->format != format3)&&
	   (dci_alloc->format != format3A)&&
	   (dci_alloc->format != format4)){ // this is a normal DLSCH allocation
    
Raymond Knopp's avatar
 
Raymond Knopp committed
578

579 580
    
    if (UE_id>=0) {
581
      LOG_I(PHY,"Generating dlsch params for RNTI %x\n",dci_alloc->rnti);      
582
      
583 584 585 586 587
      generate_eNB_dlsch_params_from_dci(frame,
					 subframe,
					 &dci_alloc->dci_pdu[0],
					 dci_alloc->rnti,
					 dci_alloc->format,
588
					 eNB->dlsch[(uint8_t)UE_id],
589
					 fp,
590
					 &eNB->pdsch_config_dedicated[UE_id],
591 592 593
					 SI_RNTI,
					 0,
					 P_RNTI,
594 595
					 eNB->UE_stats[(uint8_t)UE_id].DL_pmi_single,
					 eNB->transmission_mode[(uint8_t)UE_id]<7?0:eNB->transmission_mode[(uint8_t)UE_id]);
596
      LOG_D(PHY,"[eNB %"PRIu8"][PDSCH %"PRIx16"/%"PRIu8"] Frame %d subframe %d: Generated dlsch params\n",
597
	    eNB->Mod_id,dci_alloc->rnti,eNB->dlsch[(uint8_t)UE_id][0]->current_harq_pid,frame,subframe);
598 599
      
      
Cedric Roux's avatar
Cedric Roux committed
600 601
      T(T_ENB_PHY_DLSCH_UE_DCI, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(UE_id),
        T_INT(dci_alloc->rnti), T_INT(dci_alloc->format),
602 603 604
        T_INT(dci_alloc->harq_pid),
        T_INT(eNB->dlsch[(int)UE_id][0]->harq_processes[dci_alloc->harq_pid]->mcs),
        T_INT(eNB->dlsch[(int)UE_id][0]->harq_processes[dci_alloc->harq_pid]->TBS));
605

606
      eNB->dlsch[(uint8_t)UE_id][0]->nCCE[subframe] = dci_alloc->firstCCE;
607
      
608 609
      LOG_I(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for ue DCI (PDSCH %"PRIx16")  => %"PRIu8" length %d bits\n",eNB->Mod_id,frame,subframe,
	    dci_alloc->rnti,eNB->dlsch[(uint8_t)UE_id][0]->nCCE[subframe],dci_alloc->dci_length);
610 611 612
      
      LOG_D(PHY,"[eNB %"PRIu8"][DCI][PDSCH %"PRIx16"] Frame %d subframe %d UE_id %"PRId8" Generated DCI format %d, aggregation %d\n",
	    eNB->Mod_id, dci_alloc->rnti,
613
	    frame, subframe,UE_id,
614 615
	    dci_alloc->format,
	    1<<dci_alloc->L);
Raymond Knopp's avatar
 
Raymond Knopp committed
616
    } else {
617
      LOG_D(PHY,"[eNB %"PRIu8"][PDSCH] Frame %d : No UE_id with corresponding rnti %"PRIx16", dropping DLSCH\n",
618
	    eNB->Mod_id,frame,dci_alloc->rnti);
619
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
620
  }
621 622
  
}
623

624
void generate_eNB_ulsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,const int UE_id) {
625

626
  int harq_pid;
627
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
628
  int frame = proc->frame_tx;
Raymond Knopp's avatar
Raymond Knopp committed
629
  int subframe = proc->subframe_tx;
630 631 632 633 634 635
  
//  uint16_t srsPeriodicity=0;
//  uint16_t srsOffset=0;
//  uint16_t srsConfigIndex=0;
//  uint16_t do_srs=0;
  
636
  uint16_t is_srs_pos=0;
637

638
  LOG_I(PHY,
639 640 641
	"[eNB %"PRIu8"][PUSCH %"PRIu8"] Frame %d subframe %d UL Frame %"PRIu32", UL Subframe %"PRIu8", Generated ULSCH (format0) DCI (rnti %"PRIx16", dci %"PRIx8"), aggregation %d\n",
	eNB->Mod_id,
	subframe2harq_pid(fp,
642
			  pdcch_alloc2ul_frame(fp,frame,subframe),
643
			  pdcch_alloc2ul_subframe(fp,subframe)),
644
	frame,
645
	subframe,
646
	pdcch_alloc2ul_frame(fp,frame,subframe),
647 648 649 650 651
	pdcch_alloc2ul_subframe(fp,subframe),
	dci_alloc->rnti,
	dci_alloc->dci_pdu[0],
	1<<dci_alloc->L);
  
652
  is_srs_pos = is_srs_occasion_common(fp,pdcch_alloc2ul_frame(fp,frame,subframe),pdcch_alloc2ul_subframe(fp,subframe));
653 654 655 656 657 658 659 660 661 662 663 664
  
//if (is_srs_pos && eNB->soundingrs_ul_config_dedicated[UE_id].srsConfigDedicatedSetup) {
//    srsConfigIndex = eNB->soundingrs_ul_config_dedicated[UE_id].srs_ConfigIndex;
//    compute_srs_pos(fp->frame_type, srsConfigIndex, &srsPeriodicity, &srsOffset);
//    if ((((10*pdcch_alloc2ul_frame(fp,frame,subframe)+pdcch_alloc2ul_subframe(fp,subframe)) % srsPeriodicity) == srsOffset)) {
//     do_srs = 1;
//    }
//  }
//      LOG_D(PHY,"frame %d (%d), subframe %d (%d), UE_id %d: is_srs_pos %d, do_SRS %d, index %d, period %d, offset %d \n",
//	    frame,pdcch_alloc2ul_frame(fp,frame,subframe),subframe,pdcch_alloc2ul_subframe(fp,subframe),
//	    UE_id,is_srs_pos,do_srs,srsConfigIndex,srsPeriodicity,srsOffset);
//  
665

666
  generate_eNB_ulsch_params_from_dci(eNB,
667
				     proc,
668
				     &dci_alloc->dci_pdu[0],
669 670 671 672 673 674 675
				     dci_alloc->rnti,
				     format0,
				     UE_id,
				     SI_RNTI,
				     0,
				     P_RNTI,
				     CBA_RNTI,
676
				     is_srs_pos);  
677
  LOG_T(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resources for UE spec DCI (PUSCH %"PRIx16") => %d\n",
678
	eNB->Mod_id,frame,subframe,dci_alloc->rnti,
679 680 681 682
	dci_alloc->firstCCE);
  
  // get the hard_pid for this subframe 
  harq_pid = subframe2harq_pid(fp,
683
			       pdcch_alloc2ul_frame(fp,frame,subframe),
684 685
			       pdcch_alloc2ul_subframe(fp,subframe));
  
686 687 688
  AssertFatal(harq_pid!=255,"[eNB %"PRIu8"] Frame %d: Bad harq_pid for ULSCH allocation\n",eNB->Mod_id,frame);

  eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 1;
689
  
Cedric Roux's avatar
Cedric Roux committed
690
  T(T_ENB_PHY_ULSCH_UE_DCI, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(UE_id),
Cedric Roux's avatar
Cedric Roux committed
691 692 693 694 695
    T_INT(dci_alloc->rnti), T_INT(harq_pid),
    T_INT(eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->mcs),
    T_INT(eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->round),
    T_INT(eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->first_rb),
    T_INT(eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->nb_rb),
696 697 698
    T_INT(eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->TBS),
    T_INT(dci_alloc->L),
    T_INT(dci_alloc->firstCCE));
699
}
700
*/
701

702 703 704 705 706 707
void pdsch_procedures(PHY_VARS_eNB *eNB,
		      eNB_rxtx_proc_t *proc,
		      int harq_pid,
		      LTE_eNB_DLSCH_t *dlsch, 
		      LTE_eNB_DLSCH_t *dlsch1,
		      LTE_eNB_UE_stats *ue_stats,
708
		      int ra_flag) {
709

710 711
  int frame=proc->frame_tx;
  int subframe=proc->subframe_tx;
712 713
  LTE_DL_eNB_HARQ_t *dlsch_harq=dlsch->harq_processes[harq_pid];
  int input_buffer_length = dlsch_harq->TBS/8;
714
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
715
  int i;
716

islam.galal's avatar
islam.galal committed
717
  if (frame < 20) {
718

islam.galal's avatar
islam.galal committed
719
    LOG_D(PHY,
720
	  "[eNB %"PRIu8"][PDSCH %"PRIx16"/%"PRIu8"] Frame %d, subframe %d: Generating PDSCH/DLSCH with input size = %"PRIu16", pdsch_start %d, G %d, nb_rb %"PRIu16", rb0 %x, rb1 %x, TBS %"PRIu16", pmi_alloc %"PRIx64", rv %"PRIu8" (round %"PRIu8")\n",
islam.galal's avatar
islam.galal committed
721
	  eNB->Mod_id, dlsch->rnti,harq_pid,
722
	  frame, subframe, input_buffer_length, dlsch_harq->pdsch_start,
islam.galal's avatar
islam.galal committed
723 724 725 726 727
	  get_G(fp,
		dlsch_harq->nb_rb,
		dlsch_harq->rb_alloc,
		dlsch_harq->Qm,
		dlsch_harq->Nl,
728
		dlsch_harq->pdsch_start,
islam.galal's avatar
islam.galal committed
729 730 731 732 733 734 735 736 737
		frame,
		subframe,
		dlsch_harq->mimo_mode==TM7?7:0),
	  dlsch_harq->nb_rb,
	  dlsch_harq->rb_alloc[0],
	  dlsch_harq->rb_alloc[1],
	  dlsch_harq->TBS,
	  pmi2hex_2Ar1(dlsch_harq->pmi_alloc),
	  dlsch_harq->rvidx,
738 739
	  dlsch_harq->round);
  }    
740
#if defined(MESSAGE_CHART_GENERATOR_PHY)
741 742 743
  MSC_LOG_TX_MESSAGE(
		     MSC_PHY_ENB,MSC_PHY_UE,
		     NULL,0,
islam.galal's avatar
islam.galal committed
744
		     "%05u:%02u PDSCH/DLSCH input size = %"PRIu16", G %d, nb_rb %"PRIu16", TBS %"PRIu16", pmi_alloc %"PRIx16", rv %"PRIu8" (round %"PRIu8")",
745 746 747 748 749
		     frame, subframe,
		     input_buffer_length,
		     get_G(fp,
			   dlsch_harq->nb_rb,
			   dlsch_harq->rb_alloc,
islam.galal's avatar
islam.galal committed
750
			   dlsch_harq->Qm,
751
			   dlsch_harq->Nl,
752
			   dlsch_harq->pdsch_start,
753 754 755
			   frame,
			   subframe,
			   dlsch_harq->mimo_mode==TM7?7:0),
756
		     dlsch_harq->nb_rb,
islam.galal's avatar
islam.galal committed
757
		     dlsch_harq->TBS,
758 759 760 761
		     pmi2hex_2Ar1(dlsch_harq->pmi_alloc),
		     dlsch_harq->rvidx,
		     dlsch_harq->round);
#endif
762 763
  
  
764
  if (ue_stats) ue_stats->dlsch_sliding_cnt++;
765
  
766 767 768
  if (dlsch_harq->round == 0) {
    if (ue_stats)
      ue_stats->dlsch_trials[harq_pid][0]++;
769 770 771 772 773 774 775 776
  } else {
    ue_stats->dlsch_trials[harq_pid][dlsch_harq->round]++;
#ifdef DEBUG_PHY_PROC
#ifdef DEBUG_DLSCH
    LOG_D(PHY,"[eNB] This DLSCH is a retransmission\n");
#endif
#endif
  }
777 778


779 780 781 782 783
  LOG_D(PHY,"Generating DLSCH/PDSCH %d\n",ra_flag);
  // 36-212
  start_meas(&eNB->dlsch_encoding_stats);
  eNB->te(eNB,
	  dlsch_harq->pdu,
784
	  dlsch_harq->pdsch_start,
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
	  dlsch,
	  frame,subframe,
	  &eNB->dlsch_rate_matching_stats,
	  &eNB->dlsch_turbo_encoding_stats,
	  &eNB->dlsch_interleaving_stats);
  stop_meas(&eNB->dlsch_encoding_stats);
  // 36-211
  start_meas(&eNB->dlsch_scrambling_stats);
  dlsch_scrambling(fp,
		   0,
		   dlsch,
		   harq_pid,
		   get_G(fp,
			 dlsch_harq->nb_rb,
			 dlsch_harq->rb_alloc,
islam.galal's avatar
islam.galal committed
800
			 dlsch_harq->Qm,
801
			 dlsch_harq->Nl,
802
			 dlsch_harq->pdsch_start,
803 804 805
			 frame,subframe,
			 0),
		   0,
806
		   frame,
807 808 809 810 811 812 813 814 815 816
		   subframe<<1);
  stop_meas(&eNB->dlsch_scrambling_stats);
  
  start_meas(&eNB->dlsch_modulation_stats);
  
  
  dlsch_modulation(eNB,
		   eNB->common_vars.txdataF,
		   AMP,
		   subframe,
817
		   dlsch_harq->pdsch_start,
818 819 820 821
		   dlsch,
		   dlsch1);
  
  stop_meas(&eNB->dlsch_modulation_stats);
822

823 824
  dlsch->active = 0;
}
825 826


827 828 829 830
void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,nfapi_dl_config_request_pdu_t *dl_config_pdu);
void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB,  
			     eNB_rxtx_proc_t *proc,
			     nfapi_dl_config_request_pdu_t *dl_config_pdu) {
831

832 833 834
  int idx                         = proc->subframe_tx&1;  
  LTE_eNB_PDCCH *pdcch_vars       = &eNB->pdcch_vars[idx];
  nfapi_dl_config_dci_dl_pdu *pdu = &dl_config_pdu->dci_dl_pdu;
835

836
  LOG_D(PHY,"Frame %d, Subframe %d: DCI processing\n",proc->frame_tx,proc->subframe_tx);
837

838 839 840
  // copy dci configuration into eNB structure
  fill_dci_and_dlsch(eNB,proc,&pdcch_vars->dci_alloc[pdcch_vars->num_dci],pdu);
}
841

842 843 844 845 846 847 848 849 850
void handle_nfapi_mpdcch_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,nfapi_dl_config_request_pdu_t *dl_config_pdu);
void handle_nfapi_mpdcch_pdu(PHY_VARS_eNB *eNB,  
			     eNB_rxtx_proc_t *proc,
			     nfapi_dl_config_request_pdu_t *dl_config_pdu) {

  int idx                         = proc->subframe_tx&1;  
  LTE_eNB_MPDCCH *mpdcch_vars     = &eNB->mpdcch_vars[idx];
  nfapi_dl_config_mpdcch_pdu *pdu = &dl_config_pdu->mpdcch_pdu;

851
  LOG_D(PHY,"Frame %d, Subframe %d: MDCI processing\n",proc->frame_tx,proc->subframe_tx);
852 853 854 855 856

  // copy dci configuration into eNB structure
  fill_mdci_and_dlsch(eNB,proc,&mpdcch_vars->mdci_alloc[mpdcch_vars->num_dci],pdu);
}

857 858
void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
				  nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu);
859

860 861 862 863 864 865 866 867 868
void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,  
				  nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu) {
  
  int idx                         = proc->subframe_tx&1;
  LTE_eNB_PDCCH *pdcch_vars       = &eNB->pdcch_vars[idx];
  nfapi_hi_dci0_dci_pdu *pdu      = &hi_dci0_config_pdu->dci_pdu;
  // copy dci configuration in to eNB structure
  fill_dci_and_ulsch(eNB,proc,&pdcch_vars->dci_alloc[pdcch_vars->num_dci],pdu);
}
869

870 871 872 873 874 875 876 877 878
void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
				 nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu);


void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,  
				 nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu) {
  
  nfapi_hi_dci0_hi_pdu *pdu      = &hi_dci0_config_pdu->hi_pdu;
  // copy dci configuration in to eNB structure
879
  LOG_D(PHY,"Received HI PDU which value %d (rbstart %d,cshift %d)\n",
880 881 882 883
	hi_dci0_config_pdu->hi_pdu.hi_pdu_rel8.hi_value,
	hi_dci0_config_pdu->hi_pdu.hi_pdu_rel8.resource_block_start,
	hi_dci0_config_pdu->hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms);
}
884

885 886 887
handle_nfapi_bch_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,  
		     nfapi_dl_config_request_pdu_t *dl_config_pdu,
		     uint8_t *sdu) {
888

889 890 891
  nfapi_dl_config_bch_pdu_rel8_t *rel8 = &dl_config_pdu->bch_pdu.bch_pdu_rel8;
  
  AssertFatal(rel8->length == 3, "BCH PDU has length %d != 3\n",rel8->length);
892

893
  LOG_D(PHY,"bch_pdu: %x,%x,%x\n",sdu[0],sdu[1],sdu[2]);
894 895 896
  eNB->pbch_pdu[0] = sdu[2];
  eNB->pbch_pdu[1] = sdu[1];
  eNB->pbch_pdu[2] = sdu[0];
897

898
  // adjust transmit amplitude here based on NFAPI info
899

900 901
}

902 903 904 905 906 907 908 909 910 911 912
#ifdef Rel14
extern uint32_t localRIV2alloc_LUT6[32];
extern uint32_t localRIV2alloc_LUT25[512];
extern uint32_t localRIV2alloc_LUT50_0[1600];
extern uint32_t localRIV2alloc_LUT50_1[1600];
extern uint32_t localRIV2alloc_LUT100_0[6000];
extern uint32_t localRIV2alloc_LUT100_1[6000];
extern uint32_t localRIV2alloc_LUT100_2[6000];
extern uint32_t localRIV2alloc_LUT100_3[6000];
#endif

913 914 915 916 917 918
handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,  
		       nfapi_dl_config_request_pdu_t *dl_config_pdu,
		       uint8_t codeword_index,
		       uint8_t *sdu) {

  nfapi_dl_config_dlsch_pdu_rel8_t *rel8 = &dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8;
919 920 921
#ifndef Rel8
  nfapi_dl_config_dlsch_pdu_rel10_t *rel10 = &dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10;
#endif
922 923 924
#ifdef Rel14
  nfapi_dl_config_dlsch_pdu_rel13_t *rel13 = &dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13;
#endif
925 926 927 928
  LTE_eNB_DLSCH_t *dlsch0=NULL,*dlsch1=NULL;
  LTE_DL_eNB_HARQ_t *dlsch0_harq=NULL,*dlsch1_harq=NULL;
  int UE_id;
  int harq_pid;
929
  
930 931 932 933
  
  UE_id = find_dlsch(rel8->rnti,eNB,SEARCH_EXIST_OR_FREE);
  AssertFatal(UE_id!=-1,"no free or exiting dlsch_context\n");
  AssertFatal(UE_id<NUMBER_OF_UE_MAX,"returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n",UE_id,NUMBER_OF_UE_MAX);
934
  
935 936
  dlsch0 = eNB->dlsch[UE_id][0];
  dlsch1 = eNB->dlsch[UE_id][1];
937 938

#ifdef Rel14
islam.galal's avatar
islam.galal committed
939
  if ((rel13->pdsch_payload_type < 2) && (rel13->ue_type>0)) dlsch0->harq_ids[proc->subframe_tx] = 0;
940 941
#endif

942 943 944 945 946 947
  harq_pid        = dlsch0->harq_ids[proc->subframe_tx];
  AssertFatal((harq_pid>=0) && (harq_pid<8),"harq_pid %d not in 0...7\n",harq_pid);
  dlsch0_harq     = dlsch0->harq_processes[harq_pid];
  dlsch1_harq     = dlsch1->harq_processes[harq_pid];
  AssertFatal(dlsch0_harq!=NULL,"dlsch_harq is null\n");

948 949
  dlsch0_harq->pdsch_start = eNB->pdcch_vars[proc->subframe_tx & 1].num_pdcch_symbols;

950
  LOG_D(PHY,"NFAPI: frame %d, subframe %d: programming dlsch, rnti %x, UE_id %d, harq_pid %d\n",
951
    proc->frame_tx,proc->subframe_tx,rel8->rnti,UE_id,harq_pid);
952 953 954
  if (codeword_index == 0) dlsch0_harq->pdu                    = sdu;
  else                     dlsch1_harq->pdu                    = sdu;

955
#ifdef Rel14
islam.galal's avatar
islam.galal committed
956
  dlsch0->sib1_br_flag=0;
957

958
  if ((rel13->pdsch_payload_type <2) && (rel13->ue_type>0)) { // this is a BR/CE UE and SIB1-BR/SI-BR
959 960 961 962 963 964
    dlsch0->rnti             = 0xFFFF;
    dlsch0->Kmimo            = 1;
    dlsch0->Mdlharq          = 4; 
    dlsch0->Nsoft            = 25344;
    dlsch0->i0               = rel13->initial_transmission_sf_io;
    dlsch0_harq->pdsch_start = rel10->pdsch_start;
islam.galal's avatar
islam.galal committed
965 966 967

    if (rel13->pdsch_payload_type == 0) dlsch0->sib1_br_flag=1;

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
    // configure PDSCH
    switch (eNB->frame_parms.N_RB_DL) {
    case 6:
      dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT6[rel8->resource_block_coding];
      break;
    case 15:
      AssertFatal(1==0,"15 PRBs not supported for now\n");
      break;
    case 25:
      dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT25[rel8->resource_block_coding];
      break;
    case 50:  
      dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT50_0[rel8->resource_block_coding];
      dlsch0_harq->rb_alloc[1]      = localRIV2alloc_LUT50_1[rel8->resource_block_coding];
      break;
    case 75:
      AssertFatal(1==0,"75 PRBs not supported for now\n");
      break;
    case 100:
      dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT100_0[rel8->resource_block_coding];
      dlsch0_harq->rb_alloc[1]      = localRIV2alloc_LUT100_1[rel8->resource_block_coding];
      dlsch0_harq->rb_alloc[2]      = localRIV2alloc_LUT100_2[rel8->resource_block_coding];
      dlsch0_harq->rb_alloc[3]      = localRIV2alloc_LUT100_3[rel8->resource_block_coding];
    }

    dlsch0->active                  = 1;
994 995
  
    dlsch0_harq->nb_rb              = 6; 
996
    dlsch0_harq->vrb_type           = LOCALIZED;
997 998
    dlsch0_harq->rvidx              = rel8->redundancy_version;
    dlsch0_harq->Nl                 = 1;
999 1000 1001 1002
    dlsch0_harq->mimo_mode          = (eNB->frame_parms.nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI;
    dlsch0_harq->dl_power_off       = 1;
    dlsch0_harq->round              = 0;
    dlsch0_harq->status             = ACTIVE;
1003
    dlsch0_harq->TBS                = rel8->length<<3;
islam.galal's avatar
islam.galal committed
1004 1005
    dlsch0_harq->Qm                 = rel8->modulation;
    dlsch0_harq->codeword           = 0;
1006 1007 1008 1009 1010
  }
  else {

  }
#endif
1011 1012
}

1013 1014 1015 1016
handle_uci_harq_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,nfapi_ul_config_request_pdu_t *ul_config_pdu) {

}

1017 1018 1019 1020
handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,  
		    nfapi_ul_config_request_pdu_t *ul_config_pdu) {

  nfapi_ul_config_ulsch_pdu_rel8_t *rel8 = &ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8;
1021 1022 1023 1024 1025

  uint16_t *RIV2nb_rb_LUT, *RIV2first_rb_LUT;
  uint16_t RIV_max;
  uint16_t use_srs=0;

1026
  int8_t UE_id;
1027 1028 1029
  LTE_eNB_ULSCH_t *ulsch;
  LTE_UL_eNB_HARQ_t *ulsch_harq;

1030
  // check if we have received a dci for this ue and ulsch descriptor is configured
1031 1032 1033 1034 1035 1036

  if (ul_config_pdu == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE) {
    AssertFatal((UE_id = find_ulsch(rel8->rnti,eNB,SEARCH_EXIST))>=0,
		"No existing UE ULSCH for rnti %x\n",rel8->rnti);
    AssertFatal(eNB->ulsch[UE_id]->harq_mask > 0,
		"ulsch for UE_id %d is not active\n",UE_id);
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
    LOG_I(PHY,"Applying UL config for UE %d, rnti %x\n",
	  UE_id,rel8->rnti);
    /*
#ifdef Rel14
    nfapi_ul_config_ulsch_pdu_rel13_t *rel13 = &ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13;
    int harq_pid = rel8->harq_process_number;

    if (rel13->ue_type > 0) { // This is a BL/CE UE, retrieve PUSCH programming
      ulsch = eNB->ulsch[UE_id];
      
      ulsch_harq = ulsch->harq_processes[harq_pid];
      
      switch (eNB->frame_parms.N_RB_DL) {
      case 6:
	RIV2nb_rb_LUT     = &RIV2nb_rb_LUT6[0];
	RIV2first_rb_LUT  = &RIV2first_rb_LUT6[0];
	RIV_max           = RIV_max6;
	break;
	
      case 25:
	RIV2nb_rb_LUT     = &RIV2nb_rb_LUT25[0];
	RIV2first_rb_LUT  = &RIV2first_rb_LUT25[0];
	RIV_max           = RIV_max25;
	break;
	
      case 50:
	RIV2nb_rb_LUT     = &RIV2nb_rb_LUT50[0];
	RIV2first_rb_LUT  = &RIV2first_rb_LUT50[0];
	RIV_max           = RIV_max50;
	break;
	
      case 100:
	RIV2nb_rb_LUT     = &RIV2nb_rb_LUT100[0];
	RIV2first_rb_LUT  = &RIV2first_rb_LUT100[0];
	RIV_max           = RIV_max100;
	break;
	
      default:
	DevParam(frame_parms->N_RB_DL, harq_pid, 0);
	break;
      }
      
      
      ulsch_harq->first_rb               = rel8->resource_block_start;
      ulsch_harq->nb_rb                  = rel8->number_of_resource_blocks;
      ulsch_harq->O_RI                   = 0;//1;
      ulsch_harq->Or2                    = 0;
      ulsch_harq->Or1                    = 0;
      ulsch_harq->O_ACK                  = 0;//2;
      ulsch->beta_offset_cqi_times8      = 18;
      ulsch->beta_offset_ri_times8       = 10;
      ulsch->beta_offset_harqack_times8  = 16;
      
      ulsch->rnti = rel8->rnti;
      ulsch->harq_mask = 1<<harq_pid;
      
      if (ulsch_harq->round == 0) {
	ulsch_harq->status = ACTIVE;
	ulsch_harq->rvidx = 0;
	//ulsch_harq->TBS         = dlsch_tbs25[ulsch_harq->mcs][ulsch_harq->nb_rb-1];
	ulsch_harq->TBS         = TBStable[get_I_TBS_UL(ulsch_harq->mcs)][ulsch_harq->nb_rb-1];
	ulsch_harq->Msc_initial   = 12*ulsch_harq->nb_rb;
	ulsch_harq->Nsymb_initial = 9;
	ulsch_harq->round = 0;
      } else {
	ulsch_harq->rvidx = 0;
	ulsch_harq->round++;
      }
      use_srs = is_srs_occasion_common(frame_parms,ulsch_harq->frame,ulsch_harq->subframe);
      ulsch_harq->Nsymb_pusch = 12-(frame_parms->Ncp<<1)-(use_srs==0?0:1);
      ulsch_harq->srs_active                            = use_srs;
    }
    #endif
*/
1111 1112 1113 1114 1115 1116 1117
  }
  else if (ul_config_pdu == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) {
    AssertFatal((UE_id = find_uci(rel8->rnti,proc->frame_tx,proc->subframe_tx,eNB,SEARCH_EXIST))>=0,
		"No existing UE UCI for rnti %x\n",rel8->rnti);
    handle_uci_harq_pdu(eNB,proc,ul_config_pdu);
  }
  else if (ul_config_pdu == NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE) {
1118
    
1119 1120
  }
  else if (ul_config_pdu == NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE) {
1121
    
1122 1123
  }
  else if (ul_config_pdu == NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE) {
1124
    
1125 1126
  }
  else if (ul_config_pdu == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE) {
1127
    
1128 1129
  }
  else if (ul_config_pdu == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE) {
1130
    
1131
  }
1132 1133 1134
	      
}

1135 1136 1137 1138 1139
void schedule_response(Sched_Rsp_t *Sched_INFO) {

  PHY_VARS_eNB *eNB;
  eNB_rxtx_proc_t *proc;
  // copy data from L2 interface into L1 structures
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
  module_id_t               Mod_id       = Sched_INFO->module_id;
  uint8_t                   CC_id        = Sched_INFO->CC_id;
  nfapi_dl_config_request_t *DL_req      = Sched_INFO->DL_req;
  nfapi_hi_dci0_request_t   *HI_DCI0_req = Sched_INFO->HI_DCI0_req;
  nfapi_ul_config_request_t *UL_req      = Sched_INFO->UL_req;
  nfapi_tx_request_t        *TX_req      = Sched_INFO->TX_req;
  frame_t                   frame        = Sched_INFO->frame;
  sub_frame_t               subframe     = Sched_INFO->subframe;
  LTE_DL_FRAME_PARMS        *fp;
  int                       ul_subframe;
  int                       ul_frame;
  int                       harq_pid;
  LTE_UL_eNB_HARQ_t         *ulsch_harq;
1153 1154 1155 1156 1157

  AssertFatal(RC.eNB!=NULL,"RC.eNB is null\n");
  AssertFatal(RC.eNB[Mod_id]!=NULL,"RC.eNB[%d] is null\n",Mod_id);
  AssertFatal(RC.eNB[Mod_id][CC_id]!=NULL,"RC.eNB[%d][%d] is null\n",Mod_id,CC_id);

1158 1159 1160 1161 1162
  eNB         = RC.eNB[Mod_id][CC_id];
  fp          = &eNB->frame_parms;
  proc        = &eNB->proc.proc_rxtx[0];
  ul_subframe = pdcch_alloc2ul_subframe(fp,subframe);
  ul_frame    = pdcch_alloc2ul_frame(fp,frame,subframe);
1163 1164 1165 1166

  AssertFatal(proc->subframe_tx == subframe, "Current subframe %d != NFAPI subframe %d\n",proc->subframe_tx,subframe);
  AssertFatal(proc->subframe_tx == subframe, "Current frame %d != NFAPI frame %d\n",proc->frame_tx,frame);

1167 1168 1169 1170 1171 1172
  int8_t UE_id;
  uint8_t number_dl_pdu             = DL_req->dl_config_request_body.number_pdu;
  uint8_t number_hi_dci0_pdu        = HI_DCI0_req->hi_dci0_request_body.number_of_dci+HI_DCI0_req->hi_dci0_request_body.number_of_hi;
  uint8_t number_ul_pdu             = UL_req->ul_config_request_body.number_of_pdus;
  uint8_t number_pdsch_rnti         = DL_req->dl_config_request_body.number_pdsch_rnti;
  uint8_t transmission_power_pcfich = DL_req->dl_config_request_body.transmission_power_pcfich;
1173 1174 1175


  nfapi_dl_config_request_pdu_t *dl_config_pdu;
1176 1177
  nfapi_hi_dci0_request_pdu_t   *hi_dci0_req_pdu;
  nfapi_ul_config_request_pdu_t *ul_config_pdu;
1178 1179 1180

  int i;

1181
  eNB->pdcch_vars[subframe&1].num_pdcch_symbols = DL_req->dl_config_request_body.number_pdcch_ofdm_symbols;
1182 1183 1184
  eNB->pdcch_vars[subframe&1].num_dci           = 0;


1185
  LOG_D(PHY,"NFAPI: received %d dl_pdu, %d tx_req, %d hi_dci0_config_req, %d UL_config \n",
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
	number_dl_pdu,TX_req->tx_request_body.number_of_pdus,number_hi_dci0_pdu,number_ul_pdu);

  
  if ((subframe_select(fp,ul_subframe)==SF_UL) ||
      (fp->frame_type == FDD)) {
    harq_pid = subframe2harq_pid(fp,ul_frame,ul_subframe);

    // clear DCI allocation maps for new subframe
    
    for (i=0; i<NUMBER_OF_UE_MAX; i++) {
      if (eNB->ulsch[i]) {
	ulsch_harq = eNB->ulsch[i]->harq_processes[harq_pid];
        ulsch_harq->dci_alloc=0;
        ulsch_harq->rar_alloc=0;
      }
    }
  }
1203
  for (i=0;i<number_dl_pdu;i++) {
1204
    dl_config_pdu = &DL_req->dl_config_request_body.dl_config_pdu_list[i];
1205
    LOG_D(PHY,"NFAPI: dl_pdu %d : type %d\n",i,dl_config_pdu->pdu_type);
1206 1207 1208
    switch (dl_config_pdu->pdu_type) {
    case NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE:
      handle_nfapi_dci_dl_pdu(eNB,proc,dl_config_pdu);
1209
      eNB->pdcch_vars[subframe&1].num_dci++;
1210 1211
      break;
    case NFAPI_DL_CONFIG_BCH_PDU_TYPE:
1212
      AssertFatal(dl_config_pdu->bch_pdu.bch_pdu_rel8.pdu_index<TX_req->tx_request_body.number_of_pdus,
1213 1214
		  "bch_pdu_rel8.pdu_index>=TX_req->number_of_pdus (%d>%d)\n",
		  dl_config_pdu->bch_pdu.bch_pdu_rel8.pdu_index,
1215
		  TX_req->tx_request_body.number_of_pdus);
1216
      eNB->pbch_configured=1;
1217 1218
      handle_nfapi_bch_pdu(eNB,proc,dl_config_pdu,
			   TX_req->tx_request_body.tx_pdu_list[dl_config_pdu->bch_pdu.bch_pdu_rel8.pdu_index].segments[0].segment_data);
1219 1220 1221 1222 1223
      break;
    case NFAPI_DL_CONFIG_MCH_PDU_TYPE:
      //      handle_nfapi_mch_dl_pdu(eNB,dl_config_pdu);
      break;
    case NFAPI_DL_CONFIG_DLSCH_PDU_TYPE:
1224
      AssertFatal(dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index<TX_req->tx_request_body.number_of_pdus,
1225 1226
		  "dlsch_pdu_rel8.pdu_index>=TX_req->number_of_pdus (%d>%d)\n",
		  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index,
1227
		  TX_req->tx_request_body.number_of_pdus);
1228 1229 1230 1231 1232 1233
      AssertFatal((dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks<3) &&
		  (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks>0),
		  "dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = %d not in [1,2]\n",
		  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks);
      handle_nfapi_dlsch_pdu(eNB,proc,dl_config_pdu,
			     dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks-1,
1234
			     TX_req->tx_request_body.tx_pdu_list[dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data);
1235
      if (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti == eNB->preamble_list[0].preamble_rel8.rnti) {// is RAR pdu
1236
	LOG_I(PHY,"Frame %d, Subframe %d: Received LTE RAR pdu, programming based on UL Grant\n"); 
1237 1238 1239 1240 1241 1242
	generate_eNB_ulsch_params_from_rar(eNB,
					   TX_req->tx_request_body.tx_pdu_list[dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data,
					   frame,
					   subframe);
					   
      }					   
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
      break;
    case NFAPI_DL_CONFIG_PCH_PDU_TYPE:
      //      handle_nfapi_pch_pdu(eNB,dl_config_pdu);
      break;
    case NFAPI_DL_CONFIG_PRS_PDU_TYPE:
      //      handle_nfapi_prs_pdu(eNB,dl_config_pdu);
      break;
    case NFAPI_DL_CONFIG_CSI_RS_PDU_TYPE:
      //      handle_nfapi_csi_rs_pdu(eNB,dl_config_pdu);
      break;
    case NFAPI_DL_CONFIG_EPDCCH_DL_PDU_TYPE:
      //      handle_nfapi_epdcch_pdu(eNB,dl_config_pdu);
      break;
    case NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE:
1257 1258
      handle_nfapi_mpdcch_pdu(eNB,proc,dl_config_pdu);
      eNB->mpdcch_vars[subframe&1].num_dci++; 
1259 1260
      break;
    }
1261
  }
1262 1263
  
  for (i=0;i<number_hi_dci0_pdu;i++) {
1264
    hi_dci0_req_pdu = &HI_DCI0_req->hi_dci0_request_body.hi_dci0_pdu_list[i];
1265
    switch (hi_dci0_req_pdu->pdu_type) {
1266

1267 1268 1269 1270
    case NFAPI_HI_DCI0_DCI_PDU_TYPE:
      handle_nfapi_hi_dci0_dci_pdu(eNB,proc,hi_dci0_req_pdu);
      eNB->pdcch_vars[subframe&1].num_dci++; 
      break;
1271 1272 1273

    case NFAPI_HI_DCI0_HI_PDU_TYPE:
      handle_nfapi_hi_dci0_hi_pdu(eNB,proc,hi_dci0_req_pdu);
Raymond.Knopp's avatar
Raymond.Knopp committed
1274
      eNB->pdcch_vars[subframe&1].num_dci++; 
1275

1276
      break;
1277 1278
    }
  } 
1279 1280 1281

  for (i=0;i<number_ul_pdu;i++) {
    ul_config_pdu = &UL_req->ul_config_request_body.ul_config_pdu_list[i];
1282
    LOG_I(PHY,"NFAPI: ul_pdu %d : type %d\n",i,ul_config_pdu->pdu_type);
1283 1284
    AssertFatal(ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE ||
		ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE,
1285 1286 1287
		"Optional UL_PDU type %d not supported\n",ul_config_pdu->pdu_type);
    handle_nfapi_ul_pdu(eNB,proc,ul_config_pdu);
  }
1288
}
1289

1290 1291


1292
void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
1293
			   eNB_rxtx_proc_t *proc,
1294
                           relaying_type_t r_type,
1295 1296
			   PHY_VARS_RN *rn,
			   int do_meas)
1297 1298
{
  UNUSED(rn);
1299 1300
  int frame=proc->frame_tx;
  int subframe=proc->subframe_tx;
1301
  uint32_t i,j,aa;
1302
  uint8_t harq_pid;
1303
  int8_t UE_id=0;
1304
  uint8_t num_pdcch_symbols=0;
1305
  uint8_t num_dci=0;
1306 1307
  uint8_t ul_subframe;
  uint32_t ul_frame;
1308
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
1309
  LTE_UL_eNB_HARQ_t *ulsch_harq;
1310

1311
  int offset = eNB->CC_id;//proc == &eNB->proc.proc_rxtx[0] ? 0 : 1;
1312

1313
  if ((fp->frame_type == TDD) && (subframe_select(fp,subframe)==SF_UL)) return;
1314

1315
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,1);
1316
  if (do_meas==1) start_meas(&eNB->phy_proc_tx);
1317

Cedric Roux's avatar
Cedric Roux committed
1318
  T(T_ENB_PHY_DL_TICK, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe));
1319

1320
  /*
1321 1322
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
    // If we've dropped the UE, go back to PRACH mode for this UE
1323 1324 1325
    if ((frame==0)&&(subframe==0)) {
      if (eNB->UE_stats[i].crnti > 0) {
	LOG_I(PHY,"UE %d : rnti %x\n",i,eNB->UE_stats[i].crnti);
1326
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
1327
    }
1328
    if (eNB->UE_stats[i].ulsch_consecutive_errors == ULSCH_max_consecutive_errors) {
1329
      LOG_W(PHY,"[eNB %d, CC %d] frame %d, subframe %d, UE %d: ULSCH consecutive error count reached %u, triggering UL Failure\n",
1330 1331
            eNB->Mod_id,eNB->CC_id,frame,subframe, i, eNB->UE_stats[i].ulsch_consecutive_errors);
      eNB->UE_stats[i].ulsch_consecutive_errors=0;
1332 1333 1334
      mac_xface->UL_failure_indication(eNB->Mod_id,
				       eNB->CC_id,
				       frame,
1335
				       eNB->UE_stats[i].crnti,
1336 1337
				       subframe);
				       
Raymond Knopp's avatar
 
Raymond Knopp committed
1338
    }
1339
	
1340

Raymond Knopp's avatar
 
Raymond Knopp committed
1341
  }
1342 1343 1344


  // Get scheduling info for next subframe
1345
  // This is called only for the CC_id = 0 and triggers scheduling for all CC_id's
1346 1347
  if (eNB->mac_enabled==1) {
    if (eNB->CC_id == 0) {
1348
      mac_xface->eNB_dlsch_ulsch_scheduler(eNB->Mod_id,0,frame,subframe);//,1);
Raymond Knopp's avatar
 
Raymond Knopp committed
1349
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
1350
  }
1351
  */
1352

1353
  // clear the transmit data array for the current subframe
1354 1355 1356
  for (aa=0; aa<fp->nb_antenna_ports_eNB; aa++) {      
    memset(&eNB->common_vars.txdataF[aa][subframe*fp->ofdm_symbol_size*(fp->symbols_per_tti)],
	   0,fp->ofdm_symbol_size*(fp->symbols_per_tti)*sizeof(int32_t));
Raymond Knopp's avatar
 
Raymond Knopp committed
1357
  }
1358
  
1359

1360
  if (is_pmch_subframe(frame,subframe,fp)) {
1361
    pmch_procedures(eNB,proc,rn,r_type);
1362 1363 1364
  }
  else {
    // this is not a pmch subframe, so generate PSS/SSS/PBCH
1365
    common_signal_procedures(eNB,proc);
1366
  }
1367

Raymond Knopp's avatar
 
Raymond Knopp committed
1368
  // clear existing ulsch dci allocations before applying info from MAC  (this is table
1369
  ul_subframe = pdcch_alloc2ul_subframe(fp,subframe);
1370
  ul_frame = pdcch_alloc2ul_frame(fp,frame,subframe);
1371 1372 1373



Raymond Knopp's avatar
 
Raymond Knopp committed
1374
  // clear previous allocation information for all UEs
1375
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
1376 1377
    if (eNB->dlsch[i][0])
      eNB->dlsch[i][0]->subframe_tx[subframe] = 0;
Raymond Knopp's avatar
 
Raymond Knopp committed
1378
  }
1379

1380 1381
  /* save old HARQ information needed for PHICH generation */
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
1382
    harq_pid = subframe2harq_pid(fp,ul_frame,ul_subframe);
1383
    if (eNB->ulsch[i]) {
1384 1385
      ulsch_harq = eNB->ulsch[i]->harq_processes[harq_pid];

1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405
      /* Store first_rb and n_DMRS for correct PHICH generation below.
       * For PHICH generation we need "old" values of last scheduling
       * for this HARQ process. 'generate_eNB_dlsch_params' below will
       * overwrite first_rb and n_DMRS and 'generate_phich_top', done
       * after 'generate_eNB_dlsch_params', would use the "new" values
       * instead of the "old" ones.
       *
       * This has been tested for FDD only, may be wrong for TDD.
       *
       * TODO: maybe we should restructure the code to be sure it
       *       is done correctly. The main concern is if the code
       *       changes and first_rb and n_DMRS are modified before
       *       we reach here, then the PHICH processing will be wrong,
       *       using wrong first_rb and n_DMRS values to compute
       *       ngroup_PHICH and nseq_PHICH.
       *
       * TODO: check if that works with TDD.
       */
      if ((subframe_select(fp,ul_subframe)==SF_UL) ||
          (fp->frame_type == FDD)) {
1406 1407
        ulsch_harq->previous_first_rb = ulsch_harq->first_rb;
        ulsch_harq->previous_n_DMRS   = ulsch_harq->n_DMRS;
1408 1409 1410 1411
      }
    }
  }

1412

1413 1414 1415 1416 1417
  //  num_pdcch_symbols = DCI_pdu->num_pdcch_symbols;
  num_pdcch_symbols = eNB->pdcch_vars[subframe&1].num_pdcch_symbols;
  num_dci           = eNB->pdcch_vars[subframe&1].num_dci;
  //  LOG_D(PHY,"num_pdcch_symbols %"PRIu8",(dci common %"PRIu8", dci uespec %"PRIu8"\n",num_pdcch_symbols,
  //        DCI_pdu->Num_common_dci,DCI_pdu->Num_ue_spec_dci);
1418
  LOG_D(PHY,"num_pdcch_symbols %"PRIu8",(number dci %"PRIu8"\n",num_pdcch_symbols,
1419 1420
	num_dci);
  VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,num_pdcch_symbols);
1421

1422

1423 1424
  VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,(frame*10)+subframe);

Raymond Knopp's avatar
 
Raymond Knopp committed
1425
  // Apply physicalConfigDedicated if needed
1426 1427
  // This is for UEs that have received this IE, which changes these DL and UL configuration, we apply after a delay for the eNodeB UL parameters
  phy_config_dedicated_eNB_step2(eNB);
1428

1429
  if (num_dci > 0)
1430
    LOG_D(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d: Calling generate_dci_top (pdcch) (num_dci %"PRIu8")\n",eNB->Mod_id,frame, subframe,
1431 1432
	  num_dci);
    
1433 1434 1435 1436 1437 1438 1439 1440 1441
  generate_dci_top(num_pdcch_symbols,
		   num_dci,
		   &eNB->pdcch_vars[subframe&1].dci_alloc[0],
		   0,
		   AMP,
		   fp,
		   eNB->common_vars.txdataF,
		   subframe);
  
1442

1443
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PDCCH_TX,0);
1444

Raymond Knopp's avatar
 
Raymond Knopp committed
1445
  // Now scan UE specific DLSCH
islam.galal's avatar
islam.galal committed
1446
  LTE_eNB_DLSCH_t *dlsch0,*dlsch1;
1447
  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++)
1448
    {
islam.galal's avatar
islam.galal committed
1449 1450
      dlsch0 = eNB->dlsch[(uint8_t)UE_id][0]; 
      dlsch1 = eNB->dlsch[(uint8_t)UE_id][1]; 
1451

islam.galal's avatar
islam.galal committed
1452 1453 1454
      if ((dlsch0)&&
	  (dlsch0->rnti>0)&&
	  (dlsch0->active == 1)) {
1455

1456
	// get harq_pid
islam.galal's avatar
islam.galal committed
1457
	harq_pid = dlsch0->harq_ids[subframe];
1458 1459 1460 1461 1462
	AssertFatal(harq_pid>=0,"harq_pid is negative\n");
	// generate pdsch
	pdsch_procedures(eNB,
			 proc,
			 harq_pid,
islam.galal's avatar
islam.galal committed
1463 1464
			 dlsch0,
			 dlsch1,
1465
			 &eNB->UE_stats[(uint32_t)UE_id],
1466
			 0);
1467 1468


Raymond Knopp's avatar
 
Raymond Knopp committed
1469
      }
1470

islam.galal's avatar
islam.galal committed
1471 1472 1473
      else if ((dlsch0)&&
	       (dlsch0->rnti>0)&&
	       (dlsch0->active == 0)) {
1474

1475
	// clear subframe TX flag since UE is not scheduled for PDSCH in this subframe (so that we don't look for PUCCH later)
islam.galal's avatar
islam.galal committed
1476
	dlsch0->subframe_tx[subframe]=0;
Raymond Knopp's avatar
 
Raymond Knopp committed
1477
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
1478
    }
1479

1480 1481


Raymond Knopp's avatar
 
Raymond Knopp committed
1482
  // if we have PHICH to generate
1483

1484
  if (is_phich_subframe(fp,subframe))
1485 1486 1487 1488
    {
      generate_phich_top(eNB,
			 proc,
			 AMP,
1489
			 0);
1490
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
1491

1492 1493 1494 1495 1496 1497 1498
  /*
  if (frame>=10 && subframe>=9) {
    write_output("/tmp/txsigF0.m","txsF0", &eNB->common_vars.txdataF[0][0][0],120*eNB->frame_parms.ofdm_symbol_size,1,1);
    write_output("/tmp/txsigF1.m","txsF1", &eNB->common_vars.txdataF[0][0][0],120*eNB->frame_parms.ofdm_symbol_size,1,1);
    abort();
  }
  */
1499

1500
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,0);
1501
  if (do_meas==1) stop_meas(&eNB->phy_proc_tx);
1502
  
1503 1504
}

1505
void process_Msg3(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,uint8_t UE_id, uint8_t harq_pid)
1506
{
Raymond Knopp's avatar
 
Raymond Knopp committed
1507
  // this prepares the demodulation of the first PUSCH of a new user, containing Msg3
1508 1509
  int subframe = proc->subframe_rx;
  int frame = proc->frame_rx;
1510 1511
  LTE_eNB_ULSCH_t *ulsch = eNB->ulsch[UE_id];
  LTE_UL_eNB_HARQ_t *ulsch_harq=ulsch->harq_processes[harq_pid];
Raymond Knopp's avatar
 
Raymond Knopp committed
1512

Raymond Knopp's avatar
 
Raymond Knopp committed
1513
  LOG_D(PHY,"[eNB %d][RAPROC] frame %d : subframe %d : process_Msg3 UE_id %d (active %d, subframe %d, frame %d)\n",
1514
        eNB->Mod_id,
1515
        frame,subframe,
1516 1517 1518 1519 1520
        UE_id,ulsch->Msg3_active,
        ulsch_harq->subframe,
        ulsch_harq->frame);

  ulsch_harq->Msg3_flag = 0;
1521

1522 1523 1524
  if ((ulsch->Msg3_active == 1) &&
      (ulsch_harq->subframe == subframe) &&
      (ulsch_harq->frame == (uint32_t)frame))   {
1525

1526
    //    harq_pid = 0;
1527

1528 1529
    ulsch->Msg3_active = 0;
    ulsch_harq->Msg3_flag = 1;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1530
    LOG_D(PHY,"[eNB %d][RAPROC] frame %d, subframe %d: Setting subframe_scheduling_flag (Msg3) for UE %d\n",
1531
          eNB->Mod_id,
1532
          frame,subframe,UE_id);
1533 1534 1535 1536 1537 1538 1539 1540 1541
  }
}


// This function retrieves the harq_pid of the corresponding DLSCH process
// and updates the error statistics of the DLSCH based on the received ACK
// info from UE along with the round index.  It also performs the fine-grain
// rate-adaptation based on the error statistics derived from the ACK/NAK process

1542
void process_HARQ_feedback(uint8_t UE_id,
1543
                           PHY_VARS_eNB *eNB,
1544
			   eNB_rxtx_proc_t *proc,
1545 1546 1547 1548 1549
                           uint8_t pusch_flag,
                           uint8_t *pucch_payload,
                           uint8_t pucch_sel,
                           uint8_t SR_payload)
{
1550

1551
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1552
  uint8_t dl_harq_pid[8],dlsch_ACK[8],dl_subframe;
1553 1554
  LTE_eNB_DLSCH_t *dlsch             =  eNB->dlsch[(uint32_t)UE_id][0];
  LTE_eNB_UE_stats *ue_stats         =  &eNB->UE_stats[(uint32_t)UE_id];
1555
  LTE_DL_eNB_HARQ_t *dlsch_harq_proc;
1556
  uint8_t subframe_m4,M,m;
1557 1558
  int mp;
  int all_ACKed=1,nb_alloc=0,nb_ACK=0;
1559 1560
  int frame = proc->frame_rx;
  int subframe = proc->subframe_rx;
1561
  int harq_pid = subframe2harq_pid( fp,frame,subframe);
1562

1563 1564
  nfapi_harq_indication_pdu_t *pdu;

1565
  if (fp->frame_type == FDD) { //FDD
1566
    subframe_m4 = (subframe<4) ? subframe+6 : subframe-4;
1567

1568 1569
    dl_harq_pid[0] = dlsch->harq_ids[subframe_m4];
    M=1;
1570

1571
    if (pusch_flag == 1) {
1572
      dlsch_ACK[0] = eNB->ulsch[(uint8_t)UE_id]->harq_processes[harq_pid]->o_ACK[0];
1573
      if (dlsch->subframe_tx[subframe_m4]==1)
1574 1575
	LOG_D(PHY,"[eNB %d] Frame %d: Received ACK/NAK %d on PUSCH for subframe %d\n",eNB->Mod_id,
	      frame,dlsch_ACK[0],subframe_m4);
1576 1577
    }
    else {
1578
      dlsch_ACK[0] = pucch_payload[0];
1579
      LOG_D(PHY,"[eNB %d] Frame %d: Received ACK/NAK %d on PUCCH for subframe %d\n",eNB->Mod_id,
1580
	    frame,dlsch_ACK[0],subframe_m4);
kaltenbe's avatar
kaltenbe committed
1581
      /*
1582
	if (dlsch_ACK[0]==0)
1583
	AssertFatal(0,"Exiting on NAK on PUCCH\n");
kaltenbe's avatar
kaltenbe committed
1584
      */
1585
    }
1586

1587 1588 1589
    // fill ACK/NAK Indication
    pdu = &eNB->UL_INFO.harq_ind.harq_pdu_list[eNB->UL_INFO.harq_ind.number_of_harqs];
    eNB->UL_INFO.harq_ind.number_of_harqs++;    
Lionel Gauthier's avatar
Lionel Gauthier committed
1590 1591 1592

#if defined(MESSAGE_CHART_GENERATOR_PHY)
    MSC_LOG_RX_MESSAGE(
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602
		       MSC_PHY_ENB,MSC_PHY_UE,
		       NULL,0,
		       "%05u:%02u %s received %s  rnti %x harq id %u  tx SF %u",
		       frame,subframe,
		       (pusch_flag == 1)?"PUSCH":"PUCCH",
		       (dlsch_ACK[0])?"ACK":"NACK",
		       dlsch->rnti,
		       dl_harq_pid[0],
		       subframe_m4
		       );
Lionel Gauthier's avatar
Lionel Gauthier committed
1603
#endif
1604 1605
  } else { // TDD Handle M=1,2 cases only

1606
    M=ul_ACK_subframe2_M(fp,
1607 1608
                         subframe);

1609 1610 1611 1612 1613 1614 1615 1616
    // Now derive ACK information for TDD
    if (pusch_flag == 1) { // Do PUSCH ACK/NAK first
      // detect missing DAI
      //FK: this code is just a guess
      //RK: not exactly, yes if scheduled from PHICH (i.e. no DCI format 0)
      //    otherwise, it depends on how many of the PDSCH in the set are scheduled, we can leave it like this,
      //    but we have to adapt the code below.  For example, if only one out of 2 are scheduled, only 1 bit o_ACK is used

1617
      dlsch_ACK[0] = eNB->ulsch[(uint8_t)UE_id]->harq_processes[harq_pid]->o_ACK[0];
1618
      dlsch_ACK[1] = (eNB->pucch_config_dedicated[UE_id].tdd_AckNackFeedbackMode == bundling)
1619
	?eNB->ulsch[(uint8_t)UE_id]->harq_processes[harq_pid]->o_ACK[0]:eNB->ulsch[(uint8_t)UE_id]->harq_processes[harq_pid]->o_ACK[1];
1620
    }
1621

1622

1623
    else {  // PUCCH ACK/NAK
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
      if ((SR_payload == 1)&&(pucch_sel!=2)) {  // decode Table 7.3 if multiplexing and SR=1
        nb_ACK = 0;

        if (M == 2) {
          if ((pucch_payload[0] == 1) && (pucch_payload[1] == 1)) // b[0],b[1]
            nb_ACK = 1;
          else if ((pucch_payload[0] == 1) && (pucch_payload[1] == 0))
            nb_ACK = 2;
        } else if (M == 3) {
          if ((pucch_payload[0] == 1) && (pucch_payload[1] == 1))
            nb_ACK = 1;
          else if ((pucch_payload[0] == 1) && (pucch_payload[1] == 0))
            nb_ACK = 2;
          else if ((pucch_payload[0] == 0) && (pucch_payload[1] == 1))
            nb_ACK = 3;
        }
      } else if (pucch_sel == 2) { // bundling or M=1
        dlsch_ACK[0] = pucch_payload[0];
        dlsch_ACK[1] = pucch_payload[0];
      } else { // multiplexing with no SR, this is table 10.1
        if (M==1)
          dlsch_ACK[0] = pucch_payload[0];
        else if (M==2) {
          if (((pucch_sel == 1) && (pucch_payload[0] == 1) && (pucch_payload[1] == 1)) ||
              ((pucch_sel == 0) && (pucch_payload[0] == 0) && (pucch_payload[1] == 1)))
            dlsch_ACK[0] = 1;
          else
            dlsch_ACK[0] = 0;

          if (((pucch_sel == 1) && (pucch_payload[0] == 1) && (pucch_payload[1] == 1)) ||
              ((pucch_sel == 1) && (pucch_payload[0] == 0) && (pucch_payload[1] == 0)))
            dlsch_ACK[1] = 1;
          else
            dlsch_ACK[1] = 0;
        }
1659
      }
1660
    }
1661 1662 1663 1664
  }

  // handle case where positive SR was transmitted with multiplexing
  if ((SR_payload == 1)&&(pucch_sel!=2)&&(pusch_flag == 0)) {
1665
    nb_alloc = 0;
1666 1667

    for (m=0; m<M; m++) {
1668
      dl_subframe = ul_ACK_subframe2_dl_subframe(fp,
1669 1670
						 subframe,
						 m);
1671 1672 1673

      if (dlsch->subframe_tx[dl_subframe]==1)
        nb_alloc++;
1674
    }
1675

1676 1677
    if (nb_alloc == nb_ACK)
      all_ACKed = 1;
1678
    else
1679
      all_ACKed = 0;
1680 1681 1682
  }


1683
  for (m=0,mp=-1; m<M; m++) {
1684

1685
    dl_subframe = ul_ACK_subframe2_dl_subframe(fp,
1686 1687
					       subframe,
					       m);
1688 1689
    if (dlsch->subframe_tx[dl_subframe]==1) {
      if (pusch_flag == 1)
1690
        mp++;
1691
      else
1692
        mp = m;
1693

1694
      dl_harq_pid[m]     = dlsch->harq_ids[dl_subframe];
1695
      harq_pid_updated[UE_id][dl_harq_pid[m]] = 1;
1696

1697
      if ((pucch_sel != 2)&&(pusch_flag == 0)) { // multiplexing
1698 1699 1700 1701
        if ((SR_payload == 1)&&(all_ACKed == 1))
          dlsch_ACK[m] = 1;
        else
          dlsch_ACK[m] = 0;
1702
      }
1703

1704
      if (dl_harq_pid[m]<dlsch->Mdlharq) {
1705 1706
        dlsch_harq_proc = dlsch->harq_processes[dl_harq_pid[m]];
#ifdef DEBUG_PHY_PROC
islam.galal's avatar
islam.galal committed
1707
        LOG_D(PHY,"[eNB %d][PDSCH %x/%d] subframe %d, status %d, round %d (rv %d, TBS %d)\n",eNB->Mod_id,
1708 1709 1710 1711 1712 1713 1714 1715
              dlsch->rnti,dl_harq_pid[m],dl_subframe,
              dlsch_harq_proc->status,dlsch_harq_proc->round,
              dlsch->harq_processes[dl_harq_pid[m]]->rvidx,
              dlsch->harq_processes[dl_harq_pid[m]]->TBS);

        if (dlsch_harq_proc->status==DISABLED)
          LOG_E(PHY,"dlsch_harq_proc is disabled? \n");

1716
#endif
1717 1718 1719 1720 1721 1722 1723 1724

        if ((dl_harq_pid[m]<dlsch->Mdlharq) &&
            (dlsch_harq_proc->status == ACTIVE)) {
          // dl_harq_pid of DLSCH is still active

          if ( dlsch_ACK[mp]==0) {
            // Received NAK
#ifdef DEBUG_PHY_PROC
1725
            LOG_D(PHY,"[eNB %d][PDSCH %x/%d] M = %d, m= %d, mp=%d NAK Received in round %d, requesting retransmission\n",eNB->Mod_id,
1726
                  dlsch->rnti,dl_harq_pid[m],M,m,mp,dlsch_harq_proc->round);
1727
#endif
1728

1729
            T(T_ENB_PHY_DLSCH_UE_NACK, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(UE_id), T_INT(dlsch->rnti),
1730
              T_INT(dl_harq_pid[m]));
1731

1732 1733 1734 1735 1736 1737 1738 1739 1740
            if (dlsch_harq_proc->round == 0)
              ue_stats->dlsch_NAK_round0++;

            ue_stats->dlsch_NAK[dl_harq_pid[m]][dlsch_harq_proc->round]++;


            // then Increment DLSCH round index
            dlsch_harq_proc->round++;

1741

1742
            if (dlsch_harq_proc->round == dlsch->Mlimit) {
1743 1744
              // This was the last round for DLSCH so reset round and increment l2_error counter
#ifdef DEBUG_PHY_PROC
1745
              LOG_W(PHY,"[eNB %d][PDSCH %x/%d] DLSCH retransmissions exhausted, dropping packet\n",eNB->Mod_id,
1746
                    dlsch->rnti,dl_harq_pid[m]);
1747
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
1748
#if defined(MESSAGE_CHART_GENERATOR_PHY)
1749
              MSC_LOG_EVENT(MSC_PHY_ENB, "0 HARQ DLSCH Failed RNTI %"PRIx16" round %u",
1750 1751
                            dlsch->rnti,
                            dlsch_harq_proc->round);
Lionel Gauthier's avatar
Lionel Gauthier committed
1752
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
1753

1754 1755 1756 1757 1758 1759 1760
              dlsch_harq_proc->round = 0;
              ue_stats->dlsch_l2_errors[dl_harq_pid[m]]++;
              dlsch_harq_proc->status = SCH_IDLE;
              dlsch->harq_ids[dl_subframe] = dlsch->Mdlharq;
            }
          } else {
#ifdef DEBUG_PHY_PROC
1761
            LOG_D(PHY,"[eNB %d][PDSCH %x/%d] ACK Received in round %d, resetting process\n",eNB->Mod_id,
1762
                  dlsch->rnti,dl_harq_pid[m],dlsch_harq_proc->round);
1763
#endif
1764

1765
            T(T_ENB_PHY_DLSCH_UE_ACK, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(UE_id), T_INT(dlsch->rnti),
1766
              T_INT(dl_harq_pid[m]));
1767

1768 1769 1770 1771 1772 1773 1774 1775
            ue_stats->dlsch_ACK[dl_harq_pid[m]][dlsch_harq_proc->round]++;

            // Received ACK so set round to 0 and set dlsch_harq_pid IDLE
            dlsch_harq_proc->round  = 0;
            dlsch_harq_proc->status = SCH_IDLE;
            dlsch->harq_ids[dl_subframe] = dlsch->Mdlharq;

            ue_stats->total_TBS = ue_stats->total_TBS +
1776
	      eNB->dlsch[(uint8_t)UE_id][0]->harq_processes[dl_harq_pid[m]]->TBS;
1777 1778
            /*
              ue_stats->total_transmitted_bits = ue_stats->total_transmitted_bits +
1779
              eNB->dlsch[(uint8_t)UE_id][0]->harq_processes[dl_harq_pid[m]]->TBS;
1780 1781
            */
          }
1782
	 
1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793
          // Do fine-grain rate-adaptation for DLSCH
          if (ue_stats->dlsch_NAK_round0 > dlsch->error_threshold) {
            if (ue_stats->dlsch_mcs_offset == 1)
              ue_stats->dlsch_mcs_offset=0;
            else
              ue_stats->dlsch_mcs_offset=-1;
          }

#ifdef DEBUG_PHY_PROC
          LOG_D(PHY,"[process_HARQ_feedback] Frame %d Setting round to %d for pid %d (subframe %d)\n",frame,
                dlsch_harq_proc->round,dl_harq_pid[m],subframe);
1794
#endif
1795
	  harq_pid_round[UE_id][dl_harq_pid[m]] = dlsch_harq_proc->round;
1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
          // Clear NAK stats and adjust mcs offset
          // after measurement window timer expires
          if (ue_stats->dlsch_sliding_cnt == dlsch->ra_window_size) {
            if ((ue_stats->dlsch_mcs_offset == 0) && (ue_stats->dlsch_NAK_round0 < 2))
              ue_stats->dlsch_mcs_offset = 1;

            if ((ue_stats->dlsch_mcs_offset == 1) && (ue_stats->dlsch_NAK_round0 > 2))
              ue_stats->dlsch_mcs_offset = 0;

            if ((ue_stats->dlsch_mcs_offset == 0) && (ue_stats->dlsch_NAK_round0 > 2))
              ue_stats->dlsch_mcs_offset = -1;

            if ((ue_stats->dlsch_mcs_offset == -1) && (ue_stats->dlsch_NAK_round0 < 2))
              ue_stats->dlsch_mcs_offset = 0;

            ue_stats->dlsch_NAK_round0 = 0;
            ue_stats->dlsch_sliding_cnt = 0;
          }
        }
1815
      }
1816
    }
1817 1818 1819
  }
}

1820
void get_n1_pucch_eNB(PHY_VARS_eNB *eNB,
1821
		      eNB_rxtx_proc_t *proc,
1822 1823 1824 1825 1826 1827
                      uint8_t UE_id,
                      int16_t *n1_pucch0,
                      int16_t *n1_pucch1,
                      int16_t *n1_pucch2,
                      int16_t *n1_pucch3)
{
1828

1829
  LTE_DL_FRAME_PARMS *frame_parms=&eNB->frame_parms;
1830
  uint8_t nCCE0,nCCE1;
1831
  int sf;
1832 1833
  int frame = proc->frame_rx;
  int subframe = proc->subframe_rx;
1834 1835

  if (frame_parms->frame_type == FDD ) {
1836
    sf = (subframe<4) ? (subframe+6) : (subframe-4);
1837

1838 1839
    if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[sf]>0) {
      *n1_pucch0 = frame_parms->pucch_config_common.n1PUCCH_AN + eNB->dlsch[(uint32_t)UE_id][0]->nCCE[sf];
1840
      *n1_pucch1 = -1;
1841
    } else {
1842 1843 1844
      *n1_pucch0 = -1;
      *n1_pucch1 = -1;
    }
1845
  } else {
1846

1847 1848 1849
    switch (frame_parms->tdd_config) {
    case 1:  // DL:S:UL:UL:DL:DL:S:UL:UL:DL
      if (subframe == 2) {  // ACK subframes 5 and 6
1850
        /*  if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[6]>0) {
1851 1852 1853 1854 1855
	    nCCE1 = eNB->dlsch[(uint32_t)UE_id][0]->nCCE[6];
	    *n1_pucch1 = get_Np(frame_parms->N_RB_DL,nCCE1,1) + nCCE1 + frame_parms->pucch_config_common.n1PUCCH_AN;
	    }
	    else
	    *n1_pucch1 = -1;*/
1856

1857 1858
        if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[5]>0) {
          nCCE0 = eNB->dlsch[(uint32_t)UE_id][0]->nCCE[5];
1859 1860 1861 1862 1863 1864 1865
          *n1_pucch0 = get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0+ frame_parms->pucch_config_common.n1PUCCH_AN;
        } else
          *n1_pucch0 = -1;

        *n1_pucch1 = -1;
      } else if (subframe == 3) { // ACK subframe 9

1866 1867
        if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[9]>0) {
          nCCE0 = eNB->dlsch[(uint32_t)UE_id][0]->nCCE[9];
1868 1869 1870 1871 1872 1873 1874 1875 1876
          *n1_pucch0 = get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0 +frame_parms->pucch_config_common.n1PUCCH_AN;
        } else
          *n1_pucch0 = -1;

        *n1_pucch1 = -1;

      } else if (subframe == 7) { // ACK subframes 0 and 1
        //harq_ack[0].nCCE;
        //harq_ack[1].nCCE;
1877 1878
        if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[0]>0) {
          nCCE0 = eNB->dlsch[(uint32_t)UE_id][0]->nCCE[0];
1879 1880 1881 1882 1883 1884 1885
          *n1_pucch0 = get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0 + frame_parms->pucch_config_common.n1PUCCH_AN;
        } else
          *n1_pucch0 = -1;

        *n1_pucch1 = -1;
      } else if (subframe == 8) { // ACK subframes 4
        //harq_ack[4].nCCE;
1886 1887
        if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[4]>0) {
          nCCE0 = eNB->dlsch[(uint32_t)UE_id][0]->nCCE[4];
1888 1889 1890 1891 1892 1893 1894
          *n1_pucch0 = get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0 + frame_parms->pucch_config_common.n1PUCCH_AN;
        } else
          *n1_pucch0 = -1;

        *n1_pucch1 = -1;
      } else {
        LOG_D(PHY,"[eNB %d] frame %d: phy_procedures_lte.c: get_n1pucch, illegal subframe %d for tdd_config %d\n",
1895
              eNB->Mod_id,
1896 1897 1898
              frame,
              subframe,frame_parms->tdd_config);
        return;
1899
      }
1900

1901
      break;
1902

1903 1904
    case 3:  // DL:S:UL:UL:UL:DL:DL:DL:DL:DL
      if (subframe == 2) {  // ACK subframes 5,6 and 1 (S in frame-2), forget about n-11 for the moment (S-subframe)
1905 1906
        if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[6]>0) {
          nCCE1 = eNB->dlsch[(uint32_t)UE_id][0]->nCCE[6];
1907 1908 1909 1910
          *n1_pucch1 = get_Np(frame_parms->N_RB_DL,nCCE1,1) + nCCE1 + frame_parms->pucch_config_common.n1PUCCH_AN;
        } else
          *n1_pucch1 = -1;

1911 1912
        if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[5]>0) {
          nCCE0 = eNB->dlsch[(uint32_t)UE_id][0]->nCCE[5];
1913 1914 1915 1916 1917
          *n1_pucch0 = get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0+ frame_parms->pucch_config_common.n1PUCCH_AN;
        } else
          *n1_pucch0 = -1;
      } else if (subframe == 3) { // ACK subframes 7 and 8
        LOG_D(PHY,"get_n1_pucch_eNB : subframe 3, subframe_tx[7] %d, subframe_tx[8] %d\n",
1918
              eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[7],eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[8]);
1919

1920 1921
        if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[8]>0) {
          nCCE1 = eNB->dlsch[(uint32_t)UE_id][0]->nCCE[8];
1922 1923 1924 1925 1926
          *n1_pucch1 = get_Np(frame_parms->N_RB_DL,nCCE1,1) + nCCE1 + frame_parms->pucch_config_common.n1PUCCH_AN;
          LOG_D(PHY,"nCCE1 %d, n1_pucch1 %d\n",nCCE1,*n1_pucch1);
        } else
          *n1_pucch1 = -1;

1927 1928
        if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[7]>0) {
          nCCE0 = eNB->dlsch[(uint32_t)UE_id][0]->nCCE[7];
1929 1930 1931 1932 1933
          *n1_pucch0 = get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0 +frame_parms->pucch_config_common.n1PUCCH_AN;
          LOG_D(PHY,"nCCE0 %d, n1_pucch0 %d\n",nCCE0,*n1_pucch0);
        } else
          *n1_pucch0 = -1;
      } else if (subframe == 4) { // ACK subframes 9 and 0
1934 1935
        if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[0]>0) {
          nCCE1 = eNB->dlsch[(uint32_t)UE_id][0]->nCCE[0];
1936 1937 1938 1939
          *n1_pucch1 = get_Np(frame_parms->N_RB_DL,nCCE1,1) + nCCE1 + frame_parms->pucch_config_common.n1PUCCH_AN;
        } else
          *n1_pucch1 = -1;

1940 1941
        if (eNB->dlsch[(uint32_t)UE_id][0]->subframe_tx[9]>0) {
          nCCE0 = eNB->dlsch[(uint32_t)UE_id][0]->nCCE[9];
1942 1943 1944 1945 1946
          *n1_pucch0 = get_Np(frame_parms->N_RB_DL,nCCE0,0) + nCCE0 +frame_parms->pucch_config_common.n1PUCCH_AN;
        } else
          *n1_pucch0 = -1;
      } else {
        LOG_D(PHY,"[eNB %d] Frame %d: phy_procedures_lte.c: get_n1pucch, illegal subframe %d for tdd_config %d\n",
1947
              eNB->Mod_id,frame,subframe,frame_parms->tdd_config);
1948
        return;
1949
      }
1950

1951
      break;
1952 1953
    }  // switch tdd_config

1954 1955 1956
    // Don't handle the case M>2
    *n1_pucch2 = -1;
    *n1_pucch3 = -1;
1957 1958 1959
  }
}

1960 1961 1962 1963 1964
void prach_procedures(PHY_VARS_eNB *eNB,
#ifdef Rel14
		      int br_flag
#endif
		      ) {
1965

1966
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
1967
  uint16_t max_preamble[4],max_preamble_energy[4],max_preamble_delay[4];
1968
  uint16_t i;
1969 1970 1971 1972 1973
  int frame,subframe;
#ifdef Rel14
  if (br_flag==1) {
    subframe = eNB->proc.subframe_prach_br;
    frame = eNB->proc.frame_prach_br;
1974 1975 1976
    pthread_mutex_lock(&eNB->UL_INFO_mutex);
    eNB->UL_INFO.rach_ind_br.number_of_preambles=0;
    pthread_mutex_unlock(&eNB->UL_INFO_mutex);
1977 1978 1979 1980
  }
  else
#endif
    {
1981 1982 1983
      pthread_mutex_lock(&eNB->UL_INFO_mutex);
      eNB->UL_INFO.rach_ind.number_of_preambles=0;
      pthread_mutex_unlock(&eNB->UL_INFO_mutex);
1984 1985 1986
      subframe = eNB->proc.subframe_prach;
      frame = eNB->proc.frame_prach;
    }
1987
  uint8_t CC_id = eNB->CC_id;
1988 1989 1990
  RU_t *ru;
  int aa=0;
  int ru_aa;
1991
  LTE_eNB_PRACH *prach_vars;
1992

1993
 
1994
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PRACH_RX,1);
1995

1996 1997


1998 1999
  for (i=0;i<eNB->num_RU;i++) {
    ru=eNB->RU_list[i];
2000 2001 2002 2003 2004 2005 2006 2007 2008
    for (ru_aa=0,aa=0;ru_aa<ru->nb_rx;ru_aa++,aa++) {
      eNB->prach_vars.rxsigF[aa] = eNB->RU_list[i]->prach_rxsigF[ru_aa];
#ifdef Rel14
      int ce_level;

      if (br_flag==1)
	for (ce_level=0;ce_level<4;ce_level++) eNB->prach_vars_br.rxsigF[aa] = eNB->RU_list[i]->prach_rxsigF_br[ce_level][ru_aa];
#endif
    }
2009
  }
2010

2011 2012
  rx_prach(eNB,
	   eNB->RU_list[0],
2013 2014 2015
	   &max_preamble[0],
	   &max_preamble_energy[0],
	   &max_preamble_delay[0],
2016
	   frame,
2017 2018 2019 2020 2021
	   0
#ifdef Rel14
	   ,br_flag
#endif
	   );
2022

2023 2024
#ifdef DEBUG_PHY_PROC
  LOG_I(PHY,"[RAPROC] Frame %d, subframe %d : Most likely preamble %d, energy %d dB delay %d\n",
2025
        frame,subframe,
2026
	max_preamble[0],
2027
        max_preamble_energy[0]/10,
2028
        max_preamble_delay[0]);
2029
#endif
2030

2031 2032
#ifdef Rel14
  if (br_flag==1) {
Raymond Knopp's avatar
 
Raymond Knopp committed
2033

2034 2035 2036 2037 2038 2039
    prach_vars = &eNB->prach_vars_br;
    int prach_mask;
      
    prach_mask = is_prach_subframe(&eNB->frame_parms,eNB->proc.frame_prach_br,eNB->proc.subframe_prach_br);
    
    eNB->UL_INFO.rach_ind_br.preamble_list                              = eNB->preamble_list_br;
2040 2041 2042
    int ind=0;
    int ce_level=0;
    /* Save for later, it doesn't work    
2043
    for (int ind=0,ce_level=0;ce_level<4;ce_level++) {
2044 2045 2046
      
      if ((eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[ce_level]==1)&&
	  (prach_mask&(1<<(1+ce_level)) > 0) && // prach is active and CE level has finished its repetitions
2047 2048
	  (eNB->prach_vars_br.repetition_number[ce_level]==
	   eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[ce_level])) {
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069
    */
    if (eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[0]==1){ 
      if (max_preamble_energy[0] > 350) {
	eNB->UL_INFO.rach_ind_br.number_of_preambles++;
	
	eNB->preamble_list_br[ind].preamble_rel8.timing_advance        = max_preamble_delay[ind];//
	eNB->preamble_list_br[ind].preamble_rel8.preamble              = max_preamble[ind];
	// note: fid is implicitly 0 here, this is the rule for eMTC RA-RNTI from 36.321, Section 5.1.4
	eNB->preamble_list_br[ind].preamble_rel8.rnti                  = 1+subframe+(eNB->prach_vars_br.first_frame[ce_level]%40);  
	eNB->preamble_list_br[ind].instance_length                     = 0; //don't know exactly what this is
	eNB->preamble_list_br[ind].preamble_rel13.rach_resource_type   = 1+ce_level;  // CE Level
	LOG_I(PHY,"Filling NFAPI indication for RACH %d CELevel %d (mask %x) : TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
	      ind,
	      ce_level,
	      prach_mask,
	      eNB->preamble_list_br[ind].preamble_rel8.timing_advance,
	      eNB->preamble_list_br[ind].preamble_rel8.preamble,
	      eNB->preamble_list_br[ind].preamble_rel8.rnti,
	      eNB->preamble_list_br[ind].preamble_rel13.rach_resource_type);
      }
      /*
2070 2071
	ind++;
      }
2072 2073
      } */// ce_level
    }
2074 2075 2076
  }
  else
#endif
Cedric Roux's avatar
Cedric Roux committed
2077

2078
    {
2079
      if (max_preamble_energy[0] > 10000) {
2080 2081 2082 2083 2084 2085 2086 2087 2088 2089

	LOG_D(PHY,"[eNB %d/%d][RAPROC] Frame %d, subframe %d Initiating RA procedure with preamble %d, energy %d.%d dB, delay %d\n",
	      eNB->Mod_id,
	      eNB->CC_id,
	      frame,
	      subframe,
	      max_preamble[0],
	      max_preamble_energy[0]/10,
	      max_preamble_energy[0]%10,
	      max_preamble_delay[0]);
2090
	
2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108
	    T(T_ENB_PHY_INITIATE_RA_PROCEDURE, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), 0,
	      T_INT(max_preamble[0]), T_INT(max_preamble_energy[0]), T_INT(max_preamble_delay[0]));
	    
	    if (eNB->mac_enabled==1) {
	      
	      prach_vars = &eNB->prach_vars;
	      
	      
	      pthread_mutex_lock(&eNB->UL_INFO_mutex);
	      
	      eNB->UL_INFO.rach_ind.number_of_preambles                 = 1;
	      eNB->UL_INFO.rach_ind.preamble_list                       = eNB->preamble_list;
	      
	      eNB->preamble_list[0].preamble_rel8.timing_advance        = max_preamble_delay[0];
	      eNB->preamble_list[0].preamble_rel8.preamble              = max_preamble[0];
	      eNB->preamble_list[0].preamble_rel8.rnti                  = 1+subframe;  // note: fid is implicitly 0 here
	      eNB->preamble_list[0].preamble_rel13.rach_resource_type   = 0;
	      eNB->preamble_list[0].instance_length                     = 0; //don't know exactly what this is
2109 2110 2111 2112 2113 2114

	      LOG_I(PHY,"Filling NFAPI indication for RACH : TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
		    eNB->preamble_list[0].preamble_rel8.timing_advance,
		    eNB->preamble_list[0].preamble_rel8.preamble,
		    eNB->preamble_list[0].preamble_rel8.rnti,
		    eNB->preamble_list[0].preamble_rel13.rach_resource_type);	    
2115 2116
	      pthread_mutex_unlock(&eNB->UL_INFO_mutex);
	    }
2117
      } // max_preamble_energy > 350
2118
    } // else br_flag
2119
      /*
2120
	mac_xface->initiate_ra_proc(eNB->Mod_id,
2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132
	eNB->CC_id,
	frame,
	preamble_max,
	preamble_delay_list[preamble_max]*update_TA/update_TA2,
	0,subframe,0);*/
      
    
    /*  } else {
    MSC_LOG_EVENT(MSC_PHY_ENB, "0 RA Failed add user, too many");
    LOG_I(PHY,"[eNB %d][RAPROC] frame %d, subframe %d: Unable to add user, max user count reached\n",
	  eNB->Mod_id,frame, subframe);
	  }*/
2133

2134
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PRACH_RX,0);
2135 2136
}

2137
void pucch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,int UE_id,int harq_pid,uint8_t do_srs)
Cedric Roux's avatar
Cedric Roux committed
2138
{
2139
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
2140
  uint8_t SR_payload = 0,*pucch_payload=NULL,pucch_payload0[2]= {0,0},pucch_payload1[2]= {0,0};
Cedric Roux's avatar
Cedric Roux committed
2141
  int16_t n1_pucch0 = -1, n1_pucch1 = -1, n1_pucch2 = -1, n1_pucch3 = -1;
2142 2143
  uint8_t do_SR = 0;
  uint8_t pucch_sel = 0;
2144
  int32_t metric0=0,metric1=0,metric0_SR=0;
2145 2146
  ANFBmode_t bundling_flag;
  PUCCH_FMT_t format;
2147 2148
  const int subframe = proc->subframe_rx;
  const int frame = proc->frame_rx;
2149

2150 2151
  if ((eNB->dlsch[UE_id][0]) &&
      (eNB->dlsch[UE_id][0]->rnti>0) &&
2152 2153
      (eNB->ulsch[UE_id]->harq_processes[harq_pid]->frame != frame) &&
      (eNB->ulsch[UE_id]->harq_processes[harq_pid]->subframe != subframe)) {
2154

2155
    // check SR availability
2156 2157
    do_SR = is_SR_subframe(eNB,proc,UE_id);
    //      do_SR = 0;
Cedric Roux's avatar
Cedric Roux committed
2158

2159 2160
    // Now ACK/NAK
    // First check subframe_tx flag for earlier subframes
2161

2162
    get_n1_pucch_eNB(eNB,
Cedric Roux's avatar
Cedric Roux committed
2163 2164 2165 2166 2167 2168 2169
                     proc,
                     UE_id,
                     &n1_pucch0,
                     &n1_pucch1,
                     &n1_pucch2,
                     &n1_pucch3);

2170
    LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d, subframe %d Checking for PUCCH (%d,%d,%d,%d) SR %d\n",
Cedric Roux's avatar
Cedric Roux committed
2171 2172 2173 2174
          eNB->Mod_id,eNB->dlsch[UE_id][0]->rnti,
          frame,subframe,
          n1_pucch0,n1_pucch1,n1_pucch2,n1_pucch3,do_SR);

2175 2176 2177
    if ((n1_pucch0==-1) && (n1_pucch1==-1) && (do_SR==0)) {  // no TX PDSCH that have to be checked and no SR for this UE_id
    } else {
      // otherwise we have some PUCCH detection to do
Cedric Roux's avatar
Cedric Roux committed
2178

2179 2180 2181
      // Null out PUCCH PRBs for noise measurement
      switch(fp->N_RB_UL) {
      case 6:
Cedric Roux's avatar
Cedric Roux committed
2182 2183
        eNB->rb_mask_ul[0] |= (0x1 | (1<<5)); //position 5
        break;
2184
      case 15:
Cedric Roux's avatar
Cedric Roux committed
2185 2186
        eNB->rb_mask_ul[0] |= (0x1 | (1<<14)); // position 14
        break;
2187
      case 25:
Cedric Roux's avatar
Cedric Roux committed
2188 2189
        eNB->rb_mask_ul[0] |= (0x1 | (1<<24)); // position 24
        break;
2190
      case 50:
Cedric Roux's avatar
Cedric Roux committed
2191 2192 2193
        eNB->rb_mask_ul[0] |= 0x1;
        eNB->rb_mask_ul[1] |= (1<<17); // position 49 (49-32)
        break;
2194
      case 75:
Cedric Roux's avatar
Cedric Roux committed
2195 2196 2197
        eNB->rb_mask_ul[0] |= 0x1;
        eNB->rb_mask_ul[2] |= (1<<10); // position 74 (74-64)
        break;
2198
      case 100:
Cedric Roux's avatar
Cedric Roux committed
2199 2200 2201
        eNB->rb_mask_ul[0] |= 0x1;
        eNB->rb_mask_ul[3] |= (1<<3); // position 99 (99-96)
        break;
2202
      default:
Cedric Roux's avatar
Cedric Roux committed
2203 2204
        LOG_E(PHY,"Unknown number for N_RB_UL %d\n",fp->N_RB_UL);
        break;
2205
      }
2206

2207
      if (do_SR == 1) {
Cedric Roux's avatar
Cedric Roux committed
2208 2209 2210
        eNB->UE_stats[UE_id].sr_total++;


2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227
	metric0_SR = rx_pucch(eNB,
			      pucch_format1,
			      UE_id,
			      eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex,
			      0, // n2_pucch
			      do_srs, // shortened format
			      &SR_payload,
			      frame,
			      subframe,
			      PUCCH1_THRES);
	LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Checking SR is %d (SR n1pucch is %d)\n",
	      eNB->Mod_id,
	      eNB->ulsch[UE_id]->rnti,
	      frame,
	      subframe,
	      SR_payload,
	      eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex);
2228
      }// do_SR==1
Cedric Roux's avatar
Cedric Roux committed
2229

2230
      if ((n1_pucch0==-1) && (n1_pucch1==-1)) { // just check for SR
Cedric Roux's avatar
Cedric Roux committed
2231 2232 2233 2234 2235 2236
      } else if (fp->frame_type==FDD) { // FDD
        // if SR was detected, use the n1_pucch from SR, else use n1_pucch0
        //          n1_pucch0 = (SR_payload==1) ? eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex:n1_pucch0;

        LOG_D(PHY,"Demodulating PUCCH for ACK/NAK: n1_pucch0 %d (%d), SR_payload %d\n",n1_pucch0,eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex,SR_payload);

2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247
	metric0 = rx_pucch(eNB,
			   pucch_format1a,
			   UE_id,
			   (uint16_t)n1_pucch0,
			   0, //n2_pucch
			   do_srs, // shortened format
			   pucch_payload0,
			   frame,
			   subframe,
			   PUCCH1a_THRES);
        
Cedric Roux's avatar
Cedric Roux committed
2248 2249 2250 2251 2252 2253 2254 2255

        /* cancel SR detection if reception on n1_pucch0 is better than on SR PUCCH resource index */
        if (do_SR && metric0 > metric0_SR) SR_payload = 0;

        if (do_SR && metric0 <= metric0_SR) {
          /* when transmitting ACK/NACK on SR PUCCH resource index, SR payload is always 1 */
          SR_payload = 1;

2256 2257 2258 2259 2260 2261 2262 2263 2264 2265
	  metric0=rx_pucch(eNB,
			   pucch_format1a,
			   UE_id,
			   eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex,
			   0, //n2_pucch
			   do_srs, // shortened format
			   pucch_payload0,
			   frame,
			   subframe,
			   PUCCH1a_THRES);
Cedric Roux's avatar
Cedric Roux committed
2266 2267
        }

2268
#ifdef DEBUG_PHY_PROC
Cedric Roux's avatar
Cedric Roux committed
2269 2270 2271 2272 2273
        LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d pucch1a (FDD) payload %d (metric %d)\n",
            eNB->Mod_id,
            eNB->dlsch[UE_id][0]->rnti,
            frame,subframe,
            pucch_payload0[0],metric0);
2274
#endif
2275

Cedric Roux's avatar
Cedric Roux committed
2276 2277 2278 2279 2280 2281 2282
        process_HARQ_feedback(UE_id,eNB,proc,
                            0,// pusch_flag
                            pucch_payload0,
                            2,
                            SR_payload);
      } // FDD
      else {  //TDD
2283

Cedric Roux's avatar
Cedric Roux committed
2284
        bundling_flag = eNB->pucch_config_dedicated[UE_id].tdd_AckNackFeedbackMode;
2285

Cedric Roux's avatar
Cedric Roux committed
2286
        // fix later for 2 TB case and format1b
Raymond Knopp's avatar
Raymond Knopp committed
2287

Cedric Roux's avatar
Cedric Roux committed
2288 2289
        if ((fp->frame_type==FDD) ||
          (bundling_flag==bundling)    ||
gabrielC's avatar
gabrielC committed
2290
          ((fp->frame_type==TDD)&&(fp->tdd_config==1)&&((subframe!=2)&&(subframe!=7)))) {
Cedric Roux's avatar
Cedric Roux committed
2291 2292 2293 2294
          format = pucch_format1a;
        } else {
          format = pucch_format1b;
        }
2295

Cedric Roux's avatar
Cedric Roux committed
2296 2297
        // if SR was detected, use the n1_pucch from SR
        if (SR_payload==1) {
2298
#ifdef DEBUG_PHY_PROC
Cedric Roux's avatar
Cedric Roux committed
2299 2300 2301 2302
          LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d Checking ACK/NAK (%d,%d,%d,%d) format %d with SR\n",eNB->Mod_id,
                eNB->dlsch[UE_id][0]->rnti,
                frame,subframe,
                n1_pucch0,n1_pucch1,n1_pucch2,n1_pucch3,format);
2303
#endif
2304

2305 2306 2307 2308 2309 2310 2311 2312 2313 2314
	  metric0 = rx_pucch(eNB,
			     format,
			     UE_id,
			     eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex,
			     0, //n2_pucch
			     do_srs, // shortened format
			     pucch_payload0,
			     frame,
			     subframe,
			     PUCCH1a_THRES);
Cedric Roux's avatar
Cedric Roux committed
2315
        } else { //using n1_pucch0/n1_pucch1 resources
2316
#ifdef DEBUG_PHY_PROC
Cedric Roux's avatar
Cedric Roux committed
2317 2318 2319 2320
          LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d Checking ACK/NAK (%d,%d,%d,%d) format %d\n",eNB->Mod_id,
                eNB->dlsch[UE_id][0]->rnti,
                frame,subframe,
                n1_pucch0,n1_pucch1,n1_pucch2,n1_pucch3,format);
2321
#endif
Cedric Roux's avatar
Cedric Roux committed
2322 2323 2324 2325 2326
          metric0=0;
          metric1=0;

          // Check n1_pucch0 metric
          if (n1_pucch0 != -1) {
2327 2328 2329 2330 2331 2332 2333 2334 2335 2336
	    metric0 = rx_pucch(eNB,
			       format,
			       UE_id,
			       (uint16_t)n1_pucch0,
			       0, // n2_pucch
			       do_srs, // shortened format
			       pucch_payload0,
			       frame,
			       subframe,
			       PUCCH1a_THRES);
Cedric Roux's avatar
Cedric Roux committed
2337
          }
2338

Cedric Roux's avatar
Cedric Roux committed
2339 2340
          // Check n1_pucch1 metric
          if (n1_pucch1 != -1) {
2341 2342 2343 2344 2345 2346 2347 2348 2349 2350
	    metric1 = rx_pucch(eNB,
			       format,
			       UE_id,
			       (uint16_t)n1_pucch1,
			       0, //n2_pucch
			       do_srs, // shortened format
			       pucch_payload1,
			       frame,
			       subframe,
			       PUCCH1a_THRES);
Cedric Roux's avatar
Cedric Roux committed
2351 2352
          }
        }
2353
	
Cedric Roux's avatar
Cedric Roux committed
2354 2355
        if (SR_payload == 1) {
          pucch_payload = pucch_payload0;
2356
	  
Cedric Roux's avatar
Cedric Roux committed
2357 2358 2359 2360 2361 2362 2363 2364 2365 2366
          if (bundling_flag == bundling)
            pucch_sel = 2;
        } else if (bundling_flag == multiplexing) { // multiplexing + no SR
          pucch_payload = (metric1>metric0) ? pucch_payload1 : pucch_payload0;
          pucch_sel     = (metric1>metric0) ? 1 : 0;
        } else { // bundling + no SR
          if (n1_pucch1 != -1)
            pucch_payload = pucch_payload1;
          else if (n1_pucch0 != -1)
            pucch_payload = pucch_payload0;
2367
	  
Cedric Roux's avatar
Cedric Roux committed
2368 2369
          pucch_sel = 2;  // indicate that this is a bundled ACK/NAK
        }
2370
	
2371
#ifdef DEBUG_PHY_PROC
Cedric Roux's avatar
Cedric Roux committed
2372 2373 2374 2375
        LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d ACK/NAK metric 0 %d, metric 1 %d, sel %d, (%d,%d)\n",eNB->Mod_id,
              eNB->dlsch[UE_id][0]->rnti,
              frame,subframe,
              metric0,metric1,pucch_sel,pucch_payload[0],pucch_payload[1]);
2376
#endif
Cedric Roux's avatar
Cedric Roux committed
2377 2378 2379 2380 2381 2382
        process_HARQ_feedback(UE_id,eNB,proc,
                              0,// pusch_flag
                              pucch_payload,
                              pucch_sel,
                              SR_payload);
      } // TDD
2383
    }
Cedric Roux's avatar
Cedric Roux committed
2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399

    if (SR_payload == 1) {
      LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Got SR for PUSCH, transmitting to MAC\n",eNB->Mod_id,
            eNB->ulsch[UE_id]->rnti,frame,subframe);
      eNB->UE_stats[UE_id].sr_received++;

      if (eNB->first_sr[UE_id] == 1) { // this is the first request for uplink after Connection Setup, so clear HARQ process 0 use for Msg4
        eNB->first_sr[UE_id] = 0;
        eNB->dlsch[UE_id][0]->harq_processes[0]->round=0;
        eNB->dlsch[UE_id][0]->harq_processes[0]->status=SCH_IDLE;
        LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d First SR\n",
              eNB->Mod_id,
              eNB->ulsch[UE_id]->rnti,frame,subframe);
      }

      if (eNB->mac_enabled==1) {
2400
	/*
Cedric Roux's avatar
Cedric Roux committed
2401 2402 2403 2404
        mac_xface->SR_indication(eNB->Mod_id,
                                 eNB->CC_id,
                                 frame,
                                 eNB->dlsch[UE_id][0]->rnti,subframe);
2405 2406 2407
	*/

	// fill eNB->UL_info with SR indications
Cedric Roux's avatar
Cedric Roux committed
2408 2409 2410
      }
    }
  }
2411
}
2412

2413

2414

2415 2416
extern int oai_exit;

2417 2418 2419
extern void *td_thread(void*);

void init_td_thread(PHY_VARS_eNB *eNB,pthread_attr_t *attr_td) {
2420 2421 2422

  eNB_proc_t *proc = &eNB->proc;

2423 2424
  proc->tdp.eNB = eNB;
  proc->instance_cnt_td         = -1;
2425
    
2426 2427
  pthread_mutex_init( &proc->mutex_td, NULL);
  pthread_cond_init( &proc->cond_td, NULL);
2428

2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446
  pthread_create(&proc->pthread_td, attr_td, td_thread, (void*)&proc->tdp);

}

extern void *te_thread(void*);

void init_te_thread(PHY_VARS_eNB *eNB,pthread_attr_t *attr_te) {

  eNB_proc_t *proc = &eNB->proc;

  proc->tep.eNB = eNB;
  proc->instance_cnt_te         = -1;
    
  pthread_mutex_init( &proc->mutex_te, NULL);
  pthread_cond_init( &proc->cond_te, NULL);

  printf("Creating te_thread\n");
  pthread_create(&proc->pthread_te, attr_te, te_thread, (void*)&proc->tep);
2447 2448 2449

}

2450

2451

2452
/*
2453
void phy_procedures_eNB_common_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc){
2454 2455


2456
  //  eNB_proc_t *proc       = &eNB->proc;
Raymond Knopp's avatar
Raymond Knopp committed
2457 2458 2459
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  const int subframe     = proc->subframe_rx;
  const int frame        = proc->frame_rx;
2460
  int offset             = (eNB->single_thread_flag==1) ? 0 : (subframe&1);
Sandeep Kumar's avatar
Sandeep Kumar committed
2461

Raymond Knopp's avatar
Raymond Knopp committed
2462 2463
  VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_RX0_ENB+offset, proc->frame_rx );
  VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_SUBFRAME_NUMBER_RX0_ENB+offset, proc->subframe_rx );
2464

Raymond Knopp's avatar
Raymond Knopp committed
2465 2466 2467 2468 2469 2470 2471 2472
  if ((fp->frame_type == TDD) && (subframe_select(fp,subframe)!=SF_UL)) {

    if (eNB->node_function == NGFI_RRU_IF4p5) {
      /// **** in TDD during DL send_IF4 of ULTICK to RCC **** ///
      send_IF4p5(eNB, proc->frame_rx, proc->subframe_rx, IF4p5_PULTICK, 0);
    }    
    return;
  }
2473

2474 2475

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_RX_COMMON+offset, 1 ); 
2476
  start_meas(&eNB->phy_proc_rx);
2477
  LOG_D(PHY,"[eNB %d] Frame %d: Doing phy_procedures_eNB_common_RX(%d)\n",eNB->Mod_id,frame,subframe);
2478

Raymond Knopp's avatar
Raymond Knopp committed
2479

2480
  if (eNB->fep) eNB->fep(eNB,proc);
2481

Raymond Knopp's avatar
Raymond Knopp committed
2482
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_RX_COMMON+offset, 0 );
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
void fill_rx_indication(PHY_VARS_eNB *eNB,int UE_id,int frame,int subframe) {

  nfapi_rx_indication_pdu_t *pdu;

  int timing_advance_update;
  int sync_pos;

  uint32_t harq_pid = subframe2harq_pid(&eNB->frame_parms,
					frame,subframe);

  pthread_mutex_lock(&eNB->UL_INFO_mutex);
  pdu                                    = &eNB->UL_INFO.rx_ind.rx_pdu_list[eNB->UL_INFO.rx_ind.number_of_pdus];

  //  pdu->rx_ue_information.handle          = eNB->ulsch[UE_id]->handle;
  pdu->rx_ue_information.rnti            = eNB->ulsch[UE_id]->rnti;
  pdu->rx_indication_rel8.length         = eNB->ulsch[UE_id]->harq_processes[harq_pid]->TBS>>3;
  pdu->rx_indication_rel8.offset         = 0;  // filled in at the end of the UL_INFO formation
  pdu->data                              = eNB->ulsch[UE_id]->harq_processes[harq_pid]->b;  
  // estimate timing advance for MAC
  sync_pos                               = lte_est_timing_advance_pusch(eNB,UE_id);
  timing_advance_update                  = sync_pos - eNB->frame_parms.nb_prefix_samples/4; //to check
  switch (eNB->frame_parms.N_RB_DL) {
  case 6:
    pdu->rx_indication_rel8.timing_advance = timing_advance_update;  
    break;
  case 15:
    pdu->rx_indication_rel8.timing_advance = timing_advance_update/2;  
    break;
  case 25:
    pdu->rx_indication_rel8.timing_advance = timing_advance_update/4;  
    break;
  case 50:
    pdu->rx_indication_rel8.timing_advance = timing_advance_update/8;  
    break;
  case 75:
    pdu->rx_indication_rel8.timing_advance = timing_advance_update/12;  
    break;
  case 100:
    pdu->rx_indication_rel8.timing_advance = timing_advance_update/16;  
    break;
  }
  // put timing advance command in 0..63 range
  pdu->rx_indication_rel8.timing_advance += 31;
  if (pdu->rx_indication_rel8.timing_advance < 0)  pdu->rx_indication_rel8.timing_advance = 0;
  if (pdu->rx_indication_rel8.timing_advance > 63) pdu->rx_indication_rel8.timing_advance = 63;

  // estimate UL_CQI for MAC (from antenna port 0 only)
  int SNRtimes10 = dB_fixed_times10(eNB->pusch_vars[UE_id]->ulsch_power[0]) - 200;//(10*eNB->measurements.n0_power_dB[0]);

  if      (SNRtimes10 < -640) pdu->rx_indication_rel8.ul_cqi=0;
  else if (SNRtimes10 >  635) pdu->rx_indication_rel8.ul_cqi=255;
  else                        pdu->rx_indication_rel8.ul_cqi=(640+SNRtimes10)/5;

  eNB->UL_INFO.rx_ind.number_of_pdus++;
  pthread_mutex_unlock(&eNB->UL_INFO_mutex);

}

void fill_crc_indication(PHY_VARS_eNB *eNB,int UE_id,int frame,int subframe,uint8_t crc_flag) {

  pthread_mutex_lock(&eNB->UL_INFO_mutex);
  nfapi_crc_indication_pdu_t *pdu =   &eNB->UL_INFO.crc_ind.crc_pdu_list[eNB->UL_INFO.crc_ind.number_of_crcs];

  pdu->instance_length                                = 0; // don't know what to do with this
  //  pdu->rx_ue_information.handle                       = handle;
  pdu->rx_ue_information.rnti                         = eNB->ulsch[UE_id]->rnti;
  pdu->crc_indication_rel8.crc_flag                   = crc_flag;
  pthread_mutex_unlock(&eNB->UL_INFO_mutex);

  eNB->UL_INFO.crc_ind.number_of_crcs++;
  pthread_mutex_unlock(&eNB->UL_INFO_mutex);
}

void update_harq_scheduling(LTE_DL_FRAME_PARMS *fp,LTE_UL_eNB_HARQ_t *ulsch_harq,int frame,int subframe) {
  if (fp->frame_type == FDD) {
    ulsch_harq->frame    += (ulsch_harq->subframe>1) ? 1 : 0;
    ulsch_harq->subframe  = (ulsch_harq->subframe + 8)%10;
  }
  else ulsch_harq->frame++;
}


2569
void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const relaying_type_t r_type)
2570
{
2571
  //RX processing for ue-specific resources (i
2572
  UNUSED(r_type);
2573
  uint32_t ret=0,i,j,k;
2574 2575 2576 2577 2578
  uint32_t harq_pid, harq_idx, round;
  uint8_t nPRS;
  int sync_pos;
  uint16_t rnti=0;
  uint8_t access_mode;
2579
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
2580 2581
  LTE_eNB_ULSCH_t *ulsch;
  LTE_UL_eNB_HARQ_t *ulsch_harq;
2582

2583
  const int subframe = proc->subframe_rx;
Raymond Knopp's avatar
Raymond Knopp committed
2584
  const int frame    = proc->frame_rx;
2585
  int offset         = eNB->CC_id;//(proc == &eNB->proc.proc_rxtx[0]) ? 0 : 1;
2586

2587 2588 2589 2590 2591
  uint16_t srsPeriodicity;
  uint16_t srsOffset;
  uint16_t do_srs=0;
  uint16_t is_srs_pos=0;

2592 2593 2594 2595 2596
  T(T_ENB_PHY_UL_TICK, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe));

  T(T_ENB_PHY_INPUT_SIGNAL, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(0),
    T_BUFFER(&eNB->common_vars.rxdata[0][0][subframe*eNB->frame_parms.samples_per_tti],
             eNB->frame_parms.samples_per_tti * 4));
2597

2598
  if ((fp->frame_type == TDD) && (subframe_select(fp,subframe)!=SF_UL)) return;
2599

Raymond Knopp's avatar
Raymond Knopp committed
2600
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_RX_UESPEC+offset, 1 );
2601

2602
#ifdef DEBUG_PHY_PROC
2603
  LOG_D(PHY,"[eNB %d] Frame %d: Doing phy_procedures_eNB_uespec_RX(%d)\n",eNB->Mod_id,frame, subframe);
Lionel Gauthier's avatar
Lionel Gauthier committed
2604
#endif
2605

2606 2607 2608 2609
  eNB->rb_mask_ul[0]=0;
  eNB->rb_mask_ul[1]=0;
  eNB->rb_mask_ul[2]=0;
  eNB->rb_mask_ul[3]=0;
2610

2611 2612 2613
  eNB->UL_INFO.rx_ind.number_of_pdus  = 0;
  eNB->UL_INFO.crc_ind.number_of_crcs = 0;

2614
  // Check for active processes in current subframe
2615
  harq_pid = subframe2harq_pid(fp,
2616
                               frame,subframe);
2617

2618 2619
  is_srs_pos = is_srs_occasion_common(fp,frame,subframe);
  
2620
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
2621

2622 2623 2624
    ulsch = eNB->ulsch[i];
    ulsch_harq = ulsch->harq_processes[harq_pid];

2625 2626 2627
    // Do SRS processing 
    // check if there is SRS and we have to use shortened format
    // TODO: check for exceptions in transmission of SRS together with ACK/NACK
2628
    do_srs=0;
2629 2630
    if (is_srs_pos && eNB->soundingrs_ul_config_dedicated[i].srsConfigDedicatedSetup ) {
      compute_srs_pos(fp->frame_type, eNB->soundingrs_ul_config_dedicated[i].srs_ConfigIndex, &srsPeriodicity, &srsOffset);
2631
      if (((10*frame+subframe) % srsPeriodicity) == srsOffset) {
2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645
	do_srs = 1;
      }
    }

    if (do_srs==1) {
      if (lte_srs_channel_estimation(fp,
				     &eNB->common_vars,
				     &eNB->srs_vars[i],
				     &eNB->soundingrs_ul_config_dedicated[i],
				     subframe,
				     0/*eNB_id*/)) {
	LOG_E(PHY,"problem processing SRS\n");
      }
    }
2646
    
2647 2648 2649 2650
    // Do PUCCH processing 

    pucch_procedures(eNB,proc,i,harq_pid, do_srs);

2651

2652
    // check for Msg3
2653
    if (eNB->mac_enabled==1) {
2654
      //      if (eNB->UE_stats[i].mode == RA_RESPONSE) {
2655
	process_Msg3(eNB,proc,i,harq_pid);
2656
	//      }
2657
    }
2658 2659


2660 2661 2662
    eNB->pusch_stats_rb[i][(frame*10)+subframe] = -63;
    eNB->pusch_stats_round[i][(frame*10)+subframe] = 0;
    eNB->pusch_stats_mcs[i][(frame*10)+subframe] = -63;
2663

2664 2665 2666
    if ((ulsch) &&
        (eNB->ulsch[i]->rnti>0) &&
        (ulsch_harq->status = ACTIVE))
2667
      LOG_D(PHY,"Frame %d Subframe UE %d/%x active: scheduled for (%d,%d)\n",
2668 2669
	    frame,i,eNB->ulsch[i]->rnti,ulsch_harq->frame,ulsch_harq->subframe);
    if ((ulsch) &&
2670
        (eNB->ulsch[i]->rnti>0) &&
2671 2672 2673
        (ulsch_harq->status = ACTIVE) &&
        (ulsch_harq->subframe==subframe)&&
        (ulsch_harq->frame==frame)) {
2674
      // UE is has ULSCH scheduling
2675
      round = ulsch_harq->round;
2676
 
2677
      for (int rb=0;
2678
           rb<=ulsch_harq->nb_rb;
2679
	   rb++) {
2680
	int rb2 = rb+ulsch_harq->first_rb;
2681
	eNB->rb_mask_ul[rb2>>5] |= (1<<(rb2&31));
2682
      }
2683 2684


2685
      if (ulsch_harq->Msg3_flag == 1) {
2686
        LOG_D(PHY,"[eNB %d] frame %d, subframe %d: Scheduling ULSCH Reception for Msg3 in Sector %d\n",
2687
              eNB->Mod_id,
2688 2689
              frame,
              subframe,
2690
              eNB->UE_stats[i].sector);
2691 2692
	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_ULSCH_MSG3,1);
      } else {
2693

2694
        LOG_D(PHY,"[eNB %d] frame %d, subframe %d: Scheduling ULSCH Reception for UE %d Mode %s\n",
2695
              eNB->Mod_id,
2696 2697 2698
              frame,
              subframe,
              i,
2699
              mode_string[eNB->UE_stats[i].mode]);
2700
      }
2701

2702

2703
      nPRS = fp->pusch_config_common.ul_ReferenceSignalsPUSCH.nPRS[subframe<<1];
2704

2705
      ulsch->cyclicShift = (ulsch_harq->n_DMRS2 + fp->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift +
2706
				    nPRS)%12;
2707

2708
      if (fp->frame_type == FDD ) {
2709
        int sf = (subframe<4) ? (subframe+6) : (subframe-4);
2710

2711
        if (eNB->dlsch[i][0]->subframe_tx[sf]>0) { // we have downlink transmission
2712
          ulsch_harq->O_ACK = 1;
2713
        } else {
2714
          ulsch_harq->O_ACK = 0;
2715
        }
2716
      }
2717

2718
      LOG_D(PHY,
2719
            "[eNB %d][PUSCH %d] Frame %d Subframe %d Demodulating PUSCH: dci_alloc %d, rar_alloc %d, round %d, first_rb %d, nb_rb %d, mcs %d, TBS %d, rv %d, cyclic_shift %d (n_DMRS2 %d, cyclicShift_common %d, nprs %d), O_ACK %d \n",
2720
            eNB->Mod_id,harq_pid,frame,subframe,
2721 2722 2723 2724 2725 2726 2727 2728
            ulsch_harq->dci_alloc,
            ulsch_harq->rar_alloc,
            ulsch_harq->round,
            ulsch_harq->first_rb,
            ulsch_harq->nb_rb,
            ulsch_harq->mcs,
            ulsch_harq->TBS,
            ulsch_harq->rvidx,
2729
            eNB->ulsch[i]->cyclicShift,
2730
            ulsch_harq->n_DMRS2,
2731
            fp->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift,
2732
            nPRS,
2733 2734 2735 2736
            ulsch_harq->O_ACK);
      eNB->pusch_stats_rb[i][(frame*10)+subframe] = ulsch_harq->nb_rb;
      eNB->pusch_stats_round[i][(frame*10)+subframe] = ulsch_harq->round;
      eNB->pusch_stats_mcs[i][(frame*10)+subframe] = ulsch_harq->mcs;
2737
      start_meas(&eNB->ulsch_demodulation_stats);
2738

2739 2740 2741
      rx_ulsch(eNB,proc,
	       i);
      
2742

2743
      stop_meas(&eNB->ulsch_demodulation_stats);
2744

2745

2746
      start_meas(&eNB->ulsch_decoding_stats);
2747

2748 2749 2750
      ret = ulsch_decoding(eNB,proc,
			   i,
			   0, // control_only_flag
2751 2752
			   ulsch_harq->V_UL_DAI,
			   ulsch_harq->nb_rb>20 ? 1 : 0);
2753
      
2754 2755


2756
      stop_meas(&eNB->ulsch_decoding_stats);
2757

2758
      LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d RNTI %x RX power (%d,%d) RSSI (%d,%d) N0 (%d,%d) dB ACK (%d,%d), decoding iter %d\n",
2759
            eNB->Mod_id,harq_pid,
2760
            frame,subframe,
2761
            ulsch->rnti,
2762 2763 2764 2765
            dB_fixed(eNB->pusch_vars[i]->ulsch_power[0]),
            dB_fixed(eNB->pusch_vars[i]->ulsch_power[1]),
            eNB->UE_stats[i].UL_rssi[0],
            eNB->UE_stats[i].UL_rssi[1],
2766 2767 2768 2769
            20,//eNB->measurements.n0_power_dB[0],
            20,//eNB->measurements.n0_power_dB[1],
            ulsch_harq->o_ACK[0],
            ulsch_harq->o_ACK[1],
2770
            ret);
2771

2772

2773
      //compute the expected ULSCH RX power (for the stats)
2774
      eNB->ulsch[(uint32_t)i]->harq_processes[harq_pid]->delta_TF =
2775
        get_hundred_times_delta_IF_eNB(eNB,i,harq_pid, 0); // 0 means bw_factor is not considered
2776

2777
      eNB->UE_stats[i].ulsch_decoding_attempts[harq_pid][ulsch_harq->round]++;
2778 2779
#ifdef DEBUG_PHY_PROC
      LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d UE %d harq_pid %d Clearing subframe_scheduling_flag\n",
2780
            eNB->Mod_id,harq_pid,frame,subframe,i,harq_pid);
2781
#endif
2782

2783
      if (ulsch_harq->cqi_crc_status == 1) {
2784
#ifdef DEBUG_PHY_PROC
2785
        //if (((frame%10) == 0) || (frame < 50))
2786
        print_CQI(ulsch_harq->o,ulsch_harq->uci_format,0,fp->N_RB_DL);
2787
#endif
2788 2789
        extract_CQI(ulsch_harq->o,
                    ulsch_harq->uci_format,
2790
                    &eNB->UE_stats[i],
2791
                    fp->N_RB_DL,
2792
                    &rnti, &access_mode);
2793
        eNB->UE_stats[i].rank = ulsch_harq->o_RI[0];
2794

2795
      }
2796

2797
      if (ulsch_harq->Msg3_flag == 1)
2798
	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_ULSCH_MSG3,0);
2799

2800
      if (ret == (1+MAX_TURBO_ITERATIONS)) {
2801
        T(T_ENB_PHY_ULSCH_UE_NACK, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(i), T_INT(ulsch->rnti),
2802
          T_INT(harq_pid));
2803

2804 2805 2806 2807
        eNB->UE_stats[i].ulsch_round_errors[harq_pid][ulsch_harq->round]++;
        ulsch_harq->phich_active = 1;
        ulsch_harq->phich_ACK = 0;
        ulsch_harq->round++;
2808

2809
	update_harq_scheduling(fp,ulsch_harq,frame,subframe);
2810

2811
	fill_crc_indication(eNB,i,frame,subframe,1); // indicate NAK to MAC
2812

2813 2814 2815 2816 2817
        LOG_D(PHY,"[eNB][PUSCH %d] Increasing to round %d\n",harq_pid,ulsch_harq->round);

        if (ulsch_harq->Msg3_flag == 1) {

          LOG_I(PHY,"[eNB %d/%d][RAPROC] frame %d, subframe %d, UE %d: Error receiving ULSCH (Msg3), round %d\n",
2818 2819
                eNB->Mod_id,
                eNB->CC_id,
2820
                frame,subframe, i,
2821 2822 2823
                ulsch_harq->round-1);

	  
2824
	  LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d RNTI %x RX power (%d,%d) RSSI (%d,%d) N0 (%d,%d) dB ACK (%d,%d), decoding iter %d\n",
2825
		eNB->Mod_id,harq_pid,
2826
		frame,subframe,
2827
		ulsch->rnti,
2828 2829 2830 2831
		dB_fixed(eNB->pusch_vars[i]->ulsch_power[0]),
		dB_fixed(eNB->pusch_vars[i]->ulsch_power[1]),
		eNB->UE_stats[i].UL_rssi[0],
		eNB->UE_stats[i].UL_rssi[1],
2832 2833
		eNB->measurements.n0_power_dB[0],
		eNB->measurements.n0_power_dB[1],
2834 2835
		ulsch_harq->o_ACK[0],
		ulsch_harq->o_ACK[1],
2836 2837 2838
		ret);
          LOG_D(PHY,"[eNB] Frame %d, Subframe %d: Msg3 in error, i = %d \n", frame,subframe,i);
        } // This is Msg3 error
2839

2840 2841
        else { //normal ULSCH
          LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d UE %d Error receiving ULSCH, round %d/%d (ACK %d,%d)\n",
2842
                eNB->Mod_id,harq_pid,
2843
                frame,subframe, i,
2844 2845 2846 2847
                ulsch_harq->round-1,
                ulsch->Mlimit,
                ulsch_harq->o_ACK[0],
                ulsch_harq->o_ACK[1]);
2848 2849 2850

#if defined(MESSAGE_CHART_GENERATOR_PHY)
          MSC_LOG_RX_DISCARDED_MESSAGE(
2851 2852 2853 2854
				       MSC_PHY_ENB,MSC_PHY_UE,
				       NULL,0,
				       "%05u:%02u ULSCH received rnti %x harq id %u round %d",
				       frame,subframe,
2855 2856
				       ulsch->rnti,harq_pid,
				       ulsch_harq->round-1
2857
				       );
2858
#endif
2859

2860
          if (ulsch_harq->round== ulsch->Mlimit) {
2861
            LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d UE %d ULSCH Mlimit %d reached\n",
2862
                  eNB->Mod_id,harq_pid,
2863
                  frame,subframe, i,
2864
                  ulsch->Mlimit);
2865
	    
2866 2867
            ulsch_harq->round=0;
            ulsch_harq->phich_active=0;
2868 2869
            eNB->UE_stats[i].ulsch_errors[harq_pid]++;
            eNB->UE_stats[i].ulsch_consecutive_errors++;
2870 2871 2872
	    
	  }
	}
2873 2874
      }  // ulsch in error
      else {
2875
	
2876

2877 2878 2879
	fill_crc_indication(eNB,i,frame,subframe,0); // indicate ACK to MAC
	fill_rx_indication(eNB,i,frame,subframe);    // indicate SDU to MAC
        T(T_ENB_PHY_ULSCH_UE_ACK, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(i), T_INT(ulsch->rnti),
2880 2881
          T_INT(harq_pid));

2882
        if (ulsch_harq->Msg3_flag == 1) {
2883
	  LOG_D(PHY,"[eNB %d][PUSCH %d] Frame %d subframe %d ULSCH received, setting round to 0, PHICH ACK\n",
2884
		eNB->Mod_id,harq_pid,
2885 2886
		frame,subframe);
	  LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d RNTI %x RX power (%d,%d) RSSI (%d,%d) N0 (%d,%d) dB ACK (%d,%d), decoding iter %d\n",
2887
		eNB->Mod_id,harq_pid,
2888
		frame,subframe,
2889
		ulsch->rnti,
2890 2891 2892 2893
		dB_fixed(eNB->pusch_vars[i]->ulsch_power[0]),
		dB_fixed(eNB->pusch_vars[i]->ulsch_power[1]),
		eNB->UE_stats[i].UL_rssi[0],
		eNB->UE_stats[i].UL_rssi[1],
2894 2895
		eNB->measurements.n0_power_dB[0],
		eNB->measurements.n0_power_dB[1],
2896 2897
		ulsch_harq->o_ACK[0],
		ulsch_harq->o_ACK[1],
2898 2899 2900 2901
		ret);
	}
#if defined(MESSAGE_CHART_GENERATOR_PHY)
        MSC_LOG_RX_MESSAGE(
2902 2903 2904 2905
			   MSC_PHY_ENB,MSC_PHY_UE,
			   NULL,0,
			   "%05u:%02u ULSCH received rnti %x harq id %u",
			   frame,subframe,
2906
			   ulsch->rnti,harq_pid
2907
			   );
2908
#endif
2909
        for (j=0; j<fp->nb_antennas_rx; j++)
2910
          //this is the RSSI per RB
2911
          eNB->UE_stats[i].UL_rssi[j] =
2912
	    
2913
            dB_fixed(eNB->pusch_vars[i]->ulsch_power[j]*
2914
                     (ulsch_harq->nb_rb*12)/
2915
                     fp->ofdm_symbol_size) -
2916
            eNB->rx_total_gain_dB -
2917
            hundred_times_log10_NPRB[ulsch_harq->nb_rb-1]/100 -
2918
            get_hundred_times_delta_IF_eNB(eNB,i,harq_pid, 0)/100;
2919
	    
2920 2921 2922
        ulsch_harq->phich_active = 1;
        ulsch_harq->phich_ACK = 1;
        ulsch_harq->round = 0;
2923
        eNB->UE_stats[i].ulsch_consecutive_errors = 0;
2924

2925
        if (ulsch_harq->Msg3_flag == 1) {
2926
	  if (eNB->mac_enabled==1) {
2927

2928
	    LOG_I(PHY,"[eNB %d][RAPROC] Frame %d Terminating ra_proc for harq %d, UE %d\n",
2929
		  eNB->Mod_id,
2930
		  frame,harq_pid,i);
2931 2932 2933
	    if (eNB->mac_enabled) {
	      // Fill UL info
	    }
2934
	    // one-shot msg3 detection by MAC: empty PDU (e.g. CRNTI)
2935
	    if (ulsch_harq->Msg3_flag == 0 ) {
2936 2937
	      eNB->UE_stats[i].mode = PRACH;
	      eNB->ulsch[(uint32_t)i]->Msg3_active = 0;
2938 2939 2940
	    } // Msg3_flag == 0
	    
	  } // mac_enabled==1
2941

2942
          eNB->UE_stats[i].mode = PUSCH;
2943
          ulsch_harq->Msg3_flag = 0;
2944

2945
	  LOG_D(PHY,"[eNB %d][RAPROC] Frame %d : RX Subframe %d Setting UE %d mode to PUSCH\n",eNB->Mod_id,frame,subframe,i);
2946

2947
          for (k=0; k<8; k++) { //harq_processes
2948 2949 2950 2951
            for (j=0; j<eNB->dlsch[i][0]->Mlimit; j++) {
              eNB->UE_stats[i].dlsch_NAK[k][j]=0;
              eNB->UE_stats[i].dlsch_ACK[k][j]=0;
              eNB->UE_stats[i].dlsch_trials[k][j]=0;
2952
            }
2953

2954 2955 2956
            eNB->UE_stats[i].dlsch_l2_errors[k]=0;
            eNB->UE_stats[i].ulsch_errors[k]=0;
            eNB->UE_stats[i].ulsch_consecutive_errors=0;
2957

2958
            for (j=0; j<ulsch->Mlimit; j++) {
2959 2960 2961 2962
              eNB->UE_stats[i].ulsch_decoding_attempts[k][j]=0;
              eNB->UE_stats[i].ulsch_decoding_attempts_last[k][j]=0;
              eNB->UE_stats[i].ulsch_round_errors[k][j]=0;
              eNB->UE_stats[i].ulsch_round_fer[k][j]=0;
2963
            }
2964 2965
          }

2966 2967 2968
          eNB->UE_stats[i].dlsch_sliding_cnt=0;
          eNB->UE_stats[i].dlsch_NAK_round0=0;
          eNB->UE_stats[i].dlsch_mcs_offset=0;
2969 2970 2971
        } // Msg3_flag==1
	else {  // Msg3_flag == 0

2972
#ifdef DEBUG_PHY_PROC
2973 2974
#ifdef DEBUG_ULSCH
          LOG_D(PHY,"[eNB] Frame %d, Subframe %d : ULSCH SDU (RX harq_pid %d) %d bytes:",frame,subframe,
2975
                harq_pid,ulsch_harq->TBS>>3);
2976

2977
          for (j=0; j<ulsch_harq->TBS>>3; j++)
2978
            LOG_T(PHY,"%x.",eNB->ulsch[i]->harq_processes[harq_pid]->b[j]);
2979 2980 2981

          LOG_T(PHY,"\n");
#endif
2982
#endif
2983

2984
        } // Msg3_flag == 0
2985

2986
        
2987

2988 2989
#ifdef DEBUG_PHY_PROC
        LOG_D(PHY,"[eNB %d] frame %d, subframe %d: user %d: timing advance = %d\n",
2990
              eNB->Mod_id,
2991 2992
              frame, subframe,
              i,
2993
              eNB->UE_stats[i].timing_advance_update);
2994
#endif
2995 2996


2997 2998 2999
      }  // ulsch not in error

      // process HARQ feedback
3000
#ifdef DEBUG_PHY_PROC
3001
      LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d, Processing HARQ feedback for UE %d (after PUSCH)\n",eNB->Mod_id,
3002
            eNB->dlsch[i][0]->rnti,
3003 3004
            frame,subframe,
            i);
3005
#endif
3006
      process_HARQ_feedback(i,
3007
                            eNB,proc,
3008 3009 3010 3011 3012 3013 3014
                            1, // pusch_flag
                            0,
                            0,
                            0);

#ifdef DEBUG_PHY_PROC
      LOG_D(PHY,"[eNB %d] Frame %d subframe %d, sect %d: received ULSCH harq_pid %d for UE %d, ret = %d, CQI CRC Status %d, ACK %d,%d, ulsch_errors %d/%d\n",
3015
            eNB->Mod_id,frame,subframe,
3016
            eNB->UE_stats[i].sector,
3017 3018 3019
            harq_pid,
            i,
            ret,
3020 3021 3022 3023 3024
            eNB->ulsch[i]->harq_processes[harq_pid]->cqi_crc_status,
            eNB->ulsch[i]->harq_processes[harq_pid]->o_ACK[0],
            eNB->ulsch[i]->harq_processes[harq_pid]->o_ACK[1],
            eNB->UE_stats[i].ulsch_errors[harq_pid],
            eNB->UE_stats[i].ulsch_decoding_attempts[harq_pid][0]);
3025 3026 3027 3028
#endif
      
      // dump stats to VCD
      if (i==0) {
3029 3030 3031
	VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_MCS0+harq_pid,eNB->pusch_stats_mcs[0][(frame*10)+subframe]);
	VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_RB0+harq_pid,eNB->pusch_stats_rb[0][(frame*10)+subframe]);
	VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_ROUND0+harq_pid,eNB->pusch_stats_round[0][(frame*10)+subframe]);
3032
	VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_RSSI0+harq_pid,dB_fixed(eNB->pusch_vars[0]->ulsch_power[0]));
3033 3034
	VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_RES0+harq_pid,ret);
	VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_SFN0+harq_pid,(frame*10)+subframe);
Lionel Gauthier's avatar
Lionel Gauthier committed
3035
      }
3036
    } // ulsch[0] && ulsch[0]->rnti>0 && ulsch[0]->subframe_scheduling_flag == 1
3037 3038


3039
    // update ULSCH statistics for tracing
3040
    if ((frame % 100 == 0) && (subframe == 4)) {
3041
      for (harq_idx=0; harq_idx<8; harq_idx++) {
3042
        for (round=0; round<ulsch->Mlimit; round++) {
3043 3044 3045 3046 3047 3048 3049
          if ((eNB->UE_stats[i].ulsch_decoding_attempts[harq_idx][round] -
               eNB->UE_stats[i].ulsch_decoding_attempts_last[harq_idx][round]) != 0) {
            eNB->UE_stats[i].ulsch_round_fer[harq_idx][round] =
              (100*(eNB->UE_stats[i].ulsch_round_errors[harq_idx][round] -
                    eNB->UE_stats[i].ulsch_round_errors_last[harq_idx][round]))/
              (eNB->UE_stats[i].ulsch_decoding_attempts[harq_idx][round] -
               eNB->UE_stats[i].ulsch_decoding_attempts_last[harq_idx][round]);
3050
          } else {
3051
            eNB->UE_stats[i].ulsch_round_fer[harq_idx][round] = 0;
3052 3053
          }

3054 3055 3056 3057
          eNB->UE_stats[i].ulsch_decoding_attempts_last[harq_idx][round] =
            eNB->UE_stats[i].ulsch_decoding_attempts[harq_idx][round];
          eNB->UE_stats[i].ulsch_round_errors_last[harq_idx][round] =
            eNB->UE_stats[i].ulsch_round_errors[harq_idx][round];
3058
        }
3059 3060
      }
    }
3061

Florian Kaltenberger's avatar
Florian Kaltenberger committed
3062
    if ((frame % 100 == 0) && (subframe==4)) {
3063
      eNB->UE_stats[i].dlsch_bitrate = (eNB->UE_stats[i].total_TBS -
3064
					eNB->UE_stats[i].total_TBS_last);
3065

3066
      eNB->UE_stats[i].total_TBS_last = eNB->UE_stats[i].total_TBS;
3067
    }
3068

3069 3070
  } // loop i=0 ... NUMBER_OF_UE_MAX-1

3071 3072 3073 3074 3075 3076
  lte_eNB_I0_measurements(eNB,
			  subframe,
			  0,
			  eNB->first_run_I0_measurements);
  eNB->first_run_I0_measurements = 0;
  
3077 3078


3079
  //}
3080

3081 3082 3083 3084 3085 3086 3087 3088 3089
#if defined(FLEXRAN_AGENT_SB_IF)
#ifndef DISABLE_SF_TRIGGER
  //Send subframe trigger to the controller
  if (mac_agent_registered[eNB->Mod_id]) {
    agent_mac_xface[eNB->Mod_id]->flexran_agent_send_sf_trigger(eNB->Mod_id);
  }
#endif
#endif

Raymond Knopp's avatar
Raymond Knopp committed
3090
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_RX_UESPEC+offset, 0 );
3091

3092
  stop_meas(&eNB->phy_proc_rx);
3093

3094 3095 3096 3097
}

#undef DEBUG_PHY_PROC

Cedric Roux's avatar
Cedric Roux committed
3098
#if defined(Rel10) || defined(Rel14)
3099 3100 3101
int phy_procedures_RN_eNB_TX(unsigned char last_slot, unsigned char next_slot, relaying_type_t r_type)
{

3102
  int do_proc=0;// do nothing
3103 3104

  switch(r_type) {
3105
  case no_relay:
3106
    do_proc= no_relay; // perform the normal eNB operation
3107
    break;
3108

3109
  case multicast_relay:
3110
    if (((next_slot >>1) < 6) || ((next_slot >>1) > 8))
3111
      do_proc = 0; // do nothing
3112 3113 3114
    else // SF#6, SF#7 and SF#8
      do_proc = multicast_relay; // do PHY procedures eNB TX

3115
    break;
3116

3117 3118
  default: // should'not be here
    LOG_W(PHY,"Not supported relay type %d, do nothing\n", r_type);
3119
    do_proc=0;
3120 3121
    break;
  }
3122

3123 3124
  return do_proc;
}
3125 3126
#endif