#include "Page1.h"
#include "PalmChip.h"

#include "p_dsp.h"
#include "gdiconst.h"
#include "p_rtp.h"

#include "v_task.h"

#ifdef SYS_YIYANG
#include "yiyang.h"
#endif

#ifdef SYS_ASIAINFO
#include "asiainfo.h"
#endif

XCHAR Sys_iScrollType;		// Andy

//static BOOLEAN _bHookStatus, _bHookFlash = FALSE;
//static XCHAR _iHookFlashTimer = 0;

#ifdef VER_IPH_E00
extern XCHAR Task_iSpecKey;
#endif

#ifndef CALL_MGCP
BOOLEAN OnMapMatch(BOOLEAN bTimeOut)
{
	XCHAR pEvent[MAX_KEYBUF_LEN+1];
	DCHAR iNum, iVal;
	
	for (iNum = 0; iNum < p_strlen_x(Key_pBuf); iNum ++)
	{
		pEvent[iNum] = p_getKeyId(Key_pBuf[iNum]);
	}
	if (bTimeOut)
	{
		pEvent[iNum] = p_getKeyId('T');
		iNum ++;
	}

	iVal = p_matchMap(pEvent, iNum);
	switch (iVal)
	{
	case DIGITMAP_NOTMATCH:
//		DebugCString((PCCHAR)"Not Match");
		return TRUE;
	case DIGITMAP_UNDERMATCH:
//		DebugCString((PCCHAR)"Under Match");
		Map_iTimeOut = MAP_TIME_OUT_1;
		return FALSE;
	case DIGITMAP_MATCH:
//		DebugCString((PCCHAR)"Match!");
		return TRUE;
	case DIGITMAP_TOMATCH:
//		DebugCString((PCCHAR)"Time Out Match");
		Map_iTimeOut = MAP_TIME_OUT_2;
		return FALSE;
	default:
			return FALSE;
	}
}
#endif

UCHAR OnScroll(UCHAR iOrg, UCHAR iLimit, BOOLEAN bUp)
{
	DCHAR iVal, iMax;

	iMax = iLimit;
	iVal = iOrg;

	if (!iMax)	return 0;

	if (bUp)
	{
		iVal ++;
		if (iVal >= iMax)
		{
			iVal = 0;
		}				
	}
	else
	{
		if (!iVal)
		{
			iVal = iMax;
		}
		iVal --;
	}
	return iVal;
}


BOOLEAN IsCallMode()
{
	if (PIO_bHandFree)		return TRUE;
	if (PIO_bHandsetUp)		return TRUE;
	return FALSE;
}

void OnHookFlash()
{
#ifdef CALL_MGCP
	MgcpNotify(MGCP_EVENT_LINE_HF);
#else
	if (IsInCall())
	{
#ifdef CALL_SIP
		if (Sys_iServiceType == SIP_SERVICE_TYPE_AYCTEL)
		{
			RtpSendDtmfKey(16);
		}
		else
		{
#if defined	VER_IPLINK || defined OEM_JR168
			HangupPhone();
#else
			OnCallHold();
#endif
		}
#else
//		OnCallTransfer();
#if defined	VER_IPLINK || defined OEM_JR168
		HangupPhone();
#else
#ifdef CALL_IAX2	// Thomas NOEL <thomas.noel@auf.org>
		Iax2Flash();
#else
		OnCallHold();
#endif
#endif
#endif
		return;
	}
/*
	if (!IsCallMode())		return;

	_bHookFlash = TRUE;
	_iHookFlashTimer = 2;
	if (PIO_bHandsetUp)
	{
		_bHookStatus = TRUE;
		PIO_bHandsetUp = FALSE;
		OnHandset();
	}
	else
	{
		_bHookStatus = FALSE;
		OnHandFree();
	}
*/
#endif
}

