IF_Module.c 25.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#include "openair1/PHY/defs.h"
#include "openair2/PHY_INTERFACE/IF_Module.h"
#include "openair1/PHY/extern.h"
#include "LAYER2/MAC/extern.h"
#include "LAYER2/MAC/proto.h"
#include "common/ran_context.h"

#define MAX_IF_MODULES 100

IF_Module_t *if_inst[MAX_IF_MODULES];
Sched_Rsp_t Sched_INFO[MAX_IF_MODULES][MAX_NUM_CCs];

13 14 15 16
extern int oai_nfapi_harq_indication(nfapi_harq_indication_t *harq_ind);
extern int oai_nfapi_crc_indication(nfapi_crc_indication_t *crc_ind);
extern int oai_nfapi_cqi_indication(nfapi_cqi_indication_t *cqi_ind);
extern int oai_nfapi_rx_ind(nfapi_rx_indication_t *ind);
17
extern uint8_t nfapi_mode;
18

19
void handle_rach(UL_IND_t *UL_info) {
20
  int i;
21 22 23 24 25

  if (UL_info->rach_ind.number_of_preambles>0) {

    AssertFatal(UL_info->rach_ind.number_of_preambles==1,"More than 1 preamble not supported\n");
    UL_info->rach_ind.number_of_preambles=0;
26
    LOG_E(MAC,"Frame %d, Subframe %d Calling initiate_ra_proc\n",UL_info->frame,UL_info->subframe);
27 28 29 30 31 32
    initiate_ra_proc(UL_info->module_id,
		     UL_info->CC_id,
		     UL_info->frame,
		     UL_info->subframe,
		     UL_info->rach_ind.preamble_list[0].preamble_rel8.preamble,
		     UL_info->rach_ind.preamble_list[0].preamble_rel8.timing_advance,
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
		     UL_info->rach_ind.preamble_list[0].preamble_rel8.rnti
#ifdef Rel14
		     ,0
#endif
		     );
  }

#ifdef Rel14
  if (UL_info->rach_ind_br.number_of_preambles>0) {

    AssertFatal(UL_info->rach_ind_br.number_of_preambles<5,"More than 4 preambles not supported\n");
    for (i=0;i<UL_info->rach_ind_br.number_of_preambles;i++) {
      AssertFatal(UL_info->rach_ind_br.preamble_list[i].preamble_rel13.rach_resource_type>0,
		  "Got regular PRACH preamble, not BL/CE\n");
      LOG_D(MAC,"Frame %d, Subframe %d Calling initiate_ra_proc (CE_level %d)\n",UL_info->frame,UL_info->subframe,
	    UL_info->rach_ind_br.preamble_list[i].preamble_rel13.rach_resource_type-1);
      initiate_ra_proc(UL_info->module_id,
		       UL_info->CC_id,
		       UL_info->frame,
		       UL_info->subframe,
		       UL_info->rach_ind_br.preamble_list[i].preamble_rel8.preamble,
		       UL_info->rach_ind_br.preamble_list[i].preamble_rel8.timing_advance,
		       UL_info->rach_ind_br.preamble_list[i].preamble_rel8.rnti,
		       UL_info->rach_ind_br.preamble_list[i].preamble_rel13.rach_resource_type);
    }
    UL_info->rach_ind.number_of_preambles=0;
59
  }
60
#endif
61 62
}

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
void handle_sr(UL_IND_t *UL_info) {

  int i;

  for (i=0;i<UL_info->sr_ind.number_of_srs;i++) 
    SR_indication(UL_info->module_id,
		  UL_info->CC_id,
		  UL_info->frame,
		  UL_info->subframe,
		  UL_info->sr_ind.sr_pdu_list[i].rx_ue_information.rnti,
		  UL_info->sr_ind.sr_pdu_list[i].ul_cqi_information.ul_cqi);

  UL_info->sr_ind.number_of_srs=0;
}

