#ifndef _MGCP__H
#define _MGCP__H

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

#define MGCP_RET_CODE_TEMP_RSP		100
#define MGCP_RET_CODE_TEMP_RSP_DESC	"temp response"

#define MGCP_RET_CODE_TRANS_OK		200
#define MGCP_RET_CODE_TRANS_OK_DESC	"OK"

#define MGCP_RET_CODE_TRANS_TIME_OUT		406
#define MGCP_RET_CODE_TRANS_TIME_OUT_DESC	"transaction time out"

#define MGCP_RET_CODE_INTERNAL_OVERLOAD		409
#define MGCP_RET_CODE_INTERNAL_OVERLOAD_DESC	"internal overload"

#define MGCP_RET_CODE_UNEP		500
#define MGCP_RET_CODE_UNEP_DESC	"endpoint unknow"

#define MGCP_RET_CODE_UNCMD		504
#define MGCP_RET_CODE_UNCMD_DESC	"unknow or unsupport command"

#define MGCP_RET_CODE_RCD_ERR		509
#define MGCP_RET_CODE_RCD_ERR_DESC	"remoto connection descriptor error"

#define MGCP_RET_CODE_INCONID		515
#define MGCP_RET_CODE_INCONID_DESC	"incorrect connect id"

#define MGCP_RET_CODE_UNCLLID		516
#define MGCP_RET_CODE_UNCLLID_DESC	"unknow call id"

#define MGCP_RET_CODE_UNMD		517
#define MGCP_RET_CODE_UNMD_DESC	"unsupported or invalid mode"

#define MGCP_RET_CODE_UNPKG		518
#define MGCP_RET_CODE_UNPKG_DESC	"unsupported or unknow package"

#define MGCP_RET_CODE_NES		522
#define MGCP_RET_CODE_NES_DESC	"no such event or signal"

#define MGCP_RET_CODE_ILCO		524
#define MGCP_RET_CODE_ILCO_DESC	"internal inconsistency in LocalConnectionOption"

#define MGCP_RET_CODE_UNRM		526
#define MGCP_RET_CODE_UNRM_DESC	"unknow or unsupported RestartMethod" 

#define MGCP_MAX_NUM_OF_SAP		1
#define MGCP_MAX_NUM_OF_PORT	8192

#define MGCP_MAX_USER_NAME_LEN	16
#define MGCP_MAX_MG_NAME_LEN	32
#define MGCP_MAX_DOMAIN_LEN		64

#define MGCP_COMMAND			1
#define MGCP_RESPONSE			2

#define MGCP_CMD_CRCX			1
#define MGCP_CMD_MDCX			2
#define MGCP_CMD_DLCX			3
#define MGCP_CMD_RQNT			4
#define MGCP_CMD_NTFY			5
#define MGCP_CMD_AUEP			6
#define MGCP_CMD_RSIP			7

#define MGCP_EP_NAME_STRUCTURED		1
#define MGCP_EP_NAME_UNSTRUCTURED	2
#define MGCP_EP_NAME_CHNL_WILDCAST	0xFFFF
#define MGCP_EP_NAME_TRK_WILDCAST	0xFF

#define MGCP_MG_TYPE_AudioCoder 	1
#define MGCP_MG_TYPE_LGC_MG         2
#define MGCP_MG_TYPE_SSW_CSS        3
#define MGCP_MG_TYPE_ANALOG         11
#define MGCP_MG_TYPE_ANN			21

#define MGCP_PORT_TYPE_E1				1
#define MGCP_PORT_TYPE_T1				2
#define MGCP_PORT_TYPE_AALN			3

#define MGCP_CON_MODE_INACTIVE		0
#define MGCP_CON_MODE_RECVONLY		1
#define MGCP_CON_MODE_SENDONLY		2
#define MGCP_CON_MODE_SENDRECV		3

#define MGCP_RST_MODE_RESTART		    0
#define MGCP_RST_MODE_FORCED		    1
#define MGCP_RST_MODE_DISCONNECTED      2
#define MGCP_RST_MODE_GRACEFUL          3
#define MGCP_RST_MODE_CANCEL_GRACEFUL   4 

