/*****************************************************************************
 * 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: isdn_proto.h,v 1.69.2.2 2000/07/15 06:13:14 erics 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: 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_

/*
 * Following are isdn user messsage primitives
 * XN_LISTEN :   Listen Request, Listen Confirmation
 * XN_CONNECT:   Connect Request, Connect Indication
 * XN_CONNACK:   Connect Response, Connect Confirmation
 * XN_CACTIVE:   Connect Acknowledgement
 * XN_DISCONN:   Disconnect Request, Disconnect Indication
 * XN_CONNEND:   Disconnect Response
 * XN_STS    :   Status of stream <--- not in use
 * XN_DATA   :   Data
 * XN_INFO   :   Info messages per request of CAPI driver
 * XN_BAD_MSG:   malformed or incorrect user message
 *
 * The following numerical command values are reserved for
 * firmware interprocess communication:
 *
 *                     0x0F00D4BC
 *
 */
#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_DATA   	8      /* Uses message type `xn_data_t' */
#define XN_INFO   	9      /* Uses message type `xn_info_t' */
#define XN_RING   	10     /* Uses message type `xn_ring_t' */
#define XN_UPDATE   	11     /* Uses message type `xn_updt_t' */
#define XN_SYNC   	12     /* Uses message type `xn_sync_t' */
#define XN_FLUSH   	13     /* Uses message type `xn_flsh_t' */
#define XN_MARK   	14     /* Uses message type `xn_mark_t' */
#define XN_ALERT	15     /* Uses message type `xn_alrt_t' */

#ifdef ARB_2
#define XN_CALL_PROC	16     /* Uses message type `xn_callproc_t' */
#define XN_CONNECT_B	17     /* Uses message type `xn_b_call_t' */
#define XN_CONNACK_B	18     /* Uses message type `xn_b_call_t' */
#define XN_DISCONNECT_B	19     /* Uses message type `xn_b_call_t' */
#define XN_DISCONNACK_B	20     /* Uses message type `xn_b_call_t' */
#define XN_CACTIVE_B3	22     /* Uses message type `xn_b_call_t' */
#define XN_PROGRESS	23     /* Uses message type `xn_progress_t' */
#define XN_FACILITY	24     /* Uses message type `xn_facility_t' */
#define XN_USER_INFO	25     /* Uses message type `xn_user_info_t' */
#define XN_B_PROTOCOL	26     /* Uses message type `xn_sel_b_proto_t' */
#define XN_DISCONN_COMP	27     /* Uses message type `xn_disconn_ind_t' */
#endif /* ARB_2 */

#define XN_PIAFS	28     /* Uses message type `xn_piafs_t' */

#define	XN_BAD_MSG	0xFF   /* Uses message type `xn_badm_t' */

/*
 * 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 */
#define	IL3REASON_INVALID_APPID 0x07	/* Appid not recognized */
#define	IL3REASON_INVALID_INDEX 0x08	/* Channel index not recognized */
#define	IL3REASON_BAD_INFO_MASK 0x09	/* Request not supported */
#define	IL3REASON_BAD_CHAN_TYPE 0x10	/* Channel type not supported */

#define	IL3REASON_INVALID_CALL_ID 0xFF	/* */
#define	IL3REASON_USED_CALL_ID 0xFF	/* */
#define	IL3REASON_UNUSED_CALL_ID 0xFF	/* */

/* 
 * ISDN Channel type
 */
#define NO_B_CH		0
#define B_CH		1
#define H0_CH		2
#define H11_CH		3
#define H12_CH		4
#define MULT_CH		5
#define ANY_CH		6
#define ANY_B_CH	8
#define B_OR_D_CH	9
#define D_CH		10
#define B_CH_NO_SIG	11
#define ANY_B_CH_NO_SIG	12
#define LEASED_CHAN	13

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

#ifndef ARB_2 
#define ADD_NUMPLAN_UNKNOWN	0
#define ADD_NUMPLAN_ISDN	1
#define ADD_NUMPLAN_DATA	3
#define ADD_NUMPLAN_TELEX	4
#define ADD_NUMPLAN_NATIONAL	8
#define ADD_NUMPLAN_PRIVATE	9

#define ADD_NUMTYPE_UNKNOWN	0
#define ADD_NUMTYPE_INTL	1
#define ADD_NUMTYPE_NATIONAL	2
#define ADD_NUMTYPE_NETWORK	3
#define ADD_NUMTYPE_SUBSCR	4
#define ADD_NUMTYPE_ABBREV	6

#define SUBADD_TYPE_NSAP	0
#define SUBADD_TYPE_USER	2

#else /* ARB_2 */
#define ADDR_EXT_BIT		0x80
#define ADDR_PLAN_MASK 		0x0F
#define ADDR_TYPE_MASK		0x70
#define ADDR_PRESENT_MASK	0x60
#define ADDR_SCREEN_MASK	0x03
#define ADDR_ODDEVEN_MASK	0x08

#define ADDR_PLAN_UNKNOWN	ADDR_EXT_BIT|0x00
#define ADDR_PLAN_ISDN		ADDR_EXT_BIT|0x01
#define ADDR_PLAN_DATA		ADDR_EXT_BIT|0x03
#define ADDR_PLAN_TELEX		ADDR_EXT_BIT|0x04
#define ADDR_PLAN_NATIONAL	ADDR_EXT_BIT|0x08
#define ADDR_PLAN_PRIVATE	ADDR_EXT_BIT|0x09

#define ADDR_TYPE_UNKNOWN	ADDR_EXT_BIT|0x00
#define ADDR_TYPE_INTL		ADDR_EXT_BIT|0x10
#define ADDR_TYPE_NATIONAL	ADDR_EXT_BIT|0x20
#define ADDR_TYPE_NETWORK	ADDR_EXT_BIT|0x30
#define ADDR_TYPE_SUBSCR	ADDR_EXT_BIT|0x40
#define ADDR_TYPE_ABBREV	ADDR_EXT_BIT|0x60

#define ADDR_PRESENT_ALLOW	ADDR_EXT_BIT|0x00
#define ADDR_PRESENT_RESTRICT	ADDR_EXT_BIT|0x20
#define ADDR_PRESENT_UNAVAIL	ADDR_EXT_BIT|0x40

#define ADDR_SCREEN_USER	ADDR_EXT_BIT|0x00
#define ADDR_SCREEN_PASS	ADDR_EXT_BIT|0x01
#define ADDR_SCREEN_FAIL	ADDR_EXT_BIT|0x02
#define ADDR_SCREEN_NETWORK	ADDR_EXT_BIT|0x03

#define ADDR_ALLOW_USER		ADDR_PRESENT_ALLOW|ADDR_SCREEN_USER
#define ADDR_ALLOW_PASS		ADDR_PRESENT_ALLOW|ADDR_SCREEN_PASS
#define ADDR_ALLOW_FAIL		ADDR_PRESENT_ALLOW|ADDR_SCREEN_FAIL
#define ADDR_ALLOW_NETWORK	ADDR_PRESENT_ALLOW|ADDR_SCREEN_NETWORK
#define ADDR_RESTRICT_USER	ADDR_PRESENT_RESTRICT|ADDR_SCREEN_USER
#define ADDR_RESTRICT_PASS	ADDR_PRESENT_RESTRICT|ADDR_SCREEN_PASS
#define ADDR_RESTRICT_FAIL	ADDR_PRESENT_RESTRICT|ADDR_SCREEN_FAIL
#define ADDR_RESTRICT_NETWORK	ADDR_PRESENT_RESTRICT|ADDR_SCREEN_NETWORK
#define ADDR_UNAVAIL_NETWORK	ADDR_PRESENT_RESTRICT|ADDR_SCREEN_UNAVAIL

#define SUBADDR_TYPE_NSAP	ADDR_EXT_BIT|0x00
#define SUBADDR_TYPE_USER	ADDR_EXT_BIT|0x20
#define SUBADDR_EVEN_IND	ADDR_EXT_BIT|0x00
#define SUBADDR_ODD_IND		ADDR_EXT_BIT|0x08
#endif /* ARB_2 */

/*
 * Error (XN_DATA) codes.
 */
#define ERROR_NONE		0x00000000	/* Good data */
#define ERROR_HDLC_UNDERRUN	0x00000001
#define ERROR_HDLC_SHORT	0x00000020
#define ERROR_HDLC_FORMAT	0x00000040
#define ERROR_HDLC_OVERRUN	0x00000080	/* Includes long frame */
#define ERROR_HDLC_ABORTED	0x00000100
#define ERROR_HDLC_CRC		0x00000200
#define ERROR_HDLC_LENGTH	0x00000400	/* Good long frame */
#define ERROR_HDLC_MARK		0x00000800	/* Mark spacing follows */

