#ifndef _BICCIF_H_
#define _BICCIF_H_

#include "q765_5e.h"
#include "q1902_3e.h"
#include "../../../mtp3/src/include/mtp3.h"
#include "../../../snmp/src/include/snmp.h"
//#include "../../../public/src/include/proto_pub.h"
#include "bicc_debug.h"
#include "../../../pal/pal.h"
/*********************************/
/*** BICC Management Structure ***/
/*********************************/

#define BICC_CM_OK                 1                 //command request success
#define BICC_CM_FAILED             -1		    //command request failed

/*************************************
******BICC Resource Structure*********
*************************************/
#define BICC_MAX_PORT		8192
#define BICC_CG_CIRCUIT		32
#define BICC_CIRCUIT_CIC	32


/*** BICC Primitive Parameter Structure (different to q1902_3e) ***/
typedef struct AppTransM_struct {	//Application Transport Mechanism
	u8					pres;
	ApmUser_struct		apm_info;
} AppTransM_struct;
/*********************************/
/**** BICC Primitive Structure ***/
/*********************************/
typedef struct BiccSetup_Req {
	NatConnInd_struct		natConn;//F
	FwdCallInd_struct		fwdCall;//F
	CallingPtyCat_struct	callingPtyCat;//F
	TransMedReq_struct		transMedReq;//F
	CalledPtyNum_struct		calledPtyNum;//V
	AppTransM_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;
} BiccSetup_Req, BiccSetup_Ind;

typedef struct BiccSetup_Rsp {
	AppTransM_struct		app;
	BackCallInd_struct		backCall;//C: use it if no alert req is sent before
	ConfTreatInd_struct		confTreat;
	ConnNum_struct			connNum;
	UserToUserInd_struct	utuInd;
	UserToUserInfo_struct	utuInfo;
} BiccSetup_Rsp, BiccSetup_Cnf;

typedef struct BiccAlert_Req {
	BackCallInd_struct		backCall;//F
	AppTransM_struct		app;
	CauseInd_struct			cause;
	ConfTreatInd_struct		confTreat;
	OptBackCallInd_struct optBackCall;
	UserToUserInd_struct	utuInd;
	UserToUserInfo_struct	utuInfo;
} BiccAlert_Req, BiccAlert_Ind;

typedef struct BiccInfo_Req {
	SubseqNum_struct		subseqNum;//V
} BiccInfo_Req, BiccInfo_Ind;

typedef struct BiccApm_Req {
	AppTransM_struct		app;
} BiccApm_Req, BiccApm_Ind;

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

typedef struct BiccRel_Req {
	CauseInd_struct			cause;//V
	UserToUserInd_struct	utuInd;
	UserToUserInfo_struct	utuInfo;
} BiccRel_Req, BiccRel_Ind;

typedef struct BiccRel_Rsp {
	CauseInd_struct			cause;
} BiccRel_Rsp, BiccRel_Cnf;

typedef struct BiccRes_Req {
	SusResInd_struct		susRes;//F
} BiccRes_Req, BiccRes_Ind;

typedef struct BiccSus_Req {
	SusResInd_struct		susRes;//F
} BiccSus_Req, BiccSus_Ind;

typedef struct BiccCgb_Req {
	CicGrpSpv_struct		cicGrpSpv;//F
	RangeStatus_struct		rangeStatus;//V
} BiccCgb_Req, BiccCgb_Ind;

typedef struct BiccCgb_Rsp {
	CicGrpSpv_struct		cicGrpSpv;//F
	RangeStatus_struct		rangeStatus;//V
} BiccCgb_Rsp, BiccCgb_Cnf;

typedef struct BiccCgu_Req {
	CicGrpSpv_struct		cicGrpSpv;//F
	RangeStatus_struct		rangeStatus;//V
} BiccCgu_Req, BiccCgu_Ind;

typedef struct BiccCgu_Rsp {
	CicGrpSpv_struct		cicGrpSpv;//F
	RangeStatus_struct		rangeStatus;//V
} BiccCgu_Rsp, BiccCgu_Cnf;

