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

/*! \file fapi_l1.c
 * \brief functions for FAPI L1 interface
 * \author R. Knopp
 * \date 2017
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr
 * \note
 * \warning
 */

33 34 35
#include "PHY/defs_eNB.h"
#include "PHY/LTE_TRANSPORT/transport_proto.h"
#include "SCHED/sched_eNB.h"
frtabu's avatar
frtabu committed
36
#include "nfapi/oai_integration/vendor_ext.h"
37
#include "nfapi_pnf_interface.h"
38 39
#include "fapi_l1.h"

40 41 42 43 44
int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req);
int oai_nfapi_tx_req(nfapi_tx_request_t *tx_req);
int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req);
int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req);

45
int oai_nfapi_ue_release_req(nfapi_ue_release_request_t *release_req);
Cedric Roux's avatar
Cedric Roux committed
46
void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB,
47
                             int frame, int subframe,
48
                             L1_rxtx_proc_t *proc,
frtabu's avatar
frtabu committed
49
                             nfapi_dl_config_request_pdu_t *dl_config_pdu) {
50
  int idx                         = subframe&1;
51 52 53
  LTE_eNB_PDCCH *pdcch_vars       = &eNB->pdcch_vars[idx];
  nfapi_dl_config_dci_dl_pdu *pdu = &dl_config_pdu->dci_dl_pdu;

frtabu's avatar
frtabu committed
54
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
55

frtabu's avatar
frtabu committed
56 57
  LOG_D(PHY,"Frame %d, Subframe %d: DCI processing - populating pdcch_vars->dci_alloc[%d] proc:subframe_tx:%d idx:%d pdcch_vars->num_dci:%d\n",frame,subframe, pdcch_vars->num_dci, proc->subframe_tx,
        idx, pdcch_vars->num_dci);
58
  // copy dci configuration into eNB structure
59
  fill_dci_and_dlsch(eNB,frame,subframe,proc,&pdcch_vars->dci_alloc[pdcch_vars->num_dci],pdu);
frtabu's avatar
frtabu committed
60 61
  LOG_D(PHY,"Frame %d, Subframe %d: DCI processing - populated pdcch_vars->dci_alloc[%d] proc:subframe_tx:%d idx:%d pdcch_vars->num_dci:%d\n",proc->frame_tx,proc->subframe_tx, pdcch_vars->num_dci,
        proc->subframe_tx, idx, pdcch_vars->num_dci);
62 63
}

64
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
65

Cedric Roux's avatar
Cedric Roux committed
66
void handle_nfapi_mpdcch_pdu(PHY_VARS_eNB *eNB,
67
                             L1_rxtx_proc_t *proc,
frtabu's avatar
frtabu committed
68
                             nfapi_dl_config_request_pdu_t *dl_config_pdu) {
Cedric Roux's avatar
Cedric Roux committed
69
  int idx                         = proc->subframe_tx&1;
70 71 72
  LTE_eNB_MPDCCH *mpdcch_vars     = &eNB->mpdcch_vars[idx];
  nfapi_dl_config_mpdcch_pdu *pdu = &dl_config_pdu->mpdcch_pdu;

frtabu's avatar
frtabu committed
73
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
74

75 76 77 78
  LOG_D(PHY,"Frame %d, Subframe %d: MDCI processing\n",proc->frame_tx,proc->subframe_tx);
  // copy dci configuration into eNB structure
  fill_mdci_and_dlsch(eNB,proc,&mpdcch_vars->mdci_alloc[mpdcch_vars->num_dci],pdu);
}
79

80
#endif
81

82
void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
frtabu's avatar
frtabu committed
83
                                  nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu) {
84
  int idx                         = subframe&1;
85
  LTE_eNB_PDCCH *pdcch_vars       = &eNB->pdcch_vars[idx];
86

frtabu's avatar
frtabu committed
87
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
88

89
  //LOG_D(PHY,"%s() SFN/SF:%04d%d Before num_dci:%d\n", __FUNCTION__,frame,subframe,pdcch_vars->num_dci);
90
  // copy dci configuration in to eNB structure
91
  fill_dci0(eNB,frame,subframe,proc,&pdcch_vars->dci_alloc[pdcch_vars->num_dci], &hi_dci0_config_pdu->dci_pdu);
92 93
}

94

95 96

void handle_nfapi_hi_dci0_mpdcch_dci_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
frtabu's avatar
frtabu committed
97
    nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu) {
sharma's avatar
sharma committed
98
  int idx                         = proc->subframe_tx&1;
99
  LTE_eNB_MPDCCH *pdcch_vars      = &eNB->mpdcch_vars[idx];
frtabu's avatar
frtabu committed
100 101

  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
102

sharma's avatar
sharma committed
103
  // copy dci configuration in to eNB structure
104
  fill_mpdcch_dci0(eNB,proc,&pdcch_vars->mdci_alloc[pdcch_vars->num_dci], &hi_dci0_config_pdu->mpdcch_dci_pdu);
sharma's avatar
sharma committed
105 106
}

107

108
void handle_nfapi_hi_dci0_hi_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
frtabu's avatar
frtabu committed
109
                                 nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu) {
110
  LTE_eNB_PHICH *phich = &eNB->phich_vars[subframe&1];
111

frtabu's avatar
frtabu committed
112
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
113

114
  // copy dci configuration in to eNB structure
115
  LOG_D(PHY,"Received HI PDU with value %d (rbstart %d,cshift %d)\n",
Cedric Roux's avatar
Cedric Roux committed
116 117 118
        hi_dci0_config_pdu->hi_pdu.hi_pdu_rel8.hi_value,
        hi_dci0_config_pdu->hi_pdu.hi_pdu_rel8.resource_block_start,
        hi_dci0_config_pdu->hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms);
119
  // DJP - TODO FIXME - transmission power ignored
120 121 122
  phich->config[phich->num_hi].hi       = hi_dci0_config_pdu->hi_pdu.hi_pdu_rel8.hi_value;
  phich->config[phich->num_hi].first_rb = hi_dci0_config_pdu->hi_pdu.hi_pdu_rel8.resource_block_start;
  phich->config[phich->num_hi].n_DMRS   = hi_dci0_config_pdu->hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms;
123 124
  phich->num_hi++;
  AssertFatal(phich->num_hi<32,"Maximum number of phich reached in subframe\n");
125 126
}

127
void handle_nfapi_bch_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
Cedric Roux's avatar
Cedric Roux committed
128
                          nfapi_dl_config_request_pdu_t *dl_config_pdu,
frtabu's avatar
frtabu committed
129
                          uint8_t *sdu) {
130
  nfapi_dl_config_bch_pdu_rel8_t *rel8 = &dl_config_pdu->bch_pdu.bch_pdu_rel8;
Cedric Roux's avatar
Cedric Roux committed
131

frtabu's avatar
frtabu committed
132
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
133

134
  AssertFatal(rel8->length == 3, "BCH PDU has length %d != 3\n",rel8->length);
135
  //LOG_D(PHY,"bch_pdu: %x,%x,%x\n",sdu[0],sdu[1],sdu[2]);
136 137 138 139 140 141
  eNB->pbch_pdu[0] = sdu[2];
  eNB->pbch_pdu[1] = sdu[1];
  eNB->pbch_pdu[2] = sdu[0];
  // adjust transmit amplitude here based on NFAPI info
}

142
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
frtabu's avatar
frtabu committed
143 144 145 146 147 148 149 150
  extern uint32_t localRIV2alloc_LUT6[32];
  extern uint32_t localRIV2alloc_LUT25[512];
  extern uint32_t localRIV2alloc_LUT50_0[1600];
  extern uint32_t localRIV2alloc_LUT50_1[1600];
  extern uint32_t localRIV2alloc_LUT100_0[6000];
  extern uint32_t localRIV2alloc_LUT100_1[6000];
  extern uint32_t localRIV2alloc_LUT100_2[6000];
  extern uint32_t localRIV2alloc_LUT100_3[6000];
151 152
#endif

153
void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t *proc,
Cedric Roux's avatar
Cedric Roux committed
154 155
                            nfapi_dl_config_request_pdu_t *dl_config_pdu,
                            uint8_t codeword_index,