void handle_cqi(UL_IND_t *UL_info) {

  int i;

82
  if (nfapi_mode == 1)
83 84 85 86 87 88 89 90 91 92 93 94 95 96
  {
    if (UL_info->cqi_ind.number_of_cqis>0)
    {
      LOG_D(PHY,"UL_info->cqi_ind.number_of_cqis:%d\n", UL_info->cqi_ind.number_of_cqis);
      nfapi_cqi_indication_t ind;

      ind.header.message_id = NFAPI_RX_CQI_INDICATION;
      ind.sfn_sf = UL_info->frame<<4 | UL_info->subframe;
      ind.cqi_indication_body = UL_info->cqi_ind;

      oai_nfapi_cqi_indication(&ind);
    }
  }

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
  for (i=0;i<UL_info->cqi_ind.number_of_cqis;i++) 
    cqi_indication(UL_info->module_id,
		   UL_info->CC_id,
		   UL_info->frame,
		   UL_info->subframe,
		   UL_info->cqi_ind.cqi_pdu_list[i].rx_ue_information.rnti,
		   &UL_info->cqi_ind.cqi_pdu_list[i].cqi_indication_rel9,
		   UL_info->cqi_ind.cqi_raw_pdu_list[i].pdu,
		   &UL_info->cqi_ind.cqi_pdu_list[i].ul_cqi_information);

  UL_info->cqi_ind.number_of_cqis=0;
}

void handle_harq(UL_IND_t *UL_info) {

  int i;

114 115
  //if (UL_info->harq_ind.number_of_harqs>0)

116
  if (nfapi_mode == 1 && UL_info->harq_ind.harq_indication_body.number_of_harqs>0) // PNF
117
  {
118
    LOG_E(PHY, "UL_info->harq_ind.harq_indication_body.number_of_harqs:%d Send to VNF\n", UL_info->harq_ind.harq_indication_body.number_of_harqs);
119 120 121 122 123 124 125 126 127 128 129 130 131 132

    nfapi_harq_indication_t ind;

    ind.header.message_id = NFAPI_HARQ_INDICATION;
    ind.sfn_sf = UL_info->frame<<4 | UL_info->subframe;

    int retval = oai_nfapi_harq_indication(&ind);

    if (retval!=0)
    {
      LOG_E(PHY, "Failed to encode NFAPI HARQ_IND retval:%d\n", retval);
    }
  }

133
  for (i=0;i<UL_info->harq_ind.harq_indication_body.number_of_harqs;i++) 
134 135 136 137
    harq_indication(UL_info->module_id,
		    UL_info->CC_id,
		    UL_info->frame,
		    UL_info->subframe,
138
		    &UL_info->harq_ind.harq_indication_body.harq_pdu_list[i]);
139

140
  UL_info->harq_ind.harq_indication_body.number_of_harqs=0;
141 142
}

143 144
void handle_ulsch(UL_IND_t *UL_info) {

145
  int i,j;
146

147
  if(nfapi_mode == 1)
148 149 150 151 152 153 154 155 156
  {
    if (UL_info->crc_ind.crc_indication_body.number_of_crcs>0)
    {
      LOG_D(PHY,"UL_info->crc_ind.crc_indication_body.number_of_crcs:%d\n", UL_info->crc_ind.crc_indication_body.number_of_crcs);

      oai_nfapi_crc_indication(&UL_info->crc_ind);
    }
  }

157

158
  if (nfapi_mode == 1 && UL_info->rx_ind.rx_indication_body.number_of_pdus>0)
159 160 161 162 163 164 165
  {
    LOG_D(PHY,"UL_info->rx_ind.number_of_pdus:%d\n", UL_info->rx_ind.rx_indication_body.number_of_pdus);
    oai_nfapi_rx_ind(&UL_info->rx_ind);
  }

  for (i=0;i<UL_info->rx_ind.rx_indication_body.number_of_pdus;i++) {
    for (j=0;j<UL_info->crc_ind.crc_indication_body.number_of_crcs;j++) {
166
      // find crc_indication j corresponding rx_indication i
167 168 169 170 171 172 173 174 175 176 177
      LOG_D(PHY,"UL_info->crc_ind.crc_indication_body.crc_pdu_list[%d].rx_ue_information.rnti:%04x UL_info->rx_ind.rx_indication_body.rx_pdu_list[%d].rx_ue_information.rnti:%04x\n", j, UL_info->crc_ind.crc_indication_body.crc_pdu_list[j].rx_ue_information.rnti, i, UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_ue_information.rnti);
      if (UL_info->crc_ind.crc_indication_body.crc_pdu_list[j].rx_ue_information.rnti ==
          UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_ue_information.rnti) {
        LOG_D(PHY, "UL_info->crc_ind.crc_indication_body.crc_pdu_list[%d].crc_indication_rel8.crc_flag:%d\n", j, UL_info->crc_ind.crc_indication_body.crc_pdu_list[j].crc_indication_rel8.crc_flag);
        if (UL_info->crc_ind.crc_indication_body.crc_pdu_list[j].crc_indication_rel8.crc_flag == 1) { // CRC error indication
          LOG_D(MAC,"Frame %d, Subframe %d Calling rx_sdu (CRC error) \n",UL_info->frame,UL_info->subframe);
          rx_sdu(UL_info->module_id,
              UL_info->CC_id,
              UL_info->frame,
              UL_info->subframe,
              UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_ue_information.rnti,
178
		 (uint8_t *)NULL,
179 180 181
		 UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length,
		 UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.timing_advance,
		 UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.ul_cqi);
182 183 184 185 186 187 188
	}
	else {
	  LOG_D(MAC,"Frame %d, Subframe %d Calling rx_sdu (CRC ok) \n",UL_info->frame,UL_info->subframe);
	  rx_sdu(UL_info->module_id,
		 UL_info->CC_id,
		 UL_info->frame,
		 UL_info->subframe,
189 190 191 192 193
		 UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_ue_information.rnti,
		 UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].data,
		 UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length,
		 UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.timing_advance,
		 UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.ul_cqi);
194 195 196 197
	}
	break;
      } //if (UL_info->crc_ind.crc_pdu_list[j].rx_ue_information.rnti ==
	//    UL_info->rx_ind.rx_pdu_list[i].rx_ue_information.rnti) {
198 199
    } //    for (j=0;j<UL_info->crc_ind.crc_indication_body.number_of_crcs;j++) {
    AssertFatal(j<UL_info->crc_ind.crc_indication_body.number_of_crcs,"Couldn't find matchin CRC indication\n");
200
  } //   for (i=0;i<UL_info->rx_ind.number_of_pdus;i++) {
