/***************************************
*        Author:     Zane Yi           
*        Date:       2007.02.01        
***************************************/

#include "./include/isup_debug.h"
#include "./include/isup_public.h"
#include "./include/isup_if.h"
#include "./include/isup_struct.h"
#include "./include/isup_def.h"
#include "./include/isup_const.h"


#define DEBUG_ID	22
#define	VER_DEBUG	"R9V0_04"
#define	IS_PATCH	3



#define	PAGE_NUM	5
#define	MONITOR_NONE				0x0000
#define	MONITOR_ERROR				0x0002
#define	MONITOR_MSG					0x0004
#define	MONITOR_FUNC				0x0008
#define	MONITOR_STATE				0x8000
#define	MONITOR_ALL					0x7fff

u8	isup_msg_test=0;

static ISUP_Msg_Csta isup_csta;
static BYTE		AsciInBuf[4096];
static BYTE		AsciOutBuf[4096];
static BYTE		AsciTempBuf[4096];
static WORD		MonitorFg;
static int debug_dpc,debug_opc,debug_ni;


static BYTE	log_help[] = {
	"ISUP Debug Monitor Help:\n\r\
	\n\r\
	1.[help]                                    display help menu\n\r\
	2.[log all/none]                            display all/none logs\n\r\
	3.[log error on/off]                        display error logs \n\r\
	3.[log state on/off]                        display state logs \n\r\
	4.[list cg]                                 display all cg \n\r\
	5.[list cg-x]                               display cg  \n\r\
	6.[list circuit-x]                          display circuit->port  \n\r\n\r\
	7.[list port-x] 	                          display port->port  \n\r\n\r"
};

static	WORD	disp_page[10];
static	BYTE	*disp_ptr = (BYTE *) disp_page;

static 	DWORD	debug_status_id[20] = 
{
	1,3,6,1,4,1,1373,1,1,2,3,1,2,DEBUG_ID + 2,1
};

static	BYTE 	debug_status = 1;

static DWORD	debug_name_id[20] = 
{
	1,3,6,1,4,1,1373,1,1,2,3,1,2,DEBUG_ID + 2,2
};

static DWORD	debug_ascin_id[20] = 
{
	1,3,6,1,4,1,1373,1,1,2,3,1,2,DEBUG_ID + 2,3
};

static DWORD	debug_ascout_id[20] = 
{
	1,3,6,1,4,1,1373,1,1,2,3,1,2,DEBUG_ID + 2,4
};

static	DWORD	debug_page_title[20] = 		
{
	1,3,6,1,4,1,1373,1,1,2,3,1,2,DEBUG_ID + 2,1,1
};

static	DWORD	debug_page_line[20] = 		
{
	1,3,6,1,4,1,1373,1,1,2,3,1,2,DEBUG_ID + 2,1,2,1
};

const static BYTE	BASE_ID_LEN = 15;
const static BYTE	PAGE_POINT 	= 14;
const static BYTE  	LINE_POINT 	= 15;

static BYTE	title1_p[] = 
{
	"    ISUP    Page 01    SAP Info\n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
Subpage\n\r\
Enable\n\r\
SystemID\n\r\
Run mode\n\r\
Remote IP\n\r"
};

static BYTE	title2_p[] = 
{
	"    ISUP    Page 02    CG      Info\n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
Subpage\n\r\
Enable\n\r\
SAP_ID\n\r\
Variant\n\r\
Priority\n\r\
NI\n\r\
DPC\n\r\
OPC\n\r\
TG_ID\n\r"
};

static BYTE	title3_p[] = 
{
	"    ISUP    Page 03    CIC Info\n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
Subpage\n\r\
CG_ID\n\r\
PLAT_ID\n\r\
CIC RANGE\n\r\
HEAD CIC\n\r"
};

static BYTE	title4_p[] = 
{
	"    ISUP    Page 04    Port Info\n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
Subpage\n\r\
Enable\n\r\
Fsm_state\n\r\
CIC_state\n\r\
SU_port\n\r\
Timer_F\n\r\
Time_W\n\r"
};

static BYTE	title5_p[] = 
{
	"    ISUP    Page 05    Csta Info\n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
RV-IAM\n\r\
SD-IAM\n\r\
RV-ACM\n\r\
SD-ACM\n\r\
RV-REL\n\r\
SD-REL\n\r\
RV-RLC\n\r\
SD-RLC\n\r"
};


static void debug_setcol(int color);
static void debug_cancelcol();

static void isup_asciout_proc(const char *fmt, ...)
{
	va_list		ap;
	char		buf[4096];

	va_start(ap, fmt);
	vsprintf(buf, fmt, ap);
	if((strlen(AsciOutBuf) + strlen(buf)) < 4096)
		strcat(AsciOutBuf, buf);
	else
		strcpy(AsciOutBuf, buf);
	va_end(ap);
}


