/*++
*******************************************************************************
* 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 IWAN_CONTROL_H
#define IWAN_CONTROL_H

/*****************************************************************************
 *
 * 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


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


/*
    Ioctl command values
*/
#define N_ZEROSTATS          ('W'<<8 | 1) 
#define N_GETSTATS           ('W'<<8 | 2) 
#define N_SETTUNE            ('W'<<8 | 3)
#define N_GETTUNE            ('W'<<8 | 4)
#define N_PUTMAP             ('W'<<8 | 5)
#define N_GETMAP             ('W'<<8 | 6)
#define N_DELMAP             ('W'<<8 | 7)
#define N_SETSNID            ('W'<<8 | 8)
#define N_GETSTATUS          ('W'<<8 | 9)
#define N_ENABLE             ('W'<<8 | 10)
#define N_DISABLE            ('W'<<8 | 11)

/*
    Structure Identifiers
*/
#define WAN_HDR              0x33  /* Indicates 'struct iwan_hdioc' */
#define WAN_STATS            0x34  /* Indicates 'struct iwan_stioc' */
#define WAN_TUNE             0x35  /* Indicates 'struct iwan_tnioc' */
#define WAN_MAP              0x36  /* Indicates 'struct iwan_mpioc' */
#define WAN_SNID             0x37  /* Indicates 'strcut iwan_snioc' */
#define WAN_STATUS           0x38  /* Indicates 'strcut iwan_saioc' */

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

#define WAN_MAP_SIZE   (MAXIOCBSZ - 8)
#define MAX_IWAN_ENTS   (WAN_MAP_SIZE / sizeof(iwanmap_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 iwan_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 iwan_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 iwan_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 iwan_mpioc {
    uint8     w_type;                 /* Always N_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		*/
    iwanmap_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 iwan_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 iwan_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 iwan_hdioc iwan_hdioc_t;
typedef struct iwan_tnioc iwan_tnioc_t;
typedef struct iwan_stioc iwan_stioc_t;
typedef struct iwan_snioc iwan_snioc_t;
typedef struct iwan_saioc iwan_saioc_t;
typedef struct iwan_mpioc iwan_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 */

#endif // IWAN_CONTROL_H