comparison g23m/condat/ms/src/aci/aci_util.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-PS (6147)
4 | Modul : ACI_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 defines the utility functions for the AT
18 | command interpreter.
19 +-----------------------------------------------------------------------------
20 */
21
22
23
24 #ifndef ACI_UTIL_C
25 #define ACI_UTIL_C
26 #endif
27
28 #include "aci_all.h"
29
30 #include "aci_cmh.h"
31 #include "ati_cmd.h"
32
33 #include "aci_cmd.h"
34
35 #ifdef FAX_AND_DATA
36 #include "aci_fd.h"
37 #endif /* of #ifdef FAX_AND_DATA */
38
39 #include "psa.h"
40 #include "psa_sms.h"
41 #include "phb.h"
42 #include "cmh.h"
43 #include "cmh_sms.h"
44
45 #if defined (FF_ATI) || defined (FF_BAT)
46 #include "aci_mem.h"
47 #include "aci_lst.h"
48 #include "aci_io.h"
49 #include "ksd.h"
50 #include "cmh_ss.h"
51 #include "psa_ss.h"
52 #endif
53 #ifdef FF_ATI
54 #include "ati_int.h"
55 #endif
56 #ifdef FF_BAT
57 #include "aci_bat_cb.h"
58 #endif
59
60
61
62 #ifdef GPRS
63 #include "gaci_cmh.h"
64 #endif /* GPRS */
65
66 /*==== CONSTANTS ==================================================*/
67
68 #define CSCS_CHSET_Chars 256
69
70 /*==== TYPES ======================================================*/
71
72 /*==== EXPORT =====================================================*/
73 /* This fucntion cuts the pathname from the file
74 used by ACI_ASSERT makro*/
75 GLOBAL char * getFileName(char * file)
76 {
77 char *cursor = file;
78 do {
79 #ifdef _SIMULATION_
80 if(*cursor EQ '\\') { file = cursor+1;}
81 #else
82 if(*cursor EQ '/') { file = cursor+1;}
83 #endif
84 cursor++;
85 } while(*cursor NEQ '\0');
86 return file;
87 }
88
89
90 LOCAL USHORT utl_ucs2FromGsm ( UBYTE* in,
91 USHORT inLen,
92 UBYTE* out,
93 USHORT maxOutLen,
94 USHORT* outLen,
95 T_ACI_GSM_ALPHA gsm,
96 T_ACI_CSCS_ALPHA alphabet );
97
98 /*==== VARIABLES ==================================================*/
99
100 GLOBAL const UBYTE chset [CSCS_CHSET_Tables][CSCS_CHSET_Chars] =
101 {
102 /*
103 *-------------------------------------------------------------------
104 * Conversion table: IRA -> internal GSM
105 *-------------------------------------------------------------------
106 */
107 /* 0x00 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108 /* 0x08 */ 0x00, 0x00, 0x8A, 0x00, 0x00, 0x8D, 0x00, 0x00,
109 /* 0x10 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
110 /* 0x18 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
111 /* 0x20 */ 0xA0, 0xA1, 0xA2, 0xA3, 0x82, 0xA5, 0xA6, 0xA7,
112 /* 0x28 */ 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
113 /* 0x30 */ 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
114 /* 0x38 */ 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
115 /* 0x40 */ 0x80, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
116 /* 0x48 */ 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
117 /* 0x50 */ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
118 /* 0x58 */ 0xD8, 0xD9, 0xDA, 0x00, 0x00, 0x00, 0x00, 0x91/*00*/,
119 /* 0x60 */ 0x00, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
120 /* 0x68 */ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
121 /* 0x70 */ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
122 /* 0x78 */ 0xF8, 0xF9, 0xFA, 0x00, 0x00, 0x00, 0x00, 0x00,
123 /* 0x80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124 /* 0x88 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125 /* 0x90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126 /* 0x98 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
127 /* 0xA0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128 /* 0xA8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
129 /* 0xB0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130 /* 0xB8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131 /* 0xC0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 /* 0xC8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 /* 0xD0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 /* 0xD8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
135 /* 0xE0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136 /* 0xE8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137 /* 0xF0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138 /* 0xF8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
139
140 /*
141 *-------------------------------------------------------------------
142 * Conversion table: PC Danish/Norwegian -> internal GSM
143 *-------------------------------------------------------------------
144 */
145 /* 0x00 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
146 /* 0x08 */ 0x00, 0x00, 0x8A, 0x00, 0x00, 0x8D, 0x00, 0x00,
147 /* 0x10 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF, 0x00, 0x00,
148 /* 0x18 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
149 /* 0x20 */ 0xA0, 0xA1, 0xA2, 0xA3, 0x82, 0xA5, 0xA6, 0xA7,
150 /* 0x28 */ 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
151 /* 0x30 */ 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
152 /* 0x38 */ 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
153 /* 0x40 */ 0x80, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
154 /* 0x48 */ 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
155 /* 0x50 */ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
156 /* 0x58 */ 0xD8, 0xD9, 0xDA, 0x00, 0x00, 0x00, 0x00, 0x91/*00*/,
157 /* 0x60 */ 0x00, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
158 /* 0x68 */ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
159 /* 0x70 */ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
160 /* 0x78 */ 0xF8, 0xF9, 0xFA, 0x00, 0x00, 0x00, 0x00, 0x00,
161 /* 0x80 */ 0x89, 0xFE, 0x85, 0xE1, 0xFB, 0xFF, 0x8F, 0x89,
162 /* 0x88 */ 0xE5, 0xE5, 0x84, 0xE9, 0xE9, 0x87, 0xDB, 0x8E,
163 /* 0x90 */ 0x9F/*C5*/, 0x9D, 0x9C, 0xEF, 0xFC, 0x88, 0xF5/*E5*/, 0x86,
164 /* 0x98 */ 0xF9/*E9*/, 0xDC, 0xDE, 0x8C, 0x81, 0x8B, 0x00, 0x00,
165 /* 0xA0 */ 0xE1, 0xE9, 0xEF, 0xF5, 0xFD, 0xDD, 0x00, 0x00,
166 /* 0xA8 */ 0xE0, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00,
167 /* 0xB0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
168 /* 0xB8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
169 /* 0xC0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
170 /* 0xC8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
171 /* 0xD0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
172 /* 0xD8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173 /* 0xE0 */ 0x00, 0x9E, 0x93, 0x00, 0x98, 0x00, 0x00, 0x00,
174 /* 0xE8 */ 0x92, 0x99, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00,
175 /* 0xF0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176 /* 0xF8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
177
178 /*
179 *-------------------------------------------------------------------
180 * Conversion table: ISO 8859 Latin 1 -> internal GSM
181 *-------------------------------------------------------------------
182 */
183 /* 0x00 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
184 /* 0x08 */ 0x00, 0x00, 0x8A, 0x00, 0x00, 0x8D, 0x00, 0x00,
185 /* 0x10 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186 /* 0x18 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
187 /* 0x20 */ 0xA0, 0xA1, 0xA2, 0xA3, 0x82, 0xA5, 0xA6, 0xA7,
188 /* 0x28 */ 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
189 /* 0x30 */ 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
190 /* 0x38 */ 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
191 /* 0x40 */ 0x80, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
192 /* 0x48 */ 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
193 /* 0x50 */ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
194 /* 0x58 */ 0xD8, 0xD9, 0xDA, 0x00, 0x00, 0x00, 0x00, 0x91/*00*/,
195 /* 0x60 */ 0x00, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
196 /* 0x68 */ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
197 /* 0x70 */ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
198 /* 0x78 */ 0xF8, 0xF9, 0xFA, 0x00, 0x00, 0x00, 0x00, 0x00,
199 /* 0x80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
200 /* 0x88 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201 /* 0x90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
202 /* 0x98 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
203 /* 0xA0 */ 0x00, 0xC0, 0x00, 0x81, 0xA4, 0x83, 0x00, 0xDF,
204 /* 0xA8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
205 /* 0xB0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
206 /* 0xB8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0,
207 /* 0xC0 */ 0xC1, 0xC1, 0xC1, 0xC1, 0xDB, 0x8E, 0x9C, 0x89,
208 /* 0xC8 */ 0xC5, 0x9F/*C5*/, 0xC5, 0xC5, 0xC9, 0xC9, 0xC9, 0xC9,
209 /* 0xD0 */ 0x00, 0xDD, 0xCF, 0xCF, 0xCF, 0xCF, 0xDC, 0x00,
210 /* 0xD8 */ 0x8B, 0xD5, 0xD5, 0xD5, 0xDE, 0xD9, 0x00, 0x9E,
211 /* 0xE0 */ 0xFF, 0xE1, 0xE1, 0xE1, 0xFB, 0x8F, 0x9D, 0x89,
212 /* 0xE8 */ 0x84, 0x85, 0xE5, 0xE5, 0x87, 0xE9, 0xE9, 0xE9,
213 /* 0xF0 */ 0x00, 0xFD, 0x88, 0xEF, 0xEF, 0xEF, 0xFC, 0x00,
214 /* 0xF8 */ 0x8C, 0x86, 0xF5, 0xF5, 0xFE, 0xF9, 0x00, 0xF9 },
215
216 /*
217 *-------------------------------------------------------------------
218 * Conversion table: PC Code Page 437 -> internal GSM
219 *-------------------------------------------------------------------
220 */
221 /* 0x00 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
222 /* 0x08 */ 0x00, 0x00, 0x8A, 0x00, 0x00, 0x8D, 0x00, 0x00,
223 /* 0x10 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF, 0x00, 0x00,
224 /* 0x18 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225 /* 0x20 */ 0xA0, 0xA1, 0xA2, 0xA3, 0x82, 0xA5, 0xA6, 0xA7,
226 /* 0x28 */ 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
227 /* 0x30 */ 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
228 /* 0x38 */ 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
229 /* 0x40 */ 0x80, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
230 /* 0x48 */ 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
231 /* 0x50 */ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
232 /* 0x58 */ 0xD8, 0xD9, 0xDA, 0x00, 0x00, 0x00, 0x00, 0x91/*00*/,
233 /* 0x60 */ 0x00, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
234 /* 0x68 */ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
235 /* 0x70 */ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
236 /* 0x78 */ 0xF8, 0xF9, 0xFA, 0x00, 0x00, 0x00, 0x00, 0x00,
237 /* 0x80 */ 0x89, 0xFE, 0x85, 0xE1, 0xFB, 0xFF, 0x8F, 0x89,
238 /* 0x88 */ 0xE5, 0xE5, 0x84, 0xE9, 0xE9, 0x87, 0xDB, 0x8E,
239 /* 0x90 */ 0x9F/*C5*/, 0x9D, 0x9C, 0xEF, 0xFC, 0x88, 0xF5/*E5*/, 0x86,
240 /* 0x98 */ 0xF9/*E9*/, 0xDC, 0xDE, 0x00, 0x81, 0x83, 0x00, 0x00,
241 /* 0xA0 */ 0xE1, 0xE9, 0xEF, 0xF5, 0xFD, 0xDD, 0x00, 0x00,
242 /* 0xA8 */ 0xE0, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00,
243 /* 0xB0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 /* 0xB8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245 /* 0xC0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246 /* 0xC8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 /* 0xD0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248 /* 0xD8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
249 /* 0xE0 */ 0x00, 0x9E, 0x93, 0x00, 0x98, 0x00, 0x00, 0x00,
250 /* 0xE8 */ 0x92, 0x99, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00,
251 /* 0xF0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 /* 0xF8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
253
254 /*
255 *-------------------------------------------------------------------
256 * Conversion table: GSM -> internal GSM
257 *-------------------------------------------------------------------
258 */
259 /* 0x00 */ { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
260 /* 0x08 */ 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
261 /* 0x10 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
262 /* 0x18 */ 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
263 /* 0x20 */ 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
264 /* 0x28 */ 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
265 /* 0x30 */ 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
266 /* 0x38 */ 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
267 /* 0x40 */ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
268 /* 0x48 */ 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
269 /* 0x50 */ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
270 /* 0x58 */ 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
271 /* 0x60 */ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
272 /* 0x68 */ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
273 /* 0x70 */ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
274 /* 0x78 */ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
275 /* 0x80 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276 /* 0x88 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
277 /* 0x90 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278 /* 0x98 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279 /* 0xA0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280 /* 0xA8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
281 /* 0xB0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
282 /* 0xB8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283 /* 0xC0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
284 /* 0xC8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285 /* 0xD0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286 /* 0xD8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287 /* 0xE0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288 /* 0xE8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
289 /* 0xF0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 /* 0xF8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
291 };
292
293
294 /*
295 *-------------------------------------------------------------------
296 * Conversion table: ASCII <-> internal GSM
297 * ( needed for the conversion of UCS2 <-> internal GSM )
298 *-------------------------------------------------------------------
299 */
300 /* GSM alphabet characters unknown in the ASCII table have been
301 replaced by <SP> characters */
302 LOCAL const UBYTE gsmToAsciiTable[128] =
303 {
304 /*n = 0 1 2 3 4 5 6 7 8 9 A B C D E F */
305 /* 0x0n */ 64,163, 36,165,232,233,249,236,242,199, 10,216,248, 13,197,229,
306 /* 0x1n */ 128, 95,129,130,131,132,133,134,135,136,137, 32,198,230,223,201,
307 /* 0x2n */ 32, 33, 34, 35,164, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
308 /* 0x3n */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
309 /* 0x4n */ 161, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
310 /* 0x5n */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,196,214,209,220,167,
311 /* 0x6n */ 191, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
312 /* 0x7n */ 112,113,114,115,116,117,118,119,120,121,122,228,246,241,252,224
313 };
314
315 LOCAL const UBYTE hexVal[] = {"0123456789ABCDEF"};
316
317 /*
318 static const unsigned char
319 gsm_2_ascii_table[128] =
320 {
321 0x40, 0x9C, 0x24, 0x9D, 0x8A, 0x82, 0x97, 0x8D, 0x95, 0x80, 0x0A, 0x02, 0x07, 0x0D, 0x8F, 0x86,
322 0x04, 0x5F, 0xE8, 0xE2, 0xEF, 0xEA, 0xE3, 0x05, 0xE6, 0xE9, 0xF0, 0x20, 0x92, 0x91, 0xE1, 0x90,
323 0x20, 0x21, 0x22, 0x23, 0x01, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
324 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
325 0xAD, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
326 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x8E, 0x99, 0xA5, 0x9A, 0x06,
327 0xA8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
328 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x84, 0x94, 0xA4, 0x81, 0x85
329 };
330 */
331
332 /*==== FUNCTIONS ==================================================*/
333 #ifdef FF_ATI
334 /*
335 +-------------------------------------------------------------------+
336 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
337 | STATE : code ROUTINE : strupper |
338 +-------------------------------------------------------------------+
339
340 PURPOSE : Converts all characters from 'a' to 'z' to capital
341 characters from 'A' to 'Z'.
342 */
343 GLOBAL char* strupper ( char* s )
344 {
345 USHORT i = 0;
346
347 while ( s NEQ 0 AND s[i] NEQ '\0')
348 {
349 if ( s[i] >= 0x61 AND s[i] <= 0x7a )
350
351 s[i] = s[i] - 0x20;
352
353 i++;
354 }
355
356 return s;
357 }
358 #endif
359
360 #ifdef FF_ATI
361 /*
362 +-------------------------------------------------------------------+
363 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
364 | STATE : code ROUTINE : utl_chsetToGsm |
365 +-------------------------------------------------------------------+
366
367 PURPOSE : This function converts the characters of a string from
368 the character set used within the AT command interpreter
369 to the SIM GSM character set.
370 */
371 GLOBAL void utl_chsetToSim ( UBYTE* in,
372 USHORT inLen,
373 UBYTE* out,
374 USHORT* outLen,
375 T_ACI_GSM_ALPHA gsm )
376 {
377 UBYTE cvtdVal;
378 USHORT outIdx = 0;
379 USHORT inIdx;
380 UBYTE corr = ( gsm EQ GSM_ALPHA_Int ? 0xFF : 0x7F );
381 T_ACI_CSCS_CHSET cscsChset;
382 UBYTE srcId = srcId_cb;
383
384 cscsChset = ati_user_output_cfg[srcId].cscsChset;
385
386 if ( cscsChset EQ CSCS_CHSET_Hex )
387 {
388 utl_hexToGsm ( in, inLen, out, outLen, gsm, CSCS_ALPHA_8_Bit );
389 }
390 else if ( cscsChset EQ CSCS_CHSET_Ucs2 )
391 {
392 /* If the user chooses UCS2, then the best mode of coding should be
393 * used to store the characters in the SIM */
394 utl_ucs2ToSim(in, inLen, out, outLen, gsm, CSCS_ALPHA_8_Bit);
395 }
396 else
397 {
398 for ( inIdx = 0; inIdx < inLen; inIdx++ )
399 {
400 cvtdVal = chset[cscsChset][( UBYTE ) in[inIdx]];
401
402 if ( cvtdVal NEQ 0x00 )
403 {
404 out[outIdx] = ( CHAR ) cvtdVal & corr;
405 outIdx++;
406 }
407 }
408
409 if ( gsm EQ GSM_ALPHA_Int )
410 out[outIdx] = '\0';
411
412 *outLen = outIdx;
413 }
414 }
415 #endif
416
417 #ifdef FF_ATI
418 /*
419 +-------------------------------------------------------------------+
420 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
421 | STATE : code ROUTINE : utl_codeUcs2 |
422 +-------------------------------------------------------------------+
423
424 PURPOSE : This function finds optimal coding format to store the
425 UCS2 character string in the phone book.
426 */
427 GLOBAL void utl_ucs2ToSim( UBYTE* in,
428 USHORT inLen,
429 UBYTE* out,
430 USHORT* outLen,
431 T_ACI_GSM_ALPHA gsm,
432 T_ACI_CSCS_ALPHA alphabet)
433 {
434 int i;
435 BOOL flag = TRUE;
436 USHORT ucs2_len = inLen/4;
437 UBYTE hexOut[MAX_ALPHA_LEN * 4];
438 USHORT hexOutLen = 0;
439
440 /* Convert the hex character string to actual hex values */
441 hexOutLen = utl_HexStrToBin(in, inLen, hexOut, (MAX_ALPHA_LEN * 4));
442
443 /* Initial check is done for GSM or ASCII only characters */
444 for(i = 0; i < (hexOutLen/2); i++)
445 {
446 if(( hexOut[i*2] NEQ 0x00 ))
447 {
448 flag = FALSE;
449 break;
450 }
451 }
452 if (flag EQ TRUE)
453 {
454 utl_ConvUcs2ToGSM(hexOut, hexOutLen, out, outLen, gsm, alphabet);
455 if (*outLen)
456 return;
457 }
458
459 /* If possible UCS2 character string is coded in 0x81 format which
460 uses a one byte base pointer */
461 utl_Ucs2InFormat1 (hexOut, hexOutLen, out, outLen);
462 if (*outLen)
463 return;
464
465 /* If possible UCS2 character string is coded in 0x82 format which
466 uses two byte base pointer */
467 utl_Ucs2InFormat2 (hexOut, hexOutLen, out, outLen);
468 if (*outLen)
469 return;
470
471 /* If none of the above work, UCS2 character string is coded in 0x80 */
472 *out = 0x80;
473 utl_hexToGsm ( in, inLen, out + 1, outLen, gsm, CSCS_ALPHA_8_Bit );
474 (*outLen)++;
475 }
476 #endif
477
478 #ifdef FF_ATI
479 /*
480 +-------------------------------------------------------------------+
481 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
482 | STATE : code ROUTINE : utl_ConvUcs2ToGSM |
483 +-------------------------------------------------------------------+
484
485 PURPOSE : This function converts UCS2 charecter string consisting of
486 only ASCII charecters to default GSM values.
487 */
488 GLOBAL void utl_ConvUcs2ToGSM ( UBYTE* in,
489 USHORT inLen,
490 UBYTE* out,
491 USHORT* outLen,
492 T_ACI_GSM_ALPHA gsm,
493 T_ACI_CSCS_ALPHA alphabet )
494 {
495 int i, j;
496 BOOL flag;
497 UBYTE val = 0x00;
498 USHORT len;
499 UBYTE tmpOut;
500 USHORT outIdx = 0;
501
502 len = inLen/2;
503 for (i = 0;i < len; i++)
504 {
505 tmpOut = in[(i*2) + 1];
506 /* convert the hexadecimal ASCII value to GSM, if the value is
507 * not convertible then we exit */
508 if ( tmpOut EQ ( gsmToAsciiTable[tmpOut])) /* ASCII and GSM are identical */
509 {
510 val = tmpOut;
511 }
512 else /* find match in the table and copy index of match */
513 {
514 flag = FALSE;
515 for (j=0; j<128; j++)
516 {
517 if (tmpOut EQ gsmToAsciiTable[j])
518 {
519 val = (UBYTE)j;
520 flag = TRUE;
521 break;
522 }
523 }
524 if (!flag)
525 {
526 *outLen = 0;
527 return;
528 }
529 }
530
531 /* if necessary, cut the GSM value to 7bit */
532 if ( alphabet EQ CSCS_ALPHA_7_Bit AND !( val & 0x80 ) )
533 {
534 if ( gsm EQ GSM_ALPHA_Int )
535 {
536 out[outIdx++] = val | 0x80;
537 }
538 else
539 {
540 out[outIdx++] = val;
541 }
542 }
543 else
544 {
545 out[outIdx++] = val;
546 }
547 }
548
549 if ( gsm EQ GSM_ALPHA_Int )
550 {
551 out[outIdx] = '\0';
552 }
553
554 /* set the outlength */
555 *outLen = outIdx;
556 }
557 #endif
558
559 #ifdef FF_ATI
560 /*
561 +-------------------------------------------------------------------+
562 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
563 | STATE : code ROUTINE : utl_Ucs2InFormat1 |
564 +-------------------------------------------------------------------+
565
566 PURPOSE : This function converts the UCS2 character string in the
567 0x81 coding scheme for UCS2.
568 Octet 1: 0x81
569 Octet 2: Num of Characters
570 Octet 3: Bits 15 to 8 of Base pointer
571 Octet 4 onwards: Characters
572 */
573 GLOBAL void utl_Ucs2InFormat1( UBYTE* in,
574 USHORT inLen,
575 UBYTE* out,
576 USHORT* outLen)
577 {
578 int i, j;
579 UBYTE base_ptr = 0x00;
580 UBYTE temp_ptr;
581 USHORT len = inLen/2;
582 USHORT tmp_base;
583 USHORT tmp;
584 USHORT outIdx = 0;
585
586
587 /* We first check if the UCS2 string can be coded
588 * using a single base pointer */
589 for (i = 0; i < len; i++)
590 {
591 if (in[i*2])
592 {
593 if ((in[i*2] & 0x80))
594 {
595 *outLen = 0;
596 return;
597 }
598 temp_ptr = in[i*2] & 0x7f;
599 temp_ptr <<= 1;
600 temp_ptr |= ((in[(i*2)+1] & 0x80) >> 7);
601
602 if (base_ptr)
603 {
604 if (temp_ptr NEQ base_ptr)
605 {
606 *outLen = 0;
607 return;
608 }
609 } else
610 {
611 base_ptr = temp_ptr;
612 }
613 }
614 }
615
616
617 /* Characters are coded using the base pointer below */
618 /* For details, see GSM 11.11 Annex B (normative) */
619 out[0] = 0x81;
620 if (len < PHB_MAX_TAG_LEN - 3)
621 {
622 out[1] = (UBYTE)len;
623 } else
624 {
625 out[1] = PHB_MAX_TAG_LEN - 3;
626 }
627 out[2] = base_ptr;
628 tmp_base = 0;
629 tmp_base = base_ptr << 7;
630 outIdx = 3;
631
632 len = out[1];
633 for (i = 0; i < len; i++)
634 {
635 if (in[i*2])
636 {
637 tmp = 0;
638 tmp = in[i*2] << 8;
639 tmp |= in[(i*2)+1];
640 out[outIdx++] = (tmp - tmp_base) | 0x80;
641 } else
642 {
643 for (j=0; j<128; j++)
644 {
645 if (in[(i*2)+1] EQ gsmToAsciiTable[j])
646 {
647 out[outIdx++] = (UBYTE)j;
648 break;
649 }
650 }
651
652 /* If the charecter cannot be found in ASCII table exit */
653 if (j EQ 128)
654 {
655 *outLen = 0;
656 return ;
657 }
658
659 }
660 }
661
662 *outLen = outIdx;
663 }
664 #endif
665
666 #ifdef FF_ATI
667 /*
668 +-------------------------------------------------------------------+
669 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
670 | STATE : code ROUTINE : utl_Ucs2InFormat2 |
671 +-------------------------------------------------------------------+
672
673 PURPOSE : This function converts the UCS2 character string in the
674 0x82 coding scheme for UCS2.
675 Octet 1: 0x82
676 Octet 2: Number of characters
677 Octet 3 and Octet 4: 2 byte base pointer
678 Octet 5 onwards: Characters
679
680 */
681 GLOBAL void utl_Ucs2InFormat2( UBYTE* in,
682 USHORT inLen,
683 UBYTE* out,
684 USHORT* outLen)
685 {
686 int i, j;
687 USHORT len = inLen/2;
688 USHORT lowest_ch = 0;
689 USHORT highest_ch = 0;
690 USHORT tmp;
691 USHORT outIdx = 0;
692
693
694 /* We first check if the UCS2 string can be coded
695 * using a smallest char as the base pointer */
696 for (i = 0; i < len; i++)
697 {
698 if (in[i*2])
699 {
700 tmp = 0;
701 tmp = in[i*2] << 8;
702 tmp |= in[(i*2)+1];
703
704 if (lowest_ch EQ 0 OR tmp < lowest_ch)
705 lowest_ch = tmp;
706
707 if (tmp > highest_ch)
708 highest_ch = tmp;
709 }
710 }
711
712 /* To use lowest char can be used as the base pointer, the distance
713 * between the lowest and highest char must not be more then 128 */
714 if ((highest_ch - lowest_ch) > 0x80)
715 {
716 *outLen = 0;
717 return;
718 }
719
720 /* Characters are coded using the base pointer below */
721 /* For details, see GSM 11.11 Annex B (normative) */
722 out[0] = 0x82;
723 if (len < PHB_MAX_TAG_LEN - 4)
724 {
725 out[1] = (UBYTE)len;
726 } else
727 {
728 out[1] = PHB_MAX_TAG_LEN - 4;
729 }
730 out[2] = (lowest_ch & 0xff00) >> 8;
731 out[3] = (lowest_ch & 0x00ff);
732 outIdx = 4;
733
734 len = out[1];
735 for (i = 0; i < len; i++)
736 {
737 if (in[i*2])
738 {
739 tmp = 0;
740 tmp = in[i*2] << 8;
741 tmp |= in[(i*2)+1];
742 out[outIdx++] = (tmp - lowest_ch) | 0x80;
743 } else
744 {
745 for (j=0; j<128; j++)
746 {
747 if (in[(i*2)+1] EQ gsmToAsciiTable[j])
748 {
749 out[outIdx++] = (UBYTE)j;
750 break;
751 }
752 }
753
754 /* If the charecter cannot be found in ASCII table exit */
755 if (j EQ 128)
756 {
757 *outLen = 0;
758 return ;
759 }
760 }
761 }
762
763 *outLen = outIdx;
764 }
765 #endif
766
767 #ifdef FF_ATI
768 /*
769 +-------------------------------------------------------------------+
770 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
771 | STATE : code ROUTINE : utl_chsetToGsm |
772 +-------------------------------------------------------------------+
773
774 PURPOSE : This function converts the characters of a string from
775 the character set used within the AT command interpreter
776 to the ACI internal GSM character set.
777 */
778 GLOBAL void utl_chsetToGsm ( UBYTE* in,
779 USHORT inLen,
780 UBYTE* out,
781 USHORT* outLen,
782 T_ACI_GSM_ALPHA gsm )
783 {
784 UBYTE cvtdVal;
785 USHORT outIdx = 0;
786 USHORT inIdx;
787 UBYTE corr = ( gsm EQ GSM_ALPHA_Int ? 0xFF : 0x7F );
788 T_ACI_CSCS_CHSET cscsChset;
789 UBYTE srcId = srcId_cb;
790
791 cscsChset = ati_user_output_cfg[srcId].cscsChset;
792
793 if ( ati_user_output_cfg[srcId].cscsChset EQ CSCS_CHSET_Hex )
794 {
795 utl_hexToGsm ( in, inLen, out, outLen, gsm, CSCS_ALPHA_8_Bit );
796 }
797 else if ( cscsChset EQ CSCS_CHSET_Ucs2 )
798 {
799 utl_ucs2ToGsm ( in, inLen, out, outLen, gsm, CSCS_ALPHA_8_Bit );
800 }
801 else
802 {
803 for ( inIdx = 0; inIdx < inLen; inIdx++ )
804 {
805 cvtdVal = chset[cscsChset][( UBYTE ) in[inIdx]];
806
807 if ( cvtdVal NEQ 0x00 )
808 {
809 out[outIdx] = ( CHAR ) cvtdVal & corr;
810 outIdx++;
811 }
812 }
813
814 if ( gsm EQ GSM_ALPHA_Int )
815 out[outIdx] = '\0';
816
817 *outLen = outIdx;
818 }
819 }
820 #endif
821
822
823 #ifdef FF_ATI
824 /*
825 +-------------------------------------------------------------------+
826 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
827 | STATE : code ROUTINE : utl_hexFromAlpha |
828 +-------------------------------------------------------------------+
829
830 PURPOSE : This function converts the characters of a string from
831 the SIM with UCS2 form 0x81 or 0x82 to 16 Bit hex values.
832 see GSM 11.11 Annex B Coding of Alpha fields in the SIM for UCS2
833 UCS2 form 0x81:
834 - octet 1 = 0x81
835 - octet 2 = length
836 - octet 3 = Bits 15 to 8 of the base pointer to a half page in the UCS2 code space
837 0hhh hhhh h000 0000 , with h = bits of the half page base pointer
838 16... .... .... ...1
839
840 UCS2 form 0x82:
841 - octet 1 = 0x81
842 - octet 2 = length
843 - octet 3 = upper 8 Bit of 16 Bit base pointer to a half page in the UCS2 code space
844 - octet 4 = lower 8 Bit of 16 Bit base pointer to a half page in the UCS2 code space
845 */
846 GLOBAL void utl_hexFromUCS2 ( UBYTE *in,
847 UBYTE *out,
848 USHORT maxOutlen,
849 USHORT *outlen)
850 {
851 USHORT outIdx = 0;
852 USHORT base_pointer;
853 USHORT length = in[1];
854 USHORT tmp;
855
856 if (*in EQ 0x81)
857 {
858 base_pointer = in[2] << 7;
859 in += 3;
860 }
861 else /* if (*in EQ 0x82) */
862 {
863 base_pointer = in[2]<<8 | in[3];
864 in += 4;
865 }
866
867 while ( length-- AND outIdx < maxOutlen-2)
868 {
869 if (*in & 0x80)
870 {
871 tmp = base_pointer + (*in & 0x7F);
872 }
873 else
874 {
875 tmp = 0x0000 + gsmToAsciiTable[*in];
876 }
877 out[outIdx++] = hexVal[(tmp >> 12) & 0x0F ];
878 out[outIdx++] = hexVal[(tmp >> 8) & 0x0F ];
879 out[outIdx++] = hexVal[(tmp >> 4) & 0x0F ];
880 out[outIdx++] = hexVal[(tmp ) & 0x0F ];
881
882 in++;
883 }
884
885 out[outIdx] = '\0';
886 *outlen = outIdx;
887 }
888 #endif
889
890
891 #ifdef FF_ATI
892 /*
893 +-------------------------------------------------------------------+
894 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
895 | STATE : code ROUTINE : utl_chsetFromGsm |
896 +-------------------------------------------------------------------+
897
898 PURPOSE : This function converts the characters of a string from
899 the SIM format to the character set
900 used within the AT command interpreter.
901 */
902 GLOBAL void utl_chsetFromSim ( UBYTE* in,
903 USHORT inLen,
904 UBYTE* out,
905 USHORT maxOutLen,
906 USHORT* outLen,
907 T_ACI_GSM_ALPHA gsm )
908 {
909 T_ACI_CSCS_CHSET cscsChset;
910 UBYTE srcId = srcId_cb;
911
912 cscsChset = ati_user_output_cfg[srcId].cscsChset;
913
914 if ( cscsChset EQ CSCS_CHSET_Ucs2 AND
915 (( *in EQ 0x80 ) OR ( *in EQ 0x81 ) OR ( *in EQ 0x82 )) )
916 {
917 /* UCS2 with form 0x81 or 0x82 as HEX string */
918 if (( *in EQ 0x81 ) OR ( *in EQ 0x82 ))
919 {
920 utl_hexFromUCS2 ( in, out, maxOutLen, outLen);
921 return;
922 }
923
924 /* UCS2 form 0x80 as HEX string */
925 utl_hexFromGsm ( in + 1, (USHORT)( inLen - 1 ), out, maxOutLen, outLen,
926 gsm, CSCS_ALPHA_8_Bit );
927 }
928 else
929 {
930 utl_chsetFromGsm ( in, inLen, out, maxOutLen, outLen, gsm );
931 }
932 }
933 #endif /* #ifdef FF_ATI */
934
935 #if defined(FF_ATI) || defined(FF_BAT)
936 /*
937 +-------------------------------------------------------------------+
938 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
939 | STATE : code ROUTINE : utl_chsetFromGsm |
940 +-------------------------------------------------------------------+
941
942 PURPOSE : This function converts the characters of a string from
943 the ACI internal GSM character set to the character set
944 used within the AT command interpreter.
945 */
946
947 GLOBAL USHORT utl_chsetFromGsm(
948 UBYTE* in,
949 USHORT inLen,
950 UBYTE* out,
951 USHORT maxOutLen,
952 USHORT* outLen,
953 T_ACI_GSM_ALPHA gsm)
954 {
955 USHORT outIdx = 0;
956 USHORT inIdx = 0;
957 USHORT actLen = ( gsm EQ GSM_ALPHA_Int ?
958 ( USHORT ) strlen ( ( CHAR* ) in ) : inLen );
959 UBYTE corr = ( gsm EQ GSM_ALPHA_Int ? 0x00 : 0x80 );
960 T_ACI_CSCS_CHSET cscsChset;
961 UBYTE srcId = srcId_cb;
962 USHORT tblIdx;
963
964 cscsChset = ati_user_output_cfg[srcId].cscsChset;
965
966 if ( cscsChset EQ CSCS_CHSET_Hex )
967 {
968 return utl_hexFromGsm ( in, inLen, out, maxOutLen, outLen, gsm, CSCS_ALPHA_8_Bit );
969 }
970 else if ( cscsChset EQ CSCS_CHSET_Ucs2 )
971 {
972 return utl_ucs2FromGsm ( in, inLen, out, maxOutLen, outLen, gsm, CSCS_ALPHA_8_Bit );
973 }
974 else
975 {
976 while ( inIdx < actLen AND outIdx < maxOutLen - 1 )
977 {
978 tblIdx = 0;
979
980 while ( tblIdx <= 0xFF AND
981 chset[cscsChset][tblIdx] NEQ (( UBYTE )in[inIdx] | corr ))
982 tblIdx++;
983
984 if ( tblIdx <= 0xFF )
985 {
986 out[outIdx] = ( UBYTE )tblIdx;
987 outIdx++;
988 }
989
990 inIdx++;
991 }
992
993 out[outIdx] = '\0';
994 *outLen = outIdx;
995
996 return inIdx;
997 }
998 }
999 #endif
1000
1001 #ifdef FF_ATI
1002 /*
1003 +-------------------------------------------------------------------+
1004 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1005 | STATE : code ROUTINE : utl_sprints |
1006 +-------------------------------------------------------------------+
1007
1008 PURPOSE : This function writes a not null terminated string to a
1009 buffer.
1010 */
1011 GLOBAL USHORT sprints ( CHAR* buf, CHAR* arg, USHORT len )
1012 {
1013 buf[0] = '\"';
1014
1015 memcpy ( &buf[1], arg, len );
1016
1017 buf[len + 1] = '\"';
1018 buf[len + 2] = '\0';
1019
1020 return (len + 2);
1021 }
1022 #endif
1023
1024 #ifdef FF_ATI
1025 /*
1026 +-------------------------------------------------------------------+
1027 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1028 | STATE : code ROUTINE : utl_sprintq |
1029 +-------------------------------------------------------------------+
1030
1031 PURPOSE : This function writes a not null terminated string to a
1032 buffer.
1033 */
1034 GLOBAL USHORT sprintq ( CHAR* buf, CHAR* arg, USHORT len )
1035 {
1036 memcpy ( &buf[0], arg, len );
1037
1038 buf[len] = '\0';
1039
1040 return (len);
1041 }
1042 #endif
1043
1044 #ifdef FF_ATI
1045 /*
1046 +-------------------------------------------------------------------+
1047 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1048 | STATE : code ROUTINE : utl_hexToIntGsm |
1049 +-------------------------------------------------------------------+
1050
1051 PURPOSE : This function converts the characters of a string from
1052 the "HEX" character set to the ACI internal GSM
1053 character set.
1054 */
1055 GLOBAL void utl_hexToGsm ( UBYTE* in,
1056 USHORT inLen,
1057 UBYTE* out,
1058 USHORT* outLen,
1059 T_ACI_GSM_ALPHA gsm,
1060 T_ACI_CSCS_ALPHA alphabet )
1061 {
1062 SHORT val = 0;
1063 UBYTE digit;
1064 USHORT inIdx = 0;
1065 USHORT outIdx = 0;
1066 SHORT base = 0x10;
1067
1068 while ( inIdx < inLen )
1069 {
1070 if ( in[inIdx] >= 0x30 AND in[inIdx] <= 0x39 ) /* '0' ... '9' */
1071 {
1072 digit = in[inIdx] - 0x30; /* ->0 ... 9 */
1073 }
1074 else if ( in[inIdx] >= 0x61 AND in[inIdx] <= 0x66 ) /* 'a' ... 'f' */
1075 {
1076 digit = in[inIdx] - 0x61 + 0x0A; /* ->0x0a...0x0f */
1077 }
1078 else if ( in[inIdx] >= 0x41 AND in[inIdx] <= 0x46 ) /* 'A' ... 'F' */
1079 {
1080 digit = in[inIdx] - 0x41 + 0x0A; /* ->0x0a...0x0f */
1081 }
1082 else
1083 {
1084 digit = 0xFF;
1085 }
1086
1087 if ( digit NEQ 0xFF ) /* skip invalid digit */
1088 {
1089 if ( base EQ 0x10 )
1090 {
1091 val = digit << 4;
1092 }
1093 else
1094 {
1095 val |= digit;
1096
1097 if ( alphabet EQ CSCS_ALPHA_7_Bit AND !( val & 0x80 ) )
1098 {
1099 if ( gsm EQ GSM_ALPHA_Int )
1100 {
1101 out[outIdx++] = ( CHAR ) val | 0x80;
1102 }
1103 else
1104 {
1105 out[outIdx++] = ( CHAR ) val;
1106 }
1107 }
1108 else if ( alphabet NEQ CSCS_ALPHA_7_Bit )
1109 {
1110 out[outIdx++] = ( CHAR ) val;
1111 }
1112 }
1113
1114 base ^= 0x10;
1115 }
1116
1117 inIdx++;
1118 }
1119
1120 if ( gsm EQ GSM_ALPHA_Int )
1121 out[outIdx] = '\0';
1122
1123 *outLen = outIdx;
1124 }
1125 #endif
1126
1127 #ifdef FF_ATI
1128 /*
1129 +-------------------------------------------------------------------+
1130 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1131 | STATE : code ROUTINE : utl_ucs2ToGsm |
1132 +-------------------------------------------------------------------+
1133
1134 PURPOSE : This function converts the characters of a string from
1135 the "UCS2" character set to the ACI internal GSM
1136 character set.
1137 */
1138 GLOBAL void utl_ucs2ToGsm ( UBYTE* in,
1139 USHORT inLen,
1140 UBYTE* out,
1141 USHORT* outLen,
1142 T_ACI_GSM_ALPHA gsm,
1143 T_ACI_CSCS_ALPHA alphabet )
1144 {
1145 int i, j;
1146 UBYTE val;
1147 USHORT len;
1148 UBYTE tmpIn[2]; /* store temporary two chars (HEX conversion) */
1149 UBYTE tmpInIdx; /* holds a temporary index for two chars (HEX conversion)*/
1150 UBYTE digit; /* holds a digit (HEX conversion) */
1151 SHORT tmpVal; /* hold a temporary value (HEX conversion) */
1152 UBYTE tmpOut; /* the HEX output (HEX conversion) */
1153 SHORT base = 0x10;
1154 USHORT outIdx = 0;
1155 UBYTE tmpInLen = 2;
1156
1157 /* TRACE_FUNCTION(" utl_ucs2ToGsm() "); */
1158
1159 len = inLen/4;
1160
1161 for (i=0;i<len;i++)
1162 {
1163 /* check if this is a UCS2 character in 00xy format */
1164 if ( ( in[i*4] EQ '0' ) AND ( in[i*4+1] EQ '0' ) )
1165 {
1166 /* convert the next two character to HEX */
1167 tmpIn[0] = in[i*4+2];
1168 tmpIn[1] = in[i*4+3];
1169
1170 tmpVal = tmpOut = val = 0;
1171
1172 /* convert the two characters into the real hexadecimal ASCII value */
1173 for( tmpInIdx=0; tmpInIdx<2; tmpInIdx++ )
1174 {
1175 if ( tmpIn[tmpInIdx] >= '0' AND tmpIn[tmpInIdx] <= '9' )
1176 {
1177 digit = tmpIn[tmpInIdx] - '0';
1178 }
1179 else if ( tmpIn[tmpInIdx] >= 'a' AND tmpIn[tmpInIdx] <= 'f' )
1180 {
1181 digit = tmpIn[tmpInIdx] - 'a' + 0x0A;
1182 }
1183 else if ( tmpIn[tmpInIdx] >= 'A' AND tmpIn[tmpInIdx] <= 'F' )
1184 {
1185 digit = tmpIn[tmpInIdx] - 'A' + 0x0A;
1186 }
1187 else
1188 {
1189 digit = 0xFF;
1190 }
1191
1192 if ( digit NEQ 0xFF )
1193 {
1194 if ( base EQ 0x10 )
1195 {
1196 tmpVal = digit * 0x10;
1197 }
1198 else
1199 {
1200 tmpVal += digit;
1201 tmpOut = (UBYTE) tmpVal;
1202 }
1203
1204 base ^= 0x10;
1205 }
1206 }
1207
1208 /* convert the hexadecimal ASCII value to GSM */
1209 if (!(tmpOut & 0x80))
1210 {
1211 if ( tmpOut EQ ( gsmToAsciiTable[tmpOut])) /* ASCII and GSM are identical */
1212 {
1213 val = tmpOut;
1214 }
1215 else /* find match in the table and copy index of match */
1216 {
1217 for (j=0; j<128; j++)
1218 {
1219 if (tmpOut EQ gsmToAsciiTable[j])
1220 {
1221 val = (UBYTE)j;
1222 break;
1223 }
1224 }
1225 }
1226 }
1227 else /* find match in the table and copy index of match */
1228 {
1229 for (j=0; j<128; j++)
1230 {
1231 if (tmpOut EQ gsmToAsciiTable[j])
1232 {
1233 val = (UBYTE)j;
1234 break;
1235 }
1236 }
1237 }
1238
1239 /* if necessary, cut the GSM value to 7bit */
1240 if ( alphabet EQ CSCS_ALPHA_7_Bit AND !( val & 0x80 ) )
1241 {
1242 if ( gsm EQ GSM_ALPHA_Int )
1243 {
1244 out[outIdx++] = val | 0x80;
1245 }
1246 else
1247 {
1248 out[outIdx++] = val;
1249 }
1250 }
1251 else
1252 {
1253 out[outIdx++] = val;
1254 }
1255 }
1256
1257 else /* unknown char, skip it */
1258 {
1259 /* TRACE_EVENT("UCS2 MISMATCH: Unknown UCS2 entry, character skipped!"); */
1260 /* out[outIdx++] = '?'; */
1261 }
1262 }
1263
1264 if ( gsm EQ GSM_ALPHA_Int )
1265 {
1266 out[outIdx] = '\0';
1267 }
1268
1269 /* set the outlength */
1270 *outLen = outIdx;
1271
1272 }
1273 #endif
1274
1275 #ifdef FF_ATI
1276 /*
1277 +-------------------------------------------------------------------+
1278 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1279 | STATE : code ROUTINE : utl_hexFromGsm |
1280 +-------------------------------------------------------------------+
1281
1282 PURPOSE : This function converts the characters of a string from
1283 the ACI internal GSM character set to the "HEX"
1284 character set.
1285 */
1286 GLOBAL USHORT utl_hexFromGsm ( UBYTE* in,
1287 USHORT inLen,
1288 UBYTE* out,
1289 USHORT maxOutLen,
1290 USHORT* outLen,
1291 T_ACI_GSM_ALPHA gsm,
1292 T_ACI_CSCS_ALPHA alphabet )
1293 {
1294 USHORT inIdx = 0;
1295 USHORT outIdx = 0;
1296
1297 while ( inIdx < inLen AND outIdx < maxOutLen - 2 )
1298 {
1299 if ( alphabet NEQ CSCS_ALPHA_7_Bit OR
1300 ( gsm EQ GSM_ALPHA_Def AND !( in[inIdx] & 0x80 ) ) OR
1301 ( gsm EQ GSM_ALPHA_Int AND ( in[inIdx] & 0x80 ) ) )
1302 {
1303 out[outIdx++] = hexVal[ in[inIdx] >> 4 ];
1304 out[outIdx++] = hexVal[ in[inIdx] & 0x0F ];
1305 }
1306
1307 inIdx++;
1308 }
1309
1310 out[outIdx] = '\0';
1311 *outLen = outIdx;
1312
1313 return inIdx;
1314 }
1315 #endif
1316
1317 #ifdef FF_ATI
1318 /*
1319 +-------------------------------------------------------------------+
1320 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1321 | STATE : code ROUTINE : utl_ucs2FromGsm |
1322 +-------------------------------------------------------------------+
1323
1324 PURPOSE : This function converts the characters of a string from
1325 the ACI internal GSM character set to the "UCS2"
1326 character set.
1327 */
1328 LOCAL USHORT utl_ucs2FromGsm (UBYTE* in,
1329 USHORT inLen,
1330 UBYTE* out,
1331 USHORT maxOutLen,
1332 USHORT* outLen,
1333 T_ACI_GSM_ALPHA gsm,
1334 T_ACI_CSCS_ALPHA alphabet )
1335 {
1336 USHORT inIdx = 0;
1337 USHORT outIdx = 0;
1338
1339 while ( inIdx < inLen AND outIdx < maxOutLen - 4 )
1340 {
1341 if ( alphabet NEQ CSCS_ALPHA_7_Bit OR
1342 ( gsm EQ GSM_ALPHA_Def AND !( in[inIdx] & 0x80 ) ) OR
1343 ( gsm EQ GSM_ALPHA_Int AND ( in[inIdx] & 0x80 ) ) )
1344 {
1345 /* Insert two leading Os, convert GSM to ASCII and print out as HEX */
1346 out[outIdx++] = '0';
1347 out[outIdx++] = '0';
1348 out[outIdx++] = hexVal[ gsmToAsciiTable[in[inIdx]] >> 4 ];
1349 out[outIdx++] = hexVal[ gsmToAsciiTable[in[inIdx]] & 0x0F ];
1350 }
1351
1352 inIdx++;
1353 }
1354
1355 out[outIdx] = '\0';
1356 *outLen = outIdx;
1357
1358 return inIdx;
1359
1360 }
1361 #endif
1362
1363 #ifdef FF_ATI
1364 /*
1365 +-------------------------------------------------------------------+
1366 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1367 | STATE : code ROUTINE : utl_smDtaToTe |
1368 +-------------------------------------------------------------------+
1369
1370 PURPOSE : This function converts the SM data in the format
1371 specified in Rec. GSM 07.05, message data parameter
1372 <data>, to the format used by the AT Command Interface.
1373 */
1374 GLOBAL void utl_smDtaToTe ( UBYTE* in,
1375 USHORT inLen,
1376 UBYTE* out,
1377 USHORT maxOutLen,
1378 USHORT* outLen,
1379 UBYTE fo,
1380 UBYTE dcs )
1381 {
1382 UBYTE alphabet = cmhSMS_getAlphabetPp ( dcs );
1383
1384 if ( alphabet EQ CSCS_ALPHA_7_Bit AND
1385 (fo & TP_UDHI_MASK) EQ TP_UDHI_WITHOUT_HEADER )
1386 {
1387 utl_chsetFromGsm ( in, inLen, out, maxOutLen, outLen, GSM_ALPHA_Def );
1388 }
1389 else if ( alphabet NEQ CSCS_ALPHA_7_Bit OR
1390 (fo & TP_UDHI_MASK) EQ TP_UDHI_WITH_HEADER )
1391 {
1392 utl_hexFromGsm ( in, inLen, out, maxOutLen, outLen, GSM_ALPHA_Def,
1393 CSCS_ALPHA_8_Bit );
1394 }
1395 else
1396 {
1397 *outLen = MINIMUM ( inLen, maxOutLen - 1 );
1398 memcpy ( out, in, *outLen );
1399 out[*outLen] = '\0';
1400 }
1401 }
1402 #endif
1403
1404 #ifdef FF_ATI
1405 /*
1406 +-------------------------------------------------------------------+
1407 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1408 | STATE : code ROUTINE : utl_smDtaFromTe |
1409 +-------------------------------------------------------------------+
1410
1411 PURPOSE : This function converts the SM data in the format used
1412 by the AT Command Interface to the format specified in
1413 Rec. GSM 07.05, message data parameter <data>.
1414 */
1415 GLOBAL void utl_smDtaFromTe ( UBYTE* in,
1416 USHORT inLen,
1417 UBYTE* out,
1418 USHORT* outLen,
1419 UBYTE fo,
1420 UBYTE dcs )
1421 {
1422 UBYTE alphabet = cmhSMS_getAlphabetPp ( dcs );
1423
1424 if ( alphabet EQ CSCS_ALPHA_7_Bit AND
1425 ( fo & TP_UDHI_MASK ) EQ TP_UDHI_WITHOUT_HEADER )
1426 {
1427 utl_chsetToGsm ( in, inLen, out, outLen, GSM_ALPHA_Def );
1428 }
1429 else if ( alphabet NEQ CSCS_ALPHA_7_Bit OR
1430 ( fo & TP_UDHI_MASK ) EQ TP_UDHI_WITH_HEADER )
1431 {
1432 utl_hexToGsm ( in, inLen, out, outLen, GSM_ALPHA_Def, alphabet );
1433 }
1434 else
1435 {
1436 memcpy ( out, in, inLen );
1437 *outLen = inLen;
1438 }
1439 }
1440 #endif
1441
1442 #ifdef FF_ATI
1443 /*
1444 +-------------------------------------------------------------------+
1445 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1446 | STATE : code ROUTINE : utl_ussdDtaFromTe |
1447 +-------------------------------------------------------------------+
1448
1449 PURPOSE : This function converts the USSD data in the format used
1450 by the AT Command Interface to the format specified in
1451 Rec. GSM 07.07.
1452 */
1453 GLOBAL void utl_ussdDtaFromTe ( UBYTE* in,
1454 USHORT inLen,
1455 UBYTE* out,
1456 USHORT* outLen,
1457 UBYTE dcs )
1458 {
1459 UBYTE alphabet = cmhSMS_getAlphabetCb ( dcs );
1460
1461 if ( alphabet EQ CSCS_ALPHA_7_Bit )
1462 {
1463 utl_chsetToGsm ( in, inLen, out, outLen, GSM_ALPHA_Def );
1464 }
1465 else
1466 {
1467 utl_hexToGsm ( in, inLen, out, outLen, GSM_ALPHA_Def, alphabet );
1468 }
1469 }
1470 #endif
1471
1472 #ifdef FF_ATI
1473 /*
1474 +-------------------------------------------------------------------+
1475 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1476 | STATE : code ROUTINE : utl_ussdDtaToTe |
1477 +-------------------------------------------------------------------+
1478
1479 PURPOSE : This function converts the USSD data in the format
1480 specified in Rec. GSM 07.07 to the format used
1481 by the AT Command Interface.
1482 */
1483
1484 GLOBAL USHORT utl_ussdDtaToTe ( UBYTE* in,
1485 USHORT inLen,
1486 UBYTE* out,
1487 USHORT maxOutLen,
1488 USHORT* outLen,
1489 UBYTE dcs )
1490 {
1491 UBYTE alphabet = cmhSMS_getAlphabetCb ( dcs );
1492
1493 if ( alphabet EQ CSCS_ALPHA_7_Bit )
1494 {
1495 return utl_chsetFromGsm ( in, inLen, out, maxOutLen, outLen, GSM_ALPHA_Def );
1496 }
1497 else
1498 {
1499 return utl_hexFromGsm ( in, inLen, out, maxOutLen, outLen, GSM_ALPHA_Def, alphabet );
1500 }
1501 }
1502 #endif
1503
1504 #ifdef FF_ATI
1505 /*
1506 +-------------------------------------------------------------------+
1507 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1508 | STATE : code ROUTINE : utl_cbmDtaToTe |
1509 +-------------------------------------------------------------------+
1510
1511 PURPOSE : This function converts the CBM data in the format
1512 specified in Rec. GSM 07.05, message data parameter
1513 <data>, to the format used by the AT Command Interface.
1514 */
1515 GLOBAL void utl_cbmDtaToTe ( UBYTE* in,
1516 USHORT inLen,
1517 UBYTE* out,
1518 USHORT maxOutLen,
1519 USHORT* outLen,
1520 UBYTE fo,
1521 UBYTE dcs )
1522 {
1523 UBYTE alphabet = cmhSMS_getAlphabetCb ( dcs );
1524
1525 if ( alphabet EQ CSCS_ALPHA_7_Bit AND
1526 ( fo & TP_UDHI_MASK ) EQ TP_UDHI_WITHOUT_HEADER )
1527 {
1528 utl_chsetFromGsm ( in, inLen, out, maxOutLen, outLen, GSM_ALPHA_Def );
1529 }
1530 else if ( alphabet NEQ CSCS_ALPHA_7_Bit OR
1531 ( fo & TP_UDHI_MASK ) EQ TP_UDHI_WITH_HEADER )
1532 {
1533 utl_hexFromGsm ( in, inLen, out, maxOutLen, outLen, GSM_ALPHA_Def, alphabet );
1534 }
1535 else
1536 {
1537 *outLen = MINIMUM ( inLen, maxOutLen );
1538 memcpy ( out, in, *outLen );
1539 }
1540 }
1541 #endif
1542
1543 /*
1544 +-------------------------------------------------------------------+
1545 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1546 | STATE : code ROUTINE : utl_cvtGsmIra |
1547 +-------------------------------------------------------------------+
1548
1549 PURPOSE : This function converts the characters of a string from
1550 the ACI internal GSM character set to the IRA character
1551 set or vice versa.
1552 */
1553 GLOBAL BOOL utl_cvtGsmIra ( UBYTE* in,
1554 USHORT inLen,
1555 UBYTE* out,
1556 USHORT outLen,
1557 T_ACI_CSCS_DIR dir )
1558 {
1559 USHORT inIdx = 0;
1560 USHORT outIdx = 0;
1561 USHORT tblIdx;
1562 UBYTE cvtdVal;
1563
1564 TRACE_FUNCTION("utl_cvtGsmIra()");
1565
1566
1567 if ( inLen > outLen )
1568 {
1569 return ( FALSE );
1570 }
1571
1572 if ( dir EQ CSCS_DIR_GsmToIra )
1573 {
1574 while ( inIdx < inLen )
1575 {
1576 tblIdx = 0;
1577
1578 while ( tblIdx <= 0xFF AND
1579 chset[CSCS_CHSET_Ira][tblIdx] NEQ (( UBYTE )in[inIdx] | 0x80 ))
1580 tblIdx++;
1581
1582 if ( tblIdx <= 0xFF )
1583 {
1584 out[outIdx] = ( UBYTE )tblIdx;
1585 outIdx++;
1586 }
1587 else
1588 {
1589 return ( FALSE );
1590 }
1591
1592 inIdx++;
1593 }
1594 }
1595 else if ( dir EQ CSCS_DIR_IraToGsm )
1596 {
1597 for ( inIdx = 0; inIdx < inLen; inIdx++ )
1598 {
1599 cvtdVal = chset[CSCS_CHSET_Ira][( UBYTE ) in[inIdx]];
1600
1601 if ( cvtdVal NEQ 0x00 )
1602 {
1603 out[outIdx] = ( CHAR ) cvtdVal & 0x7F;
1604 outIdx++;
1605 }
1606 else
1607 {
1608 return ( FALSE );
1609 }
1610 }
1611
1612 }
1613 else
1614 {
1615 return ( FALSE );
1616 }
1617
1618 return ( TRUE );
1619 }
1620
1621
1622 /*
1623 +-------------------------------------------------------------------+
1624 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1625 | STATE : code ROUTINE : utl_binToHex |
1626 +-------------------------------------------------------------------+
1627
1628 PURPOSE : This function converts a binary string of bytes with a
1629 given length into an null terminated ASCII string
1630 representation.
1631 */
1632 GLOBAL void utl_binToHex (UBYTE* in,
1633 SHORT inLen,
1634 CHAR* out )
1635 {
1636 SHORT idx = 0;
1637 UBYTE hNib;
1638 UBYTE lNib;
1639
1640 while( idx < inLen )
1641 {
1642 hNib = (in[idx]&0xF0)>>4;
1643
1644 if( hNib > 9 ) *out = (hNib-10)+0x41;
1645 else *out = hNib + 0x30;
1646
1647 out++;
1648
1649 lNib = in[idx]&0x0F;
1650
1651 if( lNib > 9 ) *out = (lNib-10)+0x41;
1652 else *out = lNib + 0x30;
1653
1654 out++;
1655 idx++;
1656 }
1657 *out = 0x0;
1658 }
1659
1660
1661 #ifdef FF_ATI
1662 /*
1663 +-------------------------------------------------------------------+
1664 | PROJECT : GSM MODULE : ACI_UTIL |
1665 | STATE : code ROUTINE : utl_HexStrToBin |
1666 +-------------------------------------------------------------------+
1667
1668 PURPOSE : This function converts a null terminated string of HEX
1669 values in a binary buffer.
1670 RETURN: byte count.
1671 */
1672 GLOBAL USHORT utl_HexStrToBin (UBYTE *in,
1673 USHORT inLen,
1674 UBYTE *out,
1675 USHORT outLen)
1676 {
1677 USHORT inIdx = 0;
1678 USHORT outIdx = 0;
1679 UBYTE value;
1680 BOOL hNib = TRUE;
1681
1682 while ((inIdx < inLen) AND (outIdx < outLen))
1683 {
1684 if ((in[inIdx] >= 0x30) AND (in[inIdx] <= 0x39))
1685 {
1686 value = in[inIdx] - 0x30;
1687 }
1688 else if ((in[inIdx] >= 0x61) AND (in[inIdx] <= 0x66))
1689 {
1690 value = in[inIdx] - 0x61 + 0x0A;
1691 }
1692 else if ((in[inIdx] >= 0x41) AND (in[inIdx] <= 0x46))
1693 {
1694 value = in[inIdx] - 0x41 + 0x0A;
1695 }
1696 else
1697 {
1698 return (0);
1699 }
1700
1701 if (hNib)
1702 {
1703 out[outIdx] = (value << 0x04) & 0xF0;
1704 hNib = FALSE;
1705 }
1706 else
1707 {
1708 out[outIdx] |= value & 0x0F;
1709 hNib = TRUE;
1710 outIdx++;
1711 }
1712 inIdx++;
1713 }
1714
1715 return (outIdx);
1716 }
1717 #endif
1718
1719 #ifdef FF_ATI
1720 /*
1721 +-------------------------------------------------------------------+
1722 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1723 | STATE : code ROUTINE : trace_cmd_line |
1724 +-------------------------------------------------------------------+
1725
1726 PURPOSE : This function trace the command line and check
1727 this string for % character
1728 */
1729
1730 GLOBAL void trace_cmd_line (char *prefix, char *output, UBYTE srcId, USHORT output_len)
1731 {
1732 char trcBuf[80];
1733 int dst_i;
1734
1735 dst_i = sprintf (trcBuf, "%s(Src %d)[lth %d]", (prefix) ? prefix : "", srcId, output_len);
1736
1737 strncpy(&trcBuf[dst_i], output, 79-dst_i);
1738 trcBuf[79] = '\0';
1739
1740 if (trcBuf[76])
1741 {
1742 trcBuf[76] = trcBuf[77] = trcBuf[78] = '.'; /* add trailing "..." if string is >=76 */
1743 }
1744
1745 /* Send the trace if either EVENT or CLASS8 is turned on */
1746 TRACE_USER_CLASS_P1(TC_EVENT|TC_USER8, "%s",trcBuf);
1747 }
1748 #endif
1749
1750
1751 #ifdef FF_ATI
1752 /*
1753 +-------------------------------------------------------------------+
1754 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
1755 | STATE : code ROUTINE : trace_cmd_state |
1756 +-------------------------------------------------------------------+
1757
1758 PURPOSE : This function trace the command line state
1759 */
1760
1761 GLOBAL void trace_cmd_state (UBYTE srcId,
1762 T_ATI_CMD_STATE old_state,
1763 T_ATI_CMD_STATE new_state)
1764 {
1765 char trcBuf[50];
1766
1767 if (old_state EQ new_state)
1768 {
1769 return;
1770 }
1771
1772 sprintf (trcBuf, "(Src %d) cmd_state: ", srcId );
1773
1774 switch (old_state)
1775 {
1776 case (CMD_IDLE):
1777 strcat (trcBuf, "CMD_IDLE -> ");
1778 break;
1779 case (CMD_TYPING):
1780 strcat (trcBuf, "CMD_TYPING -> ");
1781 break;
1782 case (CMD_RUNNING):
1783 strcat (trcBuf, "CMD_RUNNING -> ");
1784 break;
1785 default:
1786 strcat (trcBuf, "CMD_UNKNOWN ! ");
1787 }
1788
1789 switch (new_state)
1790 {
1791 case (CMD_IDLE):
1792 strcat (trcBuf, "CMD_IDLE");
1793 break;
1794 case (CMD_TYPING):
1795 strcat (trcBuf, "CMD_TYPING");
1796 break;
1797 case (CMD_RUNNING):
1798 strcat (trcBuf, "CMD_RUNNING");
1799 break;
1800 default:
1801 strcat (trcBuf, "CMD_UNKNOWN !");
1802 }
1803
1804 TRACE_EVENT_P1("%s",trcBuf);
1805 }
1806 #endif
1807
1808 /*
1809 +--------------------------------------------------------------------+
1810 | PROJECT : GSM-F&D (8411) MODULE : ACI_CMD |
1811 | STATE : code ROUTINE : toa_merge |
1812 +--------------------------------------------------------------------+
1813
1814 PURPOSE : builds type of address octet from TOA structure
1815
1816 */
1817
1818 GLOBAL UBYTE toa_merge (T_ACI_TOA type)
1819 {
1820
1821 return ((type.ton << 4) & 0xF0)
1822 | ( type.npi & 0x0F)
1823 | 0x80;
1824 }
1825
1826
1827
1828 #ifdef GPRS
1829 /*
1830 +-----------------------------------------------------------------------------
1831 | Function : utl_create_pco
1832 +-----------------------------------------------------------------------------
1833 | Description : The function create_pco() creates protocol configuration
1834 | options needed to activate a PDPcontext.
1835 |
1836 | Parameters : buffer - buffer to write the PCOs
1837 | length - on call: buffer size; on return: written bytes
1838 | content - mask to specify the PCO content
1839 | config_prot - used configuration protocol (currently PPP)
1840 | auth_prot - authentication protocol (currently PAP)
1841 | user_name - string with the user name
1842 | password - string with the password
1843 | dns1 - requested primary DNS address
1844 | dns2 - requested secondary DNS address
1845 |
1846 | Return : 0 - operation successful
1847 | -1 - operation fails
1848 |
1849 +-----------------------------------------------------------------------------
1850 */
1851 GLOBAL int utl_create_pco (UBYTE* buffer,
1852 USHORT* length,
1853 ULONG content,
1854 UBYTE config_prot,
1855 USHORT auth_prot,
1856 UBYTE* user_name,
1857 UBYTE* password,
1858 ULONG dns1,
1859 ULONG dns2)
1860 {
1861 USHORT size;
1862 USHORT temp_len;
1863 USHORT len_user;
1864 USHORT len_pwd;
1865 USHORT written;
1866 UBYTE* pos;
1867 UBYTE* len_pos1;
1868 UBYTE* len_pos2;
1869
1870 TRACE_FUNCTION( "create_pco" );
1871
1872 /*
1873 * store buffer size
1874 */
1875 size = *length;
1876 /*
1877 * initialize values
1878 */
1879 *length = 0;
1880 written = 0;
1881 pos = buffer;
1882 /*
1883 * calculate if requested content is writeable
1884 */
1885 temp_len = 1;
1886 if(content & ACI_PCO_CONTENTMASK_AUTH)
1887 {
1888 len_user = strlen((char*)user_name);
1889 len_pwd = strlen((char*)password);
1890 temp_len+= ACI_PCO_PAP_OVERHEAD + len_user + len_pwd;
1891 }
1892 if((content & ACI_PCO_CONTENTMASK_DNS1) ||
1893 (content & ACI_PCO_CONTENTMASK_DNS2))
1894 {
1895 temp_len+= ACI_PCO_IPCP_OVERHEAD;
1896 if(content & ACI_PCO_CONTENTMASK_DNS1)
1897 temp_len+= ACI_PCO_IPCP_LENGTH_DNS1;
1898 if(content & ACI_PCO_CONTENTMASK_DNS2)
1899 temp_len+= ACI_PCO_IPCP_LENGTH_DNS2;
1900 }
1901 TRACE_EVENT_P2("temp_len=%d size=%d", temp_len, size);
1902 if(temp_len > size)
1903 {
1904 /*
1905 * content is to long
1906 */
1907 return -1;
1908 }
1909 /*
1910 * set configuration protocol identifier
1911 */
1912 *pos = 0x80 | config_prot;
1913 pos++;
1914 written++;
1915
1916 /*
1917 * authentication
1918 */
1919 if(content & ACI_PCO_CONTENTMASK_AUTH)
1920 {
1921 /*
1922 * set authentication protocol
1923 */
1924 *pos = (UBYTE)((auth_prot >> 8) & 0x00ff);
1925 pos++;
1926 written++;
1927 *pos = (UBYTE)(auth_prot & 0x00ff);
1928 pos++;
1929 written++;
1930 /*
1931 * store first length position
1932 */
1933 len_pos1 = pos;
1934 pos++;
1935 written++;
1936 /*
1937 * Code field
1938 */
1939 *pos = ACI_PCO_PAP_AUTH_REQ;
1940 pos++;
1941 written++;
1942 /*
1943 * Identifier field (just some value)
1944 */
1945 *pos = 0x01;
1946 pos++;
1947 written++;
1948 /*
1949 * Length field (store length position)
1950 */
1951 *pos = 0x00;
1952 pos++;
1953 written++;
1954 len_pos2 = pos;
1955 pos++;
1956 written++;
1957 /*
1958 * User Name Length field
1959 */
1960 *pos = (UBYTE)(/*lint -e(644) */len_user & 0x00ff);
1961 pos++;
1962 written++;
1963 /*
1964 * User Name field
1965 */
1966 memcpy(pos, user_name, len_user);
1967 pos += len_user;
1968 written+= len_user;
1969 /*
1970 * Password Length field
1971 */
1972 *pos = (UBYTE)(/*lint -e(644) */len_pwd & 0x00ff);
1973 pos++;
1974 written++;
1975 /*
1976 * Password field
1977 */
1978 memcpy(pos, password, len_pwd);
1979 pos += len_pwd;
1980 written+= len_pwd;
1981 /*
1982 * fill length fields
1983 */
1984 *len_pos1 = (UBYTE)(pos - len_pos1 - 1);
1985 *len_pos2 = *len_pos1;
1986 }
1987 /*
1988 * DNS addresses
1989 */
1990 if((content & ACI_PCO_CONTENTMASK_DNS1) ||
1991 (content & ACI_PCO_CONTENTMASK_DNS2))
1992 {
1993 /*
1994 * set IPCP protocol
1995 */
1996 *pos = ACI_PCO_IPCP_PROT_MSB;
1997 pos++;
1998 written++;
1999 *pos = ACI_PCO_IPCP_PROT_LSB;
2000 pos++;
2001 written++;
2002 /*
2003 * store first length position
2004 */
2005 len_pos1 = pos;
2006 pos++;
2007 written++;
2008 /*
2009 * Code field
2010 */
2011 *pos = ACI_PCO_IPCP_CONF_REQ;
2012 pos++;
2013 written++;
2014 /*
2015 * Identifier field (just some value)
2016 */
2017 *pos = 0x01;
2018 pos++;
2019 written++;
2020 /*
2021 * Length field (store length position)
2022 */
2023 *pos = 0x00;
2024 pos++;
2025 written++;
2026 len_pos2 = pos;
2027 pos++;
2028 written++;
2029 /*
2030 * primary DNS address
2031 */
2032 if(content & ACI_PCO_CONTENTMASK_DNS1)
2033 {
2034 /*
2035 * Type field
2036 */
2037 *pos = ACI_PCO_IPCP_TYPE_DNS1;
2038 pos++;
2039 written++;
2040 /*
2041 * Length field
2042 */
2043 *pos = ACI_PCO_IPCP_LENGTH_DNS1;
2044 pos++;
2045 written++;
2046 /*
2047 * primary DNS address
2048 */
2049 *pos = (UBYTE)((dns1 >> 24) & 0x000000ff);
2050 pos++;
2051 written++;
2052 *pos = (UBYTE)((dns1 >> 16) & 0x000000ff);
2053 pos++;
2054 written++;
2055 *pos = (UBYTE)((dns1 >> 8) & 0x000000ff);
2056 pos++;
2057 written++;
2058 *pos = (UBYTE)(dns1 & 0x000000ff);
2059 pos++;
2060 written++;
2061 }
2062 /*
2063 * secondary DNS address
2064 */
2065 if(content & ACI_PCO_CONTENTMASK_DNS2)
2066 {
2067 /*
2068 * Type field
2069 */
2070 *pos = ACI_PCO_IPCP_TYPE_DNS2;
2071 pos++;
2072 written++;
2073 /*
2074 * Length field
2075 */
2076 *pos = ACI_PCO_IPCP_LENGTH_DNS2;
2077 pos++;
2078 written++;
2079 /*
2080 * primary DNS address
2081 */
2082 *pos = (UBYTE)((dns2 >> 24) & 0x000000ff);
2083 pos++;
2084 written++;
2085 *pos = (UBYTE)((dns2 >> 16) & 0x000000ff);
2086 pos++;
2087 written++;
2088 *pos = (UBYTE)((dns2 >> 8) & 0x000000ff);
2089 pos++;
2090 written++;
2091 *pos = (UBYTE)(dns2 & 0x000000ff);
2092 pos++;
2093 written++;
2094 }
2095 /*
2096 * fill length fields
2097 */
2098 *len_pos1 = (UBYTE)(pos - len_pos1 - 1);
2099 *len_pos2 = *len_pos1;
2100 }
2101 /*
2102 * pass written bytes to caller
2103 */
2104 *length = written;
2105 /*
2106 * return result
2107 */
2108 return 0;
2109 } /* utl_create_pco() */
2110
2111
2112
2113 /*
2114 +-----------------------------------------------------------------------------
2115 | Function : utl_analyze_pco
2116 +-----------------------------------------------------------------------------
2117 | Description : The function analyze_pco() analyzes the response protocol
2118 | configuration from the network
2119 |
2120 | Parameters : buffer - buffer with the response PCOs
2121 | length - length of PCOs
2122 | dns1 - returns primary DNS address
2123 | dns2 - returns secondary DNS address
2124 | gateway - returns Gateway address
2125 |
2126 | Return : 0 - operation successful
2127 | -1 - operation fails
2128 |
2129 +-----------------------------------------------------------------------------
2130 */
2131 GLOBAL int utl_analyze_pco (UBYTE* buffer,
2132 USHORT length,
2133 ULONG* dns1,
2134 ULONG* dns2,
2135 ULONG* gateway)
2136 {
2137 UBYTE* pos;
2138 USHORT pos_len;
2139 USHORT packet_len;
2140 USHORT start_pos;
2141 USHORT dist_to_next;
2142 UBYTE type_len;
2143
2144 TRACE_FUNCTION( "utl_analyze_pco" );
2145
2146 /*
2147 * initialize values
2148 */
2149 pos = buffer;
2150 pos_len = 0;
2151 *dns1 = 0;
2152 *dns2 = 0;
2153 *gateway = 0;
2154 /*
2155 * check configuration protocol
2156 */
2157 if( (length <= pos_len) ||
2158 !(*pos & 0x80) )
2159 {
2160 return -1;
2161 }
2162
2163 #if 0
2164 /* Table 10.5.154/3GPP TS 24.008 states:
2165 "All other values are interpreded as PPP in this version of the protocol.
2166 so the next check should not be performed
2167 */
2168 if((*pos & 0x07) NEQ ACI_PCO_CONFIG_PROT_PPP)
2169 {
2170 /*
2171 * configuration protocol is not PPP
2172 */
2173 return 0;
2174 }
2175 #endif
2176
2177 pos++;
2178 pos_len++;
2179
2180 /*
2181 * search for IPCP packet
2182 */
2183 while(length > (pos_len + ACI_PCO_IPCP_OVERHEAD))
2184 {
2185 /*
2186 * initialize distance to next packet
2187 */
2188 dist_to_next = *(pos + 2) + 3;
2189 /*
2190 * check for IPCP packet
2191 */
2192 if((*pos EQ ACI_PCO_IPCP_PROT_MSB) &&
2193 (*(pos + 1) EQ ACI_PCO_IPCP_PROT_LSB))
2194 {
2195 /*
2196 * check for correct length field
2197 */
2198 pos += 2;
2199 pos_len += 2;
2200 dist_to_next-= 2;
2201 packet_len = *(pos + 3);
2202 packet_len = packet_len << 8;
2203 packet_len += *(pos + 4);
2204 if((packet_len EQ *pos) &&
2205 (length > (pos_len + packet_len)))
2206 {
2207 pos++;
2208 pos_len++;
2209 dist_to_next--;
2210 /*
2211 * check of code field
2212 */
2213 start_pos = pos_len;
2214 switch(*pos)
2215 {
2216 case ACI_PCO_IPCP_CONF_REQ:
2217 /*
2218 * search for Gateway address
2219 */
2220 pos += 4;
2221 pos_len+= 4;
2222 while((pos_len + 1 - start_pos) < packet_len)
2223 {
2224 type_len = *(pos + 1);
2225 if((*pos EQ ACI_PCO_IPCP_TYPE_IP) &&
2226 (type_len EQ ACI_PCO_IPCP_LENGTH_IP) &&
2227 ((pos_len +
2228 ACI_PCO_IPCP_LENGTH_IP -
2229 start_pos) <= packet_len))
2230 {
2231 *gateway = *(pos + 2);
2232 *gateway = ((*gateway) << 8);
2233 *gateway+= *(pos + 3);
2234 *gateway = ((*gateway) << 8);
2235 *gateway+= *(pos + 4);
2236 *gateway = ((*gateway) << 8);
2237 *gateway+= *(pos + 5);
2238 }
2239 pos += type_len;
2240 pos_len+= type_len;
2241 }
2242 if((pos_len - start_pos) <= packet_len)
2243 {
2244 dist_to_next = packet_len + start_pos - pos_len;
2245 }
2246 else
2247 {
2248 dist_to_next = 0;
2249 pos -= (pos_len - start_pos - packet_len);
2250 pos_len -= (pos_len - start_pos - packet_len);
2251 }
2252 break;
2253
2254 case ACI_PCO_IPCP_CONF_ACK:
2255 case ACI_PCO_IPCP_CONF_NAK:
2256 /*
2257 * search for DNS addresses
2258 */
2259 pos += 4;
2260 pos_len+= 4;
2261 while((pos_len + 1 - start_pos) < packet_len)
2262 {
2263 type_len = *(pos + 1);
2264 if((*pos EQ ACI_PCO_IPCP_TYPE_DNS1) &&
2265 (type_len EQ ACI_PCO_IPCP_LENGTH_DNS1) &&
2266 ((pos_len +
2267 ACI_PCO_IPCP_LENGTH_DNS1 -
2268 start_pos) <= packet_len))
2269 {
2270 *dns1 = *(pos + 2);
2271 *dns1 = ((*dns1) << 8);
2272 *dns1+= *(pos + 3);
2273 *dns1 = ((*dns1) << 8);
2274 *dns1+= *(pos + 4);
2275 *dns1 = ((*dns1) << 8);
2276 *dns1+= *(pos + 5);
2277 }
2278 else if((*pos EQ ACI_PCO_IPCP_TYPE_DNS2) &&
2279 (type_len EQ ACI_PCO_IPCP_LENGTH_DNS2) &&
2280 ((pos_len +
2281 ACI_PCO_IPCP_LENGTH_DNS2 -
2282 start_pos) <= packet_len))
2283 {
2284 *dns2 = *(pos + 2);
2285 *dns2 = ((*dns2) << 8);
2286 *dns2+= *(pos + 3);
2287 *dns2 = ((*dns2) << 8);
2288 *dns2+= *(pos + 4);
2289 *dns2 = ((*dns2) << 8);
2290 *dns2+= *(pos + 5);
2291 }
2292 pos += type_len;
2293 pos_len+= type_len;
2294 }
2295 if((pos_len - start_pos) <= packet_len)
2296 {
2297 dist_to_next = packet_len + start_pos - pos_len;
2298 }
2299 else
2300 {
2301 dist_to_next = 0;
2302 pos -= (pos_len - start_pos - packet_len);
2303 pos_len -= (pos_len - start_pos - packet_len);
2304 }
2305 break;
2306 }
2307 }
2308 }
2309 /*
2310 * go to next packet
2311 */
2312 pos_len+= dist_to_next;
2313 pos += dist_to_next;
2314 }
2315 /*
2316 * return
2317 */
2318 return 0;
2319 } /* utl_analyze_pco() */
2320
2321
2322
2323
2324 GLOBAL int utl_strcasecmp (const char *s1, const char *s2)
2325 {
2326 char c1, c2;
2327 int i;
2328
2329 int len1 = (s1 == NULL) ? 0 : strlen(s1);
2330 int len2 = (s2 == NULL) ? 0 : strlen(s2);
2331
2332 if (len1 > len2)
2333 {
2334 return (1);
2335 }
2336 if(len1 < len2)
2337 {
2338 return (-1);
2339 }
2340 for (i = 0; i < len1; i++)
2341 {
2342 c1 = s1[i];
2343 c2 = s2[i];
2344 if (c1 == c2)
2345 {
2346 continue ;
2347 }
2348 if (c1 >= 'a' AND c1 <= 'z')
2349 {
2350 c1 = c1 - ('a'-'A');
2351 }
2352 if (c2 >= 'a' AND c2 <= 'z')
2353 {
2354 c2 = c2 - ('a'-'A');
2355 }
2356 if (c1 != c2)
2357 {
2358 return (1);
2359 }
2360 }
2361 return (0);
2362 }
2363
2364
2365 #endif /* GPRS */
2366
2367
2368
2369 #if defined (FF_ATI) || defined (FF_BAT)
2370
2371 /*
2372 +--------------------------------------------------------------------+
2373 | PROJECT : GSM-PS (6147) MODULE : ACI_UTIL |
2374 | STATE : code ROUTINE : rci_display_USSD |
2375 +--------------------------------------------------------------------+
2376
2377 PURPOSE : used by rCI_PlusCUSD and utl_cb_percentKSIR
2378 */
2379 GLOBAL void rci_display_USSD (UBYTE srcId,
2380 T_ACI_CUSD_MOD mode,
2381 UBYTE *ussd_str,
2382 UBYTE ussd_len,
2383 BOOL cvtStr,
2384 SHORT dcs )
2385 {
2386 SHORT pos = 0;
2387 USHORT chunksize;
2388 USHORT lenCvtdStr;
2389 CHAR sa[80];
2390
2391
2392 TRACE_FUNCTION("rci_display_USSD()");
2393
2394 pos = sprintf(sa,"+CUSD: ");
2395
2396 if (mode NEQ CUSD_MOD_NotPresent)
2397 {
2398 pos += sprintf(sa+pos,"%d,",mode);
2399 }
2400 else
2401 pos += sprintf(sa+pos,",");
2402
2403 if(ussd_str NEQ NULL)
2404 {
2405 pos += sprintf(sa+pos,"\""); /* beginning double quote */
2406 while (ussd_len)
2407 {
2408 if( cvtStr EQ CONVERT_STRING )
2409 {
2410 chunksize = utl_ussdDtaToTe( ussd_str,
2411 (USHORT)ussd_len,
2412 (UBYTE*)(sa + pos),
2413 sizeof(sa)-pos,
2414 &lenCvtdStr,
2415 (UBYTE)dcs );
2416
2417 pos += lenCvtdStr;
2418 }
2419 else
2420 {
2421 /*
2422 * How much space do we have left in the output array?
2423 */
2424 chunksize=(sizeof(sa)-pos)-1;
2425
2426 if (ussd_len<chunksize)
2427 {
2428 /*
2429 * Remaining data fits within the output array.
2430 */
2431 chunksize=ussd_len;
2432 }
2433 else if (chunksize>3)
2434 {
2435 /*
2436 * If the remaining data will not fit in the output
2437 * array, and we have more than 3 bytes available (which
2438 * we will), make sure that the amount of data output
2439 * divides by 4. This is so we don't split UCS2 characters
2440 * between two lines of output.
2441 */
2442 chunksize &= ~0x3;
2443 }
2444
2445 memcpy(sa+pos,ussd_str,chunksize);
2446
2447 pos += chunksize;
2448
2449 sa[pos]=0;
2450 }
2451 ussd_len-=chunksize;
2452 ussd_str+=chunksize;
2453
2454 if (ussd_len OR (sizeof(sa)-pos) < 10)
2455 {
2456 #ifdef _SIMULATION_
2457 io_sendMessage(srcId, sa, ATI_NORMAL_OUTPUT); /* append CR+LF only for testcase */
2458 #else
2459 io_sendMessage(srcId, sa, ATI_ECHO_OUTPUT); /* normal output a chunk */
2460 #endif
2461 pos=0;
2462 memset(sa, 0, 80);
2463 }
2464 }
2465
2466 pos+=sprintf(sa+pos,"\","); /* ending double quote */
2467
2468 if (dcs EQ ACI_NumParmNotPresent)
2469 {
2470 /* see 07.07: default is 0 */
2471 dcs = 0;
2472 }
2473
2474 pos+=sprintf(sa+pos,"%d",dcs);
2475 }
2476
2477 ci_remTrailCom(sa, pos);
2478 io_sendMessage(srcId, sa, ATI_NORMAL_OUTPUT);
2479 }
2480
2481 /*
2482 ****************************************************************
2483 */
2484 LOCAL void utl_cvtCLIRStat ( UBYTE clirOpt,
2485 UBYTE ssSt,
2486 T_ACI_CLIR_STAT *clirStat )
2487 {
2488 if ( clirOpt EQ KSD_CO_NOT_VALID )
2489 {
2490 /* SS Status of class - T_ACI_KSD_ST */
2491 if ( ssSt EQ KSD_ST_NOT_VALID )
2492 *clirStat = CLIR_STAT_Unknown;
2493 else if ( ssSt & SSS_P )
2494 *clirStat = CLIR_STAT_Permanent;
2495 else
2496 *clirStat = CLIR_STAT_NotProv;
2497 }
2498 else
2499 {
2500 switch ( clirOpt )
2501 {
2502 case( CLIR_OPT_PERMANENT ):
2503 *clirStat = CLIR_STAT_Permanent;
2504 break;
2505
2506 case( CLIR_OPT_TEMPORARY ):
2507 *clirStat = CLIR_STAT_RestrictTemp;
2508 break;
2509
2510 case( CLIR_OPT_ALLOWED ):
2511 *clirStat = CLIR_STAT_AllowTemp;
2512 break;
2513
2514 default:
2515 *clirStat = CLIR_STAT_Unknown;
2516 break;
2517 }
2518 }
2519 }
2520
2521 /*
2522 ****************************************************************
2523 */
2524 LOCAL void utl_cb_ccbs( UBYTE srcId, T_ACI_KSIR * ksStat )
2525 {
2526 T_ACI_CCBS_SET *CCBS_Setting = NULL;
2527
2528 T_ACI_CCBS_STAT status;
2529 T_basicService basicServ;
2530 int i;
2531 T_CC_FEAT *ccbs_features;
2532
2533 TRACE_FUNCTION("utl_cb_ccbs()");
2534
2535 /* SS Status of CCBS */
2536 if (ksStat->ir.rKSCC.ssSt EQ KSD_ST_NOT_VALID)
2537 status = CCBS_STAT_NotPresent;
2538 else if (!(ksStat->ir.rKSCC.ssSt & SSS_P))
2539 status = CCBS_STAT_NotProvisioned;
2540 else if (ksStat->ir.rKSCC.ssSt & SSS_A)
2541 status = CCBS_STAT_Active;
2542 else
2543 status = CCBS_STAT_Provisioned;
2544
2545 ACI_MALLOC(CCBS_Setting, sizeof(T_ACI_CCBS_SET));
2546
2547 /* CCBS_Setting infos */
2548 if (!ksStat->ir.rKSCC.c_ccFeatLst)
2549 {
2550 TRACE_EVENT("KSD_CMD_CCBS: no feature list");
2551
2552 if (aci_cmd_src_mode_get(srcId) EQ CMD_MODE_ATI)
2553 {
2554 rCI_PercentCCBS(CCBS_IND_IrgtResult,
2555 status,
2556 CCBS_Setting,
2557 TRUE);
2558 }
2559 #ifdef FF_BAT
2560 else /* CMD_MODE_BAT */
2561 {
2562 rBAT_PercentCCBS(CCBS_IND_IrgtResult,
2563 status,
2564 CCBS_Setting,
2565 TRUE);
2566 }
2567 #endif
2568 return;
2569 }
2570
2571 for (i=0; i<ksStat->ir.rKSCC.c_ccFeatLst; i++)
2572 {
2573 ccbs_features = ksStat->ir.rKSCC.ccFeatLst + i;
2574
2575 memcpy( CCBS_Setting->number, ccbs_features->num, MAX_B_SUBSCR_NUM_LEN);
2576 memcpy( CCBS_Setting->subaddr, ccbs_features->sub, MAX_SUBADDR_LEN);
2577
2578 CCBS_Setting->type.npi = ccbs_features->npi NEQ 0xFF
2579 ? (T_ACI_TOA_NPI)ccbs_features->npi
2580 : NPI_NotPresent;
2581 CCBS_Setting->type.ton = ccbs_features->ton NEQ 0xFF
2582 ? (T_ACI_TOA_TON)ccbs_features->ton
2583 : TON_NotPresent;
2584 CCBS_Setting->satype.tos = ccbs_features->tos NEQ 0xFF
2585 ? (T_ACI_TOS_TOS)ccbs_features->tos
2586 : TOS_NotPresent;
2587 CCBS_Setting->satype.oe = ccbs_features->oe NEQ 0xFF
2588 ? (T_ACI_TOS_OE)ccbs_features->oe
2589 : OE_NotPresent;
2590
2591 if( ccbs_features->bsTp EQ BS_TELE_SRV )
2592 {
2593 basicServ.v_teleservice = TRUE;
2594 basicServ.v_bearerService = FALSE;
2595 basicServ.teleservice = ccbs_features->bsCd;
2596 }
2597 else /* if( p_servType EQ BS_BEAR_SRV ) */
2598 {
2599 basicServ.v_bearerService = TRUE;
2600 basicServ.v_teleservice = FALSE;
2601 basicServ.bearerService = ccbs_features->bsCd;
2602 }
2603
2604 CCBS_Setting->class_type = cmhSS_GetClass( &basicServ );
2605
2606 CCBS_Setting->idx = ccbs_features->idx NEQ 0xFF
2607 ? ccbs_features->idx
2608 : ACI_NumParmNotPresent;
2609
2610 CCBS_Setting->alrtPtn = ALPT_NotPresent;
2611
2612 if (aci_cmd_src_mode_get(srcId) EQ CMD_MODE_ATI)
2613 {
2614 rCI_PercentCCBS(CCBS_IND_IrgtResult,
2615 status,
2616 CCBS_Setting,
2617 TRUE);
2618 }
2619 #ifdef FF_BAT
2620 else /* CMD_MODE_BAT */
2621 {
2622 rBAT_PercentCCBS(CCBS_IND_IrgtResult,
2623 status,
2624 CCBS_Setting,
2625 TRUE);
2626 }
2627 #endif
2628 }
2629
2630 ACI_MFREE( CCBS_Setting );
2631 }
2632
2633 /*
2634 ****************************************************************
2635 */
2636 LOCAL void utl_cb_callwaiting( UBYTE srcId, T_ACI_KSIR *ksStat )
2637 {
2638 T_ACI_CLSSTAT classStat;
2639 UBYTE idx;
2640 T_ACI_TOA type;
2641
2642 TRACE_FUNCTION("utl_cb_callwaiting()");
2643
2644 if ( ksStat->ir.rKSCW.opCd NEQ KSD_OP_IRGT )
2645 return;
2646
2647 /* SS Status of class - T_ACI_KSD_ST */
2648 if ( ksStat->ir.rKSCW.ssSt EQ KSD_ST_NOT_VALID )
2649 {
2650 classStat.status = STATUS_NotPresent;
2651 }
2652 else if ( ksStat->ir.rKSCW.ssSt & KSD_ST_A )
2653 {
2654 classStat.status = STATUS_Active;
2655 }
2656 else
2657 {
2658 classStat.status = STATUS_NotActive;
2659 }
2660
2661 /* init parameter type: */
2662 type.npi = NPI_NotPresent;
2663 type.ton = TON_NotPresent;
2664
2665 for( idx = 0; idx < ksStat->ir.rKSCW.c_cwBSGLst; idx++ )
2666 {
2667 /* type of class */
2668 classStat.class_type = cmhSS_GetClassType(ksStat->ir.rKSCW.cwBSGLst[idx].bsTp,
2669 ksStat->ir.rKSCW.cwBSGLst[idx].bsCd);
2670 if (aci_cmd_src_mode_get(srcId) EQ CMD_MODE_ATI)
2671 {
2672 }
2673 else /* CMD_MODE_BAT */
2674 {
2675 }
2676
2677 rCI_PlusCCWA(&classStat,"\0", &type, PRES_NOT_PRES, CLASS_NotPresent, NULL);
2678 }
2679 }
2680
2681 /*
2682 ****************************************************************
2683 */
2684 LOCAL void utl_cb_lineidentification( UBYTE srcId, T_ACI_KSIR * ksStat )
2685 {
2686 T_ACI_CLIP_STAT clipStat;
2687 T_ACI_CLIR_MOD clirMode;
2688 T_ACI_CLIR_STAT clirStat;
2689 T_ACI_COLP_STAT colpStat;
2690 T_ACI_COLR_STAT colrStat;
2691
2692 TRACE_FUNCTION("utl_cb_lineidentification()");
2693
2694 if ( ksStat->ir.rKSCL.opCd NEQ KSD_OP_IRGT )
2695 return;
2696
2697 switch ( ksStat->ir.rKSCL.ssCd )
2698 {
2699 case KSD_SS_CLIP:
2700 {
2701 /* SS Status of class - T_ACI_KSD_ST */
2702 if ( ksStat->ir.rKSCL.ssSt EQ KSD_ST_NOT_VALID )
2703 clipStat = CLIP_STAT_Unknown;
2704 else if ( ksStat->ir.rKSCL.ssSt & SSS_P )
2705 clipStat = CLIP_STAT_Prov;
2706 else
2707 clipStat = CLIP_STAT_NotProv;
2708
2709 if (aci_cmd_src_mode_get(srcId) EQ CMD_MODE_ATI)
2710 {
2711 rCI_PlusCLIP ( clipStat, NULL, NULL, PRES_NOT_PRES, NULL, NULL, NULL );
2712 }
2713 #ifdef FF_BAT
2714 else /* CMD_MODE_BAT */
2715 {
2716 rBAT_PlusCLIP ( clipStat, NULL, NULL, PRES_NOT_PRES, NULL, NULL, NULL );
2717 }
2718 #endif
2719 break;
2720 }
2721 case KSD_SS_CLIR:
2722 {
2723 clirMode = ksStat->ir.rKSCL.mode;
2724 utl_cvtCLIRStat(ksStat->ir.rKSCL.clirOpt,
2725 ksStat->ir.rKSCL.ssSt,
2726 &clirStat);
2727 if (aci_cmd_src_mode_get(srcId) EQ CMD_MODE_ATI)
2728 {
2729 rCI_PlusCLIR (clirMode, clirStat);
2730 }
2731 #ifdef FF_BAT
2732 else /* CMD_MODE_BAT */
2733 {
2734 rBAT_PlusCLIR (clirMode, clirStat);
2735 }
2736 #endif
2737 break;
2738 }
2739 case KSD_SS_COLP:
2740 {
2741 /* SS Status of class - T_ACI_KSD_ST */
2742 if ( ksStat->ir.rKSCL.ssSt EQ KSD_ST_NOT_VALID )
2743 colpStat = COLP_STAT_Unknown;
2744 else if ( ksStat->ir.rKSCL.ssSt & SSS_P )
2745 colpStat = COLP_STAT_Prov;
2746 else
2747 colpStat = COLP_STAT_NotProv;
2748
2749 if (aci_cmd_src_mode_get(srcId) EQ CMD_MODE_ATI)
2750 {
2751 rCI_PlusCOLP ( colpStat, NULL, NULL, NULL, NULL, NULL );
2752 }
2753 #ifdef FF_BAT
2754 else /* CMD_MODE_BAT */
2755 {
2756 rBAT_PlusCOLP ( colpStat, NULL, NULL, NULL, NULL, NULL );
2757 }
2758 #endif
2759 break;
2760 }
2761 case KSD_SS_COLR:
2762 {
2763 /* SS Status of class - T_ACI_KSD_ST */
2764 if ( ksStat->ir.rKSCL.ssSt EQ KSD_ST_NOT_VALID )
2765 colrStat = COLR_STAT_Unknown;
2766 else if ( ksStat->ir.rKSCL.ssSt & SSS_P )
2767 colrStat = COLR_STAT_Prov;
2768 else
2769 colrStat = COLR_STAT_NotProv;
2770
2771 if (aci_cmd_src_mode_get(srcId) EQ CMD_MODE_ATI)
2772 {
2773 rCI_PercentCOLR(colrStat);
2774 }
2775 #ifdef FF_BAT
2776 else /* CMD_MODE_BAT */
2777 {
2778 rBAT_PercentCOLR(colrStat);
2779 }
2780 #endif
2781 break;
2782 }
2783 }
2784 }
2785
2786 /*
2787 ****************************************************************
2788 */
2789 LOCAL void utl_cb_callforwarding( UBYTE srcId, T_ACI_KSIR * ksStat )
2790 {
2791 T_ACI_CCFC_SET ccfcSetting;
2792 UBYTE idx;
2793
2794 TRACE_FUNCTION("utl_cb_callforwarding()");
2795
2796 if ( ksStat->ir.rKSCF.opCd NEQ KSD_OP_IRGT )
2797 return;
2798
2799 for( idx = 0; idx < ksStat->ir.rKSCF.c_cfFeatLst; idx++ )
2800 {
2801 /* SS Status of class - T_ACI_KSD_ST */
2802 if ( ksStat->ir.rKSCF.cfFeatLst[idx].ssSt EQ KSD_ST_NOT_VALID )
2803 ccfcSetting.clsstat.status = STATUS_NotPresent;
2804 else if ( ksStat->ir.rKSCF.cfFeatLst[idx].ssSt & SSS_A )
2805 ccfcSetting.clsstat.status = STATUS_Active;
2806 else
2807 ccfcSetting.clsstat.status = STATUS_NotActive;
2808 /* type of class */
2809 if ( ksStat->ir.rKSCF.cfFeatLst[idx].bsTp EQ KSD_BS_TP_None
2810 AND ksStat->ir.rKSCF.cfFeatLst[idx].bsCd EQ KSD_BS_TeleBearerUnknown)
2811 {
2812 if (ccfcSetting.clsstat.status EQ STATUS_NotPresent)
2813 ccfcSetting.clsstat.class_type = CLASS_None;
2814 else
2815 ccfcSetting.clsstat.class_type = CLASS_VceDatFax;
2816 }
2817 else
2818 ccfcSetting.clsstat.class_type = cmhSS_GetClassType(ksStat->ir.rKSCF.cfFeatLst[idx].bsTp,
2819 ksStat->ir.rKSCF.cfFeatLst[idx].bsCd);
2820 /* number */
2821 strcpy(ccfcSetting.number, (char *)ksStat->ir.rKSCF.cfFeatLst[idx].num);
2822 if ( !strlen ( ccfcSetting.number ))
2823 {
2824 ccfcSetting.type.npi = NPI_NotPresent;
2825 ccfcSetting.type.ton = TON_NotPresent;
2826 ccfcSetting.subaddr[0] = 0x0;
2827 ccfcSetting.satype.tos = TOS_NotPresent;
2828 ccfcSetting.satype.oe = OE_NotPresent;
2829 ccfcSetting.time = ACI_NumParmNotPresent;
2830 }
2831 else
2832 {
2833 T_CF_FEAT *cfFeat = &ksStat->ir.rKSCF.cfFeatLst[idx];
2834 /* toa */
2835 ccfcSetting.type.ton = cfFeat->ton NEQ 0xFF
2836 ? (T_ACI_TOA_TON)cfFeat->ton
2837 : TON_NotPresent;
2838 ccfcSetting.type.npi = cfFeat->npi NEQ 0xFF
2839 ? (T_ACI_TOA_NPI)cfFeat->npi
2840 : NPI_NotPresent;
2841 /* subaddr */
2842 strcpy(ccfcSetting.subaddr, (char *)ksStat->ir.rKSCF.cfFeatLst[idx].sub);
2843 /* tos */
2844 ccfcSetting.satype.tos = cfFeat->tos NEQ 0xFF
2845 ? (T_ACI_TOS_TOS)cfFeat->tos
2846 : TOS_NotPresent;
2847 ccfcSetting.satype.oe = cfFeat->oe NEQ 0xFF
2848 ? (T_ACI_TOS_OE)cfFeat->oe
2849 : OE_NotPresent;
2850 /* time */
2851 ccfcSetting.time = cfFeat->time NEQ 0xFF
2852 ? cfFeat->time
2853 : ACI_NumParmNotPresent;
2854 }
2855 if (aci_cmd_src_mode_get(srcId) EQ CMD_MODE_ATI)
2856 {
2857 rCI_PlusCCFC (&ccfcSetting);
2858 }
2859 #ifdef FF_BAT
2860 else
2861 {
2862 rBAT_PlusCCFC (&ccfcSetting);
2863 }
2864 #endif
2865 }
2866 }
2867
2868 /*
2869 ****************************************************************
2870 */
2871 LOCAL void utl_cb_callbarring( UBYTE srcId, T_ACI_KSIR * ksStat )
2872 {
2873 T_ACI_CLSSTAT classStat;
2874 UBYTE idx;
2875
2876 TRACE_FUNCTION("utl_cb_callbarring()");
2877
2878 if (ksStat->ir.rKSCB.opCd NEQ KSD_OP_IRGT)
2879 {
2880 return;
2881 }
2882 for (idx = 0; idx < ksStat->ir.rKSCB.c_cbInfoLst; idx++)
2883 {
2884 /* type of class */
2885 classStat.class_type = cmhSS_GetCbClassType(ksStat->ir.rKSCB.cbInfoLst[idx].bsTp,
2886 ksStat->ir.rKSCB.cbInfoLst[idx].bsCd);
2887
2888 /* SS Status of class */
2889 if (classStat.class_type EQ CLASS_VceDatFaxSms
2890 OR classStat.class_type EQ CLASS_None)
2891 {
2892 classStat.status = STATUS_NotActive;
2893 }
2894 else
2895 {
2896 classStat.status = STATUS_Active;
2897 }
2898 if (aci_cmd_src_mode_get(srcId) EQ CMD_MODE_ATI)
2899 {
2900 rCI_PlusCLCK(&classStat);
2901 }
2902 #ifdef FF_BAT
2903 else /* CMD_MODE_BAT */
2904 {
2905 rBAT_PlusCLCK(&classStat);
2906 }
2907 #endif
2908 }
2909 }
2910
2911 /*
2912 ****************************************************************
2913 */
2914 LOCAL void utl_cb_imei( UBYTE srcId, T_ACI_KSIR * ksStat )
2915 {
2916 TRACE_FUNCTION("utl_cb_imei()");
2917
2918 sprintf ( g_sa,
2919 "%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d",
2920 (ksStat->ir.rKSIMEI.tac1 >> 4) & 0x0F,
2921 ksStat->ir.rKSIMEI.tac1 & 0x0F,
2922
2923 (ksStat->ir.rKSIMEI.tac2 >> 4) & 0x0F,
2924 ksStat->ir.rKSIMEI.tac2 & 0x0F,
2925
2926 (ksStat->ir.rKSIMEI.tac3 >> 4) & 0x0F,
2927 ksStat->ir.rKSIMEI.tac3 & 0x0F,
2928
2929 (ksStat->ir.rKSIMEI.fac >> 4) & 0x0F,
2930 ksStat->ir.rKSIMEI.fac & 0x0F,
2931
2932 (ksStat->ir.rKSIMEI.snr1 >> 4) & 0x0F,
2933 ksStat->ir.rKSIMEI.snr1 & 0x0F,
2934
2935 (ksStat->ir.rKSIMEI.snr2 >> 4) & 0x0F,
2936 ksStat->ir.rKSIMEI.snr2 & 0x0F,
2937
2938 (ksStat->ir.rKSIMEI.snr3 >> 4) & 0x0F,
2939 ksStat->ir.rKSIMEI.snr3 & 0x0F,
2940
2941 ksStat->ir.rKSIMEI.cd,
2942 (ksStat->ir.rKSIMEI.svn >> 4) & 0x0F,
2943 ksStat->ir.rKSIMEI.svn & 0x0F );
2944
2945 io_sendMessage ( srcId, g_sa, ATI_NORMAL_OUTPUT );
2946 }
2947
2948 /*
2949 +--------------------------------------------------------------------+
2950 | PROJECT : GSM-F&D (8411) MODULE : ACI_UTIL |
2951 | STATE : code ROUTINE : |
2952 +--------------------------------------------------------------------+
2953
2954 PURPOSE : handles PercentKSIR call back
2955
2956 */
2957 GLOBAL void utl_cb_percentKSIR (U8 srcId, T_ACI_KSIR *ksStat)
2958 {
2959 T_ACI_USSD_DATA ussd;
2960
2961 TRACE_FUNCTION("utl_cb_percentKSIR()");
2962
2963 switch (ksStat->ksdCmd)
2964 {
2965 case (KSD_CMD_IMEI):
2966 if (aci_cmd_src_mode_get(srcId) EQ CMD_MODE_ATI)
2967 {
2968 utl_cb_imei(srcId, ksStat);
2969 }
2970 #ifdef FF_BAT
2971 else /* CMD_MODE_BAT */
2972 {
2973 rBAT_PercentIMEI(&(ksStat->ir.rKSIMEI));
2974 }
2975 #endif
2976 break;
2977
2978 case (KSD_CMD_CB):
2979 utl_cb_callbarring(srcId, ksStat);
2980 break;
2981
2982 case (KSD_CMD_CF):
2983 utl_cb_callforwarding(srcId, ksStat);
2984 break;
2985
2986 case (KSD_CMD_CL):
2987 utl_cb_lineidentification(srcId, ksStat);
2988 break;
2989
2990 case (KSD_CMD_CW):
2991 utl_cb_callwaiting(srcId, ksStat);
2992 break;
2993
2994 case (KSD_CMD_PWD):
2995 /* no specific answer to +CPWD which is the corresponding AT cmd */
2996 break;
2997
2998 case (KSD_CMD_UBLK):
2999 /* no specific answer to +CPIN which is the corresponding AT cmd */
3000 break;
3001
3002 case (KSD_CMD_USSD):
3003 if (aci_cmd_src_mode_get(srcId) EQ CMD_MODE_ATI)
3004 {
3005 rci_display_USSD(srcId,
3006 ksStat->ir.rKSUS.mode,
3007 (UBYTE *)ksStat->ir.rKSUS.ussd,
3008 ksStat->ir.rKSUS.len,
3009 FALSE, /* means DO NOT CONVERT STRING */
3010 ksStat->ir.rKSUS.dcs);
3011 }
3012 #ifdef FF_BAT
3013 else /* CMD_MODE_BAT */
3014 {
3015 ussd.len = ksStat->ir.rKSUS.len;
3016 memcpy (ussd.data, (UBYTE *)ksStat->ir.rKSUS.ussd, ussd.len);
3017 rBAT_PlusCUSD(ksStat->ir.rKSUS.mode, &ussd, ksStat->ir.rKSUS.dcs);
3018 }
3019 #endif
3020 break;
3021
3022 case (KSD_CMD_CCBS):
3023 utl_cb_ccbs(srcId, ksStat);
3024 break;
3025 }
3026
3027 }
3028 #endif /* defined (FF_ATI) || defined (FF_BAT) */