#include "../../debug/src/include/debug.h"
#include "./include/mtp3.h"
#include "./include/mtpstm.h"
#include "./include/mtpext.h"
extern void mtp3_debug(int n,const char *fmt,...);
/*@ignore@*/
int mtp3_send_netcap=0;

void reset_mtp3();
long	atol(const char *nptr);
int		gettimeofday(struct timeval *tv,struct timezone *tz);
struct tm *localtime(const time_t *timep);
void mtp3_list_link(BYTE i);

static char ascii[16] = {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,
			0x41,0x42,0x43,0x44,0x45,0x46};
extern BOOL mtp3DebugFull;

BYTE	disp_flag;
BYTE	disp_page[16];

/* by simon at 23/9/27 */
extern BYTE	* disp_ptr;
extern BYTE disp_length;

static DWORD	debug_mask=0;
void mtp3_show_routine_status(BYTE nw);
void mtp3_show_routine_status_sorted(BYTE nw);
void mtp3_list_log_status();
void mtp3_reload_data();
int mtp3_write_parameter();

static BYTE	title1_p[] = 
{
	"	PAGE01 MTP3 Measure-TRAFFIC sub-page0:flow, sub-page1:throwed  \n\r\
                   [---SNM---] [---T+M---] [--SCCP---] [---TUP---] [--ISUP---]\n\r\
--Page--\n\r\
 U (nw0)\n\r\
 t (nw1)\n\r\
 o (nw2)\n\r\
 M (nw3)\n\r\
  M (nw0)\n\r\
  t (nw1)  E\n\r\
  o (nw2)  1\n\r\
  I (nw3)\n\r\
   I (nw0)\n\r\
   t (nw1)\n\r\
   o (nw2)\n\r\
   M (nw3)\n\r\
    M (nw0)\n\r\
    t (nw1)\n\r\
    o (nw2)\n\r\
    U (nw3)\n\r\
     M (nw0)\n\r\
     S (nw1)\n\r\
     T (nw2)\n\r\
     P (nw3)\n\r\
"
};

static BYTE	title2_p[] = 
{
	"		PAGE02 link mark    \n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
--Page--\n\r\
link_available\n\r\
link_unavailable\n\r\
failed\n\r\
CB_in_progress\n\r\
CO_in_progress\n\r\
link_inhibited\n\r\
locally_inhibited\n\r\
remotely_inhibited\n\r\
localInhibit_inPro\n\r\
uninhibit_in_pro\n\r\
local_blocked\n\r\
remote_blocked\n\r\
local_change_over\n\r\
"
};

static BYTE	title3_p[] = 
{
	"		PAGE03 MTP2  MTP3 flag   \n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
  Page\n\r\
 mtp2 flag(old)\n\r\
 \n\r\
 mtp2 flag(new)\n\r\
 \n\r\
 \n\r\
 page\n\r\
 0:mtp3 ip\n\r\
 1:mtp3 flag old\n\r\
 2:mtp3 flag new\n\r\
 3:lk_configured\n\r\
"
};

static BYTE	title4_p[] = 
{
	"		PAGE09  MTP3    STATE MACHINE'S INPUT   \n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
--Page--\n\r\
LSAC L2\n\r\
LSAC SLTC\n\r\
LSAC SLM\n\r\
LSAC STM\n\r\
LSAC TCOC\n\r\
LSAC MGMT\n\r\
TLAC SLM\n\r\
TLAC STM\n\r\
TLAC HMDT\n\r\
TSRC STM\n\r\
TSRC TLAC\n\r\
TSRC TCOC\n\r\
TSRC TCBC\n\r\
TSRC SRM\n\r\
TCOC L2\n\r\
TCOC STM\n\r\
TCOC TSRC\n\r\
TCOC HMDT\n\r\
TCBC\n\r\
TCBC_TSRC\n\r\
T(A)PRC\n\r\
"
};

static BYTE	title5_p[] = 
{
	"    PAGE05  MTP3     Port state(16 port per sub page)\n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
subPage\r\n\
L1\r\n\
L2\r\n\
L3\r\n\
lsac\r\n\
sltc\r\n\
tlac\r\n\
tsrc\r\n\
tcoc\r\n\
tcbc\r\n\
rtpc[nw0]\r\n\
rtpc[nw1]\r\n\
rtpc[nw2]\r\n\
rtpc[nw3]\r\n\
rtac[nw0]\r\n\
rtac[nw1]\r\n\
rtac[nw2]\r\n\
rtac[nw3]\r\n\
tprc"
};

static BYTE	title6_p[] = 
{
	"		PAGE06  MTP3 ROUTINE TABLE(4)         \n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
--PAGE--\n\r\
0 INTERNATIONAL\n\r\
1 INTERNATIONAL(S)\n\r\
2 NATIONAL\n\r\
3 NATIONAL(S)\n\r\
\n\r\
\n\r\
value=\n\r\
18:route:normal ls\n\r\
   nls:available\n\r\
   als:unavailable\n\r\
10:route:normal ls\n\r\
   nls:available\n\r\
   als:available\n\r\
52:route=alter ls\n\r\
   nls:unavailable\n\r\
   als:available\n\r\
8A:no route\n\r\
other:problem bug\n\r\
"
};

static BYTE title7_p[] = 
{
	"		PAGE07  MTP3 LINKSET SLS TABLE        \n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
--PAGE--\n\r\
(16*page+00)ls\n\r\
(16*page+01)ls\n\r\
(16*page+02)ls\n\r\
(16*page+03)ls\n\r\
(16*page+04)ls\n\r\
(16*page+05)ls\n\r\
(16*page+06)ls\n\r\
(16*page+07)ls\n\r\
(16*page+08)ls\n\r\
(16*page+09)ls\n\r\
(16*page+10)ls\n\r\
(16*page+11)ls\n\r\
(16*page+12)ls\n\r\
(16*page+13)ls\n\r\
(16*page+14)ls\n\r\
(16*page+15)ls\n\r\
"
};

static BYTE	title8_p[] = 
{
	"    PAGE08  MTP3    Version 1.0    linkset State   \n\r\
                   avail mark  place cf influence dst number\n\r\
--Page--\n\r\
(16*page+00)ls\n\r\
(16*page+01)ls\n\r\
(16*page+02)ls\n\r\
(16*page+03)ls\n\r\
(16*page+04)ls\n\r\
(16*page+05)ls\n\r\
(16*page+06)ls\n\r\
(16*page+07)ls\n\r\
(16*page+08)ls\n\r\
(16*page+09)ls\n\r\
(16*page+10)ls\n\r\
(16*page+11)ls\n\r\
(16*page+12)ls\n\r\
(16*page+13)ls\n\r\
(16*page+14)ls\n\r\
(16*page+15)ls\n\r\
"
};

static BYTE	title9_p[] = 
{
	"    PAGE9  MTP3    ls influence dst\n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
--page--\n\r\
page0-page127\n\r\
ls0  -ls127\n\r\
[NLS]\n\r\
\n\r\
\n\r\
\n\r\
\n\r\
\n\r\
\n\r\
[ALS]\n\r\
"
};

static BYTE	title10_p[] = 
{
	"    PAGE10  MTP3    isup sd/rv count\n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
--page--\n\r\
RvISUP\n\r\
\n\r\
\n\r\
\n\r\
SdISUP\n\r\
\n\r\
\n\r\
\n\r\
\n\r\
\n\r\
"
};

static BYTE	title11_p[] = 
{
	"    PAGE11  MTP3    watch dog\n\r\
                   0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15\n\r\
Dog\n\r\
"
};

void mtpi_m()
{
	memset(disp_page,0,16);
}

