[Feature]Upload Modem source code

Change-Id: Id4294f30faced84d3e6fd6d5e61e1111bf287a37
diff --git a/mcu/interface/service/asn1_common/asn_aper_common.c b/mcu/interface/service/asn1_common/asn_aper_common.c
new file mode 100644
index 0000000..4537661
--- /dev/null
+++ b/mcu/interface/service/asn1_common/asn_aper_common.c
@@ -0,0 +1,1038 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2011
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*****************************************************************************
+ * $Log:$
+ *
+ * 07 31 2013 vend_eric.chuang
+ * [MOLY00031885] [MT6290] fix compile warnings
+ * .remove LTE compile warning
+ * .turn off GENERATE_EXTERN_ALL_PDU
+ *
+ * 11 06 2012 nick.wang
+ * [MOLY00005322] TATAKA merge to MOLY
+ * Merge Moly_tataka asn common
+ * 
+ * 09 06 2012 changshun.li
+ * [MOLY00000064] [asn.1] for check in tool/code to MOLY
+ * .
+ *
+ * 03 27 2012 changshun.li
+ * removed!
+ * for msbb2
+ *
+ * 03 27 2012 changshun.li
+ * removed!
+ * for msbb2
+ *
+ ****************************************************************************/
+
+#include "kal_public_api.h"
+#include "asn_memory.h"
+#include "asn_common.h"
+
+#include "asn_aper_common.h"
+
+
+extern	Bool IsReindexOneByteAlphabet(ASN_OneByteAlphabet *pAlphabet)
+{
+
+	return ((U32)(*(pAlphabet->value + pAlphabet->valueLen - 1)) 
+			<= GetOneByteCharacterBitWidth(pAlphabet)) ? 0 : 1;
+}
+
+
+extern	U32 GetOneByteCharacterBitWidth(ASN_OneByteAlphabet *pAlphabet)
+{
+	U32	uB, uB2;
+
+	uB = GetNumberBitLength(pAlphabet->valueLen);
+	uB2 = GetNumberBitLength(uB);
+
+	return	(U32)(1 << uB2); //pow(2, uB2);
+}	
+
+
+U32 GetNumberBitLength(U32  Data)
+{
+	if (Data > 0 && Data < 2) {
+		return 1;
+	}
+	else if (Data >= 2 && Data < 4) {
+		return 2;
+	}
+	else if (Data >= 4 && Data < 8) {
+		return 3;
+	}
+	else if (Data >= 8 && Data < 16) {
+		return 4;
+	}
+	else if (Data >= 16 && Data < 32) {
+		return 5;
+	}
+	else if (Data >= 32 && Data < 64) {
+		return 6;
+	}
+	else if (Data >= 64 && Data < 128) {
+		return 7;
+	}
+	else if (Data >= 128 && Data < 256) {
+		return 8;
+	}
+	else if (Data >= 256 && Data < 512) {
+		return 9;
+	}
+	else if (Data >= 512 && Data < 1024) {
+		return 10;
+	}
+	else if (Data >= 1024 && Data < 2048) {
+		return 11;
+	}
+	else if (Data >= 2048 && Data < 4096) {
+		return 12;
+	}
+	else{
+		return 0;
+	}
+}
+
+
+/************************************************************************/
+/*         APER    Encode   Tools  Function                             */
+/************************************************************************/
+extern void AperPutSmallNumber(AsnContext *pContext, U32 uNum)
+{
+	if (uNum < 64)
+	{
+		putShortBits(pContext, 1, 0);
+		putShortBits(pContext, 6, uNum);
+	}
+	else
+	{
+		putShortBits(pContext, 1, 1);
+		AperPutSemiConstraintNumber(pContext, 0, uNum);
+	}
+}
+
+extern U32 AperGetSmallNumber(AsnContext *pContext)
+{
+	U32 uNum;
+
+	if (0 ==  getShortBits(pContext, 1))
+	{
+		uNum = getShortBits(pContext, 6);
+	}
+	else
+	{
+		uNum = 	AperGetSemiConstraintNumber(pContext, 0);
+	}
+
+	return uNum;
+}
+
+
+extern U32 AperPutLengthValue(AsnContext *pContext, U32 lBound, U32 uBound, U32 uLen)
+{
+	U32 uDistance;
+
+	ASSERT(uBound >= lBound);
+
+	uDistance = uBound - lBound;
+	
+	if ((0 == uDistance) & (uDistance <= 65535))
+	{
+		// Need Not to encode;
+		return 0;	
+	}
+
+	if (uBound < 65536)
+	{
+		AperPutWholeConstraintNumber(pContext, lBound, uBound, uLen);
+	}
+	else if (uBound >= 65536)
+	{
+		if (uLen <= 127)
+		{
+			PER_ALIGN
+			putShortBits(pContext, 1, 0);
+			putShortBits(pContext, 7, uLen);
+		}
+		else if (uLen >127 && uLen<=16383)
+		{
+			PER_ALIGN
+			putShortBits(pContext, 2, 0x02);
+			putShortBits(pContext, 14, uLen);
+		}
+		else if (uLen>16383)
+		{
+			//....  
+		}
+	}
+
+	return 0;
+}
+
+extern U32 AperGetLengthValue(AsnContext *pContext, U32 lBound, U32 uBound)
+{
+	U32 ulen = 0, uDistance = uBound - lBound;
+	
+	ASSERT(uBound >= lBound);
+
+	if ((0 == uDistance) & (uDistance <= 65535))
+	{
+		// Need Not to encode;
+		return lBound;	
+	}
+	
+	if (uBound < 65536)
+	{
+		ulen = AperGetWholeConstraintNumber(pContext, lBound, uBound);
+	}
+	else if (uBound >= 65536)
+	{
+
+		if (0 == testGetShortBits(pContext, 1))
+		{
+			PER_CLEAR_ALIGN_BITS
+			// Len < 127
+			ulen = getShortBits(pContext, 8);
+		}
+		else if (0x20 == testGetShortBits(pContext, 2))
+		{
+			PER_CLEAR_ALIGN_BITS
+			// uLen >127 && uLen<=16383
+			getShortBits(pContext, 2);
+			ulen = getShortBits(pContext, 14);
+		}
+		else
+		{
+			// uLen>16383  ...
+		}
+	}
+
+	return ulen;
+}
+
+extern void AperPutWholeConstraintNumber(AsnContext *pContext, S32 lBound, S32 uBound, U32 uNum)
+{	
+	U32		range, nByte;
+
+	ASSERT(uBound >= lBound);
+	range = uBound - lBound;
+
+	if (0 == range)
+	{
+		// put no bit 
+	}
+	else if((range >= 1) && (range <= 254))
+	{
+		putShortBits(pContext, GetNumberBitLength(range), uNum-lBound);
+	}
+	else if(255 == range)
+	{
+		PER_ALIGN
+		putShortBits(pContext, 8, uNum-lBound);
+	}
+	else if(range <= 65535)
+	{
+		PER_ALIGN
+		putShortBits(pContext, 16, uNum-lBound);
+	}
+	else if(range >= 65536)
+	{
+		PER_ALIGN
+		range = GetNumberOctetLength(uBound - lBound);
+		nByte = GetNumberOctetLength(uNum - lBound);
+
+		AperPutLengthValue(pContext, 1, range, nByte);
+
+		PER_ALIGN
+		putShortBits(pContext, nByte * 8, uNum-lBound);
+	}
+}
+
+extern U32	AperGetWholeConstraintNumber(AsnContext *pContext, S32 lBound, S32 uBound)
+{
+	U32		range, uNum=0, nByte;
+
+	ASSERT(uBound >= lBound);
+	range = uBound - lBound;
+
+	if (0 == range)
+	{
+		// put no bit 
+	}
+	else if((range >= 1) && (range <= 254))
+	{
+		uNum = getShortBits(pContext, GetNumberBitLength(range)) + lBound;
+	}
+	else if(255 == range)
+	{
+		PER_CLEAR_ALIGN_BITS
+		uNum = getShortBits(pContext, 8) + lBound;
+	}
+	else if(range <= 65535)
+	{
+		PER_CLEAR_ALIGN_BITS
+		uNum = getShortBits(pContext, 16) + lBound;
+	}
+	else if(range >= 65536)
+	{
+		PER_CLEAR_ALIGN_BITS
+		nByte = GetNumberOctetLength(uBound-lBound);
+		nByte = AperGetLengthValue(pContext, 1, nByte);
+		
+		PER_CLEAR_ALIGN_BITS
+		uNum = getShortBits(pContext, nByte * 8) + lBound;
+	}
+
+	return uNum;
+}
+
+
+extern  void AperPutSemiConstraintNumber(AsnContext *pContext, S32 lBound, S32 uNum)
+{	
+	U32		distance, nByte ;
+	
+	ASSERT(uNum >= lBound);
+	distance = uNum - lBound;
+
+	nByte = GetNumberOctetLength(distance);
+	AperPutLengthValue(pContext, 0, ASN_MAX, nByte);
+
+	PER_ALIGN
+
+	putBits(pContext, nByte * 8, distance);
+
+}
+
+extern S32 AperGetSemiConstraintNumber(AsnContext *pContext, S32 lBound)
+{	
+	U32	sNum, nByte;
+
+	nByte = AperGetLengthValue(pContext, 0, ASN_MAX);
+
+	PER_CLEAR_ALIGN_BITS
+	
+	if (nByte <= 3)
+	{
+		sNum = getShortBits(pContext, nByte * 8) + lBound;
+	}
+	else
+	{
+		sNum = getShortBits(pContext, 16);
+		sNum = sNum << 16;
+
+		sNum &= 0xFFFF0000;
+		sNum |= getShortBits(pContext, 16);
+
+		sNum += lBound;
+	}
+		
+	return sNum;
+}
+
+extern  void AperPutNonConstraintNumber(AsnContext *pContext,  S32 uNum)
+{	
+	int		ulen, nByte, temp=0;
+	EncodeBeginPoint	begin;
+
+	PER_ALIGN
+
+	SkipEncodeByte(pContext);	// For Record 
+	begin = BeginTestEncodeLen(pContext);
+
+	if (uNum > 0)
+	{
+		nByte = GetNumberOctetLength(uNum);
+
+		switch(nByte)
+		{
+		case 1:
+			temp = uNum & 0x00000080;
+			break;
+		case 2:
+			temp = uNum & 0x00008000;
+			break;
+		case 3:
+			temp = uNum & 0x00800000;
+		    break;
+		case 4:
+			temp = uNum & 0x80000000;
+		    break;
+		default:
+		    break;
+		}
+
+		if (0 != temp)
+		{
+			putShortBits(pContext, 8, 0);
+		}
+
+		putShortBits(pContext, nByte * 8, uNum);
+	}
+	else
+	{
+		nByte = GetNumberOctetLength(-uNum);
+
+		uNum = -uNum;
+		uNum = ~uNum;
+		uNum += 1;
+
+		if (nByte == 1){
+			uNum &= 0x000000FF;
+		}
+		else if (nByte == 2){
+			uNum &= 0x0000FFFF;
+		}
+		else if (nByte == 3){
+			uNum &= 0x00FFFFFF;
+		}
+
+		putShortBits(pContext, nByte * 8, uNum);
+	}
+
+	PER_ALIGN
+
+	ulen = EndTestEncodeLen(pContext, begin);
+	PutShortSkipedEncodeByte(pContext, GetNumberOctetLength(ulen), ulen, ulen);
+}
+
+extern S32 AperGetNonConstraintNumber(AsnContext *pContext)
+{
+	int		nByte;
+	S32		uNum = 0;
+
+	PER_CLEAR_ALIGN_BITS
+
+	nByte = testGetShortBits(pContext, 8);
+
+	if (0 == getShortBits(pContext, 1))
+	{
+		// positive
+
+		if (0 == testGetShortBits(pContext, 8))
+		{
+			getShortBits(pContext, 8);			
+			uNum =  getShortBits(pContext, 8 * (nByte-1));
+		}
+		else
+		{
+			uNum =  getShortBits(pContext, 8 * nByte);
+		}				
+	}
+	else
+	{
+		// negetive
+		uNum =  getShortBits(pContext, (8 * nByte));
+
+		uNum--;
+		uNum = ~uNum;
+		uNum = -uNum;
+
+		if (nByte == 1){
+			uNum |= 0xFFFFFF00;
+		}
+		else if (nByte == 2){
+			uNum |= 0xFFFF0000;
+		}
+		else if (nByte == 3){
+			uNum |= 0xFF000000;
+		}
+	}
+	
+	
+	PER_CLEAR_ALIGN_BITS
+
+	return uNum;
+}
+
+extern void AperEncodeOpenType(AsnContext *pContext,  U8 * pData, U32 uSize)
+{
+	if (uSize > 0)
+	{
+		AperPutLengthValue(pContext, 0, ASN_MAX, uSize);	
+		putLongBits(pContext, uSize*8, pData);
+	}	
+}
+
+extern U32 AperDecodeOpenTypeLength(AsnContext *pContext)
+{
+	return AperGetLengthValue(pContext, 0, ASN_MAX);
+}
+
+extern U32 AperDecodeOpenType(AsnContext *pContext,  U8 * pData, U32 uSize)
+{
+	U32		   uLen;
+	AsnContext TempContext = *pContext;
+
+	uLen = AperGetLengthValue(pContext, 0, ASN_MAX);
+
+	if (NULL == pData)
+	{	
+		*pContext = TempContext;
+		return uLen;
+	}
+
+	getLongBits(pContext, 8 * asn_min(uLen, uSize),  (U8 *)pData);
+
+	// return decode length (by byte)
+	return asn_min(uLen, uSize);
+}
+
+static void AperEncodeOIDItem(AsnContext *pContext,  U32  uData)
+{
+	ASSERT(uData < 2097152);
+
+	if (uData < 128)
+	{
+		putShortBits(pContext,  8, uData);
+	}
+	else if (uData < 16384)
+	{
+		// First Octet
+		putShortBits(pContext,  1, 1);
+		putShortBits(pContext,  7, (uData - uData%128)/128);
+
+		// Second Octet
+		putShortBits(pContext,  1, 0);
+		putShortBits(pContext,  7, uData%128);
+	}
+	else if (uData < 2097152)
+	{
+		// First Octet
+		putShortBits(pContext,  1, 1);
+		putShortBits(pContext,  7, (uData - uData%16384)/16384);
+		
+		// Second Octet
+		putShortBits(pContext,  1, 1);
+		putShortBits(pContext,  7, ((uData - uData%128)%16384)/128);
+
+		// Third Octet
+		putShortBits(pContext,  1, 0);
+		putShortBits(pContext,  7, uData%128);
+	}
+
+}
+
+static U32 AperDecodeOIDItem(AsnContext *pContext,  U8 **ppData)
+{
+	U32		uNum = 0;
+	U8		uData = **ppData;
+
+	if (uData <= 0x7F)
+	{
+		uNum = uData;
+		(*ppData)++;
+	}	
+	else if (*(*ppData+1)  <= 0x7F)
+	{
+		// First Octet
+		uData &= 0x7F;
+		uNum = uData;
+
+		uNum *= 128;
+
+		(*ppData)++;
+		uData = **ppData;
+		
+		// Second Octet
+		uData &= 0x7F;
+		uNum += uData;
+
+		(*ppData)++;
+	}
+	else if (*(*ppData+2) <= 0x7F)
+	{
+		// First Octet
+		uData &= 0x7F;
+		uNum = uData;
+		uNum *= 128; 
+
+		(*ppData)++;
+		uData = **ppData;
+		
+		// Second Octet
+		uData &= 0x7F;
+		uNum += uData;
+		uNum *= 128; 
+
+		(*ppData)++;
+		uData = **ppData;
+		
+		// Third Octet
+		uData &= 0x7F;
+		uNum += uData;
+
+		(*ppData)++;
+	}
+	else
+	{
+		UA1_ERROR(103);
+	}
+	
+	return uNum;
+}
+
+extern void AperEncodeOID(AsnContext *pContext,  OID *pOid)
+{
+	U32		ulen, i;
+	AsnContext TempContext;
+	U8 * pBuf = NULL;
+	EncodeBeginPoint	begin;
+
+	PER_ALIGN
+
+	begin = BeginTestEncodeLen(pContext);
+
+	TempContext = *pContext;
+
+	putShortBits(pContext,  8, ((*pOid->value)*40 + (* (pOid->value + 1))));
+
+	for(i=2; i<pOid->valueLen; i++)
+	{
+		AperEncodeOIDItem(pContext, *(pOid->value + i));
+	}
+
+	ulen = EndTestEncodeLen(pContext, begin);
+
+	asnMemAlloc(pContext, (void **)&pBuf, ulen);
+	
+	asnMemCopy(pBuf, pContext->pEncoded - ulen, ulen);	
+
+	*pContext = TempContext;
+
+	AperEncodeOpenType(pContext, pBuf, ulen);
+
+   if (pContext->pMemFreeFunc != NULL)
+   {
+      pContext->pMemFreeFunc((void **)&pBuf);
+   }
+   else
+   {
+	asnMemFree((void **)&pBuf);
+   }
+
+}
+
+extern void AperDecodeOID(AsnContext *pContext,  OID *pOid)
+{	
+	U32	 ulen, i, *pItemOrg;
+	U8 * pBuf;// , * pBufOrg;
+		
+	PER_CLEAR_ALIGN_BITS
+
+	ulen = AperDecodeOpenType(pContext, NULL, 0);
+
+	AsnDecodeAlloc(pContext, (void **)&pBuf, ulen);
+
+	//pBufOrg = pBuf;
+
+	AperDecodeOpenType(pContext, pBuf, ulen);
+
+	//Got object Identify Item count
+	for (i=1, pOid->valueLen=2; i<ulen; i++)
+	{
+		if (*(pBuf+i) <= 0x7F )
+		{
+			(pOid->valueLen)++;
+		}
+	}
+
+	AsnDecodeAlloc(pContext, (void **)&(pOid->value), (pOid->valueLen)*4);
+
+	pItemOrg = pOid->value;
+
+	if ((*pBuf) <= 39)
+	{
+		*pOid->value = 0;
+	}
+	else if ((*pBuf) <= 79)
+	{
+		*pOid->value = 1;
+	}
+	else
+	{
+		*pOid->value = 2;
+	}
+
+	*(pOid->value+1) = (*pBuf)%40;
+
+	pBuf++;
+	pOid->value += 2;
+
+	for (i=2; i<pOid->valueLen; i++, pOid->value++)
+	{
+		*pOid->value = AperDecodeOIDItem(pContext, &pBuf);
+	}
+
+	pOid->value = pItemOrg;
+}
+
+
+extern void AperEncodeBitString(AsnContext *pContext, U32 lBound, U32 uBound, U8 *pData, U32 uLen)
+{
+	U32	distance;
+	
+	distance = uBound - lBound;
+	
+	if (0 == distance)
+	{
+		if (lBound <= 16)
+		{
+			putLongBits(pContext, uLen, pData);
+		}
+		else if (lBound <= 65536)
+		{
+			PER_ALIGN
+			putLongBits(pContext, uLen, pData);
+			PER_ALIGN
+		}
+		else
+		{
+			AperPutLengthValue(pContext, distance, distance, distance);
+			putLongBits(pContext, uLen, pData);
+		}
+	}
+	else
+	{
+		AperPutLengthValue(pContext, 0, ASN_MAX, distance);
+		putLongBits(pContext, uLen, pData);
+	}
+}
+
+extern U32 AperDecodeBitString(AsnContext *pContext, U32 lBound, U32 uBound, U8 *pData)
+{
+	U32	distance, uLen;
+	
+	distance = uBound - lBound;
+	
+	if (0 == distance)
+	{
+		if (lBound <= 16)
+		{
+			uLen = lBound;
+			getLongBits(pContext, lBound, (U8 *)pData);
+		}
+		else if (lBound <= 65536)
+		{
+			PER_CLEAR_ALIGN_BITS
+				
+			uLen = lBound;
+			getLongBits(pContext, lBound, (U8 *)pData);
+			
+			PER_CLEAR_ALIGN_BITS
+		}
+		else
+		{
+			uLen = AperGetLengthValue(pContext, distance, distance);
+			AsnDecodeAlloc(pContext,(void **) &pData, lBound);
+			getLongBits(pContext, uLen, (U8 *)pData);
+		}
+	}
+	else
+	{
+		uLen =  AperGetLengthValue(pContext, 0, ASN_MAX);
+		
+		AsnDecodeAlloc(pContext, (void **)&pData, lBound);
+		getLongBits(pContext, uLen, (U8 *)pData);
+	}
+	
+	return uLen;
+}
+
+//////////////////////////////////////////////////////////////////////////
+// String Encode
+//////////////////////////////////////////////////////////////////////////
+
+extern void AperEncodeOneByteString(AsnContext *pContext,  OneByteString *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet *pAlphabet)
+{
+	U32		i=0, bitSize=0;
+ S32     index=0;
+
+	AperPutLengthValue(pContext, minSize, maxSize, pStr->valueLen);
+	
+	PER_ALIGN
+	
+	if (NULL == pAlphabet)
+	{
+		for(i = 0; i < pStr->valueLen; i++)
+		{		
+			putShortBits(pContext, 8,  *(pStr->value+i));
+		}
+	}
+	else
+	{
+		if (IsReindexOneByteAlphabet(pAlphabet))
+		{
+			bitSize = GetOneByteCharacterBitWidth(pAlphabet);
+			
+			for(i = 0; i < pStr->valueLen; i++)
+			{	
+				index = GetAlphabetIndex(pAlphabet, (pStr->value+i));
+				
+				if (-1 == index)
+				{
+					UA1_ERROR(112);
+				}
+				
+				putShortBits(pContext, bitSize,  index);
+			}	
+		}
+		else
+		{
+			for(i = 0; i < pStr->valueLen; i++)
+			{		
+				putShortBits(pContext, 8,  *(pStr->value+i));
+			}
+		}	
+	}
+	
+}
+
+static void AperDecodeOneByteStringA(AsnContext *pContext,  OneByteString *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet *pAlphabet)
+{
+	// ... ?  Check Characters ?	
+	U32		i, bitSize, index;
+
+	pStr->valueLen = AperGetLengthValue(pContext, minSize, maxSize);
+
+	PER_CLEAR_ALIGN_BITS
+
+	if (NULL == pAlphabet)
+	{
+		AsnDecodeAlloc(pContext, (void **)&pStr->value, pStr->valueLen);
+		getLongBits(pContext, pStr->valueLen * 8, (U8 *)pStr->value);
+	}
+	else
+	{
+		if (IsReindexOneByteAlphabet(pAlphabet))
+		{		
+			AsnDecodeAlloc(pContext, (void **)&pStr->value, pStr->valueLen);
+			bitSize = GetOneByteCharacterBitWidth(pAlphabet);
+
+			for(i = 0; i < pStr->valueLen; i++)
+			{	
+				index = getShortBits(pContext, bitSize);
+				*(pStr->value + i) = *(pAlphabet->value + index);
+			}	
+		}
+		else
+		{
+			AsnDecodeAlloc(pContext, (void **)&pStr->value, pStr->valueLen);
+			getLongBits(pContext, pStr->valueLen * 8, (U8 *)pStr->value);
+		}			
+	}	
+}
+
+static  void AperEncodeTwoByteString(AsnContext *pContext,  TwoByteString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet *pAlphabet)
+{
+	// If No Constraint 
+	U32		i;
+
+	AperPutLengthValue(pContext, minSize, maxSize, pStr->valueLen);
+	
+	PER_ALIGN
+	
+	for(i = 0; i < pStr->valueLen; i++){		
+		putShortBits(pContext, 8,  GET_U16_HIGH(*(pStr->value+i)) );
+		putShortBits(pContext, 8,  GET_U16_LOW(*(pStr->value+i)) );
+	}
+
+  if ( pAlphabet) {
+    /* do nothing */
+  } else {
+    /* do nothing */
+  }
+}
+
+static  void AperDecodeTwoByteStringA(AsnContext *pContext,  TwoByteString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet *pAlphabet)
+{
+	// If No Constraint 
+	U32		i;
+	U16		uHigh, uLow;
+
+	pStr->valueLen = AperGetLengthValue(pContext, minSize, maxSize);	
+	AsnDecodeAlloc(pContext, (void **)&pStr->value, pStr->valueLen * 2);
+
+	PER_CLEAR_ALIGN_BITS
+
+	for(i = 0; i < pStr->valueLen; i++){		
+		uHigh = (U16)getShortBits(pContext, 8);
+		uLow  = (U16)getShortBits(pContext, 8);
+		*(pStr->value + i) = MAKE_U16(uHigh, uLow);
+	}
+	
+  if ( pAlphabet) {
+    /* do nothing */
+  } else {
+    /* do nothing */
+  }	
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+// Numeric String
+
+extern  void AperEncodeNumericString(AsnContext *pContext,  asn_NumericString *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet *pAlphabet)
+{
+	// ... ?  Check Characters ?
+	U32		i;
+
+	AperPutLengthValue(pContext, minSize, maxSize, pStr->valueLen);
+	
+	PER_ALIGN
+
+	for(i = 0; i < pStr->valueLen; i++){		
+		putShortBits(pContext, 4,  *(pStr->value+i) - 47);
+	}
+	
+	if ( pAlphabet) {
+    /* do nothing */
+  } else {
+    /* do nothing */
+  }
+}
+
+extern  void AperDecodeNumericStringA(AsnContext *pContext,  asn_NumericString *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet *pAlphabet)
+{
+	// ... ?  Check Characters ?
+	U32		i;
+	
+	pStr->valueLen = AperGetLengthValue(pContext, minSize, maxSize);	
+
+	PER_CLEAR_ALIGN_BITS
+
+	AsnDecodeAlloc(pContext, (void **)&pStr->value, pStr->valueLen);
+
+	for(i = 0; i < pStr->valueLen; i++){		
+		*(pStr->value+i) = (U8)getShortBits(pContext, 4) + 47;
+	}
+  if ( pAlphabet) {
+    /* do nothing */
+  } else {
+    /* do nothing */
+  }	
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+// IA5 String
+extern  void AperEncodeIA5String(AsnContext *pContext,  asn_IA5String *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet *pAlphabet)
+{
+	// ... ?  Check Characters ?
+	AperEncodeOneByteString(pContext, pStr, minSize, maxSize, pAlphabet);
+}
+
+extern  void AperDecodeIA5StringA(AsnContext *pContext,  asn_IA5String *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet *pAlphabet)
+{
+	AperDecodeOneByteStringA (pContext, pStr, minSize, maxSize, pAlphabet);
+}	
+
+//////////////////////////////////////////////////////////////////////////
+// BMP String
+extern  void AperEncodeBMPString(AsnContext *pContext,  asn_BMPString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet *pAlphabet)
+{
+	// ... ?  Check Characters ?
+	AperEncodeTwoByteString(pContext, pStr, minSize, maxSize, pAlphabet);
+}
+
+extern  void AperDecodeBMPStringA(AsnContext *pContext,  asn_BMPString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet *pAlphabet)
+{
+	// ... ?  Check Characters ?
+	AperDecodeTwoByteStringA(pContext, pStr, minSize, maxSize, pAlphabet);
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+// General String
+extern  void AperEncodeGeneralString(AsnContext *pContext,  asn_GeneralString *pStr)
+{
+	AperEncodeOpenType(pContext, (U8 *)pStr->value, pStr->valueLen);
+}
+
+extern  void AperDecodeGeneralStringA(AsnContext *pContext,  asn_GeneralString *pStr)
+{
+	pStr->valueLen = AperDecodeOpenType(pContext, NULL, 0);
+	AsnDecodeAlloc(pContext, (void **)&pStr->value, pStr->valueLen);
+		
+	AperDecodeOpenType(pContext, (U8 *)pStr->value, pStr->valueLen);
+}
+
+extern	void AperDecodeChoiceUnKnowItem(AsnContext *pContext, ChoiceUnKnow *pUnKnowItem)
+{
+	ChoiceUnKnow	*pUnKnow;
+	
+	// In the extension
+	AsnDecodeAlloc(pContext, (void **)&pUnKnow, sizeof(ChoiceUnKnow));
+	pUnKnow->uIndex =  AperGetSmallNumber(pContext); // Index
+	
+	PER_CLEAR_ALIGN_BITS
+	pUnKnow->valueLen = AperDecodeOpenType(pContext, NULL, 0);
+	
+	AsnDecodeAlloc(pContext, (void **)&(pUnKnow->value), pUnKnow->valueLen);
+	AperDecodeOpenType(pContext, pUnKnow->value, pUnKnow->valueLen);
+	
+	pUnKnowItem = pUnKnow;
+}
+
+extern void AperDecodeSequcenceUnKnowItem(AsnContext *pContext,  UnKnowExtensionItemArray *pArray, U32 uSize, Bool  *pIsItemExist)
+{
+	U32	i, uUnKonwSize;
+	U8 *pData;
+	
+	AsnDecodeAlloc(pContext, (void **)&(pArray->value), sizeof(UnKnowExtensionItem) * uSize);
+	memset(pArray->value, 0, sizeof(UnKnowExtensionItem) * uSize);
+	
+	for (i=0; i<uSize; i++)
+	{
+		if (*(pIsItemExist+i))
+		{
+			uUnKonwSize = AperDecodeOpenType(pContext, NULL, 0);
+			AsnDecodeAlloc(pContext, (void **)&pData, uUnKonwSize);
+			AperDecodeOpenType(pContext, pData, uUnKonwSize);
+		
+			(pArray->value + i)->valueLen = uUnKonwSize;
+			(pArray->value + i)->value = pData;
+			pArray->valueLen++;
+		}	
+		else
+		{
+			(pArray->value + i)->valueLen = 0;
+			(pArray->value + i)->value = NULL;
+			pArray->valueLen++;
+		}
+	}
+	
+}
diff --git a/mcu/interface/service/asn1_common/asn_aper_common.h b/mcu/interface/service/asn1_common/asn_aper_common.h
new file mode 100644
index 0000000..d3c39b8
--- /dev/null
+++ b/mcu/interface/service/asn1_common/asn_aper_common.h
@@ -0,0 +1,111 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2011
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*****************************************************************************
+ * $Log:$
+ * 
+ * 09 06 2012 changshun.li
+ * [MOLY00000064] [asn.1] for check in tool/code to MOLY
+ * .
+ *
+ * 03 27 2012 changshun.li
+ * removed!
+ * for msbb2
+ *
+ * 03 27 2012 changshun.li
+ * removed!
+ * for msbb2
+ *
+ ****************************************************************************/
+
+#if !defined _ASN_APER_COMMON_H_
+#define _ASN_APER_COMMON_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "asn_common.h"
+#include "asn_memory.h"
+#include "mtkasn_global.h"
+
+
+extern void AperEncodeOID(AsnContext *pContext,  OID *pOid);
+extern void AperDecodeOID(AsnContext *pContext,  OID *pOid);
+
+extern void AperEncodeBitString(AsnContext *pContext, U32 lBound, U32 uBound, U8 *pData, U32 uLen);
+extern U32  AperDecodeBitString(AsnContext *pContext, U32 lBound, U32 uBound, U8 *pData);
+
+extern void AperEncodeOpenType(AsnContext *pContext,  U8 * pData, U32 uSize);
+extern U32 AperDecodeOpenTypeLength(AsnContext *pContext);
+extern U32 AperDecodeOpenType(AsnContext *pContext,  U8 * pData, U32 uSize);
+
+extern void AperPutNonConstraintNumber(AsnContext *pContext,  S32 uNum);
+extern S32 AperGetNonConstraintNumber(AsnContext *pContext);
+
+extern U32 AperPutLengthValue(AsnContext *pContext, U32 lBound, U32 uBound, U32 uLen);
+extern U32 AperGetLengthValue(AsnContext *pContext, U32 lBound, U32 uBound);
+
+extern void AperPutSmallNumber(AsnContext *pContext, U32 uNum);
+extern U32 AperGetSmallNumber(AsnContext *pContext);
+
+extern void AperPutSemiConstraintNumber(AsnContext *pContext, S32 lBound, S32 uNum);
+extern S32 AperGetSemiConstraintNumber(AsnContext *pContext, S32 lBound);
+
+extern void AperPutWholeConstraintNumber(AsnContext *pContext, S32 lBound, S32 uBound, U32 uNum);
+extern U32 AperGetWholeConstraintNumber(AsnContext *pContext, S32 lBound, S32 uBound);
+
+
+// APER STRING Encode function
+extern void  AperEncodeGeneralString(AsnContext *pContext,  asn_GeneralString *pStr);
+extern void  AperEncodeBMPString(AsnContext *pContext,  asn_BMPString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet  *pAlphabet);
+extern void  AperEncodeIA5String(AsnContext *pContext,  asn_IA5String *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet  *pAlphabet);
+extern void  AperEncodeNumericString(AsnContext *pContext,  asn_NumericString *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet  *pAlphabet);
+extern void  AperDecodeNumericStringA(AsnContext *pContext,  asn_NumericString *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet  *pAlphabet);
+extern void	AperDecodeIA5StringA(AsnContext *pContext,  asn_IA5String *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet  *pAlphabet);
+extern void	AperDecodeBMPStringA(AsnContext *pContext,  asn_BMPString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet  *pAlphabet);
+extern void	AperDecodeGeneralStringA(AsnContext *pContext,  asn_GeneralString *pStr);
+extern void	AperDecodeChoiceUnKnowItem(AsnContext *pContext, ChoiceUnKnow *pUnKnowItem);
+extern void	AperDecodeSequcenceUnKnowItem(AsnContext* pContext,  UnKnowExtensionItemArray *pArray, U32	uSize, Bool  *pIsItemExist);
+extern S32	GetAlphabetIndex(ASN_OneByteAlphabet *pAlphabet, char *pChar);
+
+extern  U32  GetNumberBitLength(U32  Data);
+extern  Bool IsReindexOneByteAlphabet(ASN_OneByteAlphabet *pAlphabet);
+extern  U32  GetOneByteCharacterBitWidth(ASN_OneByteAlphabet *pAlphabet);
+
+	
+#ifdef __cplusplus       
+}
+#endif
+#endif //_ASN_APER_COMMON_H_
diff --git a/mcu/interface/service/asn1_common/asn_common.c b/mcu/interface/service/asn1_common/asn_common.c
new file mode 100644
index 0000000..89b92c4
--- /dev/null
+++ b/mcu/interface/service/asn1_common/asn_common.c
@@ -0,0 +1,921 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2011
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/****************************************************************************
+ *
+ * COMPONENT:   ASN
+ * MODULE:      ASN_COMMON
+ * DESCRIPTION: Auto generated by MTK ASN.1 Compiler
+ *
+ ****************************************************************************/
+/*****************************************************************************
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ ****************************************************************************/
+
+#include <setjmp.h>
+#include <assert.h>
+#include "kal_public_api.h"
+#include "asn_common.h"
+#include "asn_memory.h"
+
+#ifdef  MCD_DLL_EXPORT
+#include <stdarg.h>
+
+#if defined(__COSIM_BYPASS_DRV__)
+void MDM_ASSERT(kal_uint32 e1, kal_uint32 e2, kal_uint32 e3)
+{
+    while(1);/* YY Hsieh  */
+}
+#endif
+
+void AsnFreeString( char *string )
+{
+   if( string )
+   {
+      asnMemFree( (void **)&string );
+   }
+}
+
+void InitAsnBuf( AsnContext *pContext )
+{
+   pContext->printBufSize = ASNBUF_BLOCKSIZE;
+   pContext->pMemAllocFunc=NULL;
+   pContext->pMemFreeFunc =NULL;
+   asnMemAlloc(pContext,(void**)&pContext->printBufStart, pContext->printBufSize);
+
+   pContext->printBufNext = pContext->printBufStart;
+}
+
+void AsnPrint( AsnContext *pContext, char *fmt, ... )
+{
+   va_list va;
+   char *new_buf;
+
+   if( (unsigned)(pContext->printBufNext - pContext->printBufStart) > pContext->printBufSize - ASNBUF_RESERVE )
+   {
+      /* Buffer usage has crossed the watermark - need to allocate another
+         buffer one block size bigger */
+      pContext->printBufSize += ASNBUF_BLOCKSIZE;
+
+      asnMemAlloc(pContext,(void**)&new_buf, pContext->printBufSize );
+
+      /* Copy everything from the old buffer to the new buffer */
+      memcpy( new_buf, pContext->printBufStart, pContext->printBufNext - pContext->printBufStart );
+      pContext->printBufNext = pContext->printBufNext - pContext->printBufStart + new_buf;
+
+      /* Free the old buffer */
+      if( pContext->printBufStart )
+         asnMemFree( (void**)&pContext->printBufStart );
+      pContext->printBufStart = new_buf;
+   }
+
+   va_start( va, fmt );
+
+   pContext->printBufNext += vsprintf( pContext->printBufNext, fmt, va );
+
+   va_end( va );
+}
+
+void AsnPrintNull( AsnContext *pContext )
+{
+   AsnPrint( pContext, "NULL" );
+}
+
+void AsnPrintInteger( AsnContext *pContext, S32 value )
+{
+   AsnPrint( pContext, "%d", value );
+}
+
+void AsnPrintBoolean( AsnContext *pContext, Bool boolean )
+{
+   if( boolean == TRUE )
+   {
+      AsnPrint( pContext, "TRUE" );
+   }
+   else
+   {
+      AsnPrint( pContext, "FALSE" );
+   }
+}
+
+void AsnPrintOctetString( AsnContext *pContext, U8 *buffer, U32 length )
+{
+   unsigned int i;
+
+   AsnPrint( pContext, "'" );
+   for( i = 0; i < length; i++ )
+   {
+      AsnPrint( pContext, "%02X", buffer[i] );
+   }
+   AsnPrint( pContext, "'H" );
+}
+
+void AsnPrintBitString( AsnContext *pContext, U8 *buffer, U32 length )
+{
+   unsigned int i;
+   U8 mask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
+
+   AsnPrint( pContext, "'" );
+   for( i = 0; i < length; i++ )
+   {
+      if( buffer[ i/8 ] & mask[ i%8 ] )
+         AsnPrint( pContext, "1" );
+      else
+         AsnPrint( pContext, "0" );
+   }
+   AsnPrint( pContext, "'B" );
+}
+
+void AsnPrintCharacterString( AsnContext *pContext, char *string )
+{
+   AsnPrint( pContext, "\"" );
+   AsnPrint( pContext, "%s", string );
+   AsnPrint( pContext, "\"" );
+}
+
+void AsnPrintOneByteString( AsnContext *pContext, U8 *buffer, U32 length )
+{
+   unsigned int i;
+   AsnPrint( pContext, "'" );
+   for( i = 0; i < length; i++ )
+   {
+      AsnPrint( pContext, "%c", buffer[i] );
+   }
+   AsnPrint( pContext, "'" );
+}
+
+void AsnPrintVisibleString( AsnContext *pContext, asn_VisibleString* pType )
+{
+    AsnPrintOneByteString( pContext, pType->value, pType->valueLen );
+}
+
+void AsnPrintIA5String( AsnContext *pContext, asn_IA5String* pType )
+{
+    AsnPrintOneByteString( pContext, pType->value, pType->valueLen );
+}
+#endif //MCD_DLL_EXPORT
+
+
+U16 GetUperLengthDeterminant( AsnContext *pContext )
+{
+   U16 length = 0;
+   if( ! getShortBits( pContext, 1 ) )
+   {
+      /* 7 bit length */
+      length = (U16)getShortBits( pContext, 7 );
+   }
+   else
+   if( !getShortBits( pContext, 1 ) )
+   {
+      /* 14 bit length */
+      length = (U16)getShortBits( pContext, 14 );
+   }
+   else
+   {
+      /* Unsupported length format */
+      UA1_ERROR( 1 );
+   }
+
+   return length;
+}
+
+void PutUperLengthDeterminant( AsnContext *pContext, U16 length )
+{
+   if( length < 128 )
+   {
+      /* 8 bit length determinant */
+      putShortBits( pContext, 8, length );
+   }
+   else
+   if( length < 16384 )
+   {
+      /* 16 bit length determinant */
+      putShortBits( pContext, 16, length | 0x8000 );
+   }
+   else
+   {
+      /* Unsupported length */
+      UA1_ERROR( 2 );
+   }
+}
+
+void AsnFreeDecoded( void *pType, PAsnMemFreeCallBack pFreeFunc)
+{
+   AsnDecodeFree( ( AllocRecord *)pType - 1, pFreeFunc);
+}
+
+void AsnFreeEncoded( U8 *pEncoded, PAsnMemFreeCallBack pFreeFunc)
+{
+   AsnEncodeFree( pEncoded, pFreeFunc);
+}
+
+void AsnRootDecodeAlloc( AsnContext *pContext, void **ppType, int size )
+{
+   if( !(*ppType) )
+   {
+#if defined(__UMTS_RAT__) || defined(__LTE_RAT__)
+      int i;
+#endif      
+      size += sizeof( AllocRecord );
+      asnMemAlloc(pContext, (void**) &pContext->decodeAlloc, size );
+	  pContext->decodeAlloc->ppEnd = &(pContext->decodeAlloc->pMemBlock[0]) + sizeof( pContext->decodeAlloc->pMemBlock ) / sizeof( pContext->decodeAlloc->pMemBlock[0] );
+	  pContext->decodeAlloc->ppNext = &(pContext->decodeAlloc->pMemBlock[0]);
+      *ppType = pContext->decodeAlloc + 1;
+
+#if defined(__UMTS_RAT__) || defined(__LTE_RAT__)      
+	  /*nick for block reset*/
+      pContext->decodeAlloc->blocknum = 0;
+      for ( i = 0 ; i < ASN_BLOCK_FREE_NUM ;i ++) {          
+        pContext->decodeAlloc->start[i] = NULL;
+        pContext->decodeAlloc->count[i] = 0;
+      }
+#endif 
+   }
+}
+
+void AsnDecodeAlloc( AsnContext *pContext, void **ppMem, int size )
+{
+   if( !pContext->decodeAlloc )
+   {
+      /* Attempt to allocate memory when decoding to a user supplied buffer */
+      UA1_ERROR( 3 );
+   }
+
+   if( pContext->decodeAlloc->ppNext >= pContext->decodeAlloc->ppEnd )
+   {
+      /* Limit of runtime allocated decode memory blocks reached */
+	    //printf("Limit of runtime allocated decode memory blocks reached");
+	    UA1_ERROR( 4 );
+   }
+   asnMemAlloc(pContext, ppMem, size );
+   *pContext->decodeAlloc->ppNext++ = *ppMem;
+}
+
+void AsnDecodeFree( AllocRecord *decodeAlloc, PAsnMemFreeCallBack pFreeFunc)
+{
+  void **ppFree;
+  if( decodeAlloc )
+  {
+    for( ppFree = decodeAlloc->pMemBlock; ppFree < decodeAlloc->ppNext; ppFree++ )
+    {
+      if (pFreeFunc == NULL)
+      {
+        asnMemFree( ppFree );
+      }
+      else
+      {
+        pFreeFunc( ppFree );
+      }
+    }
+
+    if (pFreeFunc == NULL)
+    {
+        asnMemFree((void**)&decodeAlloc);
+    }
+    else
+    {
+        pFreeFunc((void**)&decodeAlloc);
+    }
+  }
+}
+
+#if defined(__UMTS_RAT__) || defined(__LTE_RAT__)
+/* nick integrate from old asn */
+
+void AsnDecodeFreeWithCallback( AllocRecord *decodeAlloc, PAsnMemFreeCallBack pFreeFunc)
+{
+  void **ppFree;
+  if( decodeAlloc )
+  {
+    for( ppFree = decodeAlloc->pMemBlock; ppFree < decodeAlloc->ppNext; ppFree++ )
+    {
+      if (pFreeFunc == NULL)
+      {
+        asnMemFree( ppFree );
+      }
+      else
+      {
+        pFreeFunc( ppFree );
+      }
+    }
+
+    if (pFreeFunc == NULL)
+    {
+        asnMemFree((void**)&decodeAlloc);
+    }
+    else
+    {
+        pFreeFunc((void**)&decodeAlloc);
+    }
+  }
+}
+
+
+
+/*nick for block free */
+static void AsnDecodeFreeWithBlock( AllocRecord *decodeAlloc, PAsnMemFreeCallBack pFreeFunc)
+{
+void **ppFree;
+
+   if( decodeAlloc )
+   {
+      for( ppFree = decodeAlloc->pMemBlock; ppFree < decodeAlloc->ppNext; ppFree++ )
+      {
+        int i = 0;
+        int found = 0;
+        for (i=0; i <ASN_BLOCK_FREE_NUM ; i++) {
+        
+         if (!decodeAlloc->start[i]) break;
+          
+         if (decodeAlloc->start[i] && 
+             decodeAlloc->count[i] &&
+             *ppFree == decodeAlloc->start[i] ) {
+
+          ppFree += ( decodeAlloc->count[i] -1 );
+          found = 1;
+          break;
+         }                   
+        }
+         if (found ) continue;
+         
+         
+         if (pFreeFunc == NULL)
+         {
+             asnMemFree((void**)ppFree );
+         }
+         else
+         {
+             pFreeFunc((void**)ppFree );
+         }
+      }
+
+      if (pFreeFunc == NULL)
+      {
+          asnMemFree((void**)&decodeAlloc);
+      }
+      else
+      {
+          pFreeFunc((void**)&decodeAlloc);
+      }
+      
+   }
+}
+
+static void AsnDecodeFreeSetBlock( AllocRecord *decodeAlloc, PAsnMemFreeCallBack pFreeFunc, void *start, int count )
+{
+//void **ppFree;
+
+   if( decodeAlloc )
+   {
+      /*EXT_ASSERT(start && count);*/
+      /*EXT_ASSERT(decodeAlloc->blocknum < ASN_BLOCK_FREE_NUM);*/
+      if (1) { /* no constrain here */
+        decodeAlloc->start[decodeAlloc->blocknum] = start;
+        decodeAlloc->count[decodeAlloc->blocknum] = count;
+        decodeAlloc->blocknum++;
+      }
+      if (pFreeFunc == NULL) {
+        /* do nothing*/
+      } else {
+        /* do nothing*/
+      }
+   }
+}
+
+void AsnFreeDecodedWithBlock( void *pType , PAsnMemFreeCallBack pFreeFunc)
+{
+   AsnDecodeFreeWithBlock( (AllocRecord *)pType - 1, pFreeFunc );
+}
+
+void AsnFreeDecodedSetBlock( void *pType, PAsnMemFreeCallBack pFreeFunc, void *start, int count)
+{
+   AsnDecodeFreeSetBlock( (AllocRecord *)pType - 1, pFreeFunc, start, count);
+}
+#endif
+
+void AsnEncodeAlloc( AsnContext *pContext, U8 **ppMem, U32 *pEncodedLength )
+{
+   U32 size;
+
+   if (NULL == ppMem)
+   {
+      // Encode length test
+      pContext->pEncoded = NULL;
+   }
+   else
+   {
+      if( !(*ppMem) )
+      {
+         /* Fixed size buffer allocated for encoding, you can change this size by modify the batch command */
+         size = 4000;
+         asnMemAlloc(pContext, (void**)&pContext->encodeAlloc, size );
+         *ppMem = (U8*)pContext->encodeAlloc;
+      }
+      NOT_USED( pEncodedLength );
+   }
+}
+
+void AsnEncodeFree( void *pFree, PAsnMemFreeCallBack pFreeFunc)
+{
+   if( pFree )
+   {
+   	 if (pFreeFunc == NULL)
+   	 {
+   	   asnMemFree( &pFree );
+   	 }
+   	 else
+   	 {
+   	 	 pFreeFunc( &pFree );
+   	 }
+   }
+}
+
+#if defined(__UMTS_RAT__) || defined(__LTE_RAT__)
+/* nick add it*/
+void AsnEncodeFreeWithCallback( void *pFree, PAsnMemFreeCallBack pFreeFunc)
+{
+   if( pFree )
+   {
+   	 if (pFreeFunc == NULL)
+   	 {
+   	   asnMemFree( &pFree );
+   	 }
+   	 else
+   	 {
+   	 	 pFreeFunc( &pFree );
+   	 }
+   }
+}
+#endif
+
+void AsnError( AsnContext *pContext, U32 errorCode )
+{
+   pContext->result = errorCode;
+   longjmp( pContext->env, 1 );
+}
+
+extern S32	GetAlphabetIndex(ASN_OneByteAlphabet *pAlphabet, char *pChar)
+{
+	U32		uIndex, left, right;
+	left = 0;
+	right = pAlphabet->valueLen - 1;
+
+	while(left <= right)
+    {
+        uIndex = (left + right) / 2;
+        if(*(pAlphabet->value+uIndex) == *pChar)
+		{
+            return uIndex;
+		}
+        else if(*(pAlphabet->value+uIndex) > *pChar)
+		{
+			right = uIndex - 1; 
+		}
+        else
+		{
+            left = uIndex + 1;
+		}
+	}
+	return -1;
+}
+
+extern U32 GetNumberOctetLength(U32  Data)
+{
+	if (Data <= 0xFF) {
+		return 1;
+	}
+	if (Data > 0xFF &&
+		Data <= 0xFFFF) {
+		return 2;
+	}
+	if (Data > 0xFFFF &&
+		Data <= 0xFFFFFF) {
+		return 3;
+	}
+	else if (Data > 0xFFFFFF &&
+			Data <= 0xFFFFFFFF) {
+		return 4;
+	}
+	else{
+		return 0;
+	}
+}
+
+extern Bool OIDCompare(OID  oidA, U32 length, U32 *pValue)
+{
+	if (oidA.valueLen != length)
+	{
+		return (Bool)FALSE;
+	}
+	if (0 == asnMemCmp(oidA.value, pValue, length * sizeof(U32)))
+	{
+		return (Bool)TRUE;
+	}
+	else
+	{
+		return (Bool)FALSE;
+	}
+}
+
+static	struct {
+	U8 *pByte;
+}SkipedEncodeByte;
+
+extern  void  SkipEncodeByte(AsnContext *pContext)
+{
+	SkipedEncodeByte.pByte = pContext->pEncoded;
+	pContext->pEncoded += 1;
+}
+
+extern EncodeBeginPoint BeginTestEncodeLen(AsnContext *pContext)
+{
+   if (NULL != pContext->pEncoded)
+   {
+      return (EncodeBeginPoint) pContext->pEncoded;
+   }
+   else
+   {
+      return (EncodeBeginPoint)pContext->shiftRegister;
+   }
+}
+
+extern  U32 EndTestEncodeLen(AsnContext *pContext, EncodeBeginPoint	BeginPoint)
+{
+   S32	len;
+   ASSERT(BeginPoint != 0);
+
+   if (NULL == pContext->pEncoded)
+   {
+      len = (U32)pContext->shiftRegister - (U32)BeginPoint;
+   }
+   else
+   {
+      len = (U32)pContext->pEncoded - (U32)BeginPoint;
+   }
+
+   len = len > 0 ? len : -len ;
+   return len;
+}
+
+extern U32 testGetShortBits( AsnContext *pContext, U32 numBits)
+{
+	U32		result;
+	AsnContext TempContext = *pContext;
+	result = getShortBits(&TempContext, numBits);
+
+	return result;
+}
+
+extern  void PutShortSkipedEncodeByte(AsnContext *pContext,  U32 uByte, U32 Data, U32 uAfterSize)
+{
+	AsnContext	tempContext;
+
+	if (uAfterSize != 0)
+	{
+		ASSERT(1 >= uByte);
+	}
+
+	if (1 < uByte)
+	{
+		asnMemMove(SkipedEncodeByte.pByte+uByte, SkipedEncodeByte.pByte + 1, uAfterSize);
+	}
+
+	tempContext = *pContext;
+	pContext->pEncoded = SkipedEncodeByte.pByte;
+	putShortBits(pContext, uByte * 8, Data);
+
+	*pContext = tempContext;
+}
+
+
+#define MAX_BITS_FOR_SHORT (24)
+#define BIT_MASK_ARRAY_LENGTH (65)
+
+#if defined (__GNUC__)
+
+static const U64 lsbMask[BIT_MASK_ARRAY_LENGTH]=
+{
+0X0000000000000000ULL,
+0X0000000000000001ULL, 0X0000000000000003ULL, 0X0000000000000007ULL, 0X000000000000000FULL,
+0X000000000000001FULL, 0X000000000000003FULL, 0X000000000000007FULL, 0X00000000000000FFULL,
+0X00000000000001FFULL, 0X00000000000003FFULL, 0X00000000000007FFULL, 0X0000000000000FFFULL,
+0X0000000000001FFFULL, 0X0000000000003FFFULL, 0X0000000000007FFFULL, 0X000000000000FFFFULL,
+0X000000000001FFFFULL, 0X000000000003FFFFULL, 0X000000000007FFFFULL, 0X00000000000FFFFFULL,
+0X00000000001FFFFFULL, 0X00000000003FFFFFULL, 0X00000000007FFFFFULL, 0X0000000000FFFFFFULL,
+0X0000000001FFFFFFULL, 0X0000000003FFFFFFULL, 0X0000000007FFFFFFULL, 0X000000000FFFFFFFULL,
+0X000000001FFFFFFFULL, 0X000000003FFFFFFFULL, 0X000000007FFFFFFFULL, 0X00000000FFFFFFFFULL,
+0X00000001FFFFFFFFULL, 0X00000003FFFFFFFFULL, 0X00000007FFFFFFFFULL, 0X0000000FFFFFFFFFULL,
+0X0000001FFFFFFFFFULL, 0X0000003FFFFFFFFFULL, 0X0000007FFFFFFFFFULL, 0X000000FFFFFFFFFFULL,
+0X000001FFFFFFFFFFULL, 0X000003FFFFFFFFFFULL, 0X000007FFFFFFFFFFULL, 0X00000FFFFFFFFFFFULL,
+0X00001FFFFFFFFFFFULL, 0X00003FFFFFFFFFFFULL, 0X00007FFFFFFFFFFFULL, 0X0000FFFFFFFFFFFFULL,
+0X0001FFFFFFFFFFFFULL, 0X0003FFFFFFFFFFFFULL, 0X0007FFFFFFFFFFFFULL, 0X000FFFFFFFFFFFFFULL,
+0X001FFFFFFFFFFFFFULL, 0X003FFFFFFFFFFFFFULL, 0X007FFFFFFFFFFFFFULL, 0X00FFFFFFFFFFFFFFULL,
+0X01FFFFFFFFFFFFFFULL, 0X03FFFFFFFFFFFFFFULL, 0X07FFFFFFFFFFFFFFULL, 0X0FFFFFFFFFFFFFFFULL,
+0X1FFFFFFFFFFFFFFFULL, 0X3FFFFFFFFFFFFFFFULL, 0X7FFFFFFFFFFFFFFFULL, 0XFFFFFFFFFFFFFFFFULL
+};
+
+#else
+
+static const U64 lsbMask[BIT_MASK_ARRAY_LENGTH]=
+{
+0x0000000000000000,
+0x0000000000000001, 0x0000000000000003, 0x0000000000000007, 0x000000000000000f,
+0x000000000000001f, 0x000000000000003f, 0x000000000000007f, 0x00000000000000ff,
+0x00000000000001ff, 0x00000000000003ff, 0x00000000000007ff, 0x0000000000000fff,
+0x0000000000001fff, 0x0000000000003fff, 0x0000000000007fff, 0x000000000000ffff,
+0x000000000001ffff, 0x000000000003ffff, 0x000000000007ffff, 0x00000000000fffff,
+0x00000000001fffff, 0x00000000003fffff, 0x00000000007fffff, 0x0000000000ffffff,
+0x0000000001ffffff, 0x0000000003ffffff, 0x0000000007ffffff, 0x000000000fffffff,
+0x000000001fffffff, 0x000000003fffffff, 0x000000007fffffff, 0x00000000ffffffff,
+0x00000001ffffffff, 0x00000003ffffffff, 0x00000007ffffffff, 0x0000000fffffffff,
+0x0000001fffffffff, 0x0000003fffffffff, 0x0000007fffffffff, 0x000000ffffffffff,
+0x000001ffffffffff, 0x000003ffffffffff, 0x000007ffffffffff, 0x00000fffffffffff,
+0x00001fffffffffff, 0x00003fffffffffff, 0x00007fffffffffff, 0x0000ffffffffffff,
+0x0001ffffffffffff, 0x0003ffffffffffff, 0x0007ffffffffffff, 0x000fffffffffffff,
+0x001fffffffffffff, 0x003fffffffffffff, 0x007fffffffffffff, 0x00ffffffffffffff,
+0x01ffffffffffffff, 0x03ffffffffffffff, 0x07ffffffffffffff, 0x0fffffffffffffff,
+0x1fffffffffffffff, 0x3fffffffffffffff, 0x7fffffffffffffff, 0xffffffffffffffff
+};
+#endif //defined (__GNUC__)
+
+extern void initFifo( AsnContext *pContext, U8 *buffer, U32 bufferLength )
+{
+   pContext->pEncoded = buffer;
+   pContext->pEncodedEnd = buffer + bufferLength;
+   pContext->shiftRegister = pContext->shiftRegisterLength = 0;
+   pContext->result = 0;
+}
+
+extern void flushFifo( AsnContext *pContext )
+{
+   if( pContext->shiftRegisterLength > 0 )
+   {
+      if (NULL == pContext->pEncoded)
+      {
+         pContext->shiftRegister++;
+	  }
+      else
+      {
+         *pContext->pEncoded++ = (U8)(pContext->shiftRegister >> 24);
+	  }
+   }
+}
+
+extern U32 getShortBits( AsnContext *pContext, U32 numBits )
+{
+   U32 retVal;
+   ASSERT( numBits <= MAX_BITS_FOR_SHORT );
+
+   while ( numBits > pContext->shiftRegisterLength )
+   {
+      if( pContext->pEncoded >= pContext->pEncodedEnd )
+      {
+         UA1_ERROR( 5 );
+      }
+
+      pContext->shiftRegister |= *pContext->pEncoded++ << (24 - pContext->shiftRegisterLength);
+      pContext->shiftRegisterLength += 8;
+   }
+
+   retVal = pContext->shiftRegister >> (32 - numBits);
+   pContext->shiftRegister <<= numBits;
+   pContext->shiftRegisterLength -= numBits;
+
+   return( retVal );
+}
+
+extern U32 getBits( AsnContext *pContext, U32 numBits )
+{
+   U32 retVal;
+   if ( numBits > 32)
+   {
+      UA1_ERROR( 7 );
+   }
+   else if ( numBits <= MAX_BITS_FOR_SHORT )
+   {
+      retVal = (U32)getShortBits( pContext, numBits );
+   }
+   else
+   {
+      retVal = (U32) getShortBits( pContext, MAX_BITS_FOR_SHORT );
+      numBits -= MAX_BITS_FOR_SHORT;
+      /* ASN.1 is big endian so first n bits go at top of word */
+      retVal <<= numBits;
+      retVal |= (U32)getShortBits( pContext, numBits );
+   }
+   return( retVal );
+}
+
+extern void getLongBits( AsnContext *pContext, U32 numBits, U8 *outputBuffer )
+{
+   while ( numBits >= 8 )
+   {
+      if( pContext->pEncoded >= pContext->pEncodedEnd )
+      {
+         UA1_ERROR( 6 );
+      }
+      pContext->shiftRegister |= *pContext->pEncoded++ << (24 - pContext->shiftRegisterLength);
+      *outputBuffer++ = (U8)(pContext->shiftRegister >> 24);
+      pContext->shiftRegister <<= 8;
+      numBits-= 8;
+   }
+
+   if ( numBits )
+   {
+      *outputBuffer = (U8)(getShortBits( pContext, numBits ) << (8 - numBits));
+   }
+}
+
+extern U64 getInt64( AsnContext *pContext, U32 numBits )
+{
+   U64 retVal;
+   ASSERT( numBits <= 64 );
+   if ( numBits <= 32 )
+   {
+      retVal = (U64)getBits( pContext, numBits );
+   }
+   else
+   {
+      retVal = (U64) getBits( pContext, 32 );
+      numBits -= 32;
+      /* ASN.1 is big endian so first n bits go at top of word */
+      retVal <<= numBits;
+      retVal |= (U64)getBits( pContext, numBits );
+   }
+   return( retVal );
+}
+
+extern void putShortBits( AsnContext *pContext, U32 numBits, U32 data )
+{
+   ASSERT( numBits <= MAX_BITS_FOR_SHORT );
+   ASSERT( 0 == (data & ~lsbMask[numBits]) );
+
+   if (NULL != pContext->pEncoded)
+   {
+      pContext->shiftRegister |= data << (32 - pContext->shiftRegisterLength - numBits);
+   }
+
+   pContext->shiftRegisterLength += numBits;
+
+   while ( pContext->shiftRegisterLength >= 8 )
+   {
+	  if (NULL == pContext->pEncoded)
+      {
+         pContext->shiftRegister++;
+      }
+      else
+      {
+         if (pContext->pEncoded >= pContext->pEncodedEnd)
+         {
+             UA1_ERROR(15);
+         }
+
+         *pContext->pEncoded++ = (U8)(pContext->shiftRegister >> 24);
+         pContext->shiftRegister <<= 8;
+      }
+
+      pContext->shiftRegisterLength -= 8;
+   }
+}
+
+extern void putBits( AsnContext *pContext, U32 numBits, U32 data )
+{
+   ASSERT( numBits <= 32 );
+   if( numBits > MAX_BITS_FOR_SHORT )
+   {
+      /* Insert top 24 bits */
+      putShortBits( pContext, MAX_BITS_FOR_SHORT, data >> (numBits - MAX_BITS_FOR_SHORT) );
+      /* reduce amount to fit, and then mask off bits inserted */
+      numBits -= MAX_BITS_FOR_SHORT;
+      data &= lsbMask[numBits];
+   }
+   putShortBits( pContext, numBits, data );
+}
+
+extern void putInt64( AsnContext *pContext, U32 numBits, U64 data )
+{
+   ASSERT( numBits <= 64 );
+   if( numBits > 32 )
+   {
+      /* Insert top 32 bits */
+      putBits( pContext, 32, (U32)(data >> (numBits - 32)) );
+      /* reduce amount to fit, and then mask off bits inserted */
+      numBits -= 32;
+      data &= lsbMask[numBits];
+   }
+   putBits( pContext, numBits, (U32)(data) );
+}
+
+extern void putLongBits( AsnContext *pContext, U32 numBits, U8 *data )
+{
+   while ( numBits >= 8 )
+   {
+	  if (NULL == pContext->pEncoded)
+	  {
+		  pContext->shiftRegister++;
+	  }
+	  else
+      {
+          if (pContext->pEncoded >= pContext->pEncodedEnd)
+          {
+              UA1_ERROR(15);
+          }
+
+          pContext->shiftRegister |= *data++ << ( 24 - pContext->shiftRegisterLength );
+          *pContext->pEncoded++ = (U8)(pContext->shiftRegister >> 24);
+          pContext->shiftRegister <<= 8;
+      }
+
+      numBits -= 8;
+   }
+
+   if ( numBits && data )
+   {
+      putShortBits( pContext, numBits, *data >> (8 - numBits) );
+   }
+}
+
diff --git a/mcu/interface/service/asn1_common/asn_common.h b/mcu/interface/service/asn1_common/asn_common.h
new file mode 100644
index 0000000..97ea4c5
--- /dev/null
+++ b/mcu/interface/service/asn1_common/asn_common.h
@@ -0,0 +1,456 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2011
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/****************************************************************************
+ *
+ * COMPONENT:   ASN
+ * MODULE:      ASN_COMMON
+ * DESCRIPTION: Auto generated by MTK ASN.1 Compiler
+ *
+ ****************************************************************************/
+/*****************************************************************************
+ * $Log:$
+ *
+ * 12 19 2018 hannu.huusko
+ * [MOLY00308815] [6297][NRRC] MAIN module implementation
+ * [NRRC] Increase memory size for ASN.1 decoding
+ *
+ * 09 28 2018 eric.chuang
+ * [MOLY00355921] Fix target build warning due to nano MIPS
+ * .remove build warning for Nano MIPS compiler
+ *
+ * 06 04 2014 eric.chuang
+ * [MOLY00067682] split asn.1 for 4G vs. 2G only projects
+ * .use __UMTS_RAT__ & __LTE_RAT__ to split 4G vs. 2G only projects
+ * .fix memory leak when decoding wrong extension items
+ *
+ * 03 28 2014 eric.chuang
+ * [MOLY00061188] ASN.1 memory leakage when decoding wrong data
+ * .
+ *
+ * 11 06 2012 nick.wang
+ * [MOLY00005322] TATAKA merge to MOLY
+ * Merge Moly_tataka asn common
+ * 
+ * 09 06 2012 changshun.li
+ * [MOLY00000064] [asn.1] for check in tool/code to MOLY
+ * .
+ *
+ * 03 27 2012 changshun.li
+ * removed!
+ * for msbb2
+ *
+ * 03 27 2012 changshun.li
+ * removed!
+ * for msbb2
+ *
+ ****************************************************************************/
+
+#ifndef ASN_COMMON_H
+#define ASN_COMMON_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+
+//#include <setjmp.h>
+//#include "app_buff_alloc.h"
+#include "asn_memory.h"
+#include "mtkasn_global.h"
+
+typedef enum
+{
+   ASN_OK    =  0,
+   ASN_ERROR = -1
+}
+AsnStatus;
+
+typedef S8 AsnNull;
+
+typedef struct
+{
+   int length;
+   unsigned char value[100];
+}
+AsnAny;
+
+typedef S8 AsnObjId;
+
+typedef S8 AsnOpen;
+
+typedef S8 AsnBool;
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef NULL
+#define NULL (void *)0
+#endif
+
+#ifndef NOT_USED
+#define NOT_USED(x) (void)(x)
+#endif
+
+#define UA1_ERROR( x ) AsnError( pContext, x )
+
+/* Error Code nick */
+#define ASN_ERR_GP_COM_NG (0)   /* original    */    
+#define ASN_ERR_GP_PRC_NG (1)   /* process     */    
+#define ASN_ERR_GP_EDC_NG (2)   /* en/decode   */    
+#define ASN_ERR_GP_NOT_SP (10)  /* not support */
+
+#define ASN_ERR_GETGP(x)    ( ((x) >> 24) & 0x00FF)
+#define ASN_ERR_SETGP(x,y)  ( ((x) << 24 ) | (y & 0x00FFFFFF) )
+#define ASN_ERR_OK          (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG,   0))  /* OK */
+#define ASN_ERR_SPNULL      (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG, 300))  /* error code for special purpose */
+#define ASN_ERR_ATST        (ASN_ERR_SETGP(ASN_ERR_GP_EDC_NG, 500)) /* error code autogen start code  */
+
+#define ASN_ERR_MEMALOC     (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG,  16))  /* error code for special purpose */
+#define ASN_ERR_DECALOC     (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG,   3)) /* no root */
+#define ASN_ERR_DECALOC2    (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG,   4)) /* no enough buffer */
+#define ASN_ERR_DECLEN      (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG,   5)) /* get short */
+#define ASN_ERR_DECLEN2     (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG,   6)) /* get long  */
+#define ASN_ERR_ENCLEN      (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG,  15)) /* put short */
+#define ASN_ERR_ENCLEN2     (ASN_ERR_SETGP(ASN_ERR_GP_NOT_SP,   0)) /* put long  */
+
+typedef struct
+{
+#ifdef  MCD_DLL_EXPORT
+   void *pMemBlock[1024];
+#else
+#if defined(__NR_RAT__)
+   void *pMemBlock[400];
+#elif defined(__UMTS_RAT__) || defined(__LTE_RAT__)
+   void *pMemBlock[200]; /* enlarge block number only for 3/4G */
+#else
+   void *pMemBlock[20];
+#endif
+#endif
+   void **ppNext;
+   void **ppEnd;
+#if defined(__UMTS_RAT__) || defined(__LTE_RAT__)
+  /* nick for block free */
+#define ASN_BLOCK_FREE_NUM 32
+   int blocknum;
+   void *start[ASN_BLOCK_FREE_NUM];
+   unsigned int  count[ASN_BLOCK_FREE_NUM];
+#endif
+} AllocRecord;
+
+//add for customize call back
+typedef  void  (*PAsnMemAllocCallBack)(void **memPtr, unsigned long size, const char *file, unsigned long line);
+typedef  void  (*PAsnMemFreeCallBack)(void ** ppBuffer);
+//add for customize call back end
+
+typedef struct
+{
+   PAsnMemAllocCallBack pMemAllocFunc;
+   PAsnMemFreeCallBack pMemFreeFunc;
+}AsnCustomMemFunctions;
+
+//added for replace jmpbuf
+#ifdef MCD_DLL_EXPORT
+  #include <setjmp.h>
+  #define asn_jmpbuf jmp_buf
+#else
+  #if defined(__MTK_TARGET__) && defined(__RVCT__)
+    typedef long long asn_jmpbuf[32];
+  #elif defined(__MTK_TARGET__)
+    #include <setjmp.h>
+    #define asn_jmpbuf jmp_buf
+  #else
+   	///add for vc9.0
+    //vc 9.0 have un-standard code , cgen could not pass the parse
+    // GEN_FOR_PC: just defined when codegen_modis
+    #ifndef GEN_FOR_PC
+      #include <setjmp.h>
+    #else
+      #define _JBLEN 32
+      #define _JBTYPE int
+      typedef _JBTYPE jmp_buf[_JBLEN];
+    #endif
+    ///
+    #define asn_jmpbuf jmp_buf
+  #endif
+#endif
+//added for replace jmpbuf
+
+typedef struct
+{
+   U32 shiftRegister;
+   U32 shiftRegisterLength;
+   U8 *pEncoded;
+   U8 *pEncodedEnd;
+   //jmp_buf env;
+   asn_jmpbuf env;
+   void *encodeAlloc;
+   AllocRecord *decodeAlloc;
+#ifdef  MCD_DLL_EXPORT
+   char *printBufStart;
+   char *printBufNext;
+   U32  printBufSize;
+#endif
+   void *pAppContext;
+   U32 result;
+   PAsnMemAllocCallBack pMemAllocFunc;
+   PAsnMemFreeCallBack  pMemFreeFunc;
+}  AsnContext;
+
+#define		ASN_MAX		0xFFFFFFFF
+#define		ASN_MIN		-2147483648
+
+typedef struct Tag_OID
+{
+	U32		valueLen;
+	U32		*value;
+}OID;
+
+
+typedef struct Tag_OCTETSTR {
+	U32    valueLen;
+	U8     *value;
+}OCTETSTR;
+
+/************************************************************************/
+/*  String  Definition                                                  */
+/************************************************************************/
+typedef struct Tag__OneByteString
+{
+	U32		valueLen;
+	char  	*value;
+}OneByteString;
+
+typedef struct Tag__TwoByteString
+{
+	U32		valueLen;
+	U16  	*value;
+}TwoByteString;
+
+typedef struct Tag__FourByteString
+{
+	U32		valueLen;
+	U32  	*value;
+}FourByteString;
+
+
+typedef struct Tag_ASN_OneByteAlphabet
+{
+	U32		valueLen;
+	char	*value;
+}ASN_OneByteAlphabet;
+
+typedef struct Tag_ASN_TwoByteAlphabet
+{
+	U32		valueLen;
+	U16		*value;
+}ASN_TwoByteAlphabet;
+
+//////////////////////////////////////////////////////////////////////////
+// Extension Item
+typedef struct Tag_UnKnowExtensionItem
+{
+	U32		valueLen;
+	U8  	*value;
+}UnKnowExtensionItem;
+
+typedef struct Tag_UnKnowExtensionItemArray
+{
+	U32						valueLen;		// Extension Number
+	UnKnowExtensionItem		*value;		// Point to the first 
+}UnKnowExtensionItemArray;
+
+
+typedef struct Tag_ChoiceUnKnow
+{
+	U32		uIndex;
+	U32		valueLen;
+	U8		*value;
+}ChoiceUnKnow;
+
+typedef 		OneByteString      asn_ESCString;
+
+typedef		OneByteString      asn_IA5String;
+typedef		OneByteString      asn_NumericString;
+typedef		OneByteString      asn_VisibleString;
+typedef		OneByteString      asn_PrintableString;
+
+typedef		TwoByteString      asn_BMPString;
+
+typedef		FourByteString     asn_UniversalString;
+typedef		asn_ESCString      asn_GeneralString;
+
+typedef		asn_VisibleString  asn_UTCTime;
+typedef		asn_VisibleString  asn_GeneralizedTime;
+
+#ifdef  MCD_DLL_EXPORT
+#define ASNBUF_BLOCKSIZE 4000
+#define ASNBUF_RESERVE 500
+
+void AsnFreeString( char *string );
+void InitAsnBuf( AsnContext *pContext );
+void AsnPrint( AsnContext *pContext, char *fmt, ... );
+void AsnPrintNull( AsnContext *pContext );
+void AsnPrintInteger( AsnContext *pContext, S32 value );
+void AsnPrintBoolean( AsnContext *pContext, Bool boolean );
+void AsnPrintOctetString( AsnContext *pContext, U8 *buffer, U32 length );
+void AsnPrintBitString( AsnContext *pContext, U8 *buffer, U32 length );
+void AsnPrintCharacterString( AsnContext *pContext, char *string );
+void AsnPrintOneByteString( AsnContext *pContext, U8 *buffer, U32 length );
+void AsnPrintVisibleString( AsnContext *pContext, asn_VisibleString* pType );
+void AsnPrintIA5String( AsnContext *pContext, asn_IA5String* pType );
+#endif
+
+typedef		U32  EncodeBeginPoint;
+
+#define		GET_U16_LOW(x)		((x) & 0x00FF)
+#define		GET_U16_HIGH(x)		(((x) >> 8) & 0x00FF)
+#define		MAKE_U16(low,high)  ((U16)((U8)(low)) | (((U16)(U8)(high))<<8))  
+
+#define		asn_min(a,b)		(((a) < (b)) ? (a) : (b))
+#define		asn_max(a,b)		(((a) > (b)) ? (a) : (b))
+
+#define		PER_ALIGN		do{		\
+if (0 != (pContext->shiftRegisterLength)%8) {			\
+putShortBits( pContext, 8 - (pContext->shiftRegisterLength)%8 , 0);	\
+}	\
+}while(0);
+
+
+#define		PER_CLEAR_ALIGN_BITS	getShortBits( pContext, pContext->shiftRegisterLength);
+
+
+#define		BEGIN_PRE_ENCODE			do{	 						\
+   EncodeBeginPoint	begin;					\
+   AsnContext TempContext = *pContext;			\
+   pContext->shiftRegisterLength = 0;\
+   if (NULL != pContext->pEncoded)\
+   {\
+      pContext->shiftRegister = 0;\
+   }\
+	 begin = BeginTestEncodeLen(pContext);	
+
+
+#define	END_PRE_ENCODE	ulen = EndTestEncodeLen(pContext, begin);	\
+   if(0 == ulen){putShortBits(pContext, 8, 0); ulen = 1;}\
+   *pContext = TempContext;			\
+   if (NULL != pContext->pEncoded)\
+   {\
+      asnMemAlloc(pContext, (void **)&pTemp, ulen);		\
+      asnMemCopy(pTemp, pContext->pEncoded, ulen);	\
+   }\
+}while(0); 
+
+
+#define		BEGIN_PRE_DECODE_EXT			do{	 		\
+		U8 *pTemp;	\
+		AsnContext TempContext;	\
+		int len = UperGetLengthValue(pContext, 0, ASN_MAX);		\
+		if( pContext->pEncoded + len > pContext->pEncodedEnd ) \
+		{ \
+			UA1_ERROR( 8 ); \
+		} \
+		TempContext = *pContext;
+
+
+#define	END_PRE_DECODE_EXT	*pContext = TempContext;	\
+		asnMemAlloc(pContext, (void **)&pTemp, len);	\
+		getLongBits(pContext, len*8, pTemp);			\
+   if (pContext->pMemFreeFunc != NULL)\
+   {\
+      pContext->pMemFreeFunc((void **)&pTemp);\
+   }\
+   else\
+   {\
+		asnMemFree((void **)&pTemp);	\
+   }\
+}while(0);
+
+
+#define	COPY_STATIC_ARRAY_TO_BUFFER(pBuffer, Array, begin, len)		do{\
+	int i;\
+	for(i=0; i<len; i++)\
+		{*(pBuffer+i) = Array[begin+i];}\
+}while(0);	
+
+U16  GetUperLengthDeterminant( AsnContext *pContext );
+void PutUperLengthDeterminant( AsnContext *pContext, U16 length );
+
+void AsnFreeDecoded( void *pType, PAsnMemFreeCallBack pFreeFunc);
+
+#if defined(__UMTS_RAT__) || defined(__LTE_RAT__)
+/* nick for block free */
+void AsnFreeDecodedSetBlock( void *pType, PAsnMemFreeCallBack pFreeFunc, void *start, int count);
+void AsnFreeDecodedWithBlock( void *pType , PAsnMemFreeCallBack pFreeFunc);
+
+/* nick integrate from old asn common*/
+void AsnDecodeFreeWithCallback( AllocRecord *decodeAlloc, PAsnMemFreeCallBack pFreeFunc );
+void AsnEncodeFreeWithCallback( void *pFree, PAsnMemFreeCallBack pFreeFunc);
+#endif
+
+void AsnFreeEncoded( U8 *pEncoded, PAsnMemFreeCallBack pFreeFunc);
+void AsnRootDecodeAlloc( AsnContext *pContext, void **ppType, int size );
+void AsnDecodeAlloc( AsnContext *pContext, void **ppMem, int size );
+void AsnDecodeFree( AllocRecord *decodeAlloc, PAsnMemFreeCallBack pFreeFunc);
+void AsnEncodeAlloc( AsnContext *pContext, U8 **ppMem, U32 *pEncodedLength );
+void AsnEncodeFree( void *pFree, PAsnMemFreeCallBack pFreeFunc);
+void AsnError( AsnContext *pContext, U32 errorCode );
+extern void initFifo( AsnContext *pContext, U8 *buffer, U32 bufferLength );
+extern void flushFifo( AsnContext *pContext );
+extern U32  getShortBits( AsnContext *pContext, U32 numBits );
+extern U32  getBits( AsnContext *pContext, U32 numBits );
+extern void getLongBits( AsnContext *pContext, U32 numBits, U8 *outputBuffer );
+extern U64 getInt64( AsnContext *pContext, U32 numBits );
+extern void putShortBits( AsnContext *pContext, U32 numBits, U32 data );
+extern void putBits( AsnContext *pContext, U32 numBits, U32 data );
+extern void putInt64( AsnContext *pContext, U32 numBits, U64 data );
+extern void putLongBits( AsnContext *pContext, U32 numBits, U8 *data );
+extern S32  GetAlphabetIndex(ASN_OneByteAlphabet *pAlphabet, char *pChar);
+extern U32  GetNumberOctetLength(U32  Data);
+extern Bool OIDCompare(OID  oidA, U32 length, U32 *pValue);
+extern void  SkipEncodeByte(AsnContext *pContext);
+extern EncodeBeginPoint BeginTestEncodeLen(AsnContext *pContext);
+extern U32	EndTestEncodeLen(AsnContext *pContext, EncodeBeginPoint	BeginPoint);
+extern void	PutShortSkipedEncodeByte(AsnContext *pContext,  U32 uByte, U32 Data, U32 uAfterSize);
+extern U32	testGetShortBits(AsnContext *pContext, U32 numBits);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* ASN_COMMON_H */
diff --git a/mcu/interface/service/asn1_common/asn_memory.c b/mcu/interface/service/asn1_common/asn_memory.c
new file mode 100644
index 0000000..67e1aa8
--- /dev/null
+++ b/mcu/interface/service/asn1_common/asn_memory.c
@@ -0,0 +1,168 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2011
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/****************************************************************************
+ *
+ * COMPONENT:   ASN
+ * MODULE:      ASN_MEMORY
+ * DESCRIPTION: Auto generated by MTK ASN.1 Compiler
+ *
+ ****************************************************************************/
+/*****************************************************************************
+ * $Log:$
+ *
+ * 04 09 2019 roger.lo
+ * [MOLY00397500] [MT6297] ASN.1 common enhancement
+ * 	
+ * 	Dummy checkin for changing owner of asn.1 compiler.
+ *
+ * 06 13 2017 eric.chuang
+ * [MOLY00256879] Init memory content to 0x00 to prevent unexpected decode result
+ * 	
+ * 	.
+ * 
+ * 09 06 2012 changshun.li
+ * [MOLY00000064] [asn.1] for check in tool/code to MOLY
+ * .
+ *
+ * 03 27 2012 changshun.li
+ * removed!
+ * for msbb2
+ *
+ * 03 27 2012 changshun.li
+ * removed!
+ * for msbb2
+ *
+ ****************************************************************************/
+#include "kal_public_api.h"
+//#include "app_buff_alloc.h"  
+#include "asn_memory.h"
+#include "asn_common.h"
+
+unsigned int max_size_tolerance=0;
+
+extern void asnMemSetMaxSizeTolerance(unsigned int maxlength)
+{
+   if (maxlength > max_size_tolerance)
+      max_size_tolerance = maxlength;
+}
+
+extern unsigned int asnMemGetMaxSizeTolerance(void)
+{
+   return max_size_tolerance;
+}
+
+extern  void  asnMemAlloc(void *pVoid, void ** ppBuffer, unsigned long size)
+{
+   /**
+    * For MCDDLL, malloc() from C Standard Library is used;
+    * otherwise, memory allocation from KAL is used.
+    */
+	AsnContext *pContext = (AsnContext*) pVoid;
+    if(size == 0)
+    {
+      *ppBuffer = (void *)0;
+      return;
+    }
+
+    /*added for memory limit*/
+    if(max_size_tolerance > 0)
+    {
+        if(size > max_size_tolerance)
+        {
+            UA1_ERROR(16);
+        }
+    }
+
+    if (pContext->pMemAllocFunc != NULL)
+    {
+        pContext->pMemAllocFunc(ppBuffer, size, __FILE__, __LINE__);
+    }
+    else
+    {
+#ifdef  MCD_DLL_EXPORT
+        *ppBuffer = (void *)malloc(size);
+        memset(*ppBuffer ,0,size);
+#else
+        *ppBuffer = (void*) get_ctrl_buffer(size);
+        asnMemSet(*ppBuffer ,0,size);
+#endif 
+        if(*ppBuffer == NULL)
+        {
+            ASSERT(0);
+        }
+    }
+}
+
+extern  void  asnMemFree(void ** ppBuffer)
+{
+   /**
+    * For MCDDLL, malloc() from C Standard Library is used;
+    * otherwise, memory allocation from KAL is used.
+    */
+    if(NULL == *ppBuffer)
+       return;
+#ifdef  MCD_DLL_EXPORT
+    free(*ppBuffer);
+#else
+    free_ctrl_buffer(*ppBuffer);
+#endif
+    *ppBuffer = NULL;
+}
+
+
+extern  void  asnMemMove(void * pDest, const void * pSource, unsigned long uLen)
+{
+	memmove(pDest, pSource, uLen);
+}
+
+extern  void  asnMemCopy(void * pDest, const void * pSource, unsigned long uLen)
+{
+#ifdef  MCD_DLL_EXPORT
+   memcpy(pDest, pSource, (signed)uLen);
+#else
+   kal_mem_cpy (pDest, pSource, (signed)uLen);
+#endif
+}
+
+extern long asnMemCmp(void *p1, void *p2, unsigned long uLen)
+{
+	return memcmp(p1, p2, uLen);
+}
+
+extern void asnMemSet(void *p1, unsigned long value, unsigned long uLen)
+{
+	memset(p1, value, uLen);
+}
diff --git a/mcu/interface/service/asn1_common/asn_memory.h b/mcu/interface/service/asn1_common/asn_memory.h
new file mode 100644
index 0000000..700491d
--- /dev/null
+++ b/mcu/interface/service/asn1_common/asn_memory.h
@@ -0,0 +1,79 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2011
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ * $Log:$
+ * 
+ * 09 06 2012 changshun.li
+ * [MOLY00000064] [asn.1] for check in tool/code to MOLY
+ * .
+ *
+ * 03 27 2012 changshun.li
+ * removed!
+ * for msbb2
+ *
+ * 03 27 2012 changshun.li
+ * removed!
+ * for msbb2
+ *
+ ****************************************************************************/
+#if !defined ASN_MEMORY_H_
+#define ASN_MEMORY_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "mtkasn_global.h"
+
+
+#define asnMemAlloc asnMemAlloc
+#define asnMemFree asnMemFree
+
+extern void asnMemSetMaxSizeTolerance(unsigned int maxlength);
+extern unsigned int asnMemGetMaxSizeTolerance(void);
+
+extern  void  asnMemFree(void ** ppBuffer);
+extern  void  asnMemAlloc(void *pContext, void ** ppBuffer, unsigned long uLen);
+
+extern  void  asnMemMove(void * pDest, const void * pSource, unsigned long uLen);
+extern  void  asnMemCopy(void * pDest, const void * pSource, unsigned long uLen);
+extern  long  asnMemCmp(void *p1, void *p2, unsigned long uLen);
+extern  void  asnMemSet(void *p1, unsigned long value, unsigned long uLen);
+
+#ifdef __cplusplus
+}
+#endif
+#endif //_ASN_MEMORY_H_
diff --git a/mcu/interface/service/asn1_common/asn_uper_common.c b/mcu/interface/service/asn1_common/asn_uper_common.c
new file mode 100644
index 0000000..10eecb9
--- /dev/null
+++ b/mcu/interface/service/asn1_common/asn_uper_common.c
@@ -0,0 +1,687 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2011
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+#include "kal_public_api.h"
+#include "asn_memory.h"
+#include "asn_common.h"
+#include "asn_uper_common.h"
+
+/************************************************************************/
+/*         UPER    Encode   Tools  Function                             */
+/************************************************************************/
+
+extern void UperPutSmallNumber(AsnContext *pContext, U32 uNum)
+{
+	if (uNum < 64)
+	{
+		putShortBits(pContext, 1, 0);
+		putShortBits(pContext, 6, uNum);
+	}
+	else
+	{
+		putShortBits(pContext, 1, 1);
+		UperPutSemiConstraintNumber(pContext, 0, uNum);
+	}
+}
+
+extern U32 UperGetSmallNumber(AsnContext *pContext)
+{
+	U32 uNum;
+
+	if (0 ==  getShortBits(pContext, 1))
+	{
+		uNum = getShortBits(pContext, 6);
+	}
+	else
+	{
+		uNum = 	UperGetSemiConstraintNumber(pContext, 0);
+	}
+
+	return uNum;
+}
+
+extern U32 UperPutLengthValue(AsnContext *pContext, U32 lBound, U32 uBound, U32 uLen)
+{
+	U32 uDistance;
+	ASSERT(uBound >= lBound);
+
+	uDistance = uBound - lBound;
+	if ((0 == uDistance) & (uDistance <= 65535))
+	{
+		// Need Not to encode;
+		return 0;
+	}
+	if (uBound < 65536)
+	{
+		UperPutWholeConstraintNumber(pContext, lBound, uBound, uLen);
+	}
+	else if (uBound >= 65536)
+	{
+		if (uLen <= 127)
+		{
+			putShortBits(pContext, 1, 0);
+			putShortBits(pContext, 7, uLen);
+		}
+		else if (uLen >127 && uLen<=16383)
+		{
+			putShortBits(pContext, 2, 0x02);
+			putShortBits(pContext, 14, uLen);
+		}
+		else if (uLen>16383)
+		{
+			//.....
+		}
+	}
+	return 0;
+}
+
+extern U32 UperGetLengthValue(AsnContext *pContext, U32 lBound, U32 uBound)
+{
+	U32 ulen = 0, uDistance = uBound - lBound;
+	ASSERT(uBound >= lBound);
+
+	if ((0 == uDistance) & (uDistance <= 65535))
+	{
+		// Need Not to encode;
+		return lBound;	
+	}
+
+	if (uBound < 65536)
+	{
+		ulen = UperGetWholeConstraintNumber(pContext, lBound, uBound);
+	}
+	else if (uBound >= 65536)
+	{
+		if (0 == testGetShortBits(pContext, 1))
+		{
+			// Len < 127
+			ulen = getShortBits(pContext, 8);
+		}
+		else if (0x02 == testGetShortBits(pContext, 2))
+		{
+			// uLen >127 && uLen<=16383
+			getShortBits(pContext, 2);
+			ulen = getShortBits(pContext, 14);
+		}
+		else
+		{
+			// uLen>16383  ...
+		}
+	}
+	return ulen;
+}
+
+extern  void UperPutWholeConstraintNumber(AsnContext *pContext, S32 lBound, S32 uBound, U32 uNum)
+{	
+	U32		range, bits, temp, i;
+	range = uBound - lBound;
+
+	if (0 == range)
+	{
+		// put no bit 
+	}
+	else
+	{
+		temp = 0;
+		i = 32;
+
+		while (0 == temp)
+		{
+			temp = range & 1<<(i-1);
+			i--;
+		}
+		bits = i+1;
+		putBits(pContext, bits, (uNum-lBound));
+	}
+}
+
+extern U32	UperGetWholeConstraintNumber(AsnContext *pContext, S32 lBound, S32 uBound)
+{
+	U32		range, bits, temp, i, uNum = 0;
+	ASSERT(uBound >= lBound);
+	range = uBound - lBound;
+
+	if (0 == range)
+	{
+		// put no bit 
+	}
+	else
+	{
+		temp = 0;
+		i = 32;
+		while (0 == temp)
+		{
+			temp = range & 1<<(i-1);
+			i--;
+		}
+
+		bits = i+1;
+
+		uNum = getShortBits(pContext, bits) + lBound;
+	}
+	return uNum;
+}
+
+extern void  UperPutSemiConstraintNumber(AsnContext *pContext, S32 lBound, S32 uNum)
+{	
+	U32		distance, nByte ;
+
+	distance = uNum - lBound;
+	nByte = GetNumberOctetLength(distance);
+	UperPutLengthValue(pContext, 0, ASN_MAX, nByte);
+	putBits(pContext, nByte * 8, distance);
+}
+
+extern S32 UperGetSemiConstraintNumber(AsnContext *pContext, S32 lBound)
+{	
+	U32	sNum, nByte;
+	nByte = UperGetLengthValue(pContext, 0, ASN_MAX);
+
+	if (nByte != 0 )
+	{
+		sNum = getBits(pContext, nByte * 8);
+	}
+	else
+	{
+		sNum = 0;
+	}
+  
+	return lBound+sNum;
+}
+
+extern void UperPutNonConstraintNumber(AsnContext *pContext,  S32 uNum)
+{
+	int		ulen, nByte, temp;
+	ulen = 0;
+	temp = 0;
+
+	if (uNum > 0)
+	{
+		nByte = GetNumberOctetLength(uNum);
+
+		switch(nByte)
+		{
+		case 1:
+			temp = uNum & 0x00000080;
+			break;
+		case 2:
+			temp = uNum & 0x00008000;
+			break;
+		case 3:
+			temp = uNum & 0x00800000;
+		    break;
+		case 4:
+			temp = uNum & 0x80000000;
+		    break;
+		default:
+		    break;
+		}
+
+		if (0 != temp)
+		{
+			ulen = 1;
+			putShortBits(pContext, 8, 0);
+		}
+
+		ulen += nByte;
+		putShortBits(pContext, GetNumberOctetLength(ulen) * 8, ulen);	//Put length
+
+
+		if (0 != temp)
+		{
+			putShortBits(pContext, 8, 0);
+		}
+
+		putShortBits(pContext, nByte * 8, uNum);
+	}
+	else
+	{
+		nByte = GetNumberOctetLength(-uNum);
+
+		uNum = -uNum;
+		uNum = ~uNum;
+		uNum += 1;
+
+		if (nByte == 1){
+			uNum &= 0x000000FF;
+		}
+		else if (nByte == 2){
+			uNum &= 0x0000FFFF;
+		}
+		else if (nByte == 3){
+			uNum &= 0x00FFFFFF;
+		}
+
+		putShortBits(pContext, GetNumberOctetLength(nByte) * 8, nByte);	//Put length
+		putShortBits(pContext, nByte * 8, uNum);
+	}
+}
+
+extern S32 UperGetNonConstraintNumber(AsnContext *pContext)
+{
+	int		nByte;
+	S32		uNum = 0;
+
+	nByte = getShortBits(pContext, 8);	//Get length
+
+	if (0 == testGetShortBits(pContext, 1))
+	{
+		// positive
+		if (0 == testGetShortBits(pContext, 8))
+		{
+			getShortBits(pContext, 8);	
+			uNum =  getShortBits(pContext, 8 * (nByte-1));
+		}
+		else
+		{
+			uNum =  getShortBits(pContext, 8 * nByte);
+		}	
+	}
+	else
+	{
+		// negetive
+		uNum =  getShortBits(pContext, (8 * nByte));
+		uNum--;
+		uNum = ~uNum;
+		uNum = -uNum;
+
+		if (nByte == 1){
+			uNum |= 0xFFFFFF00;
+		}
+		else if (nByte == 2){
+			uNum |= 0xFFFF0000;
+		}
+		else if (nByte == 3){
+			uNum |= 0xFF000000;
+		}
+	}
+	return uNum;
+}
+
+extern void UperEncodeOpenType(AsnContext *pContext,  U8 * pData, U32 uSize)
+{
+	if (uSize > 0)
+	{
+		UperPutLengthValue(pContext, 0, ASN_MAX, uSize);
+
+		putLongBits(pContext, uSize*8, pData);
+	}
+}
+
+extern U32 UperDecodeOpenTypeLength(AsnContext *pContext)
+{
+	return UperGetLengthValue(pContext, 0, ASN_MAX);
+}
+
+extern U32 UperDecodeOpenType(AsnContext *pContext,  U8 * pData, U32 uSize)
+{
+	U32		   uLen;
+	AsnContext TempContext = *pContext;
+
+	uLen = UperGetLengthValue(pContext, 0, ASN_MAX);
+	if (NULL == pData)
+	{
+		*pContext = TempContext;
+		return uLen;
+	}
+
+	getLongBits(pContext, 8 * asn_min(uLen, uSize),  pData);
+
+	// return decode length (by byte)
+	return asn_min(uLen, uSize);
+}
+
+static void UperEncodeOIDItem(AsnContext *pContext,  U32  uData)
+{
+	ASSERT(uData < 2097152);
+	if (uData < 128)
+	{
+		putShortBits(pContext,  8, uData);
+	}
+	else if (uData < 16384)
+	{
+		// First Octet
+		putShortBits(pContext,  1, 1);
+		putShortBits(pContext,  7, (uData - uData%128)/128);
+
+		// Second Octet
+		putShortBits(pContext,  1, 0);
+		putShortBits(pContext,  7, uData%128);
+	}
+	else if (uData < 2097152)
+	{
+		// First Octet
+		putShortBits(pContext,  1, 1);
+		putShortBits(pContext,  7, (uData - uData%16384)/16384);
+
+		// Second Octet
+		putShortBits(pContext,  1, 1);
+		putShortBits(pContext,  7, ((uData - uData%128)%16384)/128);
+
+		// Third Octet
+		putShortBits(pContext,  1, 0);
+		putShortBits(pContext,  7, uData%128);
+	}
+}
+
+static U32 UperDecodeOIDItem(AsnContext *pContext,  U8 **ppData)
+{
+	U32		uNum = 0;
+	U8		uData = **ppData;
+
+	if (uData <= 0x7F)
+	{
+		uNum = uData;
+		(*ppData)++;
+	}
+	else if (*(*ppData+1)  <= 0x7F)
+	{
+		// First Octet
+		uData &= 0x7F;
+		uNum = uData;
+		uNum *= 128;
+
+		(*ppData)++;
+		uData = **ppData;
+
+		// Second Octet
+		uData &= 0x7F;
+		uNum += uData;
+		(*ppData)++;
+	}
+	else if (*(*ppData+2) <= 0x7F)
+	{
+		// First Octet
+		uData &= 0x7F;
+		uNum = uData;
+		uNum *= 128;
+
+		(*ppData)++;
+		uData = **ppData;
+
+		// Second Octet
+		uData &= 0x7F;
+		uNum += uData;
+		uNum *= 128; 
+
+		(*ppData)++;
+		uData = **ppData;
+
+		// Third Octet
+		uData &= 0x7F;
+		uNum += uData;
+
+		(*ppData)++;
+	}
+	else
+	{
+		UA1_ERROR(10);
+	}
+	return uNum;
+}
+
+extern void UperEncodeOID(AsnContext *pContext, OID *pOid)
+{
+	U32		ulen, i;
+	U8 * pTemp = NULL;
+
+	BEGIN_PRE_ENCODE
+	putShortBits(pContext,  8, ((*pOid->value)*40 + (* (pOid->value + 1))));
+
+	for(i=2; i<pOid->valueLen; i++)
+	{
+		UperEncodeOIDItem(pContext, *(pOid->value + i));
+	}
+
+	END_PRE_ENCODE
+	UperEncodeOpenType(pContext, (U8 *)pTemp, ulen);
+
+   if (pContext->pMemFreeFunc != NULL)
+   {
+      pContext->pMemFreeFunc((void **)&pTemp);
+   }
+   else
+   {
+	  asnMemFree((void **)&pTemp);
+   }
+}
+
+extern void UperDecodeOID(AsnContext *pContext, OID *pOid)
+{	
+	U32	 ulen, i, *pItemOrg;
+	U8 * pBuf;// , * pBufOrg;
+
+	ulen = UperDecodeOpenType(pContext, (U8 *)NULL, 0);
+	AsnDecodeAlloc(pContext, (void **)&pBuf, ulen);
+
+	//pBufOrg = pBuf;
+	UperDecodeOpenType(pContext, (U8 *)pBuf, ulen);
+
+	//Got object Identify Item count
+	for (i=1, pOid->valueLen=2; i<ulen; i++)
+	{
+		if (*(pBuf+i) <= 0x7F )
+		{
+			(pOid->valueLen)++;
+		}
+	}
+
+	AsnDecodeAlloc(pContext, (void **)&(pOid->value), (pOid->valueLen)*4);
+
+	pItemOrg = pOid->value;
+
+	if ((*pBuf) <= 39)
+	{
+		*pOid->value = 0;
+	}
+	else if ((*pBuf) <= 79)
+	{
+		*pOid->value = 1;
+	}
+	else
+	{
+		*pOid->value = 2;
+	}
+
+	*(pOid->value+1) = (*pBuf)%40;
+	pBuf++;
+	pOid->value += 2;
+
+	for (i=2; i<pOid->valueLen; i++, pOid->value++)
+	{
+		*pOid->value = UperDecodeOIDItem(pContext, &pBuf);
+	}
+	pOid->value = pItemOrg;
+}
+
+//////////////////////////////////////////////////////////////////////////
+// String Encode
+//////////////////////////////////////////////////////////////////////////
+static void UperEncodeTwoByteString(AsnContext *pContext,  TwoByteString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet *pAlphabet)
+{
+	// If No Constraint 
+	U32		i;
+
+	UperPutLengthValue(pContext, minSize, maxSize, pStr->valueLen);
+	for(i = 0; i < pStr->valueLen; i++){
+		putShortBits(pContext, 8,  GET_U16_HIGH(*(pStr->value+i)) );
+		putShortBits(pContext, 8,  GET_U16_LOW(*(pStr->value+i)) );
+	}
+	if (pAlphabet){/*donothing*/}
+}
+
+static void UperDecodeTwoByteStringA(AsnContext *pContext,  TwoByteString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet *pAlphabet)
+{
+	// If No Constraint 
+	U32		i;
+	U16		uHigh, uLow;
+
+	pStr->valueLen = UperGetLengthValue(pContext, minSize, maxSize);
+	AsnDecodeAlloc(pContext, (void **)&pStr->value, pStr->valueLen * 2);
+
+	for(i = 0; i < pStr->valueLen; i++){
+		uHigh = (U16)getShortBits(pContext, 8);
+		uLow  = (U16)getShortBits(pContext, 8);
+		*(pStr->value + i) = MAKE_U16(uHigh, uLow);
+	}
+	if (pAlphabet){/*donothing*/}
+}
+
+//////////////////////////////////////////////////////////////////////////
+// Numeric String
+extern  void UperEncodeNumericString(AsnContext *pContext,  asn_NumericString *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet *pAlphabet)
+{
+	// ... ?  Check Characters ?
+	U32		i;
+	UperPutLengthValue(pContext, minSize, maxSize, pStr->valueLen);
+	for(i = 0; i < pStr->valueLen; i++){
+		putShortBits(pContext, 4,  *(pStr->value+i) - 47);
+	}
+	if (pAlphabet){/*donothing*/}
+}
+
+extern  void UperDecodeNumericStringA(AsnContext *pContext,  asn_NumericString *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet *pAlphabet)
+{
+	// ... ?  Check Characters ?
+	U32		i;
+
+	pStr->valueLen = UperGetLengthValue(pContext, minSize, maxSize);
+	AsnDecodeAlloc(pContext, (void **)&pStr->value, pStr->valueLen);
+
+	for(i = 0; i < pStr->valueLen; i++){
+		*(pStr->value+i) = (U8)getShortBits(pContext, 4) + 47;
+	}
+	if (pAlphabet){/*donothing*/}	
+}
+
+//////////////////////////////////////////////////////////////////////////
+// BMP String
+extern  void UperEncodeBMPString(AsnContext *pContext,  asn_BMPString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet *pAlphabet)
+{
+	// ... ?  Check Characters ?
+	UperEncodeTwoByteString(pContext, pStr, minSize, maxSize, pAlphabet);
+}
+
+extern  void UperDecodeBMPStringA(AsnContext *pContext,  asn_BMPString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet *pAlphabet)
+{
+	// ... ?  Check Characters ?
+	UperDecodeTwoByteStringA(pContext, pStr, minSize, maxSize, pAlphabet);
+}
+
+//////////////////////////////////////////////////////////////////////////
+// General String
+extern  void UperEncodeGeneralString(AsnContext *pContext,  asn_GeneralString *pStr)
+{
+	UperEncodeOpenType(pContext, (U8 *)pStr->value, pStr->valueLen);
+}
+
+extern  void UperDecodeGeneralStringA(AsnContext *pContext,  asn_GeneralString *pStr)
+{
+	pStr->valueLen = UperDecodeOpenType(pContext, (U8 *)NULL, 0);
+	AsnDecodeAlloc(pContext, (void **)&pStr->value, pStr->valueLen);
+
+	UperDecodeOpenType(pContext, (U8 *)pStr->value, pStr->valueLen);
+}
+
+extern	void UperDecodeChoiceUnKnowItem(AsnContext *pContext, ChoiceUnKnow *pUnKnowItem)
+{
+	ChoiceUnKnow	*pUnKnow;
+	// In the extension
+
+	AsnDecodeAlloc(pContext, (void **)&pUnKnow, sizeof(ChoiceUnKnow));
+	pUnKnow->uIndex =  UperGetSmallNumber(pContext); // Index
+
+	pUnKnow->valueLen = UperDecodeOpenType(pContext, (U8 *)NULL, 0);
+	AsnDecodeAlloc(pContext, (void **)&(pUnKnow->value), pUnKnow->valueLen);
+	UperDecodeOpenType(pContext, (U8 *)pUnKnow->value, pUnKnow->valueLen);
+
+	pUnKnowItem = pUnKnow;
+    
+    NOT_USED(pUnKnowItem); //add for clear warning
+}
+
+extern void	UperDecodeSequcenceUnKnowItem(AsnContext *pContext,  UnKnowExtensionItemArray *pArray, U32 uSize, Bool  *pIsItemExist)
+{
+	U32	i, uUnKonwSize;
+	U8 *pData;
+
+	AsnDecodeAlloc(pContext, (void **)&(pArray->value), sizeof(UnKnowExtensionItem) * uSize);
+	memset(pArray->value, 0, sizeof(UnKnowExtensionItem) * uSize);
+
+	for (i=0; i<uSize; i++)
+	{
+		if (*(pIsItemExist+i))
+		{
+			uUnKonwSize = UperDecodeOpenType(pContext, (U8 *)NULL, 0);
+			if (uUnKonwSize)
+			{
+				AsnDecodeAlloc(pContext, (void **)&pData, uUnKonwSize);
+				UperDecodeOpenType(pContext, (U8 *)pData, uUnKonwSize);
+				(pArray->value + i)->valueLen = uUnKonwSize;
+				(pArray->value + i)->value = pData;
+				pArray->valueLen++;
+			}
+			else
+			{
+				UperGetLengthValue(pContext, 0, ASN_MAX);
+				(pArray->value + i)->valueLen = 0;
+				(pArray->value + i)->value = NULL;
+				pArray->valueLen++;
+			}
+		}
+		else
+		{
+			(pArray->value + i)->valueLen = 0;
+			(pArray->value + i)->value = NULL;
+			pArray->valueLen++;
+		}
+	}
+}
+
+extern int	GetPresentBitsNum(unsigned long data)
+{
+	int		iNum,i;
+
+	for (i=0 , iNum=0; i<32; i++)
+	{
+		if ((data & 0x00000001) == 1)
+		{
+			iNum++;
+		}
+		data >>= 1;
+		data &= 0x7FFFFFFF;
+	}
+	return  iNum;
+}
diff --git a/mcu/interface/service/asn1_common/asn_uper_common.h b/mcu/interface/service/asn1_common/asn_uper_common.h
new file mode 100644
index 0000000..db71e73
--- /dev/null
+++ b/mcu/interface/service/asn1_common/asn_uper_common.h
@@ -0,0 +1,192 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2011
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+#if !defined ASN_UPER_COMMON_H_
+#define ASN_UPER_COMMON_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#include "asn_common.h"
+#include "asn_memory.h"
+#include "mtkasn_global.h"
+
+
+/* here move from old aper header */
+/* nick add */
+
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#else
+
+#define		APER_ALIGN		do{		\
+									if (0 != (pContext->shiftRegisterLength)%8) {			\
+									putShortBits( pContext, 8 - (pContext->shiftRegisterLength)%8 , 0);	\
+									}	\
+							}while(0);
+	
+#define		APER_CLEAR_ALIGN_BITS	getShortBits( pContext, pContext->shiftRegisterLength);
+
+
+#define		UPER_BEGIN_PRE_ENCODE       BEGIN_PRE_ENCODE
+#define	  UPER_END_PRE_ENCODE         END_PRE_ENCODE
+#define   UPER_BEGIN_PRE_DECODE_EXT   BEGIN_PRE_DECODE_EXT
+#define   UPER_END_PRE_DECODE_EXT     END_PRE_DECODE_EXT
+
+
+#endif
+
+
+
+extern   void   UperEncodeOID(AsnContext *pContext,  OID *pOid);
+extern   void   UperDecodeOID(AsnContext *pContext,  OID *pOid);
+extern   void	UperEncodeOpenType(AsnContext *pContext,  U8 * pData, U32 uSize);
+extern   U32	UperDecodeOpenTypeLength(AsnContext *pContext);
+extern   U32	UperDecodeOpenType(AsnContext *pContext,  U8 * pData, U32 uSize);
+
+extern   void   UperPutNonConstraintNumber(AsnContext *pContext,  S32 uNum);
+extern   S32    UperGetNonConstraintNumber(AsnContext *pContext);
+
+extern   U32    UperPutLengthValue(AsnContext *pContext, U32 lBound, U32 uBound, U32 uLen);
+extern   U32	UperGetLengthValue(AsnContext *pContext, U32 lBound, U32 uBound);
+
+extern   void   UperPutSmallNumber(AsnContext *pContext, U32 uNum);
+extern   U32	UperGetSmallNumber(AsnContext *pContext);
+
+extern   void   UperPutSemiConstraintNumber(AsnContext *pContext, S32 lBound, S32 uNum);
+extern   S32	UperGetSemiConstraintNumber(AsnContext *pContext, S32 lBound);
+
+extern   void   UperPutWholeConstraintNumber(AsnContext *pContext, S32 lBound, S32 uBound, U32 uNum);
+extern   U32    UperGetWholeConstraintNumber(AsnContext *pContext, S32 lBound, S32 uBound);
+
+extern   void UperEncodeGeneralString(AsnContext *pContext,  asn_GeneralString *pStr);
+extern   void UperEncodeBMPString(AsnContext *pContext,  asn_BMPString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet  *pAlphabet);
+extern   void UperEncodeNumericString(AsnContext *pContext,  asn_NumericString *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet  *pAlphabet);
+extern   void UperDecodeNumericStringA(AsnContext *pContext,  asn_NumericString *pStr, U32 minSize, U32 maxSize, ASN_OneByteAlphabet  *pAlphabet);
+extern   void UperDecodeBMPStringA(AsnContext *pContext,  asn_BMPString *pStr, U32 minSize, U32 maxSize, ASN_TwoByteAlphabet  *pAlphabet);
+extern   void UperDecodeGeneralStringA(AsnContext *pContext,  asn_GeneralString *pStr);
+extern   void UperDecodeChoiceUnKnowItem(AsnContext *pContext, ChoiceUnKnow *pUnKnowItem);
+extern   void UperDecodeSequcenceUnKnowItem(AsnContext* pContext,  UnKnowExtensionItemArray *pArray, U32	uSize, Bool  *pIsItemExist);
+
+#ifdef __cplusplus  
+}
+#endif
+
+#endif //_UPER_COMMON_H_
+
diff --git a/mcu/interface/service/asn1_common/mtk_asn_comm_gen.pl b/mcu/interface/service/asn1_common/mtk_asn_comm_gen.pl
new file mode 100644
index 0000000..c428639
--- /dev/null
+++ b/mcu/interface/service/asn1_common/mtk_asn_comm_gen.pl
@@ -0,0 +1,48 @@
+#! /usr/bin/perl -w 
+
+use strict;
+use warnings;
+use diagnostics;
+   
+ 
+$ENV{'ENCODE_BUFFER_SIZE'} = "4000";
+ 
+$ENV{'SUPPORT_VERSION'} = "2";
+$ENV{'SUPPORT_GENERATE_ALTERNATIVE_COMMONFILES'} = "1";
+$ENV{'SUPPORT_GENERATE_ALTERNATIVE_COMMONFILES_PREFIX'}="";
+$ENV{'GEN_COMMON_FILE_ONLY'}="1";
+   
+ 
+print "OS: $^O\n";
+
+my $result;
+my $command;
+my $input = "";
+
+if ( $^O eq "MSWin32" )
+{
+  $command = "mtkasn.exe $input";
+  $result = system $command;  
+}
+elsif ($^O eq "linux") 
+{
+  system "chmod 777 ./mtkasn";
+  $command = "./mtkasn $input";
+  $result = system $command;
+}
+else
+{
+   my $final_error_msg = "the tool cannot run on $^O system\n";
+   print $final_error_msg;
+   exit(1);
+}
+
+delete $ENV{'SUPPORT_VERSION'};
+delete $ENV{'SUPPORT_GENERATE_ALTERNATIVE_COMMONFILES'};
+delete $ENV{'SUPPORT_GENERATE_ALTERNATIVE_COMMONFILES_PREFIX'}; 
+delete $ENV{'ENCODE_BUFFER_SIZE'};
+delete $ENV{'GEN_COMMON_FILE_ONLY'}; 
+
+
+exit(0);
+
diff --git a/mcu/interface/service/asn1_common/mtkasn b/mcu/interface/service/asn1_common/mtkasn
new file mode 100755
index 0000000..bb2c7f1
--- /dev/null
+++ b/mcu/interface/service/asn1_common/mtkasn
Binary files differ
diff --git a/mcu/interface/service/asn1_common/mtkasn.exe b/mcu/interface/service/asn1_common/mtkasn.exe
new file mode 100755
index 0000000..6e23eca
--- /dev/null
+++ b/mcu/interface/service/asn1_common/mtkasn.exe
Binary files differ
diff --git a/mcu/interface/service/asn1_common/mtkasn_global.h b/mcu/interface/service/asn1_common/mtkasn_global.h
new file mode 100644
index 0000000..c3cdfc3
--- /dev/null
+++ b/mcu/interface/service/asn1_common/mtkasn_global.h
@@ -0,0 +1,61 @@
+/*******************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2011
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+#if !defined MTKASN_GLOBAL_H_
+#define MTKASN_GLOBAL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "kal_general_types.h"
+
+
+#define  U8   kal_uint8
+#define  U16  kal_uint16
+#define  U32  kal_uint32
+#define  U64  kal_uint64
+#define  Bool kal_bool
+
+
+#define	S8  kal_int8
+#define	S16 kal_int16
+#define	S32 kal_int32
+#define S64 kal_int64
+
+#ifdef __cplusplus   
+}
+#endif
+#endif //_ASN_GLOBAL_H_
diff --git a/mcu/interface/service/asn1_common/mtkasn_lte b/mcu/interface/service/asn1_common/mtkasn_lte
new file mode 100644
index 0000000..a9ea5e7
--- /dev/null
+++ b/mcu/interface/service/asn1_common/mtkasn_lte
Binary files differ
diff --git a/mcu/interface/service/asn1_common/mtkasn_lte.exe b/mcu/interface/service/asn1_common/mtkasn_lte.exe
new file mode 100755
index 0000000..c885815
--- /dev/null
+++ b/mcu/interface/service/asn1_common/mtkasn_lte.exe
Binary files differ
diff --git a/mcu/interface/service/asn1_common/mtkasn_uper b/mcu/interface/service/asn1_common/mtkasn_uper
new file mode 100755
index 0000000..9257ad3
--- /dev/null
+++ b/mcu/interface/service/asn1_common/mtkasn_uper
Binary files differ
diff --git a/mcu/interface/service/asn1_common/mtkasn_uper.exe b/mcu/interface/service/asn1_common/mtkasn_uper.exe
new file mode 100755
index 0000000..6ea93be
--- /dev/null
+++ b/mcu/interface/service/asn1_common/mtkasn_uper.exe
Binary files differ
diff --git a/mcu/interface/service/asn1_common/readme.txt b/mcu/interface/service/asn1_common/readme.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mcu/interface/service/asn1_common/readme.txt