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

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


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

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

  Contact Information
ghaddab's avatar
ghaddab committed
22 23
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
24
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
25

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

ghaddab's avatar
ghaddab committed
28
 *******************************************************************************/
29 30 31

/*! \file phy_procedures_lte_eNB.c
 * \brief Implementation of eNB procedures from 36.213 LTE specifications
32
 * \author R. Knopp, F. Kaltenberger, N. Nikaein
33 34 35
 * \date 2011
 * \version 0.1
 * \company Eurecom
36
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr,navid.nikaein@eurecom.fr
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
 * \note
 * \warning
 */

#include "PHY/defs.h"
#include "PHY/extern.h"
#include "MAC_INTERFACE/defs.h"
#include "MAC_INTERFACE/extern.h"
#include "SCHED/defs.h"
#include "SCHED/extern.h"

#ifdef EMOS
#include "SCHED/phy_procedures_emos.h"
#endif

52
//#define DEBUG_PHY_PROC (Already defined in cmake)
53 54 55 56 57 58 59
//#define DEBUG_ULSCH

#include "LAYER2/MAC/extern.h"
#include "LAYER2/MAC/defs.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"

60
#include "assertions.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
61
#include "msc.h"
62

63
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
Lionel Gauthier committed
64
#   include "intertask_interface.h"
65
#   if ENABLE_RAL
Lionel Gauthier's avatar
Lionel Gauthier committed
66 67
#     include "timer.h"
#   endif
68 69
#endif

70 71 72 73 74 75 76
//#define DIAG_PHY

#define NS_PER_SLOT 500000

#define PUCCH 1

extern int exit_openair;
77
//extern void do_OFDM_mod(mod_sym_t **txdataF, int32_t **txdata, uint32_t frame, uint16_t next_slot, LTE_DL_FRAME_PARMS *frame_parms);
78 79 80 81 82 83 84


unsigned char dlsch_input_buffer[2700] __attribute__ ((aligned(16)));
int eNB_sync_buffer0[640*6] __attribute__ ((aligned(16)));
int eNB_sync_buffer1[640*6] __attribute__ ((aligned(16)));
int *eNB_sync_buffer[2] = {eNB_sync_buffer0, eNB_sync_buffer1};

85
extern uint16_t hundred_times_log10_NPRB[100];
86

87
unsigned int max_peak_val;
88 89 90 91 92 93 94 95 96 97 98
int max_sect_id, max_sync_pos;

//DCI_ALLOC_t dci_alloc[8];

#ifdef EMOS
fifo_dump_emos_eNB emos_dump_eNB;
#endif

#if defined(SMBV) && !defined(EXMIMO)
extern const char smbv_fname[];
extern unsigned short config_frames[4];
99
extern uint8_t smbv_frame_cnt;
100 101 102 103 104 105
#endif

#ifdef DIAG_PHY
extern int rx_sig_fifo;
#endif

106 107
uint8_t is_SR_subframe(PHY_VARS_eNB *phy_vars_eNB,uint8_t UE_id,uint8_t sched_subframe)
{
Raymond Knopp's avatar
 
Raymond Knopp committed
108

Lionel Gauthier's avatar
Lionel Gauthier committed
109 110
  const int subframe = phy_vars_eNB->proc[sched_subframe].subframe_rx;
  const int frame = phy_vars_eNB->proc[sched_subframe].frame_rx;
111

112
  LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Checking for SR TXOp(sr_ConfigIndex %d)\n",
113 114 115
        phy_vars_eNB->Mod_id,phy_vars_eNB->ulsch_eNB[UE_id]->rnti,frame,subframe,
        phy_vars_eNB->scheduling_request_config[UE_id].sr_ConfigIndex);

116
  if (phy_vars_eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 4) {        // 5 ms SR period
117 118
    if ((subframe%5) == phy_vars_eNB->scheduling_request_config[UE_id].sr_ConfigIndex)
      return(1);
119
  } else if (phy_vars_eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 14) { // 10 ms SR period
120 121
    if (subframe==(phy_vars_eNB->scheduling_request_config[UE_id].sr_ConfigIndex-5))
      return(1);
122
  } else if (phy_vars_eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 34) { // 20 ms SR period
Raymond Knopp's avatar
 
Raymond Knopp committed
123
    if ((10*(frame&1)+subframe) == (phy_vars_eNB->scheduling_request_config[UE_id].sr_ConfigIndex-15))
124
      return(1);
125
  } else if (phy_vars_eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 74) { // 40 ms SR period
Raymond Knopp's avatar
 
Raymond Knopp committed
126
    if ((10*(frame&3)+subframe) == (phy_vars_eNB->scheduling_request_config[UE_id].sr_ConfigIndex-35))
127
      return(1);
128
  } else if (phy_vars_eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 154) { // 80 ms SR period
Raymond Knopp's avatar
 
Raymond Knopp committed
129
    if ((10*(frame&7)+subframe) == (phy_vars_eNB->scheduling_request_config[UE_id].sr_ConfigIndex-75))
130
      return(1);
131 132 133 134
  }

  return(0);
}
135

136 137 138 139 140 141
void put_harq_pid_in_freelist(LTE_eNB_DLSCH_t *DLSCH_ptr, int harq_pid)
{
  DLSCH_ptr->harq_pid_freelist[DLSCH_ptr->tail_freelist] = harq_pid;
  DLSCH_ptr->tail_freelist = (DLSCH_ptr->tail_freelist + 1) % 10;
}

Cedric Roux's avatar
Cedric Roux committed
142
void remove_harq_pid_from_freelist(LTE_eNB_DLSCH_t *DLSCH_ptr, int harq_pid)
143 144 145 146 147
{
  if (DLSCH_ptr->head_freelist == DLSCH_ptr->tail_freelist) {
    LOG_E(PHY, "%s:%d: you cannot read this!\n", __FILE__, __LINE__);
    abort();
  }
Cedric Roux's avatar
Cedric Roux committed
148 149 150 151 152 153 154 155 156
  /* basic check, in case several threads deal with the free list at the same time
   * in normal situations it should not happen, that's also why we don't use any
   * locking mechanism to protect the free list
   * to be refined in case things don't work properly
   */
  if (harq_pid != DLSCH_ptr->harq_pid_freelist[DLSCH_ptr->head_freelist]) {
    LOG_E(PHY, "%s:%d: critical error, get in touch with the authors\n", __FILE__, __LINE__);
    abort();
  }
157 158 159
  DLSCH_ptr->head_freelist = (DLSCH_ptr->head_freelist + 1) % 10;
}

160 161
int32_t add_ue(int16_t rnti, PHY_VARS_eNB *phy_vars_eNB)
{
162
  uint8_t i;
163

Raymond Knopp's avatar
 
Raymond Knopp committed
164
#ifdef DEBUG_PHY_PROC
165 166 167 168
  LOG_I(PHY,"[eNB %d/%d] Adding UE with rnti %x\n",
        phy_vars_eNB->Mod_id,
        phy_vars_eNB->CC_id,
        (uint16_t)rnti);
Raymond Knopp's avatar
 
Raymond Knopp committed
169
#endif
170 171

  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
172
    if ((phy_vars_eNB->dlsch_eNB[i]==NULL) || (phy_vars_eNB->ulsch_eNB[i]==NULL)) {
173
      MSC_LOG_EVENT(MSC_PHY_ENB, "0 Failed add ue %"PRIx16" (ENOMEM)", rnti);
174 175
      LOG_E(PHY,"Can't add UE, not enough memory allocated\n");
      return(-1);
176
    } else {
177
      if (phy_vars_eNB->eNB_UE_stats[i].crnti==0) {
178
        MSC_LOG_EVENT(MSC_PHY_ENB, "0 Add ue %"PRIx16" ", rnti);
Cedric Roux's avatar
Cedric Roux committed
179
        LOG_I(PHY,"UE_id %d associated with rnti %x\n",i, (uint16_t)rnti);
180 181 182
        phy_vars_eNB->dlsch_eNB[i][0]->rnti = rnti;
        phy_vars_eNB->ulsch_eNB[i]->rnti = rnti;
        phy_vars_eNB->eNB_UE_stats[i].crnti = rnti;
183 184 185 186 187 188 189 190 191

	phy_vars_eNB->eNB_UE_stats[i].Po_PUCCH1_below = 0;
	phy_vars_eNB->eNB_UE_stats[i].Po_PUCCH1_above = (int32_t)pow(10.0,.1*(phy_vars_eNB->lte_frame_parms.ul_power_control_config_common.p0_NominalPUCCH+phy_vars_eNB->rx_total_gain_eNB_dB));
	phy_vars_eNB->eNB_UE_stats[i].Po_PUCCH        = (int32_t)pow(10.0,.1*(phy_vars_eNB->lte_frame_parms.ul_power_control_config_common.p0_NominalPUCCH+phy_vars_eNB->rx_total_gain_eNB_dB));
	LOG_I(PHY,"Initializing Po_PUCCH: p0_NominalPUCCH %d, gain %d => %d\n",
	      phy_vars_eNB->lte_frame_parms.ul_power_control_config_common.p0_NominalPUCCH,
	      phy_vars_eNB->rx_total_gain_eNB_dB,
	      phy_vars_eNB->eNB_UE_stats[i].Po_PUCCH);
  
192
        return(i);
193
      }
194
    }
195 196 197 198
  }
  return(-1);
}

199 200
int32_t remove_ue(uint16_t rnti, PHY_VARS_eNB *phy_vars_eNB, uint8_t abstraction_flag)
{
201
  uint8_t i;
202
  int j;
203

204
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
205
    if ((phy_vars_eNB->dlsch_eNB[i]==NULL) || (phy_vars_eNB->ulsch_eNB[i]==NULL)) {
206
      MSC_LOG_EVENT(MSC_PHY_ENB, "0 Failed remove ue %"PRIx16" (ENOMEM)", rnti);
207 208
      LOG_E(PHY,"Can't remove UE, not enough memory allocated\n");
      return(-1);
209
    } else {
210
      if (phy_vars_eNB->eNB_UE_stats[i].crnti==rnti) {
211
        MSC_LOG_EVENT(MSC_PHY_ENB, "0 Removed ue %"PRIx16" ", rnti);
212 213 214
#ifdef DEBUG_PHY_PROC
	LOG_I(PHY,"eNB %d removing UE %d with rnti %x\n",phy_vars_eNB->Mod_id,i,rnti);
#endif
215 216 217 218 219 220
        //msg("[PHY] UE_id %d\n",i);
        clean_eNb_dlsch(phy_vars_eNB->dlsch_eNB[i][0], abstraction_flag);
        clean_eNb_ulsch(phy_vars_eNB->ulsch_eNB[i],abstraction_flag);
        //phy_vars_eNB->eNB_UE_stats[i].crnti = 0;
        memset(&phy_vars_eNB->eNB_UE_stats[i],0,sizeof(LTE_eNB_UE_stats));
        //  mac_exit_wrapper("Removing UE");
221 222 223 224 225 226 227

        /* clear the harq pid freelist */
        phy_vars_eNB->dlsch_eNB[i][0]->head_freelist = 0;
        phy_vars_eNB->dlsch_eNB[i][0]->tail_freelist = 0;
        for (j = 0; j < 8; j++)
          put_harq_pid_in_freelist(phy_vars_eNB->dlsch_eNB[i][0], j);

228
        return(i);
229
      }
230
    }
231
  }
232

233
  MSC_LOG_EVENT(MSC_PHY_ENB, "0 Failed remove ue %"PRIx16" (not found)", rnti);
234 235 236
  return(-1);
}

237 238
int8_t find_next_ue_index(PHY_VARS_eNB *phy_vars_eNB)
{
239
  uint8_t i;
240

241
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
242
    if (phy_vars_eNB->eNB_UE_stats[i].crnti==0) {
243 244 245
      /*if ((phy_vars_eNB->dlsch_eNB[i]) &&
      (phy_vars_eNB->dlsch_eNB[i][0]) &&
      (phy_vars_eNB->dlsch_eNB[i][0]->rnti==0))*/
246 247 248
      LOG_D(PHY,"Next free UE id is %d\n",i);
      return(i);
    }
249
  }
250

251 252 253
  return(-1);
}

Lionel Gauthier's avatar
Lionel Gauthier committed
254
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 ul_flag)
255 256 257 258
{
  LTE_eNB_DLSCH_t *DLSCH_ptr;
  LTE_eNB_ULSCH_t *ULSCH_ptr;
  uint8_t ulsch_subframe,ulsch_frame;
259
  uint8_t i;
Raymond Knopp's avatar
 
Raymond Knopp committed
260
  int8_t UE_id = find_ue(rnti,PHY_vars_eNB_g[Mod_id][CC_id]);
261
  int sf1=(10*frame)+subframe,sf2,sfdiff,sfdiff_max=7;
262 263

  if (UE_id==-1) {
264
    LOG_D(PHY,"Cannot find UE with rnti %x (Mod_id %d, CC_id %d)\n",rnti, Mod_id, CC_id);
265 266
    *round=0;
    return(-1);
267 268 269
  }

  if (ul_flag == 0)  {// this is a DL request
Raymond Knopp's avatar
 
Raymond Knopp committed
270
    DLSCH_ptr = PHY_vars_eNB_g[Mod_id][CC_id]->dlsch_eNB[(uint32_t)UE_id][0];
271

272 273 274 275 276
    // set to no available process first
    *harq_pid = -1;

    for (i=0; i<DLSCH_ptr->Mdlharq; i++) {
      if (DLSCH_ptr->harq_processes[i]!=NULL) {
277
	if (DLSCH_ptr->harq_processes[i]->status == ACTIVE) {
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
	  sf2 = (DLSCH_ptr->harq_processes[i]->frame*10) + DLSCH_ptr->harq_processes[i]->subframe;
	  if (sf2<=sf1)
	    sfdiff = sf1-sf2;
	  else // this happens when wrapping around 1024 frame barrier
	    sfdiff = 10240 + sf1-sf2;
	  LOG_D(PHY,"process %d is active, round %d (waiting %d)\n",i,DLSCH_ptr->harq_processes[i]->round,sfdiff);

	  if (sfdiff>sfdiff_max) { // this is an active process that is waiting longer than the others (and longer than 7 ms)
	    sfdiff_max = sfdiff; 
	    *harq_pid = i;
	    *round = DLSCH_ptr->harq_processes[i]->round;
	  }
	}
      } else { // a process is not defined
	LOG_E(PHY,"[eNB %d] DLSCH process %d for rnti %x (UE_id %d) not allocated\n",Mod_id,i,rnti,UE_id);
	return(-1);
294
      }
295
    }
296 297 298 299 300 301 302 303

    /* if no active harq pid, get the oldest in the freelist, if any */
    if (*harq_pid == 255 && DLSCH_ptr->head_freelist != DLSCH_ptr->tail_freelist) {
      *harq_pid = DLSCH_ptr->harq_pid_freelist[DLSCH_ptr->head_freelist];
      *round = 0;
      LOG_D(PHY,"process %d is first free process\n", *harq_pid);
    }

304 305
    LOG_D(PHY,"get_ue_active_harq_pid DL => Frame %d, Subframe %d : harq_pid %d\n",
	  frame,subframe,*harq_pid);
306
  } else { // This is a UL request
307

Raymond Knopp's avatar
 
Raymond Knopp committed
308 309 310
    ULSCH_ptr = PHY_vars_eNB_g[Mod_id][CC_id]->ulsch_eNB[(uint32_t)UE_id];
    ulsch_subframe = pdcch_alloc2ul_subframe(&PHY_vars_eNB_g[Mod_id][CC_id]->lte_frame_parms,subframe);
    ulsch_frame    = pdcch_alloc2ul_frame(&PHY_vars_eNB_g[Mod_id][CC_id]->lte_frame_parms,frame,subframe);
311
    // Note this is for TDD configuration 3,4,5 only
Raymond Knopp's avatar
 
Raymond Knopp committed
312
    *harq_pid = subframe2harq_pid(&PHY_vars_eNB_g[Mod_id][CC_id]->lte_frame_parms,
313 314
                                  ulsch_frame,
                                  ulsch_subframe);
315
    *round    = ULSCH_ptr->harq_processes[*harq_pid]->round;
316
    LOG_T(PHY,"[eNB %d][PUSCH %d] Frame %d subframe %d Checking HARQ, round %d\n",Mod_id,*harq_pid,frame,subframe,*round);
317
  }
318

319 320 321
  return(0);
}

322
int16_t get_target_pusch_rx_power(const module_id_t module_idP, const uint8_t CC_id)
323
{
324 325
  //return PHY_vars_eNB_g[module_idP][CC_id]->PHY_measurements_eNB[0].n0_power_tot_dBm;
  return PHY_vars_eNB_g[module_idP][CC_id]->lte_frame_parms.ul_power_control_config_common.p0_NominalPUSCH;
326 327
}

328 329 330 331 332 333
int16_t get_target_pucch_rx_power(const module_id_t module_idP, const uint8_t CC_id)
{
  //return PHY_vars_eNB_g[module_idP][CC_id]->PHY_measurements_eNB[0].n0_power_tot_dBm;
  return PHY_vars_eNB_g[module_idP][CC_id]->lte_frame_parms.ul_power_control_config_common.p0_NominalPUCCH;
}

334
#ifdef EMOS
335 336
void phy_procedures_emos_eNB_TX(unsigned char subframe, PHY_VARS_eNB *phy_vars_eNB)
{
337 338 339 340 341

}
#endif

/*
342
  void phy_procedures_eNB_S_TX(unsigned char next_slot,PHY_VARS_eNB *phy_vars_eNB,uint8_t abstraction_flag) {
343 344 345 346 347 348 349 350

  int sect_id = 0, aa;

  if (next_slot%2==0) {
  #ifdef DEBUG_PHY_PROC
  msg("[PHY][eNB %d] Frame %d, slot %d: Generating pilots for DL-S\n",
  phy_vars_eNB->Mod_id,phy_vars_eNB->frame,next_slot);
  #endif
351

352 353 354 355
  for (sect_id=0;sect_id<number_of_cards;sect_id++) {
  if (abstraction_flag == 0) {

  for (aa=0; aa<phy_vars_eNB->lte_frame_parms.nb_antennas_tx; aa++) {
356 357


358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
  #ifdef IFFT_FPGA
  memset(&phy_vars_eNB->lte_eNB_common_vars.txdataF[sect_id][aa][next_slot*(phy_vars_eNB->lte_frame_parms.N_RB_DL*12)*(phy_vars_eNB->lte_frame_parms.symbols_per_tti>>1)],
  0,(phy_vars_eNB->lte_frame_parms.N_RB_DL*12)*(phy_vars_eNB->lte_frame_parms.symbols_per_tti>>1)*sizeof(mod_sym_t));
  #else
  memset(&phy_vars_eNB->lte_eNB_common_vars.txdataF[sect_id][aa][next_slot*phy_vars_eNB->lte_frame_parms.ofdm_symbol_size*(phy_vars_eNB->lte_frame_parms.symbols_per_tti>>1)],
  0,phy_vars_eNB->lte_frame_parms.ofdm_symbol_size*(phy_vars_eNB->lte_frame_parms.symbols_per_tti>>1)*sizeof(mod_sym_t));
  #endif
  }

  generate_pilots_slot(phy_vars_eNB,
  phy_vars_eNB->lte_eNB_common_vars.txdataF[sect_id],
  AMP,
  next_slot);

  msg("[PHY][eNB] Frame %d, subframe %d Generating PSS\n",
  phy_vars_eNB->frame,next_slot>>1);
374

375 376 377 378 379
  generate_pss(phy_vars_eNB->lte_eNB_common_vars.txdataF[sect_id],
  4*AMP,
  &phy_vars_eNB->lte_frame_parms,
  2,
  next_slot);
380

381 382 383 384 385 386 387 388 389
  }
  else {
  #ifdef PHY_ABSTRACTION
  generate_pss_emul(phy_vars_eNB,sect_id);
  #endif
  }
  }
  }
  }
390
*/
391

392 393 394
void phy_procedures_eNB_S_RX(unsigned char sched_subframe,PHY_VARS_eNB *phy_vars_eNB,uint8_t abstraction_flag,relaying_type_t r_type)
{
  UNUSED(r_type);
395

396
  //  unsigned char sect_id=0;
397
  int subframe = phy_vars_eNB->proc[sched_subframe].subframe_rx;
398

399
#ifdef DEBUG_PHY_PROC
400
  LOG_D(PHY,"[eNB %d] Frame %d: Doing phy_procedures_eNB_S_RX(%d)\n", phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_rx, subframe);
401
#endif
402

Raymond Knopp's avatar
 
Raymond Knopp committed
403
  //  for (sect_id=0;sect_id<number_of_cards;sect_id++) {
404

Raymond Knopp's avatar
 
Raymond Knopp committed
405 406
  if (abstraction_flag == 0) {
    lte_eNB_I0_measurements(phy_vars_eNB,
407
			    subframe,
408 409
                            0,
                            phy_vars_eNB->first_run_I0_measurements);
Raymond Knopp's avatar
 
Raymond Knopp committed
410
  }
411

412
#ifdef PHY_ABSTRACTION
Raymond Knopp's avatar
 
Raymond Knopp committed
413 414
  else {
    lte_eNB_I0_measurements_emul(phy_vars_eNB,
415
                                 0);
416
  }
417

Raymond Knopp's avatar
 
Raymond Knopp committed
418 419
#endif

420

421 422
}

Raymond Knopp's avatar
 
Raymond Knopp committed
423 424


425
#ifdef EMOS
426 427 428
void phy_procedures_emos_eNB_RX(unsigned char subframe,PHY_VARS_eNB *phy_vars_eNB)
{

429 430 431 432
  uint8_t aa;
  uint16_t last_subframe_emos;
  uint16_t pilot_pos1 = 3 - phy_vars_eNB->lte_frame_parms.Ncp, pilot_pos2 = 10 - 2*phy_vars_eNB->lte_frame_parms.Ncp;
  uint32_t bytes;
433 434 435

  last_subframe_emos=0;

Raymond Knopp's avatar
 
Raymond Knopp committed
436

Raymond Knopp's avatar
 
Raymond Knopp committed
437

Raymond Knopp's avatar
 
Raymond Knopp committed
438

439
#ifdef EMOS_CHANNEL
440

441
  //if (last_slot%2==1) // this is for all UL subframes
442
  if (subframe==3)
443
    for (aa=0; aa<phy_vars_eNB->lte_frame_parms.nb_antennas_rx; aa++) {
444 445 446 447 448 449
      memcpy(&emos_dump_eNB.channel[aa][last_subframe_emos*2*phy_vars_eNB->lte_frame_parms.N_RB_UL*12],
             &phy_vars_eNB->lte_eNB_pusch_vars[0]->drs_ch_estimates[0][aa][phy_vars_eNB->lte_frame_parms.N_RB_UL*12*pilot_pos1],
             phy_vars_eNB->lte_frame_parms.N_RB_UL*12*sizeof(int));
      memcpy(&emos_dump_eNB.channel[aa][(last_subframe_emos*2+1)*phy_vars_eNB->lte_frame_parms.N_RB_UL*12],
             &phy_vars_eNB->lte_eNB_pusch_vars[0]->drs_ch_estimates[0][aa][phy_vars_eNB->lte_frame_parms.N_RB_UL*12*pilot_pos2],
             phy_vars_eNB->lte_frame_parms.N_RB_UL*12*sizeof(int));
450
    }
451

452 453
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
454
  if (subframe==4) {
455
    emos_dump_eNB.timestamp = rt_get_time_ns();
jiangx's avatar
jiangx committed
456
    emos_dump_eNB.frame_tx = phy_vars_eNB->proc[subframe].frame_rx;
457 458 459 460 461 462 463 464
    emos_dump_eNB.rx_total_gain_dB = phy_vars_eNB->rx_total_gain_eNB_dB;
    emos_dump_eNB.mimo_mode = phy_vars_eNB->transmission_mode[0];
    memcpy(&emos_dump_eNB.PHY_measurements_eNB,
           &phy_vars_eNB->PHY_measurements_eNB[0],
           sizeof(PHY_MEASUREMENTS_eNB));
    memcpy(&emos_dump_eNB.eNB_UE_stats[0],&phy_vars_eNB->eNB_UE_stats[0],NUMBER_OF_UE_MAX*sizeof(LTE_eNB_UE_stats));

    bytes = rtf_put(CHANSOUNDER_FIFO_MINOR, &emos_dump_eNB, sizeof(fifo_dump_emos_eNB));
465

466 467
    //bytes = rtf_put(CHANSOUNDER_FIFO_MINOR, "test", sizeof("test"));
    if (bytes!=sizeof(fifo_dump_emos_eNB)) {
Raymond Knopp's avatar
 
Raymond Knopp committed
468
      LOG_W(PHY,"[eNB %d] Frame %d, subframe %d, Problem writing EMOS data to FIFO (bytes=%d, size=%d)\n",
jiangx's avatar
jiangx committed
469
            phy_vars_eNB->Mod_id,phy_vars_eNB->proc[(subframe+1)%10].frame_rx, subframe,bytes,sizeof(fifo_dump_emos_eNB));
470
    } else {
Raymond Knopp's avatar
 
Raymond Knopp committed
471 472
      if (phy_vars_eNB->proc[(subframe+1)%10].frame_tx%100==0) {
        LOG_I(PHY,"[eNB %d] Frame %d (%d), subframe %d, Writing %d bytes EMOS data to FIFO\n",
jiangx's avatar
jiangx committed
473
              phy_vars_eNB->Mod_id,phy_vars_eNB->proc[(subframe+1)%10].frame_rx, ((fifo_dump_emos_eNB*)&emos_dump_eNB)->frame_tx, subframe, bytes);
474
      }
475
    }
476 477 478 479 480 481 482
  }
}
#endif


