#include "p_apps.h"
#include "p_sip.h"
#include "v_task.h"
#include "my_mgcp.h"

void MgcpSendReqData()
{
	OutputPXCHAR((PXCHAR)Adapter_pSendUdpData, Mgcp_iSendLen);
	UdpSend(Mgcp_iSendLen, MGCP_REQ_SDRAM_LO);
	Mgcp_iSendLen = 0;
}

void MgcpSendRespData()
{
	OutputPXCHAR((PXCHAR)Adapter_pSendUdpData, Mgcp_iSendLen);
	UdpSend(Mgcp_iSendLen, MGCP_RESP_SDRAM_LO);
	Mgcp_iSendLen = 0;
}

void MgcpRxReqPacket(UCHAR iTransNo)
{
	SdramCopyAll((USHORT)(PROTOCOL_SDRAM_POS+ (iTransNo << 1) + MGCP_REQ_TRANS_RETRANSMIT), (PXCHAR)Adapter_pSendUdpData);
	MgcpSendReqData();
}

void MgcpRxRespPacket(UCHAR iTransNo)
{
	SdramCopyAll((USHORT)(PROTOCOL_SDRAM_POS+(iTransNo << 1) + MGCP_RESP_TRANS_RETRANSMIT), (PXCHAR)Adapter_pSendUdpData);
	MgcpSendRespData();
}
/**********************************************************************************
****** MGCP API functions
***********************************************************************************/

 BOOLEAN MgcpRunUdp()
{
	DSHORT iDstPort;

	if (Adapter_iReceiveUdpPort == Sys_iRegisterPort)
	{
		iDstPort = PXCHAR2USHORT((PXCHAR)Adapter_pReceivePacket);
		UdpOpen(Adapter_pReceiveIPAddress, iDstPort, Sys_iRegisterPort, MGCP_RESP_SDRAM_LO);
		OutputPXCHAR((PXCHAR)Adapter_pReceiveUdpData, Adapter_iReceiveLen);
		MgcpRunData((PXCHAR)Adapter_pReceiveUdpData);
		MgcpProcessData();
		MgcpInitRecv();
		return TRUE;
	}
	return FALSE;
}

