FreeCalypso > hg > fc-magnetite
comparison src/gpf3/ccd/asn1_bitstr.c @ 2:c41a534f33c6
src/gpf3: preened GPF goo from TCS3.2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 25 Sep 2016 23:52:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:864b8cc0cf63 | 2:c41a534f33c6 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Project : | |
4 | Modul : asn1_bitstr.c | |
5 +----------------------------------------------------------------------------- | |
6 | Copyright 2002 Texas Instruments Berlin, AG | |
7 | All rights reserved. | |
8 | | |
9 | This file is confidential and a trade secret of Texas | |
10 | Instruments Berlin, AG | |
11 | The receipt of or possession of this file does not convey | |
12 | any rights to reproduce or disclose its contents or to | |
13 | manufacture, use, or sell anything it may describe, in | |
14 | whole, or in part, without the specific written consent of | |
15 | Texas Instruments Berlin, AG. | |
16 +----------------------------------------------------------------------------- | |
17 | Purpose : Definition of encoding and decoding functions for ASN1_BITSTRING | |
18 | elements | |
19 +----------------------------------------------------------------------------- | |
20 */ | |
21 | |
22 /* | |
23 * Standard definitions like UCHAR, ERROR etc. | |
24 */ | |
25 #include "typedefs.h" | |
26 #include "header.h" | |
27 | |
28 /* | |
29 * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only | |
30 * look at ccdapi.h | |
31 */ | |
32 #undef USE_DRIVER | |
33 #include "ccdapi.h" | |
34 | |
35 /* | |
36 * Types and functions for bit access and manipulation | |
37 */ | |
38 #include "ccd_globs.h" | |
39 #include "bitfun.h" | |
40 | |
41 /* | |
42 * Prototypes of ccd internal functions | |
43 */ | |
44 #include "ccd.h" | |
45 | |
46 /* | |
47 * Declaration of coder/decoder tables | |
48 */ | |
49 #include "ccdtable.h" | |
50 #include "ccddata.h" | |
51 | |
52 #ifndef RUN_INT_RAM | |
53 /* | |
54 +--------------------------------------------------------------------+ | |
55 | PROJECT : CCD (6144) MODULE : CDC_GSM | | |
56 | STATE : code ROUTINE : cdc_bitstring_decode | | |
57 +--------------------------------------------------------------------+ | |
58 | |
59 PURPOSE : UNALIGNED PER decoding of the bit string type (UMTS) | |
60 The coded bits are preceded by a length indicator, if | |
61 they are not of fixed length. The length indicator is | |
62 decoded as an ASN1_INTEGER type. | |
63 */ | |
64 | |
65 SHORT cdc_bitstring_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) | |
66 { | |
67 ULONG repeat; | |
68 U8 *old_pstruct = NULL; | |
69 | |
70 #ifdef DEBUG_CCD | |
71 #ifndef CCD_SYMBOLS | |
72 TRACE_CCD (globs, "cdc_asn1_bitstring_decode()"); | |
73 #else | |
74 TRACE_CCD (globs, "cdc_asn1_bitstring_decode() '%s'", ccddata_get_alias((USHORT) e_ref, 1)); | |
75 #endif | |
76 #endif | |
77 | |
78 /* | |
79 * Set pstrcutOffs and maxRep. | |
80 * Check the valid flag in case of optional elements. | |
81 */ | |
82 if (PER_CommonBegin (e_ref, &repeat, globs) NEQ ccdOK) | |
83 return 1; | |
84 | |
85 #ifdef DYNAMIC_ARRAYS | |
86 /* | |
87 * Check for pointer types, and allocate memory if necessary. | |
88 * May overwrite globs->pstruct (and initialize globs->pstructOffs to 0). | |
89 */ | |
90 if ( is_pointer_type(e_ref) ) { | |
91 old_pstruct = globs->pstruct; | |
92 if ( PER_allocmem_and_update(e_ref, (USHORT) ((repeat >> 3) +1), globs) NEQ ccdOK) | |
93 /* No memory - Return. Error already set in function call above. */ | |
94 return 1; | |
95 } | |
96 #endif | |
97 | |
98 bf_readBitStr_PER ((USHORT) repeat, globs); | |
99 | |
100 #ifdef DYNAMIC_ARRAYS | |
101 if (old_pstruct NEQ NULL) | |
102 globs->pstruct = old_pstruct; | |
103 #endif | |
104 | |
105 return 1; | |
106 } | |
107 | |
108 #endif /* !RUN_INT_RAM */ | |
109 #ifndef RUN_INT_RAM | |
110 | |
111 /* | |
112 +--------------------------------------------------------------------+ | |
113 | PROJECT : CCD (6144) MODULE : CDC_GSM | | |
114 | STATE : code ROUTINE : cdc_bitstring_encode | | |
115 +--------------------------------------------------------------------+ | |
116 | |
117 PURPOSE : UNALIGNED PER encoding of the bit string type (UMTS) | |
118 The coded bits are preceded by a length indicator, if | |
119 they are not of fixed length. The length indicator is | |
120 decoded as an ASN1_INTEGER type. | |
121 */ | |
122 | |
123 SHORT cdc_bitstring_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) | |
124 { | |
125 ULONG repeat; | |
126 U8 *old_pstruct = NULL; | |
127 | |
128 #ifdef DEBUG_CCD | |
129 #ifndef CCD_SYMBOLS | |
130 TRACE_CCD (globs, "cdc_asn1_bitstring_encode()"); | |
131 #else | |
132 TRACE_CCD (globs, "cdc_asn1_bitstring_encode() '%s'", ccddata_get_alias((USHORT) e_ref, 1)); | |
133 #endif | |
134 #endif | |
135 | |
136 /* | |
137 * Set pstructOffs and maxRep. | |
138 * Check the valid flag in case of optional elements. | |
139 */ | |
140 if (PER_CommonBegin (e_ref, &repeat, globs) NEQ ccdOK) | |
141 return 1; | |
142 | |
143 #ifdef DYNAMIC_ARRAYS | |
144 if ( is_pointer_type(e_ref) ) { | |
145 old_pstruct = globs->pstruct; | |
146 globs->pstruct = *(U8 **)(globs->pstruct + globs->pstructOffs); | |
147 | |
148 if (ccd_check_pointer(globs->pstruct) == ccdOK) | |
149 { | |
150 globs->pstructOffs = 0; | |
151 } | |
152 else | |
153 { | |
154 ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref, | |
155 &globs->pstruct[globs->pstructOffs]); | |
156 return 1; | |
157 } | |
158 } | |
159 #endif | |
160 | |
161 bf_writeBitStr_PER ((USHORT) repeat, globs); | |
162 | |
163 #ifdef DYNAMIC_ARRAYS | |
164 if ( old_pstruct NEQ NULL ) | |
165 globs->pstruct = old_pstruct; | |
166 #endif | |
167 | |
168 return 1; | |
169 } | |
170 #endif /* !RUN_INT_RAM */ |