#ident "$Id: isdn_proto.h,v 1.5 1996/06/13 20:50:56 meern Exp $"
/*****************************************************************************
 * 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.
 * 
 *****************************************************************************/

/*****************************************************************************
 *
 * 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: Richard Bradley, D John M Martin
 *
 * isdn_proto.h of snet module
 *
 * SpiderISDN
 * Release 3.0.0 94/12/20
 * 
 * SpiderISDN Release 3 - Official Release.
 *
 *****************************************************************************/
 
/*
 * This file contains the protocol structures for the XE-to-ISDN driver.
 */

#ifndef _ISDN_PROTO_
#define _ISDN_PROTO_

#define XN_LISTEN	1	/* Uses message type `xn_lstn_t' */
#define XN_CONNECT	2	/* Uses message type `xn_call_t' */
#define	XN_CONNACK	3	/* Uses message type `xn_cccc_t' */
#define XN_CACTIVE	4	/* Uses message type `xn_cccc_t' */
#define XN_DISCONN	5	/* Uses message type `xn_cccc_t' */
#define XN_CONNEND	6	/* Uses message type `xn_cccc_t' */
#define XN_STS		7
#define	XN_BAD_MSG	0xFF	/* Uses message type `xn_badm_t' */


/*
 * Note:  the structure for CONNACK, CACTIVE, DISCONN and CONNEND is a
 *        truncated version of `x_call_t'.  XISDN will accept messages
 *        which are longer than specified for a command, and ignore the
 *        extra fields.
 */

/*
 * ISDN addressing
 */
#define ISDN_NUMBER_MAXSZ	20
#define ISDN_SUBADR_MAXSZ	20

typedef struct xisdnf {
    unsigned long sn_id;
    unsigned char number_len;
    unsigned char number[ISDN_NUMBER_MAXSZ];
    unsigned char subadr_len;
    unsigned char subadr[ISDN_SUBADR_MAXSZ];
    unsigned char features;
    unsigned char pad[1];
} xisdnf_t;

#ifdef DIGI_API
typedef struct xbeardef {
    uint8    ue_tcap;           /* Information Transfer Capability */
    uint8    ue_trate;
    uint8    ue_rt_adpt;        /* User defined Rate Adaption Std. */
    uint8    ue_rt;             /* User defined Rate Value         */
    uint8    oct5b;             /* User defined bearer services    */
    uint8    oct5c;             /* User defined bearer services    */
    uint8    pad[2] ;           /* Maintain 32-bit alignment */
} usr_bearcap_t;

typedef struct usr_llc_s {
        uint8   llc_len ;          /* Low-Layer Compatibility Len */
        uint8   llc_elem[23] ;     /* Low-Layer Compatibility Elem */
} usr_llc_t ;

typedef struct usr_hlc_s {
        uint8   hlc_len ;       /* High-Layer Compatibility Len */
        uint8   hlc_elem[11] ;  /* High-Layer Compatibility Elem */
} usr_hlc_t ;

typedef struct usr_call_no_s {
        uint8   num_type ;                  /* Octet 2 */
        uint8   dig_num[ISDN_NUMBER_MAXSZ]; /* number  */
	uint8   pad[3];                     /* Maintain 32 bit allignment */ 
} usr_call_no_t ;

#endif         /* @Meer */

typedef struct {
    unsigned char        command;	/* Command code (always XN_LISTEN) */
    unsigned char	 grab_listener;	/* For test software */
    unsigned char	 pad[2];	/* Padding */
    xisdnf_t		 address;	/* Listen address */
} xn_lstn_t;

#ifndef DIGI_API
typedef struct {
    unsigned char    command;		/* Command code (see above) */
    unsigned char    cause;		/* Cause (if any) else zero */
    unsigned char    controller;	/* Selected controller */
    unsigned char    channel;		/* Selected logical channel */
} xn_cccc_t;		

#else  /* DIGI_API Meer */

typedef struct {
    unsigned char    command;		/* Command code (see above) */
    unsigned char    cause;		/* Cause (if any) else zero */
    unsigned char    controller;	/* Selected controller */
    unsigned char    channel;		/* Selected logical channel */
    unsigned char    pref_tx_cap;       /* User Prefers transfer Cap Meer */
    unsigned char    pad[3];            /* 32 bit allignment    Meer */
} xn_cccc_t;		