201
    
202 203 204 205 206 207 208 209 210 211 212
  if (NFAPI_SFNSF2SFN(UL_info->rx_ind.sfn_sf) == UL_info->frame && NFAPI_SFNSF2SF(UL_info->rx_ind.sfn_sf) == UL_info->subframe && UL_info->rx_ind.rx_indication_body.number_of_pdus>0)
  {
    UL_info->rx_ind.rx_indication_body.number_of_pdus = 0;
    LOG_D(PHY, "UL_INFO:SFN/SF:%d/%d ZEROING rx_ind.number_of_pdus:%d \n", UL_info->frame, UL_info->subframe, UL_info->rx_ind.rx_indication_body.number_of_pdus);
  }

  if (NFAPI_SFNSF2SFN(UL_info->rx_ind.sfn_sf) == UL_info->frame && NFAPI_SFNSF2SF(UL_info->rx_ind.sfn_sf) == UL_info->subframe && UL_info->crc_ind.crc_indication_body.number_of_crcs>0)
  {
    LOG_D(PHY, "UL_INFO:SFN/SF:%d/%d crcs:%d Reset to zero\n", UL_info->frame, UL_info->subframe, UL_info->crc_ind.crc_indication_body.number_of_crcs);
    UL_info->crc_ind.crc_indication_body.number_of_crcs=0;
  }
213 214
}

215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
/****************************************************************************/
/* debug utility functions begin                                            */
/****************************************************************************/

//#define DUMP_FAPI

#ifdef DUMP_FAPI

#define C do { size = 0; put(0); } while (0)
#define A(...) do { char t[4096]; sprintf(t, __VA_ARGS__); append_string(t); } while (0)

static char *s;
static int size;
static int maxsize;

static void put(char x)
{
  if (size == maxsize) {
    maxsize += 32768;
    s = realloc(s, maxsize); if (s == NULL) abort();
  }
  s[size++] = x;
}

static void append_string(char *t)
{
  size--;
  while (*t) put(*t++);
  put(0);
}

