From: Saurav Babu Date: Wed, 10 Jan 2018 05:36:16 +0000 (+0530) Subject: d2d-subowner: Add implementation of missing function X-Git-Tag: submit/tizen/20190131.065036~262 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=02bfe9e1d0da73bc2476a4648ab3d0f41e3b329c;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git d2d-subowner: Add implementation of missing function Signed-off-by: Saurav Babu --- diff --git a/src/d2d-subowner/d2ds-subowner.c b/src/d2d-subowner/d2ds-subowner.c index 583e5e5..09cf6c6 100644 --- a/src/d2d-subowner/d2ds-subowner.c +++ b/src/d2d-subowner/d2ds-subowner.c @@ -99,6 +99,27 @@ typedef struct { /* For CRED provisioning */ gchar *uuid_dev1; /**< 1st device for CRED provisiong */ gchar *uuid_dev2; /**< 2nd device for CRED provisiong */ + + /* For Pairwaise linking */ + OCProvisionDev_t *target_1; /**< Target device 1*/ + OCProvisionDev_t *target_2; /**< Target device 1*/ + + OCProvisionDev_t *subject_1; /**< Target device for ACL */ + gchar *rsrc_uri_1; /**< Resource URI */ + gchar *rsrc_type_1; /**< Resouce Type */ + gchar *rsrc_interface_1; /**< Resource Interface Array To-Do : Make this as array */ + int permission_1;/**< Permision */ + OCProvisionDev_t *subject_2; /**< Target device for ACL */ + gchar *rsrc_uri_2; /**< Resource URI */ + gchar *rsrc_type_2; /**< Resouce Type */ + gchar *rsrc_interface_2; /**< Resource Interface Array To-Do : Make this as array */ + int permission_2;/**< Permision */ + OCProvisionDev_t *dev1; /**< 1st device for CRED provisiong */ + OCProvisionDev_t *dev2; /**< 2nd device for CRED provisiong */ + + /* For unpair */ + OCProvisionDev_t *target; /**< Target device */ + } d2ds_req_cb_s; typedef struct _d2ds_subowner { @@ -1253,6 +1274,32 @@ static void _provisioning_acl_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr client->g_doneCB = true; } +static void _provisioning_pairwise_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error) +{ + d2ds_subowner_s *client = (d2ds_subowner_s *)ctx; + + if (!has_error) { + D2DS_LOGD("Provision pairwise SUCCEEDED"); + } else { + D2DS_LOGD( "Provision pairwise FAILED "); + _print_result_list((const OCProvisionResult_t*) arr, nOfRes); + } + client->g_doneCB = true; +} + +static void _unpair_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error) +{ + d2ds_subowner_s *client = (d2ds_subowner_s *)ctx; + + if (!has_error) { + D2DS_LOGD("unpair SUCCEEDED"); + } else { + D2DS_LOGD( "unpair 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; @@ -1364,6 +1411,274 @@ static int _provisioning_acl(d2ds_service *service, gchar *target, gchar *subjec return D2DS_ERROR_NONE; } +static gpointer _provisioning_pairwise_func(gpointer data) +{ + OCStackResult ret = OC_STACK_OK; + d2ds_req_cb_s *con = (d2ds_req_cb_s *)data; + OicSecAcl_t* acl_1 = NULL; + OicSecAcl_t* acl_2 = NULL; + + 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) { + D2DS_LOGE("Some parameters are wrong"); + D2DS_LOGE("%p", con->subject_1 ); + D2DS_LOGE("%s", con->rsrc_uri_1 ); + D2DS_LOGE("%s", con->rsrc_type_1 ); + D2DS_LOGE("%s", con->rsrc_interface_1 ); + D2DS_LOGE("%p", con->subject_2 ); + D2DS_LOGE("%s", con->rsrc_uri_2 ); + D2DS_LOGE("%s", con->rsrc_type_2 ); + D2DS_LOGE("%s", con->rsrc_interface_2 ); + + goto PVACL_ERROR; + } + + g_client->g_doneCB = false; + D2DS_LOGI(" Provisioning Selected Pairwise.."); + + acl_1 = _create_target_acl(&con->target_1->doxm->deviceID, + &con->subject_1->doxm->deviceID, con->rsrc_uri_1, + con->rsrc_type_1, + con->rsrc_interface_1, con->permission_1); + if (NULL == acl_1) { + D2DS_LOGE( "Failed to create ACL for %s", con->rsrc_uri); + goto PVACL_ERROR; + } + + acl_2 = _create_target_acl(&con->target_2->doxm->deviceID, + &con->subject_2->doxm->deviceID, con->rsrc_uri_2, + con->rsrc_type_2, + con->rsrc_interface_2, con->permission_2); + if (NULL == acl_2) { + D2DS_LOGE( "Failed to create ACL for %s", con->rsrc_uri); + goto PVACL_ERROR; + } + + ret = OCProvisionPairwiseDevices((void*) g_client, SYMMETRIC_PAIR_WISE_KEY, + OWNER_PSK_LENGTH_256, con->target_1, acl_1, + con->target_2, acl_2, _provisioning_pairwise_cb); + if (OC_STACK_OK != ret) { + D2DS_LOGD( "OCProvisionPairwiseDevices API error: %d (%s)", ret, + _error_to_string(ret)); + goto PVACL_ERROR; + } + + ret = _wait_cb_ret(CALLBACK_TIMEOUT_S); + if (ret) { + D2DS_LOGE( "OCProvisionPairwise Faild = %d", errno); + goto PVACL_ERROR; + } + /* display the pairwise-provisioned result */ + D2DS_LOGI(" Provision pairwise Successfully"); + +PVACL_ERROR: + /* Notify ACL result */ + net_d2ds_emit_prov_acl_done(d2ds_dbus_get_object(), (int)ret); + + if (acl_1) { + OCDeleteACLList(acl_1); + acl_1 = NULL; + } + if (acl_2) { + OCDeleteACLList(acl_2); + acl_2 = NULL; + } + _request_cleanup(con); + g_thread_exit(GINT_TO_POINTER (1)); + return NULL; +} + +static gpointer _unpair_func(gpointer data) +{ + OCStackResult ret = OC_STACK_OK; + d2ds_req_cb_s *con = (d2ds_req_cb_s *)data; + + if (!con->target) { + D2DS_LOGE("Some parameters are wrong"); + D2DS_LOGE("%p", con->target ); + goto PVACL_ERROR; + } + + g_client->g_doneCB = false; + D2DS_LOGI(" unpair device.."); + + ret = OCRemoveDevice((void*) g_client,DISCOVERY_TIMEOUT,con->target,_unpair_cb ); + if (OC_STACK_OK != ret) { + D2DS_LOGD( "OCRemoveDevice API error: %d (%s)", ret, _error_to_string(ret)); + goto PVACL_ERROR; + } + + ret = _wait_cb_ret(CALLBACK_TIMEOUT_S); + if (ret) { + D2DS_LOGE( "OCRemoveDevice Faild = %d", errno); + goto PVACL_ERROR; + } + /* display the pairwise-provisioned result */ + D2DS_LOGI(" Provision pairwise Successfully"); + +PVACL_ERROR: + /* Notify ACL result */ + net_d2ds_emit_prov_acl_done(d2ds_dbus_get_object(), (int)ret); + + _request_cleanup(con); + g_thread_exit(GINT_TO_POINTER (1)); + return NULL; +} + +static int _provisioning_unpair(d2ds_service *service, gchar *target) +{ + + OicUuid_t *uuid = NULL; + OCProvisionDev_t *target_dev = NULL; + + d2ds_req_cb_s *con = NULL; + con = g_malloc0(sizeof(d2ds_req_cb_s)); + if (NULL == con) { + D2DS_LOGE( "g_malloc0() Fail=%d", errno); + /* Unset d2ds status 'pending' */ + g_atomic_int_set(&service->pending, 0); + return D2DS_ERROR_OUT_OF_MEMORY; + } + + con->userdata = service; + con->cid = D2DS_UNPAIR; + + uuid = _convert_uuid(target); + + target_dev = _get_dev_by_uuid(g_client->g_mowned_list, uuid); + if (!target_dev) { + D2DS_LOGE("We can't find target in MOWNED dev list"); + _request_cleanup(con); + return D2DS_ERROR_NO_DATA; + } + g_free(uuid); + + + /* Copy subject device and related information */ + con->target = PMCloneOCProvisionDev(target_dev); + /* To do ACL provisioning only one */ + con->target->next = NULL; + + + con->thread = g_thread_try_new("unpair_device", _unpair_func, con, NULL); + if (!con->thread) { + D2DS_LOGE("Failed to create thread"); + _request_cleanup(con); + return D2DS_ERROR_OUT_OF_MEMORY; + } + g_thread_unref(con->thread); +#ifdef TIMEOUT_USED + con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_S + 1, _d2ds_timeout_cb, con); +#endif + return D2DS_ERROR_NONE; +} + +static int _provisioning_pairwise_link(d2ds_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) +{ + + OicUuid_t *uuid_1 = NULL; + OicUuid_t *uuid_2 = NULL; + OCProvisionDev_t *target_dev_1 = NULL; + OCProvisionDev_t *subject_dev_1 = NULL; + OCProvisionDev_t *target_dev_2 = NULL; + OCProvisionDev_t *subject_dev_2 = NULL; + + d2ds_req_cb_s *con = NULL; + con = g_malloc0(sizeof(d2ds_req_cb_s)); + if (NULL == con) { + D2DS_LOGE( "g_malloc0() Fail=%d", errno); + /* Unset d2ds status 'pending' */ + g_atomic_int_set(&service->pending, 0); + return D2DS_ERROR_OUT_OF_MEMORY; + } + + con->userdata = service; + con->cid = D2DS_PROV_PAIRWISE; + + uuid_1 = _convert_uuid(target_1); + uuid_2 = _convert_uuid(target_2); + + target_dev_1 = _get_dev_by_uuid(g_client->g_mowned_list, uuid_1); + if (!target_dev_1) { + D2DS_LOGE("We can't find target in MOWNED dev list"); + _request_cleanup(con); + return D2DS_ERROR_NO_DATA; + } + g_free(uuid_1); + + target_dev_2 = _get_dev_by_uuid(g_client->g_mowned_list, uuid_2); + if (!target_dev_2) { + D2DS_LOGE("We can't find target in MOWNED dev list"); + _request_cleanup(con); + return D2DS_ERROR_NO_DATA; + } + g_free(uuid_2); + + /* Copy subject device and related information */ + con->target_1 = PMCloneOCProvisionDev(target_dev_1); + /* To do ACL provisioning only one */ + con->target_1->next = NULL; + + + /* Copy subject device and related information */ + con->target_2 = PMCloneOCProvisionDev(target_dev_2); + /* To do ACL provisioning only one */ + con->target_2->next = NULL; + + uuid_1 = _convert_uuid(subject_1); + subject_dev_1 = _get_dev_by_uuid(g_client->g_mowned_list, uuid_1); + if (!subject_dev_1) { + D2DS_LOGE("We can't find subject in MOWNED dev list"); + _request_cleanup(con); + return D2DS_ERROR_NO_DATA; + } + g_free(uuid_1); + + uuid_2 = _convert_uuid(subject_2); + subject_dev_2 = _get_dev_by_uuid(g_client->g_mowned_list, uuid_2); + if (!subject_dev_2) { + D2DS_LOGE("We can't find subject in MOWNED dev list"); + _request_cleanup(con); + return D2DS_ERROR_NO_DATA; + } + g_free(uuid_2); + + /* Copy subject device and related information */ + con->subject_1 = PMCloneOCProvisionDev(subject_dev_1); + /* To do ACL provisioning only one */ + con->subject_1->next = NULL; + + /* Copy subject device and related information */ + con->subject_2 = PMCloneOCProvisionDev(subject_dev_2); + /* To do ACL provisioning only one */ + con->subject_2->next = NULL; + + con->rsrc_uri_1 = OICStrdup(rsrc_uri_1); + con->rsrc_type_1 = OICStrdup(rsrc_type_1); + con->rsrc_interface_1 = OICStrdup(rsrc_interface_1); + + con->rsrc_uri_2 = OICStrdup(rsrc_uri_2); + con->rsrc_type_2 = OICStrdup(rsrc_type_2); + con->rsrc_interface_2 = OICStrdup(rsrc_interface_2); + + con->thread = g_thread_try_new("prov_pairwise", _provisioning_pairwise_func, + con, NULL); + if (!con->thread) { + D2DS_LOGE("Failed to create thread"); + _request_cleanup(con); + return D2DS_ERROR_OUT_OF_MEMORY; + } + g_thread_unref(con->thread); +#ifdef TIMEOUT_USED + con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_S + 1, _d2ds_timeout_cb, + con); +#endif + return D2DS_ERROR_NONE; +} + + static void _provision_cred_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error) { d2ds_subowner_s *client = (d2ds_subowner_s *)ctx; @@ -1693,3 +2008,69 @@ int d2ds_request_disable(d2ds_service *service) return D2DS_ERROR_NONE; } +int d2ds_request_pairwise(d2ds_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) +{ + int ret =D2DS_ERROR_NONE; + + d2ds_check_null_ret_error("service", service, FALSE); + + D2DS_LOGD("[IPC] Link Pairwise"); + + /* If we are working now? */ + if (g_atomic_int_get(&service->pending)) + return D2DS_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) { + D2DS_LOGE("target_1 = %s", target_1); + D2DS_LOGE("subject_1 = %s", subject_1); + D2DS_LOGE("rsrc_uri_1 = %s", rsrc_uri_1); + D2DS_LOGE("rsrc_type_1 = %s", rsrc_type_1); + D2DS_LOGE("rsrc_interface_1 = %s", rsrc_interface_1); + D2DS_LOGE("target_2 = %s", target_2); + D2DS_LOGE("subject_2 = %s", subject_2); + D2DS_LOGE("rsrc_uri_2 = %s", rsrc_uri_2); + D2DS_LOGE("rsrc_type_2 = %s", rsrc_type_2); + D2DS_LOGE("rsrc_interface_2 = %s", rsrc_interface_2); + return D2DS_ERROR_INVALID_PARAMETER; + } + + /* Set d2ds status 'pending' */ + g_atomic_int_set(&service->pending, 1); + + ret = _provisioning_pairwise_link(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); + + return ret; + +} + +int d2ds_request_unpair(d2ds_service *service, gchar *uuid_dev) +{ + int ret = D2DS_ERROR_NONE; + + d2ds_check_null_ret_error("service", service, FALSE); + + D2DS_LOGD("[IPC] Unpair device"); + + /* If we are working now? */ + if (g_atomic_int_get(&service->pending)) + return D2DS_ERROR_IN_PROGRESS; + + if (!uuid_dev) { + D2DS_LOGE("uuid_dev = %s", uuid_dev); + + return D2DS_ERROR_INVALID_PARAMETER; + } + + /* Set d2ds status 'pending' */ + g_atomic_int_set(&service->pending, 1); + + ret = _provisioning_unpair(service, uuid_dev); + + return ret; + +} + diff --git a/src/d2d-subowner/d2ds-subowner.h b/src/d2d-subowner/d2ds-subowner.h index fb6f564..aa5829b 100644 --- a/src/d2d-subowner/d2ds-subowner.h +++ b/src/d2d-subowner/d2ds-subowner.h @@ -33,6 +33,8 @@ typedef enum { D2DS_PROV_ACL, /**< ACL Provisioning */ D2DS_PROV_CRED, /**< CRED Provisioning */ D2DS_REMOVE_MOT, /**< Remove Multiple Ownership */ + D2DS_UNPAIR, /**< Unpair */ + D2DS_PROV_PAIRWISE, /** < Pairwise Provisioning */ } d2ds_cmd_id_e; /* ACL Permission type */ @@ -53,9 +55,12 @@ int d2ds_request_remove_mo(d2ds_service *service, gchar* uuid_str); int d2ds_request_prov_acl(d2ds_service *service, gchar *target, gchar *subject, gchar *rsrc_uri, gchar *rsrc_type, gchar *rsrc_interface, int permission); int d2ds_request_prov_cred(d2ds_service *service, gchar *uuid_dev1, gchar *uuid_dev2); -int d2ds_request_unpair(d2ds_service *service, gchar *uuid_dev1, gchar *uuid_dev2); +int d2ds_request_unpair(d2ds_service *service, gchar *uuid_dev); int d2ds_request_get_ownerid(d2ds_service *service, gchar **uuid_str); int d2ds_request_disable(d2ds_service *service); +int d2ds_request_pairwise(d2ds_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); #ifdef __cplusplus }