/*	XAP provider head file				*/
/*	Written by Liu Zhiguo 2003-08-26	*/
/*	Version 1.0							*/
/*	--------------------------------	*/

#include "../../public/src/include/includes.h"
#include "../../public/src/include/pub_fmt.h"
#include "../../sccp/src/include/sccp.h"
#include "../../tcap/src/include/tcap_head.h"
#include "../../tcap/src/include/tcap_public.h"
#include "../../tcap/src/include/tcap_struct.h"
#include "ixap.h"
#include "mapp/map_const.h"
#include "mapp/map_public.h"
#include "mapp/map_code.h"
#include "mapp/map_coding.h"
#include "mapp/is41_code.h"
#include "mapp/map_struct.h"
#include "mapp/map_acn.h"
#include "mapp/map_dlgpdu.h"

#ifndef _PROVIDER_H
#define _PROVIDER_H

#define XAP_MAP_SSN					1		// ssn is used for map
#define XAP_CAP_SSN					2		// ssn is used for cap
#define XAP_IS41_SSN				3		// ssn is used for is41

#define XAP_VM_KEY					0xa0e00000
#define XAP_VM_PERM					0664
#define XAP_INTER_KEY				0xa0f00000
#define XAP_INTER_PERM				0664

#define MAX_XAP_SSN					16
#define XAP_OPEN_LEN				128
#define XAP_ACN_LEN					7		// xap acn length
#define XAP_ACN_NUM					50		// acn buffer length
#define XAP_OPR_NUM					80		// operation length

#define XAP_ASCIN_LEN				1024
#define XAP_ASCOUT_LEN				4096
#define XAP_WTDOG_LEN				256

#define XAP_INIT					0x00
#define XAP_IDLE					0x01
#define XAP_WFUR					0x02	// wait for user requests
#define XAP_WFCBI					0x03	// wait for check begin indicate
#define XAP_DLG_INITIATED			0x05
#define XAP_DLG_PENDING				0x04	// dialogue pending
#define XAP_DLG_ACCEPTED			0x06
#define XAP_DLG_ESTABLISHED			0x07
#define XAP_DLG_SUSPEND				0x08
#define XAP_DLG_HALT				0x09

/*	the state of SSM	*/
#define SSM_IDLE					0x00
#define SSM_WFRESPONSE				0x01	// wait for response
#define SSM_WFCONFIRM				0x02

/*	the flag of requesting map SSM	*/
#define SERVICE_INVOKED				0x01
#define RESULT_RECEIVED				0x02
#define PARTIAL_RESULT_RECEIVED		0x03
#define NEGATIVE_RESULT_RECEIVED	0x04
#define LINKED_REQUEST_RECEIVED		0x05
#define LINKED_SERVICE_INVOKED		0x06
#define USER_REJECT_RECEIVED		0x07
#define PROVIDER_REJECT_RECEIVED	0x08
#define TIMER_EXPIRY				0x09
#define TERMINATED					0x0a

/*	the flag of performing map SSM	*/
#define	SERVICE_INVOCATION_RECEIVED	0x01
#define RESPONSE_ISSUED				0x02
#define GUARD_TIMER					0x03

#define SUSPEND_TIME				1
#define DLGPEND_TIME				180
#define XAPP_TIMERHZ				100

#define XAPP_PRIVATE_TCAP			1
#define	XAPP_OPER_FAMILY			9

typedef struct	xap_acn_info		// store info about application context name
{
	u8		buf_len;
	u8		acn[XAP_ACN_NUM];		// acn buffer
	u8		acn_ver[XAP_ACN_NUM];	// acn version buffer
}	xap_acn_info;

typedef struct	xap_opr_info		// store info about opration code
{
	u8		buf_len;
	u8		opr_code[XAP_OPR_NUM];		// operation code buffer
	u8		opr_class[XAP_OPR_NUM];		// operation class buffer
	u32		opr_timer[XAP_OPR_NUM];		// operation timer buffer
}	xap_opr_info;


typedef struct	xap_inter_struct	// xap interface structure
{
	u8		mcc[2];
	u8		mnc0;
	u8		cc[2];
	u8		ndc[3];
	u8		inter_prefix[2];
	u8		national_prefix[2];
	u8		local_prefix[2];
	u8		mnc[2];//expend mnc from 1 byte to 2 bytes

/* mscid is special use for CDMA */
	u8		mscidToNum[256][14];
/* mscid is special use for CDMA */
	
	// define for the ssn control
	u8		regssn_len;
	u8		reg_ssn[MAX_XAP_SSN];
	u8		regssn_flag[MAX_XAP_SSN];	// indicate if the register SSN is MAP or CAP ssn
	u8		open_head[MAX_XAP_SSN];
	u8		open_tail[MAX_XAP_SSN];
	u32		open_did[MAX_XAP_SSN][XAP_OPEN_LEN];
}	xap_inter_struct;

typedef struct	xap_debug_struct
{
	char	*start_time;			// time of module start
	u32		monitor_did;			// the dialogue id for monitored
	u8		error_switch;
	u8		map_switch;
	u8		cap_switch;
	u8		send_control;			// control if can send xap message
	u8		ascin_buf[XAP_ASCIN_LEN];
	u8		ascout_buf[XAP_ASCOUT_LEN];
	u32		watch_dog[XAP_WTDOG_LEN];
}	xap_debug_struct;

typedef struct psmvm_data	// xap provider state machine data
{
	u8		xap_flag;		// 0: empty; 1: map primitive; 2: cap primitive
	u8		psm_state;
	u8		sub_state1;
	u8		delimiter_flag;
	u8		acn;
	u8		acn_ver;
	u8		msg_type;
	u8		msg_flag;
	u32		port_id;
	u32		suspend_timer;
	u8		data_count;
	u8    recv_bsa_count;
	u8		opr_state[MAX_INVOKEID];
	u8		opr_code[MAX_INVOKEID];
	u8		opr_class[MAX_INVOKEID];
}	psmvm_data;

typedef struct xapp_vm_data		// XAP provider virtue machine structure
{
	struct	psmvm_data			psm_data;
	u8		recvcom_flag; // USER=>XAPP 
	u8		recvopr_flag;	// USER=>XAPP 0: has not data 1: has data 2: has partial data
	u8		sendcom_flag; // XAPP=>USER
	u8		sendopr_flag; // XAPP=>USER
	u32		recvopr_site;	// USER=>XAPP 0: has not data 1: has data 2: has partial data
	struct	MapComSrv_struct	recvcom_data;
	struct	MapOprData_struct	recvopr_data;
	struct	MapComSrv_struct	sendcom_data;
	struct	MapOprData_struct	sendopr_data;
	struct	CSLdlg_struct		tcap_data;
	struct	MapDlg_struct		map_dlg;
} xapp_vm_data;

typedef struct xap_vm_struct
{
	int     grantdid;
	struct	xapp_vm_data		xap_data[MAX_DIALOGUEID];
	struct	xap_debug_struct	debug_data;
}	xap_vm_struct;

struct	xap_vm_struct		*xap_vm_ptr;
struct	xap_inter_struct	*xap_inter_ptr;

#endif