static void	list_cg(u16 cg_id)
{
	const pal_cg_struct* cg_str;				
		
	cg_str = pal_cg_ptr(cg_id);		
	if(cg_str == NULL) 
		return;
		
	isup_asciout_proc("\r\n\
	#ISUP  CG   Info\r\n\
		cg_id=%d\r\n\
		sap_id=%d\r\n\
		Attrib->\r\n\
		variant_type(%d)\r\n\
		priority(%d)\r\n\
		network_id(%d)\r\n\
		dpc(%d)\r\n\
		opc(%d)\r\n\
		tg_id(%d)\r\n\
	-------------------\r\n",
	cg_id,
	cg_str->sap_id,
	cg_str->attrib.variant,
	cg_str->attrib.priority,
	cg_str->attrib.network_id,
	cg_str->attrib.dpc,
	cg_str->attrib.opc,
	cg_str->attrib.tg_id
	);
	return;	
}
static void	list_all_cg(void)
{
	int i;
	const pal_cg_struct* cg_str;
		
	isup_asciout_proc("CgId\tSapId\tDPC\tOPC\tNI\tVariant\tPrior\tTgId\r\n");

	for(i=0;i<ISUP_MAX_CG;i++)
	{
		cg_str = pal_cg_ptr(i);
		if(cg_str == NULL)
			continue;		
    if(cg_str->enable==0)
      continue;
      
    if(cg_str->attrib.protocol!=1)//isup
    	continue;
    	
		isup_asciout_proc("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n",
			i,
			cg_str->sap_id,
			cg_str->attrib.dpc,
			cg_str->attrib.opc,
			cg_str->attrib.network_id,
			cg_str->attrib.variant,
			cg_str->attrib.priority,
			cg_str->attrib.tg_id
			);
	}
	return;	
}
static void	list_all_circuit(u16 cg_id)
{
	int i;
	const pal_circuit_struct* circuit_str;
	const pal_cg_struct* cg_str;
	
	cg_str = pal_cg_ptr(cg_id);		
	if(cg_str == NULL) 
		return;
			
	isup_asciout_proc("CgId\tSapId\tDPC\tOPC\tNI\tVariant\tPrior\tTgId\r\n");
	isup_asciout_proc("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n",
		cg_id,
		cg_str->sap_id,
		cg_str->attrib.dpc,
		cg_str->attrib.opc,
		cg_str->attrib.network_id,
		cg_str->attrib.variant,
		cg_str->attrib.priority,
		cg_str->attrib.tg_id
		);


	isup_asciout_proc("->circuit:\r\n");
	isup_asciout_proc("ID\tCgID\tPlatNo\tHeadCIC\tRange\tEnable\r\n");

	for(i=0;i<ISUP_MAX_CIRCUIT;i++)
	{
		circuit_str = pal_circuit_ptr(i);
		if(circuit_str == NULL)
			continue;		
					
		if(circuit_str->enable == 0 ||
			circuit_str->cg_id != cg_id)
			continue;
		isup_asciout_proc("%d\t%d\t%d\t%d\t%d\t%d\r\n",
			i,
			circuit_str->cg_id,
			circuit_str->attrib.plat_id,
			circuit_str->attrib.head_cic,
			circuit_str->attrib.cic_range,
			circuit_str->enable
			);
	}
	return;		

}
static void	list_all_port(u16 circuit_id)
{
	int i,cic,port;
	const pal_circuit_struct* circuit_str;
	
	circuit_str = pal_circuit_ptr(circuit_id);
	if(circuit_str == NULL)
		return;			
	
	port =  ISUP_CIRCUIT_CIC*circuit_id;
	cic	=	circuit_str->attrib.head_cic;

	isup_asciout_proc("Circuit\tCgID\tPlatNo\tHeadCIC\tRange\tEnable\r\n");
	isup_asciout_proc("%d\t%d\t%d\t%d\t%d\t%d\r\n",
		circuit_id,
		circuit_str->cg_id,
		circuit_str->attrib.plat_id,
		circuit_str->attrib.head_cic,
		circuit_str->attrib.cic_range,
		circuit_str->enable
		);

	isup_asciout_proc("->port:\r\n");
	isup_asciout_proc("CIC\tPort\tSuID\tcall\tsus\tblo\tcpc\tblr\tbls\tmgbs\tmgbr\tcrs\tcrr\tcgrs\tcgrr\r\n");

	for(i=0;i<ISUP_CIRCUIT_CIC;i++)
	{		
		isup_asciout_proc("%d\t%d\t%d(%d)\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n",
			cic,
			port,
			isup_db.port_pond[port].su_proc_id,
			isup_db.port_pond[port].sm_proc_id,
			isup_db.port_pond[port].cic_state.call_state,
			isup_db.port_pond[port].cic_state.sus_state,
			isup_db.port_pond[port].cic_state.blo_state,
			isup_db.port_pond[port].fsm_state.cpc_state,
			isup_db.port_pond[port].fsm_state.blr_state,
			isup_db.port_pond[port].fsm_state.bls_state,
			isup_db.port_pond[port].fsm_state.mgbs_state,
			isup_db.port_pond[port].fsm_state.mgbr_state,
			isup_db.port_pond[port].fsm_state.crs_state,
			isup_db.port_pond[port].fsm_state.crr_state,
			isup_db.port_pond[port].fsm_state.cgrs_state,
			isup_db.port_pond[port].fsm_state.cgrr_state);
			cic++;
			port++;			
	}
	return;
}

static void	list_circuit(u16 circuit_id)
{
	const pal_circuit_struct* circuit_str;
	
	circuit_str = pal_circuit_ptr(circuit_id);
	if(circuit_str == NULL)
		return;		
			
	isup_asciout_proc("\r\n\
	#ISUP  CIRCUIT   Info\r\n\
		circuit_id=%d\r\n\
		cg_id=%d\r\n\
		Attrib->\r\n\
		plat_id(%d)\r\n\
		head_cic(%d)\r\n\
		cic_range(%d)\r\n\
	-------------------\r\n",
	circuit_id,
	circuit_str->cg_id,
	circuit_str->attrib.plat_id,
	circuit_str->attrib.head_cic,
	circuit_str->attrib.cic_range
	);
	return;		

}

static void	list_port(u32 pid)
{	
	int circuit_id;	
	const pal_circuit_struct* circuit_str; 
		
	if(pid>=ISUP_MAX_PORT)
		return;

	circuit_id = pid/ISUP_CIRCUIT_CIC;		
	circuit_str = pal_circuit_ptr(circuit_id);
	if(circuit_str ==NULL)
		return;
	list_cg(circuit_str->cg_id);
	list_circuit(circuit_id);		
		
	isup_asciout_proc("\r\n\
	#ISUP  PORT   Info\r\n\
		pid=%d\r\n\
		su_proc_id=%d\r\n\
		sm_proc_id=%d\r\n\
		---------------\r\n\
		call_state=%d\r\n\
		sus_state=%d\r\n\
		blo_state=%d\r\n\
		---------------\r\n\
		cpc_state=%d\r\n\
		blr_state=%d\r\n\
		bls_state=%d\r\n\
		mgbs_state=%d\r\n\
		mgbr_state=%d\r\n\
		crs_state=%d\r\n\
		crr_state=%d\r\n\
		cgrs_state=%d\r\n\
		cgrr_state=%d\r\n\
	-------------------\r\n",
	pid,
	isup_db.port_pond[pid].su_proc_id,
	isup_db.port_pond[pid].sm_proc_id,
	isup_db.port_pond[pid].cic_state.call_state,
	isup_db.port_pond[pid].cic_state.sus_state,
	isup_db.port_pond[pid].cic_state.blo_state,
	isup_db.port_pond[pid].fsm_state.cpc_state,
	isup_db.port_pond[pid].fsm_state.blr_state,
	isup_db.port_pond[pid].fsm_state.bls_state,
	isup_db.port_pond[pid].fsm_state.mgbs_state,
	isup_db.port_pond[pid].fsm_state.mgbr_state,
	isup_db.port_pond[pid].fsm_state.crs_state,
	isup_db.port_pond[pid].fsm_state.crr_state,
	isup_db.port_pond[pid].fsm_state.cgrs_state,
	isup_db.port_pond[pid].fsm_state.cgrr_state
	);
	return;		

}