frtabu's avatar
frtabu committed
156
                            uint8_t *sdu) {
157
  nfapi_dl_config_dlsch_pdu_rel8_t *rel8 = &dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8;
158
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
159 160
  nfapi_dl_config_dlsch_pdu_rel10_t *rel10 = &dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10;
#endif
161
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
162 163 164 165 166 167
  nfapi_dl_config_dlsch_pdu_rel13_t *rel13 = &dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13;
#endif
  LTE_eNB_DLSCH_t *dlsch0=NULL,*dlsch1=NULL;
  LTE_DL_eNB_HARQ_t *dlsch0_harq=NULL,*dlsch1_harq=NULL;
  int UE_id;
  int harq_pid;
Cedric Roux's avatar
Cedric Roux committed
168

frtabu's avatar
frtabu committed
169
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
170

171
  UE_id = find_dlsch(rel8->rnti,eNB,SEARCH_EXIST_OR_FREE);
frtabu's avatar
frtabu committed
172 173

  if( (UE_id<0) || (UE_id>=NUMBER_OF_UE_MAX) ) {
Wang Tsu-Han's avatar
Wang Tsu-Han committed
174 175 176
    LOG_E(PHY,"illegal UE_id found!!! rnti %04x UE_id %d\n",rel8->rnti,UE_id);
    return;
  }
frtabu's avatar
frtabu committed
177

Wang Tsu-Han's avatar
Wang Tsu-Han committed
178 179
  //AssertFatal(UE_id!=-1,"no free or exiting dlsch_context\n");
  //AssertFatal(UE_id<NUMBER_OF_UE_MAX,"returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n",UE_id,NUMBER_OF_UE_MAX);
180 181
  dlsch0 = eNB->dlsch[UE_id][0];
  dlsch1 = eNB->dlsch[UE_id][1];
182
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
frtabu's avatar
frtabu committed
183

haswell's avatar
haswell committed
184
  if ((rel13->pdsch_payload_type < 2) && (rel13->ue_type>0)) dlsch0->harq_ids[proc->frame_tx%2][proc->subframe_tx] = 0;
185

frtabu's avatar
frtabu committed
186
#endif
haswell's avatar
haswell committed
187
  harq_pid        = dlsch0->harq_ids[proc->frame_tx%2][proc->subframe_tx];
188

189 190 191 192 193
  if((harq_pid < 0) || (harq_pid >= dlsch0->Mdlharq)) {
    LOG_E(PHY,"illegal harq_pid %d %s:%d\n", harq_pid, __FILE__, __LINE__);
    return;
  }

194 195 196
  dlsch0_harq     = dlsch0->harq_processes[harq_pid];
  dlsch1_harq     = dlsch1->harq_processes[harq_pid];
  AssertFatal(dlsch0_harq!=NULL,"dlsch_harq is null\n");
197 198
  // compute DL power control parameters
  eNB->pdsch_config_dedicated[UE_id].p_a = rel8->pa;
frtabu's avatar
frtabu committed
199
#ifdef PHY_TX_THREAD
200

frtabu's avatar
frtabu committed
201
  if (dlsch0->active[proc->subframe_tx]) {
Wang Tsu-Han's avatar
Wang Tsu-Han committed
202
# else
frtabu's avatar
frtabu committed
203 204

  if (dlsch0->active) {
Wang Tsu-Han's avatar
Wang Tsu-Han committed
205
#endif
206 207
    computeRhoA_eNB(rel8->pa, dlsch0,dlsch0_harq->dl_power_off, eNB->frame_parms.nb_antenna_ports_eNB);
    computeRhoB_eNB(rel8->pa,eNB->frame_parms.pdsch_config_common.p_b,eNB->frame_parms.nb_antenna_ports_eNB,dlsch0,dlsch0_harq->dl_power_off);
208
  }
frtabu's avatar
frtabu committed
209

Wang Tsu-Han's avatar
Wang Tsu-Han committed
210
#ifdef PHY_TX_THREAD
frtabu's avatar
frtabu committed
211 212

  if (dlsch1->active[proc->subframe_tx]) {
Wang Tsu-Han's avatar
Wang Tsu-Han committed
213
#else
frtabu's avatar
frtabu committed
214 215

  if (dlsch1->active) {
Wang Tsu-Han's avatar
Wang Tsu-Han committed
216
#endif
217 218
    computeRhoA_eNB(rel8->pa, dlsch1,dlsch1_harq->dl_power_off, eNB->frame_parms.nb_antenna_ports_eNB);
    computeRhoB_eNB(rel8->pa,eNB->frame_parms.pdsch_config_common.p_b,eNB->frame_parms.nb_antenna_ports_eNB,dlsch1,dlsch1_harq->dl_power_off);
219 220
  }

haswell's avatar
haswell committed
221
  dlsch0_harq->pdsch_start = eNB->pdcch_vars[proc->subframe_tx & 1].num_pdcch_symbols;
222 223

  if (dlsch0_harq->round==0) {  //get pointer to SDU if this a new SDU
Wang Tsu-Han's avatar
Wang Tsu-Han committed
224
    if(sdu == NULL) {
frtabu's avatar
frtabu committed
225 226
      LOG_E(PHY,
            "NFAPI: SFN/SF:%04d%d proc:TX:[frame %d subframe %d]: programming dlsch for round 0, rnti %x, UE_id %d, harq_pid %d : sdu is null for pdu_index %d dlsch0_harq[round:%d SFN/SF:%d%d pdu:%p mcs:%d ndi:%d pdschstart:%d]\n",
Wang Tsu-Han's avatar
Wang Tsu-Han committed
227 228 229 230 231
            frame,subframe,
            proc->frame_tx,proc->subframe_tx,rel8->rnti,UE_id,harq_pid,
            dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index,dlsch0_harq->round,dlsch0_harq->frame,dlsch0_harq->subframe,dlsch0_harq->pdu,dlsch0_harq->mcs,dlsch0_harq->ndi,dlsch0_harq->pdsch_start);
      return;
    }
frtabu's avatar
frtabu committed
232

Wang Tsu-Han's avatar
Wang Tsu-Han committed
233 234 235 236
    //AssertFatal(sdu!=NULL,"NFAPI: SFN/SF:%04d%d proc:TX:[frame %d subframe %d]: programming dlsch for round 0, rnti %x, UE_id %d, harq_pid %d : sdu is null for pdu_index %d dlsch0_harq[round:%d SFN/SF:%d%d pdu:%p mcs:%d ndi:%d pdschstart:%d]\n",
    //            frame,subframe,
    //            proc->frame_tx,proc->subframe_tx,rel8->rnti,UE_id,harq_pid,
    //            dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index,dlsch0_harq->round,dlsch0_harq->frame,dlsch0_harq->subframe,dlsch0_harq->pdu,dlsch0_harq->mcs,dlsch0_harq->ndi,dlsch0_harq->pdsch_start);
237
    if (rel8->rnti != 0xFFFF) LOG_D(PHY,"NFAPI: SFN/SF:%04d%d proc:TX:[frame %d, subframe %d]: programming dlsch for round 0, rnti %x, UE_id %d, harq_pid %d\n",
frtabu's avatar
frtabu committed
238 239
                                      frame,subframe,proc->frame_tx,proc->subframe_tx,rel8->rnti,UE_id,harq_pid);

240 241
    if (codeword_index == 0) dlsch0_harq->pdu                    = sdu;
    else                     dlsch1_harq->pdu                    = sdu;
frtabu's avatar
frtabu committed
242
  } else {
243
    if (rel8->rnti != 0xFFFF) LOG_D(PHY,"NFAPI: SFN/SF:%04d%d proc:TX:[frame %d, subframe %d]: programming dlsch for round %d, rnti %x, UE_id %d, harq_pid %d\n",
frtabu's avatar
frtabu committed
244 245
                                      frame,subframe,proc->frame_tx,proc->subframe_tx,dlsch0_harq->round,
                                      rel8->rnti,UE_id,harq_pid);
246
  }
Cedric Roux's avatar
Cedric Roux committed
247

248
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
Wang Tsu-Han's avatar
Wang Tsu-Han committed
249 250 251
#ifdef PHY_TX_THREAD
  dlsch0_harq->sib1_br_flag=0;
#else
252
  dlsch0->sib1_br_flag=0;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
253
#endif
254 255

  if ((rel13->pdsch_payload_type <2) && (rel13->ue_type>0)) { // this is a BR/CE UE and SIB1-BR/SI-BR
256
    UE_id = find_dlsch(rel8->rnti,eNB,SEARCH_EXIST_OR_FREE);
257 258 259
    AssertFatal(UE_id!=-1,"no free or exiting dlsch_context\n");
    AssertFatal(UE_id<NUMBER_OF_UE_MAX,"returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n",UE_id,NUMBER_OF_UE_MAX);
    dlsch0 = eNB->dlsch[UE_id][0];
frtabu's avatar
frtabu committed
260
    dlsch0->harq_mask = 1;
261 262
    dlsch0_harq     = dlsch0->harq_processes[0];
    dlsch0_harq->pdu                    = sdu;
263
    LOG_D(PHY,"NFAPI: frame %d, subframe %d (TX %d.%d): Programming SI-BR (%d) => %d\n",frame,subframe,proc->frame_tx,proc->subframe_tx,rel13->pdsch_payload_type,UE_id);
264 265
    dlsch0->rnti             = 0xFFFF;
    dlsch0->Kmimo            = 1;
Cedric Roux's avatar
Cedric Roux committed
266
    dlsch0->Mdlharq          = 4;
267 268 269
    dlsch0->Nsoft            = 25344;
    dlsch0->i0               = rel13->initial_transmission_sf_io;
    dlsch0_harq->pdsch_start = rel10->pdsch_start;
haswell's avatar
haswell committed
270
    dlsch0->harq_ids[proc->frame_tx%2][proc->subframe_rx] = 0;
Raymond Knopp's avatar
Raymond Knopp committed
271 272
    dlsch0_harq->frame       = proc->frame_tx;
    dlsch0_harq->subframe    = proc->subframe_tx;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
273
#ifdef PHY_TX_THREAD
frtabu's avatar
frtabu committed
274

Wang Tsu-Han's avatar
Wang Tsu-Han committed
275
    if (rel13->pdsch_payload_type == 0) dlsch0_harq->sib1_br_flag=1;
frtabu's avatar
frtabu committed
276

Wang Tsu-Han's avatar
Wang Tsu-Han committed
277
#else
frtabu's avatar
frtabu committed
278

279
    if (rel13->pdsch_payload_type == 0) dlsch0->sib1_br_flag=1;
frtabu's avatar
frtabu committed
280

Wang Tsu-Han's avatar
Wang Tsu-Han committed
281
#endif
282

frtabu's avatar
frtabu committed
283
    // configure PDSCH
284
    switch (eNB->frame_parms.N_RB_DL) {
frtabu's avatar
frtabu committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
      case 6:
        dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT6[rel8->resource_block_coding];
        break;

      case 15:
        AssertFatal(1==0,"15 PRBs not supported for now\n");
        break;

      case 25:
        dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT25[rel8->resource_block_coding];
        break;

      case 50:
        dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT50_0[rel8->resource_block_coding];
        dlsch0_harq->rb_alloc[1]      = localRIV2alloc_LUT50_1[rel8->resource_block_coding];
        break;

      case 75:
        AssertFatal(1==0,"75 PRBs not supported for now\n");
        break;

      case 100:
        dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT100_0[rel8->resource_block_coding];
        dlsch0_harq->rb_alloc[1]      = localRIV2alloc_LUT100_1[rel8->resource_block_coding];
        dlsch0_harq->rb_alloc[2]      = localRIV2alloc_LUT100_2[rel8->resource_block_coding];
        dlsch0_harq->rb_alloc[3]      = localRIV2alloc_LUT100_3[rel8->resource_block_coding];
311 312
    }

Wang Tsu-Han's avatar
Wang Tsu-Han committed
313 314 315
#ifdef PHY_TX_THREAD
    dlsch0->active[proc->subframe_tx]= 1;
#else
316
    dlsch0->active                  = 1;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
317
#endif
Cedric Roux's avatar
Cedric Roux committed
318
    dlsch0_harq->nb_rb              = 6;
319 320 321 322 323 324 325 326 327 328
    dlsch0_harq->vrb_type           = LOCALIZED;
    dlsch0_harq->rvidx              = rel8->redundancy_version;
    dlsch0_harq->Nl                 = 1;
    dlsch0_harq->mimo_mode          = (eNB->frame_parms.nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI;
    dlsch0_harq->dl_power_off       = 1;
    dlsch0_harq->round              = 0;
    dlsch0_harq->status             = ACTIVE;
    dlsch0_harq->TBS                = rel8->length<<3;
    dlsch0_harq->Qm                 = rel8->modulation;
    dlsch0_harq->codeword           = 0;
329
    dlsch0_harq->pdsch_start        = rel10->pdsch_start;
frtabu's avatar
frtabu committed
330
  } else
331
#endif
frtabu's avatar
frtabu committed
332
  {
333 334 335 336 337
    UE_id = find_dlsch(rel8->rnti,eNB,SEARCH_EXIST_OR_FREE);
    AssertFatal(UE_id!=-1,"no free or exiting dlsch_context\n");
    AssertFatal(UE_id<NUMBER_OF_UE_MAX,"returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n",UE_id,NUMBER_OF_UE_MAX);
    dlsch0 = eNB->dlsch[UE_id][0];
    dlsch1 = eNB->dlsch[UE_id][1];
338
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
339
    dlsch0->sib1_br_flag=0;
340
    dlsch0->i0               = 0xFFFF;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
341
#endif
342
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
frtabu's avatar
frtabu committed
343
    LOG_D(PHY,"dlsch->i0:%04x dlsch0_harq[pdsch_start:%d nb_rb:%d vrb_type:%d rvidx:%d Nl:%d mimo_mode:%d dl_power_off:%d round:%d status:%d TBS:%d Qm:%d codeword:%d rb_alloc:%d] rel8[length:%d]\n",
Wang Tsu-Han's avatar
Wang Tsu-Han committed
344
#ifdef PHY_TX_THREAD
frtabu's avatar
frtabu committed
345
          dlsch0_harq->i0,
Wang Tsu-Han's avatar
Wang Tsu-Han committed
346
#else
frtabu's avatar
frtabu committed
347
          dlsch0->i0,
Wang Tsu-Han's avatar
Wang Tsu-Han committed
348
#endif
frtabu's avatar
frtabu committed
349 350 351 352
          dlsch0_harq->pdsch_start, dlsch0_harq->nb_rb, dlsch0_harq->vrb_type, dlsch0_harq->rvidx, dlsch0_harq->Nl, dlsch0_harq->mimo_mode, dlsch0_harq->dl_power_off, dlsch0_harq->round, dlsch0_harq->status,
          dlsch0_harq->TBS, dlsch0_harq->Qm, dlsch0_harq->codeword, dlsch0_harq->rb_alloc[0],
          rel8->length
         );
353
#else
frtabu's avatar
frtabu committed
354 355 356 357 358
    LOG_D(PHY,"dlsch0_harq[pdsch_start:%d nb_rb:%d vrb_type:%d rvidx:%d Nl:%d mimo_mode:%d dl_power_off:%d round:%d status:%d TBS:%d Qm:%d codeword:%d rb_alloc:%d] rel8[length:%d]\n",
          dlsch0_harq->pdsch_start, dlsch0_harq->nb_rb, dlsch0_harq->vrb_type, dlsch0_harq->rvidx, dlsch0_harq->Nl, dlsch0_harq->mimo_mode, dlsch0_harq->dl_power_off, dlsch0_harq->round, dlsch0_harq->status,
          dlsch0_harq->TBS, dlsch0_harq->Qm, dlsch0_harq->codeword, dlsch0_harq->rb_alloc[0],
          rel8->length
         );
359
#endif
360
    dlsch0->active = 1;
361
    harq_pid        = dlsch0->harq_ids[frame%2][proc->subframe_tx];
362
    dlsch0->harq_mask |= (1<<harq_pid);
sharma's avatar
sharma committed
363
    AssertFatal((harq_pid>=0) && (harq_pid<8),"subframe %d: harq_pid %d not in 0...7\n",proc->subframe_tx,harq_pid);
364 365 366 367
    dlsch0_harq     = dlsch0->harq_processes[harq_pid];
    dlsch1_harq     = dlsch1->harq_processes[harq_pid];
    AssertFatal(dlsch0_harq!=NULL,"dlsch_harq is null\n");

frtabu's avatar
frtabu committed
368
    // compute DL power control parameters
369

frtabu's avatar
frtabu committed
370
    if (dlsch0->active) {
371 372
      computeRhoA_eNB(rel8->pa,dlsch0,dlsch0_harq->dl_power_off, eNB->frame_parms.nb_antenna_ports_eNB);
      computeRhoB_eNB(rel8->pa,eNB->frame_parms.pdsch_config_common.p_b,eNB->frame_parms.nb_antenna_ports_eNB,dlsch0,dlsch0_harq->dl_power_off);
frtabu's avatar
frtabu committed
373 374 375
    }

    if (dlsch1->active) {
376 377
      computeRhoA_eNB(rel8->pa, dlsch1,dlsch1_harq->dl_power_off, eNB->frame_parms.nb_antenna_ports_eNB);
      computeRhoB_eNB(rel8->pa,eNB->frame_parms.pdsch_config_common.p_b,eNB->frame_parms.nb_antenna_ports_eNB,dlsch1,dlsch1_harq->dl_power_off);
378 379
    }

380
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
frtabu's avatar
frtabu committed
381

nepes's avatar
nepes committed
382 383 384
    if (rel13->ue_type>0)
      dlsch0_harq->pdsch_start = rel10->pdsch_start;
    else
385
#endif
nepes's avatar
nepes committed
386 387
      dlsch0_harq->pdsch_start = eNB->pdcch_vars[proc->subframe_tx & 1].num_pdcch_symbols;

388 389 390 391
    if (dlsch0_harq->round==0) {  //get pointer to SDU if this a new SDU
      AssertFatal(sdu!=NULL,"NFAPI: frame %d, subframe %d: programming dlsch for round 0, rnti %x, UE_id %d, harq_pid %d : sdu is null for pdu_index %d\n",
                  proc->frame_tx,proc->subframe_tx,rel8->rnti,UE_id,harq_pid,
                  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index);
frtabu's avatar
frtabu committed
392

sharma's avatar
sharma committed
393
      if (rel8->rnti != 0xFFFF) LOG_D(PHY,"NFAPI: frame %d, subframe %d: programming dlsch for round 0, rnti %x, UE_id %d, harq_pid %d\n",
frtabu's avatar
frtabu committed
394 395
                                        proc->frame_tx,proc->subframe_tx,rel8->rnti,UE_id,harq_pid);

396 397
      if (codeword_index == 0) dlsch0_harq->pdu                    = sdu;
      else                     dlsch1_harq->pdu                    = sdu;
frtabu's avatar
frtabu committed
398
    } else {
sharma's avatar
sharma committed
399
      if (rel8->rnti != 0xFFFF) LOG_D(PHY,"NFAPI: frame %d, subframe %d: programming dlsch for round %d, rnti %x, UE_id %d, harq_pid %d\n",
frtabu's avatar
frtabu committed
400 401
                                        proc->frame_tx,proc->subframe_tx,dlsch0_harq->round,
                                        rel8->rnti,UE_id,harq_pid);
402 403
    }
  }
404 405
}

frtabu's avatar
frtabu committed
406
int16_t to_beta_offset_harqack[16]= {16,20,25,32,40,50,64,80,101,127,160,248,400,640,1008,8};
407

408
void handle_ulsch_harq_pdu(
frtabu's avatar
frtabu committed
409 410 411 412 413 414
  PHY_VARS_eNB                           *eNB,
  int                                     UE_id,
  nfapi_ul_config_request_pdu_t          *ul_config_pdu,
  nfapi_ul_config_ulsch_harq_information *harq_information,
  uint16_t                                frame,
  uint8_t                                 subframe) {
415 416 417 418
  nfapi_ul_config_ulsch_pdu_rel8_t *rel8 = &ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8;
  LTE_eNB_ULSCH_t *ulsch=eNB->ulsch[UE_id];
  LTE_UL_eNB_HARQ_t *ulsch_harq;

frtabu's avatar
frtabu committed
419
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
420

421 422 423 424 425 426
  int harq_pid = rel8->harq_process_number;
  ulsch_harq = ulsch->harq_processes[harq_pid];
  ulsch_harq->frame                      = frame;
  ulsch_harq->subframe                   = subframe;
  ulsch_harq->O_ACK                      = harq_information->harq_information_rel10.harq_size;
  ulsch->beta_offset_harqack_times8      = to_beta_offset_harqack[harq_information->harq_information_rel10.delta_offset_harq];
frtabu's avatar
frtabu committed
427

Wang Tsu-Han's avatar
Wang Tsu-Han committed
428 429
  if (eNB->frame_parms.frame_type == TDD) {
    if (harq_information->harq_information_rel10.ack_nack_mode==0) //bundling
frtabu's avatar
frtabu committed
430 431
      ulsch->bundling = 1;
  }
432 433
}

frtabu's avatar
frtabu committed
434 435
uint16_t to_beta_offset_ri[16]= {9,13,16,20,25,32,40,50,64,80,101,127,160,0,0,0};
uint16_t to_beta_offset_cqi[16]= {0,0,9,10,11,13,14,16,18,20,23,25,28,32,40,50};
436

frtabu's avatar
frtabu committed
437
void handle_ulsch_cqi_ri_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_pdu_t *ul_config_pdu,uint16_t frame,uint8_t subframe) {
438 439 440 441 442
  nfapi_ul_config_cqi_ri_information_rel9_t *rel9 = &ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9;
  LTE_eNB_ULSCH_t *ulsch        = eNB->ulsch[UE_id];
  int harq_pid = ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.harq_process_number;
  LTE_UL_eNB_HARQ_t *ulsch_harq = ulsch->harq_processes[harq_pid];

frtabu's avatar
frtabu committed
443
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
444

445
  ulsch_harq->frame                       = frame;
Cedric Roux's avatar
Cedric Roux committed
446
  ulsch_harq->subframe                    = subframe;
447 448
  ulsch_harq->O_RI                        = rel9->aperiodic_cqi_pmi_ri_report.cc[0].ri_size;
  ulsch_harq->Or1                         = rel9->aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[0];
frtabu's avatar
frtabu committed
449

450
  if (ulsch_harq->O_RI>1) ulsch_harq->Or2 = rel9->aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[1];
frtabu's avatar
frtabu committed
451

452 453
  ulsch->beta_offset_ri_times8            = to_beta_offset_ri[rel9->delta_offset_ri];
  ulsch->beta_offset_cqi_times8           = to_beta_offset_cqi[rel9->delta_offset_cqi];
454
  LOG_D(PHY,"Filling ulsch_cqi_ri information for frame %d, subframe %d : O_RI %d, Or1 %d, beta_offset_cqi_times8 %d (%d)\n",
Cedric Roux's avatar
Cedric Roux committed
455 456
        frame,subframe,ulsch_harq->O_RI,ulsch_harq->Or1,ulsch->beta_offset_cqi_times8,
        rel9->delta_offset_cqi);
457 458
}

frtabu's avatar
frtabu committed
459
void handle_ulsch_cqi_harq_ri_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_pdu_t *ul_config_pdu,uint16_t frame,uint8_t subframe) {
460 461 462 463 464 465
  nfapi_ul_config_cqi_ri_information_rel9_t *rel9 = &ul_config_pdu->ulsch_cqi_harq_ri_pdu.cqi_ri_information.cqi_ri_information_rel9;
  LTE_eNB_ULSCH_t *ulsch        = eNB->ulsch[UE_id];
  int harq_pid = ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.harq_process_number;
  LTE_UL_eNB_HARQ_t *ulsch_harq = ulsch->harq_processes[harq_pid];
  nfapi_ul_config_ulsch_harq_information *harq_information = &ul_config_pdu->ulsch_cqi_harq_ri_pdu.harq_information;

frtabu's avatar
frtabu committed
466
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
467

468
  ulsch_harq->frame                       = frame;
Cedric Roux's avatar
Cedric Roux committed
469
  ulsch_harq->subframe                    = subframe;
470 471 472 473 474 475 476 477 478 479 480
  ulsch_harq->O_RI                        = rel9->aperiodic_cqi_pmi_ri_report.cc[0].ri_size;
  ulsch_harq->Or1                         = rel9->aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[0];
  ulsch_harq->O_ACK                       = harq_information->harq_information_rel10.harq_size;

  if (ulsch_harq->O_RI>1) ulsch_harq->Or2 = rel9->aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[1];

  ulsch->beta_offset_harqack_times8       = to_beta_offset_harqack[harq_information->harq_information_rel10.delta_offset_harq];
  ulsch->beta_offset_ri_times8            = to_beta_offset_ri[rel9->delta_offset_ri];
  ulsch->beta_offset_cqi_times8           = to_beta_offset_cqi[rel9->delta_offset_cqi];
}

frtabu's avatar
frtabu committed
481 482
void handle_uci_harq_information(PHY_VARS_eNB *eNB, LTE_eNB_UCI *uci,nfapi_ul_config_harq_information *harq_information) {
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
483

484
  if (eNB->frame_parms.frame_type == FDD) {
Cedric Roux's avatar
Cedric Roux committed
485
    uci->num_pucch_resources = harq_information->harq_information_rel9_fdd.number_of_pucch_resources;
486
    LOG_D(PHY,"Programming UCI HARQ mode %d : size %d in (%d,%d)\n",
Cedric Roux's avatar
Cedric Roux committed
487 488 489
          harq_information->harq_information_rel9_fdd.ack_nack_mode,
          harq_information->harq_information_rel9_fdd.harq_size,
          uci->frame,uci->subframe);
490 491

    if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 0) &&
Cedric Roux's avatar
Cedric Roux committed
492
        (harq_information->harq_information_rel9_fdd.harq_size == 1)) {
493 494 495
      uci->pucch_fmt =  pucch_format1a;
      uci->n_pucch_1[0][0] = harq_information->harq_information_rel9_fdd.n_pucch_1_0;
      uci->n_pucch_1[0][1] = harq_information->harq_information_rel11.n_pucch_2_0;
frtabu's avatar
frtabu committed
496 497
    } else if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 0) &&
               (harq_information->harq_information_rel9_fdd.harq_size == 2)) {
498 499 500
      uci->pucch_fmt =  pucch_format1b;
      uci->n_pucch_1[0][0] = harq_information->harq_information_rel9_fdd.n_pucch_1_0;
      uci->n_pucch_1[0][1] = harq_information->harq_information_rel11.n_pucch_2_0;
frtabu's avatar
frtabu committed
501 502
    } else if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 1) &&
               (harq_information->harq_information_rel9_fdd.harq_size == 2)) {
503 504 505 506 507
      uci->pucch_fmt =  pucch_format1b_csA2;
      uci->n_pucch_1[0][0] = harq_information->harq_information_rel9_fdd.n_pucch_1_0;
      uci->n_pucch_1[0][1] = harq_information->harq_information_rel11.n_pucch_2_0;
      uci->n_pucch_1[1][0] = harq_information->harq_information_rel9_fdd.n_pucch_1_1;
      uci->n_pucch_1[1][1] = harq_information->harq_information_rel11.n_pucch_2_1;
frtabu's avatar
frtabu committed
508 509
    } else if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 1) &&
               (harq_information->harq_information_rel9_fdd.harq_size == 3)) {
510 511 512 513 514 515 516
      uci->pucch_fmt =  pucch_format1b_csA3;
      uci->n_pucch_1[0][0] = harq_information->harq_information_rel9_fdd.n_pucch_1_0;
      uci->n_pucch_1[0][1] = harq_information->harq_information_rel11.n_pucch_2_0;
      uci->n_pucch_1[1][0] = harq_information->harq_information_rel9_fdd.n_pucch_1_1;
      uci->n_pucch_1[1][1] = harq_information->harq_information_rel11.n_pucch_2_1;
      uci->n_pucch_1[2][0] = harq_information->harq_information_rel9_fdd.n_pucch_1_2;
      uci->n_pucch_1[2][1] = harq_information->harq_information_rel11.n_pucch_2_2;
frtabu's avatar
frtabu committed
517 518
    } else if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 1) &&
               (harq_information->harq_information_rel9_fdd.harq_size == 4)) {
519 520 521 522 523 524 525
      uci->pucch_fmt =  pucch_format1b_csA4;
      uci->n_pucch_1[0][0] = harq_information->harq_information_rel9_fdd.n_pucch_1_0;
      uci->n_pucch_1[0][1] = harq_information->harq_information_rel11.n_pucch_2_0;
      uci->n_pucch_1[1][0] = harq_information->harq_information_rel9_fdd.n_pucch_1_1;
      uci->n_pucch_1[1][1] = harq_information->harq_information_rel11.n_pucch_2_1;
      uci->n_pucch_1[2][0] = harq_information->harq_information_rel9_fdd.n_pucch_1_2;
      uci->n_pucch_1[2][1] = harq_information->harq_information_rel11.n_pucch_2_2;
frtabu's avatar
frtabu committed
526
    } else if (harq_information->harq_information_rel9_fdd.ack_nack_mode == 2) {
527 528 529
      uci->pucch_fmt =  pucch_format3;
      uci->n_pucch_3[0] = harq_information->harq_information_rel9_fdd.n_pucch_1_0;
      uci->n_pucch_3[1] = harq_information->harq_information_rel11.n_pucch_2_0;
frtabu's avatar
frtabu committed
530 531
    } else AssertFatal(1==0,"unsupported FDD HARQ mode %d size %d\n",harq_information->harq_information_rel9_fdd.ack_nack_mode,harq_information->harq_information_rel9_fdd.harq_size);
  } else { // TDD
Cedric Roux's avatar
Cedric Roux committed
532
    uci->num_pucch_resources = harq_information->harq_information_rel10_tdd.number_of_pucch_resources;
533 534 535 536 537 538

    if (harq_information->harq_information_rel10_tdd.ack_nack_mode == 0) {//bundling
      uci->pucch_fmt =  harq_information->harq_information_rel10_tdd.harq_size==1 ? pucch_format1a : pucch_format1b;
      uci->tdd_bundling = 1;
      uci->n_pucch_1[0][0] = harq_information->harq_information_rel10_tdd.n_pucch_1_0;
      uci->n_pucch_1[0][1] = harq_information->harq_information_rel11.n_pucch_2_0;
frtabu's avatar
frtabu committed
539 540
    } else if ((harq_information->harq_information_rel10_tdd.ack_nack_mode == 1) && //multiplexing
               (uci->num_pucch_resources == 1)) {
541 542 543 544
      uci->pucch_fmt = harq_information->harq_information_rel10_tdd.harq_size==1 ? pucch_format1a : pucch_format1b;
      uci->tdd_bundling = 0;
      uci->n_pucch_1[0][0] = harq_information->harq_information_rel10_tdd.n_pucch_1_0;
      uci->n_pucch_1[0][1] = harq_information->harq_information_rel11.n_pucch_2_0;
frtabu's avatar
frtabu committed
545 546
    } else if ((harq_information->harq_information_rel10_tdd.ack_nack_mode == 1) && //multiplexing M>1
               (uci->num_pucch_resources > 1)) {
547 548 549 550 551 552 553 554 555 556
      uci->pucch_fmt = pucch_format1b;
      uci->tdd_bundling = 0;
      uci->n_pucch_1[0][0] = harq_information->harq_information_rel10_tdd.n_pucch_1_0;
      uci->n_pucch_1[0][1] = harq_information->harq_information_rel11.n_pucch_2_0;
      uci->n_pucch_1[1][0] = harq_information->harq_information_rel10_tdd.n_pucch_1_1;
      uci->n_pucch_1[1][1] = harq_information->harq_information_rel11.n_pucch_2_1;
      uci->n_pucch_1[2][0] = harq_information->harq_information_rel10_tdd.n_pucch_1_2;
      uci->n_pucch_1[2][1] = harq_information->harq_information_rel11.n_pucch_2_2;
      uci->n_pucch_1[3][0] = harq_information->harq_information_rel10_tdd.n_pucch_1_3;
      uci->n_pucch_1[3][1] = harq_information->harq_information_rel11.n_pucch_2_3;
frtabu's avatar
frtabu committed
557
    } else if (harq_information->harq_information_rel10_tdd.ack_nack_mode == 2) {
558 559 560
      uci->pucch_fmt =  pucch_format3;
      uci->n_pucch_3[0] = harq_information->harq_information_rel10_tdd.n_pucch_1_0;
      uci->n_pucch_3[1] = harq_information->harq_information_rel11.n_pucch_2_0;
frtabu's avatar
frtabu committed
561
    } else AssertFatal(1==0,"unsupported HARQ mode %d\n",harq_information->harq_information_rel10_tdd.ack_nack_mode);
562 563 564
  }
}

