#ifndef _q1902_3E_H_
#define _q1902_3E_H_
#include "define.h"
#include "q765_5e.h"
/******************************************/
/******** BICC SIO (Q.1901E C.7.3) ********/
/******************************************/
#define BICC_SI		13

/******************************************/
/* Message Type Codes (Q.1902-3E, page 5) */
/******************************************/
#define M_ACM		0x06//Address complete
#define M_ANM		0x09//Answer
#define M_APM		0x41//Application transport
#define M_BLO		0x13//Blocking
#define M_BLA		0x15//Blocking acknowledgement
#define M_CPG		0x2c//Call progress
#define M_CGB		0x18//Circuit/CIC group blocking
#define M_CGBA		0x1a//Circuit/CIC group blocking acknowledgement
#define M_CQM		0x2a//Circuit/CIC group query (national use)
#define M_CQR		0x2b//Circuit/CIC group query response (national use)
#define M_GRS		0x17//Circuit/CIC group reset
#define M_GRA		0x29//Circuit/CIC group reset acknowledgement
#define M_CGU		0x19//Circuit/CIC group unblocking
#define M_CGUA		0x1b//Circuit/CIC group unblocking acknowledgement
#define M_CRG		0x31//Charge information (national use)
#define M_CFN		0x2f//Confusion
#define M_CON		0x07//Connect
#define M_COT		0x05//Continuity
#define M_FAC		0x33//Facility 
#define M_FAA		0x20//Facility accepted
#define M_FRJ		0x21//Facility reject
#define M_FAR		0x1f//Facility request
#define M_FOT		0x08//Forward transfer
#define M_IDR		0x36//Identification request
#define M_IRS		0x37//Identification response
#define M_INF		0x04//Information (national use)
#define M_INR		0x03//Information request (national use)
#define M_IAM		0x01//Initial address
#define M_LOP		0x40//Loop prevention
#define M_NRM		0x32//Network resource management
#define M_PRI		0x42//Pre-release information
#define M_REL		0x0c//Release
#define M_RLC		0x10//Release complete
#define M_RSC		0x12//Reset circuit/CIC
#define M_RES		0x0e//Resume
#define M_SGM		0x38//Segmentation
#define M_SAM		0x02//Subsequent address
#define M_SDM		0x43//Subsequent Directory Number (national use)
#define M_SUS		0x0d//Suspend
#define M_UBL		0x14//Unblocking
#define M_UBA		0x16//Unblocking acknowledgement
#define M_UCIC		0x2e//Unequipped CIC (national use)
#define M_USR		0x2d//User-to-user information


/*********************************************/
/* Parameter Name Codes (Q.1902-3E, page 10) */
/*********************************************/
#define P_APPTRANS			0x78//Application transport
#define P_BACKCALLIND		0x11//Backward call indicators
#define P_CALLEDPTYNUM		0x04//Called party number
#define P_CALLINGPTYNUM		0x0a//Calling party number
#define P_CALLINGPTYCAT		0x09//Calling party's category
#define P_CAUSEIND			0x02//Cause indicators
#define P_CICGRPSPV			0x15//Circuit/CIC group supervision message type
#define P_COLLECTCALLREQ	0x79//Collect call request
#define P_CONFTREATIND		0x72//Conference treatment indicators
#define P_CONNNUM			0x21//Connected number
#define P_CORRELATIONID		0x65//Correlation id
#define P_EVENINFO			0x24//Event information
#define P_FACIND			0x18//Facility indicator
#define P_FWDCALLIND		0x07//Forward call indicators
#define P_NATCONNIND		0x06//Nature of connection indicators
#define P_ORIGCALLEDNUM		0x28//Original called number
#define P_RANGESTATUS		0x16//Range and status
#define P_REDIRGNUM			0x0b//Redirecting number
#define P_REDIRINFO			0x13//Redirection information
#define P_SCFID				0x66//SCF id
#define P_SUBSEQNUM			0x05//Subsequent number
#define P_SUSRESIND			0x22//Suspend/Resume indicators
#define P_TRANSMEDREQ		0x02//Transmission medium requirement
#define P_UTUIND			0x2a//User-to-user indicators
#define P_UTUINFO			0x20//User-to-user information
#define P_CALLDIVERINFO	0x36//Call diversion information
#define P_OPTBACKCALLIND 0x29//Optional backward call indicators

/**********************************************/
/* Parameter Structure (Q.1902-3E, section 6) */
/**********************************************/
#define MAX_BICC_DIGIT			32
#define BICC_STATUS_LEN			32
#define BICC_APP_LEN			200
#define MAX_DIAGNOSTIC_LEN		32

typedef struct AppTrans_struct {
	u8					pres;
	u8					aci[2];				//Application context identifier
	u8					:6;
	u8					sni:1;				//Send notification indicator
	u8					rci:1;				//Release call indicator
	u16					:1;
	u16					si:1;				//Sequence indicator
	u16					segment:6;			//APM segmentation indicator
	u16					:1;
	u16					slr:7;				//Segmentation local reference
	// APM-user information (For APM'98-user application only) //
	ApmUser_struct		apm_info;
} AppTrans_struct;

