#include "p_apps.h"

#ifdef CALL_H323
#include "p_h323.h"
#elif defined CALL_SIP
#include "p_sip.h"
#elif defined CALL_MGCP
#include "p_mgcp.h"
#elif defined CALL_N2P
#include "p_n2p.h"
#elif defined CALL_WP
#include "p_wp.h"
#elif defined CALL_IAX2
#include "p_iax2.h"
#elif defined CALL_EPN
#include "p_epn.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifdef VER_IPH_E00
#define	MENU_TMR					30		// 30 seconds
#define	KEY_TYPE_NULL				0
#define	KEY_CALL_RECORD				1
#define	KEY_CALLREC_DELETE			2
//Add iPH-E00-2G Board support, by Louis 20040628
#define	KEY_IP_TELNUM					3
//Add store config feature support, by Anfernee 20040810
//Add load config feature support, by Anfernee 20040810
#define	KEY_CONFIG_STORE				4
#define	KEY_CONFIG_LOAD				5
#define	KEY_IVR_FLOW					6
#define	KEY_IVR_CONFIRM				7
#define  SET_BIT0_TO_1                 1	//ISP connect bit
#define  SET_BIT1_TO_1                 2
#define  SET_BIT2_TO_1                 4        //GK logon bit
#define  SET_BIT0_2_TO_1               5
#define  CLEAR_BIT4                    7
#define  COUNT_BIT4							8


#define	LED_MISSCALL_OR_MASK		0x01
#define	LED_MISSCALL_AND_MASK		0xfe

#define	RE_DISPLAY_NORMAL	0
#define	RE_DISPLAY_ARJ		1
#define	RE_DISPLAY_BUSY		2
#define	RE_DISPLAY_CDR		3
#ifdef E00_NEW_HW
#define	SPK_VOL_RING		18
#else
#define	SPK_VOL_RING		30
#endif
#endif	// VER_IPH_E00

#ifdef VER_WG2000
extern BOOLEAN bUserallread;//judy
#endif
extern BOOLEAN Key_bCopied;
extern BOOLEAN Task_bSetupMode;
extern BOOLEAN Task_bExtraDisplay;
extern BOOLEAN Task_bInbandDtmf;
extern XCHAR Task_iTimer;
extern BOOLEAN PIO_bIndicated;
extern BOOLEAN KeyIO_bIndicated;
extern BOOLEAN Ac97_bIVR;
extern XCHAR Ac97_bMuteInput;			// save boolean space
extern XCHAR Sys_iScrollType;
extern volatile DCHAR Sys_iWholeSecond;

// Functions in Keypad.c
void DisplayKeys();
void UpdateRedialBuf();

// Functions in Chip.c
void SysNormalSpeed();
void SysHighSpeed();

// Functions in Sdram.c
void SdramStartup();

void SdramWriteMsg(UCHAR iMsgIndex);
void SdramWriteStrings(PXCHAR pString);
void SdramWriteDigit(UCHAR iDigit);
void SdramWriteIndex(USHORT iIndex);

void SdramPlay(PXCHAR pString, UCHAR iIVR1, USHORT iIndex, UCHAR iIVR2); 
void SdramPlayIP(UCHAR iIVR1, UCHAR iIVR2, PXCHAR pIP);
void SdramPlayString(PXCHAR pString);
//void SdramPlayNumber(USHORT iNumber);
void SdramPhoneNumber();
void SdramSpeedDial(UCHAR iIndex);

BOOLEAN SdramFileCreate();

void SdramWriteFile(UCHAR iIndexHigh, UCHAR iIndexLow, USHORT iLength);

void SdramRingFile();

// Functions in Dtmf.c
void DtmfRun();
void DtmfDialTone();
void DtmfRing();
void DtmfStopRing();
void DtmfBusy();
void DtmfCongestion();
void DtmfStopAll();
void DtmfPlayKey(UCHAR iKeyID);
BOOLEAN DtmfPlayKeys();

// Functions in Ac97_1.c
void Ac97Startup();
void Ac97Run();
void Ac97HandleInterrupt();

void Ac97StartIVR();
void Ac97StopIVR();

void Ac97StartRing();
void Ac97StopRing();

// Functions in Function.c
#define FUNCTION_TIME_OUT	5