#define AMP_OVER_SQRT2 ((AMP*ONE_OVER_SQRT2_Q15)>>15)
#define AMP_OVER_2 (AMP>>1)
483 484
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)};
485

Lionel Gauthier's avatar
Lionel Gauthier committed
486 487

#if defined(ENABLE_ITTI)
488
#   if ENABLE_RAL
Lionel Gauthier's avatar
Lionel Gauthier committed
489 490
extern PHY_MEASUREMENTS PHY_measurements;

491 492
void phy_eNB_lte_measurement_thresholds_test_and_report(instance_t instanceP, ral_threshold_phy_t* threshold_phy_pP, uint16_t valP)
{
Raymond Knopp's avatar
 
Raymond Knopp committed
493
  MessageDef *message_p = NULL;
494

Raymond Knopp's avatar
 
Raymond Knopp committed
495
  if (
496 497 498 499 500 501
    (
      ((threshold_phy_pP->threshold.threshold_val <  valP) && (threshold_phy_pP->threshold.threshold_xdir == RAL_ABOVE_THRESHOLD)) ||
      ((threshold_phy_pP->threshold.threshold_val >  valP) && (threshold_phy_pP->threshold.threshold_xdir == RAL_BELOW_THRESHOLD))
    )  ||
    (threshold_phy_pP->threshold.threshold_xdir == RAL_NO_THRESHOLD)
  ) {
Raymond Knopp's avatar
 
Raymond Knopp committed
502 503 504 505
    message_p = itti_alloc_new_message(TASK_PHY_ENB , PHY_MEAS_REPORT_IND);
    memset(&PHY_MEAS_REPORT_IND(message_p), 0, sizeof(PHY_MEAS_REPORT_IND(message_p)));

    memcpy(&PHY_MEAS_REPORT_IND (message_p).threshold,
506 507
           &threshold_phy_pP->threshold,
           sizeof(PHY_MEAS_REPORT_IND (message_p).threshold));
Raymond Knopp's avatar
 
Raymond Knopp committed
508 509

    memcpy(&PHY_MEAS_REPORT_IND (message_p).link_param,
510 511 512
           &threshold_phy_pP->link_param,
           sizeof(PHY_MEAS_REPORT_IND (message_p).link_param));
    \
Raymond Knopp's avatar
 
Raymond Knopp committed
513 514 515 516 517

    switch (threshold_phy_pP->link_param.choice) {
    case RAL_LINK_PARAM_CHOICE_LINK_PARAM_VAL:
      PHY_MEAS_REPORT_IND (message_p).link_param._union.link_param_val = valP;
      break;
518

Raymond Knopp's avatar
 
Raymond Knopp committed
519 520 521 522
    case RAL_LINK_PARAM_CHOICE_QOS_PARAM_VAL:
      //PHY_MEAS_REPORT_IND (message_p).link_param._union.qos_param_val.
      AssertFatal (1 == 0, "TO DO RAL_LINK_PARAM_CHOICE_QOS_PARAM_VAL\n");
      break;
523
    }
524

Raymond Knopp's avatar
 
Raymond Knopp committed
525 526
    itti_send_msg_to_task(TASK_RRC_ENB, instanceP, message_p);
  }
Lionel Gauthier's avatar
Lionel Gauthier committed
527 528
}

529 530
void phy_eNB_lte_check_measurement_thresholds(instance_t instanceP, ral_threshold_phy_t* threshold_phy_pP)
{
Raymond Knopp's avatar
 
Raymond Knopp committed
531 532 533 534 535 536 537 538 539 540 541
  unsigned int  mod_id;

  mod_id = instanceP;

  switch (threshold_phy_pP->link_param.link_param_type.choice) {

  case RAL_LINK_PARAM_TYPE_CHOICE_GEN:
    switch (threshold_phy_pP->link_param.link_param_type._union.link_param_gen) {
    case RAL_LINK_PARAM_GEN_DATA_RATE:
      phy_eNB_lte_measurement_thresholds_test_and_report(instanceP, threshold_phy_pP, 0);
      break;
542

Raymond Knopp's avatar
 
Raymond Knopp committed
543 544 545
    case RAL_LINK_PARAM_GEN_SIGNAL_STRENGTH:
      phy_eNB_lte_measurement_thresholds_test_and_report(instanceP, threshold_phy_pP, 0);
      break;
546

Raymond Knopp's avatar
 
Raymond Knopp committed
547 548 549
    case RAL_LINK_PARAM_GEN_SINR:
      phy_eNB_lte_measurement_thresholds_test_and_report(instanceP, threshold_phy_pP, 0);
      break;
550

Raymond Knopp's avatar
 
Raymond Knopp committed
551 552
    case RAL_LINK_PARAM_GEN_THROUGHPUT:
      break;
553

Raymond Knopp's avatar
 
Raymond Knopp committed
554 555
    case RAL_LINK_PARAM_GEN_PACKET_ERROR_RATE:
      break;
556 557 558

    default:
      ;
Lionel Gauthier's avatar
Lionel Gauthier committed
559
    }
560

Raymond Knopp's avatar
 
Raymond Knopp committed
561 562 563 564 565 566
    break;

  case RAL_LINK_PARAM_TYPE_CHOICE_LTE:
    switch (threshold_phy_pP->link_param.link_param_type._union.link_param_gen) {
    case RAL_LINK_PARAM_LTE_UE_RSRP:
      break;
567

Raymond Knopp's avatar
 
Raymond Knopp committed
568 569
    case RAL_LINK_PARAM_LTE_UE_RSRQ:
      break;
570

Raymond Knopp's avatar
 
Raymond Knopp committed
571 572
    case RAL_LINK_PARAM_LTE_UE_CQI:
      break;
573

Raymond Knopp's avatar
 
Raymond Knopp committed
574 575
    case RAL_LINK_PARAM_LTE_AVAILABLE_BW:
      break;
576

Raymond Knopp's avatar
 
Raymond Knopp committed
577 578
    case RAL_LINK_PARAM_LTE_PACKET_DELAY:
      break;
579

Raymond Knopp's avatar
 
Raymond Knopp committed
580 581
    case RAL_LINK_PARAM_LTE_PACKET_LOSS_RATE:
      break;
582

Raymond Knopp's avatar
 
Raymond Knopp committed
583 584
    case RAL_LINK_PARAM_LTE_L2_BUFFER_STATUS:
      break;
585

Raymond Knopp's avatar
 
Raymond Knopp committed
586 587
    case RAL_LINK_PARAM_LTE_MOBILE_NODE_CAPABILITIES:
      break;
588

Raymond Knopp's avatar
 
Raymond Knopp committed
589 590
    case RAL_LINK_PARAM_LTE_EMBMS_CAPABILITY:
      break;
591

Raymond Knopp's avatar
 
Raymond Knopp committed
592 593
    case RAL_LINK_PARAM_LTE_JUMBO_FEASIBILITY:
      break;
594

Raymond Knopp's avatar
 
Raymond Knopp committed
595 596
    case RAL_LINK_PARAM_LTE_JUMBO_SETUP_STATUS:
      break;
597

Raymond Knopp's avatar
 
Raymond Knopp committed
598 599
    case RAL_LINK_PARAM_LTE_NUM_ACTIVE_EMBMS_RECEIVERS_PER_FLOW:
      break;
600 601 602

    default:
      ;
Raymond Knopp's avatar
 
Raymond Knopp committed
603
    }
604

Raymond Knopp's avatar
 
Raymond Knopp committed
605 606
    break;

607 608
  default:
    ;
Raymond Knopp's avatar
 
Raymond Knopp committed
609
  }
Lionel Gauthier's avatar
Lionel Gauthier committed
610 611 612 613
}
#   endif
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
614 615


Raymond Knopp's avatar
 
Raymond Knopp committed
616
void phy_procedures_eNB_TX(unsigned char sched_subframe,PHY_VARS_eNB *phy_vars_eNB,uint8_t abstraction_flag,
617 618
                           relaying_type_t r_type,PHY_VARS_RN *phy_vars_rn)
{
619
  UNUSED(phy_vars_rn);
620 621
  uint8_t *pbch_pdu=&phy_vars_eNB->pbch_pdu[0];
  uint16_t input_buffer_length, re_allocated=0;
Raymond Knopp's avatar
 
Raymond Knopp committed
622
  uint32_t i,aa;
623
  uint8_t harq_pid;
624
  DCI_PDU *DCI_pdu;
625
  uint8_t *DLSCH_pdu=NULL;
626
  DCI_PDU DCI_pdu_tmp;
627 628 629 630 631
  uint8_t DLSCH_pdu_tmp[768*8];
  int8_t UE_id;
  uint8_t num_pdcch_symbols=0;
  uint8_t ul_subframe;
  uint32_t ul_frame;
632
#ifdef Rel10
633 634
  MCH_PDU *mch_pduP;
  MCH_PDU  mch_pdu;
635
  //  uint8_t sync_area=255;
636 637 638 639
#endif
#if defined(SMBV) && !defined(EXMIMO)
  // counts number of allocations in subframe
  // there is at least one allocation for PDCCH
640
  uint8_t smbv_alloc_cnt = 1;
641
#endif
642
  int frame = phy_vars_eNB->proc[sched_subframe].frame_tx;
Raymond Knopp's avatar
 
Raymond Knopp committed
643
  int subframe = phy_vars_eNB->proc[sched_subframe].subframe_tx;
644

645
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX,1);
646
  start_meas(&phy_vars_eNB->phy_proc_tx);
647

648
#ifdef DEBUG_PHY_PROC
649
  LOG_D(PHY,"[%s %"PRIu8"] Frame %d subframe %d : Doing phy_procedures_eNB_TX\n",
650 651
        (r_type == multicast_relay) ? "RN/eNB" : "eNB",
        phy_vars_eNB->Mod_id, frame, subframe);
652
#endif
653

654
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
655 656 657
    // If we've dropped the UE, go back to PRACH mode for this UE
    //#if !defined(EXMIMO_IOT)
    if (phy_vars_eNB->eNB_UE_stats[i].ulsch_consecutive_errors == ULSCH_max_consecutive_errors) {
658
      LOG_W(PHY,"[eNB %d, CC %d] frame %d, subframe %d, UE %d: ULSCH consecutive error count reached %u, removing UE\n",
659 660 661 662
            phy_vars_eNB->Mod_id,phy_vars_eNB->CC_id,frame,subframe, i, phy_vars_eNB->eNB_UE_stats[i].ulsch_consecutive_errors);
      phy_vars_eNB->eNB_UE_stats[i].mode = PRACH;
      remove_ue(phy_vars_eNB->eNB_UE_stats[i].crnti,phy_vars_eNB,abstraction_flag);
      phy_vars_eNB->eNB_UE_stats[i].ulsch_consecutive_errors=0;
663
    }
664

665 666 667 668
    //#endif
  }


669
  // Get scheduling info for next subframe
670 671 672 673 674
  if (phy_vars_eNB->mac_enabled==1) {
    if (phy_vars_eNB->CC_id == 0) {
      mac_xface->eNB_dlsch_ulsch_scheduler(phy_vars_eNB->Mod_id,0,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe);//,1);
    }
  }
675

Raymond Knopp's avatar
 