/*
 * Layer 1 configuration of HDLC controller
 * If adding another layer_1_cfg remember to increase
 * size of FILL_MASK_SZ and and another entry to
 * fill_mask[] in il3_to_wan() in il3_wan.c
 */

#define L1_CIP_DEFAULT  0
#define L1_RAW64        1
#define L1_RAW56        2
#define L1_HDLC64       3
#define L1_HDLC56       4
#define L1_ULAW         5      /* Not Supported */
#define L1_ALAW         6      /* Not Supported */
#define L1_V110         7
#define L1_V120         8      /* Not Supported */
#define L1_NONE         9
#define L1_HDLC_ID      10

#define L1_PIAFS32	11
#define L1_PIAFS64	12

#define L1_X75          13

#define MAX_L1_SZ	14    /* one greater than largest L1_ value */


#ifndef ARB_2

/*
 * Application ID's
 *
 * New definitions MUST use bitfields, unless we exceed 32
 * different application ID types.  In this case, the arbiter must
 * be modified, for it assumes a unique bit for each type.
 *
 * For empty appid fields, the arbiter defaults to the value defined
 * by APPID_DEFAULT;  for now, that value is APPID_ANY_DIGITAL_CALL.
 */
#define	APPID_64K_DIGITAL_CALL		0x00000001
#define	APPID_56K_DIGITAL_CALL		0x00000002
#define	APPID_TOLLSAVER_56K_CALL	0x00000004
#define	APPID_ANALOG_ENVELOPE_CALL	0x00000008
#define	APPID_ANALOG_RING_CALL		0x00000010
#define	APPID_ISDN_VOICE_CALL		0x00000020
#define	APPID_TERMINAL_ADAPTER_64K	0x00000040
#define	APPID_TERMINAL_ADAPTER_56K	0x00000080
#define	APPID_TERMINAL_ADAPTER_V110	0x00000100
#define	APPID_TERMINAL_ADAPTER_32K	0x00000200
#define	APPID_TERMINAL_ADAPTER_PIAFS64K 0x00000400
#define	APPID_TERMINAL_ADAPTER_CALL	0x000007c0
#define	APPID_ANY_DIGITAL_CALL		(APPID_64K_DIGITAL_CALL| \
					 APPID_56K_DIGITAL_CALL| \
					 APPID_TOLLSAVER_56K_CALL)
#define	APPID_ANY_ANALOG_CALL		(APPID_ANALOG_ENVELOPE_CALL| \
					 APPID_ANALOG_RING_CALL| \
					 APPID_ISDN_VOICE_CALL| \
					 APPID_TERMINAL_ADAPTER_CALL)
#define	APPID_ALL		(APPID_ANY_DIGITAL_CALL| \
				 APPID_ANY_ANALOG_CALL)
#define	APPID_DEFAULT		APPID_ANY_DIGITAL_CALL

/*
 * Also see ITU Q.931 documentation for detail information.
 * This structure is used for CALLED and CALLING addresses
 * and sub-addresses. 
 * number_plan :ADDNUMPLAN:Unknown,Isdn,Data,Telex,National,Private 
 * number_type :ADDNUMTYPE: Unknown,International,National,Network,
 *              Subscriber,Abbrev 
 * pres_ind_scr: For future use cureently set to Zero.
 * number_len  : length of ISDN number field
 * number      : 
 * subadr_type : NSAP/User
 * subadr_len  : length of subadr
 * subadr      : sub-address
 */
typedef struct xisdnf
{
    uint32 number_plan;
    uint32 number_type;
    uint32 pres_ind_scr;
    uint32 number_len;
    unsigned char number[ISDN_NUMBER_MAXSZ];
    uint32 subadr_type;
    uint32 subadr_len;
    unsigned char subadr[ISDN_SUBADR_MAXSZ];
}
xisdnf_t;

/*
 * Also see ITU Q.931 documentation for detail information.
 * Bearer Capability:
 * bc_len : length/number of octets in Bearer Information element.
 *          This does not contain the first two octets so bc_elem
 *          will contain (bc_len + 2) octets.
 * bc_elem: bc_elem[0] = IE_BEARER_CAP
 *          bc_elem[1] = bc_len
 *          bc_elem[2...] = rest of IE's
 *
 */

#define MAX_BC_LEN 12

typedef struct usr_bc_s
{
    uint32 bc_len;
    uint8 bc_elem[MAX_BC_LEN];
}
usr_bc_t;

/*
 * Also see ITU Q.931 documentation for detail information.
 * Low Layer Compatability:
 * llc_len : length/number of octets in LLC Information element.
 *           This does not contain the first two octets so llc_elem
 *           will contain (llc_len + 2) octets.
 * llc_elem: llc_elem[0] = IE_LOW_LAYER_COMPAT
 *           llc_elem[1] = llc_len
 *           llc_elem[2...] = rest of IE's
 *
 */

#define MAX_LLC_LEN 24

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

/*
 * Also see ITU Q.931 documentation for detail information.
 * High Layer Compatability:
 * hlc_len : length/number of octets in HLC Information element.
 *          This does not contain the first two octets so hlc_elem
 *          will contain (hlc_len + 2) octets.
 * hlc_elem: hlc_elem[0] = IE_HIGH_LAYER_COMPAT
 *           hlc_elem[1] = hlc_len
 *           hlc_elem[2...] = rest of IE's
 *
 */

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

/*
 * Also see ITU Q.931 documentation for detail information.
 * Call reference value:
 * cref_len : length/number of call reference value.
 * cref_val :  call refernce value in octets
 *
 */

typedef struct cref	       /* Call reference */
{
    uint32 cref_len;
    uint8 cref_val[4];
}
cref_t;


typedef struct
{
    uint32 command;	       /* Command code (always XN_LISTEN)  */
    uint32 snid;	       /* subnetwork id                    */
    uint32 appid;	       /* application id                   */
    xisdnf_t address;	       /* Listen called address               */
    uint32 features;	       /* CAPI info mask defined values below */
}
xn_lstn_t;

typedef struct
{
    uint32 command;	       /* Command code (see above) */
    uint32 snid;	       /* Selected subnetwork id   */
    uint32 appid;	       /* application id           */
    uint32 cause;	       /* Cause (if any) else zero */
    uint32 channel;	       /* Selected physical channel */
    uint32 chan_index;	       /* Index to physical channel */
    cref_t cref;	       /* API Call ref value        */
    xisdnf_t conn_address;     /* Connected address        */
    usr_llc_t llc;	       /* Low Layer Compatability  */
    uint32 layer_1_config;     /* Layer 1 params           */
    uint32 max_frame_size;     /* maximum frame size       */
}
xn_cccc_t;

typedef struct
{
    uint32 command;	       /* XN_ALERT                          */
    uint32 snid;	       /* subnetwork id                     */
    uint32 appid;	       /* application id for arbitrator use */
    uint32 chan_index;	       /* errored message                   */
    uint32 padding;	       /* Reserved; matches xn_badm_t size  */
}
xn_alrt_t;

typedef struct
{
    uint32 command;	       /* Command code (see above)     */
    uint32 snid;	       /* subnetwork id                */
    uint32 appid;	       /* application id               */
    uint32 chan_type;	       /* Select Channel Type B,H0     */
    uint32 channel;	       /* Selected physical channel     */
    uint32 chan_index;	       /* Index to physical channel    */
    cref_t cref;	       /* API call reference value     */
    uint32 cip;		       /* CAPI CIP                     */
    xisdnf_t dest_address;     /* Called Address               */
    xisdnf_t org_address;      /* Calling address              */
    usr_bc_t bc;	       /* User defined bearer services */
    usr_llc_t llc;	       /* Low-Layer Compatibility Elem */
    usr_hlc_t hlc;	       /* HighLayer Compatibility Elem */
    uint32 layer_1_config;     /* layer controller protocol    */
    uint32 max_frame_size;     /* maximum frame size for HDLC  */
    uint32 features;	       /* CAPI info mask -- see below  */
}
xn_call_t;

typedef struct
{
    uint32 command;	       /* XN_STS                             */
    uint32 snid;	       /* subnetwork id                      */
    uint32 appid;	       /* application id for arbitrator use  */
    uint32 state;	       /* Status of stream                   */
}
xn_sts_t;

typedef struct
{
    uint32 command;	       /* XN_BAD_MSG                        */
    uint32 snid;	       /* subnetwork id                     */
    uint32 appid;	       /* application id for arbitrator use */
    uint32 message;	       /* errored message                   */
    uint32 reason;	       /* Cause for error message           */
}
xn_badm_t;

typedef struct
{
    uint32 command;	       /* XN_DATA                           */
    uint32 snid;	       /* subnetwork id                     */
    uint32 appid;	       /* application id for arbitrator use */
    uint32 error;	       /* Error message type                */
}
xn_data_t;

