FreeCalypso > hg > freecalypso-citrine
comparison g23m-aci/aci/psa_util.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 : GSM-PS (6147) | |
4 | Modul : PSA_UTIL | |
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 : This module provides utility functions | |
18 +----------------------------------------------------------------------------- | |
19 */ | |
20 | |
21 #ifndef PSA_UTIL_C | |
22 #define PSA_UTIL_C | |
23 #endif | |
24 | |
25 #include "config.h" | |
26 #include "fixedconf.h" | |
27 #include "condat-features.h" | |
28 #include "aci_conf.h" | |
29 | |
30 #include "aci_all.h" | |
31 | |
32 /*==== INCLUDES ===================================================*/ | |
33 #include "aci_cmh.h" | |
34 #include "ati_cmd.h" | |
35 | |
36 /*==== CONSTANTS ==================================================*/ | |
37 /*==== EXPORT =====================================================*/ | |
38 | |
39 /*==== VARIABLES ==================================================*/ | |
40 | |
41 /*==== FUNCTIONS ==================================================*/ | |
42 | |
43 /* | |
44 +--------------------------------------------------------------------+ | |
45 | PROJECT : GSM-F&D () MODULE : ATI_RET | | |
46 | STATE : code ROUTINE : psa_search_SATSrcId| | |
47 +--------------------------------------------------------------------+ | |
48 | |
49 PURPOSE : search SAT Source Id | |
50 */ | |
51 | |
52 /* CLB: can't be returning a UBYTE... Otherwise search_SATSrcId is | |
53 ALWAYS positive: -1 is 0xFF */ | |
54 #ifdef FF_SAT_E | |
55 GLOBAL T_ACI_CMD_SRC psa_search_SATSrcId (void) | |
56 { | |
57 T_ACI_CMD_SRC src_id; /* Current command source id. */ | |
58 | |
59 TRACE_FUNCTION("psa_search_SATSrcId ()"); | |
60 | |
61 #ifdef SIM_TOOLKIT | |
62 for (src_id = CMD_SRC_LCL; src_id < CMD_SRC_MAX; src_id++) | |
63 { | |
64 if (ati_is_src_type((UBYTE) src_id, ATI_SRC_TYPE_SAT)) | |
65 { | |
66 return src_id; | |
67 } | |
68 } | |
69 #endif /* SIM_TOOLKIT */ | |
70 | |
71 return(CMD_SRC_NONE); | |
72 } | |
73 #endif /* FF_SAT_E */ | |
74 /* | |
75 +--------------------------------------------------------------------+ | |
76 | PROJECT : GSM-PS (6147) MODULE : PSA_UTIL | | |
77 | STATE : code ROUTINE : utl_BCD2String | | |
78 +--------------------------------------------------------------------+ | |
79 | |
80 PURPOSE : Function for converting a buffer that contains unpacked | |
81 bcd digits of either MCC or MNC into a printable, | |
82 null terminated C-string. Note: The output buffer "bcd_string" | |
83 has to have at least the size len + 1, as the "len" is the | |
84 length of the input "bcd" digits and the terminating '\0' | |
85 also has to be stored. | |
86 | |
87 */ | |
88 | |
89 GLOBAL void utl_BCD2String (char *bcd_string, const UBYTE *bcd, USHORT len) | |
90 { | |
91 SHORT idx; | |
92 | |
93 for (idx = 0; idx < len; idx++) | |
94 { | |
95 if (bcd[idx] <= 9) | |
96 { | |
97 bcd_string[idx] = bcd[idx] + '0'; | |
98 } | |
99 else | |
100 { | |
101 bcd_string[idx] = '\0'; | |
102 return; | |
103 } | |
104 } | |
105 bcd_string[len] = '\0'; | |
106 } | |
107 | |
108 /* | |
109 +--------------------------------------------------------------------+ | |
110 | PROJECT : GSM-PS (6147) MODULE : PSA_UTIL | | |
111 | STATE : code ROUTINE : utl_dialStr2BCD | | |
112 +--------------------------------------------------------------------+ | |
113 | |
114 PURPOSE : Function that cleans all characters in a dialnumber | |
115 that are not in 0-9,a,b,c,#,*. and converts the valid | |
116 characters into a BCD number. the function returns the | |
117 number of BCD digits that are converted. If pBCDBuf is | |
118 NULL, only the length of the resulting BCD number is evaluated. | |
119 | |
120 */ | |
121 | |
122 GLOBAL USHORT utl_dialStr2BCD (const char *pDialStr, UBYTE *pBCDBuf, | |
123 UBYTE maxDigits) | |
124 { | |
125 USHORT numBcdDigits = 0, strIdx; | |
126 UBYTE c; | |
127 | |
128 for(strIdx = 0; numBcdDigits < maxDigits AND pDialStr[strIdx] NEQ '\0'; strIdx++) | |
129 { | |
130 c = 0xFF; | |
131 switch (pDialStr[strIdx]) | |
132 { | |
133 case '0': | |
134 case '1': | |
135 case '2': | |
136 case '3': | |
137 case '4': | |
138 case '5': | |
139 case '6': | |
140 case '7': | |
141 case '8': | |
142 case '9': | |
143 c = pDialStr[strIdx]-'0'; | |
144 break; | |
145 | |
146 case '*': | |
147 c = 0x0a; | |
148 break; | |
149 | |
150 case '#': | |
151 c = 0x0b; | |
152 break; | |
153 | |
154 case 'A': | |
155 c = 0x0c; | |
156 break; | |
157 | |
158 case 'B': | |
159 c = 0x0d; | |
160 break; | |
161 | |
162 case 'C': | |
163 c = 0x0e; | |
164 break; | |
165 | |
166 default: /* Ignore non-matching characters */ | |
167 break; | |
168 } | |
169 if (c NEQ 0xFF) | |
170 { | |
171 if (pBCDBuf NEQ NULL) | |
172 pBCDBuf[numBcdDigits] = c; | |
173 numBcdDigits++; | |
174 } | |
175 } | |
176 | |
177 return numBcdDigits; | |
178 } | |
179 | |
180 /* | |
181 +--------------------------------------------------------------------+ | |
182 | PROJECT : GSM-PS (6147) MODULE : PSA_UTIL | | |
183 | STATE : code ROUTINE : utl_BCD2DialStr | | |
184 +--------------------------------------------------------------------+ | |
185 | |
186 PURPOSE : converts a BCD number into a string of ascii digits | |
187 | |
188 */ | |
189 | |
190 GLOBAL void utl_BCD2DialStr (const UBYTE *pBCD, char *pDSBuf, UBYTE numDigits) | |
191 { | |
192 | |
193 for( ;numDigits > 0; numDigits--, pBCD++ ) | |
194 { | |
195 switch( *pBCD ) | |
196 { | |
197 case( 0x00 ): | |
198 case( 0x01 ): | |
199 case( 0x02 ): | |
200 case( 0x03 ): | |
201 case( 0x04 ): | |
202 case( 0x05 ): | |
203 case( 0x06 ): | |
204 case( 0x07 ): | |
205 case( 0x08 ): | |
206 case( 0x09 ): | |
207 | |
208 *pDSBuf++ = *pBCD + '0'; | |
209 break; | |
210 | |
211 case( 0x0a ): | |
212 *pDSBuf++ = '*'; | |
213 break; | |
214 | |
215 case( 0x0b ): | |
216 *pDSBuf++ = '#'; | |
217 break; | |
218 | |
219 case( 0x0c ): | |
220 *pDSBuf++ = 'A'; | |
221 break; | |
222 | |
223 case( 0x0d ): | |
224 *pDSBuf++ = 'B'; | |
225 break; | |
226 | |
227 case( 0x0e ): | |
228 *pDSBuf++ = 'C'; | |
229 break; | |
230 } | |
231 } | |
232 | |
233 *pDSBuf = 0x0; | |
234 } | |
235 | |
236 /* | |
237 +-------------------------------------------------------------------+ | |
238 | PROJECT : GSM-PS (6147) MODULE : PSA_UTIL | | |
239 | STATE : code ROUTINE : utl_cvt7To8 | | |
240 +-------------------------------------------------------------------+ | |
241 | |
242 PURPOSE : This function converts from the 7 bit default alphabet | |
243 for SMS point-to-point messages to 8 bit alphabet. | |
244 The function returns the length in bytes of the converted | |
245 destination string. | |
246 | |
247 Note: This function is copied from entity SMS, file | |
248 sms_tlf.c | |
249 */ | |
250 | |
251 /* PATCH add a parameter to tell the function to begin to expand | |
252 to 8 bits from a specific bit offset inside the first byte | |
253 (needed to handle correctly TP-UD headers in SMS) */ | |
254 GLOBAL UBYTE utl_cvt7To8 (const UBYTE* source, | |
255 UBYTE source_len, | |
256 UBYTE* dest, | |
257 UBYTE bit_offset) /* indicates which bit of the first byte is the boundary of the 7bits source | |
258 ex: for bit_offset = 3, bits 0-2 (low weight bits) will not be decoded*/ | |
259 { | |
260 UBYTE d_mask = 0x01; | |
261 UBYTE s_mask; | |
262 UBYTE icnt; | |
263 UBYTE ocnt; | |
264 | |
265 *dest = 0x00; | |
266 icnt = source_len; | |
267 | |
268 if( !icnt ) return( 0 ); | |
269 ocnt = 0; | |
270 | |
271 while (icnt) | |
272 { | |
273 s_mask = 0x01; | |
274 | |
275 /* PATCH */ | |
276 if (icnt == source_len) | |
277 s_mask <<= bit_offset; | |
278 /* PATCH end */ | |
279 | |
280 while (s_mask > 0x00) | |
281 { | |
282 if (s_mask & *source) | |
283 *dest |= d_mask; | |
284 | |
285 s_mask <<= 1; | |
286 d_mask <<= 1; | |
287 | |
288 if (d_mask > 0x40) | |
289 { | |
290 dest++; | |
291 ocnt++; | |
292 d_mask = 0x01; | |
293 *dest = 0x00; | |
294 } | |
295 } | |
296 | |
297 source++; | |
298 icnt--; | |
299 } | |
300 | |
301 return( ocnt ); | |
302 } | |
303 | |
304 | |
305 /* | |
306 +-------------------------------------------------------------------+ | |
307 | PROJECT : GSM-PS (6147) MODULE : PSA_UTIL | | |
308 | STATE : code ROUTINE : utl_cvtPnn7To8 | | |
309 +-------------------------------------------------------------------+ | |
310 | |
311 PURPOSE : This function converts from the 7 bit default alphabet | |
312 for PNN Operator names to 8 bit alphabet. | |
313 The function returns the length in bytes of the converted | |
314 destination string. | |
315 */ | |
316 | |
317 GLOBAL UBYTE utl_cvtPnn7To8 (const UBYTE* source, UBYTE source_len, UBYTE dcs, UBYTE* dest ) | |
318 { | |
319 return utl_cvt7To8 (source, | |
320 (UBYTE)(MINIMUM (MAX_ALPHA_OPER_LEN,(source_len*8-(dcs&0x07)+6)/7) ), | |
321 dest, | |
322 0); | |
323 } | |
324 | |
325 /* | |
326 +-------------------------------------------------------------------+ | |
327 | PROJECT : GSM-PS (6147) MODULE : PSA_UTIL | | |
328 | STATE : code ROUTINE : utl_cvt8To7 | | |
329 +-------------------------------------------------------------------+ | |
330 | |
331 PURPOSE : This function converts from the 8 bit default alphabet | |
332 for SMS point-to-point messages to 7 bit alphabet. | |
333 The function returns the length in bytes of the converted | |
334 destination string. | |
335 | |
336 Note: This function is copied from entity SMS, file | |
337 sms_tlf.c | |
338 */ | |
339 GLOBAL UBYTE utl_cvt8To7 ( UBYTE* source, | |
340 UBYTE source_len, | |
341 UBYTE* dest, | |
342 UBYTE bit_offset) | |
343 { | |
344 UBYTE d_mask = 0x01; | |
345 UBYTE s_mask; | |
346 UBYTE icnt; | |
347 UBYTE ocnt; | |
348 | |
349 *dest = 0x00; | |
350 icnt = source_len; | |
351 | |
352 if( !icnt ) return( 0 ); | |
353 ocnt = 1; | |
354 | |
355 /* PATCH */ | |
356 if (icnt == source_len) | |
357 d_mask <<= bit_offset; | |
358 /* PATCH end */ | |
359 | |
360 while (icnt) | |
361 { | |
362 s_mask = 0x01; | |
363 | |
364 while (s_mask <= 0x40) | |
365 { | |
366 if (s_mask & *source) | |
367 *dest |= d_mask; | |
368 | |
369 s_mask <<= 1; | |
370 d_mask <<= 1; | |
371 | |
372 if (d_mask EQ 0x00) | |
373 { | |
374 dest++; | |
375 | |
376 /* don't increment ocnt if the new octet will not be used */ | |
377 if ((s_mask < 0x80) OR (icnt NEQ 1)) | |
378 ocnt++; | |
379 | |
380 d_mask = 0x01; | |
381 *dest = 0x00; | |
382 } | |
383 } | |
384 | |
385 source++; | |
386 icnt--; | |
387 } | |
388 | |
389 return( ocnt ); | |
390 } | |
391 | |
392 /* Implements Measure 25 */ | |
393 | |
394 /*==== EOF ========================================================*/ |