/*****************************************************************************
 * 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: x25_proto.h,v 1.5 1997/09/24 23:13:45 gary Exp $
 */

/******************************************************************
 *
 *  Spider-X25 Interface Primitives
 *
 *  Copyright (C) 1991  Spider Systems Limited
 *
 *  X25_PROTO.H
 *
 *  Streams primitives include file 
 *  for X.25 Network Service Users
 *
 ******************************************************************/

/* ---- MESSAGE TYPE FIELDS FOR NETWORK SERVICE USER ---- */

#define		XL_DAT		0	/* Data type    */
#define		XL_CTL		1	/* Control type */

/* ---- INDICATIONS TO NETWORK SERVICE USER ---- */

#define		N_Data		0	/* Data           */
#define		N_EData		1	/* Expedited data */
#define		DTflow		2	/* data flow      */
#define		N_EAck		3	/* expedited ack  */
#define		N_CI		4	/* Connect        */
#define		N_CC		5	/* Connect conf   */
#define		N_DI		6	/* Disconnect     */
#define		N_RI		7	/* Reset          */
#define		N_RC		8	/* Reset conf     */
#define		N_Abort		9	/* Abort - DI but no resource */
#define 	N_DC		10	/* Disconnect Confirm         */

#define		N_Xlisten	11	/* Listen request */
#define		N_Xcanlis	12	/* Cancel listen  */

#define		N_DAck          13      /* data ack       */

#define		N_PVC_ATTACH	14	/* PVC attach msg */
#define		N_PVC_DETACH	15	/* PVC detach msg */


/* ----------------------------------------------------------------------
 *              Address formats for the NS user
 * ----------------------------------------------------------------------
 */

#define		LSAPMAXSIZE	12
#define		DTEMAXSIZE	(LSAPMAXSIZE * 2)-1
#define		NSAPMAXSIZE	20
#define		MAXAOCTETS	NSAPMAXSIZE
#define		MAXASEMIOCTETS	(MAXAOCTETS << 1)

struct lsapformat {
	uint32 		lsap_len;
	uint8 		lsap_add[LSAPMAXSIZE];
};

struct xaddrf {
	uint32		sn_id;
	uint32		aflags;
	uint32		nsap_len;
	struct lsapformat	DTE_MAC;
	uint8		NSAP[NSAPMAXSIZE];
};


/*
 *----------------------------------------------------------------------
 *	Flag settings for 'aflags' field.
 * ----------------------------------------------------------------------
 */

#define		NSAP_ADDR	0
#define		EXT_ADDR	1
#define		PVC_LCI		2

/* ----------------------------------------------------------------------
 *  Declaration of the 'qos' and 'extraformat' used in the user interface.
 * ----------------------------------------------------------------------
 */
#define MAX_CUG_LEN	4
#define MAX_RPOA_LEN 	8
#define MAX_NUI_LEN	64
#define MAX_FAC_LEN	32

#define MAX_PROT        32
#define PRT_SRC         1
#define PRT_DST         2
#define PRT_GLB         3

#define MAX_PRTY_LEN    6

/*  Charging Information Sizes  - Set up for four different tariffs.  */

#define		MAX_TARIFFS	4
#define		MAX_MU_LEN	16
#define		MAX_SC_LEN	(MAX_TARIFFS * 8)
#define		MAX_CD_LEN	(MAX_TARIFFS * 4)

#define CUG	1
#define BCUG	2

/* Possible values for reqackservice */

#define RC_CONF_DTE	1
#define RC_CONF_APP	2


struct extraformat {
	uint32	  fastselreq;
	uint32	  restrictresponse, reversecharges;
	uint32	  pwoptions;
	uint32	  locpacket, rempacket;
	uint32	  locwsize , remwsize;
	int32		  nsdulimit;
	uint32	  nui_len;
	uint8	  nui_field[MAX_NUI_LEN];
	uint32    rpoa_len;
	uint8	  rpoa_field[MAX_RPOA_LEN];
	uint32    cug_type;
	uint8 	  cug_field[MAX_CUG_LEN];
	uint32	  reqcharging;
	uint32	  chg_cd_len;
	uint8	  chg_cd_field[MAX_CD_LEN];
	uint32	  chg_sc_len;
	uint8	  chg_sc_field[MAX_SC_LEN];
	uint32	  chg_mu_len;
	uint8	  chg_mu_field[MAX_MU_LEN];
	uint32	  called_add_mod;
	uint32	  call_redirect;
	struct lsapformat called;
	uint32	  call_deflect;
	uint32 	  x_fac_len;
	uint32	  cg_fac_len;
	uint32	  cd_fac_len;
	uint8	  fac_field[MAX_FAC_LEN];
};