#define MGCP_PKG_L	0
#define MGCP_PKG_D	1
#define MGCP_PKG_G	2

#define MGCP_SIG_DL		1
#define MGCP_SIG_BZ		2
#define MGCP_SIG_RT		3
#define MGCP_SIG_WT		4

#define MGCP_L_SIG_AW		1
#define MGCP_L_SIG_DL		2
#define MGCP_L_SIG_BZ		3
#define MGCP_L_SIG_WT		4
#define MGCP_L_SIG_NBZ		5
#define MGCP_L_SIG_RG		6
#define MGCP_L_SIG_E		7
#define MGCP_L_SIG_OT		8

#define MGCP_D_SIG_ONE		1
#define MGCP_D_SIG_TWO		2
#define MGCP_D_SIG_THREE    3
#define MGCP_D_SIG_FOUR		4
#define MGCP_D_SIG_FIVE		5
#define MGCP_D_SIG_SIX		6
#define MGCP_D_SIG_SEVEN	7
#define MGCP_D_SIG_EIGHT    8
#define MGCP_D_SIG_NINE 	9
#define MGCP_D_SIG_ZERO		10
#define MGCP_D_SIG_STAR		11
#define MGCP_D_SIG_POUND	12
#define MGCP_D_SIG_WILD	    13

#define MGCP_G_SIG_RT        1
#define MGCP_G_SIG_CF        2
#define MGCP_G_SIG_CG        3
#define MGCP_G_SIG_IT        4
#define MGCP_G_SIG_PT        5


#define MGCP_OBDENT_ZERO	0
#define MGCP_OBDENT_HU		1
#define MGCP_OBDENT_HD		2

#define MGCP_L_EVENT_HD		1
#define MGCP_L_EVENT_HU		2
#define MGCP_L_EVENT_HF		3
#define MGCP_L_EVENT_AW		4
#define MGCP_L_EVENT_NBZ	5
#define MGCP_L_EVENT_E		6
#define MGCP_L_EVENT_OC 	7
#define MGCP_L_EVENT_OF		8

#define MGCP_D_EVENT_ONE		1
#define MGCP_D_EVENT_TWO		2
#define MGCP_D_EVENT_THREE		3
#define MGCP_D_EVENT_FOUR		4
#define MGCP_D_EVENT_FIVE		5
#define MGCP_D_EVENT_SIX	 	6
#define MGCP_D_EVENT_SEVEN		7
#define MGCP_D_EVENT_EIGHT		8
#define MGCP_D_EVENT_NINE		9
#define MGCP_D_EVENT_ZERO	  	10
#define MGCP_D_EVENT_STAR		11
#define MGCP_D_EVENT_POUND	 	12




#define MGCP_G_EVENT_MT		1
#define MGCP_G_EVENT_FT		2
#define MGCP_G_EVENT_LD	 	3
#define MGCP_G_EVENT_OF		4

#define MGCP_PACKAGE_MAX			3
#define MGCP_PACKAGE_AALN			0
#define MGCP_PACKAGE_SIG_NONE		0

#define MGCP_PKG_AALN_SIG_MAX		18

#define MGCP_OBD_ENT_MAX   3
#define MGCP_ENT_MAX     18

#define MGCP_REST_MOD_MAX  5

#define MGCP_PARA_FLAG_SL		0x00000001
#define MGCP_PARA_FLAG_C		0x00000002
#define MGCP_PARA_FLAG_I		0x00000004
#define MGCP_PARA_FLAG_L		0x00000008
#define MGCP_PARA_FLAG_M		0x00000010
#define MGCP_PARA_FLAG_S		0x00000020
#define MGCP_PARA_FLAG_RM		0x00000040
#define MGCP_PARA_FLAG_RD		0x00000080
#define MGCP_PARA_FLAG_R		0x00000100
#define MGCP_PARA_FLAG_O		0x00000200
#define MGCP_PARA_FLAG_SDP		0x00000400
#define MGCP_PARA_FLAG_TFO      0x00000800

