From: saerome.kim Date: Mon, 15 Jan 2018 08:32:09 +0000 (+0900) Subject: mot-agent: fix bugs when MOT failsure occurs after MOT & remove MO X-Git-Tag: submit/tizen/20190131.065036~220 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a01601096a2e1794b9cde6e099fa419ce1375dfd;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git mot-agent: fix bugs when MOT failsure occurs after MOT & remove MO Even if we remove MO information at remote device, our local provisioning tool has CRED info for remote device. So in this case, 2nd trial of MOT always fails due to remained CRED info. for remote device. - add 'remove_cred_local' & 'remove_cred_local_done' GDBus signal - To remove MO information: 1. Call 'remove_mo' 2. Call 'remove_cred_local' Signed-off-by: saerome.kim --- diff --git a/oic_svr_db_ma.dat b/oic_svr_db_ma.dat new file mode 100644 index 0000000..14e9ffa Binary files /dev/null and b/oic_svr_db_ma.dat differ diff --git a/src/companion-manager/include/comp_mot_agent.h b/src/companion-manager/include/comp_mot_agent.h index abebe8a..53c4980 100755 --- a/src/companion-manager/include/comp_mot_agent.h +++ b/src/companion-manager/include/comp_mot_agent.h @@ -33,6 +33,7 @@ int agent_pairwise(char* target1, char *subject1, char *uri1, char *rt1, char *interface1, int permission1, char* target2, char *subject2, char *uri2, char *rt2, char *interface2, int permission2); int agent_remove_mo_at_device(char* uuid_str); +int agent_remove_cred_at_local(char* uuid_str); int agent_remove_myowned_device(char* uuid_str); #endif /* __COMP_MOT_AGENT_H__ */ \ No newline at end of file diff --git a/src/companion-manager/src/comp_mot_agent.c b/src/companion-manager/src/comp_mot_agent.c index d1f3cb9..413004e 100755 --- a/src/companion-manager/src/comp_mot_agent.c +++ b/src/companion-manager/src/comp_mot_agent.c @@ -203,6 +203,32 @@ int agent_remove_mo_at_device(char* uuid_str) return result; } +int agent_remove_cred_at_local(char* uuid_str) +{ + GVariant *variant = NULL; + int result = COMP_ERROR_NONE; + GError *error = NULL; + + if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) { + LOG_ERR("I/O error"); + return COMP_ERROR_IO_ERROR; + } + + variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "remove_cred_local", + g_variant_new("(s)", uuid_str), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (variant) { + g_variant_get(variant, "(i)", &result); + LOGD("remove_cred_cocal status 0x%x", result); + } else if (error) { + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return COMP_ERROR_IO_ERROR; + } + + return result; +} + + int agent_remove_myowned_device(char* uuid_str) { GVariant *variant = NULL; @@ -553,6 +579,9 @@ static void _agent_signal_handler(GDBusConnection *connection, } else if (0 == g_strcmp0(signal_name, "remove_mo_done")) { g_variant_get(parameters, "(i)", &result); LOG_DEBUG("Result : %d", result); + } else if (0 == g_strcmp0(signal_name, "remove_cred_local_done")) { + g_variant_get(parameters, "(i)", &result); + LOG_DEBUG("Result : %d", result); comp_group_notify_group_dismiss(result); } else if (0 == g_strcmp0(signal_name, "pairwise_done")) { @@ -623,6 +652,17 @@ static int _subscribe_event() h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); LOG_DEBUG("subscribed for (remove_mo_done) signal %d", id); + /* remove_cred_local_done */ + id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME, + "remove_cred_local_done", AGENT_OBJECT_PATH, NULL, + G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL); + if (0 == id) { + LOG_ERR("g_dbus_connection_signal_subscribe(remove_cred_local_done) Fail(%d)", errno); + return -1; + } + h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id)); + LOG_DEBUG("subscribed for (remove_cred_local_done) signal %d", id); + /* acl_done */ id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME, "acl_done", AGENT_OBJECT_PATH, NULL, diff --git a/src/mot-agent/introspection/ma.xml b/src/mot-agent/introspection/ma.xml index de168bc..6165439 100644 --- a/src/mot-agent/introspection/ma.xml +++ b/src/mot-agent/introspection/ma.xml @@ -22,6 +22,10 @@ + + + + @@ -77,6 +81,9 @@ + + + diff --git a/src/mot-agent/ma-db.c b/src/mot-agent/ma-db.c index edf9ff9..3c12909 100644 --- a/src/mot-agent/ma-db.c +++ b/src/mot-agent/ma-db.c @@ -126,7 +126,7 @@ static OCStackResult rollback() return OC_STACK_OK; } -int openDB() +int ma_open_db() { int result = 0; char path[MAX_FILE_PATH_LEN] = {0,}; @@ -142,7 +142,7 @@ int openDB() return OC_STACK_OK; } -int closeDB() +int ma_close_db() { CHECK_PDM_INIT(); int res = 0; @@ -235,7 +235,7 @@ static OCStackResult removeFromDeviceList(int id) return OC_STACK_OK; } -int PDMDeleteDevice(const OicUuid_t *UUID) +int ma_delete_device(const OicUuid_t *UUID) { CHECK_PDM_INIT(); if (NULL == UUID) @@ -282,7 +282,7 @@ static OCStackResult removeLink(int id1, int id2) return OC_STACK_OK; } -int PDMUnlinkDevices(const OicUuid_t *UUID1, const OicUuid_t *UUID2) +int ma_unlink_devices(const OicUuid_t *UUID1, const OicUuid_t *UUID2) { CHECK_PDM_INIT(); if (NULL == UUID1 || NULL == UUID2) diff --git a/src/mot-agent/ma-db.h b/src/mot-agent/ma-db.h index 4eb8a6c..47ef03e 100644 --- a/src/mot-agent/ma-db.h +++ b/src/mot-agent/ma-db.h @@ -23,10 +23,10 @@ extern "C" { #endif -int openDB(); -int closeDB(); -int PDMDeleteDevice(const OicUuid_t *UUID); -int PDMUnlinkDevices(const OicUuid_t *UUID1, const OicUuid_t *UUID2); +int ma_open_db(); +int ma_close_db(); +int ma_delete_device(const OicUuid_t *UUID); +int ma_unlink_devices(const OicUuid_t *UUID1, const OicUuid_t *UUID2); #ifdef __cplusplus } diff --git a/src/mot-agent/ma-service-interface.c b/src/mot-agent/ma-service-interface.c index 7e84e09..c021b22 100644 --- a/src/mot-agent/ma-service-interface.c +++ b/src/mot-agent/ma-service-interface.c @@ -204,6 +204,23 @@ static gboolean _ma_dbus_handle_remove_mo(NetMa *object, return TRUE; } +static gboolean _ma_dbus_handle_remove_cred_local(NetMa *object, + GDBusMethodInvocation *invocation, gchar *arg_target, gpointer user_data) +{ + int ret = MA_ERROR_NONE; + ma_service *service = (ma_service *)user_data; + + ma_check_null_ret_error("service", service, FALSE); + + + ret = ma_request_remove_cred_local(service, arg_target); + if (MA_ERROR_NONE != ret) + MA_LOGE("Failed to ma_request_remove_mo !"); + + net_ma_complete_remove_cred_local(object, invocation, ret); + + return TRUE; +} static gboolean _ma_dbus_handle_acl(NetMa *object, GDBusMethodInvocation *invocation, gchar *arg_target, gchar *arg_subject, gchar *arg_uri, @@ -329,6 +346,8 @@ static void _ma_dbus_on_bus_acquired(GDBusConnection *conn, const gchar *name, G_CALLBACK(_ma_dbus_handle_mot), service); g_signal_connect(ma_dbus_object, "handle-remove-mo", G_CALLBACK(_ma_dbus_handle_remove_mo), service); + g_signal_connect(ma_dbus_object, "handle-remove-cred-local", + G_CALLBACK(_ma_dbus_handle_remove_cred_local), service); g_signal_connect(ma_dbus_object, "handle-acl", G_CALLBACK(_ma_dbus_handle_acl), service); g_signal_connect(ma_dbus_object, "handle-cred", diff --git a/src/mot-agent/ma-subowner.c b/src/mot-agent/ma-subowner.c index 9c8cdf9..a7c37c9 100644 --- a/src/mot-agent/ma-subowner.c +++ b/src/mot-agent/ma-subowner.c @@ -783,6 +783,9 @@ static gboolean _ma_timeout_cb(gpointer data) case MA_REMOVE_MOT: net_ma_emit_remove_mo_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED); break; + case MA_REMOVE_CRED_LOCAL: + net_ma_emit_remove_cred_local_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED); + break; case MA_UNPAIR: net_ma_emit_unpair_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED); break; @@ -898,8 +901,10 @@ static int _disc_owned_devs(ma_service *service) static void _mot_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has_error) { +#if MANIPULATE_LOCAL_PDM int i = 0; int ret = OC_STACK_OK; +#endif ma_subowner_s *client = (ma_subowner_s *)ctx; if (!has_error) { @@ -908,19 +913,20 @@ static void _mot_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has_error MA_LOGD( "Multiple Ownership Transfer FAILED "); _print_result_list((const OCProvisionResult_t*) arr, num); - - ret = openDB(); +#if MANIPULATE_LOCAL_PDM + ret = ma_open_db(); if (OC_STACK_OK != ret) MA_LOGE( "openDB: ret = %d (%s)", ret, _error_to_string(ret)); for ( ; num > i; ++i) { if (OC_STACK_OK !=arr[i].res) { - ret = PDMDeleteDevice((const OicUuid_t*) &arr[i].deviceId); + ret = ma_delete_device((const OicUuid_t*) &arr[i].deviceId); } } - ret = closeDB(); + ret = ma_close_db(); if (OC_STACK_OK != ret) MA_LOGE( "closeDB: ret = %d (%s)", ret, _error_to_string(ret)); +#endif } client->g_doneCB = true; } @@ -1037,7 +1043,6 @@ static void _remove_mo_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has _print_result_list((const OCProvisionResult_t*) arr, num); } client->g_doneCB = true; - OCTerminatePM(); } static gpointer _remove_mo_func(gpointer data) @@ -1068,17 +1073,17 @@ static gpointer _remove_mo_func(gpointer data) MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]", ret, _error_to_string(ret)); goto MOT_ENDED; } - - ret = openDB(); +#if MANIPULATE_LOCAL_PDM + ret = ma_open_db(); if (OC_STACK_OK != ret) MA_LOGE( "openDB: ret = %d (%s)", ret, _error_to_string(ret)); - ret = PDMDeleteDevice((const OicUuid_t*) uuid_target); + ret = ma_delete_device((const OicUuid_t*) uuid_target); if (OC_STACK_OK != ret) MA_LOGE( "delete_mowned_device_db: ret = %d (%s)", ret, _error_to_string(ret)); - ret = closeDB(); + ret = ma_close_db(); if (OC_STACK_OK != ret) MA_LOGE( "closeDB: ret = %d (%s)", ret, _error_to_string(ret)); - +#endif ret = OCRemoveSubOwner(g_client, src_dev, &uuid_mowner, _remove_mo_cb); if (OC_STACK_OK != ret ) { MA_LOGE( "OCRemoveSubOwner: ret = %d (%s)", ret, _error_to_string(ret)); @@ -1134,6 +1139,92 @@ static int _ma_remove_mo(ma_service *service, gchar *uuid_str) return MA_ERROR_NONE; } +static void _remove_remove_cred_local_cb(void* ctx, int num, + OCProvisionResult_t* arr, bool has_error) +{ + ma_subowner_s *client = (ma_subowner_s *)ctx; + + if (!has_error) { + MA_LOGD("Remove CRED for mowned device SUCCEEDED"); + } else { + MA_LOGD( "Remove CRED for mowned device FAILED "); + _print_result_list((const OCProvisionResult_t*) arr, num); + } + client->g_doneCB = true; +} + +static gpointer _remove_cred_local_func(gpointer data) +{ + OCStackResult ret = OC_STACK_OK; + ma_req_cb_s *con = (ma_req_cb_s *)data; + + OicUuid_t *uuid = NULL; + + if (!con->target_to_revoke) { + MA_LOGE("Some parameters are wrong"); + MA_LOGE("%s", con->target_to_revoke ); + goto PVACL_ERROR; + } + + uuid = _convert_uuid(con->target_to_revoke); + + g_client->g_doneCB = false; + MA_LOGI(" Removing CRED for remote device at local SVR DB"); + + ret = OCRemoveDeviceWithUuid((void*) g_client, CALLBACK_TIMEOUT_5S, uuid, + _remove_remove_cred_local_cb ); + if (OC_STACK_OK != ret) { + MA_LOGD( "OCRemoveDeviceWithUuid API error: %d (%s)", ret, _error_to_string(ret)); + goto PVACL_ERROR; + } + + ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S); + if (ret) { + MA_LOGE( "OCRemoveDeviceWithUuid Faild = %d", errno); + goto PVACL_ERROR; + } + /* Disaply result result */ + MA_LOGI(" Removing CRED info. at local SVR DB - Done"); + +PVACL_ERROR: + /* Notify ACL result */ + net_ma_emit_remove_cred_local_done(ma_dbus_get_object(), (int)ret); + if (uuid) + g_free(uuid); + _request_cleanup(con); + g_thread_exit(GINT_TO_POINTER (1)); + return NULL; +} + +static int _ma_remove_cred_local(ma_service *service, gchar *uuid_str) +{ + ma_req_cb_s *con = NULL; + con = g_malloc0(sizeof(ma_req_cb_s)); + if (NULL == con) { + MA_LOGE( "g_malloc0() Fail=%d", errno); + /* Unset d2ds status 'pending' */ + g_atomic_int_set(&service->pending, 0); + return MA_ERROR_OUT_OF_MEMORY; + } + + con->userdata = service; + con->cid = MA_REMOVE_CRED_LOCAL; + con->target_to_revoke = g_strdup(uuid_str); + + con->thread = g_thread_try_new("remove_mowned_dev_cred", _remove_cred_local_func, con, NULL); + if (!con->thread) { + MA_LOGE("Failed to create thread"); + _request_cleanup(con); + return MA_ERROR_OUT_OF_MEMORY; + } + g_thread_unref(con->thread); + +#ifdef TIMEOUT_USED + con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S + 1, _ma_timeout_cb, con); +#endif + return MA_ERROR_NONE; +} + #if 0 /* TEST */ static int sendGetLed() { @@ -1988,6 +2079,31 @@ int ma_request_remove_mo(ma_service *service, gchar* uuid_str) return ret; } +int ma_request_remove_cred_local(ma_service *service, gchar* uuid_str) +{ + int ret =MA_ERROR_NONE; + + ma_check_null_ret_error("service", service, FALSE); + + MA_LOGD("[IPC] Remove CRED for Owned Dev in my SVR DB"); + + /* If we are working now? */ + if (g_atomic_int_get(&service->pending)) + return MA_ERROR_IN_PROGRESS; + + if (!uuid_str) { + MA_LOGE("uuid_str = %s", uuid_str); + return MA_ERROR_INVALID_PARAMETER; + } + + /* Set d2ds status 'pending' */ + g_atomic_int_set(&service->pending, 1); + + ret = _ma_remove_cred_local(service, uuid_str); + + return ret; +} + int ma_request_prov_acl(ma_service *service, gchar *target, gchar *subject, gchar *rsrc_uri, gchar *rsrc_type, gchar *rsrc_interface, int permission) { diff --git a/src/mot-agent/ma-subowner.h b/src/mot-agent/ma-subowner.h index 0d60c7f..3c5c1ac 100644 --- a/src/mot-agent/ma-subowner.h +++ b/src/mot-agent/ma-subowner.h @@ -33,6 +33,7 @@ typedef enum { MA_PROV_ACL, /**< ACL Provisioning */ MA_PROV_CRED, /**< CRED Provisioning */ MA_REMOVE_MOT, /**< Remove Multiple Ownership */ + MA_REMOVE_CRED_LOCAL, /**< Remove CRED my owned device in MOT agent's SVR DB */ MA_UNPAIR, /**< Unpair */ MA_PROV_PAIRWISE, /** < Pairwise Provisioning */ } ma_cmd_id_e; @@ -52,6 +53,7 @@ int ma_request_disc_mot_enb_devs(ma_service *service); int ma_request_disc_owned_devs(ma_service *service); int ma_request_mot(ma_service *service, gchar* uuid, gchar *pin); int ma_request_remove_mo(ma_service *service, gchar* uuid_str); +int ma_request_remove_cred_local(ma_service *service, gchar* uuid_str); int ma_request_prov_acl(ma_service *service, gchar *target, gchar *subject, gchar *rsrc_uri, gchar *rsrc_type, gchar *rsrc_interface, int permission); int ma_request_prov_cred(ma_service *service, gchar *uuid_dev1,