/*****************************************************************************
 * 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: ll_control.h,v 1.6 1997/09/23 16:38:02 gary Exp $
 */

/******************************************************************
 *
 *  SpiderX25 Protocol Streams Component
 *
 *  Copyright 1991  Spider Systems Limited
 *
 *  LL_CONTROL.H
 *
 *    LAPB Top-level STREAMS interface.
 *
 ******************************************************************/

/* IOCTL commands */
#define L_SETSNID   ('L'<<8 | 1) /* Set subnetwork identifier (use ll_snioc) */
#define L_GETSNID   ('L'<<8 | 2) /* Get subnetwork identifier (use ll_snioc) */
#define L_SETTUNE   ('L'<<8 | 3) /* Set tuning parameters (use ll_tnioc)     */
#define L_GETTUNE   ('L'<<8 | 4) /* Get tuning parameters (use ll_tnioc)     */
#define L_GETSTATS  ('L'<<8 | 5) /* Get statistics counts (use ll_stioc)     */
#define L_ZEROSTATS ('L'<<8 | 6) /* Zero statistics       (use ll_hdioc)     */
#define L_TRACEON   ('L'<<8 | 7) /* Set message tracing on.                  */
#define L_TRACEOFF  ('L'<<8 | 8) /* Set message tracing off.                 */

/* LAPB MIB commands */
#define	RFC_1381_ADMN	('M'<<8 | 33)	/* LAPB configuration MIB */
#define	RFC_1381_FLOW	('M'<<8 | 34)	/* Statistics MIB */

/* Values for 'lli_type' (with names of corresponding structures) */
#define LI_PLAIN	0x01        /* Indicates 'struct ll_hdioc'  */
#define LI_SNID		0x02        /* Indicates 'struct ll_snioc'  */
#define LI_STATS	0x04        /* Indicates 'struct ll_stioc'  */

#define LI_LAPBTUNE	0x13        /* Indicates 'struct lapb_tnioc'*/
#define LI_LLC2TUNE	0x23        /* Indicates 'struct llc2_tnioc'*/

/* LAPB tuning structure */
typedef struct lapbtune {
    uint32  N2;		    /* Maximum number of retries		*/
    uint32  T1;		    /* Acknowledgement time	(unit 0.1 sec)  */
    uint32  Tpf;            /* P/F cycle retry time	(unit 0.1 sec)  */
    uint32  Trej;           /* Reject retry time	(unit 0.1 sec)  */
    uint32  Tbusy;          /* Remote busy check time   (unit 0.1 sec)  */
    uint32  Tidle;          /* Idle P/F cycle time	(unit 0.1 sec)  */
    uint32  ack_delay;      /* RR delay time		(unit 0.1 sec)  */
    uint32  notack_max;     /* Maximum number of unack'ed Rx I-frames   */
    uint32  tx_window;      /* Transmit window size			*/
    uint32  tx_probe;       /* P-bit position before end of Tx window   */
    uint32  max_I_len;      /* Maximum I-frame length			*/
    uint32  llconform;      /* LAPB conformance				*/
} lapbtune_t;

/* Values for llconform field in lapbtune_t  */

#define	IGN_UA_ERROR       1	/* UA frames ignored in ERROR state	*/
#define	FRMR_FRMR_ERROR    2	/* FRMR is retransmitted in ERROR state	*/
#define	FRMR_INVRSP_ERROR  4	/* Invalid response frames are FRMR'ed	*/
#define	SFRAME_PBIT        8	/* S frame commands must have P-bit set	*/
#define	NO_DM_ADM         16	/* Dont send DM on entry to ADM state   */

/* LLC2 tuning structure */
typedef struct llc2tune {
    uint32  N2;		    /* Maximum number of retries		*/
    uint32  T1;		    /* Acknowledgement time	(unit 0.1 sec)  */
    uint32  Tpf;            /* P/F cycle retry time	(unit 0.1 sec)  */
    uint32  Trej;           /* Reject retry time	(unit 0.1 sec)  */
    uint32  Tbusy;          /* Remote busy check time   (unit 0.1 sec)  */
    uint32  Tidle;          /* Idle P/F cycle time	(unit 0.1 sec)  */
    uint32  ack_delay;      /* RR delay time		(unit 0.1 sec)  */
    uint32  notack_max;     /* Maximum number of unack'ed Rx I-frames   */
    uint32  tx_window;      /* Transmit window (if no XID received)	*/
    uint32  tx_probe;       /* P-bit position before end of Tx window   */
    uint32  max_I_len;      /* Maximum I-frame length			*/
    uint32  xid_window;     /* XID window size (receive window)		*/
    uint32  xid_Ndup;       /* Duplicate MAC XID count  (0 => no test)  */
    uint32  xid_Tdup;       /* Duplicate MAC XID time   (unit 0.1 sec)  */
} llc2tune_t;

/* Header alone (for decoding and L_ZEROSTATS commands) */
struct ll_hdioc {
    uint32          lli_type;      /* Table type = LI_PLAIN	*/
    uint32          lli_snid;      /* Subnetwork ID character	*/
};

/* Ioctl block for L_SETSNID and L_GETSNID commands */
struct ll_snioc {
    uint32          lli_type;      /* Table type = LI_SNID		*/
    uint32          lli_snid;      /* Subnetwork ID character		*/
    uint32          lli_index;     /* Link index			*/
};


/* Ioctl block for LAPB L_SETTUNE and L_GETTUNE commands */
struct lapb_tnioc {
    uint32          lli_type;      /* Table type = LI_LAPBTUNE		  */
    uint32          lli_snid;      /* Subnetwork ID character ('*' => 'all') */

    lapbtune_t      lapb_tune;     /* Table of tuning values		  */
};

