#include <srmutility.h>
#include <securevirtualresourcetypes.h>
#include <security/srmutility.h>
-#include <pmtypes.h>
-#include <pmutility.h>
-
-#include <wifi-manager.h>
-#include <tzplatform_config.h>
#include "ma.h"
#include "ma-log.h"
#include "ma-generated-code.h"
#include "ma-db.h"
-#define WIFI_MAC_ADDR_LENGTH 17
-
-#define MAX_FILE_PATH_LEN 1024
-#define ACL_RESRC_MAX_LEN 128
-
-/*This value is used only for sample (not OCF spec) */
-#define ACL_RESRC_ARRAY_SIZE 3
+#define MAX_FILE_PATH_LEN 1024 /**< Max. file path length */
+#define ACL_RESRC_MAX_LEN 128 /**< '128' is ACL_RESRC_MAX_LEN */
+#define ACL_RESRC_ARRAY_SIZE 3 /**< This value is used only for sample (not OCF spec) */
#define DISCOVERY_TIMEOUT 6 /**< 6 sec */
#define CALLBACK_TIMEOUT_10S 10 * 1000 /**< 10 sec = 10 * 1000 * 1ms */
#define CALLBACK_TIMEOUT_5S 5 * 1000 /**< 5sec = 5 * 1000 * 1ms */
-//#define TIMEOUT_USED
-#define DEBUG_UUID
-
/* '_' for separaing from the same constant variable in srmresourcestrings.c */
static const char* SVR_DB_FILE_NAME = "oic_svr_db_ma.dat";
static const char* PRVN_DB_FILE_NAME = "oic_pdm_ma.db";
static const OicSecPrm_t SUPPORTED_PRMS[2] = { PRM_PRE_CONFIGURED, PRM_RANDOM_PIN };
#endif
+/**< GetDoxmDevOwnerId() is IoTivity function */
OCStackResult GetDoxmDevOwnerId(OicUuid_t *devownerid);
typedef struct {
int permission;/**< Permision */
/* For CRED provisioning */
- gchar *uuid_dev1; /**< 1st device for CRED provisiong */
- gchar *uuid_dev2; /**< 2nd device for CRED provisiong */
+ gchar *uuid_dev1; /**< 1st device for CRED provisiong */
+ gchar *uuid_dev2; /**< 2nd device for CRED provisiong */
/* For Pairwaise linking */
gchar *target_1; /**< Target device 1*/
} ma_req_cb_s;
typedef struct _ma_subowner {
+ GThread *thread; /**< Worker Thread */
+ GAsyncQueue *queue; /**< Async Queue to be handled */
+ gint pending; /**< Is there any pending operation? */
+
OCProvisionDev_t* g_motdev_list; /**< Discoverd MOT enabled devices list */
OCProvisionDev_t* g_mowned_list; /**< My owned MOT enabled devices list */
char *rnd_pin; /**< Random PIN */
int rnd_pin_len; /**< Random PIN length */
-
} ma_subowner_s;
-ma_subowner_s *g_client;
-GMutex iotivity_mutex;
-
-#define CASE_TO_STR(x) case x: return #x;
-const char* _error_to_string(OCStackResult err)
-{
- switch (err) {
- /* CHECK: List all enum values here */
- CASE_TO_STR(OC_STACK_OK)
- CASE_TO_STR(OC_STACK_RESOURCE_CREATED)
- CASE_TO_STR(OC_STACK_RESOURCE_DELETED)
- CASE_TO_STR(OC_STACK_CONTINUE)
- CASE_TO_STR(OC_STACK_RESOURCE_CHANGED)
- CASE_TO_STR(OC_STACK_INVALID_URI)
- CASE_TO_STR(OC_STACK_INVALID_QUERY)
- CASE_TO_STR(OC_STACK_INVALID_IP)
- CASE_TO_STR(OC_STACK_INVALID_PORT)
- CASE_TO_STR(OC_STACK_INVALID_CALLBACK)
- CASE_TO_STR(OC_STACK_INVALID_METHOD)
- CASE_TO_STR(OC_STACK_INVALID_PARAM)
- CASE_TO_STR(OC_STACK_INVALID_OBSERVE_PARAM)
-
- CASE_TO_STR(OC_STACK_NO_MEMORY)
- CASE_TO_STR(OC_STACK_COMM_ERROR)
- CASE_TO_STR(OC_STACK_TIMEOUT)
- CASE_TO_STR(OC_STACK_ADAPTER_NOT_ENABLED)
- CASE_TO_STR(OC_STACK_NOTIMPL)
- CASE_TO_STR(OC_STACK_RESOURCE_ERROR)
- CASE_TO_STR(OC_STACK_SLOW_RESOURCE)
- CASE_TO_STR(OC_STACK_DUPLICATE_REQUEST)
- CASE_TO_STR(OC_STACK_OBSERVER_NOT_FOUND)
- CASE_TO_STR(OC_STACK_VIRTUAL_DO_NOT_HANDLE)
- CASE_TO_STR(OC_STACK_INVALID_OPTION)
- CASE_TO_STR(OC_STACK_MALFORMED_RESPONSE)
- CASE_TO_STR(OC_STACK_PERSISTENT_BUFFER_REQUIRED)
-
- CASE_TO_STR(OC_STACK_INVALID_REQUEST_HANDLE)
- CASE_TO_STR(OC_STACK_INVALID_DEVICE_INFO)
- CASE_TO_STR(OC_STACK_INVALID_JSON)
- CASE_TO_STR(OC_STACK_UNAUTHORIZED_REQ)
- CASE_TO_STR(OC_STACK_TOO_LARGE_REQ)
- CASE_TO_STR(OC_STACK_PDM_IS_NOT_INITIALIZED)
- CASE_TO_STR(OC_STACK_DUPLICATE_UUID)
- CASE_TO_STR(OC_STACK_INCONSISTENT_DB)
- CASE_TO_STR(OC_STACK_SVR_DB_NOT_EXIST)
- CASE_TO_STR(OC_STACK_AUTHENTICATION_FAILURE)
- CASE_TO_STR(OC_STACK_NOT_ALLOWED_OXM)
-#ifdef WITH_PRESENCE
- CASE_TO_STR(OC_STACK_PRESENCE_STOPPED)
- CASE_TO_STR(OC_STACK_PRESENCE_TIMEOUT)
- CASE_TO_STR(OC_STACK_PRESENCE_DO_NOT_HANDLE)
-#endif
- CASE_TO_STR(OC_STACK_USER_DENIED_REQ)
- CASE_TO_STR(OC_STACK_NOT_ACCEPTABLE)
- CASE_TO_STR(OC_STACK_METHOD_NOT_ALLOWED)
- CASE_TO_STR(OC_STACK_FORBIDDEN_REQ)
- CASE_TO_STR(OC_STACK_INTERNAL_SERVER_ERROR)
- CASE_TO_STR(OC_STACK_NOT_IMPLEMENTED)
- CASE_TO_STR(OC_STACK_BAD_GATEWAY)
- CASE_TO_STR(OC_STACK_SERVICE_UNAVAILABLE)
- CASE_TO_STR(OC_STACK_GATEWAY_TIMEOUT)
- CASE_TO_STR(OC_STACK_PROXY_NOT_SUPPORTED)
- CASE_TO_STR(OC_STACK_ERROR)
- default :
- return "Unknown Error";
- }
-}
-
-static const char* _wifi_error_to_string(wifi_manager_error_e err)
-{
- switch (err) {
- /* CHECK: List all enum values here */
- CASE_TO_STR(WIFI_MANAGER_ERROR_NONE)
- CASE_TO_STR(WIFI_MANAGER_ERROR_INVALID_PARAMETER)
- CASE_TO_STR(WIFI_MANAGER_ERROR_OUT_OF_MEMORY)
- CASE_TO_STR(WIFI_MANAGER_ERROR_INVALID_OPERATION)
- CASE_TO_STR(WIFI_MANAGER_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED)
- CASE_TO_STR(WIFI_MANAGER_ERROR_OPERATION_FAILED)
- CASE_TO_STR(WIFI_MANAGER_ERROR_NO_CONNECTION)
- CASE_TO_STR(WIFI_MANAGER_ERROR_NOW_IN_PROGRESS)
- CASE_TO_STR(WIFI_MANAGER_ERROR_ALREADY_EXISTS)
- CASE_TO_STR(WIFI_MANAGER_ERROR_OPERATION_ABORTED)
- CASE_TO_STR(WIFI_MANAGER_ERROR_DHCP_FAILED)
- CASE_TO_STR(WIFI_MANAGER_ERROR_INVALID_KEY)
- CASE_TO_STR(WIFI_MANAGER_ERROR_NO_REPLY)
- CASE_TO_STR(WIFI_MANAGER_ERROR_SECURITY_RESTRICTED)
- CASE_TO_STR(WIFI_MANAGER_ERROR_ALREADY_INITIALIZED)
- CASE_TO_STR(WIFI_MANAGER_ERROR_PERMISSION_DENIED)
- CASE_TO_STR(WIFI_MANAGER_ERROR_NOT_SUPPORTED)
- default :
- return "WIFI_MANAGER_ERROR_UNKNOWN";
- }
-}
-
-OicUuid_t* _convert_uuid(gchar *device_id)
-{
- OicUuid_t *uuid;
-
- if (NULL == device_id)
- return NULL;
-
- uuid = g_malloc0(sizeof(struct OicUuid));
- if (NULL == uuid) {
- MA_LOGE("g_malloc0() Fail(%d)", errno);
- return NULL;
- }
-
- sscanf(&device_id[0], "%2hhx", &uuid->id[0]);
- sscanf(&device_id[2], "%2hhx", &uuid->id[1]);
- sscanf(&device_id[4], "%2hhx", &uuid->id[2]);
- sscanf(&device_id[6], "%2hhx", &uuid->id[3]);
- /* device_id[8] == '-' */
- sscanf(&device_id[9], "%2hhx", &uuid->id[4]);
- sscanf(&device_id[11], "%2hhx", &uuid->id[5]);
- /* device_id[13] == '-' */
- sscanf(&device_id[14], "%2hhx", &uuid->id[6]);
- sscanf(&device_id[16], "%2hhx", &uuid->id[7]);
- /* device_id[18] == '-' */
- sscanf(&device_id[19], "%2hhx", &uuid->id[8]);
- sscanf(&device_id[21], "%2hhx", &uuid->id[9]);
- /* device_id[23] == '-' */
- sscanf(&device_id[24], "%2hhx", &uuid->id[10]);
- sscanf(&device_id[26], "%2hhx", &uuid->id[11]);
- sscanf(&device_id[28], "%2hhx", &uuid->id[12]);
- sscanf(&device_id[30], "%2hhx", &uuid->id[13]);
- sscanf(&device_id[32], "%2hhx", &uuid->id[14]);
- sscanf(&device_id[34], "%2hhx", &uuid->id[15]);
-
- return uuid;
-}
-
-char g_uuid_str[256] = {0};
-static char * _get_readable_uuid(const OicUuid_t* uuid)
-{
- memset(g_uuid_str, 0, sizeof(g_uuid_str));
- snprintf(g_uuid_str, sizeof(g_uuid_str),
- "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- (*uuid).id[0], (*uuid).id[1], (*uuid).id[2], (*uuid).id[3],
- (*uuid).id[4], (*uuid).id[5], (*uuid).id[6], (*uuid).id[7],
- (*uuid).id[8], (*uuid).id[9], (*uuid).id[10], (*uuid).id[11],
- (*uuid).id[12], (*uuid).id[13], (*uuid).id[14], (*uuid).id[15]);
- return g_uuid_str;
-}
-
-#ifdef TEST
-static OCProvisionDev_t* _get_dev_by_id(const OCProvisionDev_t* dev_lst, const int dev_num)
-{
- if (!dev_lst || 0>=dev_num) {
- MA_LOGI("Device List is Empty..\n");
- return NULL;
- }
-
- OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
- for (int i=0; lst; ) {
- if (dev_num == ++i) {
- return lst;
- }
- lst = lst->next;
- }
-
- return NULL;
-}
-#endif
-
-static OCProvisionDev_t* _get_dev_by_uuid(const OCProvisionDev_t* dev_lst,
- const OicUuid_t* uuid)
-{
- if (!dev_lst ) {
- MA_LOGI("dev_lst is empty");
- return NULL;
- }
-
- if (!uuid ) {
- MA_LOGI("uuid is NULL");
- return NULL;
- }
-
-#ifdef DEBUG_UUID
- MA_LOGD("[T] : %s", _get_readable_uuid(uuid));
-#endif
- OCProvisionDev_t* lst = (OCProvisionDev_t*)dev_lst;
- while (lst) {
-#ifdef DEBUG_UUID
- MA_LOGD("[C] : %s", _get_readable_uuid(&lst->doxm->deviceID));
-#endif
- if (!memcmp((const void *)&lst->doxm->deviceID, (const void *)uuid, sizeof(OicUuid_t))) {
- MA_LOGD("[M] : %s", _get_readable_uuid(&lst->doxm->deviceID));
- return lst;
- }
- lst = lst->next;
- }
-
- return NULL;
-}
-
-static int _print_dev_list(const OCProvisionDev_t* dev_lst)
-{
- if (!dev_lst) {
- MA_LOGI("Device List is Empty..\n\n");
- return 0;
- }
-
- OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
- int lst_cnt = 0;
- for ( ; lst; ) {
- MA_LOGI("[%d] %s", ++lst_cnt, _get_readable_uuid((const OicUuid_t*) &lst->doxm->deviceID));
- lst = lst->next;
- }
-
- return lst_cnt;
-}
-
-static int _print_result_list(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
-{
- if (!rslt_lst || 0>=rslt_cnt) {
- MA_LOGI(" Device List is Empty..\n\n");
- return 0;
- }
-
- int lst_cnt = 0;
- for ( ; rslt_cnt>lst_cnt; ++lst_cnt) {
- MA_LOGD("%s : [%d][%s]",
- _get_readable_uuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId),
- rslt_lst[lst_cnt].res, _error_to_string(rslt_lst[lst_cnt].res));
- }
-
- return lst_cnt;
-}
-
-static FILE* _fopen_prvn_mng(const char* path, const char* mode)
-{
- char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
- snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
- "/opt/usr/data", SVR_DB_FILE_NAME);
-
- NOTUSED(path);
-#if 0
- MA_LOGD("Unsed DB path %s\n", path);
-#endif
-
- return fopen(data_dir, mode);
-}
-
-#if 0
-static OCProvisionDev_t* _clone_ocprovision_dev(const OCProvisionDev_t* src)
-{
- MA_LOGD("");
-
- if (!src)
- {
- MA_LOGD("Invalid parameter");
- return NULL;
- }
-
- OCProvisionDev_t* newDev = g_try_malloc0(sizeof(OCProvisionDev_t));
-
- memcpy(&newDev->endpoint, &src->endpoint, sizeof(OCDevAddr));
-
- if (src->pstat)
- {
- newDev->pstat= g_try_malloc0(sizeof(OicSecPstat_t));
-
- memcpy(newDev->pstat, src->pstat, sizeof(OicSecPstat_t));
- // We have to assign NULL for not necessary information to prevent memory corruption.
- newDev->pstat->sm = g_try_malloc0(sizeof(OicSecDpom_t));
- memcpy(newDev->pstat->sm, src->pstat->sm, sizeof(OicSecDpom_t));
- }
-
- if (src->doxm)
- {
- newDev->doxm = g_try_malloc0(sizeof(OicSecDoxm_t));
-
- memcpy(newDev->doxm, src->doxm, sizeof(OicSecDoxm_t));
-
- newDev->doxm->oxmType = g_try_malloc0(src->doxm->oxmTypeLen + 1);
- memcpy(newDev->doxm->oxmType, src->doxm->oxmType,
- src->doxm->oxmTypeLen);
-
- newDev->doxm->oxm = g_try_malloc0(sizeof(OicSecOxm_t));
- memcpy(newDev->doxm->oxm, src->doxm->oxm, sizeof(OicSecOxm_t));
-
- newDev->doxm->mom = g_try_malloc0(sizeof(OicSecMom_t));
- memcpy(newDev->doxm->mom, src->doxm->mom, sizeof(OicSecMom_t));
-
- if (src->doxm->subOwners) {
- int count = 0;
- OicSecSubOwner_t* subowner = NULL;
- OicSecSubOwner_t* temp = NULL;
- OicSecSubOwner_t* temp2 = NULL;
- OicSecSubOwner_t* temp3 = NULL;
- LL_FOREACH_SAFE(src->doxm->subOwners, subowner, temp) {
- temp2 = g_try_malloc0(sizeof(OicSecSubOwner_t));
- temp3 = subowner;
- temp3->next = NULL;
- memcpy(temp2, temp3, sizeof(OicSecSubOwner_t));
- LL_PREPEND(newDev->doxm->subOwners, temp2);
- }
- LL_COUNT(newDev->doxm->subOwners, subowner, count);
- MA_LOGD("newdev subowner count %d", count);
- }
- }
-
- if (0 == strlen(src->secVer))
- {
- g_strlcpy(newDev->secVer, "0.0.0", OIC_SEC_MAX_VER_LEN);
- }
- else
- {
- g_strlcpy(newDev->secVer, src->secVer, OIC_SEC_MAX_VER_LEN);
- }
-
- newDev->securePort = src->securePort;
- newDev->devStatus = src->devStatus;
- newDev->connType = src->connType;
- newDev->next = NULL;
-
- return newDev;
-}
-#endif
+ma_subowner_s *g_client; /**< MOT agent client instance */
+GMutex iotivity_mutex; /**< Mutex for IoTivity stack */
#ifdef THREAD_COND_WAIT_USED
/*
pthread_cond_t cond;
long int waits;
} PROC;
+
void _exec_and_wait(void* args) {
OCStackResult ret = OC_STACK_OK;
static struct timespec time_to_wait = {0, 0};
return MA_ERROR_NONE;
}
#endif
+
+static FILE* _fopen_prvn_mng(const char* path, const char* mode)
+{
+ char data_dir[MAX_FILE_PATH_LEN] = {0,};
+
+ snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
+ "/opt/usr/data", SVR_DB_FILE_NAME);
+
+ NOTUSED(path);
+#if 0
+ MA_LOGD("Unsed DB path %s\n", path);
+#endif
+
+ return fopen(data_dir, mode);
+}
+
static int _wait_cb_ret(int msec)
{
OCStackResult ret = OC_STACK_OK;
}
}
-static int _set_device_id_seed(void)
-{
- int ret = WIFI_MANAGER_ERROR_NONE;
- gchar *mac_addr = NULL;
- gchar *test_mac = "00:12:36:11:22:33";
-
- wifi_manager_h wifi_handle = NULL;
- bool wifi_activated = false;
-
- /* Initialize Wi-Fi driver */
- ret = wifi_manager_initialize(&wifi_handle);
- if (WIFI_MANAGER_ERROR_NONE != ret)
- MA_LOGE("Failed to get wifi manager handle ! [%d][%s]", ret, _wifi_error_to_string(ret));
-
- wifi_manager_is_activated(wifi_handle, &wifi_activated);
- if (false == wifi_activated) {
- ret = wifi_manager_activate(wifi_handle, NULL, NULL);
- if (WIFI_MANAGER_ERROR_NONE != ret)
- MA_LOGE("Failed to activate wifi ! [%d][%s]", ret, _wifi_error_to_string(ret));
- }
-
- ret = wifi_manager_get_mac_address(wifi_handle, &mac_addr);
- if (WIFI_MANAGER_ERROR_NONE != ret) {
- MA_LOGE("Fail to get MAC address [%d][%s]", ret, _wifi_error_to_string(ret));
- /* Make deviceID based on Fake MAC address */
- ret = SetDeviceIdSeed((const guchar *)test_mac, WIFI_MAC_ADDR_LENGTH);
- } else {
- /* Make deviceID based on Wi-Fi MAC address */
- ret = SetDeviceIdSeed((const guchar *)mac_addr, WIFI_MAC_ADDR_LENGTH);
- g_free(mac_addr);
- }
- if (OC_STACK_OK != ret ) {
- MA_LOGE( "SetDeviceIdSeed() error = [%d][%s]", ret, _error_to_string(ret));
- }
- wifi_manager_deinitialize(wifi_handle);
- return ret;
-}
-
-static int _init_provision_client(void)
-{
- int ret = OC_STACK_OK;
- char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
- if (g_client)
- return ret;
-
- g_mutex_init(&iotivity_mutex);
-
- 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);
- ret = OCRegisterPersistentStorageHandler(&ps);
- g_mutex_unlock(&iotivity_mutex);
- if (OC_STACK_OK != ret ) {
- MA_LOGE( "OCRegisterPersistentStorageHandler error = %d", ret);
- return ret;
- }
-
- _set_device_id_seed();
-
- /* initialize OC stack and provisioning manager */
- g_mutex_lock(&iotivity_mutex);
- ret = OCInit(NULL, 0, OC_CLIENT_SERVER);
- g_mutex_unlock(&iotivity_mutex);
- if (OC_STACK_OK != ret ) {
- MA_LOGE( "OCInit() error = [%d][%s]", ret, _error_to_string(ret));
- return ret;
- }
-
- /* Do Self-Ownership Transfer */
- g_mutex_lock(&iotivity_mutex);
- ret = OCConfigSelfOwnership();
- g_mutex_unlock(&iotivity_mutex);
- if (OC_STACK_OK != ret ) {
- MA_LOGE( "OCConfigSelfOwnership() error = [%d][%s]", ret, _error_to_string(ret));
- }
-
- g_mutex_lock(&iotivity_mutex);
- ret = OCInitPM(data_dir);
- g_mutex_unlock(&iotivity_mutex);
- if (OC_STACK_OK != ret ) {
- MA_LOGE( "OCInitPM() error = [%d][%s]", ret, _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->g_motdev_list = NULL;
- g_client->g_mowned_list = NULL;
- g_client->rnd_pin = NULL;
-
- return ret;
-}
static void _request_cleanup(gpointer data)
{
ma_req_cb_s *con = (ma_req_cb_s *)data;
}
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ g_atomic_int_set(&g_client->pending, 0);
if (con) {
g_free(con);
/* g_mowned_list would be filled above request */
g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
- if (MA_DISC_MOT_ENB_DEVS == con->cid) {
+ if (MA_FIND_MOT_ENABLED_DEVICES == con->cid) {
iter = g_client->g_motdev_list;
- g_client->g_motdev_cnt = _print_dev_list(g_client->g_motdev_list);
+ g_client->g_motdev_cnt = ma_print_dev_list(g_client->g_motdev_list);
MA_LOGD("Found %d MOT enabled devices", g_client->g_motdev_cnt);
- } else if (MA_DISC_MOWNED_DEVS == con->cid) {
+ } else if (MA_FIND_MULTIPLE_OWNED_DEVICES == con->cid) {
iter = g_client->g_mowned_list;
- g_client->g_mowndev_cnt = _print_dev_list(g_client->g_mowned_list);
+ g_client->g_mowndev_cnt = ma_print_dev_list(g_client->g_mowned_list);
MA_LOGD("Found %d Mowned devices", g_client->g_mowndev_cnt);
}
g_variant_builder_open(&builder, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add(&builder, "{sv}", "deviceId",
- g_variant_new_string(_get_readable_uuid(uuid)));
+ g_variant_new_string(ma_get_readable_uuid(uuid)));
g_variant_builder_add(&builder, "{sv}", "adapter",
g_variant_new_uint32(iter->endpoint.adapter));
g_variant_builder_add(&builder, "{sv}", "flags",
devices = g_variant_builder_end(&builder);
- if (MA_DISC_MOT_ENB_DEVS == con->cid)
+ if (MA_FIND_MOT_ENABLED_DEVICES == con->cid)
ma_notify_mot_env_devs(devices);
- else if (MA_DISC_MOWNED_DEVS == con->cid)
+ else if (MA_FIND_MULTIPLE_OWNED_DEVICES == con->cid)
ma_notify_mowned_devs(devices);
g_variant_builder_unref(&builder);
g_variant_unref(devices);
-
}
-#ifdef TIMEOUT_USED
-static gboolean _ma_timeout_cb(gpointer data)
-{
- ma_req_cb_s *con = (ma_req_cb_s *)data;
- ma_check_null_ret_error("con", con, G_SOURCE_REMOVE);
-
- if (NULL == con) {
- MA_LOGE("container is NULL");
- return G_SOURCE_REMOVE;
- }
- if (con->found) {
- MA_LOGE("cb was alreay handled");
- return G_SOURCE_REMOVE;
- }
- if(OC_STACK_OK != OCProcess()) {
- MA_LOGE( "OCStack process error");
- return G_SOURCE_REMOVE;
- }
-
- if (MA_DISC_MOWNED_DEVS < con->cid) {
- OCPDMCleanupForTimeout();
- }
-
- switch (con->cid) {
- case MA_DISC_MOT_ENB_DEVS:
- MA_LOGW("Timeout: Discovered MOT Enabled Devices");
- __notify_found_devs(con);
- break;
- case MA_DISC_MOWNED_DEVS:
- MA_LOGW("Timeout: Discovered My Owned Devices");
- __notify_found_devs(con);
- break;
- case MA_MOT:
- net_ma_emit_mot_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
- break;
- case MA_PROV_ACL:
- net_ma_emit_acl_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
- break;
- case MA_PROV_CRED:
- net_ma_emit_cred_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
- break;
- case MA_PROV_PAIRWISE:
- net_ma_emit_pairwise_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
- break;
- case MA_REMOVE_MOT:
- net_ma_emit_remove_mo_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
- break;
- case MA_REMOVE_CRED_LOCAL:
- net_ma_emit_remove_cred_local_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
- break;
- case MA_UNLINK:
- net_ma_emit_unpair_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
- break;
- case MA_PAIR:
- net_ma_emit_pair_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
- break;
- case MA_UNPAIR:
- net_ma_emit_unpair_done(ma_dbus_get_object(), MA_ERROR_OPERATION_FAILED);
- break;
- }
-
- _request_cleanup(con);
-
- return G_SOURCE_REMOVE;
-}
-#endif
-
-static gpointer _disc_mot_env_devs_func(gpointer data)
+static void _disc_mot_env_devs_func(ma_req_cb_s *con)
{
int ret = OC_STACK_OK;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
- ma_check_null_ret_error("con", con, NULL);
- MA_LOGI("Discovering Multiple Ownership Transfer enabled Devices on Network..");
+ ma_check_null_ret("con", con);
+ ma_check_null_ret("g_client", g_client);
+
+ MA_LOGI("Discovering MOT enabled Devices on Network..");
/* delete mot device lists before updating them */
_remove_mot_client();
MA_LOGE( "OCDiscoverMultipleOwnerEnalbedDevices API error");
goto DISC_MOT_ENB_DEVS_END;
}
-
__notify_found_devs(con);
DISC_MOT_ENB_DEVS_END:
-
_request_cleanup(con);
-
- g_thread_exit(GINT_TO_POINTER (1));
-
- return NULL;
}
static int _disc_mot_enb_devs(ma_service *service, int timeout)
{
ma_req_cb_s *con = NULL;
-
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);
+ g_atomic_int_set(&g_client->pending, 0);
return MA_ERROR_OUT_OF_MEMORY;
}
con->userdata = service;
- con->cid = MA_DISC_MOT_ENB_DEVS;
+ con->cid = MA_FIND_MOT_ENABLED_DEVICES;
if (timeout < 1)
timeout = DISCOVERY_TIMEOUT;
con->timeout = timeout;
- con->thread = g_thread_try_new("disc_mot_env_devs", _disc_mot_env_devs_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);
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-#ifdef TIMEOUT_USED
- con->tid = g_timeout_add_seconds(timeout * 2, _ma_timeout_cb, con);
-#endif
return MA_ERROR_NONE;
}
-static gpointer _disc_owned_devs_func(gpointer data)
+static void _disc_owned_devs_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
- ma_check_null_ret_error("g_client", g_client, NULL);
+ ma_check_null_ret("con", con);
+ ma_check_null_ret("g_client", g_client);
/* delete un/owned device lists before updating them */
_remove_owned_client();
- MA_LOGD("Discovering Multiple Owned Devices");
+ MA_LOGD("Discovering MOWNED Devices");
g_mutex_lock(&iotivity_mutex);
ret = OCDiscoverMultipleOwnedDevices(con->timeout,
MA_LOGE( "OCDiscoverMultipleOwnerEnabledDevices API error");
goto DISC_OWNED_DEVS_END;
}
-
__notify_found_devs(con);
DISC_OWNED_DEVS_END:
_request_cleanup(con);
- g_thread_exit(GINT_TO_POINTER (1));
-
- return NULL;
}
static int _disc_owned_devs(ma_service *service, int timeout)
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
/* Unset d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ g_atomic_int_set(&g_client->pending, 0);
return MA_ERROR_OUT_OF_MEMORY;
}
con->userdata = service;
- con->cid = MA_DISC_MOWNED_DEVS;
+ con->cid = MA_FIND_MULTIPLE_OWNED_DEVICES;
if (timeout < 1)
timeout = DISCOVERY_TIMEOUT;
con->timeout = timeout;
- con->thread = g_thread_try_new("disc_owned_devs", _disc_owned_devs_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(timeout * 2, _ma_timeout_cb, con);
-#endif
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
+
return MA_ERROR_NONE;
}
static void _mot_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has_error)
{
-#ifdef MANIPULATE_LOCAL_PDM
- int i = 0;
- int ret = OC_STACK_OK;
-#endif
ma_subowner_s *client = (ma_subowner_s *)ctx;
if (!has_error) {
MA_LOGD("Multiple Ownership Transfer SUCCEEDED");
} else {
MA_LOGD( "Multiple Ownership Transfer FAILED ");
-
- _print_result_list((const OCProvisionResult_t*) arr, num);
-#ifdef MANIPULATE_LOCAL_PDM
- ret = ma_open_db();
- if (OC_STACK_OK != ret)
- MA_LOGE( "openDB: ret = %d (%s)", ret, _error_to_string(ret));
-
- for ( ; num > i; ++i) {
- if (OC_STACK_OK !=arr[i].res) {
- ret = ma_delete_device((const OicUuid_t*) &arr[i].deviceId);
- }
- }
- ret = ma_close_db();
- if (OC_STACK_OK != ret)
- MA_LOGE( "closeDB: ret = %d (%s)", ret, _error_to_string(ret));
-#endif
+ ma_print_result_list((const OCProvisionResult_t*) arr, num);
}
client->g_doneCB = true;
}
-static gpointer _mot_func(gpointer data)
+static void _mot_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
-
OCProvisionDev_t *src_dev = NULL;
OCProvisionDev_t *next_dev = NULL;
OicUuid_t *uuid_target = NULL;
MA_LOGE("mot agent is not initialized");
goto MOT_ENDED;
}
-
+ if (NULL == con) {
+ ret = OC_STACK_INVALID_PARAM;
+ MA_LOGE("container is NULL");
+ goto MOT_ENDED;
+ }
if (!con->uuid_target_str) {
ret = OC_STACK_INVALID_PARAM;
goto MOT_ENDED;
}
- uuid_target = _convert_uuid(con->uuid_target_str);
- src_dev = _get_dev_by_uuid(g_client->g_motdev_list, uuid_target);
+ 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 MOT_ENDED;
}
ret = OCDoMultipleOwnershipTransfer(g_client, g_client->g_motdev_list, _mot_cb);
if (OC_STACK_OK != ret ) {
- MA_LOGE( "OCDoMultipleOwnershipTransfer: ret = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGE( "OCDoMultipleOwnershipTransfer: ret = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto MOT_ENDED;
}
}
ret = OCDoMultipleOwnershipTransfer(g_client, src_dev, _mot_cb);
if (OC_STACK_OK != ret ) {
- MA_LOGE( "OCDoMultipleOwnershipTransfer: ret = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGE( "OCDoMultipleOwnershipTransfer: ret = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto MOT_ENDED;
}
#endif
-
-
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if(ret) {
- MA_LOGE( "OCDoMultipleOwnershipTransfer callback error = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGE( "OCDoMultipleOwnershipTransfer callback error = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto MOT_ENDED;
}
/* Restore MOT enabled devices */
MA_LOGI("Registered Discovered Devices");
MOT_ENDED:
-
net_ma_emit_mot_done(ma_dbus_get_object(), (int)ret);
if (uuid_target)
g_free(uuid_target);
- _request_cleanup(data);
- g_thread_exit(GINT_TO_POINTER (1));
-
- return NULL;
+ _request_cleanup(con);
}
static int _ma_mot(ma_service *service, gchar *uuid_str, gchar *pin)
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
/* Unset d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ g_atomic_int_set(&g_client->pending, 0);
return MA_ERROR_OUT_OF_MEMORY;
}
con->userdata = service;
- con->cid = MA_MOT;
+ con->cid = MA_DO_MOT;
con->uuid_target_str = g_strdup(uuid_str);
if (pin) {
memcpy(con->pin, pin, OXM_RANDOM_PIN_MAX_SIZE);
}
- con->thread = g_thread_try_new("mot", _mot_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);
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-#ifdef TIMEOUT_USED
- con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S * 2, _ma_timeout_cb, con);
-#endif
return MA_ERROR_NONE;
}
-#if 0 /* TEST */
-static int sendGetLed()
-{
- int selDevNum;
- char query[256] = {0};
- OCCallbackData cbData;
- cbData.cb = &LedCB;
- cbData.context = NULL;
- cbData.cd = NULL;
-
- printDevList(g_mowned_list);
-
- // select device for provisioning access control list
- for( ; ; ) {
- printf(" > Enter Device Number, for sending GET LED request: ");
- for(int ret=0; 1!=ret; ) {
- ret = scanf("%d", &selDevNum);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<selDevNum && g_mowned_cnt>=selDevNum) {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
- }
-
- OCProvisionDev_t* selDev = _get_dev_by_id(g_mowned_list, selDevNum);
- if(NULL == selDev) {
- printf("Failed to _get_dev_by_id()\n");
- return -1;
- }
-
- if(PMGenerateQuery(true, selDev->endpoint.addr, selDev->securePort, selDev->connType,
- query, sizeof(query), "/a/led")) {
- g_doneCB = false;
- printf("query=%s\n", query);
- if(OC_STACK_OK != OCDoResource(NULL, OC_REST_GET, query, NULL, NULL, selDev->connType,
- OC_HIGH_QOS, &cbData, NULL, 0)) {
- printf("********************************\n");
- printf("Failed to send GET request to %s\n", query);
- printf("********************************\n");
- g_doneCB = true;
- return -1;
- }
-
- waitCallbackRet();
- } else {
- printf("Failed to generate GET request for /a/led\n");
- return -1;
- }
-
- return 0;
-}
-
-static int sendPutLed()
-{
- int selDevNum;
- char query[256] = {0};
- OCCallbackData cbData;
- cbData.cb = &LedCB;
- cbData.context = NULL;
- cbData.cd = NULL;
-
- printDevList(g_mowned_list);
- // select device for provisioning access control list
- for( ; ; ) {
- printf(" > Enter Device Number, for sending PUT LED request: ");
- for(int ret=0; 1!=ret; ) {
- ret = scanf("%d", &selDevNum);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<selDevNum && g_mowned_cnt>=selDevNum) {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
- }
-
- OCProvisionDev_t* selDev = _get_dev_by_id(g_mowned_list, selDevNum);
- if (NULL == selDev) {
- printf("Failed to _get_dev_by_id()\n");
- return -1;
- }
-
- if (PMGenerateQuery(true, selDev->endpoint.addr, selDev->securePort, selDev->connType, query,
- sizeof(query), "/a/led")) {
- g_doneCB = false;
- MA_LOGI("query=%s\n", query);
- if(OC_STACK_OK != OCDoResource(NULL, OC_REST_PUT, query, NULL, NULL, selDev->connType,
- OC_LOW_QOS, &cbData, NULL, 0)) {
- MA_LOGI("********************************\n");
- MA_LOGI("Failed to send PUT request to %s\n", query);
- MA_LOGI("********************************\n");
- g_doneCB = true;
- return -1;
- }
-
- waitCallbackRet();
- } else {
- printf("Failed to generate PUT request for /a/led\n");
- return -1;
- }
-
- return 0;
-}
-#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)
{
ma_check_null_ret_error(target, "target", NULL);
ma_check_null_ret_error(subject, "subject", NULL);
-
#ifdef DEBUG_UUID
- MA_LOGD("target = %s", _get_readable_uuid(target));
- MA_LOGD("subject = %s", _get_readable_uuid(subject));
+ MA_LOGD("target = %s", ma_get_readable_uuid(target));
+ MA_LOGD("subject = %s", ma_get_readable_uuid(subject));
MA_LOGD("rsrc_uri = %s", rsrc_uri);
MA_LOGD("rsrc_type = %s", rsrc_type);
MA_LOGD("rsrc_interface = %s", rsrc_interface);
MA_LOGD("Provision ACL SUCCEEDED");
} else {
MA_LOGD( "Provision ACL FAILED ");
- _print_result_list((const OCProvisionResult_t*) arr, nOfRes);
+ ma_print_result_list((const OCProvisionResult_t*) arr, nOfRes);
}
client->g_doneCB = true;
}
-static gpointer _acl_func(gpointer data)
+static void _acl_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
+
OicSecAcl_t* acl = NULL;
OicUuid_t *uuid1 = NULL;
OicUuid_t *uuid2 = NULL;
MA_LOGE("mot agent is not initialized");
goto PVACL_ERROR;
}
+ 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) {
goto PVACL_ERROR;
}
- uuid1 = _convert_uuid(con->uuid_target_str);
- target_dev = _get_dev_by_uuid(g_client->g_motdev_list, uuid1);
+ 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;
}
- uuid2 = _convert_uuid(con->uuid_subject_str);
- subject_dev = _get_dev_by_uuid(g_client->g_motdev_list, uuid2);
+ 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;
g_client->g_doneCB = false;
MA_LOGI(" Provisioning Selected ACL..");
- acl = _create_target_acl(&target_dev->doxm->deviceID, &subject_dev->doxm->deviceID, con->rsrc_uri, con->rsrc_type,
+ acl = _create_target_acl(&target_dev->doxm->deviceID,
+ &subject_dev->doxm->deviceID, con->rsrc_uri, con->rsrc_type,
con->rsrc_interface, con->permission);
if (NULL == acl) {
MA_LOGE( "Failed to create ACL for %s", con->rsrc_uri);
ret= OCProvisionACL((void*) g_client, target_dev, acl, _acl_cb);
if (OC_STACK_OK != ret) {
- MA_LOGD( "OCProvisionACL API error: %d (%s)", ret, _error_to_string(ret));
+ MA_LOGD( "OCProvisionACL API error: %d (%s)", ret, ma_ocf_error_to_string(ret));
goto PVACL_ERROR;
}
g_free(uuid1);
if (uuid2)
g_free(uuid2);
+
_request_cleanup(con);
- g_thread_exit(GINT_TO_POINTER (1));
- return NULL;
}
static int _acl(ma_service *service, gchar *target, gchar *subject,
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
/* Unset d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ g_atomic_int_set(&g_client->pending, 0);
return MA_ERROR_OUT_OF_MEMORY;
}
con->userdata = service;
- con->cid = MA_PROV_ACL;
+ con->cid = MA_DO_ACL_PROVISIONING;
con->uuid_target_str = g_strdup(target);
con->uuid_subject_str = g_strdup(subject);
con->rsrc_uri = g_strdup(rsrc_uri);
con->rsrc_type = g_strdup(rsrc_type);
con->rsrc_interface = g_strdup(rsrc_interface);
- con->thread = g_thread_try_new("prov_acl", _acl_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
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
+
return MA_ERROR_NONE;
}
MA_LOGD("Provision ACL SUCCEEDED");
} else {
MA_LOGD( "Provision ACL FAILED ");
- _print_result_list((const OCProvisionResult_t*) arr, nOfRes);
+ ma_print_result_list((const OCProvisionResult_t*) arr, nOfRes);
}
client->g_doneCB = true;
}
-static gpointer _cred_func(gpointer data)
+static void _cred_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
OicUuid_t *uuid1 = NULL;
OicUuid_t *uuid2 = NULL;
MA_LOGE("mot agent is not initialized");
goto PVCRED_ERROR;
}
+ if (NULL == con) {
+ ret = OC_STACK_INVALID_PARAM;
+ MA_LOGE("container is NULL");
+ goto PVCRED_ERROR;
+ }
if (!con->uuid_dev1 ) {
MA_LOGE("dev1 is NULL");
goto PVCRED_ERROR;
}
- uuid1 = _convert_uuid(con->uuid_dev1);
- dev1 = _get_dev_by_uuid(g_client->g_motdev_list, uuid1);
+ 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;
}
- uuid2 = _convert_uuid(con->uuid_dev2);
- dev2 = _get_dev_by_uuid(g_client->g_motdev_list, uuid2);
+ 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;
SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_256,
dev1, dev2, _cred_cb);
if (OC_STACK_OK != ret) {
- MA_LOGD( "OCProvisionPairwiseDevices API error: %d (%s)", ret, _error_to_string(ret));
+ MA_LOGD( "OCProvisionPairwiseDevices API error: %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto PVCRED_ERROR;
}
g_free(uuid1);
if (uuid2)
g_free(uuid2);
- _request_cleanup(con);
- g_thread_exit(GINT_TO_POINTER (1));
-
- return NULL;
+ _request_cleanup(con);
}
static int _cred(ma_service *service,
if (!con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
/* Unset d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ g_atomic_int_set(&g_client->pending, 0);
return MA_ERROR_OUT_OF_MEMORY;
}
con->userdata = service;
- con->cid = MA_PROV_CRED;
+ con->cid = MA_DO_CRED_PROVISIONING;
if (!uuid_dev1 ||!uuid_dev2) {
MA_LOGE( "Invaild Prameters");
con->uuid_dev1 = g_strdup(uuid_dev1);
con->uuid_dev2 = g_strdup(uuid_dev2);
- con->thread = g_thread_try_new("prov_cred", _cred_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
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
+
return MA_ERROR_NONE;
}
-static void _pairwise_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool has_error)
+static void _pairwise_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr,
+ bool has_error)
{
ma_subowner_s *client = (ma_subowner_s *)ctx;
MA_LOGD("Provision pairwise SUCCEEDED");
} else {
MA_LOGD( "Provision pairwise FAILED ");
- _print_result_list((const OCProvisionResult_t*) arr, nOfRes);
+ ma_print_result_list((const OCProvisionResult_t*) arr, nOfRes);
}
client->g_doneCB = true;
}
-static gpointer _pairwise_func(gpointer data)
+static void _pairwise_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
OicUuid_t *uuid_1 = NULL;
OicUuid_t *uuid_2 = NULL;
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) {
goto PVPAIRWIE_ERROR;
}
- uuid_1 = _convert_uuid(con->target_1);
- target_dev_1 = _get_dev_by_uuid(g_client->g_motdev_list, uuid_1);
+ 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 PVPAIRWIE_ERROR;
}
- uuid_2 = _convert_uuid(con->target_2);
- target_dev_2 = _get_dev_by_uuid(g_client->g_motdev_list, uuid_2);
+ 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 PVPAIRWIE_ERROR;
}
- uuid_3 = _convert_uuid(con->subject_1);
- subject_dev_1 = _get_dev_by_uuid(g_client->g_motdev_list, uuid_3);
+ 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 PVPAIRWIE_ERROR;
}
- uuid_4 = _convert_uuid(con->subject_2);
- subject_dev_2 = _get_dev_by_uuid(g_client->g_motdev_list, uuid_4);
+ 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 PVPAIRWIE_ERROR;
target_dev_2, acl_2, _pairwise_cb);
if (OC_STACK_OK != ret) {
MA_LOGD( "OCProvisionPairwiseDevices API error: %d (%s)", ret,
- _error_to_string(ret));
+ ma_ocf_error_to_string(ret));
goto PVPAIRWIE_ERROR;
}
OCDeleteACLList(acl_2);
_request_cleanup(con);
- g_thread_exit(GINT_TO_POINTER (1));
- return NULL;
}
static int _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)
+ 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;
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);
+ g_atomic_int_set(&g_client->pending, 0);
return MA_ERROR_OUT_OF_MEMORY;
}
con->userdata = service;
- con->cid = MA_PROV_PAIRWISE;
+ con->cid = MA_DO_RESOURCES_PAIRWISE;
con->target_1 = g_strdup(target_1);
con->subject_1 = g_strdup(subject_1);
con->rsrc_interface_2 = g_strdup(rsrc_interface_2);
con->permission_2 = permission_2;
- con->thread = g_thread_try_new("prov_pairwise", _pairwise_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
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
+
return MA_ERROR_NONE;
}
MA_LOGD("unlink SUCCEEDED");
} else {
MA_LOGD( "unlink FAILED ");
- _print_result_list((const OCProvisionResult_t*) arr, nOfRes);
+ ma_print_result_list((const OCProvisionResult_t*) arr, nOfRes);
}
client->g_doneCB = true;
}
-static gpointer _unlink_func(gpointer data)
+static void _unlink_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
OicUuid_t *uuid1 = NULL;
OicUuid_t *uuid2 = NULL;
MA_LOGE("mot agent is not initialized");
goto PVUNLINKPAIRWISE_ERROR;
}
+ if (NULL == con) {
+ ret = OC_STACK_INVALID_PARAM;
+ MA_LOGE("container is NULL");
+ goto PVUNLINKPAIRWISE_ERROR;
+ }
if (!con->uuid_dev1 ) {
MA_LOGE("dev1 is NULL");
goto PVUNLINKPAIRWISE_ERROR;
}
- uuid1 = _convert_uuid(con->uuid_dev1);
- dev1 = _get_dev_by_uuid(g_client->g_motdev_list, uuid1);
+ 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 PVUNLINKPAIRWISE_ERROR;
}
- uuid2 = _convert_uuid(con->uuid_dev2);
- dev2 = _get_dev_by_uuid(g_client->g_motdev_list, uuid2);
+ 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 PVUNLINKPAIRWISE_ERROR;
MA_LOGI("Unlink Selected Pairwise Devices..");
ret = OCUnlinkDevices((void*) g_client, dev1, dev2, _unlink_cb );
if (OC_STACK_OK != ret) {
- MA_LOGD( "OCUnlinkDevices API error: %d (%s)", ret, _error_to_string(ret));
+ MA_LOGD( "OCUnlinkDevices API error: %d (%s)", ret, ma_ocf_error_to_string(ret));
goto PVUNLINKPAIRWISE_ERROR;
}
g_free(uuid1);
if (uuid2)
g_free(uuid2);
- _request_cleanup(con);
- g_thread_exit(GINT_TO_POINTER (1));
-
- return NULL;
+ _request_cleanup(con);
}
static int _unlink(ma_service *service,
if (!con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
/* Unset d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ g_atomic_int_set(&g_client->pending, 0);
return MA_ERROR_OUT_OF_MEMORY;
}
con->userdata = service;
- con->cid = MA_UNLINK;
+ con->cid = MA_UNLINK_RESOURCES;
if (!uuid_dev1 ||!uuid_dev2) {
MA_LOGE( "Invaild Prameters");
con->uuid_dev1 = g_strdup(uuid_dev1);
con->uuid_dev2 = g_strdup(uuid_dev2);
- con->thread = g_thread_try_new("prov_unlink", _unlink_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
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
+
return MA_ERROR_NONE;
}
-static void _remove_mo_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has_error)
+static void _remove_mo_cb(void* ctx, int num, OCProvisionResult_t* arr,
+ bool has_error)
{
ma_subowner_s *client = (ma_subowner_s *)ctx;
MA_LOGD("Remove Multiple Ownership SUCCEEDED");
} else {
MA_LOGD( "Remove Multiple Ownership FAILED ");
- _print_result_list((const OCProvisionResult_t*) arr, num);
+ ma_print_result_list((const OCProvisionResult_t*) arr, num);
}
client->g_doneCB = true;
}
-static gpointer _remove_mo_func(gpointer data)
+static void _remove_mo_func(ma_req_cb_s *con)
{
OCStackResult ret = MA_ERROR_OPERATION_FAILED;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
OCProvisionDev_t *src_dev = NULL;
OicUuid_t uuid_mowner;
MA_LOGE("mot agent is not initialized");
goto REMOVE_MO_ENDED;
}
+ if (NULL == con) {
+ ret = OC_STACK_INVALID_PARAM;
+ MA_LOGE("container is NULL");
+ goto REMOVE_MO_ENDED;
+ }
if (!con->uuid_target_str) {
MA_LOGE("Target device UUID is NULL");
goto REMOVE_MO_ENDED;
}
- uuid_target = _convert_uuid(con->uuid_target_str);
- src_dev = _get_dev_by_uuid(g_client->g_motdev_list, uuid_target);
+ 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;
ret = GetDoxmDevOwnerId(&uuid_mowner);
if (OC_STACK_OK != ret) {
- MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]", ret, _error_to_string(ret));
+ MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]",
+ ret, ma_ocf_error_to_string(ret));
goto REMOVE_MO_ENDED;
}
-#ifdef MANIPULATE_LOCAL_PDM
- ret = ma_open_db();
- if (OC_STACK_OK != ret)
- MA_LOGE( "openDB: ret = %d (%s)", ret, _error_to_string(ret));
- ret = ma_delete_device((const OicUuid_t*) uuid_target);
- if (OC_STACK_OK != ret)
- MA_LOGE( "delete_mowned_device_db: ret = %d (%s)", ret, _error_to_string(ret));
- ret = ma_close_db();
- if (OC_STACK_OK != ret)
- MA_LOGE( "closeDB: ret = %d (%s)", ret, _error_to_string(ret));
-#endif
ret = OCRemoveSubOwner(g_client, src_dev, &uuid_mowner, _remove_mo_cb);
if (OC_STACK_OK != ret ) {
- MA_LOGE( "OCRemoveSubOwner: ret = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGE( "OCRemoveSubOwner: ret = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto REMOVE_MO_ENDED;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if(ret) {
- MA_LOGE( "OCRemoveSubOwner callback error = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGE( "OCRemoveSubOwner callback error = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto REMOVE_MO_ENDED;
}
MA_LOGI("Remove Multiple Ownership Done");
REMOVE_MO_ENDED:
-
net_ma_emit_remove_mo_done(ma_dbus_get_object(), (int)ret);
-
if (uuid_target)
g_free(uuid_target);
- _request_cleanup(data);
- g_thread_exit(GINT_TO_POINTER (1));
-
- return NULL;
+ _request_cleanup(con);
}
static int _ma_remove_mo(ma_service *service, gchar *uuid_str)
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
/* Unset d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ g_atomic_int_set(&g_client->pending, 0);
return MA_ERROR_OUT_OF_MEMORY;
}
con->userdata = service;
- con->cid = MA_REMOVE_MOT;
+ con->cid = MA_REMOVE_MULTIPLE_OWNED_DEVICE;
con->uuid_target_str = g_strdup(uuid_str);
- con->thread = g_thread_try_new("remove_mo", _remove_mo_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);
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-#ifdef TIMEOUT_USED
- con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S * 2, _ma_timeout_cb, con);
-#endif
return MA_ERROR_NONE;
}
MA_LOGD("Remove CRED for mowned device SUCCEEDED");
} else {
MA_LOGD( "Remove CRED for mowned device FAILED ");
- _print_result_list((const OCProvisionResult_t*) arr, num);
+ ma_print_result_list((const OCProvisionResult_t*) arr, num);
}
client->g_doneCB = true;
}
-static gpointer _remove_cred_local_func(gpointer data)
+static void _remove_cred_local_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
-
OicUuid_t *uuid = NULL;
if (!g_client) {
MA_LOGE("mot agent is not initialized");
goto REMOVE_LOCAL_CRED_ERROR;
}
-
+ if (NULL == con) {
+ ret = OC_STACK_INVALID_PARAM;
+ MA_LOGE("container is NULL");
+ goto REMOVE_LOCAL_CRED_ERROR;
+ }
if (!con->target_to_revoke) {
MA_LOGE("Some parameters are wrong");
MA_LOGE("%s", con->target_to_revoke );
goto REMOVE_LOCAL_CRED_ERROR;
}
- uuid = _convert_uuid(con->target_to_revoke);
+ 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 );
if (OC_STACK_OK != ret) {
- MA_LOGD( "OCRemoveDeviceWithUuid API error: %d (%s)", ret, _error_to_string(ret));
+ MA_LOGD( "OCRemoveDeviceWithUuid API error: %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto REMOVE_LOCAL_CRED_ERROR;
}
if (uuid)
g_free(uuid);
_request_cleanup(con);
- g_thread_exit(GINT_TO_POINTER (1));
- return NULL;
}
static int _ma_remove_cred_local(ma_service *service, gchar *uuid_str)
if (NULL == con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
/* Unset d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ g_atomic_int_set(&g_client->pending, 0);
return MA_ERROR_OUT_OF_MEMORY;
}
con->userdata = service;
- con->cid = MA_REMOVE_CRED_LOCAL;
+ con->cid = MA_REMOVE_DEVICE_WITH_UUID_IN_SVR;
con->target_to_revoke = g_strdup(uuid_str);
- con->thread = g_thread_try_new("remove_mowned_dev_cred", _remove_cred_local_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);
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-#ifdef TIMEOUT_USED
- con->tid = g_timeout_add_seconds(CALLBACK_TIMEOUT_5S * 2, _ma_timeout_cb, con);
-#endif
return MA_ERROR_NONE;
}
-static gpointer _pair_func(gpointer data)
+static void _pair_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
OicUuid_t *uuid_1 = NULL;
OicUuid_t *uuid_2 = NULL;
MA_LOGE("mot agent is not initialized");
goto PVPAIR_ERROR;
}
+ 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) {
+ 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 );
goto PVPAIR_ERROR;
}
- uuid_1 = _convert_uuid(con->target_1);
- target_dev_1 = _get_dev_by_uuid(g_client->g_motdev_list, uuid_1);
+ 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;
}
- uuid_2 = _convert_uuid(con->target_2);
- target_dev_2 = _get_dev_by_uuid(g_client->g_motdev_list, uuid_2);
+ 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;
}
- uuid_3 = _convert_uuid(con->subject_1);
- subject_dev_1 = _get_dev_by_uuid(g_client->g_motdev_list, uuid_3);
+ 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;
}
- uuid_4 = _convert_uuid(con->subject_2);
- subject_dev_2 = _get_dev_by_uuid(g_client->g_motdev_list, uuid_4);
+ 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;
}
- src_dev = _get_dev_by_uuid(g_client->g_motdev_list, uuid_2);
+ 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;
ret = OCDoMultipleOwnershipTransfer(g_client, src_dev, _mot_cb);
g_mutex_unlock(&iotivity_mutex);
if (OC_STACK_OK != ret ) {
- MA_LOGE( "OCDoMultipleOwnershipTransfer: ret = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGE( "OCDoMultipleOwnershipTransfer: ret = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto PVPAIR_ERROR;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (OC_STACK_OK != ret ) {
- MA_LOGE( "OCDoMultipleOwnershipTransfer callback error = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGE( "OCDoMultipleOwnershipTransfer callback error = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto PVPAIR_ERROR;
}
/* Restore MOT enabled devices */
g_mutex_unlock(&iotivity_mutex);
if (OC_STACK_OK != ret) {
MA_LOGD( "OCProvisionPairwiseDevices API error: %d (%s)", ret,
- _error_to_string(ret));
+ ma_ocf_error_to_string(ret));
goto PVPAIR_ERROR;
}
OCDeleteACLList(acl_2);
_request_cleanup(con);
-
- g_thread_exit(GINT_TO_POINTER (1));
- return NULL;
}
static int _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)
+ 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;
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);
+ g_atomic_int_set(&g_client->pending, 0);
return MA_ERROR_OUT_OF_MEMORY;
}
con->userdata = service;
- con->cid = MA_PAIR;
+ con->cid = MA_MAKE_PAIR;
con->pin = g_strdup(pin);
con->target_1 = g_strdup(target_1);
con->rsrc_interface_2 = g_strdup(rsrc_interface_2);
con->permission_2 = permission_2;
- con->thread = g_thread_try_new("pair", _pair_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
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
+
return MA_ERROR_NONE;
}
-static gpointer _unpair_func(gpointer data)
+static void _unpair_func(ma_req_cb_s *con)
{
OCStackResult ret = OC_STACK_OK;
- ma_req_cb_s *con = (ma_req_cb_s *)data;
OicUuid_t uuid_mowner;
OicUuid_t *owner_uuid = NULL;
MA_LOGE("mot agent is not initialized");
goto PVUNPAIR_ERROR;
}
+ if (NULL == con) {
+ ret = OC_STACK_INVALID_PARAM;
+ MA_LOGE("container is NULL");
+ goto PVUNPAIR_ERROR;
+ }
if (NULL == con->uuid_dev1 ) {
MA_LOGE("dev1 is NULL");
goto PVUNPAIR_ERROR;
}
- owner_uuid = _convert_uuid(con->uuid_dev1);
- owner_dev = _get_dev_by_uuid(g_client->g_motdev_list, owner_uuid);
+ 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;
}
- owned_uuid = _convert_uuid(con->uuid_dev2);
- owned_dev = _get_dev_by_uuid(g_client->g_motdev_list, owned_uuid);
+ 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;
ret = OCUnlinkDevices((void*) g_client, owner_dev, owned_dev, _unlink_cb );
g_mutex_unlock(&iotivity_mutex);
if (OC_STACK_OK != ret) {
- MA_LOGD( "OCUnlinkDevices API error = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGD( "OCUnlinkDevices API error = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
} else {
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (OC_STACK_OK != ret) {
- MA_LOGD( "OCUnlinkDevices Timeout = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGD( "OCUnlinkDevices Timeout = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto PVUNPAIR_ERROR;
}
}
ret = GetDoxmDevOwnerId(&uuid_mowner);
if (OC_STACK_OK != ret) {
- MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]", ret, _error_to_string(ret));
+ MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]",
+ ret, ma_ocf_error_to_string(ret));
goto PVUNPAIR_ERROR;
}
ret = OCRemoveSubOwner(g_client, owned_dev, &uuid_mowner, _remove_mo_cb);
g_mutex_unlock(&iotivity_mutex);
if (OC_STACK_OK != ret ) {
- MA_LOGE( "OCRemoveSubOwner: ret = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGE( "OCRemoveSubOwner: ret = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto PVUNPAIR_ERROR;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (OC_STACK_OK != ret) {
- MA_LOGE( "OCRemoveSubOwner Timeout = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGE( "OCRemoveSubOwner Timeout = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto PVUNPAIR_ERROR;
}
_remove_remove_cred_local_cb );
g_mutex_unlock(&iotivity_mutex);
if (OC_STACK_OK != ret) {
- MA_LOGD( "OCRemoveDeviceWithUuid API error = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGD( "OCRemoveDeviceWithUuid API error = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto PVUNPAIR_ERROR;
}
ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
if (OC_STACK_OK != ret) {
- MA_LOGD( "OCRemoveDeviceWithUuid Timeout = %d (%s)", ret, _error_to_string(ret));
+ MA_LOGD( "OCRemoveDeviceWithUuid Timeout = %d (%s)",
+ ret, ma_ocf_error_to_string(ret));
goto PVUNPAIR_ERROR;
}
/* Disaply result result */
PVUNPAIR_ERROR:
/* Notify unpair result */
net_ma_emit_unpair_done(ma_dbus_get_object(), (int)ret);
-
if (owner_uuid)
g_free(owner_uuid);
if (owned_uuid)
g_free(owned_uuid);
-
_request_cleanup(con);
-
- g_thread_exit(GINT_TO_POINTER (1));
-
- return NULL;
}
static int _unpair(ma_service *service, gchar *uuid_dev1, gchar *uuid_dev2)
if (!con) {
MA_LOGE( "g_malloc0() Fail=%d", errno);
/* Unset d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 0);
+ g_atomic_int_set(&g_client->pending, 0);
return MA_ERROR_OUT_OF_MEMORY;
}
con->userdata = service;
- con->cid = MA_UNPAIR;
+ con->cid = MA_MAKE_UNPAIR;
if (!uuid_dev1 ||!uuid_dev2) {
MA_LOGE( "Invaild Prameters");
con->uuid_dev1 = g_strdup(uuid_dev1);
con->uuid_dev2 = g_strdup(uuid_dev2);
- con->thread = g_thread_try_new("prov_unlink", _unpair_func, con, NULL);
- if (!con->thread) {
- MA_LOGE("Failed to create thread");
- _request_cleanup(con);
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
+
+ return MA_ERROR_NONE;
+}
+
+static int _disable(ma_service *service)
+{
+ 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(&g_client->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 * 2, _ma_timeout_cb, con);
-#endif
+ con->userdata = service;
+ con->cid = -1;
+
+ g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
+
return MA_ERROR_NONE;
}
+static gpointer _worker_thread(gpointer data)
+{
+ ma_req_cb_s *con = NULL;
+ ma_subowner_s *client = (ma_subowner_s *)data;
+
+ while (1) {
+ if (0 == g_atomic_int_get(&client->pending)) {
+ con = g_async_queue_pop(client->queue);
+ if (NULL == con) continue;
+ switch(con->cid) {
+ case MA_FIND_MOT_ENABLED_DEVICES:
+ _disc_mot_env_devs_func(con);
+ break;
+ case MA_FIND_MULTIPLE_OWNED_DEVICES:
+ _disc_owned_devs_func(con);
+ break;
+ case MA_DO_MOT:
+ _mot_func(con);
+ break;
+ case MA_DO_ACL_PROVISIONING:
+ _acl_func(con);
+ break;
+ case MA_DO_CRED_PROVISIONING:
+ _cred_func(con);
+ break;
+ case MA_DO_RESOURCES_PAIRWISE:
+ _pairwise_func(con);
+ break;
+ case MA_REMOVE_MULTIPLE_OWNED_DEVICE:
+ _remove_mo_func(con);
+ break;
+ case MA_REMOVE_DEVICE_WITH_UUID_IN_SVR:
+ _remove_cred_local_func(con);
+ break;
+ case MA_UNLINK_RESOURCES:
+ _unlink_func(con);
+ break;
+ case MA_MAKE_PAIR:
+ _pair_func(con);
+ break;
+ case MA_MAKE_UNPAIR:
+ _unpair_func(con);
+ break;
+ default:
+ _request_cleanup(con);
+ goto WORKER_EXIT;
+ }
+ }
+ }
+WORKER_EXIT:
+ g_thread_exit(GINT_TO_POINTER(1));
+ return NULL;
+}
+
+static int _init_provision_client(void)
+{
+ int ret = OC_STACK_OK;
+ char data_dir[MAX_FILE_PATH_LEN] = {0,};
+
+ if (g_client)
+ return ret;
+
+ g_mutex_init(&iotivity_mutex);
+
+ 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);
+ ret = OCRegisterPersistentStorageHandler(&ps);
+ g_mutex_unlock(&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);
+ ret = OCInit(NULL, 0, OC_CLIENT_SERVER);
+ g_mutex_unlock(&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);
+ ret = OCConfigSelfOwnership();
+ g_mutex_unlock(&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);
+ ret = OCInitPM(data_dir);
+ g_mutex_unlock(&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;
+}
+
int ma_request_get_ownerid(ma_service *service, gchar **uuid_str)
{
int ret =MA_ERROR_NONE;
OicUuid_t uuid;
+ ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
ma_check_null_ret_error("service", service, FALSE);
MA_LOGD("[IPC] Get Device ID");
ret = GetDoxmDevOwnerId(&uuid);
if (OC_STACK_OK != ret)
- MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]", ret, _error_to_string(ret));
+ MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]", ret, ma_ocf_error_to_string(ret));
ret = ConvertUuidToStr(&uuid, uuid_str);
if (OC_STACK_OK != ret)
- MA_LOGE("ConvertUuidToStr faild = [%d][%s]", ret, _error_to_string(ret));
+ MA_LOGE("ConvertUuidToStr faild = [%d][%s]", ret, ma_ocf_error_to_string(ret));
return ret;
}
{
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] Discovery MOT enabled devices");
/* If we are working now? */
- if (g_atomic_int_get(&service->pending))
+ if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 1);
+ g_atomic_int_set(&g_client->pending, 1);
ret = _disc_mot_enb_devs(service, timeout);
{
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] Discovery Owned devices");
/* If we are working now? */
- if (g_atomic_int_get(&service->pending))
+ if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 1);
+ g_atomic_int_set(&g_client->pending, 1);
ret = _disc_owned_devs(service, timeout);
{
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] Mullti Ownership Transfer");
/* If we are working now? */
- if (g_atomic_int_get(&service->pending))
+ if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
if (!uuid_str || !pin) {
}
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 1);
+ g_atomic_int_set(&g_client->pending, 1);
ret = _ma_mot(service, uuid_str, pin);
{
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] Provisioning ACL");
/* If we are working now? */
- if (g_atomic_int_get(&service->pending))
+ if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
if (!target || !subject || !rsrc_uri || !rsrc_type || !rsrc_interface) {
}
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 1);
+ g_atomic_int_set(&g_client->pending, 1);
ret = _acl(service, target, subject, rsrc_uri, rsrc_type, rsrc_interface, permission);
{
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] Provisioning Credential");
/* If we are working now? */
- if (g_atomic_int_get(&service->pending))
+ if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
if (!uuid_dev1 || !uuid_dev2) {
}
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 1);
+ g_atomic_int_set(&g_client->pending, 1);
ret = _cred(service, uuid_dev1, 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] Link Pairwise");
/* If we are working now? */
- if (g_atomic_int_get(&service->pending))
+ if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
if (!target_1 || !subject_1 || !rsrc_uri_1 || !rsrc_type_1 ||
}
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 1);
+ g_atomic_int_set(&g_client->pending, 1);
ret = _pairwise(service, target_1, subject_1, rsrc_uri_1,
rsrc_type_1, rsrc_interface_1, permission_1, target_2,
{
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");
/* If we are working now? */
- if (g_atomic_int_get(&service->pending))
+ if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
if (!uuid_dev1 || !uuid_dev2) {
}
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 1);
+ g_atomic_int_set(&g_client->pending, 1);
ret = _unlink(service, uuid_dev1, 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] Remove Mulltiple Ownership");
/* If we are working now? */
- if (g_atomic_int_get(&service->pending))
+ if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
if (!uuid_str) {
}
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 1);
+ g_atomic_int_set(&g_client->pending, 1);
ret = _ma_remove_mo(service, 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");
/* If we are working now? */
- if (g_atomic_int_get(&service->pending))
+ if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
if (!uuid_str) {
}
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 1);
+ g_atomic_int_set(&g_client->pending, 1);
ret = _ma_remove_cred_local(service, 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] Pair both device");
/* If we are working now? */
- if (g_atomic_int_get(&service->pending))
+ 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 ||
}
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 1);
+ g_atomic_int_set(&g_client->pending, 1);
ret = _pair(service, pin, target_1, subject_1, rsrc_uri_1,
rsrc_type_1, rsrc_interface_1, permission_1, target_2,
{
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] Unpair both devices");
/* If we are working now? */
- if (g_atomic_int_get(&service->pending))
+ if (g_atomic_int_get(&g_client->pending))
return MA_ERROR_IN_PROGRESS;
if (!uuid_dev1 || !uuid_dev2) {
}
/* Set d2ds status 'pending' */
- g_atomic_int_set(&service->pending, 1);
+ g_atomic_int_set(&g_client->pending, 1);
ret = _unpair(service, uuid_dev1, uuid_dev2);
int ma_request_disable(ma_service *service)
{
- int ret = OC_STACK_OK;
+ if (NULL == g_client)
+ return MA_ERROR_NONE;
+
+ return _disable(service);
+}
+
+int ma_delete_mot_agent(ma_service *service)
+{
+ int ret = MA_ERROR_NONE;
NOTUSED(service);
- if (!g_client)
+ if (NULL == g_client)
return MA_ERROR_NONE;
+ 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);
ret = OCStop();
g_mutex_unlock(&iotivity_mutex);
g_mutex_clear(&iotivity_mutex);
_remove_owned_client();
-
_remove_mot_client();
if (g_client->rnd_pin) {
g_free(g_client);
g_client = NULL;
-
- return MA_ERROR_NONE;
}