BYTE	mtp_disp_line(BYTE page, BYTE line)//return display length,disp data ptr per line
{
	BYTE	disp_length;
	BYTE	subpage;
	
	disp_length = 16;
	
	page = page & 15;
	disp_page[page] = disp_page[page] & 31;
	subpage = disp_page[page];

	switch(page)
	{
		case 1:
			if (subpage == 0)
			{
				disp_length = 20;
				switch (line)
				{
					case 0:
						disp_ptr = &disp_page[page];
						disp_length = 1;
						break;
					case 1:
						disp_ptr = (BYTE*)&mtp3.nw[0].flow.UtoM;
						break;
					case 2:
						disp_ptr = (BYTE*)&mtp3.nw[1].flow.UtoM;
						break;
					case 3:
						disp_ptr = (BYTE*)&mtp3.nw[2].flow.UtoM;
						break;
					case 4:
						disp_ptr = (BYTE*)&mtp3.nw[3].flow.UtoM;
						break;
					case 5:
						disp_ptr = (BYTE*)&mtp3.nw[0].flow.MtoI;
						break;
					case 6:
						disp_ptr = (BYTE*)&mtp3.nw[1].flow.MtoI;
						break;
					case 7:
						disp_ptr = (BYTE*)&mtp3.nw[2].flow.MtoI;
						break;
					case 8:
						disp_ptr = (BYTE*)&mtp3.nw[3].flow.MtoI;
						break;
					case 9:
						disp_ptr = (BYTE*)&mtp3.nw[0].flow.ItoM;
						break;
					case 10:
						disp_ptr = (BYTE*)&mtp3.nw[1].flow.ItoM;
						break;
					case 11:
						disp_ptr = (BYTE*)&mtp3.nw[2].flow.ItoM;
						break;
					case 12:
						disp_ptr = (BYTE*)&mtp3.nw[3].flow.ItoM;
						break;
					case 13:
						disp_ptr = (BYTE*)&mtp3.nw[0].flow.MtoU;
						break;
					case 14:
						disp_ptr = (BYTE*)&mtp3.nw[1].flow.MtoU;
						break;
					case 15:
						disp_ptr = (BYTE*)&mtp3.nw[2].flow.MtoU;
						break;
					case 16:
						disp_ptr = (BYTE*)&mtp3.nw[3].flow.MtoU;
						break;
					case 17:
						disp_ptr = (BYTE*)&mtp3.nw[0].flow.stp;
						break;
					case 18:
						disp_ptr = (BYTE*)&mtp3.nw[1].flow.stp;
						break;
					case 19:
						disp_ptr = (BYTE*)&mtp3.nw[2].flow.stp;
						break;
					case 20:
						disp_ptr = (BYTE*)&mtp3.nw[3].flow.stp;
						break;
					default:
						disp_length = 0;
						break;
				}
			}
			else if (subpage == 1)
			{
				disp_length = 20;
				switch (line)
				{
					case 0:
						disp_ptr = &disp_page[page];
						disp_length = 1;
						break;
					case 1:
						disp_ptr = (BYTE*)&mtp3.nw[0].flow.UtoM_throwed;
						break;
					case 2:
						disp_ptr = (BYTE*)&mtp3.nw[1].flow.UtoM_throwed;
						break;
					case 3:
						disp_ptr = (BYTE*)&mtp3.nw[2].flow.UtoM_throwed;
						break;
					case 4:
						disp_ptr = (BYTE*)&mtp3.nw[3].flow.UtoM_throwed;
						break;
					case 5:
						disp_ptr = (BYTE*)&mtp3.nw[0].flow.MtoI_throwed;
						break;
					case 6:
						disp_ptr = (BYTE*)&mtp3.nw[1].flow.MtoI_throwed;
						break;
					case 7:
						disp_ptr = (BYTE*)&mtp3.nw[2].flow.MtoI_throwed;
						break;
					case 8:
						disp_ptr = (BYTE*)&mtp3.nw[3].flow.MtoI_throwed;
						break;
					case 9:
						disp_ptr = (BYTE*)&mtp3.nw[0].flow.ItoM_throwed;
						break;
					case 10:
						disp_ptr = (BYTE*)&mtp3.nw[1].flow.ItoM_throwed;
						break;
					case 11:
						disp_ptr = (BYTE*)&mtp3.nw[2].flow.ItoM_throwed;
						break;
					case 12:
						disp_ptr = (BYTE*)&mtp3.nw[3].flow.ItoM_throwed;
						break;
					case 13:
						disp_ptr = (BYTE*)&mtp3.nw[0].flow.MtoU_throwed;
						break;
					case 14:
						disp_ptr = (BYTE*)&mtp3.nw[1].flow.MtoU_throwed;
						break;
					case 15:
						disp_ptr = (BYTE*)&mtp3.nw[2].flow.MtoU_throwed;
						break;
					case 16:
						disp_ptr = (BYTE*)&mtp3.nw[3].flow.MtoU_throwed;
						break;
					case 17:
						disp_ptr = (BYTE*)&mtp3.nw[0].flow.stp_throwed;
						break;
					case 18:
						disp_ptr = (BYTE*)&mtp3.nw[1].flow.stp_throwed;
						break;
					case 19:
						disp_ptr = (BYTE*)&mtp3.nw[2].flow.stp_throwed;
						break;
					case 20:
						disp_ptr = (BYTE*)&mtp3.nw[3].flow.stp_throwed;
						break;
					default:
						disp_length = 0;
						break;
				}
			}
            else if (subpage == 2)
            {
                disp_length = 20;
                switch (line)
                {
                    case 0:
                        disp_ptr = &disp_page[page];
                        disp_length = 1;
                        break;
                    case 1:
                        disp_ptr = (BYTE*)&mtp3.nw[0].flow.stp_loop;
                        break;
                    case 2:
                        disp_ptr = (BYTE*)&mtp3.nw[1].flow.stp_loop;
                        break;
                    case 3:
                        disp_ptr = (BYTE*)&mtp3.nw[2].flow.stp_loop;
                        break;
                    case 4:
                        disp_ptr = (BYTE*)&mtp3.nw[3].flow.stp_loop;
                        break;
                    default:
                        disp_length = 0;
                        break;
                }
            }
			else
				disp_length = 0;
			break;
		case 2:
			if (subpage > 15)
				return 0;
			switch (line)
			{
				case 0:
					disp_ptr = &disp_page[page];
					disp_length = 1;
					break;
				case 1:
					disp_ptr = link_available + subpage*16;
					break;		
				case 2:
/*					disp_ptr = link_unavailable + subpage*16;*/
					break;	
				case 3:
					disp_ptr = failed + subpage*16;
					break;		
				case 4:/* l3 */
					disp_ptr = changeback_in_progress + subpage*16;
					break;
				case 5:/* l2 */
					disp_ptr = changeover_in_progress + subpage*16;
					break;
				case 6:
					disp_ptr = link_inhibited + subpage*16;
					break;
				case 7:
					disp_ptr = link_locally_inhibited + subpage*16;
					break;							
				case 8:
					disp_ptr = link_remotely_inhibited + subpage*16;
					break;
				case 9:
					disp_ptr = local_inhibit_in_progress + subpage*16;
					break;
				case 10:
					disp_ptr = uninhibit_in_progress + subpage*16;
					break;
				case 11:
					disp_ptr = local_blocked + subpage*16;
					break;
				case 12:
					disp_ptr = remote_blocked + subpage*16;
					break;
				case 13:
					disp_ptr = local_change_over + subpage*16;
					break;
				default:
					disp_length = 0;

			}
			break;
		case 3:
			if (line == 0)
			{
				disp_ptr = &disp_page[page];
				disp_length = 1;
			}
			else if (line < 3)
			{
				disp_ptr = mtp2_flag_old+(line-1)*16;
			}
			else if (line < 5)
			{
				disp_ptr = mtp2_flag_new+(line-3)*16;
			}
			else if (line==5)
			{
				disp_ptr = &MTP3IPMng.LinkIPNum;
				disp_length = 1;
			}
			else if (line < 24)
			{
				if (subpage == 0)
					disp_ptr = (BYTE*)MTP3IPMng.mtp3_flag_ip+(line-6)*16;
				else if (subpage == 1)
					disp_ptr = MTP3IPMng.mtp3_flag_old+(line-6)*16;
				else if (subpage == 2)
					disp_ptr = MTP3IPMng.mtp3_flag_new+(line-6)*16;
				else if (subpage == 3)
					disp_ptr = mtp3ObjState.lk_configured+(line-6)*16;
				else if (subpage == 4)
					disp_ptr = mtp3ObjState.lk_NMTP3_ok+(line-6)*16;
				else if (subpage == 5)
					disp_ptr = mtp3ObjState.lk_AMTP3_ok+(line-6)*16;
				else if (subpage == 6)
					disp_ptr = (BYTE*)MTP3IPMng.LinkIP+(line-6)*16;
			}
			else
				disp_length = 0;
			break;
		case 4:/* input of state machine */
			if (subpage > 15)
				return 0;
			switch (line)
			{
				case 0:
					disp_ptr = &disp_page[page];
					disp_length = 1;
					break;
				case 1:/* l3 */
					disp_ptr = mtp3ObjInput.lsac_input_from_l2 + subpage*16;
					break;
				case 2:/* l2 */
					disp_ptr = mtp3ObjInput.lsac_input_from_sltc + subpage*16;
					break;
				case 3:/* l1 */
					disp_length = 0;
					break;
				case 4:
					disp_ptr = mtp3ObjInput.lsac_input_from_stm + subpage*16;
					break;
				case 5:
					disp_ptr = mtp3ObjInput.lsac_input_from_tcoc + subpage*16;
					break;
				case 6:
					disp_ptr = mtp3ObjInput.lsac_input_from_mgmt + subpage*16;
					break;
				case 7:
					disp_ptr = mtp3ObjInput.tlac_input_from_slm + subpage*16;
					break;
				case 8:
					disp_ptr = mtp3ObjInput.tlac_input_from_stm + subpage*16;
					break;
				case 9:
					disp_ptr = mtp3ObjInput.tlac_input_from_hmdt + subpage*16;
					break;
				case 10:
					disp_ptr = mtp3ObjInput.tsrc_input_from_stm + subpage*16;
					break;
				case 11:
					disp_ptr = mtp3ObjInput.tsrc_input_from_tlac + subpage*16;
					break;
				case 12:
					disp_ptr = mtp3ObjInput.tsrc_input_from_tcoc + subpage*16;
					break;
				case 13:
					disp_ptr = mtp3ObjInput.tsrc_input_from_tcbc + subpage*16;
					break;
				case 14:
					disp_length = 0;
					break;
				case 15:
					disp_length = 0;
					break;
				case 16:
					disp_ptr = mtp3ObjInput.tcoc_input_from_stm + subpage*16;
					break;
				case 17:
					disp_ptr = mtp3ObjInput.tcoc_input_from_tsrc + subpage*16;
					break;
				case 18:
					disp_ptr = mtp3ObjInput.tcoc_input_from_hmdt + subpage*16;
					break;
				case 19:
					disp_ptr = mtp3ObjInput.tcbc_input + subpage*16;
					break;
				case 20:
					disp_ptr = mtp3ObjInput.tcbc_input_from_tsrc + subpage*16;
					break;
/*				case 21:
					disp_ptr = mtp3ObjInput.sltc_input + subpage*16;
					break;*/
				case 21:
					disp_ptr = mtp3ObjInput.taprc_input + subpage*16;
					break;
				case 22:
					disp_ptr = &mtp3ObjInput.tprc_input;
					disp_length = 1;
					break;
				default:
					disp_length = 0;
					break;
			
			}
			break;
		case 5: /* state machine */
			if (subpage > 15)
				return 0;
			switch (line)
			{
				case 0:
					disp_ptr = &disp_page[page];
					disp_length = 1;
					break;
				case 1:
					disp_ptr = mtp3ObjState.link_l1_state+subpage*16;
					break;
				case 2:
					disp_ptr = mtp3ObjState.link_l2_state+subpage*16;
					break;
				case 3:
					disp_ptr = mtp3ObjState.link_l3_state+subpage*16;
					break;
				case 4:
					disp_ptr = mtp3ObjState.lsac_state+subpage*16;
					break;
				case 5:
					disp_ptr = mtp3ObjState.sltc_state+subpage*16;
					break;
				case 6:
					disp_ptr = mtp3ObjState.tlac_state+subpage*16;
					break;
				case 7:
					disp_ptr = mtp3ObjState.tsrc_state+subpage*16;
					break;
				case 8:
					disp_ptr = mtp3ObjState.tcoc_state+subpage*16;
					break;
				case 9:
					disp_ptr = mtp3ObjState.tcbc_state+subpage*16;
					break;
				case 10:
					disp_ptr = mtp3.nw[0].rtpc_state+subpage*16;
					break;
				case 11:
					disp_ptr = mtp3.nw[1].rtpc_state+subpage*16;
					break;
				case 12:
					disp_ptr = mtp3.nw[2].rtpc_state+subpage*16;
					break;
				case 13:
					disp_ptr = mtp3.nw[3].rtpc_state+subpage*16;
					break;
				case 14:
					disp_ptr = mtp3.nw[0].rtac_state+subpage*16;
					break;
				case 15:
					disp_ptr = mtp3.nw[1].rtac_state+subpage*16;
					break;
				case 16:
					disp_ptr = mtp3.nw[2].rtac_state+subpage*16;
					break;
				case 17:
					disp_ptr = mtp3.nw[3].rtac_state+subpage*16;
					break;
				case 18:
					disp_ptr = &mtp3ObjState.tprc_state;
					disp_length = 1;
					break;
				default:
					disp_length = 0;
					break;
			}
					
			break;
		case 6:/* routine */
			if (line == 0)
			{
				disp_ptr = &disp_page[page];
				disp_length = 1;
			}
			else if ( line <17 )
			{
				if (subpage < 4)
				{
					disp_ptr = mtp3.nw[subpage].routine+(line-1)*16;
				}
				else
					disp_length = 0;
			}
			else
				disp_length = 0;
			break;

		case 7:/* ls sls & ls slc table */
			if (line == 0)
			{
				disp_ptr = &disp_page[page];
				disp_length = 1;
			}
			else if ( line <17 )
			{
				if (subpage < 8)
				{
					disp_ptr = ls_sls + (line-1)*16 + subpage*256;
				}
				else if (subpage < 16)
				{
					disp_ptr = ls_slc + (line-1)*16 + (subpage-8)*256;
				}
				else if (subpage < 24)
				{
					disp_ptr = sls_to_link + (line-1)*16 + (subpage-16)*256;
				}
				else
					disp_length = 0;
			}
			else
				disp_length = 0;
			break;
		
		case 8:/* E1 STATE */
			if (line == 0)
			{
				disp_ptr = &disp_page[page];
				disp_length = 1;
			}
			else if (line < 17)
			{
				if (subpage < 8)
				{
					disp_ptr = (BYTE*)&mtp3.ls[subpage*16+line-1];
					disp_length = 9;
				}
				else
					disp_length = 0;
			}
			else
				disp_length = 0;
			break;
		case 9:/* ls influence dstination table */
			if (line == 0)
			{
				disp_ptr = &disp_page[page];
				disp_length = 1;
			}
			else if (line < 18)
			{
				if (subpage < 128)
				{
					if (line < 9)
					{
						disp_ptr = (BYTE*)&mtp3.ls[subpage].influ_dstplace_intable_asNLS[(line-1)*16];
						disp_length = 16;
					}
					else if (line == 9)
					{
						disp_length = 0;
					}
					else
					{
						disp_ptr = (BYTE*)&mtp3.ls[subpage].influ_dstplace_intable_asALS[(line-10)*16];
						disp_length = 16;
					}
				}
				else
					disp_length = 0;
			}
			else if (line == 18)
				disp_length = 0;
			else if (line == 19)
			{
				disp_ptr = (BYTE*)&mtp3.ls[subpage];
				disp_length = 9;
			}
			else
				disp_length = 0;
			break;

		case 10:/* isup watch dog */
			if (line == 0)
			{
				disp_ptr = &disp_page[page];
				disp_length = 1;
			}
			else if (line < 9)
			{
				disp_ptr = (BYTE*)&mtp3.nw[page].flow.isup_detail[(line-1)*16];
				disp_length = 16;
			}
			else
				disp_length = 0;
			break;
		case 11:/* watch dog */
			if (line < 16)
			{
				disp_ptr = (BYTE*)&mtp3ObjState.MTP3WatchDog[line*16];
				disp_length = 16;
			}
			else
				disp_length = 0;
			break;
		default:
			disp_length = 0;
			break;
	}	
	return disp_length;
}