Cedric Roux's avatar
minor  
Cedric Roux committed
246
static void dump_ul(UL_IND_t *u)
247 248 249 250 251 252 253
{
  int i;

  C;
  A("XXXX UL  mod %d CC %d f.sf %d.%d\n",
    u->module_id, u->CC_id, u->frame, u->subframe);

254 255 256
  A("XXXX     harq_ind %d\n", u->harq_ind.harq_indication_body.number_of_harqs);
      for (i = 0; i < u->harq_ind.harq_indication_body.number_of_harqs; i++) {
        nfapi_harq_indication_pdu_t *v = &u->harq_ind.harq_indication_body.harq_pdu_list[i];
Cedric Roux's avatar
Cedric Roux committed
257
  A("XXXX         harq ind %d\n", i);
258 259 260 261 262
  A("XXXX         rnti %d\n", v->rx_ue_information.rnti);
  A("XXXX         tb1 %d tb2 %d\n", v->harq_indication_fdd_rel8.harq_tb1,
                                    v->harq_indication_fdd_rel8.harq_tb2);
  A("XXXX         number_of_ack_nack %d\n",
                          v->harq_indication_fdd_rel9.number_of_ack_nack);
Cedric Roux's avatar
Cedric Roux committed
263 264 265
  A("XXXX             harq[0] = %d\n",
                                    v->harq_indication_fdd_rel9.harq_tb_n[0]);
  A("XXXX harq        ul_cqi %d channel %d\n", v->ul_cqi_information.ul_cqi,
266 267 268
                                           v->ul_cqi_information.channel);
      }

269
  A("XXXX     crc_ind  %d\n", u->crc_ind.crc_indication_body.number_of_crcs);
270 271 272 273

  A("XXXX     sr_ind   %d\n", u->sr_ind.number_of_srs);

  A("XXXX     cqi_ind  %d\n", u->cqi_ind.number_of_cqis);
Cedric Roux's avatar
Cedric Roux committed
274 275 276 277 278 279
      for (i = 0; i < u->cqi_ind.number_of_cqis; i++) {
        nfapi_cqi_indication_pdu_t *v = &u->cqi_ind.cqi_pdu_list[i];
  A("XXXX         cqi ind %d\n", i);
  A("XXXX cqi         ul_cqi %d channel %d\n", v->ul_cqi_information.ul_cqi,
                                               v->ul_cqi_information.channel);
      }
280 281 282

  A("XXXX     rach_ind %d\n", u->rach_ind.number_of_preambles);

283
  A("XXXX     rx_ind   %d\n", u->rx_ind.rx_indication_body.number_of_pdus);
David Price's avatar
David Price committed
284 285
      for (i = 0; i < u->rx_ind.rx_indication_body.number_of_pdus; i++) {
        nfapi_rx_indication_pdu_t *v = &u->rx_ind.rx_indication_body.rx_pdu_list[i];
Cedric Roux's avatar
Cedric Roux committed
286 287 288 289 290
  A("XXXX         rx ind %d\n", i);
  A("XXXX             timing_advance %d\n",
                                    v->rx_indication_rel8.timing_advance);
  A("XXXX rx          ul_cqi %d\n", v->rx_indication_rel8.ul_cqi);
      }
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338

  LOG_I(PHY, "XXXX UL\nXXXX UL\n%s", s);
}

static char *DL_PDU_TYPE(int x)
{
  switch (x) {
  case NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE: return "NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE";
  case NFAPI_DL_CONFIG_BCH_PDU_TYPE: return "NFAPI_DL_CONFIG_BCH_PDU_TYPE";
  case NFAPI_DL_CONFIG_MCH_PDU_TYPE: return "NFAPI_DL_CONFIG_MCH_PDU_TYPE";
  case NFAPI_DL_CONFIG_DLSCH_PDU_TYPE: return "NFAPI_DL_CONFIG_DLSCH_PDU_TYPE";
  case NFAPI_DL_CONFIG_PCH_PDU_TYPE: return "NFAPI_DL_CONFIG_PCH_PDU_TYPE";
  case NFAPI_DL_CONFIG_PRS_PDU_TYPE: return "NFAPI_DL_CONFIG_PRS_PDU_TYPE";
  case NFAPI_DL_CONFIG_CSI_RS_PDU_TYPE: return "NFAPI_DL_CONFIG_CSI_RS_PDU_TYPE";
  case NFAPI_DL_CONFIG_EPDCCH_DL_PDU_TYPE: return "NFAPI_DL_CONFIG_EPDCCH_DL_PDU_TYPE";
  case NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE: return "NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE";
  case NFAPI_DL_CONFIG_NBCH_PDU_TYPE: return "NFAPI_DL_CONFIG_NBCH_PDU_TYPE";
  case NFAPI_DL_CONFIG_NPDCCH_PDU_TYPE: return "NFAPI_DL_CONFIG_NPDCCH_PDU_TYPE";
  case NFAPI_DL_CONFIG_NDLSCH_PDU_TYPE: return "NFAPI_DL_CONFIG_NDLSCH_PDU_TYPE";
  }
  return "UNKNOWN";
}