void OnDirectSpeedDial(UCHAR iIndex)
{
	PXCHAR_D pBuf;
	DCHAR iNum;

	iNum = iIndex;
	if (IsFunctionMode())
	{
		iNum <<= 1;
		pBuf = ReadSpeedDial(iNum);
		if (CheckSpeedDial(pBuf))
		{
			Key_bCopied = TRUE;
			p_strcpy_x2x(Key_pBuf, pBuf);
			iNum ++;
			pBuf = ReadSpeedDial(iNum);
			DisplayLine(pBuf, 1);	// display name here
			OnCall();
		}
	}
}

void DisplayNormalState()
{
	XCHAR pBuf[DISPLAY_MAX_CHAR+1];

#ifdef VER_YODAO
	DisplayString("China Telecom QD", 2);
	DisplayString("www.yodao.com.cn", 3);
#endif

	if (Task_bLogoned)
	{
		if (Task_bConnected)
		{
#ifdef CALL_SIP	
			if (Task_bCallTransfer)
			{
				DisplayString(g_cCallTransfer, 0);
			}
			else
			{
				DisplayString((Task_bOnHold || Task_bCallHold) ? g_cCallHold : g_cConnected, 0);
			}
			
#else
			DisplayString(Task_bCallHold ? g_cCallHold : g_cConnected, 0);
#endif
			return;
		}

		if (Task_bConnecting)
		{
			if (Task_bCaller)
			{
				if (Sys_iServiceType != SIP_SERVICE_TYPE_QMASTER)
				{
					DisplayString(g_cCalling, 0);
					DisplayLine(Sys_pPeerDisplay, 1);
				}
			}
			else
			{
				if (p_strlen_x(Sys_pRemoteNumber))
				{
					DisplayLine(Sys_pRemoteNumber, 0);
				}
				else
				{
					DisplayString(g_cRinging, 0);
				}
				DisplayLine(Sys_pPeerDisplay, 1);
			}
		}
		else
		{
			if (!Task_bExtraDisplay)
			{
				if (IsCallMode())
				{
					DisplayString((Ac97_iDtmfCode == DTMF_SIGNAL_BUSY) ? g_cPleaseHangup : g_cPleaseDial, 0);
				}
				else
				{
					if (Sntp_bFinished)
					{
						GetDateTimeDisplay(pBuf, TRUE, Sys_lCurrentTime);
						DisplayLine(pBuf, 0);
					}
					else
					{
						DisplayString(g_cReady, 0);
					}
					KeypadClear();
				}
			}
		}
	}
	else
	{
		DisplayString(g_cWaitLogon, 0);
#if defined VER_IPH_E00_8B_F || defined VER_IPH_E00_8B_NF
		DisplayLine((PXCHAR)GetVersionText(), 1);
#else
		DisplayLine((PXCHAR)GetHardwareVersion(), 1);	                                          	
#endif
	}
}

void SysLogoff()
{
	if (Sys_bUseService)
	{
#ifdef CALL_H323
		H323Logoff();
		if (Sys_iNatTraversal == H323_NAT_TRAVERSAL_CITRON || Sys_iNatTraversal == H323_NAT_TRAVERSAL_AIVGR)
		{
			H323NatDisconnect();
		}
#elif defined CALL_SIP
		SipLogoff();
#elif defined CALL_MGCP
		MgcpLogoff();
#elif defined CALL_N2P
		N2pLogoff();
#elif defined CALL_WP
		WpLogoff();
#elif defined CALL_IAX2
		Iax2Logoff();
#elif defined CALL_EPN
		EpnLogoff();
#endif
	}
	else
	{
		TaskLogoffCompleted();
	}
	Led_Off(NORMAL_LIGHT);
	Led_Off(SECOND_LIGHT);
	Led_Off(KEYPAD_LIGHT);
}