565 566 567 568 569
void handle_uci_sr_pdu(PHY_VARS_eNB *eNB,
                       int UE_id,
                       nfapi_ul_config_request_pdu_t *ul_config_pdu,
                       uint16_t frame,
                       uint8_t subframe,
570
                       uint8_t srs_active) {
571 572
  LTE_eNB_UCI *uci = &eNB->uci_vars[UE_id];

frtabu's avatar
frtabu committed
573
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
574

575 576 577
  uci->frame               = frame;
  uci->subframe            = subframe;
  uci->rnti                = ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti;
578
  uci->ue_id               = find_dlsch(ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti,eNB,SEARCH_EXIST_OR_FREE);
579 580 581 582 583 584 585
  uci->type                = SR;
  uci->pucch_fmt           = pucch_format1;
  uci->num_antenna_ports   = 1;
  uci->num_pucch_resources = 1;
  uci->n_pucch_1_0_sr[0]   = ul_config_pdu->uci_sr_pdu.sr_information.sr_information_rel8.pucch_index;
  uci->srs_active          = srs_active;
  uci->active              = 1;
586
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
sharma's avatar
sharma committed
587 588 589 590
  uci->ue_type                     = ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel13.ue_type;
  uci->empty_symbols               = ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel13.empty_symbols;
  uci->total_repetitions = ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel13.total_number_of_repetitions;
#endif
591
  LOG_D(PHY,"Programming UCI SR rnti %x, pucch1_0 %d for (%d,%d)\n",
592 593 594 595
        uci->rnti,
        uci->n_pucch_1_0_sr[0],
        frame,
        subframe);
596 597
}

