comparison gsm-fw/ccd/s_padding_0.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 : s_padding_0.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_0
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 MODULE : s_padding_0 |
56 | STATE : code ROUTINE : cdc_padd_0_decode |
57 +--------------------------------------------------------------------+
58
59 PURPOSE : Decoding of the GSM Type CSN1 spare padding which is
60 preceded by a 0 bit.
61 If that bit is read as 1 then a protocol extension is
62 assumed by CCD.
63 This function does not evaluate the encoded bits, since
64 their content is irrelevant.
65 */
66
67 SHORT cdc_padd_0_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs)
68 {
69 U16 cixRef;
70 #ifdef DEBUG_CCD
71 TRACE_CCD (globs, "cdc_padd_0_decode()");
72 #endif
73
74 if (bf_readBit(globs) == 1)
75 {
76 ccd_recordFault (globs, ERR_PROTOCOL_EXTENSION, CONTINUE, (USHORT) e_ref, NULL);
77 }
78
79 /*
80 * Do not decode padding bits. They are not relevant.
81 * Just adjust the position pointer in the bit stream buffer.
82 * Either to the next octet boundary or to the message end, if necessary.
83 */
84 bf_incBitpos (8-(globs->bitpos & 7), globs);
85
86 /* First assume padding bits up to an octet boundary. In this case
87 * message extension could be made of T, TV or TLV types.
88 */
89 globs->SeekTLVExt = TRUE;
90
91 cixRef = melem[e_ref].calcIdxRef;
92 if (calcidx[cixRef].numPrologSteps > 0)
93 {
94 U16 msgEnd = (USHORT) calc[calcidx[cixRef].prologStepRef].operand * 8;
95 if (msgEnd)
96 {
97 msgEnd += globs->bitoffs;
98 msgEnd = (USHORT)MINIMUM(globs->maxBitpos, msgEnd);
99 bf_setBitpos (msgEnd, globs);
100 /*
101 * Padding bytes exclude the presence of message extension.
102 */
103 globs->SeekTLVExt = FALSE;
104 }
105 }
106 return 1;
107 }
108 #endif /* !RUN_FLASH */
109
110 #ifndef RUN_FLASH
111 /*
112 +--------------------------------------------------------------------+
113 | PROJECT : CCD MODULE : s_padding_0.c |
114 | STATE : code ROUTINE : cdc_padd_0_encode |
115 +--------------------------------------------------------------------+
116
117 PURPOSE : Encoding of the GSM Type CSN1 spare padding which is
118 preceded by a 0 bit.
119 Supported padding values are 0x00 and 0x2B.
120 If the first prologue step is a value msg_len, padding
121 is done until globs->bitpos is msg_len*8.
122 Otherwise until the octet boundary.
123 */
124
125 SHORT cdc_padd_0_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs)
126 {
127 U8 padd_bit = 0;
128 U16 cixRef;
129 U16 msgLen = globs->buflen;
130 BOOL paddingOctets = FALSE;
131
132 #ifdef DEBUG_CCD
133 TRACE_CCD (globs, "cdc_padd_0_encode()");
134 #endif
135
136 cixRef = melem[e_ref].calcIdxRef;
137
138 /*
139 * if this element is conditional, check the condition
140 */
141 if (calcidx[cixRef].numCondCalcs NEQ 0
142 AND ! ccd_conditionOK (e_ref, globs))
143 return 1;
144
145 if (calcidx[cixRef].numPrologSteps > 0)
146 {
147 if (calc[calcidx[cixRef].prologStepRef].operation NEQ 'P')
148 ccd_setError (globs, ERR_INTERNAL_ERROR, BREAK, (USHORT) -1);
149 else
150 {
151 msgLen = (USHORT)(calc[calcidx[cixRef].prologStepRef].operand * 8);
152 paddingOctets = TRUE;
153 }
154 }
155
156 /*
157 * If there is some space left for spare padding, we will code them.
158 * If the bit pos pointer goes beyond the message border, ccd will detect
159 * this later and bring a warning. But not here. Reason: saving room.
160 */
161 if (globs->bitpos - globs->bitoffs < msgLen )
162 {
163 /*
164 * The IE should be present in the message so we code 0 bit.
165 */
166 bf_writeBit (0, globs);
167
168 if (melem[e_ref].elemType EQ 'S' AND spare[melem[e_ref].elemRef].bSize EQ 8)
169 {
170 ULONG spareVal = spare[melem[e_ref].elemRef].value;
171 /*
172 * Element is a SPARE of length 8.
173 */
174 while (globs->bitpos % 8 NEQ 0)
175 {
176 switch(spareVal)
177 {
178 case 0:
179 break;
180 case 0x2B:
181 padd_bit = (UBYTE)GET_HL(0);
182 break;
183 default:
184 ccd_setError (globs, ERR_INTERNAL_ERROR,
185 BREAK,
186 (USHORT) (globs->bitpos),
187 (USHORT) -1);
188 }
189 bf_writeBit (padd_bit, globs);
190 }
191
192 /* Write spare padding octets. */
193 if (paddingOctets)
194 {
195 while (globs->bitpos - globs->bitoffs < msgLen )
196 {
197 bf_codeLongNumber (8, spareVal, globs);
198 }
199 }
200 }
201
202 else
203 {
204 ccd_setError (globs, ERR_INVALID_TYPE,
205 BREAK,
206 (USHORT) (globs->bitpos),
207 (USHORT) -1);
208 }
209 }
210
211 return 1;
212 }
213 #endif /* !RUN_FLASH */