#define SCROLL_SPEED_DIAL	3
#define SCROLL_VOICE_MSG	4
#define SCROLL_VOLUME		5
#define SCROLL_MENU			6
#define SCROLL_HOTLINE		7
#define SCROLL_NULL			8

void DisplayNormalState();
void OnPhoneNumber();
void OnSaveSpeedDial(BOOLEAN bSpeedDial);
void OnLoadSpeedDial();
void OnDirectSpeedDial(UCHAR iIndex);
void OnRedial();
void OnCall();
void OnVolHigher();
void OnVolLower();
void OnMute();
void OnBackSpace();
void OnGKAddress();
void OnIPAddress();
void OnSubnetMask();
void OnRouterAddress();
void OnMissedCall();
void OnAnsweredCall();
void OnDialedCall();
void OnAnsweredCall();
void OnMissedCall();
void OnDialedCall();
void OnMenuOK();
void OnMenuCancel();
void OnCallHold();
void OnCallTransfer();
void OnModemConnect();
void OnModemDisconnect();

void OnPrepareCall();
void OnHotLine();

BOOLEAN OnMapMatch(BOOLEAN bTimeOut);

void OnCheckHandset();
UCHAR OnScroll(UCHAR iOrg, UCHAR iLimit, BOOLEAN bUp);

void UIStartup();
void UIInitialize();
void UIHandleTimer();
void UIRingIndicate(BOOLEAN bRinging);
void UIMissedCallIndicate();
BOOLEAN UIHandleSpecialKeys();

void OnMenuPassword();

BOOLEAN OnMenu(BOOLEAN bSet);

BOOLEAN	CanAcceptCall();
void OnCalled();

void OnOutgoingKey(UCHAR iKey);

void OnPingFailed();

void CommonUIHandleTimer();

void OnMgcpCall();

#ifdef VER_IPH_E00
#ifdef E00_NEW_HW
void L3Led_Mute_On();
void L3Led_Mute_Off();
void L3Led_Spk_On();
void L3Led_Spk_Off();
#endif
void SetSpkOutput(UCHAR iVol);
void OnGetBalance();
void OnBalanceIVRcall();
void OnCallRecord();
void OnSoftKey1();
void OnSoftKey2();
void OnSoftKey3();
void OnFuncKey();
void OnDelete();
void OnLoadSettings(UCHAR iOptions);
void OnStoreSettings(UCHAR iOptions);
void OnSoftKeys();
void GKIndicate();
void ModemChangeStatus();
void ModemInitializeStatus();
BOOLEAN IsModemConnect();
void LedMute();
#endif

void SysRingBack();

UCHAR CheckSpeedDial(PXCHAR pBuf);
void CopySpeedDialKeypad();
void UndoSpeedDialKeypad();

void CheckNatAddr();
void CheckProxy();

// Functions in callrec.c

extern XLONG Call_lDuration;

UCHAR CallRecReadScroll(BOOLEAN bUp);
UCHAR CallRecRead(UCHAR iType);
void CallRecDisplay(UCHAR iType);
void CallRecWriteStart(PXCHAR pNumber, UCHAR iType);
UCHAR CallRecWriteStop();
UCHAR CallRecDelete(UCHAR iDelType, BOOLEAN bFromStart);

ULONG CallRecGetStartTime(UCHAR iType, UCHAR iIndex);	// use the return val of CallRecRead and CallRecReadScroll as iIndex
//ULONG CallRecGetDuration(UCHAR iType, UCHAR	iIndex);

// Functions in dialplan.c
void DialPlanBuildNumber();

#ifdef HW_MODEM

// Functions in modem.c
void ModemStartup();
void ModemInit();
void ModemDial();
void ModemRedial();
void ModemDisConnect();

// Functions in p_modem.c
#define PPPINITFCS16    0xffff  /* Initial FCS value */
#define PPPGOODFCS16    0xf0b8  /* Good final FCS value */
USHORT pppfcs16(USHORT fcs, PXCHAR cp, USHORT len);
BOOLEAN	ModemInitialize();													// at_modem.c
void	ModemRun();
void	ModemSend(USHORT iLength, PXCHAR pData);
void	ModemSendData(USHORT iLength, PXCHAR pData);
void	ModemHandleInterrupt();

#endif

// Functions in convert.c
void ConvertRing();

#ifdef __cplusplus
}
#endif

