/*****************************************************************************
 * 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: lapd_control.h,v 1.6 1999/05/14 21:02:35 gary Exp $
 *
 * 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
 *
 * lapd_control.h of snet module
 *
 * SpiderISDN
 * Release 3.0.0 94/12/20
 * 
 * SpiderISDN Release 3 - Official Release.
 *
 *****************************************************************************/
 
/*
 * lapd_control.h
 * 	LAPD (upper) control interface declarations.
 */

/*
 * Stream ID - each kernel driver has one - used by strlog
 */
#define LAPD_STID	500

#define LC_LAPD_TE	1
#define LC_LAPD_NT	2
#define LC_LAPD_NONE	3

/*
 *   IOCTL commands.  These values follow on from the end of SpiderX25
 *   Link Layer IOCTL commands, which (in release 6.0) have a value between
 *   (N<<8 | 1) and (N<<8 | 16).  The values for LAPD IOCTLs start at '20',
 *   which should be increased if the driver is ever used alongside a
 *   LAPB/LLC2 with an extended range of IOCTL commands.
 */

#define LAPD_CODE	('L' << 8)
#define LAPD_BASE	20

#define LAPD_SETSNID	(LAPD_CODE | (LAPD_BASE+1))
#define LAPD_GETSNID	(LAPD_CODE | (LAPD_BASE+2))
#define LAPD_SETTUNE	(LAPD_CODE | (LAPD_BASE+3))
#define LAPD_GETTUNE	(LAPD_CODE | (LAPD_BASE+4))
#define LAPD_GETSTATS	(LAPD_CODE | (LAPD_BASE+5))
#define LAPD_ZEROSTATS	(LAPD_CODE | (LAPD_BASE+6))
#define LAPD_GETGSTATS	(LAPD_CODE | (LAPD_BASE+7))
#define LAPD_ZEROGSTATS	(LAPD_CODE | (LAPD_BASE+8))
#define LAPD_TRACEON	(LAPD_CODE | (LAPD_BASE+9))
#define LAPD_TRACEOFF	(LAPD_CODE | (LAPD_BASE+10))


/*
 * Values of "l_type", indicating the type of structure used in 
 * LAPD IOCTL commands.
 */
#define LAPD_STATS	0x01	/* Indicates structure lapd_stioc	*/
#define LAPD_GSTATS	0x02	/* Indicates structure lapd_gstats	*/
#define LAPD_TUNE	0x03	/* Indicates structure lapd_tnioc	*/
#define LAPD_SNID	0x04	/* Indicates structure lapd_snioc	*/
#define LAPD_TRACE	0x05	/* Indicates structure lapd_trioc_t	*/


/* 
 * Macros for field value settings in the IOCTL data structures.
 */
#define L_DISCONNECTED	    0		/* Values of l_state field of 	*/
#define L_PENDING	    1		/* the lapd_stioc_t structure	*/
#define L_CONNECTED	    2

#define USE_XID		      0x01	/* Values of llconform field of */
#define TEI_ASSIGN_ON_POWER   0x02	/* the lapd_tune_t structure.	*/
#define ACK_I_ON_NR_ERR       0x04
#define TEI_MGMT_PRIORITY     0x08
#define CHECK_ALL_TEI_ASSIGN  0x10

/* 
 *   Definitions of data sent/received in IOCTL commands, as follows...
 *
 *   lapd_stats_t: Used in the lapd_stioc structure to retrieve per-subnetwork
 *		  statistics with the LAPD_GETSTATS ioctl command.
 *
 *   lapd_gstats_t: Used in the lapd_gstats structure to retrieve global
 *		  statistics with the LAPD_GETGSTATS ioctl command.
 *
 *   lapd_tune_t: Used in the lapd_tnioc structure to set and retrieve
 *		  the values of configurable objects using the LAPD_SETTUNE
 *		  and LAPD_GETTUNE ioctl commands, respectively.
 */

