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