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 = 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;
}
g_thread_unref(con->thread);
#ifdef TIMEOUT_USED
- con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S + 1, _ma_timeout_cb, con);
+ con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S * 2, _ma_timeout_cb, con);
#endif
return MA_ERROR_NONE;
}
g_thread_unref(con->thread);
#ifdef TIMEOUT_USED
- con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S + 1, _ma_timeout_cb, con);
+ con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S * 2, _ma_timeout_cb, con);
#endif
return MA_ERROR_NONE;
}
g_thread_unref(con->thread);
#ifdef TIMEOUT_USED
- con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S + 1, _ma_timeout_cb, con);
+ con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S * 2, _ma_timeout_cb, con);
#endif
return MA_ERROR_NONE;
}
}
client->g_doneCB = true;
}
-
-static void _provisioning_pairwise_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error)
-{
- ma_subowner_s *client = (ma_subowner_s *)ctx;
-
- if (!has_error) {
- MA_LOGD("Provision pairwise SUCCEEDED");
- } else {
- MA_LOGD( "Provision pairwise FAILED ");
- _print_result_list((const OCProvisionResult_t*) arr, nOfRes);
- }
- client->g_doneCB = true;
-}
-
static gpointer _provisioning_acl_func(gpointer data)
{
OCStackResult ret = OC_STACK_OK;
ma_req_cb_s *con = (ma_req_cb_s *)data;
OicSecAcl_t* acl = NULL;
- OicUuid_t *uuid = NULL;
+ OicUuid_t *uuid1 = NULL;
+ OicUuid_t *uuid2 = NULL;
OCProvisionDev_t *target_dev = NULL;
OCProvisionDev_t *subject_dev = NULL;
goto PVACL_ERROR;
}
- uuid = _convert_uuid(con->uuid_target_str);
- target_dev = _get_dev_by_uuid(g_client->g_mowned_list, uuid);
+ uuid1 = _convert_uuid(con->uuid_target_str);
+ target_dev = _get_dev_by_uuid(g_client->g_mowned_list, uuid1);
if (!target_dev) {
MA_LOGE("We can't find target in MOWNED dev list");
goto PVACL_ERROR;
}
- g_free(uuid);
- uuid = _convert_uuid(con->uuid_subject_str);
- subject_dev = _get_dev_by_uuid(g_client->g_mowned_list, uuid);
+ uuid2 = _convert_uuid(con->uuid_subject_str);
+ subject_dev = _get_dev_by_uuid(g_client->g_mowned_list, uuid2);
if (!subject_dev) {
MA_LOGE("We can't find subject in MOWNED dev list");
goto PVACL_ERROR;
}
- g_free(uuid);
g_client->g_doneCB = false;
MA_LOGI(" Provisioning Selected ACL..");
if (acl)
OCDeleteACLList(acl);
- if (uuid)
- g_free(uuid);
+ if (uuid1)
+ g_free(uuid1);
+ if (uuid2)
+ g_free(uuid2);
_request_cleanup(con);
g_thread_exit(GINT_TO_POINTER (1));
return NULL;
}
g_thread_unref(con->thread);
#ifdef TIMEOUT_USED
- con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S + 1, _ma_timeout_cb, con);
+ con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S * 2, _ma_timeout_cb, con);
+#endif
+ return MA_ERROR_NONE;
+}
+
+static void _provision_cred_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error)
+{
+ ma_subowner_s *client = (ma_subowner_s *)ctx;
+
+ if (!has_error) {
+ MA_LOGD("Provision ACL SUCCEEDED");
+ } else {
+ MA_LOGD( "Provision ACL FAILED ");
+ _print_result_list((const OCProvisionResult_t*) arr, nOfRes);
+ }
+ client->g_doneCB = true;
+}
+
+static gpointer _cred_provisioning_func(gpointer data)
+{
+ OCStackResult ret = OC_STACK_OK;
+ ma_req_cb_s *con = (ma_req_cb_s *)data;
+
+ OicUuid_t *uuid1 = NULL;
+ OicUuid_t *uuid2 = NULL;
+ OCProvisionDev_t *dev1 = NULL;
+ OCProvisionDev_t *dev2 = NULL;
+
+ if (!con->uuid_dev1 ) {
+ MA_LOGE("dev1 is NULL");
+ goto PVCRED_ERROR;
+ }
+ if (!con->uuid_dev2) {
+ MA_LOGE("dev2 is NULL");
+ goto PVCRED_ERROR;
+ }
+
+ uuid1 = _convert_uuid(con->uuid_dev1);
+ dev1 = _get_dev_by_uuid(g_client->g_mowned_list, uuid1);
+ if (!dev1) {
+ MA_LOGE("We can't find in MOWNED dev list");
+ goto PVCRED_ERROR;
+ }
+
+ uuid2 = _convert_uuid(con->uuid_dev2);
+ dev2 = _get_dev_by_uuid(g_client->g_mowned_list, uuid2);
+ if (!dev2) {
+ MA_LOGE("We can't find in MOWNED dev list");
+ goto PVCRED_ERROR;
+ }
+
+ /* To do ACL provisioning only one */
+ dev1->next = NULL;
+
+ /* To do ACL provisioning only one */
+ 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, _provision_cred_cb);
+ if (OC_STACK_OK != ret) {
+ MA_LOGD( "OCProvisionPairwiseDevices API error: %d (%s)", ret, _error_to_string(ret));
+ goto PVCRED_ERROR;
+ }
+
+ ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
+ if (ret) {
+ MA_LOGE( "OCProvisionCredentials Faild = %d", errno);
+ goto PVCRED_ERROR;
+ }
+
+ /* display the pairwise-provisioned result */
+ MA_LOGI("Provisioned Selected Pairwise Devices");
+
+PVCRED_ERROR:
+ /* Notify ACL result */
+ net_ma_emit_cred_done(ma_dbus_get_object(), (int)ret);
+
+ if (uuid1)
+ g_free(uuid1);
+ if (uuid2)
+ g_free(uuid2);
+ _request_cleanup(con);
+
+ g_thread_exit(GINT_TO_POINTER (1));
+
+ return NULL;
+}
+
+static int _provisioning_cred(ma_service *service,
+ gchar *uuid_dev1, gchar *uuid_dev2)
+{
+ ma_req_cb_s *con = NULL;
+ con = g_malloc0(sizeof(ma_req_cb_s));
+ if (!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_PROV_CRED;
+
+ if (!uuid_dev1 ||!uuid_dev2) {
+ MA_LOGE( "Invaild Prameters");
+ _request_cleanup(con);
+ return MA_ERROR_INVALID_PARAMETER;
+ }
+
+ con->uuid_dev1 = g_strdup(uuid_dev1);
+ con->uuid_dev2 = g_strdup(uuid_dev2);
+
+ con->thread = g_thread_try_new("prov_cred", _cred_provisioning_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 * 2, _ma_timeout_cb, con);
#endif
return MA_ERROR_NONE;
}
+static void _provisioning_pairwise_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error)
+{
+ ma_subowner_s *client = (ma_subowner_s *)ctx;
+
+ if (!has_error) {
+ MA_LOGD("Provision pairwise SUCCEEDED");
+ } else {
+ MA_LOGD( "Provision pairwise FAILED ");
+ _print_result_list((const OCProvisionResult_t*) arr, nOfRes);
+ }
+ client->g_doneCB = true;
+}
+
static gpointer _provisioning_pairwise_func(gpointer data)
{
OCStackResult ret = OC_STACK_OK;
MA_LOGE("%s", con->rsrc_type_2 );
MA_LOGE("%s", con->rsrc_interface_2 );
- goto PVACL_ERROR;
+ goto PVPAIRWIE_ERROR;
}
uuid_1 = _convert_uuid(con->target_1);
target_dev_1 = _get_dev_by_uuid(g_client->g_mowned_list, uuid_1);
if (!target_dev_1) {
MA_LOGE("We can't find target in MOWNED dev list");
- goto PVACL_ERROR;
+ goto PVPAIRWIE_ERROR;
}
uuid_2 = _convert_uuid(con->target_2);
target_dev_2 = _get_dev_by_uuid(g_client->g_mowned_list, uuid_2);
if (!target_dev_2) {
MA_LOGE("We can't find target in MOWNED dev list");
- goto PVACL_ERROR;
+ goto PVPAIRWIE_ERROR;
}
uuid_3 = _convert_uuid(con->subject_1);
subject_dev_1 = _get_dev_by_uuid(g_client->g_mowned_list, uuid_3);
if (!subject_dev_1) {
MA_LOGE("We can't find subject in MOWNED dev list");
- goto PVACL_ERROR;
+ goto PVPAIRWIE_ERROR;
}
uuid_4 = _convert_uuid(con->subject_2);
subject_dev_2 = _get_dev_by_uuid(g_client->g_mowned_list, uuid_4);
if (!subject_dev_2) {
MA_LOGE("We can't find subject in MOWNED dev list");
- goto PVACL_ERROR;
+ goto PVPAIRWIE_ERROR;
}
g_client->g_doneCB = false;
con->rsrc_interface_1, con->permission_1);
if (NULL == acl_1) {
MA_LOGE( "Failed to create ACL for %s", con->rsrc_uri);
- goto PVACL_ERROR;
+ goto PVPAIRWIE_ERROR;
}
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 PVACL_ERROR;
+ goto PVPAIRWIE_ERROR;
}
ret = OCProvisionPairwiseDevices((void*) g_client, SYMMETRIC_PAIR_WISE_KEY,
if (OC_STACK_OK != ret) {
MA_LOGD( "OCProvisionPairwiseDevices API error: %d (%s)", ret,
_error_to_string(ret));
- goto PVACL_ERROR;
+ goto PVPAIRWIE_ERROR;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (ret) {
MA_LOGE( "OCProvisionPairwise Faild = %d", errno);
- goto PVACL_ERROR;
+ goto PVPAIRWIE_ERROR;
}
/* display the pairwise-provisioned result */
- MA_LOGI(" Provision pairwise Successfully");
+ MA_LOGI(" Provision pairwise Done");
-PVACL_ERROR:
+PVPAIRWIE_ERROR:
/* Notify ACL result */
net_ma_emit_pairwise_done(ma_dbus_get_object(), (int)ret);
}
g_thread_unref(con->thread);
#ifdef TIMEOUT_USED
- con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S + 1, _ma_timeout_cb,
+ con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S * 2, _ma_timeout_cb,
con);
#endif
return MA_ERROR_NONE;
}
-static void _provision_cred_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error)
-{
- ma_subowner_s *client = (ma_subowner_s *)ctx;
-
- if (!has_error) {
- MA_LOGD("Provision ACL SUCCEEDED");
- } else {
- MA_LOGD( "Provision ACL FAILED ");
- _print_result_list((const OCProvisionResult_t*) arr, nOfRes);
- }
- client->g_doneCB = true;
-}
-
static void _unlink_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error)
{
ma_subowner_s *client = (ma_subowner_s *)ctx;
{
OCStackResult ret = OC_STACK_OK;
ma_req_cb_s *con = (ma_req_cb_s *)data;
+ ma_service *service = (ma_service *)con->userdata;
- OicUuid_t *uuid = NULL;
+ OicUuid_t *uuid1 = NULL;
+ OicUuid_t *uuid2 = NULL;
OCProvisionDev_t *dev1 = NULL;
OCProvisionDev_t *dev2 = NULL;
if (!con->uuid_dev1 ) {
MA_LOGE("dev1 is NULL");
- goto PVPWS_ERROR;
+ goto PVUNLINKPAIRWISE_ERROR;
}
if (!con->uuid_dev2) {
MA_LOGE("dev2 is NULL");
- goto PVPWS_ERROR;
+ goto PVUNLINKPAIRWISE_ERROR;
}
- uuid = _convert_uuid(con->uuid_dev1);
- dev1 = _get_dev_by_uuid(g_client->g_mowned_list, uuid);
+ uuid1 = _convert_uuid(con->uuid_dev1);
+ dev1 = _get_dev_by_uuid(g_client->g_mowned_list, uuid1);
if (!dev1) {
MA_LOGE("We can't find in MOWNED dev list");
- goto PVPWS_ERROR;
+ goto PVUNLINKPAIRWISE_ERROR;
}
- g_free(uuid);
- uuid = _convert_uuid(con->uuid_dev2);
- dev2 = _get_dev_by_uuid(g_client->g_mowned_list, uuid);
+ uuid2 = _convert_uuid(con->uuid_dev2);
+ dev2 = _get_dev_by_uuid(g_client->g_mowned_list, uuid2);
if (!dev2) {
MA_LOGE("We can't find in MOWNED dev list");
- goto PVPWS_ERROR;
+ goto PVUNLINKPAIRWISE_ERROR;
}
- g_free(uuid);
/* To do ACL provisioning only one */
dev1->next = NULL;
if (OC_STACK_OK != ret) {
MA_LOGD( "OCUnlinkDevices API error: %d (%s)", ret, _error_to_string(ret));
- goto PVPWS_ERROR;
+ goto PVUNLINKPAIRWISE_ERROR;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (ret) {
MA_LOGE( "OCUnlinkDevices Faild = %d", errno);
- goto PVPWS_ERROR;
+ goto PVUNLINKPAIRWISE_ERROR;
}
/* display the pairwise-provisioned result */
MA_LOGI("Unlink Devices");
- return 0;
-
-PVPWS_ERROR:
+PVUNLINKPAIRWISE_ERROR:
/* Notify ACL result */
net_ma_emit_unpair_done(ma_dbus_get_object(), (int)ret);
- if (uuid)
- g_free(uuid);
+ if (uuid1)
+ g_free(uuid1);
+ if (uuid2)
+ g_free(uuid2);
_request_cleanup(con);
g_thread_exit(GINT_TO_POINTER (1));
return NULL;
}
-static gpointer _cred_provisioning_func(gpointer data)
-{
- OCStackResult ret = OC_STACK_OK;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
-
- OicUuid_t *uuid = NULL;
- OCProvisionDev_t *dev1 = NULL;
- OCProvisionDev_t *dev2 = NULL;
-
- if (!con->uuid_dev1 ) {
- MA_LOGE("dev1 is NULL");
- goto PVPWS_ERROR;
- }
- if (!con->uuid_dev2) {
- MA_LOGE("dev2 is NULL");
- goto PVPWS_ERROR;
- }
-
- uuid = _convert_uuid(con->uuid_dev1);
- dev1 = _get_dev_by_uuid(g_client->g_mowned_list, uuid);
- if (!dev1) {
- MA_LOGE("We can't find in MOWNED dev list");
- goto PVPWS_ERROR;
- }
- g_free(uuid);
-
- uuid = _convert_uuid(con->uuid_dev2);
- dev2 = _get_dev_by_uuid(g_client->g_mowned_list, uuid);
- if (!dev2) {
- MA_LOGE("We can't find in MOWNED dev list");
- goto PVPWS_ERROR;
- }
- g_free(uuid);
-
- /* To do ACL provisioning only one */
- dev1->next = NULL;
-
- /* To do ACL provisioning only one */
- 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, _provision_cred_cb);
- if (OC_STACK_OK != ret) {
- MA_LOGD( "OCProvisionPairwiseDevices API error: %d (%s)", ret, _error_to_string(ret));
- goto PVPWS_ERROR;
- }
-
- ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
- if (ret) {
- MA_LOGE( "OCProvisionCredentials Faild = %d", errno);
- goto PVPWS_ERROR;
- }
-
- /* display the pairwise-provisioned result */
- MA_LOGI("Provisioned Selected Pairwise Devices");
-
- return 0;
-
-PVPWS_ERROR:
- /* Notify ACL result */
- net_ma_emit_cred_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 _provisioning_cred(ma_service *service,
- gchar *uuid_dev1, gchar *uuid_dev2)
-{
- ma_req_cb_s *con = NULL;
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (!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_PROV_CRED;
-
- if (!uuid_dev1 ||!uuid_dev2) {
- MA_LOGE( "Invaild Prameters");
- _request_cleanup(con);
- return MA_ERROR_INVALID_PARAMETER;
- }
-
- con->uuid_dev1 = g_strdup(uuid_dev1);
- con->uuid_dev2 = g_strdup(uuid_dev2);
-
- con->thread = g_thread_try_new("prov_cred", _cred_provisioning_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;
-}
-
static int _provisioning_unlink(ma_service *service,
gchar *uuid_dev1, gchar *uuid_dev2)
{
}
g_thread_unref(con->thread);
#ifdef TIMEOUT_USED
- con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S + 1, _ma_timeout_cb,
+ con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S * 2, _ma_timeout_cb,
con);
#endif
return MA_ERROR_NONE;