ADD_DEFINITIONS("-DTCP_ADAPTER")
MESSAGE(" - Start building src directories")
-ADD_SUBDIRECTORY(src/mot-agent)
ADD_SUBDIRECTORY(src/mdg-manager)
+++ /dev/null
-[Unit]
-Description=OCF MOT Agent
-Requires=dbus.socket
-After=dbus.socket
-
-[Service]
-Type=dbus
-User=network_fw
-Group=network_fw
-BusName=net.ma.enabler
-SmackProcessLabel=System
-ExecStart=/usr/bin/mot-agent
Source1: %{name}.manifest
Source2: mdgd.service
Source3: net.mdgd.service
-Source4: ma.service
-Source5: net.ma.service
BuildRequires: cmake
BuildRequires: pkgconfig(iotivity)
BuildRequires: pkgconfig(gmock)
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(capi-system-system-settings)
+Requires: capi-system-system-settings
%description
Multi Device Group Manager
chmod 644 %{SOURCE1}
chmod 644 %{SOURCE2}
chmod 644 %{SOURCE3}
-chmod 644 %{SOURCE4}
-chmod 644 %{SOURCE5}
cp %{SOURCE1} .
cp %{SOURCE2} .
cp %{SOURCE3} .
-cp %{SOURCE4} .
-cp %{SOURCE5} .
%build
mkdir -p %{buildroot}/etc/dbus-1/system.d/
mkdir -p %{buildroot}/opt/usr/data/network/lib
cp -af %{_builddir}/%{name}-%{version}/packaging/org.tizen.mdg.conf %{buildroot}/etc/dbus-1/system.d/
-cp -af %{_builddir}/%{name}-%{version}/packaging/net.ma.conf %{buildroot}/etc/dbus-1/system.d/
unrpm %{_builddir}/%{name}-%{version}/resources/*.rpm
cp -af ./usr/lib/libconnectivity_abstraction.so %{buildroot}/opt/usr/data/network/lib
cp -af ./usr/lib/liboc_logger.so %{buildroot}/opt/usr/data/network/lib
mkdir -p %{buildroot}%{_unitdir}
cp %{SOURCE2} %{buildroot}%{_unitdir}/mdgd.service
-cp %{SOURCE5} %{buildroot}%{_datadir}/dbus-1/system-services/net.ma.service
mkdir -p %{buildroot}%{_unitdir}
-cp %{SOURCE4} %{buildroot}%{_unitdir}/ma.service
%postun
rm -rf %{NETWORK_FW_DATADIR}/*.db
%manifest %{name}.manifest
%license LICENSE
%defattr(-,root,root,-)
-%{_bindir}/mot-agent
%{_bindir}/mdgd
%attr(644,root,root) %{_datadir}/dbus-1/system-services/*
%attr(644,root,root) %{_unitdir}/mdgd.service
-%attr(644,root,root) %{_unitdir}/ma.service
-%attr(644,network_fw,network_fw) %{NETWORK_FW_DATADIR}/oic_svr_db_ma.dat
%attr(644,network_fw,network_fw) %{NETWORK_FW_DATADIR}/oic_svr_db_mdgd_manager.dat
%attr(644,root,root) /etc/dbus-1/system.d/org.tizen.mdg.conf
-%attr(644,root,root) /etc/dbus-1/system.d/net.ma.conf
/opt/usr/data/network/lib/*.so
+++ /dev/null
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-
-<busconfig>
- <policy user="network_fw">
- <allow own="net.ma"/>
- </policy>
- <policy context="default">
- <deny own="net.ma"/>
- <allow send_destination="net.ma"/>
- </policy>
-</busconfig>
+++ /dev/null
-[D-BUS Service]
-Name=net.ma.enabler
-
-Exec=/bin/false
-User=network_fw
-Group=network_fw
-SystemdService=ma.service
/* Group Manangement */
int mdgd_group_create(const char* name);
-int mdgd_group_delete(const char* name);
+int mdgd_group_delete(char* name);
int mdgd_group_find(char *sender, int timeout);
int mdgd_group_find_device(char *sender, int timeout, bool is_invited);
-int mdgd_group_invite_device(char *sender, const char *group_name,
- mdgd_device_t *device, const char *pin);
-int mdgd_group_eject_device(char *sender, const char *group_name, const char *uuid);
+int mdgd_group_invite_device(char *sender, char *group_name,
+ mdgd_device_t *device, char *pin);
+int mdgd_group_eject_device(char *sender, char *group_name, char *uuid);
int mdgd_group_regist_channel(char *sender, char *channel_id);
int mdgd_group_unregist_channel(char *sender, char *channel_id);
#define MAX_FILE_PATH_LEN 1024
#define SVR_DB_FILE_NAME "oic_svr_db_mdgd_manager.dat"
+#define PRVN_DB_FILE_NAME "oic_pdm_mdgd.db"
+
#define SYSTEM_INFO_PLATFORM_VERSION "http://tizen.org/feature/platform.version"
#define SYSTEM_INFO_MANUF_NAME "http://tizen.org/system/manufacturer"
#define SYSTEM_INFO_MODEL_NAME "http://tizen.org/system/model_name"
int mdgd_iot_initialize();
int mdgd_iot_add_resource(mdgd_resource_type_e resource_type, const char *uri);
+int mdgd_iot_delete_resource(mdgd_resource_type_e resource_type, const char *uri);
int mdgd_iot_discovery_resource(mdgd_resource_type_e resource_type, void *user_data);
int mdgd_iot_get_device_description(mdgd_command_t *cmd, char *host_addr, int conn_type);
int mdgd_iot_send_response(char *sender, char *uuid, char *channel_id,
int msg_id, unsigned char *data, int len, bool timeout);
int mdgd_iot_set_preconfigured_pin(char *pin);
int mdgd_iot_remove_subowner(char *subject_id);
-int mdgd_iot_remove_secure_information(char *subject_id);
int mdgd_iot_deinitialize();
+int mdgd_iot_find_devices(char* sender, int timeout, bool is_invited);
+int mdgd_iot_pair(char *group_name, char *pin, char* target1, char *subject1, char *uri1,
+ char *rt1, char *interface1, int permission1, char* target2,
+ char *subject2, char *uri2, char *rt2, char *interface2, int permission2);
+int mdgd_iot_unpair(char *group_name, char *subowner_id, char *subowned_id);
+
#ifdef __cplusplus
}
#endif
} while (FALSE)
const char *mdgd_log_get_error_string(int result);
+const char* mdgd_log_get_iot_error_string(int result);
#ifdef __cplusplus
}
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
- #ifndef __MDGD_MOT_AGENT_H__
- #define __MDGD_MOT_AGENT_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int agent_dbus_start();
-int agent_dbus_stop();
-
-int agent_enable();
-int agent_disable();
-int agent_get_ownerid(char** deviceid);
-int agent_find_mot_enable_devices(char *sender, int timeout);
-int agent_find_mowned_devices(char *sender, int timeout);
-int agent_mot(char* uuid_str, char *pin);
-int agent_pair(char *sender, char *group_name, const char *pin, char* target1, const char *subject1, char *uri1,
- char *rt1, char *interface1, int permission1, const char* target2,
- char *subject2, char *uri2, char *rt2, char *interface2, int permission2);
-int agent_unpair(char *sender, char *group_name, char* uuid_str1, const char *uuid_str2);
-
-#ifdef __cplusplus
-}
-#endif
-
- #endif /* __MDGD_MOT_AGENT_H__ */
char *device_uuid;
mdgd_device_t *device;
sqlite3 *db;
- bool mot_me;
GDBusConnection *connection;
} mdgd_context_t;
mdgd_resource_type_e resource_type;
char *type;
char *uri_prefix;
- char *policies;
+ char policies;
} mdgd_rd_t;
#endif /* __MDGD_TYPEDEF_H__ */
#include <mdgd_log.h>
#include <base64.h>
+const char* mdgd_ocf_error_to_string(int err);
+char* mdgd_get_readable_uuid(const OicUuid_t* uuid);
char *mdgd_addr2host(char *addr, int port, bool is_secure);
int mdgd_uuid_to_str(const OicUuid_t* uuid, char** strUuid);
int mdgd_str_to_uuid(const char *strUuid, OicUuid_t* uuid);
GVariant *mdgd_create_variant_progress(char *file_path,
long send_size, long total_size, int percent);
GVariant *mdgd_create_variant_dummy();
-mdgd_device_t *mdg_get_device_from_variant(GVariant *va);
+mdgd_device_t *mdgd_get_device_from_variant(GVariant *va);
int mdgd_util_get_msg_id();
-
void mdgd_util_data_encode(const char *data, int data_len,
char **encoded_data, int *encoded_len);
return MDGD_ERROR_OUT_OF_MEMORY;
}
- mdgd_ctx->mot_me = false;
mdgd_ctx->channel = g_hash_table_new_full(g_str_hash, g_str_equal, __on_destroy, __on_destroy);
return MDGD_ERROR_NONE;
ret = sqlite3_prepare_v2(mdgd_ctx->db, sql, strlen(sql), &stmt, NULL);
if (ret == SQLITE_OK) {
while (sqlite3_step(stmt) == SQLITE_ROW)
- groups[i++] = g_strdup(sqlite3_column_text(stmt, 1));
+ groups[i++] = g_strdup((char *)sqlite3_column_text(stmt, 1));
sqlite3_finalize(stmt);
} else {
if (ret == SQLITE_OK) {
while (sqlite3_step(stmt) == SQLITE_ROW) {
devices[i] = g_new0(mdgd_device_t, 1);
- devices[i]->device_id = g_strdup(sqlite3_column_text(stmt, 2));
- devices[i]->model_name = g_strdup(sqlite3_column_text(stmt, 3));
- devices[i]->device_name = g_strdup(sqlite3_column_text(stmt, 4));
- devices[i]->platform_ver = g_strdup(sqlite3_column_text(stmt, 5));
- devices[i]->vendor_id = g_strdup(sqlite3_column_text(stmt, 6));
- devices[i]->profile = g_strdup(sqlite3_column_text(stmt, 7));
+ devices[i]->device_id = g_strdup((char *)sqlite3_column_text(stmt, 2));
+ devices[i]->model_name = g_strdup((char *)sqlite3_column_text(stmt, 3));
+ devices[i]->device_name = g_strdup((char *)sqlite3_column_text(stmt, 4));
+ devices[i]->platform_ver = g_strdup((char *)sqlite3_column_text(stmt, 5));
+ devices[i]->vendor_id = g_strdup((char *)sqlite3_column_text(stmt, 6));
+ devices[i]->profile = g_strdup((char *)sqlite3_column_text(stmt, 7));
devices[i]->is_invited = sqlite3_column_int(stmt, 8);
devices[i]->type = sqlite3_column_int(stmt, 9);
if (ret == SQLITE_OK) {
while (sqlite3_step(stmt) == SQLITE_ROW) {
char *group_name;
- group_name = g_strdup(sqlite3_column_text(stmt, 1));
+ group_name = g_strdup((char *)sqlite3_column_text(stmt, 1));
LOG_DEBUG("%d. %s", ++i, group_name);
}
while (sqlite3_step(stmt) == SQLITE_ROW) {
char *group_name;
char *device_id;
- group_name = g_strdup(sqlite3_column_text(stmt, 1));
- device_id = g_strdup(sqlite3_column_text(stmt, 2));
+ group_name = g_strdup((char *)sqlite3_column_text(stmt, 1));
+ device_id = g_strdup((char *)sqlite3_column_text(stmt, 2));
LOG_DEBUG("%d. %s, %s", ++i, group_name, device_id);
}
*
*/
-#include <mdgd_gdbus.h>
#include <sys/types.h>
-#include <mdgd_group.h>
+
#include <mdgd_db.h>
+#include <mdgd_util.h>
+#include <mdgd_gdbus.h>
+#include <mdgd_group.h>
static Group *group_skeleton;
static Enabler *enabler_skeleton;
LOG_BEGIN();
- result = mdgd_group_find(sender, timeout);
+ result = mdgd_group_find((char *)sender, timeout);
group_complete_find(group, invocation, result);
LOG_END();
LOG_BEGIN();
- result = mdgd_group_find_device(sender, timeout, is_invited);
+ result = mdgd_group_find_device((char *)sender, timeout, is_invited);
group_complete_find_device(group, invocation, result);
LOG_END();
mdgd_device_t *device = mdgd_get_device_from_variant(va);
- result = mdgd_group_invite_device(sender, group_name, device, pin);
+ result = mdgd_group_invite_device((char *)sender, group_name, device, pin);
group_complete_invite_device(group, invocation, result);
LOG_BEGIN();
- result = mdgd_group_eject_device(sender, group_name, uuid);
+ result = mdgd_group_eject_device((char *)sender, group_name, uuid);
group_complete_eject_device(group, invocation, result);
LOG_END();
{
int ret = MDGD_ERROR_NONE;
GVariant *va;
- mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
LOG_BEGIN();
LOG_BEGIN();
- ret = mdgd_group_regist_channel(sender, channel_id);
+ ret = mdgd_group_regist_channel((char *)sender, channel_id);
group_complete_regist_channel(group, invocation, ret);
LOG_BEGIN();
- ret = mdgd_group_unregist_channel(sender, channel_id);
+ ret = mdgd_group_unregist_channel((char *)sender, channel_id);
group_complete_unregist_channel(group, invocation, ret);
data = g_try_malloc0(len + 1);
if (NULL == data) {
- group_complete_send_data(group, invocation, -1, NULL);
+ group_complete_send_data(group, invocation, -1, 0);
LOG_ERR("Failed to allocate memory");
return TRUE;
}
g_variant_iter_free(iter);
- ret = mdgd_group_send_data(sender, uuid, channel_id, data, len, &msg_id);
+ ret = mdgd_group_send_data((char *)sender, uuid, channel_id, data, len, &msg_id);
group_complete_send_data(group, invocation, ret, msg_id);
g_variant_iter_free(iter);
- ret = mdgd_group_send_response(sender, uuid, channel_id, msg_id, data, len);
+ ret = mdgd_group_send_response((char *)sender, uuid, channel_id, msg_id, data, len);
group_complete_send_response(group, invocation, ret);
LOG_BEGIN();
- ret = mdgd_group_request(MDGD_REQ_SEND_FILE, sender, uuid,
+ ret = mdgd_group_request(MDGD_REQ_SEND_FILE, (char *)sender, uuid,
file_path, NULL, NULL, NULL);
group_complete_send_file(group, invocation, ret);
LOG_BEGIN();
- ret = mdgd_group_request(MDGD_REQ_CREATE_GROUP, sender, uuid,
+ ret = mdgd_group_request(MDGD_REQ_CREATE_GROUP, (char *)sender, uuid,
group_name, NULL, NULL, NULL);
group_complete_request_create_group(group, invocation, ret);
LOG_BEGIN();
- ret = mdgd_group_request(MDGD_REQ_INVITE_DEVICE, sender, uuid,
+ ret = mdgd_group_request(MDGD_REQ_INVITE_DEVICE, (char *)sender, uuid,
group_name, target_uuid, PIN, NULL);
group_complete_request_invite(group, invocation, ret);
LOG_BEGIN();
- ret = mdgd_group_request(MDGD_REQ_EJECT_DEVICE, sender, uuid,
+ ret = mdgd_group_request(MDGD_REQ_EJECT_DEVICE, (char *)sender, uuid,
group_name, target_uuid, NULL, NULL);
group_complete_request_eject(group, invocation, ret);
LOG_BEGIN();
- ret = mdgd_group_request(MDGD_REQ_CHANNEL_LIST, sender, uuid,
+ ret = mdgd_group_request(MDGD_REQ_CHANNEL_LIST, (char *)sender, uuid,
NULL, NULL, NULL, NULL);
group_complete_request_channel_list(group, invocation, ret);
gchar *preconfigured_pin, gpointer user_data)
{
int ret = MDGD_ERROR_NONE;
- const gchar *sender = g_dbus_method_invocation_get_sender(invocation);
LOG_BEGIN();
*/
#include <mdgd_group.h>
-#include <mdgd_mot_agent.h>
#include <mdgd_db.h>
#include <mdgd_context.h>
#include <mdgd_gdbus.h>
+#include <mdgd_iot.h>
int mdgd_group_create(const char* name)
{
return ret;
}
-int mdgd_group_delete(const char *name)
+int mdgd_group_delete(char *name)
{
int ret = MDGD_ERROR_NONE;
mdgd_device_t *devices[256];
for (int i = 0; i < device_count; i++) {
mdgd_db_device_delete(name, devices[i]->device_id);
- if (mdgd_db_check_device_exist(devices[i]) == false)
- agent_unpair("tmp", name, mdgd_ctx->device_uuid, devices[i]->device_id);
+ if (mdgd_db_check_device_exist((char *)devices[i]) == false)
+ mdgd_iot_unpair(name, mdgd_ctx->device_uuid, devices[i]->device_id);
}
/* delete group */
return ret;
}
+
static gboolean __timeout_cb(gpointer data)
{
int ret = MDGD_ERROR_NONE;
mdgd_command_t *cmd = (mdgd_command_t *)data;
- mdgd_check_null_ret("cmd", cmd);
+ if (!cmd) {
+ LOG_ERR("cmd is null");
+ return false;
+ }
LOG_BEGIN();
LOG_ERR("Unknown Resource Type");
LOG_END();
+
+ return G_SOURCE_REMOVE;
}
int mdgd_group_find(char *sender, int timeout)
cmd->resource_type = MDGD_RESOURCE_TYPE_DEVICE;
cmd->sender = g_strdup(sender);
- if (is_invited == false)
- ret = agent_find_mot_enable_devices(sender, timeout);
- else
- ret = agent_find_mowned_devices(sender, timeout);
-
+ ret = mdgd_iot_find_devices(sender, timeout, is_invited);
if (ret != MDGD_ERROR_NONE) {
LOG_ERR("Failed to find device : %s",
mdgd_log_get_error_string(ret));
#define FULL_PERMISSION 31
-int mdgd_group_invite_device(char *sender, const char *group_name,
- mdgd_device_t *device, const char *pin)
+int mdgd_group_invite_device(char *sender, char *group_name,
+ mdgd_device_t *device, char *pin)
{
int ret = MDGD_ERROR_NONE;
mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, MDGD_ERROR_INVALID_PARAMETER);
- if (mdgd_db_check_device_exist_in_group(group_name, device->device_id)) {
- ret = MDGD_ERROR_ALREADY_REGISTERED;
- } else {
- if (mdgd_db_check_device_exist(device->device_id) == false) {
- ret = agent_pair(sender, group_name, pin, mdgd_ctx->device_uuid, device->device_id, "/comp/data",
- "core.comp.data", "oic.if.baseline", FULL_PERMISSION, device->device_id,
- mdgd_ctx->device_uuid, "/comp/data", "core.comp.data",
- "oic.if.baseline", FULL_PERMISSION);
- } else {
- LOG_DEBUG("Already paired device. send invited event to remote device");
-
- mdgd_command_t *cmd = g_try_malloc0(sizeof(mdgd_command_t));
- if (NULL == cmd) {
- ret = MDGD_ERROR_OUT_OF_MEMORY;
- LOG_ERR("Failed to alloc memory");
- return ret;
- }
-
- cmd->resource_type = MDGD_RESOURCE_TYPE_DEVICE;
- cmd->type = MDGD_REQ_EVENT_INVITED;
- cmd->uuid = g_strdup(device->device_id);
- cmd->arg1 = g_strdup(group_name);
-
- mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DEVICE, cmd);
- }
-
- if (MDGD_ERROR_NONE == ret)
- mdgd_db_device_insert(group_name, device);
+ ret = mdgd_iot_pair(group_name, pin, mdgd_ctx->device_uuid, device->device_id, "/comp/data",
+ "core.comp.data", "oic.if.baseline", FULL_PERMISSION, device->device_id,
+ mdgd_ctx->device_uuid, "/comp/data", "core.comp.data",
+ "oic.if.baseline", FULL_PERMISSION);
+
+ if (ret == MDGD_ERROR_NONE && mdgd_db_check_device_exist_in_group(group_name, device->device_id) == false) {
+ mdgd_db_device_insert(group_name, device);
}
+ mdgd_group_notify_event(sender, MDGD_EVENT_INVITE_DEVICE_FINISH, ret, NULL);
+
LOG_END();
return ret;
}
-int mdgd_group_eject_device(char *sender, const char *group_name, const char *uuid)
+int mdgd_group_eject_device(char *sender, char *group_name, char *uuid)
{
int ret = MDGD_ERROR_NONE;
mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, MDGD_ERROR_INVALID_PARAMETER);
- if (mdgd_db_check_device_exist_in_group(group_name, uuid) == false) {
- ret = MDGD_ERROR_NO_DATA;
- } else {
+ ret = mdgd_iot_unpair(group_name, mdgd_ctx->device_uuid, uuid);
+ if (ret == MDGD_ERROR_NONE && mdgd_db_check_device_exist_in_group(group_name, uuid) == true) {
mdgd_db_device_delete(group_name, uuid);
- if (mdgd_db_check_device_exist(uuid) == false) {
- ret = agent_unpair(sender, group_name, mdgd_ctx->device_uuid, uuid);
- } else {
- LOG_DEBUG("Not yet unpaired device. send eject event to remote device");
-
- mdgd_command_t *cmd = g_try_malloc0(sizeof(mdgd_command_t));
- if (NULL == cmd) {
- ret = MDGD_ERROR_OUT_OF_MEMORY;
- LOG_ERR("Failed to alloc memory");
- return ret;
- }
-
- cmd->resource_type = MDGD_RESOURCE_TYPE_DEVICE;
- cmd->type = MDGD_REQ_EVENT_EJECTED;
- cmd->uuid = g_strdup(uuid);
- cmd->arg1 = g_strdup(group_name);
-
- mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DEVICE, cmd);
- }
}
+ mdgd_group_notify_event(sender, MDGD_EVENT_EJECT_DEVICE_FINISH, ret, NULL);
+
LOG_END();
return ret;
}
mdgd_gdbus_emit_event(sender, type, result, va);
+
+ return MDGD_ERROR_NONE;
}
#include <mdgd_iot.h>
#include <mdgd_group.h>
#include <mdgd_gdbus.h>
-#include <mdgd_mot_agent.h>
#include <mdgd_db.h>
+#include <mdgd_util.h>
#include "OCProvisioningManager.hpp"
#include "OCPlatform.h"
#include "OCApi.h"
#include "credresource.h"
-#include "aclresource.h"
using namespace OC;
using namespace std;
+#define DISCOVERY_TIMEOUT 6 /**< 6 sec */
+#define CALLBACK_TIMEOUT_5S 5 * 1000 /**< 5sec = 5 * 1000 * 1ms */
+#define CALLBACK_MARGIN 10 * 1000 /**< 10sec */
+#define TIME_UNIT 10 /**< Sleep time unit */
+
+bool g_doneCB;
+
+OCPersistentStorage ps;
+DeviceList_t g_motdev_list; /**< Discoverd MOT enabled devices list */
+DeviceList_t g_mowned_list; /**< My owned MOT enabled devices list */
+
+static OCStackResult _wait_cb_ret(int msec)
+{
+ OCStackResult ret = OC_STACK_OK;
+#ifndef THREAD_COND_WAIT_USED
+ int result = -1;
+ struct timespec tim, tim2;
+ tim.tv_sec = 0;
+ tim.tv_nsec = 100 * 1000000;
+#endif
+
+#ifdef THREAD_COND_WAIT_USED
+ void *result;
+ process_t proc;
+
+ ma_check_null_ret_error("g_client", g_client, OC_STACK_INVALID_PARAM);
+
+ strcpy(proc.name, "A\0");
+ proc.data = 0;
+ proc.waits = msec + CALLBACK_MARGIN;
+
+ if (0 != _init_proc(&proc, _exec_and_wait)) {
+ LOG_ERR("Fail to init proc [%s]", proc.name);
+ return OC_STACK_ERROR;
+ }
+ pthread_join(proc.thread, &result);
+#else
+ for (int i = 0; !g_doneCB && (msec + CALLBACK_MARGIN) >= i; i += TIME_UNIT) {
+
+ result = nanosleep(&tim, &tim2);
+ if (0 > result)
+ LOG_ERR("nanosleep failed=%d", errno);
+
+ ret = OCProcess();
+
+ if (OC_STACK_OK != ret) {
+ LOG_ERR("OCStack process error = %d", ret);
+ break;
+ }
+ }
+#endif
+ if (!g_doneCB) {
+ OCPDMCleanupForTimeout();
+ ret = OC_STACK_TIMEOUT;
+ }
+
+ return ret;
+}
+
static FILE* __client_open(const char* /*path*/, const char *mode)
{
char data_dir[MAX_FILE_PATH_LEN] = {0,};
}
}
-OCPersistentStorage ps;
-
int mdgd_iot_set_preconfigured_pin(char *pin)
{
int ret = MDGD_ERROR_NONE;
return ret;
}
-int mdgd_iot_remove_secure_information(char *subject_id)
+int mdgd_iot_find_devices(char* sender, int timeout, bool is_invited)
{
- int ret = MDGD_ERROR_NONE;
- OicUuid_t uuid;
+ int result = MDGD_ERROR_NONE;
+ DeviceList_t devList;
+ mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
- LOG_BEGIN();
+ if (is_invited == false) {
+ g_motdev_list.clear();
+ OCSecure::discoverMultipleOwnerEnabledDevices(timeout, g_motdev_list);
+ devList = g_motdev_list;
+ } else {
+ g_mowned_list.clear();
+ OCSecure::discoverMultipleOwnedDevices(timeout, g_mowned_list);
+ devList = g_mowned_list;
+ }
- LOG_DEBUG("Remove %s secure information", subject_id);
+ for (unsigned int i = 0; i < devList.size(); i++ ) {
- ret = mdgd_str_to_uuid(subject_id, &uuid);
- if (ret != OC_STACK_OK) {
- LOG_ERR("mdgd_str_to_uuid failed : %d", ret);
- return MDGD_ERROR_OPERATION_FAILED;
+ char *uuid_str = NULL;
+ OCProvisionDev_t *selDev = devList[i]->getDevPtr();
+ if (!selDev) {
+ LOG_ERR("getDevPtr() failed");
+ continue;
+ }
+
+ mdgd_uuid_to_str(&selDev->doxm->deviceID, &uuid_str);
+ if (!uuid_str) {
+ LOG_ERR("uuid_str is null");
+ continue;
+ }
+
+ LOG_DEBUG("!!!Device Found!!!");
+
+ if (strcmp(uuid_str, mdgd_ctx->device_uuid) == 0) {
+ LOG_DEBUG("Already Stored : Skip Local device");
+ continue;
+ }
+
+ if (is_invited == false) {
+ bool check_invited = false;
+ UuidList_t subOwnerList;
+ devList[i]->getSubOwnerList(subOwnerList);
+
+ for(unsigned int j = 0; j < subOwnerList.size(); j++) {
+ char *readable_uuid = mdgd_get_readable_uuid(&subOwnerList[j]);
+ LOG_DEBUG("remote owner uuid is %s", readable_uuid);
+
+ if (g_strcmp0(readable_uuid, uuid_str) == 0) {
+ check_invited = true;
+ break;
+ }
+ }
+
+ if (check_invited == true) {
+ LOG_DEBUG("The device is already invited. Skip the device");
+ continue;
+ }
+ }
+
+ mdgd_command_t *cmd = (mdgd_command_t *)g_try_malloc0(sizeof(mdgd_command_t));
+ mdgd_device_t *device = (mdgd_device_t *)g_try_malloc0(sizeof(mdgd_device_t));
+
+ int port = selDev->endpoint.port;
+ int conn_type = selDev->connType;
+ char *addr = g_strdup(selDev->endpoint.addr);
+ char *host_addr = mdgd_addr2host(addr, port, false);
+
+ device->device_id = uuid_str;
+ device->is_invited = is_invited;
+
+ cmd->sender = g_strdup(sender);
+ cmd->user_data = (void *)device;
+
+ mdgd_iot_get_device_description(cmd, host_addr, conn_type);
}
- ret = RemoveACE(&uuid, NULL);
- if (ret != OC_STACK_RESOURCE_DELETED) {
- LOG_ERR("remove Access Control Entity failed : %d", ret);
- return MDGD_ERROR_OPERATION_FAILED;
+ return result;
+}
+
+static OCProvisionDev_t* _get_dev_by_uuid(DeviceList_t &list, OicUuid_t *target)
+{
+ for (unsigned int i = 0; i < list.size(); i++ ) {
+ if (list[i]->getDeviceID().compare((const char *)target)) {
+ return list[i]->getDevPtr();
+ }
}
+ return nullptr;
+}
- ret = RemoveCredential(&uuid);
- if (ret != OC_STACK_RESOURCE_DELETED) {
- LOG_ERR("remove cred failed : %d", ret);
- return MDGD_ERROR_OPERATION_FAILED;
+static int _get_devid_by_uuid(DeviceList_t &list, OicUuid_t *target)
+{
+ char *t = mdgd_get_readable_uuid(target);
+ for (unsigned int i = 0; i < list.size(); i++ ) {
+ if (0 == list[i]->getDeviceID().compare(t)) {
+ return i;
+ }
}
+ return -1;
+}
- LOG_END();
+static OicUuid_t* _convert_uuid(gchar *device_id)
+{
+ OicUuid_t *uuid;
- return ret;
+ if (NULL == device_id)
+ return NULL;
+
+ uuid = (OicUuid_t *)g_malloc0(sizeof(struct OicUuid));
+ if (NULL == uuid) {
+ LOG_ERR("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;
+}
+
+static void _mot_cb(PMResultList_t *result, int has_error)
+{
+ LOG_DEBUG("Multiple Ownership Transfer Result = %d", has_error);
+ for (unsigned int i = 0; result && i < result->size(); i++) {
+ LOG_DEBUG("[%d] %s = [%d][%s]",
+ i,
+ mdgd_get_readable_uuid(&result->at(i).deviceId),
+ result->at(i).res,
+ mdgd_ocf_error_to_string(result->at(i).res));
+ }
+
+ g_doneCB = true;
+}
+
+int mdgd_iot_pair(char *group_name, char *pin, char* target1, char *subject1, char *uri1,
+ char *rt1, char *interface1, int permission1, char* target2,
+ char *subject2, char *uri2, char *rt2, char *interface2, int permission2)
+{
+ int idx1 = -1;
+ int idx2 = -1;
+
+ int result = MDGD_ERROR_NONE;
+ OCStackResult ret = OC_STACK_OK;
+ mdgd_command_t *cmd = NULL;
+
+ OicUuid_t *uuid_1 = NULL;
+ OicUuid_t *uuid_2 = NULL;
+ OicUuid_t *uuid_3 = NULL;
+ OicUuid_t *uuid_4 = NULL;
+
+ OicSecAcl_t* acl_1 = NULL;
+ OicSecAcl_t* acl_2 = NULL;
+
+ OCProvisionDev_t *target_dev_1 = NULL;
+ OCProvisionDev_t *target_dev_2 = NULL;
+ OCProvisionDev_t *subject_dev_1 = NULL;
+ OCProvisionDev_t *subject_dev_2 = NULL;
+
+ OCProvisionDev_t *src_dev = NULL;
+ OCProvisionDev_t *next_dev = NULL;
+
+ uuid_1 = _convert_uuid(target1);
+ target_dev_1 = _get_dev_by_uuid(g_motdev_list, uuid_1);
+ if (!target_dev_1) {
+ LOG_ERR("We can't find target in MOT enabled dev list");
+ goto PV_PAIR_END;
+ }
+
+ idx1 = _get_devid_by_uuid(g_motdev_list, uuid_1);
+ if (0 > idx1) {
+ LOG_ERR("We can't find in MOT dev list");
+ goto PV_PAIR_END;
+ }
+
+ uuid_2 = _convert_uuid(target2);
+ target_dev_2 = _get_dev_by_uuid(g_motdev_list, uuid_2);
+ if (!target_dev_2) {
+ LOG_ERR("We can't find target in MOT enabled dev list");
+ goto PV_PAIR_END;
+ }
+
+ idx2 = _get_devid_by_uuid(g_motdev_list, uuid_2);
+ if (0 > idx2) {
+ LOG_ERR("We can't find in MOT dev list");
+ goto PV_PAIR_END;
+ }
+
+ uuid_3 = _convert_uuid(subject1);
+ subject_dev_1 = _get_dev_by_uuid(g_motdev_list, uuid_3);
+ if (!subject_dev_1) {
+ LOG_ERR("We can't find subject in MOWNED dev list");
+ goto PV_PAIR_END;
+ }
+
+ uuid_4 = _convert_uuid(subject2);
+ subject_dev_2 = _get_dev_by_uuid(g_motdev_list, uuid_4);
+ if (!subject_dev_2) {
+ LOG_ERR("We can't find subject in MOWNED dev list");
+ goto PV_PAIR_END;
+ }
+
+ src_dev = _get_dev_by_uuid(g_motdev_list, uuid_2);
+ if (!src_dev) {
+ LOG_ERR("We can't find in MOT dev list");
+ goto PV_PAIR_END;
+ }
+
+ next_dev = src_dev->next;
+ src_dev->next = NULL;
+
+ g_doneCB = false;
+
+ LOG_DEBUG("MOT Start...");
+ if (OIC_PRECONFIG_PIN == target_dev_2->doxm->oxmSel) {
+ ret = g_motdev_list[idx2]->addPreconfigPIN(pin, strlen(pin));
+ if (OC_STACK_OK != ret) {
+ LOG_ERR("Failed to save the pre-configured PIN");
+ LOG_ERR("You can't use the pre-configured PIN OxM for MOT");
+ goto PV_PAIR_END;
+ }
+ }
+
+ ret = g_motdev_list[idx2]->doMultipleOwnershipTransfer(_mot_cb);
+ if (OC_STACK_OK != ret) {
+ LOG_ERR("doMultipleOwnershipTransfer: ret = %d (%s)",
+ ret, mdgd_log_get_iot_error_string(ret));
+ goto PV_PAIR_END;
+ }
+
+ ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
+ if (OC_STACK_OK != ret) {
+ LOG_ERR("doMultipleOwnershipTransfer callback error = %d (%s)",
+ ret, mdgd_log_get_iot_error_string(ret));
+ goto PV_PAIR_END;
+ }
+
+ LOG_DEBUG("MOT Done");
+
+ g_doneCB = false;
+
+ cmd = (mdgd_command_t *)g_try_malloc0(sizeof(mdgd_command_t));
+ cmd->resource_type = MDGD_RESOURCE_TYPE_DEVICE;
+ cmd->uuid = g_strdup(subject1);
+ cmd->arg1 = g_strdup(group_name);
+
+ if (result == MDGD_ERROR_NONE) {
+ cmd->type = MDGD_REQ_EVENT_INVITED;
+ mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DEVICE, cmd);
+ }
+
+PV_PAIR_END:
+ /* Restore MOT enabled devices */
+ if (src_dev)
+ src_dev->next = next_dev ;
+
+ /* Notify pair result */
+ if (uuid_1)
+ g_free(uuid_1);
+ if (uuid_2)
+ g_free(uuid_2);
+ if (uuid_3)
+ g_free(uuid_3);
+ if (uuid_4)
+ g_free(uuid_4);
+ if (acl_1)
+ OCDeleteACLList(acl_1);
+ if (acl_2)
+ OCDeleteACLList(acl_2);
+
+ return result;
+}
+
+static void _remove_cb(PMResultList_t *result, int has_error)
+{
+ LOG_DEBUG("Remove Device Result = %d", has_error);
+ for (unsigned int i = 0; result && i < result->size(); i++) {
+ LOG_DEBUG("[%d] %s = [%d][%s]",
+ i,
+ mdgd_get_readable_uuid(&result->at(i).deviceId),
+ result->at(i).res,
+ mdgd_ocf_error_to_string(result->at(i).res));
+ }
+ g_doneCB = true;
+}
+
+int mdgd_iot_unpair(char *group_name, char *subowner_id, char *subowned_id)
+{
+ int result = MDGD_ERROR_NONE;
+ OCStackResult ret = OC_STACK_OK;
+ mdgd_command_t *cmd = NULL;
+ std::string str(subowned_id);
+
+ if (NULL == subowner_id) {
+ LOG_ERR("dev1 is NULL");
+ goto PV_UNPAIR_END;
+ }
+
+ if (NULL == subowned_id) {
+ LOG_ERR("dev2 is NULL");
+ goto PV_UNPAIR_END;
+ }
+
+ LOG_DEBUG("Start Removing CRED for remote device at local SVR DB");
+ g_doneCB = false;
+
+ ret = OCSecure::removeDeviceWithUuid(CALLBACK_TIMEOUT_5S, str, _remove_cb);
+ if (OC_STACK_OK != ret) {
+ LOG_DEBUG("removeDeviceWithUuid API error = %d (%s)", ret,
+ mdgd_log_get_iot_error_string(ret));
+ goto PV_UNPAIR_END;
+ } else {
+ ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
+ if (OC_STACK_OK != ret) {
+ LOG_DEBUG("removeDeviceWithUuid Timeout = %d (%s)", ret,
+ mdgd_log_get_iot_error_string(ret));
+ goto PV_UNPAIR_END;
+ }
+ }
+
+ /* Disaply result result */
+ LOG_DEBUG("Removing CRED info. at local SVR DB Done");
+
+ /* Send Event to remote */
+ cmd = (mdgd_command_t *)g_try_malloc0(sizeof(mdgd_command_t));
+ cmd->resource_type = MDGD_RESOURCE_TYPE_DEVICE;
+ cmd->uuid = g_strdup(subowned_id);
+ cmd->arg1 = g_strdup(group_name);
+
+ if (result == MDGD_ERROR_NONE) {
+ cmd->type = MDGD_REQ_EVENT_EJECTED;
+ mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DEVICE, cmd);
+ }
+
+PV_UNPAIR_END:
+ return result;
}
int mdgd_iot_initialize()
/* Do Self-Ownership Transfer */
ret = OCSecure::configSelfOwnership();
if (OC_STACK_OK != ret ) {
- LOG_ERR( "OCConfigSelfOwnership() error = [%d][%s]", ret, get_error_message(ret));
+ LOG_ERR("OCConfigSelfOwnership() error = [%d][%s]", ret, get_error_message(ret));
}
mdgd_iot_add_resource(MDGD_RESOURCE_TYPE_GROUP, ""); //For Group
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);
+ "/opt/usr/data", PRVN_DB_FILE_NAME);
ret = OCInitPM(data_dir);
+ if (OC_STACK_OK != ret)
+ LOG_ERR("OCInitPM() error = [%d][%s]", ret, get_error_message(ret));
OCProvisionDev_t* motdev_list = NULL;
OCDiscoverMultipleOwnerEnabledDevices(1, &motdev_list);
char *model_name = NULL;
char *platform_ver = NULL;
char *profile = NULL;
- char *vendor_id = NULL;
system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEVICE_NAME, &device_name);
system_info_get_platform_string(SYSTEM_INFO_MODEL_NAME, &model_name);
#include <mdgd_iot.h>
#include <mdgd_group.h>
#include <mdgd_gdbus.h>
-#include <mdgd_mot_agent.h>
#include <mdgd_db.h>
#include <map>
serveraddr_v6.sin6_flowinfo = 0;
serveraddr_v6.sin6_scope_id = if_nametoindex("wlan0");
- sscanf(cmd->addr, "coaps://[%s", &tempaddr);
+ sscanf(cmd->addr, "coaps://[%s", (char *)tempaddr);
strtok(tempaddr, "%");
inet_pton(AF_INET6, tempaddr, &serveraddr_v6.sin6_addr);
serveraddr.sin_family = AF_INET;
serveraddr.sin_port = htons(PORT);
- sscanf(cmd->addr, "coaps://%s", &tempaddr);
+ sscanf(cmd->addr, "coaps://%s", (char *)tempaddr);
strtok(tempaddr, ":");
inet_pton(AF_INET, tempaddr, &serveraddr.sin_addr.s_addr);
static void __get_group_information(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode, void *user_data)
{
- int ret;
-
LOG_BEGIN();
try {
mdgd_check_null_ret("user_data", user_data);
mdgd_group_t *group = (mdgd_group_t *)user_data;
std::vector<std::string> group_list;
- int i;
+ unsigned int i;
if (!rep.getValue("GroupList", group_list)) {
LOG_ERR("GroupList not found in representation");
static gboolean _send_data_timeout_cb(gpointer data)
{
- int ret = MDGD_ERROR_NONE;
mdgd_data_t *send_data = (mdgd_data_t *)data;
LOG_BEGIN();
char* decoded_data;
int decoded_len, data_len = 0;
bool time_out;
- mdgd_data_t *send_data = (mdgd_data_t *)user_data;
LOG_BEGIN();
static bool _found_resource(std::shared_ptr<OCResource> resource,
void *user_data)
{
- int ret;
- char *resource_uri_path;
- char *resource_host;
char *resource_type = NULL;
- mdgd_group_type_e group_type;
std::string resourceURI;
OCRepresentation rep;
rep.setValue("CMD", cmd->type);
rep.setValue("DeviceID", std::string(mdgd_ctx->device_uuid));
rep.setValue("GroupName", std::string(cmd->arg1));
- rep.setValue("OwnerID", std::string(cmd->arg2));
resource->put(rep, QueryParamsMap(), std::bind(&__send_event_finish,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
void __get_device_description(const HeaderOptions& headerOptions,
const OCRepresentation& rep, const int eCode, void *user_data)
{
- int ret;
-
mdgd_check_null_ret("user_data", user_data);
- mdgd_command_t *cmd = (mdgd_command_t *)user_data;
LOG_BEGIN();
mdgd_check_null_ret("user_data", user_data);
mdgd_command_t *cmd = (mdgd_command_t *)user_data;
mdgd_device_t *device = (mdgd_device_t *)cmd->user_data;
- mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
std::string modelName;
std::string platformVer;
#include <mdgd_iot.h>
#include <mdgd_group.h>
#include <mdgd_gdbus.h>
-#include <mdgd_mot_agent.h>
#include <mdgd_db.h>
#include "OCProvisioningManager.hpp"
std::shared_ptr<OC::OCResourceResponse> pResponse;
} OCResourceResponse_t;
+
+map <string, OCResourceHandle> addedResList;
/* FILE Receive in thread */
static gpointer __file_receive_thread_func(gpointer user_data)
{
char *model_name = NULL;
char *platform_ver = NULL;
char *profile = NULL;
- char *vendor_id = NULL;
system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEVICE_NAME, &device_name);
system_info_get_platform_string(SYSTEM_INFO_MODEL_NAME, &model_name);
*/
break;
case MDGD_REQ_EJECT_DEVICE:
- LOG_DEBUG("Request eject device");
-
- if (!requestRep.getValue("GroupName", group_name))
- LOG_ERR("Group name not found");
- if (!requestRep.getValue("ID", uuid))
- LOG_ERR("UUID not found");
-
- LOG_DEBUG("group name : %s Self UUID : %s Target UUID : %s",
- group_name.c_str(),mdgd_ctx->device_uuid, uuid.c_str());
-
- result = mdgd_group_eject_device("tmp", group_name.c_str(),
- uuid.c_str());
+ {
+ char *group_name_str = strdup(group_name.c_str());
+ char *uuid_str = strdup(uuid.c_str());
+ LOG_DEBUG("Request eject device");
+
+ if (!requestRep.getValue("GroupName", group_name))
+ LOG_ERR("Group name not found");
+ if (!requestRep.getValue("ID", uuid))
+ LOG_ERR("UUID not found");
+
+ LOG_DEBUG("group name : %s Self UUID : %s Target UUID : %s",
+ group_name_str, mdgd_ctx->device_uuid, uuid_str);
+
+ result = mdgd_group_eject_device((char *)"tmp",
+ group_name_str, uuid_str);
+ free(group_name_str);
+ free(uuid_str);
+ }
break;
case MDGD_REQ_CHANNEL_LIST:
LOG_DEBUG("Request channel list");
} else if (requestType == "PUT") {
if (strcmp(resourceUri.c_str(),
mdgd_resource_get_uri_prefix(MDGD_RESOURCE_TYPE_DEVICE)) == 0) {
- int result = MDGD_ERROR_NONE;
int cmd;
- int event;
- std::string requester_id, group_name, owner_id;
+ std::string requester_id, group_name;
LOG_DEBUG("Request event occur");
else
LOG_DEBUG("group_name received %s", group_name.c_str());
- if (!requestRep.getValue("OwnerID", owner_id))
- LOG_ERR("device_id not found in representation");
- else
- LOG_DEBUG("group_name received %s", group_name.c_str());
-
mdgd_group_t *group = (mdgd_group_t *)g_try_malloc0(sizeof(mdgd_group_t));
group->device_id = g_strdup(requester_id.c_str());
group->group_name = g_strdup(group_name.c_str());
mdgd_group_notify_event(NULL, MDGD_EVENT_INVITED, MDGD_ERROR_NONE, (void *)group);
break;
case MDGD_REQ_EVENT_EJECTED:
- mdgd_iot_remove_subowner((char *)owner_id.c_str());
- mdgd_iot_remove_secure_information(group->device_id);
+ mdgd_iot_remove_subowner(group->device_id);
mdgd_group_notify_event(NULL, MDGD_EVENT_EJECTED, MDGD_ERROR_NONE, (void *)group);
break;
default:
return MDGD_ERROR_NONE;
}
+int mdgd_iot_delete_resource(mdgd_resource_type_e resource_type, const char *uri)
+{
+ std::string uri_path;
+
+ LOG_BEGIN();
+
+ uri_path = std::string(mdgd_resource_get_uri_prefix(resource_type)) +
+ std::string(uri);
+
+ LOG_DEBUG("[Delete] resource uri is %s", uri_path.c_str());
+
+ auto search = addedResList.find(uri_path);
+ if (search != addedResList.end()) {
+ LOG_DEBUG("[Saurav] Found resource handle");
+ try {
+ OCPlatform::unregisterResource(search->second);
+ addedResList.erase(uri_path);
+ LOG_DEBUG("[Saurav] Number of elements in hash %d",
+ addedResList.size());
+ } catch (std::exception& e) {
+ LOG_ERR("Exception occured in unregistering %s", e.what());
+ }
+ }
+
+ return MDGD_ERROR_NONE;
+}
+
*/
#include <mdgd_log.h>
+#include <octypes.h>
+
+#define CASE_TO_STR(x) case x: return #x;
+const char* mdgd_log_get_iot_error_string(int result)
+{
+ switch (result) {
+ 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_TOO_MANY_REQUESTS)
+ 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";
+ }
+}
const char *mdgd_log_get_error_string(int result)
{
#include <mdgd_resource.h>
#include <mdgd_gdbus.h>
#include <mdgd_db.h>
-#include <mdgd_mot_agent.h>
int main(int argc, char *argv[])
{
goto EXIT;
}
- //5. operation mgr initialize
- ret = agent_dbus_start();
- if (ret != MDGD_ERROR_NONE) {
- LOG_ERR("MOT agent interface initialize failed : %s",
- mdgd_log_get_error_string(ret));
- goto EXIT;
- }
- agent_enable();
-
//7. g main loop run
mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, MDGD_ERROR_INVALID_PARAMETER);
g_main_loop_run(mdgd_ctx->main_loop);
EXIT:
- //8. deinitialize phase
- agent_disable();
- ret = agent_dbus_stop();
- if (ret != MDGD_ERROR_NONE)
- LOG_ERR("MOT agent interface deinitialize failed : %s",
- mdgd_log_get_error_string(ret));
-
ret = mdgd_db_deinit();
if (ret != MDGD_ERROR_NONE)
LOG_ERR("COMP db deinitialize failed : %s", mdgd_log_get_error_string(ret));
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <mdgd_context.h>
-#include <mdgd_group.h>
-#include <mdgd_mot_agent.h>
-
-#define AGENT_SERVER_NAME "net.ma"
-#define AGENT_OBJECT_PATH "/net/ma"
-#define AGENT_SERVICE_INTERFACE "net.ma"
-
-#define AGENT_ENABLER_NAME "net.ma.enabler"
-#define AGENT_ENABLER_OBJ_PATH "/net/ma/enabler"
-#define AGENT_ENABLER_INTERFACE "net.ma.enabler"
-
-#define AGENT_DBUS_PROXY_TIMEOUT ((9.5 + 2) * 1000) /**< default timeout for GDBus */
-
-struct agent_s {
- GDBusProxy *gproxy_agent_service; /**< Proxy for MOT agent */
- gpointer dbus_connection; /**< Dbus connection for MOT agent */
- GCancellable *ca; /**< Cancellable for MOT agent */
- GList *dbus_sub_ids; /**< DBus ID for MOT agent */
-};
-struct agent_s agent; /**< MOT agent context */
-
-int agent_get_ownerid(char** deviceid)
-{
- GVariant *variant = NULL;
- int result = MDGD_ERROR_NONE;
- GError *error = NULL;
- if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
- LOG_ERR("I/O error");
- return MDGD_ERROR_IO_ERROR;
- }
-
- variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "get_ownerid",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
- if (variant) {
- g_variant_get(variant, "(si)", deviceid, &result);
- LOGD("get_ownerid status %s, 0x%x", *deviceid, result);
- } else if (error) {
- LOGE("Failed DBus call [%s]", error->message);
- g_error_free(error);
- return MDGD_ERROR_IO_ERROR;
- }
-
- return result;
-}
-
-static int _check_agent_vaild(void)
-{
- if (NULL == agent.dbus_connection || NULL == agent.gproxy_agent_service) {
- LOG_ERR("I/O error");
- return MDGD_ERROR_IO_ERROR;
- }
- return MDGD_ERROR_NONE;
-}
-
-int agent_find_mot_enable_devices(char* sender, int timeout)
-{
- GVariant *variant = NULL;
- int result = MDGD_ERROR_NONE;
- GError *error = NULL;
-
- result = _check_agent_vaild();
- if (MDGD_ERROR_NONE != result)
- return result;
-
- variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "disc_mot_enb_devs",
- g_variant_new("(si)", sender, timeout), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
- if (variant) {
- g_variant_get(variant, "(i)", &result);
- LOGD("disc_mot_enb_devs status 0x%x", result);
- } else if (error) {
- LOGE("Failed DBus call [%s]", error->message);
- g_error_free(error);
- /* Restart mot-agent */
- agent_enable();
- result = MDGD_ERROR_IO_ERROR;
- }
-
- return result;
-}
-
-int agent_find_mowned_devices(char* sender, int timeout)
-{
- GVariant *variant = NULL;
- int result = MDGD_ERROR_NONE;
- GError *error = NULL;
-
- result = _check_agent_vaild();
- if (MDGD_ERROR_NONE != result)
- return result;
-
- variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "disc_mowned_devs",
- g_variant_new("(si)", sender, timeout), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
- if (variant) {
- g_variant_get(variant, "(i)", &result);
- LOGD("disc_mowned_devs status 0x%x", result);
- } else if (error) {
- LOGE("Failed DBus call [%s]", error->message);
- g_error_free(error);
- /* Restart mot-agent */
- agent_enable();
- result = MDGD_ERROR_IO_ERROR;
- }
-
- return result;
-}
-
-int agent_mot(char* uuid_str, char *pin)
-{
- GVariant *variant = NULL;
- int result = MDGD_ERROR_NONE;
- GError *error = NULL;
-
- result = _check_agent_vaild();
- if (MDGD_ERROR_NONE != result)
- return result;
-
- variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "mot",
- g_variant_new("(ss)", uuid_str, pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
- if (variant) {
- g_variant_get(variant, "(i)", &result);
- if (result != MDGD_ERROR_NONE)
- LOGD("mot status 0x%x", result);
- } else if (error) {
- LOGE("Failed DBus call [%s]", error->message);
- g_error_free(error);
- /* Restart mot-agent */
- agent_enable();
- result = MDGD_ERROR_IO_ERROR;
- }
-
- return result;
-}
-
-int agent_pair(char* sender, char *group_name, const char *pin, char* target1, const char *subject1, char *uri1,
- char *rt1, char *interface1, int permission1, const char* target2,
- char *subject2, char *uri2, char *rt2, char *interface2, int permission2)
-{
- GVariant *variant = NULL;
- int result = MDGD_ERROR_NONE;
- GError *error = NULL;
-
- result = _check_agent_vaild();
- if (MDGD_ERROR_NONE != result)
- return result;
-
- variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "pair",
- g_variant_new("(ssssssssisssssi)", sender, group_name, pin,
- target1, subject1, uri1, rt1, interface1, permission1,
- target2, subject2, uri2, rt2, interface2, permission2),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
- if (variant) {
- g_variant_get(variant, "(i)", &result);
- LOGD("pair status 0x%x", result);
- } else if (error) {
- LOGE("Failed DBus call [%s]", error->message);
- g_error_free(error);
- /* Restart mot-agent */
- agent_enable();
- result = MDGD_ERROR_IO_ERROR;
- }
-
- return result;
-}
-
-int agent_unpair(char* sender, char *group_name, char* uuid_str1, const char *uuid_str2)
-{
- GVariant *variant = NULL;
- int result = MDGD_ERROR_NONE;
- GError *error = NULL;
-
- result = _check_agent_vaild();
- if (MDGD_ERROR_NONE != result)
- return result;
-
- variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "unpair",
- g_variant_new("(ssss)", sender, group_name, uuid_str1, uuid_str2), G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
- if (variant) {
- g_variant_get(variant, "(i)", &result);
- LOGD("remove_subowner status 0x%x", result);
- } else if (error) {
- LOGE("Failed DBus call [%s]", error->message);
- g_error_free(error);
- /* Restart mot-agent */
- agent_enable();
- result = MDGD_ERROR_IO_ERROR;
- }
-
- return result;
-}
-
-int agent_enable()
-{
- GVariant *variant = NULL;
- int result = MDGD_ERROR_NONE;
- GError *error = NULL;
-
- result = _check_agent_vaild();
- if (MDGD_ERROR_NONE != result)
- return result;
-
- variant = g_dbus_connection_call_sync(agent.dbus_connection,
- AGENT_ENABLER_NAME, AGENT_ENABLER_OBJ_PATH, AGENT_ENABLER_INTERFACE,
- "enable", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
- if (variant) {
- g_variant_get(variant, "(i)", &result);
- LOG_DEBUG("MOT Agent Enabled status 0x%x", result);
- } else if (error) {
- LOGE("Failed DBus call [%s]", error->message);
- g_error_free(error);
- /* Restart mot-agent */
- agent_enable();
- result = MDGD_ERROR_IO_ERROR;
- }
-
- return result;
-}
-
-int agent_disable()
-{
- GVariant *variant = NULL;
- int result = MDGD_ERROR_NONE;
- GError *error = NULL;
-
- result = _check_agent_vaild();
- if (MDGD_ERROR_NONE != result)
- return result;
-
- variant = g_dbus_connection_call_sync(agent.dbus_connection,
- AGENT_ENABLER_NAME, AGENT_ENABLER_OBJ_PATH, AGENT_ENABLER_INTERFACE,
- "disable", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
- if (variant) {
- g_variant_get(variant, "(i)", &result);
- LOG_DEBUG("MOT Agent Disabled status 0x%x", result);
- } else if (error) {
- LOGE("Failed DBus call [%s]", error->message);
- g_error_free(error);
- /* Restart mot-agent */
- agent_enable();
- result = MDGD_ERROR_IO_ERROR;
- }
- return result;
-}
-
-static int _close_gdbus_call()
-{
- /* CHECK: is connection ref count required? */
- g_object_unref(agent.dbus_connection);
- agent.dbus_connection = NULL;
-
- return MDGD_ERROR_NONE;
-}
-
-static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec,
- gpointer *userdata)
-{
- GDBusProxy *proxy = G_DBUS_PROXY(object);
- gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
-
- NOTUSED(userdata);
-
- LOG_DEBUG("Name owner notify [%s]", name_owner);
-
- if (NULL == name_owner)
- _close_gdbus_call();
-
- g_free(name_owner);
-}
-
-static int _create_gdbus_call()
-{
- int id;
- GError *error = NULL;
-
- if (agent.dbus_connection != NULL)
- return MDGD_ERROR_IN_PROGRESS;
-
- agent.dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (NULL == agent.dbus_connection) {
- if (error != NULL) {
- LOG_ERR("Failed to connect to the D-BUS daemon [%s]", error->message);
- g_error_free(error);
- }
- return MDGD_ERROR_IO_ERROR;
- }
-
- id = g_signal_connect(agent.dbus_connection, "notify::g-name-owner",
- G_CALLBACK(_dbus_name_owner_notify), &agent);
- if (0 == id) {
- LOGE("g_signal_connect() Fail");
- g_object_unref(agent.dbus_connection);
- agent.dbus_connection = NULL;
- return MDGD_ERROR_IO_ERROR;
- }
-
- return MDGD_ERROR_NONE;
-}
-
-static GDBusProxy *_get_proxy_service()
-{
- GDBusProxy *proxy = NULL;
-
- if (NULL == agent.gproxy_agent_service) {
- proxy = g_dbus_proxy_new_sync(agent.dbus_connection, G_DBUS_PROXY_FLAGS_NONE, NULL,
- AGENT_SERVER_NAME, AGENT_OBJECT_PATH, AGENT_SERVICE_INTERFACE,
- NULL, NULL);
- } else
- proxy = agent.gproxy_agent_service;
-
- return proxy;
-}
-
-static void _remove_device_cb(void* ctx, int num,
- OCProvisionResult_t* arr, bool has_error)
-{
- if (!has_error) {
- LOG_DEBUG("Remove CRED for mowned device SUCCEEDED");
- } else {
- LOG_DEBUG("Remove CRED for mowned device FAILED ");
- }
-}
-
-static void _agent_signal_handler(GDBusConnection *connection,
- const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
- const gchar *signal_name, GVariant *parameters, gpointer userdata)
-{
- int result = MDGD_ERROR_NONE;
- gchar *sender = NULL;
-
- LOG_BEGIN();
-
- mdgd_check_null_ret("userdata", userdata);
- LOG_DEBUG("signal received = %s", signal_name);
-
- if (0 == g_strcmp0(signal_name, "disc_mot_enb_devs_done") ||
- 0 == g_strcmp0(signal_name, "disc_mowned_devs_done")) {
- mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
- GVariant *device_info;
- GVariantIter *iter = NULL;
-
- mdgd_check_null_ret("mdgd_ctx", mdgd_ctx);
- mdgd_check_null_ret("parameters", parameters);
-
- /* create device handle from parameter */
- g_variant_get(parameters, "(saa{sv})", &sender, &iter);
- LOG_DEBUG("sender : %s", sender);
- while ((device_info = g_variant_iter_next_value(iter))) {
- mdgd_command_t *cmd = (mdgd_command_t *)g_try_malloc0(sizeof(mdgd_command_t));
- mdgd_device_t *device;
-
- cmd->sender = g_strdup(sender);
-
- GVariant *val = g_variant_lookup_value(device_info, "deviceId", G_VARIANT_TYPE_STRING);
- gsize len = 0;
- const char *device_id = g_variant_get_string(val, &len);
-
- LOG_DEBUG("!!!Device Found!!!");
-
- if (strcmp(device_id, mdgd_ctx->device_uuid) == 0) {
- LOG_DEBUG("Already Stored : Skip Local device");
-
- if (mdgd_ctx->mot_me == false) {
- agent_mot(mdgd_ctx->device_uuid, "12341234");
- mdgd_ctx->mot_me = true;
- }
-
- continue;
- }
-
- device = (mdgd_device_t *)g_try_malloc0(sizeof(mdgd_device_t));
-
- LOG_DEBUG("deviceId = %s", device_id);
- device->device_id = g_strdup(device_id);
-
- val = g_variant_lookup_value(device_info, "port", G_VARIANT_TYPE_UINT16);
- int port = g_variant_get_uint16(val);
- LOG_DEBUG("port = %d", port);
-
- val = g_variant_lookup_value(device_info, "addr", G_VARIANT_TYPE_STRING);
- const char *addr = g_variant_get_string(val, &len);
- LOG_DEBUG("addr = %s", addr);
-
- char *host_addr = mdgd_addr2host(addr, port, false);
-
- val = g_variant_lookup_value(device_info, "connType", G_VARIANT_TYPE_UINT32);
- int conn_type = g_variant_get_uint32(val);
- LOG_DEBUG("connType = %d", conn_type);
-
- if (!strncmp(signal_name, "disc_mot_enb_devs_done", strlen(signal_name))) {
- device->is_invited = false;
- LOG_DEBUG("The device is mot enabled device");
- } else {
- device->is_invited = true;
- LOG_DEBUG("The device is mowned device");
- }
-
- cmd->user_data = (void *)device;
-
- mdgd_iot_get_device_description(cmd, host_addr, conn_type);
- }
- } else if (0 == g_strcmp0(signal_name, "pair_done") ||
- 0 == g_strcmp0(signal_name, "unpair_done")) {
- char *device_id;
- char *group_name;
-
- g_variant_get(parameters, "(sssi)", &sender, &device_id, &group_name, &result);
-
- mdgd_command_t *cmd = g_try_malloc0(sizeof(mdgd_command_t));
- cmd->resource_type = MDGD_RESOURCE_TYPE_DEVICE;
- cmd->uuid = g_strdup(device_id);
- cmd->arg1 = g_strdup(group_name);
-
- char *mot_agent_id = NULL;
- agent_get_ownerid(&mot_agent_id);
- cmd->arg2 = g_strdup(mot_agent_id);
-
- LOG_DEBUG("%s, %s, %s", device_id, group_name, mot_agent_id);
-
- if (0 == g_strcmp0(signal_name, "pair_done")) {
- if (result == MDGD_ERROR_NONE) {
- cmd->type = MDGD_REQ_EVENT_INVITED;
- mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DEVICE, cmd);
- } else {
- mdgd_db_device_delete(group_name, device_id);
- }
- mdgd_group_notify_event(sender, MDGD_EVENT_INVITE_DEVICE_FINISH, result, NULL);
- } else if (0 == g_strcmp0(signal_name, "unpair_done")) {
- if (result == MDGD_ERROR_NONE) {
- cmd->type = MDGD_REQ_EVENT_EJECTED;
-
- //mdgd_iot_remove_secure_information(cmd->uuid);
- OicUuid_t owned_uuid;
- mdgd_str_to_uuid(cmd->uuid, &owned_uuid);
- int ret = OCRemoveDeviceWithUuid(NULL, 5, &owned_uuid,
- _remove_device_cb);
-
- mdgd_iot_discovery_resource(MDGD_RESOURCE_TYPE_DEVICE, cmd);
- }
-
- mdgd_group_notify_event(sender, MDGD_EVENT_EJECT_DEVICE_FINISH, result, NULL);
- }
- }
-
- LOG_END();
-}
-static int _subscribe_event()
-{
- unsigned int id;
- struct agent_s *h = &agent;
-
- /* subowner_enabled */
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
- "subowner_enabled", AGENT_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
- if (0 == id) {
- LOG_ERR("g_dbus_connection_signal_subscribe(subowner_enabled) Fail(%d)", errno);
- return -1;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-
- /* disc_mot_enb_devs_done */
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
- "disc_mot_enb_devs_done", AGENT_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
- if (0 == id) {
- LOG_ERR("g_dbus_connection_signal_subscribe(disc_mot_enb_devs_done) Fail(%d)", errno);
- return -1;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-
- /* disc_mowned_devs_done */
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
- "disc_mowned_devs_done", AGENT_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
- if (0 == id) {
- LOG_ERR("g_dbus_connection_signal_subscribe(disc_mowned_devs_done) Fail(%d)", errno);
- return -1;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-
- /* mot_done */
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
- "mot_done", AGENT_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
- if (0 == id) {
- LOG_ERR("g_dbus_connection_signal_subscribe(mot_done) Fail(%d)", errno);
- return -1;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-
- /* acl_done */
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
- "acl_done", AGENT_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
- if (0 == id) {
- LOG_ERR("g_dbus_connection_signal_subscribe(acl_done) Fail(%d)", errno);
- return -1;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-
- /*cred_done */
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
- "cred_done", AGENT_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
- if (0 == id) {
- LOG_ERR("g_dbus_connection_signal_subscribe(cred_done) Fail(%d)", errno);
- return -1;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-
- /* remove_mo_done */
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
- "remove_mo_done", AGENT_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
- if (0 == id) {
- LOG_ERR("g_dbus_connection_signal_subscribe(remove_mo_done) Fail(%d)", errno);
- return -1;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-
- /* remove_cred_local_done */
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
- "remove_cred_local_done", AGENT_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
- if (0 == id) {
- LOG_ERR("g_dbus_connection_signal_subscribe(remove_cred_local_done) Fail(%d)", errno);
- return -1;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-
- /*pair_done */
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
- "pair_done", AGENT_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
- if (0 == id) {
- LOG_ERR("g_dbus_connection_signal_subscribe(pair_done) Fail(%d)", errno);
- return -1;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-
- /*unpair_done */
- id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
- "unpair_done", AGENT_OBJECT_PATH, NULL,
- G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
- if (0 == id) {
- LOG_ERR("g_dbus_connection_signal_subscribe(unpair_done) Fail(%d)", errno);
- return -1;
- }
- h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
-
- return 0;
-}
-
-static void _on_unsubscribe_ids(gpointer data, gpointer userdata)
-{
- unsigned int id = GPOINTER_TO_UINT(data);
- struct agent_s *h = (struct agent_s*)userdata;
- if (NULL == h) {
- LOG_ERR("Invaild parameter");
- return;
- }
- g_dbus_connection_signal_unsubscribe(h->dbus_connection, id);
-}
-static void _unsubscribe_event()
-{
- g_list_foreach(agent.dbus_sub_ids, _on_unsubscribe_ids, &agent);
- g_list_free(agent.dbus_sub_ids);
- agent.dbus_sub_ids = NULL;
-}
-
-int agent_dbus_start()
-{
- int ret = MDGD_ERROR_NONE;
-
- ret = _create_gdbus_call();
- if (MDGD_ERROR_NONE != ret)
- return ret;
-
- agent.ca = g_cancellable_new();
-
- /* Create all proxies here */
- agent.gproxy_agent_service = _get_proxy_service();
- if (NULL == agent.gproxy_agent_service) {
- LOG_ERR("Couldn't get _get_proxy_service");
- return MDGD_ERROR_IO_ERROR;
- }
-
- g_dbus_proxy_set_default_timeout(
- G_DBUS_PROXY(agent.gproxy_agent_service), AGENT_DBUS_PROXY_TIMEOUT);
-
- /* Subscribe events */
- _subscribe_event();
-
- return MDGD_ERROR_NONE;
-}
-
-int agent_dbus_stop()
-{
- int ret = MDGD_ERROR_NONE;
-
- _unsubscribe_event();
-
- /* Unref all proxies here */
- if (agent.gproxy_agent_service) {
- g_object_unref(agent.gproxy_agent_service);
- agent.gproxy_agent_service = NULL;
- }
-
- g_cancellable_cancel(agent.ca);
- g_object_unref(agent.ca);
- agent.ca = NULL;
-
- ret = _close_gdbus_call();
- return ret;
-}
-
* limitations under the License.
*
*/
-
-#include <mdgd_util.h>
#include <time.h>
+#include <mdgd_db.h>
+#include <mdgd_util.h>
+
+#define CASE_TO_STR(x) case x: return #x;
+const char* mdgd_ocf_error_to_string(int 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_TOO_MANY_REQUESTS)
+ 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";
+ }
+}
+
+char g_uuid_str[256] = {0};
+char* mdgd_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;
+}
char *mdgd_addr2host(char *addr, int port, bool is_secure)
{
mdgd_device_t *mdgd_get_device_from_variant(GVariant *va)
{
char *device_id = NULL;
- char *addr = NULL;
- int port;
- int secure_port;
- int conn_type;
char *model_name = NULL;
char *device_name = NULL;
char *platform_ver = NULL;
{
#ifdef SUPPORT_BASE64_ENCODING
size_t out_size;
- uint8_t *out;
+ char *out;
out_size = B64ENCODE_OUT_SAFESIZE(data_len + 1);
- out = (char *)g_malloc0(out_size);
+ out = g_malloc0(out_size);
if (NULL == out) {
LOG_ERR("Can't allocate memory for base64 str");
return;
}
- if (B64_OK != b64Encode(data, data_len, out, out_size, encoded_len)) {
+ if (B64_OK != b64Encode(
+ (const uint8_t*)data,
+ (const size_t)data_len,
+ out,
+ (const size_t)out_size,
+ (uint32_t *)&encoded_len)) {
LOG_ERR("Base64 encoding failed.");
g_free(out);
return;
{
#ifdef SUPPORT_BASE64_ENCODING
size_t out_size;
- uint8_t *out;
+ char *out;
out_size = B64DECODE_OUT_SAFESIZE(data_len + 1);
- out = (uint8_t *)g_try_malloc0(out_size);
+ out = g_try_malloc0(out_size);
if (NULL == out) {
LOG_ERR("Can't allocate memory for base64 str");
return;
}
- if (B64_OK != b64Decode(data, data_len, out, out_size, decoded_len)) {
+ if (B64_OK != b64Decode((const char *)data,
+ (const size_t)data_len,
+ (uint8_t *)out,
+ (const size_t)out_size,
+ (uint32_t *)&decoded_len)) {
LOG_ERR("Base64 decoding failed.");
g_free(out);
return;
+++ /dev/null
-MESSAGE("===================================================================")
-MESSAGE("Building...MOT client")
-MESSAGE("===================================================================")
-SET(CMAKE_INSTALL_RPATH "/opt/usr/data/network/lib")
-SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
-
-SET(INTROSPECTION_PATH ${CMAKE_CURRENT_SOURCE_DIR}/introspection)
-ADD_CUSTOM_COMMAND(
- OUTPUT dbus1
- COMMAND gdbus-codegen
- --interface-prefix net.ma.
- --generate-c-code ma-generated-code
- --c-generate-object-manager
- --generate-docbook generated-docs
- ${INTROSPECTION_PATH}/ma.xml
- ${INTROSPECTION_PATH}/enabler.xml
- COMMENT "Generating MOT agent GDBus .c/.h"
-)
-
-MESSAGE(" - Check cmake packagesion")
-pkg_check_modules(ma_pkgs REQUIRED ${COMMON_DEPS} ${TIZEN_DEPS}
- capi-network-wifi-manager
- sqlite3
- )
-
-ADD_CUSTOM_TARGET(GENERATED_MA_DBUS_CODE DEPENDS dbus1)
-MESSAGE(" - Set source folder")
-FILE(GLOB MOT_AGENT_SRCS *.c)
-SET(MOT_AGENT_SRCS ${MOT_AGENT_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/ma-generated-code.c)
-SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/ma-generated-code.c PROPERTIES GENERATED TRUE)
-
-INCLUDE_DIRECTORIES(${ma_pkgs_INCLUDE_DIRS})
-LINK_DIRECTORIES(${ma_pkgs_LIBRARY_DIRS})
-
-SET(MOT_AGENT "mot-agent")
-ADD_EXECUTABLE(${MOT_AGENT} ${MOT_AGENT_SRCS})
-ADD_DEPENDENCIES(${MOT_AGENT} GENERATED_MA_DBUS_CODE)
-TARGET_LINK_LIBRARIES(${MOT_AGENT} ${ma_pkgs_LIBRARIES} pthread)
-INSTALL(TARGETS ${MOT_AGENT} DESTINATION bin)
-INSTALL(FILES oic_svr_db_ma.dat DESTINATION ${NETWORK_FW_DATADIR})
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<!DOCTYPE node PUBLIC
- "-//freedesktop//DTD D-Bus Object Introspection 1.0//EN"
- "http://standards.freedesktop.org/dbus/1.0/introspect.dtd">
-
-<node>
- <interface name="net.ma.enabler">
- <!-- Method definitions -->
- <method name="enable">
- <arg type="i" name="result" direction="out"/>
- </method>
- <method name="disable">
- <arg type="i" name="result" direction="out"/>
- </method>
- </interface>
-</node>
+++ /dev/null
-gdbus-codegen --interface-prefix net.ma. \
- --generate-c-code ma-generated-code \
- --c-generate-object-manager \
- --generate-docbook generated-docs \
- ma.xml \
- enabler.xml
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>\r
-\r
-<!DOCTYPE node PUBLIC\r
- "-//freedesktop//DTD D-Bus Object Introspection 1.0//EN"\r
- "http://standards.freedesktop.org/dbus/1.0/introspect.dtd">\r
-\r
-<node>\r
- <interface name="net.ma">\r
- <!-- Method definitions -->\r
- <method name="get_ownerid">\r
- <arg type="s" name="devownerid" direction="out"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
- <method name="disc_mot_enb_devs">\r
- <arg type="s" name="sender" direction="in"/>\r
- <arg type="i" name="timeout" direction="in"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
- <method name="disc_mowned_devs">\r
- <arg type="s" name="sender" direction="in"/>\r
- <arg type="i" name="timeout" direction="in"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
- <method name="mot">\r
- <arg type="s" name="target" direction="in"/>\r
- <arg type="s" name="pin" direction="in"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
- <method name="remove_subowner">\r
- <arg type="s" name="target" direction="in"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
- <method name="remove_device">\r
- <arg type="s" name="target" direction="in"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
- <method name="acl">\r
- <arg type="s" name="target" direction="in"/>\r
- <arg type="s" name="subject" direction="in"/>\r
- <arg type="s" name="uri" direction="in"/>\r
- <arg type="s" name="rt" direction="in"/>\r
- <arg type="s" name="interface" direction="in"/>\r
- <arg type="i" name="permission" direction="in"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
- <method name="cred">\r
- <arg type="s" name="dev1" direction="in"/>\r
- <arg type="s" name="dev2" direction="in"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
- <method name="pairwise">\r
- <arg type="s" name="target_1" direction="in"/>\r
- <arg type="s" name="subject_1" direction="in"/>\r
- <arg type="s" name="uri_1" direction="in"/>\r
- <arg type="s" name="rt_1" direction="in"/>\r
- <arg type="s" name="interface_1" direction="in"/>\r
- <arg type="i" name="permission_1" direction="in"/>\r
- <arg type="s" name="target_2" direction="in"/>\r
- <arg type="s" name="subject_2" direction="in"/>\r
- <arg type="s" name="uri_2" direction="in"/>\r
- <arg type="s" name="rt_2" direction="in"/>\r
- <arg type="s" name="interface_2" direction="in"/>\r
- <arg type="i" name="permission_2" direction="in"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
- <method name="unlink">\r
- <arg type="s" name="uuid_dev1" direction="in"/>\r
- <arg type="s" name="uuid_dev2" direction="in"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
- <method name="pair">\r
- <arg type="s" name="sender" direction="in"/>\r
- <arg type="s" name="group_name" direction="in"/>\r
- <arg type="s" name="pin" direction="in"/>\r
- <arg type="s" name="target_1" direction="in"/>\r
- <arg type="s" name="subject_1" direction="in"/>\r
- <arg type="s" name="uri_1" direction="in"/>\r
- <arg type="s" name="rt_1" direction="in"/>\r
- <arg type="s" name="interface_1" direction="in"/>\r
- <arg type="i" name="permission_1" direction="in"/>\r
- <arg type="s" name="target_2" direction="in"/>\r
- <arg type="s" name="subject_2" direction="in"/>\r
- <arg type="s" name="uri_2" direction="in"/>\r
- <arg type="s" name="rt_2" direction="in"/>\r
- <arg type="s" name="interface_2" direction="in"/>\r
- <arg type="i" name="permission_2" direction="in"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
- <method name="unpair">\r
- <arg type="s" name="sender" direction="in"/>\r
- <arg type="s" name="group_name" direction="in"/>\r
- <arg type="s" name="owner_uuid" direction="in"/>\r
- <arg type="s" name="owned_uuid" direction="in"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
-\r
- <!-- Signal (D-Bus) definitions -->\r
- <signal name="subowner_enabled">\r
- <arg type="i" name="result" direction="out"/>\r
- </signal>\r
- <signal name="disc_mot_enb_devs_done">\r
- <arg type="s" name="sender" direction="out"/>\r
- <arg type="aa{sv}" name="list" direction="out"/>\r
- </signal>\r
- <signal name="disc_mowned_devs_done">\r
- <arg type="s" name="sender" direction="out"/>\r
- <arg type="aa{sv}" name="list" direction="out"/>\r
- </signal>\r
- <signal name="mot_done">\r
- <arg type="i" name="result" direction="out"/>\r
- </signal>\r
- <signal name="remove_mo_done">\r
- <arg type="i" name="result" direction="out"/>\r
- </signal>\r
- <signal name="remove_cred_local_done">\r
- <arg type="i" name="result" direction="out"/>\r
- </signal>\r
- <signal name="acl_done">\r
- <arg type="i" name="result" direction="out"/>\r
- </signal>\r
- <signal name="cred_done">\r
- <arg type="i" name="result" direction="out"/>\r
- </signal>\r
- <signal name="pairwise_done">\r
- <arg type="i" name="result" direction="out"/>\r
- </signal>\r
- <signal name="unlink_done">\r
- <arg type="i" name="result" direction="out"/>\r
- </signal>\r
- <signal name="pair_done">\r
- <arg type="s" name="sender" direction="out"/>\r
- <arg type="s" name="device_id" direction="out"/>\r
- <arg type="s" name="group_name" direction="out"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </signal>\r
- <signal name="unpair_done">\r
- <arg type="s" name="sender" direction="out"/>\r
- <arg type="s" name="device_id" direction="out"/>\r
- <arg type="s" name="group_name" direction="out"/>\r
- <arg type="i" name="result" direction="out"/>\r
- </signal>\r
- </interface>\r
-</node>\r
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __MA_LOG_H__
-#define __MA_LOG_H__
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#ifdef USE_DLOG
-#include <dlog/dlog.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "MOT_AGENT"
-
-#define MA_LOGV(format, arg...) LOGD(format, ##arg)
-#define MA_LOGD(format, arg...) LOGD(format, ##arg)
-#define MA_LOGI(format, arg...) LOGI(format, ##arg)
-#define MA_LOGW(format, arg...) LOGW(format, ##arg)
-#define MA_LOGE(format, arg...) LOGE(format, ##arg)
-#define MA_LOGF(format, arg...) LOGE(format, ##arg)
-
-#define __MA_LOG_FUNC_ENTER__ LOGD("Enter")
-#define __MA_LOG_FUNC_EXIT__ LOGD("Quit")
-
-#define MA_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, MA_LOG_TAG, format, ##args)
-#define MA_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, MA_LOG_TAG, format, ##args)
-#else /* USE_DLOG */
-
-#define MA_LOGV(format, args...)
-#define MA_LOGD(format, args...)
-#define MA_LOGI(format, args...)
-#define MA_LOGW(format, args...)
-#define MA_LOGE(format, args...)
-#define MA_LOGF(format, args...)
-
-#define __MA_LOG_FUNC_ENTER__
-#define __MA_LOG_FUNC_EXIT__
-
-#define MA_SECLOGI(format, args...)
-#define MA_SECLOGD(format, args...)
-
-#endif /* USE_DLOG */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __MA_LOG_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <glib.h>
-
-#include "ma.h"
-#include "ma-log.h"
-#include "ma-util.h"
-#include "ma-service.h"
-#include "ma-subowner.h"
-#include "ma-service-interface.h"
-#include "ma-generated-code.h"
-
-static NetMa *ma_dbus_object;
-static Enabler *ma_activator_dbus_object;
-
-/* global list to care resource handle for each client */
-static GList *ma_dbus_client_list;
-static GMutex ma_dbus_client_list_mutex;
-
-typedef struct _ma_dbus_client_s {
- gchar *bus_name;
-} ma_dbus_client_s;
-
-NetMa* ma_dbus_get_object()
-{
- return ma_dbus_object;
-}
-
-static int _ma_dbus_client_list_cleanup(GList *client_list)
-{
- ma_dbus_client_s *client;
-
- ma_check_null_ret_error("client_list", client_list, FALSE);
-
- client = client_list->data;
-
- g_free(client->bus_name);
- client->bus_name = NULL;
- g_free(client);
- g_list_free(client_list);
-
- return MA_ERROR_NONE;
-}
-
-static int _ma_dbus_client_list_compare_bus_name(const void *a, const void *b)
-{
- const ma_dbus_client_s *client = a;
- return g_strcmp0(client->bus_name, b);
-}
-
-static inline GList* _ma_dbus_client_list_find_client(const gchar *owner)
-{
- return g_list_find_custom(ma_dbus_client_list, owner,
- _ma_dbus_client_list_compare_bus_name);
-}
-
-static void _ma_dbus_name_owner_changed_cb(GDBusConnection *conn,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- int ret;
- GList *client = NULL;
- gchar *name, *old_owner, *new_owner;
-
- NOTUSED(conn);
- NOTUSED(sender_name);
- NOTUSED(object_path);
- NOTUSED(interface_name);
- NOTUSED(signal_name);
- NOTUSED(user_data);
-
- g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
-
- if (0 == strlen(new_owner)) {
- g_mutex_lock(&ma_dbus_client_list_mutex);
- client = _ma_dbus_client_list_find_client(old_owner);
- if (client) { /* found bus name in our bus list */
- MA_LOGD("bus(%s) stopped", old_owner);
- ma_dbus_client_list = g_list_remove_link(ma_dbus_client_list, client);
- }
- g_mutex_unlock(&ma_dbus_client_list_mutex);
-
- if (client) {
- ret = _ma_dbus_client_list_cleanup(client);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("_ma_dbus_client_list_cleanup() Fail(%d)", ret);
- }
- }
-}
-
-static int _ma_dbus_subscribe_name_owner_changed(GDBusConnection *conn)
-{
- unsigned int id;
-
- id = g_dbus_connection_signal_subscribe(conn,
- "org.freedesktop.DBus", /* bus name */
- "org.freedesktop.DBus", /* interface */
- "NameOwnerChanged", /* member */
- "/org/freedesktop/DBus", /* path */
- NULL, /* arg0 */
- G_DBUS_SIGNAL_FLAGS_NONE,
- _ma_dbus_name_owner_changed_cb,
- NULL,
- NULL);
- if (0 == id) {
- MA_LOGE("g_dbus_connection_signal_subscribe() Fail");
- return MA_ERROR_IO_ERROR;
- }
-
- return MA_ERROR_NONE;
-}
-
-static gboolean _ma_dbus_handle_get_ownerid(NetMa *object,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
-{
- gchar *uuid_str = NULL;
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
- ret = ma_request_get_ownerid(service, &uuid_str);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_get_ownerid [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- MA_LOGE("Owner ID is %s", uuid_str);
-
- net_ma_complete_get_ownerid(object, invocation, uuid_str, ret);
-
- if (uuid_str)
- g_free(uuid_str);
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_disc_mot_enb_devs(NetMa *object,
- GDBusMethodInvocation *invocation,
- gchar *sender,
- gint timeout,
- gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
- ret = ma_request_disc_mot_enb_devs(service, sender, timeout);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_disc_mot_enb_devs [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- net_ma_complete_disc_mot_enb_devs(object, invocation, ret);
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_disc_mowned_devs(NetMa *object,
- GDBusMethodInvocation *invocation,
- gchar *sender,
- gint timeout,
- gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
-
- ret = ma_request_disc_owned_devs(service, sender, timeout);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_disc_owned_devs [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- net_ma_complete_disc_mowned_devs(object, invocation, ret);
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_mot(NetMa *object,
- GDBusMethodInvocation *invocation, gchar *arg_target, gchar *arg_pin,
- gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
-
- ret = ma_request_mot(service, arg_target, arg_pin);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_disc_moted_devs [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- net_ma_complete_mot(object, invocation, ret);
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_acl(NetMa *object,
- GDBusMethodInvocation *invocation, gchar *arg_target, gchar *arg_subject,
- gchar *arg_uri, gchar *arg_rt, gchar *arg_interface, gint arg_permission,
- gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
-
- ret = ma_request_prov_acl(service, arg_target, arg_subject, arg_uri, arg_rt,
- arg_interface, arg_permission);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_prov_acl [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- net_ma_complete_acl(object, invocation, ret);
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_cred(NetMa *object,
- GDBusMethodInvocation *invocation, gchar *arg_dev1, gchar *arg_dev2,
- gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
-
- ret = ma_request_prov_cred(service, arg_dev1, arg_dev2);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_prov_cred [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- net_ma_complete_cred(object, invocation, ret);
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_pairwise(NetMa *object,
- GDBusMethodInvocation *invocation, gchar *target_1,
- gchar *subject_1, gchar *uri_1, gchar *rt_1,
- gchar *interface_1, int permission_1, gchar *target_2,
- gchar *subject_2, gchar *uri_2, gchar *rt_2,
- gchar *interface_2, int permission_2, gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
-
- ret = ma_request_rsrc_pairwise(service, target_1, subject_1, uri_1, rt_1,
- interface_1, permission_1, target_2, subject_2, uri_2,
- rt_2, interface_2, permission_2);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_pairwise [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- net_ma_complete_pairwise(object, invocation, ret);
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_unlink(NetMa *object,
- GDBusMethodInvocation *invocation, gchar *uuid_dev1, gchar *uuid_dev2,
- gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
- ret = ma_request_unlink_rsrc(service, uuid_dev1, uuid_dev2);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_unpair [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- net_ma_complete_unpair(object, invocation, ret);
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_remove_subowner(NetMa *object,
- GDBusMethodInvocation *invocation, gchar *arg_target, gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
-
- ret = ma_request_remove_subowner(service, arg_target);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_remove_subowner [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- net_ma_complete_remove_subowner(object, invocation, ret);
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_remove_device(NetMa *object,
- GDBusMethodInvocation *invocation, gchar *arg_target, gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
-
- ret = ma_request_remove_device(service, arg_target);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_remove_subowner [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- net_ma_complete_remove_device(object, invocation, ret);
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_pair(NetMa *object,
- GDBusMethodInvocation *invocation, gchar *sender, gchar *group_name, gchar *pin,
- gchar *target_1, gchar *subject_1, gchar *uri_1,
- gchar *rt_1, gchar *interface_1, int permission_1,
- gchar *target_2, gchar *subject_2, gchar *uri_2,
- gchar *rt_2, gchar *interface_2, int permission_2,
- gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
-
- ret = ma_request_pair(service, sender, group_name, pin, target_1, subject_1, uri_1, rt_1,
- interface_1, permission_1, target_2, subject_2, uri_2,
- rt_2, interface_2, permission_2);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_pair [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- net_ma_complete_pair(object, invocation, ret);
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_unpair(NetMa *object,
- GDBusMethodInvocation *invocation, gchar *sender, gchar *group_name, gchar *uuid_owner, gchar *uuid_owned,
- gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- ma_check_null_ret_error("service", service, FALSE);
-
- ret = ma_request_unpair(service, sender, group_name, uuid_owner, uuid_owned);
- if (MA_ERROR_NONE != ret)
- MA_LOGE("Failed to ma_request_unpair [%d][%s]",
- ret, ma_erro_to_string(ret));
-
- net_ma_complete_unpair(object, invocation, ret);
-
- return TRUE;
-}
-
-static void _ma_dbus_on_bus_acquired(GDBusConnection *conn, const gchar *name,
- gpointer user_data)
-{
- gboolean ret;
- GError *error = NULL;
- ma_service *service = (ma_service *)user_data;
-
- NOTUSED(name);
-
- ma_dbus_object = net_ma_skeleton_new();
- if (NULL == ma_dbus_object) {
- MA_LOGE("net_ma_skeleton_new() Fail");
- return;
- }
- g_signal_connect(ma_dbus_object, "handle-get-ownerid",
- G_CALLBACK(_ma_dbus_handle_get_ownerid), service);
- g_signal_connect(ma_dbus_object, "handle-disc-mot-enb-devs",
- G_CALLBACK(_ma_dbus_handle_disc_mot_enb_devs), service);
- g_signal_connect(ma_dbus_object, "handle-disc-mowned-devs",
- G_CALLBACK(_ma_dbus_handle_disc_mowned_devs), service);
- g_signal_connect(ma_dbus_object, "handle-mot",
- G_CALLBACK(_ma_dbus_handle_mot), service);
- g_signal_connect(ma_dbus_object, "handle-pairwise",
- G_CALLBACK(_ma_dbus_handle_pairwise), service);
- g_signal_connect(ma_dbus_object, "handle-unlink",
- G_CALLBACK(_ma_dbus_handle_unlink), service);
- g_signal_connect(ma_dbus_object, "handle-remove-subowner",
- G_CALLBACK(_ma_dbus_handle_remove_subowner), service);
- g_signal_connect(ma_dbus_object, "handle-remove-device",
- G_CALLBACK(_ma_dbus_handle_remove_device), service);
- g_signal_connect(ma_dbus_object, "handle-acl",
- G_CALLBACK(_ma_dbus_handle_acl), service);
- g_signal_connect(ma_dbus_object, "handle-cred",
- G_CALLBACK(_ma_dbus_handle_cred), service);
- g_signal_connect(ma_dbus_object, "handle-pair",
- G_CALLBACK(_ma_dbus_handle_pair), service);
- g_signal_connect(ma_dbus_object, "handle-unpair",
- G_CALLBACK(_ma_dbus_handle_unpair), service);
-
- ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(ma_dbus_object),
- conn, MA_DBUS_OBJPATH, &error);
- if (FALSE == ret) {
- MA_LOGE("g_dbus_interface_skeleton_export() Fail(%s)", error->message);
- g_error_free(error);
- }
-
- ret = _ma_dbus_subscribe_name_owner_changed(conn);
- if (MA_ERROR_NONE != ret) {
- MA_LOGE("_ma_dbus_subscribe_name_owner_changed() Fail(%d)", ret);
- return;
- }
-}
-
-static void _ma_dbus_on_name_lost(GDBusConnection *conn, const gchar *name,
- gpointer user_data)
-{
- NOTUSED(conn);
- NOTUSED(user_data);
-
- MA_LOGD("Lost the name %s", name);
-}
-
-static void _ma_dbus_on_name_acquired(GDBusConnection *conn, const gchar *name,
- gpointer user_data)
-{
- NOTUSED(conn);
- NOTUSED(user_data);
-
- MA_LOGD("Acquired the name %s", name);
-}
-
-static gboolean _ma_dbus_handle_enable(Enabler *object,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- __MA_LOG_FUNC_ENTER__;
-
- /* Do API response first */
- enabler_complete_enable(object, invocation, ret);
- service->ma_activated = TRUE;
-
- /* Intialize subowner client */
- ret = ma_request_enable(service);
- if (MA_ERROR_NONE != ret) {
- MA_LOGE("ma_request_enable() Fail(%d)", ret);
- return FALSE;
- }
-
- /* Notify d2ds enabled */
- net_ma_emit_subowner_enabled(ma_dbus_get_object(), ret);
-
- __MA_LOG_FUNC_EXIT__;
-
- return TRUE;
-}
-
-static gboolean _ma_dbus_handle_disable(Enabler *object,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
-{
- int ret = MA_ERROR_NONE;
- ma_service *service = (ma_service *)user_data;
-
- __MA_LOG_FUNC_ENTER__;
-
- /* Make response first */
- enabler_complete_disable(object, invocation, ret);
-
- /* De-Intialize subowner client */
- ret = ma_request_disable(service);
- if (MA_ERROR_NONE != ret) {
- MA_LOGE("ma_request_disable() Fail(%d)", ret);
- return FALSE;
- }
-
- /* Terminate daemon */
- ma_service_exit(service);
-
- return TRUE;
-}
-
-static void _ma_dbus_on_activator_bus_acquired(GDBusConnection *conn,
- const gchar *name, gpointer user_data)
-{
- gboolean ret;
- GError *error = NULL;
- ma_service *service = (ma_service *)user_data;
-
- NOTUSED(name);
-
- __MA_LOG_FUNC_ENTER__;
-
- ma_activator_dbus_object = enabler_skeleton_new();
- if (NULL == ma_activator_dbus_object) {
- MA_LOGE("enabler_skeleton_new() Fail");
- return;
- }
-
- g_signal_connect(ma_activator_dbus_object, "handle-enable",
- G_CALLBACK(_ma_dbus_handle_enable), service);
- g_signal_connect(ma_activator_dbus_object, "handle-disable",
- G_CALLBACK(_ma_dbus_handle_disable), service);
-
- ret = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(ma_activator_dbus_object),
- conn, MA_DBUS_ENABLER_OBJPATH, &error);
- if (FALSE == ret) {
- MA_LOGE("g_dbus_interface_skeleton_export() Fail(%s)", error->message);
- g_error_free(error);
- }
-
- __MA_LOG_FUNC_EXIT__;
-
-}
-
-static gboolean _ma_dbus_interface_init(ma_service *service)
-{
- guint id;
- guint activation_dbus_id;
- ma_check_null_ret_error("service", service, FALSE);
-
- id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- MA_DBUS_INTERFACE,
- G_BUS_NAME_OWNER_FLAGS_REPLACE,
- _ma_dbus_on_bus_acquired,
- _ma_dbus_on_name_acquired,
- _ma_dbus_on_name_lost,
- service,
- NULL);
- if (0 == id) {
- MA_LOGE("g_bus_own_name() Fail");
- return FALSE;
- }
-
- /* Get D-Bus owner to activate subowner service daemon */
- activation_dbus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- MA_DBUS_INTERFACE".enabler",
- G_BUS_NAME_OWNER_FLAGS_REPLACE,
- _ma_dbus_on_activator_bus_acquired,
- NULL,
- NULL,
- service,
- NULL);
-
- service->dbus_id = id;
- service->activation_dbus_id = activation_dbus_id;
-
- return TRUE;
-}
-
-void ma_notify_mot_env_devs(char *sender, GVariant *devices)
-{
- /* Notify d2ds enabled */
- MA_LOGE("[JIHOON] sender is %s", sender);
- net_ma_emit_disc_mot_enb_devs_done(ma_dbus_get_object(), sender, devices);
-}
-
-void ma_notify_mowned_devs(char *sender, GVariant *devices)
-{
- /* Notify d2ds enabled */
- MA_LOGE("[JIHOON] sender is %s", sender);
- net_ma_emit_disc_mowned_devs_done(ma_dbus_get_object(), sender, devices);
-}
-
-static void _ma_dbus_deinit(ma_service *service)
-{
- ma_check_null_ret("service", service);
-
- g_bus_unown_name(service->dbus_id);
- g_bus_unown_name(service->activation_dbus_id);
-}
-
-gboolean ma_service_interface_init(ma_service *service)
-{
- guint ret;
- ma_check_null_ret_error("service", service, FALSE);
-
- __MA_LOG_FUNC_ENTER__;
-
- /* Initialize dbus interface */
- ret = _ma_dbus_interface_init(service);
- if (FALSE == ret) {
- MA_LOGE("%s failed!!!", __func__);
- return FALSE;
- }
-
- __MA_LOG_FUNC_EXIT__;
-
- return TRUE;
-}
-
-void ma_service_interface_deinit(ma_service *service)
-{
- ma_check_null_ret("service", service);
-
- /* De-initialize dbus interface */
- _ma_dbus_deinit(service);
- /* De-initialize mot-agent instance */
- ma_delete_mot_agent(service);
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __MA_SERVICE_INTERFACE_H__
-#define __MA_SERVICE_INTERFACE_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**< Mesh D-BUS service*/
-#define MA_DBUS_SERVICE "net.ma"
-
-/**< Mesh D-BUS service path */
-#define MA_DBUS_PATH "/net/ma"
-
-#ifndef MA_DBUS_INTERFACE
-#define MA_DBUS_INTERFACE "net.ma"
-#endif
-
-#ifndef MA_DBUS_OBJPATH
-#define MA_DBUS_OBJPATH "/net/ma"
-#endif
-
-#ifndef MA_DBUS_ENABLER_OBJPATH
-#define MA_DBUS_ENABLER_OBJPATH "/net/ma/enabler"
-#endif
-
-struct _NetMa;
-typedef struct _NetMa NetMa;
-
-NetMa* ma_dbus_get_object();
-gboolean ma_service_interface_init(ma_service *service);
-void ma_service_interface_deinit(ma_service *service);
-void ma_notify_mot_env_devs(char *sender, GVariant *devices);
-void ma_notify_mowned_devs(char *sender, GVariant *devices);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __MA_SERVICE_INTERFACE_H__ */
-
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <glib.h>
-
-#include "ma.h"
-#include "ma-log.h"
-#include "ma-util.h"
-
-ma_service *ma_service_new()
-{
- ma_service *service;
-
- service = g_malloc0(sizeof(struct _ma_service));
- if (NULL == service)
- return NULL;
-
- /* Create g-main loop */
- service->main_loop = g_main_loop_new(NULL, FALSE);
- if (G_UNLIKELY(NULL == service->main_loop)) {
- MA_LOGE("g-main loop creation failed!!!");
- g_free(service);
- return NULL;
- }
-
- return service;
-}
-
-void ma_service_free(ma_service *service)
-{
- ma_check_null_ret("service", service);
-
- /* Unref 'g-main loop' */
- if (service->main_loop)
- g_main_loop_unref(service->main_loop);
-
- g_free(service);
-}
-
-gboolean ma_service_run(ma_service *service)
-{
- ma_check_null_ret_error("service", service, FALSE);
- ma_check_null_ret_error("service->main_loop", service->main_loop, FALSE);
-
- g_main_loop_run(service->main_loop);
-
- return TRUE;
-}
-
-gboolean ma_service_exit(ma_service *service)
-{
- ma_check_null_ret_error("service", service, FALSE);
- ma_check_null_ret_error("service->main_loop", service->main_loop, FALSE);
-
- g_main_loop_quit(service->main_loop);
-
- return TRUE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __MA_SERVICE_H__
-#define __MA_SERVICE_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-ma_service* ma_service_new();
-void ma_service_free(ma_service *service);
-gboolean ma_service_run(ma_service *service);
-gboolean ma_service_exit(ma_service *service);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __MA_SERVICE_H__ */
-
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/time.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <glib.h>
-#include <gio/gio.h>
-
-#include <utlist.h>
-#include <oic_malloc.h>
-#include <oxmjustworks.h>
-#include <oxmrandompin.h>
-#include <iotivity_config.h>
-#include <platform_features.h>
-#include <ocprovisioningmanager.h>
-#include <securevirtualresourcetypes.h>
-
-#include "ma.h"
-#include "ma-log.h"
-#include "ma-util.h"
-#include "ma-subowner.h"
-#include "ma-service-interface.h"
-#include "ma-generated-code.h"
-
-#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_5S 5 * 1000 /**< 5sec = 5 * 1000 * 1ms */
-#define CALLBACK_MARGIN 10 * 1000 /**< 10sec */
-#define TIME_UNIT 10 /**< Sleep time unit */
-
-/* '_' 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";
-
-#ifdef TEST
-static const OicSecPrm_t SUPPORTED_PRMS[2] = { PRM_PRE_CONFIGURED, PRM_RANDOM_PIN };
-#endif
-
-/**< GetDoxmDevOwnerId() is IoTivity function */
-OCStackResult GetDoxmDevOwnerId(OicUuid_t *devownerid);
-OCStackResult PDMUnlinkDevices(const OicUuid_t *UUID1, const OicUuid_t *UUID2);
-OCStackResult PDMDeleteDevice(const OicUuid_t *uuidOfDevice);
-
-typedef struct {
- int ret; /** Result of command */
- ma_cmd_id_e cid; /**< Command ID */
- int tid; /**< Timer ID */
- int timeout; /**< Timeout value */
- 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 */
- char *sender;
- char *group_name;
- /* To-Do : Change belows to union type */
-
- /* For MOT */
- gchar *uuid_target_str; /**< Target device*/
- gchar *pin; /**< PIN */
-
- /* For ACL provisioning */
- gchar *uuid_subject_str;/**< Subject 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 */
- 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*/
- gchar *target_2; /**< Target device 1*/
-
- gchar *subject_1; /**< Target device for ACL */
- gchar *rsrc_uri_1; /**< Resource URI */
- gchar *rsrc_type_1; /**< Resouce Type */
- gchar *rsrc_interface_1; /**< Resource Interface Array To-Do : Make this as array */
- int permission_1;/**< Permision */
- gchar *subject_2; /**< Target device for ACL */
- gchar *rsrc_uri_2; /**< Resource URI */
- gchar *rsrc_type_2; /**< Resouce Type */
- gchar *rsrc_interface_2; /**< Resource Interface Array To-Do : Make this as array */
- int permission_2;/**< Permision */
-
- /* For unpair */
- gchar *target_to_revoke; /**< Target device to revoke */
-
-} 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? */
- GMutex iotivity_mutex; /**< Mutex for IoTivity stack */
-
- OCProvisionDev_t* g_motdev_list; /**< Discoverd MOT enabled devices list */
- OCProvisionDev_t* g_mowned_list; /**< My owned MOT enabled devices list */
-
- 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 */
-} ma_subowner_s;
-
-ma_subowner_s *g_client; /**< MOT agent client instance */
-
-#ifdef THREAD_COND_WAIT_USED
-/*
- * data structure
- */
-typedef struct _proc {
- char name[2]; /**< Thread name */
- int data; /**< User data */
- pthread_t thread; /**< POSIX Thread */
- pthread_mutex_t lock; /**< POSIX Mutex */
- pthread_cond_t cond; /**< POSIX condition */
- long int waits; /**< How long we have to wait */
-} process_t;
-
-static void* _exec_and_wait(void* args)
-{
- int ret = OC_STACK_OK;
- process_t *proc = (process_t *)args;
- static struct timespec time_to_wait = {0, 0};
-
- int TIMES = proc->waits / TIME_UNIT;
- if (0 != proc->waits % TIME_UNIT)
- TIMES += 1;
-
- while (!g_client->g_doneCB && proc->data <= TIMES) {
- /* Increase wait time per unit time (= 10 msec) */
- time_to_wait.tv_sec = time(NULL);
- time_to_wait.tv_nsec = TIME_UNIT * 1000000;
-
- pthread_mutex_lock(&proc->lock);
- pthread_cond_timedwait(&proc->cond, &proc->lock, &time_to_wait);
- pthread_mutex_unlock(&proc->lock);
-
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCProcess();
- g_mutex_unlock(&g_client->iotivity_mutex);
-
- if (OC_STACK_OK != ret) {
- MA_LOGE("OCStack process error = %d", ret);
- break;
- }
- proc->data++;
- }
- return NULL;
-}
-
-static int _init_proc(process_t *proc, void *(*routine) (void *))
-{
- pthread_attr_t attr;
-
- MA_LOGD("try to init proc [%s]", proc->name);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
-
- pthread_mutex_init(&proc->lock, NULL);
- pthread_cond_init(&proc->cond, NULL);
-
- pthread_create(&proc->thread, &attr, routine, (void*) proc);
- pthread_attr_destroy(&attr);
-
- return MA_ERROR_NONE;
-}
-#endif /* THREAD_COND_WAIT_USED */
-
-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);
-#ifdef DEBUG_SVR_DB
- MA_LOGD("Unsed DB path %s\n", path);
-#endif
-
- return fopen(data_dir, mode);
-}
-
-static int _wait_cb_ret(int msec)
-{
- int ret = OC_STACK_OK;
-#ifndef THREAD_COND_WAIT_USED
- int result = -1;
- struct timespec tim, tim2;
- tim.tv_sec = 0;
- tim.tv_nsec = 100 * 1000000;
-#endif
-
-#ifdef THREAD_COND_WAIT_USED
- void *result;
- process_t proc;
-
- ma_check_null_ret_error("g_client", g_client, OC_STACK_INVALID_PARAM);
-
- strcpy(proc.name, "A\0");
- proc.data = 0;
- proc.waits = msec + CALLBACK_MARGIN;
-
- if (0 != _init_proc(&proc, _exec_and_wait)) {
- MA_LOGE("Fail to init proc [%s]", proc.name);
- return OC_STACK_ERROR;
- }
- pthread_join(proc.thread, &result);
-#else
- for (int i = 0; !g_client->g_doneCB && (msec + CALLBACK_MARGIN) >= i; i += TIME_UNIT) {
-
- result = nanosleep(&tim, &tim2);
- if (0 > result)
- MA_LOGE("nanosleep failed=%d", errno);
-
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCProcess();
- g_mutex_unlock(&g_client->iotivity_mutex);
-
- if (OC_STACK_OK != ret) {
- MA_LOGE("OCStack process error = %d", ret);
- break;
- }
- }
-#endif
- if (!g_client->g_doneCB) {
- OCPDMCleanupForTimeout();
- ret = OC_STACK_TIMEOUT;
- }
-
- return ret;
-}
-
-static void _input_pin_cb(char* pin, size_t len)
-{
- ma_check_null_ret("g_client", g_client);
-
- if (!pin || OXM_RANDOM_PIN_MAX_SIZE >= len) {
- MA_LOGE("inputPinCB invalid parameters");
- return;
- }
-
- memcpy(pin, g_client->rnd_pin, g_client->rnd_pin_len);
- MA_LOGI("Random PIN : %s", g_client->rnd_pin);
-}
-
-static void _remove_mot_client()
-{
- ma_check_null_ret("g_client", g_client);
-
- if (g_client->g_motdev_list) {
- OCDeleteDiscoveredDevices(g_client->g_motdev_list);
- g_client->g_motdev_list = NULL;
- }
-}
-
-static void _remove_owned_client()
-{
- ma_check_null_ret("g_client", g_client);
-
- if (g_client->g_mowned_list) {
- OCDeleteDiscoveredDevices(g_client->g_mowned_list);
- g_client->g_mowned_list = NULL;
- }
-}
-
-static void _request_cleanup(gpointer data)
-{
- ma_req_cb_s *con = (ma_req_cb_s *)data;
- ma_check_null_ret("con", con);
- ma_service *service = (ma_service *)con->userdata;
- ma_check_null_ret("service", service);
-
- if (con->tid) {
- g_source_remove(con->tid);
- con->tid = 0;
- }
- con->sid = 0;
- con->found = FALSE;
-
- if (con->pin) {
- g_free(con->pin);
- con->pin = NULL;
- }
- if (con->rsrc_uri) {
- g_free(con->rsrc_uri);
- con->rsrc_uri = NULL;
- }
- if (con->rsrc_type) {
- g_free(con->rsrc_type);
- con->rsrc_type = NULL;
- }
- if (con->rsrc_interface) {
- g_free(con->rsrc_interface);
- con->rsrc_interface = NULL;
- }
- if (con->uuid_target_str) {
- g_free(con->uuid_target_str);
- con->uuid_target_str = NULL;
- }
- if (con->uuid_dev1) {
- g_free(con->uuid_dev1);
- con->uuid_dev1 = NULL;
- }
- if (con->uuid_dev2) {
- g_free(con->uuid_dev2);
- con->uuid_dev2 = NULL;
- }
- if (con->target_1) {
- g_free(con->target_1);
- con->target_1 = NULL;
- }
- if (con->subject_1) {
- g_free(con->subject_1);
- con->subject_1 = NULL;
- }
- if (con->rsrc_uri_1) {
- g_free(con->rsrc_uri_1);
- con->rsrc_uri_1 = NULL;
- }
- if (con->rsrc_type_1) {
- g_free(con->rsrc_type_1);
- con->rsrc_type_1 = NULL;
- }
- if (con->rsrc_interface_1) {
- g_free(con->rsrc_interface_1);
- con->rsrc_interface_1 = NULL;
- }
- if (con->target_2) {
- g_free(con->target_1);
- con->target_1 = NULL;
- }
- if (con->subject_2) {
- g_free(con->subject_1);
- con->subject_1 = NULL;
- }
- if (con->rsrc_uri_2) {
- g_free(con->rsrc_uri_2);
- con->rsrc_uri_2 = NULL;
- }
- if (con->rsrc_type_2) {
- g_free(con->rsrc_type_2);
- con->rsrc_type_2 = NULL;
- }
- if (con->rsrc_interface_2) {
- g_free(con->rsrc_interface_2);
- con->rsrc_interface_2 = NULL;
- }
-
- /* Set d2ds status 'pending' */
- if (g_client)
- g_atomic_int_set(&g_client->pending, 0);
-
- if (con) {
- g_free(con);
- con = NULL;
- }
-}
-
-static gpointer ___notify_found_devs(gpointer data)
-{
- GVariantBuilder builder;
- GVariant* devices;
- OCProvisionDev_t *iter = NULL;
-
- ma_req_cb_s *con = (ma_req_cb_s *)data;
- ma_check_null_ret_error("con", con, NULL);
- ma_service *service = (ma_service *)con->userdata;
- ma_check_null_ret_error("service", service, NULL);
- ma_check_null_ret_error("g_client", g_client, NULL);
-
- /* g_mowned_list would be filled above request */
- g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
-
- if (MA_FIND_MOT_ENABLED_DEVICES == con->cid) {
- iter = 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_FIND_MULTIPLE_OWNED_DEVICES == con->cid) {
- iter = 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);
- }
-
- char *uuid_str = NULL;
- OicUuid_t uuid;
-
- GetDoxmDevOwnerId(&uuid);
- ConvertUuidToStr(&uuid, &uuid_str);
-
- MA_LOGD("local owner uuid is %s", uuid_str);
-
- while (iter != NULL) {
- MA_LOGD("-----------------------------------");
- if (con->cid == MA_FIND_MOT_ENABLED_DEVICES) {
- bool is_invited = false;
- OicSecSubOwner_t* subOwner = iter->doxm->subOwners;
- if (subOwner != NULL) {
- while (subOwner != NULL) {
- char *readable_uuid = ma_get_readable_uuid(&(subOwner->uuid));
- MA_LOGD("remote owner uuid is %s", readable_uuid);
-
- if (g_strcmp0(readable_uuid, uuid_str) == 0) {
- is_invited = true;
- break;
- }
- subOwner = subOwner->next;
- }
- }
-
- if (is_invited == true) {
- MA_LOGD("The device is already invited. Skip the device");
- iter = iter->next;
- continue;
- }
- }
-
- OicUuid_t *uuid = &iter->doxm->deviceID;
- ma_check_null_ret_error("uuid", uuid, NULL);
-
- g_variant_builder_open(&builder, G_VARIANT_TYPE_VARDICT);
-
- g_variant_builder_add(&builder, "{sv}", "deviceId",
- 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",
- g_variant_new_int32(iter->endpoint.flags));
- g_variant_builder_add(&builder, "{sv}", "port",
- g_variant_new_uint16(iter->endpoint.port));
- g_variant_builder_add(&builder, "{sv}", "addr",
- g_variant_new_string(iter->endpoint.addr));
- g_variant_builder_add(&builder, "{sv}", "ifindex",
- g_variant_new_int32(iter->endpoint.ifindex));
- g_variant_builder_add(&builder, "{sv}", "routeData",
- g_variant_new_string(iter->endpoint.routeData));
- g_variant_builder_add(&builder, "{sv}", "remoteId",
- g_variant_new_string(iter->endpoint.remoteId));
-
- g_variant_builder_add(&builder, "{sv}", "connType",
- g_variant_new_uint32(iter->connType));
- g_variant_builder_add(&builder, "{sv}", "securePort",
- g_variant_new_uint16(iter->securePort));
-#ifdef WITH_TCP
- g_variant_builder_add(&builder, "{sv}", "tcpPort",
- g_variant_new_uint16(iter->tcpPort));
-#endif
- g_variant_builder_add(&builder, "{sv}", "secVer",
- g_variant_new_string(iter->secVer));
- g_variant_builder_add(&builder, "{sv}", "devStatus",
- g_variant_new_uint32(iter->devStatus));
- g_variant_builder_close(&builder);
-
- iter = iter->next;
- }
-
- devices = g_variant_builder_end(&builder);
-
- if (MA_FIND_MOT_ENABLED_DEVICES == con->cid)
- ma_notify_mot_env_devs(con->sender, devices);
- else if (MA_FIND_MULTIPLE_OWNED_DEVICES == con->cid)
- ma_notify_mowned_devs(con->sender, devices);
-
- g_variant_builder_unref(&builder);
- g_variant_unref(devices);
-
- _request_cleanup(con);
- g_thread_exit(GINT_TO_POINTER(1));
-
- return NULL;
-}
-
-static int __notify_found_devs(ma_req_cb_s *con)
-{
- con->thread = g_thread_try_new("notify_devs", ___notify_found_devs, 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);
-
- return MA_ERROR_NONE;
-}
-
-static void _disc_mot_env_devs_func(ma_req_cb_s *con)
-{
- int ret = OC_STACK_OK;
-
- 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();
-
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCDiscoverMultipleOwnerEnabledDevices(con->timeout, &g_client->g_motdev_list);
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret) {
- MA_LOGE("OCDiscoverMultipleOwnerEnalbedDevices API error");
- goto DISC_MOT_ENB_DEVS_END;
- }
-
- __notify_found_devs(con);
-
- return;
-
-DISC_MOT_ENB_DEVS_END:
- _request_cleanup(con);
-}
-
-static int _disc_mot_enb_devs(ma_service *service, char *sender, int timeout)
-{
- ma_req_cb_s *con = NULL;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (NULL == con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
-
- con->userdata = service;
- con->cid = MA_FIND_MOT_ENABLED_DEVICES;
- con->sender = g_strdup(sender);
-
- if (timeout < 1)
- timeout = DISCOVERY_TIMEOUT;
- con->timeout = timeout;
-
- g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-
- return MA_ERROR_NONE;
-}
-
-static void _disc_owned_devs_func(ma_req_cb_s *con)
-{
- OCStackResult ret = OC_STACK_OK;
-
- 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 MOWNED Devices");
-
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCDiscoverMultipleOwnedDevices(con->timeout,
- &g_client->g_mowned_list);
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret) {
- MA_LOGE("OCDiscoverMultipleOwnerEnabledDevices API error");
- goto DISC_OWNED_DEVS_END;
- }
-
- __notify_found_devs(con);
-
- return;
-
-DISC_OWNED_DEVS_END:
- _request_cleanup(con);
-}
-
-static int _disc_owned_devs(ma_service *service, char *sender, int timeout)
-{
- ma_req_cb_s *con = NULL;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (NULL == con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
-
- con->userdata = service;
- con->cid = MA_FIND_MULTIPLE_OWNED_DEVICES;
- con->sender = g_strdup(sender);
-
- if (timeout < 1)
- timeout = DISCOVERY_TIMEOUT;
- con->timeout = timeout;
-
- g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-
- return MA_ERROR_NONE;
-}
-
-static gpointer ___notify_result(gpointer data)
-{
- ma_req_cb_s *con = (ma_req_cb_s *)data;
- ma_check_null_ret_error("con", con, NULL);
- ma_service *service = (ma_service *)con->userdata;
- ma_check_null_ret_error("service", service, NULL);
- ma_check_null_ret_error("g_client", g_client, NULL);
-
- switch (con->cid) {
- case MA_DO_MOT:
- /* Notify ACL result */
- net_ma_emit_acl_done(ma_dbus_get_object(), con->ret);
- break;
- case MA_DO_ACL_PROVISIONING:
- net_ma_emit_acl_done(ma_dbus_get_object(), con->ret);
- break;
- case MA_DO_CRED_PROVISIONING:
- net_ma_emit_cred_done(ma_dbus_get_object(), con->ret);
- break;
- case MA_DO_RESOURCES_PAIRWISE:
- net_ma_emit_pairwise_done(ma_dbus_get_object(), con->ret);
- break;
- case MA_REMOVE_MULTIPLE_OWNED_DEVICE:
- net_ma_emit_remove_mo_done(ma_dbus_get_object(), con->ret);
- break;
- case MA_REMOVE_DEVICE_WITH_UUID_IN_SVR:
- net_ma_emit_remove_cred_local_done(ma_dbus_get_object(), con->ret);
- break;
- case MA_UNLINK_RESOURCES:
- net_ma_emit_unlink_done(ma_dbus_get_object(), con->ret);
- break;
- case MA_MAKE_PAIR:
- net_ma_emit_pair_done(ma_dbus_get_object(), con->sender, con->target_2, con->group_name, con->ret);
- break;
- case MA_MAKE_UNPAIR:
- net_ma_emit_unpair_done(ma_dbus_get_object(), con->sender, con->uuid_dev2, con->group_name, con->ret);
- break;
- default:
- break;
- }
-
- _request_cleanup(con);
-
- g_thread_exit(GINT_TO_POINTER(1));
-
- return NULL;
-}
-
-
-static int __notify_result(ma_req_cb_s *con)
-{
- con->thread = g_thread_try_new("notify_result", ___notify_result, 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);
-
- return MA_ERROR_NONE;
-}
-
-static void _mot_cb(void* ctx, int num, OCProvisionResult_t* arr, bool has_error)
-{
- ma_subowner_s *client = (ma_subowner_s *)ctx;
-
- if (!has_error) {
- MA_LOGD("Multiple Ownership Transfer SUCCEEDED");
- } else {
- MA_LOGD("Multiple Ownership Transfer FAILED ");
- ma_print_result_list((const OCProvisionResult_t*) arr, num);
- }
- client->g_doneCB = true;
-}
-
-static void _mot_func(ma_req_cb_s *con)
-{
- OCStackResult ret = OC_STACK_OK;
- OCProvisionDev_t *src_dev = NULL;
- OCProvisionDev_t *next_dev = NULL;
- OicUuid_t *uuid_target = NULL;
-
- if (!g_client) {
- ret = OC_STACK_INVALID_PARAM;
- 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;
- MA_LOGE("Target device UUID is NULL");
- goto MOT_ENDED;
- }
-
- uuid_target = ma_convert_uuid(con->uuid_target_str);
- src_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_target);
- if (!src_dev) {
- MA_LOGE("We can't find in MOT dev list");
- goto MOT_ENDED;
- }
-#ifndef MULTIPLE_OWN_AT_ONCE
- /* Copy next MOT enabled device pointer temporally */
- next_dev = src_dev->next;
- /* Next MOT enabled device set NULL to MOT a single device */
- src_dev->next = NULL;
-#endif
-
- g_client->g_doneCB = false;
-
-#ifdef MULTIPLE_OWN_AT_ONCE
- OCProvisionDev_t* dev = NULL;
- LL_FOREACH(g_client->g_motdev_list, dev) {
- if (OIC_PRECONFIG_PIN == dev->doxm->oxmSel) {
- /* Pre-Configured PIN initialization */
- const char* testPreconfigPin = con->pin;/* Ex) "12341234" */
- ret = OCAddPreconfigPin(dev, testPreconfigPin, strlen(testPreconfigPin));
- if (OC_STACK_OK != ret) {
- MA_LOGE("Failed to save the pre-configured PIN");
- MA_LOGE("You can't use the pre-configured PIN OxM for MOT");
- goto 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, ma_ocf_error_to_string(ret));
- goto MOT_ENDED;
- }
-
-#else
- if (OIC_PRECONFIG_PIN == src_dev->doxm->oxmSel) {
- /* Pre-Configured PIN initialization */
- const char* testPreconfigPin = con->pin;/* Ex) "12341234" */
- ret = OCAddPreconfigPin(src_dev, testPreconfigPin, strlen(testPreconfigPin));
- if (OC_STACK_OK != ret) {
- MA_LOGE("Failed to save the pre-configured PIN");
- goto MOT_ENDED;
- }
- }
- ret = OCDoMultipleOwnershipTransfer(g_client, src_dev, _mot_cb);
- if (OC_STACK_OK != 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, ma_ocf_error_to_string(ret));
- goto MOT_ENDED;
- }
- MA_LOGI("Registered Discovered Devices");
-
-MOT_ENDED:
-#ifndef MULTIPLE_OWN_AT_ONCE
- /* Restore MOT enabled devices */
- if (src_dev)
- src_dev->next = next_dev;
-#endif
-
- /* Notify of MOT result */
- if (con) {
- con->ret = ret;
- __notify_result(con);
- }
-
- if (uuid_target)
- g_free(uuid_target);
-}
-
-static int _mot(ma_service *service, gchar *uuid_str, gchar *pin)
-{
- ma_req_cb_s *con = NULL;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (NULL == con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
-
- con->userdata = service;
- con->cid = MA_DO_MOT;
- con->uuid_target_str = g_strdup(uuid_str);
-
- if (pin) {
- con->pin = g_malloc0(OXM_RANDOM_PIN_MAX_SIZE+1);
- if (!con->pin) {
- MA_LOGE("Failed to allocate PIN number");
- _request_cleanup(con);
- return MA_ERROR_OUT_OF_MEMORY;
- }
- memcpy(con->pin, pin, OXM_RANDOM_PIN_MAX_SIZE);
- }
-
- g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-
- return MA_ERROR_NONE;
-}
-
-static OicSecAcl_t* _create_target_acl(const OicUuid_t* subject, const char *rsrc_uri,
- const char *rsrc_type, const char *rsrc_interface, int permission)
-{
- /* For example
- * subejct = "12341234-1234-1234-12341234"
- * rsrc_uri = "/a/led"
- * rsrc_type = "oic.r.core"
- * rsrc_interface = "oic.if.baseline"
- * rsrc_permission = MA_PERMISSION_FULL
- */
-
- size_t len;
- OicUuid_t eowner;
- OCStackResult ret;
- OicSecAcl_t* acl = NULL;
- OicSecAce_t* ace = NULL;
- OicSecRsrc_t* rsrc = NULL;
-
- ma_check_null_ret_error(subject, "subject", NULL);
- ma_check_null_ret_error(rsrc_uri, "rsrc_uri", NULL);
- ma_check_null_ret_error(rsrc_type, "rsrc_type", NULL);
- ma_check_null_ret_error(rsrc_interface, "rsrc_interface", NULL);
-
-#ifdef DEBUG_UUID
- 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("permission = %d", permission);
-#endif
- acl = (OicSecAcl_t*)calloc(1, sizeof(OicSecAcl_t));
- if (!acl) {
- MA_LOGE("acl : calloc failed = %d", errno);
- return NULL;
- }
- ace = (OicSecAce_t*) calloc(1, sizeof(OicSecAce_t));
- if (!ace) {
- MA_LOGE("ace : calloc failed = %d", errno);
- return NULL;
- }
- LL_APPEND(acl->aces, ace);
- memcpy(ace->subjectuuid.id, subject->id, sizeof(subject->id));
-
- /* fill the href */
- rsrc = (OicSecRsrc_t*)calloc(1, sizeof(OicSecRsrc_t));
- if (!rsrc) {
- MA_LOGE("rsrc: calloc failed = %d", errno);
- goto CREATE_ACL_ERROR;
- }
-
- len = strlen(rsrc_uri)+1; // '1' for null termination
- rsrc->href = (char*) calloc(len, sizeof(char));
- if (!rsrc->href) {
- MA_LOGE("rsrc->href: calloc failed = %d", errno);
- goto CREATE_ACL_ERROR;
- }
- memcpy(rsrc->href, rsrc_uri, len);
-
- /* Fill the resource type (rt) */
- rsrc->typeLen = 1;
- rsrc->types = (char**)calloc(1, sizeof(char*));
- if (!rsrc->types) {
- MA_LOGE("rsrc->types: calloc failed = %d", errno);
- goto CREATE_ACL_ERROR;
- }
- rsrc->types[0] = g_strdup(rsrc_type);
- if (!rsrc->types[0]) {
- MA_LOGE("rsrc->types[0]: g_strdup failed = %d", errno);
- goto CREATE_ACL_ERROR;
- }
-
- /* Fill the interface (if) */
- rsrc->interfaceLen = 1;
- rsrc->interfaces = (char**)calloc(1, sizeof(char*));
- if (!rsrc->interfaces) {
- MA_LOGE("rsrc->interfaces: calloc failed = %d", errno);
- goto CREATE_ACL_ERROR;
- }
- rsrc->interfaces[0] = g_strdup(rsrc_interface);
- if (!rsrc->interfaces[0]) {
- MA_LOGE("rsrc->interfaces[0] : g_strdup failed = %d", errno);
- goto CREATE_ACL_ERROR;
- }
-
- LL_APPEND(ace->resources, rsrc);
-
- /* Fill permission for the reource */
- ace->permission = permission;
-
- ace->eownerID = (OicUuid_t*)calloc(1, sizeof(OicUuid_t));
- if (NULL == ace->eownerID) {
- MA_LOGE("ace->eownerID : calloc failed = %d", errno);
- goto CREATE_ACL_ERROR;
- }
- ret = GetDoxmDevOwnerId(&eowner);
- if (OC_STACK_OK != ret) {
- MA_LOGE("GeDoxmDevOwner failed = %d", ret);
- goto CREATE_ACL_ERROR;
- }
- memcpy(ace->eownerID->id, eowner.id, sizeof(subject->id));
-
- return acl;
-
-CREATE_ACL_ERROR:
- OCDeleteACLList(acl);
- return NULL;
-}
-
-static void _acl_provisioning_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr,
- bool has_error)
-{
- ma_subowner_s *client = (ma_subowner_s *)ctx;
-
- if (!has_error) {
- MA_LOGD("Provision ACL SUCCEEDED");
- } else {
- MA_LOGD("Provision ACL FAILED ");
- ma_print_result_list((const OCProvisionResult_t*) arr, nOfRes);
- }
- client->g_doneCB = true;
-}
-static void _acl_provisioning_func(ma_req_cb_s *con)
-{
- OCStackResult ret = OC_STACK_OK;
-
- OicSecAcl_t* acl = NULL;
- OicUuid_t *uuid1 = NULL;
- OicUuid_t *uuid2 = NULL;
- OCProvisionDev_t *target_dev = NULL;
- OCProvisionDev_t *subject_dev = NULL;
-
- if (!g_client) {
- MA_LOGE("mot agent is not initialized");
- goto PV_ACL_END;
- }
- if (NULL == con) {
- MA_LOGE("container is NULL");
- goto PV_ACL_END;
- }
-
- uuid1 = ma_convert_uuid(con->uuid_target_str);
- target_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid1);
- if (!target_dev) {
- MA_LOGE("We can't find target in MOT enabled dev list");
- goto PV_ACL_END;
- }
-
- uuid2 = ma_convert_uuid(con->uuid_subject_str);
- subject_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid2);
- if (!subject_dev) {
- MA_LOGE("We can't find subject in MOT enabled dev list");
- goto PV_ACL_END;
- }
-
- g_client->g_doneCB = false;
- MA_LOGI(" Provisioning Selected ACL..");
-
- acl = _create_target_acl(&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);
- goto PV_ACL_END;
- }
-
- /* Do ACL provisioning */
- ret = OCProvisionACL((void*) g_client, target_dev, acl, _acl_provisioning_cb);
- if (OC_STACK_OK != ret) {
- MA_LOGD("OCProvisionACL API error: %d (%s)", ret, ma_ocf_error_to_string(ret));
- goto PV_ACL_END;
- }
-
- ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
- if (ret) {
- MA_LOGE("OCProvisionCredentials Faild = %d", errno);
- goto PV_ACL_END;
- }
- /* display the ACL-provisioned result */
- MA_LOGI(" Provisioned Selected ACL Successfully");
-
-PV_ACL_END:
- /* Notify ACL result */
- if (con) {
- con->ret = ret;
- __notify_result(con);
- }
-
- if (acl)
- OCDeleteACLList(acl);
- if (uuid1)
- g_free(uuid1);
- if (uuid2)
- g_free(uuid2);
-}
-
-static int _acl_provisioning(ma_service *service, gchar *target, gchar *subject,
- gchar *rsrc_uri, gchar *rsrc_type, gchar *rsrc_interface, int permission)
-{
- ma_req_cb_s *con = NULL;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (NULL == con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
-
- con->userdata = service;
- 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);
-
- g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-
- return MA_ERROR_NONE;
-}
-
-static void _cred_provisioning_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr,
- bool has_error)
-{
- ma_subowner_s *client = (ma_subowner_s *)ctx;
-
- if (!has_error) {
- MA_LOGD("Provision CRED SUCCEEDED");
- } else {
- MA_LOGD("Provision CRED FAILED ");
- ma_print_result_list((const OCProvisionResult_t*) arr, nOfRes);
- }
- client->g_doneCB = true;
-}
-
-static void _cred_provisioning_func(ma_req_cb_s *con)
-{
- OCStackResult ret = OC_STACK_OK;
-
- OicUuid_t *uuid1 = NULL;
- OicUuid_t *uuid2 = NULL;
- OCProvisionDev_t *dev1 = NULL;
- OCProvisionDev_t *dev2 = NULL;
- OCProvisionDev_t *dev1_next = NULL;
- OCProvisionDev_t *dev2_next = NULL;
-
- if (!g_client) {
- MA_LOGE("mot agent is not initialized");
- goto PV_CRED_END;
- }
- if (NULL == con) {
- MA_LOGE("container is NULL");
- goto PV_CRED_END;
- }
-
- if (!con->uuid_dev1) {
- MA_LOGE("dev1 is NULL");
- goto PV_CRED_END;
- }
- if (!con->uuid_dev2) {
- MA_LOGE("dev2 is NULL");
- goto PV_CRED_END;
- }
-
- uuid1 = ma_convert_uuid(con->uuid_dev1);
- dev1 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid1);
- if (!dev1) {
- MA_LOGE("We can't find in MOWNED dev list");
- goto PV_CRED_END;
- }
-
- uuid2 = ma_convert_uuid(con->uuid_dev2);
- dev2 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid2);
- if (!dev2) {
- MA_LOGE("We can't find in MOWNED dev list");
- goto PV_CRED_END;
- }
-
- /* To do ACL provisioning only one */
- dev1_next = dev1->next;
- dev1->next = NULL;
- dev2_next = dev2->next;
- dev2->next = NULL;
-
- g_client->g_doneCB = false;
-
- MA_LOGI("Provisioning Selected Pairwise Devices..");
- ret = OCProvisionCredentials((void*) g_client,
- SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_256,
- dev1, dev2, _cred_provisioning_cb);
- if (OC_STACK_OK != ret) {
- MA_LOGD("OCProvisionCredentials API error: %d (%s)",
- ret, ma_ocf_error_to_string(ret));
- goto PV_CRED_END;
- }
-
- ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
- if (ret) {
- MA_LOGE("OCProvisionCredentials Faild = %d", errno);
- goto PV_CRED_END;
- }
-
- /* display the pairwise-provisioned result */
- MA_LOGI("Provisioned Selected Pairwise Devices");
-
-PV_CRED_END:
- /* Restore MOT enabled device list */
- if (dev1)
- dev1->next = dev1_next;
- if (dev2)
- dev2->next = dev2_next;
-
- /* Notify CRED provisiong result */
- if (con) {
- con->ret = ret;
- __notify_result(con);
- }
-
- if (uuid1)
- g_free(uuid1);
- if (uuid2)
- g_free(uuid2);
-}
-
-static int _cred_provisioning(ma_service *service,
- gchar *uuid_dev1, gchar *uuid_dev2)
-{
- ma_req_cb_s *con = NULL;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (!con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
-
- con->userdata = service;
- con->cid = MA_DO_CRED_PROVISIONING;
-
- if (!uuid_dev1 || !uuid_dev2) {
- MA_LOGE("Invaild Prameters");
- _request_cleanup(con);
- return MA_ERROR_INVALID_PARAMETER;
- }
-
- con->uuid_dev1 = g_strdup(uuid_dev1);
- con->uuid_dev2 = g_strdup(uuid_dev2);
-
- g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-
- return MA_ERROR_NONE;
-}
-
-int pairwise_ret;
-
-static void _resources_pairwise_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr,
- bool has_error)
-{
- ma_subowner_s *client = (ma_subowner_s *)ctx;
-
- if (!has_error) {
- MA_LOGD("Provision pairwise SUCCEEDED");
- pairwise_ret = MA_ERROR_NONE;
- } else {
- MA_LOGD("Provision pairwise FAILED ");
- pairwise_ret = nOfRes;
- ma_print_result_list((const OCProvisionResult_t*) arr, nOfRes);
- }
- client->g_doneCB = true;
-}
-
-static void _resources_pairwise_func(ma_req_cb_s *con)
-{
- OCStackResult ret = OC_STACK_OK;
-
- OicUuid_t *uuid_1 = NULL;
- OicUuid_t *uuid_2 = NULL;
- OicUuid_t *uuid_3 = NULL;
- OicUuid_t *uuid_4 = NULL;
-
- OicSecAcl_t* acl_1 = NULL;
- OicSecAcl_t* acl_2 = NULL;
-
- OCProvisionDev_t *target_dev_1 = NULL;
- OCProvisionDev_t *target_dev_2 = NULL;
- OCProvisionDev_t *subject_dev_1 = NULL;
- OCProvisionDev_t *subject_dev_2 = NULL;
-
- if (!g_client) {
- MA_LOGE("mot agent is not initialized");
- goto PVPAIRWIE_ERROR;
- }
- if (NULL == con) {
- MA_LOGE("container is NULL");
- goto PVPAIRWIE_ERROR;
- }
-
- uuid_1 = ma_convert_uuid(con->target_1);
- target_dev_1 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_1);
- if (!target_dev_1) {
- MA_LOGE("We can't find target in MOT enabled dev list");
- goto PVPAIRWIE_ERROR;
- }
-
- 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 = 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 = 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;
- }
-
- g_client->g_doneCB = false;
- MA_LOGI(" Provisioning Selected Pairwise..");
-
- acl_1 = _create_target_acl(&subject_dev_1->doxm->deviceID, con->rsrc_uri_1,
- con->rsrc_type_1, con->rsrc_interface_1, con->permission_1);
- if (NULL == acl_1) {
- MA_LOGE("Failed to create ACL for %s", con->rsrc_uri);
- goto PVPAIRWIE_ERROR;
- }
-
- acl_2 = _create_target_acl(&subject_dev_2->doxm->deviceID, con->rsrc_uri_2,
- con->rsrc_type_2, con->rsrc_interface_2, con->permission_2);
- if (NULL == acl_2) {
- MA_LOGE("Failed to create ACL for %s", con->rsrc_uri);
- goto PVPAIRWIE_ERROR;
- }
-
- /* Do both resources pairwise */
- ret = OCProvisionPairwiseDevices((void*) g_client, SYMMETRIC_PAIR_WISE_KEY,
- OWNER_PSK_LENGTH_256, target_dev_1, acl_1, target_dev_2, acl_2,
- _resources_pairwise_cb);
- if (OC_STACK_OK != ret) {
- MA_LOGD("OCProvisionPairwiseDevices API error: %d (%s)", ret,
- ma_ocf_error_to_string(ret));
- goto PVPAIRWIE_ERROR;
- }
-
- ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
- if (ret) {
- MA_LOGE("OCProvisionPairwise Faild = %d", errno);
- goto PVPAIRWIE_ERROR;
- }
- /* display the pairwise-provisioned result */
- MA_LOGI(" Provision pairwise Done");
-
-PVPAIRWIE_ERROR:
-
- /* Notify resource pairwise result */
- if (con) {
- con->ret = ret;
- __notify_result(con);
- }
-
- if (uuid_1)
- g_free(uuid_1);
- if (uuid_2)
- g_free(uuid_2);
- if (uuid_3)
- g_free(uuid_3);
- if (uuid_4)
- g_free(uuid_4);
- if (acl_1)
- OCDeleteACLList(acl_1);
- if (acl_2)
- OCDeleteACLList(acl_2);
-}
-
-static int _resources_pairwise(ma_service *service, gchar *target_1,
- gchar *subject_1, gchar *rsrc_uri_1, gchar *rsrc_type_1, gchar *rsrc_interface_1,
- int permission_1, gchar *target_2, gchar *subject_2, gchar *rsrc_uri_2,
- gchar *rsrc_type_2, gchar *rsrc_interface_2, int permission_2)
-{
- ma_req_cb_s *con = NULL;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (NULL == con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
-
- con->userdata = service;
- con->cid = MA_DO_RESOURCES_PAIRWISE;
-
- con->target_1 = g_strdup(target_1);
- con->subject_1 = g_strdup(subject_1);
- con->rsrc_uri_1 = g_strdup(rsrc_uri_1);
- con->rsrc_type_1 = g_strdup(rsrc_type_1);
- con->rsrc_interface_1 = g_strdup(rsrc_interface_1);
- con->permission_1 = permission_1;
-
- con->target_2 = g_strdup(target_2);
- con->subject_2 = g_strdup(subject_2);
- con->rsrc_uri_2 = g_strdup(rsrc_uri_2);
- con->rsrc_type_2 = g_strdup(rsrc_type_2);
- con->rsrc_interface_2 = g_strdup(rsrc_interface_2);
- con->permission_2 = permission_2;
-
- g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-
- return MA_ERROR_NONE;
-}
-
-static void _unlink_resources_cb(void* ctx, int nOfRes, OCProvisionResult_t* arr,
- bool has_error)
-{
- ma_subowner_s *client = (ma_subowner_s *)ctx;
-
- if (!has_error) {
- MA_LOGD("unlink SUCCEEDED");
- } else {
- MA_LOGD("unlink FAILED ");
- ma_print_result_list((const OCProvisionResult_t*) arr, nOfRes);
- }
- client->g_doneCB = true;
-}
-
-static void _unlink_resources_func(ma_req_cb_s *con)
-{
- OCStackResult ret = OC_STACK_OK;
-
- OicUuid_t *uuid1 = NULL;
- OicUuid_t *uuid2 = NULL;
- OCProvisionDev_t *dev1 = NULL;
- OCProvisionDev_t *dev2 = NULL;
-
- if (!g_client) {
- ret = OC_STACK_INVALID_PARAM;
- 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;
- }
- if (!con->uuid_dev2) {
- MA_LOGE("dev2 is NULL");
- goto PVUNLINKPAIRWISE_ERROR;
- }
-
- 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 = 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;
- }
-
- g_client->g_doneCB = false;
-
- MA_LOGI("Unlink Selected Pairwise Devices..");
- ret = OCUnlinkDevices((void*) g_client, dev1, dev2, _unlink_resources_cb);
- if (OC_STACK_OK != ret) {
- MA_LOGD("OCUnlinkDevices API error: %d (%s)", ret, ma_ocf_error_to_string(ret));
- goto PVUNLINKPAIRWISE_ERROR;
- }
-
- ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
- if (ret) {
- MA_LOGE("OCUnlinkDevices Faild = %d", errno);
- goto PVUNLINKPAIRWISE_ERROR;
- }
-
- /* display the pairwise-provisioned result */
- MA_LOGI("Unlink Devices");
-
-PVUNLINKPAIRWISE_ERROR:
- /* Notify resource unpair result */
- if (con) {
- con->ret = ret;
- __notify_result(con);
- }
-
- if (uuid1)
- g_free(uuid1);
- if (uuid2)
- g_free(uuid2);
-}
-
-static int _unlink_resources(ma_service *service,
- gchar *uuid_dev1, gchar *uuid_dev2)
-{
- ma_req_cb_s *con = NULL;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (!con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
-
- con->userdata = service;
- con->cid = MA_UNLINK_RESOURCES;
-
- if (!uuid_dev1 || !uuid_dev2) {
- MA_LOGE("Invaild Prameters");
- _request_cleanup(con);
- return MA_ERROR_INVALID_PARAMETER;
- }
-
- con->uuid_dev1 = g_strdup(uuid_dev1);
- con->uuid_dev2 = g_strdup(uuid_dev2);
-
- g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-
- return MA_ERROR_NONE;
-}
-
-static void _remove_subowner_cb(void* ctx, int num, OCProvisionResult_t* arr,
- bool has_error)
-{
- ma_subowner_s *client = (ma_subowner_s *)ctx;
-
- if (!has_error) {
- MA_LOGD("Remove Multiple Ownership SUCCEEDED");
- } else {
- MA_LOGD("Remove Multiple Ownership FAILED ");
- ma_print_result_list((const OCProvisionResult_t*) arr, num);
- }
- client->g_doneCB = true;
-}
-
-static void _remove_subowner_func(ma_req_cb_s *con)
-{
- OCStackResult ret = MA_ERROR_OPERATION_FAILED;
-
- OCProvisionDev_t *src_dev = NULL;
- OicUuid_t uuid_mowner;
- OicUuid_t *uuid_target = NULL;
-
- if (!g_client) {
- ret = OC_STACK_INVALID_PARAM;
- MA_LOGE("mot agent is not initialized");
- goto REMOVE_SUBOWNER_ENDED;
- }
- if (NULL == con) {
- ret = OC_STACK_INVALID_PARAM;
- MA_LOGE("container is NULL");
- goto REMOVE_SUBOWNER_ENDED;
- }
-
- if (!con->uuid_target_str) {
- MA_LOGE("Target device UUID is NULL");
- goto REMOVE_SUBOWNER_ENDED;
- }
-
- uuid_target = ma_convert_uuid(con->uuid_target_str);
- src_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_target);
- if (!src_dev) {
- MA_LOGE("We can't find in MOT dev list");
- goto REMOVE_SUBOWNER_ENDED;
- }
-
- g_client->g_doneCB = false;
-
- ret = GetDoxmDevOwnerId(&uuid_mowner);
- if (OC_STACK_OK != ret) {
- MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]",
- ret, ma_ocf_error_to_string(ret));
- goto REMOVE_SUBOWNER_ENDED;
- }
- ret = OCRemoveSubOwner(g_client, src_dev, &uuid_mowner, _remove_subowner_cb);
- if (OC_STACK_OK != ret) {
- MA_LOGE("OCRemoveSubOwner: ret = %d (%s)",
- ret, ma_ocf_error_to_string(ret));
- goto REMOVE_SUBOWNER_ENDED;
- }
-
- ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
- if (ret) {
- MA_LOGE("OCRemoveSubOwner callback error = %d (%s)",
- ret, ma_ocf_error_to_string(ret));
- goto REMOVE_SUBOWNER_ENDED;
- }
-
- MA_LOGI("Remove Multiple Ownership Done");
-
-REMOVE_SUBOWNER_ENDED:
- /* Notify remove multiple owner at the remote device */
- if (con) {
- con->ret = ret;
- __notify_result(con);
- }
-
- if (uuid_target)
- g_free(uuid_target);
-}
-
-static int _ma_remove_subowner(ma_service *service, gchar *uuid_str)
-{
- ma_req_cb_s *con = NULL;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (NULL == con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
-
- con->userdata = service;
- con->cid = MA_REMOVE_MULTIPLE_OWNED_DEVICE;
- con->uuid_target_str = g_strdup(uuid_str);
-
- g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-
- return MA_ERROR_NONE;
-}
-
-static void _remove_device_cb(void* ctx, int num,
- OCProvisionResult_t* arr, bool has_error)
-{
- ma_subowner_s *client = (ma_subowner_s *)ctx;
-
- if (!has_error) {
- MA_LOGD("Remove CRED for mowned device SUCCEEDED");
- } else {
- MA_LOGD("Remove CRED for mowned device FAILED ");
- ma_print_result_list((const OCProvisionResult_t*) arr, num);
- }
- client->g_doneCB = true;
-}
-
-static void _remove_device_func(ma_req_cb_s *con)
-{
- OCStackResult ret = OC_STACK_OK;
- OicUuid_t *uuid = NULL;
-
- if (!g_client) {
- ret = OC_STACK_INVALID_PARAM;
- MA_LOGE("mot agent is not initialized");
- goto REMOVE_DEVICE_END;
- }
- if (NULL == con) {
- ret = OC_STACK_INVALID_PARAM;
- MA_LOGE("container is NULL");
- goto REMOVE_DEVICE_END;
- }
- if (!con->target_to_revoke) {
- MA_LOGE("Some parameters are wrong");
- MA_LOGE("%s", con->target_to_revoke);
- goto REMOVE_DEVICE_END;
- }
-
- uuid = ma_convert_uuid(con->target_to_revoke);
-
- g_client->g_doneCB = false;
- MA_LOGI(" Removing CRED for remote device at local SVR DB");
-
- ret = OCRemoveDeviceWithUuid((void*) g_client, CALLBACK_TIMEOUT_5S, uuid,
- _remove_subowner_cb);
- if (OC_STACK_OK != ret) {
- MA_LOGD("OCRemoveDeviceWithUuid API error: %d (%s)",
- ret, ma_ocf_error_to_string(ret));
- goto REMOVE_DEVICE_END;
- }
-
- ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
- if (ret) {
- MA_LOGE("OCRemoveDeviceWithUuid Faild = %d", errno);
- goto REMOVE_DEVICE_END;
- }
- /* Disaply result result */
- MA_LOGI(" Removing CRED info. at local SVR DB - Done");
-
-REMOVE_DEVICE_END:
- /* Notify of result of removing CRED infor at local SVR DB */
- if (con) {
- con->ret = ret;
- __notify_result(con);
- }
-
- if (uuid)
- g_free(uuid);
-}
-
-static int _remove_device(ma_service *service, gchar *uuid_str)
-{
- ma_req_cb_s *con = NULL;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (NULL == con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
-
- con->userdata = service;
- con->cid = MA_REMOVE_DEVICE_WITH_UUID_IN_SVR;
- con->target_to_revoke = g_strdup(uuid_str);
-
- g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-
- return MA_ERROR_NONE;
-}
-
-static void _make_devices_pair_func(ma_req_cb_s *con)
-{
- OCStackResult ret = OC_STACK_OK;
-
- OicUuid_t *uuid_1 = NULL;
- OicUuid_t *uuid_2 = NULL;
- OicUuid_t *uuid_3 = NULL;
- OicUuid_t *uuid_4 = NULL;
-
- OicSecAcl_t* acl_1 = NULL;
- OicSecAcl_t* acl_2 = NULL;
-
- OCProvisionDev_t *target_dev_1 = NULL;
- OCProvisionDev_t *target_dev_2 = NULL;
- OCProvisionDev_t *subject_dev_1 = NULL;
- OCProvisionDev_t *subject_dev_2 = NULL;
-
- OCProvisionDev_t *src_dev = NULL;
- OCProvisionDev_t *next_dev = NULL;
-
- if (!g_client) {
- ret = OC_STACK_INVALID_PARAM;
- MA_LOGE("mot agent is not initialized");
- goto PV_PAIR_END;
- }
- if (NULL == con) {
- ret = OC_STACK_INVALID_PARAM;
- MA_LOGE("container is NULL");
- goto PV_PAIR_END;
- }
-
- uuid_1 = ma_convert_uuid(con->target_1);
- target_dev_1 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_1);
- if (!target_dev_1) {
- MA_LOGE("We can't find target in MOT enabled dev list");
- goto PV_PAIR_END;
- }
-
- uuid_2 = ma_convert_uuid(con->target_2);
- target_dev_2 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_2);
- if (!target_dev_2) {
- MA_LOGE("We can't find target in MOT enabled dev list");
- goto PV_PAIR_END;
- }
-
- uuid_3 = ma_convert_uuid(con->subject_1);
- subject_dev_1 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_3);
- if (!subject_dev_1) {
- MA_LOGE("We can't find subject in MOWNED dev list");
- goto PV_PAIR_END;
- }
-
- uuid_4 = ma_convert_uuid(con->subject_2);
- subject_dev_2 = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_4);
- if (!subject_dev_2) {
- MA_LOGE("We can't find subject in MOWNED dev list");
- goto PV_PAIR_END;
- }
-
- src_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, uuid_2);
- if (!src_dev) {
- MA_LOGE("We can't find in MOT dev list");
- goto PV_PAIR_END;
- }
- /* Copy next MOT enabled device pointer temporally */
- next_dev = src_dev->next;
- /* Next MOT enabled device set NULL to MOT a single device */
- src_dev->next = NULL;
-
- g_client->g_doneCB = false;
-
- if (OIC_PRECONFIG_PIN == src_dev->doxm->oxmSel) {
- /* Pre-Configured PIN initialization */
- const char* testPreconfigPin = con->pin;/* Ex) "12341234" */
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCAddPreconfigPin(src_dev, testPreconfigPin, strlen(testPreconfigPin));
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret) {
- MA_LOGE("Failed to save the pre-configured PIN");
- MA_LOGE("You can't use the pre-configured PIN OxM for MOT");
- goto PV_PAIR_END;
- }
- }
-
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCDoMultipleOwnershipTransfer(g_client, src_dev, _mot_cb);
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret) {
- MA_LOGE("OCDoMultipleOwnershipTransfer: ret = %d (%s)",
- ret, ma_ocf_error_to_string(ret));
- goto PV_PAIR_END;
- }
-
- ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
- if (OC_STACK_OK != ret) {
- MA_LOGE("OCDoMultipleOwnershipTransfer callback error = %d (%s)",
- ret, ma_ocf_error_to_string(ret));
- goto PV_PAIR_END;
- }
-
- MA_LOGI("MOT Done");
-
- g_client->g_doneCB = false;
-
- MA_LOGI(" Provisioning Selected Pairwise..");
-
- acl_1 = _create_target_acl(&subject_dev_1->doxm->deviceID, con->rsrc_uri_1,
- con->rsrc_type_1, con->rsrc_interface_1, con->permission_1);
- if (NULL == acl_1) {
- MA_LOGE("Failed to create ACL for %s", con->rsrc_uri);
- goto PV_PAIR_END;
- }
-
- acl_2 = _create_target_acl(&subject_dev_2->doxm->deviceID, con->rsrc_uri_2,
- con->rsrc_type_2, con->rsrc_interface_2, con->permission_2);
- if (NULL == acl_2) {
- MA_LOGE("Failed to create ACL for %s", con->rsrc_uri);
- goto PV_PAIR_END;
- }
-
- g_mutex_lock(&g_client->iotivity_mutex);
- pairwise_ret = MA_ERROR_OPERATION_FAILED;
- ret = OCProvisionPairwiseDevices((void*) g_client, SYMMETRIC_PAIR_WISE_KEY,
- OWNER_PSK_LENGTH_256, target_dev_1, acl_1,
- target_dev_2, acl_2, _resources_pairwise_cb);
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret) {
- MA_LOGD("OCProvisionPairwiseDevices API error: %d (%s)", ret,
- ma_ocf_error_to_string(ret));
- goto PV_PAIR_END;
- }
-
- ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
- if (ret) {
- MA_LOGE("OCProvisionPairwise Faild = %d", errno);
- goto PV_PAIR_END;
- }
- /* display the pairwise-provisioned result */
- MA_LOGI(" Provision pairwise Done");
-
-PV_PAIR_END:
- /* Restore MOT enabled devices */
- if (src_dev)
- src_dev->next = next_dev ;
-
- /* Notify pair result */
- if (con) {
- con->ret = pairwise_ret;
- __notify_result(con);
- }
- if (uuid_1)
- g_free(uuid_1);
- if (uuid_2)
- g_free(uuid_2);
- if (uuid_3)
- g_free(uuid_3);
- if (uuid_4)
- g_free(uuid_4);
- if (acl_1)
- OCDeleteACLList(acl_1);
- if (acl_2)
- OCDeleteACLList(acl_2);
-}
-
-static int _make_devices_pair(ma_service *service, gchar *sender, gchar *group_name, gchar *pin, gchar *target_1,
- gchar *subject_1, gchar *rsrc_uri_1, gchar *rsrc_type_1, gchar *rsrc_interface_1,
- int permission_1, gchar *target_2, gchar *subject_2, gchar *rsrc_uri_2,
- gchar *rsrc_type_2, gchar *rsrc_interface_2, int permission_2)
-{
- ma_req_cb_s *con = NULL;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (NULL == con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
-
- con->userdata = service;
- con->cid = MA_MAKE_PAIR;
- con->sender = g_strdup(sender);
- con->group_name = g_strdup(group_name);
-
- con->pin = g_strdup(pin);
- con->target_1 = g_strdup(target_1);
- con->subject_1 = g_strdup(subject_1);
- con->rsrc_uri_1 = g_strdup(rsrc_uri_1);
- con->rsrc_type_1 = g_strdup(rsrc_type_1);
- con->rsrc_interface_1 = g_strdup(rsrc_interface_1);
- con->permission_1 = permission_1;
-
- con->target_2 = g_strdup(target_2);
- con->subject_2 = g_strdup(subject_2);
- con->rsrc_uri_2 = g_strdup(rsrc_uri_2);
- con->rsrc_type_2 = g_strdup(rsrc_type_2);
- con->rsrc_interface_2 = g_strdup(rsrc_interface_2);
- con->permission_2 = permission_2;
-
- g_async_queue_push(g_client->queue, GINT_TO_POINTER(con));
-
- return MA_ERROR_NONE;
-}
-
-static void _make_devices_unpair_func(ma_req_cb_s *con)
-{
- OCStackResult ret = OC_STACK_OK;
-
- OicUuid_t uuid_mowner;
- OicUuid_t *owner_uuid = NULL;
- OicUuid_t *owned_uuid = NULL;
- OCProvisionDev_t *owner_dev = NULL;
- OCProvisionDev_t *owned_dev = NULL;
-
- if (NULL == g_client) {
- ret = OC_STACK_INVALID_PARAM;
- MA_LOGE("mot agent is not initialized");
- goto PV_UNPAIR_END;
- }
- if (NULL == con) {
- ret = OC_STACK_INVALID_PARAM;
- MA_LOGE("container is NULL");
- goto PV_UNPAIR_END;
- }
-
- if (NULL == con->uuid_dev1) {
- MA_LOGE("dev1 is NULL");
- goto PV_UNPAIR_END;
- }
- if (NULL == con->uuid_dev2) {
- MA_LOGE("dev2 is NULL");
- goto PV_UNPAIR_END;
- }
-
- owner_uuid = ma_convert_uuid(con->uuid_dev1);
- owner_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, owner_uuid);
- if (!owner_dev) {
- MA_LOGE("We can't find in MOT enabled dev list");
- goto PV_UNPAIR_END;
- }
-
- owned_uuid = ma_convert_uuid(con->uuid_dev2);
- owned_dev = ma_get_dev_by_uuid(g_client->g_motdev_list, owned_uuid);
- if (!owned_dev) {
- MA_LOGE("We can't find in MOT enabled dev list");
- goto PV_UNPAIR_END;
- }
-
-#ifdef DEBUG_UUID
- MA_LOGD("owner_dev = %s", ma_get_readable_uuid(owner_uuid));
- MA_LOGD("owned_dev = %s", ma_get_readable_uuid(owned_uuid));
-#endif
-
- MA_LOGI("Unlink Selected Pairwise Devices..");
- g_client->g_doneCB = false;
-
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCUnlinkDevices((void*) g_client, owner_dev, owned_dev, _unlink_resources_cb);
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret) {
- MA_LOGD("OCUnlinkDevices API error = %d (%s)",
- ret, ma_ocf_error_to_string(ret));
- } else {
- ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
- if (OC_STACK_OK != ret) {
- MA_LOGD("OCUnlinkDevices Timeout = %d (%s)",
- ret, ma_ocf_error_to_string(ret));
- }
- }
- MA_LOGI("Unlink Devices Done");
-
- MA_LOGI("Start Remove SubOwner..");
- g_client->g_doneCB = false;
-
- ret = GetDoxmDevOwnerId(&uuid_mowner);
- if (OC_STACK_OK != ret) {
- MA_LOGE("GetDoxmDevOwnerId faild = [%d][%s]",
- ret, ma_ocf_error_to_string(ret));
- }
-#ifdef DEBUG_UUID
- MA_LOGD("uuid_mowner = %s", ma_get_readable_uuid(&uuid_mowner));
-#endif
-
- MA_LOGI("Start Removing CRED for remote device at local SVR DB");
- g_client->g_doneCB = false;
-
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCRemoveDeviceWithUuid((void*) g_client, CALLBACK_TIMEOUT_5S, owned_uuid,
- _remove_device_cb);
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret) {
- MA_LOGD("OCRemoveDeviceWithUuid API error = %d (%s)",
- ret, ma_ocf_error_to_string(ret));
- }
-
- ret = _wait_cb_ret(CALLBACK_TIMEOUT_5S);
- if (OC_STACK_OK != ret) {
- MA_LOGD("OCRemoveDeviceWithUuid Timeout = %d (%s)",
- ret, ma_ocf_error_to_string(ret));
- goto PV_UNPAIR_END;
- }
- /* Disaply result result */
- MA_LOGI("Removing CRED info. at local SVR DB Done");
-
- MA_LOGI("Unlink Selected Pairwise Devices..");
-
- ret = PDMUnlinkDevices(owner_uuid, owned_uuid);
- if (OC_STACK_OK != ret) {
- MA_LOGD("PDMUnlinkDevices API error: %d (%s)", ret, ma_ocf_error_to_string(ret));
- goto PV_UNPAIR_END;
- }
-
- ret = PDMDeleteDevice(owned_uuid);
- if (OC_STACK_OK != ret) {
- MA_LOGD("PDMUnlinkDevices API error: %d (%s)", ret, ma_ocf_error_to_string(ret));
- goto PV_UNPAIR_END;
- }
-
- MA_LOGI("Unlink Devices Done");
-PV_UNPAIR_END:
- /* Notify unpair result */
- if (con) {
- con->ret = ret;
- __notify_result(con);
- }
-
- if (owner_uuid)
- g_free(owner_uuid);
- if (owned_uuid)
- g_free(owned_uuid);
-}
-
-static int _make_devices_unpair(ma_service *service, gchar *sender, gchar *group_name, gchar *uuid_dev1, gchar *uuid_dev2)
-{
- ma_req_cb_s *con = NULL;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (!con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
-
- con->userdata = service;
- con->cid = MA_MAKE_UNPAIR;
- con->sender = g_strdup(sender);
- con->group_name = g_strdup(group_name);
-
- if (!uuid_dev1 || !uuid_dev2) {
- MA_LOGE("Invaild Prameters");
- _request_cleanup(con);
- return MA_ERROR_INVALID_PARAMETER;
- }
-
- con->uuid_dev1 = g_strdup(uuid_dev1);
- con->uuid_dev2 = g_strdup(uuid_dev2);
-
- 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;
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- con = g_malloc0(sizeof(ma_req_cb_s));
- if (!con) {
- MA_LOGE("g_malloc0() Fail=%d", errno);
- /* Unset d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 0);
- return MA_ERROR_OUT_OF_MEMORY;
- }
- 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_provisioning_func(con);
- break;
- case MA_DO_CRED_PROVISIONING:
- _cred_provisioning_func(con);
- break;
- case MA_DO_RESOURCES_PAIRWISE:
- _resources_pairwise_func(con);
- break;
- case MA_REMOVE_MULTIPLE_OWNED_DEVICE:
- _remove_subowner_func(con);
- break;
- case MA_REMOVE_DEVICE_WITH_UUID_IN_SVR:
- _remove_device_func(con);
- break;
- case MA_UNLINK_RESOURCES:
- _unlink_resources_func(con);
- break;
- case MA_MAKE_PAIR:
- _make_devices_pair_func(con);
- break;
- case MA_MAKE_UNPAIR:
- _make_devices_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_client = g_malloc0(sizeof(ma_subowner_s));
- if (!g_client) {
- MA_LOGE("memory allocation error = %d", errno);
- return MA_ERROR_OUT_OF_MEMORY;
- }
- g_mutex_init(&g_client->iotivity_mutex);
- g_client->thread = g_thread_try_new("worker", _worker_thread, g_client, NULL);
- g_client->queue = g_async_queue_new();
- g_client->g_motdev_list = NULL;
- g_client->g_mowned_list = NULL;
- g_client->rnd_pin = NULL;
-
- snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
- "/opt/usr/data", PRVN_DB_FILE_NAME);
-
- /* initialize persistent storage for SVR DB */
- static OCPersistentStorage ps = { _fopen_prvn_mng, fread, fwrite, fclose, unlink };
-
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCRegisterPersistentStorageHandler(&ps);
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret) {
- MA_LOGE("OCRegisterPersistentStorageHandler error = %d", ret);
- return ret;
- }
-#if 0
- ma_set_device_id_seed();
-#endif
- /* initialize OC stack and provisioning manager */
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCInit(NULL, 0, OC_CLIENT_SERVER);
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret) {
- MA_LOGE("OCInit() error = [%d][%s]", ret, ma_ocf_error_to_string(ret));
- return ret;
- }
-
- /* Do Self-Ownership Transfer */
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCConfigSelfOwnership();
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret) {
- MA_LOGE("OCConfigSelfOwnership() error = [%d][%s]",
- ret, ma_ocf_error_to_string(ret));
- }
-
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCInitPM(data_dir);
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret) {
- MA_LOGE("OCInitPM() error = [%d][%s]", ret, ma_ocf_error_to_string(ret));
- return ret;
- }
-
- SetInputPinCB(_input_pin_cb);
-
- 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, ma_ocf_error_to_string(ret));
-
- ret = ConvertUuidToStr(&uuid, uuid_str);
- if (OC_STACK_OK != ret)
- MA_LOGE("ConvertUuidToStr faild = [%d][%s]", ret, ma_ocf_error_to_string(ret));
-
- return ret;
-}
-
-int ma_request_disc_mot_enb_devs(ma_service *service, char *sender, int 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] Find MOT enabled devices");
-
- /* If we are working now? */
- if (g_atomic_int_get(&g_client->pending))
- return MA_ERROR_IN_PROGRESS;
-
- /* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 1);
-
- ret = _disc_mot_enb_devs(service, sender, timeout);
-
- return ret;
-}
-
-int ma_request_disc_owned_devs(ma_service *service, char *sender, int 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] Find owned devices");
-
- /* If we are working now? */
- if (g_atomic_int_get(&g_client->pending))
- return MA_ERROR_IN_PROGRESS;
-
- /* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 1);
-
- ret = _disc_owned_devs(service, sender, timeout);
-
- return ret;
-}
-
-int ma_request_mot(ma_service *service, gchar* uuid_str, gchar *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] Do Mullti Ownership Transfer");
-
- /* If we are working now? */
- if (g_atomic_int_get(&g_client->pending))
- return MA_ERROR_IN_PROGRESS;
-
- if (!uuid_str || !pin) {
- MA_LOGE("uuid_str = %s", uuid_str);
- MA_LOGE("pin = %s", pin);
- return MA_ERROR_INVALID_PARAMETER;
- }
-
- /* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 1);
-
- ret = _mot(service, uuid_str, pin);
-
- return ret;
-}
-
-int ma_request_prov_acl(ma_service *service, gchar *target, gchar *subject,
- gchar *rsrc_uri, gchar *rsrc_type, gchar *rsrc_interface, int 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 ACL");
-
- /* If we are working now? */
- if (g_atomic_int_get(&g_client->pending))
- return MA_ERROR_IN_PROGRESS;
-
- ma_check_null_ret_error("target", target, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("subject", subject, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_uri", rsrc_uri, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_type", rsrc_type, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_interface", rsrc_interface, MA_ERROR_INVALID_PARAMETER);
-
- /* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 1);
-
- ret = _acl_provisioning(service, target, subject, rsrc_uri, rsrc_type, rsrc_interface,
- permission);
-
- return ret;
-}
-
-int ma_request_prov_cred(ma_service *service, gchar *uuid_dev1, gchar *uuid_dev2)
-{
- int ret = MA_ERROR_NONE;
-
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- ma_check_null_ret_error("service", service, FALSE);
-
- MA_LOGD("[IPC] Provisioning credential");
-
- /* If we are working now? */
- if (g_atomic_int_get(&g_client->pending))
- return MA_ERROR_IN_PROGRESS;
-
- if (!uuid_dev1 || !uuid_dev2) {
- MA_LOGE("uuid_dev1 = %s", uuid_dev1);
- MA_LOGE("uuid_dev2 = %s", uuid_dev2);
- return MA_ERROR_INVALID_PARAMETER;
- }
-
- /* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 1);
-
- ret = _cred_provisioning(service, uuid_dev1, uuid_dev2);
-
- return ret;
-}
-
-int ma_request_rsrc_pairwise(ma_service *service, gchar *target_1,
- gchar *subject_1, gchar *rsrc_uri_1, gchar *rsrc_type_1,
- gchar *rsrc_interface_1, int permission_1,
- gchar *target_2, gchar *subject_2, gchar *rsrc_uri_2,
- gchar *rsrc_type_2, gchar *rsrc_interface_2,
- int permission_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] Link both resources pairwise");
-
- /* If we are working now? */
- if (g_atomic_int_get(&g_client->pending))
- return MA_ERROR_IN_PROGRESS;
-
- ma_check_null_ret_error("target_1", target_1, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("subject_1", subject_1, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_uri_1", rsrc_uri_1, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_type_1", rsrc_type_1, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_interface_1", rsrc_interface_1, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("target_2", target_2, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("subject_2", subject_2, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_uri_2", rsrc_uri_2, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_type_2", rsrc_type_2, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_interface_2", rsrc_interface_2, MA_ERROR_INVALID_PARAMETER);
-
- /* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 1);
-
- ret = _resources_pairwise(service, target_1, subject_1, rsrc_uri_1,
- rsrc_type_1, rsrc_interface_1, permission_1, target_2,
- subject_2, rsrc_uri_2, rsrc_type_2, rsrc_interface_2,
- permission_2);
-
- return ret;
-
-}
-
-int ma_request_unlink_rsrc(ma_service *service, gchar *uuid_dev1,
- gchar *uuid_dev2)
-{
- int ret = MA_ERROR_NONE;
-
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- ma_check_null_ret_error("service", service, FALSE);
-
- MA_LOGD("[IPC] Unlink both devices");
-
- /* If we are working now? */
- if (g_atomic_int_get(&g_client->pending))
- return MA_ERROR_IN_PROGRESS;
-
- if (!uuid_dev1 || !uuid_dev2) {
- MA_LOGE("uuid_dev1 = %s", uuid_dev1);
- MA_LOGE("uuid_dev2 = %s", uuid_dev2);
- return MA_ERROR_INVALID_PARAMETER;
- }
-
- /* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 1);
-
- ret = _unlink_resources(service, uuid_dev1, uuid_dev2);
-
- return ret;
-}
-
-int ma_request_remove_subowner(ma_service *service, gchar* uuid_str)
-{
- int ret = MA_ERROR_NONE;
-
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- ma_check_null_ret_error("service", service, FALSE);
-
- MA_LOGD("[IPC] Remove Mulltiple Ownership");
-
- /* If we are working now? */
- if (g_atomic_int_get(&g_client->pending))
- return MA_ERROR_IN_PROGRESS;
-
- if (!uuid_str) {
- MA_LOGE("uuid_str = %s", uuid_str);
- return MA_ERROR_INVALID_PARAMETER;
- }
-
- /* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 1);
-
- ret = _ma_remove_subowner(service, uuid_str);
-
- return ret;
-}
-
-int ma_request_remove_device(ma_service *service, gchar* uuid_str)
-{
- int ret = MA_ERROR_NONE;
-
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- ma_check_null_ret_error("service", service, FALSE);
-
- MA_LOGD("[IPC] Remove target CRED in local SVR");
-
- /* If we are working now? */
- if (g_atomic_int_get(&g_client->pending))
- return MA_ERROR_IN_PROGRESS;
-
- if (!uuid_str) {
- MA_LOGE("uuid_str = %s", uuid_str);
- return MA_ERROR_INVALID_PARAMETER;
- }
-
- /* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 1);
-
- ret = _remove_device(service, uuid_str);
-
- return ret;
-}
-
-int ma_request_pair(ma_service *service, gchar *sender, gchar *group_name, 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)
-{
- 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] Make both devices pair ");
-
- /* If we are working now? */
- if (g_atomic_int_get(&g_client->pending))
- return MA_ERROR_IN_PROGRESS;
-
- ma_check_null_ret_error("pin", pin, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("target_1", target_1, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("subject_1", subject_1, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_uri_1", rsrc_uri_1, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_type_1", rsrc_type_1, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_interface_1", rsrc_interface_1, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("target_2", target_2, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("subject_2", subject_2, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_uri_2", rsrc_uri_2, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_type_2", rsrc_type_2, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("rsrc_interface_2", rsrc_interface_2, MA_ERROR_INVALID_PARAMETER);
-
- /* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 1);
-
- ret = _make_devices_pair(service, sender, group_name, pin, target_1, subject_1, rsrc_uri_1,
- rsrc_type_1, rsrc_interface_1, permission_1, target_2,
- subject_2, rsrc_uri_2, rsrc_type_2, rsrc_interface_2,
- permission_2);
-
- return ret;
-
-}
-
-int ma_request_unpair(ma_service *service, gchar *sender, gchar *group_name, gchar *uuid_dev1,
- gchar *uuid_dev2)
-{
- int ret = MA_ERROR_NONE;
-
- ma_check_null_ret_error("g_client", g_client, MA_ERROR_NO_DATA);
- ma_check_null_ret_error("service", service, FALSE);
-
- MA_LOGD("[IPC] Make both devices unpair");
-
- /* If we are working now? */
- if (g_atomic_int_get(&g_client->pending))
- return MA_ERROR_IN_PROGRESS;
-
- ma_check_null_ret_error("uuid_dev1", uuid_dev1, MA_ERROR_INVALID_PARAMETER);
- ma_check_null_ret_error("uuid_dev2", uuid_dev2, MA_ERROR_INVALID_PARAMETER);
-
- /* Set d2ds status 'pending' */
- g_atomic_int_set(&g_client->pending, 1);
-
- ret = _make_devices_unpair(service, sender, group_name, uuid_dev1, uuid_dev2);
-
- return ret;
-}
-
-int ma_request_enable(ma_service *service)
-{
- int ret = MA_ERROR_NONE;
- ma_check_null_ret_error("service", service, FALSE);
- ret = _init_provision_client();
- return ret;
-}
-
-int ma_request_disable(ma_service *service)
-{
- 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 (NULL == g_client)
- return MA_ERROR_NONE;
-
- /* Wait until worker thread exits */
- if (g_client->thread) {
- g_thread_join(g_client->thread);
- g_thread_unref(g_client->thread);
- g_client->thread = NULL;
- }
-
- /* Stop OCF threads */
- g_mutex_lock(&g_client->iotivity_mutex);
- ret = OCStop();
- g_mutex_unlock(&g_client->iotivity_mutex);
- if (OC_STACK_OK != ret)
- MA_LOGE("OCStack stop error");
-
- /* Stop provisioning */
- g_mutex_lock(&g_client->iotivity_mutex);
- OCTerminatePM();
- g_mutex_unlock(&g_client->iotivity_mutex);
-
- g_mutex_clear(&g_client->iotivity_mutex);
-
- /* Remove found devices list */
- _remove_owned_client();
- _remove_mot_client();
-
- /* Remove random PIN number */
- if (g_client->rnd_pin) {
- g_free(g_client->rnd_pin);
- g_client->rnd_pin = NULL;
- }
-
- /* Remove queue */
- while (0 < g_async_queue_length(g_client->queue)) {
- ma_req_cb_s *con = g_async_queue_pop(g_client->queue);
- _request_cleanup(con);
- }
- g_async_queue_unref(g_client->queue);
-
- g_free(g_client);
- g_client = NULL;
-
- return ret;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __MA_SUBONWER_H__
-#define __MA_SUBONWER_H__
-
-#include "ma.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* command id */
-typedef enum {
- MA_FIND_MOT_ENABLED_DEVICES = 0, /**< Discover MOT enabled devices */
- MA_FIND_MULTIPLE_OWNED_DEVICES, /**< Discover my owned MOT enabled devices */
- MA_DO_MOT, /**< Do Multiple Onwership Transfer */
- MA_DO_ACL_PROVISIONING, /**< ACL Provisioning */
- MA_DO_CRED_PROVISIONING, /**< CRED Provisioning */
- MA_UNLINK_RESOURCES, /**< Unlink */
- MA_REMOVE_MULTIPLE_OWNED_DEVICE, /**< Remove Multiple Ownership */
- MA_REMOVE_DEVICE_WITH_UUID_IN_SVR, /**< Remove CRED my owned device in MOT agent's SVR DB */
- MA_MAKE_PAIR, /**< Pair 2 devices */
- MA_MAKE_UNPAIR, /**< Unpair 2 devices */
- MA_DO_RESOURCES_PAIRWISE, /** < Pairwise Provisioning */
- MA_CMD_MAX /**< Max command id */
-} ma_cmd_id_e;
-
-/* ACL Permission type */
-typedef enum {
- MA_PERMISSION_CREATE = (1 << 0), /**< C */
- MA_PERMISSION_READ = (1 << 1), /**< R */
- MA_PERMISSION_WRITE = (1 << 2), /**< U */
- MA_PERMISSION_DELETE = (1 << 3), /**< D */
- MA_PERMISSION_NOTIFY = (1 << 4), /**< N */
- MA_PERMISSION_FULL = 0x11111 /**< CRUDN */
-} ma_permission_e;
-
-int ma_request_enable(ma_service *service);
-int ma_request_disable(ma_service *service);
-int ma_request_get_ownerid(ma_service *service, gchar **uuid_str);
-int ma_request_disc_mot_enb_devs(ma_service *service, char *sender, int timeout);
-int ma_request_disc_owned_devs(ma_service *service, char *sender, int timeout);
-int ma_request_mot(ma_service *service, gchar* uuid, gchar *pin);
-int ma_request_prov_acl(ma_service *service, gchar *target, gchar *subject,
- gchar *rsrc_uri, gchar *rsrc_type, gchar *rsrc_interface, int permission);
-int ma_request_prov_cred(ma_service *service, gchar *uuid_dev1, gchar *uuid_dev2);
-int ma_request_rsrc_pairwise(ma_service *service, gchar *target_1, gchar *subject_1,
- gchar *rsrc_uri_1, gchar *rsrc_type_1,
- gchar *rsrc_interface_1, int permission_1,
- gchar *target_2, gchar *subject_2, gchar *rsrc_uri_2,
- gchar *rsrc_type_2, gchar *rsrc_interface_2,
- int permission_2);
-int ma_request_unlink_rsrc(ma_service *service, gchar *uuid_dev1, gchar *uuid_dev2);
-int ma_request_remove_subowner(ma_service *service, gchar* uuid_str);
-int ma_request_remove_device(ma_service *service, gchar* uuid_str);
-int ma_request_pair(ma_service *service, gchar *sender, gchar *group_name, 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);
-int ma_request_unpair(ma_service *service, gchar *sender, gchar *group_name, gchar *uuid_owner, gchar *uuid_owned);
-int ma_delete_mot_agent(ma_service *service);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __MA_SUBONWER_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <glib.h>
-#include <wifi-manager.h>
-#include <tzplatform_config.h>
-
-#include <iotivity_config.h>
-#include <platform_features.h>
-
-#include "ma.h"
-#include "ma-log.h"
-#include "ma-util.h"
-
-#define CASE_TO_STR(x) case x: return #x;
-const char* ma_ocf_error_to_string(int 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_TOO_MANY_REQUESTS)
- 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";
- }
-}
-
-const char* ma_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";
- }
-}
-
-const char * ma_erro_to_string(ma_error_e err)
-{
- switch (err) {
- /* CHECK: List all enum values here */
- CASE_TO_STR(MA_ERROR_NONE)
- CASE_TO_STR(MA_ERROR_IO_ERROR)
- CASE_TO_STR(MA_ERROR_INVALID_PARAMETER)
- CASE_TO_STR(MA_ERROR_OUT_OF_MEMORY)
- CASE_TO_STR(MA_ERROR_PERMISSION_DENIED)
- CASE_TO_STR(MA_ERROR_NOT_SUPPORTED)
- CASE_TO_STR(MA_ERROR_NO_DATA)
- CASE_TO_STR(MA_ERROR_OPERATION_FAILED)
- CASE_TO_STR(MA_ERROR_ALREADY_REGISTERED)
- CASE_TO_STR(MA_ERROR_IN_PROGRESS)
- CASE_TO_STR(MA_ERROR_COMM_ERROR)
- CASE_TO_STR(MA_ERROR_RX)
- CASE_TO_STR(MA_ERROR_TX)
- CASE_TO_STR(MA_ERROR_PLUGIN_FAIL)
- CASE_TO_STR(MA_ERROR_ALREADY_IN_PROGRESS)
- CASE_TO_STR(MA_ERROR_NOT_STARTED)
- CASE_TO_STR(MA_ERROR_ALREADY_INITIALIZED)
- CASE_TO_STR(MA_ERROR_UNKNOWN)
- default :
- return "Unknown Error";
- }
-}
-
-OicUuid_t* ma_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};
-char* ma_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;
-}
-
-OCProvisionDev_t* ma_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", ma_get_readable_uuid(uuid));
-#endif
- OCProvisionDev_t* lst = (OCProvisionDev_t*)dev_lst;
- while (lst) {
-#ifdef DEBUG_UUID
- MA_LOGD("[C] : %s", ma_get_readable_uuid(&lst->doxm->deviceID));
-#endif
- if (!memcmp((const void *)&lst->doxm->deviceID, (const void *)uuid,
- sizeof(OicUuid_t))) {
- MA_LOGD("[M] : %s", ma_get_readable_uuid(&lst->doxm->deviceID));
- return lst;
- }
- lst = lst->next;
- }
-
- return NULL;
-}
-
-int ma_print_dev_list(const OCProvisionDev_t* dev_lst)
-{
- if (!dev_lst) {
- MA_LOGI("Device List is Empty..");
- return 0;
- }
-
- OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
- int lst_cnt = 0;
- for ( ; lst; ) {
- MA_LOGI("[%d] %s", ++lst_cnt, ma_get_readable_uuid((const OicUuid_t*)
- &lst->doxm->deviceID));
- lst = lst->next;
- }
-
- return lst_cnt;
-}
-
-int ma_print_result_list(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
-{
- if (!rslt_lst || 0 >= rslt_cnt) {
- MA_LOGI(" Device List is Empty..");
- return 0;
- }
-
- int lst_cnt = 0;
- for (; rslt_cnt > lst_cnt; ++lst_cnt) {
- MA_LOGD("%s : [%d][%s]",
- ma_get_readable_uuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId),
- rslt_lst[lst_cnt].res, ma_ocf_error_to_string(rslt_lst[lst_cnt].res));
- }
-
- return lst_cnt;
-}
-
-#if 0
-int ma_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, ma_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, ma_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, ma_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, ma_ocf_error_to_string(ret));
-
- wifi_manager_deinitialize(wifi_handle);
- return ret;
-}
-#endif
-
-#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
-
-int ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid)
-{
- if (NULL == uuid || NULL == strUuid || NULL != *strUuid) {
- MA_LOGE("ConvertUuidToStr : Invalid param");
- return OC_STACK_INVALID_PARAM;
- }
-
- size_t uuidIdx = 0;
- size_t urnIdx = 0;
- const size_t urnBufSize = (UUID_LENGTH * 2) + 4 + 1;
- char* convertedUrn = (char*)calloc(urnBufSize, sizeof(char));
- if (NULL == convertedUrn) {
- MA_LOGE("Memory Allocation Failed");
- goto exit;
- }
-
- for (uuidIdx = 0, urnIdx = 0; uuidIdx < UUID_LENGTH && urnIdx < urnBufSize;
- uuidIdx++, urnIdx += 2) {
- // canonical format for UUID has '8-4-4-4-12'
- if (uuidIdx == 4 || uuidIdx == 6 || uuidIdx == 8 || uuidIdx == 10) {
- snprintf(convertedUrn + urnIdx, 2, "%c", '-');
- urnIdx++;
- }
- snprintf(convertedUrn + urnIdx, 3, "%02x", (uint8_t)(uuid->id[uuidIdx]));
- }
- convertedUrn[urnBufSize - 1] = '\0';
-
- *strUuid = convertedUrn;
- return OC_STACK_OK;
-
-exit:
- return OC_STACK_NO_MEMORY;
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __MA_UTIL_H__
-#define __MA_UTIL_H__
-
-#include <glib.h>
-#include <unistd.h>
-#include <gio/gio.h>
-
-#include <wifi-manager.h>
-
-#include <octypes.h>
-#include <pmtypes.h>
-#include <pmutility.h>
-#include <securevirtualresourcetypes.h>
-
-#include "ma-log.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#define DEBUG_UUID /**< To print device uuid */
-
-#define WIFI_MAC_ADDR_LENGTH 17 /**< Wi-Fi MAC address size */
-
-#define NOTUSED(var) (var = var)
-
-#define ma_check_null_print_ret_error(msg, value, error) do { \
- if (G_UNLIKELY(NULL == (value))) { \
- MA_LOGE("%s", msg); \
- return error; \
- } \
-} while (FALSE)
-
-#define ma_check_null_ret_error(name, value, error) do { \
- if (G_UNLIKELY(NULL == (value))) { \
- MA_LOGE("%s is NULL", name); \
- return error; \
- } \
-} while (FALSE)
-
-#define ma_check_null_ret(name, value) do { \
- if (G_UNLIKELY(NULL == (value))) { \
- MA_LOGE("%s is NULL", name); \
- return; \
- } \
-} while (FALSE)
-
-const char* ma_ocf_error_to_string(int err);
-const char* ma_wifi_error_to_string(wifi_manager_error_e err);
-const char * ma_erro_to_string(ma_error_e err);
-OicUuid_t* ma_convert_uuid(gchar *device_id);
-char * ma_get_readable_uuid(const OicUuid_t* uuid);
-OCProvisionDev_t* ma_get_dev_by_uuid(const OCProvisionDev_t* dev_lst,
- const OicUuid_t* uuid);
-int ma_print_dev_list(const OCProvisionDev_t* dev_lst);
-int ma_print_result_list(const OCProvisionResult_t* rslt_lst, const int rslt_cnt);
-int ma_set_device_id_seed(void);
-int ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __MA_UTIL_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <glib.h>
-
-#include "ma.h"
-#include "ma-log.h"
-#include "ma-util.h"
-#include "ma-service.h"
-#include "ma-service-interface.h"
-
-/**< d2d-subowner service */
-ma_service *d2dssvc;
-
-int main(int argc, char *argv[])
-{
- ma_service *service = NULL;
- int ret_code = 0;
- gboolean ret;
-
- __MA_LOG_FUNC_ENTER__;
-
-#if !GLIB_CHECK_VERSION(2, 32, 0)
- if (!g_thread_supported())
- g_thread_init(NULL);
-#endif
-
-#if !GLIB_CHECK_VERSION(2, 36, 0)
- g_type_init();
-#endif
- NOTUSED(argc);
- NOTUSED(argv);
-
- MA_LOGI("service mainloop start");
-
- /* Create MOT agent */
- d2dssvc = service = ma_service_new();
-
- /* Initialize MOT agent service interface layer */
- ret = ma_service_interface_init(service);
- if (G_UNLIKELY(FALSE == ret)) {
- MA_LOGE("Service interface init. failed!");
- ret_code = EXIT_FAILURE;
- goto END;
- }
- /* Run MOT agent service */
- ret = ma_service_run(service);
- if (G_UNLIKELY(FALSE == ret)) {
- MA_LOGE("Run service failed!");
- ret_code = EXIT_FAILURE;
- }
-
-END:
- /* Free MOT agent service */
- ma_service_interface_deinit(service);
- ma_service_free(service);
- d2dssvc = NULL;
-
- __MA_LOG_FUNC_EXIT__;
- return ret_code;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __MA_AGENT_H__
-#define __MA_AGENT_H__
-
-#include <glib.h>
-#include <gio/gio.h>
-#include <tizen.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#ifndef TIZEN_ERROR_MDG
-#define TIZEN_ERROR_MDG -0x02F50000 /**< Base error code */
-#endif
-
-/**< Internal error code with d2ds daemon. It should be matched with API side */
-typedef enum {
- MA_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
- MA_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
- MA_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
- MA_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
- MA_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
- MA_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
- MA_ERROR_NO_DATA = TIZEN_ERROR_MDG | 0x01, /**< Data not exists */
- MA_ERROR_OPERATION_FAILED = TIZEN_ERROR_MDG | 0x02, /**< operation failed */
- MA_ERROR_ALREADY_REGISTERED = TIZEN_ERROR_MDG | 0x03, /**< Request already registered */
- MA_ERROR_IN_PROGRESS = TIZEN_ERROR_MDG | 0x04,/**< operation is in progress */
- MA_ERROR_COMM_ERROR = TIZEN_ERROR_MDG | 0x05, /**< communication error */
- MA_ERROR_RX = TIZEN_ERROR_MDG | 0x06, /**< RX error */
- MA_ERROR_TX = TIZEN_ERROR_MDG | 0x07, /**< TX error */
- MA_ERROR_PLUGIN_FAIL = TIZEN_ERROR_MDG | 0x08, /**< Plugin failed */
- MA_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_MDG | 0x09, /**< Already in progress */
- MA_ERROR_NOT_STARTED = TIZEN_ERROR_MDG | 0x0A, /**< Not Started */
- MA_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_MDG | 0x0B, /**< Already initilized */
- MA_ERROR_UNKNOWN = -999,
-} ma_error_e;
-
-/**< d2d-subowner service structure */
-typedef struct _ma_service {
- GMainLoop *main_loop; /**< Service main-loop */
- guint dbus_id; /**< D-Bus id */
- guint activation_dbus_id; /**< D-Bus id for activation */
- gpointer connection; /**< Connection handle for D-Bus call to other process */
- GCancellable *ca; /**< Cancellable object for D-Bus call (Daemon->other) */
- GList *dbus_sub_ids; /**< The list of subscribed signals */
- gboolean ma_activated; /**< Whether d2d-manager enabled or not */
-} ma_service;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __MA_AGENT_H__ */
-
+++ /dev/null
-{
- "acl": {
- "aclist": {
- "aces": [
- {
- "subjectuuid": "*",
- "resources": [
- {
- "href": "/oic/res",
- "rel": "",
- "rt": ["oic.wk.res"],
- "if": ["oic.if.ll"]
- },{
- "href": "/oic/d",
- "rel": "",
- "rt": ["oic.wk.d"],
- "if": ["oic.if.baseline", "oic.if.r"]
- },{
- "href": "/oic/p",
- "rel": "",
- "rt": ["oic.wk.p"],
- "if": ["oic.if.baseline", "oic.if.r"]
- }
- ],
- "permission": 2
- },
- {
- "subjectuuid": "*",
- "resources": [
- {
- "href": "/oic/sec/doxm",
- "rel": "",
- "rt": ["oic.r.doxm"],
- "if": ["oic.if.baseline"]
- },
- {
- "href": "/oic/sec/pstat",
- "rel": "",
- "rt": ["oic.r.pstat"],
- "if": ["oic.if.baseline"]
- },
- {
- "href": "/oic/sec/cred",
- "rel": "",
- "rt": ["oic.r.cred"],
- "if": ["oic.if.baseline"]
- }
- ],
- "permission": 6
- }
- ]
- },
- "rowneruuid": "00000000-0000-0000-0000-000000000000"
- },
- "pstat": {
- "isop": false,
- "deviceuuid": "00000000-0000-0000-0000-000000000000",
- "rowneruuid": "00000000-0000-0000-0000-000000000000",
- "cm": 2,
- "tm": 0,
- "om": 4,
- "sm": 4
- },
- "doxm": {
- "oxms": [0],
- "oxmsel": 0,
- "sct": 0,
- "owned": false,
- "deviceuuid": "00000000-0000-0000-0000-000000000000",
- "devowneruuid": "",
- "rowneruuid": "00000000-0000-0000-0000-000000000000"
- }
-}