#include "oxmrandompin.h"
#include "securevirtualresourcetypes.h"
#include "security/srmutility.h"
-//#include "srmutility.h"
#include "pmtypes.h"
#include "pmutility.h"
#include <tzplatform_config.h>
-#define MAX_FILE_PATH_LEN 1024
-
#include "d2ds.h"
#include "d2ds-log.h"
#include "d2ds-util.h"
+#include "d2ds-subowner.h"
-// declaration(s) for provisioning client using C-level provisioning API
-// user input definition for main loop on provisioning client
-#define _10_DISCOV_MOT_ENABLED_DEV_ 10
-#define _11_DISCOV_MULTIPLE_OWNED_DEV_ 11
-#define _20_PERFORM_MOT_ 20
-#define _30_GET_LED_RESOURCE_ 30
-#define _31_PUT_LED_RESOURCE_ 31
-#define _40_PROVISION_ACL_ 40
-#define _41_PROVISION_CRED_ 41
-#define _99_EXIT_PRVN_CLT_ 99
-
-#define ACL_RESRC_MAX_NUM 16
-#define ACL_RESRC_ARRAY_SIZE 3 //This value is used only for sample (not OCF spec)
+#define MAX_FILE_PATH_LEN 1024
#define ACL_RESRC_MAX_LEN 128
-#define ACL_PEMISN_CNT 5
-#define DISCOVERY_TIMEOUT 1 // 1 sec
-#define CALLBACK_TIMEOUT /* 100ms */ 10 * 10
-#define TAG "subownerclient"
+/*This value is used only for sample (not OCF spec) */
+#define ACL_RESRC_ARRAY_SIZE 3
+
+#define DISCOVERY_TIMEOUT 5 /* 5 sec */
+#define CALLBACK_TIMEOUT_S 5 /* 5 sec */
+#define CALLBACK_TIMEOUT_MS 10 * 50 /* 5sec = 100ms * 50 */
+
+/* '_' for separaing from the same constant variable in srmresourcestrings.c */
static const char* SVR_DB_FILE_NAME = "oic_svr_db_subowner_client.dat";
- // '_' for separaing from the same constant variable in |srmresourcestrings.c|
static const char* PRVN_DB_FILE_NAME = "oic_pdm_subowner.db";
-static const OicSecPrm_t SUPPORTED_PRMS[1] =
-{
- PRM_PRE_CONFIGURED,
-};
-
-// |g_ctx| means provision manager application context and
-// the following, includes |un/own_list|, could be variables, which |g_ctx| has,
-// for accessing all function(s) for these, they are declared on global domain
-static const char* g_ctx = "SubOwner Client Context";
-static char* g_svr_fname;
-static char* g_prvn_fname;
-static OCProvisionDev_t* g_own_list;
-static OCProvisionDev_t* g_unown_list;
-static OCProvisionDev_t* g_motdev_list;
-static OCProvisionDev_t* g_mowned_list;
-static int g_own_cnt;
-static int g_unown_cnt;
-static int g_motdev_cnt;
-static int g_mowned_cnt;
-static bool g_doneCB;
-
-// function declaration(s) for calling them before implementing
-
-static void _d2d_print_uuid(const OicUuid_t* uuid)
+
+static const OicSecPrm_t SUPPORTED_PRMS[2] = { PRM_PRE_CONFIGURED, PRM_RANDOM_PIN };
+
+typedef struct {
+ d2ds_cmd_id_e cid; /**< Command ID */
+ int tid; /**< Timer ID */
+ GThread *thread; /**< Thread handle */
+ unsigned int sid; /**< Subcribed signal ID */
+ bool found; /**< Whether we discoverd devices */
+ void *cb; /**< Callback function pointer */
+ void *userdata; /**< User data */
+
+ /* To-Do : Change belows to union type */
+
+ /* For MOT */
+ OCProvisionDev_t *target; /**< Target device for MOT */
+ gchar *pin; /**< PIN */
+
+ /* For ACL provisioning */
+ OCProvisionDev_t *subject; /**< Target device for ACL */
+ gchar *rsrc_uri; /**< Resource URI */
+ gchar *rsrc_type; /**< Resouce Type */
+ gchar *rsrc_interface; /**< Resource Interface Array To-Do : Make this as array */
+ int permission;/**< Permision */
+
+ /* For CRED provisioning */
+ OCProvisionDev_t *dev1; /**< 1st device for CRED provisiong */
+ OCProvisionDev_t *dev2; /**< 2nd device for CRED provisiong */
+} d2ds_req_cb_s;
+
+typedef struct _d2ds_subowner {
+ OCProvisionDev_t* g_motdev_list; /**< Discoverd MOT enabled devices list */
+ OCProvisionDev_t* g_mowned_list; /**< My owned MOT enabled devices list */
+
+ int g_motdev_cnt; /**< Number of MOT enabled devices */
+ int g_mowndev_cnt; /**< Number of my owned MOT enabled devices */
+
+ bool g_doneCB; /**< This means callback completed or not */
+
+ char *rnd_pin; /**< Random PIN */
+ int rnd_pin_len; /**< Random PIN length */
+
+} d2ds_subowner_s;
+
+d2ds_subowner_s *g_client;
+
+static void _print_uuid(const OicUuid_t* uuid)
{
char uuid_string[256] = {0};
snprintf(uuid_string, sizeof(uuid_string),
lst = lst->next;
}
- return NULL; // in here |lst| is always |NULL|
+ return NULL;
}
static OCProvisionDev_t* _get_dev_by_uuid(const OCProvisionDev_t* dev_lst,
}
OCProvisionDev_t* lst = (OCProvisionDev_t*)dev_lst;
+ _print_uuid(&lst->doxm->deviceID);
while (lst) {
if (!memcmp((const void *)&lst->doxm->deviceID, (const void *)uuid, sizeof(OicUuid_t)))
return lst;
+ _print_uuid(uuid);
lst = lst->next;
}
return NULL;
}
-static int printDevList(const OCProvisionDev_t* dev_lst)
+static int _print_dev_list(const OCProvisionDev_t* dev_lst)
{
if(!dev_lst) {
D2DS_LOGI(" Device List is Empty..\n\n");
int lst_cnt = 0;
for( ; lst; ) {
D2DS_LOGI(" [%d] ", ++lst_cnt);
- _d2d_print_uuid((const OicUuid_t*) &lst->doxm->deviceID);
+ _print_uuid((const OicUuid_t*) &lst->doxm->deviceID);
lst = lst->next;
}
return lst_cnt;
}
-static size_t printUuidList(const OCUuidList_t* uid_lst)
-{
- if(!uid_lst) {
- D2DS_LOGI(" Device List is Empty..\n\n");
- return 0;
- }
-
- OCUuidList_t* lst = (OCUuidList_t*) uid_lst;
- size_t lst_cnt = 0;
- for( ; lst; ) {
- D2DS_LOGI(" [%zu] ", ++lst_cnt);
- _d2d_print_uuid((const OicUuid_t*) &lst->dev);
- lst = lst->next;
- }
- D2DS_LOGI("\n");
-
- return lst_cnt;
-}
-
-static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
+static int _print_result_list(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
{
if(!rslt_lst || 0>=rslt_cnt) {
D2DS_LOGI(" Device List is Empty..\n\n");
int lst_cnt = 0;
for( ; rslt_cnt>lst_cnt; ++lst_cnt) {
- D2DS_LOGI(" [%d] ", lst_cnt+1);
- _d2d_print_uuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
- D2DS_LOGI(" - result: %d\n", rslt_lst[lst_cnt].res);
+ _print_uuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
+ D2DS_LOGI(" -> result: %d\n", rslt_lst[lst_cnt].res);
}
- D2DS_LOGI("\n");
return lst_cnt;
}
-static FILE*_d2ds_fopen_prvn_mng(const char* path, const char* mode)
+static FILE* _fopen_prvn_mng(const char* path, const char* mode)
{
char data_dir[MAX_FILE_PATH_LEN] = {0,};
return fopen(data_dir, mode);
}
-static int ___d2d_wait_cb_ret(void)
+static int _wait_cb_ret(int milli_seconds)
{
OCStackResult ret = OC_STACK_OK;
- for(int i=0; !g_doneCB && CALLBACK_TIMEOUT>i; ++i) {
+ for(int i=0; !g_client->g_doneCB && milli_seconds > i; ++i) {
usleep(1000);
ret = OCProcess();
if(OC_STACK_OK != ret) {
}
}
- if(!g_doneCB)
+ if(!g_client->g_doneCB)
OCPDMCleanupForTimeout();
return ret;
}
-#if 0 /* TEST */
-static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
-{
- if(!a || !b || 2>max || !str) {
- return -1;
- }
-
- for( ; ; ) {
- for(int i=0; 2>i; ++i) {
- int* num = 0==i?a:b;
- for( ; ; ) {
- printf(" > Enter Device[%d] Number, %s: ", i+1, str);
- for(int ret=0; 1!=ret; ) {
- ret = scanf("%d", num);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<*num && max>=*num) {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
- }
- }
- if(*a != *b) {
- printf("\n");
- return 0;
- }
- }
-
- return -1;
-}
-
-// callback function(s) for provisioning client using C-level provisioning API
-static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
- if(!hasError)
- {
- D2DS_LOGD( "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
- }
- else
- {
- D2DS_LOGD( "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
- printResultList((const OCProvisionResult_t*) arr, nOfRes);
- }
- g_doneCB = true;
-}
-
-static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
- if(!hasError)
- {
- D2DS_LOGD( "POST 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
- }
- else
- {
- D2DS_LOGD( "POST 'doxm' FAILED - ctx: %s", (char*) ctx);
- printResultList((const OCProvisionResult_t*) arr, nOfRes);
- }
- g_doneCB = true;
-}
-
-static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
- if(!hasError)
- {
- D2DS_LOGD( "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
- }
- else
- {
- D2DS_LOGD( "Provision Credential FAILED - ctx: %s", (char*) ctx);
- printResultList((const OCProvisionResult_t*) arr, nOfRes);
- }
- g_doneCB = true;
-}
-
-static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
- if(!hasError)
- {
- D2DS_LOGD( "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
- }
- else
- {
- D2DS_LOGD( "Provision ACL FAILED - ctx: %s", (char*) ctx);
- printResultList((const OCProvisionResult_t*) arr, nOfRes);
- }
- g_doneCB = true;
-}
-
-// response handler for LED requests.
-static void LedCB(void *ctx, OCDoHandle UNUSED,
- OCClientResponse *clientResponse)
-{
- if(clientResponse)
- {
- if(OC_STACK_OK == clientResponse->result)
- {
- printf("Received OC_STACK_OK from server\n");
- if(clientResponse->payload)
- {
- printf("Response ===================> %s\n", clientResponse->payload);
- }
- }
- else if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
- {
- printf("Received OC_STACK_RESOURCE_CHANGED from server\n");
- }
- else
- {
- printf("Error in response : %d\n", clientResponse->result);
- }
- }
- else
- {
- printf("Hit the response callback but can not find response data\n");
- }
-
- g_doneCB = true;
-}
-#endif /* TEST */
-
-static void inputPinCB(char* pin, size_t len)
+static void _input_pin_cb(char* pin, size_t len)
{
- if(!pin || OXM_RANDOM_PIN_MAX_SIZE>=len)
- {
+ if(!pin || OXM_RANDOM_PIN_MAX_SIZE>=len) {
D2DS_LOGE( "inputPinCB invalid parameters");
return;
}
- printf(" > INPUT PIN: ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%32s", pin);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
+ memcpy(pin, g_client->rnd_pin, g_client->rnd_pin_len);
+ D2DS_LOGI("Random PIN : %s", g_client->rnd_pin);
}
-static void _d2ds_remove_mot_client()
+static void _remove_mot_client()
{
GMutex motdev_mutex;
g_mutex_init(&motdev_mutex);
g_mutex_lock(&motdev_mutex);
- if(g_motdev_list) {
- OCDeleteDiscoveredDevices(g_motdev_list);
- g_motdev_list = NULL;
+ if(g_client->g_motdev_list) {
+ OCDeleteDiscoveredDevices(g_client->g_motdev_list);
+ g_client->g_motdev_list = NULL;
}
g_mutex_unlock(&motdev_mutex);
}
-static void _d2ds_remove_owned_client()
+static void _remove_owned_client()
{
GMutex owned_dev_mutex;
/* delete un/owned device lists before updating them */
g_mutex_init(&owned_dev_mutex);
g_mutex_lock(&owned_dev_mutex);
- if(g_mowned_list) {
- OCDeleteDiscoveredDevices(g_mowned_list);
- g_mowned_list = NULL;
+ if(g_client->g_mowned_list) {
+ OCDeleteDiscoveredDevices(g_client->g_mowned_list);
+ g_client->g_mowned_list = NULL;
}
g_mutex_unlock(&owned_dev_mutex);
}
// function(s) for provisioning client using C-level provisioning API
-static int d2ds_init_provision_client(void)
+static int _init_provision_client(void)
{
OCStackResult ret = OC_STACK_OK;
char data_dir[MAX_FILE_PATH_LEN] = {0,};
snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), PRVN_DB_FILE_NAME);
- // initialize persistent storage for SVR DB
- static OCPersistentStorage ps = {
- _d2ds_fopen_prvn_mng,
- fread,
- fwrite,
- fclose,
- unlink
- };
+ /* initialize persistent storage for SVR DB */
+ static OCPersistentStorage ps = { _fopen_prvn_mng, fread, fwrite, fclose, unlink };
ret = OCRegisterPersistentStorageHandler(&ps);
if(OC_STACK_OK != ret ) {
D2DS_LOGE( "OCRegisterPersistentStorageHandler error = %d", ret);
- return -1;
+ return ret;
}
- // initialize OC stack and provisioning manager
+ /* initialize OC stack and provisioning manager */
ret = OCInit(NULL, 0, OC_CLIENT_SERVER);
if(OC_STACK_OK != ret ) {
D2DS_LOGE( "OCInit() error = %d", ret);
- return -1;
+ return ret;
}
if (access(data_dir, F_OK) != -1)
ret = OCInitPM(data_dir);
if(OC_STACK_OK != ret ) {
D2DS_LOGE( "OCInitPM() error = %d", ret);
- return -1;
+ return ret;
}
- SetInputPinCB(inputPinCB);
+ SetInputPinCB(_input_pin_cb);
+
+ g_client = calloc(1, sizeof(d2ds_subowner_s));
+ if(!g_client) {
+ D2DS_LOGE( "memory allocation error = %d", errno);
+ return D2DS_ERROR_OUT_OF_MEMORY;
+ }
+ g_client->g_motdev_list = NULL;
+ g_client->g_mowned_list = NULL;
+ g_client->rnd_pin = NULL;
return ret;
}
-
-/* command id */
-typedef enum {
- D2DS_DISC_MOT_ENB_DEVS = 0,
- D2DS_DISC_MOTED_DEVS,
- D2DS_MOT,
- D2DS_MOT_PAIRWISE,
-} d2ds_cmd_id_e;
-
-typedef struct {
- d2ds_cmd_id_e cid; /**< Command ID */
- int tid; /**< Timer ID */
- GThread *thread; /**< Thread handle */
- unsigned int sid; /**< Subcribed signal ID */
- bool found; /**< Whether we discoverd devices */
- void *cb; /**< Callback function pointer */
- void *userdata; /**< User data */
-
- OCProvisionDev_t *target; /**< Target device */
- guchar *pin /**< PIN */
-
-} d2ds_req_cb_s;
-
-static void _d2sd_request_cleanup(gpointer data)
+static void _request_cleanup(gpointer data)
{
d2ds_req_cb_s *con = (d2ds_req_cb_s *)data;
d2ds_service *service = (d2ds_service *)con->userdata;
+ if (!con) {
+ D2DS_LOGI("container is null");
+ return;
+ }
+
if (con->tid) {
g_source_remove(con->tid);
con->tid = 0;
}
con->sid = 0;
con->found = FALSE;
- if (con->target)
+#if 0
+ if (con->target) {
PMDeleteDeviceList(con->target);
- if (con->pin)
+ con->target = NULL;
+ }
+#endif
+ if (con->pin) {
free(con->pin);
+ con->pin = NULL;
+ }
+#if 0
+ D2DS_LOGE("KSR : %p", con->subject);
+ if (con->subject) {
+ PMDeleteDeviceList(con->subject);
+ con->subject = NULL;
+ }
+#endif
+ if (con->rsrc_uri) {
+ free(con->rsrc_uri);
+ con->rsrc_uri = NULL;
+ }
+ if (con->rsrc_type) {
+ free(con->rsrc_type);
+ con->rsrc_type = NULL;
+ }
+ if (con->rsrc_interface) {
+ free(con->rsrc_interface);
+ con->rsrc_interface = NULL;
+ }
/* Set d2ds status 'pending' */
g_atomic_int_set(&service->pending, 0);
- free(con);
+ if (con) {
+ free(con);
+ con = NULL;
+ }
}
-static gboolean _d2ds_timeout_cb(gpointer p)
+static gboolean _d2ds_timeout_cb(gpointer data)
{
- d2ds_req_cb_s *con = (d2ds_req_cb_s *)p;
+ d2ds_req_cb_s *con = (d2ds_req_cb_s *)data;
- if (NULL == con, G_SOURCE_REMOVE) {
+ if (NULL == con) {
D2DS_LOGE("container is NULL");
return G_SOURCE_REMOVE;
}
OCPDMCleanupForTimeout();
switch (con->cid) {
- case D2DS_DISC_MOT_ENB_DEVS:
- // display the discovered device lists
- D2DS_LOGE(" > Discovered Multiple Ownership Transfer Enabled Devices\n");
- g_motdev_cnt = printDevList(g_motdev_list);
- break;
- case D2DS_DISC_MOTED_DEVS:
- break;
- case D2DS_MOT:
- break;
- case D2DS_MOT_PAIRWISE:
- break;
- }
-
- _d2sd_request_cleanup((gpointer)con);
+ case D2DS_DISC_MOT_ENB_DEVS:
+ D2DS_LOGE(" > Discovered Multiple Ownership Transfer Enabled Devices\n");
+ g_client->g_motdev_cnt = _print_dev_list(g_client->g_motdev_list);
+ break;
+ case D2DS_DISC_MOWNED_DEVS:
+ D2DS_LOGE(" > Discovered Multiple Ownership Transfer Enabled Devices\n");
+ g_client->g_mowndev_cnt = _print_dev_list(g_client->g_mowned_list);
+ break;
+ case D2DS_MOT:
+ case D2DS_PROV_ACL:
+ case D2DS_PROV_CRED:
+ break;
+ }
+
+ _request_cleanup((gpointer)con);
return G_SOURCE_REMOVE;
}
-#ifdef TIMER_TEST
-static int _d2ds_disc_mot_enb_devs_timer(d2ds_service *service)
+static gpointer _disc_mot_env_devs_func(gpointer data)
{
- d2ds_req_cb_s *con = NULL;
-
- _d2ds_remove_mot_client();
-
- // call |OCDiscoverMultipleOwnerEnabledDevices| API actually
- D2DS_LOGI(" Discovering Multiple Ownership Transfer enabled Devices on Network..\n");
- if(OC_STACK_OK != OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT,
- &g_motdev_list)) {
- D2DS_LOGE( "OCDiscoverMultipleOwnerEnalbedDevices API error");
- return D2DS_ERROR_OPERATION_FAILED;
- }
-
- con = calloc(1, sizeof(d2ds_req_cb_s));
- if (NULL == con) {
- D2DS_LOGE( "calloc() Fail=%d", errno);
- return D2DS_ERROR_OUT_OF_MEMORY;
- }
-
- //con->cb = cb;
- //con->sid = sub_id;
- con->userdata = service;
- con->cid = D2DS_DISC_MOT_ENB_DEVS;
- con->tid = g_timeout_add_seconds(DISCOVERY_TIMEOUT + 1, _d2ds_timeout_cb, con);
-
- return D2DS_ERROR_NONE;
-}
-#endif
-
-static gpointer __d2ds_disc_mot_env_devs_func(gpointer data)
-{
- NOTUSED(data);
+ d2ds_req_cb_s *con = (d2ds_req_cb_s *)data;
/* delete un/owned device lists before updating them */
- _d2ds_remove_mot_client();
+ _remove_mot_client();
- // call |OCDiscoverMultipleOwnerEnabledDevices| API actually
- D2DS_LOGI(" Discovering Multiple Ownership Transfer enabled Devices on Network..\n");
+ D2DS_LOGI("Discovering Multiple Ownership Transfer enabled Devices on Network..");
if(OC_STACK_OK != OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT,
- &g_motdev_list)) {
+ &g_client->g_motdev_list)) {
D2DS_LOGE( "OCDiscoverMultipleOwnerEnalbedDevices API error");
- return NULL;
+ goto DISC_MOT_ENB_DEVS_END;
}
- g_thread_exit(GINT_TO_POINTER (1));
+ /* display the discovered device lists */
+ D2DS_LOGD(" > Discovered Multiple Owner Transfer Enabled Devices\n");
+ g_client->g_motdev_cnt = _print_dev_list(g_client->g_motdev_list);
- _d2sd_request_cleanup((gpointer)data);
+DISC_MOT_ENB_DEVS_END:
+ _request_cleanup(con);
+ g_thread_exit(GINT_TO_POINTER (1));
return NULL;
}
-static int _d2ds_disc_mot_enb_devs_thd(d2ds_service *service)
+static int _disc_mot_enb_devs(d2ds_service *service)
{
d2ds_req_cb_s *con = NULL;
con = calloc(1, sizeof(d2ds_req_cb_s));
return D2DS_ERROR_OUT_OF_MEMORY;
}
- con->thread = g_thread_try_new("disc_mot_env_devs", __d2ds_disc_mot_env_devs_func, con, NULL);
+ con->thread = g_thread_try_new("disc_mot_env_devs", _disc_mot_env_devs_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);
con->userdata = service;
con->cid = D2DS_DISC_MOT_ENB_DEVS;
- con->tid = g_timeout_add_seconds(DISCOVERY_TIMEOUT + 1, _d2ds_timeout_cb, con);
+ //con->tid = g_timeout_add_seconds(DISCOVERY_TIMEOUT + 1, _d2ds_timeout_cb, con);
return D2DS_ERROR_NONE;
}
-static gpointer __d2ds_disc_owned_env_devs_func(gpointer data)
+static gpointer _disc_owned_devs_func(gpointer data)
{
- NOTUSED(data);
+ OCStackResult ret = OC_STACK_OK;
+ d2ds_req_cb_s *con = (d2ds_req_cb_s *)data;
- // delete un/owned device lists before updating them
- _d2ds_remove_owned_client();
+ /* delete un/owned device lists before updating them */
+ _remove_owned_client();
- // call |OCDiscoverMultipleOwnedDevices| API actually
- printf(" Discovering Multiple Owned Devices on Network..\n");
- if(OC_STACK_OK != OCDiscoverMultipleOwnedDevices(DISCOVERY_TIMEOUT, &g_mowned_list))
- {
+ D2DS_LOGD(" Discovering Multiple Owned Devices on Network.");
+ ret = OCDiscoverMultipleOwnedDevices(DISCOVERY_TIMEOUT, &g_client->g_mowned_list);
+ if(OC_STACK_OK != ret) {
D2DS_LOGE( "OCDiscoverMultipleOwnerEnabledDevices API error");
- return NULL;
+ goto DISC_OWNED_DEVS_END;
}
- // display the discovered device lists
- printf(" > Discovered Multiple Owned Devices\n");
- g_mowned_cnt = printDevList(g_mowned_list);
+ /* display the discovered device lists */
+ D2DS_LOGD(" > Discovered My Owned Devices\n");
+ g_client->g_mowndev_cnt = _print_dev_list(g_client->g_mowned_list);
- _d2sd_request_cleanup(data);
+DISC_OWNED_DEVS_END:
+ _request_cleanup(data);
+ g_thread_exit(GINT_TO_POINTER (1));
return NULL;
}
-static int _d2ds_disc_owned_devs(d2ds_service *service)
+static int _disc_owned_devs(d2ds_service *service)
{
d2ds_req_cb_s *con = NULL;
con = calloc(1, sizeof(d2ds_req_cb_s));
return D2DS_ERROR_OUT_OF_MEMORY;
}
- con->thread = g_thread_try_new("disc_owned_devs", __d2ds_disc_owned_env_devs_func, con, NULL);
+ con->userdata = service;
+ con->cid = D2DS_DISC_MOWNED_DEVS;
+
+ con->thread = g_thread_try_new("disc_owned_devs", _disc_owned_devs_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);
- con->userdata = service;
- con->cid = D2DS_DISC_MOTED_DEVS;
- con->tid = g_timeout_add_seconds(DISCOVERY_TIMEOUT + 1, _d2ds_timeout_cb, con);
+ //con->tid = g_timeout_add_seconds(DISCOVERY_TIMEOUT + 1, _d2ds_timeout_cb, con);
return D2DS_ERROR_NONE;
}
-// callback function(s) for provisioning client using C-level provisioning API
-static void ___d2ds_mot_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
+static void _mot_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
{
if(!hasError) {
D2DS_LOGD("Multiple Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
} else {
D2DS_LOGD( "Multiple Ownership Transfer FAILED - ctx: %s", (char*) ctx);
- printResultList((const OCProvisionResult_t*) arr, nOfRes);
+ _print_result_list((const OCProvisionResult_t*) arr, nOfRes);
}
- g_doneCB = true;
+ g_client->g_doneCB = true;
}
-static gpointer __d2ds_mot_func(gpointer data)
+static gpointer _mot_func(gpointer data)
{
OCStackResult ret = OC_STACK_OK;
d2ds_req_cb_s *con = (d2ds_req_cb_s *)data;
D2DS_LOGE("Target device is NULL");
return NULL;
}
- // call |getDevInst| API actually
- // calling this API with callback actually acts like blocking
- // for error checking, the return value saved and printed
- g_doneCB = false;
+
+ g_client->g_doneCB = false;
#ifdef MULTIPLE_OWNER
OCProvisionDev_t* dev = NULL;
LL_FOREACH(con->target, dev) {
if(OIC_PRECONFIG_PIN == dev->doxm->oxmSel) {
//Pre-Configured PIN initialization
- const char* testPreconfigPin = con->pin;//"12341234";
+ const char* testPreconfigPin = con->pin;/* Ex) "12341234" */
if(OC_STACK_OK != OCAddPreconfigPin(dev, testPreconfigPin, strlen(testPreconfigPin))) {
D2DS_LOGE("Failed to save the pre-configured PIN");
D2DS_LOGE("You can't use the pre-configured PIN OxM for MOT");
}
}
#endif //MULTIPLE_OWNER
- ret = OCDoMultipleOwnershipTransfer(g_ctx, con->target, ___d2ds_mot_cb);
+ ret = OCDoMultipleOwnershipTransfer(g_client, con->target, _mot_cb);
if(OC_STACK_OK != ret ) {
D2DS_LOGE( "OCDoMultipleOwnershipTransfer: ret=%d", ret);
return NULL;
}
- ret = ___d2d_wait_cb_ret();
+ ret = _wait_cb_ret(CALLBACK_TIMEOUT_MS);
if(ret) {
D2DS_LOGE( "OCProvisionCredentials callback error = %d", ret);
return NULL;
}
- // display the registered result
+ /* display the registered result */
D2DS_LOGE(" > Registered Discovered Devices\n");
- _d2sd_request_cleanup(data);
+ _request_cleanup(data);
return NULL;
}
-OicUuid_t* __d2ds_convert_uuid(const gchar *device_id)
+OicUuid_t* _convert_uuid(const gchar *device_id)
{
OicUuid_t *uuid;
#if 0
D2DS_LOGE("device_id : %s", device_id);
- _d2d_print_uuid(uuid);
+ _print_uuid(uuid);
#endif
return uuid;
}
return D2DS_ERROR_OUT_OF_MEMORY;
}
- uuid = __d2ds_convert_uuid(uuid_str);
- src_dev = _get_dev_by_uuid(g_motdev_list, uuid);
+ uuid = _convert_uuid(uuid_str);
+ src_dev = _get_dev_by_uuid(g_client->g_motdev_list, uuid);
if (!src_dev) {
D2DS_LOGE("We can't find in MOT dev list");
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ g_free(uuid);
+ _request_cleanup(con);
return D2DS_ERROR_NO_DATA;
}
+ g_free(uuid);
/* Copy target device & PIN */
con->target = PMCloneOCProvisionDev(src_dev);
con->pin = calloc(1, OXM_RANDOM_PIN_MAX_SIZE+1);
if (!pin) {
D2DS_LOGE("Failed to allocate PIN number");
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ _request_cleanup(con);
return D2DS_ERROR_OUT_OF_MEMORY;
}
memcpy(con->pin, pin, OXM_RANDOM_PIN_MAX_SIZE);
con->userdata = service;
con->cid = D2DS_MOT;
- con->thread = g_thread_try_new("mot", __d2ds_mot_func, con, NULL);
+ con->thread = g_thread_try_new("mot", _mot_func, con, NULL);
if (!con->thread) {
D2DS_LOGE("Failed to create thread");
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ _request_cleanup(con);
return D2DS_ERROR_OUT_OF_MEMORY;
}
g_thread_unref(con->thread);
- con->tid = g_timeout_add_seconds(DISCOVERY_TIMEOUT + 1, _d2ds_timeout_cb, con);
+ //con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_S + 1, _d2ds_timeout_cb, con);
return D2DS_ERROR_NONE;
}
return 0;
}
-
-static OicSecAcl_t* createAclForLEDAccess(const OicUuid_t* subject)
+#endif /* TEST */
+static OicSecAcl_t* _create_target_acl(const OicUuid_t* target, const OicUuid_t* subject,
+ const char *rsrc_uri, const char *rsrc_type, const char *rsrc_interface, int permission)
{
- if(NULL == subject)
- {
- D2DS_LOGE( "createAcl: Invalid paramters");
+ /* For example
+ * subejct = "12341234-1234-1234-12341234"
+ * rsrc_uri = "/a/led"
+ * rsrc_type = "oic.r.core"
+ * rsrc_interface = "oic.if.baseline"
+ * rsrc_permission = D2DS_PERMISSION_FULL
+ */
+ size_t len;
+ OicSecAcl_t* acl = NULL;
+ OicSecAce_t* ace = NULL;
+ OicSecRsrc_t* rsrc = NULL;
+
+ if(NULL == target) {
+ D2DS_LOGE( "target is NULL");
return NULL;
}
- // allocate memory for |acl| struct
- OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
- if(!acl)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- return NULL; // not need to 'goto' |ERROR| before allocating |acl|
+
+ if(NULL == subject) {
+ D2DS_LOGE( "subejct is NULL");
+ return NULL;
}
- OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
- if(!ace)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- return NULL; // not need to 'goto' |ERROR| before allocating |acl|
+
+ acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
+ if(!acl) {
+ D2DS_LOGE( "acl : OICCalloc failed =%d", errno);
+ return NULL;
+ }
+ ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
+ if(!ace) {
+ D2DS_LOGE( "ace : OICCalloc failed =%d", errno);
+ return NULL;
}
LL_APPEND(acl->aces, ace);
memcpy(ace->subjectuuid.id, subject->id, sizeof(subject->id));
- // fill the href
- char* rsrc_in = "/a/led"; // '1' for null termination
- OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
- if(!rsrc)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- goto CRACL_ERROR;
+ /* fill the href */
+ rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
+ if(!rsrc) {
+ D2DS_LOGE( "rsrc: OICCalloc failed =%d", errno);
+ goto CREATE_ACL_ERROR;
}
- size_t len = strlen(rsrc_in)+1; // '1' for null termination
+ len = strlen(rsrc_uri)+1; // '1' for null termination
rsrc->href = (char*) OICCalloc(len, sizeof(char));
- if(!rsrc->href)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- goto CRACL_ERROR;
+ if(!rsrc->href) {
+ D2DS_LOGE( "rsrc->href: OICStrdup failed =%d", errno);
+ goto CREATE_ACL_ERROR;
}
- OICStrcpy(rsrc->href, len, rsrc_in);
+ OICStrcpy(rsrc->href, len, rsrc_uri);
- //fill the resource type (rt)
+ /* Fill the resource type (rt) */
rsrc->typeLen = 1;
rsrc->types = (char**)OICCalloc(1, sizeof(char*));
- if(!rsrc->types)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- goto CRACL_ERROR;
+ if(!rsrc->types) {
+ D2DS_LOGE( "rsrc->types: OICCalloc failed =%d", errno);
+ goto CREATE_ACL_ERROR;
}
- rsrc->types[0] = OICStrdup("oic.r.core");
- if(!rsrc->types[0])
- {
- D2DS_LOGE( "createAcl: OICStrdup error return");
- goto CRACL_ERROR;
+ rsrc->types[0] = OICStrdup(rsrc_type);
+ if(!rsrc->types[0]) {
+ D2DS_LOGE( "rsrc->types[0]: OICStrdup failed =%d", errno);
+ goto CREATE_ACL_ERROR;
}
- //fill the interface (if)
+ /* Fill the interface (if) */
rsrc->interfaceLen = 1;
rsrc->interfaces = (char**)OICCalloc(1, sizeof(char*));
- if(!rsrc->interfaces)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- goto CRACL_ERROR;
+ if(!rsrc->interfaces) {
+ D2DS_LOGE( "rsrc->interfaces: OICCalloc failed =%d", errno);
+ goto CREATE_ACL_ERROR;
}
- rsrc->interfaces[0] = OICStrdup("oic.if.baseline");
- if(!rsrc->interfaces[0])
- {
- D2DS_LOGE( "createAcl: OICStrdup error return");
- goto CRACL_ERROR;
+ rsrc->interfaces[0] = OICStrdup(rsrc_interface);
+ if(!rsrc->interfaces[0]) {
+ D2DS_LOGE( "rsrc->interfaces[0] : OICStrdup failed =%d", errno);
+ goto CREATE_ACL_ERROR;
}
LL_APPEND(ace->resources, rsrc);
- // full permission for /a/led
- ace->permission = PERMISSION_FULL_CONTROL;
+ /* Fill permission for the reource */
+ ace->permission = permission;
ace->eownerID = (OicUuid_t*)OICCalloc(1, sizeof(OicUuid_t));
- if(NULL == ace->eownerID)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- goto CRACL_ERROR;
+ if(NULL == ace->eownerID) {
+ D2DS_LOGE( "ace->eownerID : OICCalloc failed =%d", errno);
+ goto CREATE_ACL_ERROR;
}
-
memcpy(ace->eownerID->id, subject->id, sizeof(subject->id));
return acl;
-CRACL_ERROR:
- OCDeleteACLList(acl); // after here |acl| points nothing
+CREATE_ACL_ERROR:
+ OCDeleteACLList(acl);
return NULL;
}
-static int provisionAclForLed()
+static void _provisioning_acl_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
{
- OicSecAcl_t* acl = NULL;
-
- // check |own_list| for provisioning access control list
- if(!g_mowned_list || 1> g_mowned_cnt)
- {
- printf(" > MOT Device List is Empty\n");
- printf(" > Please Perform MOT first, with [12|21] Menu\n");
- return 0; // normal case
+ if(!hasError) {
+ D2DS_LOGD( "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
+ } else {
+ D2DS_LOGD( "Provision ACL FAILED - ctx: %s", (char*) ctx);
+ _print_result_list((const OCProvisionResult_t*) arr, nOfRes);
}
+ g_client->g_doneCB = true;
+}
- // display the MOT dev list
- printf(" > MOT Devices\n");
- g_mowned_cnt = printDevList(g_mowned_list);
+static gpointer _provisioning_acl_func(gpointer data)
+{
+ OCStackResult ret = OC_STACK_OK;
+ d2ds_req_cb_s *con = (d2ds_req_cb_s *)data;
+ OicSecAcl_t* acl = NULL;
- // select device for provisioning access control list
- int dev_num = 0;
- for( ; ; )
- {
- printf(" > Enter Device Number, for Provisioning LED's ACL: ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%d", &dev_num);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<dev_num && g_mowned_list>=dev_num)
- {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
+ if(!con->subject || !con->rsrc_uri || !con->rsrc_type || !con->rsrc_interface) {
+ D2DS_LOGE("Some parameters are wrong");
+ D2DS_LOGE("%p", con->subject );
+ D2DS_LOGE("%s", con->rsrc_uri );
+ D2DS_LOGE("%s", con->rsrc_type );
+ D2DS_LOGE("%s", con->rsrc_interface );
+ return NULL;
}
- g_doneCB = false;
- printf(" Provisioning Selected ACL..\n");
- OCProvisionDev_t* dev = _get_dev_by_id((const OCProvisionDev_t*) g_mowned_list, dev_num);
- if(!dev)
- {
- D2DS_LOGE( "provisionAcl: device instance empty");
- goto PVACL_ERROR;
- }
+ g_client->g_doneCB = false;
+ D2DS_LOGI(" Provisioning Selected ACL..");
- acl = createAclForLEDAccess(&dev->doxm->subOwners->uuid);
- if(NULL == acl)
- {
- D2DS_LOGE( "provisionAcl: Failed to create ACL for LED");
- return -1;
+ acl = _create_target_acl(&con->target->doxm->deviceID, &con->subject->doxm->deviceID, con->rsrc_uri, con->rsrc_type,
+ con->rsrc_interface, con->permission);
+ if(NULL == acl) {
+ D2DS_LOGE( "Failed to create ACL for %s", con->rsrc_uri);
+ goto PVACL_ERROR;
}
- OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
- if(OC_STACK_OK != rst)
- {
- D2DS_LOGD( "OCProvisionACL API error: %d", rst);
+ ret= OCProvisionACL((void*) g_client, con->subject, acl, _provisioning_acl_cb);
+ if(OC_STACK_OK != ret) {
+ D2DS_LOGD( "OCProvisionACL API error: %d", ret);
goto PVACL_ERROR;
}
- if(waitCallbackRet()) // input |g_doneCB| flag implicitly
- {
- D2DS_LOGE( "OCProvisionCredentials callback error");
+
+ ret = _wait_cb_ret(CALLBACK_TIMEOUT_MS * 2);
+ if(ret) {
+ D2DS_LOGE( "OCProvisionCredentials Faild = %d", errno);
goto PVACL_ERROR;
}
- // display the ACL-provisioned result
- printf(" > Provisioned Selected ACL\n");
-
- OCDeleteACLList(acl); // after here |acl| points nothing
- return 0;
+ /* display the ACL-provisioned result */
+ D2DS_LOGI(" -> Provisioned Selected ACL Successfully");
PVACL_ERROR:
- OCDeleteACLList(acl);
- return -1;
+ if (acl) {
+ OCDeleteACLList(acl);
+ acl = NULL;
+ }
+ _request_cleanup(con);
+ g_thread_exit(GINT_TO_POINTER (1));
+ return NULL;
}
-static int provisionCred()
+static int _provisioning_acl(d2ds_service *service, gchar *target, gchar *subject,
+ gchar *rsrc_uri, gchar *rsrc_type, gchar *rsrc_interface, int permission)
{
- // check |unown_list| for registering devices
- if(!g_mowned_list|| 0 >=g_mowned_cnt)
- {
- printf(" > Multiple Owned Device List is Empty\n");
- printf(" > Please Discover Devices first, with [13] Menu\n");
- return 0; // normal case
+
+ OicUuid_t *uuid = NULL;
+ OCProvisionDev_t *target_dev = NULL;
+ OCProvisionDev_t *subject_dev = NULL;
+
+ d2ds_req_cb_s *con = NULL;
+ con = calloc(1, sizeof(d2ds_req_cb_s));
+ if (NULL == con) {
+ D2DS_LOGE( "calloc() Fail=%d", errno);
+ /* Unset d2ds status 'pending' */
+ g_atomic_int_set(&service->pending, 0);
+ return D2DS_ERROR_OUT_OF_MEMORY;
}
- // display the MOT dev list
- printf(" > Multiple Owned Devices\n");
- g_mowned_cnt = printDevList(g_mowned_list);
+ 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);
- int dev_num = 0;
- for( ; ; )
- {
- printf(" > Enter Multiple Owned Device Number to link : ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%d", &dev_num);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<dev_num && g_mowned_cnt>=dev_num)
- {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
+ /* Copy subject device and related information */
+ con->target = PMCloneOCProvisionDev(target_dev);
+ /* To do ACL provisioning only one */
+ con->target->next = NULL;
+
+ uuid = _convert_uuid(subject);
+ subject_dev = _get_dev_by_uuid(g_client->g_mowned_list, uuid);
+ if (!subject_dev) {
+ D2DS_LOGE("We can't find subject in MOWNED dev list");
+ _request_cleanup(con);
+ return D2DS_ERROR_NO_DATA;
}
+ g_free(uuid);
- OCProvisionDev_t* motDev = _get_dev_by_id(g_mowned_list, dev_num);
- if(NULL == motDev)
- {
- D2DS_LOGE( "Failed to _get_dev_by_id()");
- return -1;
+ /* Copy subject device and related information */
+ con->subject = PMCloneOCProvisionDev(subject_dev);
+ /* To do ACL provisioning only one */
+ con->subject->next = NULL;
+
+ con->rsrc_uri = OICStrdup(rsrc_uri);
+ con->rsrc_type = OICStrdup(rsrc_type);
+ con->rsrc_interface = OICStrdup(rsrc_interface);
+ con->userdata = service;
+ con->cid = D2DS_PROV_ACL;
+
+ con->thread = g_thread_try_new("prov_acl", _provisioning_acl_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);
- // display the MOT dev list
- printf(" > Owned Devices\n");
- g_own_cnt = printDevList(g_own_list);
+ //con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_S + 1, _d2ds_timeout_cb, con);
- for( ; ; )
- {
- printf(" > Enter Owned Device Number to link : ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%d", &dev_num);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<dev_num && g_own_cnt>=dev_num)
- {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
+ return D2DS_ERROR_NONE;
+}
+
+static void _provision_cred_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
+{
+ if(!hasError) {
+ D2DS_LOGD("Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
+ } else {
+ D2DS_LOGD("Provision Credential FAILED - ctx: %s", (char*) ctx);
+ _print_result_list((const OCProvisionResult_t*) arr, nOfRes);
}
+ g_client->g_doneCB = true;
+}
- OCProvisionDev_t* ownDev = _get_dev_by_id(g_own_list, dev_num);
- if(NULL == ownDev)
- {
- D2DS_LOGE( "Failed to _get_dev_by_id()");
- return -1;
+static gpointer _cred_provisioning_func(gpointer data)
+{
+ OCStackResult ret = OC_STACK_OK;
+ d2ds_req_cb_s *con = (d2ds_req_cb_s *)data;
+
+ if(!con->target ) {
+ D2DS_LOGE("Target device is NULL");
+ return NULL;
}
- // call |OCProvisionCredentials| API actually
- // calling this API with callback actually acts like blocking
- // for error checking, the return value saved and printed
- g_doneCB = false;
- printf(" Provisioning Selected Pairwise Devices..\n");
- OCStackResult rst = OCProvisionCredentials((void*) g_ctx,
+ g_client->g_doneCB = false;
+
+ D2DS_LOGI(" Provisioning Selected Pairwise Devices..");
+ OCStackResult rst = OCProvisionCredentials((void*) g_client,
SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
- ownDev, motDev, provisionCredCB);
- if(OC_STACK_OK != rst)
- {
+ con->dev1, con->dev2, _provision_cred_cb);
+ if (OC_STACK_OK != rst) {
D2DS_LOGD( "OCProvisionPairwiseDevices API error: %d", rst);
goto PVPWS_ERROR;
}
- if(waitCallbackRet()) // input |g_doneCB| flag implicitly
- {
- D2DS_LOGE( "OCProvisionCredentials callback error");
+
+ ret = _wait_cb_ret(CALLBACK_TIMEOUT_MS);
+ if (ret) {
+ D2DS_LOGE( "OCProvisionCredentials Faild = %d", errno);
goto PVPWS_ERROR;
}
- // display the pairwise-provisioned result
- printf(" > Provisioned Selected Pairwise Devices\n");
+ /* display the pairwise-provisioned result */
+ D2DS_LOGI(" > Provisioned Selected Pairwise Devices");
return 0;
PVPWS_ERROR:
- return -1;
+ _request_cleanup(con);
+ g_thread_exit(GINT_TO_POINTER (1));
+
+ return NULL;
}
-#endif /* TEST */
+
+static int _d2ds_provisioning_cred(d2ds_service *service,
+ gchar *uuid_dev1, gchar *uuid_dev2)
+{
+
+ OicUuid_t *uuid = NULL;
+ OCProvisionDev_t *dev1 = NULL;
+ OCProvisionDev_t *dev2 = NULL;
+
+ d2ds_req_cb_s *con = NULL;
+ con = calloc(1, sizeof(d2ds_req_cb_s));
+ if (!con) {
+ D2DS_LOGE( "calloc() Fail=%d", errno);
+ /* Unset d2ds status 'pending' */
+ g_atomic_int_set(&service->pending, 0);
+ return D2DS_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (!uuid_dev1 ||!uuid_dev2) {
+ D2DS_LOGE( "Invaild Prameters");
+ _request_cleanup(con);
+ return D2DS_ERROR_INVALID_PARAMETER;
+ }
+
+ uuid = _convert_uuid(uuid_dev1);
+ dev1 = _get_dev_by_uuid(g_client->g_mowned_list, uuid);
+ if (!dev1) {
+ D2DS_LOGE("We can't find in MOWNED dev list");
+ g_free(uuid);
+ _request_cleanup(con);
+ return D2DS_ERROR_NO_DATA;
+ }
+ g_free(uuid);
+
+ uuid = _convert_uuid(uuid_dev2);
+ dev2 = _get_dev_by_uuid(g_client->g_mowned_list, uuid);
+ if (!dev2) {
+ D2DS_LOGE("We can't find in MOWNED dev list");
+ g_free(uuid);
+ _request_cleanup(con);
+ return D2DS_ERROR_NO_DATA;
+ }
+ g_free(uuid);
+
+ /* Copy subject device and related information */
+ con->dev1 = PMCloneOCProvisionDev(dev1);
+ /* To do ACL provisioning only one */
+ con->dev1->next = NULL;
+
+ con->dev2 = PMCloneOCProvisionDev(dev2);
+ /* To do ACL provisioning only one */
+ con->dev2->next = NULL;
+
+ con->userdata = service;
+ con->cid = D2DS_PROV_CRED;
+
+ con->thread = g_thread_try_new("prov_cred", _cred_provisioning_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);
+
+ //con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_S + 1, _d2ds_timeout_cb, con);
+
+ return D2DS_ERROR_NONE;
+}
+
int d2ds_request_enable(d2ds_service *service)
{
int ret = D2DS_ERROR_NONE;
d2ds_check_null_ret_error("service", service, FALSE);
- ret = d2ds_init_provision_client();
+ ret = _init_provision_client();
return ret;
}
/* Set d2ds status 'pending' */
g_atomic_int_set(&service->pending, 1);
-#ifdef TIMER_TEST
- ret = _d2ds_disc_mot_enb_devs_timer(service);
-#else
- ret = _d2ds_disc_mot_enb_devs_thd(service);
-#endif
+ ret = _disc_mot_enb_devs(service);
+
return ret;
}
/* Set d2ds status 'pending' */
g_atomic_int_set(&service->pending, 1);
- ret = _d2ds_disc_owned_devs(service);
+ ret = _disc_owned_devs(service);
return ret;
}
-int d2ds_request_mot(d2ds_service *service, gchar* uuid, gchar *pin)
+int d2ds_request_mot(d2ds_service *service, gchar* uuid_str, gchar *pin)
{
int ret =D2DS_ERROR_NONE;
if (g_atomic_int_get(&service->pending))
return D2DS_ERROR_IN_PROGRESS;
- if (!uuid || !pin)
+ if (!uuid_str || !pin) {
+ D2DS_LOGE("uuid_str = %s", uuid_str);
+ D2DS_LOGE("pin = %s", pin);
return D2DS_ERROR_INVALID_PARAMETER;
+ }
/* Set d2ds status 'pending' */
g_atomic_int_set(&service->pending, 1);
- ret = _d2ds_mot(service, uuid, pin);
+ ret = _d2ds_mot(service, uuid_str, pin);
return ret;
}
-int d2ds_request_disable(d2ds_service *service)
+int d2ds_request_prov_acl(d2ds_service *service, gchar *target, gchar *subject,
+ gchar *rsrc_uri, gchar *rsrc_type, gchar *rsrc_interface, int permission)
{
+ int ret =D2DS_ERROR_NONE;
+
d2ds_check_null_ret_error("service", service, FALSE);
- if(OC_STACK_OK != OCStop()) {
- D2DS_LOGE( "OCStack stop error");
- }
- OCDeleteDiscoveredDevices(g_own_list); // after here |g_own_list| points nothing
- OCDeleteDiscoveredDevices(g_unown_list); // after here |g_unown_list| points nothing
- OCDeleteDiscoveredDevices(g_motdev_list); // after here |g_motdev_list| points nothing
- if(g_svr_fname) {
- OICFree(g_svr_fname); // after here |g_svr_fname| points nothing
+ D2DS_LOGD("[IPC] Provisioning ACL");
+
+ /* If we are working now? */
+ if (g_atomic_int_get(&service->pending))
+ return D2DS_ERROR_IN_PROGRESS;
+
+ if (!target || !subject || !rsrc_uri || !rsrc_type || !rsrc_interface) {
+ D2DS_LOGE("target = %s", target);
+ D2DS_LOGE("subject = %s", subject);
+ D2DS_LOGE("rsrc_uri = %s", rsrc_uri);
+ D2DS_LOGE("rsrc_type = %s", rsrc_type);
+ D2DS_LOGE("rsrc_interface = %s", rsrc_interface);
+ return D2DS_ERROR_INVALID_PARAMETER;
}
- if(g_prvn_fname) {
- OICFree(g_prvn_fname); // after here |g_prvn_fname| points nothing
+
+ /* Set d2ds status 'pending' */
+ g_atomic_int_set(&service->pending, 1);
+
+ ret = _provisioning_acl(service, target, subject, rsrc_uri, rsrc_type, rsrc_interface, permission);
+
+ return ret;
+}
+
+int d2ds_request_prov_cred(d2ds_service *service, gchar *uuid_dev1, gchar *uuid_dev2)
+{
+ int ret =D2DS_ERROR_NONE;
+
+ d2ds_check_null_ret_error("service", service, FALSE);
+
+ D2DS_LOGD("[IPC] Provisioning Credential");
+
+ /* If we are working now? */
+ if (g_atomic_int_get(&service->pending))
+ return D2DS_ERROR_IN_PROGRESS;
+
+ if (!uuid_dev1 || !uuid_dev2) {
+ D2DS_LOGE("uuid_dev1 = %s", uuid_dev1);
+ D2DS_LOGE("uuid_dev2 = %s", uuid_dev2);
+ return D2DS_ERROR_INVALID_PARAMETER;
}
- return D2DS_ERROR_NONE;
+ /* Set d2ds status 'pending' */
+ g_atomic_int_set(&service->pending, 1);
+
+ ret = _d2ds_provisioning_cred(service, uuid_dev1, uuid_dev2);
+
+ return ret;
}
-#if 0
-// main function for provisioning client using C-level provisioning API
-int main()
+int d2ds_request_disable(d2ds_service *service)
{
- // initialize provisioning client
- if(initProvisionClient())
- {
- D2DS_LOGE( "ProvisionClient init error");
- goto PMCLT_ERROR;
- }
-
- // main loop for provisioning manager
- int mnNum = 0;
- int selDevNum = 0;
- for( ; ; )
- {
- printf("\n");
- printMenu();
- printf(">> Enter Menu Number: ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%d", &mnNum);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- printf("\n");
- switch(mnNum)
- {
- case _10_DISCOV_MOT_ENABLED_DEV_:
- if(discoverMotSupportedDevices())
- {
- D2DS_LOGE( "_12_MOT_DISCOV_DEV_: error");
- }
- break;
- case _11_DISCOV_MULTIPLE_OWNED_DEV_:
- if(discoverSubOwnerDevices())
- {
- D2DS_LOGE( "_13_DISCOV_MULTIPLE_OWNED_DEV_: error");
- }
- break;
- case _20_PERFORM_MOT_:
- if(multipleOwnershipTransfer())
- {
- D2DS_LOGE( "_21_PERFORM_MOT_: error");
- }
- break;
- case _30_GET_LED_RESOURCE_:
- if(sendGetLed())
- {
- D2DS_LOGE( "_30_GET_LED_RESOURCE_: error");
- }
- break;
- case _31_PUT_LED_RESOURCE_:
- if(sendPutLed())
- {
- D2DS_LOGE( "_31_PUT_LED_RESOURCE_: error");
- }
- break;
- case _40_PROVISION_ACL_:
- if(provisionAclForLed())
- {
- D2DS_LOGE( "_40_PROVISION_ACL_: error");
- }
- break;
- case _41_PROVISION_CRED_:
- D2DS_LOGE( "NOT SUPPORTED YET.");
- break;
- /*
- if(provisionCred())
- {
- D2D_LOGE( "_41_PROVISION_CRED_: error");
- }
- break;
- */
- case _99_EXIT_PRVN_CLT_:
- goto PMCLT_ERROR;
- default:
- printf(">> Entered Wrong Number. Please Enter Again\n\n");
- break;
- }
- }
-
-PMCLT_ERROR:
- if(OC_STACK_OK != OCStop())
- {
- //D2D_LOGE( "OCStack stop error");
- }
- OCDeleteDiscoveredDevices(g_own_list); // after here |g_own_list| points nothing
- OCDeleteDiscoveredDevices(g_unown_list); // after here |g_unown_list| points nothing
- OCDeleteDiscoveredDevices(g_motdev_list); // after here |g_motdev_list| points nothing
-
- if(g_svr_fname)
- {
- OICFree(g_svr_fname); // after here |g_svr_fname| points nothing
- }
- if(g_prvn_fname)
- {
- OICFree(g_prvn_fname); // after here |g_prvn_fname| points nothing
- }
- return 0; // always return normal case
+ NOTUSED(service);
+
+ if(OC_STACK_OK != OCStop()) {
+ D2DS_LOGE( "OCStack stop error");
+ }
+
+ OCDeleteDiscoveredDevices(g_client->g_mowned_list);
+ OCDeleteDiscoveredDevices(g_client->g_motdev_list);
+
+ if (g_client->rnd_pin) {
+ g_free(g_client->rnd_pin);
+ g_client->rnd_pin = NULL;
+ }
+ g_free(g_client);
+ g_client = NULL;
+
+ return D2DS_ERROR_NONE;
}
-#endif