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