static char *UL_PDU_TYPE(int x)
{
  switch (x) {
  case NFAPI_UL_CONFIG_ULSCH_PDU_TYPE: return "NFAPI_UL_CONFIG_ULSCH_PDU_TYPE";
  case NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE: return "NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE";
  case NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE: return "NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE";
  case NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE: return "NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE";
  case NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE: return "NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE";
  case NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE: return "NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE";
  case NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE: return "NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE";
  case NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE: return "NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE";
  case NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE: return "NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE";
  case NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE: return "NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE";
  case NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE: return "NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE";
  case NFAPI_UL_CONFIG_SRS_PDU_TYPE: return "NFAPI_UL_CONFIG_SRS_PDU_TYPE";
  case NFAPI_UL_CONFIG_HARQ_BUFFER_PDU_TYPE: return "NFAPI_UL_CONFIG_HARQ_BUFFER_PDU_TYPE";
  case NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE: return "NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE";
  case NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE: return "NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE";
  case NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE: return "NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE";
  case NFAPI_UL_CONFIG_NULSCH_PDU_TYPE: return "NFAPI_UL_CONFIG_NULSCH_PDU_TYPE";
  case NFAPI_UL_CONFIG_NRACH_PDU_TYPE: return "NFAPI_UL_CONFIG_NRACH_PDU_TYPE";
  }
  return "UNKNOWN";
}

Cedric Roux's avatar
Cedric Roux committed
339 340 341 342 343 344 345 346 347 348 349 350
static char *HI_DCI0_PDU_TYPE(int x)
{
  switch (x) {
  case NFAPI_HI_DCI0_HI_PDU_TYPE: return "NFAPI_HI_DCI0_HI_PDU_TYPE";
  case NFAPI_HI_DCI0_DCI_PDU_TYPE: return "NFAPI_HI_DCI0_DCI_PDU_TYPE";
  case NFAPI_HI_DCI0_EPDCCH_DCI_PDU_TYPE: return "NFAPI_HI_DCI0_EPDCCH_DCI_PDU_TYPE";
  case NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE: return "NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE";
  case NFAPI_HI_DCI0_NPDCCH_DCI_PDU_TYPE: return "NFAPI_HI_DCI0_NPDCCH_DCI_PDU_TYPE";
  }
  return "UNKNOWN";
}

