#ifndef MCLI_DEFS_H
#define MCLI_DEFS_H

#include <net/if.h>
#include <netinet/ip6.h>
#include <zlib.h>

typedef enum fe_caps {
    FE_IS_STUPID = 0,
    FE_CAN_INVERSION_AUTO = 0x1,
    FE_CAN_FEC_1_2 = 0x2,
    FE_CAN_FEC_2_3 = 0x4,
    FE_CAN_FEC_3_4 = 0x8,
    FE_CAN_FEC_4_5 = 0x10,
    FE_CAN_FEC_5_6 = 0x20,
    FE_CAN_FEC_6_7 = 0x40,
    FE_CAN_FEC_7_8 = 0x80,
    FE_CAN_FEC_8_9 = 0x100,
    FE_CAN_FEC_AUTO = 0x200,
    FE_CAN_QPSK = 0x400,
    FE_CAN_QAM_16 = 0x800,
    FE_CAN_QAM_32 = 0x1000,
    FE_CAN_QAM_64 = 0x2000,
    FE_CAN_QAM_128 = 0x4000,
    FE_CAN_QAM_256 = 0x8000,
    FE_CAN_QAM_AUTO = 0x10000,
    FE_CAN_TRANSMISSION_MODE_AUTO = 0x20000,
    FE_CAN_BANDWIDTH_AUTO = 0x40000,
    FE_CAN_GUARD_INTERVAL_AUTO = 0x80000,
    FE_CAN_HIERARCHY_AUTO = 0x100000,
    FE_CAN_8VSB = 0x200000,
    FE_CAN_16VSB = 0x400000,
    FE_HAS_EXTENDED_CAPS =
        0x800000, /* We need more bitspace for newer APIs, indicate this. */
    FE_CAN_MULTISTREAM =
        0x4000000,                /* frontend supports multistream filtering */
    FE_CAN_TURBO_FEC = 0x8000000, /* frontend supports "turbo fec modulation" */
    FE_CAN_2G_MODULATION =
        0x10000000, /* frontend supports "2nd generation modulation" (DVB-S2) */
    FE_NEEDS_BENDING = 0x20000000, /* not supported anymore, don't use (frontend
                                      requires frequency bending) */
    FE_CAN_RECOVER =
        0x40000000, /* frontend can recover from a cable unplug automatically */
    FE_CAN_MUTE_TS = 0x80000000 /* frontend can stop spurious TS data output */
} fe_caps_t;

struct dvb_frontend_info {
    char name[128];
    fe_type_t type; /* DEPRECATED. Use DTV_ENUM_DELSYS instead */
    __u32 frequency_min;
    __u32 frequency_max;
    __u32 frequency_stepsize;
    __u32 frequency_tolerance;
    __u32 symbol_rate_min;
    __u32 symbol_rate_max;
    __u32 symbol_rate_tolerance; /* ppm */
    __u32 notifier_delay;        /* DEPRECATED */
    fe_caps_t caps;
};

/**
 *  Check out the DiSEqC bus spec available on http://www.eutelsat.org/ for
 *  the meaning of this struct...
 */
struct dvb_diseqc_master_cmd {
    __u8 msg[6];  /*  { framing, address, command, data [3] } */
    __u8 msg_len; /*  valid values are 3...6  */
};

typedef enum fe_sec_voltage {
    SEC_VOLTAGE_13,
    SEC_VOLTAGE_18,
    SEC_VOLTAGE_OFF
} fe_sec_voltage_t;

typedef enum fe_sec_tone_mode { SEC_TONE_ON, SEC_TONE_OFF } fe_sec_tone_mode_t;

typedef enum fe_sec_mini_cmd { SEC_MINI_A, SEC_MINI_B } fe_sec_mini_cmd_t;

typedef enum fe_hierarchy {
    HIERARCHY_NONE,
    HIERARCHY_1,
    HIERARCHY_2,
    HIERARCHY_4,
    HIERARCHY_AUTO
} fe_hierarchy_t;

struct dvb_qpsk_parameters {
    __u32 symbol_rate;        /* symbol rate in Symbols per second */
    fe_code_rate_t fec_inner; /* forward error correction (see above) */
};

struct dvb_qam_parameters {
    __u32 symbol_rate;          /* symbol rate in Symbols per second */
    fe_code_rate_t fec_inner;   /* forward error correction (see above) */
    fe_modulation_t modulation; /* modulation type (see above) */
};

struct dvb_vsb_parameters {
    fe_modulation_t modulation; /* modulation type (see above) */
};

struct dvb_ofdm_parameters {
    fe_bandwidth_t bandwidth;
    fe_code_rate_t code_rate_HP;   /* high priority stream code rate */
    fe_code_rate_t code_rate_LP;   /* low priority stream code rate */
    fe_modulation_t constellation; /* modulation type (see above) */
    fe_transmit_mode_t transmission_mode;
    fe_guard_interval_t guard_interval;
    fe_hierarchy_t hierarchy_information;
};

struct dvb_frontend_parameters {
    __u32 frequency; /* (absolute) frequency in Hz for QAM/OFDM/ATSC */
                     /* intermediate frequency in kHz for QPSK */
    fe_spectral_inversion_t inversion;
    union {
        struct dvb_qpsk_parameters qpsk;
        struct dvb_qam_parameters qam;
        struct dvb_ofdm_parameters ofdm;
        struct dvb_vsb_parameters vsb;
    } u;
};

typedef struct recv_sec {
    struct dvb_diseqc_master_cmd diseqc_cmd;
    fe_sec_mini_cmd_t mini_cmd;
    fe_sec_tone_mode_t tone_mode;
    fe_sec_voltage_t voltage;
} recv_sec_t;

typedef struct ca_caps {
    unsigned int slot_num;   /* total number of CA card and module slots */
    unsigned int slot_type;  /* OR of all supported types */
    unsigned int descr_num;  /* total number of descrambler slots (keys) */
    unsigned int descr_type; /* OR of all supported types */
} ca_caps_t;

typedef struct ca_slot_info {
    int num; /* slot number */

    int type;        /* CA interface this slot supports */
#define CA_CI 1      /* CI high level interface */
#define CA_CI_LINK 2 /* CI link layer level interface */
#define CA_CI_PHYS 4 /* CI physical layer level interface */
#define CA_DESCR 8   /* built-in descrambler */
#define CA_SC 128    /* simple smart card interface */

    unsigned int flags;
#define CA_CI_MODULE_PRESENT 1 /* module (or card) inserted */
#define CA_CI_MODULE_READY 2
} ca_slot_info_t;

#define CA_MAX_SLOTS 16
typedef struct {
    ca_caps_t cap;
    ca_slot_info_t info[CA_MAX_SLOTS];
} recv_cacaps_t;

typedef struct recv_festatus {
    fe_status_t st;
    uint32_t ber;
    uint16_t strength;
    uint16_t snr;
    uint32_t ucblocks;
} recv_festatus_t;

#include <libxml/xpath.h>

#define UUID_SIZE 256
#define DLL_SYMBOL
#define SOCKET int

#define FE_DVBS2 (FE_ATSC + 1)

// RMM S2 Extension
#define FEC_1_4 10
#define FEC_1_3 11
#define FEC_2_5 12
#define FEC_3_5 13
#define FEC_9_10 14
#define QPSK_S2 9
#define PSK8 10

#include "api_server.h"
#include "list.h"
#include "mcast.h"
#include "recv_ccpp.h"
#include "recv_tv.h"
#include "satlists.h"
#include "tca_handler.h"

#endif
