Updated Invite / Eject operation for Tizen public iotivity 15/188315/4
authorJihoon Jung <jh8801.jung@samsung.com>
Tue, 4 Sep 2018 02:05:09 +0000 (11:05 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Tue, 11 Sep 2018 23:43:43 +0000 (08:43 +0900)
Even we modify Invite/Eject operation, unless developing provisionACL/CRED and Pairwise APIs done,
we have to use private iotivity in locally.

Change-Id: I543b087e72da5b6a767b32966aa5261d48c9ccda

src/mdg-manager/include/mdgd_iot.h
src/mdg-manager/include/mdgd_mot_agent.h
src/mdg-manager/include/mdgd_util.h
src/mdg-manager/src/mdgd_iot.cpp
src/mdg-manager/src/mdgd_iot_client.cpp
src/mdg-manager/src/mdgd_iot_server.cpp [changed mode: 0755->0644]
src/mdg-manager/src/mdgd_mot_agent.c
src/mdg-manager/src/mdgd_util.c [changed mode: 0755->0644]
src/mot-agent/ma-service-interface.c
src/mot-agent/ma-subowner.c

index 4a1abb6..00e36b7 100755 (executable)
@@ -42,6 +42,8 @@ int mdgd_iot_get_device_description(mdgd_command_t *cmd, char *host_addr, int co
 int mdgd_iot_send_response(char *sender, char *uuid, char *channel_id,
                                                 int msg_id, unsigned char *data, int len, bool timeout);
 int mdgd_iot_set_preconfigured_pin(char *pin);
+int mdgd_iot_remove_subowner(char *subject_id);
+int mdgd_iot_remove_secure_information(char *subject_id);
 int mdgd_iot_deinitialize();
 
 #ifdef __cplusplus
index e2959b2..b7731c2 100755 (executable)
@@ -27,6 +27,7 @@ int agent_dbus_stop();
 
 int agent_enable();
 int agent_disable();
+int agent_get_ownerid(char** deviceid);
 int agent_find_mot_enable_devices(char *sender, int timeout);
 int agent_find_mowned_devices(char *sender, int timeout);
 int agent_mot(char* uuid_str, char *pin);
index b88311c..6063155 100755 (executable)
@@ -30,6 +30,7 @@ extern "C"
 
 char *mdgd_addr2host(char *addr, int port, bool is_secure);
 int mdgd_uuid_to_str(const OicUuid_t* uuid, char** strUuid);
+int mdgd_str_to_uuid(const char *strUuid, OicUuid_t* uuid);
 void mdgd_clean_user_data(void *user_data);
 GVariant *mdgd_create_variant_group(mdgd_group_t *group);
 GVariant *mdgd_create_variant_device(mdgd_device_t *device);
index 5c15e53..0198a69 100755 (executable)
@@ -43,6 +43,7 @@
 #include "OCPlatform.h"
 #include "OCApi.h"
 #include "credresource.h"
+#include "aclresource.h"
 
 using namespace OC;
 using namespace std;
@@ -178,12 +179,74 @@ int mdgd_iot_set_preconfigured_pin(char *pin)
 {
        int ret = MDGD_ERROR_NONE;
 
+       LOG_BEGIN();
+
        ret = AddPreconfPinCredential(pin);
        if (ret != OC_STACK_OK) {
                LOG_ERR("set preconfigure pin failed : %d", ret);
                return MDGD_ERROR_OPERATION_FAILED;
        }
 
+       LOG_END();
+
+       return ret;
+}
+
+int mdgd_iot_remove_subowner(char *subject_id)
+{
+       int ret = MDGD_ERROR_NONE;
+       OicUuid_t uuid;
+
+       LOG_BEGIN();
+
+       LOG_DEBUG("Remove %s subowner", subject_id);
+
+       ret = mdgd_str_to_uuid(subject_id, &uuid);
+       if (ret != OC_STACK_OK) {
+               LOG_ERR("mdgd_str_to_uuid failed : %d", ret);
+               return MDGD_ERROR_OPERATION_FAILED;
+       }
+
+       ret = RemoveSubOwner(&uuid);
+       if (ret != OC_STACK_RESOURCE_DELETED) {
+               LOG_ERR("remove subowner failed : %d", ret);
+               return MDGD_ERROR_OPERATION_FAILED;
+       }
+
+       LOG_END();
+
+       return ret;
+}
+
+int mdgd_iot_remove_secure_information(char *subject_id)
+{
+       int ret = MDGD_ERROR_NONE;
+       OicUuid_t uuid;
+
+       LOG_BEGIN();
+
+       LOG_DEBUG("Remove %s secure information", subject_id);
+
+       ret = mdgd_str_to_uuid(subject_id, &uuid);
+       if (ret != OC_STACK_OK) {
+               LOG_ERR("mdgd_str_to_uuid failed : %d", ret);
+               return MDGD_ERROR_OPERATION_FAILED;
+       }
+
+       ret = RemoveACE(&uuid, NULL);
+       if (ret != OC_STACK_RESOURCE_DELETED) {
+               LOG_ERR("remove Access Control Entity failed : %d", ret);
+               return MDGD_ERROR_OPERATION_FAILED;
+       }
+
+       ret = RemoveCredential(&uuid);
+       if (ret != OC_STACK_RESOURCE_DELETED) {
+               LOG_ERR("remove cred failed : %d", ret);
+               return MDGD_ERROR_OPERATION_FAILED;
+       }
+
+       LOG_END();
+
        return ret;
 }
 
index dc5213c..e286ac5 100755 (executable)
@@ -418,6 +418,7 @@ static bool _found_resource(std::shared_ptr<OCResource> resource,
                                rep.setValue("CMD", cmd->type);
                                rep.setValue("DeviceID", std::string(mdgd_ctx->device_uuid));
                                rep.setValue("GroupName", std::string(cmd->arg1));
+                               rep.setValue("OwnerID", std::string(cmd->arg2));
 
                                resource->put(rep, QueryParamsMap(), std::bind(&__send_event_finish,
                                                std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
old mode 100755 (executable)
new mode 100644 (file)
index 79cd5ee..31e6cae
@@ -497,7 +497,7 @@ OCEntityHandlerResult _request_handler(std::shared_ptr<OCResourceRequest> reques
                                int result = MDGD_ERROR_NONE;
                                int cmd;
                                int event;
-                               std::string requester_id, group_name;
+                               std::string requester_id, group_name, owner_id;
 
                                LOG_DEBUG("Request event occur");
 
@@ -516,6 +516,11 @@ OCEntityHandlerResult _request_handler(std::shared_ptr<OCResourceRequest> reques
                                else
                                        LOG_DEBUG("group_name received %s", group_name.c_str());
 
+                               if (!requestRep.getValue("OwnerID", owner_id))
+                                       LOG_ERR("device_id not found in representation");
+                               else
+                                       LOG_DEBUG("group_name received %s", group_name.c_str());
+
                                mdgd_group_t *group = (mdgd_group_t *)g_try_malloc0(sizeof(mdgd_group_t));
                                group->device_id = g_strdup(requester_id.c_str());
                                group->group_name = g_strdup(group_name.c_str());
@@ -526,6 +531,8 @@ OCEntityHandlerResult _request_handler(std::shared_ptr<OCResourceRequest> reques
                                        mdgd_group_notify_event(NULL, MDGD_EVENT_INVITED, MDGD_ERROR_NONE, (void *)group);
                                        break;
                                case MDGD_REQ_EVENT_EJECTED:
+                                       mdgd_iot_remove_subowner((char *)owner_id.c_str());
+                                       mdgd_iot_remove_secure_information(group->device_id);
                                        mdgd_group_notify_event(NULL, MDGD_EVENT_EJECTED, MDGD_ERROR_NONE, (void *)group);
                                        break;
                                default:
index 42888b7..85b7453 100755 (executable)
@@ -36,6 +36,30 @@ struct agent_s {
 };
 struct agent_s agent; /**< MOT agent context */
 
+int agent_get_ownerid(char** deviceid)
+{
+        GVariant *variant = NULL;
+        int result = MDGD_ERROR_NONE;
+        GError *error = NULL;
+        if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
+                LOG_ERR("I/O error");
+                return MDGD_ERROR_IO_ERROR;
+        }
+
+        variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "get_ownerid",
+                        NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+        if (variant) {
+                g_variant_get(variant, "(si)", deviceid, &result);
+                LOGD("get_ownerid status %s, 0x%x", *deviceid, result);
+        } else if (error) {
+                LOGE("Failed DBus call [%s]", error->message);
+                g_error_free(error);
+                return MDGD_ERROR_IO_ERROR;
+        }
+
+        return result;
+}
+
 static int _check_agent_vaild(void)
 {
        if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
@@ -303,6 +327,16 @@ static GDBusProxy *_get_proxy_service()
        return proxy;
 }
 
+static void _remove_device_cb(void* ctx, int num,
+       OCProvisionResult_t* arr, bool has_error)
+{
+       if (!has_error)  {
+               LOG_DEBUG("Remove CRED for mowned device SUCCEEDED");
+       } else {
+               LOG_DEBUG("Remove CRED for mowned device  FAILED ");
+       }
+}
+
 static void _agent_signal_handler(GDBusConnection *connection,
                const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
                const gchar *signal_name, GVariant *parameters, gpointer userdata)
@@ -393,7 +427,12 @@ static void _agent_signal_handler(GDBusConnection *connection,
                cmd->uuid = g_strdup(device_id);
                cmd->arg1 = g_strdup(group_name);
 
-               LOG_DEBUG("%s, %s", device_id, group_name);
+               char *mot_agent_id = NULL;
+               agent_get_ownerid(&mot_agent_id);
+               cmd->arg2 = g_strdup(mot_agent_id);
+
+               LOG_DEBUG("%s, %s, %s", device_id, group_name, mot_agent_id);
+
                if (0 == g_strcmp0(signal_name, "pair_done")) {
                        if (result == MDGD_ERROR_NONE) {
                                cmd->type = MDGD_REQ_EVENT_INVITED;
@@ -405,6 +444,13 @@ static void _agent_signal_handler(GDBusConnection *connection,
                } else if (0 == g_strcmp0(signal_name, "unpair_done")) {
                        if (result == MDGD_ERROR_NONE) {
                                cmd->type = MDGD_REQ_EVENT_EJECTED;
+
+                               //mdgd_iot_remove_secure_information(cmd->uuid);
+                               OicUuid_t owned_uuid;
+                               mdgd_str_to_uuid(cmd->uuid, &owned_uuid);
+                               int ret = OCRemoveDeviceWithUuid(NULL, 5, &owned_uuid,
+                                       _remove_device_cb);
+
                                mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DEVICE, cmd);
                        }
 
old mode 100755 (executable)
new mode 100644 (file)
index f1f9362..2223ca3
@@ -80,6 +80,42 @@ exit:
        return OC_STACK_NO_MEMORY;
 }
 
+int mdgd_str_to_uuid(const char* strUuid, OicUuid_t* uuid)
+{
+       if(NULL == strUuid || NULL == uuid) {
+                LOG_ERR("ConvertStrToUuid : Invalid param");
+                return OC_STACK_INVALID_PARAM;
+       }
+
+       size_t urnIdx = 0;
+       size_t uuidIdx = 0;
+       size_t strUuidLen = 0;
+       char convertedUuid[UUID_LENGTH * 2] = {0};
+
+       strUuidLen = strlen(strUuid);
+       if(0 == strUuidLen) {
+                LOG_DEBUG("The empty string detected, The UUID will be converted to "\
+                                                                 "\"00000000-0000-0000-0000-000000000000\"");
+       } else if(UUID_LENGTH * 2 + 4 == strUuidLen) {
+                for(uuidIdx=0, urnIdx=0; uuidIdx < UUID_LENGTH ; uuidIdx++, urnIdx+=2)  {
+                         if(*(strUuid + urnIdx) == '-') {
+                                       urnIdx++;
+                         }
+                         sscanf(strUuid + urnIdx, "%2hhx", &convertedUuid[uuidIdx]);
+                }
+       } else {
+                LOG_ERR("Invalid string uuid format, Please set the uuid as correct format");
+                LOG_ERR("e.g) \"72616E64-5069-6E44-6576-557569643030\" (4-2-2-2-6)");
+                LOG_ERR("e.g) \"\"");
+
+                return OC_STACK_INVALID_PARAM;
+       }
+
+       memcpy(uuid->id, convertedUuid, UUID_LENGTH);
+
+       return OC_STACK_OK;
+}
+
 void mdgd_clean_user_data(void *user_data)
 {
        mdgd_command_t *cmd = (mdgd_command_t *)user_data;
index 8c1956c..9d1c38b 100755 (executable)
@@ -143,6 +143,8 @@ static gboolean _ma_dbus_handle_get_ownerid(NetMa *object,
                MA_LOGE("Failed to ma_request_get_ownerid [%d][%s]",
                        ret, ma_erro_to_string(ret));
 
+       MA_LOGE("Owner ID is %s", uuid_str);
+
        net_ma_complete_get_ownerid(object, invocation, uuid_str, ret);
 
        if (uuid_str)
index 009a6fe..37b761e 100644 (file)
@@ -60,6 +60,8 @@ static const OicSecPrm_t  SUPPORTED_PRMS[2] = { PRM_PRE_CONFIGURED, PRM_RANDOM_P
 
 /**< GetDoxmDevOwnerId() is IoTivity function */
 OCStackResult GetDoxmDevOwnerId(OicUuid_t *devownerid);
+OCStackResult PDMUnlinkDevices(const OicUuid_t *UUID1, const OicUuid_t *UUID2);
+OCStackResult PDMDeleteDevice(const OicUuid_t *uuidOfDevice);
 
 typedef struct {
        int ret; /** Result of command */
@@ -1934,22 +1936,6 @@ static void _make_devices_unpair_func(ma_req_cb_s *con)
        MA_LOGD("uuid_mowner = %s", ma_get_readable_uuid(&uuid_mowner));
 #endif
 
-       g_mutex_lock(&g_client->iotivity_mutex);
-       ret = OCRemoveSubOwner(g_client, owned_dev, &uuid_mowner, _remove_subowner_cb);
-       g_mutex_unlock(&g_client->iotivity_mutex);
-       if (OC_STACK_OK != ret) {
-               MA_LOGE("OCRemoveSubOwner: ret = %d (%s)",
-                       ret, ma_ocf_error_to_string(ret));
-       }
-
-       ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
-       if (OC_STACK_OK  != ret) {
-               MA_LOGE("OCRemoveSubOwner Timeout = %d (%s)",
-                       ret, ma_ocf_error_to_string(ret));
-       }
-
-       MA_LOGI("Remove SubOwner Done");
-
        MA_LOGI("Start Removing CRED for remote device at local SVR DB");
        g_client->g_doneCB = false;
 
@@ -1971,6 +1957,21 @@ static void _make_devices_unpair_func(ma_req_cb_s *con)
        /* Disaply result result */
        MA_LOGI("Removing CRED info. at local SVR DB Done");
 
+       MA_LOGI("Unlink Selected Pairwise Devices..");
+
+       ret = PDMUnlinkDevices(owner_uuid, owned_uuid);
+       if (OC_STACK_OK != ret)  {
+               MA_LOGD("PDMUnlinkDevices API error: %d (%s)", ret, ma_ocf_error_to_string(ret));
+               goto PV_UNPAIR_END;
+       }
+
+       ret = PDMDeleteDevice(owned_uuid);
+       if (OC_STACK_OK != ret)  {
+               MA_LOGD("PDMUnlinkDevices API error: %d (%s)", ret, ma_ocf_error_to_string(ret));
+               goto PV_UNPAIR_END;
+       }
+
+       MA_LOGI("Unlink Devices Done");
 PV_UNPAIR_END:
        /* Notify unpair result  */
        if (con) {