Raymond Knopp committed
676
  if (abstraction_flag==0) {
677
    // clear the transmit data array for the current subframe
678 679
    for (aa=0; aa<phy_vars_eNB->lte_frame_parms.nb_antennas_tx_eNB; aa++) {

Raymond Knopp's avatar
 
Raymond Knopp committed
680
      memset(&phy_vars_eNB->lte_eNB_common_vars.txdataF[0][aa][subframe*phy_vars_eNB->lte_frame_parms.ofdm_symbol_size*(phy_vars_eNB->lte_frame_parms.symbols_per_tti)],
681
             0,phy_vars_eNB->lte_frame_parms.ofdm_symbol_size*(phy_vars_eNB->lte_frame_parms.symbols_per_tti)*sizeof(mod_sym_t));
Raymond Knopp's avatar
 
Raymond Knopp committed
682 683
    }
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
684 685


Raymond Knopp's avatar
 
Raymond Knopp committed
686
  if (is_pmch_subframe(phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,&phy_vars_eNB->lte_frame_parms)) {
Raymond Knopp's avatar
 
Raymond Knopp committed
687

688
    if (abstraction_flag==0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
689 690
      // This is DL-Cell spec pilots in Control region
      generate_pilots_slot(phy_vars_eNB,
691 692 693
                           phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
                           AMP,
                           subframe<<1,1);
Raymond Knopp's avatar
 
Raymond Knopp committed
694
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
695

696
#ifdef Rel10
Raymond Knopp's avatar
 
Raymond Knopp committed
697
    // if mcch is active, send regardless of the node type: eNB or RN
698
    // when mcch is active, MAC sched does not allow MCCH and MTCH multiplexing
Raymond Knopp's avatar
 
Raymond Knopp committed
699
    mch_pduP = mac_xface->get_mch_sdu(phy_vars_eNB->Mod_id,
700 701 702 703 704
                                      phy_vars_eNB->CC_id,
                                      phy_vars_eNB->proc[sched_subframe].frame_tx,
                                      subframe);

    switch (r_type) {
Raymond Knopp's avatar
 
Raymond Knopp committed
705
    case no_relay:
706
      if ((mch_pduP->Pdu_size > 0) && (mch_pduP->sync_area == 0)) // TEST: only transmit mcch for sync area 0
707
        LOG_I(PHY,"[eNB%"PRIu8"] Frame %d subframe %d : Got MCH pdu for MBSFN (MCS %"PRIu8", TBS %d) \n",
708 709
              phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,mch_pduP->mcs,
              phy_vars_eNB->dlsch_eNB_MCH->harq_processes[0]->TBS>>3);
Raymond Knopp's avatar
 
Raymond Knopp committed
710
      else {
711
        LOG_D(PHY,"[DeNB %"PRIu8"] Frame %d subframe %d : Do not transmit MCH pdu for MBSFN sync area %"PRIu8" (%s)\n",
712 713 714
              phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,mch_pduP->sync_area,
              (mch_pduP->Pdu_size == 0)? "Empty MCH PDU":"Let RN transmit for the moment");
        mch_pduP = NULL;
Raymond Knopp's avatar
 
Raymond Knopp committed
715
      }
716

Raymond Knopp's avatar
 
Raymond Knopp committed
717
      break;
718

Raymond Knopp's avatar
 
Raymond Knopp committed
719
    case multicast_relay:
720
      if ((mch_pduP->Pdu_size > 0) && ((mch_pduP->mcch_active == 1) || mch_pduP->msi_active==1)) {
721
        LOG_I(PHY,"[RN %"PRIu8"] Frame %d subframe %d: Got the MCH PDU for MBSFN  sync area %"PRIu8" (MCS %"PRIu8", TBS %"PRIu16")\n",
722 723 724 725 726 727 728 729 730
              phy_vars_rn->Mod_id,phy_vars_rn->frame, subframe,
              mch_pduP->sync_area,mch_pduP->mcs,mch_pduP->Pdu_size);
      } else if (phy_vars_rn->mch_avtive[subframe%5] == 1) { // SF2 -> SF7, SF3 -> SF8
        mch_pduP= &mch_pdu;
        memcpy(&mch_pduP->payload, // could be a simple copy
               phy_vars_rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->b,
               phy_vars_rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->TBS>>3);
        mch_pduP->Pdu_size = (uint16_t) (phy_vars_rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->TBS>>3);
        mch_pduP->mcs = phy_vars_rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->mcs;
731
        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",
732 733
              phy_vars_rn->Mod_id,phy_vars_rn->frame, subframe,subframe%5,
              phy_vars_rn->sync_area[subframe%5],mch_pduP->mcs,mch_pduP->Pdu_size);
Raymond Knopp's avatar
 
Raymond Knopp committed
734
      } else {
735 736 737 738
        /* LOG_I(PHY,"[RN %d] Frame %d subframe %d: do not forward MCH pdu for MBSFN  sync area %d (MCS %d, TBS %d)\n",
           phy_vars_rn->Mod_id,phy_vars_rn->frame, next_slot>>1,
           mch_pduP->sync_area,mch_pduP->mcs,mch_pduP->Pdu_size);*/
        mch_pduP=NULL;
Raymond Knopp's avatar
 
Raymond Knopp committed
739
      }
740

Raymond Knopp's avatar
 
Raymond Knopp committed
741 742
      phy_vars_rn->mch_avtive[subframe]=0;
      break;
743

Raymond Knopp's avatar
 
Raymond Knopp committed
744
    default:
745
      LOG_W(PHY,"[eNB %"PRIu8"] Frame %d subframe %d: unknown relaying type %d \n",
746
            phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,r_type);
Raymond Knopp's avatar
 
Raymond Knopp committed
747 748
      mch_pduP=NULL;
      break;
749 750 751
    }// switch

    if (mch_pduP) {
Raymond Knopp's avatar
 
Raymond Knopp committed
752 753
      fill_eNB_dlsch_MCH(phy_vars_eNB,mch_pduP->mcs,1,0, abstraction_flag);
      // Generate PMCH
Raymond Knopp's avatar
 
Raymond Knopp committed
754
      generate_mch(phy_vars_eNB,sched_subframe,(uint8_t*)mch_pduP->payload,abstraction_flag);
755
#ifdef DEBUG_PHY
756 757

      for (i=0; i<mch_pduP->Pdu_size; i++)
758
        msg("%2"PRIx8".",(uint8_t)mch_pduP->payload[i]);
759

Raymond Knopp's avatar
 
Raymond Knopp committed
760
      msg("\n");
761
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
762 763
    } else {
      LOG_D(PHY,"[eNB/RN] Frame %d subframe %d: MCH not generated \n",phy_vars_eNB->proc[sched_subframe].frame_tx,subframe);
764
    }
765

Raymond Knopp's avatar
 
Raymond Knopp committed
766 767
#endif
  }
768

Raymond Knopp's avatar
 
Raymond Knopp committed
769
  else {
770
    // this is not a pmch subframe
771 772

    if (abstraction_flag==0) {
773
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,1);
Raymond Knopp's avatar
 
Raymond Knopp committed
774
      generate_pilots_slot(phy_vars_eNB,
775 776 777
                           phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
                           AMP,
                           subframe<<1,0);
778 779 780 781 782 783
      if (subframe_select(&phy_vars_eNB->lte_frame_parms,subframe) == SF_DL)
	generate_pilots_slot(phy_vars_eNB,
			     phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
			     AMP,
			     (subframe<<1)+1,0);

784
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,0);
785

Raymond Knopp's avatar
 
Raymond Knopp committed
786 787
      // First half of PSS/SSS (FDD)
      if (subframe == 0) {
788 789
        if (phy_vars_eNB->lte_frame_parms.frame_type == FDD) {
          generate_pss(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
790
                       AMP,
791
                       &phy_vars_eNB->lte_frame_parms,
792
                       (phy_vars_eNB->lte_frame_parms.Ncp==NORMAL) ? 6 : 5,
793 794
                       0);
          generate_sss(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
795
                       AMP,
796
                       &phy_vars_eNB->lte_frame_parms,
797
                       (phy_vars_eNB->lte_frame_parms.Ncp==NORMAL) ? 5 : 4,
798 799 800 801
                       0);

        }
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
802
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
803
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
804

Raymond Knopp's avatar
 
Raymond Knopp committed
805
  if (subframe == 0) {
806
    // generate PBCH (Physical Broadcast CHannel) info
Raymond Knopp's avatar
 
Raymond Knopp committed
807
    if ((phy_vars_eNB->proc[sched_subframe].frame_tx&3) == 0) {
808
      pbch_pdu[2] = 0;
809

810
      // FIXME setting pbch_pdu[2] to zero makes the switch statement easier: remove all the or-operators
Raymond Knopp's avatar
 
Raymond Knopp committed
811 812
      switch (phy_vars_eNB->lte_frame_parms.N_RB_DL) {
      case 6:
813
        pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (0<<5);
814 815
        break;

Raymond Knopp's avatar
 
Raymond Knopp committed
816
      case 15:
817
        pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (1<<5);
818 819
        break;

Raymond Knopp's avatar
 
Raymond Knopp committed
820
      case 25:
821
        pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5);
822 823
        break;

Raymond Knopp's avatar
 
Raymond Knopp committed
824
      case 50:
825
        pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (3<<5);
826 827
        break;

Raymond Knopp's avatar
 
Raymond Knopp committed
828
      case 75:
829
        pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (4<<5);
830 831
        break;

Raymond Knopp's avatar
 
Raymond Knopp committed
832
      case 100:
833
        pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (5<<5);
834 835
        break;

Raymond Knopp's avatar
 
Raymond Knopp committed
836
      default:
837 838
        // FIXME if we get here, this should be flagged as an error, right?
        pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5);
839
        break;
Raymond Knopp's avatar
 
Raymond Knopp committed
840
      }
841

842
      pbch_pdu[2] = (pbch_pdu[2]&0xef) |
843 844
                    ((phy_vars_eNB->lte_frame_parms.phich_config_common.phich_duration << 4)&0x10);

Raymond Knopp's avatar
 
Raymond Knopp committed
845 846
      switch (phy_vars_eNB->lte_frame_parms.phich_config_common.phich_resource) {
      case oneSixth:
847
        pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (0<<2);
848 849
        break;

Raymond Knopp's avatar
 
Raymond Knopp committed
850
      case half:
851
        pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (1<<2);
852 853
        break;

Raymond Knopp's avatar
 
Raymond Knopp committed
854
      case one:
855
        pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (2<<2);
856 857
        break;

Raymond Knopp's avatar
 
Raymond Knopp committed
858
      case two:
859
        pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (3<<2);
860 861
        break;

Raymond Knopp's avatar
 
Raymond Knopp committed
862
      default:
863
        // unreachable
864
        break;
Raymond Knopp's avatar
 
Raymond Knopp committed
865
      }
866

867 868 869
      pbch_pdu[2] = (pbch_pdu[2]&0xfc) | ((phy_vars_eNB->proc[sched_subframe].frame_tx>>8)&0x3);
      pbch_pdu[1] = phy_vars_eNB->proc[sched_subframe].frame_tx&0xfc;
      pbch_pdu[0] = 0;
Raymond Knopp's avatar
 
Raymond Knopp committed
870
    }
871

Raymond Knopp's avatar
 
Raymond Knopp committed
872 873
    /// First half of SSS (TDD)
    if (abstraction_flag==0) {
874

Raymond Knopp's avatar
 
Raymond Knopp committed
875
      if (phy_vars_eNB->lte_frame_parms.frame_type == TDD) {
876 877 878
        generate_sss(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
                     AMP,
                     &phy_vars_eNB->lte_frame_parms,
879
                     (phy_vars_eNB->lte_frame_parms.Ncp==NORMAL) ? 6 : 5,
880
                     1);
Raymond Knopp's avatar
 
Raymond Knopp committed
881
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
882
    }
883 884


885 886


887
#ifdef DEBUG_PHY_PROC
888 889 890
    uint16_t frame_tx = (((int) (pbch_pdu[2]&0x3))<<8) + ((int) (pbch_pdu[1]&0xfc)) + phy_vars_eNB->proc[sched_subframe].frame_tx%4;

    LOG_D(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d: Generating PBCH, mode1_flag=%"PRIu8", frame_tx=%"PRIu16", pdu=%02"PRIx8"%02"PRIx8"%02"PRIx8"\n",
891 892 893 894 895
          phy_vars_eNB->Mod_id,
          phy_vars_eNB->proc[sched_subframe].frame_tx,
          subframe,
          phy_vars_eNB->lte_frame_parms.mode1_flag,
          frame_tx,
896 897 898
          pbch_pdu[2],
          pbch_pdu[1],
          pbch_pdu[0]);
899
#endif
900

Raymond Knopp's avatar
 
Raymond Knopp committed
901
    if (abstraction_flag==0) {
902

Raymond Knopp's avatar
 
Raymond Knopp committed
903
      generate_pbch(&phy_vars_eNB->lte_eNB_pbch,
904 905 906 907 908 909
                    phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
                    AMP,
                    &phy_vars_eNB->lte_frame_parms,
                    pbch_pdu,
                    phy_vars_eNB->proc[sched_subframe].frame_tx&3);

Raymond Knopp's avatar
 
Raymond Knopp committed
910
    }
911

912
#ifdef PHY_ABSTRACTION
Raymond Knopp's avatar
 
Raymond Knopp committed
913
    else {
914
      generate_pbch_emul(phy_vars_eNB,pbch_pdu);
Raymond Knopp's avatar
 
Raymond Knopp committed
915
    }
916

Raymond Knopp's avatar
 
Raymond Knopp committed
917
#endif
918 919


Raymond Knopp's avatar
 
Raymond Knopp committed
920
  }
921

Raymond Knopp's avatar
 
Raymond Knopp committed
922
  if (subframe == 1) {
923

Raymond Knopp's avatar
 
Raymond Knopp committed
924
    if (abstraction_flag==0) {
925

Raymond Knopp's avatar
 
Raymond Knopp committed
926
      if (phy_vars_eNB->lte_frame_parms.frame_type == TDD) {
927 928
        //    printf("Generating PSS (frame %d, subframe %d)\n",phy_vars_eNB->proc[sched_subframe].frame_tx,next_slot>>1);
        generate_pss(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
929
                     AMP,
930 931 932
                     &phy_vars_eNB->lte_frame_parms,
                     2,
                     2);
Raymond Knopp's avatar
 
Raymond Knopp committed
933
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
934
    }
935 936
  }

Raymond Knopp's avatar
 
Raymond Knopp committed
937 938
  // Second half of PSS/SSS (FDD)
  if (subframe == 5) {
939

Raymond Knopp's avatar
 
Raymond Knopp committed
940
    if (abstraction_flag==0) {
941

Raymond Knopp's avatar
 
Raymond Knopp committed
942
      if (phy_vars_eNB->lte_frame_parms.frame_type == FDD) {
943
        generate_pss(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
944
                     AMP,
945
                     &phy_vars_eNB->lte_frame_parms,
946
                     (phy_vars_eNB->lte_frame_parms.Ncp==NORMAL) ? 6 : 5,
947 948
                     10);
        generate_sss(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
949
                     AMP,
950
                     &phy_vars_eNB->lte_frame_parms,
951
                     (phy_vars_eNB->lte_frame_parms.Ncp==NORMAL) ? 5 : 4,
952 953
                     10);

954
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
955
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
956
  }
957

Raymond Knopp's avatar
 
Raymond Knopp committed
958 959 960
  //  Second-half of SSS (TDD)
  if (subframe == 5) {
    if (abstraction_flag==0) {
961

Raymond Knopp's avatar
 
Raymond Knopp committed
962
      if (phy_vars_eNB->lte_frame_parms.frame_type == TDD) {
963 964 965
        generate_sss(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
                     AMP,
                     &phy_vars_eNB->lte_frame_parms,
966
                     (phy_vars_eNB->lte_frame_parms.Ncp==NORMAL) ? 6 : 5,
967
                     11);
968
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
969
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
970
  }
971

Raymond Knopp's avatar
 
Raymond Knopp committed
972 973
  // Second half of PSS (TDD)
  if (subframe == 6) {
974

Raymond Knopp's avatar
 
Raymond Knopp committed
975
    if (abstraction_flag==0) {
976

Raymond Knopp's avatar
 
Raymond Knopp committed
977
      if (phy_vars_eNB->lte_frame_parms.frame_type == TDD) {
978 979
        //      printf("Generating PSS (frame %d, subframe %d)\n",phy_vars_eNB->proc[sched_subframe].frame_tx,next_slot>>1);
        generate_pss(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
980
                     AMP,
981 982 983
                     &phy_vars_eNB->lte_frame_parms,
                     2,
                     12);
984
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
985
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
986
  }
987 988 989



Raymond Knopp's avatar
 
Raymond Knopp committed
990
  //  sect_id=0;
991

992
#if defined(SMBV) && !defined(EXMIMO)
993

Raymond Knopp's avatar
 
Raymond Knopp committed
994 995
  // PBCH takes one allocation
  if (smbv_is_config_frame(phy_vars_eNB->proc[sched_subframe].frame_tx) && (smbv_frame_cnt < 4)) {
996
    if (subframe==0)
Raymond Knopp's avatar
 
Raymond Knopp committed
997 998
      smbv_alloc_cnt++;
  }
999

1000
#endif
1001

1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
  if (phy_vars_eNB->mac_enabled==1) {
    // Parse DCI received from MAC
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PDCCH_TX,1);
    DCI_pdu = mac_xface->get_dci_sdu(phy_vars_eNB->Mod_id,
				     phy_vars_eNB->CC_id,
				     phy_vars_eNB->proc[sched_subframe].frame_tx,
				     subframe);
  }
  else {
    DCI_pdu = &DCI_pdu_tmp;
1012
#ifdef EMOS_CHANNEL
1013
    fill_dci_emos(DCI_pdu,sched_subframe,phy_vars_eNB);
1014
#else
1015
    fill_dci(DCI_pdu,sched_subframe,phy_vars_eNB);
1016
#endif
1017
  }
1018

Raymond Knopp's avatar
 
Raymond Knopp committed
1019 1020
  // clear existing ulsch dci allocations before applying info from MAC  (this is table
  ul_subframe = pdcch_alloc2ul_subframe(&phy_vars_eNB->lte_frame_parms,subframe);
1021
  ul_frame = pdcch_alloc2ul_frame(&phy_vars_eNB->lte_frame_parms,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe);
1022

Raymond Knopp's avatar
 
Raymond Knopp committed
1023 1024 1025
  if ((subframe_select(&phy_vars_eNB->lte_frame_parms,ul_subframe)==SF_UL) ||
      (phy_vars_eNB->lte_frame_parms.frame_type == FDD)) {
    harq_pid = subframe2harq_pid(&phy_vars_eNB->lte_frame_parms,ul_frame,ul_subframe);
1026 1027

    for (i=0; i<NUMBER_OF_UE_MAX; i++)
Raymond Knopp's avatar
 
Raymond Knopp committed
1028
      if (phy_vars_eNB->ulsch_eNB[i]) {
1029 1030
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->dci_alloc=0;
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->rar_alloc=0;
Raymond Knopp's avatar
 
Raymond Knopp committed
1031 1032
      }
  }
1033

1034
#ifdef EMOS
Raymond Knopp's avatar
 
Raymond Knopp committed
1035
  //emos_dump_eNB.dci_cnt[next_slot>>1] = DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci; //nb_dci_common+nb_dci_ue_spec;
1036
#endif
1037

Raymond Knopp's avatar
 
Raymond Knopp committed
1038
  // clear previous allocation information for all UEs
1039
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1040 1041
    phy_vars_eNB->dlsch_eNB[i][0]->subframe_tx[subframe] = 0;
  }
1042

1043
  //  init_nCCE_table();
1044

1045 1046 1047 1048 1049 1050
  num_pdcch_symbols = DCI_pdu->num_pdcch_symbols;
  /*get_num_pdcch_symbols(DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci,
    DCI_pdu->dci_alloc,
    &phy_vars_eNB->lte_frame_parms,
    subframe);*/
  /*
Raymond Knopp's avatar
 
Raymond Knopp committed
1051
  DCI_pdu->nCCE = get_nCCE(num_pdcch_symbols,
1052
                           &phy_vars_eNB->lte_frame_parms,
1053 1054
                           get_mi(&phy_vars_eNB->lte_frame_parms,subframe));*/

1055
  LOG_D(PHY,"num_pdcch_symbols %"PRIu8", nCCE %u (dci commond %"PRIu8", dci uespec %"PRIu8"\n",num_pdcch_symbols,DCI_pdu->nCCE,
1056 1057
        DCI_pdu->Num_common_dci,DCI_pdu->Num_ue_spec_dci);

1058
#if defined(SMBV) && !defined(EXMIMO)
1059

Raymond Knopp's avatar
 
Raymond Knopp committed
1060 1061 1062 1063 1064 1065
  // Sets up PDCCH and DCI table
  if (smbv_is_config_frame(phy_vars_eNB->proc[sched_subframe].frame_tx) && (smbv_frame_cnt < 4) && ((DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci)>0)) {
    msg("[SMBV] Frame %3d, SF %d PDCCH, number of DCIs %d\n",phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci);
    dump_dci(&phy_vars_eNB->lte_frame_parms,&DCI_pdu->dci_alloc[0]);
    smbv_configure_pdcch(smbv_fname,(smbv_frame_cnt*10) + (subframe),num_pdcch_symbols,DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci);
  }
1066 1067 1068 1069

#endif

  for (i=0; i<DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci ; i++) {
1070
    LOG_D(PHY,"[eNB] Subframe %d: DCI %d/%d : rnti %x, CCEind %d\n",subframe,i,DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci,DCI_pdu->dci_alloc[i].rnti,DCI_pdu->dci_alloc[i].firstCCE);
1071
#ifdef DEBUG_PHY_PROC
1072

Raymond Knopp's avatar
 
Raymond Knopp committed
1073
    if (DCI_pdu->dci_alloc[i].rnti != SI_RNTI) {
1074
      LOG_D(PHY,"[eNB] Subframe %d : Doing DCI index %"PRIu32"/%d\n",subframe,i,DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci);
Raymond Knopp's avatar
 
Raymond Knopp committed
1075 1076
      dump_dci(&phy_vars_eNB->lte_frame_parms,&DCI_pdu->dci_alloc[i]);
    }
1077

1078
#endif
1079

Raymond Knopp's avatar
 
Raymond Knopp committed
1080
    if (DCI_pdu->dci_alloc[i].rnti == SI_RNTI) {
1081
#ifdef DEBUG_PHY_PROC
1082
      LOG_D(PHY,"[eNB %"PRIu8"] SI generate_eNB_dlsch_params_from_dci\n", phy_vars_eNB->Mod_id);
Raymond Knopp's avatar
 
Raymond Knopp committed
1083
#endif
1084

1085 1086
      generate_eNB_dlsch_params_from_dci(frame,
					 subframe,
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
                                         &DCI_pdu->dci_alloc[i].dci_pdu[0],
                                         DCI_pdu->dci_alloc[i].rnti,
                                         DCI_pdu->dci_alloc[i].format,
                                         &phy_vars_eNB->dlsch_eNB_SI,
                                         &phy_vars_eNB->lte_frame_parms,
                                         phy_vars_eNB->pdsch_config_dedicated,
                                         SI_RNTI,
                                         0,
                                         P_RNTI,
                                         phy_vars_eNB->eNB_UE_stats[0].DL_pmi_single);

1098

1099
      phy_vars_eNB->dlsch_eNB_SI->nCCE[subframe] = DCI_pdu->dci_alloc[i].firstCCE;
1100

1101 1102 1103
      LOG_T(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for common DCI (SI)  => %"PRIu8"/%u\n",phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,
	    phy_vars_eNB->dlsch_eNB_SI->nCCE[subframe],DCI_pdu->nCCE);
      
1104
#if defined(SMBV) && !defined(EXMIMO)
1105

1106 1107 1108 1109
      // configure SI DCI
      if (smbv_is_config_frame(phy_vars_eNB->proc[sched_subframe].frame_tx) && (smbv_frame_cnt < 4)) {
	msg("[SMBV] Frame %3d, SI in SF %d DCI %"PRIu32"\n",phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,i);
	smbv_configure_common_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), "SI", &DCI_pdu->dci_alloc[i], i);
Raymond Knopp's avatar
 
Raymond Knopp committed
1110
      }
1111 1112 1113
      
#endif
      
1114 1115

    } else if (DCI_pdu->dci_alloc[i].ra_flag == 1) {
1116
#ifdef DEBUG_PHY_PROC
1117
      LOG_D(PHY,"[eNB %"PRIu8"] RA generate_eNB_dlsch_params_from_dci\n", phy_vars_eNB->Mod_id);
Raymond Knopp's avatar
 
Raymond Knopp committed
1118
#endif
1119

1120 1121
      generate_eNB_dlsch_params_from_dci(frame,
					 subframe,
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
                                         &DCI_pdu->dci_alloc[i].dci_pdu[0],
                                         DCI_pdu->dci_alloc[i].rnti,
                                         DCI_pdu->dci_alloc[i].format,
                                         &phy_vars_eNB->dlsch_eNB_ra,
                                         &phy_vars_eNB->lte_frame_parms,
                                         phy_vars_eNB->pdsch_config_dedicated,
                                         SI_RNTI,
                                         DCI_pdu->dci_alloc[i].rnti,
                                         P_RNTI,
                                         phy_vars_eNB->eNB_UE_stats[0].DL_pmi_single);

      //    mac_xface->macphy_exit("Transmitted RAR, exiting\n");
Raymond Knopp's avatar
 
Raymond Knopp committed
1134

1135

1136
      phy_vars_eNB->dlsch_eNB_ra->nCCE[subframe] = DCI_pdu->dci_alloc[i].firstCCE;
1137

1138 1139 1140
      LOG_D(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for common DCI (RA)  => %"PRIu8"/%u\n",phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,
	    phy_vars_eNB->dlsch_eNB_ra->nCCE[subframe],DCI_pdu->nCCE);
#if defined(SMBV) && !defined(EXMIMO)
Raymond Knopp's avatar
 
Raymond Knopp committed
1141

1142 1143 1144 1145
      // configure RA DCI
      if (smbv_is_config_frame(phy_vars_eNB->proc[sched_subframe].frame_tx) && (smbv_frame_cnt < 4)) {
	msg("[SMBV] Frame %3d, RA in SF %d DCI %"PRIu32"\n",phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,i);
	smbv_configure_common_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), "RA", &DCI_pdu->dci_alloc[i], i);
Raymond Knopp's avatar
 
Raymond Knopp committed
1146
      }
1147

1148
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1149 1150

    }
1151

1152
    else if (DCI_pdu->dci_alloc[i].format != format0) { // this is a normal DLSCH allocation
1153 1154

#ifdef DEBUG_PHY_PROC
1155
      LOG_D(PHY,"[eNB] Searching for RNTI %"PRIx16"\n",DCI_pdu->dci_alloc[i].rnti);
1156
#endif
1157 1158 1159 1160 1161

      if (phy_vars_eNB->mac_enabled==1)
	UE_id = find_ue((int16_t)DCI_pdu->dci_alloc[i].rnti,phy_vars_eNB);
      else
	UE_id = i;
1162

Raymond Knopp's avatar
 
Raymond Knopp committed
1163
      if (UE_id>=0) {
1164 1165 1166 1167
	if ((frame%100)==0) {
	  LOG_D(PHY,"Frame %3d, SF %d \n",frame,subframe); 
	  dump_dci(&phy_vars_eNB->lte_frame_parms,&DCI_pdu->dci_alloc[i]);
	}
1168
#if defined(SMBV) && !defined(EXMIMO)
1169 1170 1171 1172 1173 1174 1175
        // Configure this user
        if (smbv_is_config_frame(phy_vars_eNB->proc[sched_subframe].frame_tx) && (smbv_frame_cnt < 4)) {
          msg("[SMBV] Frame %3d, SF %d (SMBV SF %d) Configuring user %d with RNTI %"PRIu16" in TM%"PRIu8"\n",phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,(smbv_frame_cnt*10) + (subframe),UE_id+1,
              DCI_pdu->dci_alloc[i].rnti,phy_vars_eNB->transmission_mode[(uint8_t)UE_id]);
          smbv_configure_user(smbv_fname,UE_id+1,phy_vars_eNB->transmission_mode[(uint8_t)UE_id],DCI_pdu->dci_alloc[i].rnti);
        }

Raymond Knopp's avatar
 
Raymond Knopp committed
1176
#endif
1177

1178 1179
        generate_eNB_dlsch_params_from_dci(frame,
					   subframe,
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
                                           &DCI_pdu->dci_alloc[i].dci_pdu[0],
                                           DCI_pdu->dci_alloc[i].rnti,
                                           DCI_pdu->dci_alloc[i].format,
                                           phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id],
                                           &phy_vars_eNB->lte_frame_parms,
                                           phy_vars_eNB->pdsch_config_dedicated,
                                           SI_RNTI,
                                           0,
                                           P_RNTI,
                                           phy_vars_eNB->eNB_UE_stats[(uint8_t)UE_id].DL_pmi_single);
1190 1191 1192
        LOG_D(PHY,"[eNB %"PRIu8"][PDSCH %"PRIx16"/%"PRIu8"] Frame %d subframe %d: Generated dlsch params\n",
              phy_vars_eNB->Mod_id,DCI_pdu->dci_alloc[i].rnti,phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->current_harq_pid,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe);

1193

1194
        phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->nCCE[subframe] = DCI_pdu->dci_alloc[i].firstCCE;
1195

1196 1197
	LOG_D(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for ue DCI (PDSCH %"PRIx16")  => %"PRIu8"/%u\n",phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,
	      DCI_pdu->dci_alloc[i].rnti,phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->nCCE[subframe],DCI_pdu->nCCE);
1198

1199 1200 1201 1202 1203 1204 1205
#if defined(SMBV) && !defined(EXMIMO)
	
	// configure UE-spec DCI
	if (smbv_is_config_frame(phy_vars_eNB->proc[sched_subframe].frame_tx) && (smbv_frame_cnt < 4)) {
	  msg("[SMBV] Frame %3d, PDSCH in SF %d DCI %"PRIu32"\n",phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,i);
	  smbv_configure_ue_spec_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), UE_id+1, &DCI_pdu->dci_alloc[i], i);
	}
1206

Raymond Knopp's avatar
 
Raymond Knopp committed
1207
#endif
1208 1209 1210

#ifdef DEBUG_PHY_PROC
        //if (phy_vars_eNB->proc[sched_subframe].frame_tx%100 == 0)
1211
        LOG_D(PHY,"[eNB %"PRIu8"][DCI][PDSCH %"PRIx16"] Frame %d subframe %d UE_id %"PRId8" Generated DCI format %d, aggregation %d\n",
1212 1213 1214 1215
              phy_vars_eNB->Mod_id, DCI_pdu->dci_alloc[i].rnti,
              phy_vars_eNB->proc[sched_subframe].frame_tx, subframe,UE_id,
              DCI_pdu->dci_alloc[i].format,
              1<<DCI_pdu->dci_alloc[i].L);
Raymond Knopp's avatar
 
Raymond Knopp committed
1216
#endif
1217
      } else {
1218 1219
        LOG_D(PHY,"[eNB %"PRIu8"][PDSCH] Frame %d : No UE_id with corresponding rnti %"PRIx16", dropping DLSCH\n",
              phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx,DCI_pdu->dci_alloc[i].rnti);
1220
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
1221
    }
1222

Raymond Knopp's avatar
 
Raymond Knopp committed
1223
  }
1224

Raymond Knopp's avatar
 
Raymond Knopp committed
1225 1226
  // Apply physicalConfigDedicated if needed
  phy_config_dedicated_eNB_step2(phy_vars_eNB);
Raymond Knopp's avatar
 
Raymond Knopp committed
1227

1228
  for (i=0; i<DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci ; i++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1229 1230 1231
    if (DCI_pdu->dci_alloc[i].format == format0) {  // this is a ULSCH allocation

      harq_pid = subframe2harq_pid(&phy_vars_eNB->lte_frame_parms,
1232 1233 1234
                                   pdcch_alloc2ul_frame(&phy_vars_eNB->lte_frame_parms,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe),
                                   pdcch_alloc2ul_subframe(&phy_vars_eNB->lte_frame_parms,subframe));

Raymond Knopp's avatar
 
Raymond Knopp committed
1235
      if (harq_pid==255) {
1236
        LOG_E(PHY,"[eNB %"PRIu8"] Frame %d: Bad harq_pid for ULSCH allocation\n",phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx);
kaltenbe's avatar
kaltenbe committed
1237
        //mac_exit_wrapper("Invalid harq_pid (255) detected");
1238
        return; 
Raymond Knopp's avatar
 
Raymond Knopp committed
1239
      }
1240

1241 1242 1243 1244
      if (phy_vars_eNB->mac_enabled==1)
	UE_id = find_ue((int16_t)DCI_pdu->dci_alloc[i].rnti,phy_vars_eNB);
      else
	UE_id = i;
1245

Raymond Knopp's avatar
 
Raymond Knopp committed
1246
      if (UE_id<0) {
1247
        LOG_E(PHY,"[eNB %"PRIu8"] Frame %d: Unknown UE_id for rnti %"PRIx16"\n",phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx,DCI_pdu->dci_alloc[i].rnti);
1248 1249
        mac_exit_wrapper("Invalid UE id (< 0) detected");
        return; // not reached
Raymond Knopp's avatar
 
Raymond Knopp committed
1250
      }
1251

1252
#ifdef DEBUG_PHY_PROC
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1253
      //if (phy_vars_eNB->proc[sched_subframe].frame_tx%100 == 0)
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
      LOG_D(PHY,
            "[eNB %"PRIu8"][PUSCH %"PRIu8"] Frame %d subframe %d UL Frame %"PRIu32", UL Subframe %"PRIu8", Generated ULSCH (format0) DCI (rnti %"PRIx16", dci %"PRIx8") (DCI pos %"PRIu32"/%d), aggregation %d\n",
            phy_vars_eNB->Mod_id,
            subframe2harq_pid(&phy_vars_eNB->lte_frame_parms,
                              pdcch_alloc2ul_frame(&phy_vars_eNB->lte_frame_parms,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe),
                              pdcch_alloc2ul_subframe(&phy_vars_eNB->lte_frame_parms,subframe)),
            phy_vars_eNB->proc[sched_subframe].frame_tx,
            subframe,
            pdcch_alloc2ul_frame(&phy_vars_eNB->lte_frame_parms,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe),
            pdcch_alloc2ul_subframe(&phy_vars_eNB->lte_frame_parms,subframe),
            DCI_pdu->dci_alloc[i].rnti,
            DCI_pdu->dci_alloc[i].dci_pdu[0],
            i,
            DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci,
            1<<DCI_pdu->dci_alloc[i].L);
Raymond Knopp's avatar
 
Raymond Knopp committed
1269 1270 1271 1272
#endif

      //dump_dci(&phy_vars_eNB->lte_frame_parms,&DCI_pdu->dci_alloc[i]);
      //LOG_D(PHY,"[eNB] cba generate_eNB_ulsch_params_from_dci for ue %d for dci rnti %x\n", UE_id, DCI_pdu->dci_alloc[i].rnti);
1273

Raymond Knopp's avatar
 
Raymond Knopp committed
1274
      generate_eNB_ulsch_params_from_dci(&DCI_pdu->dci_alloc[i].dci_pdu[0],
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
                                         DCI_pdu->dci_alloc[i].rnti,
                                         sched_subframe,
                                         format0,
                                         UE_id,
                                         phy_vars_eNB,
                                         SI_RNTI,
                                         0,
                                         P_RNTI,
                                         CBA_RNTI,
                                         0);  // do_srs
Raymond Knopp's avatar
 
Raymond Knopp committed
1285

1286 1287 1288 1289
      LOG_T(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resources for UE spec DCI (PUSCH %"PRIx16") => %d/%u\n",
	    phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,DCI_pdu->dci_alloc[i].rnti,
	    DCI_pdu->dci_alloc[i].firstCCE,DCI_pdu->nCCE);
      
1290
#if defined(SMBV) && !defined(EXMIMO)
1291 1292

        // configure UE-spec DCI for UL Grant
1293 1294 1295 1296 1297
      if (smbv_is_config_frame(phy_vars_eNB->proc[sched_subframe].frame_tx) && (smbv_frame_cnt < 4)) {
	msg("[SMBV] Frame %3d, SF %d UL DCI %"PRIu32"\n",phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,i);
	smbv_configure_ue_spec_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), UE_id+1, &DCI_pdu->dci_alloc[i], i);
      }
      
1298 1299
#endif

1300
      
1301

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1302
#ifdef DEBUG_PHY_PROC
1303
      LOG_D(PHY,"[eNB %"PRIu8"][PUSCH %"PRIu8"] frame %d subframe %d Setting subframe_scheduling_flag for UE %"PRIu32" harq_pid %"PRIu8" (ul subframe %"PRIu8")\n",
1304 1305 1306
            phy_vars_eNB->Mod_id,harq_pid,
            phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,i,harq_pid,
            pdcch_alloc2ul_subframe(&phy_vars_eNB->lte_frame_parms,subframe));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1307
#endif
1308

Raymond Knopp's avatar
 
Raymond Knopp committed
1309
      if ((DCI_pdu->dci_alloc[i].rnti  >= CBA_RNTI) && (DCI_pdu->dci_alloc[i].rnti < P_RNTI))
1310 1311 1312
        phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->harq_processes[harq_pid]->subframe_cba_scheduling_flag = 1;
      else
        phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 1;
1313

Raymond Knopp's avatar
 
Raymond Knopp committed
1314
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
1315
  }
