#include "../../../iptrans/src/include/iptrans.h"
#ifdef _INCLUDE_M2UA
	#include "../../../m2ua/src/include/m2ua.h"
#endif
#ifndef _MTP3_HEAD_FILE
#define _MTP3_HEAD_FILE

#define _up_message		up_message
#define MAX_SS7_MSG_LEN	272

typedef	struct up_message{
	long    dest_ip;
	long	dpc;
	long	opc;
	BYTE	cic[2];
	BYTE	link;
	BYTE	sio;
//	BYTE	len;/* len not include itself */
	WORD len;//long message
	BYTE	msgList[MAX_SS7_MSG_LEN];
}up_message;

typedef	struct up_message_2{
	long    dest_ip;
	long	dpc;
	long	opc;
	BYTE	cic[4];
	BYTE	link;
	BYTE	sio;	// 13 for BICC
//	BYTE	len;/* len not include itself */
	WORD len;//long message
	BYTE	msgList[MAX_SS7_MSG_LEN];
}up_message_2;

typedef struct up_buffer /* user part buffer. user part:telephone user part,
			    isdn user part, and sccp part */
{
    BYTE         RSub;      /* subscript of array msgList for reader */
    BYTE         WSub;     /* subscript of array msgList for writer */
    up_message	 msgNum[256];/* this buffer can storge up to 256 
					   messages */
}up_buffer;

typedef struct up_buffer_2 /* user part buffer. user part:telephone user part,
			    isdn user part, and sccp part */
{
    BYTE         RSub;      /* subscript of array msgList for reader */
    BYTE         WSub;     /* subscript of array msgList for writer */
    up_message_2 msgNum[256];/* this buffer can storge up to 256 
					   messages */
}up_buffer_2;

#define _tup_shm   tup_shm
typedef struct tup_shm {
    up_buffer     	TM_Buf;
    up_buffer     	MT_Buf;
} tup_shm;

#define _isup_shm   isup_shm
typedef struct isup_shm {
    up_buffer      	IM_Buf;
    up_buffer      	MI_Buf;
} isup_shm;

#define _bicc_shm   bicc_shm
typedef struct bicc_shm {
    up_buffer_2    	IM_Buf;
    up_buffer_2    	MI_Buf;
} bicc_shm;

#define _sccp_shm   sccp_shm
typedef struct sccp_shm {
    up_buffer      	SM_Buf;
    up_buffer      	MS_Buf;
} sccp_shm;

typedef struct iprt1
{
	BYTE			pad[20]			__attribute__((packed));
	message_list 	io_msg			__attribute__((packed));
}iprt1;

typedef struct mtp_primitive
{
	long	pc;
	BYTE	nw_indicator;
	BYTE	availability;
}mtp_primitive;

typedef struct primitive_to_tup
{
	mtp_primitive	primitive[16];
	BYTE	WSub;
	BYTE	RSub;
}primitive_to_tup;

typedef struct primitive_to_isup
{
	mtp_primitive	primitive[16];
	BYTE	WSub;
	BYTE	RSub;
}primitive_to_isup;

typedef struct primitive_to_bicc
{
	mtp_primitive	primitive[16];
	BYTE	WSub;
	BYTE	RSub;
}primitive_to_bicc;

typedef struct primitive_to_sccp
{
	mtp_primitive	primitive[16];
	BYTE	WSub;
	BYTE	RSub;
}primitive_to_sccp;

typedef struct mtp3_routing_result
{
	BYTE	tupMsgOutLink[256];
	BYTE	isupMsgOutLink[256];
	BYTE	biccMsgOutLink[256];
	BYTE	sccpMsgOutLink[256];
}mtp3_routing_result;

#define MTP3DB_CMD		0
#define MTP3DB_SNMMSG		1
#define MTP3DB_SCCPMSG		2
#define MTP3DB_TUPMSG		3
#define MTP3DB_ISUPMSG		4
#define MTP3DB_ERROR		5
#define MTP3DB_EVENT		6
#define MTP3DB_ALLLKON		7
#define MTP3DB_PFHB			8// platform heartbeat
#define MTP3DB_APP_APP_MSG	9// msg from app to app
#define MTP3DB_PRIMITIVE_MSG 10// msg from MTP3 to MTP2
#define MTP3DB_BICCMSG		11

void mtp_shm_init(WORD moduleid_systemid);
//moduleid = 8/9/11 vss/mss/aas
//void iptrans_init();
void mtp3_proc();
int tup_to_mtp3(up_message *msgptr);
int isup_to_mtp3(up_message *msgptr);
int bicc_to_mtp3(up_message_2 *msgptr);
int sccp_to_mtp3(up_message *msgptr);
int sccp_redirect(up_message *msgptr);
int bicc_redirect(up_message_2 *msgptr);
int isup_redirect(up_message *msgptr);
int tup_GetMsg(up_message *msgptr);
int isup_GetMsg(up_message *msgptr);
int bicc_GetMsg(up_message_2 *msgptr);
int sccp_GetMsg(up_message *msgptr);
int	sccp_get_SPstate(mtp_primitive *ptr);
int	isup_get_SPstate(mtp_primitive *ptr);
int	bicc_get_SPstate(mtp_primitive *ptr);
int	tup_get_SPstate(mtp_primitive *ptr);
BYTE *spc_to_acn(BYTE netID,DWORD spc);
BYTE mtp3_ansiFlag(BYTE netID);
BYTE *check_MTP3LinkType();
BYTE *check_MTP3LinkL2State();
void MTP3_activate(DWORD ip);
void MTP3_deactivate(DWORD ip);
void MTP3_Enable_SubSystem(BYTE SubSystem);
void MTP3_Disable_SubSystem(BYTE SubSystem);
void mtp3_init_serial(char *Serial);
int mtp3_create_opc(BYTE nw, DWORD opc);
int mtp3_delete_opc(BYTE nw, DWORD opc);
int check_m3ua_rc_verify(DWORD rc);

#endif