frtabu's avatar
frtabu committed
598
void handle_uci_sr_harq_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_pdu_t *ul_config_pdu,uint16_t frame,uint8_t subframe,uint8_t srs_active) {
599 600
  LTE_eNB_UCI *uci = &eNB->uci_vars[UE_id];

frtabu's avatar
frtabu committed
601
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
602

603 604 605
  uci->frame               = frame;
  uci->subframe            = subframe;
  uci->rnti                = ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti;
606
  uci->ue_id               = find_dlsch(ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti,eNB,SEARCH_EXIST_OR_FREE);
607 608 609
  uci->type                = HARQ_SR;
  uci->num_antenna_ports   = 1;
  uci->num_pucch_resources = 1;
610
  uci->n_pucch_1_0_sr[0]   = ul_config_pdu->uci_sr_harq_pdu.sr_information.sr_information_rel8.pucch_index;
611 612
  uci->srs_active          = srs_active;
  uci->active              = 1;
613
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
sharma's avatar
sharma committed
614 615 616 617
  uci->ue_type                     = ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel13.ue_type;
  uci->empty_symbols               = ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel13.empty_symbols;
  uci->total_repetitions = ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel13.total_number_of_repetitions;
#endif
618 619 620
  handle_uci_harq_information(eNB,uci,&ul_config_pdu->uci_sr_harq_pdu.harq_information);
}