#endif /* DIGI_API */

#ifndef DIGI_API                         /* Meer                  */
typedef struct {
    unsigned char   command;		/* Command code (see above) */
    unsigned char   cause;		/* Cause (if any) else zero */
    unsigned char   controller;		/* Selected controller */
    unsigned char   channel;		/* Selected logical channel */
    xisdnf_t  	    address;		/* Called or calling address */
} xn_call_t;		

#else   /* DIGI_API */

typedef struct {
    unsigned char   command;		/* Command code (see above) */
    unsigned char   cause;		/* Cause (if any) else zero */
    unsigned char   controller;		/* Selected controller */
    unsigned char   channel;		/* Selected logical channel */
    unsigned char   chan_type;          /* Select Channel Type B,H0 */
    unsigned char   pad[3];             /* Maintain 32 bit allignment */
    xisdnf_t  	    address;		/* Called or calling address*/
    usr_bearcap_t   bearcap;            /* User defined bearer services */
    usr_llc_t       llc;                /* Low-Layer Compatibility Elem */
    usr_hlc_t       hlc;                /* High-Layer Compatibility Elem */
    usr_call_no_t   dest_num;           /* called_party_number   Meer */
    usr_call_no_t   org_num;            /* calling party number  Meer */
} xn_call_t;		

#endif  /* DIGI_API Meer */

typedef struct {
	unsigned char  command;		/* XN_STS           */
	unsigned char  state;		/* Status of stream */
} xn_sts_t;

typedef struct {
	unsigned char  command;		/* XN_BAD_MSG       */
	unsigned char  reason;		/* Cause for error message */
} xn_badm_t;

/*
    Generic ISDN protocol primitive
*/
union ISDN_primitives {
    unsigned char  command;    /* Variant type */
    xn_lstn_t      lstn;    
    xn_call_t      call;    
    xn_cccc_t      cccc;
    xn_badm_t      badm;
    xn_sts_t	   sts;
};


#define ISDN_LSTN_SIZE sizeof(xn_lstn_t)
#define ISDN_CALL_SIZE sizeof(xn_call_t)
#define ISDN_CCCC_SIZE sizeof(xn_cccc_t)
#define ISDN_STS_SIZE  sizeof(xn_sts_t)

/*
 * Q.931 Cause values
 */
#define CALL_ACCEPT		 0
#define	NO_ROUTE		 2
#define NORM_CALL_CLEAR	16
#define USER_BUSY		17
#define CALL_REJECT		21
#define NO_CHANNEL		34
#define OUT_OF_ORDER    	38
#define TEMP_FAILURE	        41

/*
 * Features bit mask values for xisdnf_t struct.
 */
#define ISDN_SEMI_PERM_CIRC_F	0x01	/* 1TR6 only */
#define ISDN_UNDEFINED_BIT2_F	0x02	/* Not used */
#define ISDN_UNDEFINED_BIT3_F	0x04	/* Not used */
#define ISDN_UNDEFINED_BIT4_F	0x08	/* Not used */
#define ISDN_UNDEFINED_BIT5_F	0x10	/* Not used */
#define ISDN_UNDEFINED_BIT6_F	0x20	/* Not used */
#define ISDN_UNDEFINED_BIT7_F	0x40	/* Not used */
#define ISDN_UNDEFINED_BIT8_F	0x80	/* Not used */

/*
 * Bad message (XN_BAD_MSG) reason codes.
 */
#define	IL3REASON_MESSAGE_SIZE  0x01    /* Message size wrong for command */
#define	IL3REASON_BAD_DIRECTORY 0x02    /* Unable to make directory match */
#define	IL3REASON_BAD_SUBADDR   0x03    /* Unable to make subaddress match */
#define	IL3REASON_INVALID_SNID  0x04    /* SNID not recognized */
#define	IL3REASON_BAD_COMMAND   0x05    /* Command not recognized */
#define	IL3REASON_BAD_STATE     0x06    /* Inappropriate message */

#endif /*_ISDN_PROTO_*/
