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