/*****************************************************************************
 * Copyright (c) 1988-95 Digi International Inc., All Rights Reserved
 * 
 * This  software  contains  proprietary  and  confidential   information   of
 * Digi International  Inc.   By  accepting  transfer  of this copy, Recipient
 * agrees to retain this software in  confidence,  to  prevent  disclosure  to
 * others,  and  to make no  use of this software other than that for which it
 * was delivered.  This is an unpublished copyright work  Digi   International
 * Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is
 * strictly prohibited.
 * 
 * Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc.
 * Confidential  when   combined   with   the   aggregated  modules  for  this
 * product) OBJECT CODE ONLY SOURCE MATERIALS
 * 
 * (C) COPYRIGHT Digi International Inc. 1995
 * 
 * All Rights Reserved
 * 
 * US   Government   Users   Restricted   Rights   -   Use,   duplication   or
 * disclosure  restricted by GSA ADP Schedule Contract with Digi International
 * Inc.
 * 
 *****************************************************************************/

/*
 * $Id: wan_control.h,v 1.8 1996/10/24 20:24:19 gary Exp $
 */

/******************************************************************
 *
 *  SpiderX25 Protocol Streams Component
 *
 *  Copyright 1991  Spider Systems Limited
 *
 *  WAN_CONTROL.H
 *
 ******************************************************************/

/* For host systems */
#ifndef MAXIOCBSZ
#define	MAXIOCBSZ	1024
#endif

#define	W_SETTUNE	('W'<<8 | 1) /* set tuning parameters (use wan_tnioc) */
#define W_GETTUNE	('W'<<8 | 2) /* get tuning parameters (use wan_tnioc) */
#define	W_PUTWANMAP	('W'<<8 | 3)
#define	W_GETWANMAP	('W'<<8 | 4)
#define	W_DELWANMAP	('W'<<8 | 5)
#define W_STATUS	('W'<<8 | 6)
#define W_ENABLE	('W'<<8 | 7)
#define W_DISABLE	('W'<<8 | 8)
#define W_SETMODEM	('W'<<8 | 9)
#define W_GETMODEM	('W'<<8 | 10)

#define LI_WANSTATS	0x34        /* Indicates 'struct wan_stioc' */
#define LI_WANTUNE	0x35	    /* Indicates 'struct wan_tnioc' */
#define LI_WANMAP	0x35	    /* Indicates 'struct wan_mpioc' */
#define LI_WANSTATUS    0x36        /* Indicates 'struct sntioc'    */
#define LI_WANPLAIN     0x37        /* Indicates 'struct hdioc'     */

#define	RFC_1317_RS232		('M'<<8 | 1)	/* For RS-232 MIB */
#define	RFC_1317_SYNCPORT	('M'<<8 | 2)	/* For Sync MIB */
#define	RFC_1317_INSIG		('M'<<8 | 3)	/* For InSig MIB */
#define	RFC_1317_OUTSIG		('M'<<8 | 4)	/* For OutSig MIB */


/*
    HDLC statistics (one per channel)
*/
typedef struct hstats
{
    uint32           hc_txgood;     /* Number of good frames transmitted    */
    uint32           hc_txgdbytes;  /* Number of good bytes transmitted     */
    uint32           hc_txurun;     /* Number of transmit underruns         */
    uint32           hc_rxgood;     /* Number of good frames received       */
    uint32           hc_rxgdbytes;  /* Number of good bytes 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		    */
    uint32           hc_txabort;    /* Number of tx aborts (hdplx only)	    */
} hdlcstats_t;

/*
    Ioctl block for WAN L_GETSTATS command
*/
struct wan_stioc {
    uint8           lli_type;      /* Table type = LI_WANSTATS		*/
    uint8           lli_spare[3];  /*   (for alignment)			*/
    uint32          lli_snid;      /* Subnetwork ID character		*/
    hdlcstats_t     hdlc_stats;    /* Table of HDLC stats values	*/
};

/*
    Ioctl block for WAN W_GETMODEM/W_SETMODEM command
*/
struct wan_mdmioc {
    uint32          snid;          /* Subnetwork ID character		*/
    uint8           mask;          /* Mask of bits to affect (SET only) */
    uint8           signals;       /* State of bits (SET/GET)           */
};

/*
    Signals for W_GETMODEM/W_SETMODEM commands
*/
#define	W_DTR	0x01
#define	W_RTS	0x02
#define	W_CTS	0x04
#define	W_DSR	0x08
#define	W_DCD	0x10

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

/*
    Values for WAN_procs field

    N.b. these values are used to directly access the procedural interface
    table for all supported calling procedures. So do not change these values
    without changing the access method for the table.
*/
#define	WAN_NONE	0	/* No calling procedures	*/
#define WAN_X21P        1       /* X21 calling procedures       */
#define WAN_V25bis      2       /* V25bis calling procedures    */
#define WAN_MDM         3       /* Basic modem support          */

/*
    Values for WAN_interface field
*/
#define WAN_X21         0
#define WAN_V28         1
#define WAN_V35         2


/*
	This contains all of the national network specific timeouts.
*/
struct  WAN_x21
{
	uint16	WAN_cptype ;	/* Variant type.                        */
	uint16	T1 ;		/* Timer for call request state.        */
	uint16	T2 ;		/* Timer for EOS to data transfer.      */
	uint16	T3A ;		/* Timer for call progress signals.     */
	uint16	T4B ;		/* Timer for DCE provided info.         */
	uint16	T5 ;		/* Timer for DTE clear request.         */
	uint16	T6 ;		/* Timer for DTE clear conf. state.     */
} ;