typedef struct lapd_stats {
	uint32 RR_rx_cmd;
	uint32 RR_rx_rsp;
	uint32 RR_tx_cmd;
	uint32 RR_tx_rsp;
	uint32 RR_tx_cmd_p;
	uint32 RNR_rx_cmd;
	uint32 RNR_rx_rsp;
	uint32 RNR_tx_cmd;
	uint32 RNR_tx_rsp;
	uint32 RNR_tx_cmd_p;
	uint32 REJ_rx_cmd;
	uint32 REJ_rx_rsp;
	uint32 REJ_tx_cmd;
	uint32 REJ_tx_rsp;
	uint32 REJ_tx_cmd_p;
	uint32 I_tx_cmd;
	uint32 I_rx_cmd;
	uint32 SABME_rx_cmd;
	uint32 SABME_tx_cmd;
	uint32 DISC_rx_cmd;
	uint32 DISC_tx_cmd;
	uint32 UA_rx_rsp;
	uint32 UA_tx_rsp;
	uint32 DM_rx_rsp;
	uint32 DM_tx_rsp;
	uint32 UI_rx_cmd;
	uint32 UI_tx_cmd;
	uint32 FRMR_rx_rsp;
	uint32 FRMR_tx_rsp;
	uint32 XID_rx_cmd;
	uint32 XID_rx_rsp;
	uint32 XID_tx_cmd;
	uint32 XID_tx_rsp;
	uint32 rx_badlen;
	uint32 rx_unknown;
	uint32 rx_bad;
	uint32 rx_dud;
	uint32 rx_ign;
	uint32 tx_rtr;
	uint32 tx_ign;
	uint32 T200_exp;
	uint32 T200_N200_exp;
	uint32 rx_mgmt_dud;
	uint32 rx_mgmt_badlen;
	uint32 rx_mgmt_ign;
	uint32 rx_mgmt_unknown;
	uint32 rx_tei_assigned;
	uint32 rx_tei_denied;
	uint32 rx_tei_check;
	uint32 rx_tei_remove;
} lapd_stats_t;


typedef struct lapd_gstats {
	uint32 frames_tx;
	uint32 frames_rx;
	uint32 bytes_tx;
	uint32 bytes_rx;
} lapd_gstats_t;


typedef struct lapd_tune {
    uint16  N200;
    uint16  N201;
    uint16  N202;
    uint16  T200;
    uint16  T202;
    uint16  T203;
    uint16  rem_busy_poll;
    uint16  tx_window;
    uint16  ack_delay;
    uint16  notack_max;
    uint16  lme_enabled;
    uint16  llconform;
    uint16  multiple_tei;
    uint16  pad;             /* Align to 32 bit boundry */
} lapd_tune_t;


/*
 * IOCTL block for LAPD_GETSTATS and LAPD_ZEROSTATS commands.
 */
typedef struct lapd_stioc { 
	uint8        	l_type;
	uint8        	l_state;	/* Old version "state" */
	uint8       	l_teistates[2];	/* State of individual TEI's */
	uint32       	l_snid;
	lapd_stats_t 	l_stats;
} lapd_stioc_t;


/* 
 * IOCTL block for LAPD_GETGSTATS and LAPD_ZEROGSTATS commands.
 */
typedef struct lapd_gstioc {
	uint8		l_type;
	uint8		spare[3];
	lapd_gstats_t	l_gstats;
} lapd_gstioc_t;


/* 
 * IOCTL block for LAPD_GETTUNE and LAPD_SETTUNE commands.
 */
typedef struct lapd_tnioc {
	uint8		l_type;
	uint8		spare[3];
	uint32		l_snid;
	lapd_tune_t	l_tune;
} lapd_tnioc_t;


/* 
 * IOCTL block for LAPD_GETSNID and LAPD_SETSNID commands.
 */
typedef struct lapd_snioc {
	uint8  	l_type;
	uint8  	l_class;
	uint8  	spare[2];
	uint32 	l_snid;
	uint32 	l_index;
} lapd_snioc_t;


/*
 * Header only - used for decoding command type.
 */
typedef struct lapd_hdioc {
	uint8	l_type;
	uint8	spare[3];
	uint32	l_snid;
} lapd_hdioc_t;


/*
 * Union of IOCTL blocks.
 */
typedef union lapd_unioc {
	struct lapd_hdioc	lapd_hd;
	struct lapd_stioc	lapd_st;
	struct lapd_gstats	lapd_gs;
	struct lapd_tnioc	lapd_tn;
	struct lapd_snioc	lapd_sn;
} lapd_unioc_t;