#define	MGCP_PARA_L_FLAG_ESS_CCI    0x00000001
#define	MGCP_PARA_L_FLAG_ESS_CCD    0x00000002

typedef	struct _MGCP_ESCCD
{
	char		domain[MGCP_MAX_DOMAIN_LEN];
	WORD	port;
}MGCP_ESCCD;

typedef struct _MGCP_SL
{
	BYTE		cmdRes;							// command or response
	
	DWORD		transId;						// transaction ID for command received
	
	BYTE		epNameMethod;					// structured/unstructured
	BYTE		mgType;							// Non-Virtual/ANN
	BYTE		portType;           			// E1/T1/Analog
	BYTE		trkNum;							// trunk number
	WORD		chlNum;							// channel number
	char		mgName[MGCP_MAX_MG_NAME_LEN];
	
	WORD		retCode;						// return code, for response message only
	char		desc[64];						// descriptions
}MGCP_SL;

typedef struct _MGCP_C
{
	char		callId[33];						// max 32 hexadecimal digits
}MGCP_C;

typedef struct _MGCP_I
{
	char		conId[33];						// max 32 hexadecimal digits
}MGCP_I;

typedef struct _MGCP_L
{
	BYTE			flag;
	BYTE		p;								// packetization period in ms
	char		codec[16];						// PCMA/PCMU/EVRC/QCELP
	char			esCci[32];
	MGCP_ESCCD		esCcd;
	BYTE		ecDisable;						// echo canceller enable or disable
	BYTE		ssDisable;						// silence suppression enable or disable
}MGCP_L;

typedef struct _MGCP_M
{
	BYTE		mode;							// inactive/recvonly/sendonly/sendrecv
}MGCP_M;

typedef struct _MGCP_S
{
	BYTE		pkg;							// package id
	BYTE		signal;							// signal id
	char		reqId[32];
}MGCP_S;

typedef struct _MGCP_RM
{
	BYTE		rm;								// restart mode, restart/forced
}MGCP_RM;

typedef struct _MGCP_RD
{
	WORD		rd;								// restart delay, no delay/delay time
}MGCP_RD;

typedef struct _MGCP_R
{
	BYTE		pkg;							// package id
	BYTE		event;							// signal id
	char		reqId[32];
}MGCP_R;

typedef struct _MGCP_O
{
	BYTE		package;						// package id
	BYTE		event;							// event id
    char        reqId[32];	
}MGCP_O;

typedef struct _MGCP_PARA
{
	DWORD		ip;
	WORD		localPort;
	WORD		peerPort;
	
	DWORD		flag;
	
	MGCP_SL		sl;
	MGCP_C		c;
	MGCP_I		i;
	MGCP_L		l;
	MGCP_M		m;
	MGCP_S		s;
	MGCP_RM		rm;
	MGCP_RD		rd;
	MGCP_R		r;
	MGCP_O		o;
	
	PUB_SDP_MSG	sdp;
}MGCP_PARA;	

typedef struct _MGCP_SAP
{
	char	name[MGCP_MAX_USER_NAME_LEN];	// User name
	
	//  The MGCP module sends a indication to its user when it receives a 
	//	MGCP CRCX/MDCX/DLCX/RQNT/NTFY/AUEP/RSIP command message
	int 	(*MGCP_ind)(BYTE cmd, WORD *usrPort, WORD hdlPort, MGCP_PARA *para);
	
	// 	The MGCP module sends this failure/success return code to the user
	int  	(*MGCP_cnf)(BYTE cmd, WORD usrPort, WORD hdlPort, WORD retCode, MGCP_PARA *para);
}MGCP_SAP;

int mgcp_bind(MGCP_SAP *sap);
int MGCP_req(BYTE sapIndex, BYTE cmd, WORD usrPort, MGCP_PARA *para);
int MGCP_rsp(BYTE sapIndex, BYTE cmd, WORD usrPort, WORD hdlPort, WORD retCode, MGCP_PARA *para);

#endif