1316

1317 1318


Lionel Gauthier's avatar
Lionel Gauthier committed
1319 1320


Raymond Knopp's avatar
 
Raymond Knopp committed
1321 1322
  // if we have DCI to generate do it now
  if ((DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci)>0) {
Lionel Gauthier's avatar
Lionel Gauthier committed
1323

1324 1325

  } else { // for emulation!!
Raymond Knopp's avatar
 
Raymond Knopp committed
1326 1327 1328
    phy_vars_eNB->num_ue_spec_dci[(subframe)&1]=0;
    phy_vars_eNB->num_common_dci[(subframe)&1]=0;
  }
1329

Raymond Knopp's avatar
 
Raymond Knopp committed
1330
  if (abstraction_flag == 0) {
1331
    //#ifdef DEBUG_PHY_PROC
1332

Raymond Knopp's avatar
 
Raymond Knopp committed
1333
    if (DCI_pdu->Num_ue_spec_dci+DCI_pdu->Num_common_dci > 0)
1334 1335 1336
      LOG_D(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d: Calling generate_dci_top (pdcch) (common %"PRIu8",ue_spec %"PRIu8")\n",phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx, subframe,
            DCI_pdu->Num_common_dci,DCI_pdu->Num_ue_spec_dci);

1337
    //#endif
1338

1339 1340 1341 1342 1343 1344 1345 1346 1347
    //    for (sect_id=0;sect_id<number_of_cards;sect_id++)
    num_pdcch_symbols = generate_dci_top(DCI_pdu->Num_ue_spec_dci,
                                         DCI_pdu->Num_common_dci,
                                         DCI_pdu->dci_alloc,
                                         0,
                                         AMP,
                                         &phy_vars_eNB->lte_frame_parms,
                                         phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
                                         subframe);
Raymond Knopp's avatar
Raymond Knopp committed
1348 1349

#ifdef DEBUG_PHY_PROC
1350
    //  LOG_I(PHY,"[eNB %d] Frame %d, subframe %d: num_pdcch_symbols %d)\n",phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx, next_slot>>1,num_pdcch_symbols);
Raymond Knopp's avatar
Raymond Knopp committed
1351 1352

#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1353
  }
1354

1355
#ifdef PHY_ABSTRACTION // FIXME this ifdef seems suspicious
Raymond Knopp's avatar
 
Raymond Knopp committed
1356
  else {
1357
    LOG_D(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d: Calling generate_dci_top_emul\n",phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx, subframe);
Raymond Knopp's avatar
 
Raymond Knopp committed
1358 1359
    num_pdcch_symbols = generate_dci_top_emul(phy_vars_eNB,DCI_pdu->Num_ue_spec_dci,DCI_pdu->Num_common_dci,DCI_pdu->dci_alloc,subframe);
  }
1360

1361 1362
#endif

1363
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PDCCH_TX,0);
1364 1365

#ifdef DEBUG_PHY_PROC
Raymond Knopp's avatar
 
Raymond Knopp committed
1366
  //LOG_D(PHY,"[eNB %d] Frame %d, slot %d: num_pdcch_symbols=%d\n",phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx, next_slot,num_pdcch_symbols);
1367 1368
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
1369
  // Check for SI activity
1370

Raymond Knopp's avatar
 
Raymond Knopp committed
1371 1372
  if (phy_vars_eNB->dlsch_eNB_SI->active == 1) {
    input_buffer_length = phy_vars_eNB->dlsch_eNB_SI->harq_processes[0]->TBS/8;
1373 1374


1375 1376 1377 1378 1379 1380 1381 1382 1383
    if (phy_vars_eNB->mac_enabled==1) {
      DLSCH_pdu = mac_xface->get_dlsch_sdu(phy_vars_eNB->Mod_id,
					   phy_vars_eNB->CC_id,
					   phy_vars_eNB->proc[sched_subframe].frame_tx,
					   SI_RNTI,
					   0);
    }
    else {
      DLSCH_pdu = DLSCH_pdu_tmp;
1384

1385 1386 1387
      for (i=0; i<input_buffer_length; i++)
	DLSCH_pdu[i] = (unsigned char)(taus()&0xff);
    }
1388

1389
#if defined(SMBV) && !defined(EXMIMO)
1390

Raymond Knopp's avatar
 
Raymond Knopp committed
1391 1392
    // Configures the data source of allocation (allocation is configured by DCI)
    if (smbv_is_config_frame(phy_vars_eNB->proc[sched_subframe].frame_tx) && (smbv_frame_cnt < 4)) {
1393
      msg("[SMBV] Frame %3d, Configuring SI payload in SF %d alloc %"PRIu8"\n",phy_vars_eNB->proc[sched_subframe].frame_tx,(smbv_frame_cnt*10) + (subframe),smbv_alloc_cnt);
Raymond Knopp's avatar
 
Raymond Knopp committed
1394 1395
      smbv_configure_datalist_for_alloc(smbv_fname, smbv_alloc_cnt++, (smbv_frame_cnt*10) + (subframe), DLSCH_pdu, input_buffer_length);
    }
1396 1397

#endif
1398 1399 1400

#ifdef DEBUG_PHY_PROC
#ifdef DEBUG_DLSCH
1401 1402
   //FIXME: The code below is commented as next_slot is not defined which results in failed compilation
   /*
1403 1404
    LOG_D(PHY,"[eNB %"PRIu8"][SI] Frame %d, slot %d: Calling generate_dlsch (SI) with input size = %"PRIu16", num_pdcch_symbols %"PRIu8"\n",
          phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx, next_slot, input_buffer_length,num_pdcch_symbols); // FIXME this code is broken (next_slot?)
1405 1406

    for (i=0; i<input_buffer_length; i++)
1407
      LOG_T(PHY,"%x.",i,DLSCH_pdu[i]);// FIXME this code is broken (number of arguments)
1408

Raymond Knopp's avatar
 
Raymond Knopp committed
1409
    LOG_T(PHY,"\n");
1410
    */
1411 1412 1413
#endif
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
1414
    if (abstraction_flag == 0) {
1415

1416
      start_meas(&phy_vars_eNB->dlsch_encoding_stats);
Raymond Knopp's avatar
 
Raymond Knopp committed
1417
      dlsch_encoding(DLSCH_pdu,
1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
                     &phy_vars_eNB->lte_frame_parms,
                     num_pdcch_symbols,
                     phy_vars_eNB->dlsch_eNB_SI,
                     phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,
                     &phy_vars_eNB->dlsch_rate_matching_stats,
                     &phy_vars_eNB->dlsch_turbo_encoding_stats,
                     &phy_vars_eNB->dlsch_interleaving_stats);
      stop_meas(&phy_vars_eNB->dlsch_encoding_stats);

      start_meas(&phy_vars_eNB->dlsch_scrambling_stats);
Raymond Knopp's avatar
 
Raymond Knopp committed
1428
      dlsch_scrambling(&phy_vars_eNB->lte_frame_parms,
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
                       0,
                       phy_vars_eNB->dlsch_eNB_SI,
                       get_G(&phy_vars_eNB->lte_frame_parms,
                             phy_vars_eNB->dlsch_eNB_SI->harq_processes[0]->nb_rb,
                             phy_vars_eNB->dlsch_eNB_SI->harq_processes[0]->rb_alloc,
                             get_Qm(phy_vars_eNB->dlsch_eNB_SI->harq_processes[0]->mcs),
                             1,
                             num_pdcch_symbols,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe),
                       0,
                       subframe<<1);

      stop_meas(&phy_vars_eNB->dlsch_scrambling_stats);

      start_meas(&phy_vars_eNB->dlsch_modulation_stats);
      //      for (sect_id=0;sect_id<number_of_cards;sect_id++)
Raymond Knopp's avatar
 
Raymond Knopp committed
1444
      re_allocated = dlsch_modulation(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
1445 1446 1447 1448 1449 1450 1451 1452 1453
                                      AMP,
                                      subframe,
                                      &phy_vars_eNB->lte_frame_parms,
                                      num_pdcch_symbols,
                                      phy_vars_eNB->dlsch_eNB_SI,
                                      (LTE_eNB_DLSCH_t *)NULL);
      stop_meas(&phy_vars_eNB->dlsch_modulation_stats);
    }

1454
#ifdef PHY_ABSTRACTION
Raymond Knopp's avatar
 
Raymond Knopp committed
1455
    else {
1456
      start_meas(&phy_vars_eNB->dlsch_encoding_stats);
Raymond Knopp's avatar
 
Raymond Knopp committed
1457
      dlsch_encoding_emul(phy_vars_eNB,
1458 1459 1460
                          DLSCH_pdu,
                          phy_vars_eNB->dlsch_eNB_SI);
      stop_meas(&phy_vars_eNB->dlsch_encoding_stats);
Raymond Knopp's avatar
 
Raymond Knopp committed
1461
    }
1462

1463
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1464
    phy_vars_eNB->dlsch_eNB_SI->active = 0;
1465

Raymond Knopp's avatar
 
Raymond Knopp committed
1466
  }
Lionel Gauthier's avatar
Lionel Gauthier committed
1467

Raymond Knopp's avatar
 
Raymond Knopp committed
1468 1469
  // Check for RA activity
  if (phy_vars_eNB->dlsch_eNB_ra->active == 1) {
1470
#ifdef DEBUG_PHY_PROC
1471
    LOG_D(PHY,"[eNB %"PRIu8"][RAPROC] Frame %d, subframe %d, RA active, filling RAR:\n",
1472
          phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx, subframe);
1473 1474
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
1475
    input_buffer_length = phy_vars_eNB->dlsch_eNB_ra->harq_processes[0]->TBS/8;
1476

1477
    int16_t crnti = mac_xface->fill_rar(phy_vars_eNB->Mod_id,
1478 1479 1480 1481 1482
                                        phy_vars_eNB->CC_id,
                                        phy_vars_eNB->proc[sched_subframe].frame_tx,
                                        dlsch_input_buffer,
                                        phy_vars_eNB->lte_frame_parms.N_RB_UL,
                                        input_buffer_length);
Raymond Knopp's avatar
 
Raymond Knopp committed
1483 1484 1485 1486 1487
    /*
      for (i=0;i<input_buffer_length;i++)
      LOG_T(PHY,"%x.",dlsch_input_buffer[i]);
      LOG_T(PHY,"\n");
    */
kaltenbe's avatar
kaltenbe committed
1488 1489 1490 1491
    if (crnti!=0) 
      UE_id = add_ue(crnti,phy_vars_eNB);
    else 
      UE_id = -1;
1492

Raymond Knopp's avatar
 
Raymond Knopp committed
1493 1494 1495 1496
    if (UE_id==-1) {
      LOG_W(PHY,"[eNB] Max user count reached.\n");
      //mac_xface->macphy_exit("[PHY][eNB] Max user count reached.\n");
      mac_xface->cancel_ra_proc(phy_vars_eNB->Mod_id,
1497 1498 1499 1500
                                phy_vars_eNB->CC_id,
                                phy_vars_eNB->proc[sched_subframe].frame_tx,
                                crnti);
    } else {
Raymond Knopp's avatar
 
Raymond Knopp committed
1501 1502 1503 1504 1505
      phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].mode = RA_RESPONSE;
      // Initialize indicator for first SR (to be cleared after ConnectionSetup is acknowledged)
      phy_vars_eNB->first_sr[(uint32_t)UE_id] = 1;

      generate_eNB_ulsch_params_from_rar(dlsch_input_buffer,
1506 1507 1508 1509
                                         phy_vars_eNB->proc[sched_subframe].frame_tx,
                                         (subframe),
                                         phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id],
                                         &phy_vars_eNB->lte_frame_parms);
Raymond Knopp's avatar
 
Raymond Knopp committed
1510 1511 1512 1513

      phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_active = 1;

      get_Msg3_alloc(&phy_vars_eNB->lte_frame_parms,
1514 1515 1516 1517
                     subframe,
                     phy_vars_eNB->proc[sched_subframe].frame_tx,
                     &phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_frame,
                     &phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_subframe);
1518
      LOG_I(PHY,"[eNB][RAPROC] Frame %d subframe %d, Activated Msg3 demodulation for UE %"PRId8" in frame %"PRIu32", subframe %"PRIu8"\n",
1519 1520 1521 1522 1523 1524
            phy_vars_eNB->proc[sched_subframe].frame_tx,
            subframe,
            UE_id,
            phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_frame,
            phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_subframe);

1525 1526 1527 1528 1529 1530 1531 1532
    /*
      for (i=0; i<input_buffer_length; i++)
	dlsch_input_buffer[i]= (unsigned char) i; //(taus()&0xff);
      
      dlsch_input_buffer[1] = (phy_vars_eNB->eNB_UE_stats[0].UE_timing_offset)>>(2+4); // 7 MSBs of timing advance + divide by 4
      dlsch_input_buffer[2] = ((phy_vars_eNB->eNB_UE_stats[0].UE_timing_offset)<<(4-2))&0xf0;  // 4 LSBs of timing advance + divide by 4
      //LOG_I(PHY,"UE %d: timing_offset = %d\n",UE_id,phy_vars_eNB->eNB_UE_stats[0].UE_timing_offset);
    */
1533 1534

#if defined(SMBV) && !defined(EXMIMO)
1535

Raymond Knopp's avatar
 
Raymond Knopp committed
1536 1537
      // Configures the data source of allocation (allocation is configured by DCI)
      if (smbv_is_config_frame(phy_vars_eNB->proc[sched_subframe].frame_tx) && (smbv_frame_cnt < 4)) {
1538
        msg("[SMBV] Frame %3d, Configuring RA payload in SF %d alloc %"PRIu8"\n",phy_vars_eNB->proc[sched_subframe].frame_tx,(smbv_frame_cnt*10) + (subframe),smbv_alloc_cnt);
1539
        smbv_configure_datalist_for_alloc(smbv_fname, smbv_alloc_cnt++, (smbv_frame_cnt*10) + (subframe), dlsch_input_buffer, input_buffer_length);
Raymond Knopp's avatar
 
Raymond Knopp committed
1540
      }
1541 1542

#endif
1543 1544

#ifdef DEBUG_PHY_PROC
1545
      LOG_D(PHY,"[eNB %"PRIu8"][RAPROC] Frame %d, subframe %d: Calling generate_dlsch (RA) with input size = %"PRIu16",Msg3 frame %"PRIu32", Msg3 subframe %"PRIu8"\n",
1546 1547 1548 1549
            phy_vars_eNB->Mod_id,
            phy_vars_eNB->proc[sched_subframe].frame_tx, subframe,input_buffer_length,
            phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_frame,
            phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_subframe);
1550 1551
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
1552 1553
      if (abstraction_flag == 0) {

1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
        dlsch_encoding(dlsch_input_buffer,
                       &phy_vars_eNB->lte_frame_parms,
                       num_pdcch_symbols,
                       phy_vars_eNB->dlsch_eNB_ra,
                       phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,
                       &phy_vars_eNB->dlsch_rate_matching_stats,
                       &phy_vars_eNB->dlsch_turbo_encoding_stats,
                       &phy_vars_eNB->dlsch_interleaving_stats);

        //  phy_vars_eNB->dlsch_eNB_ra->rnti = RA_RNTI;
        dlsch_scrambling(&phy_vars_eNB->lte_frame_parms,
                         0,
                         phy_vars_eNB->dlsch_eNB_ra,
                         get_G(&phy_vars_eNB->lte_frame_parms,
                               phy_vars_eNB->dlsch_eNB_ra->harq_processes[0]->nb_rb,
                               phy_vars_eNB->dlsch_eNB_ra->harq_processes[0]->rb_alloc,
                               get_Qm(phy_vars_eNB->dlsch_eNB_ra->harq_processes[0]->mcs),
                               1,
                               num_pdcch_symbols,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe),
                         0,
                         subframe<<1);
        //  for (sect_id=0;sect_id<number_of_cards;sect_id++)
        re_allocated = dlsch_modulation(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
                                        AMP,
                                        subframe,
                                        &phy_vars_eNB->lte_frame_parms,
                                        num_pdcch_symbols,
                                        phy_vars_eNB->dlsch_eNB_ra,
                                        (LTE_eNB_DLSCH_t *)NULL);
Raymond Knopp's avatar
 
Raymond Knopp committed
1583
      }
1584

1585
#ifdef PHY_ABSTRACTION
Raymond Knopp's avatar
 
Raymond Knopp committed
1586
      else {
1587 1588 1589
        dlsch_encoding_emul(phy_vars_eNB,
                            dlsch_input_buffer,
                            phy_vars_eNB->dlsch_eNB_ra);
Raymond Knopp's avatar
 
Raymond Knopp committed
1590
      }
1591

1592
#endif
1593
      LOG_D(PHY,"[eNB %"PRIu8"][RAPROC] Frame %d subframe %d Deactivating DLSCH RA\n",phy_vars_eNB->Mod_id,
1594 1595 1596
            phy_vars_eNB->proc[sched_subframe].frame_tx,subframe);

#ifdef DEBUG_PHY_PROC
1597
      LOG_D(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d, DLSCH (RA) re_allocated = %"PRIu16"\n",phy_vars_eNB->Mod_id,
1598
            phy_vars_eNB->proc[sched_subframe].frame_tx, subframe, re_allocated);
1599 1600
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
1601
    } //max user count
1602

Raymond Knopp's avatar
 
Raymond Knopp committed
1603 1604
    phy_vars_eNB->dlsch_eNB_ra->active = 0;
  }
1605

Raymond Knopp's avatar
 
Raymond Knopp committed
1606
  // Now scan UE specific DLSCH
1607 1608
  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++)
  {
Raymond Knopp's avatar
 
Raymond Knopp committed
1609
    if ((phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0])&&
1610 1611
        (phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->rnti>0)&&
        (phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->active == 1)) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1612 1613
      harq_pid = phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->current_harq_pid;
      input_buffer_length = phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->TBS/8;
1614

1615

1616
      //#ifdef DEBUG_PHY_PROC
1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
      LOG_D(PHY,
            "[eNB %"PRIu8"][PDSCH %"PRIx16"/%"PRIu8"] Frame %d, subframe %d: Generating PDSCH/DLSCH with input size = %"PRIu16", G %d, nb_rb %"PRIu16", mcs %"PRIu8", pmi_alloc %"PRIx16", rv %"PRIu8" (round %"PRIu8")\n",
            phy_vars_eNB->Mod_id, phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->rnti,harq_pid,
            phy_vars_eNB->proc[sched_subframe].frame_tx, subframe, input_buffer_length,
            get_G(&phy_vars_eNB->lte_frame_parms,
                  phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->nb_rb,
                  phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->rb_alloc,
                  get_Qm(phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->mcs),
                  phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->Nl,
                  num_pdcch_symbols,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe),
            phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->nb_rb,
            phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->mcs,
            pmi2hex_2Ar1(phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->pmi_alloc),
            phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->rvidx,
            phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->round);
1632
      //#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
#if defined(MESSAGE_CHART_GENERATOR_PHY)
      MSC_LOG_TX_MESSAGE(
        MSC_PHY_ENB,MSC_PHY_UE,
        NULL,0,
        "%05u:%02u PDSCH/DLSCH input size = %"PRIu16", G %d, nb_rb %"PRIu16", mcs %"PRIu8", pmi_alloc %"PRIx16", rv %"PRIu8" (round %"PRIu8")",
        phy_vars_eNB->proc[sched_subframe].frame_tx, subframe,
        input_buffer_length,
        get_G(&phy_vars_eNB->lte_frame_parms,
        		phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->nb_rb,
        		phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->rb_alloc,
        		get_Qm(phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->mcs),
        		phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->Nl,
        		num_pdcch_symbols,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe),
        phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->nb_rb,
        phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->mcs,
        pmi2hex_2Ar1(phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->pmi_alloc),
        phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->rvidx,
        phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->round);
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1652 1653

      phy_vars_eNB->eNB_UE_stats[(uint8_t)UE_id].dlsch_sliding_cnt++;
1654

Raymond Knopp's avatar
 
Raymond Knopp committed
1655 1656
      if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->harq_processes[harq_pid]->round == 0) {

1657 1658
        phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].dlsch_trials[harq_pid][0]++;

1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
	if (phy_vars_eNB->mac_enabled==1) {
	  DLSCH_pdu = mac_xface->get_dlsch_sdu(phy_vars_eNB->Mod_id,
					       phy_vars_eNB->CC_id,
					       phy_vars_eNB->proc[sched_subframe].frame_tx,
					       phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->rnti,
					       0);
	  phy_vars_eNB->eNB_UE_stats[UE_id].total_TBS_MAC += phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->TBS;
	}
	else {
	  DLSCH_pdu = DLSCH_pdu_tmp;
	  
	  for (i=0; i<input_buffer_length; i++)
	    DLSCH_pdu[i] = (unsigned char)(taus()&0xff);
	}
	
1674
#if defined(SMBV) && !defined(EXMIMO)
1675 1676 1677

        // Configures the data source of allocation (allocation is configured by DCI)
        if (smbv_is_config_frame(phy_vars_eNB->proc[sched_subframe].frame_tx) && (smbv_frame_cnt < 4)) {
1678
          msg("[SMBV] Frame %3d, Configuring PDSCH payload in SF %d alloc %"PRIu8"\n",phy_vars_eNB->proc[sched_subframe].frame_tx,(smbv_frame_cnt*10) + (subframe),smbv_alloc_cnt);
1679 1680 1681 1682
          smbv_configure_datalist_for_user(smbv_fname, UE_id+1, DLSCH_pdu, input_buffer_length);
        }

#endif
1683 1684 1685 1686


#ifdef DEBUG_PHY_PROC
#ifdef DEBUG_DLSCH
1687 1688 1689
        LOG_T(PHY,"eNB DLSCH SDU: \n");

        for (i=0; i<phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->TBS>>3; i++)
1690
          LOG_T(PHY,"%"PRIx8".",DLSCH_pdu[i]);
1691 1692

        LOG_T(PHY,"\n");
1693 1694
#endif
#endif
1695 1696
      } else {
        phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].dlsch_trials[harq_pid][phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->round]++;
1697
#ifdef DEBUG_PHY_PROC
1698 1699
#ifdef DEBUG_DLSCH
        LOG_D(PHY,"[eNB] This DLSCH is a retransmission\n");
1700 1701
#endif
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1702
      }
1703

Raymond Knopp's avatar
 
Raymond Knopp committed
1704
      if (abstraction_flag==0) {
1705

1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
        // 36-212
        start_meas(&phy_vars_eNB->dlsch_encoding_stats);
        dlsch_encoding(DLSCH_pdu,
                       &phy_vars_eNB->lte_frame_parms,
                       num_pdcch_symbols,
                       phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0],
                       phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,
                       &phy_vars_eNB->dlsch_rate_matching_stats,
                       &phy_vars_eNB->dlsch_turbo_encoding_stats,
                       &phy_vars_eNB->dlsch_interleaving_stats);
        stop_meas(&phy_vars_eNB->dlsch_encoding_stats);
        // 36-211
        start_meas(&phy_vars_eNB->dlsch_scrambling_stats);
        dlsch_scrambling(&phy_vars_eNB->lte_frame_parms,
                         0,
                         phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0],
                         get_G(&phy_vars_eNB->lte_frame_parms,
                               phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->nb_rb,
                               phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->rb_alloc,
                               get_Qm(phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->mcs),
                               phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->Nl,
                               num_pdcch_symbols,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe),
                         0,
                         subframe<<1);
        stop_meas(&phy_vars_eNB->dlsch_scrambling_stats);
        start_meas(&phy_vars_eNB->dlsch_modulation_stats);
        //for (sect_id=0;sect_id<number_of_cards;sect_id++) {

        /*          if ((phy_vars_eNB->transmission_mode[(uint8_t)UE_id] == 5) &&
              (phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->dl_power_off == 0))
              amp = (int16_t)(((int32_t)AMP*(int32_t)ONE_OVER_SQRT2_Q15)>>15);
              else*/
        //              amp = AMP;
        //      if (UE_id == 1)
        //      LOG_I(PHY,"[MYEMOS] MCS_i %d\n", phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[harq_pid]->mcs);

        re_allocated = dlsch_modulation(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
                                        AMP,
                                        subframe,
                                        &phy_vars_eNB->lte_frame_parms,
                                        num_pdcch_symbols,
                                        phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0],
                                        phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][1]);

        stop_meas(&phy_vars_eNB->dlsch_modulation_stats);
Raymond Knopp's avatar
 
Raymond Knopp committed
1751
      }
1752

1753
#ifdef PHY_ABSTRACTION
Raymond Knopp's avatar
 
Raymond Knopp committed
1754
      else {
1755 1756 1757 1758 1759
        start_meas(&phy_vars_eNB->dlsch_encoding_stats);
        dlsch_encoding_emul(phy_vars_eNB,
                            DLSCH_pdu,
                            phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]);
        stop_meas(&phy_vars_eNB->dlsch_encoding_stats);
