comparison src/aci2/mfw/mfw_cnvt.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: MMI-Framework (8417) $Workfile:: mfw_cnvt.c $|
4 | $Author:: Es $ CONDAT GmbH $Revision:: 1 $|
5 | CREATED: 03.08.00 $Modtime:: 03.08.00 18:57 $|
6 | STATE : code |
7 +--------------------------------------------------------------------+
8
9 MODULE : MFW_CNVT
10
11 PURPOSE : string convertion
12
13 EXPORT :
14
15 TO DO :
16
17 $History:: mfw_cnvt.c $
18 */
19
20 #define ENTITY_MFW
21
22 #include <string.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 #if defined (NEW_FRAME)
27
28 #include "typedefs.h"
29 #include "vsi.h"
30 #include "pei.h"
31 #include "custom.h"
32 #include "gsm.h"
33
34 #else
35
36 #include "STDDEFS.H"
37 #include "custom.h"
38 #include "gsm.h"
39 #include "vsi.h"
40
41 #endif
42
43 #include "mfw_mfw.h"
44 #include "mfw_phb.h"
45 #include "mfw_phbi.h"
46 #include "mfw_cm.h"
47 #include "mfw_cmi.h"
48 #include "mfw_nm.h"
49 #include "mfw_sim.h"
50 #include "mfw_sima.h"
51 #include "mfw_nmi.h"
52 #include "mfw_simi.h"
53 #include "mfw_win.h"
54
55 #include "mfw_tim.h"
56
57 #include "ksd.h"
58 #include "psa.h"
59
60 #if defined (FAX_AND_DATA)
61 #include "aci_fd.h"
62 #endif
63
64 #include "cmh.h"
65 #include "phb.h"
66 #include "cmh_phb.h"
67
68 #include "mfw_ss.h"
69 #include "mfw_ssi.h"
70
71 #define PASSED 0
72 #define FAILED 1
73 #define LEN_OFFSET 1
74 /*
75 +---------------------------------------------------------------+
76 | PROJECT: MMI-Framework (8417) MODULE: MFW_CNVT |
77 | STATE : code ROUTINE: mfw_getStrMode |
78 +---------------------------------------------------------------+
79
80 PURPOSE : This function is used to request the coding format
81 of a given string. The return value is
82 "MFW_DCS_7bits" or " MFW_DCS_UCS2".
83
84 */
85
86 T_MFW_DCS mfw_getStrMode( UBYTE *str, // alpha string in MFW
87 UBYTE len) // length of alpha string
88
89 {
90
91 if( str[0] == 0x80)
92 return MFW_DCS_UCS2;
93 else
94 return MFW_DCS_7bits;
95 }
96
97 /*
98 +---------------------------------------------------------------+
99 | PROJECT: MMI-Framework (8417) MODULE: MFW_CNVT |
100 | STATE : code ROUTINE: mfw_SIM2GsmStr |
101 +---------------------------------------------------------------+
102
103 PURPOSE : This function is used to convert the MFW alpha
104 formatted string (consisting of alpha name and
105 length of name in bytes) to a GSM default string
106 (including zero-termination) and to additionally
107 set the @ code to 0x80.
108
109 */
110
111 T_MFW mfw_SIM2GsmStr( UBYTE inLen,
112 UBYTE *inMfwStr,
113 UBYTE maxOutSize, /* in byte */
114 UBYTE *outGsmStr )
115
116 {
117 int i;
118 UBYTE len;
119
120 if (!inLen OR !maxOutSize)
121 return FAILED; /* string is zero length */
122
123 if (*inMfwStr EQ 0x80) /* input UCS, output GSM default */
124 {
125 len = inLen / 2; /* GSM string is half length of unicode string */
126 for( i=0; i<MINIMUM(len,maxOutSize-1); i++ )
127 {
128 if (inMfwStr[(i*2)+2] == 0x00)
129 * (outGsmStr + i) = 0x80;
130 else
131 * (outGsmStr + i) = inMfwStr[(i*2)+2]; /* copy every 2nd byte */
132 }
133 outGsmStr[i] = '\0';
134 return PASSED;
135 }
136 else /* input GSM default, output GSM default */
137 {
138 for( i=0; i<MINIMUM(inLen,maxOutSize-1); i++ )
139 {
140 if (inMfwStr[i] EQ 0x00)
141 * (outGsmStr + i) = 0x80;
142 else
143 * (outGsmStr + i) = inMfwStr[i];
144 }
145 outGsmStr[i] = '\0';
146 return PASSED;
147 }
148
149 }
150
151 /*
152 +---------------------------------------------------------------+
153 | PROJECT: MMI-Framework (8417) MODULE: MFW_CNVT |
154 | STATE : code ROUTINE: mfw_SIM2UcsStr |
155 +---------------------------------------------------------------+
156
157 PURPOSE : This function is used to convert the MFW alpha
158 formatted string to a unicode string. The first
159 two bytes of this unicode string indicates the
160 number of characters in the string.
161
162 */
163
164 T_MFW mfw_SIM2UcsStr( UBYTE inLen,
165 UBYTE* inMfwStr,
166 UBYTE maxOutSize, /* in short */
167 U16* outUcsStr)
168
169 {
170 int i;
171 short cnt;
172
173 if (!inLen OR !maxOutSize)
174 return FAILED;
175
176 if (inMfwStr[0] EQ 0x80) /* input UCS, output UCS */
177 {
178 TRACE_FUNCTION("First byte is indeed 0x80");
179 //inMfwStr++;
180 inLen--;
181
182 // NOTE: do not add '\0' termination!
183 // len should not include termination
184 cnt = 1;
185 for( i=0; i<MINIMUM(inLen/2,maxOutSize-1); i++ )
186 {
187 outUcsStr[ i + LEN_OFFSET] = ((U16)inMfwStr[cnt] << 8)&0xFF00 + ((U16)inMfwStr[cnt + 1])&0xFF;
188 cnt += 2;
189 }
190 outUcsStr[0] = i;
191 return PASSED;
192 }
193 else /* input GSM default, output UCS */
194 {
195 for( i=0; i<MINIMUM(inLen,maxOutSize-1); i++ )
196 * (outUcsStr + i + LEN_OFFSET) = (U16) inMfwStr[i];
197
198 outUcsStr[0] = i; /* length of unicode string */
199 return PASSED;
200 }
201 }
202
203 /*
204 +---------------------------------------------------------------+
205 | PROJECT: MMI-Framework (8417) MODULE: MFW_CNVT |
206 | STATE : code ROUTINE: mfw_Gsm2SIMStr |
207 +---------------------------------------------------------------+
208
209 PURPOSE : This function is used to convert a zero-terminated
210 GSM default string ( @ code is 0x80) to a MFW
211 alpha formatted string (consisting of alpha name
212 and length of name in bytes and @ code is 0x00).
213 The MFW alpha format is dependent on the parameter "outMode"
214 "outMode" is set to either " MFW_DCS_7bits" or " MFW_DCS_UCS2"
215
216 GW-SPR#762- Increased array size - required for larger phonebook entries (>40 chars).
217 */
218
219 #define MAX_CONVERT_LEN 255
220 T_MFW mfw_Gsm2SIMStr( T_MFW_DCS outMode,
221 UBYTE *inGsmStr,
222 UBYTE maxOutSize,
223 UBYTE *outMfwStr,
224 UBYTE *outLen )
225 {
226
227 UBYTE temp_str[MAX_CONVERT_LEN];
228 int i;
229 UBYTE len = (UBYTE) strlen( (char *)inGsmStr );
230 char GSM_char;/*SPR2175*/
231
232 /* copy string to local storage */
233 if (len > MAX_CONVERT_LEN)
234 len = MAX_CONVERT_LEN;
235 memcpy( temp_str,inGsmStr,len );
236
237 if( outMode EQ MFW_DCS_7bits )
238 {
239 /* write to outMfwStr */
240 for( i=0; i<MINIMUM(len,maxOutSize); i++ )
241 { /*SPR2175, convert to GSM encoding*/
242 GSM_char= ATB_char_GSM( temp_str[i] );
243 temp_str[i]= GSM_char;
244 * (outMfwStr + i) = temp_str[i];
245 }
246 /* write length of name to outLen */
247 *outLen = len;
248 return PASSED;
249 }
250 else if( outMode EQ MFW_DCS_UCS2 )
251 {
252 /* write to outMfwStr */
253 outMfwStr[0] = 0x80;
254 for( i=0; i<MINIMUM(len,maxOutSize-1); i++ )
255 {
256 if( temp_str[i] EQ 0x80 ) /* check for occurance of @ */
257 temp_str[i] = 0x00;
258 * (outMfwStr + (i*2) + 1) = 0x00;
259 * (outMfwStr + (i*2) + 2) = temp_str[i];
260 }
261 /* write length of name to outLen */
262 *outLen = len*2 + 1;
263 return PASSED;
264 }
265 else
266 {
267 TRACE_EVENT ("mfw_Gsm2SIMStr() - outMode is not valid");
268 return FAILED;
269 }
270
271 // return PASSED; // RAVI
272 }
273
274 /*
275 +---------------------------------------------------------------+
276 | PROJECT: MMI-Framework (8417) MODULE: MFW_CNVT |
277 | STATE : code ROUTINE: mfw_Ucs2SIMStr |
278 +---------------------------------------------------------------+
279
280 PURPOSE : This function is used to convert a unicode string
281 to MFW alpha format. The MFW alpha format is
282 dependent on the parameter "outMode". "outMode"
283 is " MFW_DCS_7bits" or " MFW_DCS_UCS2".
284
285 */
286
287 T_MFW mfw_Ucs2SIMStr( T_MFW_DCS outMode,
288 U16 *inDcsStr,
289 UBYTE maxOutSize,
290 UBYTE *outMfwStr,
291 UBYTE *outLen )
292 {
293 int i;
294 U16 len;
295
296 len = inDcsStr[0];
297
298 if( outMode EQ MFW_DCS_7bits )
299 {
300 /* write to outMfwStr */
301 for( i=0; i<MINIMUM(len,maxOutSize); i++ )
302 {
303 * (outMfwStr + (i*2) + 1) = (UBYTE) (inDcsStr[i+1] & 0xff);
304 * (outMfwStr + (i*2)) = (UBYTE) ((inDcsStr[i+1] & 0xff00) >> 8);
305 }
306 /* write length of name to outLen */
307 *outLen = len * 2;
308
309 return PASSED;
310 }
311 else if( outMode EQ MFW_DCS_UCS2 )
312 {
313 /* write to outMfwStr */
314 outMfwStr[0] = 0x80;
315 for( i=0; i<len; i++)
316 {/*MC, SPR 1752, bytes are no longer swapped*/
317 * (outMfwStr + (i*2) + 1) = (UBYTE) (inDcsStr[i+1] & 0xff);
318 * (outMfwStr + (i*2) + 2) = (UBYTE) ((inDcsStr[i+1] & 0xff00) >> 8);
319 }
320 /* write length to outLen */
321 *outLen = (len*2) + 1;
322
323 return PASSED;
324
325 }
326 else /* string does not require conversion to unicode */
327 {
328 TRACE_EVENT ("mfw_Ucs2SIMStr() - outMode is not valid");
329 return FAILED;
330 }
331
332 // return PASSED; // RAVI
333 }
334
335 /*CONQUEST 5992(related) MC added function to convert GSM string to ASCII*/
336 static const char gsm_2_ascii_table[128] = { 64, 156, 36, 157, 138, 130, 151, 141, 149, 128,
337 10, 2 , 7, 32, 143, 134, 4, 95, 232, 226, 239, 234, 227, 5, 228,
338 233, 240, 32, 146, 145, 225, 144, 32, 33, 34, 35, 1, 37, 38, 39,
339 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
340 55, 56, 57, 58, 59, 60, 61, 62, 63, 173, 65, 66, 67, 68, 69,
341 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
342 85, 86, 87, 88, 89, 90, 142, 153, 165, 154, 06, 168, 97, 98, 99,
343 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
344 115, 116, 117, 118, 119, 120, 121, 122, 132, 148, 164, 129, 133};
345 /* PATCH JPS 29.09 END */
346
347 /*
348 +---------------------------------------------------------------------------+
349 | PROJECT : MMI-Framework (8417) MODULE : MFW_SMS |
350 | STATE : code ROUTINE : mfw_GSM_2_ASCII |
351 +---------------------------------------------------------------------------+
352
353 PURPOSE : copy the index and status of a short message
354
355 */
356 void mfw_GSM_2_ASCII(UBYTE* gsm_string, UBYTE* ascii_string, SHORT length)
357 { int i;
358
359 for(i=0;i<length;i++)
360 {
361 ascii_string[i] = gsm_2_ascii_table[gsm_string[i]];
362 }
363 }
364