comparison src/ui3/mfw/mfw_cnvt.c @ 420:e8ddbb0837ed

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