3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <glib/gprintf.h>
27 #include <sync_agent.h>
29 #include "plugin_devexe_error.h"
32 #define EXPORT_API __attribute__ ((visibility("default")))
35 #ifndef OMADM_AGENT_LOG
37 #define LOG_TAG "PLUGIN_LAWMO"
42 #define ROOT "./Ext/OSPS"
63 typedef int (*Execute_Device) (int plugin_name, ...);
65 lawmo_ext_name_e ext_name;
66 char *main_path; /* path except to root path */
67 Execute_Device func_execute_device;
70 static sync_agent_dev_return_e _fully_lock(int platform, int *err_num, int check_operation);
71 static sync_agent_dev_return_e _partially_lock(int platform, int *err_num, int check_operation);
72 static sync_agent_dev_return_e _unlock(int platform, int *err_num, int check_operation);
73 static sync_agent_dev_return_e _factory_reset(int platform, int *err_num, int check_operation);
74 static sync_agent_dev_return_e _remote_wipe(int platform, int *err_num, int check_operation);
75 static sync_agent_dev_return_e _ring_my_phone_start(int platform, int *err_num, int check_operation);
76 static sync_agent_dev_return_e _ring_my_phone_stop(int platform, int *err_num, int check_operation);
77 static sync_agent_dev_return_e _mobile_tracking_get_location(int platform, int *err_num, int check_operation);
78 static sync_agent_dev_return_e _mobile_tracking_operation_stop(int platform, int *err_num, int check_operation);
79 static sync_agent_dev_return_e _mobile_tracking_operation(int platform, int *err_num, int check_operation);
80 static sync_agent_dev_return_e _forwarding_diver_request(int platform, int *err_num, int check_operation);
81 static sync_agent_dev_return_e _master_key_lock_release(int platform, int *err_num, int check_operation);
83 static ext_function_s ext_functions[] = {
86 {FULLY_LOCK, "LAWMO/OSP/Operations/FullyLock", (Execute_Device) _fully_lock},
87 {PARTAILLY_LOCK, "LAWMO/OSP/Operations/PartiallyLock", (Execute_Device) _partially_lock},
88 {UNLOCK, "LAWMO/OSP/Operations/UnLock", (Execute_Device) _unlock},
89 {FACTORY_RESET, "LAWMO/OSP/Operations/FactoryReset", (Execute_Device) _factory_reset},
90 {WIPE, "LAWMO/OSP/Operations/Wipe", (Execute_Device) _remote_wipe},
91 /* TODO : should add the lock&wipe interface */
95 {RING_START, "LAWMO/OSP/Ext/RingMyPhone/Operations/Start", (Execute_Device) _ring_my_phone_start},
96 {RING_STOP, "LAWMO/OSP/Ext/RingMyPhone/Operations/Stop", (Execute_Device) _ring_my_phone_stop},
100 {MT_LOCATION, "MobileTraking/Operation/Get/Location", (Execute_Device) _mobile_tracking_get_location},
101 {MT_STOP, "MobileTracking/Operations/Stop", (Execute_Device) _mobile_tracking_operation_stop},
102 {MT_TRACKING, "MobileTracking/Operations/Tracking", (Execute_Device) _mobile_tracking_operation},
106 {FW_DIVERTREQUEST, "Forwarding/Operations/DivertRequest", (Execute_Device) _forwarding_diver_request},
110 {MK_LOCK, "MasterKey/Operations/LockRelease", (Execute_Device) _master_key_lock_release},
112 {0, 0} /* end array */
115 static sync_agent_get_devinfo_cb func_get_dev_Info = 0;
117 /* static function */
118 static char *_get_main_path(const char *mo_path);
120 //static int _get_index(const char *name);
121 //static char *_get_mo_value_str(const char *vconf_key, int n_index);
123 EXPORT_API char **sync_agent_plugin_get_server_id_list(int *server_id_list_cnt)
127 *server_id_list_cnt = 0;
128 char **temp_id_list = (char **)calloc(SERVER_NUM, sizeof(char *));
129 if (temp_id_list == NULL) {
134 char *sever_name = 0;
139 for (i = 0; i < SERVER_NUM; i++) {
143 sever_name = ALTER_SYNCMLDM_ACCNAME_1;
146 sever_name = ALTER_SYNCMLDM_ACCNAME_2;
150 server_idx = _get_index(sever_name);
151 server_id = _get_mo_value_str(CSC_VCONF_KEY_SYNCMLDM_SERVID, server_idx);
152 if (server_id == NULL) {
155 server_id = strdup(ALTER_SYNCMLDM_SERVID_1);
158 server_id = strdup(ALTER_SYNCMLDM_SERVID_2);
162 _DEBUG_INFO("Temp_id_list[%d] = %s\n", i, server_id);
163 temp_id_list[i] = server_id;
164 (*server_id_list_cnt)++;
166 _DEBUG_INFO("server_id_list_cnt = %d\n", *server_id_list_cnt);
171 *server_id_list_cnt = 1;
172 char **temp_id_list = (char **)calloc(SERVER_NUM, sizeof(char *));
173 if (temp_id_list == NULL) {
177 char *server_id = NULL;
178 server_id = strdup("*");
179 *temp_id_list = server_id;
181 _DEBUG_INFO("lawmo server_id = %s\n", server_id);
182 _DEBUG_INFO("lawmo server_id_list_cnt = %d\n", *server_id_list_cnt);
188 EXPORT_API int sync_agent_plugin_get_mo_value(const char *mo_pull_path, const char *mo_name, char **mo_value)
192 _DEBUG_INFO("mo_name : %s", mo_name);
195 if (mo_pull_path == NULL || mo_name == NULL) {
199 _DEBUG_INFO("mo_value : %s", *mo_value);
205 EXPORT_API void sync_agent_plugin_set_function_get_devinfo(sync_agent_get_devinfo_cb func)
209 func_get_dev_Info = func;
214 EXPORT_API int sync_agent_plugin_initialize()
219 result = 0; //req_fmm_server_reg(NULL);
234 EXPORT_API int sync_agent_plugin_execute_ext(const char *mo_path, int *err_num, int check_operation)
238 if (mo_path == NULL) {
239 _DEBUG_INFO("mo_path is NULL\n");
243 _DEBUG_INFO("mo_path = %s\n", mo_path);
245 char *main_path = _get_main_path(mo_path);
246 if (main_path == NULL) {
247 _DEBUG_INFO("main_path is NULL\n");
251 _DEBUG_INFO("main_path = %s\n", main_path);
257 while (ext_functions[i].main_path != 0 && ext_functions[i].func_execute_device != 0) {
258 _DEBUG_INFO("oper 1 %s", main_path);
259 _DEBUG_INFO("oper 2 %s", ext_functions[i].main_path);
260 if (strcmp(main_path, ext_functions[i].main_path) == 0) {
261 _DEBUG_INFO("%s Part", main_path);
263 slp_exe_ret = ext_functions[i].func_execute_device(1, err_num, check_operation);
264 _DEBUG_INFO("execute return : %d", slp_exe_ret);
266 if (slp_exe_ret != SYNC_AGENT_DEV_RETURN_SUCCESS) {
268 _DEBUG_INFO("--------------------------------------lawmo operation fail : %d---------------------------------\n", (*err_num));
270 //*err_num = __convert_errcode(ext_functions[i].ext_name, slp_exe_ret);
271 _DEBUG_INFO("--------------------------------------lawmo result value : %d---------------------------------\n", (*err_num));
275 _DEBUG_INFO("--------------------------------------not search lawmo operation---------------------------------\n");
280 if (main_path != NULL)
287 static char *_get_main_path(const char *mo_path)
291 int root_length = strlen(ROOT);
292 int mo_path_length = strlen(mo_path);
296 char *ptr = strstr(mo_path, ROOT);
297 if (ptr != NULL && root_length < mo_path_length) {
298 _DEBUG_TRACE("%s Search Success !!\n", ROOT);
299 main_path = g_strdup_printf("%s", mo_path + (root_length + 1));
308 static int _get_index(const char *name)
317 if (vconf_get_int(CSC_VCONF_KEY_SYNCMLDM_NBFIELD, &n_acc_count)) {
318 _DEBUG_TRACE("vconf_get_int FAIL");
320 n_acc_count =ALTER_SYNCMLDM_NBFIELD;
323 _DEBUG_TRACE("nAccCount : %d", n_acc_count);
326 for (; i < n_acc_count; i++) {
327 char *compare_name = _get_mo_value_str(CSC_VCONF_KEY_SYNCMLDM_ACCNAME, i + 1);
328 if (compare_name == NULL) {
331 compare_name = ALTER_SYNCMLDM_ACCNAME_1;
334 compare_name = ALTER_SYNCMLDM_ACCNAME_2;
341 _DEBUG_TRACE("[%d] compare_name : %s [%d], name : %s [%d]", i, compare_name, strlen(compare_name), name, strlen(name));
342 if (!strcmp(name, compare_name)) {
343 _DEBUG_TRACE("nIndex : %d", i + 1);
353 static char *_get_mo_value_str(const char *vconf_key, int n_index)
362 char input_vconf_path[200] = { 0, };
365 memset(rec_idx, 0x0, sizeof(rec_idx));
366 snprintf(rec_idx, sizeof(rec_idx), "%d", n_index);
367 snprintf(input_vconf_path, strlen(vconf_key) + strlen(rec_idx) + 1, vconf_key, n_index);
369 char *value = vconf_get_str(input_vconf_path);
371 _DEBUG_TRACE("vconf_get_str FAIL");
380 static sync_agent_dev_return_e _fully_lock(int platform, int *err_num, int check_operation)
385 _DEBUG_TRACE("====================Fully_Lock==================== \n");
386 _DEBUG_TRACE("check_operarion [%d]\n", check_operation);
390 if (check_operation == 1) {
391 _DEBUG_TRACE("checked : 1 =======return 202 =======\n");
395 return_value = EXE_SUCCESS; //exec_fully_lock();
396 _DEBUG_TRACE("checked : 0 =======return :%d =======\n", return_value);
398 if (return_value == EXE_SUCCESS) {
399 *err_num = OPERATION_SUCCEEDED;
401 *err_num = CLIENT_ERROR;
407 return SYNC_AGENT_DEV_RETURN_SUCCESS;
411 static sync_agent_dev_return_e _partially_lock(int platform, int *err_num, int check_operation)
416 _DEBUG_TRACE("====================Partially_Lock==================== \n");
418 int return_value = OPERATION_SUCCEEDED;
420 return PARTIALLY_LOCK_DEVICE_FAILED;
421 sync_agent_execute_dev_function(2, "partial_lock", 0);
422 vconf_get_bool(VCONFKEY_SETAPPL_FIND_MY_MOBILE_REMOTE_CONTROL_BOOL, &rc_status));
428 *err_num = return_value;
431 return SYNC_AGENT_DEV_RETURN_SUCCESS;
434 static sync_agent_dev_return_e _unlock(int platform, int *err_num, int check_operation)
439 _DEBUG_TRACE("====================UnLock==================== \n");
440 _DEBUG_TRACE("check_operarion [%d]\n", check_operation);
442 int return_value = OPERATION_SUCCEEDED;
444 *err_num = return_value;
447 return SYNC_AGENT_DEV_RETURN_SUCCESS;
450 static sync_agent_dev_return_e _factory_reset(int platform, int *err_num, int check_operation)
455 _DEBUG_TRACE("====================Factory_Reset==================== \n");
456 int return_value = OPERATION_SUCCEEDED;
459 vconf_get_bool(VCONFKEY_SETAPPL_FIND_MY_MOBILE_REMOTE_CONTROL_BOOL, &rc_status));
465 *err_num = return_value;
468 return SYNC_AGENT_DEV_RETURN_SUCCESS;
471 static sync_agent_dev_return_e _remote_wipe(int platform, int *err_num, int check_operation)
475 _DEBUG_TRACE("====================Remote_Wipe==================== \n");
477 int return_value = 202;
478 if (check_operation == 1) {
480 vconf_get_bool(VCONFKEY_SETAPPL_FIND_MY_MOBILE_REMOTE_CONTROL_BOOL, &rc_status));
486 *err_num = return_value;
488 return_value = OPERATION_SUCCEEDED; //exec_wipe_out();
489 g_printf("checked : 0 =======return :%d =======\n", return_value);
490 *err_num = return_value;
493 sync_agent_execute_dev_function(2, "factory_reset", 0);
494 return WIPE_OPERATION_NOT_PERFORMED;
495 return WIPE_DEVICES_DATA_FAILED;
496 return EXTERNAL_AND_SIM_MEMORY_WIPE_FAILED;
497 return EXTERNAL_MEMORY_WIPE_FAILED;
498 return SIM_MEMORY_WIPE_FAILED;
501 return SYNC_AGENT_DEV_RETURN_SUCCESS;
504 static sync_agent_dev_return_e _ring_my_phone_start(int platform, int *err_num, int check_operation)
509 _DEBUG_TRACE("====================Ring my phone start==================== \n");
510 _DEBUG_TRACE("check_operarion [%d]\n", check_operation);
514 if (check_operation == 1) {
516 vconf_get_bool(VCONFKEY_SETAPPL_FIND_MY_MOBILE_REMOTE_CONTROL_BOOL, &rc_status));
522 *err_num = OPERATION_SUCCEEDED;
525 return_value = EXE_SUCCESS; // exec_ring_start();
526 _DEBUG_TRACE("checked : 0 =======return :%d =======\n", return_value);
528 if (return_value == EXE_SUCCESS) {
529 *err_num = OPERATION_SUCCEEDED;
531 *err_num = AMT_STATUS_OFF;
537 return SYNC_AGENT_DEV_RETURN_SUCCESS;
540 static sync_agent_dev_return_e _ring_my_phone_stop(int platform, int *err_num, int check_operation)
544 _DEBUG_TRACE("====================Ring my phone stop====================\n");
545 _DEBUG_TRACE("check_operarion [%d]\n", check_operation);
547 int return_value = 202;
550 if (check_operation == 1) {
551 *err_num = return_value;
554 return_value = EXE_SUCCESS; //exec_ring_stop();
556 if (return_value == EXE_SUCCESS) {
557 *err_num = OPERATION_SUCCEEDED;
559 *err_num = OPERATION_SUCCEEDED;
565 return SYNC_AGENT_DEV_RETURN_SUCCESS;
568 static sync_agent_dev_return_e _mobile_tracking_get_location(int platform, int *err_num, int check_operation)
573 _DEBUG_TRACE("====================MobileTracking_Get_Location====================\n");
575 int return_value = 202;
576 if (check_operation == 1) {
578 vconf_get_bool(VCONFKEY_SETAPPL_FIND_MY_MOBILE_REMOTE_CONTROL_BOOL, &rc_status));
584 _DEBUG_TRACE("checked : 1 =======return 202 =======\n");
585 *err_num = return_value;
587 return_value = OPERATION_SUCCEEDED; // exec_location();
588 _DEBUG_TRACE("checked : 0 =======return :%d =======\n", return_value);
589 *err_num = return_value;
593 return SYNC_AGENT_DEV_RETURN_SUCCESS;
596 static sync_agent_dev_return_e _mobile_tracking_operation_stop(int platform, int *err_num, int check_operation)
601 _DEBUG_TRACE("====================MobileTracking_Operation_Stop====================\n");
604 *err_num = OPERATION_SUCCEEDED;
607 return SYNC_AGENT_DEV_RETURN_SUCCESS;
610 static sync_agent_dev_return_e _mobile_tracking_operation(int platform, int *err_num, int check_operation)
614 _DEBUG_TRACE("====================MobileTracking_Operation====================\n");
616 int return_value = 202;
617 if (check_operation == 1) {
618 *err_num = return_value;
620 *err_num = OPERATION_SUCCEEDED;
624 return SYNC_AGENT_DEV_RETURN_SUCCESS;
628 static sync_agent_dev_return_e _forwarding_diver_request(int platform, int *err_num, int check_operation)
633 _DEBUG_TRACE("====================Forwarding_DiverRequest====================\n");
634 int return_value = 202;
635 if (check_operation == 1) {
637 vconf_get_bool(VCONFKEY_SETAPPL_FIND_MY_MOBILE_REMOTE_CONTROL_BOOL, &rc_status));
643 //return return_value;
644 *err_num = return_value;
646 return_value = OPERATION_SUCCEEDED; // exec_call_forwarding();
647 _DEBUG_TRACE("checked : 0 =======return :%d =======\n", return_value);
648 *err_num = return_value;
651 return CALL_AND_SMS_FORWARDING_FAILED;
652 return CALL_FORWARDING_FAILED;
653 return SMS_FORWARDING_FAILED;
655 //return return_value;
658 return SYNC_AGENT_DEV_RETURN_SUCCESS;
662 static sync_agent_dev_return_e _master_key_lock_release(int platform, int *err_num, int check_operation)
666 _DEBUG_TRACE("====================MasterKey_LockRelease====================\n");
667 _DEBUG_TRACE("check_operarion [%d]\n", check_operation);
668 int return_value = 202;
671 if (check_operation == 1) {
672 *err_num = return_value;
675 return_value = EXE_SUCCESS; //exec_unlock_lock();
677 if (return_value == EXE_SUCCESS) {
678 *err_num = OPERATION_SUCCEEDED;
680 *err_num = OPERATION_SUCCEEDED;
686 return SYNC_AGENT_DEV_RETURN_SUCCESS;