/*++
*******************************************************************************
* Copyright (c) 1999-2000 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 copyrighted work of Digi International   *
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly   *
* prohibited.                                                                 *
*                                                                             *
* Restricted Rights Legend                                                    *
*                                                                             *
* Use, duplication, or disclosure by the Government is subject to             *
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in         *
* Technical Data and Computer Software clause at DFARS 252.227-7031 or        *
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -          *
* Restricted Rights at 48 CFR 52.227-19, as applicable.                       *
*                                                                             *
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343          *
*                                                                             *
*******************************************************************************
--*/
#ifndef WAN_CONTROL_H
#define WAN_CONTROL_H
/******************************************************************
 *
 *  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 W_LINKMINIPORT          ('W'<<8 | 11)
#define W_TRACEON               ('W'<<8 | 12) 
#define W_TRACEOFF              ('W'<<8 | 13)
#define W_LINESTATUS            ('W'<<8 | 14) 



#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)     */
	uint32	hc_noclock;    /* Number of "clock missing" timeouts   */
	uint32	hc_rxbiterr;   /* Number of short frame/bit count errs */
	uint32	hc_rxnomp;     /* Number of frames w/o buffers avail.  */
	uint32	hc_rxglitch;   /* Number of Receive Clock Glitchs      */
	uint32	hc_txglitch;   /* Number of Transmit Clock Glitchs     */
	uint32	hc_rxpacketdisfc; /* Number of Rx Packets Dropped for No BD's */
} hdlcstats_t;

/*
    Ioctl block for WAN L_GETSTATS command
*/
struct wan_stioc {
    uint32          lli_type;      /* Table type = LI_WANSTATS		*/
    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		*/
    uint32          mask;          /* Mask of bits to affect (SET only) */
    uint32          signals;       /* State of bits (SET/GET)           */
};

struct wan_modem_s {
	uint8	wan_type ;
	uint8	resv[3] ;
	struct	wan_mdmioc wan_modems ;
};


/*
    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
#define W_MODE  0x20
#define W_RI    0x40 

/*
    Values for WAN_options field
*/
#define TRANSLATE	1	/* Translate to interface address   */
#define	WAN_NRZI		0x02
#define	WAN_HDLC		0x04
#define	WAN_WAIT_CTS	0x08	/* Raise RTS and wait for CTS */


/*
    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
#define WAN_V36             3
#define WAN_EIA530          4
#define WAN_EIA449          5
#define WAN_CSUDSU          6
#define WAN_SW56            7
#define WAN_V35RS232        8
#define WAN_530             9
#define WAN_LOOPBACK       10
#define WAN_NO_CABLE       11

#define	WAN_CPCI_X21       12
#define	WAN_CPCI_V28       13
#define	WAN_CPCI_V35       14
#define	WAN_CPCI_V36       15
#define	WAN_CPCI_EIA530    16
#define	WAN_CPCI_EIA449    17

#define WAN_LOOPBACK_GOOD  18
#define WAN_LOOPBACK_BAD   19

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

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

struct WAN_mdm
{
	uint32 WAN_cptype;	/* Variant type                            */
	uint32 auto_connect;	/* Establish, maintain physical connection */
	uint32 callreq;		/* Timer for call request state.           */
	uint32 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
{
	uint32      WAN_maxframe;               /* WAN maximum frame size 	*/
	uint32      WAN_baud;                   /* WAN baud rate		*/
	uint32      WAN_StationAddress1;        /* WAN Filtering Address 1	*/
	uint32      WAN_StationAddress2;        /* WAN Filtering Address 2	*/
	uint32      WAN_interface ;             /* WAN physical interface       */
	union {
		uint32	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.	*/
	uint32      WAN_hdplx ;         /* Half-duplex mode tunable     */
} ;


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

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

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

struct wan_tune_proto_s {
	uint8	wan_type ;
	uint8	resv[3] ;
	struct	wan_tnioc wan_tune_proto ;

};

#define WAN_MAP_SIZE   (MAXIOCBSZ - 8)
#define MAX_WAN_ENTS   (WAN_MAP_SIZE / sizeof(wanmap_t))
#define MAX_WAN_ADDRS   20
#ifdef POWERPC
#define NWANS           4
#else
#define NWANS           2
#endif

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

struct wanmapgf {
	uint32		lli_type;              /* Always LI_WANMAP        */
	uint32		lli_snid;              /* Subnetwork id character */
	wanget_t	wan_ents ;             /* Returned structure      */
};

/*
    Ioctl block for WAN PUT MAP command
*/
struct wanmappf {
	uint32          lli_type;              /* Always LI_WANMAP	  */
	uint32          lli_snid;              /* Subnetwork id character */
	wanmap_t	wan_ent;               /* Mapping entry           */
};

/*
    Ioctl block for WAN DEL MAP command
*/
struct wanmapdf {
	uint32		lli_type;		/* Always LI_WANMAP        */
	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 {
    uint32	    lli_type;		/* Table type = LI_WANSTATUS	*/
    uint32	    lli_snid;		/* subnetwork id character 	*/
    uint32	    wan_status;		/* Table of tuning values	*/
};

/*
    Ioctl header block. Used for WAN W_ENABLE/W_DISABLE command
*/
struct wan_hdioc {
    uint32          lli_type;      /* Table type = LI_WANPLAIN		*/
    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 ;

/*
 * Trace Direction
 */
#define WAN_TRACE_DIRECTION_TRANSMIT    0
#define WAN_TRACE_DIRECTION_RECEIVE     1


typedef struct wan_trace {
	uint32	wan_trace_snid ;
	uint32	wan_trace_sequence ;
	uint32	wan_trace_direction ;
	uint32	wan_trace_time ; 
	uint32	wan_trace_modem ; 
	uint32	wan_trace_modem_delta ;
	uint32	wan_trace_cable_id ;
	uint32  wan_trace_line_speed ;
	uint32	wan_trace_line_status ;
} wan_trace_t ;

/*
	WAN_LINESTATUS_FLAGS set to one denotes receiving flags
	WAN_LINESTATUS_IDLE  set to one denotes a idle line 
 */
#define	WAN_LINESTATUS_AVAILABLE 0x00000008
#define WAN_LINESTATUS_FLAGS 	0x00000004
#define WAN_LINESTATUS_IDLE  	0x00000001


 typedef struct wan_linestatus {
	uint32  wan_linestatus_snid ;
	uint32  wan_linestatus_linespeed ;
	uint32  wan_linestatus_linestatus ; 
	uint32  wan_linestatus_config_baud ;
	uint32  wan_linestatus_maxframe ;
	uint32  wan_linestatus_options ;
	uint32  wan_linestatus_hdplx ;
	hdlcstats_t wan_linestatus_stats ;
	uint32  wan_linestatus_cable_id ;
	uint8   wan_linestatus_modem ;
	uint8   resv[3] ;
	char    SerialNum[12] ;
} wan_linestatus_t ;


struct wan_get_line_status_proto_s {
	uint8	wan_type ;
	uint8	resv[3]  ;
	wan_linestatus_t linestatus ;
} ;


typedef struct wan_trace_config {
	uint32	wan_trace_snid ;
}wan_trace_config_t ;


#endif // WAN_CONTROL_H