comparison ccd/csn1_concat.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 : csn1_concat.c
5 +-----------------------------------------------------------------------------
6 | Copyright 2004 Texas Instruments Deutschland GmbH
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Deutschland GmbH
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 Deutschland GmbH.
16 +-----------------------------------------------------------------------------
17 | Purpose : Condat Conder Decoder -
18 | Definition of encoding and decoding functions of
19 | CSN1 truncated concatenation elements
20 +-----------------------------------------------------------------------------
21 */
22
23
24 /*
25 * Standard definitions like GLOBAL, UCHAR, ERROR etc.
26 */
27
28 #include "typedefs.h"
29 #include "header.h"
30
31 /*
32 * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only
33 * look at ccdapi.h
34 */
35 #undef USE_DRIVER
36 #include "ccdapi.h"
37
38 /*
39 * Types and functions for bit access and manipulation
40 */
41 #include "ccd_globs.h"
42 #include "bitfun.h"
43
44 /*
45 * Prototypes of ccd internal functions
46 */
47 #include "ccd.h"
48 #include "ccd_codingtypes.h"
49
50 /*
51 * Declaration of coder/decoder tables
52 */
53 #include "ccdtable.h"
54 #include "ccddata.h"
55
56 EXTERN T_FUNC_POINTER codec[MAX_CODEC_ID+1][2];
57
58 #ifndef RUN_FLASH
59 /*
60 +---------------------------------------------------------------------+
61 | PROJECT : CCD (6144) MODULE : CCD |
62 | STATE : code ROUTINE : cdc_csn1_concat_decode |
63 +---------------------------------------------------------------------+
64
65 PURPOSE : decodes the bitstream to a C-Structure.The decoding
66 rules contains the element definitions for the
67 elements of this message.
68 This function may called recursivly because of a
69 substructured element definition.
70 */
71
72 SHORT cdc_csn1_concat_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs)
73 {
74 /*
75 * index in table melem
76 */
77 ULONG elem_ref, last_elem, start_elem;
78 SHORT codecRet;
79 U8 *actStructpos;
80 U8 actErrLabel;
81 U16 actMaxBitpos, finalBitPos;
82 U8 *pnumConcatElem = NULL;
83 ULONG i, num_concat_elem;
84 BOOL SetPosExpected = FALSE;
85 ULONG cix_ref, num_prolog_steps, prolog_step_ref;
86
87 #ifdef DEBUG_CCD
88 #ifndef CCD_SYMBOLS
89 TRACE_CCD (globs, "cdc_csn1_concat_decode()");
90 #else
91 TRACE_CCD (globs, "cdc_csn1_concat_decode() %s", ccddata_get_alias((USHORT) e_ref, 1));
92 #endif
93 #endif
94
95 actErrLabel = globs->errLabel;
96
97 /* Set ref number for calcidx table. */
98 cix_ref = melem[e_ref].calcIdxRef;
99 num_prolog_steps = calcidx[cix_ref].numPrologSteps;
100 prolog_step_ref = calcidx[cix_ref].prologStepRef;
101
102 /*
103 * If this element is conditional, check the condition.
104 */
105 if (calcidx[cix_ref].numCondCalcs NEQ 0
106 AND ! ccd_conditionOK (e_ref, globs))
107 return 1;
108
109 /*
110 * if this element have a defined Prolog
111 * we have to process it before decoding the bitstream
112 */
113 if (num_prolog_steps)
114 {
115 ccd_performOperations (num_prolog_steps, prolog_step_ref, globs);
116 }
117
118 globs->ccd_recurs_level++;
119
120 if (globs->bitpos < globs->maxBitpos)
121 {
122 if (melem[e_ref].repType == 's')
123 {
124 BOOL is_variable;
125 ULONG max_rep, repeat;
126
127 is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs);
128 if (repeat > (ULONG) (globs->maxBitpos-globs->bitpos))
129 {
130 ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE,
131 (USHORT) e_ref, globs->pstruct + globs->pstructOffs);
132 repeat = MINIMUM (repeat, (ULONG) (globs->maxBitpos-globs->bitpos));
133 }
134
135 finalBitPos = (USHORT) (globs->bitpos + repeat);
136
137 #ifdef DEBUG_CCD
138 #ifdef CCD_SYMBOLS
139 TRACE_CCD (globs, "decoding of concatenation %s as a bit array",
140 mcomp[melem[e_ref].elemRef].name);
141 #else
142 TRACE_CCD (globs, "decoding of concatenation %d as a bit array", melem[e_ref].elemRef);
143 #endif
144 #endif
145 /* Store the limit. The truncated concatenation may contain
146 other compositions as bitstring. */
147 actMaxBitpos = globs->maxBitpos;
148 globs->maxBitpos = finalBitPos;
149 }
150 else
151 {
152 #ifdef DEBUG_CCD
153 #ifdef CCD_SYMBOLS
154 TRACE_CCD (globs, "decoding concatenation %s",
155 mcomp[melem[e_ref].elemRef].name);
156 #else
157 TRACE_CCD (globs, "decoding concatenation %d", melem[e_ref].elemRef);
158 #endif
159 #endif
160 }
161
162 /*
163 * Store the actual structure position.
164 */
165 actStructpos = globs->pstruct;
166 globs->pstructOffs = melem[e_ref].structOffs;
167 globs->pstruct += globs->pstructOffs;
168 /*
169 * setup the index in the melem table for this composition.
170 */
171 elem_ref = (ULONG) mcomp[melem[e_ref].elemRef].componentRef;
172 last_elem = elem_ref + mcomp[melem[e_ref].elemRef].numOfComponents;
173 /*
174 * It is recommended to use a leading element of coding type NO_CODE
175 * in the message description which is used to count the existing
176 * elements of the truncated concatenation. If this element is missing
177 * the decoding process will proceed but the CCD user is forced to
178 * evaluate all of the valid flags.
179 */
180
181 if (melem[elem_ref].codingType == CCDTYPE_NO_CODE)
182 {
183 pnumConcatElem = globs->pstruct;
184 elem_ref++;
185
186 num_concat_elem = (ULONG) (mcomp[melem[e_ref].elemRef].numOfComponents - 1);
187 }
188
189 start_elem = elem_ref;
190 /*
191 * decode all elements
192 */
193 while (elem_ref < last_elem)
194
195 {
196 #ifdef ERR_TRC_STK_CCD
197 /* save the value for tracing in error case */
198 globs->error_stack[globs->ccd_recurs_level] = (USHORT) elem_ref;
199 #endif /* ERR_TRC_STK_CCD */
200
201 /*
202 * check if the bitstream has ended
203 */
204 if (bf_endOfBitstream(globs) AND !globs->TagPending)
205 {
206 /* End of the bit stream is not reached if a call to bf_setBitpos()
207 * is expected for the next element of the current substructure.
208 * An instructive example is an empty "mob_id"
209 */
210 cix_ref = melem[elem_ref].calcIdxRef;
211 num_prolog_steps = calcidx[cix_ref].numPrologSteps;
212 prolog_step_ref = calcidx[cix_ref].prologStepRef;
213
214 if (num_prolog_steps)
215 {
216 i = prolog_step_ref + num_prolog_steps;
217
218 while (i >= prolog_step_ref)
219 {
220 if (calc[i].operation == 'S')
221 {
222 SetPosExpected = TRUE;
223 break;
224 }
225 i--;
226 }
227 }
228
229 if (SetPosExpected EQ FALSE)
230 {
231 num_concat_elem = elem_ref - start_elem;
232 /* after the while loop the recursion level will be decremented. */
233 break;
234 }
235
236 }//if end of bit string
237
238 /*
239 * use the jump-table for selecting the decode function
240 */
241 codecRet =
242 codec[melem[elem_ref].codingType][DECODE_FUN](melem[e_ref].elemRef,
243 elem_ref, globs);
244 if (codecRet NEQ 0x7f)
245 {
246 /*
247 * set the elem_ref to the next or the same element
248 */
249 elem_ref += codecRet;
250 }
251 }
252
253 if (pnumConcatElem != NULL)
254 {
255 *pnumConcatElem = (UBYTE) num_concat_elem;
256 }
257
258
259 if (melem[e_ref].repType == 's')
260 {
261 if (globs->bitpos > finalBitPos)
262 {
263 ccd_recordFault (globs, ERR_CONCAT_LEN, CONTINUE, (USHORT) elem_ref,
264 globs->pstruct + globs->pstructOffs);
265 }
266 bf_setBitpos (finalBitPos, globs);
267 /* Update maxBitpos to avoid an early end of decoding. */
268 globs->maxBitpos = actMaxBitpos;
269 }
270
271 /*
272 * restore the write pointer
273 */
274 globs->pstruct = actStructpos;
275 }
276
277 globs->errLabel = actErrLabel;
278 /* Reset indicator of exhaustion in the IEI table*/
279 for (i = 0; globs->iei_ctx[globs->ccd_recurs_level].iei_table[i].valid == TRUE; i++)
280 {
281 globs->iei_ctx[globs->ccd_recurs_level].iei_table[i].exhausted = FALSE;
282 }
283 globs->ccd_recurs_level--;
284
285 return 1;
286 }
287 #endif /* !RUN_FLASH */
288
289 #ifndef RUN_FLASH
290 /*
291 +---------------------------------------------------------------------+
292 | PROJECT : CCD (6144) MODULE : CCD |
293 | STATE : code ROUTINE : cdc_csn1_concat_encode |
294 +---------------------------------------------------------------------+
295
296 PURPOSE : codes the content of a C-Structure into a bitstream.
297 This function may be called recursivly if an IE in the
298 structure is itself a structured IE.
299 */
300
301 SHORT cdc_csn1_concat_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs)
302
303 {
304 ULONG cix_ref, elem_ref, last_elem;
305 U8 codecRet;
306 U16 actBitpos;
307 U8 actByteOffs;
308 U8 *actStructpos;
309
310 #ifdef DEBUG_CCD
311 #ifndef CCD_SYMBOLS
312 TRACE_CCD (globs, "cdc_csn1_concat_encode()");
313 #else
314 TRACE_CCD (globs, "cdc_csn1_concat_encode() %s", ccddata_get_alias((USHORT) e_ref, 1));
315 #endif
316 #endif
317
318 cix_ref = melem[e_ref].calcIdxRef;
319
320 /*
321 * If this element is conditional, check the condition.
322 */
323 if (calcidx[cix_ref].numCondCalcs NEQ 0
324 AND ! ccd_conditionOK (e_ref, globs))
325 return 1;
326
327 globs->ccd_recurs_level++;
328
329 actStructpos = globs->pstruct;
330 globs->pstructOffs = melem[e_ref].structOffs;
331 globs->pstruct += globs->pstructOffs;
332
333 elem_ref = (ULONG) mcomp[melem[e_ref].elemRef].componentRef;
334 last_elem = elem_ref + mcomp[melem[e_ref].elemRef].numOfComponents;
335
336 /*
337 * It is recommended to use a leading element of coding type NO_CODE
338 * in the message description which is used to count the existing
339 * elements of the truncated concatenation in case of decoding.
340 * In case of encoding this element must be skipped.
341 */
342
343 if (melem[elem_ref].codingType == CCDTYPE_NO_CODE)
344 {
345 elem_ref++;
346 /* last_elem = elem_ref + *globs->pstruct;
347
348 * Encoding act on the assumption that all elements of the truncated
349 * concatenation should be encoded. CCD will skip tagged elements
350 * but in case of CSN1 coding CCD will write the flag indicating absent
351 * elements. Values of mandatory elements without valid flags are coded
352 * according to their assignments in the C-structure.
353 * If more bits are written than the component l_buf of the message buffer
354 * suggested CCD generates a warning (error code ERR_BUFFER_OF). It is up
355 * to the user to analyse the consequences of this warning and to choose
356 * adequate procedures.
357 */
358 }
359
360 /*
361 * code all elements
362 */
363 while ((elem_ref < last_elem) && (globs->bitpos < globs->msgLen))
364 {
365 #ifdef ERR_TRC_STK_CCD
366 /*
367 * Save the value for tracing in error case.
368 */
369 globs->error_stack[globs->ccd_recurs_level] = (USHORT) elem_ref;
370 #endif /* ERR_TRC_STK_CCD */
371
372 #if defined _TOOLS_
373 if (ccd_patch (globs, 0))
374 codecRet = 1;
375 else
376 #endif /* _TOOLS_ */
377
378 actBitpos = globs->bitpos;
379 actByteOffs = globs->byteoffs;
380
381 /* Use the jump-table for selecting encode function. */
382 codecRet = (UBYTE)
383 codec[melem[elem_ref].codingType][ENCODE_FUN](melem[e_ref].elemRef,
384 elem_ref, globs);
385
386 if (globs->bitpos < globs->msgLen)
387 {
388 if (codecRet NEQ 0x7f)
389 {
390 /* Set the elem_ref to the next or the same element. */
391 elem_ref += codecRet;
392 }
393 }
394 else
395 {
396 if (globs->bitpos > globs->msgLen)
397 {
398 globs->bitpos = actBitpos;
399 globs->byteoffs = actByteOffs;
400 ccd_recordFault (globs, ERR_CONCAT_LEN, CONTINUE, (USHORT) elem_ref,
401 globs->pstruct + globs->pstructOffs);
402 }
403 break;
404 }
405 }
406
407 globs->pstruct += mcomp[melem[e_ref].elemRef].cSize;
408 /*
409 * restore the read pointer
410 */
411 globs->pstruct = actStructpos;
412 globs->ccd_recurs_level--;
413 return 1;
414 }
415 #endif /* !RUN_FLASH */