frtabu's avatar
frtabu committed
621
void handle_uci_harq_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_pdu_t *ul_config_pdu,uint16_t frame,uint8_t subframe,uint8_t srs_active) {
622 623
  LTE_eNB_UCI *uci = &eNB->uci_vars[UE_id];

frtabu's avatar
frtabu committed
624
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
625

626
  LOG_D(PHY,"Frame %d, Subframe %d: Programming UCI_HARQ process (type %d)\n",frame,subframe,HARQ);
627 628 629
  uci->frame             = frame;
  uci->subframe          = subframe;
  uci->rnti              = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti;
630
  uci->ue_id             = find_dlsch(ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti,eNB,SEARCH_EXIST_OR_FREE);
631 632 633
  uci->type              = HARQ;
  uci->srs_active        = srs_active;
  uci->num_antenna_ports = ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel11.num_ant_ports;
634
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
sharma's avatar
sharma committed
635 636 637 638
  uci->ue_type                     = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.ue_type;
  uci->empty_symbols               = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.empty_symbols;
  uci->total_repetitions           = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.total_number_of_repetitions;
#endif
639 640 641 642
  handle_uci_harq_information(eNB,uci,&ul_config_pdu->uci_harq_pdu.harq_information);
  uci->active=1;
}

frtabu's avatar
frtabu committed
643
void handle_srs_pdu(PHY_VARS_eNB *eNB,nfapi_ul_config_request_pdu_t *ul_config_pdu,uint16_t frame,uint8_t subframe) {
644 645
  int i;

frtabu's avatar
frtabu committed
646
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
Cedric Roux's avatar
Cedric Roux committed
647

frtabu's avatar
frtabu committed
648
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
649
    if (eNB->soundingrs_ul_config_dedicated[i].active==1) continue;
Cedric Roux's avatar
Cedric Roux committed
650

651 652 653 654 655 656 657 658 659 660
    eNB->soundingrs_ul_config_dedicated[i].active               = 1;
    eNB->soundingrs_ul_config_dedicated[i].frame                = frame;
    eNB->soundingrs_ul_config_dedicated[i].subframe             = subframe;
    eNB->soundingrs_ul_config_dedicated[i].rnti                 = ul_config_pdu->srs_pdu.srs_pdu_rel8.rnti;
    eNB->soundingrs_ul_config_dedicated[i].srs_Bandwidth        = ul_config_pdu->srs_pdu.srs_pdu_rel8.srs_bandwidth;
    eNB->soundingrs_ul_config_dedicated[i].srs_HoppingBandwidth = ul_config_pdu->srs_pdu.srs_pdu_rel8.srs_hopping_bandwidth;
    eNB->soundingrs_ul_config_dedicated[i].freqDomainPosition   = ul_config_pdu->srs_pdu.srs_pdu_rel8.frequency_domain_position;
    eNB->soundingrs_ul_config_dedicated[i].transmissionComb     = ul_config_pdu->srs_pdu.srs_pdu_rel8.transmission_comb;
    eNB->soundingrs_ul_config_dedicated[i].srs_ConfigIndex      = ul_config_pdu->srs_pdu.srs_pdu_rel8.i_srs;
    eNB->soundingrs_ul_config_dedicated[i].cyclicShift          = ul_config_pdu->srs_pdu.srs_pdu_rel8.sounding_reference_cyclic_shift;
Cedric Roux's avatar
Cedric Roux committed
661
    break;
662
  }
