/*****************************************************************************
 *
 * Copyright (c) 1993-1994 Spider Systems Limited
 *
 * This Source Code is furnished under Licence, and may not be
 * copied or distributed without express written agreement.
 *
 * All rights reserved.  Made in Scotland.
 *
 * Authors: Duncan Walker
 *
 * iwan_control.h of snet module
 *
 * SpiderISDN
 * Release 3.0.0 94/12/20
 * 
 * SpiderISDN Release 3 - Official Release.
 *
 *****************************************************************************/
 
/*
 * iwan_control.h
 * 	WAN (upper) control interface declarations.
 */

/*
 * Stream ID - each kernel driver has one - used by strlog
 */
#define IWAN_STID        501
#define IWLOOP_STID	 502

/*
    Ioctl command values
*/
#define	W_ZEROSTATS	('W'<<8 | 1) 
#define W_GETSTATS	('W'<<8 | 2) 
#define	W_SETTUNE	('W'<<8 | 3)
#define W_GETTUNE	('W'<<8 | 4)
#define	W_PUTMAP	('W'<<8 | 5)
#define	W_GETMAP	('W'<<8 | 6)
#define	W_DELMAP	('W'<<8 | 7)
#define W_SETSNID	('W'<<8 | 8)
#define W_GETSTATUS	('W'<<8 | 9)
#define W_ENABLE	('W'<<8 | 10)
#define W_DISABLE	('W'<<8 | 11)

/*
    Structure Identifiers
*/
#define WAN_HDR		0x33        /* Indicates 'struct wan_hdioc' */
#define WAN_STATS	0x34        /* Indicates 'struct wan_stioc' */
#define WAN_TUNE	0x35        /* Indicates 'struct wan_tnioc' */
#define WAN_MAP		0x36        /* Indicates 'struct wan_mpioc' */
#define WAN_SNID	0x37        /* Indicates 'strcut wan_snioc' */
#define WAN_STATUS	0x38        /* Indicates 'strcut wan_saioc' */

/*
    WAN address mapping structure
*/
typedef struct wanmapf {
    uint8 remsize;        /* Rem address size (octets)        */
    uint8 remaddr[20];    /* Remote address                   */
    uint8 infsize;        /* Interface address size  (octets) */
    uint8 infaddr[30];    /* Interface address                */
} wanmap_t;

#define WAN_MAP_SIZE   (MAXIOCBSZ - 8)
#define MAX_IWAN_ENTS   (WAN_MAP_SIZE / sizeof(wanmap_t))
#define MAX_IWAN_ADDRS  20

/*
    Values for WAN_options field
*/
#define TRANSLATE	1	/* Translate to interface address   */

/*
    Ioctl block for WAN_TUNE operations
*/
struct wan_tnioc {
    uint8  w_type;	    /* Table type = WAN_TUNE	              */
    uint8  w_spare[3];      /* (for alignment)			      */
    uint16 w_options;
    uint16 w_tune_offset;
    uint32 w_snid;          /* subnetwork id character ('*' => 'all') */
    uint32 w_chanid;
};

typedef struct chtune {
	uint32	max_frame_len;
	uint32	default_buf_len;
} chtune_t ;

/*
    Ioctl block for WAN_STATS operations
*/
struct wan_stioc {
    uint8  w_type;         /* Table type = WAN_STATS      */
    uint8  w_spare;        /*   (for alignment)           */
    uint16 w_stats_offset;
    uint32 w_snid;         /* Subnetwork ID character     */
    uint32 w_chanid;       /* Id of physical channel      */
};

/*
    Ioctl block for WAN_STATUS operations
*/
struct wan_saioc {
    uint8   w_type;          /* Table type = WAN_STATUS   */
    uint8   w_spare;         /* (for alignment)	          */
    uint16  w_status_offset;
    uint32  w_snid;	     /* subnetwork id character   */
    uint32  w_chanid;        /* Id of physical channel    */
};

/*
    Ioctl block for WAN_MAP operations
*/
struct wan_mpioc {
    uint8    w_type;                 /* Always W_WANMAP         */
    uint8    w_start;                /* Where to start search   */
    uint8    w_nret;                 /* Number entries returned */
    uint8    w_spare;                /* For alignment           */
    uint32   w_snid;                 /* Subnetwork id character */
    uint32   w_chanid;               /* Channel number		*/
    wanmap_t w_ents[MAX_IWAN_ENTS];  /* Mapping Entries         */
};

/*
    Values for w_class field
 */
#define	FRAME_RELAY        2         /* Frame Relay partition  */
#define ISDN_DCHAN         1         /* D-channel              */
#define ISDN_BCHAN         0         /* B-channel              */