static int list_cic(u8 ni, u32 dpc, u32 opc, u32 cic)
{	
	int pid;
	const pal_circuit_struct* circuit_str;
	
	circuit_str = pal_ss7_find_circuit(ni, dpc, opc, cic);
	if(circuit_str == NULL)
	{
		isup_asciout_proc("illegal cic value!  ni=%d,dpc=%d,opc=%d,cic=%d\r\n",ni,opc,dpc,cic);
		return -1;
	}
	
		pid = ISUP_CIRCUIT_CIC*circuit_str->id + 
				(cic - circuit_str->attrib.head_cic);
				
		list_port(pid);
				
		return 1;


}

static void debug_setcol(int color)
{
	isup_asciout_proc("%c[%dm",COL_ESC , color);
}

static void debug_cancelcol()
{
	isup_asciout_proc("%c[m",COL_ESC);
}

static BYTE debug_disp_line(BYTE page, BYTE line)
{
	BYTE	disp_length;

	disp_length = 0;
	disp_ptr 	= (BYTE *) disp_page;

	switch (page)
	{
	case 1:	// Page 1: sap Info
		disp_length = 0;
		break;	
	case 2:	// Page 2: cg  Info
		disp_length = 0;
		break;	
	case 3:	// Page 3: circuit Info
		disp_length = 0;
		break;	
	case 4:	// Page 4: port Info
		switch(line)
		{
		case 0:
			disp_ptr 	= (BYTE *) &disp_page[page];	//Subpage
			disp_length = 2;
			break;
		case 1:											//enable				
			disp_ptr 	= (BYTE *) &(isup_db.port_pond[disp_page[page]].enable);
			disp_length = 1;
			break;
		case 2:											//fsm_state				
			disp_ptr 	= (BYTE *) &(isup_db.port_pond[disp_page[page]].fsm_state);
			disp_length = 9;
			break;
		case 3:											//cic_state				
			disp_ptr 	= (BYTE *) &(isup_db.port_pond[disp_page[page]].cic_state);
			disp_length = 3;
			break;
		case 4:											//su_proc_id				
			disp_ptr 	= (BYTE *) &(isup_db.port_pond[disp_page[page]].su_proc_id);
			disp_length = 4;
			break;
		case 5:											//timer_flag				
			disp_ptr 	= (BYTE *) &(isup_db.port_pond[disp_page[page]].timer_flag);
			disp_length = 2;
			break;
		case 6:											//w_time				
			disp_ptr 	= (BYTE *) &(isup_db.port_pond[disp_page[page]].w_time);
			disp_length = 4;
			break;
		default:
			break;
		}
		break;
	case 5:	// Page 5: csta Info
		switch(line)
		{
		case 0:
			disp_ptr 	= (BYTE *) &isup_csta.rv_iam;	
			disp_length = 4;
			break;
		case 1:										
			disp_ptr 	= (BYTE *) &isup_csta.sd_iam;	
			disp_length = 4;
			break;
		case 2:
			disp_ptr 	= (BYTE *) &isup_csta.rv_acm;	
			disp_length = 4;
			break;
		case 3:										
			disp_ptr 	= (BYTE *) &isup_csta.sd_acm;	
			disp_length = 4;
			break;
		case 4:
			disp_ptr 	= (BYTE *) &isup_csta.rv_rel;	
			disp_length = 4;
			break;
		case 5:										
			disp_ptr 	= (BYTE *) &isup_csta.sd_rel;	
			disp_length = 4;
			break;
		case 6:
			disp_ptr 	= (BYTE *) &isup_csta.rv_rlc;	
			disp_length = 4;
			break;
		case 7:										
			disp_ptr 	= (BYTE *) &isup_csta.sd_rlc;	
			disp_length = 4;
			break;			
		default:
			break;
		}
		break;
	default:
		disp_length = 0;
		break;
	}

	return disp_length;
}

static void debug_disp_page(BYTE page)
{
	BYTE	disp_line;
	BYTE	disp_length;

	debug_page_line[PAGE_POINT] = page + 5;

	for (disp_line = 0; disp_line < 22; disp_line++)
	{
		disp_length = debug_disp_line(page, disp_line);
		debug_page_line[LINE_POINT] = disp_line + 2;
		debug_page_line[LINE_POINT + 1] = 2;	// Data Pointer
		debug_set_response(BASE_ID_LEN + 2, debug_page_line, disp_ptr, disp_length);
	}
}