/*
 * IE SIZE
 */
#define NORMAL_SIZE_IE          36	/* any IE > 36 => il3cglob */
#define SMALL_IE                2	/* BODGE for IEDARG_MIN */
#define MAX_IE                  255	/* BODGE for IEDARG_MAX */

/*
 * Also see ITU Q.931 documentation for detail information.
 * Progress Indication: Use in XN_INFO
 * len    : length/number of octets in Progress Indication IE.
 *          This DOES NOT contain the first two octets.i.e 
 *          IE_PROGRESS_IND and length of progress_ind.  
 * prog_ind_elem: prog_ind_elem[0] = extbit+coding_std+0+location
 *                prog_ind_elem[1] = extbit+progress_description
 *
 * progpad  : for 32 bit alignment
 */

typedef struct il3_progress_ind
{
    uint32 len;
    uint8 prog_ind_elem[6];
    uint8 progpad[2];
}
il3_progress_ind_t;

/*
 * Also see ITU Q.931 documentation for detail information.
 * CAUSE Information element: for XN_INFO use
 * len    : length/number of octets in Cause Information element.
 *          This DOES NOT contain the first two octets. i.e.
 *          IE_CAUSE and length of cause.
 * cause_elem: cause_elem[0] = coding_std+0+Location
 *             cause_elem[1] = cause_value 
 *             cause_elem[2...] = rest of IE's could be diagnostic info
 */

typedef struct il3_ie_cause
{
    uint32 len;
    uint8 cause_elem[NORMAL_SIZE_IE];
}
il3_ie_cause_t;

/*
 * Also see ITU Q.931 documentation for detail information.
 * DATE_TIME_IE: date time IE
 * MAX_SZ_DATETIME : ITU documentation says maximum of octets 8 
 *                   excluding first 2 i.e. IE_DATE_TIME 
 *                    and length of date time
 * len :    length/number of octets in date/time Information element.
 *          This does not contain the first two octets .
 * datetime_elem: datetime_elem[0] = year
 *                datetime_elem[1] = month
 *                datetime_elem[2] = day
 *                datetime_elem[3] = hour
 *                datetime_elem[4] = minute
 *                datetime_elem[5] = second  
 *
 */

#define MAX_SZ_DATETIME  6
typedef struct il3_date_time
{
    uint32 len;
    uint8 datetime_elem[8];
}
il3_date_time_t;

/*
 * Facility informationa element
 */
typedef struct il3_facility_ie
{
    uint32 len;
    uint8 facility_elem[MAX_IE];
    uint8 pad;
}
il3_facility_ie_t;

/*
 * Also see ITU Q.931 documentation for detail information (?).
 * Charging/Facility: IE_FACILITY
 * len :    length/number of octets in facility Information element.
 *          This does not contain the first two octets .
 * facilty_type  :  ?
 * charging_units:  ?
 *
 * FACILITY_CHARGE will be a special define used il3_user.c
 * Special Note: This structure will carry charging info still
 *               under investigation. This is still not implemented
 *
 */

#define FACILITY_CHARGE 254

#define ETSI_OPVAL_AOCDCURR  33
#define ETSI_OPVAL_AOCDUNIT  34
#define ETSI_OPVAL_AOCECURR  35
#define ETSI_OPVAL_AOCEUNIT  36

typedef struct il3_fac_charge_info
{
    uint32 len;
    uint32 facility_type;
    uint8 charging_units[NORMAL_SIZE_IE];
}
il3_fac_charge_info_t;

typedef struct il3_called_party_info
{
    uint32 len;
    uint8 digits[MAX_IE];
}
il3_called_party_info_t;

typedef struct il3_keypad_fac_info
{
    uint32 len;
    uint8 digits[MAX_IE];
}
il3_keypad_fac_info_t;

union XNInfo_prim
{
    il3_progress_ind_t progress_ind;
    il3_ie_cause_t cause;
    il3_date_time_t date_time;
    il3_fac_charge_info_t fac_charge_info;
    il3_facility_ie_t facility_ie;
    il3_called_party_info_t called_party_info;
    il3_keypad_fac_info_t keypad_info;
};

/*
 * CAPI application can request xn_info by setting "features"
 * in XN_LISTEN as Feature bit mask values defined.
 * On receiving XN_INFO the infoNum will indicate the information.
 * infoNum is explained in CAPI 2.0 spec but here is brief description
 * infoNum:Bit 15 : Bit15 = 1 and Bit14 = 0 then the low 
 *                  byte defines a message type as follows:
 *                  0x8001 : MT_ALERTING
 *                  0x8002 : MT_CALL_PROCEEDING
 *                  0x8003 : MT_PROGRESS
 *                  0x800D : MT_SETUP_ACK
 *                  0x801E : IE_PROGRESS_IND 
 *                         also InfoIE contains il3_progressind_t
 * infoNum:Bit 15 : Bit15 = 0 and Bit14 = 0 then the 
 *                  low bytes contain following information element.
 *                  0x0008 : IE_CAUSE also InfoIE contains il3_ie_cause_t
 *                  0x0029 : IE_DATE_TIME also InfoIE contains il3_date_time_t
 * infoNum:Bit 14 : Bit14 = 1 and Bit15 = 0 and low byte = 0
 *                  contains charging units in il3_fac_charge_info_t 
 *                  0x4000 : total charging units
 *                  --- NOT IMPLEMENTED 
 * infoNum:Bit 14 : Bit14 = 1 and Bit15 = 0 and low byte = 1
 *                  charging info in national currency in il3_fac_charge_info_t
 *                  0x4001 : charging units in national currency
 *                  --- NOT IMPLEMENTED
 */

typedef struct
{
    uint32 command;	       /* XN_INFO            */
    uint32 snid;	       /* subnetwork id      */
    uint32 appid;	       /* application id     */
    uint32 channel;	       /* Physical B-Channel */
    cref_t cref;	       /* Call ref           */
    uint32 infoNum;	       /* Info Mask per CAPI */
    union XNInfo_prim InfoIE;
}
xn_info_t;

/*
 * XN_RING
 *
 * Ring event message.  Generally expected by internal analog device which
 * speak to the arbiter.  Will only appear for inbound Channelized T1 calls.
 */
typedef struct
{
    uint32 command;	       /* XN_RING            */
    uint32 snid;	       /* subnetwork id      */
    uint32 appid;	       /* application id     */
    uint32 channel;	       /* Physical B-Channel */
    uint32 chan_index;	       /* Call identifier    */
    uint32 csc;		       /* CSC device         */
    uint32 ring_event;	       /* type of ring event */
}
xn_ring_t;

/*
 * XN_UPDATE
 *
 * Quick feedback message for outbound calls.
 * Message indicates up front what channel is being
 * used for the previously requested outbound call.
 */
typedef struct
{
    uint32 command;	       /* XN_UPDATE          */
    uint32 snid;	       /* subnetwork id      */
    uint32 appid;	       /* application id     */
    uint32 channel;	       /* Physical B-Channel */
    uint32 chan_index;	       /* Call identifier    */
    uint32 csc;		       /* CSC device         */
}
xn_updt_t;

#define	RING_START_EVENT	0x00000001
#define	RING_STOP_EVENT		0x00000002

/*
 * XN_SYNC
 *
 * Synchronization message.  Message is sent by user, and firmware bounces
 * message back to user when all data before the message is transmitted,
 * if sync message is sent normal priority.
 */
typedef struct
{
    uint32 command;	       /* XN_SYNC                    */
    uint32 sync_id;	       /* Optional unique identifier */
    uint32 flags;	       /* See below                  */
}
xn_sync_t;

#define	SYNC_RESHIPRI		0x02	/* Make sync response high priority */

/*
 * XN_FLUSH
 *
 * Flush inbound and/or outbound data.  This command does NOT affect API
 * commands, including XN_SYNC.  Any of the flags may be used in any
 * combination.  This message may be sent as normal priority or high
 * priority.  No response is generated.
 */
typedef struct
{
    uint32 command;	       /* XN_FLUSH           */
    uint32 flags;	       /* See below          */
}
xn_flsh_t;

#define	FLUSH_INPUT_BUFFER	0x01	/* Flush read-side data         */
#define	FLUSH_OUTPUT_BUFFER	0x02	/* Flush write-side data  */
#define	FLUSH_ABORT_TX_FRAME	0x04	/* Abort current outbound frame */

/*
 * XN_MARK
 *
 * Set mark idle detect mode, or issue mark idle interframe fill orders.
 * This command should be issued during active calls only.
 */
typedef struct
{
    uint32 command;	       /* XN_MARK            */
    uint32 mode;	       /* Operational mode -- see below */
}
xn_mark_t;

/* XN_PIAFS
 */

typedef struct
{
    uint32 command;
    uint32 message;
    uint32 flags;
} xn_piafs_t;

