/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */

/*---------------------------------------------------------------------------*
 * 
 * Network Interface header file. This is the interface between network stack
 * and device drivers
 * 
 *---------------------------------------------------------------------------*/

#ifndef __IOP_NETIF_H__
#define __IOP_NETIF_H__

#include <socket.h>
#include <iop_ethtool.h>

#define NET_RM_IP_BOT               "/dev/net/ip/bottom"
#define NET_RM_WD_TOP               "/dev/net/wd/top"
#define NET_RM_USBETH_TOP           "/dev/net/usbeth/top"

/* network stack interface commands */
#define NET_IP_RECV_PKT             0x00010001
#define NET_IP_NOTIFY               0x00010002

/* network device driver commands */
#define NET_DEV_XMIT_PKT            0x00020001
#define NET_DEV_UP                  0x00020002
#define NET_DEV_DOWN                0x00020003
#define NET_DEV_SET_MULTICAST_LIST  0x00020004
#define NET_DEV_SET_MAC_ADDRESS     0x00020005
#define NET_DEV_GET_MAC_ADDRESS     0x00020006
#define NET_DEV_SET_MRU             0x00020007
#define NET_DEV_GET_STATS           0x00020008
#define NET_DEV_SET_ETHTOOL         0x00020009
#define NET_DEV_GET_ETHTOOL         0x0002000a

/* Supported network interface */
#define NET_IF_ETH_WIFI             0x01    /* Ethernet wireless interface */
#define NET_IF_ETH_USB              0x02    /* Ethernet USB interface */

/* Standard interface flags */
#define NET_IF_UP                   0x01    /* interface is up */
#define NET_IF_BROADCAST            0x02    /* broadcast address valid */
#define NET_IF_NOARP                0x04    /* no ARP protocol */
#define NET_IF_PROMISC              0x08    /* receive all packets */
#define NET_IF_ALLMULTI             0x10    /* receive all multicast packets */

/* Backlog congestion levels */
#define NET_RECV_SUCCESS            0       /* OK */
#define NET_RECV_CN_LOW             1       /* warning, just in case */
#define NET_RECV_CN_MOD             2       /* warning, storm on its way */
#define NET_RECV_CN_HIGH            3       /* warning, storm is here */
#define NET_RECV_DROP               -1      /* packet dropped */

/* Device state change notification index */
#define NET_NOTIFY_DEV_UP           0x01    /* device is up */
#define NET_NOTIFY_DEV_DOWN         0x02    /* device is down */
#define NET_NOTIFY_DEV_LINK_UP      0x03    /* link is up */
#define NET_NOTIFY_DEV_LINK_DOWN    0x04    /* link is down */
#define NET_NOTIFY_DEV_XMIT_ERR     0x05    /* device xmit enqueue failure */

#ifndef ETH_ALEN
#define ETH_ALEN                    6       /* Ethernet address length */
#endif

/*
 * When setting up receive packets that an ethernet device will DMA into, 
 * we typically reserve NET_IP_ALIGN bytes. By default NET_IP_ALIGN is defined 
 * to '2'. This makes it so that, after the ethernet header, the protocol 
 * header will be aligned on at least a 4-byte boundary. Nearly all of the 
 * IPV4 and IPV6 protocol processing assumes that the headers are properly 
 * aligned. 
 */
#define NET_IP_ALIGN                2

/*
 * Reserve 4 bytes in the iobuf so that the device driver can add the packet
 * size in front of the packet
 */
#define NET_IP_DRV_RESERVE          4

/*
 * Ethernet header
 */
#define ETH_HLEN                    14

typedef struct ETHHeader
{
    u8  dst[ETH_ALEN];
    u8  src[ETH_ALEN];
    u16 type;
} ETHHeader;

// obsolete
typedef struct IPInterfaceStat
{
    u32             inUcastPackets;     // Input unicast packets
    u32             inNonUcastPackets;  // Input broadcast or multicast packets
    u32             inDiscards;         // Input dropped due to ins. resources
    u32             inErrors;           // Packets dropped on input
    u32             outUcastPackets;    // Output unicast packets
    u32             outNonUcastPackets; // Output broadcast or multicast packets
    u32             outDiscards;        // Output dropped due to ins. resources
    u32             outErrors;          // Output errors
    u32             outCollisions;      // Collisions on CSMA
} IPInterfaceStat;

#if 0

/*
 * Interface request structure
 */
typedef struct NETIfReq
{
    u32     netif;                      /* network interface ID */
    union {
        u32     flags;
        struct  SOInAddr addr;          /* network IP address */
        struct  SOInAddr broadAddr;     /* protocol broadcast addr */
        struct  SOInAddr netmask;       /* network mask */
        struct  SOInAddr alias;         /* internet alias address */
        struct  SOInAddr gateway;       /* default gateway */
        struct  SOInAddr dns[2];        /* primary and secondary DNS */
        u8      macAddr[ETH_ALEN];      /* mac address */
        u32     mtu;                    /* mtu setting */
        u32     mru;                    /* mru setting */
        struct  IPInterfaceStat stat;   /* interface statistics */
        s32     cfgErr;                 /* interface config error */
        struct  SOIn6Addr addr6;        /* network IPv6 address */
        struct  NETEthTool ethTool;     /* for Ethernet card */
    } ifru;
} NETIfReq;

/*
 * Interface request structure used for PPPoE
 */
#define NET_USERNAME_LEN        16
#define NET_PASSWD_LEN          16
#define NET_SRVNAME_LEN         32

typedef struct NETIfReqPPPoE
{
    char    userName[NET_USERNAME_LEN];     /* login name */
    char    passwd[NET_PASSWD_LEN];         /* password */
    char    serviceName[NET_SRVNAME_LEN];   /* service name */
    struct  SOInAddr primaryDNS;            /* primary DNS */
    struct  SOInAddr secondaryDNS;          /* secondary DNS */
} NETIfReqPPPoE;

/*
 * Interface request structure used for DHCP
 */
#define NET_HOSTNAME_LEN        32

typedef struct NETIfReqDhcp
{
    char    userName[NET_HOSTNAME_LEN];     /* host name */
    struct  SOInAddr primaryDNS;            /* primary DNS */
    struct  SOInAddr secondaryDNS;          /* secondary DNS */
} NETIfReqDhcp;

#endif

/*
 * Multicast address list
 */
#define NET_MAX_MC_ADDR         4
typedef struct NETMcAddrList {
    u32 flags;                              /* interface multicast related flags */
    u32 count;                              /* number of multicast addr in list */
    u8  mcAddr[NET_MAX_MC_ADDR][ETH_ALEN];  /* multicast addr */
} NETMcAddrList;

#endif // __IOP_NETIF_H__