Cedric Roux's avatar
minor  
Cedric Roux committed
351
static void dump_dl(Sched_Rsp_t *d)
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
{
  int i;

  C;
  A("XXXX DL  mod %d CC %d f.sf %d.%d\n",
    d->module_id, d->CC_id, d->frame, d->subframe);

      if (d->DL_req != NULL) {
        nfapi_dl_config_request_body_t *v=&d->DL_req->dl_config_request_body;
        nfapi_dl_config_request_pdu_t *p = v->dl_config_pdu_list;
  A("XXXX     DL_req sfnsf %d\n", d->DL_req->sfn_sf);
  A("XXXX     PDCCH size   %d\n", v->number_pdcch_ofdm_symbols);
  A("XXXX     DCIs         %d\n", v->number_dci);
  A("XXXX     PDUs         %d\n", v->number_pdu);
  A("XXXX     rntis        %d\n", v->number_pdsch_rnti);
  A("XXXX     pcfich power %d\n", v->transmission_power_pcfich);
        for (i = 0; i < v->number_pdu; i++) {
  A("XXXX         pdu %d\n", i);
  A("XXXX             type %d %s\n", p[i].pdu_type, DL_PDU_TYPE(p[i].pdu_type));
          switch (p[i].pdu_type) {
          case NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE: {
            nfapi_dl_config_dci_dl_pdu_rel8_t *q =
                &p[i].dci_dl_pdu.dci_dl_pdu_rel8;
  A("XXXX                 dci format %d\n", q->dci_format);
  A("XXXX                 cce idx    %d\n", q->cce_idx);
  A("XXXX                 agg lvl    %d\n", q->aggregation_level);
  A("XXXX                 rnti       %d\n", q->rnti);
  A("XXXX                 rb coding  %8.8x\n", q->resource_block_coding);
  A("XXXX                 mcs_1      %d\n", q->mcs_1);
  A("XXXX                 rv_1       %d\n", q->redundancy_version_1);
  A("XXXX                 ndi_1      %d\n", q->new_data_indicator_1);
  A("XXXX                 harq pid   %d\n", q->harq_process);
  A("XXXX                 tpc        %d\n", q->tpc);
  A("XXXX                 tbs idx    %d\n", q->transport_block_size_index);
  A("XXXX                 dl pow off %d\n", q->downlink_power_offset);
  A("XXXX                 rnti type  %d\n", q->rnti_type);
  A("XXXX                 xmit pow   %d\n", q->transmission_power);
            break;
Cedric Roux's avatar
Cedric Roux committed
390 391 392 393 394 395 396 397 398 399
          }
          case NFAPI_DL_CONFIG_DLSCH_PDU_TYPE: {
            nfapi_dl_config_dlsch_pdu_rel8_t *q =
                &p[i].dlsch_pdu.dlsch_pdu_rel8;
  A("XXXX                 pdu_index %d\n", q->pdu_index);
  A("XXXX                 rnti      %d\n", q->rnti);
  A("XXXX                 rv        %d\n", q->redundancy_version);
  A("XXXX                 mcs       %d\n", q->modulation);
  A("XXXX                 pa        %d\n", q->pa);
            break;
400 401 402 403
          }}
        }
      }

Cedric Roux's avatar
Cedric Roux committed
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
      if (d->HI_DCI0_req != NULL) {
        nfapi_hi_dci0_request_body_t *v=&d->HI_DCI0_req->hi_dci0_request_body;
  A("XXXX up  HI_DCI0_req sfnsf %d (%d.%d)\n", d->HI_DCI0_req->sfn_sf,
    d->HI_DCI0_req->sfn_sf/16, d->HI_DCI0_req->sfn_sf%16);
  A("XXXX up     sfnsf %d\n", v->sfnsf);
  A("XXXX up     DCIs  %d\n", v->number_of_dci);
  A("XXXX up     HIs   %d\n", v->number_of_hi);
        for (i = 0; i < v->number_of_dci + v->number_of_hi; i++) {
          nfapi_hi_dci0_request_pdu_t *p = &v->hi_dci0_pdu_list[i];
  A("XXXX up      pdu %d\n", i);
  A("XXXX up          type %d %s\n",p->pdu_type,HI_DCI0_PDU_TYPE(p->pdu_type));
          if (p->pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE) {
            nfapi_hi_dci0_dci_pdu_rel8_t *q = &p->dci_pdu.dci_pdu_rel8;
  A("XXXX up          dci_format           %d\n", q->dci_format);
  A("XXXX up          cce_index            %d\n", q->cce_index);
  A("XXXX up          aggregation_level    %d\n", q->aggregation_level);
  A("XXXX up          rnti                 %d\n", q->rnti);
  A("XXXX up          rb start             %d\n", q->resource_block_start);
  A("XXXX up          # rb                 %d\n", q->number_of_resource_block);
  A("XXXX up          mcs_1                %d\n", q->mcs_1);
  A("XXXX up          cshift_2_for_drms    %d\n", q->cyclic_shift_2_for_drms);
  A("XXXX up          freq hop enabled     %d\n", q->frequency_hopping_enabled_flag);
  A("XXXX up          fre hop bits         %d\n", q->frequency_hopping_bits);
  A("XXXX up          NDI_1                %d\n", q->new_data_indication_1);
  A("XXXX up          tx_antenna_seleciton %d\n", q->ue_tx_antenna_seleciton);
  A("XXXX up          tpc                  %d\n", q->tpc);
  A("XXXX up          cqi_csi_request      %d\n", q->cqi_csi_request);
  A("XXXX up          ul_index             %d\n", q->ul_index);
  A("XXXX up          dl_assignment_index  %d\n", q->dl_assignment_index);
  A("XXXX up          tpc_bitmap           %d\n", q->tpc_bitmap);
  A("XXXX up          transmission_power   %d\n", q->transmission_power);
          }
Cedric Roux's avatar
Cedric Roux committed
436 437 438 439 440 441 442 443
          if (p->pdu_type == NFAPI_HI_DCI0_HI_PDU_TYPE) {
            nfapi_hi_dci0_hi_pdu_rel8_t *q = &p->hi_pdu.hi_pdu_rel8;
  A("XXXX up          rb start    %d\n", q->resource_block_start);
  A("XXXX up          cs2_drms    %d\n", q->cyclic_shift_2_for_drms);
  A("XXXX up          ack         %d\n", q->hi_value);
  A("XXXX up          i_phich     %d\n", q->i_phich);
  A("XXXX up          power       %d\n", q->transmission_power);
          }
Cedric Roux's avatar
Cedric Roux committed
444 445 446
        }
      }

447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
      if (d->UL_req != NULL) {
        nfapi_ul_config_request_body_t *v=&d->UL_req->ul_config_request_body;
  A("XXXX     UL_req sfnsf %d (%d.%d)\n", d->UL_req->sfn_sf,
    d->UL_req->sfn_sf/16, d->UL_req->sfn_sf%16);
  A("XXXX     PDUs         %d\n", v->number_of_pdus);
  A("XXXX     ra freq      %d\n", v->rach_prach_frequency_resources);
  A("XXXX     srs?         %d\n", v->srs_present);
        for (i = 0; i < v->number_of_pdus; i++) {
          nfapi_ul_config_request_pdu_t *p = &v->ul_config_pdu_list[i];
  A("XXXX         pdu %d\n", i);
  A("XXXX             type %d %s\n", p->pdu_type, UL_PDU_TYPE(p->pdu_type));
          switch(p->pdu_type) {
          case NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE: {
            nfapi_ul_config_uci_harq_pdu *q = &p->uci_harq_pdu;
            nfapi_ul_config_harq_information_rel9_fdd_t *h =
                &q->harq_information.harq_information_rel9_fdd;
  A("XXXX                 rnti          %d\n",
    q->ue_information.ue_information_rel8.rnti);
  A("XXXX                 harq size     %d\n", h->harq_size);
  A("XXXX                 ack_nack_mode %d\n", h->ack_nack_mode);
  A("XXXX                 # pucch res   %d\n", h->number_of_pucch_resources);
  A("XXXX                 n_pucch_1_0   %d\n", h->n_pucch_1_0);
  A("XXXX                 n_pucch_1_1   %d\n", h->n_pucch_1_1);
  A("XXXX                 n_pucch_1_2   %d\n", h->n_pucch_1_2);
  A("XXXX                 n_pucch_1_3   %d\n", h->n_pucch_1_3);
            break;
          }
          case NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE: {
            nfapi_ul_config_uci_sr_pdu *q = &p->uci_sr_pdu;
            nfapi_ul_config_sr_information_rel8_t *h =
                &q->sr_information.sr_information_rel8;
  A("XXXX                 rnti          %d\n",
    q->ue_information.ue_information_rel8.rnti);
  A("XXXX                 pucch_index   %d\n", h->pucch_index);
          }}
        }
      }

  LOG_I(PHY, "XXXX DL\nXXXX DL\n%s", s);
}