frtabu's avatar
frtabu committed
663

664 665 666
  AssertFatal(i<NUMBER_OF_UE_MAX,"No room for SRS processing\n");
}

667
void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
Cedric Roux's avatar
Cedric Roux committed
668
                         nfapi_ul_config_request_pdu_t *ul_config_pdu,
frtabu's avatar
frtabu committed
669
                         uint16_t frame,uint8_t subframe,uint8_t srs_present) {
670
  nfapi_ul_config_ulsch_pdu_rel8_t *rel8 = &ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
671
  int16_t UE_id;
672

frtabu's avatar
frtabu committed
673
  if (NFAPI_MODE==NFAPI_MODE_VNF) return;
674

675 676 677
  // check if we have received a dci for this ue and ulsch descriptor is configured

  if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE) {
678
    //if (UE_id == find_ulsch(ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.rnti,eNB,SEARCH_EXIST_OR_FREE)<0)
frtabu's avatar
frtabu committed
679
    //for (int i=0;i<16;i++) if (eNB->ulsch[i]->harq_mask>0) LOG_I(PHY,"rnti %x, mask %x\n",eNB->ulsch[i]->rnti,eNB->ulsch[i]->harq_mask >0);
Raymond Knopp's avatar
Raymond Knopp committed
680
    AssertFatal((UE_id = find_ulsch(ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.rnti,eNB,SEARCH_EXIST_OR_FREE))>=0,
Cedric Roux's avatar
Cedric Roux committed
681
                "No existing UE ULSCH for rnti %x\n",rel8->rnti);
frtabu's avatar
frtabu committed
682 683 684
    LOG_D(PHY,"Applying UL config for UE %d, rnti %x for frame %d, subframe %d, modulation %d, rvidx %d, first_rb %d, nb_rb %d\n", UE_id,rel8->rnti,frame,subframe,rel8->modulation_type,
          rel8->redundancy_version,
          rel8->resource_block_start,rel8->number_of_resource_blocks);
Wang Tsu-Han's avatar
Wang Tsu-Han committed
685
    fill_ulsch(eNB,UE_id,&ul_config_pdu->ulsch_pdu,frame,subframe);
frtabu's avatar
frtabu committed
686
  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE) {
687
    AssertFatal((UE_id = find_ulsch(ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti,eNB,SEARCH_EXIST_OR_FREE))>=0,
Cedric Roux's avatar
Cedric Roux committed
688
                "No available UE ULSCH for rnti %x\n",ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti);
Wang Tsu-Han's avatar
Wang Tsu-Han committed
689
    fill_ulsch(eNB,UE_id,&ul_config_pdu->ulsch_harq_pdu.ulsch_pdu,frame,subframe);
690
    handle_ulsch_harq_pdu(eNB, UE_id, ul_config_pdu,
frtabu's avatar
frtabu committed
691 692
                          &ul_config_pdu->ulsch_harq_pdu.harq_information, frame, subframe);
  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE) {
693
    AssertFatal((UE_id = find_ulsch(ul_config_pdu->ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti,
Cedric Roux's avatar
Cedric Roux committed
694 695
                                    eNB,SEARCH_EXIST_OR_FREE))>=0,
                "No available UE ULSCH for rnti %x\n",ul_config_pdu->ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti);
Wang Tsu-Han's avatar
Wang Tsu-Han committed
696
    fill_ulsch(eNB,UE_id,&ul_config_pdu->ulsch_cqi_ri_pdu.ulsch_pdu,frame,subframe);
697
    handle_ulsch_cqi_ri_pdu(eNB,UE_id,ul_config_pdu,frame,subframe);
frtabu's avatar
frtabu committed
698
  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE) {
699
    AssertFatal((UE_id = find_ulsch(ul_config_pdu->ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti,
Cedric Roux's avatar
Cedric Roux committed
700 701
                                    eNB,SEARCH_EXIST_OR_FREE))>=0,
                "No available UE ULSCH for rnti %x\n",ul_config_pdu->ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti);
Wang Tsu-Han's avatar
Wang Tsu-Han committed
702
    fill_ulsch(eNB,UE_id,&ul_config_pdu->ulsch_cqi_harq_ri_pdu.ulsch_pdu,frame,subframe);
703
    handle_ulsch_cqi_harq_ri_pdu(eNB,UE_id,ul_config_pdu,frame,subframe);
704
    handle_ulsch_harq_pdu(eNB, UE_id, ul_config_pdu,
frtabu's avatar
frtabu committed
705 706
                          &ul_config_pdu->ulsch_cqi_harq_ri_pdu.harq_information, frame, subframe);
  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) {
707
    AssertFatal((UE_id = find_uci(ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti,
Cedric Roux's avatar
Cedric Roux committed
708 709
                                  proc->frame_tx,proc->subframe_tx,eNB,SEARCH_EXIST_OR_FREE))>=0,
                "No available UE UCI for rnti %x\n",ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti);
nepes's avatar
nepes committed
710
    LOG_D(PHY,"Applying UL UCI_HARQ config for UE %d, rnti %x for frame %d, subframe %d\n",
sharma's avatar
sharma committed
711
          UE_id,ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti,frame,subframe);
712
    handle_uci_harq_pdu(eNB,UE_id,ul_config_pdu,frame,subframe,srs_present);
frtabu's avatar
frtabu committed
713
  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE) {
714
    AssertFatal(1==0,"NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE not handled yet\n");
frtabu's avatar
frtabu committed
715
  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE) {
716
    AssertFatal(1==0,"NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE not handled yet\n");
frtabu's avatar
frtabu committed
717
  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE) {
718
    AssertFatal(1==0,"NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE not handled yet\n");
frtabu's avatar
frtabu committed
719
  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE) {
720
    AssertFatal((UE_id = find_uci(ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti,
Cedric Roux's avatar
Cedric Roux committed
721 722
                                  proc->frame_tx,proc->subframe_tx,eNB,SEARCH_EXIST_OR_FREE))>=0,
                "No available UE UCI for rnti %x\n",ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti);
723
    handle_uci_sr_pdu(eNB,UE_id,ul_config_pdu,frame,subframe,srs_present);
frtabu's avatar
frtabu committed
724
  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE) {
725
    AssertFatal((UE_id = find_uci(rel8->rnti,proc->frame_tx,proc->subframe_tx,eNB,SEARCH_EXIST_OR_FREE))>=0,
Cedric Roux's avatar
Cedric Roux committed
726
                "No available UE UCI for rnti %x\n",ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti);
727
    handle_uci_sr_harq_pdu(eNB,UE_id,ul_config_pdu,frame,subframe,srs_present);
frtabu's avatar
frtabu committed
728
  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_SRS_PDU_TYPE) {
729 730 731 732
    handle_srs_pdu(eNB,ul_config_pdu,frame,subframe);
  }
}