typedef struct BiccGrs_Req {
	RangeStatus_struct		rangeStatus;//V
} BiccGrs_Req, BiccGrs_Ind;

typedef struct BiccGrs_Rsp {
	RangeStatus_struct		rangeStatus;//V
} BiccGrs_Rsp, BiccGrs_Cnf;


typedef struct BiccSta_Req
{
	BiccMsg_struct	biccMsg;
}BiccSta_Req;

typedef struct BiccFac_Req
{
	FacInd_struct			facInd;
}BiccFac_Req, BiccFac_Ind;

typedef struct BiccFac_Rsp
{
	FacInd_struct 			facInd;
}BiccFac_Rsp, BiccFac_Cnf;

typedef union BiccWritePrim_union {
	BiccSetup_Req			setup_req;
	BiccSetup_Rsp			setup_rsp;
	BiccAlert_Req			alert_req;
	BiccInfo_Req			info_req;
	BiccApm_Req				apm_req;
	BiccCpg_Req				cpg_req;
	BiccRel_Req				rel_req;
	BiccRel_Rsp				rel_rsp;
	BiccRes_Req				res_req;
	BiccSus_Req				sus_req;
	BiccCgb_Req				cgb_req;//only used in BICC module
	BiccCgb_Rsp				cgb_rsp;//only used in BICC module
	BiccCgu_Req				cgu_req;//only used in BICC module
	BiccCgu_Rsp				cgu_rsp;//only used in BICC module
	BiccGrs_Req				grs_req;//only used in BICC module
	BiccGrs_Rsp				grs_rsp;//only used in BICC module
	BiccFac_Req				fac_req;
	BiccFac_Rsp				fac_rsp;
} BiccWritePrim_union;

typedef union BiccReadPrim_union {
	BiccSetup_Ind			setup_ind;
	BiccSetup_Cnf			setup_cnf;
	BiccAlert_Ind			alert_ind;
	BiccInfo_Ind			info_ind;
	BiccApm_Ind				apm_ind;
	BiccCpg_Ind				cpg_ind;
	BiccRel_Ind				rel_ind;
	BiccRel_Cnf				rel_cnf;
	BiccRes_Ind				res_ind;
	BiccSus_Ind				sus_ind;
	BiccCgb_Ind				cgb_ind;//only used in BICC module
	BiccCgb_Cnf				cgb_cnf;//only used in BICC module
	BiccCgu_Ind				cgu_ind;//only used in BICC module
	BiccCgu_Cnf				cgu_cnf;//only used in BICC module
	BiccGrs_Ind				grs_ind;//only used in BICC module
	BiccGrs_Cnf				grs_cnf;//only used in BICC module
	BiccFac_Ind				fac_ind;
	BiccFac_Cnf				fac_cnf;
} BiccReadPrim_union;


/********************************************/
/****** BICC Internal Command	*************/	  
/********************************************/
#define BICC_CMD_UNBLO						0x01
#define BICC_CMD_BLO						0x02
#define BICC_CMD_RESET						0x03
#define BICC_CMD_RESET_COMP					0x04


#define BICC_SI_CPCI						0x10
#define BICC_SI_CPCO						0x20
#define BICC_SI_BLS							0x30
#define BICC_SI_BLR							0x40
#define BICC_SI_MGBR						0x50
#define BICC_SI_MGBS						0x60
#define BICC_SI_CRS							0x70
#define BICC_SI_CRR							0x80
#define BICC_SI_CGRS						0x90
#define BICC_SI_CGRR						0xA0

/********************************************/
/****** BICC Event/Primitive Definition *****/
/********************************************/