Raymond Knopp's avatar
 
Raymond Knopp committed
1760
      }
1761

1762
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1763
      phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->active = 0;
1764

Raymond Knopp's avatar
 
Raymond Knopp committed
1765 1766
      //mac_xface->macphy_exit("first dlsch transmitted\n");
    }
Lionel Gauthier's avatar
Lionel Gauthier committed
1767

Raymond Knopp's avatar
 
Raymond Knopp committed
1768
    else if ((phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0])&&
1769 1770 1771
             (phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->rnti>0)&&
             (phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->active == 0)) {

Raymond Knopp's avatar
 
Raymond Knopp committed
1772 1773
      // clear subframe TX flag since UE is not scheduled for PDSCH in this subframe (so that we don't look for PUCCH later)
      phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->subframe_tx[subframe]=0;
1774
#ifdef DEBUG_PHY_PROC
Raymond Knopp's avatar
 
Raymond Knopp committed
1775
      //LOG_D(PHY,"[eNB %d] DCI: Clearing subframe_tx for subframe %d, UE %d\n",phy_vars_eNB->Mod_id,subframe,UE_id);
1776
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1777
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
1778
  }
1779

1780 1781


Raymond Knopp's avatar
 
Raymond Knopp committed
1782
  // if we have PHICH to generate
1783 1784 1785
  //    printf("[PHY][eNB] Frame %d subframe %d Checking for phich\n",phy_vars_eNB->proc[sched_subframe].frame_tx,subframe);
  if (is_phich_subframe(&phy_vars_eNB->lte_frame_parms,subframe))
  {
1786
#ifdef DEBUG_PHY_PROC
Raymond Knopp's avatar
 
Raymond Knopp committed
1787
    //      LOG_D(PHY,"[eNB %d] Frame %d, subframe %d: Calling generate_phich_top\n",phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx, subframe);
1788
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1789 1790
    //    for (sect_id=0;sect_id<number_of_cards;sect_id++) {
    generate_phich_top(phy_vars_eNB,
1791 1792 1793 1794
                       sched_subframe,
                       AMP,
                       0,
                       abstraction_flag);
Raymond Knopp's avatar
 
Raymond Knopp committed
1795
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
1796

1797 1798


1799
#ifdef EMOS
jiangx's avatar
jiangx committed
1800
  phy_procedures_emos_eNB_TX(subframe, phy_vars_eNB);
1801
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1802

1803
#if !(defined(EXMIMO) || defined(OAI_USRP) || defined (CPRIGW))
1804 1805 1806

  if (abstraction_flag==0)
  {
Raymond Knopp's avatar
 
Raymond Knopp committed
1807 1808
    start_meas(&phy_vars_eNB->ofdm_mod_stats);
    do_OFDM_mod(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
1809 1810 1811
                phy_vars_eNB->lte_eNB_common_vars.txdata[0],
                phy_vars_eNB->proc[sched_subframe].frame_tx,subframe<<1,
                &phy_vars_eNB->lte_frame_parms);
Raymond Knopp's avatar
 
Raymond Knopp committed
1812
    do_OFDM_mod(phy_vars_eNB->lte_eNB_common_vars.txdataF[0],
1813 1814 1815
                phy_vars_eNB->lte_eNB_common_vars.txdata[0],
                phy_vars_eNB->proc[sched_subframe].frame_tx,1+(subframe<<1),
                &phy_vars_eNB->lte_frame_parms);
Raymond Knopp's avatar
 
Raymond Knopp committed
1816 1817
    stop_meas(&phy_vars_eNB->ofdm_mod_stats);
  }
1818

Raymond Knopp's avatar
 
Raymond Knopp committed
1819
#endif
1820

1821
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX,0);
1822
  stop_meas(&phy_vars_eNB->phy_proc_tx);
1823 1824


1825 1826
}

1827 1828
void process_Msg3(PHY_VARS_eNB *phy_vars_eNB,uint8_t sched_subframe,uint8_t UE_id, uint8_t harq_pid)
{
Raymond Knopp's avatar
 
Raymond Knopp committed
1829
  // this prepares the demodulation of the first PUSCH of a new user, containing Msg3
1830

Raymond Knopp's avatar
 
Raymond Knopp committed
1831
  int subframe = phy_vars_eNB->proc[sched_subframe].subframe_rx;
Raymond Knopp's avatar
 
Raymond Knopp committed
1832
  int frame = phy_vars_eNB->proc[sched_subframe].frame_rx;
Raymond Knopp's avatar
 
Raymond Knopp committed
1833

Raymond Knopp's avatar
 
Raymond Knopp committed
1834
  LOG_D(PHY,"[eNB %d][RAPROC] frame %d : subframe %d : process_Msg3 UE_id %d (active %d, subframe %d, frame %d)\n",
1835 1836 1837 1838 1839
        phy_vars_eNB->Mod_id,
        frame,subframe,
        UE_id,phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_active,
        phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_subframe,
        phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_frame);
1840
  phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_flag = 0;
1841 1842

  if ((phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_active == 1) &&
Raymond Knopp's avatar
 
Raymond Knopp committed
1843
      (phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_subframe == subframe) &&
1844
      (phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_frame == (uint32_t)frame))   {
1845

1846
    //    harq_pid = 0;
1847

1848 1849 1850
    phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_active = 0;
    phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->Msg3_flag = 1;
    phy_vars_eNB->ulsch_eNB[(uint32_t)UE_id]->harq_processes[harq_pid]->subframe_scheduling_flag=1;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1851
    LOG_D(PHY,"[eNB %d][RAPROC] frame %d, subframe %d: Setting subframe_scheduling_flag (Msg3) for UE %d\n",
1852 1853
          phy_vars_eNB->Mod_id,
          frame,subframe,UE_id);
1854 1855 1856 1857 1858 1859 1860 1861 1862
  }
}


// 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

1863 1864 1865 1866 1867 1868 1869 1870
void process_HARQ_feedback(uint8_t UE_id,
                           uint8_t sched_subframe,
                           PHY_VARS_eNB *phy_vars_eNB,
                           uint8_t pusch_flag,
                           uint8_t *pucch_payload,
                           uint8_t pucch_sel,
                           uint8_t SR_payload)
{
1871

Florian Kaltenberger's avatar
Florian Kaltenberger committed
1872
  uint8_t dl_harq_pid[8],dlsch_ACK[8],dl_subframe;
1873 1874
  LTE_eNB_DLSCH_t *dlsch             =  phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0];
  LTE_eNB_UE_stats *ue_stats         =  &phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id];
1875
  LTE_DL_eNB_HARQ_t *dlsch_harq_proc;
1876
  uint8_t subframe_m4,M,m;
1877 1878
  int mp;
  int all_ACKed=1,nb_alloc=0,nb_ACK=0;
Raymond Knopp's avatar
 
Raymond Knopp committed
1879 1880
  int frame = phy_vars_eNB->proc[sched_subframe].frame_rx;
  int subframe = phy_vars_eNB->proc[sched_subframe].subframe_rx;
Raymond Knopp's avatar
 
Raymond Knopp committed
1881
  int harq_pid = subframe2harq_pid( &phy_vars_eNB->lte_frame_parms,frame,subframe);
1882

1883
  if (phy_vars_eNB->lte_frame_parms.frame_type == FDD) { //FDD
1884
    subframe_m4 = (subframe<4) ? subframe+6 : subframe-4;
1885

1886 1887
    dl_harq_pid[0] = dlsch->harq_ids[subframe_m4];
    M=1;
1888

1889
    if (pusch_flag == 1) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1890
      dlsch_ACK[0] = phy_vars_eNB->ulsch_eNB[(uint8_t)UE_id]->harq_processes[harq_pid]->o_ACK[0];
1891 1892 1893 1894 1895
      if (dlsch->subframe_tx[subframe_m4]==1)
      LOG_D(PHY,"[eNB %d] Frame %d: Received ACK/NAK %d on PUSCH for subframe %d\n",phy_vars_eNB->Mod_id,
	    frame,dlsch_ACK[0],subframe_m4);
    }
    else {
1896
      dlsch_ACK[0] = pucch_payload[0];
kaltenbe's avatar
kaltenbe committed
1897
      LOG_D(PHY,"[eNB %d] Frame %d: Received ACK/NAK %d on PUCCH for subframe %d\n",phy_vars_eNB->Mod_id,
1898
	    frame,dlsch_ACK[0],subframe_m4);
kaltenbe's avatar
kaltenbe committed
1899
      /*
1900 1901
      if (dlsch_ACK[0]==0)
	AssertFatal(0,"Exiting on NAK on PUCCH\n");
kaltenbe's avatar
kaltenbe committed
1902
      */
1903
    }
1904

Lionel Gauthier's avatar
Lionel Gauthier committed
1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918

#if defined(MESSAGE_CHART_GENERATOR_PHY)
    MSC_LOG_RX_MESSAGE(
      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
      );
#endif
1919 1920
  } else { // TDD Handle M=1,2 cases only

1921
    M=ul_ACK_subframe2_M(&phy_vars_eNB->lte_frame_parms,
1922 1923
                         subframe);

1924 1925 1926 1927 1928 1929 1930 1931
    // 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

Raymond Knopp's avatar
 
Raymond Knopp committed
1932
      dlsch_ACK[0] = phy_vars_eNB->ulsch_eNB[(uint8_t)UE_id]->harq_processes[harq_pid]->o_ACK[0];
1933 1934
      dlsch_ACK[1] = (phy_vars_eNB->pucch_config_dedicated[UE_id].tdd_AckNackFeedbackMode == bundling)
                     ?phy_vars_eNB->ulsch_eNB[(uint8_t)UE_id]->harq_processes[harq_pid]->o_ACK[0]:phy_vars_eNB->ulsch_eNB[(uint8_t)UE_id]->harq_processes[harq_pid]->o_ACK[1];
1935 1936
      //      printf("UE %d: ACK %d,%d\n",UE_id,dlsch_ACK[0],dlsch_ACK[1]);
    }
1937

1938
    else {  // PUCCH ACK/NAK
1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
      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
        //  printf("*** (%d,%d)\n",pucch_payload[0],pucch_payload[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;
        }
1975
      }
1976
    }
1977 1978 1979 1980
  }

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

    for (m=0; m<M; m++) {
1984
      dl_subframe = ul_ACK_subframe2_dl_subframe(&phy_vars_eNB->lte_frame_parms,
1985 1986 1987 1988 1989
                    subframe,
                    m);

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

1992 1993
    if (nb_alloc == nb_ACK)
      all_ACKed = 1;
1994
    else
1995
      all_ACKed = 0;
1996

1997
    //    printf("nb_alloc %d, all_ACKed %d\n",nb_alloc,all_ACKed);
1998 1999 2000
  }


2001
  for (m=0,mp=-1; m<M; m++) {
2002

2003
    dl_subframe = ul_ACK_subframe2_dl_subframe(&phy_vars_eNB->lte_frame_parms,
2004 2005
                  subframe,
                  m);
2006

2007 2008
    if (dlsch->subframe_tx[dl_subframe]==1) {
      if (pusch_flag == 1)
2009
        mp++;
2010
      else
2011
        mp = m;
2012

2013
      dl_harq_pid[m]     = dlsch->harq_ids[dl_subframe];
2014

2015
      if ((pucch_sel != 2)&&(pusch_flag == 0)) { // multiplexing
2016 2017 2018 2019
        if ((SR_payload == 1)&&(all_ACKed == 1))
          dlsch_ACK[m] = 1;
        else
          dlsch_ACK[m] = 0;
2020
      }
2021

2022
      if (dl_harq_pid[m]<dlsch->Mdlharq) {
2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
        dlsch_harq_proc = dlsch->harq_processes[dl_harq_pid[m]];
#ifdef DEBUG_PHY_PROC
        LOG_D(PHY,"[eNB %d][PDSCH %x/%d] subframe %d, status %d, round %d (mcs %d, rv %d, TBS %d)\n",phy_vars_eNB->Mod_id,
              dlsch->rnti,dl_harq_pid[m],dl_subframe,
              dlsch_harq_proc->status,dlsch_harq_proc->round,
              dlsch->harq_processes[dl_harq_pid[m]]->mcs,
              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");

2035
#endif
2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046

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

          //    msg("[PHY] eNB %d Process %d is active (%d)\n",phy_vars_eNB->Mod_id,dl_harq_pid[m],dlsch_ACK[m]);
          if ( dlsch_ACK[mp]==0) {
            // Received NAK
#ifdef DEBUG_PHY_PROC
            LOG_D(PHY,"[eNB %d][PDSCH %x/%d] M = %d, m= %d, mp=%d NAK Received in round %d, requesting retransmission\n",phy_vars_eNB->Mod_id,
                  dlsch->rnti,dl_harq_pid[m],M,m,mp,dlsch_harq_proc->round);
2047
#endif
2048 2049 2050 2051 2052 2053 2054 2055 2056 2057

            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++;

2058
            if (dlsch_harq_proc->round == 1/*dlsch->Mdlharq*/) {
2059 2060 2061 2062
              // This was the last round for DLSCH so reset round and increment l2_error counter
#ifdef DEBUG_PHY_PROC
              LOG_W(PHY,"[eNB %d][PDSCH %x/%d] DLSCH retransmissions exhausted, dropping packet\n",phy_vars_eNB->Mod_id,
                    dlsch->rnti,dl_harq_pid[m]);
2063
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
2064
#if defined(MESSAGE_CHART_GENERATOR_PHY)
2065
              MSC_LOG_EVENT(MSC_PHY_ENB, "0 HARQ DLSCH Failed RNTI %"PRIx16" round %u",
2066 2067
                            dlsch->rnti,
                            dlsch_harq_proc->round);
Lionel Gauthier's avatar
Lionel Gauthier committed
2068
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
2069

2070 2071 2072
              dlsch_harq_proc->round = 0;
              ue_stats->dlsch_l2_errors[dl_harq_pid[m]]++;
              dlsch_harq_proc->status = SCH_IDLE;
2073
              put_harq_pid_in_freelist(dlsch, dl_harq_pid[m]);
2074 2075 2076 2077 2078 2079
              dlsch->harq_ids[dl_subframe] = dlsch->Mdlharq;
            }
          } else {
#ifdef DEBUG_PHY_PROC
            LOG_D(PHY,"[eNB %d][PDSCH %x/%d] ACK Received in round %d, resetting process\n",phy_vars_eNB->Mod_id,
                  dlsch->rnti,dl_harq_pid[m],dlsch_harq_proc->round);
2080
#endif
2081 2082 2083 2084 2085
            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;
2086
            put_harq_pid_in_freelist(dlsch, dl_harq_pid[m]);
2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107
            dlsch->harq_ids[dl_subframe] = dlsch->Mdlharq;

            ue_stats->total_TBS = ue_stats->total_TBS +
                                  phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[dl_harq_pid[m]]->TBS;
            /*
              ue_stats->total_transmitted_bits = ue_stats->total_transmitted_bits +
              phy_vars_eNB->dlsch_eNB[(uint8_t)UE_id][0]->harq_processes[dl_harq_pid[m]]->TBS;
            */
          }

          // 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);
2108
#endif
2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130

          // 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;
          }


        }
2131
      }
2132
    }
2133 2134 2135 2136
  }
}

void get_n1_pucch_eNB(PHY_VARS_eNB *phy_vars_eNB,
2137 2138 2139 2140 2141 2142 2143
                      uint8_t UE_id,
                      uint8_t sched_subframe,
                      int16_t *n1_pucch0,
                      int16_t *n1_pucch1,
                      int16_t *n1_pucch2,
                      int16_t *n1_pucch3)
{
2144 2145

  LTE_DL_FRAME_PARMS *frame_parms=&phy_vars_eNB->lte_frame_parms;
2146
  uint8_t nCCE0,nCCE1;
2147
  int sf;
Raymond Knopp's avatar
 
Raymond Knopp committed
2148 2149
  int frame = phy_vars_eNB->proc[sched_subframe].frame_rx;
  int subframe = phy_vars_eNB->proc[sched_subframe].subframe_rx;
2150 2151

  if (frame_parms->frame_type == FDD ) {
2152
    sf = (subframe<4) ? (subframe+6) : (subframe-4);
2153
    //    printf("n1_pucch_eNB: subframe %d, nCCE %d\n",sf,phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->nCCE[sf]);
2154

2155 2156
    if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[sf]>0) {
      *n1_pucch0 = frame_parms->pucch_config_common.n1PUCCH_AN + phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->nCCE[sf];
2157
      *n1_pucch1 = -1;
2158
    } else {
2159 2160 2161
      *n1_pucch0 = -1;
      *n1_pucch1 = -1;
    }
2162
  } else {
2163

2164 2165 2166
    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
2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215
        /*  if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[6]>0) {
          nCCE1 = phy_vars_eNB->dlsch_eNB[(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;*/

        if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[5]>0) {
          nCCE0 = phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->nCCE[5];
          *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

        if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[9]>0) {
          nCCE0 = phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->nCCE[9];
          *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;
        if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[0]>0) {
          nCCE0 = phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->nCCE[0];
          *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;
        if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[4]>0) {
          nCCE0 = phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->nCCE[4];
          *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",
              phy_vars_eNB->Mod_id,
              frame,
              subframe,frame_parms->tdd_config);
        return;
2216
      }
2217

2218
      break;
2219

2220 2221
    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)
2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265
        if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[6]>0) {
          nCCE1 = phy_vars_eNB->dlsch_eNB[(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;

        if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[5]>0) {
          nCCE0 = phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->nCCE[5];
          *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",
              phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[7],phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[8]);

        if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[8]>0) {
          nCCE1 = phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->nCCE[8];
          *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;

        if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[7]>0) {
          nCCE0 = phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->nCCE[7];
          *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
        if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[0]>0) {
          nCCE1 = phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->nCCE[0];
          *n1_pucch1 = get_Np(frame_parms->N_RB_DL,nCCE1,1) + nCCE1 + frame_parms->pucch_config_common.n1PUCCH_AN;
        } else
          *n1_pucch1 = -1;

        if (phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->subframe_tx[9]>0) {
          nCCE0 = phy_vars_eNB->dlsch_eNB[(uint32_t)UE_id][0]->nCCE[9];
          *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",
              phy_vars_eNB->Mod_id,frame,subframe,frame_parms->tdd_config);
        return;
2266
      }
2267

2268
      break;
2269 2270
    }  // switch tdd_config

2271 2272 2273
    // Don't handle the case M>2
    *n1_pucch2 = -1;
    *n1_pucch3 = -1;
2274 2275 2276
  }
}

2277 2278
void prach_procedures(PHY_VARS_eNB *phy_vars_eNB,uint8_t sched_subframe,uint8_t abstraction_flag)
{
2279

2280 2281 2282 2283
  uint16_t preamble_energy_list[64],preamble_delay_list[64];
  uint16_t preamble_max,preamble_energy_max;
  uint16_t i;
  int8_t UE_id;
Raymond Knopp's avatar
 
Raymond Knopp committed
2284
  int subframe = phy_vars_eNB->proc[sched_subframe].subframe_rx;
Raymond Knopp's avatar
 
Raymond Knopp committed
2285
  int frame = phy_vars_eNB->proc[sched_subframe].frame_rx;
Raymond Knopp's avatar
 
Raymond Knopp committed
2286
  uint8_t CC_id = phy_vars_eNB->CC_id;
2287

2288 2289
  memset(&preamble_energy_list[0],0,64*sizeof(uint16_t));
  memset(&preamble_delay_list[0],0,64*sizeof(uint16_t));
2290

2291
  if (abstraction_flag == 0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
2292
    LOG_D(PHY,"[eNB %d][RAPROC] Frame %d, Subframe %d : PRACH RX Signal Power : %d dBm\n",phy_vars_eNB->Mod_id, 
2293 2294
          frame,subframe,dB_fixed(signal_energy(&phy_vars_eNB->lte_eNB_common_vars.rxdata[0][0][subframe*phy_vars_eNB->lte_frame_parms.samples_per_tti],512)) - phy_vars_eNB->rx_total_gain_eNB_dB);

2295
    //    LOG_I(PHY,"[eNB %d][RAPROC] PRACH: rootSequenceIndex %d, prach_ConfigIndex %d, zeroCorrelationZoneConfig %d, highSpeedFlag %d, prach_FreqOffset %d\n",phy_vars_eNB->Mod_id,phy_vars_eNB->lte_frame_parms.prach_config_common.rootSequenceIndex,phy_vars_eNB->lte_frame_parms.prach_config_common.prach_ConfigInfo.prach_ConfigIndex, phy_vars_eNB->lte_frame_parms.prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig,phy_vars_eNB->lte_frame_parms.prach_config_common.prach_ConfigInfo.highSpeedFlag,phy_vars_eNB->lte_frame_parms.prach_config_common.prach_ConfigInfo.prach_FreqOffset);
2296

2297
    rx_prach(phy_vars_eNB,
2298 2299 2300 2301 2302 2303 2304 2305
             subframe,
             preamble_energy_list,
             preamble_delay_list,
             frame,
             0);
  } else {
    for (UE_id=0; UE_id<NB_UE_INST; UE_id++) {

2306
      LOG_D(PHY,"[RAPROC] UE_id %d (%p), generate_prach %d, UE RSI %d, eNB RSI %d preamble index %d\n",
2307 2308 2309 2310 2311
            UE_id,PHY_vars_UE_g[UE_id][CC_id],PHY_vars_UE_g[UE_id][CC_id]->generate_prach,
            PHY_vars_UE_g[UE_id][CC_id]->lte_frame_parms.prach_config_common.rootSequenceIndex,
            phy_vars_eNB->lte_frame_parms.prach_config_common.rootSequenceIndex,
            PHY_vars_UE_g[UE_id][CC_id]->prach_PreambleIndex);

Raymond Knopp's avatar
 
Raymond Knopp committed
2312
      if ((PHY_vars_UE_g[UE_id][CC_id]->generate_prach==1) &&
2313 2314 2315 2316 2317
          (PHY_vars_UE_g[UE_id][CC_id]->lte_frame_parms.prach_config_common.rootSequenceIndex ==
           phy_vars_eNB->lte_frame_parms.prach_config_common.rootSequenceIndex) ) {
        preamble_energy_list[PHY_vars_UE_g[UE_id][CC_id]->prach_PreambleIndex] = 800;
        preamble_delay_list[PHY_vars_UE_g[UE_id][CC_id]->prach_PreambleIndex] = 5;

2318
      }
2319
    }
2320
  }
2321

2322 2323 2324
  preamble_energy_max = preamble_energy_list[0];
  preamble_max = 0;

2325
  for (i=1; i<64; i++) {
2326 2327 2328 2329
    if (preamble_energy_max < preamble_energy_list[i]) {
      preamble_energy_max = preamble_energy_list[i];
      preamble_max = i;
    }
2330 2331 2332
  }

#ifdef DEBUG_PHY_PROC
2333
  LOG_D(PHY,"[RAPROC] Most likely preamble %d, energy %d dB delay %d\n",
2334 2335 2336
        preamble_max,
        preamble_energy_list[preamble_max],
        preamble_delay_list[preamble_max]);
2337 2338
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
2339
  if (preamble_energy_list[preamble_max] > 580) {
Raymond Knopp's avatar
 
Raymond Knopp committed
2340 2341 2342 2343 2344 2345 2346 2347
    /*
    write_output("prach_ifft0.m","prach_t0",prach_ifft[0],2048,1,1);
    write_output("prach_rx0.m","prach_rx0",&phy_vars_eNB->lte_eNB_common_vars.rxdata[0][0][subframe*phy_vars_eNB->lte_frame_parms.samples_per_tti],6144+792,1,1);
    write_output("prach_rxF0.m","prach_rxF0",phy_vars_eNB->lte_eNB_prach_vars.rxsigF[0],24576,1,1);

    mac_xface->macphy_exit("Exiting for PRACH debug\n");
    */

2348
    UE_id = find_next_ue_index(phy_vars_eNB);
2349

2350
    if (UE_id>=0) {
2351 2352 2353
      phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].UE_timing_offset = preamble_delay_list[preamble_max]&0x1FFF; //limit to 13 (=11+2) bits
      //phy_vars_eNb->eNB_UE_stats[(uint32_t)UE_id].mode = PRACH;
      phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].sector = 0;
2354
      LOG_I(PHY,"[eNB %d/%d][RAPROC] Frame %d, subframe %d Initiating RA procedure (UE_id %d) with preamble %d, energy %d.%d dB, delay %d\n",
2355
            phy_vars_eNB->Mod_id,
2356
            phy_vars_eNB->CC_id,
2357 2358
            frame,
            subframe,
2359
	    UE_id,
2360 2361 2362 2363
            preamble_max,
            preamble_energy_max/10,
            preamble_energy_max%10,
            preamble_delay_list[preamble_max]);
2364 2365

      if (phy_vars_eNB->mac_enabled==1) {
2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385
        uint8_t update_TA=4;

        switch (phy_vars_eNB->lte_frame_parms.N_RB_DL) {
        case 6:
          update_TA = 16;
          break;

        case 25:
          update_TA = 4;
          break;

        case 50:
          update_TA = 2;
          break;

        case 100:
          update_TA = 1;
          break;
        }

2386
      mac_xface->initiate_ra_proc(phy_vars_eNB->Mod_id,
2387 2388 2389
                                  phy_vars_eNB->CC_id,
                                  frame,
                                  preamble_max,
2390
                                  preamble_delay_list[preamble_max]*update_TA,
Raymond Knopp's avatar
 
Raymond Knopp committed
2391
				  0,subframe,0);
2392 2393
      }      

2394
    } else {
2395
      MSC_LOG_EVENT(MSC_PHY_ENB, "0 RA Failed add user, too many");
2396 2397
      LOG_I(PHY,"[eNB %d][RAPROC] frame %d, subframe %d: Unable to add user, max user count reached\n",
            phy_vars_eNB->Mod_id,frame, subframe);
2398
    }