frtabu's avatar
frtabu committed
733
void schedule_response(Sched_Rsp_t *Sched_INFO) {
734
  PHY_VARS_eNB *eNB;
735
  L1_rxtx_proc_t *proc;
736 737 738 739 740 741 742 743 744 745
  // copy data from L2 interface into L1 structures
  module_id_t               Mod_id       = Sched_INFO->module_id;
  uint8_t                   CC_id        = Sched_INFO->CC_id;
  nfapi_dl_config_request_t *DL_req      = Sched_INFO->DL_req;
  nfapi_hi_dci0_request_t   *HI_DCI0_req = Sched_INFO->HI_DCI0_req;
  nfapi_ul_config_request_t *UL_req      = Sched_INFO->UL_req;
  nfapi_tx_request_t        *TX_req      = Sched_INFO->TX_req;
  frame_t                   frame        = Sched_INFO->frame;
  sub_frame_t               subframe     = Sched_INFO->subframe;
  LTE_DL_FRAME_PARMS        *fp;
746
  uint8_t                   ul_subframe;
747 748 749 750 751 752 753 754
  int                       ul_frame;
  int                       harq_pid;
  LTE_UL_eNB_HARQ_t         *ulsch_harq;
  AssertFatal(RC.eNB!=NULL,"RC.eNB is null\n");
  AssertFatal(RC.eNB[Mod_id]!=NULL,"RC.eNB[%d] is null\n",Mod_id);
  AssertFatal(RC.eNB[Mod_id][CC_id]!=NULL,"RC.eNB[%d][%d] is null\n",Mod_id,CC_id);
  eNB         = RC.eNB[Mod_id][CC_id];
  fp          = &eNB->frame_parms;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
755
  proc        = &eNB->proc.L1_proc;
756 757
  /* TODO: check that following line is correct - in the meantime it is disabled */
  //if ((fp->frame_type == TDD) && (subframe_select(fp,subframe)==SF_UL)) return;
758 759
  ul_subframe = pdcch_alloc2ul_subframe(fp,subframe);
  ul_frame    = pdcch_alloc2ul_frame(fp,frame,subframe);
760 761 762 763
  // DJP - subframe assert will fail - not sure why yet
  // DJP - AssertFatal(proc->subframe_tx == subframe, "Current subframe %d != NFAPI subframe %d\n",proc->subframe_tx,subframe);
  // DJP - AssertFatal(proc->subframe_tx == subframe, "Current frame %d != NFAPI frame %d\n",proc->frame_tx,frame);
  uint8_t number_pdcch_ofdm_symbols = DL_req->dl_config_request_body.number_pdcch_ofdm_symbols;
764 765
  uint8_t number_dl_pdu             = DL_req->dl_config_request_body.number_pdu;
  uint8_t number_hi_dci0_pdu        = HI_DCI0_req->hi_dci0_request_body.number_of_dci+HI_DCI0_req->hi_dci0_request_body.number_of_hi;
766
  uint8_t number_ul_pdu             = UL_req!=NULL ? UL_req->ul_config_request_body.number_of_pdus : 0;
767 768 769 770
  nfapi_dl_config_request_pdu_t *dl_config_pdu;
  nfapi_hi_dci0_request_pdu_t   *hi_dci0_req_pdu;
  nfapi_ul_config_request_pdu_t *ul_config_pdu;
  int i;
771
  eNB->pdcch_vars[subframe&1].num_pdcch_symbols = number_pdcch_ofdm_symbols;
772 773
  eNB->pdcch_vars[subframe&1].num_dci           = 0;
  eNB->phich_vars[subframe&1].num_hi            = 0;
774
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
775 776
  eNB->mpdcch_vars[subframe&1].num_dci           = 0;
#endif
Wang Tsu-Han's avatar
Wang Tsu-Han committed
777
  LOG_D(PHY,"NFAPI: Sched_INFO:SFN/SF:%04d%d DL_req:SFN/SF:%04d%d:dl_pdu:%d tx_req:SFN/SF:%04d%d:pdus:%d\n",
frtabu's avatar
frtabu committed
778 779 780
        frame,subframe,
        NFAPI_SFNSF2SFN(DL_req->sfn_sf),NFAPI_SFNSF2SF(DL_req->sfn_sf),number_dl_pdu,
        NFAPI_SFNSF2SFN(TX_req->sfn_sf),NFAPI_SFNSF2SF(TX_req->sfn_sf),TX_req->tx_request_body.number_of_pdus
Wang Tsu-Han's avatar
Wang Tsu-Han committed
781 782 783 784
       );
  LOG_D(PHY,"NFAPI: hi_dci0:SFN/SF:%04d%d:pdus:%d\n",
        NFAPI_SFNSF2SFN(HI_DCI0_req->sfn_sf),NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf),number_hi_dci0_pdu
       );
frtabu's avatar
frtabu committed
785

Wang Tsu-Han's avatar
Wang Tsu-Han committed
786
  if(UL_req!=NULL)
787
    LOG_D(PHY,"NFAPI: ul_cfg:SFN/SF:%04d%d:pdus:%d num_pdcch_symbols:%d\n",
Wang Tsu-Han's avatar
Wang Tsu-Han committed
788 789
          NFAPI_SFNSF2SFN(UL_req->sfn_sf),NFAPI_SFNSF2SF(UL_req->sfn_sf),number_ul_pdu,
          eNB->pdcch_vars[subframe&1].num_pdcch_symbols);
Cedric Roux's avatar
Cedric Roux committed
790

791 792
  int do_oai =0;
  int dont_send =0;
frtabu's avatar
frtabu committed
793

794 795 796 797
  /* TODO: check the following test - in the meantime it is put back as it was before */
  //if ((ul_subframe<10)&&
  //    (subframe_select(fp,ul_subframe)==SF_UL)) { // This means that there is an ul_subframe that can be configured here
  if (ul_subframe<10) { // This means that there is an ul_subframe that can be configured here
798
    LOG_D(PHY,"NFAPI: Clearing dci allocations for potential UL subframe %d\n",ul_subframe);
799 800 801
    harq_pid = subframe2harq_pid(fp,ul_frame,ul_subframe);

    // clear DCI allocation maps for new subframe
802
    if (NFAPI_MODE!=NFAPI_MODE_VNF)
803 804 805 806 807 808
      for (i=0; i<NUMBER_OF_UE_MAX; i++) {
        if (eNB->ulsch[i]) {
          ulsch_harq = eNB->ulsch[i]->harq_processes[harq_pid];
          ulsch_harq->dci_alloc=0;
          ulsch_harq->rar_alloc=0;
        }
809 810
      }
  }
