FreeCalypso > hg > fc-magnetite
comparison src/gpf3/ccd/s_padding.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 : s_padding.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 S_PADDING elements | |
18 +----------------------------------------------------------------------------- | |
19 */ | |
20 | |
21 | |
22 /* | |
23 * standard definitions like GLOBAL, 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_FLASH | |
53 /* | |
54 +--------------------------------------------------------------------+ | |
55 | PROJECT : CCD (6144) MODULE : CDC_GSM | | |
56 | STATE : code ROUTINE : cdc_padd_decode | | |
57 +--------------------------------------------------------------------+ | |
58 | |
59 PURPOSE : Decoding of the GSM Type CSN1 spare padding. | |
60 This function does not evaluate the encoded bits, since | |
61 their content is irrelevant. | |
62 */ | |
63 | |
64 SHORT cdc_padd_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) | |
65 { | |
66 USHORT cixRef; | |
67 | |
68 #ifdef DEBUG_CCD | |
69 TRACE_CCD (globs, "cdc_padd_decode()"); | |
70 #endif | |
71 | |
72 /* | |
73 * Do not decode padding bits. They are not relevant. | |
74 * Just adjust the position pointer in the bit stream buffer. | |
75 * Either to the next octet boundary or to the message end, if necessary. | |
76 */ | |
77 bf_incBitpos (8-(globs->bitpos & 7), globs); | |
78 | |
79 /* First assume padding bits up to an octet boundary. In this case | |
80 * message extension could be made of T, TV or TLV types. | |
81 */ | |
82 globs->SeekTLVExt = TRUE; | |
83 | |
84 cixRef = melem[e_ref].calcIdxRef; | |
85 if (calcidx[cixRef].numPrologSteps > 0) | |
86 { | |
87 USHORT msgEnd = (USHORT) calc[calcidx[cixRef].prologStepRef].operand * 8; | |
88 if (msgEnd) | |
89 { | |
90 msgEnd += globs->bitoffs; | |
91 msgEnd = (USHORT)MINIMUM(globs->maxBitpos, msgEnd); | |
92 bf_setBitpos (msgEnd, globs); | |
93 /* | |
94 * Padding bytes exclude the presence of message extension. | |
95 */ | |
96 globs->SeekTLVExt = FALSE; | |
97 } | |
98 } | |
99 | |
100 return 1; | |
101 } | |
102 #endif /* !RUN_FLASH */ | |
103 | |
104 #ifndef RUN_FLASH | |
105 /* | |
106 +--------------------------------------------------------------------+ | |
107 | PROJECT : CCD (6144) MODULE : CDC_GSM | | |
108 | STATE : code ROUTINE : cdc_padd_encode | | |
109 +--------------------------------------------------------------------+ | |
110 | |
111 PURPOSE : Encoding of the GSM Type CSN1 spare padding. | |
112 Supported padding values are 0x00 and 0x2B, if first prolog | |
113 step is a value msg_len, padding is done until globs->bitpos is | |
114 msg_len*8, else until octet boundary | |
115 */ | |
116 | |
117 SHORT cdc_padd_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) | |
118 { | |
119 UBYTE padd_bit = 0; | |
120 USHORT cixRef; | |
121 | |
122 #ifdef DEBUG_CCD | |
123 TRACE_CCD (globs, "cdc_padd_encode()"); | |
124 #endif | |
125 | |
126 cixRef = melem[e_ref].calcIdxRef; | |
127 | |
128 /* | |
129 * if this element is conditional, check the condition | |
130 */ | |
131 if (calcidx[cixRef].numCondCalcs NEQ 0 | |
132 AND ! ccd_conditionOK (e_ref, globs)) | |
133 return 1; | |
134 | |
135 if (melem[e_ref].elemType EQ 'S' AND spare[melem[e_ref].elemRef].bSize EQ 8) | |
136 { | |
137 UBYTE spareVal = (UBYTE)(spare[melem[e_ref].elemRef].value); | |
138 /* | |
139 * Element is a SPARE of length 8. | |
140 */ | |
141 while (globs->bitpos % 8 NEQ 0) | |
142 { | |
143 switch(spareVal) | |
144 { | |
145 case 0: | |
146 break; | |
147 case 0x2B: | |
148 padd_bit = (UBYTE)GET_HL(0); | |
149 break; | |
150 default: | |
151 ccd_setError (globs, ERR_INTERNAL_ERROR, | |
152 BREAK, | |
153 (USHORT) (globs->bitpos), | |
154 (USHORT) -1); | |
155 } | |
156 bf_writeBit (padd_bit, globs); | |
157 } | |
158 if (calcidx[cixRef].numPrologSteps > 0) | |
159 { | |
160 if (calc[calcidx[cixRef].prologStepRef].operation NEQ 'P') | |
161 ccd_setError (globs, ERR_INTERNAL_ERROR, BREAK, (USHORT) -1); | |
162 else | |
163 { | |
164 USHORT msgLen = (USHORT)(calc[calcidx[cixRef].prologStepRef].operand * 8); | |
165 | |
166 while (globs->bitpos - globs->bitoffs < msgLen ) | |
167 { | |
168 bf_codeLongNumber (8, (ULONG) spareVal, globs); | |
169 } | |
170 } | |
171 } | |
172 } | |
173 else | |
174 { | |
175 ccd_setError (globs, ERR_INVALID_TYPE, | |
176 BREAK, | |
177 (USHORT) (globs->bitpos), | |
178 (USHORT) -1); | |
179 } | |
180 | |
181 return 1; | |
182 } | |
183 #endif /* !RUN_FLASH */ |