/***********************************************************
Copyright (C), LGC Wireless.
File Name:		isdn_const.h
Description:	ISDN const define
Version:		v9.0.0
Author:			Gengxin Chen
Create Date:	2008-1-24
History:
	<author>	<date>		<version>		<desc>
	
************************************************************/

#ifndef _ISDN_CONST_H
#define _ISDN_CONST_H

//#define PROTO_ISDN			3

//user - network interface
#define NETWORK_SIDE				0
#define USER_SIDE					1

#define ISDN_IP_PORT				4958	//4951	4953

//NFAS
#define NFAS_DISABLE				0x00
#define NFAS_ENABLE					0x01

//priority
#define REATTEMPT					0x00
#define DISCARD						0x01

//run_mode
#define ISDN_SINGLE_MODE			0x00	/* Single Plat */
#define ISDN_DUAL_MODE				0x01	/* Dual Plat  */

//call state
#define IDLE_FLAG					0x00
#define CALLIN_FLAG					0x01
#define CALLOUT_FLAG				0x02
//timer_flag
#define DC_M_FLAG					0x04
#define BC_M_FLAG					0x08

//ansi isdn maintenance state
//D-channel state
#define DS_MOOS							        	0x00	//In Service
#define DS_IS							        	0x01	//Maintenance Busy
#define DS_OOS							        	0x02	//Out Of Service
#define DS_STBY									0x04	//Standby
#define DS_WAIT									0x08	//Wait
#define DS_MB									0x10	//Manual Out Of Service
#define DS_INB							        	0x12	//Installation Busy
//B-channel state
#define IN_SERVICE								0x00
#define MAINTENANCE_SERVICE					0x01
#define OUT_OF_SERVICE							0x02
//iua link state
#define LK_OOS									0x00
#define LK_IS									0x01

/************************************************************
ISDN message type
************************************************************/
#define PROTOCOL_ISDN_LINK_MNG		0xFE
#define PROTOCOL_DISCR					0x08	//Q.931 Protocol discriminator
//Call establishment message
#define MSG_ALERT	        		 	0x01	//Alerting
#define MSG_CALL_PROC		         	0x02	//Call Proceeding
#define MSG_CONN	          			0x07	//Connect
#define MSG_CONNACK          			0x0F	//Connect Acknowledge
#define MSG_PROG	         			0x03	//Progress
#define MSG_SETUP            			0x05	//Setup
#define MSG_SETUP_ACK        			0x0D	//Setup Acknowledge
//Call clearing message
#define MSG_DISC		       		0x45	//Disconnect
#define MSG_REL		          			0x4D	//Release
#define MSG_REL_COMP          			0x5A	//Release Complete
#define MSG_RESTART          			0x46	//Restart
#define MSG_REST_ACK          			0x4E	//Restart Acknowledge
//Miscellaneous message
#define MSG_INFORMATION			0x7B	//Information
#define MSG_NOTI 	          			0x6E	//Notify
#define MSG_STATUS	           			0x7D	//Status
#define MSG_STAT_ENQ		   		0x75	//Status Enquiry
#define MSG_FAC						0x62	//Facility (connectionless)

//Maintenance message
#define M_PROTOCOL_DISCR				0x43	//Maintenance messages Protocol discriminator
#define MSG_SERVICE					0x0F	//Service
#define MSG_SERVICE_ACK			0x07	//Service Acknowledge


/************************************************************
ISDN information element identifier coding
************************************************************/
//Single octet information elements
#define IE_SHIFT							0x01	//Shift
#define IE_MORE_DATA					0xA0	//More data
#define IE_SD_COMP        				0xA1	//Send Complete
#define IE_RPT_IND						0xD2	//Repeat indicator
//Variable length information element
#define IE_BR_CAP        				0x04	//Bearer capability
#define IE_CAUSE	           			0x08	//Cause
#define IE_CALL_ID						0x10	//Call identifier
#define IE_CALL_STAT      					0x14	//Call state
#define IE_CHNL_ID       					0x18	//Channel identification
#define IE_PRG_IND     					0x1E	//Progress indicator
#define IE_NT_SP_FAC					0x20	//Network-specific facilities
#define IE_NOTIFY_IND       				0x27	//Notification indicator
#define IE_DISP							0x28	//Display
#define IE_DT_TIME						0x29	//Date/time
#define IE_KPD_FAC						0x2C	//Keypad facility
#define IE_SIGN							0x34	//Signal
#define IE_CG_PTY_NUM					0x6C	//Calling party number
#define IE_CG_PTY_ADDR					0x6D	//Calling party subaddress
#define IE_CD_PTY_NUM        				0x70	//Called party number
#define IE_CD_PTY_ADDR					0x71	//Called party subaddress
#define IE_TRAN_NT_SEL					0x78	//Transit network selection
#define IE_RESTART_IND      				0x79	//Restart indicator
#define IE_LL_COMP						0x7C	//Low layer compatibility
#define IE_HL_COMP						0x7D	//High layer compatibility
#define IE_USR_USR						0x7E	//User-user
//ansi
#define IE_CHG_STAT						0x01	//Change status
#define IE_FAC							0x1C	//Facility
//#define IE_INFO_REQ						0x32	//Information request
//#define IE_ORG_CG_NUM					0x73	//Original called number
#define IE_REDIR_NUM					0x74	//Redirection number
//QSIG
#define IE_CONN_NUM					0x4C	//Connected number
//Codeset 6 information element identifiers TO-DO