void test_isup_msg(u8 type, u8 flag)
{	
	/*
	int pid = 10,str_len;
	if(!isup_msg_test)
		return;
	memset(&isup_sd_pdus,0,sizeof(SiAllPdus));
	switch(type)
	{
	case M_ACM:
		{
			SiPduACM   data = {
			{1,1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1},//SiBckCalInd,SiOptBckCalInd
			{1,{1,1,1},0x0001},{1,1,1,1,1,{1}},
			{1,1,1,1,1,0},{1,1,1},{1,2,1,0},{1,1},{1,1},
			{1,1,1,1,1},{1,1},{1,1,1,1,1,3,1,2,3},
			{1,2,1,1},{1,1,1},{1,2,1,1},{1,2,1,1},{1,2,1,1},
			{1,1},{1,1,2,1,1},{1,1,1,1,1},
			{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_ANM:
		{
			SiPduANM   data = {
			{1,1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,0x0001},
			{1,1,1,1,1,0},{1,1,1},{1,1,1,1,1,1,7,1,2,3,4,5,6,7},//SiUsr2UsrInd,SiUsr2UsrInfo,SiConnectedNum
			{1,2,1,0},{1,1},{1,1},{1,3,1,1,1},{1,0x0001},
			{1,1,1,1,1,1,1,1,7,1,2,3,4,5,6,7},//SiGenNum
			{1,1},{1,2,1,1},{1,2,1,1},{1,1,1,1,1,5,1,2,3,4,5},
			{1,2,1,1},{1,2,1,3,1},{1,1},
			{1,1,2,1,1},{1,2,1,1},
			{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_CPG:
		{
			SiPduCPG   data = {
			{1,1,1},{1,1,1,1,1,1},{1,1,1,1,0x0001},
			{1,1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1},//SiBckCalInd,SiOptBckCalInd
			{1,3,1,1,1},{1,1,1,1,1,0},{1,1},{1,3,1,1,1},//SiNetSpecFacil
			{1,3,1,1,1},{1,1},{1,1},{1,1,1,1,1,5,1,2,3,4,5},//SiCdPtyNum
			{1,3,1,1,1},{1,2,1},{1,3,1,1,1},{1,1},//SiRedirRestr
			{1,1,1,1,1,1,1,3,1,1,1},{1,1,1,1,1},{1,1,1,1,1,1,7,1,2,3,4,5,6,7},//SiConnectedNum
			{1,1,2,1,1},{1,1,1,1,1,1,1,1,3,1,2,3},//SiGenNum
			{1,0x0001},{1,1,2,1,1},{1,1,1,2,1,1},
			{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_CGB:
		{
			SiPduCGB   data = {{1,1},{1,31,0xFF,0xFF,0xFF,0xFF}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);			
			break;
		}
	case M_CGBA:
		{
			SiPduCGBA   data = {{1,1},{1,31,0xFF,0xFF,0xFF,0xFF}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_CQM:
		{
			SiPduCQM   data = {{1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_CQR:
		{
			SiPduCQR   data = {{1,1},{1,3,1,1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_GRS:
		{
			SiPduGRS   data = {{1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_GRA:
		{
			SiPduGRA   data = {{1,31,0xFF,0xFF,0xFF,0xFF}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_CGU:
		{
			SiPduCGU   data = {{1,1},{1,31,0xFF,0xFF,0xFF,0xFF}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_CGUA:
		{
			SiPduCGUA   data = {{1,1},{1,31,0xFF,0xFF,0xFF,0xFF}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_CFN:
		{
			SiPduCFN   data = {{1,1,1,1,3,1,1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_CON:
		{
			SiPduCON   data = {
			{1,1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1},
			{1,1,1,1,1,1,7,1,2,3,4,5,6,7},{1,1,1,1,0x0001},
			{1,1,1,1,1,0},{1,1,1},{1,3,1,1,1},{1,3,1,1,1},{1,1},//SiNotifInd
			{1,3,1,1,1},{1,1},{1,1,1,1,1},{1,1},{1,0x0001},{1,3,1,1,1},
			{1,1,1,1,1,5,1,2,3,4,5},{1,3,1,1,1},//SiServiceAct
			{1,1,1,1,1,1,1,1,7,1,2,3,4,5,6,7},
			{1,1},{1,1,2,1,1},{1,1,2,1,1},
			{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_COT:
		{
			SiPduCOT   data = {{1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_FAC:
		{
			SiPduFAC   data = {
			{1,1,1,1,1,1,1,0,0,0,0,0,0},{1,3,1,1,1},{1,3,1,1,1},
			{1,3,1,1,1},{1,1,1,1,1,1,1,3,1,1,1},{1,3,1,1,1},{1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_FAA:
		{
			SiPduFAA   data = {
			{1,1},{1,1,1,1,1,0},{1,1,1,1,0x0001},{1,1,1,1,0x0001,1,1},{1,3,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_FRJ:
		{
			SiPduFRJ   data = {{1,1},{1,1,1,1,2,1,1},{1,1,1,1,1,0}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_FAR:
		{
			SiPduFAR   data = {
			{1,1},{1,1,1,1,1,0},{1,1,1,1,0x0001},{1,1,1,1,0x0001,1,1},{1,3,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_FOT:
		{
			SiPduFOT   data = {{1,1,1,1,0x0001}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_IDR:
		{
			SiPduIDR   data = {
			{1,1,1},{1,1,1,1,1,1,1,0,0,0,0,0,0},{1,3,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_IRS:
		{
			SiPduIRS   data = {
			{1,1,1},{1,1,1,1,1,1,1,0,0,0,0,0,0},{1,3,1,1,1},
			{1,1,1,1,1,1,1,3,1,1,1},{1,3,1,1,1},{1,1,1,1,1,1,1,1,3,1,2,3},//SiGenNum
			{1,3,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_INF:
		{
			SiPduINF   data = {
			{1,1,1,1,1,1,0},{1,1},{1,1,1,1,1,1,1,3,1,1,1},{1,1,1,1,0x0001},
			{1,1,1,1,0x0001,1,1},{1,3,1,1,1},{1,3,1,1,1},
			{1,1,1,1,1},
			{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
			{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
			{1,1,1,1,1},{1,1,1,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_INR:
		{
			SiPduINR   data = {{1,1,1,1,1,1,0},{1,0,0,1,0x0001},{1,3,1,1,1},{1,3,1,1,1},{1,1,1,1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_IAM:
		{
			SiPduIAM   data = {
			{1,1,1,1},{1,1,1,1,1,1,1,1,1},{1,1},{1,1},
			{1,1,1,1,1,1,1},{1,1,1,1,1,1},{0,0,0,0,0},//SiCallRef
			{0,0,0,0,0,0,0,0,0},{0,0,0,0},{1,1,1,1,1,1,1},{1,1,1,1,1},//SiRedirInfo
			{1,1,1,1,1,0x0001},{1,1,1,1,0x0001,1,1},{1,1,1,1,1,1,1},//SiOrigCdNum
			{1,2,1,1},{1,3,1,1,1},{1,2,1,1},{1,1,1,1,1,0},
			{0,0,0,0,0,0,0,0,0,0},//SiGenNum
			{0,0x0000},{0,0,0,0},{0,0,0,0},{0,0,0,0,0},//SiGenDigits
			{1,0x0002},{1,2,1,1},{1,2,1,1},{1,2,1,1},{1,1},{1,2,1,1},//SiServiceAct
			{1,1,1,1,1,1,1,0x00000001},{1,1},{0,0,0,0,0,0,0,0,0},//SiCgPtyNum
			{1,2,1,
			 3,1,2,3,0,0,0,0,0,
			 2,1,
			 3,1,2,3,0,0,0,0,0,
			   0,0,0,0,0,0,0,0,
			 3,1,1,1,
			 3,1,2,3,0,0,0,0,0,
			   0,0,0,0,0,0,0,0,},
			{1,1,},{1,1,2,1,1},{1,1,2,1,1,2},{1,2,1,1},{1,1,2,1,1},//SiCallDivTrtInd
			{1,1,1,1,1,1,1},{1,1,2,1,1},{1,1,2,1,1},{1,2,1,1},{1,1,1,2,1,1},
			{1,1,1,1,1},{1,1},{1,1},{1,1,1,1,1},{1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1},
			{1,1,1,1,1,1,1,1,1,1,1,1,1,1},{1,1,1}
			};	
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_NRM:
		{
			SiPduNRM   data = {
			{1,1,1,1,1,1,1,0,0,0,0,0,0},{1,3,1,1,1},{1,2},{1,1,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_PAM:
		{
			SiPduPAM   data = {{1,3,1,1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_REL:
		{
			SiPduREL   data = {
			{1,1,1,1,2,1,1},{1,1,1,1,1},{1,1,1,1,1,3,1,2,3},
			{1,3,1,1,1},{1,0x0001},{1,3,1,1,1},{1,1},{1,3,1,1,1},//SiNetSpecFacil
			{1,1},{1,3,1,1,1},{1,1},{1,1,1,1,1,0},{1,3,1,1,1},{1,3,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_RLC:
		{
			SiPduRLC   data = {{1,1,1,1,2,1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_RES:
		{
			SiPduRES   data = {{1,1},{1,1,1,1,0x0001}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_SGM:
		{
			SiPduSGM   data = {
			{1,3,1,1,1},{1,3,1,1,1},{1,1,1,1,1,1,1,0,0,0,0,0,0},
			{1,1,1,3,1,2,3},{1,1},
			{1,1,1,1,1,1,1,1,3,1,2,3}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_SAM:
		{
			SiPduSAM   data = {
			{1,1,3,1,1,1}
			};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_SUS:
		{
			SiPduSUS   data = {{1,1},{1,1,1,1,0x0001}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_UPA:
		{
			SiPduUPAT   data = {{1,3,1,1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_UPT:
		{
			SiPduUPAT   data = {{1,3,1,1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_USR:
		{
			SiPduUSR   data = {{1,3,1,1,1},{1,3,1,1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_LOP:
		{
			return;
		}
	case M_PRI:
		{
			SiPduPRI   data = {{1,1,1,1,1},{1,1,1,1},{1,1,1,1,1,1,1,0,0,0,0,0,0},
												 {1,3,1,1,1},{1,1,1,1,1,1,3,1,1,1}};
			str_len	=	sizeof(data);
			memcpy(&isup_sd_pdus,&data,str_len);
			break;
		}
	case M_UBL:			
	case M_UBA:			
	case M_UCIC:
	case M_BLO:
	case M_BLA:
	case M_RSC:
	case M_OLM:
	case M_LPA:
	case M_CRG:
		if(flag) return;
		break;
	default:
		return;	
	}	

	if(flag)
	{
		if(memcmp(&isup_rv_pdus,&isup_sd_pdus,str_len)==0)
		{
			isup_asciout_proc("TEST CHECK PASS.\r\n");
			return;
		}
		isup_asciout_proc("TEST CHECK ERROR.\r\n");
	}

	isup_send_msg(pid,type);
	*/
	return;
}

