Tizen 2.0 Release
[framework/system/oma-dm-agent.git] / src / agent / dm-engine / fumo / fumo_engine.c
1 /*
2  * oma-dm-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /*sync-agent*/
19 #include <sync_agent.h>
20
21 /*dm-agent*/
22 #include "common/dm_common.h"
23 #include "common/util/util.h"
24 #include "mo-handler/dm_mo_common.h"
25 #include "mo-handler/dm_mo_handler.h"
26 #include "dm-engine/fumo/fumo_engine.h"
27 #include "dm-engine/dl-manager/fw_downloader.h"
28 #include "dm-engine/dl-manager/dd_object.h"
29 #include "ipc_common.h"
30 #include "ipc_agent.h"
31
32 #define MAX_FILE_SIZE 52428800
33
34 #ifndef OMADM_AGENT_LOG
35 #undef LOG_TAG
36 #define LOG_TAG "FUMO_ENGINE"
37 #endif
38
39 #define FOTA_LOW_BATTERY_LEVEL 50
40
41 static DM_ERROR _firmware_download(char *server_url, MEMORY_TYPE * memory_type, FUMO_Error * fumo_return);
42 static DM_ERROR _firmware_install(char *full_path, MEMORY_TYPE memory_type, FUMO_Error * fumo_return);
43 static DM_ERROR __check_low_battery();
44 static DM_ERROR __check_memory(long double file_size, MEMORY_TYPE * is_internal_memory);
45 static DM_ERROR ___get_max_file_size(int *max_file_size);
46 static DM_ERROR __check_max_file_size(int file_size);
47
48 DM_ERROR fumo_engine_state_operation(char *full_path, char *down_server, FUMO_Error * fumo_return)
49 {
50         _EXTERN_FUNC_ENTER;
51
52         DM_ERROR ret = DM_OK;
53
54         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
55         retvm_if((down_server) == NULL, COMMON_ERR_IS_NULL, "down_server is NULL!!");
56
57         char *result_mo_type = NULL;
58         sync_agent_dev_return_e dci_ret_exec = SYNC_AGENT_DEV_RETURN_SUCCESS;
59         bool cancel_flag = false;
60         MEMORY_TYPE memory_type = MEMORY_INTERNAL;
61         char *fumo_state_data = NULL;
62         FUMO_State fumo_state = UNKNOWN;
63
64         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
65
66         ret = get_mo_operationtype(full_path, &result_mo_type);
67         if (ret != DM_OK)
68                 goto error;
69
70         ret = get_current_fumo_state(full_path, &fumo_state_data);
71         if (ret != DM_OK)
72                 goto error;
73
74         if (chartoint(fumo_state_data, (int *)(&fumo_state)) == 0) {
75                 _DEBUG_INFO("error char to int value");
76                 ret = COMMON_ERR_IS_NULL;
77                 goto error;
78         }
79
80         _DEBUG_INFO(" -----------------------------------------------------------------------------------------------\n");
81         _DEBUG_INFO(" get fumo_state in db : %d\n", fumo_state);
82         _DEBUG_INFO(" -----------------------------------------------------------------------------------------------\n");
83
84         switch (fumo_state) {
85         case IDLE_START:
86         case DOWNLOAD_PROGRESSING:{
87
88                         _DEBUG_INFO(" DOWNLOAD_PROGRESSING\n");
89                         fumo_state = DOWNLOAD_PROGRESSING;
90
91                         cancel_flag = sync_agent_check_cancel_flag();
92                         if (cancel_flag != 0) {
93                                 ret = DM_OK;
94                                 *fumo_return = FUMO_USER_CANCELLED;
95                                 fumo_state = DOWNLOAD_FAILED;
96                                 goto error;
97                         }
98
99                         ret = _firmware_download(down_server, &memory_type, fumo_return);
100                         if (ret != DM_OK && ret != DM_DOWNLOAD_POPUP && ret != DM_RESUME_IDLE) {
101                                 fumo_state = DOWNLOAD_FAILED;
102                                 goto error;
103                         }
104
105                         _DEBUG_INFO("fimware donwload success : 200 , cancel : 562,  result is : %d\n", ret);
106
107                         cancel_flag = sync_agent_check_cancel_flag();
108                         if (cancel_flag != 0) {
109                                 ret = DM_OK;
110                                 *fumo_return = FUMO_USER_CANCELLED;
111                                 fumo_state = DOWNLOAD_FAILED;
112                                 goto error;
113                         }
114
115                         if (ret == DM_OK) {
116                                 _DEBUG_INFO("-----------download ok---------------");
117                                 fumo_state = DOWNLOAD_COMPLETE;
118
119                                 RESUME_STATUS download_clicked = RESUME_STATUS_INSTALL_BEFORE;
120                                 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
121                                 _DEBUG_INFO("update engine status clolumn download click : %d", ret);
122                                 ret = DM_OK;
123                         } else if (ret == DM_ERR_REMINDER_INTERVAL || ret == DM_DOWNLOAD_POPUP || ret == DM_RESUME_IDLE) {
124                                 _DEBUG_INFO("-----------download popup---------------");
125                                 fumo_state = DOWNLOAD_PROGRESSING;
126                                 goto returnpart;
127                         } else {
128                                 _DEBUG_INFO("-----------download fail---------------\n");
129                                 *fumo_return = FUMO_USER_CANCELLED;
130                                 fumo_state = DOWNLOAD_FAILED;
131                         }
132
133                         ret = set_current_fumo_state(full_path, fumo_state);
134                         if (ret != DM_OK)
135                                 goto error;
136
137                         if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) {
138                         } else if (strcmp(result_mo_type, DM_FUMO_UPDATE_OP) == 0) {
139                         } else if (strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) {
140                                 fumo_engine_state_operation(full_path, down_server, fumo_return);
141                                 _DEBUG_INFO("engine state result : %d", ret);
142                         }
143                 }
144                 break;
145         case DOWNLOAD_FAILED:
146                 _DEBUG_INFO(" DOWNLOAD_FAILED\n");
147                 goto error;
148
149                 break;
150         case DOWNLOAD_COMPLETE:{
151                         _DEBUG_INFO(" DOWNLOAD_COMPLETE\n");
152
153                         if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) {
154                         } else if ((strcmp(result_mo_type, DM_FUMO_UPDATE_OP)) == 0 || strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) {
155                                 fumo_state = READY_TO_UPDATE;
156                                 ret = set_current_fumo_state(full_path, fumo_state);
157                                 if (ret != DM_OK)
158                                         goto error;
159
160                                 fumo_engine_state_operation(full_path, down_server, fumo_return);
161                                 _DEBUG_INFO("engine state result : %d", ret);
162                         }
163                 }
164                 break;
165         case READY_TO_UPDATE:{
166                         cancel_flag = sync_agent_check_cancel_flag();
167                         if (cancel_flag != 0) {
168                                 ret = DM_OK;
169                                 *fumo_return = FUMO_USER_CANCELLED;
170                                 fumo_state = DOWNLOAD_FAILED;
171                                 goto error;
172                         }
173
174                         ret = _firmware_install(full_path, memory_type, fumo_return);
175
176                         if (ret == DM_OK) {
177                                 /*if install success was rebooted */
178                                 _DEBUG_INFO("install fail");
179                                 goto error;
180                         } else if (ret == COMMON_ERR_IPC || ret == DM_LOW_BATTERY_ERROR) {
181                                 _DEBUG_INFO("-----------cancel or ipc error---------------");
182                                 fumo_state = UPDATE_FAILED_HAVE_DATA;
183                                 goto returnpart;
184                         } else if (ret == DM_ERR_REMINDER_INTERVAL || ret == DM_INSTALL_POPUP || ret == DM_RESUME_IDLE) {
185                                 _DEBUG_INFO("-----------download popup---------------");
186                                 fumo_state = READY_TO_UPDATE;
187                                 goto returnpart;
188                         } else {
189                                 _DEBUG_INFO("-----------install fail---------------\n");
190                                 *fumo_return = FUMO_USER_CANCELLED;
191                                 fumo_state = UPDATE_FAILED_HAVE_DATA;
192                         }
193
194                 }
195                 break;
196         case UPDATE_PROGRESSING:{
197
198                         cancel_flag = sync_agent_check_cancel_flag();
199                         if (cancel_flag != 0) {
200                                 ret = DM_OK;
201                                 *fumo_return = FUMO_USER_CANCELLED;
202                                 fumo_state = DOWNLOAD_FAILED;
203                                 goto error;
204                         }
205
206                         dci_ret_exec = sync_agent_execute_dev_function(2, "fota_result", 1, (int *)fumo_return);
207                         //*fumo_return = result;
208                         //*fumo_return = 202;
209                         _DEBUG_INFO("-----------------firmware update result : %d  fumo return : %d------------------", dci_ret_exec, (*fumo_return));
210                         if (dci_ret_exec != SYNC_AGENT_DEV_RETURN_SUCCESS) {
211                                 fumo_state = UPDATE_FAILED_HAVE_DATA;
212                         } else {
213                                 fumo_state = UPDATE_SUCCESSFUL_HAVE_DATA;
214                         }
215
216                         ret = set_current_fumo_state(full_path, fumo_state);
217                         if (ret != DM_OK)
218                                 goto error;
219
220                         ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
221                         _DEBUG_INFO("engine state result : %d", ret);
222                 }
223                 break;
224         case UPDATE_FAILED_HAVE_DATA:
225         case UPDATE_FAILED_NO_DATA:{
226
227                         delete_fumo_contents(memory_type);
228                         fumo_state = IDLE_START;
229                         set_current_fumo_state(full_path, fumo_state);
230 /*              if(ret != DM_OK)
231                         goto error;*/
232
233                         /*ret = FUMO_UPDATE_FAILED; */
234                         *fumo_return = FUMO_UPDATE_FAILED;
235                         _DEBUG_INFO("update fail ");
236                 }
237                 break;
238         case UPDATE_SUCCESSFUL_HAVE_DATA:
239         case UPDATE_SUCCESSFUL_NO_DATA:{
240
241                         _DEBUG_INFO("----------------------------------------------------------firmware update success delete files-----------------------------------------------------------");
242                         delete_fumo_contents(memory_type);
243                         fumo_state = IDLE_START;
244                         set_current_fumo_state(full_path, fumo_state);
245 /*              if(ret != DM_OK)
246                         goto error;*/
247
248                         /*ret = FUMO_SUCCESS; */
249                         *fumo_return = FUMO_SUCCESS;
250                         _DEBUG_INFO("update success ");
251                 }
252                 break;
253         default:
254                 break;
255         }
256
257         //      str_free(&result_mo_type);
258         _DEBUG_INFO(" end fumo state : %d\n", fumo_state);
259         str_free(&fumo_state_data);
260
261         _EXTERN_FUNC_EXIT;
262         return ret;
263
264  returnpart:
265         _DEBUG_INFO("----------------------------------------------------------fumo download, install popup----------------------------------------------------------- %d", fumo_state);
266
267         set_current_fumo_state(full_path, fumo_state);
268         str_free(&fumo_state_data);
269         str_free(&result_mo_type);
270         _EXTERN_FUNC_EXIT;
271         return ret;
272
273  error:
274         _DEBUG_INFO("----------------------------------------------------------fumo error-----------------------------------------------------------");
275         delete_fumo_contents(memory_type);
276
277         fumo_state = IDLE_START;
278         set_current_fumo_state(full_path, fumo_state);
279         str_free(&fumo_state_data);
280         str_free(&result_mo_type);
281
282         _DEBUG_INFO(" end error : %d\n", ret);
283         _EXTERN_FUNC_EXIT;
284         return ret;
285 }
286
287 DM_ERROR fumo_exec(char *full_path, char *correlator, FUMO_Error * fumo_return)
288 {
289         _EXTERN_FUNC_ENTER;
290
291         DM_ERROR ret = DM_OK;
292
293         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
294
295         char *result_mo_type = NULL;
296         ret = get_mo_operationtype(full_path, &result_mo_type);
297         if (ret != DM_OK)
298                 goto error;
299
300         if (result_mo_type == NULL) {
301                 _DEBUG_INFO("result_mo_type is null");
302                 ret = COMMON_ERR_IS_NULL;
303                 goto error;
304         }
305
306         if (strcmp(result_mo_type, DM_FUMO_DOWNLOAD_OP) == 0) {
307                 ret = firmware_download_opeartion(full_path, fumo_return);
308                 if (ret != DM_OK)
309                         goto error;
310         } else if (strcmp(result_mo_type, DM_FUMO_UPDATE_OP) == 0) {
311                 ret = firmware_update_operation(full_path, fumo_return);
312                 if (ret != DM_OK)
313                         goto error;
314         } else if (strcmp(result_mo_type, DM_FUMO_DOWNLOADAND_UPDATE_OP) == 0) {
315                 ret = firmware_downloadupdate_operation(full_path, fumo_return);
316                 if (ret != DM_OK)
317                         goto error;
318         } else {
319                 ret = vendor_dependency_firmware_operation(full_path, fumo_return);
320                 if (ret != DM_OK)
321                         goto error;
322         }
323
324         str_free(&result_mo_type);
325         _DEBUG_INFO(" end : %d", ret);
326         _EXTERN_FUNC_EXIT;
327         return ret;
328  error:
329
330         str_free(&result_mo_type);
331         _DEBUG_INFO(" end error : %d \n", ret);
332         _EXTERN_FUNC_EXIT;
333         return ret;
334 }
335
336 static DM_ERROR _firmware_download(char *server_url, MEMORY_TYPE * memory_type, FUMO_Error * fumo_return)
337 {
338         _INNER_FUNC_ENTER;
339
340         DM_ERROR ret = DM_OK;
341
342         DM_ERROR download_status = DM_ERR_USER_CANDELLED;
343         DM_ERROR installNofity_ret = DM_OK;
344         bool cancel_flag;
345         int config = -1;
346
347         char *download_folder = NULL;
348         int file_size = 0;
349         Download_Descriptor *download_descriptor = NULL;
350
351         engine_status *status = NULL;
352         int noti_res = 0;
353
354         if (server_url == NULL) {
355                 *fumo_return = FUMO_USER_CANCELLED;
356                 download_status = DM_ERR_INVALID_DESCRIPTOR;
357                 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
358                 goto error;
359         }
360
361         _DEBUG_TRACE("----------------------------------------------------------------------------------------------------- \n");
362         _DEBUG_TRACE(" server url : %s \n", server_url);
363         _DEBUG_TRACE("----------------------------------------------------------------------------------------------------- \n");
364
365         ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
366         if (ret != DM_OK || status == NULL) {
367                 *fumo_return = FUMO_USER_CANCELLED;
368                 download_status = DM_ERR_USER_CANDELLED;
369                 goto error;
370         }
371
372         switch (status->download_click) {
373         case RESUME_STATUS_DONWLOAD_BEFORE:     /*before click download popup */
374                 {
375                         _DEBUG_TRACE(" user interaction start \n");
376
377                         cancel_flag = sync_agent_check_cancel_flag();
378                         _DEBUG_TRACE(" cancel_flag : %d \n", cancel_flag);
379                         if (cancel_flag != 0) {
380                                 *fumo_return = FUMO_USER_CANCELLED;
381                                 download_status = DM_ERR_USER_CANDELLED;
382                                 ret = DM_OK;
383                                 goto error;
384                         }
385
386                         int noti_res;
387                         _DEBUG_TRACE("waiting connect to server success in firmware download\n");
388                         noti_res = noti_download();
389                         _DEBUG_TRACE("download noti response : %d \n ", noti_res);
390
391                         if (noti_res == RESPONSE_TYPE_OK) {
392                                 ret = DM_DOWNLOAD_POPUP;
393                                 goto returnpart;
394
395                         } else {
396                                 _DEBUG_TRACE("------------------------------------------------------downlaod popup noti error--------------------------------------------\n");
397                                 // error in noti-process
398                                 *fumo_return = FUMO_USER_CANCELLED;
399                                 download_status = DM_ERR_USER_CANDELLED;
400                                 ret = COMMON_ERR_IPC;
401                                 goto error;
402                         }
403                 }
404                 break;
405         case RESUME_STATUS_DOWNLOAD:    /*after click download popup */
406                 {
407                         _DEBUG_TRACE("------------------------------------------------------download button click---------------------------------------------\n");
408
409                         download_descriptor = (Download_Descriptor *) calloc(1, sizeof(Download_Descriptor) + 1);
410                         if (download_descriptor == NULL) {
411                                 _DEBUG_TRACE("calloc failed !!");
412                                 ret = COMMON_ERR_ALLOC;
413                                 *fumo_return = FUMO_USER_CANCELLED;
414                                 download_status = DM_ERR_INVALID_DESCRIPTOR;
415                                 goto error;
416                         }
417
418                         ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status);
419                         if (ret != DM_OK) {
420                                 *fumo_return = FUMO_USER_CANCELLED;
421                                 download_status = DM_ERR_INVALID_DESCRIPTOR;
422                                 goto error;
423                         }
424                         _DEBUG_TRACE(" user interaction start \n");
425
426                         cancel_flag = sync_agent_check_cancel_flag();
427                         _DEBUG_TRACE(" cancel_flag : %d \n", cancel_flag);
428                         if (cancel_flag != 0) {
429                                 *fumo_return = FUMO_USER_CANCELLED;
430                                 download_status = DM_ERR_USER_CANDELLED;
431                                 ret = DM_OK;
432                                 goto error;
433                         }
434
435                         /*wifi config */
436                         config = get_wifi_only_config();
437
438                         /*battery state check */
439                         ret = __check_low_battery();
440                         _DEBUG_TRACE("ret : %d \n", ret);
441                         if (ret != DM_OK) {
442                                 ret = DM_OK;
443                                 *fumo_return = FUMO_USER_CANCELLED;
444                                 goto error;
445                         }
446
447                         _DEBUG_TRACE("======================================================");
448                         _DEBUG_TRACE("object size %d\n", file_size);
449                         _DEBUG_TRACE("======================================================");
450
451                         ret = __check_memory(file_size, memory_type);
452                         if (ret != DM_OK) {
453                                 noti_res = noti_memory_full((int)file_size);
454                                 if (noti_res == RESPONSE_TYPE_OK) {
455                                         _DEBUG_TRACE("memory full popup success");
456                                 } else {
457                                         _DEBUG_TRACE("memory full popup fail");
458                                 }
459                                 download_status = DM_ERR_INSUFFICIENT_MEMORY;
460                                 *fumo_return = FUMO_USER_CANCELLED;
461                                 ret = DM_OK;
462                                 goto error;
463                         }
464
465                         if (config == -1) {
466                                 _DEBUG_TRACE("get wifi only config error");
467                                 *fumo_return = FUMO_MALFORMED_OR_BAD_URL;
468                                 download_status = DM_ERR_USER_CANDELLED;
469                                 ret = DM_WIFI_ONLY_ERROR;
470                                 goto error;
471                         } else if (config == 0) {
472                                 _DEBUG_TRACE("wifi config = 0");
473                                 int wifi_ret = 0;
474                                 wifi_ret = get_wifi_state();
475                                 _DEBUG_TRACE("wifi mode : %d", wifi_ret);
476
477                                 if (wifi_ret != 1) {
478                                         _DEBUG_TRACE("3g mode");
479
480                                         ret = __check_max_file_size(file_size);
481                                         if (ret != DM_OK) {
482                                                 _DEBUG_TRACE("get max file size error");
483                                                 *fumo_return = FUMO_DOWNLOAD_FAILS_DUE_TO_DEVICE_OUT_OF_MEMORY;
484                                                 download_status = DM_ERR_USER_CANDELLED;
485                                                 ret = DM_WIFI_ONLY_ERROR;
486                                                 goto error;
487                                         }
488                                 } else {
489                                         _DEBUG_TRACE("wifi mode");
490                                 }
491                         } else {
492                                 _DEBUG_TRACE("wifi config = 1");
493                                 _DEBUG_TRACE("wifi only mode");
494                         }
495
496                         ret = get_fota_download_dir((*memory_type), &download_folder);
497                         if (ret != DM_OK) {
498                                 *fumo_return = FUMO_DOWNLOAD_FAILS_DUE_TO_DEVICE_OUT_OF_MEMORY;
499                                 download_status = DM_ERR_INSUFFICIENT_MEMORY;
500                                 goto error;
501                         }
502                         _DEBUG_TRACE(" download ok \n ");
503
504                         char *downloadUrl = NULL;
505                         ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_SERVER_URL, downloadUrl);
506                         if (ret != DM_OK) {
507                                 *fumo_return = FUMO_USER_CANCELLED;
508                                 download_status = DM_ERR_USER_CANDELLED;
509                                 goto error;
510                         }
511                         /* remove remind interval */
512                         delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
513                         _DEBUG_TRACE(" delete fumo reminder in config db ");
514
515                         //FOTASaveDir //FOTADownDir
516                         DOWNLOAD_FILE_STATUS file_status = 0;
517                         Data_Resume_Infomation *data_resume_info = NULL;
518                         ret = check_file_resume(download_folder, &file_status, download_descriptor, &data_resume_info);
519                         if (ret != DM_OK) {
520                                 *fumo_return = FUMO_MALFORMED_OR_BAD_URL;
521                                 download_status = DM_ERR_USER_CANDELLED;
522                                 goto error;
523                         }
524
525                         _DEBUG_TRACE(" file_status = %d \n", file_status);
526                         /*was maked by sooyi */
527                         if (file_status != EXIST_COMPLETED_FILE) {
528                                 char *object_path = 0;
529
530                                 if (config == -1) {
531                                         _DEBUG_TRACE("get wifi only config error");
532                                         *fumo_return = FUMO_MALFORMED_OR_BAD_URL;
533                                         download_status = DM_ERR_USER_CANDELLED;
534                                         ret = DM_WIFI_ONLY_ERROR;
535                                         goto error;
536                                 } else {
537                                         _DEBUG_TRACE("get wifi only config value : %d", config);
538
539                                         ret = download_object(download_folder, &object_path, data_resume_info, config, download_descriptor, &download_status);
540                                         _DEBUG_TRACE("download object : %s", object_path);
541                                         _DEBUG_TRACE(" download_object result : %d \n", ret);
542                                         if (ret != DM_OK) {
543                                                 if (ret == DM_WIFI_ONLY_ERROR) {
544                                                         _DEBUG_TRACE("send_DL_Msg() err [%d]\n", ret);
545                                                         /* ipc wifi only pop up */
546                                                         noti_res = noti_wifi_only_download_fail();
547
548                                                         if (noti_res == RESPONSE_TYPE_OK) {
549                                                                 _DEBUG_TRACE("send_wifi only fail ipc success");
550                                                         } else {
551                                                                 _DEBUG_TRACE("send_wifi only fail ipc fail");
552                                                         }
553                                                 }
554                                                 *fumo_return = FUMO_USER_CANCELLED;
555                                                 download_status = DM_ERR_USER_CANDELLED;
556                                                 goto error;
557                                         } else {
558                                                 //do nothing
559                                         }
560
561                                         installNofity_ret = send_donwload_status(download_status, download_descriptor);
562                                         _DEBUG_TRACE("send installNotify : %d", installNofity_ret);
563                                 }
564                         } else {
565                                 _DEBUG_TRACE(" file is exist\n");
566                         }
567                 }
568                 break;
569         case RESUME_STATUS_DOWNLOAD_LATER:      /*later button clicked */
570                 {
571                         _DEBUG_TRACE("------------------------------------------------------later button click---------------------------------------------\n");
572
573                         download_descriptor = (Download_Descriptor *) calloc(1, sizeof(Download_Descriptor) + 1);
574                         if (download_descriptor == NULL) {
575                                 _DEBUG_TRACE("calloc failed !!");
576                                 ret = COMMON_ERR_ALLOC;
577                                 *fumo_return = FUMO_USER_CANCELLED;
578                                 download_status = DM_ERR_INVALID_DESCRIPTOR;
579                                 goto error;
580                         }
581
582                         ret = get_object_information(server_url, &file_size, &download_descriptor, &download_status);
583                         if (ret != DM_OK) {
584                                 *fumo_return = FUMO_USER_CANCELLED;
585                                 download_status = DM_ERR_INVALID_DESCRIPTOR;
586                                 goto error;
587                         }
588
589                         installNofity_ret = send_donwload_status(download_status, download_descriptor);
590                         _DEBUG_TRACE("send installNotify : %d", installNofity_ret);
591
592                         RESUME_STATUS download_clicked = RESUME_STATUS_DOWNLOAD_IDLE;
593                         ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
594                         _DEBUG_TRACE("update engine status clolumn download click : %d", ret);
595
596                         *fumo_return = FUMO_USER_CANCELLED;
597                         download_status = DM_ERR_USER_CANDELLED;
598                         ret = DM_ERR_REMINDER_INTERVAL;
599                 }
600                 break;
601         case RESUME_STATUS_DOWNLOAD_IDLE:
602         default:
603                 {
604                         /*case RESUME_STATUS_IDLE, default */
605                         ret = DM_RESUME_IDLE;
606                         goto returnpart;
607
608                         _DEBUG_TRACE("----------------------------------------------------bad flow--------------------------------------------------------------------");
609                 }
610
611                 break;
612         }
613
614         if (status != NULL)
615                 Free_Memory_Engine_Status(&status, 1);
616
617         if (download_descriptor != NULL) {
618                 _DEBUG_TRACE("__free_Download_Descriptor()\n");
619                 free_Download_Descriptor(&download_descriptor);
620         }
621         str_free(&download_folder);
622
623         _INNER_FUNC_EXIT;
624
625         return ret;
626
627  returnpart:
628
629         if (status != NULL)
630                 Free_Memory_Engine_Status(&status, 1);
631
632         if (download_descriptor != NULL) {
633                 _DEBUG_TRACE("__free_Download_Descriptor()\n");
634                 free_Download_Descriptor(&download_descriptor);
635         }
636         str_free(&download_folder);
637
638         _DEBUG_TRACE(" end error : %d \n", ret);
639         _INNER_FUNC_EXIT;
640         return ret;
641
642  error:
643
644         if (status != NULL)
645                 Free_Memory_Engine_Status(&status, 1);
646
647         installNofity_ret = send_donwload_status(download_status, download_descriptor);
648         _DEBUG_INFO("send installNotify : %d", installNofity_ret);
649
650         if (download_descriptor != NULL) {
651                 _DEBUG_INFO("__free_Download_Descriptor()\n");
652                 free_Download_Descriptor(&download_descriptor);
653         }
654         str_free(&download_folder);
655
656         _DEBUG_INFO(" end error : %d \n", ret);
657         _INNER_FUNC_EXIT;
658         return ret;
659
660 }
661
662 static DM_ERROR _firmware_install(char *full_path, MEMORY_TYPE memory_type, FUMO_Error * fumo_return)
663 {
664         _INNER_FUNC_ENTER;
665
666         DM_ERROR ret = DM_OK;
667
668         if (full_path == NULL) {
669                 *fumo_return = FUMO_USER_CANCELLED;
670                 goto error;
671         }
672
673         sync_agent_dev_return_e dci_ret_flag = SYNC_AGENT_DEV_RETURN_SUCCESS;
674         engine_status *status = NULL;
675         int noti_res = 0;
676         FUMO_State fumo_state = READY_TO_UPDATE;
677
678         ret = Get_Engine_Status(FUMO_SERVICE_ENGINE, &status);
679         if (ret != DM_OK || status == NULL) {
680                 *fumo_return = FUMO_USER_CANCELLED;
681                 goto error;
682         }
683
684         switch (status->download_click) {
685         case RESUME_STATUS_INSTALL_BEFORE:
686                 {
687                                 /** install UI control */
688                         noti_res = noti_install();
689                         if (noti_res == RESPONSE_TYPE_OK) {
690                                 ret = DM_INSTALL_POPUP;
691                                 goto returnpart;
692                         } else {
693                                 // error in noti-process
694                                 ret = COMMON_ERR_IPC;
695                                 *fumo_return = FUMO_USER_CANCELLED;
696                                 goto error;
697                         }
698                 }
699                 break;
700         case RESUME_STATUS_INSTALL:
701                 {
702                         /* battery state check */
703                         ret = __check_low_battery();
704                         if (ret != DM_OK) {
705                                 ret = DM_LOW_BATTERY_ERROR;
706                                 *fumo_return = FUMO_USER_CANCELLED;
707                                 goto error;
708                         }
709
710                         _DEBUG_TRACE("------------------fota install ok------------------");
711                         _DEBUG_TRACE(" fota flag api \n");
712                         delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
713                         _DEBUG_TRACE(" delete fumo reminder in config db ");
714
715                         fumo_state = UPDATE_PROGRESSING;
716                         ret = set_current_fumo_state(full_path, fumo_state);
717                         if (ret != DM_OK) {
718                                 *fumo_return = FUMO_USER_CANCELLED;
719                                 goto error;
720                         }
721
722                         dci_ret_flag = sync_agent_execute_dev_function(2, "fota_flag", 1, memory_type);
723                         //dci_ret_flag= SYNC_AGENT_DEV_RETURN_SUCCESS;
724                         _DEBUG_TRACE(" fota flag result : %d \n", dci_ret_flag);
725                         if (dci_ret_flag != SYNC_AGENT_DEV_RETURN_SUCCESS) {
726                                 _DEBUG_TRACE(" fota flag fail!!!!!!!!!!!! \n");
727                                 *fumo_return = FUMO_FAILED_VALIDATION;
728
729                                 ret = set_current_fumo_state(full_path, fumo_state);
730                                 if (ret != DM_OK) {
731                                         *fumo_return = FUMO_USER_CANCELLED;
732                                         goto error;
733                                 }
734
735                                 goto error;
736                         } else {
737                                 //for reboot
738                                 _DEBUG_TRACE(" -------------------------------------------------------------------- \n");
739                                 _DEBUG_TRACE(" fota install to be rebooting l!!!!!!!!!!!! \n");
740                                 _DEBUG_TRACE(" -------------------------------------------------------------------- \n");
741                                 sleep(1);
742                                 exit(0);
743                                 break;
744                         }
745                 }
746                 break;
747         case RESUME_STATUS_INSTALL_LATER:
748                 {
749                         //cancle to install
750                         _DEBUG_TRACE("------------------canceled install------------------");
751
752                         *fumo_return = FUMO_USER_CANCELLED;
753
754                         RESUME_STATUS download_clicked = RESUME_STATUS_INSTALL_IDLE;
755                         ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
756                         _DEBUG_TRACE("update engine status clolumn download click : %d", ret);
757                         /*fumo_state = IDLE_START;
758                            ret = set_current_fumo_state(full_path, fumo_state);
759                            if(ret != DM_OK)
760                            goto error; */
761                         ret = DM_ERR_REMINDER_INTERVAL;
762                         goto error;
763                 }
764                 break;
765         case RESUME_STATUS_INSTALL_IDLE:
766         default:
767                 {
768                         ret = DM_RESUME_IDLE;
769                         goto returnpart;
770                         _DEBUG_TRACE("----------------------------------------------------install later --------------------------------------------------------------------");
771                 }
772                 break;
773         }
774
775         if (status != NULL) {
776                 Free_Memory_Engine_Status(&status, 1);
777         }
778
779         _INNER_FUNC_EXIT;
780         return ret;
781
782  returnpart:
783
784         if (status != NULL) {
785                 Free_Memory_Engine_Status(&status, 1);
786         }
787         _DEBUG_INFO(" return part : %d \n", ret);
788         _INNER_FUNC_EXIT;
789         return ret;
790
791  error:
792
793         if (status != NULL) {
794                 Free_Memory_Engine_Status(&status, 1);
795         }
796         _DEBUG_INFO(" end error : %d \n", ret);
797         _INNER_FUNC_EXIT;
798         return ret;
799 }
800
801 DM_ERROR firmware_download_opeartion(char *full_path, FUMO_Error * fumo_return)
802 {
803         _EXTERN_FUNC_ENTER;
804         /*call DL module */
805         _DEBUG_INFO(" start\n");
806
807         DM_ERROR ret = DM_OK;
808
809         if (full_path == NULL) {
810                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
811                 goto error;
812         }
813
814         char *full_path_pkgurl = NULL;
815         full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_DWONLOAD_OP_PKGURL);
816
817         char *down_server = NULL;
818         ret = get_mo_data(full_path_pkgurl, &down_server);
819         if (ret != DM_OK) {
820                 goto error;
821         }
822
823         if (down_server == NULL) {
824                 _DEBUG_INFO("not found download server");
825                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
826                 //ret =
827                 goto error;
828         }
829 #ifdef _DM_BUNDANG_TEST
830         /*redirection code */
831         char *pkg_url = get_new_uri(down_server);
832
833         ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
834         if (ret != DM_OK)
835                 goto error;
836 #else
837         ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
838         if (ret != DM_OK)
839                 goto error;
840 #endif
841         /*
842          * return server ret
843          */
844
845         str_free(&full_path_pkgurl);
846         str_free(&down_server);
847
848         _EXTERN_FUNC_EXIT;
849         return ret;
850
851  error:
852         str_free(&full_path_pkgurl);
853         str_free(&down_server);
854
855         _DEBUG_INFO(" end error : %d \n", ret);
856         _EXTERN_FUNC_EXIT;
857         return ret;
858 }
859
860 DM_ERROR firmware_update_operation(char *full_path, FUMO_Error * fumo_return)
861 {
862         _EXTERN_FUNC_ENTER;
863
864         DM_ERROR ret = DM_OK;
865
866         if (full_path == NULL) {
867                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
868                 goto error;
869         }
870
871         char *full_path_pkgurl = NULL;
872         full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_UPDATE_PKG_OP_DATA);
873
874         char *down_server = NULL;
875         ret = get_mo_data(full_path_pkgurl, &down_server);
876         if (ret != DM_OK) {
877                 goto error;
878         }
879
880         if (down_server == NULL) {
881                 _DEBUG_INFO("not found download server");
882                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
883                 //ret =
884                 goto error;
885         }
886 #ifdef _DM_BUNDANG_TEST
887         /*redirection code */
888         char *pkg_url = get_new_uri(down_server);
889
890         ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
891         if (ret != DM_OK)
892                 goto error;
893 #else
894         ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
895         if (ret != DM_OK)
896                 goto error;
897 #endif
898
899         /*
900          * return server ret
901          */
902
903         str_free(&full_path_pkgurl);
904         str_free(&down_server);
905
906         _EXTERN_FUNC_EXIT;
907         return ret;
908
909  error:
910         str_free(&full_path_pkgurl);
911         str_free(&down_server);
912
913         _DEBUG_INFO(" end error : %d \n", ret);
914         _EXTERN_FUNC_EXIT;
915         return ret;
916 }
917
918 DM_ERROR firmware_downloadupdate_operation(char *full_path, FUMO_Error * fumo_return)
919 {
920         _EXTERN_FUNC_ENTER;
921
922         DM_ERROR ret = DM_OK;
923
924         if (full_path == NULL) {
925                 _DEBUG_INFO(" full path = null\n");
926                 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
927                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
928                 goto error;
929         }
930
931         char *full_path_pkgurl = NULL;
932         full_path_pkgurl = g_strdup_printf("%s%s", full_path, DM_FUMO_DOWNLOADAND_UPDATE_OP_PKGURL);
933
934         char *down_server = NULL;
935         ret = get_mo_data(full_path_pkgurl, &down_server);
936         _DEBUG_INFO(" server_url : %s\n", down_server);
937         if (ret != DM_OK) {
938                 goto error;
939         }
940
941         if (down_server == NULL) {
942                 _DEBUG_INFO("not found download server");
943                 (*fumo_return) = FUMO_MALFORMED_OR_BAD_URL;
944                 //ret =
945                 goto error;
946         }
947 #ifdef _DM_BUNDANG_TEST
948         /*redirection code */
949         char *pkg_url = get_new_uri(down_server);
950
951         ret = fumo_engine_state_operation(full_path, pkg_url, fumo_return);
952         if (ret != DM_OK) {
953                 goto error;
954         }
955 #else
956         ret = fumo_engine_state_operation(full_path, down_server, fumo_return);
957         if (ret != DM_OK) {
958                 goto error;
959         }
960 #endif
961         /*
962          * return server ret
963          */
964
965         str_free(&full_path_pkgurl);
966         str_free(&down_server);
967
968         _EXTERN_FUNC_EXIT;
969         return ret;
970
971  error:
972         str_free(&full_path_pkgurl);
973         str_free(&down_server);
974
975         _DEBUG_INFO(" end error : %d \n", ret);
976         _EXTERN_FUNC_EXIT;
977         return ret;
978 }
979
980 DM_ERROR vendor_dependency_firmware_operation(char *full_path, FUMO_Error * fumo_return)
981 {
982         _EXTERN_FUNC_ENTER;
983
984         DM_ERROR ret = DM_OK;
985         int check_operation = 1;
986
987         if (full_path == NULL) {
988                 ret = DM_ERR_COMMAND_FAILED;
989                 *fumo_return = FUMO_USER_CANCELLED;
990                 goto error;
991         }
992
993         sync_agent_dm_mo_error_e ext_return;
994         ext_return = sync_agent_execute_mo_ext(full_path, (int *)fumo_return, check_operation);
995         if (ext_return != SYNC_AGENT_DM_MO_SUCCESS) {
996                 ret = DM_ERR_COMMAND_FAILED;
997                 *fumo_return = FUMO_USER_CANCELLED;
998                 goto error;
999         }
1000
1001         _EXTERN_FUNC_EXIT;
1002         return ret;
1003  error:
1004
1005         _DEBUG_INFO(" end error : %d\n", ret);
1006         _EXTERN_FUNC_EXIT;
1007         return ret;
1008 }
1009
1010 DM_ERROR get_current_fumo_state(char *full_path, char **fumo_state_data)
1011 {
1012         _EXTERN_FUNC_ENTER;
1013         DM_ERROR ret = DM_OK;
1014
1015         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
1016
1017         char *fumo_root = NULL;
1018         char *fumo_state_url = NULL;
1019
1020         //ret = get_mo_servicetype(full_path, &fumo_root);
1021         ret = get_mo_root_path(full_path, &fumo_root);
1022         if (ret != DM_OK) {
1023                 ret = COMMON_ERR_INTERNAL_NOT_DEFINED;
1024                 goto error;
1025         }
1026         fumo_state_url = g_strdup_printf("%s%s", fumo_root, DM_FUMO_STATE_OP);
1027
1028         ret = get_mo_data(fumo_state_url, fumo_state_data);
1029         if (ret != DM_OK) {
1030                 ret = COMMON_ERR_GET_TYPE_NOT_FOUND;
1031                 goto error;
1032         }
1033
1034         str_free(&fumo_state_url);
1035
1036         _EXTERN_FUNC_EXIT;
1037         return ret;
1038  error:
1039         str_free(&fumo_state_url);
1040
1041         _DEBUG_INFO(" end error : %d\n", ret);
1042         _EXTERN_FUNC_EXIT;
1043         return ret;
1044 }
1045
1046 DM_ERROR set_current_fumo_state(char *full_path, FUMO_State fumo_state)
1047 {
1048         _EXTERN_FUNC_ENTER;
1049
1050         DM_ERROR ret = DM_OK;
1051
1052         retvm_if((full_path) == NULL, COMMON_ERR_IS_NULL, "full_path is NULL!!");
1053
1054         char *fumo_root = NULL;
1055         char *fumo_state_url = NULL;
1056         char *fumo_state_data = NULL;
1057
1058         //ret = get_mo_servicetype(full_path, &fumo_root);
1059         ret = get_mo_root_path(full_path, &fumo_root);
1060         if (ret != DM_OK) {
1061                 goto error;
1062         }
1063
1064         fumo_state_url = g_strdup_printf("%s%s", fumo_root, DM_FUMO_STATE_OP);
1065         fumo_state_data = g_strdup_printf("%d", fumo_state);
1066
1067         _DEBUG_INFO(" fumo_state : %d\n", fumo_state);
1068
1069         //sync_agent_dm_mo_error_e mo_ret  = sync_agent_begin_transaction_mo();
1070         ret = replace_mo_data(fumo_state_url, fumo_state_data);
1071         //mo_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1072         if (ret != DM_OK)
1073                 goto error;
1074
1075         str_free(&fumo_state_url);
1076         str_free(&fumo_state_data);
1077
1078         _EXTERN_FUNC_EXIT;
1079         return ret;
1080
1081  error:
1082         str_free(&fumo_state_url);
1083         str_free(&fumo_state_data);
1084
1085         _DEBUG_INFO(" end error : %d\n", ret);
1086         _EXTERN_FUNC_EXIT;
1087         return ret;
1088 }
1089
1090 static DM_ERROR __check_low_battery()
1091 {
1092         _INNER_FUNC_ENTER;
1093
1094         DM_ERROR ret = DM_OK;
1095         char *battery_level = 0;
1096
1097         ret = get_battery_state(&battery_level);
1098         if (ret != DM_OK)
1099                 goto error;
1100
1101         int int_battery_level = 0;
1102         if (battery_level != NULL) {
1103                 int err;
1104                 err = chartoint((battery_level), &int_battery_level);
1105                 if (err == 1) {
1106                         _DEBUG_VERBOSE("battery level : %d ", int_battery_level);
1107                         if (FOTA_LOW_BATTERY_LEVEL > int_battery_level) {
1108                                 int noti_ret = 0;
1109                                 _DEBUG_VERBOSE("batter : %s, low battery : %d", battery_level, FOTA_LOW_BATTERY_LEVEL);
1110                                 noti_ret = noti_low_battery(battery_level);
1111                                 _DEBUG_VERBOSE("noti low battery : %d", noti_ret);
1112
1113                                 goto error;
1114                         } else {
1115                                 //do nothing
1116                         }
1117                 } else {
1118                         _DEBUG_VERBOSE("battery level is null");
1119                         ret = COMMON_ERR_IS_NULL;
1120                         goto error;
1121                 }
1122         } else {
1123                 _DEBUG_VERBOSE("battery level is null");
1124                 ret = COMMON_ERR_IS_NULL;
1125                 goto error;
1126         }
1127         _DEBUG_VERBOSE("end");
1128         return ret;
1129  error:
1130         _DEBUG_VERBOSE("end error : %d", DM_LOW_BATTERY_ERROR);
1131         _INNER_FUNC_EXIT;
1132         return DM_LOW_BATTERY_ERROR;
1133 }
1134
1135 static DM_ERROR __check_memory(long double file_size, MEMORY_TYPE * is_internal_memory)
1136 {
1137         _INNER_FUNC_ENTER;
1138
1139         DM_ERROR ret = DM_OK;
1140         int ipc_ret = 0;
1141         int existed_sd;
1142         long double need_size = file_size * 2;
1143
1144         ret = compare_memory_space(FOTA_DELTA_INTERNAL_STORAGE, need_size);
1145
1146         if (ret != DM_OK) {
1147                 ret = existed_sd_card_memory(&existed_sd);
1148                 if (existed_sd == 0 || ret != DM_OK) {
1149                         /* ui ->not existed sd card or make folder error */
1150                         ipc_ret = noti_over_max_file_size();
1151                         if (ipc_ret == RESPONSE_TYPE_OK) {
1152                                 _DEBUG_VERBOSE("file size over the memory");
1153                         } else {
1154                                 _DEBUG_VERBOSE("file size over the memory ipc fail");
1155                         }
1156                         _INNER_FUNC_EXIT;
1157                         return DM_OVER_MEMORY_ERROR;
1158                 }
1159
1160                 /* ui -> do u want to use sd_card? */
1161                 ipc_ret = noti_memory_full((int)need_size);
1162                 if (ipc_ret == RESPONSE_TYPE_OK) {
1163
1164                         //FOTA_DELTA_SD_INTERNAL_STORAGE
1165                         ret = compare_memory_space(FOTA_DELTA_SD_EXTERNAL_STORAGE, need_size);
1166                         if (ret == DM_MEMORY_ERROR) {
1167                                 /* ui ->  sd_card full */
1168                                 ipc_ret = noti_over_max_file_size();
1169                                 if (ipc_ret == RESPONSE_TYPE_OK) {
1170                                         _DEBUG_VERBOSE("file size over the memory");
1171                                 } else {
1172                                         _DEBUG_VERBOSE("file size over the memory ipc fail");
1173                                 }
1174                                 _INNER_FUNC_EXIT;
1175                                 return DM_OVER_MEMORY_ERROR;
1176                         } else {
1177                                 _DEBUG_VERBOSE("save in sd memory card");
1178                         }
1179
1180                 } else {
1181                         _DEBUG_VERBOSE("memory full ipc fail");
1182                         _INNER_FUNC_EXIT;
1183                         return DM_OVER_MEMORY_ERROR;
1184                 }
1185                 /*sd card path */
1186                 (*is_internal_memory) = MEMORY_SD_CARD;
1187         } else {
1188
1189                 /*internal memory path */
1190                 (*is_internal_memory) = MEMORY_INTERNAL;
1191         }
1192
1193         _INNER_FUNC_EXIT;
1194         return DM_OK;
1195 }
1196
1197 static DM_ERROR ___get_max_file_size(int *max_file_size)
1198 {
1199         _INNER_FUNC_ENTER;
1200
1201         int err = 0;
1202         char *required_contents = NULL;
1203         unsigned long size_return = 0;
1204
1205         err = sync_agent_is_existing_fs(MAX_DELTA_FILE_SIZE);
1206         /*define value when this is file not existed */
1207         if (err == 0) {
1208                 _DEBUG_VERBOSE("max file size : 50MB");
1209                 *max_file_size = MAX_FILE_SIZE;
1210                 _INNER_FUNC_EXIT;
1211                 return DM_OK;
1212         }
1213
1214         /*value when this is file existed */
1215         err = sync_agent_read_whole_file(MAX_DELTA_FILE_SIZE, &required_contents, &size_return);
1216         if (err == 1) {
1217                 _DEBUG_VERBOSE("max file size : %s", required_contents);
1218
1219                 err = chartoint(required_contents, max_file_size);
1220                 if (err == 1) {
1221                         str_free(&required_contents);
1222                         _INNER_FUNC_EXIT;
1223                         return DM_OK;
1224                 } else {
1225                         _DEBUG_VERBOSE("get max file size error");
1226                         _INNER_FUNC_EXIT;
1227                         return COMMON_ERR_IS_NULL;
1228                 }
1229         } else {
1230                 _DEBUG_VERBOSE("get max file size error");
1231                 _INNER_FUNC_EXIT;
1232                 return COMMON_ERR_IS_NULL;
1233         }
1234         _DEBUG_VERBOSE("get max file size error");
1235
1236         _INNER_FUNC_EXIT;
1237         return COMMON_ERR_IS_NULL;
1238 }
1239
1240 static DM_ERROR __check_max_file_size(int file_size)
1241 {
1242         _INNER_FUNC_ENTER;
1243
1244         DM_ERROR ret = DM_OK;
1245         int noti_res = 0;
1246
1247         int max_file_size = 0;
1248         ret = ___get_max_file_size(&max_file_size);
1249         if (ret != DM_OK) {
1250                 _DEBUG_VERBOSE("get max file size error");
1251                 ret = DM_WIFI_ONLY_ERROR;
1252                 goto error;
1253         }
1254         _DEBUG_VERBOSE("file size = %d, max file size = %d", file_size, max_file_size);
1255
1256         /*max_file_size = 0 (0 in file or not existed file)
1257          *  - can't use this option
1258          *  - this option is max file size define in file when 3g mode
1259          */
1260         if (max_file_size != 0 && file_size > max_file_size) {
1261                 noti_res = noti_over_max_file_size();
1262                 _DEBUG_VERBOSE("noti over max file size : %d", noti_res);
1263
1264                 _DEBUG_VERBOSE("can't save current_size on 3g mode");
1265                 ret = DM_WIFI_ONLY_ERROR;
1266                 goto error;
1267
1268         } else {
1269                 _DEBUG_VERBOSE("save current size on 3g mode");
1270         }
1271
1272         _INNER_FUNC_EXIT;
1273         return ret;
1274
1275  error:
1276
1277         _DEBUG_INFO("end error : %d", ret);
1278         _INNER_FUNC_EXIT;
1279         return ret;
1280 }