struct qosformat {
	uint32		reqtclass;
	uint32		locthroughput, remthroughput;
	uint32		reqminthruput;
	uint32		locminthru, remminthru;
	uint32		reqtransitdelay;
	uint32 		transitdelay;
	uint32		reqmaxtransitdelay;
	uint32 		acceptable;
        uint32	   	reqpriority;
        uint32	 	reqprtygain;
        uint32		reqprtykeep;
        uint32		prtydata;
        uint32		prtygain;
        uint32		prtykeep;
        uint32		reqlowprtydata;
        uint32		reqlowprtygain;
        uint32		reqlowprtykeep;
        uint32		lowprtydata;
        uint32		lowprtygain;
        uint32		lowprtykeep;
        uint32		protection_type;
        uint32		prot_len;
        uint32		lowprot_len;
        uint8		protection[MAX_PROT];
        uint8		lowprotection[MAX_PROT];
	uint32		reqexpedited;
	uint32		reqackservice;

	struct extraformat xtras;
};


/* Packet & Window size negotiation values	*/

#define	DEF_X25_PKT	7		/* default X.25 packet size (2^n)   */
#define	DEF_X25_WIN	2		/* default X.25 window size	    */

/* pwoptions bit fields - true if set	*/

#define	NEGOT_PKT	0x01		/* packet size is negotiable	    */
#define	NEGOT_WIN	0x02		/* window size is negotiable	    */
#define	ASSERT_HWM	0x04		/* assert concatenation into NSDU   */
					/* up to high-water mark given	    */

/* ----------------------------------------------------------------------
 *                 Interface Message Structures
 * ----------------------------------------------------------------------
 */
  
typedef struct xhdrf {
	uint32 xl_type;
	uint32 xl_command;
} S_X25_HDR;

/* WARNING:
       This structure must not exceed the size of the LAPB ll_msg structure,
       since X.25 attempts to re-use the ll_msg buffer for its xdataf
       header.  See ll_proto.h.
*/
struct xdataf {
	uint32		xl_type;        /* Always XL_DAT */
	uint32	 	xl_command;     /* Always N_Data */
	uint32	 	More,           /* Set when more data is required to */
                                   	/* complete the nsdu */
			setDbit,	/* Set when data carries X.25 D-bit */
              		setQbit;	/* Set when data carries X.25 Q-bit */
};

struct xdatacf {
	uint32		xl_type;	/* Always XL_DAT */
	uint32		xl_command;	/* Always N_DAck */
};

struct xedataf {
	uint32		xl_type;	/* Always XL_DAT */
	uint32		xl_command;	/* Always N_EData */
};

struct xedatacf {
	uint32		xl_type;	/* Always XL_DAT */
	uint32		xl_command;	/* Always N_EAck */
};

struct xrstf {
	uint32		xl_type;	/* Always XL_CTL */
	uint32		xl_command;	/* Always N_RI */
	uint32		originator,	/* Originator and Reason mapped from */
	             	reason,		/* X.25 cause/diag in indications */
        		cause,		/* X.25 cause byte (ignored in reqs) */
			diag;		/* X.25 diagnostic byte */
};

struct xrscf {
	uint32		xl_type;	/* Always XL_CTL */
	uint32		xl_command;	/* Always N_RC */
};

struct xdiscf {
	uint32		xl_type;	/* Always XL_CTL */
	uint32		xl_command;	/* Always N_DI */
	uint32		originator,	/* Originator and Reason mapped from */
			reason,		/* X.25 cause/diag in indications */
			cause,		/* X.25 cause byte (ignored in reqs) */
			diag;		/* X.25 diagnostic byte */
	int32		conn_id;	/* Connection identifier (reject) */
	uint32		indicated_qos;	/* When set facilities indicated  */ 
	struct xaddrf   responder;      /* CONS responder address */
	struct xaddrf   deflected;      /* Address to deflect to */
	struct qosformat qos;		/* Facilities and CONS qos: if    */
					/* indicated_qos is set           */
};

struct xdcnff {
	uint32		 xl_type;	/* Always XL_CTL */
	uint32		 xl_command;	/* Always N_DC */
	uint32		 indicated_qos;	/* When set facilities indicated  */
	struct qosformat rqos;		/* Facilities and CONS qos: if    */
					/* indicated_qos is set           */
};

struct xabortf {
	uint32		xl_type;	/* Always XL_CTL */
	uint32		xl_command;	/* Always N_Abort */
};

struct xcallf {
	uint32		xl_type;	/* Always XL_CTL */
	uint32		xl_command;	/* Always N_CI */
	int32		conn_id;	/* A connection id quoted on accept. */
	uint32		CONS_call;
	uint32		negotiate_qos;  /* When set, negotiate facils etc. */
					/* else use defaults */
	struct xaddrf	calledaddr;	/* The called and */
	struct xaddrf	callingaddr;	/* calling addresses */
	struct qosformat	qos;	/* Facilities and CONS qos: if */
					/* negotiate_qos is set */
};

struct xccnff {
	uint32		xl_type;	/* Always XL_CTL */
	uint32		xl_command;	/* Always N_CC */
	int32		conn_id;	/* The connection id quoted on the */
					/* associated indication. */
	uint32		CONS_call;
	uint32		negotiate_qos;	/* When set, negotiate facils etc. */
					/* else use indicated values */
	struct xaddrf	responder;	/* Responding address */
	struct qosformat	rqos;	/* Facilities and CONS qos: if */
					/* negotiate_qos is set */
};