typedef struct BackCallInd_struct {
	u8		pres;
	u8		val[2];
} BackCallInd_struct;

typedef struct CalledPtyNum_struct {
	u8		pres;
	u8		nai;
	u8		inn;
	u8		npi;
	u8		numOfDigit;
	u8		digit[MAX_BICC_DIGIT];
} CalledPtyNum_struct;

typedef struct CallingPtyNum_struct {
	u8		pres;
	u8		nai;
	u8		ni;
	u8		npi;
	u8		apri;
	u8		si;
	u8		numOfDigit;
	u8		digit[MAX_BICC_DIGIT];
} CallingPtyNum_struct;

typedef struct CallingPtyCat_struct {
	u8		pres;
	u8		val;
} CallingPtyCat_struct;

/* defined in Q.850E */
typedef struct CauseInd_struct {
	u8					pres;
	u8					codingStd;
	u8					location;
	u8					causeVal;
	//diagnostic
} CauseInd_struct;

typedef struct CicGrpSpv_struct {
	u8		pres;
	u8		val;
} CicGrpSpv_struct;

typedef struct CollectCallReq_struct {
	u8		pres;
	u8		val;
} CollectCallReq_struct;

typedef struct ConfTreatInd_struct {
	u8		pres;
	u8		val;
} ConfTreatInd_struct;

typedef struct ConnNum_struct {
	u8		pres;
	u8		nai;
	u8		npi;
	u8		apri;
	u8		si;
	u8		numOfDigit;
	u8		digit[MAX_BICC_DIGIT];
} ConnNum_struct;

typedef struct EventInfo_struct {
	u8		pres;
	u8		val;
} EventInfo_struct;

typedef struct FacInd_struct {
	u8		pres;
	u8		val;
} FacInd_struct;

typedef struct FwdCallInd_struct {
	u8		pres;
	u8		val[2];
} FwdCallInd_struct;

typedef struct GenericNumber_struct {
	u8		pres;
	u8		nqi;		//Number qualifier indicator
	u8		nai;
	u8		ni;
	u8		npi;
	u8		apri;
	u8		si;
	u8		numOfDigit;
	u8		digit[MAX_BICC_DIGIT];
} GenericNumber_struct;


typedef struct GenericDigits_struct         /* Generic Digits */
{
        u8              pres;                   
        u8              typeOfDigits;           
        u8              encodeScheme;
	u8		numOfDigit;           
        u8*             digits;                
} GenericDigits_struct;


typedef GenericDigits_struct CorrelationId_struct;       //R10

//typedef struct CorrelationId_struct {			//R9
//	u8 pres;
//	u8 digit[4];		//4 bytes
//}CorrelationId_struct;
typedef struct NatConnInd_struct {
	u8		pres;
	u8		val;
} NatConnInd_struct;

typedef struct OrigCalledNum_struct {
	u8		pres;
	u8		nai;
	u8		npi;
	u8		apri;
	u8		numOfDigit;
	u8		digit[MAX_BICC_DIGIT];
} OrigCalledNum_struct;

typedef struct RangeStatus_struct {
	u8		pres;
	u8		range;
	u8		status[BICC_STATUS_LEN];
} RangeStatus_struct;

typedef struct RedirgNum_struct {
	u8		pres;
	u8		nai;
	u8		npi;
	u8		apri;
	u8		numOfDigit;
	u8		digit[MAX_BICC_DIGIT];
} RedirgNum_struct;

typedef struct RedirInfo_struct{
	u8		pres;
	u8		redInd;
	u8		origRedirReason;
	u8		redirCounter;
	u8		redirReason; 
}RedirInfo_struct;

typedef GenericDigits_struct ScfId_struct;
/*typedef struct ScfId_struct {			      
        u8              pres;
        u8              nai;
        u8              inn;
        u8              npi;
        u8              numOfDigit;
        u8              digit[MAX_BICC_DIGIT];
}ScfId_struct;
*/
typedef struct SubseqNum_struct {
	u8		pres;
	u8		numOfDigit;
	u8		digit[MAX_BICC_DIGIT];
} SubseqNum_struct;

typedef struct SusResInd_struct {
	u8		pres;
	u8		val;
} SusResInd_struct;

typedef struct TransMedReq_struct {
	u8		pres;
	u8		val;
} TransMedReq_struct;

typedef struct UserToUserInd_struct {
	u8		pres;
	u8		val;
} UserToUserInd_struct;

typedef struct UserToUserInfo_struct {
	u8		pres;
	u8		len;
	u8		val[129];
} UserToUserInfo_struct;

typedef struct CallDiverInfo_struct
{
	u8		pres;
	u8		notifSubsOption;
	u8		redirReason;
}CallDiverInfo_struct;