void OnLogoff()
{
#ifdef HW_MODEM
	DCHAR i;
#endif

	DisplayString(g_cLogoff, 0);
	DisplayString(g_cBlank, 1);
	SysLogoff();
	UdpDebugUpdate();
	if (PPPoE_bInUse)
	{
		DisplayString(g_cPPPoE, 0);
		DisplayString(g_cDisconnecting, 1);
		PPPoEDisconnect();
	}
#ifdef HW_MODEM
	else if (Modem_bInUse)
	{
		DisplayString(g_cModem, 0);
		DisplayString(g_cDisconnecting, 1);
		ModemDisConnect();

		i = 1;
		while (i)
		{
			i ++;
			TaskWaitPacket();
		}
		XBYTE[IO_HI_INTEN] &= MODEM_PIO_INT_AND;			// disable modem irq, IO pin 11
	}
#endif
	UdpDebugUpdate();
}

void OnPrepareCall()
{
	if (!Task_bLogoned)
	{
#ifndef CALL_MGCP
		DtmfBusy();
#endif
		return;
	}

	if (Task_bConnected)		return;

#ifdef CALL_MGCP
	MgcpNotify(MGCP_EVENT_LINE_HD);
#endif
	Map_iTimeOut = MAP_TIME_OUT_0;	// first digit time out

	if (Task_bConnecting)
	{
		if (Task_bCaller)		return;

		CallRecWriteStart(Sys_pPeerDisplay, CALL_TYPE_ANSWERED);
		DisplayString(g_cAnswering, 0);
		Task_iTimer = 0;
		Ac97StopRing();

#ifdef CALL_H323
		H323Connect();
#elif defined CALL_SIP
	if(Sys_iNatTraversal == SIP_NAT_TRAVERSAL_STUN)
	{
		StunCheckIPPort(STUN_TASK_ANSWER, Sys_iRtpPort);
	}
	else
	{
		SipConnect();
	}
#elif defined CALL_MGCP
		TaskConnected();
#elif defined CALL_N2P
		N2pConnect();
#elif defined CALL_WP
		WpConnect();
#elif defined CALL_IAX2
		Iax2Connect();
#elif defined CALL_EPN
		EpnConnect();
#endif
	}
	else
	{
		Task_bCaller = TRUE;
#ifdef CALL_H323
		if (Sys_iNatTraversal == H323_NAT_TRAVERSAL_CITRON || Sys_iNatTraversal == H323_NAT_TRAVERSAL_AIVGR)
		{
			H323NatDisconnect();
		}
#endif
#ifndef CALL_MGCP
		DtmfDialTone();
#endif

#ifdef CALL_IAX2
		if (Sys_iCallType & REMOTE_DIALPLAN_OR)
		{
			if (!Iax2DPCall())
			{
				TaskRestart(0);
				return;
			}
		}
#endif

#ifdef SYS_YIYANG
		if (Sys_iServiceType == H323_SERVICE_TYPE_YIYANG && Yiyang_iState == YIYANG_RECV_CALLED)
		{
			H323RasSendArq();
			Ac97StopRing();
			Yiyang_iState = YIYANG_SEND_ARQ;
		}
		else
#endif
		{
			DisplayString(g_cPleaseDial, 0);
			DisplayString(g_cBlank, 1);
		}
	}

	PIO_bIndicated = FALSE;
	KeyIO_bIndicated = FALSE;

	Led_On(KEYPAD_LIGHT);
}

void OnHotLine()
{
	if (Sys_iUseDialPlan != DIALPLAN_HOTLINE)	return;
	if (!Task_bLogoned)			return;
	if (Task_bConnected)		return;
	if (Task_bConnecting)		return;

//	Key_bCopied = TRUE;
	p_strcpy_x2x(Key_pBuf, Sys_pDialNumber);
	Sys_iScrollType = SCROLL_HOTLINE;
	Ac97_iDtmfCode = DTMF_SIGNAL_QUIET;
	OnCall();
}