/*
	This contains all of the national network specific timeouts.
*/
struct  WAN_v25
{
	uint16	WAN_cptype ;	/* Variant type.        */
	uint16	callreq ;	/* Abort time for call request command  *
				 * if network does not support CFI.     */
} ;

struct WAN_mdm
{
	uint16 WAN_cptype;	/* Variant type                            */
	uint16 auto_connect;	/* Establish, maintain physical connection */
	uint16 callreq;		/* Timer for call request state.           */
	uint16 dcd_cts_flutter; /* In units of milliseconds                */
};

/*
	This is the structure which contains all tuneable information
	which is passed from user space to HDLC.
*/
struct	WAN_hddef
{
	uint16	    WAN_maxframe;	/* WAN maximum frame size 	*/
	uint32	    WAN_baud;		/* WAN baud rate		*/
        uint16      WAN_interface ;     /* WAN physical interface       */
        union {
        	uint16	WAN_cptype ;	/* Variant type.	*/
		struct	WAN_x21	WAN_x21def ;
		struct	WAN_v25	WAN_v25def ;
		/* struct  WAN_mdm WAN_mdmdef; */
        } WAN_cpdef ;                 /* WAN call procedural definition *
                                       * for hardware interface.	*/
	uint8       WAN_hdplx ;		/* Half-duplex mode tunable     */
} ;


/*
    WAN tuning structure
*/
typedef struct wantune
{
	uint16			WAN_options;	/* WAN options		*/ 
	struct	WAN_hddef	WAN_hd ;	/* HD information.	*/
} wantune_t;

/*
    Ioctl block for WAN W_SETTUNE command
*/
struct wan_tnioc {
    uint8	    lli_type;	  /* Table type = LI_WANTUNE		    */
    uint8	    lli_spare[3]; /* (for alignment)			    */
    uint32	    lli_snid;	  /* subnetwork id character ('*' => 'all') */
    wantune_t	    wan_tune;	  /* Table of tuning values		    */
};

/*
    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_WAN_ENTS   (WAN_MAP_SIZE / sizeof(wanmap_t))
#define MAX_WAN_ADDRS   20
#define NWANS           2

/*
    Ioctl block for WAN GET MAP command
*/
typedef struct wangetf {
	uint16          first_ent;             /* Where to start search   */
	uint16          num_ent;               /* Number entries returned */
	wanmap_t	entries[MAX_WAN_ENTS]; /* Data buffer             */
} wanget_t ;

struct wanmapgf {
	uint8		lli_type;              /* Always LI_WANMAP        */
	uint8		lli_spare[3];          /* For alignment           */
	uint32		lli_snid;              /* Subnetwork id character */
	wanget_t	wan_ents ;             /* Returned structure      */
};

/*
    Ioctl block for WAN PUT MAP command
*/
struct wanmappf {
	uint8           lli_type;              /* Always LI_WANMAP	  */
	uint8           lli_spare[3];          /* For alignment		  */
	uint32          lli_snid;              /* Subnetwork id character */
	wanmap_t	wan_ent;               /* Mapping entry           */
};

/*
    Ioctl block for WAN DEL MAP command
*/
struct wanmapdf {
	uint8		lli_type;		/* Always LI_WANMAP        */
	uint8		lli_spare[3];		/* For alignment           */
	uint32		lli_snid;		/* Subnetwork id character */
};

/*
    Subnetwork status values returned by WAN
*/
#define W_DISCONNECTED   0
#define W_PENDING_DISC   1
#define W_PENDING_CONN   2
#define W_CONNECTED      3
/*
    Ioctl block for WAN W_STATUS command
*/
struct wan_sntioc {
    uint8	    lli_type;		/* Table type = LI_WANSTATUS	*/
    uint8	    lli_spare[3];	/* (for alignment)		*/
    uint32	    lli_snid;		/* subnetwork id character 	*/
    uint8	    wan_status;		/* Table of tuning values	*/
};

/*
    Ioctl header block. Used for WAN W_ENABLE/W_DISABLE command
*/
struct wan_hdioc {
    uint8           lli_type;      /* Table type = LI_WANPLAIN		*/
    uint8           lli_spare[3];  /*   (for alignment)			*/
    uint32          lli_snid;      /* Subnetwork ID character		*/
};

/*
 * Structure for RFC_1317_RS232 call
 */
typedef struct rfc_1317_rs232_struct {
	uint32	rs232PortIndex ;
	uint32	rs232PortType ;
	uint32	rs232PortInSigNumber ;
	uint32	rs232PortOutSigNumber ;
	uint32	rs232PortInPortSpeed ;
	uint32	rs232PortOutPortSpeed ;
} rfc_1317_rs232_t ;

/*
 * Structure for RFC_1317_SYNCPORT call
 */
typedef struct rfc_1317_syncport_struct {
	uint32	rs232SyncPortIndex ;
	uint32	rs232SyncPortClockSource ;
	uint32	rs232SyncPortFrameCheckErrs ;
	uint32	rs232SyncPortTransmitUnderrunErrs ;
	uint32	rs232SyncPortReceiveOverrunErrs ;
	uint32	rs232SyncPortInterruptedFrames ;
	uint32	rs232SyncPortAbortedFrames ;
} rfc_1317_syncport_t ;