/* Ioctl block for LLC2 L_SETTUNE and L_GETTUNE commands */
struct llc2_tnioc {
    uint32          lli_type;      /* Table type = LI_LLC2TUNE		  */
    uint32          lli_snid;      /* Subnetwork ID character ('*' => 'all') */

    llc2tune_t      llc2_tune;     /* Table of tuning values		  */
};


/* Statistics table definitions 	*/
/* Both LAPB and LLC2 			*/
#define RR_rx_cmd           0   /* RR = Receive Ready           */
#define RR_rx_rsp           1   /* tx = transmitted             */
#define RR_tx_cmd           2   /* rx = received                */
#define RR_tx_rsp           3   /* cmd/rsp = command/response   */
#define RR_tx_cmd_p         4   /* p = p-bit set                */

#define RNR_rx_cmd          5   /* RNR = Receive Not Ready      */
#define RNR_rx_rsp          6
#define RNR_tx_cmd          7
#define RNR_tx_rsp          8
#define RNR_tx_cmd_p        9

#define REJ_rx_cmd         10   /* REJ = Reject                 */
#define REJ_rx_rsp         11
#define REJ_tx_cmd         12
#define REJ_tx_rsp         13 
#define REJ_tx_cmd_p       14

#define SABME_rx_cmd       15   /* SABME = Set Asynchronous     */
#define SABME_tx_cmd       16   /*       Balanced Mode Extended */

#define DISC_rx_cmd        17   /* DISC = Disconnect            */
#define DISC_tx_cmd        18

#define UA_rx_rsp          19   /* UA = Unnumbered              */
#define UA_tx_rsp          20   /*      Acknowledement          */

#define DM_rx_rsp          21
#define DM_tx_rsp          22

#define I_rx_cmd           23   /* I = Information              */
#define I_tx_cmd           24

#define FRMR_rx_rsp        25   /* FRMR = Frame Reject          */
#define FRMR_tx_rsp        26

/* LAPB only */
#define SABM_rx_cmd        27   /* SABM = Set Asynchronous      */
#define SABM_tx_cmd        28   /*        Balanced Mode         */
#define SARM_rx_cmd        29   /* SARM = Set Asynchronous      */
#define SARM_tx_cmd        30   /*        Response Mode         */

#define lapbstatmax        31

/* LLC2 only */
/* values mutually exclusive with LAPB */

#define I_rx_rsp	   27
#define I_tx_rsp           28

#define UI_rx_cmd          29
#define UI_tx_cmd          30

#define XID_rx_cmd         31
#define XID_rx_rsp         32
#define XID_tx_cmd         33
#define XID_tx_rsp         34

#define TEST_rx_cmd        35
#define TEST_rx_rsp        36
#define TEST_tx_cmd        37
#define TEST_tx_rsp        38

#define llc2statmax        39

typedef struct llc2_stats {
	uint32	llc2monarray[llc2statmax]; /* array of LLC2 stats */
} llc2stats_t;

typedef struct lapb_stats {
	uint32	lapbmonarray[lapbstatmax]; /* array of LAPB stats */
} lapbstats_t;

/* Ioctl block for L_GETSTATS command */
struct llc2_stioc {
    uint32          lli_type;	   /* Table type = LI_STATS		*/
    uint32          lli_snid;      /* Subnetwork ID character		*/
    llc2stats_t     lli_stats;     /* Table of stats values		*/
};

struct lapb_stioc {
    uint32          lli_type;   /* Table type = LI_STATS		*/
    uint32          lli_snid;   /* Subnetwork ID character		*/
    uint32	    state;      /* connection state			*/

    lapbstats_t     lli_stats;  /* Table of stats values		*/
};

/* Union of ioctl blocks */
typedef union lli_union {
    struct ll_hdioc	ll_hd;      /* Parameter-less command       	*/
    struct ll_snioc	ll_sn;      /* Set/get subnetwork identifier    */
    struct lapb_tnioc   lapb_tn;    /* Set/get LAPB tuning          	*/
    struct llc2_tnioc   llc2_tn;    /* Set/get LLC2 tuning          	*/
    struct llc2_stioc   llc2_st;    /* Get llc2 statistics          	*/
    struct lapb_stioc   lapb_st;    /* Get lapb statistics          	*/
} lliun_t;

/* LAPB MIB structures */
typedef struct rfc_1381_admn_struct {
	uint32	lapbAdmnIndex ;
	uint32	lapbAdmnStationType ;
	uint32	lapbAdmnControlField ;
	uint32	lapbAdmnTransmitN1FrameSize ;
	uint32	lapbAdmnReceiveN1FrameSize ;
	uint32	lapbAdmnTransmitKWindowsSize ;
	uint32	lapbAdmnReceiveKWindowsSize ;
	uint32	lapbAdmnN2RxmitCount ;
	uint32	lapbAdmnT1AckTimer ;
	uint32	lapbAdmnT2AckDelayTimer ;
	uint32	lapbAdmnT3DisconnectTimer ;
	uint32	lapbAdmnT4IdleTimer ;
	uint32	lapbAdmnActionInitiate ;
	uint32	lapbAdmnActionRecvDM ;
} rfc_1381_admn_t ;

typedef struct rfc_1381_flow_struct {
	uint32	lapbFlowIndex ;
	uint32	lapbFlowStateChanges ;
	uint32	lapbFlowChangeReason ;
	uint32	lapbFlowCurrentMode ;
	uint32	lapbFlowBusyDefers ;
	uint32	lapbFlowRejOutPkts ;
	uint32	lapbFlowRejInPkts ;
	uint32	lapbFlowT1Timeouts ;
	uint32	lapbFlowFrmrSent ;
	uint32	lapbFlowFrmrReceived ;
	uint32	lapbFlowXidReceived ;
} rfc_1381_flow_t ;

