/*******************************************************************************
 * (c) Copyright 2015 Microsemi Corporation.  All rights reserved.
 *
 *
 *
 * SVN $Revision: $
 * SVN $Date: $
 */

#ifndef GATEWAY_2PORT_ETH_H
#define GATEWAY_2PORT_ETH_H

/* -----------------------------------------------------------------------*/
// Define constants used for sending CPU packets on Lan or Wan
/* -----------------------------------------------------------------------*/
#define MR_SOP_MASK_BIT                 0x1
#define MR_EOP_MASK_BIT                 0x2
#define MR_MOD_BITS_OFFSET              2
#define MR_CPU_SYS_PKT_RDY              0x4
#define MR_MAX_CPU_LAN_TX_PKT   1600    // define the maximum size CPU packet that can be sent on Lan (Sys)
#define MR_MAX_CPU_WAN_TX_PKT   1600    // define the maximum size CPU packet that can be sent on Wan (Carr)

#define MR_CPU_CARR_TX_BUF                      0x1000
#define MR_CPU_CARR_TX_BUF_SIZE         0x800

//VR Supplying missing bit mask
#define MR_MAC_RESET_BIT_MASK		0x1800018

#ifdef WIN_DLL
#include <stdint.h>
#else

#include "lwip/err.h"
#include "lwip/netif.h"
#include <api_oam_sdk/common/error_codes/inc/mr_error_codes.h>
#include <api_oam_sdk/common/types/inc/mr_api_types.h>


#ifdef commented
typedef struct gateway_ethernetif {
        struct eth_addr *ethaddr;
        volatile int    iface;
        volatile int    link_alive;
        volatile int    link_speed;
        volatile int    full_duplex;

        //  Extra stats
        volatile unsigned   bytes_sent;
        volatile unsigned   bytes_recv;

        //  lwIP pbuf circular buffer.  A list of pbufs that are used to store
        //  incoming Ethernet packets
        struct pbuf     *lwipRxPbuf[LWIP_RX_ETH_BUFFER];
        volatile int    lwipRxIndexIsr;
        volatile int    lwipRxIndex;
        volatile int    lwipRxCount;

        volatile int    current_state;

        //  Pointer to TSE hardware descriptor - needed to send packets
        struct _lwip_tse_info   *tse_info;
} ethernetif_t;
#endif

struct captPktInfo_s
{
        mrPort_t        port;
        uint16_t        captReason;
        uint16_t        pktLen;
        uint16_t        cpuCaptPktTail;
        uint16_t        cpuCaptInfoTail;
        void            *ifaceInfo;
};
typedef struct captPktInfo_s captPktInfo_t;


#define MR_CAPT_REASON_MAC_MATCH		0xF
#define MR_CAPT_REASON_BC_MATCH			0xE
#define MR_CAPT_REASON_LTM				0x5
#define MR_CAPT_REASON_LTR				0x4

// Prototypes
int gateway_mac_init(uint8_t *wanMAC, uint8_t *lanMAC, uint8_t *mgntMAC, struct netif *netif);
err_t gateway_mac_raw_send(struct netif *netif, struct pbuf *pkt);
err_t gateway_ethernetif_init(struct netif *netif);
int writeSysTxPkt(uint8_t* pktPtr, uint16_t pktLen);
int writeCarrierTxPkt(uint8_t* pktPtr, uint16_t pktLen);
int readGenericPacket(uint8_t* pktPtr, captPktInfo_t captPktInfo);

#endif //WIN_DLL

#ifdef METROAM_DLL
        METROAM_API int __stdcall mrSendLanPkt(uint8_t pktData[MR_MAX_CPU_LAN_TX_PKT],uint16_t pktLen);
        METROAM_API int __stdcall mrSendWanPkt(uint8_t pktData[MR_MAX_CPU_WAN_TX_PKT],uint16_t pktLen);
#else
        int mrSendWanPkt(uint8_t pktData[MR_MAX_CPU_WAN_TX_PKT],uint16_t pktLen);
        int mrSendLanPkt(uint8_t pktData[MR_MAX_CPU_LAN_TX_PKT],uint16_t pktLen);
#endif

#endif