int	isup_debug_init(void)
{
	BYTE	page;
	BYTE	data[10];
	BYTE 	*ptr;

	strcpy(AsciInBuf, "\0");
    strcpy(AsciOutBuf, "\0");
    MonitorFg = MONITOR_NONE;
	bzero(disp_page, 20);
	memset(&isup_csta,0,sizeof(isup_csta));
	ptr = data;

	debug_set_response(BASE_ID_LEN, debug_status_id, &debug_status, 1);
	debug_set_response(BASE_ID_LEN, debug_name_id, VER_DEBUG, 10);
	debug_set_response(BASE_ID_LEN, debug_ascin_id, AsciInBuf, 4096);
	debug_set_response(BASE_ID_LEN, debug_ascout_id, AsciOutBuf, 4096);

	for (page = 1; page <= PAGE_NUM; page++)
	{
		switch (page)
		{
		case 1: //page 1
			ptr = title1_p;
			break;
		case 2: //page 2
			ptr = title2_p;
			break;
		case 3: //page 3
			ptr = title3_p;
			break;
		case 4: //page 4
			ptr = title4_p;
			break;
		case 5: //page 5
			ptr = title5_p;
			break;
		default:
			break;				
		}
		debug_page_title[PAGE_POINT] = 5 + page;
		debug_set_response(BASE_ID_LEN + 1, debug_page_title, ptr, strlen(ptr));
		debug_disp_page(page);
	}
	return 1;
}