void	mtp_disp_page(BYTE page)
{
	BYTE	disp_line;
	BYTE	disp_length;
	DWORD	object_id[20];//for test
	
/* object_id head */
	object_id[0]	= 1;
	object_id[1]	= 3;
	object_id[2]	= 6;
	object_id[3]	= 1;
	object_id[4]	= 4;
	object_id[5]	= 1;
	object_id[6]	= 1373;
	object_id[7]	= 1;
	object_id[8]	= 1;
	object_id[9]	= 2;
/* object_id head */

	object_id[10]  = 3;
	object_id[11]  = 1;

	object_id[12] = 2;
	object_id[13] = MTP3_DEBUG_ID + 2;
	object_id[14] = 5 + page;//page	
	//object_id[3] = 2;//line
	object_id[16] = 0;//instance	
	
	for (disp_line = 0; disp_line < 22; disp_line++)
	{
		disp_length = mtp_disp_line(page,disp_line);
		object_id[15] = disp_line + 2;//line
//		debug_set_response(17,object_id,&disp_length,10);
		object_id[16] = 2;//data pointer
		debug_set_response(17,object_id,disp_ptr,disp_length);
	}
}

int	mtp_debug_set()
{
	BYTE	page;
	BYTE	data[10];
	BYTE 	*ptr;
	DWORD	object_id[20];//for test
	BYTE	mtp3_ver[20] = MTP3_VERSION;

	sprintf(mtp3_ver,"R%dV%d_%03d",mtp3_ver[0],mtp3_ver[1],mtp3_ver[2]);
	
	mtpi_m();
	
	ptr = data;

/* object_id head */
	object_id[0]	= 1;
	object_id[1]	= 3;
	object_id[2]	= 6;
	object_id[3]	= 1;
	object_id[4]	= 4;
	object_id[5]	= 1;
	object_id[6]	= 1373;
	object_id[7]	= 1;
	object_id[8]	= 1;
	object_id[9]	= 2;
/* object_id head */
	object_id[10]   = 3;
	object_id[11]   = 1;

	object_id[12] = 2;
	object_id[13] = MTP3_DEBUG_ID+2;
	object_id[14] = 1;
	object_id[15] = 0;//instance
	
	data[0] = 1;//active this module
	
	debug_set_response(16,object_id,data,1);
	object_id[14] = 2;
	debug_set_response(15,object_id,mtp3_ver,strlen(mtp3_ver));//module name
	object_id[14] = 3;
	debug_set_response(15,object_id,mtp_asciin_buf,80);//ascii in buf
	object_id[14] = 4;
	debug_set_response(15,object_id,mtp_asciout_buf,4096);//ascii out buf
	
	
	object_id[15] = 1;//TITLE
//	object_id[16] = 2;//instance
	for (page = 1; page < 16; page ++)
	{
		switch (page)
		{
			case 1:
				ptr = title1_p;/*measure*/
				break;
			case 2:
				ptr = title2_p;
				break;
			case 3:
				ptr = title3_p;/* MIB1 */
				break;
			case 4:
				ptr = title4_p;/* MIB2 */
				break;
			case 5://page 1
				ptr = title5_p;
				break;
			case 6:
				ptr = title6_p;
				break;
			case 7:
				ptr = title7_p;
				break;
			case 8:
				ptr = title8_p;
				break;
			case 9:
				ptr = title9_p;
				break;
			case 10:
				ptr = title10_p;
				break;
			case 11:
				ptr = title11_p;
				break;
			default:
				continue;
		}
		object_id[14] = 5 + page;
		debug_set_response(17,object_id,ptr,strlen(ptr));
		mtp_disp_page(page);
	}
	
	return 1;
}

int	mtp_send_ascout(BYTE *out_str)
{
#ifdef _WXC_TEST
	if( strlen(out_str) < MTP_MAX_ASCIIOUT_LEN )
	    printf("[MTP3]\n%s" ,out_str );
#else
	int out_len;
	
	out_len = strlen(out_str);
		
	if (out_len + strlen(mtp_asciout_buf) > MTP_MAX_ASCIIOUT_LEN - 2)
	{
		mtp3DebugFull = 1;
		return 0;
//		strcpy(mtp_asciout_buf,out_str);
	}
	else
		strcat(mtp_asciout_buf,out_str);
#endif
	return 1;
}