#define BICC_SETUP_REQ			0x01 		//user-defined, first 4-digit:type of primitive second 4-digit:type of event	
#define BICC_SETUP_IND			0x41
#define BICC_SETUP_RSP			0x81
#define BICC_SETUP_CNF			0xc1
#define BICC_ALERT_REQ			0x02
#define BICC_ALERT_IND			0x42
#define BICC_INFO_REQ			0x03
#define BICC_INFO_IND			0x43
#define BICC_APM_REQ			0x04
#define BICC_APM_IND			0x44
#define BICC_PROG_REQ			0x05
#define BICC_PROG_IND			0x45
#define BICC_RELEASE_REQ		0x06
#define BICC_RELEASE_IND		0x46
#define BICC_RELEASE_RSP		0x86
#define BICC_RELEASE_CNF		0xc6
#define BICC_RESET_REQ			0x07
#define BICC_RESET_IND			0x47
#define BICC_RESET_CNF			0xc7
#define BICC_RESET_RSP			0x87
#define BICC_GROUP_RESET_REQ	0x17

#define BICC_BLOCK_REQ			0x08
#define BICC_BLOCK_IND			0x48
#define BICC_BLOCK_RSP			0x88
#define BICC_BLOCK_CNF			0xc8
#define BICC_UNBLOCK_REQ		0x09
#define BICC_UNBLOCK_IND		0x49
#define BICC_UNBLOCK_RSP		0x89
#define BICC_UNBLOCK_CNF		0xc9
#define BICC_SUSPEND_REQ		0x0a
#define BICC_SUSPEND_IND		0x4a
#define BICC_RESUME_REQ			0x0b
#define BICC_RESUME_IND			0x4b
#define BICC_REATTEMPT_IND		0x4c
#define BICC_FAILURE_IND		0x4f
#define BICC_FAC_REQ			0x0d
#define BICC_FAC_RSP			0x8d
#define BICC_FAC_IND			0x4d
#define BICC_FAC_CNF			0xcd
#define BICC_STA_IND			0x4e
#define BICC_STA_REQ			0x0e
#define BICC_MAINTENANCE_IND   	0x44		//

#define BICC_STOP_REQ			0xee
#define BICC_STOP_CNF			0xef