void isup_debug_timer(void)
{
	BYTE	in_page, err_fg = 0;
	BYTE	*ascii_in_ptr 	= NULL;
	BYTE	*str_start 		= NULL;
	WORD	str_len;
	WORD	num;

	if ((str_len = strlen(AsciInBuf)) > 0)
	{
		in_page = AsciInBuf[0] - 1;
		ascii_in_ptr = AsciInBuf + 1;

		if (in_page > PAGE_NUM)
			err_fg = 1;
		else if (strcmp(ascii_in_ptr,"log error on") == 0)
		{
			MonitorFg = MonitorFg | MONITOR_ERROR;
		}
		else if (strcmp(ascii_in_ptr,"log error off") == 0)
		{
			MonitorFg = MonitorFg & (~MONITOR_ERROR);			
		}
		else if (strcmp(ascii_in_ptr,"log all") == 0)
		{
			MonitorFg = MONITOR_ALL;
		}
		else if (strcmp(ascii_in_ptr,"log none") == 0)
		{
			MonitorFg = MONITOR_NONE;
		}
		else if (strcmp(ascii_in_ptr,"log state on") == 0)
		{
			MonitorFg = MonitorFg | MONITOR_STATE;
		}
		else if (strcmp(ascii_in_ptr,"log state off") == 0)
		{
			MonitorFg = MonitorFg & (~MONITOR_STATE);			
		}

		else if (strcmp(ascii_in_ptr,"help") == 0)
		{
			isup_asciout_proc(log_help);
			isup_asciout_proc("Ver.%sp%02d\r\n",VER_DEBUG,IS_PATCH);
		}
		else if (isdigit(ascii_in_ptr[0]))
		{
			num = strtoul(ascii_in_ptr, NULL, 10);
			disp_page[in_page] = num;
			debug_disp_page(in_page);
		}
		else if ((str_start = strstr(ascii_in_ptr, ">")) != NULL)
		{
			num = strtoul(str_start + 1, NULL, 10);
			disp_page[in_page] += num;
			debug_disp_page(in_page);
		}
		else if ((str_start = strstr(ascii_in_ptr, "<"))!= NULL)
		{
			num = strtoul(str_start + 1, NULL, 10);
			disp_page[in_page] -= num;
			debug_disp_page(in_page);
		}		
		else if (strcmp(ascii_in_ptr,"reset csta") == 0)
		{
			memset(&isup_csta,0,sizeof(isup_csta));
		}
		else if (strcmp(ascii_in_ptr,"test color") == 0)
		{
			debug_setcol(COL_WHITE);
			isup_asciout_proc("COL_WHITE\n\r");
			debug_setcol(COL_RED);
			isup_asciout_proc("COL_RED\n\r");
			debug_setcol(COL_YELLOW);
			isup_asciout_proc("COL_YELLOW\n\r");
			debug_setcol(COL_GREEN);
			isup_asciout_proc("COL_GREEN\n\r");
			debug_setcol(COL_BLUE);
			isup_asciout_proc("COL_BLUE\n\r");
			debug_setcol(COL_BROWN);
			isup_asciout_proc("COL_BROWN\n\r");
			debug_setcol(COL_MEGEN);
			isup_asciout_proc("COL_MEGEN\n\r");
			debug_setcol(COL_GRAY);
			isup_asciout_proc("COL_GRAY\n\r");
			debug_setcol(COL_HI_WHI);
			isup_asciout_proc("COL_HI_WHI\n\r");
			debug_setcol(COL_HI_RED);
			isup_asciout_proc("COL_HI_RED\n\r");
			debug_setcol(COL_HI_YEL);
			isup_asciout_proc("COL_HI_YEL\n\r");
			debug_setcol(COL_HI_GRE);
			isup_asciout_proc("COL_HI_GRE\n\r");
			debug_setcol(COL_HI_BLU);
			isup_asciout_proc("COL_HI_BLU\n\r");
			debug_setcol(COL_HI_BRO);
			isup_asciout_proc("COL_HI_BRO\n\r");
			debug_setcol(COL_HI_MEG);
			isup_asciout_proc("COL_HI_MEG\n\r");
			debug_setcol(COL_BLACK);
			isup_asciout_proc("COL_BLACK\n\r");
			debug_cancelcol();
		}		
		else if (strstr(ascii_in_ptr, "reset port") != NULL)
		{
			if ((str_start = strstr(ascii_in_ptr, "-")) != NULL)
			{
				num = strtoul(str_start + 1, NULL, 10);
				if (num >= ISUP_MAX_PORT)
					err_fg = 1;
				else
				{
					memset(&(isup_db.port_pond[num]),0,sizeof(ISUP_Port_struct));
				}
			}
		}
		else if (strstr(ascii_in_ptr, "set dpc") != NULL)
		{
			if ((str_start = strstr(ascii_in_ptr, "=")) != NULL)
			{
				num = strtoul(str_start + 1, NULL, 10);
				debug_dpc = num;
			}
		}
		else if (strstr(ascii_in_ptr, "set opc") != NULL)
		{
			if ((str_start = strstr(ascii_in_ptr, "=")) != NULL)
			{
				num = strtoul(str_start + 1, NULL, 10);
				debug_opc = num;
			}
		}
		else if (strstr(ascii_in_ptr, "set ni") != NULL)
		{
			if ((str_start = strstr(ascii_in_ptr, "=")) != NULL)
			{
				num = strtoul(str_start + 1, NULL, 10);
				debug_ni = num;
			}
		}		
		else if (strstr(ascii_in_ptr, "list cg") != NULL)
		{
			if ((str_start = strstr(ascii_in_ptr, "-")) != NULL)
			{
				num = strtoul(str_start + 1, NULL, 10);
				list_all_circuit(num);
			}
			else
				list_all_cg();
		}		
		else if (strstr(ascii_in_ptr, "list circuit") != NULL)
		{
			if ((str_start = strstr(ascii_in_ptr, "-")) != NULL)
			{
				num = strtoul(str_start + 1, NULL, 10);
				list_all_port(num);
			}
		}		
		else if (strstr(ascii_in_ptr, "list port") != NULL)
		{
			if ((str_start = strstr(ascii_in_ptr, "-")) != NULL)
			{
				num = strtoul(str_start + 1, NULL, 10);
				list_port(num);
			}
		}				
		else if (strstr(ascii_in_ptr, "list debug spc") != NULL)
		{
			isup_asciout_proc("debug_dpc = %d,debug_opc = %d,debug_ni = %d\n\r",debug_dpc,debug_opc,debug_ni);
		}		
		else if (strstr(ascii_in_ptr, "list cic") != NULL)
		{
			if ((str_start = strstr(ascii_in_ptr, "-")) != NULL)
			{
				num = strtoul(str_start + 1, NULL, 10);
				list_cic(debug_ni, debug_dpc, debug_opc, num);
			}
		}
		else if (strcmp(ascii_in_ptr,"test start") == 0)
			isup_msg_test = 1;
		else if (strcmp(ascii_in_ptr,"test stop") == 0)
			isup_msg_test = 0;
		else if (strstr(ascii_in_ptr, "send") != NULL)
		{	
			if ((str_start = strstr(ascii_in_ptr, "-")) != NULL)
			{
				num = strtoul(str_start + 1, NULL, 10);
				test_isup_msg(num,0);
			}						
		}
		else if (strcmp(ascii_in_ptr,"test debug") == 0)
		{
			up_message msg;
			msg.len = 1;
			msg.msgList[0] = 1;			
			monitor_isup_msg(0,"RV=>",&msg,COL_YELLOW);			
			isup_trace_func(0,"APP => function trace: isup_setup_ind\r\n");
			monitor_isup_msg(0,"SD=>",&msg,COL_YELLOW);
			isup_trace_func(0,"APP => function trace: isup_setup_ind\r\n");
			isup_log_err(0,"Setup indicate handle is not registered@%s\r\n", __FUNCTION__);			
		}
		else
			err_fg = 1;

		if (err_fg == 0)
			isup_asciout_proc("Command OK!\n\r");
		else
			isup_asciout_proc("Command Error!\n\r");		

		strcpy(AsciInBuf, "\0");
	}
}