2399 2400 2401
  }
}

Raymond Knopp's avatar
 
Raymond Knopp committed
2402
void ulsch_decoding_procedures(unsigned char subframe, unsigned int i, PHY_VARS_eNB *phy_vars_eNB, unsigned char abstraction_flag)
2403
{
2404 2405 2406 2407
  UNUSED(subframe);
  UNUSED(i);
  UNUSED(phy_vars_eNB);
  UNUSED(abstraction_flag);
2408 2409 2410 2411
  LOG_D(PHY,"ulsch_decoding_procedures not yet implemented. should not be called");
}


Raymond Knopp's avatar
 
Raymond Knopp committed
2412

Lionel Gauthier's avatar
Lionel Gauthier committed
2413
void phy_procedures_eNB_RX(const unsigned char sched_subframe,PHY_VARS_eNB *phy_vars_eNB,const uint8_t abstraction_flag,const relaying_type_t r_type)
2414
{
2415
  //RX processing
2416
  UNUSED(r_type);
2417
  uint32_t l, ret=0,i,j,k;
2418
  uint32_t sect_id=0;
2419
  uint32_t harq_pid, harq_idx, round;
2420
  uint8_t SR_payload = 0,*pucch_payload=NULL,pucch_payload0[2]= {0,0},pucch_payload1[2]= {0,0};
2421 2422 2423
  int16_t n1_pucch0,n1_pucch1,n1_pucch2,n1_pucch3;
  uint8_t do_SR = 0;
  uint8_t pucch_sel = 0;
2424
  int32_t metric0=0,metric1=0,metric0_SR=0;
2425 2426
  ANFBmode_t bundling_flag;
  PUCCH_FMT_t format;
2427 2428 2429
  uint8_t nPRS;
  //  uint8_t two_ues_connected = 0;
  uint8_t pusch_active = 0;
2430 2431
  LTE_DL_FRAME_PARMS *frame_parms=&phy_vars_eNB->lte_frame_parms;
  int sync_pos;
2432 2433
  uint16_t rnti=0;
  uint8_t access_mode;
2434
  int num_active_cba_groups;
Lionel Gauthier's avatar
Lionel Gauthier committed
2435 2436 2437 2438
  const int subframe = phy_vars_eNB->proc[sched_subframe].subframe_rx;
  const int frame = phy_vars_eNB->proc[sched_subframe].frame_rx;

  AssertFatal(sched_subframe < NUM_ENB_THREADS, "Bad sched_subframe %d", sched_subframe);
2439

2440
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_RX,1);
2441
  start_meas(&phy_vars_eNB->phy_proc_rx);
2442
#ifdef DEBUG_PHY_PROC
Raymond Knopp's avatar
 
Raymond Knopp committed
2443
  LOG_D(PHY,"[eNB %d] Frame %d: Doing phy_procedures_eNB_RX(%d)\n",phy_vars_eNB->Mod_id,frame, subframe);
2444
#endif
2445

2446
  /*
Raymond Knopp's avatar
 
Raymond Knopp committed
2447 2448 2449 2450 2451
#ifdef OAI_USRP
  for (aa=0;aa<phy_vars_eNB->lte_frame_parms.nb_antennas_rx;aa++)
    rescale(&phy_vars_eNB->lte_eNB_common_vars.rxdata[0][aa][subframe*phy_vars_eNB->lte_frame_parms.samples_per_tti],
	    phy_vars_eNB->lte_frame_parms.samples_per_tti);
#endif
2452
  */
2453 2454 2455 2456 2457
  phy_vars_eNB->rb_mask_ul[0]=0;
  phy_vars_eNB->rb_mask_ul[1]=0;
  phy_vars_eNB->rb_mask_ul[2]=0;
  phy_vars_eNB->rb_mask_ul[3]=0;

2458
  if (abstraction_flag == 0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
2459 2460
    remove_7_5_kHz(phy_vars_eNB,subframe<<1);
    remove_7_5_kHz(phy_vars_eNB,(subframe<<1)+1);
2461
  }
2462

2463
  // check if we have to detect PRACH first
Raymond Knopp's avatar
 
Raymond Knopp committed
2464
  if (is_prach_subframe(&phy_vars_eNB->lte_frame_parms,frame,subframe)>0) {
2465
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PRACH_RX,1);
Raymond Knopp's avatar
 
Raymond Knopp committed
2466
    prach_procedures(phy_vars_eNB,sched_subframe,abstraction_flag);
2467
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PRACH_RX,0);
2468
  }
2469

2470
  if (abstraction_flag == 0) {
2471 2472 2473 2474
    start_meas(&phy_vars_eNB->ofdm_demod_stats);

    for (l=0; l<phy_vars_eNB->lte_frame_parms.symbols_per_tti/2; l++) {

Raymond Knopp's avatar
 
Raymond Knopp committed
2475 2476
      //      for (sect_id=0;sect_id<number_of_cards;sect_id++) {
      slot_fep_ul(&phy_vars_eNB->lte_frame_parms,
2477 2478 2479 2480 2481 2482
                  &phy_vars_eNB->lte_eNB_common_vars,
                  l,
                  subframe<<1,
                  0,
                  0
                 );
Raymond Knopp's avatar
 
Raymond Knopp committed
2483
      slot_fep_ul(&phy_vars_eNB->lte_frame_parms,
2484 2485 2486 2487 2488 2489
                  &phy_vars_eNB->lte_eNB_common_vars,
                  l,
                  (subframe<<1)+1,
                  0,
                  0
                 );
2490
    }
2491 2492

    stop_meas(&phy_vars_eNB->ofdm_demod_stats);
2493
  }
2494

2495 2496 2497 2498
  sect_id = 0;

  /*
    for (UE_id=0;UE_id<NUMBER_OF_UE_MAX;UE_id++) {
2499

2500
    if ((phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].mode>PRACH) && (last_slot%2==1)) {
2501
    #ifdef DEBUG_PHY_PROC
2502 2503
    LOG_D(PHY,"[eNB %d] frame %d, slot %d: Doing SRS estimation and measurements for UE_id %d (UE_mode %d)\n",
    phy_vars_eNB->Mod_id,
2504
    phy_vars_eNB->proc[sched_subframe].frame_tx, last_slot,
2505
    UE_id,phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].mode);
2506 2507
    #endif
    for (sect_id=0;sect_id<number_of_cards;sect_id++) {
2508

2509 2510
    lte_srs_channel_estimation(&phy_vars_eNB->lte_frame_parms,
    &phy_vars_eNB->lte_eNB_common_vars,
2511 2512
    &phy_vars_eNB->lte_eNB_srs_vars[(uint32_t)UE_id],
    &phy_vars_eNB->soundingrs_ul_config_dedicated[(uint32_t)UE_id],
2513 2514 2515 2516 2517 2518 2519 2520 2521
    last_slot>>1,
    sect_id);
    lte_eNB_srs_measurements(phy_vars_eNB,
    sect_id,
    UE_id,
    1);
    #ifdef DEBUG_PHY_PROC
    LOG_D(PHY,"[eNB %d] frame %d, slot %d: UE_id %d, sect_id %d: RX RSSI %d (from SRS)\n",
    phy_vars_eNB->Mod_id,
2522
    phy_vars_eNB->proc[sched_subframe].frame_tx, last_slot,
2523
    UE_id,sect_id,
2524
    phy_vars_eNB->PHY_measurements_eNB[sect_id].rx_rssi_dBm[(uint32_t)UE_id]);
2525 2526
    #endif
    }
2527

2528 2529 2530 2531 2532
    sect_id=0;
    #ifdef USER_MODE
    //write_output("srs_est0.m","srsest0",phy_vars_eNB->lte_eNB_common_vars.srs_ch_estimates[0][0],512,1,1);
    //write_output("srs_est1.m","srsest1",phy_vars_eNB->lte_eNB_common_vars.srs_ch_estimates[0][1],512,1,1);
    #endif
2533

2534 2535
    //msg("timing advance in\n");
    sync_pos = lte_est_timing_advance(&phy_vars_eNB->lte_frame_parms,
2536
    &phy_vars_eNB->lte_eNB_srs_vars[(uint32_t)UE_id],
2537
    &sect_id,
2538
    phy_vars_eNB->first_run_timing_advance[(uint32_t)UE_id],
2539 2540
    number_of_cards,
    24576);
2541

2542
    //msg("timing advance out\n");
2543

2544 2545 2546
    //phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].UE_timing_offset = sync_pos - phy_vars_eNB->lte_frame_parms.nb_prefix_samples/8;
    phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].UE_timing_offset = 0;
    phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].sector = sect_id;
2547
    #ifdef DEBUG_PHY_PROC
2548 2549
    LOG_D(PHY,"[eNB %d] frame %d, slot %d: user %d in sector %d: timing_advance = %d\n",
    phy_vars_eNB->Mod_id,
2550
    phy_vars_eNB->proc[sched_subframe].frame_tx, last_slot,
2551
    UE_id, sect_id,
2552
    phy_vars_eNB->eNB_UE_stats[(uint32_t)UE_id].UE_timing_offset);
2553 2554 2555 2556
    #endif
    }
    }
    else {
2557

2558
    }
2559
  */
Raymond Knopp's avatar
 
Raymond Knopp committed
2560

2561 2562
  // Check for active processes in current subframe
  harq_pid = subframe2harq_pid(&phy_vars_eNB->lte_frame_parms,
2563
                               frame,subframe);
2564
  pusch_active = 0;
2565 2566 2567

  // reset the cba flag used for collision detection
  for (i=0; i < NUM_MAX_CBA_GROUP; i++) {
2568
    phy_vars_eNB->cba_last_reception[i]=0;
2569
  }
2570

Raymond Knopp's avatar
Raymond Knopp committed
2571
  //  LOG_I(PHY,"subframe %d: nPRS %d\n",last_slot>>1,phy_vars_eNB->lte_frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.nPRS[last_slot-1]);
2572 2573 2574

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

2575
    /*
2576 2577
      if ((i == 1) && (phy_vars_eNB->cooperation_flag > 0) && (two_ues_connected == 1))
      break;
2578
    */
2579

2580 2581 2582 2583 2584 2585
    if (phy_vars_eNB->mac_enabled==1) {
      if (phy_vars_eNB->eNB_UE_stats[i].mode == RA_RESPONSE) {
	process_Msg3(phy_vars_eNB,sched_subframe,i,harq_pid);
      }
    }

2586

Raymond Knopp's avatar
 
Raymond Knopp committed
2587
    /*
2588
    #ifdef DEBUG_PHY_PROC
Raymond Knopp's avatar
Raymond Knopp committed
2589
    if (phy_vars_eNB->ulsch_eNB[i]) {
2590

Raymond Knopp's avatar
 
Raymond Knopp committed
2591
      LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d, subframe %d rnti %x, alloc %d, Msg3 %d\n",phy_vars_eNB->Mod_id,
2592 2593 2594 2595 2596
      harq_pid,frame,subframe,
      (phy_vars_eNB->ulsch_eNB[i]->rnti),
      (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->subframe_scheduling_flag),
      (phy_vars_eNB->ulsch_eNB[i]->Msg3_flag)
      );
Raymond Knopp's avatar
Raymond Knopp committed
2597
    }
2598
    #endif
Raymond Knopp's avatar
 
Raymond Knopp committed
2599 2600
    */

2601
    if ((phy_vars_eNB->ulsch_eNB[i]) &&
2602 2603 2604
        (phy_vars_eNB->ulsch_eNB[i]->rnti>0) &&
        (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->subframe_scheduling_flag==1)) {

2605 2606
      pusch_active = 1;
      round = phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round;
2607

2608 2609 2610 2611 2612 2613
      for (int rb=0;
           rb<=phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->nb_rb;
	   rb++) {
	int rb2 = rb+phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->first_rb;
	phy_vars_eNB->rb_mask_ul[rb2>>5] |= (1<<(rb2&31));
      }
2614
#ifdef DEBUG_PHY_PROC
2615
      LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d Scheduling PUSCH/ULSCH Reception for rnti %x (UE_id %d)\n",
2616
            phy_vars_eNB->Mod_id,harq_pid,
2617
            frame,subframe,phy_vars_eNB->ulsch_eNB[i]->rnti,i);
2618
#endif
2619

2620
#ifdef DEBUG_PHY_PROC
2621 2622 2623 2624 2625 2626 2627

      if (phy_vars_eNB->ulsch_eNB[i]->Msg3_flag == 1) {
        LOG_D(PHY,"[eNB %d] frame %d, subframe %d: Scheduling ULSCH Reception for Msg3 in Sector %d\n",
              phy_vars_eNB->Mod_id,
              frame,
              subframe,
              phy_vars_eNB->eNB_UE_stats[i].sector);
2628
      } else {
2629 2630 2631 2632 2633 2634 2635
        LOG_D(PHY,"[eNB %d] frame %d, subframe %d: Scheduling ULSCH Reception for UE %d Mode %s sect_id %d\n",
              phy_vars_eNB->Mod_id,
              frame,
              subframe,
              i,
              mode_string[phy_vars_eNB->eNB_UE_stats[i].mode],
              phy_vars_eNB->eNB_UE_stats[i].sector);
2636
      }
2637

2638 2639
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
2640
      nPRS = phy_vars_eNB->lte_frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.nPRS[subframe<<1];
2641

2642 2643
      phy_vars_eNB->ulsch_eNB[i]->cyclicShift = (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->n_DMRS2 + phy_vars_eNB->lte_frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift +
          nPRS)%12;
2644

Raymond Knopp's avatar
 
Raymond Knopp committed
2645
      if (frame_parms->frame_type == FDD ) {
2646 2647 2648 2649 2650 2651 2652
        int sf = (subframe<4) ? (subframe+6) : (subframe-4);

        if (phy_vars_eNB->dlsch_eNB[i][0]->subframe_tx[sf]>0) { // we have downlink transmission
          phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->O_ACK = 1;
        } else {
          phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->O_ACK = 0;
        }
2653
      }
Raymond Knopp's avatar
Raymond Knopp committed
2654

2655
      //#ifdef DEBUG_PHY_PROC
2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671
      LOG_D(PHY,
            "[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",
            phy_vars_eNB->Mod_id,harq_pid,frame,subframe,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->dci_alloc,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->rar_alloc,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->first_rb,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->nb_rb,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->mcs,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->rvidx,
            phy_vars_eNB->ulsch_eNB[i]->cyclicShift,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->n_DMRS2,
            phy_vars_eNB->lte_frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift,
            nPRS,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->O_ACK);
2672
      //#endif
2673 2674
      start_meas(&phy_vars_eNB->ulsch_demodulation_stats);

2675
      if (abstraction_flag==0) {
2676 2677 2678 2679 2680 2681
        rx_ulsch(phy_vars_eNB,
                 sched_subframe,
                 phy_vars_eNB->eNB_UE_stats[i].sector,  // this is the effective sector id
                 i,
                 phy_vars_eNB->ulsch_eNB,
                 0);
2682
      }
2683

2684
#ifdef PHY_ABSTRACTION
2685
      else {
2686 2687 2688 2689
        rx_ulsch_emul(phy_vars_eNB,
                      subframe,
                      phy_vars_eNB->eNB_UE_stats[i].sector,  // this is the effective sector id
                      i);
2690
      }
2691

2692
#endif
2693
      stop_meas(&phy_vars_eNB->ulsch_demodulation_stats);
2694 2695


2696
      start_meas(&phy_vars_eNB->ulsch_decoding_stats);
2697

2698
      if (abstraction_flag == 0) {
2699 2700 2701 2702 2703 2704
        ret = ulsch_decoding(phy_vars_eNB,
                             i,
                             sched_subframe,
                             0, // control_only_flag
                             phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->V_UL_DAI,
                             0);
2705
      }
2706

2707
#ifdef PHY_ABSTRACTION
2708
      else {
2709 2710 2711 2712
        ret = ulsch_decoding_emul(phy_vars_eNB,
                                  sched_subframe,
                                  i,
                                  &rnti);
2713
      }
2714

2715
#endif
2716
      stop_meas(&phy_vars_eNB->ulsch_decoding_stats);
2717

2718
      //#ifdef DEBUG_PHY_PROC
Raymond Knopp's avatar
 
Raymond Knopp committed
2719
      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",
2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731
            phy_vars_eNB->Mod_id,harq_pid,
            frame,subframe,
            phy_vars_eNB->ulsch_eNB[i]->rnti,
            dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power[0]),
            dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power[1]),
            phy_vars_eNB->eNB_UE_stats[i].UL_rssi[0],
            phy_vars_eNB->eNB_UE_stats[i].UL_rssi[1],
            phy_vars_eNB->PHY_measurements_eNB->n0_power_dB[0],
            phy_vars_eNB->PHY_measurements_eNB->n0_power_dB[1],
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_ACK[0],
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_ACK[1],
            ret);
2732
      //#endif //DEBUG_PHY_PROC
2733
      /*
2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750
      if ((two_ues_connected==1) && (phy_vars_eNB->cooperation_flag==2)) {
      for (j=0;j<phy_vars_eNB->lte_frame_parms.nb_antennas_rx;j++) {
      phy_vars_eNB->eNB_UE_stats[i].UL_rssi[j] = dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power_0[j])
      - phy_vars_eNB->rx_total_gain_eNB_dB;
      phy_vars_eNB->eNB_UE_stats[i+1].UL_rssi[j] = dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power_1[j])
      - phy_vars_eNB->rx_total_gain_eNB_dB;
      }
      #ifdef DEBUG_PHY_PROC
      LOG_D(PHY,"[eNB %d] Frame %d subframe %d: ULSCH %d RX power UE0 (%d,%d) dB RX power UE1 (%d,%d)\n",
      phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx,last_slot>>1,i,
      dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power_0[0]),
      dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power_0[1]),
      dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power_1[0]),
      dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power_1[1]));
      #endif
      }
      else {
2751
      */
2752

2753 2754
      //compute the expected ULSCH RX power (for the stats)
      phy_vars_eNB->ulsch_eNB[(uint32_t)i]->harq_processes[harq_pid]->delta_TF =
2755
        get_hundred_times_delta_IF_eNB(phy_vars_eNB,i,harq_pid, 0); // 0 means bw_factor is not considered
2756

2757
      //dump_ulsch(phy_vars_eNB, sched_subframe, i);
2758

2759
      phy_vars_eNB->eNB_UE_stats[i].ulsch_decoding_attempts[harq_pid][phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round]++;
2760
#ifdef DEBUG_PHY_PROC
Raymond Knopp's avatar
 
Raymond Knopp committed
2761
      LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d UE %d harq_pid %d Clearing subframe_scheduling_flag\n",
2762
            phy_vars_eNB->Mod_id,harq_pid,frame,subframe,i,harq_pid);
2763
#endif
2764
      phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->subframe_scheduling_flag=0;
2765

Raymond Knopp's avatar
 
Raymond Knopp committed
2766
      if (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->cqi_crc_status == 1) {
2767
#ifdef DEBUG_PHY_PROC
2768 2769
        //if (((phy_vars_eNB->proc[sched_subframe].frame_tx%10) == 0) || (phy_vars_eNB->proc[sched_subframe].frame_tx < 50))
        print_CQI(phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o,phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->uci_format,0,phy_vars_eNB->lte_frame_parms.N_RB_DL);
2770
#endif
2771 2772 2773 2774 2775 2776
        extract_CQI(phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o,
                    phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->uci_format,
                    &phy_vars_eNB->eNB_UE_stats[i],
                    phy_vars_eNB->lte_frame_parms.N_RB_DL,
                    &rnti, &access_mode);
        phy_vars_eNB->eNB_UE_stats[i].rank = phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_RI[0];
2777
      }
2778

2779
      if (ret == (1+MAX_TURBO_ITERATIONS)) {
2780

2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795
        /*
        if (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round>0) {
          dump_ulsch(phy_vars_eNB, sched_subframe, i);
          mac_xface->macphy_exit("retransmission in error");
        }
        */

        phy_vars_eNB->eNB_UE_stats[i].ulsch_round_errors[harq_pid][phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round]++;
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->phich_active = 1;
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->phich_ACK = 0;
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round++;

        LOG_D(PHY,"[eNB][PUSCH %d] Increasing to round %d\n",harq_pid,phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round);

        if (phy_vars_eNB->ulsch_eNB[i]->Msg3_flag == 1) {
2796
          LOG_I(PHY,"[eNB %d/%d][RAPROC] frame %d, subframe %d, UE %d: Error receiving ULSCH (Msg3), round %d/%d\n",
2797
                phy_vars_eNB->Mod_id,
2798
                phy_vars_eNB->CC_id,
2799 2800 2801 2802
                frame,subframe, i,
                phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round-1,
                phy_vars_eNB->lte_frame_parms.maxHARQ_Msg3Tx-1);

2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816
	  LOG_I(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",
		phy_vars_eNB->Mod_id,harq_pid,
		frame,subframe,
		phy_vars_eNB->ulsch_eNB[i]->rnti,
		dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power[0]),
		dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power[1]),
		phy_vars_eNB->eNB_UE_stats[i].UL_rssi[0],
		phy_vars_eNB->eNB_UE_stats[i].UL_rssi[1],
		phy_vars_eNB->PHY_measurements_eNB->n0_power_dB[0],
		phy_vars_eNB->PHY_measurements_eNB->n0_power_dB[1],
		phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_ACK[0],
		phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_ACK[1],
		ret);

2817 2818 2819 2820 2821
          if (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round ==
              phy_vars_eNB->lte_frame_parms.maxHARQ_Msg3Tx) {
            LOG_I(PHY,"[eNB %d][RAPROC] maxHARQ_Msg3Tx reached, abandoning RA procedure for UE %d\n",
                  phy_vars_eNB->Mod_id, i);
            phy_vars_eNB->eNB_UE_stats[i].mode = PRACH;
2822 2823 2824 2825 2826 2827
	    if (phy_vars_eNB->mac_enabled==1) {
	      mac_xface->cancel_ra_proc(phy_vars_eNB->Mod_id,
					phy_vars_eNB->CC_id,
					frame,
					phy_vars_eNB->eNB_UE_stats[i].crnti);
	    }
2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850
            remove_ue(phy_vars_eNB->eNB_UE_stats[i].crnti,phy_vars_eNB,abstraction_flag);
            phy_vars_eNB->ulsch_eNB[(uint32_t)i]->Msg3_active = 0;
            //phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->phich_active = 0;

          } else {
            // activate retransmission for Msg3 (signalled to UE PHY by PHICH (not MAC/DCI)
            phy_vars_eNB->ulsch_eNB[(uint32_t)i]->Msg3_active = 1;

            get_Msg3_alloc_ret(&phy_vars_eNB->lte_frame_parms,
                               subframe,
                               frame,
                               &phy_vars_eNB->ulsch_eNB[i]->Msg3_frame,
                               &phy_vars_eNB->ulsch_eNB[i]->Msg3_subframe);
          }/*

    LOG_D(PHY,"[eNB] Frame %d, Subframe %d : ULSCH SDU (RX harq_pid %d) %d bytes:",frame,subframe,
    harq_pid,phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3);
    for (j=0;j<phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3;j++)
      printf("%x.",phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->c[0][j]);
    printf("\n");
     */
          //    dump_ulsch(phy_vars_eNB,sched_subframe,i);
          //#ifndef EXMIMO_IOT
2851
          LOG_W(PHY,"[eNB] Frame %d, Subframe %d: Msg3 in error, i = %d \n", frame,subframe,i);
2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864
          //#else
          //mac_exit_wrapper("Msg3 error");
          //#endif
        } // This is Msg3 error
        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",
                phy_vars_eNB->Mod_id,harq_pid,
                frame,subframe, i,
                phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round-1,
                phy_vars_eNB->ulsch_eNB[i]->Mdlharq,
                phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_ACK[0],
                phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_ACK[1]);