struct pvcattf {
	uint32	     xl_type;      /* Always XL_CTL */
	uint32	     xl_command;   /* Always N_PVC_ATTACH */
	uint32       lci;          /* Logical channel */
	uint32	     sn_id;        /* Subnetwork identifier */
	/* 0 for next 3 parameters implies use of default */
	uint32	     reqackservice;
	uint32	     reqnsdulimit;
	int32        nsdulimit;   
	int32        result_code;     /* Non-zero - error */
};

struct pvcdetf {
	uint32		xl_type;      /* Always XL_CTL */
	uint32		xl_command;   /* Always N_PVC_DETACH */
	int32		reason_code;  /* Reports why */
};

/* ----------------------------------------------------------------------
 *   Numbers for the X.25 multiplexor code.  They include 
 *   identifiers for different sub-network types etc.
 * ----------------------------------------------------------------------
 */

/* ------ VALUES FOR LISTEN FLAG BYTES ------ */

#define		X25_DTE		1
#define		X25_NSAP	2
#define		X25_DONTCARE	1
#define		X25_STARTSWITH	2
#define		X25_IDENTITY	3


struct xlistenf {
	uint32		xl_type;	/* Always XL_CTL */
	uint32	 	xl_command;	/* Always N_Xlisten */
	int32		lmax;		/* Maximum number of CI's at a time */
	int32		l_result;	/* Result flag */
};

struct xcanlisf {
	uint32		xl_type;	/* Always XL_CTL */
	uint32		xl_command;	/* Always N_Xcanlis */
	int32		c_result;	/* Result flag */
};

/* ----------------------------------------------------------------------
 *                Diagnostic Code Defines
 * ----------------------------------------------------------------------
 */

/* Internal definitions for N_ provider and user - zero is undefined */

#define		NS_USER			1
#define		NS_PROVIDER		2	/* See DIS 8878 Annex A  */

/*            Network Service Reason Codes

   Definitions for NS originator = NS provider */

#define		NS_GENERIC		0XE0	/* General         (224) */
#define		NS_DTRANSIENT		0XE1	/* disc - transient      */
#define		NS_DPERMANENT		0XE2	/* disc - permanent      */
#define		NS_TUNSPECIFIED		0XE3	/* rej  - transient      */
#define		NS_PUNSPECIFIED		0XE4	/* rej  - permanent      */
#define		NS_QOSNATRANSIENT	0XE5	/* rej  - transient      */
#define		NS_QOSNAPERMANENT	0XE6	/* rej  - permanent      */
#define		NS_NSAPTUNREACHABLE	0XE7	/* rej  - transient      */
#define		NS_NSAPPUNREACHABLE	0XE8	/* rej  - permanent(232) */
#define		NS_NSAPUNKNOWN		0XEB	/* rej  - permanent(235) */

/* Definitions for NS originator = NS user     */

#define		NU_GENERIC		0XF0	/* General        (240)  */
#define		NU_DNORMAL		0XF1	/* disc - normal         */
#define		NU_DABNORMAL		0XF2	/* disc - abnormal       */
#define		NU_DINCOMPUSERDATA	0XF3	/* disc - incomp         */
#define		NU_TRANSIENT		0XF4	/* rej  - transient      */
#define		NU_PERMANENT		0XF5	/* rej  - permanent      */
#define		NU_QOSNATRANSIENT	0XF6	/* rej  - transient      */
#define		NU_QOSNAPERMANENT	0XF7	/* rej  - permanent      */
#define		NU_INCOMPUSERDATA	0XF8	/* rej  - cudf           */
#define		NU_BADPROTID		0XF9	/* rej  - prot id (249)  */

/* NS reasons for reset - first Originator =  NS provider */

#define		NS_RUNSPECIFIED		0XE9	/* unspecified    (233)  */
#define		NS_RCONGESTION		0XEA	/* congestion     (234)  */

/* Originator = NS user */

#define		NU_RESYNC		0XFA	/* user resync    (250)  */

/* ------------------------------------------------------------------------
 * PVC related error, result and indication codes for attach, detach.
 * ------------------------------------------------------------------------ */

#define	PVC_SUCCESS		0	/* Zero - OK */
#define	PVC_NOSUCHSUBNET	1	/* Subnetwork not configured */
#define	PVC_CFGERROR		2	/* LCI not in range, no PVCs */
#define	PVC_NODBELEMENTS	3	/* No db available */
#define	PVC_PARERROR		4	/* Error in req. pars */
#define PVC_BUSY		6	/* PVC in non-attach state */
#define PVC_CONGESTION		7	/* Resources low */
#define	PVC_WRONGSTATE		8	/* State wrong for fn */
#define	PVC_NOPERMISSION	9	/* Later enhancement? */

#define PVC_LINKDOWN		10	/* The link has gone down */
#define	PVC_RMTERROR		11	/* No response from remote */
#define	PVC_USRERROR		12	/* User i/f error detected */
#define PVC_INTERROR		13	/* Internal error - report */
#define	PVC_NOATTACH		14	/* Not attached yet (detach) */
#define	PVC_WAIT		15	/* Wait code - not to user */
