#ifndef _PAL_H_
#define _PAL_H_

#include "../public/src/include/public.h"

#define PROTO_AIF			0
#define PROTO_ISUP			1
#define PROTO_BICC			2
#define PROTO_ISDN			3
#define PROTO_TUP			4
#define PROTO_SIP			5
#define PROTO_MGC			6
#define MAX_PROTO_TYPE		7

#define VARIANT_ITU 		0
#define VARIANT_ANSI		1
#define VARIANT_ETSI		2
#define VARIANT_UK			3
#define VARIANT_QSIG		4

#define DUAL_SEIZURE_REATTEMPT	0 /* Re-attempt on detection of dual seizure */
#define DUAL_SEIZURE_CONTINUE	1 /* Continue the call on detection of dual seizure */

#define CTRL_PLAT_0			0
#define CTRL_PLAT_1			1

#define PAL_MAX_CALLBACK	64
#define PAL_MAX_SAP		16
#define PAL_MAX_CG			256
#define PAL_MAX_CIRCUIT	256
#define PAL_DOMAIN_LEN		32

typedef struct sap_attribute {
	void *event_handle[PAL_MAX_CALLBACK];
} sap_attrib_struct;

/*  Non-Facility Associated Signalling  */
struct nfas_info {
	u8 flag;
	u32 prim_link;
	u32 backup_link;
};

typedef struct cg_attribute {
	u8 protocol;
	u8 variant;
	u8 priority;		//0: re-attempt; 1: continue
	u8 network_id;
	u32 dpc;
	u32 opc;
	char dest_domain[PAL_DOMAIN_LEN];	//for sip
	char local_domain[PAL_DOMAIN_LEN];	//for sip
	struct nfas_info nfas;
	u32 tg_id;
} cg_attrib_struct;

typedef struct circuit_attribute {
	u8 plat_id;
	u8 cic_range;
	u32 head_cic;
	u32 link_id;			//for isdn
	u8 user_network_if;	//for isdn
	u8 d_chnl;			//for isdn
} circuit_attrib_struct;

typedef struct pal_sap {
	u8 id;
	u8 enable;
	sap_attrib_struct attrib;
} pal_sap_struct;

typedef struct pal_circuitgroup {
	u8 id;
	u8 enable;
	u8 sap_id;
	u8 circuit_num;
	cg_attrib_struct attrib;
} pal_cg_struct;

typedef struct pal_circuit {
	u8 id;
	u8 enable;
	u8 cg_id;
	circuit_attrib_struct attrib;
} pal_circuit_struct;

typedef struct _pst_struct
{
	u16 cg_id;
	u32 tg_id;
	u32 cic;

	u32 sp_proc_id;
	u32 su_proc_id;
	
	int trace_flag;
} Pst;

/* Upper layer interface */
extern u8 *pal_version(void);
extern char* pal_error(void);
extern int pal_bind_sap(sap_attrib_struct *attrib);
extern int pal_create_cg(u8 sap_id, cg_attrib_struct *attrib);
extern int pal_delete_cg(int cg_id);
extern int pal_modify_cg(int cg_id, cg_attrib_struct *attrib);
extern int pal_create_circuit(int cg_id, circuit_attrib_struct *attrib);
extern int pal_delete_circuit(int circuit_id);

/* Lower layer interface */
extern void *pal_get_handler(u32 cg_id);
extern const pal_sap_struct *pal_sap_ptr(u8 sap_id);
extern const pal_cg_struct *pal_cg_ptr(u32 cg_id);
extern const pal_circuit_struct *pal_circuit_ptr(u32 circuit_id);
extern const pal_cg_struct *pal_ss7_find_cg(u8 ni, u32 dpc, u32 opc);
extern const pal_cg_struct *pal_isdn_find_cg(u32 link_id);
extern const pal_cg_struct *pal_sip_find_cg(char *domain, char *their_domain);
extern const pal_circuit_struct *pal_locate_circuit(u32 cg_id, u32 cic);
extern const pal_circuit_struct *pal_ss7_find_circuit(u8 ni, u32 dpc, u32 opc, u32 cic);
extern const pal_circuit_struct *pal_isdn_find_circuit(u32 link_id, u32 cic);
extern const pal_circuit_struct *pal_isdn_find_circuit_of_link(u32 link_id);

#endif

