FreeCalypso > hg > freecalypso-citrine
comparison g23m-aci/ksd/ksd_utl.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-F&D (8411) | |
4 | Modul : KSD_UTL | |
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 defines utility functions for the KSD | |
18 | component of the protocol stack. | |
19 +----------------------------------------------------------------------------- | |
20 */ | |
21 | |
22 #ifndef KSD_UTL_C | |
23 #define KSD_UTL_C | |
24 #endif | |
25 | |
26 #include "config.h" | |
27 #include "fixedconf.h" | |
28 #include "condat-features.h" | |
29 #include "aci_conf.h" | |
30 | |
31 #include "aci_all.h" | |
32 /*==== INCLUDES ===================================================*/ | |
33 | |
34 /*==== CONSTANTS ==================================================*/ | |
35 | |
36 #define SUBADDR_DELIMITER '-' /* used to separate the subaddress */ | |
37 /* from the main address */ | |
38 #define NULL_TERM '\0' /* string termination */ | |
39 | |
40 /*==== TYPES ======================================================*/ | |
41 | |
42 /*==== EXPORT =====================================================*/ | |
43 | |
44 /*==== VARIABLES ==================================================*/ | |
45 | |
46 /*==== FUNCTIONS ==================================================*/ | |
47 /* | |
48 +--------------------------------------------------------------------+ | |
49 | PROJECT : GSM-PS (6147) MODULE : KSD_UTL | | |
50 | STATE : code ROUTINE : utl_cutInternational | | |
51 +--------------------------------------------------------------------+ | |
52 | |
53 PURPOSE : This function cuts all characters which signals that the | |
54 dial number is international (leading '+' or leading | |
55 '00'). | |
56 | |
57 <dial>: the origin dial number | |
58 <cuttedDial>: the dial number without leading '+' or '00' | |
59 | |
60 returns: TRUE if the dial number was of the type | |
61 international, otherwise FALSE. | |
62 */ | |
63 LOCAL BOOL utl_cutInternational (CHAR* dial, CHAR** cuttedDial) | |
64 { | |
65 BOOL international = FALSE; /* holds whether number is */ | |
66 /* international */ | |
67 | |
68 if (dial[0] EQ '+') | |
69 { | |
70 international = TRUE; | |
71 *cuttedDial = dial + 1; | |
72 } | |
73 /* | |
74 * 00 is not an indication for an international call | |
75 else if (dial[0] EQ '0' AND dial[1] EQ '0') | |
76 { | |
77 international = TRUE; | |
78 *cuttedDial = dial + 2; | |
79 } | |
80 */ | |
81 else | |
82 *cuttedDial = dial; | |
83 | |
84 return international; | |
85 } | |
86 | |
87 /* | |
88 +--------------------------------------------------------------------+ | |
89 | PROJECT : GSM-PS (6147) MODULE : KSD_UTL | | |
90 | STATE : code ROUTINE : utl_getValidDialchars | | |
91 +--------------------------------------------------------------------+ | |
92 | |
93 PURPOSE : This function returns the number of valid dial characters | |
94 in the buffer. This function is only used to process | |
95 the subaddress part. | |
96 | |
97 <dial>: the dial number (subaddress) | |
98 | |
99 returns: the number of valid dial characters. | |
100 */ | |
101 LOCAL USHORT utl_getValidDialchars (CHAR* dial) | |
102 { | |
103 USHORT numChars = 0; /* holds number of valid dial characters */ | |
104 USHORT i = 0; /* used for counting */ | |
105 | |
106 while (dial[i] NEQ NULL_TERM) | |
107 { | |
108 if ((dial[i] >= '0' AND dial[i] <= '9') OR | |
109 (dial[i] >= 'A' AND dial[i] <= 'C') OR | |
110 (dial[i] >= 'a' AND dial[i] <= 'c') OR | |
111 dial[i] EQ '*' OR | |
112 dial[i] EQ '#' ) | |
113 numChars++; | |
114 | |
115 i++; | |
116 } | |
117 | |
118 return numChars; | |
119 } | |
120 | |
121 /* | |
122 +--------------------------------------------------------------------+ | |
123 | PROJECT : GSM-PS (6147) MODULE : KSD_UTL | | |
124 | STATE : code ROUTINE : utl_splitDialnumber | | |
125 +--------------------------------------------------------------------+ | |
126 | |
127 PURPOSE : This function splits a dial string into address and | |
128 subaddress and delivers additional information about | |
129 the specific types of addresses. | |
130 | |
131 <dial>: the origin dial number | |
132 <main>: the main address of the dial number; | |
133 if it was international, leading '+' | |
134 or '00' are cutted | |
135 <international>: TRUE if the dial number is international, | |
136 otherwise FALSE | |
137 <sub>: the sub address of the dial number or | |
138 NULL if there is none | |
139 <numCharsSub>: the number of valid dial characters of | |
140 the sub address | |
141 */ | |
142 GLOBAL void utl_splitDialnumber (CHAR* dial, | |
143 CHAR** main, | |
144 BOOL* international, | |
145 CHAR** sub, | |
146 USHORT* numCharsSub) | |
147 { | |
148 CHAR* token; /* points to dial number */ | |
149 | |
150 if (dial NEQ NULL) | |
151 { | |
152 token = strchr (dial, SUBADDR_DELIMITER); | |
153 | |
154 if (token NEQ NULL) | |
155 { | |
156 *token = NULL_TERM; | |
157 *sub = ++token; | |
158 *numCharsSub = utl_getValidDialchars (token); | |
159 } | |
160 else | |
161 { | |
162 *sub = NULL; | |
163 *numCharsSub = 0; | |
164 } | |
165 | |
166 *international = utl_cutInternational (dial, main); | |
167 } | |
168 else | |
169 { | |
170 *main = NULL; | |
171 *international = FALSE; | |
172 *sub = NULL; | |
173 *numCharsSub = 0; | |
174 } | |
175 } | |
176 | |
177 /* | |
178 +--------------------------------------------------------------------+ | |
179 | PROJECT : GSM-PS (6147) MODULE : KSD_UTL | | |
180 | STATE : code ROUTINE : utl_string2UByte | | |
181 +--------------------------------------------------------------------+ | |
182 | |
183 PURPOSE : This function converts characters from a buffer to an | |
184 unsigned byte value. | |
185 | |
186 <inUByte>: buffer containing the characters forming | |
187 the unsigned byte value | |
188 <inLen>: number of characters to be taken into account | |
189 <outValue>: the converted value | |
190 | |
191 returns: TRUE if the conversion was successful, | |
192 otherwise FALSE. | |
193 */ | |
194 GLOBAL BOOL utl_string2UByte (CHAR* inUByte, | |
195 USHORT inLen, | |
196 UBYTE* outValue) | |
197 { | |
198 UBYTE result = 0; /* holds the result value of conversion */ | |
199 | |
200 if (inLen EQ 0) | |
201 return TRUE; | |
202 | |
203 while (inLen--) | |
204 { | |
205 result *= 10; | |
206 if (*inUByte >= '0' AND *inUByte <= '9') | |
207 result += *inUByte++ - '0'; | |
208 else | |
209 return FALSE; | |
210 } | |
211 | |
212 *outValue = result; | |
213 return TRUE; | |
214 } | |
215 | |
216 /* | |
217 +--------------------------------------------------------------------+ | |
218 | PROJECT : GSM-PS (6147) MODULE : KSD_UTL | | |
219 | STATE : code ROUTINE : utl_string2Byte | | |
220 +--------------------------------------------------------------------+ | |
221 | |
222 PURPOSE : This function converts characters from a buffer to a | |
223 signed byte value. | |
224 | |
225 <inByte>: buffer containing the characters forming | |
226 the signed byte value | |
227 <inLen>: number of characters to be taken into account | |
228 <outValue>: the converted value | |
229 | |
230 returns: TRUE if the conversion was successful, | |
231 otherwise FALSE. | |
232 */ | |
233 GLOBAL BOOL utl_string2Byte (CHAR* inByte, | |
234 USHORT inLen, | |
235 BYTE* outValue) | |
236 { | |
237 BYTE result = 0; /* holds the result value of conversion */ | |
238 | |
239 if (inLen EQ 0) | |
240 return TRUE; | |
241 | |
242 while (inLen--) | |
243 { | |
244 result *= 10; | |
245 if (*inByte >= '0' AND *inByte <= '9') | |
246 result += *inByte++ - '0'; | |
247 else | |
248 return FALSE; | |
249 } | |
250 | |
251 *outValue = result; | |
252 return TRUE; | |
253 } | |
254 | |
255 /* | |
256 +--------------------------------------------------------------------+ | |
257 | PROJECT : GSM-PS (6147) MODULE : KSD_UTL | | |
258 | STATE : code ROUTINE : utl_string2Short | | |
259 +--------------------------------------------------------------------+ | |
260 | |
261 PURPOSE : This function converts characters from a buffer to an | |
262 short value. | |
263 | |
264 <inShort>: buffer containing the characters forming | |
265 the short value | |
266 <inLen>: number of characters to be taken into account | |
267 <outValue>: the converted value | |
268 | |
269 returns: TRUE if the conversion was successful, | |
270 otherwise FALSE. | |
271 */ | |
272 GLOBAL BOOL utl_string2Short (CHAR* inShort, | |
273 USHORT inLen, | |
274 SHORT* outValue) | |
275 { | |
276 SHORT result = 0; /* holds the result value of conversion */ | |
277 | |
278 if (inLen EQ 0) | |
279 return TRUE; | |
280 | |
281 while (inLen--) | |
282 { | |
283 result *= 10; | |
284 if (*inShort >= '0' AND *inShort <= '9') | |
285 result += *inShort++ - '0'; | |
286 else | |
287 return FALSE; | |
288 } | |
289 | |
290 *outValue = result; | |
291 return TRUE; | |
292 } | |
293 | |
294 /* | |
295 +--------------------------------------------------------------------+ | |
296 | PROJECT : GSM-PS (6147) MODULE : KSD_UTL | | |
297 | STATE : code ROUTINE : utl_string2Long | | |
298 +--------------------------------------------------------------------+ | |
299 | |
300 PURPOSE : This function converts characters from a buffer to an | |
301 long value. | |
302 | |
303 <inLong>: buffer containing the characters forming | |
304 the short value | |
305 <inLen>: number of characters to be taken into account | |
306 <outValue>: the converted value | |
307 | |
308 returns: TRUE if the conversion was successful, | |
309 otherwise FALSE. | |
310 */ | |
311 GLOBAL BOOL utl_string2Long (CHAR* inLong, | |
312 USHORT inLen, | |
313 LONG* outValue) | |
314 { | |
315 LONG result = 0; /* holds the result value of conversion */ | |
316 | |
317 if (inLen EQ 0) | |
318 return TRUE; | |
319 | |
320 while (inLen--) | |
321 { | |
322 result *= 10; | |
323 if (*inLong >= '0' AND *inLong <= '9') | |
324 result += *inLong++ - '0'; | |
325 else | |
326 return FALSE; | |
327 } | |
328 | |
329 *outValue = result; | |
330 return TRUE; | |
331 } |