frtabu's avatar
frtabu committed
811 812

  for (i=0; i<number_dl_pdu; i++) {
813
    dl_config_pdu = &DL_req->dl_config_request_body.dl_config_pdu_list[i];
frtabu's avatar
frtabu committed
814

815
    //LOG_D(PHY,"NFAPI: dl_pdu %d : type %d\n",i,dl_config_pdu->pdu_type);
816
    switch (dl_config_pdu->pdu_type) {
frtabu's avatar
frtabu committed
817
      case NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE:
818 819
        if (NFAPI_MODE!=NFAPI_MODE_VNF)
          handle_nfapi_dci_dl_pdu(eNB,NFAPI_SFNSF2SFN(DL_req->sfn_sf),NFAPI_SFNSF2SF(DL_req->sfn_sf),proc,dl_config_pdu);
820

frtabu's avatar
frtabu committed
821 822 823 824 825 826 827 828 829 830 831 832
        eNB->pdcch_vars[NFAPI_SFNSF2SF(DL_req->sfn_sf)&1].num_dci++;
        //LOG_E(PHY,"Incremented num_dci:%d but already set??? dl_config:num_dci:%d\n", eNB->pdcch_vars[subframe&1].num_dci, number_dci);
        do_oai=1;
        break;

      case NFAPI_DL_CONFIG_BCH_PDU_TYPE:
        AssertFatal(dl_config_pdu->bch_pdu.bch_pdu_rel8.pdu_index<TX_req->tx_request_body.number_of_pdus,
                    "bch_pdu_rel8.pdu_index>=TX_req->number_of_pdus (%d>%d)\n",
                    dl_config_pdu->bch_pdu.bch_pdu_rel8.pdu_index,
                    TX_req->tx_request_body.number_of_pdus);
        eNB->pbch_configured=1;
        do_oai=1;
833

frtabu's avatar
frtabu committed
834 835
        //LOG_D(PHY,"%s() NFAPI_DL_CONFIG_BCH_PDU_TYPE TX:%d/%d RX:%d/%d TXREQ:%d/%d\n",
        //__FUNCTION__, proc->frame_tx, proc->subframe_tx, proc->frame_rx, proc->subframe_rx, NFAPI_SFNSF2SFN(TX_req->sfn_sf), NFAPI_SFNSF2SF(TX_req->sfn_sf));
836 837
        if (NFAPI_MODE!=NFAPI_MODE_VNF)
          handle_nfapi_bch_pdu(eNB,proc,dl_config_pdu,
838 839
                               TX_req->tx_request_body.tx_pdu_list[dl_config_pdu->bch_pdu.bch_pdu_rel8.pdu_index].segments[0].segment_data);

frtabu's avatar
frtabu committed
840 841 842 843 844 845 846
        break;

      case NFAPI_DL_CONFIG_MCH_PDU_TYPE:
        //      handle_nfapi_mch_dl_pdu(eNB,dl_config_pdu);
        break;

      case NFAPI_DL_CONFIG_DLSCH_PDU_TYPE: {
847 848 849 850 851
        nfapi_dl_config_dlsch_pdu_rel8_t *dlsch_pdu_rel8 = &dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8;
        uint16_t pdu_index = dlsch_pdu_rel8->pdu_index;
        uint16_t tx_pdus = TX_req->tx_request_body.number_of_pdus;
        uint16_t invalid_pdu = pdu_index == -1;
        uint8_t *sdu = invalid_pdu ? NULL : pdu_index >= tx_pdus ? NULL : TX_req->tx_request_body.tx_pdu_list[pdu_index].segments[0].segment_data;
frtabu's avatar
frtabu committed
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
        LOG_D(PHY,"%s() [PDU:%d] NFAPI_DL_CONFIG_DLSCH_PDU_TYPE SFN/SF:%04d%d TX:%d/%d RX:%d/%d transport_blocks:%d pdu_index:%d sdu:%p\n",
              __FUNCTION__, i,
              NFAPI_SFNSF2SFN(DL_req->sfn_sf),NFAPI_SFNSF2SF(DL_req->sfn_sf),
              proc->frame_tx, proc->subframe_tx,
              proc->frame_rx, proc->subframe_rx,
              dlsch_pdu_rel8->transport_blocks, pdu_index, sdu);
        /*
        AssertFatal(dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index<TX_req->tx_request_body.number_of_pdus,
                    "dlsch_pdu_rel8.pdu_index>=TX_req->number_of_pdus (%d>%d)\n",
                    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index,
                    TX_req->tx_request_body.number_of_pdus);
        */
        AssertFatal((dlsch_pdu_rel8->transport_blocks<3) &&
                    (dlsch_pdu_rel8->transport_blocks>0),
                    "dlsch_pdu_rel8->transport_blocks = %d not in [1,2]\n",
                    dlsch_pdu_rel8->transport_blocks);

        if (1) { //sdu != NULL)
870 871
          if (NFAPI_MODE!=NFAPI_MODE_VNF)
            handle_nfapi_dlsch_pdu(eNB,NFAPI_SFNSF2SFN(DL_req->sfn_sf),NFAPI_SFNSF2SF(DL_req->sfn_sf),proc,dl_config_pdu, dlsch_pdu_rel8->transport_blocks-1, sdu);
frtabu's avatar
frtabu committed
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
        } else {
          dont_send=1;
          LOG_E(MAC,"%s() NFAPI_DL_CONFIG_DLSCH_PDU_TYPE sdu is NULL DL_CFG:SFN/SF:%d:pdu_index:%d TX_REQ:SFN/SF:%d:pdus:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(DL_req->sfn_sf), pdu_index,
                NFAPI_SFNSF2DEC(TX_req->sfn_sf), tx_pdus);
        }

        // Send the data first so that the DL_CONFIG can just pluck it out of the buffer
        // DJP - OAI was here - moved to bottom
        do_oai=1;
        /*
        if (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti == eNB->preamble_list[0].preamble_rel8.rnti) {// is RAR pdu

          LOG_D(PHY,"Frame %d, Subframe %d: Received LTE RAR pdu, programming based on UL Grant\n",frame,subframe);
          generate_eNB_ulsch_params_from_rar(eNB,
                                             TX_req->tx_request_body.tx_pdu_list[dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data,
                                             frame,
                                             subframe);

                                             }        */
891
      }
frtabu's avatar
frtabu committed
892
      break;
893

frtabu's avatar
frtabu committed
894 895 896
      case NFAPI_DL_CONFIG_PCH_PDU_TYPE:
        //      handle_nfapi_pch_pdu(eNB,dl_config_pdu);
        break;
897

frtabu's avatar
frtabu committed
898 899 900
      case NFAPI_DL_CONFIG_PRS_PDU_TYPE:
        //      handle_nfapi_prs_pdu(eNB,dl_config_pdu);
        break;
901

frtabu's avatar
frtabu committed
902 903 904
      case NFAPI_DL_CONFIG_CSI_RS_PDU_TYPE:
        //      handle_nfapi_csi_rs_pdu(eNB,dl_config_pdu);
        break;
Cedric Roux's avatar
Cedric Roux committed
905

frtabu's avatar
frtabu committed
906 907 908
      case NFAPI_DL_CONFIG_EPDCCH_DL_PDU_TYPE:
        //      handle_nfapi_epdcch_pdu(eNB,dl_config_pdu);
        break;
909
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
frtabu's avatar
frtabu committed
910 911

      case NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE:
912 913
        if (NFAPI_MODE!=NFAPI_MODE_VNF)
          handle_nfapi_mpdcch_pdu(eNB,proc,dl_config_pdu);
914

frtabu's avatar
frtabu committed
915 916 917
        eNB->mpdcch_vars[subframe&1].num_dci++;
        break;
#endif
918 919
    }
  }
920

frtabu's avatar
frtabu committed
921
  if ((NFAPI_MODE!=NFAPI_MONOLITHIC) && do_oai && !dont_send) {
922
    if(Sched_INFO->TX_req->tx_request_body.number_of_pdus > 0) {
923
      Sched_INFO->TX_req->sfn_sf = frame << 4 | subframe;
924 925
      oai_nfapi_tx_req(Sched_INFO->TX_req);
    }
926

927
    Sched_INFO->DL_req->sfn_sf = frame << 4 | subframe;
928
    oai_nfapi_dl_config_req(Sched_INFO->DL_req); // DJP - .dl_config_request_body.dl_config_pdu_list[0]); // DJP - FIXME TODO - yuk - only copes with 1 pdu
929 930
    Sched_INFO->UE_release_req->sfn_sf = frame << 4 | subframe;
    oai_nfapi_ue_release_req(Sched_INFO->UE_release_req);
931 932
  }

frtabu's avatar
frtabu committed
933
  if ((NFAPI_MODE!=NFAPI_MONOLITHIC) && number_hi_dci0_pdu!=0) {
934
    HI_DCI0_req->sfn_sf = frame << 4 | subframe;
935 936 937 938
    oai_nfapi_hi_dci0_req(HI_DCI0_req);
    eNB->pdcch_vars[NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf)&1].num_dci=0;
    eNB->pdcch_vars[NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf)&1].num_pdcch_symbols=0;
  }
Cedric Roux's avatar
Cedric Roux committed
939

940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
  if (NFAPI_MODE!=NFAPI_MODE_VNF)
    for (i=0; i<number_hi_dci0_pdu; i++) {
      hi_dci0_req_pdu = &HI_DCI0_req->hi_dci0_request_body.hi_dci0_pdu_list[i];
      LOG_D(PHY,"NFAPI: hi_dci0_pdu %d : type %d\n",i,hi_dci0_req_pdu->pdu_type);

      switch (hi_dci0_req_pdu->pdu_type) {
        case NFAPI_HI_DCI0_DCI_PDU_TYPE:
          handle_nfapi_hi_dci0_dci_pdu(eNB,NFAPI_SFNSF2SFN(HI_DCI0_req->sfn_sf),NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf),proc,hi_dci0_req_pdu);
          eNB->pdcch_vars[NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf)&1].num_dci++;
          break;

        case NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE:
          handle_nfapi_hi_dci0_mpdcch_dci_pdu(eNB,proc,hi_dci0_req_pdu);
          eNB->mpdcch_vars[subframe&1].num_dci++;
          break;

        case NFAPI_HI_DCI0_HI_PDU_TYPE:
          handle_nfapi_hi_dci0_hi_pdu(eNB,NFAPI_SFNSF2SFN(HI_DCI0_req->sfn_sf),NFAPI_SFNSF2SF(HI_DCI0_req->sfn_sf),proc,hi_dci0_req_pdu);
          break;
      }
960 961
    }

frtabu's avatar
frtabu committed
962 963
  if (NFAPI_MODE!=NFAPI_MONOLITHIC) {
    if (number_ul_pdu>0) {
964
      //LOG_D(PHY, "UL_CONFIG to send to PNF\n");
965
      UL_req->sfn_sf = frame << 4 | subframe;
966 967 968 969
      oai_nfapi_ul_config_req(UL_req);
      UL_req->ul_config_request_body.number_of_pdus=0;
      number_ul_pdu=0;
    }
frtabu's avatar
frtabu committed
970 971
  } else {
    for (i=0; i<number_ul_pdu; i++) {
972
      ul_config_pdu = &UL_req->ul_config_request_body.ul_config_pdu_list[i];
973
      LOG_D(PHY,"NFAPI: ul_pdu %d : type %d\n",i,ul_config_pdu->pdu_type);
974
      AssertFatal(ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE ||
frtabu's avatar
frtabu committed
975 976 977 978 979 980 981 982
                  ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE ||
                  ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE ||
                  ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE ||
                  ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE ||
                  ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE ||
                  ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE
                  ,
                  "Optional UL_PDU type %d not supported\n",ul_config_pdu->pdu_type);
983 984
      handle_nfapi_ul_pdu(eNB,proc,ul_config_pdu,UL_req->sfn_sf>>4,UL_req->sfn_sf&0xf,UL_req->ul_config_request_body.srs_present);
    }
985 986
  }
}
987 988 989

/*Dummy functions*/

frtabu's avatar
frtabu committed
990 991
int memcpy_dl_config_req (nfapi_pnf_p7_config_t *pnf_p7, nfapi_dl_config_request_t *req) {
  return 0;
992 993
}

frtabu's avatar
frtabu committed
994 995
int memcpy_ul_config_req (nfapi_pnf_p7_config_t *pnf_p7, nfapi_ul_config_request_t *req) {
  return 0;
996 997
}

frtabu's avatar
frtabu committed
998 999
int memcpy_hi_dci0_req (nfapi_pnf_p7_config_t *pnf_p7, nfapi_hi_dci0_request_t *req) {
  return 0;
1000 1001
}

frtabu's avatar
frtabu committed
1002 1003
int memcpy_tx_req (nfapi_pnf_p7_config_t *pnf_p7, nfapi_tx_request_t *req) {
  return 0;
1004
}