#ifdef CALL_MGCP
void OnMgcpCall()
{
	DisplayLine(Key_pBuf, 1);
	p_memcpy_x2x_0(Sys_pPeerDisplay, Key_pBuf, PHONE_NUMBER_LEN);
	CallRecWriteStart(Sys_pPeerDisplay, CALL_TYPE_DIALED);
	Task_bConnecting = TRUE;
	Task_bCaller = TRUE;
	DtmfPlayKeys();
	Key_bCopied = FALSE;
}
#endif

UCHAR CheckSpeedDial(PXCHAR pBuf)
{
#ifdef CALL_H323
	DCHAR i, iLen;

	iLen = p_strlen_x(pBuf);
	for (i = 0; i < iLen; i ++)
	{
		if (!IsE164Char(pBuf[i]))
		{
			return 0;
		}
	}
	return iLen;
#else
	return p_strlen_x(pBuf);
#endif
}

void CommonUIHandleTimer()
{
	if (!Task_bLogoned)					return;
	if (SoloFileIsRunning())			return;
	if (Sys_iScrollType != SCROLL_NULL)	return;
#ifdef VER_IPH_E00
	if (Task_iSpecKey != KEY_TYPE_NULL)	return;
#endif
	if (!IsFunctionMode())				return;
	if (IsCallMode())					return;

	if (!Task_bExtraDisplay)
	{
		SntpDisplayHandleTimer();
	}

	if (Task_bNewMessage)
	{
		if (!(Sys_lCurrentTime % 30))
		{
			SdramRead(OPTIONS_SDRAM_HI, MSG_HINT_SDRAM_LO, SRAM_DMA_HALF_DWORD);
			DisplayLine((PXCHAR)Sdram_pDataCache, 1);
		}
		return;
	}

	if (!(Sys_lCurrentTime % 20))
	{
		if (p_strlen_x(Sys_pLocalNumber))
		{
			DisplayLine(Sys_pLocalNumber, 1);
		}
		else
		{
			p_IP2String(Local_pIPAddress, (PXCHAR)Sdram_pDataCache);
			DisplayLine((PXCHAR)Sdram_pDataCache, 1);
		}
	}
	else if (!(Sys_lCurrentTime % 15))
	{
#ifdef CALL_H323
		if (Sys_iLocalType >= H323_LOCAL_TYPE_AUTO && p_strlen_x(Sys_pAccount))
#else
		if (p_strlen_x(Sys_pAccount))
#endif
		{
			DisplayLine(Sys_pAccount, 1);
		}
	}
}

void OnRedial()
{
#ifdef CALL_MGCP
	if (Task_bConnected)	return;
#else
	if (!IsFunctionMode())	return;
	if (Ac97_bIVR)			return;
#endif

	DisplayString(g_cRedial, 0);
	if (SdramCopyData_0(OPTIONS_SDRAM_POS+KEY_PREVBUF_SDRAM_LO, Key_pBuf))
	{
		Key_bCopied = TRUE;
#ifdef CALL_MGCP
		if (IsCallMode())
		{
			OnMgcpCall();
		}
		else
		{
			Sys_iScrollType = SCROLL_HOTLINE;
			OnCall();
		}
#else
		OnCall();
#endif	// CALL_MGCP
	}
}

void CopySpeedDialKeypad()
{
	p_memcpy_x2x(Key_pBuf, (PXCHAR)(Key_pBuf+1), p_strlen_x(Key_pBuf));
	Key_bCopied = TRUE;
//	Sys_iScrollType = SCROLL_SPEED_DIAL;
}

void UndoSpeedDialKeypad()
{
	DCHAR i;

	for (i = p_strlen_x(Key_pBuf); i > 0; i --)
	{
		Key_pBuf[i] = Key_pBuf[i-1];
	}
	Key_pBuf[0] = '#';
}