#define PIAFS_INBAND_NEG_PASS 	1
#define PIAFS_INBAND_NEG_FAIL	2
#define PIAFS_CNTRL_NEG_PASS	3
#define PIAFS_CNTRL_NEG_FAIL	4
#define PIAFS_SYNC		5
#define PIAFS_LOST_SYNC		6
#define PIAFS_RTF		7
#define PIAFS_INFO		8
#define PIAFS_LINK_RELEASE	9

/* Choices for xn_mark_t mode field */
#define MARK_TX_DEACTIVATE      1
#define MARK_TX_ACTIVATE        2
#define MARK_TX_ONCE            3
#define MARK_RX_DETECT_ON       4
#define MARK_RX_DETECT_OFF      5

/*
 *   Generic ISDN protocol primitive
 */
union ISDN_primitives
{
    uint32 command;	       /* Variant type */
    xn_lstn_t lstn;
    xn_call_t call;
    xn_cccc_t cccc;
    xn_alrt_t alrt;
    xn_badm_t badm;
    xn_sts_t sts;
    xn_data_t data;
    xn_info_t info;
    xn_ring_t ring;
    xn_updt_t updt;
    xn_sync_t sync;
    xn_flsh_t flsh;
    xn_mark_t mark;
};


#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)

/*
 * Features bit mask values for xn_lstn_t struct.
 */
#define INFO_CAUSE	0x0001
#define INFO_DATE_TIME	0x0002
#define INFO_DISPLAY	0x0004 /* Not supported */
#define INFO_USER_USER	0x0008 /* Not supported */
#define INFO_CALL_PROG	0x0010
#define INFO_FACILITY	0x0020
#define INFO_CHARGE	0x0040
#define INFO_DEST	0x0080 /* Not supported */
#define INFO_CHANNEL_ID	0x0100 /* Not supported */
#define INFO_EARLY_B3	0x0200 /* Not supported */
#define INFO_VERBOSE	0x8000

/*
 * CIP also implies a default layer 1 config
 * CIP is defined as in CAPI document Ver 2.0.  
 * Digi plans to support only 10 values for current and future use.
 * The following values are currently supported
 * CIP_SPEECH : with HDLC 56 K for layer 1 configuration.
 * CIP_UDI
 * CIP_RDI
 * CIP_AUDIO31K
 * CIP_PACKET
 * CIP_RA56K
 * CIP_TOLLSAVER 
 *
 * The following values are not implemented/supported 
 * CIP_AUDIO7K
 * CIP_VIDEO
 * CIP_UDITA
 */
#define CIP_NONE        0
#define CIP_SPEECH      1  /* BC : 0x04, 0x03, 0x80, 0x90, 0xA2|0xA3  :RAW64  */
#define CIP_UDI         2  /* BC : 0x04, 0x02, 0x88, 0x90,            :HDLC64 */
#define CIP_RDI         3  /* BC : 0x04, 0x02, 0x89, 0x90,            :HDLC56 */
#define CIP_AUDIO31K    4  /* BC : 0x04, 0x03, 0x90, 0x90, 0xA2|0xA3  :RAW64  */
#define CIP_AUDIO7K     5  /* BC : 0x04, 0x02, 0x91, 0x90,            :RAW64  */
#define CIP_VIDEO       6  /* BC : 0x04, 0x02, 0x98, 0x90,            :RAW64  */
#define CIP_PACKET      7  /* BC : 0x04, 0x04, 0x88, 0xC0, 0xC6, 0xE6 :HDLC64 */
#define CIP_RA56K       8  /* BC : 0x04, 0x04, 0x88, 0x90, 0x21, 0x8F :V110   */
#define CIP_UDITA       9  /* BC : 0x04, 0x03, 0x91, 0x90, 0xA5,      :?      */
#define CIP_TOLLSAVER   10 /* BC : 0x04, 0x02, 0x80, 0x90,            :HDLC56 */

#ifdef PIAFS
#define CIP_PIAFS	11 /* BC : 0x04, 0x04, 0x88, 0x90, 0x21, 0x8c :RAW64  */
#endif // PIAFS
/*
 * Used for size of an array in il3_to_wan()
 */
#define CIPVALSZ 12

#else /* ARB_2 */

/******************************************************************************
 * Redefinitions of ISDN message primitives that are easier to understand
 *****************************************************************************/

/* call control */
#define XN_ALERT_REQ		XN_ALERT
#define XN_CALL_PROC_REQ	XN_CALL_PROC
#define XN_CONN_REQ		XN_CONNECT
#define XN_CONN_CONF		XN_CONNACK
#define XN_CONN_IND		XN_CONNECT
#define XN_CONN_RESP		XN_CONNACK
#define XN_CONN_RESP_REJECT	XN_CONNEND
#define XN_CONN_ACTIVE_IND	XN_CACTIVE
#define XN_DISCONN_REQ		XN_DISCONN
#define XN_DISCONN_IND		XN_DISCONN
#define XN_DISCONN_RESP		XN_CONNEND
#define XN_DISCONN_CONF		XN_CONNEND
#define XN_FACILITY_REQ		XN_FACILITY
#define XN_INFO_REQ		XN_INFO
#define XN_INFO_IND		XN_INFO
#define XN_LISTEN_REQ		XN_LISTEN
#define XN_LISTEN_CONF		XN_LISTEN
#define XN_PROGRESS_REQ		XN_PROGRESS
#define XN_SELECT_B_PROTO_REQ	XN_B_PROTOCOL
#define XN_SELECT_B_PROTO_CONF	XN_B_PROTOCOL
#define XN_USER_INFO_REQ	XN_USER_INFO

/* data */
#define XN_CONN_B_REQ		XN_CONNECT_B
#define XN_CONN_B_CONF		XN_CONNACK_B
#define XN_CONN_B_IND		XN_CONNECT_B
#define XN_CONN_B_RESP		XN_CONNACK_B
#define XN_CONN_B3_ACT_IND	XN_CACTIVE_B3
#define XN_CONN_B3_ACT_RESP	XN_CACTIVE_B3
#define XN_DISCONN_B_REQ	XN_DISCONNECT_B
#define XN_DISCONN_B_CONF	XN_DISCONNACK_B
#define XN_DISCONN_B_IND	XN_DISCONNECT_B
#define XN_DISCONN_B_RESP	XN_DISCONNACK_B
#define XN_FLUSH_REQ		XN_FLUSH
#define XN_MARK_REQ		XN_MARK
#define XN_SYNC_REQ		XN_SYNC
#define XN_SYNC_CONF		XN_SYNC

/******************************************************************************
  Information element definitions and structures
 *****************************************************************************/

/*
 * IE Sizes
 */
#define SMALL_IE                2	/* BODGE for IEDARG_MIN */
#define NORMAL_IE               36	/* any IE > 36 => il3cglob */
#define MAX_BC_IE		12
#define MAX_CPN_IE		ISDN_NUMBER_MAXSZ
#define MAX_CRV_IE		4
#define MAX_CURRENCY		10
#define MAX_DT_IE		6
#define MAX_HLC_IE		5
#define MAX_KEYPAD_IE		ISDN_NUMBER_MAXSZ
#define MAX_LLC_IE		24
#define MAX_PROG_IE		6
#define MAX_SA_IE		ISDN_SUBADR_MAXSZ
#define MAX_IE                  255	/* BODGE for IEDARG_MAX */

#define NORMAL_SIZE_IE          NORMAL_IE
#define MAX_BC_LEN		MAX_BC_IE
/*
 * Information Element Structures
 *
 * length  : number of octets in contents
 * contents: contents[0] = IE octet 3 
 *           (except for Call Reference, it's IE octet 2)
 *           (except for Called Party Number, it's IE octet 4)
 *           (except for Calling Party Number, it's IE octet 4)
 *           (except for Subaddress, it's IE octet 4)
 *             .
 *             .
 *             .
 *           contents[length - 1] = IE octet (3 + (length - 1))
 *           (except for Call Reference, it's IE octet (2 + (length - 1)))
 *           (except for Called Party Number, it's IE octet (4 + (length - 1)))
 *           (except for Calling Party Number, it's IE octet (4 + (length - 1)))
 *           (except for Subaddress, it's IE octet (4 + (length - 1)))
 *
 * See ITU Q.931 documentation for more information.
 */

/* Generic */
typedef struct
{
    dxb_uint32 length;
    dxb_uint8 contents[MAX_IE];
}
xn_ie_t;

/* Bearer Capability */
typedef struct
{
    dxb_uint32 length;
    dxb_uint8 contents[MAX_BC_IE];
}
xn_bc_ie_t;

/* Call Reference */
typedef struct
{
    dxb_uint32 length;
    dxb_uint8 contents[MAX_CRV_IE];
}
xn_crv_ie_t;

