#ifndef ENVOY_NIPCLOWLEVEL_H
#define ENVOY_NIPCLOWLEVEL_H
/*------------------------------------------------------------------------*/
/*                                                                        *
 *  $Id: nipclowlevel.h 1.3 1998/01/08 18:21:37 heinz Exp $
 *                                                                        */
/*------------------------------------------------------------------------*/

/*------------------------------------------------------------------------*/
/**************************************************************************
 *** WARNING!
 ***
 *** This stuff is very low level. It is definitely not for the
 *** casual user of nipc.library. Think twice about even thinking
 *** about it!
 **************************************************************************
 ***/
/*------------------------------------------------------------------------*/

/* The nipc.library IP layer can be influenced via tags.
 * There are different types of tag groups
 *  - packet modification tags
 *  - protocol registering tags
 *  - configuration tags
 */

#define NIPCTAG_Dummy                   (TAG_USER)

/*------------------------------------------------------------------------*/
/* Tags to manipulate IP packets on sending. Handle with extreme care! */

/* Set the DontFragment bit in the header. Not for casual use! */
#define NIPCTAG_IPDontFragment          (NIPCTAG_Dummy + 0x1000)

/* Set the MoreFragments bit in the header. Not for casual use! */
#define NIPCTAG_IPMoreFragments         (NIPCTAG_Dummy + 0x1001)

/* Add options to the IP header. Not for casual use! */
#define NIPCTAG_IPOptions               (NIPCTAG_Dummy + 0x1002)
#define NIPCTAG_IPOptionsLength         (NIPCTAG_Dummy + 0x1003)

/* Manipulate the sender ID. Not for casual use! */
#define NIPCTAG_IPPacketID              (NIPCTAG_Dummy + 0x1004)

/* Set up the TTL field in the header. Not for casual use! */
#define NIPCTAG_IPTimeToLive            (NIPCTAG_Dummy + 0x1005)

/* Set up the TOS field in the header. Not for casual use! */
#define NIPCTAG_IPTypeOfService         (NIPCTAG_Dummy + 0x1006)

/* Set up the Identification field in the header. Not for casual use! */
#define NIPCTAG_IPIdentification        (NIPCTAG_Dummy + 0x1007)

/* Set up the FragmentOffset field in the header. Not for casual use! */
#define NIPCTAG_IPFragmentOffset        (NIPCTAG_Dummy + 0x1008)

/*------------------------------------------------------------------------*/
/* Tags used when registering protocols or ports. note that even
 * though the tags have "Protocol" in their name, they may be
 * used for ports when documented as such.
 */

/* Descriptive protocol or port name. MANDATORY */
#define NIPCTAG_ProtocolName            (NIPCTAG_Dummy + 0x3000)

/* Priority relativ to other protocols. Normally 0! */
#define NIPCTAG_ProtocolPriority        (NIPCTAG_Dummy + 0x3001)

/* An optional  pointer to a LONG. On allocation, it will be set
 * to the port number chosen.
 */
#define NIPCTAG_ProtocolPortNumber      (NIPCTAG_Dummy + 0x3002)

/* User data size */
#define NIPCTAG_ProtocolUserDataSize    (NIPCTAG_Dummy + 0x3003)

/* Input function for ICMP packets */
#define NIPCTAG_ProtocolInputICMP       (NIPCTAG_Dummy + 0x3004)

/* Heartbeat function callback. Called ~ once a second */
#define NIPCTAG_ProtocolHeartbeat       (NIPCTAG_Dummy + 0x3005)

/*------------------------------------------------------------------------*/
/* Global configuration tags. Not at all for casual use!
 * See the autodoc for NIPCControlA()
 */

/* Used to set IP packet default values */
#define NIPCTAG_SetDefaultTTL           (NIPCTAG_Dummy + 0x4000)
#define NIPCTAG_SetDefaultTOS           (NIPCTAG_Dummy + 0x4001)

/* After that many seconds, unused IP datagram fragments will be discarded */
#define NIPCTAG_SetFragmentTO           (NIPCTAG_Dummy + 0x4002)

/* Timeout for ARP entry resolving. Number of retries and entry timeout */
#define NIPCTAG_SetARPResolveTO         (NIPCTAG_Dummy + 0x4010)
#define NIPCTAG_SetARPResolveRetries    (NIPCTAG_Dummy + 0x4011)
#define NIPCTAG_SetARPEntryTO           (NIPCTAG_Dummy + 0x4012)

/* RDP protocol configuration */
#define NIPCTAG_SetRDPInactivityCheck   (NIPCTAG_Dummy + 0x4020)
#define NIPCTAG_SetRDPInactivityLimit   (NIPCTAG_Dummy + 0x4021)
#define NIPCTAG_SetRDPTransmitRetries   (NIPCTAG_Dummy + 0x4022)
#define NIPCTAG_SetRDPTransmitMinTO     (NIPCTAG_Dummy + 0x4023)
#define NIPCTAG_SetRDPTransmitMaxTO     (NIPCTAG_Dummy + 0x4024)
#define NIPCTAG_SetRDPInitialRoundTripTO (NIPCTAG_Dummy + 0x4025)
#define NIPCTAG_SetRDPConnectTO         (NIPCTAG_Dummy + 0x4026)
#define NIPCTAG_SetRDPConnectRetries    (NIPCTAG_Dummy + 0x4027)

