blob: 97ea4c530540a21c649206152c8346bb1cb1bd5b [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*******************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2011
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/****************************************************************************
37 *
38 * COMPONENT: ASN
39 * MODULE: ASN_COMMON
40 * DESCRIPTION: Auto generated by MTK ASN.1 Compiler
41 *
42 ****************************************************************************/
43/*****************************************************************************
44 * $Log:$
45 *
46 * 12 19 2018 hannu.huusko
47 * [MOLY00308815] [6297][NRRC] MAIN module implementation
48 * [NRRC] Increase memory size for ASN.1 decoding
49 *
50 * 09 28 2018 eric.chuang
51 * [MOLY00355921] Fix target build warning due to nano MIPS
52 * .remove build warning for Nano MIPS compiler
53 *
54 * 06 04 2014 eric.chuang
55 * [MOLY00067682] split asn.1 for 4G vs. 2G only projects
56 * .use __UMTS_RAT__ & __LTE_RAT__ to split 4G vs. 2G only projects
57 * .fix memory leak when decoding wrong extension items
58 *
59 * 03 28 2014 eric.chuang
60 * [MOLY00061188] ASN.1 memory leakage when decoding wrong data
61 * .
62 *
63 * 11 06 2012 nick.wang
64 * [MOLY00005322] TATAKA merge to MOLY
65 * Merge Moly_tataka asn common
66 *
67 * 09 06 2012 changshun.li
68 * [MOLY00000064] [asn.1] for check in tool/code to MOLY
69 * .
70 *
71 * 03 27 2012 changshun.li
72 * removed!
73 * for msbb2
74 *
75 * 03 27 2012 changshun.li
76 * removed!
77 * for msbb2
78 *
79 ****************************************************************************/
80
81#ifndef ASN_COMMON_H
82#define ASN_COMMON_H
83
84#ifdef __cplusplus
85 extern "C" {
86#endif
87
88
89//#include <setjmp.h>
90//#include "app_buff_alloc.h"
91#include "asn_memory.h"
92#include "mtkasn_global.h"
93
94typedef enum
95{
96 ASN_OK = 0,
97 ASN_ERROR = -1
98}
99AsnStatus;
100
101typedef S8 AsnNull;
102
103typedef struct
104{
105 int length;
106 unsigned char value[100];
107}
108AsnAny;
109
110typedef S8 AsnObjId;
111
112typedef S8 AsnOpen;
113
114typedef S8 AsnBool;
115
116#ifndef TRUE
117#define TRUE 1
118#endif
119#ifndef FALSE
120#define FALSE 0
121#endif
122
123#ifndef NULL
124#define NULL (void *)0
125#endif
126
127#ifndef NOT_USED
128#define NOT_USED(x) (void)(x)
129#endif
130
131#define UA1_ERROR( x ) AsnError( pContext, x )
132
133/* Error Code nick */
134#define ASN_ERR_GP_COM_NG (0) /* original */
135#define ASN_ERR_GP_PRC_NG (1) /* process */
136#define ASN_ERR_GP_EDC_NG (2) /* en/decode */
137#define ASN_ERR_GP_NOT_SP (10) /* not support */
138
139#define ASN_ERR_GETGP(x) ( ((x) >> 24) & 0x00FF)
140#define ASN_ERR_SETGP(x,y) ( ((x) << 24 ) | (y & 0x00FFFFFF) )
141#define ASN_ERR_OK (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG, 0)) /* OK */
142#define ASN_ERR_SPNULL (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG, 300)) /* error code for special purpose */
143#define ASN_ERR_ATST (ASN_ERR_SETGP(ASN_ERR_GP_EDC_NG, 500)) /* error code autogen start code */
144
145#define ASN_ERR_MEMALOC (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG, 16)) /* error code for special purpose */
146#define ASN_ERR_DECALOC (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG, 3)) /* no root */
147#define ASN_ERR_DECALOC2 (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG, 4)) /* no enough buffer */
148#define ASN_ERR_DECLEN (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG, 5)) /* get short */
149#define ASN_ERR_DECLEN2 (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG, 6)) /* get long */
150#define ASN_ERR_ENCLEN (ASN_ERR_SETGP(ASN_ERR_GP_COM_NG, 15)) /* put short */
151#define ASN_ERR_ENCLEN2 (ASN_ERR_SETGP(ASN_ERR_GP_NOT_SP, 0)) /* put long */
152
153typedef struct
154{
155#ifdef MCD_DLL_EXPORT
156 void *pMemBlock[1024];
157#else
158#if defined(__NR_RAT__)
159 void *pMemBlock[400];
160#elif defined(__UMTS_RAT__) || defined(__LTE_RAT__)
161 void *pMemBlock[200]; /* enlarge block number only for 3/4G */
162#else
163 void *pMemBlock[20];
164#endif
165#endif
166 void **ppNext;
167 void **ppEnd;
168#if defined(__UMTS_RAT__) || defined(__LTE_RAT__)
169 /* nick for block free */
170#define ASN_BLOCK_FREE_NUM 32
171 int blocknum;
172 void *start[ASN_BLOCK_FREE_NUM];
173 unsigned int count[ASN_BLOCK_FREE_NUM];
174#endif
175} AllocRecord;
176
177//add for customize call back
178typedef void (*PAsnMemAllocCallBack)(void **memPtr, unsigned long size, const char *file, unsigned long line);
179typedef void (*PAsnMemFreeCallBack)(void ** ppBuffer);
180//add for customize call back end
181
182typedef struct
183{
184 PAsnMemAllocCallBack pMemAllocFunc;
185 PAsnMemFreeCallBack pMemFreeFunc;
186}AsnCustomMemFunctions;
187
188//added for replace jmpbuf
189#ifdef MCD_DLL_EXPORT
190 #include <setjmp.h>
191 #define asn_jmpbuf jmp_buf
192#else
193 #if defined(__MTK_TARGET__) && defined(__RVCT__)
194 typedef long long asn_jmpbuf[32];
195 #elif defined(__MTK_TARGET__)
196 #include <setjmp.h>
197 #define asn_jmpbuf jmp_buf
198 #else
199 ///add for vc9.0
200 //vc 9.0 have un-standard code , cgen could not pass the parse
201 // GEN_FOR_PC: just defined when codegen_modis
202 #ifndef GEN_FOR_PC
203 #include <setjmp.h>
204 #else
205 #define _JBLEN 32
206 #define _JBTYPE int
207 typedef _JBTYPE jmp_buf[_JBLEN];
208 #endif
209 ///
210 #define asn_jmpbuf jmp_buf
211 #endif
212#endif
213//added for replace jmpbuf
214
215typedef struct
216{
217 U32 shiftRegister;
218 U32 shiftRegisterLength;
219 U8 *pEncoded;
220 U8 *pEncodedEnd;
221 //jmp_buf env;
222 asn_jmpbuf env;
223 void *encodeAlloc;
224 AllocRecord *decodeAlloc;
225#ifdef MCD_DLL_EXPORT
226 char *printBufStart;
227 char *printBufNext;
228 U32 printBufSize;
229#endif
230 void *pAppContext;
231 U32 result;
232 PAsnMemAllocCallBack pMemAllocFunc;
233 PAsnMemFreeCallBack pMemFreeFunc;
234} AsnContext;
235
236#define ASN_MAX 0xFFFFFFFF
237#define ASN_MIN -2147483648
238
239typedef struct Tag_OID
240{
241 U32 valueLen;
242 U32 *value;
243}OID;
244
245
246typedef struct Tag_OCTETSTR {
247 U32 valueLen;
248 U8 *value;
249}OCTETSTR;
250
251/************************************************************************/
252/* String Definition */
253/************************************************************************/
254typedef struct Tag__OneByteString
255{
256 U32 valueLen;
257 char *value;
258}OneByteString;
259
260typedef struct Tag__TwoByteString
261{
262 U32 valueLen;
263 U16 *value;
264}TwoByteString;
265
266typedef struct Tag__FourByteString
267{
268 U32 valueLen;
269 U32 *value;
270}FourByteString;
271
272
273typedef struct Tag_ASN_OneByteAlphabet
274{
275 U32 valueLen;
276 char *value;
277}ASN_OneByteAlphabet;
278
279typedef struct Tag_ASN_TwoByteAlphabet
280{
281 U32 valueLen;
282 U16 *value;
283}ASN_TwoByteAlphabet;
284
285//////////////////////////////////////////////////////////////////////////
286// Extension Item
287typedef struct Tag_UnKnowExtensionItem
288{
289 U32 valueLen;
290 U8 *value;
291}UnKnowExtensionItem;
292
293typedef struct Tag_UnKnowExtensionItemArray
294{
295 U32 valueLen; // Extension Number
296 UnKnowExtensionItem *value; // Point to the first
297}UnKnowExtensionItemArray;
298
299
300typedef struct Tag_ChoiceUnKnow
301{
302 U32 uIndex;
303 U32 valueLen;
304 U8 *value;
305}ChoiceUnKnow;
306
307typedef OneByteString asn_ESCString;
308
309typedef OneByteString asn_IA5String;
310typedef OneByteString asn_NumericString;
311typedef OneByteString asn_VisibleString;
312typedef OneByteString asn_PrintableString;
313
314typedef TwoByteString asn_BMPString;
315
316typedef FourByteString asn_UniversalString;
317typedef asn_ESCString asn_GeneralString;
318
319typedef asn_VisibleString asn_UTCTime;
320typedef asn_VisibleString asn_GeneralizedTime;
321
322#ifdef MCD_DLL_EXPORT
323#define ASNBUF_BLOCKSIZE 4000
324#define ASNBUF_RESERVE 500
325
326void AsnFreeString( char *string );
327void InitAsnBuf( AsnContext *pContext );
328void AsnPrint( AsnContext *pContext, char *fmt, ... );
329void AsnPrintNull( AsnContext *pContext );
330void AsnPrintInteger( AsnContext *pContext, S32 value );
331void AsnPrintBoolean( AsnContext *pContext, Bool boolean );
332void AsnPrintOctetString( AsnContext *pContext, U8 *buffer, U32 length );
333void AsnPrintBitString( AsnContext *pContext, U8 *buffer, U32 length );
334void AsnPrintCharacterString( AsnContext *pContext, char *string );
335void AsnPrintOneByteString( AsnContext *pContext, U8 *buffer, U32 length );
336void AsnPrintVisibleString( AsnContext *pContext, asn_VisibleString* pType );
337void AsnPrintIA5String( AsnContext *pContext, asn_IA5String* pType );
338#endif
339
340typedef U32 EncodeBeginPoint;
341
342#define GET_U16_LOW(x) ((x) & 0x00FF)
343#define GET_U16_HIGH(x) (((x) >> 8) & 0x00FF)
344#define MAKE_U16(low,high) ((U16)((U8)(low)) | (((U16)(U8)(high))<<8))
345
346#define asn_min(a,b) (((a) < (b)) ? (a) : (b))
347#define asn_max(a,b) (((a) > (b)) ? (a) : (b))
348
349#define PER_ALIGN do{ \
350if (0 != (pContext->shiftRegisterLength)%8) { \
351putShortBits( pContext, 8 - (pContext->shiftRegisterLength)%8 , 0); \
352} \
353}while(0);
354
355
356#define PER_CLEAR_ALIGN_BITS getShortBits( pContext, pContext->shiftRegisterLength);
357
358
359#define BEGIN_PRE_ENCODE do{ \
360 EncodeBeginPoint begin; \
361 AsnContext TempContext = *pContext; \
362 pContext->shiftRegisterLength = 0;\
363 if (NULL != pContext->pEncoded)\
364 {\
365 pContext->shiftRegister = 0;\
366 }\
367 begin = BeginTestEncodeLen(pContext);
368
369
370#define END_PRE_ENCODE ulen = EndTestEncodeLen(pContext, begin); \
371 if(0 == ulen){putShortBits(pContext, 8, 0); ulen = 1;}\
372 *pContext = TempContext; \
373 if (NULL != pContext->pEncoded)\
374 {\
375 asnMemAlloc(pContext, (void **)&pTemp, ulen); \
376 asnMemCopy(pTemp, pContext->pEncoded, ulen); \
377 }\
378}while(0);
379
380
381#define BEGIN_PRE_DECODE_EXT do{ \
382 U8 *pTemp; \
383 AsnContext TempContext; \
384 int len = UperGetLengthValue(pContext, 0, ASN_MAX); \
385 if( pContext->pEncoded + len > pContext->pEncodedEnd ) \
386 { \
387 UA1_ERROR( 8 ); \
388 } \
389 TempContext = *pContext;
390
391
392#define END_PRE_DECODE_EXT *pContext = TempContext; \
393 asnMemAlloc(pContext, (void **)&pTemp, len); \
394 getLongBits(pContext, len*8, pTemp); \
395 if (pContext->pMemFreeFunc != NULL)\
396 {\
397 pContext->pMemFreeFunc((void **)&pTemp);\
398 }\
399 else\
400 {\
401 asnMemFree((void **)&pTemp); \
402 }\
403}while(0);
404
405
406#define COPY_STATIC_ARRAY_TO_BUFFER(pBuffer, Array, begin, len) do{\
407 int i;\
408 for(i=0; i<len; i++)\
409 {*(pBuffer+i) = Array[begin+i];}\
410}while(0);
411
412U16 GetUperLengthDeterminant( AsnContext *pContext );
413void PutUperLengthDeterminant( AsnContext *pContext, U16 length );
414
415void AsnFreeDecoded( void *pType, PAsnMemFreeCallBack pFreeFunc);
416
417#if defined(__UMTS_RAT__) || defined(__LTE_RAT__)
418/* nick for block free */
419void AsnFreeDecodedSetBlock( void *pType, PAsnMemFreeCallBack pFreeFunc, void *start, int count);
420void AsnFreeDecodedWithBlock( void *pType , PAsnMemFreeCallBack pFreeFunc);
421
422/* nick integrate from old asn common*/
423void AsnDecodeFreeWithCallback( AllocRecord *decodeAlloc, PAsnMemFreeCallBack pFreeFunc );
424void AsnEncodeFreeWithCallback( void *pFree, PAsnMemFreeCallBack pFreeFunc);
425#endif
426
427void AsnFreeEncoded( U8 *pEncoded, PAsnMemFreeCallBack pFreeFunc);
428void AsnRootDecodeAlloc( AsnContext *pContext, void **ppType, int size );
429void AsnDecodeAlloc( AsnContext *pContext, void **ppMem, int size );
430void AsnDecodeFree( AllocRecord *decodeAlloc, PAsnMemFreeCallBack pFreeFunc);
431void AsnEncodeAlloc( AsnContext *pContext, U8 **ppMem, U32 *pEncodedLength );
432void AsnEncodeFree( void *pFree, PAsnMemFreeCallBack pFreeFunc);
433void AsnError( AsnContext *pContext, U32 errorCode );
434extern void initFifo( AsnContext *pContext, U8 *buffer, U32 bufferLength );
435extern void flushFifo( AsnContext *pContext );
436extern U32 getShortBits( AsnContext *pContext, U32 numBits );
437extern U32 getBits( AsnContext *pContext, U32 numBits );
438extern void getLongBits( AsnContext *pContext, U32 numBits, U8 *outputBuffer );
439extern U64 getInt64( AsnContext *pContext, U32 numBits );
440extern void putShortBits( AsnContext *pContext, U32 numBits, U32 data );
441extern void putBits( AsnContext *pContext, U32 numBits, U32 data );
442extern void putInt64( AsnContext *pContext, U32 numBits, U64 data );
443extern void putLongBits( AsnContext *pContext, U32 numBits, U8 *data );
444extern S32 GetAlphabetIndex(ASN_OneByteAlphabet *pAlphabet, char *pChar);
445extern U32 GetNumberOctetLength(U32 Data);
446extern Bool OIDCompare(OID oidA, U32 length, U32 *pValue);
447extern void SkipEncodeByte(AsnContext *pContext);
448extern EncodeBeginPoint BeginTestEncodeLen(AsnContext *pContext);
449extern U32 EndTestEncodeLen(AsnContext *pContext, EncodeBeginPoint BeginPoint);
450extern void PutShortSkipedEncodeByte(AsnContext *pContext, U32 uByte, U32 Data, U32 uAfterSize);
451extern U32 testGetShortBits(AsnContext *pContext, U32 numBits);
452
453#ifdef __cplusplus
454}
455#endif
456#endif /* ASN_COMMON_H */