void mtp3_type_command(BYTE *ascin_ptr,BYTE option)
{
	BYTE	info_str[80];
	BYTE	*tmp_ptr;
	int		link;
	unsigned long		one=1;
	BYTE	inputValue;
	int		lsx16;
	int		i;

	if (strstr(ascin_ptr,"link all") != NULL)
	{
		if (option == 0)/* off */
		{
			debug_mask=debug_mask & (~(one<<MTP3DB_ALLLKON));
			mtp_send_ascout("all link off\n\r");
			memset(debug_link,MTP3_MSGLOG_OFF,256);
		}
		else
		{
			debug_mask=debug_mask | option<<MTP3DB_ALLLKON;
			mtp_send_ascout("all link on\n\r");
			memset(debug_link,MTP3_MSGLOG_ON,256);
		}
	}
	else if (strstr(ascin_ptr,"tup") != NULL)
	{
		if (option == 0)/* off */
		{
			debug_mask=debug_mask & (~(one<<MTP3DB_TUPMSG));
			mtp_send_ascout("tup message off\n\r");
		}
		else
		{
			debug_mask=debug_mask | one<<MTP3DB_TUPMSG;
			mtp_send_ascout("tup message on\n\r");
		}
	}
	else if (strstr(ascin_ptr,"isup") != NULL)
	{
		if (option == 0)/* off */
		{
			mtp_send_ascout("isup message off\n\r");
			debug_mask=debug_mask & (~(one<<MTP3DB_ISUPMSG));
		}
		else
		{
			mtp_send_ascout("isup message on\n\r");
			debug_mask=debug_mask | option<<MTP3DB_ISUPMSG;
		}
	}
	else if (strstr(ascin_ptr,"bicc") != NULL)
	{
		if (option == 0)/* off */
		{
			mtp_send_ascout("bicc message off\n\r");
			debug_mask=debug_mask & (~(one<<MTP3DB_BICCMSG));
		}
		else
		{
			mtp_send_ascout("bicc message on\n\r");
			debug_mask=debug_mask | option<<MTP3DB_BICCMSG;
		}
	}
	else if (strstr(ascin_ptr,"sccp") != NULL)
	{
		if (option == 0)/* off */
		{
			mtp_send_ascout("sccp message off\n\r");
			debug_mask=debug_mask & (~(one<<MTP3DB_SCCPMSG));
		}
		else
		{
			mtp_send_ascout("sccp message on\n\r");
			debug_mask=debug_mask | option<<MTP3DB_SCCPMSG;
		}
	}
	else if (strstr(ascin_ptr,"snm") != 0)
	{
		if (option == 0)/* off */
		{
			mtp_send_ascout("snm message off\n\r");
			debug_mask=debug_mask & (~(one<<MTP3DB_SNMMSG));
		}
		else
		{
			mtp_send_ascout("snm message on\n\r");
			debug_mask=debug_mask | option<<MTP3DB_SNMMSG;
		}
	}
	else if (strstr(ascin_ptr,"event") != NULL)
	{
		if (option == 0)/* off */
		{
			mtp_send_ascout("event off\n\r");
			debug_mask=debug_mask & (~(one<<MTP3DB_EVENT));
		}
		else
		{
			mtp_send_ascout("event on\n\r");
			debug_mask=debug_mask | option<<MTP3DB_EVENT;
		}
	}
	else if (strstr(ascin_ptr,"error") != NULL)
	{
		if (option == 0)/* off */
		{
			mtp_send_ascout("error logs off\n\r");
			debug_mask=debug_mask & (~(one<<MTP3DB_ERROR));
		}
		else
		{
			mtp_send_ascout("error logs on\n\r");
			debug_mask=debug_mask | option<<MTP3DB_ERROR;
		}
	}
	else if (strstr(ascin_ptr,"mtp3hb") != NULL)
	{
		if (option == 0)/* off */
		{
			mtp_send_ascout("mtp3 heartbeat off\n\r");
			debug_mask=debug_mask & (~(one<<MTP3DB_PFHB));
		}
		else
		{
			mtp_send_ascout("mtp3 heartbeat on\n\r");
			debug_mask=debug_mask | option<<MTP3DB_PFHB;
		}
	}
	else if (strstr(ascin_ptr,"internal") != NULL)
	{
		if (option == 0)/* off */
		{
			mtp_send_ascout("messages from server to server off\n\r");
			debug_mask=debug_mask & (~(one<<MTP3DB_APP_APP_MSG));
		}
		else
		{
			mtp_send_ascout("messages from server to server on\n\r");
			debug_mask=debug_mask | option<<MTP3DB_APP_APP_MSG;
		}
	}
	else if (strstr(ascin_ptr,"primitive") != NULL)
	{
		if (option == 0)/* off */
		{
			mtp_send_ascout("primitive between MTP3 and MTP2 off\n\r");
			debug_mask=debug_mask & (~(one<<MTP3DB_PRIMITIVE_MSG));
		}
		else
		{
			mtp_send_ascout("primitive between MTP3 and MTP2 on\n\r");
			debug_mask=debug_mask | option<<MTP3DB_PRIMITIVE_MSG;
		}
	}
	else if ((tmp_ptr=strstr(ascin_ptr,"link="))!=NULL)
	{
		strcpy(info_str,"\0");
		link = atol(&tmp_ptr[5]);
		if (link < 256)
		{
			if (option == 1)
			{
				debug_link[link] = MTP3_MSGLOG_ON;
				sprintf(info_str,"link %d ON\n\r",link);
				mtp_send_ascout(info_str);
			}
			else
			{
				debug_link[link] = MTP3_MSGLOG_OFF;
				sprintf(info_str,"link %d OFF\n\r",link);
				mtp_send_ascout(info_str);
				debug_mask=debug_mask & (~(one<<MTP3DB_ALLLKON));
			}
		}
	}
	else if ((tmp_ptr=strstr(ascin_ptr,"linkset="))!=NULL)
	{
		strcpy(info_str,"\0");
		inputValue = atol(&tmp_ptr[8]);
		if (inputValue < 128)
		{
			if (option == 1)
			{
				sprintf(info_str,"linkset %d ON\n\r",inputValue);
				mtp_send_ascout(info_str);
			}
			else
			{
				sprintf(info_str,"linkset %d OFF\n\r",inputValue);
				mtp_send_ascout(info_str);
			}
			lsx16 = inputValue << 4;
			for (i=0;i<16;i++)
			{
				link = ls_slc[lsx16+i];
				if (mtp3ObjState.lk_configured[link] == PARA_CONFIGURED)
				{
					if (option == 1)
						debug_link[link] = MTP3_MSGLOG_ON;
					else
						debug_link[link] = MTP3_MSGLOG_OFF;
				}
			}
		}
	}
	else
	{
		sprintf(info_str,"command error\n\r");
		mtp_send_ascout(info_str);
	}
}

void mtp3_help_page()
{
	mtp_send_ascout("MTP3 HELP PAGE\n\r");
	mtp_send_ascout("log [tup/isup/bicc/sccp/snm] on/off\n\r");
	mtp_send_ascout("log [link=x/linkset=x/link all] on/off\n\r");
//	mtp_send_ascout("log internal on/off: messages between server\n\r");
	mtp_send_ascout("log [error/event/mtp3hb/primitive] on/off\n\r");
	mtp_send_ascout("log all\n\r");
	mtp_send_ascout("log none\n\r");
	mtp_send_ascout("list par.x nStart: (parameters(from nStart),32 lines every time)\n\r");
	mtp_send_ascout("  x=opc:  OPC\n\r");
	mtp_send_ascout("  x=link: Link attribute\n\r");
	mtp_send_ascout("  x=ls:   Linkset attribute\n\r");
	mtp_send_ascout("  x=int:  International network routine\n\r");
	mtp_send_ascout("  x=ints: International network(s) routine\n\r");
	mtp_send_ascout("  x=nat:  National network routine\n\r");
	mtp_send_ascout("  x=nats: National network(s) routine\n\r");
	mtp_send_ascout("list route.x: SPC status(x=0-3,for four network)\n\r");
	mtp_send_ascout("list log status: list which log has been openned\n\r");
}