#undef C
#undef A

#endif /* DUMP_FAPI */

/****************************************************************************/
/* debug utility functions end                                              */
/****************************************************************************/

497 498 499 500 501
void UL_indication(UL_IND_t *UL_info)
{

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

502 503 504
#ifdef DUMP_FAPI
  dump_ul(UL_info);
#endif
505 506 507 508 509 510 511

  module_id_t  module_id   = UL_info->module_id;
  int          CC_id       = UL_info->CC_id;
  Sched_Rsp_t  *sched_info = &Sched_INFO[module_id][CC_id];
  IF_Module_t  *ifi        = if_inst[module_id];
  eNB_MAC_INST *mac        = RC.mac[module_id];

512
  LOG_D(PHY,"UL_Indication: frame %d, subframe %d, module_id %d, CC_id %d\n",
513 514 515
	UL_info->frame,UL_info->subframe,
	module_id,CC_id);

516
  if (nfapi_mode != 1)
517 518 519 520 521 522 523 524 525 526
  {
    if (ifi->CC_mask==0) {
      ifi->current_frame    = UL_info->frame;
      ifi->current_subframe = UL_info->subframe;
    }
    else {
      AssertFatal(UL_info->frame != ifi->current_frame,"CC_mask %x is not full and frame has changed\n",ifi->CC_mask);
      AssertFatal(UL_info->subframe != ifi->current_subframe,"CC_mask %x is not full and subframe has changed\n",ifi->CC_mask);
    }
    ifi->CC_mask |= (1<<CC_id);
527
  }
528

529

530 531 532 533
  // clear DL/UL info for new scheduling round
  clear_nfapi_information(RC.mac[module_id],CC_id,
			  UL_info->frame,UL_info->subframe);

534
  LOG_D(PHY, "UL_info[rx_ind:%d number_of_harqs:%d number_of_crcs:%d number_of_cqis:%d number_of_preambles:%d]\n", UL_info->rx_ind.rx_indication_body.number_of_pdus, UL_info->harq_ind.harq_indication_body.number_of_harqs, UL_info->crc_ind.crc_indication_body.number_of_crcs, UL_info->cqi_ind.number_of_cqis, UL_info->rach_ind.number_of_preambles);
535

536 537
  handle_rach(UL_info);

538 539 540 541 542 543
  handle_sr(UL_info);

  handle_cqi(UL_info);

  handle_harq(UL_info);

544
  // clear HI prior to handling ULSCH
545 546 547
  mac->HI_DCI0_req[CC_id].hi_dci0_request_body.number_of_hi                     = 0;
  
  handle_ulsch(UL_info);
548

549
  if (nfapi_mode != 1)
550 551
  {
    if (ifi->CC_mask == ((1<<MAX_NUM_CCs)-1)) {
552

553 554 555
      eNB_dlsch_ulsch_scheduler(module_id,
          (UL_info->frame+((UL_info->subframe>5)?1:0)) % 1024,
          (UL_info->subframe+4)%10);
556

557
      ifi->CC_mask            = 0;
558

559 560 561 562 563 564 565 566 567 568 569
      sched_info->module_id   = module_id;
      sched_info->CC_id       = CC_id;
      sched_info->frame       = (UL_info->frame + ((UL_info->subframe>5) ? 1 : 0)) % 1024;
      sched_info->subframe    = (UL_info->subframe+4)%10;
      sched_info->DL_req      = &mac->DL_req[CC_id];
      sched_info->HI_DCI0_req = &mac->HI_DCI0_req[CC_id];
      if ((mac->common_channels[CC_id].tdd_Config==NULL) ||
          (is_UL_sf(&mac->common_channels[CC_id],(sched_info->subframe+4)%10)>0)) 
        sched_info->UL_req      = &mac->UL_req[CC_id];
      else
        sched_info->UL_req      = NULL;
570

571
      sched_info->TX_req      = &mac->TX_req[CC_id];
572 573

#ifdef DUMP_FAPI
574
      dump_dl(sched_info);
575 576
#endif

577 578 579 580 581 582 583 584
      if (ifi->schedule_response)
      {
        AssertFatal(ifi->schedule_response!=NULL,
            "schedule_response is null (mod %d, cc %d)\n",
            module_id,
            CC_id);
        ifi->schedule_response(sched_info);
      }
585

586 587 588 589
      LOG_D(PHY,"Schedule_response: frame %d, subframe %d (dl_pdus %d / %p)\n",sched_info->frame,sched_info->subframe,sched_info->DL_req->dl_config_request_body.number_pdu,
          &sched_info->DL_req->dl_config_request_body.number_pdu);
    }						 
  }
590 591 592 593 594 595
}

IF_Module_t *IF_Module_init(int Mod_id){

  AssertFatal(Mod_id<MAX_MODULES,"Asking for Module %d > %d\n",Mod_id,MAX_IF_MODULES);

596 597
  LOG_D(PHY,"Installing callbacks for IF_Module - UL_indication\n");

598 599 600
  if (if_inst[Mod_id]==NULL) {
    if_inst[Mod_id] = (IF_Module_t*)malloc(sizeof(IF_Module_t));
    memset((void*)if_inst[Mod_id],0,sizeof(IF_Module_t));
601

602 603 604 605
    if_inst[Mod_id]->CC_mask=0;
    if_inst[Mod_id]->UL_indication = UL_indication;

    AssertFatal(pthread_mutex_init(&if_inst[Mod_id]->if_mutex,NULL)==0,
606
        "allocation of if_inst[%d]->if_mutex fails\n",Mod_id);
607 608 609 610 611 612 613 614 615 616
  }
  return if_inst[Mod_id];
}

void IF_Module_kill(int Mod_id) {

  AssertFatal(Mod_id>MAX_MODULES,"Asking for Module %d > %d\n",Mod_id,MAX_IF_MODULES);
  if (if_inst[Mod_id]!=NULL) free(if_inst[Mod_id]);

}