comparison g23m/condat/ms/src/mfw/mfw_ffs.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: MMI-Framework (8417) $Workfile:: mfw_ffs.c $|
4 | $Author:: $Revision:: 1 $|
5 | CREATED: $Modtime:: $|
6 | STATE : code |
7 +--------------------------------------------------------------------+
8
9 MODULE : mfw_ffs
10
11 PURPOSE : This module contains FFS Interface functions.
12
13 HISTORY:
14
15 xrashmic 22 Aug, 2004 MMI-SPR-32798
16 Adding the support for screen capture using a dynamically assigned key.
17
18 Apr 14, 2005 REF: CRR 29991 xpradipg
19 Description: Optimisation 5: Remove the static allocation and use dynamic
20 allocation/ deallocation for pb_list and black_list
21 Solution: The static definition is removed and replaced with the dynamic
22 allocation
23
24 Oct 19, 2004 REF: CRR MMI-SPR-26002 xkundadu
25 Issue description: Golite booting problem.
26 Solution: If the FFS is not formatted, prevent writing into FFS.
27
28 Aug 25, 2004 REF: CRR 20655 xnkulkar
29 Description: Voice Memo functionality not working
30 Solution: The voice recording functionality was failing because
31 " mmi" folder is not present. As a solution, we create the
32 "mmi" folder and then proceed with recording.
33 */
34
35 #define ENTITY_MFW
36
37 #include <stdio.h>
38 #include <string.h>
39 #include <stdlib.h>
40
41 #if defined (NEW_FRAME)
42
43 #include "typedefs.h"
44 #include "vsi.h"
45 #include "pei.h"
46 #include "custom.h"
47 #include "gsm.h"
48
49 #else
50
51 #include "STDDEFS.H"
52 #include "custom.h"
53 #include "gsm.h"
54 #include "vsi.h"
55
56 #endif
57
58 #include "prim.h"
59
60 #include "custom.h"
61 #include "gsm.h"
62 #include "vsi.h"
63
64 #include "mfw_sys.h"
65 #include "prim.h"
66
67 #include "vsi.h"
68
69 #include "mfw_mfw.h"
70 #include "mfw_win.h"
71
72 #include "mfw_kbd.h"
73 /* SPR#1428 - SH - New Editor changes */
74 #ifndef NEW_EDITOR
75 #include "mfw_edt.h"
76 #endif
77 #ifdef WIN32
78 #include "MmiMain.h"
79 #endif
80 #include "mfw_lng.h"
81 #include "mfw_tim.h"
82 #include "mfw_icn.h"
83 #include "mfw_mnu.h"
84 #include "mfw_phb.h"
85 #include "mfw_cm.h"
86 #include "mfw_sim.h"
87 #include "mfw_nm.h"
88 #include "mfw_phb.h"
89 #include "ksd.h"
90 #include "psa.h"
91 #include "mfw_sms.h"
92 #include "mfw_sat.h"
93
94 #include "mfw_ffs.h"
95
96 #include "dspl.h"
97
98 #include "gdi.h" //ES!!
99
100 #define hCommACI _ENTITY_PREFIXED(hCommACI)
101
102 #if( BOARD == 61 )
103 #ifdef PCM_2_FFS
104 #define T_PSPDF_SMS 20
105 #define MAX_NO_SMS 20
106 #endif
107 #endif
108
109 // Apr 14, 2005 REF: CRR 29991 xpradipg
110 // New file added for the blacklist. The total length along with the path aand
111 // file name should not exceed 20 characters
112 #ifdef FF_MMI_OPTIM
113 #define BLACK_LIST_PATH_AND_FILE "/mmi/blacklist"
114 #endif
115
116 #if defined (NEW_FRAME)
117 EXTERN T_HANDLE hCommACI;
118 #else
119 EXTERN T_VSI_CHANDLE hCommACI;
120 #endif
121 #define hCommMMI hCommACI
122
123 typedef enum
124 {
125 DATA,
126 NO_DATA
127 } WriteFlag;
128
129
130 FlashData FFS_flashData;
131
132 static WriteFlag write_flag;
133
134 int flash_formatted(void); /* SPR#2487 - DS - Function to check if FFS is formatted */
135
136 effs_t flash_write(void)
137 {
138
139 // Oct 19, 2004 REF: CRR MMI-SPR-26002 xkundadu
140 // Issue description: Golite booting problem.
141 // Solution: If the FFS is not formatted, dont write into the FFS.
142
143 if ( flash_formatted() == TRUE)
144 {
145 return (flash_data_write("/mmi","mmidata", &FFS_flashData, sizeof(FFS_flashData)));
146 }
147 else
148 {
149 TRACE_EVENT("ERROR flash_data_write(): NOT FORMATTED!");
150 // Return NOT formatted message.
151 return EFFS_NOFORMAT;
152 }
153 }
154
155 effs_t flash_update(void)
156 {
157 if (write_flag == DATA)
158 { write_flag = NO_DATA;
159 return (flash_write());
160 }
161 else
162 return EFFS_OK;
163 }
164
165 #ifndef WIN32
166 // EF 22/10/02 for WIN32 simulation, set anykeyanswer on, and keylock off
167 /* Marcus: Issue 1719: 11/02/2003: Changed return value from effs_t to int */
168 int flash_read(void)
169 {
170
171 #ifdef PCM_2_FFS
172 int val = ffs_fread("/mmi/mmidata", &FFS_flashData, sizeof(FFS_flashData));
173 #else
174 int val = FFS_fread("/mmi/mmidata", &FFS_flashData, sizeof(FFS_flashData));
175 #endif
176
177 if (val == sizeof(FFS_flashData))
178 {
179 val = EFFS_OK; /* Successful, return Zero as no data_size as in flash_data_read*/
180 }
181 else
182 {
183 TRACE_ERROR("The FFS data could not be read!");
184 TRACE_EVENT_P1("val = %d", val);
185 /* Error, presumably -ve as in FFS_ERRORS, or the actual number of bytes read */
186 }
187 return val;
188 }
189 #else
190 int flash_read()
191 {FFS_flashData.settings_status|= SettingsAnyKeyAnswerOn;
192 FFS_flashData.settings_status &= ~SettingsKeyPadLockOn;
193 FFS_flashData.ConcatenateStatus = TRUE;
194 }
195 #endif
196
197 effs_t flash_data_write(const char* dir_name, const char* file_name, void* data_pointer, int data_size)
198 {
199 T_FFS_DIR dir;
200 int val;
201 char file[200];
202
203 /* SPR#2487 - DS - If FFS is not formatted, return from function */
204 if (flash_formatted() == FALSE)
205 {
206 TRACE_EVENT("ERROR flash_data_write(): NOT FORMATTED!");
207 return EFFS_NOFORMAT;
208 }
209
210 #ifndef PCM_2_FFS
211 val = FFS_opendir(dir_name, &dir);
212 #else
213 val = ffs_opendir(dir_name, &dir);
214 #endif
215
216 if(val < 0)
217 {
218
219 #ifndef PCM_2_FFS
220 val = FFS_mkdir(dir_name);
221 #else
222 val = ffs_mkdir(dir_name);
223 #endif
224
225 switch(val)
226 {
227 case EFFS_OK:
228 case EFFS_EXISTS:
229 break;
230 default:
231 TRACE_ERROR("The FFS directory could not be created!");
232 TRACE_EVENT_P2("val = %d dir name = %s", val, dir_name);
233 return (effs_t)val;
234 }
235 }
236
237 sprintf(file, "%s/%s", dir_name, file_name);
238
239 #ifdef PCM_2_FFS
240 val = ffs_fwrite( file, data_pointer, data_size);
241 #else
242 val = FFS_fwrite( file, data_pointer, data_size);
243 #endif
244
245 if(val NEQ EFFS_OK)
246 {
247 TRACE_ERROR("The FFS file could not be created");
248 TRACE_EVENT_P2("val = %d file name = %s", val, file);
249 }
250 return (effs_t)val;
251 }
252
253 /* Marcus: Issue 1719: 11/02/2003: Changed return value from effs_t to int */
254 int flash_data_read(const char* dir_name, const char* file_name, void* data_pointer, int data_size)
255 {
256 int val;
257 char file[200];
258
259 sprintf(file, "%s/%s", dir_name, file_name);
260
261 #ifdef PCM_2_FFS
262 val = ffs_fread( file, data_pointer, data_size);
263 #else
264 val = FFS_fread( file, data_pointer, data_size);
265 #endif
266
267 if (val NEQ data_size)
268 {
269 TRACE_ERROR("The FFS data could not be read!");
270 TRACE_EVENT_P1("val = %d", val);
271 /* Error, presumably -ve as in FFS_ERRORS, or the actual number of bytes read */
272 }
273 return val;
274 }
275
276 /* SPR#2487 - DS - Function to check if FFS is formatted */
277 int flash_formatted(void)
278 {
279 T_FFS_DIR dir;
280 int val;
281
282 /* Attempt to open "/mmi" directory */
283 #ifndef PCM_2_FFS
284 val = FFS_opendir("/mmi", &dir);
285 #else
286 val = ffs_opendir("/mmi", &dir);
287 #endif
288
289
290 /* If return val is not EFFS_NOFORMAT then
291 * assume that FFS is formatted.
292 */
293 if (val == EFFS_NOFORMAT)
294 return FALSE;
295 else
296 return TRUE;
297 }
298
299 /*
300 Aug 25, 2004 REF: CRR 20655 xnkulkar
301
302 +--------------------------------------------------------------------+
303 | PROJECT: MMI-Framework (8417) MODULE: MFW_FFS |
304 | STATE : code ROUTINE: flash_makedir |
305 +--------------------------------------------------------------------+
306
307 PURPOSE : Creates a directory if not present
308 */
309 void flash_makedir(char * dir_name)
310 {
311 T_FFS_DIR dir;
312 #ifndef PCM_2_FFS
313 int val = FFS_opendir(dir_name , &dir);
314 #else
315 int val = ffs_opendir(dir_name , &dir);
316 #endif
317
318
319 if(val < 0)
320 {
321
322 #ifndef PCM_2_FFS
323 val = FFS_mkdir(dir_name);
324 #else
325 val = ffs_mkdir(dir_name);
326 #endif
327 switch(val)
328 {
329 case EFFS_OK:
330 case EFFS_EXISTS:
331 break;
332 default:
333 TRACE_ERROR("The FFS directory could not be created!");
334 TRACE_EVENT_P2("val = %d dir name = %s", val, dir_name);
335 return;
336 }
337 }
338 }
339 #ifdef MMI_EM_ENABLED
340 U32 get_screen_size(void);
341 void get_screen_capture(U8 *dest_data);
342 U32 screen_capture_index=0;
343 /*******************************************************************************
344
345 $Function: screen_capture_write
346
347 $Description: Implemented By Manju. Write the file into FFS
348 xrashmic 22 Aug, 2004 MMI-SPR-32798
349 $Returns: none
350
351 $Arguments: none
352
353 *******************************************************************************/
354 void screen_capture_write(U8 *filename, U8 *buffer, S32 size)
355 {
356 fd_t fd= -1;
357 fd = ffs_open((const char*)filename, FFS_O_CREATE | FFS_O_WRONLY);
358 ffs_write(fd, buffer, size);
359 ffs_close(fd);
360 }
361
362 /*******************************************************************************
363
364 $Function: screen_capture
365
366 $Description: Implemented By Manju. Writes the LCD buffer into a file in FFS.
367 xrashmic 22 Aug, 2004 MMI-SPR-32798
368 $Returns: none
369
370 $Arguments: none
371
372 *******************************************************************************/
373 void screen_capture(void)
374 {
375 U8 *dest_data;
376 U8 filename[16];
377 U32 dest_size;
378 dest_size=get_screen_size();
379 dest_data=(U8*)mfwAlloc(dest_size);
380 get_screen_capture(dest_data);
381 sprintf((char*)filename,(const char*)"/sc%04d",screen_capture_index);
382 screen_capture_write(filename, dest_data, dest_size);
383 mfwFree(dest_data, dest_size);
384 screen_capture_index++;
385 }
386 #endif
387
388
389 // Apr 14, 2005 REF: CRR 29991 xpradipg
390 #ifdef FF_MMI_OPTIM
391 /*******************************************************************************
392
393 $Function: flash_MMI_blackList_open
394
395 $Description: This opens the blacklist file
396
397 $Returns: value of the open result
398
399 $Arguments: none
400
401 *******************************************************************************/
402 int8 flash_MMI_blackList_open( )
403 {
404 T_FFS_FD file;
405 int status;
406 if(flash_formatted())
407 {
408 file = FFS_open(BLACK_LIST_PATH_AND_FILE, FFS_O_RDWR);
409 if(file == EFFS_NOTFOUND)
410 {
411 TRACE_FUNCTION("the file does not exist and is created");
412 file = FFS_open(BLACK_LIST_PATH_AND_FILE, FFS_O_RDWR | FFS_O_CREATE);
413 if(file < 0 )
414 {
415 TRACE_FUNCTION("file creation failed");
416 return file;
417 }
418 return file;
419 }
420 }
421 return file;
422 }
423 /*******************************************************************************
424
425 $Function: flash_MMI_blackList_close
426
427 $Description: This closes the file opened for read operation
428
429 $Returns: zero for success and -1 for failure
430
431 $Arguments: handle - handle of the file to be closed
432
433 *******************************************************************************/
434 void flash_MMI_blackList_close(int8 handle)
435 {
436 FFS_close((T_FFS_FD)handle);
437 }
438
439 /*******************************************************************************
440
441 $Function: flash_MMI_blackList_write
442
443 $Description: This writes the blacklisted numbers onto the blacklist file
444 if the file does not exist it creates and writes the data
445 $Returns: zero for success and -1 for failure
446
447 $Arguments: data - to be written into the file
448 len - length of the data to be written
449
450 *******************************************************************************/
451 int flash_MMI_blackList_write(U8 *data, SHORT len, SHORT offset)
452 {
453
454 T_FFS_FD file;
455 int status;
456 TRACE_FUNCTION("flash_MMI_blackList_write()");
457 if(flash_formatted())
458 {
459 file = FFS_open(BLACK_LIST_PATH_AND_FILE, FFS_O_RDWR);
460
461 if(file == EFFS_NOTFOUND)
462 {
463 TRACE_FUNCTION("the file does not exist and is created");
464 file = FFS_open(BLACK_LIST_PATH_AND_FILE, FFS_O_RDWR | FFS_O_CREATE);
465 if(file < 0 )
466 {
467 TRACE_FUNCTION("file creation failed");
468 return file;
469 }
470 }
471 TRACE_FUNCTION("the file exist and is opened");
472 #ifdef PCM_2_FFS
473 ffs_seek(file, offset, FFS_SEEK_SET);
474 ffs_write(file, (void*)data, len);
475 ffs_close(file);
476 #else
477 FFS_seek(file, offset, FFS_SEEK_SET);
478 FFS_write(file, (void*)data, len);
479 FFS_close(file);
480 #endif
481
482 return 0;
483 }
484 else
485 return -1;
486
487 }
488 /*******************************************************************************
489
490 $Function: flash_MMI_blackList_read
491
492 $Description: This reads the blacklisted numbers onto the data buffer
493
494 $Returns: zero for success and -1 for failure
495
496 $Arguments: data - buffer into which data is retrieved from the file
497 len - length of the data to be retrieved from the file
498
499 *******************************************************************************/
500 int flash_MMI_blackList_read(int8 file, U8* data, SHORT len,SHORT offset)
501 {
502 int status;
503 TRACE_FUNCTION("file is opened and being read");
504 TRACE_EVENT_P1("the file is seekded at %d",offset);
505 FFS_seek(file, offset, FFS_SEEK_SET);
506 status = FFS_read(file, (void *)data, len);
507 return status;
508 }
509
510
511 #endif
512
513 #if( BOARD == 61 )
514 #ifdef PCM_2_FFS
515 T_FFS_SIZE ffs_ReadRecord(const char *name, void * addr, int size, int index, int recsize)
516 {
517 int n;
518 S32 result=0;
519 T_FFS_STAT stat;
520 char buf[T_PSPDF_SMS*MAX_NO_SMS];
521
522 ffs_stat(name, &stat);
523 n = stat.size / recsize;
524
525 if (index > n)
526 return EFFS_NOTFOUND;
527
528 if (stat.size <= (T_PSPDF_SMS*MAX_NO_SMS))
529 {
530 result = ffs_file_read(name, &buf, stat.size);
531 if (result == stat.size)
532 {
533 memcpy(addr, &buf[(index-1)*recsize], recsize);
534 result = recsize;
535 }
536 }
537
538 return result;
539 }
540
541 T_FFS_RET ffs_WriteRecord(const char *name, void * addr, int size, int index, int recsize)
542 {
543 int n;
544 int result =0;
545 T_FFS_STAT stat;
546 char buf[T_PSPDF_SMS*MAX_NO_SMS];
547
548 ffs_stat(name, &stat);
549 n = stat.size / recsize;
550
551 if (index > n)
552 return EFFS_NOTFOUND;
553
554 if (stat.size <= (T_PSPDF_SMS*MAX_NO_SMS))
555 {
556 result = ffs_file_read(name, &buf, stat.size);
557 if (result == stat.size)
558 {
559 memcpy(&buf[(index-1)*recsize], addr, recsize);
560 result = ffs_file_write(name, &buf, stat.size, (FFS_O_CREATE|FFS_O_TRUNC));
561 }
562 }
563
564 return result;
565 }
566 #endif
567
568 #endif