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
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
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);
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);
#include "OCPlatform.h"
#include "OCApi.h"
#include "credresource.h"
+#include "aclresource.h"
using namespace OC;
using namespace std;
{
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;
}
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));
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");
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());
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:
};
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) {
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)
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;
} 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);
}
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;
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)
/**< 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 */
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;
/* 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) {