comparison ccd/ccd_elem.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul : ccd_elem.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 : Condat Conder Decoder -
18 | Definition of encoding and decoding functions of
19 | information elements of air interface messages
20 +-----------------------------------------------------------------------------
21 */
22
23 #define CCD_ELEM_C
24
25 #include <stdio.h>
26 #include <string.h>
27
28 #include "typedefs.h"
29 #include "ccd_globs.h"
30 #include "ccd.h"
31 #include "ccdtable.h"
32 #include "ccddata.h"
33 #include "ccdapi.h"
34 #include "bitfun.h"
35
36 #ifndef RUN_INT_RAM
37 /*
38 +--------------------------------------------------------------------+
39 | PROJECT : CCD (6144) MODULE : ccd_elem |
40 | STATE : code ROUTINE : ccd_decodeElem |
41 +--------------------------------------------------------------------+
42
43 PARAMETERS: ULONG ccdid
44 - Enumeration of the information element to be
45 decoded in the file ccdid.h. This number is also
46 the reference number of the IE in the melem table.
47
48 USHORT l_buf
49 - Number of bits in the encoded IE.
50
51 USHORT o_buf
52 - Offset of the bitstream buffer in bits.
53
54 U8 *buf
55 - Bitstream buffer of the encoded IE.
56
57 U8 *eStruct
58 - reference to the C-Structure containing the
59 C-Representation of the decoded IE.
60
61 PURPOSE: decodes a bitstream containing an encoded information
62 element. The results are written to a corresponding
63 C-Structure, the C-Representation of the IE.
64 */
65 int CCDDATA_PREF(ccd_decodeElem) (ULONG ccdid,
66 USHORT l_buf,
67 USHORT o_buf,
68 UCHAR* buf,
69 UCHAR* eStruct)
70 {
71 int jmp_ret;
72 USHORT mcompRef;
73 T_CCD_Globs *globs;
74 T_CCD_ERR_LIST_HEAD* eentry;
75 T_CCD_STORE_LIST* stoentry;
76
77 globs = ccd_GetGlobVars (&eentry, &stoentry);
78
79 #ifdef DEBUG_CCD
80 ccd_dump_msg(l_buf, o_buf, buf, globs);
81 #endif
82
83 /*
84 * setup the structure-buffer. */
85 globs->pstruct = eStruct;
86 globs->pstructOffs = 0;
87
88 ccd_common_decode_init(l_buf, o_buf, buf, globs);
89 ccd_err_reset (eentry);
90 globs->ccd_recurs_level =1;
91
92 if ((mcompRef = melem[ccdid].elemRef) EQ NO_REF)
93 {
94 ccd_recordFault (globs, ERR_INVALID_CCDID, BREAK, ccdid, NULL);
95 ccd_FreeGlobVars (globs);
96 ccd_err_free (eentry);
97 return (BYTE)globs->CCD_Error;
98 }
99
100
101 #ifdef DEBUG_CCD
102 #ifdef CCD_SYMBOLS
103 TRACE_CCD (globs, "CCD decode: Element = %s",
104 mcomp[mcompRef].name);
105 #else
106 TRACE_CCD (globs, "CCD decode: CCD_Id = %x", ccdid);
107 #endif
108 #endif
109
110 #ifdef ERR_TRC_STK_CCD
111 /* save the value for tracing in error case */
112 globs->error_stack[0] = mcompRef;
113 #endif /* ERR_TRC_STK_CCD */
114
115 /*
116 * Clean up the entite C-structure before decoding.
117 * Do not overwrite the MsgId (1. Byte)
118 */
119 #ifdef DEBUG_CCD
120 TRACE_CCD (globs, "CCD Cleaning struct %ld bytes",
121 mcomp[mcompRef].cSize);
122 #endif
123 memset ((UBYTE *) globs->pstruct, 0,
124 (size_t)(mcomp[mcompRef].cSize));
125
126 /*
127 * clear the UPN stack
128 */
129 globs->SP=0;
130 globs->StackOvfl=FALSE;
131 globs->KeepReg[0] = 0;
132
133 /*
134 * inform the GSM-CODEC about the begin of a new message
135 */
136 cdc_GSM_start (globs);
137
138 jmp_ret = setjmp (globs->jmp_mark);
139
140 if (jmp_ret EQ 0)
141 {
142 globs->jmp_mark_set = TRUE;
143 ccd_decodeComposition ((ULONG) mcompRef, globs);
144 }
145
146 #ifdef DEBUG_CCD
147 TRACE_CCD (globs, "CCD-ERROR = %d", globs->CCD_Error);
148 TRACE_CCD (globs, "-------------------------------------------------");
149 #endif /* DEBUG_CCD */
150
151 ccd_FreeGlobVars (globs);
152 ccd_err_free (eentry);
153
154 return (BYTE) globs->CCD_Error;
155 }
156 #endif /* !RUN_INT_RAM */
157
158 #ifndef RUN_INT_RAM
159 /*
160 +--------------------------------------------------------------------+
161 | PROJECT : CCD (6144) MODULE : ccd_elem |
162 | STATE : code ROUTINE : ccd_encodeElem |
163 +--------------------------------------------------------------------+
164
165 PARAMETERS: ULONG ccdid
166 - Enumeration of the information element to be
167 encoded in the file ccdid.h. This number is also
168 the reference number of the IE in the melem table
169
170 USHORT l_buf
171 - Number of bits in the encoded IE.
172
173 USHORT o_buf
174 - Offset of the bitstream buffer in bits.
175
176 U8 *buf
177 - Bitstream buffer of the encoded IE.
178
179 UBYTE * eStruct
180 - reference to the C-Structure containing the
181 C-Representation of the decoded IE.
182
183 PURPOSE: encodes a C-Structure containing the C-Representation of
184 an information element to a bitstream.
185 */
186 int CCDDATA_PREF(ccd_encodeElem) (ULONG ccdid,
187 USHORT* l_buf,
188 USHORT o_buf,
189 UCHAR* buf,
190 UCHAR* eStruct)
191 {
192 int jmp_ret;
193 USHORT maxBytes, mcompRef;
194 T_CCD_Globs *globs;
195 T_CCD_ERR_LIST_HEAD* eentry;
196 T_CCD_STORE_LIST* stoentry;
197
198 globs = ccd_GetGlobVars (&eentry, &stoentry);
199 ccd_err_reset (eentry);
200
201 #ifdef DEBUG_CCD
202 {
203 /* to avoid the vsprintf if the traces won't appear anyhow */
204 ULONG mask;
205 if (vsi_gettracemask (globs->me, globs->me, &mask) != VSI_ERROR)
206 {
207 globs->TraceIt = mask & TC_CCD;
208 }
209 }
210 #endif
211
212 /*
213 * Set a sign that no call to setjmp() is done. So ccd_setError
214 * performs no longjmp in case of an error.
215 */
216 globs->jmp_mark_set = FALSE;
217
218 /* Setup the bitbuffer. */
219 globs->bitbuf = buf;
220 globs->bitpos = 0;
221
222 /* Setup the structure-buffer. */
223 globs->pstruct = eStruct;
224 globs->pstructOffs = 0;
225
226 /* Cleanup the read-caches. */
227 globs->lastbytepos16 = globs->lastbytepos32 = 0xffff;
228
229 /* Setup the bitoffset. */
230 globs->bitoffs = o_buf;
231 bf_incBitpos (o_buf, globs);
232 globs->bitbuf[globs->bytepos] = 0;
233
234 globs->CCD_Error = ccdOK;
235 globs->ccd_recurs_level =1;
236
237 if ((mcompRef = melem[ccdid].elemRef) EQ NO_REF)
238 {
239 ccd_recordFault (globs, ERR_INVALID_CCDID, BREAK, ccdid, NULL);
240 ccd_FreeGlobVars (globs);
241 ccd_err_free (eentry);
242 return (BYTE)globs->CCD_Error;
243 }
244
245 #ifdef DEBUG_CCD
246 #ifdef CCD_SYMBOLS
247 TRACE_CCD (globs, "CCD encode: Element = %s",
248 mcomp[mcompRef].name);
249 #else
250 TRACE_CCD (globs, "CCD encode: CCD_Id = %x", ccdid);
251 #endif
252 #endif
253
254 #ifdef ERR_TRC_STK_CCD
255 /* Save the value for tracing in error case. */
256 globs->error_stack[0] = mcompRef;
257 #endif
258
259 maxBytes = (USHORT) (mcomp[mcompRef].bSize+7)>>3;
260 #ifdef DEBUG_CCD
261 TRACE_CCD (globs, "-------------------------------------------------");
262 TRACE_CCD (globs, "CCD: Code Elem");
263 TRACE_CCD (globs, "Cleaning %d bits (%d bytes) of the bitstream",
264 mcomp[mcompRef].bSize, maxBytes);
265 #endif
266
267 /*
268 * Clean up the bit buffer for the encoded message before encoding.
269 */
270 memset ((U8 *) &buf[o_buf>>3], 0, (size_t) maxBytes);
271
272 /* Store the length of ereased buffer to support error handling. */
273 globs->buflen = (USHORT) mcomp[mcompRef].bSize;
274
275 /*
276 * Clear the UPN stack.
277 */
278 globs->SP=0;
279 globs->StackOvfl=FALSE;
280 globs->KeepReg[0] = 0;
281
282 /*
283 * Inform the GSM-CODEC about the begin of a new message.
284 */
285 cdc_GSM_start (globs);
286
287 jmp_ret = setjmp (globs->jmp_mark);
288
289 if (jmp_ret EQ 0)
290 {
291 globs->jmp_mark_set = TRUE;
292 ccd_encodeComposition ((ULONG) mcompRef, globs);
293 }
294
295 *l_buf = (USHORT)(globs->bitpos - globs->bitoffs);
296
297 #ifdef DEBUG_CCD
298 {
299 int i, j, buflen;
300 char s[64], c[4];
301
302 buflen = (*l_buf + o_buf + 7) >> 3;
303
304 TRACE_CCD (globs, "-------------------------------------------------");
305 TRACE_CCD (globs, " After ENCODING: lbuf= %d, obuf= %d", *l_buf, o_buf);
306 TRACE_CCD (globs, " Hex dump of encoded message:");
307
308 s[0] = '\0';
309 for (i = o_buf >> 3; i < buflen; i+=16)
310 {
311 for (j = 0; j < 16; j++)
312 {
313 if ((i+j) < buflen)
314 {
315 sprintf(c, " %02x", buf[i+j]);
316 strcat (s, c);
317 }
318 }
319 TRACE_CCD (globs, "%s", s);
320 s[0] = '\0';
321 }
322 }
323 #endif
324
325 #ifdef DEBUG_CCD
326 TRACE_CCD (globs, "CCD-ERROR = %d", globs->CCD_Error);
327 TRACE_CCD (globs, "-------------------------------------------------");
328 #endif /* DEBUG_CCD */
329
330 ccd_FreeGlobVars (globs);
331 ccd_err_free (eentry);
332
333 return (BYTE) globs->CCD_Error;
334 }
335 #endif /* !RUN_INT_RAM */