/* Called Party Number */
typedef struct
{
    dxb_uint32 plan;
    dxb_uint32 type;
    dxb_uint32 length;
    dxb_uint8 contents[MAX_CPN_IE];
}
xn_cdpn_ie_t;

/* Calling Party Number */
typedef struct
{
    dxb_uint32 plan;
    dxb_uint32 type;
    dxb_uint32 present_screen;
    dxb_uint32 length;
    dxb_uint8 contents[MAX_CPN_IE];
}
xn_cgpn_ie_t;

/* High Layer Compatability */
typedef struct
{
    dxb_uint32 length;
    dxb_uint8 contents[MAX_HLC_IE];
}
xn_hlc_ie_t;

/* Keypad Facility */
typedef struct
{
    dxb_uint32 length;
    dxb_uint8 contents[MAX_KEYPAD_IE];
}
xn_keypad_ie_t;

/* Low Layer Compatibility */
typedef struct
{
    dxb_uint32 length;
    dxb_uint8 contents[MAX_LLC_IE];
}
xn_llc_ie_t;

/* Progress Indicator */
typedef struct
{
    dxb_uint32 length;
    dxb_uint8 contents[MAX_PROG_IE];
}
xn_progress_ie_t;

/* Called and Calling Subaddress */
typedef struct
{
    dxb_uint32 type;
    dxb_uint32 length;
    dxb_uint8 contents[MAX_SA_IE];
}
xn_sa_ie_t;

/*
 * Charging data from Facility Information Element
 *
 * charge    : sum of charges (units or currency) accumulated
 * ext_charge: sum of charges (currency) accumulated
 * multiplier: multiplier factor for charge (currency)
 * length    : number of octets in currency
 * currency  : series of IA5 characters representing the currency type
 *
 * See ETS 300 182-1 documentation for more information.
 */

typedef struct xn_charge_units_s
{
    dxb_uint32 charge;
}
xn_charge_units_t;

typedef struct xn_charge_currency_s
{
    dxb_uint32 charge;
    dxb_uint32 ext_charge;
    dxb_uint32 multiplier;
    dxb_uint32 length;
    dxb_uint8 currency[MAX_CURRENCY];
}
xn_charge_currency_t;

#define FACILITY_CHARGE 254

#define ETSI_OPVAL_AOCDCURR  33
#define ETSI_OPVAL_AOCDUNIT  34
#define ETSI_OPVAL_AOCECURR  35
#define ETSI_OPVAL_AOCEUNIT  36

/*
 * used internally
 */
typedef struct xisdnf
{
    uint32 number_plan;
    uint32 number_type;
    uint32 pres_ind_scr;
    uint32 number_len;
    unsigned char number[ISDN_NUMBER_MAXSZ];
    uint32 subadr_type;
    uint32 subadr_len;
    unsigned char subadr[ISDN_SUBADR_MAXSZ];
}
xisdnf_t;

/******************************************************************************
 * B protocol definitions and structures 
 *****************************************************************************/

/*
 * B1 protocol definitions
 */
#define B1_HDLC64       0      /* 64 kbit/s w/HDLC framing (default) */
#define B1_RAW64        1      /* 64 kbit/s bit-transparent */
#define B1_V110_ASYNC	2      /* V.110 async w/start-stop framing */
#define B1_V110_SYNC	3      /* V.110 sync w/HDLC framing */
#define B1_T30		4      /* T.30 Modem for Group 3 FAX */
#define B1_HDLC64_INV	5      /* 64 kbit/s inverted w/HDLC framing */
#define B1_RAW56        6      /* 56 kbit/s bit-transparent */
#define B1_MODEM_FN	7      /* Modem w/full negotiation */
#define B1_MODEM_SSBF	8      /* Modem async w/start-stop framing */
#define B1_MODEM_HDLC	9      /* Modem sync w/ HDLC framing */

#define B1_CIP_DEFAULT  256
#define B1_HDLC56       257
#define B1_ULAW         258    /* Not Supported */
#define B1_ALAW         259    /* Not Supported */
#define B1_NONE         260
#define B1_HDLC_ID      261    /* Layer 1 auto frame detection mode */

/* B1 protocol/layer 1 config map 

 * B1_HDLC64    L1_HDLC64
 * B1_RAW64     L1_RAW64
 * B1_V110_SYNC L1_V110         
 * B1_RAW56     L1_RAW56
 * ?            B1_CIP_DEFAULT 
 * ?            B1_HDLC56
 * ?            B1_ULAW
 * ?            B1_ALAW
 * ?            B1_V120 
 * ?            B1_NONE
 * ?            B1_HDLC_ID
 */

/*
 * B2 protocol definitions
 */
#define B2_X75SLP       0      /* ISO 7776 (X75 SLP) (default) */
#define B2_RAW		1      /* Transparent */
#define B2_SDLC		2      /* SDLC */
#define B2_LAPD		3      /* LAPD (Q.921) for D-channel X.25 on SAPI 16 */
#define B2_T30		4      /* T.30 for Group 3 FAX */
#define B2_PPP		5      /* Point-to-Point Protocol (PPP) */
#define B2_RAW_E	6      /* Transparent (ignore framing errors of B1 ) */
#define B2_MODEM_FN	7      /* Modem w/full neg. (e.g. V.42 bis, MNP 5) */
#define B2_X75SLP_V42	8      /* ISO 7776 w/V.42 bis compression */
#define B2_V120		9      /* V.120 asynchronous mode */
#define B2_V120_V42	10     /* V.120 asynchronous mode w/V.42 bis comp. */
#define B2_V120_RAW	11     /* V.120 bit-transparent mode */
#define B2_LAPD_SAPI	12     /* LAPD (Q.921) for DCH X.25 on SAPI chosen */

/*
 * B3 protocol definitions
 */
#define B3_RAW		0      /* Transparent (default) */
#define B3_T90NL	1      /* T.90NL w/T.70NL */
#define B3_X25_DTE	2      /* ISO 8208 (X25 DTE-DTE) */
#define B3_X25_DCE	3      /* X25 DCE */
#define B3_T30		4      /* T.30 for Group 3 FAX */
#define B3_T30_EXT	5      /* T.30 for Group 3 FAX Extended */
#define B3_RESERVED	6      /* Reserved */
#define B3_MODEM	7      /* Modem */

/*
 * Mode definitions
 */
#define	BMODE_STATIC	0      /* Connect req. -- no disc. indications */
#define	BMODE_ACTIVE	1      /* Connect req. -- allow disc. indications */
#define	BMODE_PASSIVE	2      /* Connect ind. -- allow disc. indications */

typedef struct
{
    dxb_uint16 max_bit_rate;
    dxb_uint16 bits_per_character;
    dxb_uint16 parity;
    dxb_uint16 stop_bits;
    dxb_uint16 options;
    dxb_uint16 speed_negotiation;
    dxb_uint32 max_frame_size; /* maximum frame size for HDLC  */
}
b1_config_t;

typedef struct
{
    dxb_uint8 address_a;
    dxb_uint8 address_b;
    dxb_uint8 modulo_mode;
    dxb_uint8 window_size;
    dxb_uint16 direction;
    dxb_uint16 code_words;
    dxb_uint16 max_string;
}
b2_config_t;

typedef struct
{
    dxb_uint16 options;
    dxb_uint16 resolution;
    dxb_uint16 format;
    char station_id[20];
    char headline[80];
}
b3_t30_config_t;

typedef struct
{
    dxb_uint16 lic;
    dxb_uint16 hic;
    dxb_uint16 ltc;
    dxb_uint16 htc;
    dxb_uint16 loc;
    dxb_uint16 hoc;
    dxb_uint16 modulo_mode;
    dxb_uint16 window_size;
}
b3_config_t;

typedef struct
{
    dxb_uint16 mode ;
    dxb_uint16 b1_protocol;
    dxb_uint16 b2_protocol;
    dxb_uint16 b3_protocol;
    b1_config_t b1_config;
    b2_config_t b2_config;
    b3_config_t b3_config;
}
b_proto_t;

/* typedef struct ncpi_x25 */
typedef struct
{
    dxb_uint8 options;
    dxb_uint8 group;
    dxb_uint8 channel;
    dxb_uint8 contents[1];
}
ncpi_x25_t;

/* typedef struct ncpi_t30 */
typedef struct 
{
    dxb_uint16 rate;
    dxb_uint16 options;
    dxb_uint16 format;
    dxb_uint16 pages;
    dxb_uint32 rx_id;
}
ncpi_t30_t;

/* typedef struct ncpi_modem */
typedef struct 
{
    dxb_uint16 rate;
    dxb_uint16 protocol;
}
ncpi_modem_t;

/******************************************************************************
 * Call control API primitive definitions and structures 
 *****************************************************************************/