typedef int f_bicc_setup_ind(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_setup_anm_cnf(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_setup_con_cnf(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_release_ind(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_release_cnf(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_alert_ind(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_info_ind(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_prog_ind(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_suspend_ind(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_resume_ind(Pst *pst,  const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_reset_ind(Pst *pst,  const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_reset_cnf(Pst *pst,  const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_apm_ind(Pst *pst,  const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_reattempt_ind(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_failure_ind(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_block_ind(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_block_cnf(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_unblock_ind(Pst *pst, const BiccReadPrim_union *prm_ptr);
typedef int f_bicc_unblock_cnf(Pst *pst, const BiccReadPrim_union *prm_ptr);

typedef struct bicc_eventhandle_struct
{
	f_bicc_setup_ind				*h_bicc_setup_ind;
	f_bicc_setup_anm_cnf			*h_bicc_setup_anm_cnf;
	f_bicc_setup_con_cnf			*h_bicc_setup_con_cnf;
	f_bicc_release_ind				*h_bicc_release_ind;
	f_bicc_release_cnf				*h_bicc_release_cnf;
	f_bicc_alert_ind				*h_bicc_alert_ind;
	f_bicc_info_ind					*h_bicc_info_ind;
	f_bicc_prog_ind					*h_bicc_prog_ind;
	f_bicc_suspend_ind				*h_bicc_suspend_ind;
	f_bicc_resume_ind				*h_bicc_resume_ind;
	f_bicc_block_ind				*h_bicc_block_ind;
	f_bicc_block_cnf				*h_bicc_block_cnf;
	f_bicc_unblock_ind				*h_bicc_unblock_ind;
	f_bicc_unblock_cnf				*h_bicc_unblock_cnf;
	f_bicc_reset_ind				*h_bicc_reset_ind;
	f_bicc_reset_cnf				*h_bicc_reset_cnf;
	f_bicc_apm_ind					*h_bicc_apm_ind;
	f_bicc_reattempt_ind			*h_bicc_reattempt_ind;
	f_bicc_failure_ind				*h_bicc_failure_ind;

}BICC_EventHandle_struct;

typedef struct _bicc_sap_attrib_
{
	BICC_EventHandle_struct event_handle;
}bicc_sap_sttrib_;

typedef enum _BICC_network_id
{
	SI_INTERNATIONAL            =          0,
	SI_INTERNATIONAL_SPARE      =          1,
	SI_NATIONAL				 	=          2,
	SI_NATIONAL_SPARE			=          3,
	
}SI_Netwrok_ID;

typedef struct bicc_cic_state
{
	u8 					call_state;
	u8					sus_state;		//suspend state, remote hold? local hold?
	u8					blo_state;		//block state, remote block? local hold?
}BICC_CIC_state;

typedef struct bicc_fsm_state
{
	u8					cpc_state;
	u8					mgbs_state;
	u8					mgbr_state;
	u8					crs_state;
	u8					crr_state;
	u8					cgrs_state;
	u8					cgrr_state;
}BICC_Fsm_state;

typedef struct bicc_port_struct
{
	u8					used_flag;
	u8					trace_flag;
	u32					w_time;
	u32					su_proc_id;
	u8					sprc_cmd;
	u8					primitive_cmd;
	u8					internal_cmd;
	BICC_Fsm_state		fsm_state;
	BICC_CIC_state		cic_state;
	up_message_2		s_mtp_msg;                        //message send to mtp3
}BICC_Port_struct;

extern up_message_2			r_mtp_msg; 			//message receive from mtp3

typedef struct BiccDmp_struct {
	// If DMP is active, circuit 0-127 is according to proccessor 0, circuit 128-255 is accroding to proccessor 1 //
	u8			active;
	u8			processor_id;
	u32			remote_ip;
} BiccDmp_struct;


/**********************
***upper layer interface***
***********************
*/

extern int BICC_con_req(Pst *pst, BiccSetup_Req *ptr);	//iam				//Connection establishment request
extern int BICC_con_rsp(Pst *pst, BiccSetup_Rsp *ptr);	//anm,con				//Connection establishment response
extern int BICC_rel_req(Pst *pst, BiccRel_Req *ptr);						//Release request
extern int BICC_rel_rsp(Pst *pst, BiccRel_Rsp *ptr);						//Release response
extern int BICC_alert_req(Pst *pst, BiccAlert_Req *ptr);				//alert
extern int BICC_info_req(Pst *pst, BiccInfo_Req *ptr);					//sam
extern int BICC_prog_req(Pst *pst, BiccCpg_Req *ptr);					//progress
extern int BICC_apm_req(Pst *pst, BiccApm_Req *ptr);
extern int BICC_sus_req(Pst *pst, BiccSus_Req *ptr);						//Call suspend request
extern int BICC_resm_req(Pst *pst, BiccRes_Req *ptr);						//Call resume request
extern int BICC_block_req(Pst *pst, BiccCgb_Req *ptr);														//block req
extern int BICC_block_rsp(Pst *pst, BiccCgb_Req *ptr);
extern int BICC_unblock_req(Pst *pst, BiccCgb_Req *ptr);														//unblock req
extern int BICC_unblock_rsp(Pst *pst, BiccCgb_Req *ptr);
extern int BICC_reset_req(Pst *pst, BiccGrs_Req *ptr);
extern int BICC_reset_rsp(Pst *pst, BiccGrs_Rsp *ptr);															//reset response

extern void BICC_EMPTY_OPTPAR(void *ptr, u8 prim);

extern BOOL bicc_trunk_reachable(u32 cg_id);
/*****************************
*** layer management interface***
******************************
*/

int BICC_active_dmp(u8 plat_id, u32 alter_id );
int BICC_deactive_dmp();

/***********************
*** lower layer interface***
************************
*/
void BICC_msdc_proc(u32 pid, up_message_2 *upmsg_ptr);
int BICC_mdsc_proc();

/******************************
*** system service interface***
*******************************
*/

void BICC_init(int interval_ms, int local_id);
void BICC_timer();

#endif