/* Corresponds to tags above. Takes pointer to value (>=32 bit) */
#define NIPCTAG_GetDefaultTTL           (NIPCTAG_Dummy + 0x4100)
#define NIPCTAG_GetDefaultTOS           (NIPCTAG_Dummy + 0x4101)
#define NIPCTAG_GetFragmentTO           (NIPCTAG_Dummy + 0x4102)
#define NIPCTAG_GetARPResolveTO         (NIPCTAG_Dummy + 0x4110)
#define NIPCTAG_GetARPResolveRetries    (NIPCTAG_Dummy + 0x4111)
#define NIPCTAG_GetARPEntryTO           (NIPCTAG_Dummy + 0x4112)
#define NIPCTAG_GetRDPInactivityCheck   (NIPCTAG_Dummy + 0x4120)
#define NIPCTAG_GetRDPInactivityLimit   (NIPCTAG_Dummy + 0x4121)
#define NIPCTAG_GetRDPTransmitRetries   (NIPCTAG_Dummy + 0x4122)
#define NIPCTAG_GetRDPTransmitMinTO     (NIPCTAG_Dummy + 0x4123)
#define NIPCTAG_GetRDPTransmitMaxTO     (NIPCTAG_Dummy + 0x4124)
#define NIPCTAG_GetRDPInitialRoundTripTO (NIPCTAG_Dummy + 0x4125)
#define NIPCTAG_GetRDPConnectTO         (NIPCTAG_Dummy + 0x4126)
#define NIPCTAG_GetRDPConnectRetries    (NIPCTAG_Dummy + 0x4127)

/* Special tags to get characteristic configuration values */

#define NIPCTAG_GetMTUforIP             (NIPCTAG_Dummy + 0x4200)

/* Tags for general AS225 like control functions
 * NIPCTAG_ControlCommand triggers the execution. You need to
 * specify any other needed tags before that one.
 */
#define NIPCTAG_ControlInterfaceName    (NIPCTAG_Dummy + 0x4300)
#define NIPCTAG_ControlCommand          (NIPCTAG_Dummy + 0x4301)
#define NIPCTAG_ControlData             (NIPCTAG_Dummy + 0x4302)
#define NIPCTAG_ControlResult           (NIPCTAG_Dummy + 0x4303)
#define NIPCTAG_ControlResult2          (NIPCTAG_Dummy + 0x4304)

/*------------------------------------------------------------------------*/
#ifdef __USE_NIPC_IOCTL
/* As NIPCControlA() supports quite some part of AS225 functionality,
 * names have sometimes been kept identical for easier
 * reference in code. This is really low level magic.
 * Typically, people won't use this stuff.
 */

/*------------------------------------------------------------------------*/
/* There are some tags that ask for and return special structures
 * that tell us about the inner state of nipc.library.
 * Note the intended similarity to certain BSD based structures
 * in names and structure layout.
 * Even though the functionality may be slightly different, the
 * names have been kept similar for easier understanding.
 * The structure layout has been kept for easier portability.
 */

/*------------------------------------------------------------------------*/
/* Addressing */
#define NIPCAF_UNSPEC       0   /* unspecified */
#define NIPCAF_INET         2   /* internetwork: UDP, TCP, etc. */

struct NIPC_SocketAddr
{
    UWORD   Family;         /* Type of address */
    UBYTE   Data[14];       /* Address data. Length depends on type */
};

/*------------------------------------------------------------------------*/
/* Interface descriptions */
#define NIPC_INTERFACENAMESIZE  16

struct NIPC_InterfaceInfo
{
    UBYTE       Name[NIPC_INTERFACENAMESIZE];
    union
    {
        struct NIPC_SocketAddr  Address;
        struct NIPC_SocketAddr  Destination;
        struct NIPC_SocketAddr  Broadcast;
        UWORD                   Flags;
        LONG                    Metric;
        APTR                    Data;
    } Info;
};

struct NIPC_InterfaceConf
{
    ULONG   BufferLength;
    union
    {
        APTR                        Buffer;
        struct NIPC_InterfaceInfo   *InterfaceInfo;
    } Info;
};

/*------------------------------------------------------------------------*/
/* Routing information */
struct NIPC_RouteEntry
{
    ULONG                   HashValue;  /* Magic. Don't touch */
    struct NIPC_SocketAddr  Destination;/* Net to match */
    struct NIPC_SocketAddr  Gateway;    /* Which way to send the packet */
    UWORD                   Flags;      /* Magic flags, see below */
    UWORD                   UseCount;   /* How many are currently referencing it */
    ULONG                   PacketCount;/* How many packets used it */
    APTR                    Interface;  /* Private. Don't touch. */
};