typedef struct OptBackCallInd_struct
{
	u8		pres;
	u8		inbandInfoInd;
	u8		callDiverOccurInd;
	u8		simpSegmInd;
	u8		mlppUserInd;	
}OptBackCallInd_struct;
/********************************************/
/* Message structure (Q.1902-3E, section 7) */
/********************************************/
typedef struct BiccAcm_struct {
	BackCallInd_struct		backCall;//F
	AppTrans_struct			app;
	CauseInd_struct			cause;
	ConfTreatInd_struct		confTreat;
	OptBackCallInd_struct optBackCall;
	UserToUserInd_struct	utuInd;
	UserToUserInfo_struct	utuInfo;
} BiccAcm_struct;

typedef struct BiccAnm_struct {
	AppTrans_struct			app;
	BackCallInd_struct		backCall;
	ConfTreatInd_struct		confTreat;
	ConnNum_struct			connNum;
	UserToUserInd_struct	utuInd;
	UserToUserInfo_struct	utuInfo;
} BiccAnm_struct;

typedef struct BiccApm_struct {
	AppTrans_struct			app;
} BiccApm_struct;

typedef struct BiccCpg_struct {
	EventInfo_struct		eventInfo;//F
	AppTrans_struct			app;
	BackCallInd_struct		backCall;
	CallDiverInfo_struct  calldiver;
	CauseInd_struct			cause;
	ConfTreatInd_struct		confTreat;
	ConnNum_struct			connNum;
	UserToUserInd_struct	utuInd;
	UserToUserInfo_struct	utuInfo;
} BiccCpg_struct;

typedef struct BiccCgb_struct {
	CicGrpSpv_struct		cicGrpSpv;//F
	RangeStatus_struct		rangeStatus;//V
} BiccCgb_struct;

typedef struct BiccCgba_struct {
	CicGrpSpv_struct		cicGrpSpv;//F
	RangeStatus_struct		rangeStatus;//V
} BiccCgba_struct;

typedef struct BiccCgu_struct {
	CicGrpSpv_struct		cicGrpSpv;//F
	RangeStatus_struct		rangeStatus;//V
} BiccCgu_struct;

typedef struct BiccCgua_struct {
	CicGrpSpv_struct		cicGrpSpv;//F
	RangeStatus_struct		rangeStatus;//V
} BiccCgua_struct;

typedef struct BiccGrs_struct {
	RangeStatus_struct		rangeStatus;//V
} BiccGrs_struct;

typedef struct BiccGra_struct {
	RangeStatus_struct		rangeStatus;//V
} BiccGra_struct;

typedef struct BiccCon_struct {
	BackCallInd_struct		backCall;//F
	AppTrans_struct			app;
	ConfTreatInd_struct		confTreat;
	ConnNum_struct			connNum;
	UserToUserInd_struct	utuInd;
	UserToUserInfo_struct	utuInfo;
} BiccCon_struct;

typedef struct BiccIam_struct {
	NatConnInd_struct		natConn;//F
	FwdCallInd_struct		fwdCall;//F
	CallingPtyCat_struct	callingPtyCat;//F
	TransMedReq_struct		transMedReq;//F
	CalledPtyNum_struct		calledPtyNum;//V
	AppTrans_struct			app;
	CallingPtyNum_struct	callingPtyNum;
	CollectCallReq_struct	collectCallReq;
	ConfTreatInd_struct		confTreat;
	CorrelationId_struct	correlationId;
	OrigCalledNum_struct	origCalledNum;
	RedirgNum_struct		redirgNum;
	RedirInfo_struct		redirInfo;
	ScfId_struct			scfId;
	UserToUserInd_struct	utuInd;
	UserToUserInfo_struct	utuInfo;
	
} BiccIam_struct;

typedef struct BiccRel_struct {
	CauseInd_struct			cause;//V
	UserToUserInd_struct	utuInd;
	UserToUserInfo_struct	utuInfo;
} BiccRel_struct;

typedef struct BiccRlc_struct {
	CauseInd_struct			cause;
} BiccRlc_struct;

typedef struct BiccRes_struct {
	SusResInd_struct		susRes;//F
	//Optional
} BiccRes_struct;

typedef struct BiccSus_struct {
	SusResInd_struct		susRes;//F
	//Optional
} BiccSus_struct;

typedef struct BiccSam_struct {
	SubseqNum_struct		subseqNum;//V
	//Optional
} BiccSam_struct;

typedef struct BiccMsg_struct
{
	
}BiccMsg_struct;


typedef union BiccMsg_union {
	BiccAcm_struct		acm;
	BiccAnm_struct		anm;
	BiccApm_struct		apm;
	BiccCpg_struct		cpg;
	BiccCgb_struct		cgb;
	BiccCgba_struct		cgba;
	BiccCgu_struct		cgu;
	BiccCgua_struct		cgua;
	BiccGrs_struct		grs;
	BiccGra_struct		gra;
	BiccCon_struct		con;
	BiccIam_struct		iam;
	BiccRel_struct		rel;
	BiccRlc_struct		rlc;
	BiccRes_struct		res;
	BiccSus_struct		sus;
	BiccSam_struct		sam;
} BiccMsg_union;

#endif