Lionel Gauthier's avatar
Lionel Gauthier committed
2865 2866 2867 2868 2869 2870 2871 2872 2873 2874
#if defined(MESSAGE_CHART_GENERATOR_PHY)
          MSC_LOG_RX_DISCARDED_MESSAGE(
            MSC_PHY_ENB,MSC_PHY_UE,
            NULL,0,
            "%05u:%02u ULSCH received rnti %x harq id %u round %d",
            frame,subframe,
            phy_vars_eNB->ulsch_eNB[i]->rnti,harq_pid,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round-1
            );
#endif
2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901
          /*
          LOG_T(PHY,"[eNB] Frame %d, Subframe %d : ULSCH SDU (RX harq_pid %d) %d bytes:\n",frame,subframe,
          harq_pid,phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3);
          if (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->c[0]!=NULL){
            for (j=0;j<phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3;j++)
              LOG_T(PHY,"%x.",phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->c[0][j]);
            LOG_T(PHY,"\n");
          }
          */


          //    dump_ulsch(phy_vars_eNB,sched_subframe,i);
          //mac_exit_wrapper("ULSCH error");

          if (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round== phy_vars_eNB->ulsch_eNB[i]->Mdlharq) {
            LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d UE %d ULSCH Mdlharq %d reached\n",
                  phy_vars_eNB->Mod_id,harq_pid,
                  frame,subframe, i,
                  phy_vars_eNB->ulsch_eNB[i]->Mdlharq);

            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round=0;
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->phich_active=0;
            phy_vars_eNB->eNB_UE_stats[i].ulsch_errors[harq_pid]++;
            phy_vars_eNB->eNB_UE_stats[i].ulsch_consecutive_errors++;
            //dump_ulsch(phy_vars_eNB, sched_subframe, i);
          }
        }
2902 2903
      }  // ulsch in error
      else {
2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921
        if (phy_vars_eNB->ulsch_eNB[i]->Msg3_flag == 1) {
	  LOG_I(PHY,"[eNB %d][PUSCH %d] Frame %d subframe %d ULSCH received, setting round to 0, PHICH ACK\n",
		phy_vars_eNB->Mod_id,harq_pid,
		frame,subframe);
	  LOG_I(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",
		phy_vars_eNB->Mod_id,harq_pid,
		frame,subframe,
		phy_vars_eNB->ulsch_eNB[i]->rnti,
		dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power[0]),
		dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power[1]),
		phy_vars_eNB->eNB_UE_stats[i].UL_rssi[0],
		phy_vars_eNB->eNB_UE_stats[i].UL_rssi[1],
		phy_vars_eNB->PHY_measurements_eNB->n0_power_dB[0],
		phy_vars_eNB->PHY_measurements_eNB->n0_power_dB[1],
		phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_ACK[0],
		phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_ACK[1],
		ret);
	}
Lionel Gauthier's avatar
Lionel Gauthier committed
2922 2923 2924 2925 2926 2927 2928 2929 2930
#if defined(MESSAGE_CHART_GENERATOR_PHY)
        MSC_LOG_RX_MESSAGE(
          MSC_PHY_ENB,MSC_PHY_UE,
          NULL,0,
          "%05u:%02u ULSCH received rnti %x harq id %u",
          frame,subframe,
          phy_vars_eNB->ulsch_eNB[i]->rnti,harq_pid
          );
#endif
2931 2932 2933
        for (j=0; j<phy_vars_eNB->lte_frame_parms.nb_antennas_rx; j++)
          //this is the RSSI per RB
          phy_vars_eNB->eNB_UE_stats[i].UL_rssi[j] =
2934
	    
2935 2936 2937 2938 2939 2940
            dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power[j]*
                     (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->nb_rb*12)/
                     phy_vars_eNB->lte_frame_parms.ofdm_symbol_size) -
            phy_vars_eNB->rx_total_gain_eNB_dB -
            hundred_times_log10_NPRB[phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->nb_rb-1]/100 -
            get_hundred_times_delta_IF_eNB(phy_vars_eNB,i,harq_pid, 0)/100;
2941 2942 2943 2944 2945 2946
	    
	    /*
            dB_fixed(phy_vars_eNB->lte_eNB_pusch_vars[i]->ulsch_power[j]*phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->nb_rb) -
            phy_vars_eNB->rx_total_gain_eNB_dB -
            hundred_times_log10_NPRB[phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->nb_rb-1]/100 -
            get_hundred_times_delta_IF_eNB(phy_vars_eNB,i,harq_pid, 0)/100;*/
2947 2948 2949 2950 2951 2952
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->phich_active = 1;
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->phich_ACK = 1;
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round = 0;
        phy_vars_eNB->eNB_UE_stats[i].ulsch_consecutive_errors = 0;

        if (phy_vars_eNB->ulsch_eNB[i]->Msg3_flag == 1) {
2953
	  if (phy_vars_eNB->mac_enabled==1) {
2954
	  //#ifdef DEBUG_PHY_PROC
2955 2956 2957
          LOG_I(PHY,"[eNB %d][RAPROC] Frame %d Terminating ra_proc for harq %d, UE %d\n",
                phy_vars_eNB->Mod_id,
                frame,harq_pid,i);
2958
	  //#endif
2959 2960
          mac_xface->rx_sdu(phy_vars_eNB->Mod_id,
                            phy_vars_eNB->CC_id,
2961
                            frame,subframe,
2962 2963 2964 2965 2966 2967
                            phy_vars_eNB->ulsch_eNB[i]->rnti,
                            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->b,
                            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3,
                            harq_pid,
                            &phy_vars_eNB->ulsch_eNB[i]->Msg3_flag);

2968
          // one-shot msg3 detection by MAC: empty PDU (e.g. CRNTI)
2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985
          if (phy_vars_eNB->ulsch_eNB[i]->Msg3_flag == 0 ) {
            phy_vars_eNB->eNB_UE_stats[i].mode = PRACH;
            mac_xface->cancel_ra_proc(phy_vars_eNB->Mod_id,
                                      phy_vars_eNB->CC_id,
                                      frame,
                                      phy_vars_eNB->eNB_UE_stats[i].crnti);
            remove_ue(phy_vars_eNB->eNB_UE_stats[i].crnti,phy_vars_eNB,abstraction_flag);
            phy_vars_eNB->ulsch_eNB[(uint32_t)i]->Msg3_active = 0;
          }

          /*
            mac_xface->terminate_ra_proc(phy_vars_eNB->Mod_id,
            frame,
            phy_vars_eNB->ulsch_eNB[i]->rnti,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->b,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3);
          */
2986
	  }
2987

2988 2989
          phy_vars_eNB->eNB_UE_stats[i].mode = PUSCH;
          phy_vars_eNB->ulsch_eNB[i]->Msg3_flag = 0;
2990

2991 2992 2993
	  //#ifdef DEBUG_PHY_PROC
	    LOG_D(PHY,"[eNB %d][RAPROC] Frame %d : RX Subframe %d Setting UE %d mode to PUSCH\n",phy_vars_eNB->Mod_id,frame,subframe,i);
	    //#endif //DEBUG_PHY_PROC
2994

2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020
          for (k=0; k<8; k++) { //harq_processes
            for (j=0; j<phy_vars_eNB->dlsch_eNB[i][0]->Mdlharq; j++) {
              phy_vars_eNB->eNB_UE_stats[i].dlsch_NAK[k][j]=0;
              phy_vars_eNB->eNB_UE_stats[i].dlsch_ACK[k][j]=0;
              phy_vars_eNB->eNB_UE_stats[i].dlsch_trials[k][j]=0;
            }

            phy_vars_eNB->eNB_UE_stats[i].dlsch_l2_errors[k]=0;
            phy_vars_eNB->eNB_UE_stats[i].ulsch_errors[k]=0;
            phy_vars_eNB->eNB_UE_stats[i].ulsch_consecutive_errors=0;

            for (j=0; j<phy_vars_eNB->ulsch_eNB[i]->Mdlharq; j++) {
              phy_vars_eNB->eNB_UE_stats[i].ulsch_decoding_attempts[k][j]=0;
              phy_vars_eNB->eNB_UE_stats[i].ulsch_decoding_attempts_last[k][j]=0;
              phy_vars_eNB->eNB_UE_stats[i].ulsch_round_errors[k][j]=0;
              phy_vars_eNB->eNB_UE_stats[i].ulsch_round_fer[k][j]=0;
            }
          }

          phy_vars_eNB->eNB_UE_stats[i].dlsch_sliding_cnt=0;
          phy_vars_eNB->eNB_UE_stats[i].dlsch_NAK_round0=0;
          phy_vars_eNB->eNB_UE_stats[i].dlsch_mcs_offset=0;

          //mac_xface->macphy_exit("Mode PUSCH. Exiting.\n");
        } else {

3021 3022
#ifdef DEBUG_PHY_PROC
#ifdef DEBUG_ULSCH
3023 3024 3025 3026 3027 3028 3029
          LOG_D(PHY,"[eNB] Frame %d, Subframe %d : ULSCH SDU (RX harq_pid %d) %d bytes:",frame,subframe,
                harq_pid,phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3);

          for (j=0; j<phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3; j++)
            LOG_T(PHY,"%x.",phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->b[j]);

          LOG_T(PHY,"\n");
3030 3031
#endif
#endif
3032 3033
          //dump_ulsch(phy_vars_eNB,sched_subframe,i);

3034

3035
	  if (phy_vars_eNB->mac_enabled==1) {
3036 3037 3038
          //    if (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->calibration_flag == 0) {
          mac_xface->rx_sdu(phy_vars_eNB->Mod_id,
                            phy_vars_eNB->CC_id,
3039
                            frame,subframe,
3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051
                            phy_vars_eNB->ulsch_eNB[i]->rnti,
                            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->b,
                            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3,
                            harq_pid,
                            NULL);
          //}
          /*
            else {
            // Retrieve calibration information and do whatever
            LOG_D(PHY,"[eNB][Auto-Calibration] Frame %d, Subframe %d : ULSCH PDU (RX) %d bytes\n",phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3);
            }
          */
3052 3053
#ifdef LOCALIZATION
          start_meas(&phy_vars_eNB->localization_stats);
3054 3055 3056 3057
          aggregate_eNB_UE_localization_stats(phy_vars_eNB,
                                              i,
                                              frame,
                                              subframe,
3058 3059
                                              get_hundred_times_delta_IF_eNB(phy_vars_eNB,i,harq_pid, 1)/100);
          stop_meas(&phy_vars_eNB->localization_stats);
3060
#endif
3061

3062
	  }
3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076
        }

        // estimate timing advance for MAC
        if (abstraction_flag == 0) {
          sync_pos = lte_est_timing_advance_pusch(phy_vars_eNB,i,sched_subframe);
          phy_vars_eNB->eNB_UE_stats[i].timing_advance_update = sync_pos - phy_vars_eNB->lte_frame_parms.nb_prefix_samples/4; //to check
        }

#ifdef DEBUG_PHY_PROC
        LOG_D(PHY,"[eNB %d] frame %d, subframe %d: user %d in sector %d: timing advance = %d\n",
              phy_vars_eNB->Mod_id,
              frame, subframe,
              i, sect_id,
              phy_vars_eNB->eNB_UE_stats[i].timing_advance_update);
3077
#endif
3078

3079

3080
      }  // ulsch not in error
3081

3082
      // process HARQ feedback
3083
#ifdef DEBUG_PHY_PROC
3084
      LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d, Processing HARQ feedback for UE %d (after PUSCH)\n",phy_vars_eNB->Mod_id,
3085 3086 3087
            phy_vars_eNB->dlsch_eNB[i][0]->rnti,
            frame,subframe,
            i);
3088 3089
#endif
      process_HARQ_feedback(i,
3090 3091 3092 3093 3094 3095 3096
                            sched_subframe,
                            phy_vars_eNB,
                            1, // pusch_flag
                            0,
                            0,
                            0);

Raymond Knopp's avatar
 
Raymond Knopp committed
3097
#ifdef DEBUG_PHY_PROC
3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108
      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",
            phy_vars_eNB->Mod_id,frame,subframe,
            phy_vars_eNB->eNB_UE_stats[i].sector,
            harq_pid,
            i,
            ret,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->cqi_crc_status,
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_ACK[0],
            phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_ACK[1],
            phy_vars_eNB->eNB_UE_stats[i].ulsch_errors[harq_pid],
            phy_vars_eNB->eNB_UE_stats[i].ulsch_decoding_attempts[harq_pid][0]);
Raymond Knopp's avatar
 
Raymond Knopp committed
3109
#endif
3110

Florian Kaltenberger's avatar
Florian Kaltenberger committed
3111
    }
3112

3113
#ifdef PUCCH
3114
    else if ((phy_vars_eNB->dlsch_eNB[i][0]) &&
3115
             (phy_vars_eNB->dlsch_eNB[i][0]->rnti>0)) { // check for PUCCH
3116 3117

      // check SR availability
Raymond Knopp's avatar
 
Raymond Knopp committed
3118
      do_SR = is_SR_subframe(phy_vars_eNB,i,sched_subframe);
3119
      //      do_SR = 0;
3120

3121 3122 3123
      // Now ACK/NAK
      // First check subframe_tx flag for earlier subframes
      get_n1_pucch_eNB(phy_vars_eNB,
3124 3125 3126 3127 3128 3129
                       i,
                       sched_subframe,
                       &n1_pucch0,
                       &n1_pucch1,
                       &n1_pucch2,
                       &n1_pucch3);
3130 3131

      LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d, subframe %d Checking for PUCCH (%d,%d,%d,%d) SR %d\n",
3132 3133 3134
            phy_vars_eNB->Mod_id,phy_vars_eNB->dlsch_eNB[i][0]->rnti,
            frame,subframe,
            n1_pucch0,n1_pucch1,n1_pucch2,n1_pucch3,do_SR);
3135 3136

      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
3137 3138 3139
      } else {
        // otherwise we have some PUCCH detection to do

3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167
	// Null out PUCCH PRBs for noise measurement
	switch(phy_vars_eNB->lte_frame_parms.N_RB_UL) {
	case 6:
	  phy_vars_eNB->rb_mask_ul[0] |= (0x1 | (1<<5)); //position 5
	  break;
	case 15:
	  phy_vars_eNB->rb_mask_ul[0] |= (0x1 | (1<<14)); // position 14
	  break;
	case 25:
	  phy_vars_eNB->rb_mask_ul[0] |= (0x1 | (1<<24)); // position 24
	  break;
	case 50:
	  phy_vars_eNB->rb_mask_ul[0] |= 0x1;
	  phy_vars_eNB->rb_mask_ul[1] |= (1<<17); // position 49 (49-32)
	  break;
	case 75:
	  phy_vars_eNB->rb_mask_ul[0] |= 0x1;
	  phy_vars_eNB->rb_mask_ul[2] |= (1<<10); // position 74 (74-64)
	  break;
	case 100:
	  phy_vars_eNB->rb_mask_ul[0] |= 0x1;
	  phy_vars_eNB->rb_mask_ul[3] |= (1<<3); // position 99 (99-96)
	  break;
	default:
	  LOG_E(PHY,"Unknown number for N_RB_UL %d\n",phy_vars_eNB->lte_frame_parms.N_RB_UL);
	  break;
	}

3168 3169 3170 3171
        if (do_SR == 1) {
          phy_vars_eNB->eNB_UE_stats[i].sr_total++;

          if (abstraction_flag == 0)
3172 3173 3174 3175 3176 3177 3178 3179 3180
            metric0_SR = rx_pucch(phy_vars_eNB,
				  pucch_format1,
				  i,
				  phy_vars_eNB->scheduling_request_config[i].sr_PUCCH_ResourceIndex,
				  0, // n2_pucch
				  0, // shortened format, should be use_srs flag, later
				  &SR_payload,
				  subframe,
				  PUCCH1_THRES);
3181

3182
#ifdef PHY_ABSTRACTION
3183
          else {
3184 3185 3186 3187 3188 3189
            metric0_SR = rx_pucch_emul(phy_vars_eNB,
				       i,
				       pucch_format1,
				       0,
				       &SR_payload,
				       sched_subframe);
3190 3191 3192 3193
            LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Checking SR (UE SR %d/%d)\n",phy_vars_eNB->Mod_id,
                  phy_vars_eNB->ulsch_eNB[i]->rnti,frame,subframe,SR_payload,phy_vars_eNB->scheduling_request_config[i].sr_PUCCH_ResourceIndex);
          }

3194 3195
#endif

3196 3197 3198 3199 3200 3201
          if (SR_payload == 1) {
            LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Got SR for PUSCH, transmitting to MAC\n",phy_vars_eNB->Mod_id,
                  phy_vars_eNB->ulsch_eNB[i]->rnti,frame,subframe);
            phy_vars_eNB->eNB_UE_stats[i].sr_received++;

            if (phy_vars_eNB->first_sr[i] == 1) { // this is the first request for uplink after Connection Setup, so clear HARQ process 0 use for Msg4
3202 3203 3204
              /* is this test necessary? */
              if (phy_vars_eNB->dlsch_eNB[i][0]->harq_processes[0]->status != SCH_IDLE)
                put_harq_pid_in_freelist(phy_vars_eNB->dlsch_eNB[i][0], 0);
3205 3206 3207 3208 3209 3210 3211 3212
              phy_vars_eNB->first_sr[i] = 0;
              phy_vars_eNB->dlsch_eNB[i][0]->harq_processes[0]->round=0;
              phy_vars_eNB->dlsch_eNB[i][0]->harq_processes[0]->status=SCH_IDLE;
              LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d First SR\n",
                    phy_vars_eNB->Mod_id,
                    phy_vars_eNB->ulsch_eNB[i]->rnti,frame,subframe);
            }

3213 3214 3215 3216 3217 3218
	    if (phy_vars_eNB->mac_enabled==1) {
	      mac_xface->SR_indication(phy_vars_eNB->Mod_id,
				       phy_vars_eNB->CC_id,
				       frame,
				       phy_vars_eNB->dlsch_eNB[i][0]->rnti,subframe);
	    }
3219 3220 3221 3222 3223 3224
          }
        }// do_SR==1

        if ((n1_pucch0==-1) && (n1_pucch1==-1)) { // just check for SR
        } else if (phy_vars_eNB->lte_frame_parms.frame_type==FDD) { // FDD
          // if SR was detected, use the n1_pucch from SR, else use n1_pucch0
3225
	  //          n1_pucch0 = (SR_payload==1) ? phy_vars_eNB->scheduling_request_config[i].sr_PUCCH_ResourceIndex:n1_pucch0;
3226

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

3229 3230 3231 3232
          if (abstraction_flag == 0) {



3233 3234 3235 3236 3237
            metric0 = rx_pucch(phy_vars_eNB,
                               pucch_format1a,
                               i,
                               (uint16_t)n1_pucch0,
                               0, //n2_pucch
3238
                               0, // shortened format
3239 3240 3241
                               pucch_payload0,
                               subframe,
                               PUCCH1a_THRES);
3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253

            if (metric0 < metric0_SR)
	      metric0=rx_pucch(phy_vars_eNB,
			       pucch_format1a,
			       i,
			       phy_vars_eNB->scheduling_request_config[i].sr_PUCCH_ResourceIndex,
			       0, //n2_pucch
			       0, // shortened format
			       pucch_payload0,
			       subframe,
			       PUCCH1a_THRES);
	  }
3254
          else {
3255
#ifdef PHY_ABSTRACTION
3256 3257 3258 3259 3260
            metric0 = rx_pucch_emul(phy_vars_eNB,i,
                                    pucch_format1a,
                                    0,
                                    pucch_payload0,
                                    subframe);
3261
#endif
3262 3263 3264 3265 3266 3267 3268 3269
          }

#ifdef DEBUG_PHY_PROC
          LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d pucch1a (FDD) payload %d (metric %d)\n",
                phy_vars_eNB->Mod_id,
                phy_vars_eNB->dlsch_eNB[i][0]->rnti,
                frame,subframe,
                pucch_payload0[0],metric0);
3270 3271
#endif

3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301
          process_HARQ_feedback(i,sched_subframe,phy_vars_eNB,
                                0,// pusch_flag
                                pucch_payload0,
                                2,
                                SR_payload);

        } // FDD
        else {  //TDD

          bundling_flag = phy_vars_eNB->pucch_config_dedicated[i].tdd_AckNackFeedbackMode;

          // fix later for 2 TB case and format1b

          if ((frame_parms->frame_type==FDD) ||
              (bundling_flag==bundling)    ||
              ((frame_parms->frame_type==TDD)&&(frame_parms->tdd_config==1)&&((subframe!=2)||(subframe!=7)))) {
            format = pucch_format1a;
            //      msg("PUCCH 1a\n");
          } else {
            format = pucch_format1b;
            //      msg("PUCCH 1b\n");
          }

          // if SR was detected, use the n1_pucch from SR
          if (SR_payload==1) {
#ifdef DEBUG_PHY_PROC
            LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d Checking ACK/NAK (%d,%d,%d,%d) format %d with SR\n",phy_vars_eNB->Mod_id,
                  phy_vars_eNB->dlsch_eNB[i][0]->rnti,
                  frame,subframe,
                  n1_pucch0,n1_pucch1,n1_pucch2,n1_pucch3,format);
3302
#endif
3303 3304

            if (abstraction_flag == 0)
3305 3306 3307 3308 3309 3310 3311 3312 3313
              metric0_SR = rx_pucch(phy_vars_eNB,
				    format,
				    i,
				    phy_vars_eNB->scheduling_request_config[i].sr_PUCCH_ResourceIndex,
				    0, //n2_pucch
				    0, // shortened format
				    pucch_payload0,
				    subframe,
				    PUCCH1a_THRES);
3314
            else {
3315
#ifdef PHY_ABSTRACTION
3316 3317 3318 3319 3320
              metric0 = rx_pucch_emul(phy_vars_eNB,i,
                                      format,
                                      0,
                                      pucch_payload0,
                                      subframe);
3321
#endif
3322 3323 3324 3325 3326 3327 3328
            }
          } else { //using n1_pucch0/n1_pucch1 resources
#ifdef DEBUG_PHY_PROC
            LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d Checking ACK/NAK (%d,%d,%d,%d) format %d\n",phy_vars_eNB->Mod_id,
                  phy_vars_eNB->dlsch_eNB[i][0]->rnti,
                  frame,subframe,
                  n1_pucch0,n1_pucch1,n1_pucch2,n1_pucch3,format);
3329
#endif
3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340
            metric0=0;
            metric1=0;

            // Check n1_pucch0 metric
            if (n1_pucch0 != -1) {
              if (abstraction_flag == 0)
                metric0 = rx_pucch(phy_vars_eNB,
                                   format,
                                   i,
                                   (uint16_t)n1_pucch0,
                                   0, // n2_pucch
3341
                                   0, // shortened format
3342 3343 3344 3345
                                   pucch_payload0,
                                   subframe,
                                   PUCCH1a_THRES);
              else {
3346
#ifdef PHY_ABSTRACTION
3347 3348 3349 3350 3351
                metric0 = rx_pucch_emul(phy_vars_eNB,i,
                                        format,
                                        0,
                                        pucch_payload0,
                                        subframe);
3352
#endif
3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363
              }
            }

            // Check n1_pucch1 metric
            if (n1_pucch1 != -1) {
              if (abstraction_flag == 0)
                metric1 = rx_pucch(phy_vars_eNB,
                                   format,
                                   i,
                                   (uint16_t)n1_pucch1,
                                   0, //n2_pucch
3364
                                   0, // shortened format
3365 3366 3367 3368
                                   pucch_payload1,
                                   subframe,
                                   PUCCH1a_THRES);
              else {
3369
#ifdef PHY_ABSTRACTION
3370 3371 3372 3373 3374
                metric1 = rx_pucch_emul(phy_vars_eNB,i,
                                        format,
                                        1,
                                        pucch_payload1,
                                        subframe);
3375

3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403

#endif
              }
            }
          }

          if (SR_payload == 1) {
            pucch_payload = pucch_payload0;

            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;

            pucch_sel = 2;  // indicate that this is a bundled ACK/NAK
          }

#ifdef DEBUG_PHY_PROC
          LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d ACK/NAK metric 0 %d, metric 1 %d, sel %d, (%d,%d)\n",phy_vars_eNB->Mod_id,
                phy_vars_eNB->dlsch_eNB[i][0]->rnti,
                frame,subframe,
                metric0,metric1,pucch_sel,pucch_payload[0],pucch_payload[1]);
3404
#endif
3405 3406 3407 3408 3409 3410
          process_HARQ_feedback(i,sched_subframe,phy_vars_eNB,
                                0,// pusch_flag
                                pucch_payload,
                                pucch_sel,
                                SR_payload);
        }