/************************************************************
ISDN states exist in the user-network interface
************************************************************/
#define NULL_STATE						0x00
#define CALL_INIT_STATE					0x01
#define OVERLAP_SD_STATE				0x02
#define OUT_CALL_PROC_STATE				0x03
#define CALL_DV_STATE					0x04
#define CALL_PRE_STATE					0x06
#define CALL_RV_STATE					0x07
#define CONN_REQ_STATE					0x08
#define IN_CALL_PROC_STATE				0x09
#define ACTIVE_STATE					0x0A
#define DISC_REQ_STATE					0x0B
#define DISC_IND_STATE					0x0C
#define REL_REQ_STATE					0x13
#define OVERLAP_RV_STATE				0x19

#define GLOBAL_NULL_STATE				0x00
#define GLOBAL_RESTART_REQ_STATE		0x3D
#define GLOBAL_RESTART_STATE			0x3E
//ansi
#define SERVICE_IDLE					0x00
#define WAIT_SERVICE_ACK				0x01
#define RSP_SERVICE						0x02




/************************************************************
ISDN Event/Primitive Definition
************************************************************/
//Primitive
#define ISDN_SETUP_REQ			0x11
#define ISDN_SETUP_IND			0x21
#define ISDN_SETUP_RSP			0x31
#define ISDN_SETUP_CNF			0x41

#define ISDN_DISCONNECT_REQ	0x12
#define ISDN_DISCONNECT_IND	0x22
#define ISDN_RELEASE_REQ		0x32
#define ISDN_RELEASE_IND		0x42
#define ISDN_RELEASE_CNF		0x52
#define ISDN_REJECT_REQ			0x62

#define ISDN_ALERT_REQ			0x13
#define ISDN_ALERT_IND			0x23
#define ISDN_INFO_REQ			0x33
#define ISDN_INFO_IND			0x43
#define ISDN_PROG_REQ			0x53
#define ISDN_PROG_IND			0x63
#define ISDN_SUSPEND_REQ		0x73
#define ISDN_SUSPEND_IND		0x83
#define ISDN_RESUME_REQ			0x93
#define ISDN_RESUME_IND			0xa3

#define ISDN_PROC_REQ			0x14
#define ISDN_PROC_IND			0x24
#define ISDN_MORE_INFO_REQ	0x34
#define ISDN_MORE_INFO_IND		0x44
#define ISDN_NOTI_REQ			0x54
#define ISDN_NOTI_IND			0x64
#define ISDN_STAT_IND			0x74
#define ISDN_SETUP_COMP_REQ	0x84
#define ISDN_SETUP_COMP_IND	0x84

#define ISDN_TIMEOUT_IND		0x15
#define ISDN_RESTART_REQ		0x25
#define ISDN_M_RESTART_REQ	0x35
#define ISDN_RESTART_CNF		0x45
#define ISDN_REATTEMPT_IND		0x55
//ansi
#define ISDN_SERVICE_REQ		0x16
#define ISDN_SERVICE_IND		0x26
#define ISDN_SERVICE_CNF		0x36
#define ISDN_SERVICE_RSP		0x46
#define ISDN_SER_TIMEOUT_IND	0x56



/************************************************************
ISDN Cause Definition
************************************************************/
#define CAUSE_UNASSIGNED			0x01	//unassigned (unallocated) number
#define CAUSE_NOROUTE_NET			0x02	//no route to specified transit network
#define CAUSE_NOROUTE_DES			0x03	//no route to destination
#define CAUSE_NORMAL				0x10	//normal call clearing
#define CAUSE_INVALID_NUM			0x1C	//invalid number format(imcomplete number)
#define CAUSE_STAT_ENQ				0x1E	//response to status enquiry
#define CAUSE_TEMP_FAIL			0X29	//temporary failure
#define CAUSE_INVALID_CR			0x51	//invalid call reference value
#define CAUSE_CALLID_INUSE			0x54	//call identity in use
#define CAUSE_M_IE_MISS			0x60	//mandatory information element is missing
#define CAUSE_MSG_NONEXI			0x61	//message type non-existent or not implemented
#define CAUSE_MSG_NOTCOMP_NOTIMPL	0x62	//message not compatible with call state or message type non-existent or not implemented
#define CAUSE_IE_NONEXI			0x63	//information element non-existent or not implemented
#define CAUSE_IE_INVALID			0x64	//invalid information element contents
#define CAUSE_MSG_NOTCOMP			0x65	//message not compatible with call state
#define CAUSE_TIMER_EXPIRY			0x66	//recovery on timer expiry


/************************************************************
ISDN Timer Definition	(Time Unit = 1s)
************************************************************/
#define ISDN_T301						180		/* 180S */
#define ISDN_T302						15			/* 15S */
#define ISDN_T303						4			/* 4S */
#define ISDN_T304						20			/* 20S */
#define ISDN_T305						30			/* 30S */
#define ISDN_T306						30			/* 30S */
#define ISDN_T307						180		/* 180S */
#define ISDN_T308						4			/* 4S */
#define ISDN_T309						6			/* 6S*/
#define ISDN_T310						10			/* 10S */ 
#define ISDN_T312						6			/*T303+2S*/
#define ISDN_T313						4			/* 4S */
#define ISDN_T316						120			/* 120S */
#define ISDN_T317						10			/* <T316 */
#define ISDN_T321						40			/* 30S */
#define ISDN_T322						4			/* 4S */
#define ISDN_T40S						40			/* 40S */
#define ISDN_T240S						240		/* 240S */

#define ISDN_T1							1		/* 1S */
#define ISDN_T3M1						120		/* 120S */


#define LINK_MAX_TIME					15000		// 150s


/************************************************************
ISDN Other Definition
************************************************************/
#define IE_MAX_LEN						(256)
#define IE_COUNT						(13)

//IUA Definition
/*#define IUA_QPTM_MSG					0x05
#define IUA_MGMT_CMD					0xA5
#define IUA_APP							0x1
*/
#endif