static void display_isup_msgtype(u8 msgtype)
{
	
	switch(msgtype)
	{
		case M_ACM:
			isup_asciout_proc("ACM:Address complete");
			break;
		case M_ANM:
			isup_asciout_proc("ANM:Answer");
			break;
		case M_APP:
			isup_asciout_proc("APP:Application transport message");
			break;		
		case M_BLO:
			isup_asciout_proc("BLO:Blocking");
			break;
		case M_BLA:
			isup_asciout_proc("BLA:Blocking acknowledgement");
			break;
		case M_CPG:
			isup_asciout_proc("CPG:Call progress");
			break;
		case M_CGB:
			isup_asciout_proc("CGB:Circuit/CIC group blocking");
			break;
		case M_CGBA:
			isup_asciout_proc("CGBA:Circuit/CIC group blocking acknowledgement");
			break;
		case M_CQM:
			isup_asciout_proc("CQM:Circuit/CIC group query (national use)");
			break;
		case M_CQR:
			isup_asciout_proc("CQR:Circuit/CIC group query response (national use)");
			break;
		case M_GRS:
			isup_asciout_proc("GRS:Circuit/CIC group reset");
			break;
		case M_GRA:
			isup_asciout_proc("GRA:Circuit/CIC group reset acknowledgement");
			break;
		case M_CGU:
			isup_asciout_proc("CGU:Circuit/CIC group unblocking");
			break;
		case M_CGUA:
			isup_asciout_proc("CGUA:Circuit/CIC group unblocking acknowledgement");
			break;
		case M_CRG:
			isup_asciout_proc("CRG:Charge information (national use)");
			break;
		case M_CFN:
			isup_asciout_proc("CFN:Confusion");
			break;
		case M_CON:
			isup_asciout_proc("CON:Connect");
			break;
		case M_COT:
			isup_asciout_proc("COT:Continuity");
			break;
		case M_FAC:
			isup_asciout_proc("FAC:Facility ");
			break;
		case M_FAA:
			isup_asciout_proc("FAA:Facility accepted");
			break;
		case M_FRJ:
			isup_asciout_proc("FRJ:Facility reject");
			break;
		case M_FAR:
			isup_asciout_proc("FAR:Facility request");
			break;
		case M_FOT:
			isup_asciout_proc("FOT:Forward transfer");
			break;
		case M_IDR:
			isup_asciout_proc("IDR:Identification request");
			break;
		case M_IRS:
			isup_asciout_proc("IRS:Identification response");
			break;
		case M_INF:
			isup_asciout_proc("INF:Information (national use)");
			break;
		case M_INR:
			isup_asciout_proc("INR:Information request (national use)");
			break;
		case M_IAM:
			isup_asciout_proc("IAM:Initial address");
			break;
		case M_LPA:
			isup_asciout_proc("LPA:Loop Back Acknowledgement");
			break;
		case M_NRM:
			isup_asciout_proc("NRM:Network resource management");
			break;
		case M_OLM:
			isup_asciout_proc("OLM:Overload");
			break;
		case M_PAM:	
			isup_asciout_proc("PAM:Pass-Along");
			break;
		case M_REL:	
			isup_asciout_proc("REL:Release");
			break;
		case M_RLC:
			isup_asciout_proc("RLC:Release complete");
			break;
		case M_RSC:	
			isup_asciout_proc("RSC:Reset circuit/CIC");
			break;
		case M_RES:	
			isup_asciout_proc("RES:Resume");
			break;
		case M_SGM:	
			isup_asciout_proc("SGM:Segmentation");
			break;
		case M_SAM:	
			isup_asciout_proc("SAM:Subsequent address");
			break;
		case M_SUS:	
			isup_asciout_proc("SUS:Suspend");
			break;
		case M_UBL:	
			isup_asciout_proc("UBL:Unblocking");
			break;
		case M_UBA:	
			isup_asciout_proc("UBA:Unblocking acknowledgement");
			break;
		case M_UCIC:	
			isup_asciout_proc("UCIC:Unequipped CIC (national use)");
			break;
		case M_UPA:	
			isup_asciout_proc("UPA:User Part Available");
			break;
		case M_UPT:	
			isup_asciout_proc("UPT:User Part Test");
			break;
		case M_USR:	
			isup_asciout_proc("USR:User-to-user information");
			break;
		case M_PRI:
			isup_asciout_proc("PRI:Pre-release information message");
			break;
		case M_CVR:
			isup_asciout_proc("CVR:Circuit validation response");
			break;
		case M_CVT:
			isup_asciout_proc("CVT:Circuit validation test");
			break;
		default:
			isup_asciout_proc("Unknown message");
	}
	isup_asciout_proc("(message type=0x%x)",msgtype);		
}

