GThread *thread; /**< Worker Thread */
GAsyncQueue *queue; /**< Async Queue to be handled */
gint pending; /**< Is there any pending operation? */
+ GMutex iotivity_mutex; /**< Mutex for IoTivity stack */
OCProvisionDev_t* g_motdev_list; /**< Discoverd MOT enabled devices list */
OCProvisionDev_t* g_mowned_list; /**< My owned MOT enabled devices list */
} ma_subowner_s;
ma_subowner_s *g_client; /**< MOT agent client instance */
-GMutex iotivity_mutex; /**< Mutex for IoTivity stack */
#ifdef THREAD_COND_WAIT_USED
/*
MA_LOGE("nanosleep failed=%d", errno);
}
- g_mutex_lock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
ret = OCProcess();
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret) {
MA_LOGE( "OCStack process error = %d", ret);
}
/* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
+ if (g_client)
+ g_atomic_int_set(&g_client->pending, 0);
if (con) {
g_free(con);
ma_check_null_ret("con", con);
ma_service *service= (ma_service *)con->userdata;
ma_check_null_ret("service", service);
+ ma_check_null_ret("g_client", g_client);
/* g_mowned_list would be filled above request */
g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
/* delete mot device lists before updating them */
_remove_mot_client();
- g_mutex_lock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
OCDiscoverMultipleOwnerEnabledDevices(con->timeout,
&g_client->g_motdev_list);
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret) {
MA_LOGE( "OCDiscoverMultipleOwnerEnalbedDevices API error");
goto DISC_MOT_ENB_DEVS_END;
static int _disc_mot_enb_devs(ma_service *service, int timeout)
{
ma_req_cb_s *con = NULL;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
MA_LOGD("Discovering MOWNED Devices");
- g_mutex_lock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
ret = OCDiscoverMultipleOwnedDevices(con->timeout,
&g_client->g_mowned_list);
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret) {
MA_LOGE( "OCDiscoverMultipleOwnerEnabledDevices API error");
goto DISC_OWNED_DEVS_END;
static int _disc_owned_devs(ma_service *service, int timeout)
{
ma_req_cb_s *con = NULL;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
MA_LOGE("We can't find in MOT dev list");
goto MOT_ENDED;
}
+#ifndef MULTIPLE_OWN_AT_ONCE
/* Copy next MOT enabled device pointer temporally */
- next_dev = src_dev->next;
+ next_dev = src_dev->next;
/* Next MOT enabled device set NULL to MOT a single device */
src_dev->next = NULL;
+#endif
g_client->g_doneCB = false;
ret, ma_ocf_error_to_string(ret));
goto MOT_ENDED;
}
- /* Restore MOT enabled devices */
- src_dev->next = next_dev ;
-
MA_LOGI("Registered Discovered Devices");
MOT_ENDED:
+#ifndef MULTIPLE_OWN_AT_ONCE
+ /* Restore MOT enabled devices */
+ src_dev->next = next_dev;
+#endif
+
net_ma_emit_mot_done(ma_dbus_get_object(), (int)ret);
if (uuid_target)
_request_cleanup(con);
}
-static int _ma_mot(ma_service *service, gchar *uuid_str, gchar *pin)
+static int _mot(ma_service *service, gchar *uuid_str, gchar *pin)
{
ma_req_cb_s *con = NULL;
-
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
return NULL;
}
-static void _acl_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error)
+static void _acl_provisioning_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr,
+ bool has_error)
{
ma_subowner_s *client = (ma_subowner_s *)ctx;
}
client->g_doneCB = true;
}
-static void _acl_func(ma_req_cb_s *con)
+static void _acl_provisioning_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
OCProvisionDev_t *subject_dev = NULL;
if (!g_client) {
- ret = OC_STACK_INVALID_PARAM;
MA_LOGE("mot agent is not initialized");
- goto PVACL_ERROR;
+ goto PV_ACL_END;
}
if (NULL == con) {
- ret = OC_STACK_INVALID_PARAM;
MA_LOGE("container is NULL");
- goto PVACL_ERROR;
- }
-
- if (!con->uuid_subject_str ||!con->uuid_target_str ||
- !con->rsrc_uri || !con->rsrc_type || !con->rsrc_interface) {
- MA_LOGE("Some parameters are wrong");
- MA_LOGE("%s", con->uuid_target_str );
- MA_LOGE("%s", con->uuid_subject_str );
- MA_LOGE("%s", con->rsrc_uri );
- MA_LOGE("%s", con->rsrc_type );
- MA_LOGE("%s", con->rsrc_interface );
- goto PVACL_ERROR;
+ goto PV_ACL_END;
}
uuid1 = ma_convert_uuid(con->uuid_target_str);
target_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid1);
if (!target_dev) {
MA_LOGE("We can't find target in MOT enabled dev list");
- goto PVACL_ERROR;
+ goto PV_ACL_END;
}
uuid2 = ma_convert_uuid(con->uuid_subject_str);
subject_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid2);
if (!subject_dev) {
MA_LOGE("We can't find subject in MOT enabled dev list");
- goto PVACL_ERROR;
+ goto PV_ACL_END;
}
g_client->g_doneCB = false;
con->rsrc_interface, con->permission);
if (NULL == acl) {
MA_LOGE( "Failed to create ACL for %s", con->rsrc_uri);
- goto PVACL_ERROR;
+ goto PV_ACL_END;
}
- ret= OCProvisionACL((void*) g_client, target_dev, acl, _acl_cb);
+ /* Do ACL provisioning */
+ ret= OCProvisionACL((void*) g_client, target_dev, acl, _acl_provisioning_cb);
if (OC_STACK_OK != ret) {
MA_LOGD( "OCProvisionACL API error: %d (%s)", ret, ma_ocf_error_to_string(ret));
- goto PVACL_ERROR;
+ goto PV_ACL_END;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (ret) {
MA_LOGE( "OCProvisionCredentials Faild = %d", errno);
- goto PVACL_ERROR;
+ goto PV_ACL_END;
}
/* display the ACL-provisioned result */
MA_LOGI(" Provisioned Selected ACL Successfully");
-PVACL_ERROR:
+PV_ACL_END:
/* Notify ACL result */
net_ma_emit_acl_done(ma_dbus_get_object(), (int)ret);
_request_cleanup(con);
}
-static int _acl(ma_service *service, gchar *target, gchar *subject,
+static int _acl_provisioning(ma_service *service, gchar *target, gchar *subject,
gchar *rsrc_uri, gchar *rsrc_type, gchar *rsrc_interface, int permission)
{
ma_req_cb_s *con = NULL;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
return MA_ERROR_NONE;
}
-static void _cred_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error)
+static void _cred_provisioning_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error)
{
ma_subowner_s *client = (ma_subowner_s *)ctx;
client->g_doneCB = true;
}
-static void _cred_func(ma_req_cb_s *con)
+static void _cred_provisioning_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
OicUuid_t *uuid2 = NULL;
OCProvisionDev_t *dev1 = NULL;
OCProvisionDev_t *dev2 = NULL;
+ OCProvisionDev_t *dev1_next = NULL;
+ OCProvisionDev_t *dev2_next = NULL;
if (!g_client) {
- ret = OC_STACK_INVALID_PARAM;
MA_LOGE("mot agent is not initialized");
- goto PVCRED_ERROR;
+ goto PV_CRED_END;
}
if (NULL == con) {
- ret = OC_STACK_INVALID_PARAM;
MA_LOGE("container is NULL");
- goto PVCRED_ERROR;
+ goto PV_CRED_END;
}
if (!con->uuid_dev1 ) {
MA_LOGE("dev1 is NULL");
- goto PVCRED_ERROR;
+ goto PV_CRED_END;
}
if (!con->uuid_dev2) {
MA_LOGE("dev2 is NULL");
- goto PVCRED_ERROR;
+ goto PV_CRED_END;
}
uuid1 = ma_convert_uuid(con->uuid_dev1);
dev1 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid1);
if (!dev1) {
MA_LOGE("We can't find in MOWNED dev list");
- goto PVCRED_ERROR;
+ goto PV_CRED_END;
}
uuid2 = ma_convert_uuid(con->uuid_dev2);
dev2 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid2);
if (!dev2) {
MA_LOGE("We can't find in MOWNED dev list");
- goto PVCRED_ERROR;
+ goto PV_CRED_END;
}
/* To do ACL provisioning only one */
+ dev1_next = dev1->next;
dev1->next = NULL;
-
- /* To do ACL provisioning only one */
+ dev2_next = dev2->next;
dev2->next = NULL;
g_client->g_doneCB = false;
MA_LOGI("Provisioning Selected Pairwise Devices..");
ret = OCProvisionCredentials((void*) g_client,
SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_256,
- dev1, dev2, _cred_cb);
+ dev1, dev2, _cred_provisioning_cb);
if (OC_STACK_OK != ret) {
MA_LOGD( "OCProvisionPairwiseDevices API error: %d (%s)",
ret, ma_ocf_error_to_string(ret));
- goto PVCRED_ERROR;
+ goto PV_CRED_END;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (ret) {
MA_LOGE( "OCProvisionCredentials Faild = %d", errno);
- goto PVCRED_ERROR;
+ goto PV_CRED_END;
}
/* display the pairwise-provisioned result */
MA_LOGI("Provisioned Selected Pairwise Devices");
-PVCRED_ERROR:
+PV_CRED_END:
+ /* Restore MOT enabled device list */
+ dev1->next = dev1_next;
+ dev2->next = dev2_next;
+
/* Notify ACL result */
net_ma_emit_cred_done(ma_dbus_get_object(), (int)ret);
_request_cleanup(con);
}
-static int _cred(ma_service *service,
+static int _cred_provisioning(ma_service *service,
gchar *uuid_dev1, gchar *uuid_dev2)
{
ma_req_cb_s *con = NULL;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (!con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
return MA_ERROR_NONE;
}
-static void _pairwise_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr,
+static void _resources_pairwise_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr,
bool has_error)
{
ma_subowner_s *client = (ma_subowner_s *)ctx;
client->g_doneCB = true;
}
-static void _pairwise_func(ma_req_cb_s *con)
+static void _resources_pairwise_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
OCProvisionDev_t *subject_dev_2 = NULL;
if (!g_client) {
- ret = OC_STACK_INVALID_PARAM;
MA_LOGE("mot agent is not initialized");
goto PVPAIRWIE_ERROR;
}
if (NULL == con) {
- ret = OC_STACK_INVALID_PARAM;
MA_LOGE("container is NULL");
goto PVPAIRWIE_ERROR;
}
- if (!con->subject_1 || !con->rsrc_uri_1 || !con->rsrc_type_1 || !con->rsrc_interface_1 ||
- !con->subject_2 || !con->rsrc_uri_2 || !con->rsrc_type_2 || !con->rsrc_interface_2) {
- MA_LOGE("Some parameters are wrong");
- MA_LOGE("%s", con->subject_1 );
- MA_LOGE("%s", con->rsrc_uri_1 );
- MA_LOGE("%s", con->rsrc_type_1 );
- MA_LOGE("%s", con->rsrc_interface_1 );
- MA_LOGE("%s", con->subject_2 );
- MA_LOGE("%s", con->rsrc_uri_2 );
- MA_LOGE("%s", con->rsrc_type_2 );
- MA_LOGE("%s", con->rsrc_interface_2 );
-
- goto PVPAIRWIE_ERROR;
- }
-
uuid_1 = ma_convert_uuid(con->target_1);
target_dev_1 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_1);
if (!target_dev_1) {
goto PVPAIRWIE_ERROR;
}
+ /* Do both resources pairwise */
ret = OCProvisionPairwiseDevices((void*) g_client, SYMMETRIC_PAIR_WISE_KEY,
OWNER_PSK_LENGTH_256, target_dev_1, acl_1,
- target_dev_2, acl_2, _pairwise_cb);
+ target_dev_2, acl_2, _resources_pairwise_cb);
if (OC_STACK_OK != ret) {
MA_LOGD( "OCProvisionPairwiseDevices API error: %d (%s)", ret,
ma_ocf_error_to_string(ret));
_request_cleanup(con);
}
-static int _pairwise(ma_service *service, gchar *target_1, gchar *subject_1,
+static int _resources_pairwise(ma_service *service, gchar *target_1, gchar *subject_1,
gchar *rsrc_uri_1, gchar *rsrc_type_1, gchar *rsrc_interface_1, int permission_1,
gchar *target_2, gchar *subject_2,gchar *rsrc_uri_2, gchar *rsrc_type_2,
gchar *rsrc_interface_2, int permission_2)
{
ma_req_cb_s *con = NULL;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
return MA_ERROR_NONE;
}
-static void _unlink_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error)
+static void _unlink_resources_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr,
+ bool has_error)
{
ma_subowner_s *client = (ma_subowner_s *)ctx;
client->g_doneCB = true;
}
-static void _unlink_func(ma_req_cb_s *con)
+static void _unlink_resources_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
g_client->g_doneCB = false;
MA_LOGI("Unlink Selected Pairwise Devices..");
- ret = OCUnlinkDevices((void*) g_client, dev1, dev2, _unlink_cb );
+ ret = OCUnlinkDevices((void*) g_client, dev1, dev2, _unlink_resources_cb);
if (OC_STACK_OK != ret) {
MA_LOGD( "OCUnlinkDevices API error: %d (%s)", ret, ma_ocf_error_to_string(ret));
goto PVUNLINKPAIRWISE_ERROR;
_request_cleanup(con);
}
-static int _unlink(ma_service *service,
+static int _unlink_resources(ma_service *service,
gchar *uuid_dev1, gchar *uuid_dev2)
{
ma_req_cb_s *con = NULL;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (!con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
con->userdata = service;
con->cid = MA_UNLINK_RESOURCES;
- if (!uuid_dev1 ||!uuid_dev2) {
+ if (!uuid_dev1 || !uuid_dev2) {
MA_LOGE( "Invaild Prameters");
_request_cleanup(con);
return MA_ERROR_INVALID_PARAMETER;
return MA_ERROR_NONE;
}
-static void _remove_mo_cb(void* ctx, int num, OCProvisionResult_t* arr,
+static void _remove_subowner_cb(void* ctx, int num, OCProvisionResult_t* arr,
bool has_error)
{
ma_subowner_s *client = (ma_subowner_s *)ctx;
client->g_doneCB = true;
}
-static void _remove_mo_func(ma_req_cb_s *con)
+static void _remove_subowner_func(ma_req_cb_s *con)
{
OCStackResult ret = MA_ERROR_OPERATION_FAILED;
if (!g_client) {
ret = OC_STACK_INVALID_PARAM;
MA_LOGE("mot agent is not initialized");
- goto REMOVE_MO_ENDED;
+ goto REMOVE_SUBOWNER_ENDED;
}
if (NULL == con) {
ret = OC_STACK_INVALID_PARAM;
MA_LOGE("container is NULL");
- goto REMOVE_MO_ENDED;
+ goto REMOVE_SUBOWNER_ENDED;
}
if (!con->uuid_target_str) {
MA_LOGE("Target device UUID is NULL");
- goto REMOVE_MO_ENDED;
+ goto REMOVE_SUBOWNER_ENDED;
}
uuid_target = ma_convert_uuid(con->uuid_target_str);
src_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_target);
if (!src_dev) {
MA_LOGE("We can't find in MOT dev list");
- goto REMOVE_MO_ENDED;
+ goto REMOVE_SUBOWNER_ENDED;
}
g_client->g_doneCB = false;
if (OC_STACK_OK != ret) {
MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]",
ret, ma_ocf_error_to_string(ret));
- goto REMOVE_MO_ENDED;
+ goto REMOVE_SUBOWNER_ENDED;
}
- ret = OCRemoveSubOwner(g_client, src_dev, &uuid_mowner, _remove_mo_cb);
+ ret = OCRemoveSubOwner(g_client, src_dev, &uuid_mowner, _remove_subowner_cb);
if (OC_STACK_OK != ret ) {
MA_LOGE( "OCRemoveSubOwner: ret = %d (%s)",
ret, ma_ocf_error_to_string(ret));
- goto REMOVE_MO_ENDED;
+ goto REMOVE_SUBOWNER_ENDED;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if(ret) {
MA_LOGE( "OCRemoveSubOwner callback error = %d (%s)",
ret, ma_ocf_error_to_string(ret));
- goto REMOVE_MO_ENDED;
+ goto REMOVE_SUBOWNER_ENDED;
}
MA_LOGI("Remove Multiple Ownership Done");
-REMOVE_MO_ENDED:
+REMOVE_SUBOWNER_ENDED:
net_ma_emit_remove_mo_done(ma_dbus_get_object(), (int)ret);
if (uuid_target)
g_free(uuid_target);
_request_cleanup(con);
}
-static int _ma_remove_mo(ma_service *service, gchar *uuid_str)
+static int _ma_remove_subowner(ma_service *service, gchar *uuid_str)
{
ma_req_cb_s *con = NULL;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
return MA_ERROR_NONE;
}
-static void _remove_remove_cred_local_cb(void* ctx, int num,
+static void _remove_remove_device_cb(void* ctx, int num,
OCProvisionResult_t* arr, bool has_error)
{
ma_subowner_s *client = (ma_subowner_s *)ctx;
client->g_doneCB = true;
}
-static void _remove_cred_local_func(ma_req_cb_s *con)
+static void _remove_device_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
OicUuid_t *uuid = NULL;
if (!g_client) {
ret = OC_STACK_INVALID_PARAM;
MA_LOGE("mot agent is not initialized");
- goto REMOVE_LOCAL_CRED_ERROR;
+ goto REMOVE_DEVICE_END;
}
if (NULL == con) {
ret = OC_STACK_INVALID_PARAM;
MA_LOGE("container is NULL");
- goto REMOVE_LOCAL_CRED_ERROR;
+ goto REMOVE_DEVICE_END;
}
if (!con->target_to_revoke) {
MA_LOGE("Some parameters are wrong");
MA_LOGE("%s", con->target_to_revoke );
- goto REMOVE_LOCAL_CRED_ERROR;
+ goto REMOVE_DEVICE_END;
}
uuid = ma_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 );
+ ret = OCRemoveDeviceWithUuid((void*) g_client, CALLBACK_TIMEOUT_5S, uuid,
+ _remove_subowner_cb );
if (OC_STACK_OK != ret) {
MA_LOGD( "OCRemoveDeviceWithUuid API error: %d (%s)",
ret, ma_ocf_error_to_string(ret));
- goto REMOVE_LOCAL_CRED_ERROR;
+ goto REMOVE_DEVICE_END;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (ret) {
MA_LOGE( "OCRemoveDeviceWithUuid Faild = %d", errno);
- goto REMOVE_LOCAL_CRED_ERROR;
+ goto REMOVE_DEVICE_END;
}
/* Disaply result result */
MA_LOGI(" Removing CRED info. at local SVR DB - Done");
-REMOVE_LOCAL_CRED_ERROR:
+REMOVE_DEVICE_END:
/* Notify ACL result */
net_ma_emit_remove_cred_local_done(ma_dbus_get_object(), (int)ret);
if (uuid)
_request_cleanup(con);
}
-static int _ma_remove_cred_local(ma_service *service, gchar *uuid_str)
+static int _remove_device(ma_service *service, gchar *uuid_str)
{
ma_req_cb_s *con = NULL;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
return MA_ERROR_NONE;
}
-static void _pair_func(ma_req_cb_s *con)
+static void _make_devices_pair_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
if (!g_client) {
ret = OC_STACK_INVALID_PARAM;
MA_LOGE("mot agent is not initialized");
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
if (NULL == con) {
ret = OC_STACK_INVALID_PARAM;
MA_LOGE("container is NULL");
- goto PVPAIR_ERROR;
- }
-
- if (!con->subject_1 || !con->rsrc_uri_1 || !con->rsrc_type_1 || !con->rsrc_interface_1 ||
- !con->subject_2 || !con->rsrc_uri_2 || !con->rsrc_type_2 || !con->rsrc_interface_2) {
- MA_LOGE("Some parameters are wrong");
- MA_LOGE("%s", con->subject_1 );
- MA_LOGE("%s", con->rsrc_uri_1 );
- MA_LOGE("%s", con->rsrc_type_1 );
- MA_LOGE("%s", con->rsrc_interface_1 );
- MA_LOGE("%s", con->subject_2 );
- MA_LOGE("%s", con->rsrc_uri_2 );
- MA_LOGE("%s", con->rsrc_type_2 );
- MA_LOGE("%s", con->rsrc_interface_2 );
-
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
uuid_1 = ma_convert_uuid(con->target_1);
target_dev_1 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_1);
if (!target_dev_1) {
MA_LOGE("We can't find target in MOT enabled dev list");
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
uuid_2 = ma_convert_uuid(con->target_2);
target_dev_2 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_2);
if (!target_dev_2) {
MA_LOGE("We can't find target in MOT enabled dev list");
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
uuid_3 = ma_convert_uuid(con->subject_1);
subject_dev_1 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_3);
if (!subject_dev_1) {
MA_LOGE("We can't find subject in MOWNED dev list");
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
uuid_4 = ma_convert_uuid(con->subject_2);
subject_dev_2 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_4);
if (!subject_dev_2) {
MA_LOGE("We can't find subject in MOWNED dev list");
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
src_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_2);
if (!src_dev) {
MA_LOGE("We can't find in MOT dev list");
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
/* Copy next MOT enabled device pointer temporally */
- next_dev = src_dev->next;
+ next_dev = src_dev->next;
/* Next MOT enabled device set NULL to MOT a single device */
src_dev->next = NULL;
if(OIC_PRECONFIG_PIN == src_dev->doxm->oxmSel) {
/* Pre-Configured PIN initialization */
const char* testPreconfigPin = con->pin;/* Ex) "12341234" */
- g_mutex_lock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
ret = OCAddPreconfigPin(src_dev, testPreconfigPin, strlen(testPreconfigPin));
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_unlock(&g_client->iotivity_mutex);
if(OC_STACK_OK != ret) {
MA_LOGE("Failed to save the pre-configured PIN");
MA_LOGE("You can't use the pre-configured PIN OxM for MOT");
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
}
- g_mutex_lock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
ret = OCDoMultipleOwnershipTransfer(g_client, src_dev, _mot_cb);
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret ) {
MA_LOGE( "OCDoMultipleOwnershipTransfer: ret = %d (%s)",
ret, ma_ocf_error_to_string(ret));
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (OC_STACK_OK != ret ) {
MA_LOGE( "OCDoMultipleOwnershipTransfer callback error = %d (%s)",
ret, ma_ocf_error_to_string(ret));
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
- /* Restore MOT enabled devices */
- src_dev->next = next_dev ;
MA_LOGI("Registered Discovered Devices");
con->rsrc_interface_1, con->permission_1);
if (NULL == acl_1) {
MA_LOGE( "Failed to create ACL for %s", con->rsrc_uri);
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
acl_2 = _create_target_acl(&target_dev_2->doxm->deviceID,
con->rsrc_interface_2, con->permission_2);
if (NULL == acl_2) {
MA_LOGE( "Failed to create ACL for %s", con->rsrc_uri);
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
- g_mutex_lock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
ret = OCProvisionPairwiseDevices((void*) g_client, SYMMETRIC_PAIR_WISE_KEY,
OWNER_PSK_LENGTH_256, target_dev_1, acl_1,
- target_dev_2, acl_2, _pairwise_cb);
- g_mutex_unlock(&iotivity_mutex);
+ target_dev_2, acl_2, _resources_pairwise_cb);
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret) {
MA_LOGD( "OCProvisionPairwiseDevices API error: %d (%s)", ret,
ma_ocf_error_to_string(ret));
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (ret) {
MA_LOGE( "OCProvisionPairwise Faild = %d", errno);
- goto PVPAIR_ERROR;
+ goto PV_PAIR_END;
}
/* display the pairwise-provisioned result */
MA_LOGI(" Provision pairwise Done");
-PVPAIR_ERROR:
+PV_PAIR_END:
+ /* Restore MOT enabled devices */
+ src_dev->next = next_dev ;
/* Notify pair result */
net_ma_emit_pair_done(ma_dbus_get_object(), (int)ret);
_request_cleanup(con);
}
-static int _pair(ma_service *service, gchar *pin, gchar *target_1, gchar *subject_1,
+static int _make_devices_pair(ma_service *service, gchar *pin, gchar *target_1, gchar *subject_1,
gchar *rsrc_uri_1, gchar *rsrc_type_1, gchar *rsrc_interface_1, int permission_1,
gchar *target_2, gchar *subject_2,gchar *rsrc_uri_2, gchar *rsrc_type_2,
gchar *rsrc_interface_2, int permission_2)
{
ma_req_cb_s *con = NULL;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
return MA_ERROR_NONE;
}
-static void _unpair_func(ma_req_cb_s *con)
+static void _make_devices_unpair_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
if (NULL == g_client) {
ret = OC_STACK_INVALID_PARAM;
MA_LOGE("mot agent is not initialized");
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
if (NULL == con) {
ret = OC_STACK_INVALID_PARAM;
MA_LOGE("container is NULL");
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
if (NULL == con->uuid_dev1 ) {
MA_LOGE("dev1 is NULL");
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
if (NULL == con->uuid_dev2) {
MA_LOGE("dev2 is NULL");
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
owner_uuid = ma_convert_uuid(con->uuid_dev1);
owner_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, owner_uuid);
if (!owner_dev) {
MA_LOGE("We can't find in MOT enabled dev list");
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
owned_uuid = ma_convert_uuid(con->uuid_dev2);
owned_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, owned_uuid);
if (!owned_dev) {
MA_LOGE("We can't find in MOT enabled dev list");
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
g_client->g_doneCB = false;
MA_LOGI("Unlink Selected Pairwise Devices..");
- g_mutex_lock(&iotivity_mutex);
- ret = OCUnlinkDevices((void*) g_client, owner_dev, owned_dev, _unlink_cb );
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
+ ret = OCUnlinkDevices((void*) g_client, owner_dev, owned_dev, _unlink_resources_cb );
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret) {
MA_LOGD( "OCUnlinkDevices API error = %d (%s)",
ret, ma_ocf_error_to_string(ret));
if (OC_STACK_OK != ret) {
MA_LOGD( "OCUnlinkDevices Timeout = %d (%s)",
ret, ma_ocf_error_to_string(ret));
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
}
if (OC_STACK_OK != ret) {
MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]",
ret, ma_ocf_error_to_string(ret));
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
- g_mutex_lock(&iotivity_mutex);
- ret = OCRemoveSubOwner(g_client, owned_dev, &uuid_mowner, _remove_mo_cb);
- g_mutex_unlock(&iotivity_mutex);
+ 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));
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
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));
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
MA_LOGI("Remove Multiple Ownership Done");
MA_LOGI(" Removing CRED for remote device at local SVR DB");
- g_mutex_lock(&iotivity_mutex);
- ret = OCRemoveDeviceWithUuid((void*) g_client, CALLBACK_TIMEOUT_5S, owned_uuid,
- _remove_remove_cred_local_cb );
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
+ ret = OCRemoveDeviceWithUuid((void*) g_client, CALLBACK_TIMEOUT_5S, owned_uuid,
+ _remove_remove_device_cb );
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret) {
MA_LOGD( "OCRemoveDeviceWithUuid API error = %d (%s)",
ret, ma_ocf_error_to_string(ret));
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (OC_STACK_OK != ret) {
MA_LOGD( "OCRemoveDeviceWithUuid Timeout = %d (%s)",
ret, ma_ocf_error_to_string(ret));
- goto PVUNPAIR_ERROR;
+ goto PV_UNPAIR_END;
}
/* Disaply result result */
MA_LOGI(" Removing CRED info. at local SVR DB - Done");
-PVUNPAIR_ERROR:
+PV_UNPAIR_END:
/* Notify unpair result */
net_ma_emit_unpair_done(ma_dbus_get_object(), (int)ret);
if (owner_uuid)
_request_cleanup(con);
}
-static int _unpair(ma_service *service, gchar *uuid_dev1, gchar *uuid_dev2)
+static int _makde_devices_unpair(ma_service *service, gchar *uuid_dev1, gchar *uuid_dev2)
{
ma_req_cb_s *con = NULL;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (!con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
static int _disable(ma_service *service)
{
ma_req_cb_s *con = NULL;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
con = g_malloc0(sizeof(ma_req_cb_s));
if (!con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
_mot_func(con);
break;
case MA_DO_ACL_PROVISIONING:
- _acl_func(con);
+ _acl_provisioning_func(con);
break;
case MA_DO_CRED_PROVISIONING:
- _cred_func(con);
+ _cred_provisioning_func(con);
break;
case MA_DO_RESOURCES_PAIRWISE:
- _pairwise_func(con);
+ _resources_pairwise_func(con);
break;
case MA_REMOVE_MULTIPLE_OWNED_DEVICE:
- _remove_mo_func(con);
+ _remove_subowner_func(con);
break;
case MA_REMOVE_DEVICE_WITH_UUID_IN_SVR:
- _remove_cred_local_func(con);
+ _remove_device_func(con);
break;
case MA_UNLINK_RESOURCES:
- _unlink_func(con);
+ _unlink_resources_func(con);
break;
case MA_MAKE_PAIR:
- _pair_func(con);
+ _make_devices_pair_func(con);
break;
case MA_MAKE_UNPAIR:
- _unpair_func(con);
+ _make_devices_unpair_func(con);
break;
default:
_request_cleanup(con);
if (g_client)
return ret;
- g_mutex_init(&iotivity_mutex);
+ g_client = g_malloc0(sizeof(ma_subowner_s));
+ if (!g_client) {
+ MA_LOGE( "memory allocation error = %d", errno);
+ return MA_ERROR_OUT_OF_MEMORY;
+ }
+ g_mutex_init(&g_client->iotivity_mutex);
+ g_client->thread = g_thread_try_new("worker", _worker_thread, g_client, NULL);
+ g_client->queue = g_async_queue_new();
+ g_client->g_motdev_list = NULL;
+ g_client->g_mowned_list = NULL;
+ g_client->rnd_pin = NULL;
snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
"/opt/usr/data", PRVN_DB_FILE_NAME);
/* initialize persistent storage for SVR DB */
static OCPersistentStorage ps = { _fopen_prvn_mng, fread, fwrite, fclose, unlink };
- g_mutex_lock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
ret = OCRegisterPersistentStorageHandler(&ps);
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret ) {
MA_LOGE( "OCRegisterPersistentStorageHandler error = %d", ret);
return ret;
ma_set_device_id_seed();
/* initialize OC stack and provisioning manager */
- g_mutex_lock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
ret = OCInit(NULL, 0, OC_CLIENT_SERVER);
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret ) {
MA_LOGE( "OCInit() error = [%d][%s]", ret, ma_ocf_error_to_string(ret));
return ret;
}
/* Do Self-Ownership Transfer */
- g_mutex_lock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
ret = OCConfigSelfOwnership();
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret ) {
MA_LOGE( "OCConfigSelfOwnership() error = [%d][%s]",
ret, ma_ocf_error_to_string(ret));
}
- g_mutex_lock(&iotivity_mutex);
+ g_mutex_lock(&g_client->iotivity_mutex);
ret = OCInitPM(data_dir);
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret ) {
MA_LOGE( "OCInitPM() error = [%d][%s]", ret, ma_ocf_error_to_string(ret));
return ret;
SetInputPinCB(_input_pin_cb);
- g_client = g_malloc0(sizeof(ma_subowner_s));
- if (!g_client) {
- MA_LOGE( "memory allocation error = %d", errno);
- return MA_ERROR_OUT_OF_MEMORY;
- }
- g_client->thread = g_thread_try_new("worker", _worker_thread, g_client, NULL);
- g_client->queue = g_async_queue_new();
- g_client->g_motdev_list = NULL;
- g_client->g_mowned_list = NULL;
- g_client->rnd_pin = NULL;
-
return ret;
}
ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
ma_check_null_ret_error("service", service, FALSE);
- MA_LOGD("[IPC] Discovery MOT enabled devices");
+ MA_LOGD("[IPC] Find MOT enabled devices");
/* If we are working now? */
if (g_atomic_int_get(&g_client->pending))
ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
ma_check_null_ret_error("service", service, FALSE);
- MA_LOGD("[IPC] Discovery Owned devices");
+ MA_LOGD("[IPC] Find owned devices");
/* If we are working now? */
if (g_atomic_int_get(&g_client->pending))
ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
ma_check_null_ret_error("service", service, FALSE);
- MA_LOGD("[IPC] Mullti Ownership Transfer");
+ MA_LOGD("[IPC] Do Mullti Ownership Transfer");
/* If we are working now? */
if (g_atomic_int_get(&g_client->pending))
/* Set d2ds status 'pending' */
g_atomic_int_set(&g_client->pending, 1);
- ret = _ma_mot(service, uuid_str, pin);
+ ret = _mot(service, uuid_str, pin);
return ret;
}
if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
- if (!target || !subject || !rsrc_uri || !rsrc_type || !rsrc_interface) {
- MA_LOGE("target = %s", target);
- MA_LOGE("subject = %s", subject);
- MA_LOGE("rsrc_uri = %s", rsrc_uri);
- MA_LOGE("rsrc_type = %s", rsrc_type);
- MA_LOGE("rsrc_interface = %s", rsrc_interface);
- return MA_ERROR_INVALID_PARAMETER;
- }
+ ma_check_null_ret_error("target", target, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("subject", subject, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_uri", rsrc_uri, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_type", rsrc_type, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_interface", rsrc_interface, MA_ERROR_INVALID_PARAMETER);
/* Set d2ds status 'pending' */
g_atomic_int_set(&g_client->pending, 1);
- ret = _acl(service, target, subject, rsrc_uri, rsrc_type, rsrc_interface, permission);
+ ret = _acl_provisioning(service, target, subject, rsrc_uri, rsrc_type, rsrc_interface,
+ permission);
return ret;
}
ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
ma_check_null_ret_error("service", service, FALSE);
- MA_LOGD("[IPC] Provisioning Credential");
+ MA_LOGD("[IPC] Provisioning credential");
/* If we are working now? */
if (g_atomic_int_get(&g_client->pending))
/* Set d2ds status 'pending' */
g_atomic_int_set(&g_client->pending, 1);
- ret = _cred(service, uuid_dev1, uuid_dev2);
+ ret = _cred_provisioning(service, uuid_dev1, uuid_dev2);
return ret;
}
-int ma_request_pairwise(ma_service *service, gchar *target_1,
+int ma_request_rsrc_pairwise(ma_service *service, gchar *target_1,
gchar *subject_1, gchar *rsrc_uri_1, gchar *rsrc_type_1,
gchar *rsrc_interface_1, int permission_1,
gchar *target_2, gchar *subject_2,gchar *rsrc_uri_2,
ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
ma_check_null_ret_error("service", service, FALSE);
- MA_LOGD("[IPC] Link Pairwise");
+ MA_LOGD("[IPC] Link both resources pairwise");
/* If we are working now? */
if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
- if (!target_1 || !subject_1 || !rsrc_uri_1 || !rsrc_type_1 ||
- !rsrc_interface_1 || !target_2 || !subject_2 || !rsrc_uri_2 ||
- !rsrc_type_2 || !rsrc_interface_2) {
- MA_LOGE("target_1 = %s", target_1);
- MA_LOGE("subject_1 = %s", subject_1);
- MA_LOGE("rsrc_uri_1 = %s", rsrc_uri_1);
- MA_LOGE("rsrc_type_1 = %s", rsrc_type_1);
- MA_LOGE("rsrc_interface_1 = %s", rsrc_interface_1);
- MA_LOGE("target_2 = %s", target_2);
- MA_LOGE("subject_2 = %s", subject_2);
- MA_LOGE("rsrc_uri_2 = %s", rsrc_uri_2);
- MA_LOGE("rsrc_type_2 = %s", rsrc_type_2);
- MA_LOGE("rsrc_interface_2 = %s", rsrc_interface_2);
- return MA_ERROR_INVALID_PARAMETER;
- }
+ ma_check_null_ret_error("target_1", target_1, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("subject_1", subject_1, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_uri_1", rsrc_uri_1, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_type_1", rsrc_type_1, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_interface_1", rsrc_interface_1, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("target_2", target_2, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("subject_2", subject_2, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_uri_2", rsrc_uri_2, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_type_2", rsrc_type_2, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_interface_2", rsrc_interface_2, MA_ERROR_INVALID_PARAMETER);
/* Set d2ds status 'pending' */
g_atomic_int_set(&g_client->pending, 1);
- ret = _pairwise(service, target_1, subject_1, rsrc_uri_1,
+ ret = _resources_pairwise(service, target_1, subject_1, rsrc_uri_1,
rsrc_type_1, rsrc_interface_1, permission_1, target_2,
subject_2, rsrc_uri_2, rsrc_type_2, rsrc_interface_2,
permission_2);
}
-int ma_request_unlink(ma_service *service, gchar *uuid_dev1,
+int ma_request_unlink_rsrc(ma_service *service, gchar *uuid_dev1,
gchar *uuid_dev2)
{
int ret = MA_ERROR_NONE;
ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
ma_check_null_ret_error("service", service, FALSE);
- MA_LOGD("[IPC] Unlink devices");
+ MA_LOGD("[IPC] Unlink both devices");
/* If we are working now? */
if (g_atomic_int_get(&g_client->pending))
/* Set d2ds status 'pending' */
g_atomic_int_set(&g_client->pending, 1);
- ret = _unlink(service, uuid_dev1, uuid_dev2);
+ ret = _unlink_resources(service, uuid_dev1, uuid_dev2);
return ret;
}
-int ma_request_remove_mo(ma_service *service, gchar* uuid_str)
+int ma_request_remove_subowner(ma_service *service, gchar* uuid_str)
{
int ret =MA_ERROR_NONE;
/* Set d2ds status 'pending' */
g_atomic_int_set(&g_client->pending, 1);
- ret = _ma_remove_mo(service, uuid_str);
+ ret = _ma_remove_subowner(service, uuid_str);
return ret;
}
-int ma_request_remove_cred_local(ma_service *service, gchar* uuid_str)
+int ma_request_remove_device(ma_service *service, gchar* uuid_str)
{
int ret =MA_ERROR_NONE;
ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
ma_check_null_ret_error("service", service, FALSE);
- MA_LOGD("[IPC] Remove CRED for Owned Dev in my SVR DB");
+ MA_LOGD("[IPC] Remove target CRED in local SVR");
/* If we are working now? */
if (g_atomic_int_get(&g_client->pending))
/* Set d2ds status 'pending' */
g_atomic_int_set(&g_client->pending, 1);
- ret = _ma_remove_cred_local(service, uuid_str);
+ ret = _remove_device(service, uuid_str);
return ret;
}
ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
ma_check_null_ret_error("service", service, FALSE);
- MA_LOGD("[IPC] Pair both device");
+ MA_LOGD("[IPC] Make both devices pair ");
/* If we are working now? */
if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
- if (!pin || !target_1 || !subject_1 || !rsrc_uri_1 || !rsrc_type_1 ||
- !rsrc_interface_1 || !target_2 || !subject_2 || !rsrc_uri_2 ||
- !rsrc_type_2 || !rsrc_interface_2) {
- MA_LOGE("pin = %s", pin);
- MA_LOGE("target_1 = %s", target_1);
- MA_LOGE("subject_1 = %s", subject_1);
- MA_LOGE("rsrc_uri_1 = %s", rsrc_uri_1);
- MA_LOGE("rsrc_type_1 = %s", rsrc_type_1);
- MA_LOGE("rsrc_interface_1 = %s", rsrc_interface_1);
- MA_LOGE("target_2 = %s", target_2);
- MA_LOGE("subject_2 = %s", subject_2);
- MA_LOGE("rsrc_uri_2 = %s", rsrc_uri_2);
- MA_LOGE("rsrc_type_2 = %s", rsrc_type_2);
- MA_LOGE("rsrc_interface_2 = %s", rsrc_interface_2);
- return MA_ERROR_INVALID_PARAMETER;
- }
+ ma_check_null_ret_error("pin", pin, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("target_1", target_1, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("subject_1", subject_1, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_uri_1", rsrc_uri_1, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_type_1", rsrc_type_1, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_interface_1", rsrc_interface_1, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("target_2", target_2, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("subject_2", subject_2, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_uri_2", rsrc_uri_2, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_type_2", rsrc_type_2, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("rsrc_interface_2", rsrc_interface_2, MA_ERROR_INVALID_PARAMETER);
/* Set d2ds status 'pending' */
g_atomic_int_set(&g_client->pending, 1);
- ret = _pair(service, pin, target_1, subject_1, rsrc_uri_1,
+ ret = _make_devices_pair(service, pin, target_1, subject_1, rsrc_uri_1,
rsrc_type_1, rsrc_interface_1, permission_1, target_2,
subject_2, rsrc_uri_2, rsrc_type_2, rsrc_interface_2,
permission_2);
ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
ma_check_null_ret_error("service", service, FALSE);
- MA_LOGD("[IPC] Unpair both devices");
+ MA_LOGD("[IPC] Make both devices unpair");
/* If we are working now? */
if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
- if (!uuid_dev1 || !uuid_dev2) {
- MA_LOGE("uuid_dev1 = %s", uuid_dev1);
- MA_LOGE("uuid_dev2 = %s", uuid_dev2);
- return MA_ERROR_INVALID_PARAMETER;
- }
+ ma_check_null_ret_error("uuid_dev1", uuid_dev1, MA_ERROR_INVALID_PARAMETER);
+ ma_check_null_ret_error("uuid_dev2", uuid_dev2, MA_ERROR_INVALID_PARAMETER);
/* Set d2ds status 'pending' */
g_atomic_int_set(&g_client->pending, 1);
- ret = _unpair(service, uuid_dev1, uuid_dev2);
+ ret = _makde_devices_unpair(service, uuid_dev1, uuid_dev2);
return ret;
}
if (NULL == g_client)
return MA_ERROR_NONE;
+ /* Wait until worker thread exits */
if (g_client->thread) {
g_thread_join(g_client->thread);
g_thread_unref(g_client->thread);
g_client->thread = NULL;
}
- g_mutex_lock(&iotivity_mutex);
+ /* Stop OCF threads */
+ g_mutex_lock(&g_client->iotivity_mutex);
ret = OCStop();
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_unlock(&g_client->iotivity_mutex);
if (OC_STACK_OK != ret) {
MA_LOGE( "OCStack stop error");
}
- g_mutex_lock(&iotivity_mutex);
+ /* Stop provisioning */
+ g_mutex_lock(&g_client->iotivity_mutex);
OCTerminatePM();
- g_mutex_unlock(&iotivity_mutex);
+ g_mutex_unlock(&g_client->iotivity_mutex);
- g_mutex_clear(&iotivity_mutex);
+ g_mutex_clear(&g_client->iotivity_mutex);
+ /* Remove found devices list */
_remove_owned_client();
_remove_mot_client();
+ /* Remove random PIN number */
if (g_client->rnd_pin) {
g_free(g_client->rnd_pin);
g_client->rnd_pin = NULL;
g_free(g_client);
g_client = NULL;
+
+ return ret;
}