int mtp3_show_parameter(BYTE option,BYTE value);
void mtp_m_rt()
{
	BYTE	page;
	int		input;
	BYTE	*ascin_ptr;
	BYTE	info_str[80];
	BYTE	*tmp_ptr;

	ascin_ptr = &mtp_asciin_buf[1];
	if (strlen(mtp_asciin_buf) > 0)
	{
		page = mtp_asciin_buf[0];
		if (( page < 11) && (page > 1))
		{
			disp_page[page-1] = atoi(ascin_ptr);
			mtp_disp_page(page-1);
		}
		if (strcmp(ascin_ptr,"C") == 0)
		{
			memset(&mtp3.nw[0].flow,0,sizeof(struct mtp3_flow));
			memset(&mtp3.nw[1].flow,0,sizeof(struct mtp3_flow));
			memset(&mtp3.nw[2].flow,0,sizeof(struct mtp3_flow));
			memset(&mtp3.nw[3].flow,0,sizeof(struct mtp3_flow));
			memset(mtp3ObjState.MTP3WatchDog,0,256);
		}
		else if (strstr(ascin_ptr,"list") != NULL)
		{
			if (strncmp(ascin_ptr,"list par.opc",12) == 0)
			{
				mtp3_show_parameter(0,0);
			}
			else if (strncmp(ascin_ptr,"list par.link",13) == 0)
			{
				input = atol(&ascin_ptr[13]);
				mtp3_show_parameter(1,input);
			}
			else if (strncmp(ascin_ptr,"list par.ls",11) == 0)
			{
				input = atol(&ascin_ptr[11]);
				mtp3_show_parameter(2,input);
			}
			else if (strncmp(ascin_ptr,"list par.ints",13) == 0)
			{
				input = atol(&ascin_ptr[13]);
				mtp3_show_parameter(4,input);
			}
			else if (strncmp(ascin_ptr,"list par.int",12) == 0)
			{
				input = atol(&ascin_ptr[12]);
				mtp3_show_parameter(3,input);
			}
			else if (strncmp(ascin_ptr,"list par.nats",13) == 0)
			{
				input = atol(&ascin_ptr[13]);
				mtp3_show_parameter(6,input);
			}
			else if (strncmp(ascin_ptr,"list par.nat",12) == 0)
			{
				input = atol(&ascin_ptr[12]);
				mtp3_show_parameter(5,input);
			}
			else if (strncmp(ascin_ptr,"list par.sg",11) == 0)
			{
				input = atol(&ascin_ptr[12]);
				mtp3_show_parameter(7,input);
			}
			else if (strncmp(ascin_ptr,"list route.",11) == 0)
			{
				input = atol(&ascin_ptr[11]);
				mtp3_show_routine_status(input);
			}
			else if (strncmp(ascin_ptr,"list rt.",8) == 0)
			{
				input = atol(&ascin_ptr[8]);
				mtp3_show_routine_status_sorted(input);
			}
			else if (strstr(ascin_ptr,"list log status") != NULL)
			{
				mtp3_list_log_status();
			}
			if (strncmp(ascin_ptr,"list link.",10) == 0)
			{
				input = atol(&ascin_ptr[10]);
				mtp3_list_link(input);
			}
		}
		else if (strstr(ascin_ptr,"log all") != NULL)
		{
			debug_mask = debug_mask | 0xfffffaff;//not concern mtp3 hb & primitive
//			debug_mask = 0xffffffff;
			memset(debug_link,MTP3_MSGLOG_ON,256);
			mtp_send_ascout("all logs on\n\r");
		}
		else if( strstr(ascin_ptr, "net cap start") !=NULL )
	    {
	       mtp3_send_netcap = 1;
	       mtp_send_ascout("mtp3 send netcap start");
        }
        else if( strstr(ascin_ptr, "net cap stop") !=NULL )
	    {
	       mtp3_send_netcap = 0;
	       mtp_send_ascout("mtp3 send netcap end");   
	    }
		else if (strstr(ascin_ptr,"log none") != NULL)
		{
			debug_mask = 0;
			memset(debug_link,MTP3_MSGLOG_OFF,256);
			mtp_send_ascout("all logs off\n\r");
		}
		else if ((tmp_ptr=strstr(ascin_ptr,"log"))!=NULL)
		{
			if (strstr(ascin_ptr,"on") != NULL)
				mtp3_type_command(tmp_ptr,1);
			else if (strstr(ascin_ptr,"off") != NULL)
				mtp3_type_command(tmp_ptr,0);
			else
				mtp_send_ascout("command error\n\r");
		}

		else if (strcmp(ascin_ptr,"current portion")==0)
		{
			sprintf(info_str,"current portion is %ld\n\r",mtp3_csta_p);
			mtp_send_ascout(info_str);
		}

		else if (strcmp(ascin_ptr,"restart")==0)
		{
			sprintf(info_str,"mtp3 restarting...\n\r");
			mtp_send_ascout(info_str);
			reset_mtp3();
		}

		else if (strcmp(ascin_ptr,"reload parameters")==0)
		{
			sprintf(info_str,"reloading mtp3 parameters...\n\r");
			mtp_send_ascout(info_str);
			mtp3_reload_data();
		}
		
		else if (strcmp(ascin_ptr,"save parameters")==0)
		{
			sprintf(info_str,"saving mtp3 parameters...\n\r");
			mtp_send_ascout(info_str);
			mtp3_write_parameter();
		}

		else if ( (strstr(ascin_ptr,"HELP") != NULL)	|
				  (strstr(ascin_ptr,"help") != NULL)	)
		{
			mtp3_help_page();
		}
		else if (strstr(ascin_ptr,"Activate") != NULL)
		{
			MTP3_activate(mtp3_localip);//deactivate alternative mtp3
		}
		else if (strstr(ascin_ptr,"Deactivate") != NULL)
		{
			MTP3_deactivate(mtp3_localip);//deactivate alternative mtp3
		}

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

int	mtp_hex_to_ascii(BYTE *from_hex,WORD from_len, BYTE *to_asc)
{
	int	i,j;

	if(from_len > 300)
	{
		mtp3_debug(MTP3DB_ERROR,"mtp_hex_to_ascii, length longer than 300, len=%d!", from_len);
		from_len = 300;
	}
	j = 0;
	for (i = 0; i< from_len; i++)
	{
		to_asc[j] = ascii[from_hex[i] >> 4];
		j++;
		to_asc[j] = ascii[from_hex[i] & 0x0f];
		j++;
		to_asc[j] = 0x20;
		j++;
	}
	to_asc[j] = '\0';
	return 1;
}

void mtp3_showbuf(int n,BYTE *msg,int len)
{
	char	info_str[1024];
	unsigned long		one=1;

	if (mtp3DebugFull == 1)
		return;

	if (((one << n) & debug_mask) == 0)
		return;

	mtp_hex_to_ascii(msg,len,info_str);
	strcat(info_str,"\n\r");
	mtp_send_ascout(info_str);
}

void slt_message_decode(BYTE code,char *c)
{
	switch (code)
	{
		case SIGNAL_SLTM:
			sprintf(c,"SLTM");
			break;
		case SIGNAL_SLTA:
			sprintf(c,"SLTA");
			break;
		default:
			sprintf(c,"UNK");
			break;
	}
}

void snm_message_decode(BYTE code,char *c)
{
	switch (code)
	{
		case SIGNAL_TFA:
			sprintf(c,"TFA");
			break;
		case SIGNAL_TFP:
			sprintf(c,"TFP");
			break;
		case SIGNAL_TRA:
			sprintf(c,"TRA");
			break;
		case SIGNAL_RST:
			sprintf(c,"RST");
			break;
		case SIGNAL_COO:
			sprintf(c,"COO");
			break;
		case SIGNAL_COA:
			sprintf(c,"COA");
			break;
		case SIGNAL_CBD:
			sprintf(c,"CBD");
			break;
		case SIGNAL_CBA:
			sprintf(c,"CBA");
			break;
		case SIGNAL_ECO:
			sprintf(c,"ECA");
			break;
		case SIGNAL_ECA:
			sprintf(c,"ECA");
			break;
		case SIGNAL_LIN:
			sprintf(c,"LIN");
			break;
		case SIGNAL_LUN:
			sprintf(c,"LUN");
			break;
		case SIGNAL_LIA:
			sprintf(c,"LIA");
			break;
		case SIGNAL_LUA:
			sprintf(c,"LUA");
			break;
		case SIGNAL_LID:
			sprintf(c,"LID");
			break;
		case SIGNAL_LFU:
			sprintf(c,"LFU");
			break;
		case SIGNAL_LLT:
			sprintf(c,"LLT");
			break;
		case SIGNAL_LRT:
			sprintf(c,"LRT");
			break;
		default:
			sprintf(c,"UNK");
			break;

	}
}

void sccp_message_decode(BYTE code,char *c)
{
	switch (code)
	{
		case MTP3_SCCP_CR:
			sprintf(c,"CR");
			break;
		case MTP3_SCCP_CC:
			sprintf(c,"CC");
			break;
		case MTP3_SCCP_CREF:
			sprintf(c,"CREF");
			break;
		case MTP3_SCCP_RLSD:
			sprintf(c,"RLSD");
			break;
		case MTP3_SCCP_RLC:
			sprintf(c,"RLC");
			break;
		case MTP3_SCCP_DT1:
			sprintf(c,"DT1");
			break;
		case MTP3_SCCP_DT2:
			sprintf(c,"DT2");
			break;
		case MTP3_SCCP_AK:
			sprintf(c,"AK");
			break;
		case MTP3_SCCP_UDT:
			sprintf(c,"UDT");
			break;
		case MTP3_SCCP_UDTS:
			sprintf(c,"UDTS");
			break;
		case MTP3_SCCP_ED:
			sprintf(c,"ED");
			break;
		case MTP3_SCCP_EA:
			sprintf(c,"EA");
			break;
		case MTP3_SCCP_RSR:
			sprintf(c,"RSR");
			break;
		case MTP3_SCCP_RSC:
			sprintf(c,"RSC");
			break;
		case MTP3_SCCP_ERR:
			sprintf(c,"ERR");
			break;
		case MTP3_SCCP_IT:
			sprintf(c,"IT");
			break;
		case MTP3_SCCP_XUDT:
			sprintf(c,"XUDT");
			break;
		case MTP3_SCCP_XUDTS:
			sprintf(c,"XUDTS");
			break;
		case MTP3_SCCP_LUDT:
			sprintf(c,"LUDT");
			break;
		case MTP3_SCCP_LUDTS:
			sprintf(c,"LUDTS");
			break;
		default:
			sprintf(c,"UNK");
			break;
	}
}

void tup_message_decode(BYTE code,char *c)
{
	switch (code)
	{
		case MTP3_TUP_IAM:
			sprintf(c,"IAM");
			break;
		case MTP3_TUP_IAI:
			sprintf(c,"IAI");
			break;
		case MTP3_TUP_SAM:
			sprintf(c,"SAM");
			break;
		case MTP3_TUP_SAO:
			sprintf(c,"SAO");
			break;
		case MTP3_TUP_GSM:
			sprintf(c,"GSM");
			break;
		case MTP3_TUP_COT:
			sprintf(c,"COT");
			break;
		case MTP3_TUP_GRQ:
			sprintf(c,"GRQ");
			break;
		case MTP3_TUP_ACM:
			sprintf(c,"ACM");
			break;
		case MTP3_TUP_SEC:
			sprintf(c,"SEC");
			break;
		case MTP3_TUP_CGC:
			sprintf(c,"CGC");
			break;
		case MTP3_TUP_CFL:
			sprintf(c,"CFL");
			break;
		case MTP3_TUP_SSB:
			sprintf(c,"SSB");
			break;
		case MTP3_TUP_UNN:
			sprintf(c,"UNN");
			break;
		case MTP3_TUP_LOS:
			sprintf(c,"LOS");
			break;
		case MTP3_TUP_SST:
			sprintf(c,"SST");
			break;
		case MTP3_TUP_ACB:
			sprintf(c,"ACB");
			break;
		case MTP3_TUP_DPN:
			sprintf(c,"DPN");
			break;
		case MTP3_TUP_ANU:
			sprintf(c,"ANU");
			break;
		case MTP3_TUP_ANC:
			sprintf(c,"ANC");
			break;
		case MTP3_TUP_ANN:
			sprintf(c,"ANN");
			break;
		case MTP3_TUP_CBK:
			sprintf(c,"CBK");
			break;
		case MTP3_TUP_CLF:
			sprintf(c,"CLF");
			break;
		case MTP3_TUP_CCL:
			sprintf(c,"CCL");
			break;
		case MTP3_TUP_RLG:
			sprintf(c,"RLG");
			break;
		case MTP3_TUP_BLO:
			sprintf(c,"BLO");
			break;
		case MTP3_TUP_BLA:
			sprintf(c,"BLA");
			break;
		case MTP3_TUP_UBL:
			sprintf(c,"UBL");
			break;
		case MTP3_TUP_UBA:
			sprintf(c,"UBA");
			break;
		case MTP3_TUP_ADI:
			sprintf(c,"ADI");
			break;
		default:
			sprintf(c,"UNK");
			break;
	}
}

void isup_message_decode(BYTE code,char *c)
{
	switch (code)
	{
		case MTP3_ISUP_IAM:
			sprintf(c,"IAM");
			break;
		case MTP3_ISUP_ACM:
			sprintf(c,"ACM");
			break;
		case MTP3_ISUP_CPG:
			sprintf(c,"CPG");
			break;
		case MTP3_ISUP_ANM:
			sprintf(c,"ANM");
			break;
		case MTP3_ISUP_REL:
			sprintf(c,"REL");
			break;
		case MTP3_ISUP_RLC:
			sprintf(c,"RLC");
			break;
		case MTP3_ISUP_UBL:
			sprintf(c,"UBL");
			break;
		case MTP3_ISUP_UBA:
			sprintf(c,"UBA");
			break;
		case MTP3_ISUP_GRA:
			sprintf(c,"GRA");
			break;
		default:
			sprintf(c,"UNK");
			break;
	}
}

BOOL iptrans_msg_flow(BYTE *msg,BYTE pclen,int direction,DWORD dest_ip)
{
	char	info_str[1024];
	long	dpc=0;
	long	opc=0;
	BYTE	sls;
	char	tempbuf[1024];
	long	route_mark;
	BYTE	sio;
	struct	timeval tv;
	struct	timezone tz;
	struct	tm *t;
	BYTE	ssf;
	unsigned long		one=1;
	struct in_addr	in;
	BOOL	msg2mtp2;
	char	type[10];
	BYTE	nw;
	char	netID[10];
	char	codeName[16];
	int  msg_len;
	
	if (mtp3DebugFull == 1)
		return 0;
	
	in.s_addr = dest_ip;

/*	if (((dest_ip & E1CARD_BASE_IP_MASK) == E1CARD_BASE_IP) &&
		(((dest_ip >> 16) & 0xff) < 32))*/
	if (msg[0] < 255)
	{
		msg2mtp2 = TRUE;
	}
	else
		msg2mtp2 = FALSE;

	sio = msg[3];
	nw = (sio >> 6) & 3;
	
	switch (nw)
	{
		case 0:
			sprintf(netID,"INAT");
			break;
		case 1:
			sprintf(netID,"INATs");
			break;
		case 2:
			sprintf(netID,"NAT");
			break;
		case 3:
			sprintf(netID,"NATs");
			break;
	}
	
	if (pclen == MTP3_24BIT_PC)
	{
		memcpy((BYTE *)&dpc,&msg[4],3);
		memcpy((BYTE *)&opc,&msg[7],3);
		sls = msg[10] & 0x0f;
	}
	else
	{
		memcpy((BYTE*)&route_mark,&msg[4],4);
		dpc = route_mark & 0x3FFF;
		opc = (route_mark & 0x0FFFFFFF) >> 14;
		sls = (route_mark >> 28) & 0x0f;
	}

	if (debug_link[msg[0]] != MTP3_MSGLOG_ON)
	{
		if (msg2mtp2 == TRUE)
			return 0;
	}

	{
		msg_len = (msg[1]<<8) + msg[2];
		if(msg_len > 300)
		{		
			mtp3_debug(MTP3DB_ERROR,"Get message in iptrans_msg_flow, length longer than 300!");
			msg[1]=0;
		}
	
	}
	ssf= sio & 0x0f;
	switch (ssf)
	{
		case TUP_SIO:
			if (((one << MTP3DB_TUPMSG) & debug_mask) == 0)
				return 0;
			sprintf(type,"TUP");
			if (pclen == MTP3_24BIT_PC)
				tup_message_decode(msg[12],codeName);
			else
				tup_message_decode(msg[9],codeName);
			break;
		case ISUP_SIO:
			if (((one << MTP3DB_ISUPMSG) & debug_mask) == 0)
				return 0;
			sprintf(type,"ISUP");
			if (pclen == MTP3_24BIT_PC)
				isup_message_decode(msg[13],codeName);
			else
				isup_message_decode(msg[10],codeName);
			break;
		case BICC_SIO:
			if (((one << MTP3DB_BICCMSG) & debug_mask) == 0)
				return 0;
			sprintf(type,"BICC");
			if (pclen == MTP3_24BIT_PC)
				isup_message_decode(msg[13],codeName);
			else
				isup_message_decode(msg[10],codeName);
			break;
		case SCCP_SIO:
			if (((one << MTP3DB_SCCPMSG) & debug_mask) == 0)
				return 0;
			sprintf(type,"SCCP");
			if (pclen == MTP3_24BIT_PC)
				sccp_message_decode(msg[11],codeName);
			else
				sccp_message_decode(msg[8],codeName);
			break;
		case SNM_SIO:
			if (((one << MTP3DB_SNMMSG) & debug_mask) == 0)
				return 0;
			sprintf(type,"SNM");
			if (pclen == MTP3_24BIT_PC)
				snm_message_decode(msg[11],codeName);
			else
				snm_message_decode(msg[8],codeName);
			break;
		case TM_SIO:
			if (((one << MTP3DB_SNMMSG) & debug_mask) == 0)
				return 0;
			sprintf(type,"SLT");
			if (pclen == MTP3_24BIT_PC)
				slt_message_decode(msg[11],codeName);
			else
				slt_message_decode(msg[8],codeName);
			break;
		default:
			return 0;
	}

	gettimeofday(&tv,&tz);
	t = localtime(&tv.tv_sec);
	switch (direction)
	{
		case MTP_MSG_UP:
			if (msg2mtp2 == TRUE)
				sprintf(info_str,"%s-%s(%02d:%02d:%02d.%06ld):MTP3<==MTP2,%dB %s SPC(%lx->%lx) SLS=%x LI=%x srcLINK=%03d srcIP=%s\r\n",
				type,codeName,t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec,pclen,netID,opc,dpc,sls,(msg[1]<<8)+msg[2],msg[0],inet_ntoa(in));
			else
			{
				if (((one << MTP3DB_APP_APP_MSG) & debug_mask) != 0)
					sprintf(info_str,"%s-%s(%02d:%02d:%02d.%06ld):MTP3<==MTP3,%dB %s SPC(%lx->%lx) SLS=%x LI=%x srcIP=%s\r\n",
				type,codeName,t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec,pclen,netID,opc,dpc,sls,(msg[1]<<8)+msg[2],inet_ntoa(in));
				else
					return 0;
			}
			mtp_hex_to_ascii(msg, (msg[1]<<8)+msg[2]+3,tempbuf);
			strcat(info_str,tempbuf);
			strcat(info_str,"\n\r");
			mtp_send_ascout(info_str);
			return 1;
			break;
		case MTP_MSG_DOWN:
			sprintf(info_str,"%s-%s(%02d:%02d:%02d.%06ld):MTP3<==USER,%s DPC=%lx SLS=%x\n\rPerform routing:MTP3==>MTP2,%dB SPC(%lx->%lx) LI=%02x dstLINK=%03d dstIP=%s\r\n",
			type,codeName,t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec,netID,dpc,sls,pclen,opc,dpc,(msg[1]<<8)+msg[2],msg[0],inet_ntoa(in));
			break;
		case MTP_MSG_STP:
			sprintf(info_str,"%s-%s(%02d:%02d:%02d.%06ld)Perform STP:MTP3==>MTP2,SPC(%lx->%lx) dstLINK=%x dstIP=%s\r\n",
			type,codeName,t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec,opc,dpc,msg[0],inet_ntoa(in));
			break;
		case MTP_MSG_OTHER_SERVER:
			if (msg2mtp2 == TRUE)
				sprintf(info_str,"%s%s(%02d:%02d:%02d.%06ld):MTP3<==USER, %s DPC=%lx SLS=%x\n\rRouting by UP:MTP3==>MTP2,%dB SPC(%lx->%lx) LI=%02x dstLINK=%03d dstIP=%s\r\n",
			type,codeName,t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec,netID,dpc,sls,pclen,opc,dpc,(msg[1]<<8)+msg[2],msg[0],inet_ntoa(in));
			else
			{
				if (((one << MTP3DB_APP_APP_MSG) & debug_mask) != 0)
					sprintf(info_str,"%s-%s(%02d:%02d:%02d.%06ld):MTP3<==USER, %s  DPC=%lx  SLS=%x\n\rRouting by UP:MTP3==>MTP3,%dB SPC(%lx->%lx) LI=%02x dstIP=%s\r\n",
				type,codeName,t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec,netID,dpc,sls,pclen,opc,dpc,(msg[1]<<8)+msg[2],inet_ntoa(in));
				else
					return 0;
			}
			break;
		case MTP_SNM_MSG:
			sprintf(info_str,"%s-%s(%02d:%02d:%02d.%06ld):MTP3==>MTP2,%dB %s SPC(%lx->%lx) SLS=%d LI=%02x dstLINK=%03d dstIP=%s\r\n",
type,codeName,t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec,pclen,netID,opc,dpc,sls,(msg[1]<<8)+msg[2],msg[0],inet_ntoa(in));
			mtp_hex_to_ascii(msg,(msg[1]<<8)+msg[2]+3,tempbuf);
			strcat(info_str,tempbuf);
			strcat(info_str,"\n\r");
			mtp_send_ascout(info_str);
			return 1;
			break;
	}
	mtp_hex_to_ascii(msg,(msg[1]<<8)+msg[2]+3,tempbuf);
	strcat(info_str,tempbuf);
	strcat(info_str,"\n\r\n\r");
	mtp_send_ascout(info_str);
	return 1;
}

BOOL iptrans_msg_flow_2(up_message *up_msg_ptr)
{
	char	info_str[1024];
	char	tempbuf[1024];
	BYTE	sio;
	struct	timeval tv;
	struct	timezone tz;
	struct	tm *t;
	unsigned long		one=1;
	char	type[10];
	BYTE	nw;
	char	netID[10];
	char	codeName[16];
	
	if (mtp3DebugFull == 1)
		return 0;

		if(up_msg_ptr->len > 300)
		{		
			mtp3_debug(MTP3DB_ERROR,"Get message in iptrans_msg_flow_2, length longer than 300!");
			up_msg_ptr->len = 300;
		}	
	sio = up_msg_ptr->sio;
	nw = (sio >> 6) & 3;
	
	switch (nw)
	{
		case 0:
			sprintf(netID,"INAT");
			break;
		case 1:
			sprintf(netID,"INATs");
			break;
		case 2:
			sprintf(netID,"NAT");
			break;
		case 3:
			sprintf(netID,"NATs");
			break;
	}
	
	if (((one << MTP3DB_SCCPMSG) & debug_mask) == 0)
		return 0;
	
	sprintf(type,"SCCP");
	sccp_message_decode(up_msg_ptr->msgList[0],codeName);

	gettimeofday(&tv,&tz);
	t = localtime(&tv.tv_sec);
	sprintf(info_str,"%s-%s(%02d:%02d:%02d.%06ld):MTP3LITE==>USER,%s LI=%x srcLINK=%03d\r\n",
		type,codeName,t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec,netID,up_msg_ptr->len,up_msg_ptr->link);
	mtp_hex_to_ascii(&up_msg_ptr->msgList[0], up_msg_ptr->len, tempbuf);
	strcat(info_str,tempbuf);
	strcat(info_str,"\n\r\n\r");
	mtp_send_ascout(info_str);
	
	return 1;
}

void mtp3_debug(int n,const char *fmt,...)
{
	char	info_str[1024];
	char	tempbuf[1024];
	va_list	ap;
    unsigned long           one=1;
	struct timeval tv;
	struct timezone tz;
	struct tm *t;

	if (mtp3DebugFull == 1)
		return;

    if(((one<<n) & debug_mask)==0)
	{
		if (n != MTP3DB_CMD)
			return;
	}


	va_start(ap,fmt);
	vsprintf(info_str, fmt, ap);
	va_end(ap);

	gettimeofday(&tv,&tz);
	t = localtime(&tv.tv_sec);

	switch (n)
	{
		case MTP3DB_EVENT:
			strcat(info_str,"\n\r");
			mtp_send_ascout(info_str);
			break;
		case MTP3DB_SNMMSG:
			sprintf(tempbuf,"\33[36mSNM(%d:%d:%d.%ld):",t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec);
			strcat(tempbuf,info_str);
			strcat(tempbuf,"\33[0m\n\r");
			mtp_send_ascout(tempbuf);
			break;
		case MTP3DB_SCCPMSG:
			sprintf(tempbuf,"\33[36mSCCP(%d:%d:%d.%ld):",t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec);
			strcat(tempbuf,info_str);
			strcat(tempbuf,"\33[0m\n\r\n\r");
			mtp_send_ascout(tempbuf);
			break;
		case MTP3DB_ISUPMSG:
			sprintf(tempbuf,"\33[36mISUP(%d:%d:%d.%ld):",t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec);
			strcat(tempbuf,info_str);
			strcat(tempbuf,"\33[0m\n\r");
			mtp_send_ascout(tempbuf);
			break;
		case MTP3DB_TUPMSG:
			sprintf(tempbuf,"\33[36mTUP(%d:%d:%d.%ld):",t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec);
			strcat(tempbuf,info_str);
			strcat(tempbuf,"\33[0m\n\r");
			mtp_send_ascout(tempbuf);
			break;
		case MTP3DB_ERROR:
			sprintf(tempbuf,"\33[31m(%d:%d:%d.%ld)",t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec);
			strcat(tempbuf,info_str);
			strcat(tempbuf,"\33[0m\n\r");
			mtp_send_ascout(tempbuf);
			break;
		case MTP3DB_PFHB:
			sprintf(tempbuf,"(%d:%d:%d.%ld)",t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec);
			strcat(tempbuf,info_str);
			strcat(tempbuf,"\n\r");
			mtp_send_ascout(tempbuf);
			break;
		case MTP3DB_PRIMITIVE_MSG:
			sprintf(tempbuf,"(%d:%d:%d.%ld)",t->tm_hour,t->tm_min,t->tm_sec,tv.tv_usec);
			strcat(tempbuf,info_str);
			strcat(tempbuf,"\n\r");
			mtp_send_ascout(tempbuf);
			break;
		case MTP3DB_CMD:
			sprintf(tempbuf,"\33[1;33m(%d:%d:%d)",t->tm_hour,t->tm_min,t->tm_sec);
			strcat(tempbuf,info_str);
			strcat(tempbuf,"\33[0m\n\r");
			mtp_send_ascout(tempbuf);
			break;
		default:
			break;
	}
}

void mtp3_list_log_status()
{
	int	i;
	BYTE info_str[80];

	mtp_send_ascout("\33[32mmtp3 log status-->\33[0m\n\r");
	if ((debug_mask & 2) != 0)
		mtp_send_ascout("log snm \33[33mON\33[0m\n\r");
	if ((debug_mask & 4) != 0)
		mtp_send_ascout("log sccp \33[33mON\33[0m\n\r");
	if ((debug_mask & 8) != 0)
		mtp_send_ascout("log tup \33[33mON\33[0m\n\r");
	if ((debug_mask & 16) != 0)
		mtp_send_ascout("log isup \33[33mON\33[0m\n\r");
	if ((debug_mask & 32) != 0)
		mtp_send_ascout("log error \33[33mON\33[0m\n\r");
	if ((debug_mask & 64) != 0)
		mtp_send_ascout("log event \33[33mON\33[0m\n\r");
	if ((debug_mask & 256) != 0)
		mtp_send_ascout("log mtp3hb \33[33mON\33[0m\n\r");
	if ((debug_mask & 512) != 0)
		mtp_send_ascout("log internal \33[33mON\33[0m\n\r");
	if ((debug_mask & 1024) != 0)
		mtp_send_ascout("log primitive \33[33mON\33[0m\n\r");
	if ((debug_mask & 128) != 0)
	{
		mtp_send_ascout("log all link \33[33mON\33[0m\n\r");
		return;
	}
	for (i=0;i<256;i++)
	{
		if (debug_link[i] == MTP3_MSGLOG_ON)
		{
			sprintf(info_str,"log link=%d \33[33mON\33[0m\n\r",i);
			mtp_send_ascout(info_str);
		}
	}
}

void mtp3_show_routine_status(BYTE nw)
{
	int	i;
	char info_str[4096];
	char tempbuf[4096];
	nw_para	*para;
	network	*sp;
	BYTE current_rt;
	BYTE	nls;
	BYTE	als;
	static	BYTE last_show[4]={0};
	BYTE	showCount=0;
	
	nw = nw & 3;

	para = &mtp3_para->nw[nw];
	sp = &mtp3.nw[nw];
	switch (nw)
	{
	case 0:
		sprintf(info_str,"\33[33mInternational Network\n\rSPC\t\tReachable\tPath\t\tNLS\tALS\n\r\33[0m");
		break;
	case 1:
		sprintf(info_str,"\33[33mInternational Network spare\n\rSPC\t\tReachable\tPath\t\tNLS\tALS\n\r\33[0m");
		break;
	case 2:
		sprintf(info_str,"\33[33mNational Network\n\rSPC\t\tReachable\tPath\t\tNLS\tALS\n\r\33[0m");
		break;
	case 3:
		sprintf(info_str,"\33[33mNational Network spare\n\rSPC\t\tReachable\tPath\t\tNLS\tALS\n\r\33[0m");
		break;
	default:
		break;
	}
	mtp_send_ascout(info_str);
	showCount=0;
	for (i=last_show[nw];i<256;i++)
	{
		nls = para->normal_ls[i];
		als = para->alternative_ls[i];
		if ((para->dpc[i] != 0)	&&
			(nls < 128)			)
		{
			current_rt = (sp->routine[i] >> 6) & 3;
			switch (current_rt)
			{
			case 0:
				if (als < 128)
					sprintf(tempbuf,"%06lx\t\t\33[32mY\33[0m\t\tLinkset %02d\t%02d\t%02d\n\r",para->dpc[i],nls,nls,als);
				else
					sprintf(tempbuf,"%06lx\t\t\33[32mY\33[0m\t\tLinkset %02d\t%02d\t--\n\r",para->dpc[i],nls,nls);
				mtp_send_ascout(tempbuf);
				break;
			case 1:
				if (als < 128)
					sprintf(tempbuf,"%06lx\t\t\33[32mY\33[0m\t\tLinkset %02d\t%02d\t%02d\n\r",para->dpc[i],als,nls,als);
				else
					sprintf(tempbuf,"%06lx\t\t\33[32mY\33[0m\t\tLinkset %02d\t%02d\t--\n\r",para->dpc[i],als,nls);
				mtp_send_ascout(tempbuf);
				break;
			case 2:
				if (als < 128)
					sprintf(tempbuf,"%06lx\t\t\33[31mN\33[0m\t\tNo Path\t\t%02d\t%02d\n\r",para->dpc[i],nls,als);
				else
					sprintf(tempbuf,"%06lx\t\t\33[31mN\33[0m\t\tNo Path\t\t%02d\t--\n\r",para->dpc[i],nls);
				mtp_send_ascout(tempbuf);
				break;
			default:
				break;
			}
			showCount++;
		}
		if (showCount > 31)
		{
			last_show[nw] = i+1;
			break;
		}
	}
	if (i>=255)
	{
		last_show[nw] = 0;
	}
	
}

void mtp3_show_routine_status_sorted(BYTE nw)
{
	int	i;
	char info_str[4096];
	char tempbuf[4096];
	nw_para	*para;
	network	*sp;
	mtp3DPCIndex	*sort_rec;
	BYTE current_rt;
	BYTE	nls;
	BYTE	als;
	static	BYTE last_show[4]={0};
	BYTE	showCount=0;
	int		index;
	
	nw = nw & 3;

	para = &mtp3_para->nw[nw];
	sp = &mtp3.nw[nw];
	sort_rec = &mtp3SortRoutine.nw[nw];
	switch (nw)
	{
	case 0:
		sprintf(info_str,"\33[33mInternational Network\n\rSPC\t\tReachable\tPath\t\tNLS\tALS\n\r\33[0m");
		break;
	case 1:
		sprintf(info_str,"\33[33mInternational Network spare\n\rSPC\t\tReachable\tPath\t\tNLS\tALS\n\r\33[0m");
		break;
	case 2:
		sprintf(info_str,"\33[33mNational Network\n\rSPC\t\tReachable\tPath\t\tNLS\tALS\n\r\33[0m");
		break;
	case 3:
		sprintf(info_str,"\33[33mNational Network spare\n\rSPC\t\tReachable\tPath\t\tNLS\tALS\n\r\33[0m");
		break;
	default:
		break;
	}
	mtp_send_ascout(info_str);
	showCount=0;
	for (i=last_show[nw];i<sort_rec->sortedNum;i++)
	{
		index = sort_rec->index[i];
		nls = para->normal_ls[index];
		als = para->alternative_ls[index];
		if ((para->dpc[index] != 0)	&&
			(nls < 128)			)
		{
			current_rt = (sp->routine[index] >> 6) & 3;
			switch (current_rt)
			{
			case 0:
				if (als < 128)
					sprintf(tempbuf,"%06lx\t\t\33[32mY\33[0m\t\tLinkset %02d\t%02d\t%02d\n\r",para->dpc[index],nls,nls,als);
				else
					sprintf(tempbuf,"%06lx\t\t\33[32mY\33[0m\t\tLinkset %02d\t%02d\t--\n\r",para->dpc[index],nls,nls);
				mtp_send_ascout(tempbuf);
				break;
			case 1:
				if (als < 128)
					sprintf(tempbuf,"%06lx\t\t\33[32mY\33[0m\t\tLinkset %02d\t%02d\t%02d\n\r",para->dpc[index],als,nls,als);
				else
					sprintf(tempbuf,"%06lx\t\t\33[32mY\33[0m\t\tLinkset %02d\t%02d\t--\n\r",para->dpc[index],als,nls);
				mtp_send_ascout(tempbuf);
				break;
			case 2:
				if (als < 128)
					sprintf(tempbuf,"%06lx\t\t\33[31mN\33[0m\t\tNo Path\t\t%02d\t%02d\n\r",para->dpc[index],nls,als);
				else
					sprintf(tempbuf,"%06lx\t\t\33[31mN\33[0m\t\tNo Path\t\t%02d\t--\n\r",para->dpc[index],nls);
				mtp_send_ascout(tempbuf);
				break;
			default:
				break;
			}
			showCount++;
		}
		if (showCount > 31)
		{
			last_show[nw] = i+1;
			break;
		}
	}
	if (i>=sort_rec->sortedNum-1)
	{
		last_show[nw] = 0;
	}
}

int pc_length(BYTE	nw);
int mtp3_show_parameter(BYTE option,BYTE index)
{
	int	i;
	char info_str[4096];
	int	maxindex;
	char nw[20];

	switch (option)
	{
		case 0:
			mtp_send_ascout("Network\t\t\tSPC Len\t\tOPC\n\r");
			if (pc_length(0) == MTP3_24BIT_PC)
				sprintf(info_str,"International\t\t24BIT\t\t%06lx\n\r",mtp3_para->nw[0].opc24);
			else
				sprintf(info_str,"International\t\t14BIT\t\t%06lx\n\r",mtp3_para->nw[0].opc14);
			mtp_send_ascout(info_str);
			if (pc_length(1) == MTP3_24BIT_PC)
				sprintf(info_str,"International(s)\t24BIT\t\t%06lx\n\r",mtp3_para->nw[1].opc24);
			else
				sprintf(info_str,"International(s)\t14BIT\t\t%06lx\n\r",mtp3_para->nw[1].opc14);
			mtp_send_ascout(info_str);
			if (pc_length(2) == MTP3_24BIT_PC)
				sprintf(info_str,"National\t\t24BIT\t\t%06lx\n\r",mtp3_para->nw[2].opc24);
			else
				sprintf(info_str,"National\t\t14BIT\t\t%06lx\n\r",mtp3_para->nw[2].opc14);
			mtp_send_ascout(info_str);
			if (pc_length(3) == MTP3_24BIT_PC)
				sprintf(info_str,"National(s)\t\t24BIT\t\t%06lx\n\r",mtp3_para->nw[3].opc24);
			else
				sprintf(info_str,"National(s)\t\t14BIT\t\t%06lx\n\r",mtp3_para->nw[3].opc14);
			mtp_send_ascout(info_str);
			sprintf(info_str, "International Dynamic (%d): %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld\r\n", 
					mtp3_opc.opc_num[0], mtp3_opc.opc[0][0], mtp3_opc.opc[0][1], mtp3_opc.opc[0][2],
					mtp3_opc.opc[0][3], mtp3_opc.opc[0][4], mtp3_opc.opc[0][5], mtp3_opc.opc[0][6], mtp3_opc.opc[0][7]);
			mtp_send_ascout(info_str);
			sprintf(info_str, "International(s) Dynamic (%d): %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld\r\n", 
					mtp3_opc.opc_num[1], mtp3_opc.opc[1][0], mtp3_opc.opc[1][1], mtp3_opc.opc[1][2],
					mtp3_opc.opc[1][3], mtp3_opc.opc[1][4], mtp3_opc.opc[1][5], mtp3_opc.opc[1][6], mtp3_opc.opc[1][7]);
			mtp_send_ascout(info_str);
			sprintf(info_str, "National Dynamic (%d): %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld\r\n", 
					mtp3_opc.opc_num[2], mtp3_opc.opc[2][0], mtp3_opc.opc[2][1], mtp3_opc.opc[2][2],
					mtp3_opc.opc[2][3], mtp3_opc.opc[2][4], mtp3_opc.opc[2][5], mtp3_opc.opc[2][6], mtp3_opc.opc[2][7]);
			mtp_send_ascout(info_str);
			sprintf(info_str, "National(s) Dynamic (%d): %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld\r\n", 
					mtp3_opc.opc_num[3], mtp3_opc.opc[3][0], mtp3_opc.opc[3][1], mtp3_opc.opc[3][2],
					mtp3_opc.opc[3][3], mtp3_opc.opc[3][4], mtp3_opc.opc[3][5], mtp3_opc.opc[3][6], mtp3_opc.opc[3][7]);
			mtp_send_ascout(info_str);
			break;
		case 1:
			sprintf(info_str," \33[32mLink Attribute-->\n\r\33[0m");
			mtp_send_ascout(info_str);
			sprintf(info_str,"\33[32mLink\tLinkset\tSLC\tNormalMTP3\tAlterMTP3\tType\tSG\tCfg\n\r\33[0m");
			mtp_send_ascout(info_str);
			if (index > 224)
				maxindex = 256;
			else
				maxindex = index+32;
			for (i=index; i<maxindex; i++)
			{
				sprintf(info_str,"%03d\t%02x\t%02x\t%08lx\t%08lx\t%02x\t%02x\t%02x\n\r",i,mtp3_para->lk[i].e1_to_linkset,mtp3_para->lk[i].e1_to_slc,
				mtp3_para->lk[i].e1_to_mtp3,mtp3_para->lk[i].e1_to_alterMTP3,mtp3_para->lk[i].e1_lk_type,mtp3_para->lk[i].e1_to_sg,mtp3ObjState.lk_configured[i]);
				mtp_send_ascout(info_str);
			}
			break;
		case 2:
			sprintf(info_str," \33[32mLinkset Attribute-->\n\r\33[0m");
			mtp_send_ascout(info_str);
			sprintf(info_str,"\33[32mLinkset\tRemote_SPC\tNetwork\t\tLoopBack\n\r\33[0m");
			mtp_send_ascout(info_str);
			index = index % 128;
			if (index > 96)
				maxindex = 128;
			else
				maxindex = index+32;
			for (i=index; i<maxindex; i++)
			{
				switch (mtp3_para->ls_pro[i] & 3)
				{
					case 0:
						sprintf(nw,"INT");
						break;
					case 1:
						sprintf(nw,"INT(s)");
						break;
					case 2:
						sprintf(nw,"NAT");
						break;
					case 3:
						sprintf(nw,"NAT(s)");
						break;
				}
				if ((mtp3_para->ls_pro[i] & 8) == 0)
					sprintf(info_str,"%03d\t%06lx\t\t%s\t\tN\n\r",i,mtp3_para->ls_op_pc[i],nw);
				else
					sprintf(info_str,"%03d\t%06lx\t\t%s\t\tY\n\r",i,mtp3_para->ls_op_pc[i],nw);
				mtp_send_ascout(info_str);
			}
			break;
		case 3:// international routine */
			sprintf(info_str," \33[32mInternational Routine\n\r\33[0m");
			mtp_send_ascout(info_str);
			sprintf(info_str," \33[32m    SPC\tNormal LS\tAlternative LS\n\r\33[0m");
			mtp_send_ascout(info_str);
			if (index > 224)
				maxindex = 256;
			else
				maxindex = index+32;
			for (i=index; i<maxindex; i++)
			{
				sprintf(info_str,"\33[33m%03d\33[0m  %06lx\t%02x\t\t%02x\n\r",i,mtp3_para->nw[0].dpc[i],mtp3_para->nw[0].normal_ls[i],mtp3_para->nw[0].alternative_ls[i]);
				mtp_send_ascout(info_str);
			}
			break;
		case 4:// international(s) routine
			sprintf(info_str," \33[32mInternational(S) Routine\n\r\33[0m");
			mtp_send_ascout(info_str);
			sprintf(info_str," \33[32m    SPC\tNormal LS\tAlternative LS\n\r\33[0m");
			mtp_send_ascout(info_str);
			if (index > 224)
				maxindex = 256;
			else
				maxindex = index+32;
			for (i=index; i<maxindex; i++)
			{
				sprintf(info_str,"\33[33m%03d\33[0m  %06lx\t%02x\t\t%02x\n\r",i,mtp3_para->nw[1].dpc[i],mtp3_para->nw[1].normal_ls[i],mtp3_para->nw[1].alternative_ls[i]);
				mtp_send_ascout(info_str);
			}
			break;
		case 5:// national routine
			sprintf(info_str," \33[32mNational Routine\n\r\33[0m");
			mtp_send_ascout(info_str);
			sprintf(info_str," \33[32m    SPC\tNormal LS\tAlternative LS\n\r\33[0m");
			mtp_send_ascout(info_str);
			if (index > 224)
				maxindex = 256;
			else
				maxindex = index+32;
			for (i=index; i<maxindex; i++)
			{
				sprintf(info_str,"\33[33m%03d\33[0m  %06lx\t%02x\t\t%02x\n\r",i,mtp3_para->nw[2].dpc[i],mtp3_para->nw[2].normal_ls[i],mtp3_para->nw[2].alternative_ls[i]);
				mtp_send_ascout(info_str);
			}
			break;
		case 6:// national(s) routine
			sprintf(info_str," \33[32mNational(S) Routine\n\r\33[0m");
			mtp_send_ascout(info_str);
			sprintf(info_str," \33[32m    SPC\tNormal LS\tAlternative LS\n\r\33[0m");
			mtp_send_ascout(info_str);
			if (index > 224)
				maxindex = 256;
			else
				maxindex = index+32;
			for (i=index; i<maxindex; i++)
			{
				sprintf(info_str,"\33[33m%03d\33[0m  %06lx\t%02x\t\t%02x\n\r",i,mtp3_para->nw[3].dpc[i],mtp3_para->nw[3].normal_ls[i],mtp3_para->nw[3].alternative_ls[i]);
				mtp_send_ascout(info_str);
			}
			break;
		case 7:// SG Attribute
			sprintf(info_str," \33[32mSG Attribute-->\n\r\33[0m");
			mtp_send_ascout(info_str);
			sprintf(info_str," \33[32mSG  Enable\tServer\tACK\tRemoteIP\n\r\33[0m");
			mtp_send_ascout(info_str);
			if (index > 224)
				maxindex = 256;
			else
				maxindex = index+32;
			for (i=index; i<maxindex; i++)
			{
				sprintf(info_str,"\33[33m%03d\33[0m  %02x\t\t%02x\t%02x\t%08lx\n\r",i,mtp3_para->sg[i].enable,mtp3_para->sg[i].server,
							mtp3_para->sg[i].data_ack,mtp3_para->sg[i].ip);
				mtp_send_ascout(info_str);
			}
			break;
	}

	return 1;
}


void mtp3_list_link(BYTE i)
{
	char info_str[4096];

	sprintf(info_str," \33[32mLink Attribute-->\n\r\33[0m");
	mtp_send_ascout(info_str);
	sprintf(info_str,"\33[32mLink\tE1_MTP3\t\tNMTP3\tAMTP3\n\r\33[0m");
	mtp_send_ascout(info_str);

	sprintf(info_str,"%03d\t%08lx\t%02x\t%02x\n\r",i,
	mtp3ObjState.lk_mtp3[i],mtp3ObjState.lk_NMTP3_ok[i],mtp3ObjState.lk_AMTP3_ok[i]);
	mtp_send_ascout(info_str);
}
/*@end@*/