void OnCheckHandset()
{
//	if (_bHookFlash)	return;

#ifdef VER_IPH_E00
	Ac97SetOutputVol();
#endif

#ifdef VER_PA168P
	if (Task_bLogoned)
	{
		Led_On(SECOND_LIGHT);
	}
	else
#endif
	{
		Led_Off(SECOND_LIGHT);
	}

#ifndef CALL_MGCP
	DtmfStopAll();
	if (IsCallMode() && !Task_bSetupMode)
	{
		DtmfBusy();
	}
/*	else
	{
		Ac97Stop();
		Led_Off(KEYPAD_LIGHT);
	}
*/
#endif
}

#ifndef CALL_MGCP
BOOLEAN	CanAcceptCall()
{
	DCHAR iIndex, iSpeedDialIndex;
	PXCHAR pDisplay;
	PXCHAR pNumber;

	Task_iTimer = 0;
//	if (Task_bDisconnecting)	return FALSE;
	
#ifdef CALL_H323
	if (Sys_iForwardType & FORWARD_ALWAYS_OR)	return FALSE;
#endif

	if (!p_strlen_x(Sys_pPeerDisplay))
	{
#ifdef CALL_H323
		p_IP2String(Remote_pH2250IP, Sys_pPeerDisplay);
#endif
#ifdef CALL_N2P
		p_IP2String(Sys_pGWIP, Sys_pPeerDisplay);
#endif
	}
	CallRecWriteStart(Sys_pPeerDisplay, CALL_TYPE_MISSED);
	if (IsCallMode() || IsUpgrading())
	{	// call missed
		CallRecWriteStop();
		return FALSE;
	}
	// call answered

	pNumber = 0;
	for (iIndex = 0; iIndex < SPEED_DIAL_NUM; iIndex ++)
	{
		iSpeedDialIndex = iIndex;
		iSpeedDialIndex <<= 1;
		pDisplay = ReadSpeedDial(iSpeedDialIndex);
		if (!p_strcmp_x2x(pDisplay, Sys_pPeerDisplay))
		{
			iSpeedDialIndex ++;
			pNumber = ReadSpeedDial(iSpeedDialIndex);
			break;
		}
	}

	if (pNumber)
	{
		p_strcpy_x2x(Sys_pRemoteNumber, pNumber);
	}
#if defined CALL_H323 || defined CALL_EPN || defined CALL_N2P || defined CALL_WP
	else
	{
		Sys_pRemoteNumber[0] = 0;
	}
#endif

	DisplayLine(Sys_pRemoteNumber, 0);
	DisplayLine(Sys_pPeerDisplay, 1);
	Sys_iScrollType = SCROLL_NULL;
	KeypadClear();
	return TRUE;
}
#endif

void OnCalled()
{
#ifdef VER_IPH_E00
	DCHAR iVol;
#endif

	Task_bConnecting = TRUE;
#ifdef CALL_MGCP
	Task_iTimer = 0;	// if not MGCP, this was done in CanAcceptCall()
#endif

#ifdef VER_IPH_E00
	// Set SPK output to SPK_VOL_RING for ringring
	iVol = Ac97_iHandfreeOutputVol+5;
	SetSpkOutput((UCHAR)(iVol > 31 ? 31 : iVol));
#endif

#ifdef _USE_FXS
	GetDateTimeDisplay((PXCHAR)Sdram_pDataCache, FALSE, Sys_lCurrentTime);
//	OutputVals((PXCHAR)Sdram_pDataCache, 36);
	SdramWriteAll(OPTIONS_SDRAM_POS+CID_INFO_SDRAM_LO);	// Save to Sdram
#endif
	Ac97StopIVR();
//	DisplayString(g_cRinging, 0);
	Ac97StartRing();

#ifdef BACKLIGHT_CTRL
//	L3ClockOn();
#ifdef INVERT_BACKLIGHT
	Cam_LedOn(0);
#else
	Cam_LedOff(0);
#endif
#endif
}