void isup_log_err(u32 pid,const char *fmt, ...)
{
	va_list		ap;
	struct timeval tv;
  struct timezone tz;
  struct tm *t;
  char timestr[1024];			

	if (((MonitorFg & MONITOR_ERROR) != MONITOR_ERROR) &&
			(isup_db.port_pond[pid%ISUP_MAX_PORT].trace_flag != 1))
		return;
		
  gettimeofday ( &tv, &tz );
  t = localtime ( &tv.tv_sec );
  sprintf ( timestr, "[%d:%d:%d.%ld]", t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec );		
		
	va_start(ap, fmt);
	vsprintf(AsciTempBuf, fmt, ap);
	debug_setcol(COL_RED);
	isup_asciout_proc("%s%s (pid=%d)",timestr,AsciTempBuf,pid);	
	debug_cancelcol();
	isup_asciout_proc("\r\n");
	va_end(ap);
}

void isup_trace_func(u32 pid,const char *fmt, ...)
{
	va_list		ap;
	struct timeval tv;
  struct timezone tz;
  struct tm *t;
  char timestr[1024];		

	if (((MonitorFg & MONITOR_FUNC) != MONITOR_FUNC) &&
			(isup_db.port_pond[pid%ISUP_MAX_PORT].trace_flag != 1))
		return;

  gettimeofday ( &tv, &tz );
  t = localtime ( &tv.tv_sec );
  sprintf ( timestr, "[%d:%d:%d.%ld]", t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec );		
		
	va_start(ap, fmt);
	vsprintf(AsciTempBuf, fmt, ap);
	debug_setcol(COL_YELLOW);
	isup_asciout_proc("%s%s (pid=%d)",timestr,AsciTempBuf,pid);	
	debug_cancelcol();
	isup_asciout_proc("\r\n");
	va_end(ap);
}

void monitor_isup_msg(u32 pid,BYTE *head,up_message *msg,BYTE col)
{
	BYTE    i;

	struct timeval tv;
  struct timezone tz;
  struct tm *t;
  char timestr[1024];	
	
	if (((MonitorFg & MONITOR_MSG) != MONITOR_MSG) &&
			(isup_db.port_pond[pid%ISUP_MAX_PORT].trace_flag != 1))
		return;

  gettimeofday ( &tv, &tz );
  t = localtime ( &tv.tv_sec );
  sprintf ( timestr, "[%d:%d:%d.%ld]", t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec );
		
	debug_setcol(col);
	isup_asciout_proc("%s%s ",timestr,head);
	display_isup_msgtype(msg->msgList[0]);	
	isup_asciout_proc("--cic=0x%x%x,dpc=%d,opc=%d,ni=%d,pid=%d->\n\r",msg->cic[1],msg->cic[0],msg->dpc,msg->opc,msg->sio>>6,pid);
	debug_cancelcol();	
	for (i = 0; i < msg->len; i ++)
	{
		sprintf(&AsciTempBuf[3*i]," %02x", msg->msgList[i]);
	}
	sprintf(&AsciTempBuf[3*i],"\n\r");	
	isup_asciout_proc(AsciTempBuf);	
	return;
}

void monitor_port_state(u32 cic_val,u32 port)
{
	if ((MonitorFg & MONITOR_STATE) != MONITOR_STATE)
		return;

	isup_asciout_proc("->port:\r\n");
	isup_asciout_proc("CIC\tPort\tSuID\tcall\tsus\tblo\tcpc\tblr\tbls\tmgbs\tmgbr\tcrs\tcrr\tcgrs\tcgrr\r\n");
	isup_asciout_proc("%d\t%d\t%d(%d)\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n",
			cic_val,
			port,
			isup_db.port_pond[port].su_proc_id,
			isup_db.port_pond[port].sm_proc_id,
			isup_db.port_pond[port].cic_state.call_state,
			isup_db.port_pond[port].cic_state.sus_state,
			isup_db.port_pond[port].cic_state.blo_state,
			isup_db.port_pond[port].fsm_state.cpc_state,
			isup_db.port_pond[port].fsm_state.blr_state,
			isup_db.port_pond[port].fsm_state.bls_state,
			isup_db.port_pond[port].fsm_state.mgbs_state,
			isup_db.port_pond[port].fsm_state.mgbr_state,
			isup_db.port_pond[port].fsm_state.crs_state,
			isup_db.port_pond[port].fsm_state.crr_state,
			isup_db.port_pond[port].fsm_state.cgrs_state,
			isup_db.port_pond[port].fsm_state.cgrr_state
			);
}

void isup_msg_csta(u8 msgtype,u8 flag)
{

	switch(msgtype)
	{
	case M_ACM:
		if(flag==0)
			isup_csta.rv_acm++;
		else
			isup_csta.sd_acm++; 
		break;
	case M_ANM:
		break;
	case M_BLO:
		break;
	case M_BLA:
		break;
	case M_CPG:
		break;
	case M_CGB:
		break;
	case M_CGBA:
		break;
	case M_CQM:
		break;
	case M_CQR:
		break;
	case M_GRS:
		break;
	case M_GRA:
		break;
	case M_CGU:
		break;
	case M_CGUA:
		break;
	case M_CRG:
		break;
	case M_CFN:
		break;
	case M_CON:
		break;
	case M_COT:
		break;
	case M_FAC:
		break;
	case M_FAA:
		break;
	case M_FRJ:
		break;
	case M_FAR:
		break;
	case M_FOT:
		break;
	case M_IDR:
		break;
	case M_IRS:
		break;
	case M_INF:
		break;
	case M_INR:
		break;
	case M_IAM:
		if(flag==0)
			isup_csta.rv_iam++;
		else
			isup_csta.sd_iam++; 
		break;
	case M_LPA:
		break;
	case M_NRM:
		break;
	case M_OLM:
		break;
	case M_PAM:	
		break;
	case M_REL:	
		if(flag==0)
			isup_csta.rv_rel++;
		else
			isup_csta.sd_rel++; 
		break;
	case M_RLC:
		if(flag==0)
			isup_csta.rv_rlc++;
		else
			isup_csta.sd_rlc++; 
		break;
	case M_RSC:	
		break;
	case M_RES:	
		break;
	case M_SGM:	
		break;
	case M_SAM:	
		break;
	case M_SUS:	
		break;
	case M_UBL:	
		break;
	case M_UBA:	
		break;
	case M_UCIC:	
		break;
	case M_UPA:	
		break;
	case M_UPT:	
		break;
	case M_USR:	
		break;
	default:	
		break;
	}
}