/*
 * T1 Channelized - Normalized/Physical Channel Map
 * 
 * Normalized 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
 * Channel    4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1
 * 
 * Physical   2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
 * Channel    4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1
 * (Timeslot)
 * 
 * T1 ISDN - Normalized/Physical Channel Map
 * 
 * Normalized   2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
 * Channel      3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1
 * 
 * Physical   2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
 * Channel    4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1
 * (Timeslot)
 * 
 * E1 R2/ISDN - Normalized/Physical Channel Map
 * 
 * Normalized 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1   1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
 * Channel    0 9 8 7 6 5 4 3 2 1 0 9 8 7 6   5 4 3 2 1 0 9 8 7 6 5 4 3 2 1
 * 
 * Physical   3 3 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
 * Channel    1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
 * (Timeslot)
 */ 

/*
 * XN_ALERT_REQ
 *
 * Generate ALERTING message
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_ALERT_REQ                 */
    dxb_uint32 call_id;	       /* call id                      */
}
xn_alert_t;

/*
 * XN_BAD_MESSAGE_IND
 *
 * Firmware indication of the receipt of a bad message from the user
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_BAD_MESSAGE_IND           */
    dxb_uint32 id;	       /* call or listen id            */
    dxb_uint32 message;	       /* errored message              */
    dxb_uint32 reason;	       /* Cause for error message      */
}
xn_bad_msg_ind_t;

/*
 * XN_CALL_PROC_REQ
 *
 * Generate CALL PROCEEDING message
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_CALL_PROC_REQ             */
    dxb_uint32 call_id;	       /* call id                      */
    xn_progress_ie_t progress;     /* progress IE                  */
}
xn_call_proc_t;

/*
 * XN_CONN_REQ
 *
 * User request to generate SETUP message
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_CONN_REQ                  */
    dxb_uint32 call_id;	       /* call id                      */
    dxb_uint32 snid;	       /* subnetwork id                */
    dxb_uint32 chan_type;      /* channel type: B, H0, etc     */
    dxb_uint32 channel;	       /* selected normalized channel  */
    dxb_uint32 cip_value;      /* CAPI style CIP value         */
    xn_cdpn_ie_t dest_addr;    /* called address               */
    xn_sa_ie_t dest_subaddr;   /* called subaddress            */
    xn_cgpn_ie_t org_addr;     /* calling address              */
    xn_sa_ie_t org_subaddr;    /* calling subaddress           */
    xn_bc_ie_t bc;	       /* bearer capability            */
    xn_llc_ie_t llc;	       /* low layer compatability      */
    xn_hlc_ie_t hlc;	       /* high layer compatibility     */
    b_proto_t b_protocol;      /* B-channel protocol config    */
    dxb_uint32 info_mask;      /* CAPI style info mask         */
}
xn_conn_req_t;

/*
 * Info_mask bit values for xn_listen_t, xn_conn_req_t and xn_conn_ind_t structs
 */
#define INFO_CAUSE	0x0001
#define INFO_DATE_TIME	0x0002
#define INFO_DISPLAY	0x0004 /* Not supported, yet */
#define INFO_USER_USER	0x0008 /* Not supported, yet */
#define INFO_CALL_PROG	0x0010
#define INFO_FACILITY	0x0020
#define INFO_CHARGE	0x0040
#define INFO_DEST	0x0080
#define INFO_CHANNEL_ID	0x0100
#define INFO_EARLY_B3	0x0200 /* Not supported, yet */
#define INFO_REDIR	0x0400 /* Not supported, yet */
#define INFO_LATE_B3	0x2000
#define INFO_AUTO_B_CON	0x4000 /* ??? */
#define INFO_VERBOSE	0x8000

/*
 * CIP also implies a default b protocol ???
 * CIP is defined as in CAPI document Ver 2.0.  
 * The following values are currently supported
 * CIP_SPEECH : 
 * CIP_UDI
 * CIP_RDI
 * CIP_AUDIO31K
 * CIP_PACKET
 * CIP_RA56K
 * CIP_TOLLSAVER 
 *
 * The following values are not implemented/supported 
 * CIP_AUDIO7K
 * CIP_VIDEO
 * CIP_UDITA
 */
#define CIP_NONE        0
#define CIP_SPEECH      1      /* BC : 0x04, 0x03, 0x80, 0x90, 0xA2|0xA3  */
#define CIP_UDI         2      /* BC : 0x04, 0x02, 0x88, 0x90,            */
#define CIP_RDI         3      /* BC : 0x04, 0x02, 0x89, 0x90,            */
#define CIP_AUDIO31K    4      /* BC : 0x04, 0x03, 0x90, 0x90, 0xA2|0xA3  */
#define CIP_AUDIO7K     5      /* BC : 0x04, 0x02, 0x91, 0x90,            */
#define CIP_VIDEO       6      /* BC : 0x04, 0x02, 0x98, 0x90,            */
#define CIP_PACKET      7      /* BC : 0x04, 0x04, 0x88, 0xC0, 0xC6, 0xE6 */
#define CIP_RA56K       8      /* BC : 0x04, 0x04, 0x88, 0x90, 0x21, 0x8F */
#define CIP_UDITA       9      /* BC : 0x04, 0x03, 0x91, 0x90, 0xA5,      */
#define CIP_TOLLSAVER   10     /* BC : 0x04, 0x02, 0x80, 0x90,            */

/*
   #define CIP_TELEPHONY        16
   #define CIP_FAX3             17
   #define CIP_FAX4             18
   #define CIP_TELEXMIXED       19
   #define CIP_TELEXPROC        20
   #define CIP_TELEXBASIC       21
   #define CIP_VIDEOTEX         22
   #define CIP_TELEX            23
   #define CIP_X400             24
   #define CIP_X200             25
   #define CIP_TELEPHONY7K      26
   #define CIP_TELEPHONYF7211   27
   #define CIP_TELEPHONYF7212   28
 */

#define CIP_MAX		32

#define CIP_TABLE \
	{ \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x04,0x03,0x80,0x90,0xA2,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x04,0x02,0x88,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x04,0x02,0x89,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x04,0x03,0x90,0x90,0xA2,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x04,0x02,0x90,0x91,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x04,0x02,0x98,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x04,0x04,0x88,0xC0,0xC6,0xE6,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x04,0x04,0x88,0x90,0x21,0x8F,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x04,0x03,0x91,0x90,0xA5,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x04,0x02,0x80,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, \
        {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}  \
	} 

/* usage: uint32 cip_table[][] = CIP_TABLE */

/*
 * Used for size of an array in il3_to_wan()
 */
#define CIPVALSZ 12

/*
 * XN_CONN_CONF
 *
 * Firmware confirmation of receipt of CONNECT message
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_CONN_CONF                 */
    dxb_uint32 call_id;	       /* call id                      */
    dxb_uint32 snid;	       /* actual subnetwork id         */
    dxb_uint32 channel;	       /* actual normalized channel    */
    xn_cgpn_ie_t conn_addr;    /* connected address            */
    xn_sa_ie_t conn_subaddr;   /* connected subaddress         */
    xn_llc_ie_t llc;	       /* low layer compatability      */
    xn_crv_ie_t cref;	       /* call reference value         */
}
xn_conn_conf_t;

/*
 * ring type definitions
 */
#define RING_TYPE_GENERIC	0x0000

/*
 * XN_CONN_IND
 *
 * Firmware indication of receipt of SETUP message
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_CONN_IND                  */
    dxb_uint32 call_id;	       /* call id                      */
    dxb_uint32 snid;	       /* subnetwork id                */
    dxb_uint32 ring_type;      /* ring type: generic, distinctive, etc... */
    dxb_uint32 chan_type;      /* channel type: B, H0, etc     */
    dxb_uint32 channel;	       /* selected normalized channel  */
    dxb_uint32 cip_value;      /* CAPI style CIP value         */
    xn_cdpn_ie_t dest_addr;    /* called address               */
    xn_sa_ie_t dest_subaddr;   /* called subaddress            */
    xn_cgpn_ie_t org_addr;     /* calling address              */
    xn_sa_ie_t org_subaddr;    /* calling subaddress           */
    xn_bc_ie_t bc;	       /* bearer capability            */
    xn_llc_ie_t llc;	       /* low layer compatability      */
    xn_hlc_ie_t hlc;	       /* high layer compatibility     */
    xn_crv_ie_t cref;	       /* call reference value         */
}
xn_conn_ind_t;

/*
 * XN_CONN_RESP
 *
 * User response to generate CONNECT message
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_CONN_RESP                 */
    dxb_uint32 call_id;	       /* call id                      */
    dxb_uint32 channel;	       /* selected normalized channel  */
    xn_cgpn_ie_t conn_addr;    /* connected address            */
    xn_sa_ie_t conn_subaddr;   /* connected subaddress         */
    xn_llc_ie_t llc;	       /* low layer compatability      */
    b_proto_t b_protocol;      /* B-channel protocol config    */
    dxb_uint32 info_mask;      /* CAPI style info mask         */
}
xn_conn_resp_t;

