comparison gsm-fw/ccd/csn1_choice_x.c @ 648:970d6199f2c5

gsm-fw/ccd/*.[ch]: initial import from the LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 04 Sep 2014 05:48:57 +0000
parents
children
comparison
equal deleted inserted replaced
647:a60b375014e3 648:970d6199f2c5
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : CCD
4 | Modul : csn1_choice_x.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 CSN1_CHOICE2
18 | elements
19 +-----------------------------------------------------------------------------
20 */
21 /*
22 * standard definitions like GLOBAL, UCHAR, ERROR etc.
23 */
24 #include "typedefs.h"
25 #include "header.h"
26
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 #include "ccd_codingtypes.h"
46 /*
47 * Declaration of coder/decoder tables
48 */
49 #include "ccdtable.h"
50 #include "ccddata.h"
51
52 EXTERN T_FUNC_POINTER codec[MAX_CODEC_ID+1][2];
53
54 #ifndef RUN_INT_RAM
55 /* Attention for RUN_...: static function */
56
57 static void decode_csn1_choice_alternative(const ULONG e_ref, T_ENUM union_tag,
58 T_CCD_Globs *globs);
59 static void encode_csn1_choice_alternative(const ULONG e_ref, T_ENUM union_tag,
60 T_CCD_Globs *globs);
61 #endif /* !RUN_INT_RAM */
62
63
64 #ifndef RUN_INT_RAM
65 /* Attention for RUN_...: static function */
66 /*
67 +--------------------------------------------------------------------+
68 | PROJECT : CCD (6144) MODULE : csn1_choice1 |
69 | STATE : code ROUTINE : decode_csn1_choice_alternative |
70 +--------------------------------------------------------------------+
71
72 PURPOSE : Decode a chosen alternative of a CSN.1 CHOICE type
73 Use the parameter union_tag to read the CHOICE index.
74 Because of union_tag it is easy to calculate the elemRef
75 for the chosen element which is to be decoded. Then the
76 appropriate decoding function for the chosen element is
77 called.
78 */
79 static void decode_csn1_choice_alternative(const ULONG e_ref, T_ENUM union_tag,
80 T_CCD_Globs *globs)
81 {
82 ULONG elem_ref, mcomp_ref;
83 UBYTE *act_structpos;
84
85 mcomp_ref= melem[e_ref].elemRef;
86 /*
87 * Write the CHOICE tag value in the C-structure.
88 * Calculate the elem_ref for the chosen element.
89 */
90 *(T_ENUM *) (globs->pstruct+globs->pstructOffs) = union_tag;
91 elem_ref = mcomp[mcomp_ref].componentRef + (ULONG) union_tag;
92
93 #ifdef DEBUG_CCD
94 #ifndef CCD_SYMBOLS
95 TRACE_CCD (globs, "decode_csn1_choice_alternative()");
96 #else
97 TRACE_CCD (globs, "decode_csn1_choice_alternative() %s", ccddata_get_alias((USHORT)e_ref, 1));
98 #endif
99 #endif
100
101 /*
102 * Store the actual structure position.
103 */
104 act_structpos = globs->pstruct;
105 globs->pstruct += (globs->pstructOffs + sizeof(T_ENUM));
106 /*
107 * Use the jump-table for selecting the decode function
108 * Call the decode function for the chosen element.
109 */
110 (void) codec[melem[elem_ref].codingType][DECODE_FUN]
111 (mcomp_ref, elem_ref, globs);
112 /*
113 * Restore the write pointer to prepare decoding of the next element
114 */
115 globs->pstruct = act_structpos;
116 }
117 #endif /* !RUN_INT_RAM */
118
119
120 #ifndef RUN_INT_RAM
121 /* Attention for RUN_...: static function */
122 /*
123 +--------------------------------------------------------------------+
124 | PROJECT : CCD (6144) MODULE : csn1_choice1 |
125 | STATE : code ROUTINE : encode_csn1_choice_alternative |
126 +--------------------------------------------------------------------+
127
128 PURPOSE : Encode a chosen alternative of a CSN.1 CHOICE type.
129
130 Because of union_tag it is easy to calculate the e_ref for
131 the chosen element to be encoded. Then the appropriate
132 encoding function for the chosen element is called.
133 */
134 static void encode_csn1_choice_alternative (const ULONG e_ref, T_ENUM union_tag,
135 T_CCD_Globs *globs)
136 {
137 ULONG elem_ref, mcomp_ref;
138 UBYTE *act_structpos;
139
140 mcomp_ref= melem[e_ref].elemRef;
141
142 /*
143 * Calculate the elem_ref for the chosen element.
144 */
145 elem_ref = mcomp[mcomp_ref].componentRef + (ULONG) union_tag;
146
147 #ifdef DEBUG_CCD
148 #ifndef CCD_SYMBOLS
149 TRACE_CCD (globs, "encode_csn1_choice_alternative()");
150 #else
151 TRACE_CCD (globs, "encode_csn1_choice_alternative() %s", ccddata_get_alias((USHORT)e_ref, 1));
152 #endif
153 #endif
154
155 /*
156 * Store the actual structure position.
157 */
158 act_structpos = globs->pstruct;
159 globs->pstruct += (globs->pstructOffs + sizeof(T_ENUM));
160 /*
161 * Use the jump-table for selecting the encode function
162 * Call the encode function for the chosen element.
163 */
164 (void) codec[melem[elem_ref].codingType][ENCODE_FUN]
165 (mcomp_ref, elem_ref, globs);
166 /*
167 * Restore the write pointer to prepare decoding of the next element
168 */
169 globs->pstruct = act_structpos;
170 }
171 #endif /* !RUN_INT_RAM */
172
173
174 #ifndef RUN_INT_RAM/*
175 +-----------------------------------------------------------------------+
176 | PROJECT : CCD (6144) MODULE : CCD |
177 | STATE : code ROUTINE : cdc_csn1_choice_x_decode |
178 +-----------------------------------------------------------------------+
179
180 PURPOSE : Decode CSN.1 CHOICE type
181 In the header file the structure containing an element of
182 coding type CSN1_CHOICE is represented by a structure
183 type declaration.
184 This structure type is composed at least of a control item
185 preceding an item of an union type. The control item
186 indicates the CHOICE index. The item of the union type
187 represents the CHOICE alternatives.
188 The CHOICE index is "num" bits long. It is read from the
189 message bit string and the result is written to the control
190 item. CCD determes "elemRef" depending on this control item
191 and processes the union element according to table entry
192 of "elemRef" .
193 */
194
195 SHORT cdc_csn1_choice_x_decode (const ULONG c_ref, const ULONG e_ref,
196 ULONG num, T_CCD_Globs *globs)
197 {
198 ULONG union_tag, num_of_alt, num_of_comps;
199 ULONG cix_ref, num_prolog_steps, prolog_step_ref;
200
201 #ifdef DEBUG_CCD
202 #ifndef CCD_SYMBOLS
203 TRACE_CCD (globs, "cdc_csn1_choice1_decode()");
204 #else
205 TRACE_CCD (globs, "cdc_csn1_choice1_decode() %s", ccddata_get_alias((USHORT)e_ref, 1));
206 #endif
207 #endif
208
209 cix_ref = melem[e_ref].calcIdxRef;
210 num_prolog_steps = calcidx[cix_ref].numPrologSteps;
211 prolog_step_ref = calcidx[cix_ref].prologStepRef;
212
213 /*
214 * If this element is conditional, check the condition.
215 */
216 if (calcidx[cix_ref].numCondCalcs NEQ 0
217 AND ! ccd_conditionOK (e_ref, globs))
218 return 1;
219
220 /*
221 * If this element has a defined prologue
222 * we have to process it before decoding the bitstream.
223 */
224 if (num_prolog_steps)
225 {
226 ccd_performOperations (num_prolog_steps, prolog_step_ref, globs);
227 }
228
229 globs->pstructOffs = melem[e_ref].structOffs;
230
231 if (melem[e_ref].optional)
232 {
233 /* Postpone optional flag setting for non-code transparent
234 * pointer types ('P', 'Q', 'R').
235 * For these types, the optional flag is the pointer itself.
236 * These types cannot be set yet, as the pointer may be
237 * preceeded by a counter octet, a union tag id octet etc.
238 */
239 if (melem[e_ref].elemType < 'P' OR melem[e_ref].elemType > 'R')
240 globs->pstruct[globs->pstructOffs++] = (UBYTE) TRUE;
241 }
242
243 /*
244 * Get the number of alternatives from the C-structure.
245 */
246 num_of_comps = mcomp[melem[e_ref].elemRef].numOfComponents;
247 /* Determine number of possible alternatives */
248 num_of_alt = num <<1;
249
250 /* read the bit representing the CHOICE index*/
251 union_tag = bf_getBits(num, globs);
252
253 /* Check number of alternatives */
254 if (!num_of_comps)
255 {
256 /* Don't do anything for empty choices */
257 return 1;
258 }
259 else if (num_of_comps != num_of_alt)
260 {
261 /* if the number of components doesn't match to number of possible
262 * examine whether the CHOICE index demands an impossible alternative
263 */
264 if (union_tag > num_of_comps)
265 {
266 /* if CHOICE index demands an impossible alternative
267 * return an error and break decoding
268 */
269 ccd_recordFault (globs, ERR_CSN1_CHOICE, BREAK, (USHORT) e_ref,
270 globs->pstruct+globs->pstructOffs);
271 }
272 else
273 {
274 ccd_recordFault (globs, ERR_CSN1_CHOICE, CONTINUE, (USHORT) e_ref,
275 globs->pstruct+globs->pstructOffs);
276 }
277 }
278
279 /*
280 * Decode a chosen alternative of an CSN.1 CHOICE type
281 */
282 decode_csn1_choice_alternative(e_ref, (T_ENUM) union_tag, globs);
283 return 1;
284 }
285 #endif /* !RUN_INT_RAM */
286
287
288
289 #ifndef RUN_INT_RAM
290
291 /*
292 +----------------------------------------------------------------------+
293 | PROJECT : CCD (6144) MODULE : csn1_choice1 |
294 | STATE : code ROUTINE : cdc_csn1_choice_x_encode |
295 +----------------------------------------------------------------------+
296
297 PURPOSE : Encoding of CHOICE1 type for UMTS
298 In the header file the structure containing an element of
299 coding type CSN1_CHOICE is represented by a structure
300 type declaration.
301 This structure type is composed at least of a control item
302 preceding an item of an union type. The control item
303 indicates the CHOICE index. The item of the union type
304 represents the CHOICE alternatives.
305 The CHOICE index is "num" bit long. Tts value is read
306 from the message structureand the result is written to the
307 bit string. CCD determines "elemRef" depending on this index
308 and processes the union element according to table entry
309 of "elemRef" .
310 */
311 SHORT cdc_csn1_choice_x_encode (const ULONG c_ref, const ULONG e_ref,
312 ULONG num, T_CCD_Globs *globs)
313 {
314 ULONG union_tag, num_of_alt, num_of_comps;
315 ULONG cix_ref, num_prolog_steps, prolog_step_ref;
316
317 #ifdef DEBUG_CCD
318 #ifndef CCD_SYMBOLS
319 TRACE_CCD (globs, "cdc_csn1_choice_encode()");
320 #else
321 TRACE_CCD (globs, "cdc_csn1_choice_encode() %s",
322 mcomp[melem[e_ref].elemRef].name);
323 #endif
324 #endif
325
326 cix_ref = melem[e_ref].calcIdxRef;
327 num_prolog_steps = calcidx[cix_ref].numPrologSteps;
328 prolog_step_ref = calcidx[cix_ref].prologStepRef;
329
330 /*
331 * If this element is conditional, check the condition.
332 */
333 if (calcidx[cix_ref].numCondCalcs NEQ 0
334 AND ! ccd_conditionOK (e_ref, globs))
335 return 1;
336
337 /*
338 * If this element has a defined prologue
339 * we have to process it before decoding the bitstream.
340 */
341 if (num_prolog_steps)
342 {
343 ccd_performOperations (num_prolog_steps, prolog_step_ref, globs);
344 }
345
346 /*
347 * Setup the offset into the C-structure for this element
348 */
349 globs->pstructOffs = melem[e_ref].structOffs;
350
351 if (melem[e_ref].optional)
352 {
353 /*
354 * For optional elements check the valid-flag in the C-struct.
355 * Postpone optional flag setting for non-code transparent
356 * pointer types ('P', 'Q', 'R').
357 * For these types, the optional flag is the pointer itself.
358 * These types cannot be set yet, as the pointer may be
359 * preceeded by a counter octet, a union tag id octet etc.
360 */
361 if (melem[e_ref].elemType < 'P' OR melem[e_ref].elemType > 'R')
362 {
363 if (globs->pstruct[globs->pstructOffs++] EQ FALSE)
364 return 1;
365 }
366 }
367 /*
368 * Get the number of alternatives from the C-structure.
369 */
370 num_of_comps = mcomp[melem[e_ref].elemRef].numOfComponents;
371 /* Determine number of possible alternatives */
372 num_of_alt = num <<1;
373 /*
374 * Get the value of CHOICE index (= union controller) from the C-structure.
375 * Check its correctness. Write it in the air message.
376 * Afterwards encode the chosen CHOICE altervative.
377 */
378 union_tag = (ULONG) globs->pstruct[globs->pstructOffs];
379 /*
380 * Check its correctness.
381 */
382 if (union_tag >= num_of_alt)
383 {
384 /*
385 * CHOICE index goes beyond the number of alternatives determined by
386 * selected coding type => return Error and break encoding process
387 */
388 ccd_recordFault (globs, ERR_CSN1_CHOICE, BREAK,
389 (USHORT) e_ref, globs->pstruct+globs->pstructOffs);
390 }
391
392 /*
393 * Write the CHOICE tag value in the C-structure.
394 */
395 bf_writeVal (union_tag, num, globs);
396
397 /* Check number of alternatives */
398 if (!num_of_comps)
399 {
400 /* Don't do anything for empty choices */
401 return 1;
402 }
403 else if (num_of_comps != num_of_alt)
404 {
405 /* if the number of components doesn't match to number of possible
406 alternatives return a warning */
407 ccd_recordFault (globs, ERR_CSN1_CHOICE, CONTINUE,
408 (USHORT) e_ref, globs->pstruct+globs->pstructOffs);
409 if (union_tag > num_of_comps)
410 {
411 /* if the CHOICE index demands an impossible one handle this choice
412 as no_code element */
413 #ifdef DEBUG_CCD
414 #ifndef CCD_SYMBOLS
415 TRACE_CCD (globs, "cdc_No_encode()");
416 #else
417 TRACE_CCD (globs, "cdc_No_encode() %s", ccddata_get_alias((USHORT) e_ref, 1));
418 #endif
419 #endif
420 return 1;
421 }
422 }
423
424 /*
425 * Encode a chosen alternative of an CSN.1 CHOICE type
426 */
427 encode_csn1_choice_alternative (e_ref, (T_ENUM) union_tag, globs);
428
429 return 1;
430 }
431 #endif /* !RUN_INT_RAM */
432
433