/*
    Ioctl block for WAN_SNID operations
*/
struct wan_snioc {
    uint8  w_type;           /* WAN_SNID                 */
    uint8  w_class;          /* Class of physical channel */
    uint16 w_spare;          /* for alignment		  */
    uint32 w_chanid;         /* Id of physical channel    */
    uint32 w_snid;           /* Subnetwork ID for stream  */
};

/*
    Standard Ioctl block header. Used for WAN_ENABLE/DISABLE.
*/
struct wan_hdioc {
    uint8  w_type;           /* WAN_HDR                   */
    uint8  w_spare[3];       /* for alignment		  */
    uint32 w_chanid;         /* Id of physical channel    */
    uint32 w_snid;           /* Subnetwork ID for stream  */
};

/*
    Typedefs for IOCTL structures
*/
typedef struct wan_hdioc wan_hdioc_t;
typedef struct wan_tnioc wan_tnioc_t;
typedef struct wan_stioc wan_stioc_t;
typedef struct wan_snioc wan_snioc_t;
typedef struct wan_saioc wan_saioc_t;
typedef struct wan_mpioc wan_mpioc_t;

/*
    The following structures contain information dependant on the
    hardware driver implementation. Namely the statistics that the
    hardware driver reports and the configuration information it
    requires for supported procedures and the status information
    it maintains.
*/

/*
    Structure used for conveying statistics information
*/
typedef struct isdnstats
{
    uint32 hc_txoctets;   /* Number of octets transmitted         */
    uint32 hc_txgood;     /* Number of good frames transmitted    */
    uint32 hc_txclass1;   /* Number of priority 1 frames tx       */
    uint32 hc_txclass2;   /* Number of priority 2 frames tx       */
    uint32 hc_txdef;      /* Number of transmit deferrals         */
    uint32 hc_txurun;     /* Number of transmit underruns         */
    uint32 hc_rxoctets;   /* Number of octets received            */
    uint32 hc_rxgood;     /* Number of good frames received       */
    uint32 hc_rxerr;      /* Number of error frames received      */
    uint32 hc_rxorun;     /* Number of receive overruns           */
    uint32 hc_rxcrc;      /* Number of receive CRC/Framing errors */
    uint32 hc_rxnobuf;    /* Number of Rx frames with no buffer   */
    uint32 hc_rxnflow;    /* Number of Rx frames with no flow ctl */
    uint32 hc_rxoflow;    /* Number of receive buffer overflows   */
    uint32 hc_rxabort;    /* Number of receive aborts		  */
} isdnstats_t;

/*
    Structure used for conveying configuration information
*/
typedef struct iwantune
{
    uint16 i_maxframe;
    uint16 i_baud;
    uint16 i_t3;
    uint16 i_power;
} iwan_tune_t;

/*
    Structure used for conveying status information
*/
typedef struct isdnstatus
{
    uint8  i_powerstatus; /* Connected status (phantom power detect) */
    uint8  i_actstate;    /* Activation State                        */
    uint8  i_rxinfo;      /* Receive INFO State                      */
    uint8  i_txinfo;      /* Transmit INFO State                     */
} isdnstatus_t;

/*
    Values for i_powerstatus field
*/
#define POWER_NOTCONNECTED	0
#define POWER_CONNECTED		1
#define POWER_UNKNOWN		2

/*
    Values for i_actstate field
*/
#define ACT_F1          1
#define ACT_F2          2
#define ACT_F3          3
#define ACT_F4          4
/* note - there is no State 5, it is subsumed into State F4 */
#define ACT_F6          6
#define ACT_F7          7
#define ACT_F8          8

/*
    Values for i_rxinfo and i_txinfo fields
*/
#define ISDN_INFO_0		0
#define ISDN_INFO_1		1
#define ISDN_INFO_2		2
#define ISDN_INFO_3		3
#define ISDN_INFO_4		4
#define ISDN_INFO_X		5

/*
    Loopback parameters 
*/
typedef struct iloop
{
    uint8  lp_location;      /* Location of loopback		*/
    uint8  lp_type;          /* Type of loopback		*/
    uint8  lp_transparency;  /* Transparent/non transparent     */
} isdnloop_t;

/*
    Values for lp_location field
*/
#define LOOP_NONE		0
#define LOOP_FORCE1		1	
#define LOOP_FORCE0		2
#define LOOP_96KHZ		3
#define LOOP_4			4	/* CCITT I.430 Loopback 4 */
#define LOOP_A			5	/* CCITT I.430 Loopback A */
#define LOOP_AFREERUN		6	/* As A, but free running clock */
#define LOOP_EXTERNAL		7

/*
    Values for lp_type field
*/
#define LT_PARTIAL		0	/* See Appendix 1 to I.430 */
#define LT_COMPLETE		1	/* See Appendix 1 to I.430 */

/*
    Values for lp_transparency field
*/
#define LT_NONTRANSPARENT	0	/* See Appendix 1 to I.430 */
#define LT_TRANSPARENT		1	/* See Appendix 1 to I.430 */