Lionel Gauthier's avatar
Lionel Gauthier committed
3411
      }
3412
    } // PUCCH processing
3413

3414
#endif //PUCCH
3415

3416
    if ((frame % 100 == 0) && (subframe == 4)) {
3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434
      for (harq_idx=0; harq_idx<8; harq_idx++) {
        for (round=0; round<phy_vars_eNB->ulsch_eNB[i]->Mdlharq; round++) {
          if ((phy_vars_eNB->eNB_UE_stats[i].ulsch_decoding_attempts[harq_idx][round] -
               phy_vars_eNB->eNB_UE_stats[i].ulsch_decoding_attempts_last[harq_idx][round]) != 0) {
            phy_vars_eNB->eNB_UE_stats[i].ulsch_round_fer[harq_idx][round] =
              (100*(phy_vars_eNB->eNB_UE_stats[i].ulsch_round_errors[harq_idx][round] -
                    phy_vars_eNB->eNB_UE_stats[i].ulsch_round_errors_last[harq_idx][round]))/
              (phy_vars_eNB->eNB_UE_stats[i].ulsch_decoding_attempts[harq_idx][round] -
               phy_vars_eNB->eNB_UE_stats[i].ulsch_decoding_attempts_last[harq_idx][round]);
          } else {
            phy_vars_eNB->eNB_UE_stats[i].ulsch_round_fer[harq_idx][round] = 0;
          }

          phy_vars_eNB->eNB_UE_stats[i].ulsch_decoding_attempts_last[harq_idx][round] =
            phy_vars_eNB->eNB_UE_stats[i].ulsch_decoding_attempts[harq_idx][round];
          phy_vars_eNB->eNB_UE_stats[i].ulsch_round_errors_last[harq_idx][round] =
            phy_vars_eNB->eNB_UE_stats[i].ulsch_round_errors[harq_idx][round];
        }
3435 3436
      }
    }
3437

Florian Kaltenberger's avatar
Florian Kaltenberger committed
3438
    if ((frame % 100 == 0) && (subframe==4)) {
3439 3440 3441
      phy_vars_eNB->eNB_UE_stats[i].dlsch_bitrate = (phy_vars_eNB->eNB_UE_stats[i].total_TBS -
          phy_vars_eNB->eNB_UE_stats[i].total_TBS_last);

3442 3443
      phy_vars_eNB->eNB_UE_stats[i].total_TBS_last = phy_vars_eNB->eNB_UE_stats[i].total_TBS;
    }
3444

3445
    num_active_cba_groups = phy_vars_eNB->ulsch_eNB[i]->num_active_cba_groups;
3446

3447
    /*if (num_active_cba_groups > 0 )
Raymond Knopp's avatar
 
Raymond Knopp committed
3448 3449 3450
      LOG_D(PHY,"[eNB] last slot %d trying cba transmission decoding UE %d num_grps %d rnti %x flag %d\n",
      last_slot, i, num_active_cba_groups,phy_vars_eNB->ulsch_eNB[i]->cba_rnti[i%num_active_cba_groups],
      phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->subframe_cba_scheduling_flag );
3451
    */
3452
    if ((phy_vars_eNB->ulsch_eNB[i]) &&
3453 3454 3455
        (num_active_cba_groups > 0) &&
        (phy_vars_eNB->ulsch_eNB[i]->cba_rnti[i%num_active_cba_groups]>0) &&
        (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->subframe_cba_scheduling_flag==1)) {
3456
      rnti=0;
3457 3458

#ifdef DEBUG_PHY_PROC
3459
      LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d Checking PUSCH/ULSCH CBA Reception for UE %d with cba rnti %x mode %s\n",
3460 3461 3462
            phy_vars_eNB->Mod_id,harq_pid,
            frame,subframe,
            i, (uint16_t)phy_vars_eNB->ulsch_eNB[i]->cba_rnti[i%num_active_cba_groups],mode_string[phy_vars_eNB->eNB_UE_stats[i].mode]);
3463
#endif
3464

3465
      if (abstraction_flag==0) {
3466 3467 3468 3469 3470 3471
        rx_ulsch(phy_vars_eNB,
                 sched_subframe,
                 phy_vars_eNB->eNB_UE_stats[i].sector,  // this is the effective sector id
                 i,
                 phy_vars_eNB->ulsch_eNB,
                 0);
3472
      }
3473

3474
#ifdef PHY_ABSTRACTION
3475
      else {
3476 3477 3478 3479
        rx_ulsch_emul(phy_vars_eNB,
                      subframe,
                      phy_vars_eNB->eNB_UE_stats[i].sector,  // this is the effective sector id
                      i);
3480
      }
3481

3482
#endif
3483

3484
      if (abstraction_flag == 0) {
3485 3486 3487 3488 3489 3490
        ret = ulsch_decoding(phy_vars_eNB,
                             i,
                             sched_subframe,
                             0, // control_only_flag
                             phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->V_UL_DAI,
                             0);
3491
      }
3492

3493
#ifdef PHY_ABSTRACTION
3494
      else {
3495 3496 3497 3498
        ret = ulsch_decoding_emul(phy_vars_eNB,
                                  sched_subframe,
                                  i,
                                  &rnti);
3499
      }
3500

3501
#endif
3502

Raymond Knopp's avatar
 
Raymond Knopp committed
3503
      if (phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->cqi_crc_status == 1) {
3504
#ifdef DEBUG_PHY_PROC
3505 3506
        //if (((phy_vars_eNB->proc[sched_subframe].frame_tx%10) == 0) || (phy_vars_eNB->proc[sched_subframe].frame_tx < 50))
        print_CQI(phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o,phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->uci_format,0,phy_vars_eNB->lte_frame_parms.N_RB_DL);
3507
#endif
3508 3509 3510 3511 3512 3513 3514
        access_mode = UNKNOWN_ACCESS;
        extract_CQI(phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o,
                    phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->uci_format,
                    &phy_vars_eNB->eNB_UE_stats[i],
                    phy_vars_eNB->lte_frame_parms.N_RB_DL,
                    &rnti, &access_mode);
        phy_vars_eNB->eNB_UE_stats[i].rank = phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->o_RI[0];
3515
      }
3516

Raymond Knopp's avatar
 
Raymond Knopp committed
3517
      /*  LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d UE %d harq_pid %d resetting the sched_subframeuling_flag, total cba groups %d %d\n",
3518 3519
      phy_vars_eNB->Mod_id,harq_pid,phy_vars_eNB->proc[sched_subframe].frame_tx,subframe,i,harq_pid,
      phy_vars_eNB->ulsch_eNB[i]->num_active_cba_groups,num_active_cba_groups);
3520 3521 3522
      */
      phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->subframe_cba_scheduling_flag=0;
      phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->status= SCH_IDLE;
3523

3524
      if ((num_active_cba_groups > 0) &&
3525 3526 3527 3528
          //  (i % num_active_cba_groups == 0) && // this ue is used a a template for the CBA
          (i + num_active_cba_groups < NUMBER_OF_UE_MAX) &&
          (phy_vars_eNB->ulsch_eNB[i+num_active_cba_groups]->cba_rnti[i%num_active_cba_groups] > 0 ) &&
          (phy_vars_eNB->ulsch_eNB[i+num_active_cba_groups]->num_active_cba_groups> 0)) {
3529
#ifdef DEBUG_PHY_PROC
3530 3531 3532
        LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d UE %d harq_pid %d resetting the subframe_scheduling_flag for Ue %d cba groups %d members\n",
              phy_vars_eNB->Mod_id,harq_pid,frame,subframe,i,harq_pid,
              i+num_active_cba_groups, i%phy_vars_eNB->ulsch_eNB[i]->num_active_cba_groups);
3533
#endif
3534 3535 3536
        phy_vars_eNB->ulsch_eNB[i+num_active_cba_groups]->harq_processes[harq_pid]->subframe_cba_scheduling_flag=1;
        phy_vars_eNB->ulsch_eNB[i+num_active_cba_groups]->harq_processes[harq_pid]->status= CBA_ACTIVE;
        phy_vars_eNB->ulsch_eNB[i+num_active_cba_groups]->harq_processes[harq_pid]->TBS=phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS;
3537
      }
3538

3539
      if (ret == (1+MAX_TURBO_ITERATIONS)) {
3540 3541 3542 3543
        phy_vars_eNB->eNB_UE_stats[i].ulsch_round_errors[harq_pid][phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round]++;
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->phich_active = 1;
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->phich_ACK = 0;
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round++;
3544 3545
      } // ulsch in error
      else {
3546 3547 3548 3549 3550 3551 3552 3553
        LOG_D(PHY,"[eNB %d][PUSCH %d] Frame %d subframe %d ULSCH received, setting round to 0, PHICH ACK\n",
              phy_vars_eNB->Mod_id,harq_pid,
              frame,subframe);

        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->phich_active = 1;
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->phich_ACK = 1;
        phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->round = 0;
        phy_vars_eNB->eNB_UE_stats[i].ulsch_consecutive_errors = 0;
3554 3555
#ifdef DEBUG_PHY_PROC
#ifdef DEBUG_ULSCH
3556 3557 3558 3559 3560 3561 3562 3563
        LOG_D(PHY,"[eNB] Frame %d, Subframe %d : ULSCH SDU (RX harq_pid %d) %d bytes:",
              frame,subframe,
              harq_pid,phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3);

        for (j=0; j<phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3; j++)
          LOG_T(PHY,"%x.",phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->b[j]);

        LOG_T(PHY,"\n");
3564 3565
#endif
#endif
3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576

        if (access_mode > UNKNOWN_ACCESS) {
          LOG_D(PHY,"[eNB %d] Frame %d, Subframe %d : received ULSCH SDU from CBA transmission, UE (%d,%x), CBA (group %d, rnti %x)\n",
                phy_vars_eNB->Mod_id, frame,subframe,
                i, phy_vars_eNB->ulsch_eNB[i]->rnti,
                i % phy_vars_eNB->ulsch_eNB[i]->num_active_cba_groups, phy_vars_eNB->ulsch_eNB[i]->cba_rnti[i%num_active_cba_groups]);

          // detect if there is a CBA collision
          if (phy_vars_eNB->cba_last_reception[i%num_active_cba_groups] == 0 ) {
            mac_xface->rx_sdu(phy_vars_eNB->Mod_id,
                              phy_vars_eNB->CC_id,
3577
                              frame,subframe,
3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602
                              phy_vars_eNB->ulsch_eNB[i]->rnti,
                              phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->b,
                              phy_vars_eNB->ulsch_eNB[i]->harq_processes[harq_pid]->TBS>>3,
                              harq_pid,
                              NULL);

            phy_vars_eNB->cba_last_reception[i%num_active_cba_groups]+=1;//(subframe);
          } else {
            if (phy_vars_eNB->cba_last_reception[i%num_active_cba_groups] == 1 )
              LOG_N(PHY,"[eNB%d] Frame %d subframe %d : first CBA collision detected \n ",
                    phy_vars_eNB->Mod_id,frame,subframe);

            LOG_N(PHY,"[eNB%d] Frame %d subframe %d : CBA collision set SR for UE %d in group %d \n ",
                  phy_vars_eNB->Mod_id,frame,subframe,
                  phy_vars_eNB->cba_last_reception[i%num_active_cba_groups],i%num_active_cba_groups );

            phy_vars_eNB->cba_last_reception[i%num_active_cba_groups]+=1;

            mac_xface->SR_indication(phy_vars_eNB->Mod_id,
                                     phy_vars_eNB->CC_id,
                                     frame,
                                     phy_vars_eNB->dlsch_eNB[i][0]->rnti,subframe);
          }
        }
      } // ULSCH CBA not in error
3603
    }
3604

3605 3606
  } // loop i=0 ... NUMBER_OF_UE_MAX-1

3607
  //  if (pusch_active == 0) {
3608 3609
    if (abstraction_flag == 0) {
      //      LOG_D(PHY,"[eNB] Frame %d, subframe %d Doing I0_measurements\n",
3610
      //    (((subframe)==9)?-1:0) + phy_vars_eNB->proc[sched_subframe].frame_tx,subframe);
3611
      lte_eNB_I0_measurements(phy_vars_eNB,
3612
			      subframe,
3613 3614
                              0,
                              phy_vars_eNB->first_run_I0_measurements);
3615
      phy_vars_eNB->first_run_I0_measurements = 0;
3616
    }
3617

3618
#ifdef PHY_ABSTRACTION
3619 3620
    else {
      lte_eNB_I0_measurements_emul(phy_vars_eNB,
3621
                                   sect_id);
3622
    }
3623

3624
#endif
3625 3626


3627
    //}
3628 3629

#ifdef EMOS
Raymond Knopp's avatar
 
Raymond Knopp committed
3630
  phy_procedures_emos_eNB_RX(subframe,phy_vars_eNB);
3631 3632
#endif

3633
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_RX,0);
3634
  stop_meas(&phy_vars_eNB->phy_proc_rx);
3635

3636 3637 3638 3639
}

#undef DEBUG_PHY_PROC

3640 3641 3642 3643
#ifdef Rel10
int phy_procedures_RN_eNB_TX(unsigned char last_slot, unsigned char next_slot, relaying_type_t r_type)
{

3644
  int do_proc=0;// do nothing
3645 3646

  switch(r_type) {
3647
  case no_relay:
3648
    do_proc= no_relay; // perform the normal eNB operation
3649
    break;
3650

3651
  case multicast_relay:
3652
    if (((next_slot >>1) < 6) || ((next_slot >>1) > 8))
3653
      do_proc = 0; // do nothing
3654 3655 3656
    else // SF#6, SF#7 and SF#8
      do_proc = multicast_relay; // do PHY procedures eNB TX

3657
    break;
3658

3659 3660
  default: // should'not be here
    LOG_W(PHY,"Not supported relay type %d, do nothing\n", r_type);
3661
    do_proc=0;
3662 3663
    break;
  }
3664

3665 3666
  return do_proc;
}
3667 3668 3669 3670
#endif
void phy_procedures_eNB_lte(unsigned char subframe,PHY_VARS_eNB **phy_vars_eNB,uint8_t abstraction_flag,
                            relaying_type_t r_type, PHY_VARS_RN *phy_vars_rn)
{
3671
#if defined(ENABLE_ITTI)
3672 3673 3674 3675 3676
  MessageDef   *msg_p;
  const char   *msg_name;
  instance_t    instance;
  unsigned int  Mod_id;
  int           result;
3677
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
3678

Raymond Knopp's avatar
 
Raymond Knopp committed
3679 3680 3681

  int CC_id=0;

3682
  /*
Raymond Knopp's avatar
 
Raymond Knopp committed
3683
    if (phy_vars_eNB->proc[sched_subframe].frame_tx >= 1000)
3684
    mac_xface->macphy_exit("Exiting after 1000 Frames\n");
3685
  */
3686 3687
  VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_TX_ENB, phy_vars_eNB[0]->proc[subframe].frame_tx);
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_LTE,1);
Raymond Knopp's avatar
 
Raymond Knopp committed
3688
  start_meas(&phy_vars_eNB[0]->phy_proc);
Lionel Gauthier's avatar
Lionel Gauthier committed
3689

3690
#if defined(ENABLE_ITTI)
3691

3692
  do {
3693 3694
    // Checks if a message has been sent to PHY sub-task
    itti_poll_msg (TASK_PHY_ENB, &msg_p);
3695

3696 3697 3698 3699
    if (msg_p != NULL) {
      msg_name = ITTI_MSG_NAME (msg_p);
      instance = ITTI_MSG_INSTANCE (msg_p);
      Mod_id = instance;
3700

3701
      switch (ITTI_MSG_ID(msg_p)) {
3702
#   if ENABLE_RAL
3703

Raymond Knopp's avatar
 
Raymond Knopp committed
3704
      case TIMER_HAS_EXPIRED:
3705 3706 3707 3708 3709
        // check if it is a measurement timer
      {
        hashtable_rc_t       hashtable_rc;

        hashtable_rc = hashtable_is_key_exists(PHY_vars_eNB_g[Mod_id][0]->ral_thresholds_timed, (uint64_t)(TIMER_HAS_EXPIRED(msg_p).timer_id));
Raymond Knopp's avatar
 
Raymond Knopp committed
3710

3711 3712 3713 3714 3715
        if (hashtable_rc == HASH_TABLE_OK) {
          phy_eNB_lte_check_measurement_thresholds(instance, (ral_threshold_phy_t*)TIMER_HAS_EXPIRED(msg_p).arg);
        }
      }
      break;
Lionel Gauthier's avatar
Lionel Gauthier committed
3716 3717


Raymond Knopp's avatar
 
Raymond Knopp committed
3718
      case PHY_MEAS_THRESHOLD_REQ:
Lionel Gauthier's avatar
Lionel Gauthier committed
3719
#warning "TO DO LIST OF THRESHOLDS"
3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811
        LOG_D(PHY, "[ENB %d] Received %s\n", Mod_id, msg_name);
        {
          ral_threshold_phy_t* threshold_phy_p  = NULL;
          int                  index, res;
          long                 timer_id;
          hashtable_rc_t       hashtable_rc;

          switch (PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.th_action) {

          case RAL_TH_ACTION_CANCEL_THRESHOLD:
            break;

          case RAL_TH_ACTION_SET_NORMAL_THRESHOLD:
          case RAL_TH_ACTION_SET_ONE_SHOT_THRESHOLD:
            for (index = 0; index < PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.num_thresholds; index++) {
              threshold_phy_p                  = calloc(1, sizeof(ral_threshold_phy_t));
              threshold_phy_p->th_action       = PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.th_action;
              memcpy(&threshold_phy_p->link_param.link_param_type,
                     &PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.link_param_type,
                     sizeof(ral_link_param_type_t));

              memcpy(&threshold_phy_p->threshold,
                     &PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.thresholds[index],
                     sizeof(ral_threshold_t));

              switch (PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.union_choice) {

              case RAL_LINK_CFG_PARAM_CHOICE_TIMER_NULL:
                switch (PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.link_param_type.choice) {
                case RAL_LINK_PARAM_TYPE_CHOICE_GEN:
                  SLIST_INSERT_HEAD(
                    &PHY_vars_eNB_g[Mod_id][0]->ral_thresholds_gen_polled[PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.link_param_type._union.link_param_gen],
                    threshold_phy_p,
                    ral_thresholds);
                  break;

                case RAL_LINK_PARAM_TYPE_CHOICE_LTE:
                  SLIST_INSERT_HEAD(
                    &PHY_vars_eNB_g[Mod_id][0]->ral_thresholds_lte_polled[PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.link_param_type._union.link_param_lte],
                    threshold_phy_p,
                    ral_thresholds);
                  break;

                default:
                  LOG_E(PHY, "[ENB %d] BAD PARAMETER cfg_param.link_param_type.choice %d in %s\n",
                        Mod_id, PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.link_param_type.choice, msg_name);
                }

                break;

              case RAL_LINK_CFG_PARAM_CHOICE_TIMER:
                res = timer_setup(
                        (uint32_t)(PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param._union.timer_interval/1000),//uint32_t      interval_sec,
                        (uint32_t)(PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param._union.timer_interval%1000),//uint32_t      interval_us,
                        TASK_PHY_ENB,
                        instance,
                        TIMER_PERIODIC,
                        threshold_phy_p,
                        &timer_id);

                if (res == 0) {
                  hashtable_rc = hashtable_insert(PHY_vars_eNB_g[Mod_id][0]->ral_thresholds_timed, (uint64_t )timer_id, (void*)threshold_phy_p);

                  if (hashtable_rc == HASH_TABLE_OK) {
                    threshold_phy_p->timer_id = timer_id;
                  } else {
                    LOG_E(PHY, "[ENB %d]  %s: Error in hashtable. Could not configure threshold index %d \n",
                          Mod_id, msg_name, index);
                  }

                } else {
                  LOG_E(PHY, "[ENB %d]  %s: Could not configure threshold index %d because of timer initialization failure\n",
                        Mod_id, msg_name, index);
                }

                break;

              default: // already checked in RRC, should not happen here
                LOG_E(PHY, "[ENB %d] BAD PARAMETER cfg_param.union_choice %d in %s\n",
                      Mod_id, PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.union_choice, msg_name);
              }
            }

            break;

          default:
            LOG_E(PHY, "[ENB %d] BAD PARAMETER th_action value %d in %s\n",
                  Mod_id, PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.th_action, msg_name);
          }

        }
        break;
Lionel Gauthier's avatar
Lionel Gauthier committed
3812
#   endif
3813

3814
        /* Messages from eNB app */
Raymond Knopp's avatar
 
Raymond Knopp committed
3815
      case PHY_CONFIGURATION_REQ:
3816 3817
        LOG_I(PHY, "[eNB %d] Received %s\n", instance, msg_name);
        /* TODO */
3818

3819
        break;
3820

Raymond Knopp's avatar
 
Raymond Knopp committed
3821
      default:
3822 3823
        LOG_E(PHY, "[ENB %d] Received unexpected message %s\n", Mod_id, msg_name);
        break;
Lionel Gauthier's avatar
Lionel Gauthier committed
3824
      }
3825 3826 3827 3828

      result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
      AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
    }
3829
  } while(msg_p != NULL);
3830

3831 3832
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
3833

3834
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
3835
    if ((((phy_vars_eNB[CC_id]->lte_frame_parms.frame_type == TDD)&&
3836 3837 3838 3839 3840 3841 3842
          (subframe_select(&phy_vars_eNB[CC_id]->lte_frame_parms,phy_vars_eNB[CC_id]->proc[subframe].subframe_tx)==SF_DL))||
         (phy_vars_eNB[CC_id]->lte_frame_parms.frame_type == FDD))) {
#ifdef Rel10

      if (phy_procedures_RN_eNB_TX(phy_vars_eNB[CC_id]->proc[subframe].subframe_rx, phy_vars_eNB[CC_id]->proc[subframe].subframe_tx, r_type) != 0 )
#endif
        phy_procedures_eNB_TX(subframe,phy_vars_eNB[CC_id],abstraction_flag,r_type,phy_vars_rn);
Raymond Knopp's avatar
 
Raymond Knopp committed
3843
    }
3844

Raymond Knopp's avatar
 
Raymond Knopp committed
3845
    if ((((phy_vars_eNB[CC_id]->lte_frame_parms.frame_type == TDD )&&
3846 3847
          (subframe_select(&phy_vars_eNB[CC_id]->lte_frame_parms,phy_vars_eNB[CC_id]->proc[subframe].subframe_rx)==SF_UL)) ||
         (phy_vars_eNB[CC_id]->lte_frame_parms.frame_type == FDD))) {
Raymond Knopp's avatar
 
Raymond Knopp committed
3848 3849
      phy_procedures_eNB_RX(subframe,phy_vars_eNB[CC_id],abstraction_flag,r_type);
    }
3850

Raymond Knopp's avatar
 
Raymond Knopp committed
3851
    if (subframe_select(&phy_vars_eNB[CC_id]->lte_frame_parms,phy_vars_eNB[CC_id]->proc[subframe].subframe_tx)==SF_S) {
3852 3853
#ifdef Rel10

Raymond Knopp's avatar
 
Raymond Knopp committed
3854
      if (phy_procedures_RN_eNB_TX(subframe, subframe, r_type) != 0 )
3855 3856
#endif
        phy_procedures_eNB_TX(subframe,phy_vars_eNB[CC_id],abstraction_flag,r_type,phy_vars_rn);
Raymond Knopp's avatar
 
Raymond Knopp committed
3857
    }
3858 3859

    if ((subframe_select(&phy_vars_eNB[CC_id]->lte_frame_parms,phy_vars_eNB[CC_id]->proc[subframe].subframe_rx)==SF_S)) {
Raymond Knopp's avatar
 
Raymond Knopp committed
3860 3861
      phy_procedures_eNB_S_RX(subframe,phy_vars_eNB[CC_id],abstraction_flag,r_type);
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
3862

Raymond Knopp's avatar
 
Raymond Knopp committed
3863 3864
    phy_vars_eNB[CC_id]->proc[subframe].frame_tx++;
    phy_vars_eNB[CC_id]->proc[subframe].frame_rx++;
3865

3866 3867
    if (phy_vars_eNB[CC_id]->proc[subframe].frame_tx>=MAX_FRAME_NUMBER) // defined in impl_defs_top.h
      phy_vars_eNB[CC_id]->proc[subframe].frame_tx-=MAX_FRAME_NUMBER;
3868

3869 3870
    if (phy_vars_eNB[CC_id]->proc[subframe].frame_rx>=MAX_FRAME_NUMBER)
      phy_vars_eNB[CC_id]->proc[subframe].frame_rx-=MAX_FRAME_NUMBER;
Raymond Knopp's avatar
 
Raymond Knopp committed
3871
  }
3872

3873
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_LTE,0);
Raymond Knopp's avatar
 
Raymond Knopp committed
3874
  stop_meas(&phy_vars_eNB[0]->phy_proc);
3875 3876
}