#define NIPCRTB_UP          0   /* Route is active */
#define NIPCRTB_GATEWAY     1   /* Destination is a gateway */
#define NIPCRTB_HOST        2   /* This is a host entry, not a net */
#define NIPCRTB_DYNAMIC     4   /* Created by ICMP_REDIRECT */
#define NIPCRTB_MODIFIED    5   /* Modified by ICMP_REDIRECT */

#define NIPCRTF_UP          (1L << NIPCRTB_UP)
#define NIPCRTF_GATEWAY     (1L << NIPCRTB_GATEWAY)
#define NIPCRTF_HOST        (1L << NIPCRTB_HOST)
#define NIPCRTF_DYNAMIC     (1L << NIPCRTB_DYNAMIC)
#define NIPCRTF_MODIFIED    (1L << NIPCRTB_MODIFIED)

/*------------------------------------------------------------------------*/
/* ARP Management */
struct NIPC_ARPRequest
{
    struct NIPC_SocketAddr  ProtocolAddress;
    struct NIPC_SocketAddr  HardwareAddress;
    ULONG                   Flags;
};

#define NIPCARPB_INUSE          0   /* entry in use */
#define NIPCARPB_COM            1   /* completed entry */
#define NIPCARPB_PERM           2   /* permanent entry */
#define NIPCARPB_PUBL           3   /* publish entry (respond for other host) */
#define NIPCARPB_USETRAILERS    4   /* has requested trailers */

#define NIPCARPF_INUSE          (1L << NIPCARPB_INUSE)
#define NIPCARPF_COM            (1L << NIPCARPB_COM)
#define NIPCARPF_PERM           (1L << NIPCARPB_PERM)
#define NIPCARPF_PUBL           (1L << NIPCARPB_PUBL)
#define NIPCARPF_USETRAILERS    (1L << NIPCARPB_USETRAILERS)

/*------------------------------------------------------------------------*/
#define IOCTL(type, op) (((type)<<8) | ((op)&0xff))
#define ROUTE   ('r')
#define NETIF   ('i')
#define MISC    ('m')

#define SIOCADDRT       IOCTL(ROUTE, 1) /* add routing entry to list    */
#define SIOCDELRT       IOCTL(ROUTE, 2) /* delete routing entry         */

#define SIOCSIFADDR     IOCTL(NETIF, 3) /* set interface address        */
#define SIOCGIFADDR     IOCTL(NETIF, 4) /* get interface address        */
#define SIOCSIFDSTADDR  IOCTL(NETIF, 5) /* set interface dest address   */
#define SIOCGIFDSTADDR  IOCTL(NETIF, 6) /* get interface dest address   */
#define SIOCSIFFLAGS    IOCTL(NETIF, 7) /* set interface flags          */
#define SIOCGIFFLAGS    IOCTL(NETIF, 8) /* get interface flags          */
#define SIOCGIFCONF     IOCTL(NETIF, 9) /* get interface configuration  */
#define SIOCSIFMTU      IOCTL(NETIF,10) /* get interface MTU            */
#define SIOCGIFMTU      IOCTL(NETIF,11) /* set interface MTU            */
#define SIOCGIFBRDADDR  IOCTL(NETIF,12) /* get interface brdcst address */
#define SIOCSIFBRDADDR  IOCTL(NETIF,13) /* set interface brdcst address */
#define SIOCGIFNETMASK  IOCTL(NETIF,14) /* get interface netmask        */
#define SIOCSIFNETMASK  IOCTL(NETIF,15) /* set interface netmask        */
#define SIOCGIFMETRIC   IOCTL(NETIF,16) /* set interface metric         */
#define SIOCSIFMETRIC   IOCTL(NETIF,17) /* get interface metric         */
#define SIOCSARP        IOCTL(NETIF,18) /* set ARP resolution           */
#define SIOCGARP        IOCTL(NETIF,19) /* get ARP entry                */
#define SIOCDARP        IOCTL(NETIF,20) /* delete arp entry             */
#define SIOCATMARK      IOCTL(NETIF,21) /* OOB at mark                  */
#define SIOCSSLIPDEV    IOCTL(NETIF,22) /* set slip device              */

#define FIONBIO         IOCTL(MISC, 22)
#define FIONREAD        IOCTL(MISC, 23)
#define FIOASYNC        IOCTL(MISC, 24)

#define SIOCSPGRP       IOCTL(MISC, 25) /* set signalled process        */
#define SIOCGPGRP       IOCTL(MISC, 26) /* get signalled process        */

#endif /* __USE_NIPC_IOCTL */

/*------------------------------------------------------------------------*/

/* EOT */
#endif /* ENVOY_NIPCLOWLEVEL_H */
