/*
 * SPDX-License-Identifier: LicenseRef-CSSL-1.0
 */

#ifndef ORAN_INIT_H
#define ORAN_INIT_H

#include "common/utils/nr/nr_common.h"
#include "openair2/LAYER2/NR_MAC_COMMON/nr_prach_config.h"

typedef struct oran_bufs {
  struct xran_flat_buffer tx[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN][XRAN_NUM_OF_SYMBOL_PER_SLOT];
  struct xran_flat_buffer tx_prbmap[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN];
  struct xran_flat_buffer rx[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN][XRAN_NUM_OF_SYMBOL_PER_SLOT];
  struct xran_flat_buffer rx_prbmap[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN];

  struct xran_flat_buffer prach[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN][XRAN_NUM_OF_SYMBOL_PER_SLOT];
  struct xran_flat_buffer prachdecomp[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN];
} oran_bufs_t;

typedef struct oran_buf_list {
  // xran API requires buffer lists as structs of arrays
  struct xran_buffer_list src[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN];
  struct xran_buffer_list srccp[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN];
  struct xran_buffer_list dst[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN];
  struct xran_buffer_list dstcp[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN];

  struct xran_buffer_list prachdst[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN];
  struct xran_buffer_list prachdstdecomp[XRAN_MAX_ANTENNA_NR][XRAN_N_FE_BUF_LEN];

  oran_bufs_t bufs;
} oran_buf_list_t;

typedef struct oran_port_instance_t {
  oran_buf_list_t *buf_list;
  void *instanceHandle;
  //uint32_t dpdkPoolIndex[MAX_SW_XRAN_INTERFACE_NUM];

  struct xran_cb_tag prach_tag;
  struct xran_cb_tag pusch_tag;
} oran_port_instance_t;

extern struct xran_fh_config gxran_fh_config[XRAN_PORTS_NUM];
#if defined F_RELEASE
extern void *gxran_handle;
#elif defined K_RELEASE
extern void *gxran_handle[XRAN_PORTS_NUM];
#endif

void *oai_oran_initialize(struct xran_fh_init *fh_init, struct xran_fh_config *fh_config);

oran_buf_list_t *get_xran_buffers(uint32_t port_id);
struct xran_fh_init *get_xran_fh_init(void);
struct xran_fh_config *get_xran_fh_config(uint32_t port_id);

/**
 * @brief queries PRACH information necessary for the FHI
 *
 * @arg port_id XRAN port id
 * @return PRACH information holding among other information:
 * - N_dur PRACH duration from TS 38.211 Table 6.3.3.2-2/3/4
 * - x from TS 38.211 Table 6.3.3.2-2/3/4
 * - y from TS 38.211 Table 6.3.3.2-2/3/4
 */
nr_prach_info_t get_prach_info(uint32_t port_id);

#endif /* ORAN_INIT_H */
