#include "p_apps.h"
#include "my_sip.h"

#define ALPHANUM_NUM	62
CCHAR _cAlphaNum[ALPHANUM_NUM] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 
'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 
'U', 'V', 'W', 'X', 'Y', 'Z'
};

void SipNewToken(PXCHAR pBuf, UCHAR iLen)
{
	DCHAR i, index;
	PXCHAR_D pToken;

	pToken = pBuf;
	for (i = 0; i < iLen; i ++)
	{
		index = p_rand() % ALPHANUM_NUM;
		pToken[i] = _cAlphaNum[index];
	}
	pToken[iLen] = 0;
}

BOOLEAN SipCmpSdram(UCHAR iDstIndex, UCHAR iSrcIndex)
{
	DCHAR iSrcLen, iDstLen;

	iSrcLen = SdramReadData((USHORT)(PROTOCOL_SDRAM_POS+iSrcIndex));
	p_memcpy_x2x((PXCHAR)Sdram_pDataCache2, (PXCHAR)Sdram_pDataCache, iSrcLen);
	iDstLen = SdramReadData((USHORT)(PROTOCOL_SDRAM_POS+iDstIndex));
	if (iSrcLen == iDstLen)
	{
		if (p_memcmp_nocase_x2x((PXCHAR)Sdram_pDataCache2, (PXCHAR)Sdram_pDataCache, iSrcLen))
			return TRUE;
	}
	return FALSE;
}

void SipCpySdram(UCHAR iDstIndex, UCHAR iSrcIndex)
{
	DCHAR iLen;

	iLen = SdramReadData((USHORT)(PROTOCOL_SDRAM_POS+iSrcIndex));
	if (iLen)
	{
		SdramWriteData((USHORT)(PROTOCOL_SDRAM_POS+iDstIndex), iLen);
	}
}

PXCHAR SipStrChr(PXCHAR pString, UCHAR iChar)
{
	PXCHAR_D pCur;

	pCur = pString;
	while (*pCur)
	{
		if (*pCur == ' ' || *pCur == iChar)
			return pCur;
		pCur ++;
	}
	return (PXCHAR)0;
}