/*
 * XN_CONN_RESP_REJECT
 *
 * User response to generate RELEASE_COMPLETE message
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_CONN_RESP_REJECT          */
    dxb_uint32 call_id;	       /* call id                      */
    dxb_uint32 listen_id;      /* responding listener ID       */
    dxb_uint32 cause;	       /* cause (if any) else zero     */
}
xn_conn_resp_rej_t;

/*
 * XN_CONN_ACTIVE_IND
 *
 * Firmware indication of active B channel data path
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_CONN_ACTIVE_IND           */
    dxb_uint32 call_id;	       /* call id                      */
}
xn_conn_act_t;

/*
 * XN_DISCONN_REQ / XN_DISCONN_RESP
 *
 * User request to generate DISCONNECT message.
 * User response to a firmware disconnect indication.
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_DISCONN_REQ / XN_DISCONN_IND */
    dxb_uint32 call_id;	       /* call id                      */
    dxb_uint32 cause;	       /* cause (if any) else zero     */
}
xn_disconn_req_t;

/*
 * XN_DISCONN_IND / XN_DISCONN_CONF / XN_DISCONN_COMP
 *
 * Firmware indication of DISCONNECT message.
 * Firmware indication of final call clearing.
 * Firmware indication of timeout while waiting for XN_DISCONN_RESP from user
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_DISCONN_IND/XN_DISCONN_CONF/
					XN_DISCONN_COMP */
    dxb_uint32 call_id;	       /* call id                      */
    dxb_uint32 net_cause;      /* cause (if any) else zero     */
    dxb_uint32 local_cause;    /* cause (if any) else zero     */
    dxb_uint32 channel;	       /* normalized channel ?         */
    xn_crv_ie_t cref;	       /* call reference value ?       */
}
xn_disconn_ind_t;

typedef xn_disconn_ind_t xn_disconn_resp_t;

/*
 * XN_FACILITY_REQ
 *
 * Generate FACILITY message
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_FACILITY_REQ              */
    dxb_uint32 call_id;	       /* call id                      */
    xn_ie_t facility;	       /* facility IE                  */
}
xn_facility_req_t;

/*
 * XN_INFO_REQ
 *
 * User request to generate INFORMATION message
 *
 * The info_num parameter specifies the contents of info. It is defined 
 *
 * Here is a brief description:
 *
 * For IEs Bit15 = 0, Bit14 = 0 and the low byte = the IE number
 *
 *     0x0070 : CALLED_PARTY_NUMBER 
 *
 *     info contains IE data in xn_cdpn_ie_t
 *
 *     0x002C : KEYPAD_FACILITY 
 *
 *     info contains IE data in xn_keypad_ie_t
 */

typedef struct
{
    dxb_uint32 command;	       /* XN_INFO_REQ			*/
    dxb_uint32 call_id;	       /* call id			*/
    dxb_uint32 info_num;       /* info number per CAPI		*/
    xn_cdpn_ie_t cpn;          /* data                          */
    xn_keypad_ie_t kp;         
}
xn_info_req_t;

/*
 *
 * XN_INFO_IND
 *
 * Firmware indication of receipt of call information
 *
 * Applications can request XN_INFO_IND by setting info_mask in 
 * XN_LISTEN_REQ, XN_CONN_REQ or XN_CONN_RESP.
 *
 * The info_num parameter specifies the contents of info. It is defined 
 * identically to CAPI 2.0 spec. Here is a brief description:
 *
 * For messages Bit15 = 1, Bit14 = 0 and the low byte = the message number
 *
 *     0x8001 : ALERTING
 *     0x8002 : CALL PROCEEDING
 *     0x8003 : PROGRESS
 *     0x800D : SETUP ACKNOWLEDGE
 *     0x8045 : DISCONNECT
 *
 *     info does not contain any data
 *
 * For IEs Bit15 = 0, Bit14 = 0 and the low byte = the IE number
 *
 *     0x0008 : CAUSE 
 *     0x0018 : CHANNEL_IDENTIFICATION
 *     0x001C : FACILITY
 *     0x001E : PROGRESS_IND 
 *     0x0028 : DISPLAY 
 *     0x0029 : DATE_TIME 
 *     0x0070 : CALLED_PARTY_NUMBER 
 *     0x0074 : REDIRECTING 
 *     0x007E : USER_USER 
 *
 *     ie or cpn contains IE data
 *
 * For charging units Bit15 = 0, Bit14 = 1 and the low byte = 0x00
 *
 *     0x4000 : total charges in charge units
 *
 *     cu contains IE data
 *
 * For charging currency Bit15 = 0, Bit14 = 1 and the low byte = 0x01
 *
 *     0x4001 : total charges in national currency
 *
 *     cc contains IE data
 */

typedef struct
{
    dxb_uint32 command;	       /* XN_INFO_IND			*/
    dxb_uint32 call_id;	       /* call id			*/
    xn_crv_ie_t cref;	       /* call ref ?			*/
    dxb_uint32 info_num;       /* info number per CAPI		*/
    xn_charge_units_t cu;      /* data                          */
    xn_charge_currency_t cc;
    xn_cdpn_ie_t cpn;
    xn_ie_t ie;
}
xn_info_ind_t;

/*
 * XN_LISTEN_REQ
 *
 * User request to listen for incoming calls
 *
 * XN_LISTEN_CONF
 *
 * Firmware confirmation of listen request
 */

typedef struct
{
    dxb_uint32 command;	       /* XN_LISTEN_REQ/XN_LISTEN_CONF */
    dxb_uint32 listen_id;      /* listener id                  */
    dxb_uint32 snid;	       /* subnetwork id                */
    xn_cdpn_ie_t dest_addr;    /* listen called address        */
    xn_sa_ie_t dest_subaddr;   /* listen called subaddress     */
    dxb_uint32 info_mask;      /* CAPI style info mask         */
    dxb_uint32 cip_mask;       /* CAPI style CIP mask          */
    dxb_uint32 cip_mask_2;     /* CAPI style CIP mask          */
}
xn_lstn_t;

typedef xn_lstn_t xn_listen_req_t;
typedef xn_lstn_t xn_listen_conf_t;

/*
 * Defines for CIP mask
 */
#define CIP_MASK_ANY		0x00000001
#define CIP_MASK_SPEECH		0x00000002
#define CIP_MASK_UDI		0x00000004
#define CIP_MASK_RDI		0x00000008
#define CIP_MASK_AUDIO31K	0x00000010
/* #define CIP_MASK_AUDIO7K     0x00000020 */
/* #define CIP_MASK_VIDEO       0x00000040 */
#define CIP_MASK_PACKET		0x00000080
#define CIP_MASK_RA56K		0x00000100
/* #define CIP_MASK_UDITA       0x00000200 */
#define CIP_MASK_TOLLSAVER	0x00000400

/*
   #define CIP_MASK_TELEPHONY   0x00010000
   #define CIP_MASK_FAX3        0x00020000
   #define CIP_MASK_FAX4        0x00040000
   #define CIP_MASK_TELEXMIXED  0x00080000
   #define CIP_MASK_TELEXPROC   0x00100000
   #define CIP_MASK_TELEXBASIC  0x00200000
   #define CIP_MASK_VIDEOTEX    0x00400000
   #define CIP_MASK_TELEX       0x00800000
   #define CIP_MASK_X400        0x01000000
   #define CIP_MASK_X200        0x02000000
   #define CIP_MASK_TELEPHONY7K 0x04000000
   #define CIP_MASK_TELEPHONYF7211 0x08000000
   #define CIP_MASK_TELEPHONYF7212 0x10000000
 */

/*
 * XN_PROGRESS_REQ
 *
 * Generate PROGRESS message
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_PROGRESS_REQ             */
    dxb_uint32 call_id;	       /* call id                      */
    xn_progress_ie_t progress;     /* progress IE                  */
}
xn_progress_req_t;

/*
 * XN_RING_IND
 *
 * Ring event message.  Generally expected by internal analog device which
 * speak to the arbiter.  Will only appear for inbound Channelized T1 calls.
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_RING_IND			*/
    dxb_uint32 call_id;	       /* call id			*/
    dxb_uint32 ring_event;     /* type of ring event		*/
}
xn_ring_t;

#define	RING_START_EVENT	0x00000001
#define	RING_STOP_EVENT		0x00000002

/*
 * XN_SELECT_B_PROTOCOL_REQ
 *
 * User request to change B protocol
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_SELECT_B_PROTOCOL_REQ     */
    dxb_uint32 call_id;	       /* call id                      */
    b_proto_t b_protocol;      /* B-channel protocol config    */
}
xn_sel_b_proto_t;