void HangupPhone()
{
#ifdef CALL_MGCP
	MgcpNotify(MGCP_EVENT_LINE_HU);
	TaskSignalMsg(MGCP_EVENT_HANGUP);
#else
	// To prevent possible timer handler failure period between DRQ sent and DCF received
	TaskHangup();
#endif
	Led_Off(KEYPAD_LIGHT);
	DtmfStopAll();
}

void ProtocolLogon()
{
	if (Sys_bUseService)
	{
#ifdef CALL_H323
		H323Logon();
#elif defined CALL_SIP
		SipLogon();
#elif defined CALL_MGCP
		MgcpLogon();
#elif defined CALL_N2P
		N2pLogon();
#elif defined CALL_WP
		WpLogon();
#elif defined CALL_IAX2
		Iax2Logon();
#elif defined CALL_EPN
		EpnLogon();
#endif
	}
	else
	{
		TaskLogonCompleted();
	}

}

void OnCallHold()
{
	if (!Task_bConnected)
	{
		return;
	}

#ifdef CALL_H323
	H323CallHold();
	if (Task_bCallHold)
	{
		Ac97_iDtmfCode = DTMF_SIGNAL_DIAL;
		SdramRingFile();	// ring file as call hold file
	}
	else
	{
		Ac97_iDtmfCode = DTMF_SIGNAL_QUIET;
		SoloFileCloseRead();
	}
#endif

#ifdef CALL_SIP
	SipCallHold();
#endif

#ifdef CALL_IAX2
	Iax2CallHold();
#endif

	if (Task_bCallHold)
	{
		DisplayString(g_cCallHold, 0);
	}
	else
	{
		DisplayString(g_cConnected, 0);
	}
	KeypadClear();
}

void OnCallTransfer()
{
	if (!Task_bConnected)
	{
		return;
	}

	DisplayString(g_cCallTransfer, 0);
#ifdef CALL_H323
	if (p_strlen_x(Key_pBuf))
	{
		H323CallTransfer(Key_pBuf);
	}
#endif

#ifdef CALL_SIP
	SipCallTransfer(Key_pBuf);
#endif

#ifdef CALL_IAX2
	if (p_strlen_x(Key_pBuf))
	{
		Iax2UnattendedTransfer(Key_pBuf);
	}
	else
	{
		Iax2AttendedTransfer();
	}
#endif
	KeypadClear();
}

void SysRingBack()
{
	if (Task_bConnected)	return;	// alerting may come after connect!

	Task_iTimer = 0;
	Ac97Start();
	Task_bRingBack = TRUE;
}

void CheckNatAddr()
{
	DSHORT iPort;

#if defined CALL_N2P || defined CALL_WP || defined CALL_IAX2 || defined CALL_EPN
	goto End;
#endif
	
//	if (Sys_bNATed)							goto End;
	if (Sys_iNatTraversal == NAT_TRAVERSAL_DISABLE)
	{
		goto End;
	}

#ifdef CALL_H323
	if (IsPublicIP(Local_pIPAddress))		goto End;
	if (Sys_iNatTraversal == H323_NAT_TRAVERSAL_CITRON) 
	{
		goto End;
	}
	else if (Sys_iNatTraversal != H323_NAT_TRAVERSAL_AIVGR)
	{
		if (Sys_bUseService)
		{
			if (!IsPublicIP(Sys_pServiceIP))	goto End;
		}
		else
		{
			if (!IsPublicIP(Sys_pGWIP))			goto End;
		}
	}
#elif defined CALL_SIP || defined CALL_MGCP
	if (Sys_bUseService)
	{
		if (!IsPublicIP(Sys_pServiceIP))	goto End;
	}
	else
	{
		if (!IsPublicIP(Sys_pGWIP))			goto End;
	}
#endif

/*	if (!p_strlen_x(Sys_pNatAddr))
	{
		p_memset_ip_0(Sys_pProxyServerIP);
		CheckProxy();
		return;
	}
*/
	iPort = ParseDnsAddr(Sys_pNatAddr, Sys_pProxyServerIP, (PXCHAR)Sdram_pDataCache);
	if (iPort)
	{
		Sys_iNatPort = iPort;
	}

	if (Sys_iNatTraversal == NAT_TRAVERSAL_ENABLE)
	{
		Sys_bNATed = TRUE;
		if (IsPublicIP(Sys_pProxyServerIP))
		{	// fill public ip manually
			p_memcpy_ip(Sys_pProxyIP, Sys_pProxyServerIP);
			SdramUpdateFlagByte(FLAGS_PAGE12_ATTR, PAGE12_FIXED_IP);
		}
		else
		{	// get page12 result
			SdramCopyData(OPTIONS_SDRAM_POS+PUBLIC_IP_SDRAM_LO, Sys_pProxyIP);
			SdramUpdateFlagByte(FLAGS_PAGE12_ATTR, PAGE12_CHANGED_IP);
		}
	}
	else
	{
		if (IsValidIP(Sys_pProxyServerIP))
		{
			CheckProxy();
		}
		else
		{
			Task_iDnsType = DNS_TYPE_PROXY;
			DnsSend((PXCHAR)Sdram_pDataCache, FALSE);
		}
		return;
	}

End:
	ProtocolLogon();
}

void CheckProxy()
{
#ifdef CALL_SIP
	if (Sys_iNatTraversal == SIP_NAT_TRAVERSAL_STUN)
	{
		StunCheckIPPort(STUN_TASK_LOGON, Sys_iRegisterPort);
		return;
	}
#endif

#ifdef CALL_H323
#ifdef SYS_ASIAINFO
	if (Sys_iNatTraversal == H323_NAT_TRAVERSAL_AIVGR)
	{
		AIVGRStart();
		return;
	}
#endif
#endif	// CALL_H323
}

void OnOutgoingKey(UCHAR iKey)
{
	DCHAR iKeyID;
	XCHAR pKeyBuf[2];

	if (!IsInCall())	return;
	if (Task_bCallHold)	return;

	iKeyID = iKey;

#ifndef _USE_FXS
	DtmfPlayKey(iKeyID);
#endif
	if (Sys_iDtmfType == DTMF_INBAND_AUDIO)
	{
		Task_bInbandDtmf = TRUE;
		return;
	}

	pKeyBuf[0] = iKeyID;

#ifdef CALL_H323
	H323SendDtmfKeys(pKeyBuf, 1);
#elif defined CALL_SIP
	if (Sys_iDtmfType == DTMF_RFC2833)
	{
		RtpSendDtmfKey(p_getKeyId(iKeyID));
	}
	else
	{
		SipSendDtmfKeys(pKeyBuf, 1);
	}
#elif defined CALL_MGCP
	RtpSendDtmfKey(p_getKeyId(iKeyID));
#elif defined CALL_IAX2
	Iax2SendDtmfKeys(pKeyBuf, 1);
#elif defined CALL_N2P
	N2pSendDtmfKeys(pKeyBuf, 1);
#elif defined CALL_WP
	WpSendDtmfKeys(pKeyBuf, 1);
#elif defined CALL_EPN
	EpnSendDtmfKeys(pKeyBuf, 1);
#endif
}

void OnMute()
{
	if (IsCallMode())
	{
#ifdef VER_IPH_E00
		if (PIO_bHandFree)
		{
			Ac97_bMuteInput = TRUE;
		}
		else if (PIO_bHandsetUp)
#endif
		{
			if (Ac97_bMuteInput)
			{
				Ac97_bMuteInput = FALSE;
				DisplayString(g_cConnected, 0);
			}
			else
			{
				Ac97_bMuteInput = TRUE;
				DisplayString(g_cCallMuted, 0);
			}
			Ac97SetInputVol();
		}
#ifdef VER_IPH_E00
		LedMute();
#endif
	}
}