/*
 * XN_USER_INFO_REQ
 *
 * Generate USER INFORMATION message
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_USER_INFO_REQ             */
    dxb_uint32 call_id;	       /* call id                      */
    xn_ie_t info;	       /* information IE               */
}
xn_user_info_req_t;

/******************************************************************************
 * Data API primitive definitions and structures 
 *****************************************************************************/

/*
 * XN_DATA_REQ
 *
 * User request to transmit B channel data
 *
 * XN_DATA_IND
 *
 * Firmware indication of received B channel data 
 *
 * Note: These are control_data messages. The structure below is in the control
 * portion and the data is in the data portion.
 *
 * Note: Many protocols will just use plain data messages.
 * Note: The secondary call id is for protocols supporting virtual calls (X.25)
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_DATA                           */
    dxb_uint32 call_id;	       /* call id                           */
    dxb_uint32 call_id_2;      /* secondary call id                 */
    dxb_uint32 error;	       /* error message type                */
    dxb_uint32 flags;	       /* CAPI flags for X.25 and V.120     */
}
xn_data_t;

/*
 * XN_CONN_B_REQ, XN_CONN_B_CONF, XN_CONN_B_IND, XN_CONN_B_RESP
 * XN_DISCONN_B_REQ, XN_DISCONN_B_CONF, XN_DISCONN_B_IND, XN_DISCONN_B_RESP
 * XN_CONN_B3_ACT_IND, XN_CONN_B3_ACT_RESP
 * XN_CONNECT_B, XN_CONNACK_B, XN_DISCONNECT_B, XN_DISCONNACK_B
 *
 * B protocol connect and disconnect messages.
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_B_*                       */
    dxb_uint32 call_id;	       /* call id                      */
    dxb_uint32 call_id_2;      /* secondary call id            */
    dxb_uint32 info;	       /* info, reason or reject       */
    ncpi_x25_t x25;            /* x25 protocol specific info   */
    ncpi_t30_t t30;            /* t30 protocol specific info   */
    ncpi_modem_t modem;        /* modem protocol specific info */
}
xn_b_call_t;

/*
 * XN_FLUSH
 *
 * Flush inbound and/or outbound data.  This command does NOT affect API
 * commands, including XN_SYNC.  Any of the flags may be used in any
 * combination.  This message may be sent as normal priority or high
 * priority.  No response is generated.
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_FLUSH           */
    dxb_uint32 call_id;	       /* call id            */
    dxb_uint32 call_id_2;      /* secondary call id  */
    dxb_uint32 flags;	       /* See below          */
}
xn_flush_t;

typedef xn_flush_t xn_flsh_t;

#define	FLUSH_INPUT_BUFFER	0x01	/* Flush read-side data         */
#define	FLUSH_OUTPUT_BUFFER	0x02	/* Flush write-side data  */
#define	FLUSH_ABORT_TX_FRAME	0x04	/* Abort current outbound frame */

/*
 * XN_MARK
 *
 * Set mark idle detect mode, or issue mark idle interframe fill orders.
 * This command should be issued during active calls only.
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_MARK            */
    dxb_uint32 call_id;	       /* call id            */
    dxb_uint32 call_id_2;      /* secondary call id  */
    dxb_uint32 mode;	       /* Operational mode -- see below */
}
xn_mark_t;

/* Choices for xn_mark_t mode field */
#define MARK_TX_DEACTIVATE      1
#define MARK_TX_ACTIVATE        2
#define MARK_TX_ONCE            3
#define MARK_RX_DETECT_ON       4
#define MARK_RX_DETECT_OFF      5

/*
 * XN_SYNC
 *
 * Synchronization message.  Message is sent by user, and firmware bounces
 * message back to user when all data before the message is transmitted,
 * if sync message is sent normal priority.
 */
typedef struct
{
    dxb_uint32 command;	       /* XN_SYNC                    */
    dxb_uint32 call_id;	       /* call id                    */
    dxb_uint32 sync_id;	       /* Optional unique identifier */
    dxb_uint32 flags;	       /* See below                  */
}
xn_sync_t;

#define	SYNC_RESHIPRI		0x02	/* Make sync response high priority */

/******************************************************************************
 * Generic ISDN API primitive
 *****************************************************************************/

/*
 * Message header
 */
typedef struct
{
    dxb_uint32 command;
    dxb_uint32 call_id;
}
xn_msg_t;

#ifndef __cplusplus
union xn_isdn_primitives
{
    dxb_uint32 command;	      
    xn_msg_t msg;

    xn_alert_t alert;
    xn_bad_msg_ind_t bad_msg;
    xn_call_proc_t call_proc;
    xn_conn_req_t conn_req;
    xn_conn_conf_t conn_conf;
    xn_conn_ind_t conn_ind;
    xn_conn_resp_t conn_resp;
    xn_conn_resp_rej_t conn_rej;
    xn_conn_act_t conn_act;
    xn_disconn_req_t disconn_req;
    xn_disconn_ind_t disconn_ind;
    xn_info_req_t info_req;
    xn_info_ind_t info_ind;
    xn_lstn_t listen;
    xn_ring_t ring;
    xn_sel_b_proto_t sel_b;


    xn_data_t data;

    xn_b_call_t b_stuff;

    xn_flush_t flush;
    xn_mark_t mark;
    xn_sync_t sync;
};

#define	ISDN_API_MAX_MSG_SIZE	(sizeof(union xn_isdn_primitives))

#else
typedef struct union_isdn_api {
private:
	// pointer is stored here
	volatile void *location ;

public:
	// methods to present casts of that pointer
	inline xn_alert_t *alert() { return ((xn_alert_t *) location) ; }
	inline xn_bad_msg_ind_t *badmsg() { return ((xn_bad_msg_ind_t *) location) ; }
	inline xn_call_proc_t *callproc() { return ((xn_call_proc_t *) location) ; }
	inline xn_conn_req_t *connreq() { return ((xn_conn_req_t *) location) ; }
	inline xn_conn_conf_t *connconf() { return ((xn_conn_conf_t *) location) ; }
	inline xn_conn_ind_t *connind() { return ((xn_conn_ind_t *) location) ; }
	inline xn_conn_resp_t *connresp() { return ((xn_conn_resp_t *) location) ; }
	inline xn_conn_resp_rej_t *connrej() { return ((xn_conn_resp_rej_t *) location) ; }
	inline xn_conn_act_t *connact() { return ((xn_conn_act_t *) location) ; }
	inline xn_disconn_req_t *discreq() { return ((xn_disconn_req_t *) location) ; }
	inline xn_disconn_ind_t *discind() { return ((xn_disconn_ind_t *) location) ; }
	inline xn_facility_req_t *facreq() { return ((xn_facility_req_t *) location) ; }
	inline xn_info_req_t *inforeq() { return ((xn_info_req_t *) location) ; }
	inline xn_info_ind_t *infoind() { return ((xn_info_ind_t *) location) ; }
	inline xn_lstn_t *listen() { return ((xn_lstn_t *) location) ; }
	inline xn_progress_req_t *progreq() { return ((xn_progress_req_t *) location) ; }
	inline xn_ring_t *ring() { return ((xn_ring_t *) location) ; }
	inline xn_sel_b_proto_t *selb() { return ((xn_sel_b_proto_t *) location) ; }
	inline xn_user_info_req_t *userinforeq() { return ((xn_user_info_req_t *) location) ; }
	inline xn_data_t *data() { return ((xn_data_t *) location) ; }
	inline xn_b_call_t *bcall() { return ((xn_b_call_t *) location) ; }
	inline xn_flush_t *flush() { return ((xn_flush_t *) location) ; }
	inline xn_mark_t *mark() { return ((xn_mark_t *) location) ; }
	inline xn_sync_t *sync() { return ((xn_sync_t *) location) ; }
	inline uint32 command() { return (uint32) *((dxb_uint32 *) location) ; }
	inline uint32 call_id() { return (uint32) ((xn_msg_t *) location)->call_id ; }

	// Constructor #1
	union_isdn_api(void *ptr) {
		location = ptr ;
	}

	// Constructor #2
	union_isdn_api(uint8 *ptr) {
		location = (void *) ptr ;
	}

	// Constructor #3
	union_isdn_api(char *ptr) {
		location = (void *) ptr ;
	}

	// Dummy null constructor
	union_isdn_api() {}

	// Eventually, we should come up with a way of quickly giving them
	// the right size.
	inline uint32 max_size() {
		return 512 ;
	}
} isdn_api_t ;

#define	ISDN_API_MAX_MSG_SIZE	(((isdn_api_t *) 0)->max_size())

#endif /* __cplusplus */

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

#endif /* ARB_2 */

#endif/*_ISDN_PROTO_*/ 

