MESSAGE(" - Start building src directories")
ADD_SUBDIRECTORY(src/d2d-manager)
-ADD_SUBDIRECTORY(src/subowner)
+ADD_SUBDIRECTORY(src/d2d-subowner)
ADD_SUBDIRECTORY(src/fn-manager)
ADD_SUBDIRECTORY(test)
--- /dev/null
+MESSAGE("===================================================================")
+MESSAGE("Building...subowner client")
+MESSAGE("===================================================================")
+SET(INTROSPECTION_PATH ${CMAKE_CURRENT_SOURCE_DIR}/introspection)
+ADD_CUSTOM_COMMAND(
+ OUTPUT dbus1
+ COMMAND gdbus-codegen
+ --interface-prefix net.d2ds.
+ --generate-c-code d2ds-generated-code
+ --c-generate-object-manager
+ --generate-docbook generated-docs
+ ${INTROSPECTION_PATH}/d2ds.xml
+ ${INTROSPECTION_PATH}/enabler.xml
+ COMMENT "Generating d2ds GDBus .c/.h"
+)
+
+ADD_CUSTOM_TARGET(GENERATED_D2DS_DBUS_CODE DEPENDS dbus1)
+MESSAGE(" - Set source folder")
+FILE(GLOB SUBOWNER_SRCS *.c)
+SET(SUBOWNER_SRCS ${SUBOWNER_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/d2ds-generated-code.c)
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/d2ds-generated-code.c PROPERTIES GENERATED TRUE)
+
+SET(SUBOWNER "d2d-subowner")
+ADD_EXECUTABLE(${SUBOWNER} ${SUBOWNER_SRCS})
+ADD_DEPENDENCIES(${SUBOWNER} GENERATED_D2DS_DBUS_CODE)
+TARGET_LINK_LIBRARIES(${SUBOWNER} ${daemon_pkgs_LIBRARIES} pthread)
+INSTALL(TARGETS ${SUBOWNER} DESTINATION bin)
--- /dev/null
+/*\r
+ * Network Configuration Module\r
+ *\r
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+#ifndef __D2DS_LOG_H__\r
+#define __D2DS_LOG_H__\r
+\r
+#ifdef D2DS_LOG_TAG\r
+#undef D2DS_LOG_TAG\r
+#endif\r
+\r
+#ifdef USE_DLOG\r
+#include <dlog.h>\r
+\r
+#undef D2DS_LOG_TAG\r
+#define D2DS_LOG_TAG "D2D_SUBOWNER"\r
+\r
+#define D2DS_LOGV(format, args...) LOGV(format, ##args)\r
+#define D2DS_LOGD(format, args...) LOGD(format, ##args)\r
+#define D2DS_LOGI(format, args...) LOGI(format, ##args)\r
+#define D2DS_LOGW(format, args...) LOGW(format, ##args)\r
+#define D2DS_LOGE(format, args...) LOGE(format, ##args)\r
+#define D2DS_LOGF(format, args...) LOGF(format, ##args)\r
+\r
+#define __D2DS_LOG_FUNC_ENTER__ LOGD("Enter")\r
+#define __D2DS_LOG_FUNC_EXIT__ LOGD("Quit")\r
+\r
+#define D2DS_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, D2DS_LOG_TAG, format, ##args)\r
+#define D2DS_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, D2DS_LOG_TAG, format, ##args)\r
+\r
+#else /* USE_DLOG */\r
+\r
+#define D2DS_LOGV(format, args...)\r
+#define D2DS_LOGD(format, args...)\r
+#define D2DS_LOGI(format, args...)\r
+#define D2DS_LOGW(format, args...)\r
+#define D2DS_LOGE(format, args...)\r
+#define D2DS_LOGF(format, args...)\r
+\r
+#define __D2DS_LOG_FUNC_ENTER__\r
+#define __D2DS_LOG_FUNC_EXIT__\r
+\r
+#define D2DS_SECLOGI(format, args...)\r
+#define D2DS_SECLOGD(format, args...)\r
+\r
+#endif /* USE_DLOG */\r
+\r
+#endif /* __D2DS_LOG_H__ */\r
--- /dev/null
+/*\r
+ * Network Configuration Module\r
+ *\r
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+#include <glib.h>\r
+\r
+#include "d2ds.h"\r
+#include "d2ds-log.h"\r
+#include "d2ds-util.h"\r
+#include "d2ds-service.h"\r
+#include "d2ds-service-interface.h"\r
+#include "d2ds-generated-code.h"\r
+\r
+static NetD2ds *d2ds_dbus_object;\r
+static Enabler *d2ds_activator_dbus_object;\r
+\r
+/* global list to care resource handle for each client */\r
+static GList *d2ds_dbus_client_list;\r
+static GMutex d2ds_dbus_client_list_mutex;\r
+\r
+typedef struct _d2ds_dbus_client_s {\r
+ gchar *bus_name;\r
+} d2ds_dbus_client_s;\r
+\r
+NetD2ds* d2ds_dbus_get_object()\r
+{\r
+ return d2ds_dbus_object;\r
+}\r
+\r
+static int _d2ds_dbus_client_list_cleanup(GList *client_list)\r
+{\r
+ d2ds_dbus_client_s *client;\r
+\r
+ d2ds_check_null_ret_error("client_list", client_list, FALSE);\r
+\r
+ client = client_list->data;\r
+\r
+ g_free(client->bus_name);\r
+ client->bus_name = NULL;\r
+ g_free(client);\r
+ g_list_free(client_list);\r
+\r
+ return D2DS_ERROR_NONE;\r
+}\r
+\r
+static int _d2ds_dbus_client_list_compare_bus_name(const void *a, const void *b)\r
+{\r
+ const d2ds_dbus_client_s *client = a;\r
+ return g_strcmp0(client->bus_name, b);\r
+}\r
+\r
+static inline GList* _d2ds_dbus_client_list_find_client(const gchar *owner)\r
+{\r
+ return g_list_find_custom(d2ds_dbus_client_list, owner,\r
+ _d2ds_dbus_client_list_compare_bus_name);\r
+}\r
+\r
+static void _d2ds_dbus_name_owner_changed_cb(GDBusConnection *conn,\r
+ const gchar *sender_name,\r
+ const gchar *object_path,\r
+ const gchar *interface_name,\r
+ const gchar *signal_name,\r
+ GVariant *parameters,\r
+ gpointer user_data)\r
+{\r
+ int ret;\r
+ GList *client = NULL;\r
+ gchar *name, *old_owner, *new_owner;\r
+\r
+ NOTUSED(conn);\r
+ NOTUSED(sender_name);\r
+ NOTUSED(object_path);\r
+ NOTUSED(interface_name);\r
+ NOTUSED(signal_name);\r
+ NOTUSED(user_data);\r
+\r
+ g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);\r
+\r
+ if (0 == strlen(new_owner)) {\r
+ g_mutex_lock(&d2ds_dbus_client_list_mutex);\r
+ client = _d2ds_dbus_client_list_find_client(old_owner);\r
+ if (client) { /* found bus name in our bus list */\r
+ D2DS_LOGD("bus(%s) stopped", old_owner);\r
+ d2ds_dbus_client_list = g_list_remove_link(d2ds_dbus_client_list, client);\r
+ }\r
+ g_mutex_unlock(&d2ds_dbus_client_list_mutex);\r
+\r
+ if (client) {\r
+ ret = _d2ds_dbus_client_list_cleanup(client);\r
+ if (D2DS_ERROR_NONE != ret)\r
+ D2DS_LOGE("_d2ds_dbus_client_list_cleanup() Fail(%d)", ret);\r
+ }\r
+ }\r
+}\r
+\r
+static int _d2ds_dbus_subscribe_name_owner_changed(GDBusConnection *conn)\r
+{\r
+ unsigned int id;\r
+\r
+ id = g_dbus_connection_signal_subscribe(conn,\r
+ "org.freedesktop.DBus", /* bus name */\r
+ "org.freedesktop.DBus", /* interface */\r
+ "NameOwnerChanged", /* member */\r
+ "/org/freedesktop/DBus", /* path */\r
+ NULL, /* arg0 */\r
+ G_DBUS_SIGNAL_FLAGS_NONE,\r
+ _d2ds_dbus_name_owner_changed_cb,\r
+ NULL,\r
+ NULL);\r
+ if (0 == id) {\r
+ D2DS_LOGE("g_dbus_connection_signal_subscribe() Fail");\r
+ return D2DS_ERROR_IO_ERROR;\r
+ }\r
+\r
+ return D2DS_ERROR_NONE;\r
+}\r
+\r
+\r
+static gboolean _d2ds_dbus_handle_disc_mot_enb_devs(NetD2ds *object,\r
+ GDBusMethodInvocation *invocation,\r
+ gpointer user_data)\r
+{\r
+ int ret = D2DS_ERROR_NONE;\r
+ d2ds_service *service = (d2ds_service *)user_data;\r
+\r
+ d2ds_check_null_ret_error("service", service, FALSE);\r
+\r
+#if 0\r
+ ret = d2ds_request_disc_mot_enb_devs(service);\r
+ if (D2DS_ERROR_NONE != ret)\r
+ D2DS_LOGE("Failed to d2ds_request_disc_mot_enb_devs !");\r
+#endif\r
+ net_d2ds_complete_disc_mot_enb_devs(object, invocation, ret);\r
+\r
+ return TRUE;\r
+}\r
+\r
+static gboolean _d2ds_dbus_handle_disc_moted_devs(NetD2ds *object,\r
+ GDBusMethodInvocation *invocation,\r
+ gpointer user_data)\r
+{\r
+ int ret = D2DS_ERROR_NONE;\r
+ d2ds_service *service = (d2ds_service *)user_data;\r
+\r
+ d2ds_check_null_ret_error("service", service, FALSE);\r
+\r
+#if 0\r
+ ret = d2ds_request_disc_moted_devs(service);\r
+ if (D2DS_ERROR_NONE != ret)\r
+ D2DS_LOGE("Failed to d2ds_request_disc_moted_devs !");\r
+#endif\r
+ net_d2ds_complete_disc_moted_devs(object, invocation, ret);\r
+\r
+ return TRUE;\r
+}\r
+\r
+static gboolean _d2ds_dbus_handle_mot(NetD2ds *object,\r
+ GDBusMethodInvocation *invocation,\r
+ gchar *target,\r
+ gchar *pin,\r
+ gpointer user_data)\r
+{\r
+ int ret = D2DS_ERROR_NONE;\r
+ d2ds_service *service = (d2ds_service *)user_data;\r
+\r
+ d2ds_check_null_ret_error("service", service, FALSE);\r
+\r
+#if 0\r
+ ret = d2ds_request_mot(service);\r
+ if (D2DS_ERROR_NONE != ret)\r
+ D2DS_LOGE("Failed to d2ds_request_disc_moted_devs !");\r
+#endif\r
+ net_d2ds_complete_mot(object, invocation, ret);\r
+\r
+ return TRUE;\r
+}\r
+\r
+static gboolean _d2ds_dbus_handle_mot_pairwise(NetD2ds *object,\r
+ GDBusMethodInvocation *invocation,\r
+ gchar *arg_subject,\r
+ gchar *arg_uri,\r
+ gint arg_permission,\r
+ gchar *arg_target,\r
+ gpointer user_data)\r
+{\r
+ int ret = D2DS_ERROR_NONE;\r
+ d2ds_service *service = (d2ds_service *)user_data;\r
+\r
+ d2ds_check_null_ret_error("service", service, FALSE);\r
+\r
+#if 0\r
+ ret = d2ds_request_mot_pairwise(service);\r
+ if (D2DS_ERROR_NONE != ret)\r
+ D2DS_LOGE("Failed to d2ds_request_mot_pairwise !");\r
+#endif\r
+ net_d2ds_complete_mot_pairwise(object, invocation, ret);\r
+\r
+ return TRUE;\r
+}\r
+\r
+\r
+static void _d2ds_dbus_on_bus_acquired(GDBusConnection *conn, const gchar *name,\r
+ gpointer user_data)\r
+{\r
+ gboolean ret;\r
+ GError *error = NULL;\r
+ d2ds_service *service = (d2ds_service *)user_data;\r
+\r
+ NOTUSED(name);\r
+\r
+ d2ds_dbus_object = net_d2ds_skeleton_new();\r
+ if (NULL == d2ds_dbus_object) {\r
+ D2DS_LOGE("net_d2ds_skeleton_new() Fail");\r
+ return;\r
+ }\r
+\r
+ g_signal_connect(d2ds_dbus_object, "handle-disc-mot-enb-devs",\r
+ G_CALLBACK(_d2ds_dbus_handle_disc_mot_enb_devs), service);\r
+ g_signal_connect(d2ds_dbus_object, "handle-disc-moted-devs",\r
+ G_CALLBACK(_d2ds_dbus_handle_disc_moted_devs), service);\r
+ g_signal_connect(d2ds_dbus_object, "handle-mot",\r
+ G_CALLBACK(_d2ds_dbus_handle_mot), service);\r
+ g_signal_connect(d2ds_dbus_object, "handle-mot-pairwise",\r
+ G_CALLBACK(_d2ds_dbus_handle_mot_pairwise), service);\r
+\r
+ ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(d2ds_dbus_object),\r
+ conn, D2DS_DBUS_OBJPATH, &error);\r
+ if (FALSE == ret) {\r
+ D2DS_LOGE("g_dbus_interface_skeleton_export() Fail(%s)", error->message);\r
+ g_error_free(error);\r
+ }\r
+\r
+ ret = _d2ds_dbus_subscribe_name_owner_changed(conn);\r
+ if (D2DS_ERROR_NONE != ret) {\r
+ D2DS_LOGE("_d2ds_dbus_subscribe_name_owner_changed() Fail(%d)", ret);\r
+ return;\r
+ }\r
+\r
+}\r
+\r
+static void _d2ds_dbus_on_name_lost(GDBusConnection *conn, const gchar *name,\r
+ gpointer user_data)\r
+{\r
+ NOTUSED(conn);\r
+ NOTUSED(user_data);\r
+\r
+ D2DS_LOGD("Lost the name %s", name);\r
+}\r
+\r
+static void _d2ds_dbus_on_name_acquired(GDBusConnection *conn, const gchar *name,\r
+ gpointer user_data)\r
+{\r
+ NOTUSED(conn);\r
+ NOTUSED(user_data);\r
+\r
+ D2DS_LOGD("Acquired the name %s", name);\r
+}\r
+\r
+static gboolean _d2ds_dbus_handle_enable(Enabler *object,\r
+ GDBusMethodInvocation *invocation,\r
+ gpointer user_data)\r
+{\r
+ int ret = D2DS_ERROR_NONE;\r
+ d2ds_service *service = (d2ds_service *)user_data;\r
+\r
+ __D2DS_LOG_FUNC_ENTER__;\r
+\r
+ /* Do API response first */\r
+ enabler_complete_enable(object, invocation, ret);\r
+ service->d2ds_activated = TRUE;\r
+\r
+ /* Notify d2ds enabled */\r
+ net_d2ds_emit_subowner_enabled(d2ds_dbus_get_object(), ret);\r
+\r
+ __D2DS_LOG_FUNC_EXIT__;\r
+\r
+ return TRUE;\r
+}\r
+\r
+static gboolean _d2ds_dbus_handle_disable(Enabler *object,\r
+ GDBusMethodInvocation *invocation,\r
+ gpointer user_data)\r
+{\r
+ int ret = D2DS_ERROR_NONE;\r
+ d2ds_service *service = (d2ds_service *)user_data;\r
+\r
+ __D2DS_LOG_FUNC_ENTER__;\r
+\r
+ /* Make response first */\r
+ enabler_complete_disable(object, invocation, ret);\r
+\r
+ /* Terminate daemon */\r
+ d2ds_service_exit(service);\r
+\r
+ return TRUE;\r
+}\r
+\r
+static void _d2ds_dbus_on_activator_bus_acquired(GDBusConnection *conn,\r
+ const gchar *name, gpointer user_data)\r
+{\r
+ gboolean ret;\r
+ GError *error = NULL;\r
+ d2ds_service *service = (d2ds_service *)user_data;\r
+\r
+ NOTUSED(name);\r
+\r
+ __D2DS_LOG_FUNC_ENTER__;\r
+\r
+ d2ds_activator_dbus_object = enabler_skeleton_new();\r
+ if (NULL == d2ds_activator_dbus_object) {\r
+ D2DS_LOGE("enabler_skeleton_new() Fail");\r
+ return;\r
+ }\r
+\r
+ g_signal_connect(d2ds_activator_dbus_object, "handle-enable",\r
+ G_CALLBACK(_d2ds_dbus_handle_enable), service);\r
+ g_signal_connect(d2ds_activator_dbus_object, "handle-disable",\r
+ G_CALLBACK(_d2ds_dbus_handle_disable), service);\r
+\r
+ ret = g_dbus_interface_skeleton_export(\r
+ G_DBUS_INTERFACE_SKELETON(d2ds_activator_dbus_object),\r
+ conn, D2DS_DBUS_ENABLER_OBJPATH, &error);\r
+ if (FALSE == ret) {\r
+ D2DS_LOGE("g_dbus_interface_skeleton_export() Fail(%s)", error->message);\r
+ g_error_free(error);\r
+ }\r
+\r
+ __D2DS_LOG_FUNC_EXIT__;\r
+\r
+}\r
+\r
+static gboolean _d2ds_dbus_interface_init(d2ds_service *service)\r
+{\r
+ guint id;\r
+ guint activation_dbus_id;\r
+ d2ds_check_null_ret_error("service", service, FALSE);\r
+\r
+ id = g_bus_own_name(G_BUS_TYPE_SYSTEM,\r
+ D2DS_DBUS_INTERFACE,\r
+ G_BUS_NAME_OWNER_FLAGS_REPLACE,\r
+ _d2ds_dbus_on_bus_acquired,\r
+ _d2ds_dbus_on_name_acquired,\r
+ _d2ds_dbus_on_name_lost,\r
+ service,\r
+ NULL);\r
+ if (0 == id) {\r
+ D2DS_LOGE("g_bus_own_name() Fail");\r
+ return FALSE;\r
+ }\r
+\r
+ /* Get D-Bus owner to activate subowner service daemon */\r
+ activation_dbus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,\r
+ D2DS_DBUS_INTERFACE".enabler",\r
+ G_BUS_NAME_OWNER_FLAGS_REPLACE,\r
+ _d2ds_dbus_on_activator_bus_acquired,\r
+ NULL,\r
+ NULL,\r
+ service,\r
+ NULL);\r
+\r
+ service->dbus_id = id;\r
+ service->activation_dbus_id = activation_dbus_id;\r
+\r
+ return TRUE;\r
+}\r
+\r
+static void _d2ds_dbus_deinit(d2ds_service *service)\r
+{\r
+ d2ds_check_null_ret("service", service);\r
+\r
+ g_bus_unown_name(service->dbus_id);\r
+ g_bus_unown_name(service->activation_dbus_id);\r
+}\r
+\r
+gboolean d2ds_service_interface_init(d2ds_service *service)\r
+{\r
+ guint ret;\r
+ d2ds_check_null_ret_error("service", service, FALSE);\r
+\r
+ __D2DS_LOG_FUNC_ENTER__;\r
+\r
+ /* Initialize dbus interface */\r
+ ret = _d2ds_dbus_interface_init(service);\r
+ if (FALSE == ret) {\r
+ D2DS_LOGE("%s failed!!!", __func__);\r
+ return FALSE;\r
+ }\r
+\r
+ __D2DS_LOG_FUNC_EXIT__;\r
+\r
+ return TRUE;\r
+}\r
+\r
+void d2ds_service_interface_deinit(d2ds_service *service)\r
+{\r
+ d2ds_check_null_ret("service", service);\r
+\r
+ /* De-initialize dbus interface */\r
+ _d2ds_dbus_deinit(service);\r
+}\r
+\r
--- /dev/null
+/*\r
+ * Network Configuration Module\r
+ *\r
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+#ifndef __D2DS_SERVICE_INTERFACE_H__\r
+#define __D2DS_SERVICE_INTERFACE_H__\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/**< Mesh D-BUS service*/\r
+#define D2DS_DBUS_SERVICE "net.d2ds"\r
+\r
+/**< Mesh D-BUS service path */\r
+#define D2DS_DBUS_PATH "/net/d2ds"\r
+\r
+#ifndef D2DS_DBUS_INTERFACE\r
+#define D2DS_DBUS_INTERFACE "net.d2ds"\r
+#endif\r
+\r
+#ifndef D2DS_DBUS_OBJPATH\r
+#define D2DS_DBUS_OBJPATH "/net/d2ds"\r
+#endif\r
+\r
+#ifndef D2DS_DBUS_ENABLER_OBJPATH\r
+#define D2DS_DBUS_ENABLER_OBJPATH "/net/d2ds/enabler"\r
+#endif\r
+\r
+gboolean d2ds_service_interface_init(d2ds_service *service);\r
+void d2ds_service_interface_deinit(d2ds_service *service);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* __D2DS_SERVICE_INTERFACE_H__ */\r
+\r
--- /dev/null
+/*\r
+ * Network Configuration Module\r
+ *\r
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+#include <glib.h>\r
+\r
+#include "d2ds.h"\r
+#include "d2ds-log.h"\r
+#include "d2ds-util.h"\r
+\r
+d2ds_service *d2ds_service_new()\r
+{\r
+ d2ds_service *service;\r
+\r
+ service = g_malloc0(sizeof(struct _d2ds_service));\r
+\r
+ /* Create g-main loop */\r
+ service->main_loop = g_main_loop_new(NULL, FALSE);\r
+ if (G_UNLIKELY(NULL == service->main_loop)) {\r
+ D2DS_LOGE("g-main loop creation failed!!!");\r
+ g_free(service);\r
+ return NULL;\r
+ }\r
+\r
+ return service;\r
+}\r
+\r
+void d2ds_service_free(d2ds_service *service)\r
+{\r
+ d2ds_check_null_ret("service", service);\r
+\r
+ /* Unref 'g-main loop' */\r
+ if (service->main_loop)\r
+ g_main_loop_unref(service->main_loop);\r
+\r
+ g_free(service);\r
+}\r
+\r
+gboolean d2ds_service_run(d2ds_service *service)\r
+{\r
+ d2ds_check_null_ret_error("service", service, FALSE);\r
+ d2ds_check_null_ret_error("service->main_loop", service->main_loop, FALSE);\r
+\r
+ g_main_loop_run(service->main_loop);\r
+\r
+ return TRUE;\r
+}\r
+\r
+gboolean d2ds_service_exit(d2ds_service *service)\r
+{\r
+ d2ds_check_null_ret_error("service", service, FALSE);\r
+ d2ds_check_null_ret_error("service->main_loop", service->main_loop, FALSE);\r
+\r
+ g_main_loop_quit(service->main_loop);\r
+\r
+ return TRUE;\r
+}\r
--- /dev/null
+/*\r
+ * Network Configuration Module\r
+ *\r
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+#ifndef __D2DS_SERVICE_H__\r
+#define __D2DS_SERVICE_H__\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+d2ds_service* d2ds_service_new();\r
+void d2ds_service_free(d2ds_service *service);\r
+gboolean d2ds_service_run(d2ds_service *service);\r
+gboolean d2ds_service_exit(d2ds_service *service);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* __D2DS_SERVICE_H__ */\r
+\r
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics 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 "iotivity_config.h"
+
+#include <stdio.h>
+#include <string.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "platform_features.h"
+#include "utlist.h"
+#include "logger.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "ocprovisioningmanager.h"
+#include "oxmjustworks.h"
+#include "oxmrandompin.h"
+#include "securevirtualresourcetypes.h"
+#include "security/srmutility.h"
+//#include "srmutility.h"
+#include "pmtypes.h"
+#include "pmutility.h"
+
+#include <tzplatform_config.h>
+
+#define MAX_FILE_PATH_LEN 1024
+
+#include "d2ds-log.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif //__cplusplus
+
+// declaration(s) for provisioning client using C-level provisioning API
+// user input definition for main loop on provisioning client
+#define _10_DISCOV_MOT_ENABLED_DEV_ 10
+#define _11_DISCOV_MULTIPLE_OWNED_DEV_ 11
+#define _20_PERFORM_MOT_ 20
+#define _30_GET_LED_RESOURCE_ 30
+#define _31_PUT_LED_RESOURCE_ 31
+#define _40_PROVISION_ACL_ 40
+#define _41_PROVISION_CRED_ 41
+#define _99_EXIT_PRVN_CLT_ 99
+
+#define ACL_RESRC_MAX_NUM 16
+#define ACL_RESRC_ARRAY_SIZE 3 //This value is used only for sample (not OCF spec)
+#define ACL_RESRC_MAX_LEN 128
+#define ACL_PEMISN_CNT 5
+#define DISCOVERY_TIMEOUT 5 // 5 sec
+#define CALLBACK_TIMEOUT 60 // 1 min
+#define TAG "subownerclient"
+
+static const char* SVR_DB_FILE_NAME = "oic_svr_db_subowner_client.dat";
+ // '_' for separaing from the same constant variable in |srmresourcestrings.c|
+static const char* PRVN_DB_FILE_NAME = "oic_pdm_subowner.db";
+static const OicSecPrm_t SUPPORTED_PRMS[1] =
+{
+ PRM_PRE_CONFIGURED,
+};
+
+// |g_ctx| means provision manager application context and
+// the following, includes |un/own_list|, could be variables, which |g_ctx| has,
+// for accessing all function(s) for these, they are declared on global domain
+static const char* g_ctx = "SubOwner Client Application Context";
+static char* g_svr_fname;
+static char* g_prvn_fname;
+static OCProvisionDev_t* g_own_list;
+static OCProvisionDev_t* g_unown_list;
+static OCProvisionDev_t* g_motdev_list;
+static OCProvisionDev_t* g_mowned_list;
+static int g_own_cnt;
+static int g_unown_cnt;
+static int g_motdev_cnt;
+static int g_mowned_cnt;
+static bool g_doneCB;
+
+// function declaration(s) for calling them before implementing
+static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int);
+static int printDevList(const OCProvisionDev_t*);
+static size_t printUuidList(const OCUuidList_t*);
+static int printResultList(const OCProvisionResult_t*, const int);
+static void printUuid(const OicUuid_t*);
+static FILE* fopen_prvnMng(const char*, const char*);
+static int waitCallbackRet(void);
+static int selectTwoDiffNum(int*, int*, const int, const char*);
+
+// callback function(s) for provisioning client using C-level provisioning API
+static void multipleOwnershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
+{
+ if(!hasError)
+ {
+ D2DS_LOGD("Multiple Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
+ }
+ else
+ {
+ D2DS_LOGD( "Multiple Ownership Transfer FAILED - ctx: %s", (char*) ctx);
+ printResultList((const OCProvisionResult_t*) arr, nOfRes);
+ }
+ g_doneCB = true;
+}
+
+// callback function(s) for provisioning client using C-level provisioning API
+static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
+{
+ if(!hasError)
+ {
+ D2DS_LOGD( "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
+ }
+ else
+ {
+ D2DS_LOGD( "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
+ printResultList((const OCProvisionResult_t*) arr, nOfRes);
+ }
+ g_doneCB = true;
+}
+
+static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
+{
+ if(!hasError)
+ {
+ D2DS_LOGD( "POST 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
+ }
+ else
+ {
+ D2DS_LOGD( "POST 'doxm' FAILED - ctx: %s", (char*) ctx);
+ printResultList((const OCProvisionResult_t*) arr, nOfRes);
+ }
+ g_doneCB = true;
+}
+
+static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
+{
+ if(!hasError)
+ {
+ D2DS_LOGD( "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
+ }
+ else
+ {
+ D2DS_LOGD( "Provision Credential FAILED - ctx: %s", (char*) ctx);
+ printResultList((const OCProvisionResult_t*) arr, nOfRes);
+ }
+ g_doneCB = true;
+}
+
+static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
+{
+ if(!hasError)
+ {
+ D2DS_LOGD( "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
+ }
+ else
+ {
+ D2DS_LOGD( "Provision ACL FAILED - ctx: %s", (char*) ctx);
+ printResultList((const OCProvisionResult_t*) arr, nOfRes);
+ }
+ g_doneCB = true;
+}
+
+// response handler for LED requests.
+static void LedCB(void *ctx, OCDoHandle UNUSED,
+ OCClientResponse *clientResponse)
+{
+ if(clientResponse)
+ {
+ if(OC_STACK_OK == clientResponse->result)
+ {
+ printf("Received OC_STACK_OK from server\n");
+ if(clientResponse->payload)
+ {
+ printf("Response ===================> %s\n", clientResponse->payload);
+ }
+ }
+ else if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
+ {
+ printf("Received OC_STACK_RESOURCE_CHANGED from server\n");
+ }
+ else
+ {
+ printf("Error in response : %d\n", clientResponse->result);
+ }
+ }
+ else
+ {
+ printf("Hit the response callback but can not find response data\n");
+ }
+
+ g_doneCB = true;
+}
+
+static void inputPinCB(char* pin, size_t len)
+{
+ if(!pin || OXM_RANDOM_PIN_MAX_SIZE>=len)
+ {
+ D2DS_LOGE( "inputPinCB invalid parameters");
+ return;
+ }
+
+ printf(" > INPUT PIN: ");
+ for(int ret=0; 1!=ret; )
+ {
+ ret = scanf("%32s", pin);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+}
+
+// function(s) for provisioning client using C-level provisioning API
+static int initProvisionClient(void)
+{
+ // initialize persistent storage for SVR DB
+ static OCPersistentStorage ps = {fopen_prvnMng, fread, fwrite, fclose, unlink};
+ if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&ps))
+ {
+ D2DS_LOGE( "OCRegisterPersistentStorageHandler error");
+ return -1;
+ }
+
+ // initialize OC stack and provisioning manager
+ if(OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
+ {
+ D2DS_LOGE( "OCStack init error");
+ return -1;
+ }
+
+ if (access(PRVN_DB_FILE_NAME, F_OK) != -1)
+ {
+ printf("************************************************************\n");
+ printf("************Provisioning DB file already exists.************\n");
+ printf("************************************************************\n");
+ }
+ else
+ {
+ printf("*************************************************************\n");
+ printf("************No provisioning DB file, creating new************\n");
+ printf("*************************************************************\n");
+ }
+
+ if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME))
+ {
+ D2DS_LOGE( "OC_PM init error");
+ return -1;
+ }
+
+ SetInputPinCB(inputPinCB);
+
+ return 0;
+}
+
+static int discoverMotSupportedDevices(void)
+{
+ // delete un/owned device lists before updating them
+ if(g_motdev_list)
+ {
+ OCDeleteDiscoveredDevices(g_motdev_list);
+ g_motdev_list = NULL;
+ }
+
+ // call |OCDiscoverMultipleOwnerEnabledDevices| API actually
+ printf(" Discovering Multiple Ownership Transfer enabled Devices on Network..\n");
+ if(OC_STACK_OK != OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT, &g_motdev_list))
+ {
+ D2DS_LOGE( "OCDiscoverMultipleOwnerEnalbedDevices API error");
+ return -1;
+ }
+
+ // display the discovered device lists
+ printf(" > Discovered Multiple Ownership Transfer Enabled Devices\n");
+ g_motdev_cnt = printDevList(g_motdev_list);
+
+ return 0;
+}
+
+static int discoverSubOwnerDevices()
+{
+ // delete un/owned device lists before updating them
+ if(g_mowned_list)
+ {
+ OCDeleteDiscoveredDevices(g_mowned_list);
+ g_mowned_list = NULL;
+ }
+
+ // call |OCDiscoverMultipleOwnedDevices| API actually
+ printf(" Discovering Multiple Owned Devices on Network..\n");
+ if(OC_STACK_OK != OCDiscoverMultipleOwnedDevices(DISCOVERY_TIMEOUT, &g_mowned_list))
+ {
+ D2DS_LOGE( "OCDiscoverMultipleOwnerEnabledDevices API error");
+ return -1;
+ }
+
+ // display the discovered device lists
+ printf(" > Discovered Multiple Owned Devices\n");
+ g_mowned_cnt = printDevList(g_mowned_list);
+
+ return 0;
+}
+
+static int multipleOwnershipTransfer(void)
+{
+ // check |unown_list| for registering devices
+ if(!g_motdev_list || 0 >=g_motdev_cnt)
+ {
+ printf(" > MultipleOwnershipTransfer Enabled Device List is Empty\n");
+ printf(" > Please Discover Devices first, with [10] Menu\n");
+ return 0; // normal case
+ }
+
+ // call |getDevInst| API actually
+ // calling this API with callback actually acts like blocking
+ // for error checking, the return value saved and printed
+ g_doneCB = false;
+
+#ifdef MULTIPLE_OWNER
+ OCProvisionDev_t* dev = NULL;
+ LL_FOREACH(g_motdev_list, dev)
+ {
+ if(OIC_PRECONFIG_PIN == dev->doxm->oxmSel)
+ {
+ //Pre-Configured PIN initialization
+ const char* testPreconfigPin = "12341234";
+ if(OC_STACK_OK != OCAddPreconfigPin(dev, testPreconfigPin, strlen(testPreconfigPin)))
+ {
+ printf("\n\n\n*** %60s ***\n", "WARNNING : Failed to save the pre-configured PIN");
+ printf("*** %60s ***\n\n\n", "WARNNING : You can't use the pre-configured PIN OxM for MOT");
+ return -1;
+ }
+ }
+ }
+#endif //MULTIPLE_OWNER
+
+ if(OC_STACK_OK != OCDoMultipleOwnershipTransfer(g_ctx, g_motdev_list, multipleOwnershipTransferCB))
+ {
+ D2DS_LOGE( "_20_PERFORM_MOT_: error");
+ return -1;
+ }
+
+ if(waitCallbackRet()) // input |g_doneCB| flag implicitly
+ {
+ D2DS_LOGE( "OCProvisionCredentials callback error");
+ return -1;
+ }
+
+ // display the registered result
+ printf(" > Registered Discovered Devices\n");
+
+ return 0;
+}
+
+static int sendGetLed()
+{
+ int selDevNum;
+ char query[256] = {0};
+ OCCallbackData cbData;
+ cbData.cb = &LedCB;
+ cbData.context = NULL;
+ cbData.cd = NULL;
+
+ printDevList(g_mowned_list);
+
+ // select device for provisioning access control list
+ for( ; ; )
+ {
+ printf(" > Enter Device Number, for sending GET LED request: ");
+ for(int ret=0; 1!=ret; )
+ {
+ ret = scanf("%d", &selDevNum);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+ if(0<selDevNum && g_mowned_cnt>=selDevNum)
+ {
+ break;
+ }
+ printf(" Entered Wrong Number. Please Enter Again\n");
+ }
+
+ OCProvisionDev_t* selDev = getDevInst(g_mowned_list, selDevNum);
+ if(NULL == selDev)
+ {
+ printf("Failed to getDevInst()\n");
+ return -1;
+ }
+
+ if(PMGenerateQuery(true, selDev->endpoint.addr, selDev->securePort, selDev->connType,
+ query, sizeof(query), "/a/led"))
+ {
+ g_doneCB = false;
+ printf("query=%s\n", query);
+ if(OC_STACK_OK != OCDoResource(NULL, OC_REST_GET, query, NULL, NULL, selDev->connType,
+ OC_HIGH_QOS, &cbData, NULL, 0))
+ {
+ printf("********************************\n");
+ printf("Failed to send GET request to %s\n", query);
+ printf("********************************\n");
+ g_doneCB = true;
+ return -1;
+ }
+
+ waitCallbackRet();
+ }
+ else
+ {
+ printf("Failed to generate GET request for /a/led\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int sendPutLed()
+{
+ int selDevNum;
+ char query[256] = {0};
+ OCCallbackData cbData;
+ cbData.cb = &LedCB;
+ cbData.context = NULL;
+ cbData.cd = NULL;
+
+ printDevList(g_mowned_list);
+ // select device for provisioning access control list
+ for( ; ; )
+ {
+ printf(" > Enter Device Number, for sending PUT LED request: ");
+ for(int ret=0; 1!=ret; )
+ {
+ ret = scanf("%d", &selDevNum);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+ if(0<selDevNum && g_mowned_cnt>=selDevNum)
+ {
+ break;
+ }
+ printf(" Entered Wrong Number. Please Enter Again\n");
+ }
+
+ OCProvisionDev_t* selDev = getDevInst(g_mowned_list, selDevNum);
+ if(NULL == selDev)
+ {
+ printf("Failed to getDevInst()\n");
+ return -1;
+ }
+
+ if(PMGenerateQuery(true, selDev->endpoint.addr, selDev->securePort, selDev->connType,
+ query, sizeof(query), "/a/led"))
+ {
+ g_doneCB = false;
+ printf("query=%s\n", query);
+ if(OC_STACK_OK != OCDoResource(NULL, OC_REST_PUT, query, NULL, NULL, selDev->connType,
+ OC_LOW_QOS, &cbData, NULL, 0))
+ {
+ printf("********************************\n");
+ printf("Failed to send PUT request to %s\n", query);
+ printf("********************************\n");
+ g_doneCB = true;
+ return -1;
+ }
+
+ waitCallbackRet();
+ }
+ else
+ {
+ printf("Failed to generate PUT request for /a/led\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static OicSecAcl_t* createAclForLEDAccess(const OicUuid_t* subject)
+{
+ if(NULL == subject)
+ {
+ D2DS_LOGE( "createAcl: Invalid paramters");
+ return NULL;
+ }
+ // allocate memory for |acl| struct
+ OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
+ if(!acl)
+ {
+ D2DS_LOGE( "createAcl: OICCalloc error return");
+ return NULL; // not need to 'goto' |ERROR| before allocating |acl|
+ }
+ OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
+ if(!ace)
+ {
+ D2DS_LOGE( "createAcl: OICCalloc error return");
+ return NULL; // not need to 'goto' |ERROR| before allocating |acl|
+ }
+ LL_APPEND(acl->aces, ace);
+ memcpy(ace->subjectuuid.id, subject->id, sizeof(subject->id));
+
+ // fill the href
+ char* rsrc_in = "/a/led"; // '1' for null termination
+ OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
+ if(!rsrc)
+ {
+ D2DS_LOGE( "createAcl: OICCalloc error return");
+ goto CRACL_ERROR;
+ }
+
+ size_t len = strlen(rsrc_in)+1; // '1' for null termination
+ rsrc->href = (char*) OICCalloc(len, sizeof(char));
+ if(!rsrc->href)
+ {
+ D2DS_LOGE( "createAcl: OICCalloc error return");
+ goto CRACL_ERROR;
+ }
+ OICStrcpy(rsrc->href, len, rsrc_in);
+
+ //fill the resource type (rt)
+ rsrc->typeLen = 1;
+ rsrc->types = (char**)OICCalloc(1, sizeof(char*));
+ if(!rsrc->types)
+ {
+ D2DS_LOGE( "createAcl: OICCalloc error return");
+ goto CRACL_ERROR;
+ }
+ rsrc->types[0] = OICStrdup("oic.r.core");
+ if(!rsrc->types[0])
+ {
+ D2DS_LOGE( "createAcl: OICStrdup error return");
+ goto CRACL_ERROR;
+ }
+
+ //fill the interface (if)
+ rsrc->interfaceLen = 1;
+ rsrc->interfaces = (char**)OICCalloc(1, sizeof(char*));
+ if(!rsrc->interfaces)
+ {
+ D2DS_LOGE( "createAcl: OICCalloc error return");
+ goto CRACL_ERROR;
+ }
+ rsrc->interfaces[0] = OICStrdup("oic.if.baseline");
+ if(!rsrc->interfaces[0])
+ {
+ D2DS_LOGE( "createAcl: OICStrdup error return");
+ goto CRACL_ERROR;
+ }
+
+ LL_APPEND(ace->resources, rsrc);
+
+ // full permission for /a/led
+ ace->permission = PERMISSION_FULL_CONTROL;
+
+ ace->eownerID = (OicUuid_t*)OICCalloc(1, sizeof(OicUuid_t));
+ if(NULL == ace->eownerID)
+ {
+ D2DS_LOGE( "createAcl: OICCalloc error return");
+ goto CRACL_ERROR;
+ }
+
+ memcpy(ace->eownerID->id, subject->id, sizeof(subject->id));
+
+ return acl;
+
+CRACL_ERROR:
+ OCDeleteACLList(acl); // after here |acl| points nothing
+ return NULL;
+}
+
+static int provisionAclForLed()
+{
+ OicSecAcl_t* acl = NULL;
+
+ // check |own_list| for provisioning access control list
+ if(!g_mowned_list || 1> g_mowned_cnt)
+ {
+ printf(" > MOT Device List is Empty\n");
+ printf(" > Please Perform MOT first, with [12|21] Menu\n");
+ return 0; // normal case
+ }
+
+ // display the MOT dev list
+ printf(" > MOT Devices\n");
+ g_mowned_cnt = printDevList(g_mowned_list);
+
+ // select device for provisioning access control list
+ int dev_num = 0;
+ for( ; ; )
+ {
+ printf(" > Enter Device Number, for Provisioning LED's ACL: ");
+ for(int ret=0; 1!=ret; )
+ {
+ ret = scanf("%d", &dev_num);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+ if(0<dev_num && g_mowned_list>=dev_num)
+ {
+ break;
+ }
+ printf(" Entered Wrong Number. Please Enter Again\n");
+ }
+
+ g_doneCB = false;
+ printf(" Provisioning Selected ACL..\n");
+ OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_mowned_list, dev_num);
+ if(!dev)
+ {
+ D2DS_LOGE( "provisionAcl: device instance empty");
+ goto PVACL_ERROR;
+ }
+
+ acl = createAclForLEDAccess(&dev->doxm->subOwners->uuid);
+ if(NULL == acl)
+ {
+ D2DS_LOGE( "provisionAcl: Failed to create ACL for LED");
+ return -1;
+ }
+
+ OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
+ if(OC_STACK_OK != rst)
+ {
+ D2DS_LOGD( "OCProvisionACL API error: %d", rst);
+ goto PVACL_ERROR;
+ }
+ if(waitCallbackRet()) // input |g_doneCB| flag implicitly
+ {
+ D2DS_LOGE( "OCProvisionCredentials callback error");
+ goto PVACL_ERROR;
+ }
+ // display the ACL-provisioned result
+ printf(" > Provisioned Selected ACL\n");
+
+ OCDeleteACLList(acl); // after here |acl| points nothing
+ return 0;
+
+PVACL_ERROR:
+ OCDeleteACLList(acl);
+ return -1;
+}
+
+static int provisionCred()
+{
+ // check |unown_list| for registering devices
+ if(!g_mowned_list|| 0 >=g_mowned_cnt)
+ {
+ printf(" > Multiple Owned Device List is Empty\n");
+ printf(" > Please Discover Devices first, with [13] Menu\n");
+ return 0; // normal case
+ }
+
+ // display the MOT dev list
+ printf(" > Multiple Owned Devices\n");
+ g_mowned_cnt = printDevList(g_mowned_list);
+
+ int dev_num = 0;
+ for( ; ; )
+ {
+ printf(" > Enter Multiple Owned Device Number to link : ");
+ for(int ret=0; 1!=ret; )
+ {
+ ret = scanf("%d", &dev_num);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+ if(0<dev_num && g_mowned_cnt>=dev_num)
+ {
+ break;
+ }
+ printf(" Entered Wrong Number. Please Enter Again\n");
+ }
+
+ OCProvisionDev_t* motDev = getDevInst(g_mowned_list, dev_num);
+ if(NULL == motDev)
+ {
+ D2DS_LOGE( "Failed to getDevInst()");
+ return -1;
+ }
+
+ // display the MOT dev list
+ printf(" > Owned Devices\n");
+ g_own_cnt = printDevList(g_own_list);
+
+ for( ; ; )
+ {
+ printf(" > Enter Owned Device Number to link : ");
+ for(int ret=0; 1!=ret; )
+ {
+ ret = scanf("%d", &dev_num);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+ if(0<dev_num && g_own_cnt>=dev_num)
+ {
+ break;
+ }
+ printf(" Entered Wrong Number. Please Enter Again\n");
+ }
+
+ OCProvisionDev_t* ownDev = getDevInst(g_own_list, dev_num);
+ if(NULL == ownDev)
+ {
+ D2DS_LOGE( "Failed to getDevInst()");
+ return -1;
+ }
+
+ // call |OCProvisionCredentials| API actually
+ // calling this API with callback actually acts like blocking
+ // for error checking, the return value saved and printed
+ g_doneCB = false;
+ printf(" Provisioning Selected Pairwise Devices..\n");
+ OCStackResult rst = OCProvisionCredentials((void*) g_ctx,
+ SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
+ ownDev, motDev, provisionCredCB);
+ if(OC_STACK_OK != rst)
+ {
+ D2DS_LOGD( "OCProvisionPairwiseDevices API error: %d", rst);
+ goto PVPWS_ERROR;
+ }
+ if(waitCallbackRet()) // input |g_doneCB| flag implicitly
+ {
+ D2DS_LOGE( "OCProvisionCredentials callback error");
+ goto PVPWS_ERROR;
+ }
+
+ // display the pairwise-provisioned result
+ printf(" > Provisioned Selected Pairwise Devices\n");
+
+ return 0;
+
+PVPWS_ERROR:
+ return -1;
+}
+
+static OCProvisionDev_t* getDevInst(const OCProvisionDev_t* dev_lst, const int dev_num)
+{
+ if(!dev_lst || 0>=dev_num)
+ {
+ printf(" Device List is Empty..\n");
+ return NULL;
+ }
+
+ OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
+ for(int i=0; lst; )
+ {
+ if(dev_num == ++i)
+ {
+ return lst;
+ }
+ lst = lst->next;
+ }
+
+ return NULL; // in here |lst| is always |NULL|
+}
+
+static int printDevList(const OCProvisionDev_t* dev_lst)
+{
+ if(!dev_lst)
+ {
+ printf(" Device List is Empty..\n\n");
+ return 0;
+ }
+
+ OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
+ int lst_cnt = 0;
+ for( ; lst; )
+ {
+ printf(" [%d] ", ++lst_cnt);
+ printUuid((const OicUuid_t*) &lst->doxm->deviceID);
+ printf("\n");
+ lst = lst->next;
+ }
+ printf("\n");
+
+ return lst_cnt;
+}
+
+static size_t printUuidList(const OCUuidList_t* uid_lst)
+{
+ if(!uid_lst)
+ {
+ printf(" Device List is Empty..\n\n");
+ return 0;
+ }
+
+ OCUuidList_t* lst = (OCUuidList_t*) uid_lst;
+ size_t lst_cnt = 0;
+ for( ; lst; )
+ {
+ printf(" [%zu] ", ++lst_cnt);
+ printUuid((const OicUuid_t*) &lst->dev);
+ printf("\n");
+ lst = lst->next;
+ }
+ printf("\n");
+
+ return lst_cnt;
+}
+
+static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
+{
+ if(!rslt_lst || 0>=rslt_cnt)
+ {
+ printf(" Device List is Empty..\n\n");
+ return 0;
+ }
+
+ int lst_cnt = 0;
+ for( ; rslt_cnt>lst_cnt; ++lst_cnt)
+ {
+ printf(" [%d] ", lst_cnt+1);
+ printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
+ printf(" - result: %d\n", rslt_lst[lst_cnt].res);
+ }
+ printf("\n");
+
+ return lst_cnt;
+}
+
+static void printUuid(const OicUuid_t* uid)
+{
+ for(int i=0; i<UUID_LENGTH; )
+ {
+ printf("%02X", (*uid).id[i++]);
+ if(i==4 || i==6 || i==8 || i==10) // canonical format for UUID has '8-4-4-4-12'
+ {
+ printf("-");
+ }
+ }
+}
+
+static FILE* fopen_prvnMng(const char* path, const char* mode)
+{
+ // input |g_svr_db_fname| internally by force, not using |path| parameter
+ // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
+ // with its own |SVR_DB_FILE_NAME|
+ char data_dir[MAX_FILE_PATH_LEN] = {0,};
+
+ snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
+ tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), SVR_DB_FILE_NAME);
+ (void)path; // unused |path| parameter
+
+ return fopen(data_dir, mode);
+}
+
+static int waitCallbackRet(void)
+{
+ for(int i=0; !g_doneCB && CALLBACK_TIMEOUT>i; ++i)
+ {
+ sleep(1);
+ if(OC_STACK_OK != OCProcess())
+ {
+ D2DS_LOGE( "OCStack process error");
+ return -1;
+ }
+ }
+
+ if(!g_doneCB)
+ {
+ OCPDMCleanupForTimeout();
+ }
+
+ return 0;
+}
+
+static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
+{
+ if(!a || !b || 2>max || !str)
+ {
+ return -1;
+ }
+
+ for( ; ; )
+ {
+ for(int i=0; 2>i; ++i)
+ {
+ int* num = 0==i?a:b;
+ for( ; ; )
+ {
+ printf(" > Enter Device[%d] Number, %s: ", i+1, str);
+ for(int ret=0; 1!=ret; )
+ {
+ ret = scanf("%d", num);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+ if(0<*num && max>=*num)
+ {
+ break;
+ }
+ printf(" Entered Wrong Number. Please Enter Again\n");
+ }
+ }
+ if(*a != *b)
+ {
+ printf("\n");
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+static void printMenu(void)
+{
+ printf("************************************************************\n");
+ printf("****** OIC Provisioning Client with using C-level API ******\n");
+ printf("************************************************************\n\n");
+
+ printf("** [A] DISCOVER DEVICES ON NETWORK\n");
+ printf("** 10. Discover Multiple Ownership Transfer Enabled Devices on Network\n");
+ printf("** 11. Discover Multiple Owned Devices on Network\n\n");
+
+ printf("** [B] PERFORM MULTIPLE OWNERSHIP TRANSFER\n");
+ printf("** 20. Perform the Multiple Ownership Transfer for ALL discovered dievices\n\n");
+
+ printf("** [C] Get/Put Request for APPLICATION RESOURCE\n");
+ printf("** 30. Get LED resource\n");
+ printf("** 31. Put LED resource\n\n");
+
+ printf("** [D] LINK DEVICES\n");
+ printf("** 40. Provision ACL for LED Resource\n");
+ printf("** 41. Provison Credential\n\n");
+
+ printf("** [F] EXIT PROVISIONING CLIENT\n");
+ printf("** 99. Exit Provisionong Client\n\n");
+
+ printf("************************************************************\n\n");
+}
+#if 0
+// main function for provisioning client using C-level provisioning API
+int main()
+{
+ // initialize provisioning client
+ if(initProvisionClient())
+ {
+ D2DS_LOGE( "ProvisionClient init error");
+ goto PMCLT_ERROR;
+ }
+
+ // main loop for provisioning manager
+ int mnNum = 0;
+ int selDevNum = 0;
+ for( ; ; )
+ {
+ printf("\n");
+ printMenu();
+ printf(">> Enter Menu Number: ");
+ for(int ret=0; 1!=ret; )
+ {
+ ret = scanf("%d", &mnNum);
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+ }
+ printf("\n");
+ switch(mnNum)
+ {
+ case _10_DISCOV_MOT_ENABLED_DEV_:
+ if(discoverMotSupportedDevices())
+ {
+ D2DS_LOGE( "_12_MOT_DISCOV_DEV_: error");
+ }
+ break;
+ case _11_DISCOV_MULTIPLE_OWNED_DEV_:
+ if(discoverSubOwnerDevices())
+ {
+ D2DS_LOGE( "_13_DISCOV_MULTIPLE_OWNED_DEV_: error");
+ }
+ break;
+ case _20_PERFORM_MOT_:
+ if(multipleOwnershipTransfer())
+ {
+ D2DS_LOGE( "_21_PERFORM_MOT_: error");
+ }
+ break;
+ case _30_GET_LED_RESOURCE_:
+ if(sendGetLed())
+ {
+ D2DS_LOGE( "_30_GET_LED_RESOURCE_: error");
+ }
+ break;
+ case _31_PUT_LED_RESOURCE_:
+ if(sendPutLed())
+ {
+ D2DS_LOGE( "_31_PUT_LED_RESOURCE_: error");
+ }
+ break;
+ case _40_PROVISION_ACL_:
+ if(provisionAclForLed())
+ {
+ D2DS_LOGE( "_40_PROVISION_ACL_: error");
+ }
+ break;
+ case _41_PROVISION_CRED_:
+ D2DS_LOGE( "NOT SUPPORTED YET.");
+ break;
+ /*
+ if(provisionCred())
+ {
+ D2D_LOGE( "_41_PROVISION_CRED_: error");
+ }
+ break;
+ */
+ case _99_EXIT_PRVN_CLT_:
+ goto PMCLT_ERROR;
+ default:
+ printf(">> Entered Wrong Number. Please Enter Again\n\n");
+ break;
+ }
+ }
+
+PMCLT_ERROR:
+ if(OC_STACK_OK != OCStop())
+ {
+ //D2D_LOGE( "OCStack stop error");
+ }
+ OCDeleteDiscoveredDevices(g_own_list); // after here |g_own_list| points nothing
+ OCDeleteDiscoveredDevices(g_unown_list); // after here |g_unown_list| points nothing
+ OCDeleteDiscoveredDevices(g_motdev_list); // after here |g_motdev_list| points nothing
+
+ if(g_svr_fname)
+ {
+ OICFree(g_svr_fname); // after here |g_svr_fname| points nothing
+ }
+ if(g_prvn_fname)
+ {
+ OICFree(g_prvn_fname); // after here |g_prvn_fname| points nothing
+ }
+ return 0; // always return normal case
+}
+#endif
+#ifdef __cplusplus
+}
+#endif //__cplusplus
+
--- /dev/null
+/*
+ * Network Configuration Module
+ *
+ * Copyright (c) 2017 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 __D2DS_UTIL_H__
+#define __D2DS_UTIL_H__
+
+#include <glib.h>
+#include <unistd.h>
+#include <gio/gio.h>
+
+#include "d2ds-log.h"
+
+#define NOTUSED(var) (var = var)
+
+#define d2ds_check_null_ret_error(name, value, error) do { \
+ if (G_UNLIKELY(NULL == (value))) { \
+ D2DS_LOGE("%s is NULL", name); \
+ return error; \
+ } \
+} while (FALSE)
+
+#define d2ds_check_null_ret(name, value) do { \
+ if (G_UNLIKELY(NULL == (value))) { \
+ D2DS_LOGE("%s is NULL", name); \
+ return; \
+ } \
+} while (FALSE)
+
+#endif /* __D2DS_UTIL_H__ */
--- /dev/null
+/*
+ * Network Configuration Module
+ *
+ * Copyright (c) 2017 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 "d2ds.h"
+#include "d2ds-log.h"
+#include "d2ds-util.h"
+#include "d2ds-service.h"
+
+/**< d2d-subowner service */
+d2ds_service *d2dssvc;
+
+int main(int argc, char *argv[])
+{
+ d2ds_service *service = NULL;
+ int ret_code = 0;
+ gboolean ret;
+
+ __D2DS_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);
+
+ D2DS_LOGI("service mainloop start");
+
+ /* Create d2d-subowner service */
+ d2dssvc = service = d2ds_service_new();
+
+ /* Initialize d2d-subowner service interface layer */
+ ret = d2ds_service_interface_init(service);
+ if (G_UNLIKELY(FALSE == ret)) {
+ D2DS_LOGE("Service interface init. failed!");
+ goto END;
+ }
+ /* Run d2d-subowner service */
+ ret = d2ds_service_run(service);
+ if (G_UNLIKELY(FALSE == ret)) {
+ D2DS_LOGE("Run service failed!");
+ ret_code = EXIT_FAILURE;
+ }
+
+END:
+ /* Free d2d-manager service */
+ d2ds_service_interface_deinit(service);
+ d2ds_service_free(service);
+ d2dssvc = NULL;
+
+ __D2DS_LOG_FUNC_EXIT__;
+ return 0;
+}
+
--- /dev/null
+/*\r
+ * Network Configuration Module\r
+ *\r
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+#ifndef __D2D_SUBOWNER_H__\r
+#define __D2D_SUBOWNER_H__\r
+\r
+#include <glib.h>\r
+#include <gio/gio.h>\r
+#include <tizen.h>\r
+\r
+/**< Internal error code with d2ds daemon. It should be matched with API side */\r
+typedef enum {\r
+ D2DS_ERROR_NONE = 0, /**< Successful */\r
+ D2DS_ERROR_IO_ERROR, /**< I/O error */\r
+ D2DS_ERROR_NO_DATA, /**< Data not exists */\r
+ D2DS_ERROR_OUT_OF_MEMORY, /**< out of memory */\r
+ D2DS_ERROR_OPERATION_FAILED, /**< operation failed */\r
+ D2DS_ERROR_INVALID_PARAMETER, /**< Invalid parameter */\r
+ D2DS_ERROR_ALREADY_REGISTERED, /**< Request already registered */\r
+ D2DS_ERROR_IN_PROGRESS /**< operation is in progress */\r
+} d2ds_error_e;\r
+\r
+/**< d2d-subowner service structure */\r
+typedef struct _d2ds_service {\r
+ GMainLoop *main_loop; /**< Service main-loop */\r
+ guint dbus_id; /**< D-Bus id */\r
+ guint activation_dbus_id; /**< D-Bus id for activation */\r
+\r
+ gpointer connection; /**< Connection handle for D-Bus call to other process */\r
+ GCancellable *ca; /**< Cancellable object for D-Bus call (Daemon->other) */\r
+ GList *dbus_sub_ids; /**< The list of subscribed signals */\r
+\r
+ gboolean d2ds_activated; /**< Whether d2d-manager enabled or not */\r
+} d2ds_service;\r
+\r
+#endif /* __D2D_SUBOWNER_H__ */\r
--- /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.d2ds">\r
+ <!-- Method definitions -->\r
+ <method name="disc_mot_enb_devs">\r
+ <arg type="i" name="result" direction="out"/>\r
+ </method>\r
+ <method name="disc_moted_devs">\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="mot_pairwise">\r
+ <arg type="s" name="subject" direction="in"/>\r
+ <arg type="s" name="uri" direction="in"/>\r
+ <arg type="i" name="permission" direction="in"/>\r
+ <arg type="s" name="target" 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="aa{sv}" name="list" direction="out"/>\r
+ </signal>\r
+ <signal name="disc_moted_devs_done">\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="mot_pairwise_done">\r
+ <arg type="i" name="result" direction="out"/>\r
+ </signal>\r
+ </interface>\r
+</node>\r
--- /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.d2ds.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.d2ds. \
+ --generate-c-code d2ds-generated-code \
+ --c-generate-object-manager \
+ --generate-docbook generated-docs \
+ d2ds.xml \
+ enabler.xml
+++ /dev/null
-MESSAGE("===================================================================")
-MESSAGE("Building...subowner client")
-MESSAGE("===================================================================")
-
-MESSAGE(" - Set source folder")
-FILE(GLOB SUBOWNER_SRCS *.c)
-
-SET(SUBOWNER "d2d-subowner")
-ADD_EXECUTABLE(${SUBOWNER} ${SUBOWNER_SRCS})
-TARGET_LINK_LIBRARIES(${SUBOWNER} ${daemon_pkgs_LIBRARIES} pthread)
-INSTALL(TARGETS ${SUBOWNER} DESTINATION bin)
+++ /dev/null
-/*\r
- * Network Configuration Module\r
- *\r
- * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- */\r
-#ifndef __D2D_SUBOWNER_LOG_H__\r
-#define __D2D_SUBOWNER_LOG_H__\r
-\r
-#ifdef D2DS_LOG_TAG\r
-#undef D2DS_LOG_TAG\r
-#endif\r
-\r
-#ifdef USE_DLOG\r
-#include <dlog.h>\r
-\r
-#undef D2DS_LOG_TAG\r
-#define D2DS_LOG_TAG "D2D_SUBOWNER"\r
-\r
-#define D2DS_LOGV(format, args...) LOGV(format, ##args)\r
-#define D2DS_LOGD(format, args...) LOGD(format, ##args)\r
-#define D2DS_LOGI(format, args...) LOGI(format, ##args)\r
-#define D2DS_LOGW(format, args...) LOGW(format, ##args)\r
-#define D2DS_LOGE(format, args...) LOGE(format, ##args)\r
-#define D2DS_LOGF(format, args...) LOGF(format, ##args)\r
-\r
-#define __D2DS_LOG_FUNC_ENTER__ LOGD("Enter")\r
-#define __D2DS_LOG_FUNC_EXIT__ LOGD("Quit")\r
-\r
-#define D2DS_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, D2DS_LOG_TAG, format, ##args)\r
-#define D2DS_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, D2DS_LOG_TAG, format, ##args)\r
-\r
-#else /* USE_DLOG */\r
-\r
-#define D2DS_LOGV(format, args...)\r
-#define D2DS_LOGD(format, args...)\r
-#define D2DS_LOGI(format, args...)\r
-#define D2DS_LOGW(format, args...)\r
-#define D2DS_LOGE(format, args...)\r
-#define D2DS_LOGF(format, args...)\r
-\r
-#define __D2DS_LOG_FUNC_ENTER__\r
-#define __D2DS_LOG_FUNC_EXIT__\r
-\r
-#define D2DS_SECLOGI(format, args...)\r
-#define D2DS_SECLOGD(format, args...)\r
-\r
-#endif /* USE_DLOG */\r
-\r
-#endif /* __D2D_SUBOWNER_LOG_H__ */\r
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2016 Samsung Electronics 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 "iotivity_config.h"
-
-#include <stdio.h>
-#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include "platform_features.h"
-#include "utlist.h"
-#include "logger.h"
-#include "oic_malloc.h"
-#include "oic_string.h"
-#include "ocprovisioningmanager.h"
-#include "oxmjustworks.h"
-#include "oxmrandompin.h"
-#include "securevirtualresourcetypes.h"
-#include "security/srmutility.h"
-//#include "srmutility.h"
-#include "pmtypes.h"
-#include "pmutility.h"
-
-#include <tzplatform_config.h>
-
-#define MAX_FILE_PATH_LEN 1024
-
-#include "d2d-subowner-log.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif //__cplusplus
-
-// declaration(s) for provisioning client using C-level provisioning API
-// user input definition for main loop on provisioning client
-#define _10_DISCOV_MOT_ENABLED_DEV_ 10
-#define _11_DISCOV_MULTIPLE_OWNED_DEV_ 11
-#define _20_PERFORM_MOT_ 20
-#define _30_GET_LED_RESOURCE_ 30
-#define _31_PUT_LED_RESOURCE_ 31
-#define _40_PROVISION_ACL_ 40
-#define _41_PROVISION_CRED_ 41
-#define _99_EXIT_PRVN_CLT_ 99
-
-#define ACL_RESRC_MAX_NUM 16
-#define ACL_RESRC_ARRAY_SIZE 3 //This value is used only for sample (not OCF spec)
-#define ACL_RESRC_MAX_LEN 128
-#define ACL_PEMISN_CNT 5
-#define DISCOVERY_TIMEOUT 5 // 5 sec
-#define CALLBACK_TIMEOUT 60 // 1 min
-#define TAG "subownerclient"
-
-static const char* SVR_DB_FILE_NAME = "oic_svr_db_subowner_client.dat";
- // '_' for separaing from the same constant variable in |srmresourcestrings.c|
-static const char* PRVN_DB_FILE_NAME = "oic_pdm_subowner.db";
-static const OicSecPrm_t SUPPORTED_PRMS[1] =
-{
- PRM_PRE_CONFIGURED,
-};
-
-// |g_ctx| means provision manager application context and
-// the following, includes |un/own_list|, could be variables, which |g_ctx| has,
-// for accessing all function(s) for these, they are declared on global domain
-static const char* g_ctx = "SubOwner Client Application Context";
-static char* g_svr_fname;
-static char* g_prvn_fname;
-static OCProvisionDev_t* g_own_list;
-static OCProvisionDev_t* g_unown_list;
-static OCProvisionDev_t* g_motdev_list;
-static OCProvisionDev_t* g_mowned_list;
-static int g_own_cnt;
-static int g_unown_cnt;
-static int g_motdev_cnt;
-static int g_mowned_cnt;
-static bool g_doneCB;
-
-// function declaration(s) for calling them before implementing
-static OCProvisionDev_t* getDevInst(const OCProvisionDev_t*, const int);
-static int printDevList(const OCProvisionDev_t*);
-static size_t printUuidList(const OCUuidList_t*);
-static int printResultList(const OCProvisionResult_t*, const int);
-static void printUuid(const OicUuid_t*);
-static FILE* fopen_prvnMng(const char*, const char*);
-static int waitCallbackRet(void);
-static int selectTwoDiffNum(int*, int*, const int, const char*);
-
-// callback function(s) for provisioning client using C-level provisioning API
-static void multipleOwnershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
- if(!hasError)
- {
- D2DS_LOGD("Multiple Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
- }
- else
- {
- D2DS_LOGD( "Multiple Ownership Transfer FAILED - ctx: %s", (char*) ctx);
- printResultList((const OCProvisionResult_t*) arr, nOfRes);
- }
- g_doneCB = true;
-}
-
-// callback function(s) for provisioning client using C-level provisioning API
-static void ownershipTransferCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
- if(!hasError)
- {
- D2DS_LOGD( "Ownership Transfer SUCCEEDED - ctx: %s", (char*) ctx);
- }
- else
- {
- D2DS_LOGD( "Ownership Transfer FAILED - ctx: %s", (char*) ctx);
- printResultList((const OCProvisionResult_t*) arr, nOfRes);
- }
- g_doneCB = true;
-}
-
-static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
- if(!hasError)
- {
- D2DS_LOGD( "POST 'doxm' SUCCEEDED - ctx: %s", (char*) ctx);
- }
- else
- {
- D2DS_LOGD( "POST 'doxm' FAILED - ctx: %s", (char*) ctx);
- printResultList((const OCProvisionResult_t*) arr, nOfRes);
- }
- g_doneCB = true;
-}
-
-static void provisionCredCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
- if(!hasError)
- {
- D2DS_LOGD( "Provision Credential SUCCEEDED - ctx: %s", (char*) ctx);
- }
- else
- {
- D2DS_LOGD( "Provision Credential FAILED - ctx: %s", (char*) ctx);
- printResultList((const OCProvisionResult_t*) arr, nOfRes);
- }
- g_doneCB = true;
-}
-
-static void provisionAclCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
-{
- if(!hasError)
- {
- D2DS_LOGD( "Provision ACL SUCCEEDED - ctx: %s", (char*) ctx);
- }
- else
- {
- D2DS_LOGD( "Provision ACL FAILED - ctx: %s", (char*) ctx);
- printResultList((const OCProvisionResult_t*) arr, nOfRes);
- }
- g_doneCB = true;
-}
-
-// response handler for LED requests.
-static void LedCB(void *ctx, OCDoHandle UNUSED,
- OCClientResponse *clientResponse)
-{
- if(clientResponse)
- {
- if(OC_STACK_OK == clientResponse->result)
- {
- printf("Received OC_STACK_OK from server\n");
- if(clientResponse->payload)
- {
- printf("Response ===================> %s\n", clientResponse->payload);
- }
- }
- else if(OC_STACK_RESOURCE_CHANGED == clientResponse->result)
- {
- printf("Received OC_STACK_RESOURCE_CHANGED from server\n");
- }
- else
- {
- printf("Error in response : %d\n", clientResponse->result);
- }
- }
- else
- {
- printf("Hit the response callback but can not find response data\n");
- }
-
- g_doneCB = true;
-}
-
-static void inputPinCB(char* pin, size_t len)
-{
- if(!pin || OXM_RANDOM_PIN_MAX_SIZE>=len)
- {
- D2DS_LOGE( "inputPinCB invalid parameters");
- return;
- }
-
- printf(" > INPUT PIN: ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%32s", pin);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
-}
-
-// function(s) for provisioning client using C-level provisioning API
-static int initProvisionClient(void)
-{
- // initialize persistent storage for SVR DB
- static OCPersistentStorage ps = {fopen_prvnMng, fread, fwrite, fclose, unlink};
- if(OC_STACK_OK != OCRegisterPersistentStorageHandler(&ps))
- {
- D2DS_LOGE( "OCRegisterPersistentStorageHandler error");
- return -1;
- }
-
- // initialize OC stack and provisioning manager
- if(OC_STACK_OK != OCInit(NULL, 0, OC_CLIENT_SERVER))
- {
- D2DS_LOGE( "OCStack init error");
- return -1;
- }
-
- if (access(PRVN_DB_FILE_NAME, F_OK) != -1)
- {
- printf("************************************************************\n");
- printf("************Provisioning DB file already exists.************\n");
- printf("************************************************************\n");
- }
- else
- {
- printf("*************************************************************\n");
- printf("************No provisioning DB file, creating new************\n");
- printf("*************************************************************\n");
- }
-
- if(OC_STACK_OK != OCInitPM(PRVN_DB_FILE_NAME))
- {
- D2DS_LOGE( "OC_PM init error");
- return -1;
- }
-
- SetInputPinCB(inputPinCB);
-
- return 0;
-}
-
-static int discoverMotSupportedDevices(void)
-{
- // delete un/owned device lists before updating them
- if(g_motdev_list)
- {
- OCDeleteDiscoveredDevices(g_motdev_list);
- g_motdev_list = NULL;
- }
-
- // call |OCDiscoverMultipleOwnerEnabledDevices| API actually
- printf(" Discovering Multiple Ownership Transfer enabled Devices on Network..\n");
- if(OC_STACK_OK != OCDiscoverMultipleOwnerEnabledDevices(DISCOVERY_TIMEOUT, &g_motdev_list))
- {
- D2DS_LOGE( "OCDiscoverMultipleOwnerEnalbedDevices API error");
- return -1;
- }
-
- // display the discovered device lists
- printf(" > Discovered Multiple Ownership Transfer Enabled Devices\n");
- g_motdev_cnt = printDevList(g_motdev_list);
-
- return 0;
-}
-
-static int discoverSubOwnerDevices()
-{
- // delete un/owned device lists before updating them
- if(g_mowned_list)
- {
- OCDeleteDiscoveredDevices(g_mowned_list);
- g_mowned_list = NULL;
- }
-
- // call |OCDiscoverMultipleOwnedDevices| API actually
- printf(" Discovering Multiple Owned Devices on Network..\n");
- if(OC_STACK_OK != OCDiscoverMultipleOwnedDevices(DISCOVERY_TIMEOUT, &g_mowned_list))
- {
- D2DS_LOGE( "OCDiscoverMultipleOwnerEnabledDevices API error");
- return -1;
- }
-
- // display the discovered device lists
- printf(" > Discovered Multiple Owned Devices\n");
- g_mowned_cnt = printDevList(g_mowned_list);
-
- return 0;
-}
-
-static int multipleOwnershipTransfer(void)
-{
- // check |unown_list| for registering devices
- if(!g_motdev_list || 0 >=g_motdev_cnt)
- {
- printf(" > MultipleOwnershipTransfer Enabled Device List is Empty\n");
- printf(" > Please Discover Devices first, with [10] Menu\n");
- return 0; // normal case
- }
-
- // call |getDevInst| API actually
- // calling this API with callback actually acts like blocking
- // for error checking, the return value saved and printed
- g_doneCB = false;
-
-#ifdef MULTIPLE_OWNER
- OCProvisionDev_t* dev = NULL;
- LL_FOREACH(g_motdev_list, dev)
- {
- if(OIC_PRECONFIG_PIN == dev->doxm->oxmSel)
- {
- //Pre-Configured PIN initialization
- const char* testPreconfigPin = "12341234";
- if(OC_STACK_OK != OCAddPreconfigPin(dev, testPreconfigPin, strlen(testPreconfigPin)))
- {
- printf("\n\n\n*** %60s ***\n", "WARNNING : Failed to save the pre-configured PIN");
- printf("*** %60s ***\n\n\n", "WARNNING : You can't use the pre-configured PIN OxM for MOT");
- return -1;
- }
- }
- }
-#endif //MULTIPLE_OWNER
-
- if(OC_STACK_OK != OCDoMultipleOwnershipTransfer(g_ctx, g_motdev_list, multipleOwnershipTransferCB))
- {
- D2DS_LOGE( "_20_PERFORM_MOT_: error");
- return -1;
- }
-
- if(waitCallbackRet()) // input |g_doneCB| flag implicitly
- {
- D2DS_LOGE( "OCProvisionCredentials callback error");
- return -1;
- }
-
- // display the registered result
- printf(" > Registered Discovered Devices\n");
-
- return 0;
-}
-
-static int sendGetLed()
-{
- int selDevNum;
- char query[256] = {0};
- OCCallbackData cbData;
- cbData.cb = &LedCB;
- cbData.context = NULL;
- cbData.cd = NULL;
-
- printDevList(g_mowned_list);
-
- // select device for provisioning access control list
- for( ; ; )
- {
- printf(" > Enter Device Number, for sending GET LED request: ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%d", &selDevNum);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<selDevNum && g_mowned_cnt>=selDevNum)
- {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
- }
-
- OCProvisionDev_t* selDev = getDevInst(g_mowned_list, selDevNum);
- if(NULL == selDev)
- {
- printf("Failed to getDevInst()\n");
- return -1;
- }
-
- if(PMGenerateQuery(true, selDev->endpoint.addr, selDev->securePort, selDev->connType,
- query, sizeof(query), "/a/led"))
- {
- g_doneCB = false;
- printf("query=%s\n", query);
- if(OC_STACK_OK != OCDoResource(NULL, OC_REST_GET, query, NULL, NULL, selDev->connType,
- OC_HIGH_QOS, &cbData, NULL, 0))
- {
- printf("********************************\n");
- printf("Failed to send GET request to %s\n", query);
- printf("********************************\n");
- g_doneCB = true;
- return -1;
- }
-
- waitCallbackRet();
- }
- else
- {
- printf("Failed to generate GET request for /a/led\n");
- return -1;
- }
-
- return 0;
-}
-
-static int sendPutLed()
-{
- int selDevNum;
- char query[256] = {0};
- OCCallbackData cbData;
- cbData.cb = &LedCB;
- cbData.context = NULL;
- cbData.cd = NULL;
-
- printDevList(g_mowned_list);
- // select device for provisioning access control list
- for( ; ; )
- {
- printf(" > Enter Device Number, for sending PUT LED request: ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%d", &selDevNum);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<selDevNum && g_mowned_cnt>=selDevNum)
- {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
- }
-
- OCProvisionDev_t* selDev = getDevInst(g_mowned_list, selDevNum);
- if(NULL == selDev)
- {
- printf("Failed to getDevInst()\n");
- return -1;
- }
-
- if(PMGenerateQuery(true, selDev->endpoint.addr, selDev->securePort, selDev->connType,
- query, sizeof(query), "/a/led"))
- {
- g_doneCB = false;
- printf("query=%s\n", query);
- if(OC_STACK_OK != OCDoResource(NULL, OC_REST_PUT, query, NULL, NULL, selDev->connType,
- OC_LOW_QOS, &cbData, NULL, 0))
- {
- printf("********************************\n");
- printf("Failed to send PUT request to %s\n", query);
- printf("********************************\n");
- g_doneCB = true;
- return -1;
- }
-
- waitCallbackRet();
- }
- else
- {
- printf("Failed to generate PUT request for /a/led\n");
- return -1;
- }
-
- return 0;
-}
-
-
-static OicSecAcl_t* createAclForLEDAccess(const OicUuid_t* subject)
-{
- if(NULL == subject)
- {
- D2DS_LOGE( "createAcl: Invalid paramters");
- return NULL;
- }
- // allocate memory for |acl| struct
- OicSecAcl_t* acl = (OicSecAcl_t*) OICCalloc(1, sizeof(OicSecAcl_t));
- if(!acl)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- return NULL; // not need to 'goto' |ERROR| before allocating |acl|
- }
- OicSecAce_t* ace = (OicSecAce_t*) OICCalloc(1, sizeof(OicSecAce_t));
- if(!ace)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- return NULL; // not need to 'goto' |ERROR| before allocating |acl|
- }
- LL_APPEND(acl->aces, ace);
- memcpy(ace->subjectuuid.id, subject->id, sizeof(subject->id));
-
- // fill the href
- char* rsrc_in = "/a/led"; // '1' for null termination
- OicSecRsrc_t* rsrc = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
- if(!rsrc)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- goto CRACL_ERROR;
- }
-
- size_t len = strlen(rsrc_in)+1; // '1' for null termination
- rsrc->href = (char*) OICCalloc(len, sizeof(char));
- if(!rsrc->href)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- goto CRACL_ERROR;
- }
- OICStrcpy(rsrc->href, len, rsrc_in);
-
- //fill the resource type (rt)
- rsrc->typeLen = 1;
- rsrc->types = (char**)OICCalloc(1, sizeof(char*));
- if(!rsrc->types)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- goto CRACL_ERROR;
- }
- rsrc->types[0] = OICStrdup("oic.r.core");
- if(!rsrc->types[0])
- {
- D2DS_LOGE( "createAcl: OICStrdup error return");
- goto CRACL_ERROR;
- }
-
- //fill the interface (if)
- rsrc->interfaceLen = 1;
- rsrc->interfaces = (char**)OICCalloc(1, sizeof(char*));
- if(!rsrc->interfaces)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- goto CRACL_ERROR;
- }
- rsrc->interfaces[0] = OICStrdup("oic.if.baseline");
- if(!rsrc->interfaces[0])
- {
- D2DS_LOGE( "createAcl: OICStrdup error return");
- goto CRACL_ERROR;
- }
-
- LL_APPEND(ace->resources, rsrc);
-
- // full permission for /a/led
- ace->permission = PERMISSION_FULL_CONTROL;
-
- ace->eownerID = (OicUuid_t*)OICCalloc(1, sizeof(OicUuid_t));
- if(NULL == ace->eownerID)
- {
- D2DS_LOGE( "createAcl: OICCalloc error return");
- goto CRACL_ERROR;
- }
-
- memcpy(ace->eownerID->id, subject->id, sizeof(subject->id));
-
- return acl;
-
-CRACL_ERROR:
- OCDeleteACLList(acl); // after here |acl| points nothing
- return NULL;
-}
-
-static int provisionAclForLed()
-{
- OicSecAcl_t* acl = NULL;
-
- // check |own_list| for provisioning access control list
- if(!g_mowned_list || 1> g_mowned_cnt)
- {
- printf(" > MOT Device List is Empty\n");
- printf(" > Please Perform MOT first, with [12|21] Menu\n");
- return 0; // normal case
- }
-
- // display the MOT dev list
- printf(" > MOT Devices\n");
- g_mowned_cnt = printDevList(g_mowned_list);
-
- // select device for provisioning access control list
- int dev_num = 0;
- for( ; ; )
- {
- printf(" > Enter Device Number, for Provisioning LED's ACL: ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%d", &dev_num);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<dev_num && g_mowned_list>=dev_num)
- {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
- }
-
- g_doneCB = false;
- printf(" Provisioning Selected ACL..\n");
- OCProvisionDev_t* dev = getDevInst((const OCProvisionDev_t*) g_mowned_list, dev_num);
- if(!dev)
- {
- D2DS_LOGE( "provisionAcl: device instance empty");
- goto PVACL_ERROR;
- }
-
- acl = createAclForLEDAccess(&dev->doxm->subOwners->uuid);
- if(NULL == acl)
- {
- D2DS_LOGE( "provisionAcl: Failed to create ACL for LED");
- return -1;
- }
-
- OCStackResult rst = OCProvisionACL((void*) g_ctx, dev, acl, provisionAclCB);
- if(OC_STACK_OK != rst)
- {
- D2DS_LOGD( "OCProvisionACL API error: %d", rst);
- goto PVACL_ERROR;
- }
- if(waitCallbackRet()) // input |g_doneCB| flag implicitly
- {
- D2DS_LOGE( "OCProvisionCredentials callback error");
- goto PVACL_ERROR;
- }
- // display the ACL-provisioned result
- printf(" > Provisioned Selected ACL\n");
-
- OCDeleteACLList(acl); // after here |acl| points nothing
- return 0;
-
-PVACL_ERROR:
- OCDeleteACLList(acl);
- return -1;
-}
-
-static int provisionCred()
-{
- // check |unown_list| for registering devices
- if(!g_mowned_list|| 0 >=g_mowned_cnt)
- {
- printf(" > Multiple Owned Device List is Empty\n");
- printf(" > Please Discover Devices first, with [13] Menu\n");
- return 0; // normal case
- }
-
- // display the MOT dev list
- printf(" > Multiple Owned Devices\n");
- g_mowned_cnt = printDevList(g_mowned_list);
-
- int dev_num = 0;
- for( ; ; )
- {
- printf(" > Enter Multiple Owned Device Number to link : ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%d", &dev_num);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<dev_num && g_mowned_cnt>=dev_num)
- {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
- }
-
- OCProvisionDev_t* motDev = getDevInst(g_mowned_list, dev_num);
- if(NULL == motDev)
- {
- D2DS_LOGE( "Failed to getDevInst()");
- return -1;
- }
-
- // display the MOT dev list
- printf(" > Owned Devices\n");
- g_own_cnt = printDevList(g_own_list);
-
- for( ; ; )
- {
- printf(" > Enter Owned Device Number to link : ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%d", &dev_num);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<dev_num && g_own_cnt>=dev_num)
- {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
- }
-
- OCProvisionDev_t* ownDev = getDevInst(g_own_list, dev_num);
- if(NULL == ownDev)
- {
- D2DS_LOGE( "Failed to getDevInst()");
- return -1;
- }
-
- // call |OCProvisionCredentials| API actually
- // calling this API with callback actually acts like blocking
- // for error checking, the return value saved and printed
- g_doneCB = false;
- printf(" Provisioning Selected Pairwise Devices..\n");
- OCStackResult rst = OCProvisionCredentials((void*) g_ctx,
- SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_128,
- ownDev, motDev, provisionCredCB);
- if(OC_STACK_OK != rst)
- {
- D2DS_LOGD( "OCProvisionPairwiseDevices API error: %d", rst);
- goto PVPWS_ERROR;
- }
- if(waitCallbackRet()) // input |g_doneCB| flag implicitly
- {
- D2DS_LOGE( "OCProvisionCredentials callback error");
- goto PVPWS_ERROR;
- }
-
- // display the pairwise-provisioned result
- printf(" > Provisioned Selected Pairwise Devices\n");
-
- return 0;
-
-PVPWS_ERROR:
- return -1;
-}
-
-static OCProvisionDev_t* getDevInst(const OCProvisionDev_t* dev_lst, const int dev_num)
-{
- if(!dev_lst || 0>=dev_num)
- {
- printf(" Device List is Empty..\n");
- return NULL;
- }
-
- OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
- for(int i=0; lst; )
- {
- if(dev_num == ++i)
- {
- return lst;
- }
- lst = lst->next;
- }
-
- return NULL; // in here |lst| is always |NULL|
-}
-
-static int printDevList(const OCProvisionDev_t* dev_lst)
-{
- if(!dev_lst)
- {
- printf(" Device List is Empty..\n\n");
- return 0;
- }
-
- OCProvisionDev_t* lst = (OCProvisionDev_t*) dev_lst;
- int lst_cnt = 0;
- for( ; lst; )
- {
- printf(" [%d] ", ++lst_cnt);
- printUuid((const OicUuid_t*) &lst->doxm->deviceID);
- printf("\n");
- lst = lst->next;
- }
- printf("\n");
-
- return lst_cnt;
-}
-
-static size_t printUuidList(const OCUuidList_t* uid_lst)
-{
- if(!uid_lst)
- {
- printf(" Device List is Empty..\n\n");
- return 0;
- }
-
- OCUuidList_t* lst = (OCUuidList_t*) uid_lst;
- size_t lst_cnt = 0;
- for( ; lst; )
- {
- printf(" [%zu] ", ++lst_cnt);
- printUuid((const OicUuid_t*) &lst->dev);
- printf("\n");
- lst = lst->next;
- }
- printf("\n");
-
- return lst_cnt;
-}
-
-static int printResultList(const OCProvisionResult_t* rslt_lst, const int rslt_cnt)
-{
- if(!rslt_lst || 0>=rslt_cnt)
- {
- printf(" Device List is Empty..\n\n");
- return 0;
- }
-
- int lst_cnt = 0;
- for( ; rslt_cnt>lst_cnt; ++lst_cnt)
- {
- printf(" [%d] ", lst_cnt+1);
- printUuid((const OicUuid_t*) &rslt_lst[lst_cnt].deviceId);
- printf(" - result: %d\n", rslt_lst[lst_cnt].res);
- }
- printf("\n");
-
- return lst_cnt;
-}
-
-static void printUuid(const OicUuid_t* uid)
-{
- for(int i=0; i<UUID_LENGTH; )
- {
- printf("%02X", (*uid).id[i++]);
- if(i==4 || i==6 || i==8 || i==10) // canonical format for UUID has '8-4-4-4-12'
- {
- printf("-");
- }
- }
-}
-
-static FILE* fopen_prvnMng(const char* path, const char* mode)
-{
- // input |g_svr_db_fname| internally by force, not using |path| parameter
- // because |OCPersistentStorage::open| is called |OCPersistentStorage| internally
- // with its own |SVR_DB_FILE_NAME|
- char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
- snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
- tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), SVR_DB_FILE_NAME);
- (void)path; // unused |path| parameter
-
- return fopen(data_dir, mode);
-}
-
-static int waitCallbackRet(void)
-{
- for(int i=0; !g_doneCB && CALLBACK_TIMEOUT>i; ++i)
- {
- sleep(1);
- if(OC_STACK_OK != OCProcess())
- {
- D2DS_LOGE( "OCStack process error");
- return -1;
- }
- }
-
- if(!g_doneCB)
- {
- OCPDMCleanupForTimeout();
- }
-
- return 0;
-}
-
-static int selectTwoDiffNum(int* a, int* b, const int max, const char* str)
-{
- if(!a || !b || 2>max || !str)
- {
- return -1;
- }
-
- for( ; ; )
- {
- for(int i=0; 2>i; ++i)
- {
- int* num = 0==i?a:b;
- for( ; ; )
- {
- printf(" > Enter Device[%d] Number, %s: ", i+1, str);
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%d", num);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- if(0<*num && max>=*num)
- {
- break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
- }
- }
- if(*a != *b)
- {
- printf("\n");
- return 0;
- }
- }
-
- return -1;
-}
-
-static void printMenu(void)
-{
- printf("************************************************************\n");
- printf("****** OIC Provisioning Client with using C-level API ******\n");
- printf("************************************************************\n\n");
-
- printf("** [A] DISCOVER DEVICES ON NETWORK\n");
- printf("** 10. Discover Multiple Ownership Transfer Enabled Devices on Network\n");
- printf("** 11. Discover Multiple Owned Devices on Network\n\n");
-
- printf("** [B] PERFORM MULTIPLE OWNERSHIP TRANSFER\n");
- printf("** 20. Perform the Multiple Ownership Transfer for ALL discovered dievices\n\n");
-
- printf("** [C] Get/Put Request for APPLICATION RESOURCE\n");
- printf("** 30. Get LED resource\n");
- printf("** 31. Put LED resource\n\n");
-
- printf("** [D] LINK DEVICES\n");
- printf("** 40. Provision ACL for LED Resource\n");
- printf("** 41. Provison Credential\n\n");
-
- printf("** [F] EXIT PROVISIONING CLIENT\n");
- printf("** 99. Exit Provisionong Client\n\n");
-
- printf("************************************************************\n\n");
-}
-
-// main function for provisioning client using C-level provisioning API
-int main()
-{
- // initialize provisioning client
- if(initProvisionClient())
- {
- D2DS_LOGE( "ProvisionClient init error");
- goto PMCLT_ERROR;
- }
-
- // main loop for provisioning manager
- int mnNum = 0;
- int selDevNum = 0;
- for( ; ; )
- {
- printf("\n");
- printMenu();
- printf(">> Enter Menu Number: ");
- for(int ret=0; 1!=ret; )
- {
- ret = scanf("%d", &mnNum);
- for( ; 0x20<=getchar(); ); // for removing overflow garbages
- // '0x20<=code' is character region
- }
- printf("\n");
- switch(mnNum)
- {
- case _10_DISCOV_MOT_ENABLED_DEV_:
- if(discoverMotSupportedDevices())
- {
- D2DS_LOGE( "_12_MOT_DISCOV_DEV_: error");
- }
- break;
- case _11_DISCOV_MULTIPLE_OWNED_DEV_:
- if(discoverSubOwnerDevices())
- {
- D2DS_LOGE( "_13_DISCOV_MULTIPLE_OWNED_DEV_: error");
- }
- break;
- case _20_PERFORM_MOT_:
- if(multipleOwnershipTransfer())
- {
- D2DS_LOGE( "_21_PERFORM_MOT_: error");
- }
- break;
- case _30_GET_LED_RESOURCE_:
- if(sendGetLed())
- {
- D2DS_LOGE( "_30_GET_LED_RESOURCE_: error");
- }
- break;
- case _31_PUT_LED_RESOURCE_:
- if(sendPutLed())
- {
- D2DS_LOGE( "_31_PUT_LED_RESOURCE_: error");
- }
- break;
- case _40_PROVISION_ACL_:
- if(provisionAclForLed())
- {
- D2DS_LOGE( "_40_PROVISION_ACL_: error");
- }
- break;
- case _41_PROVISION_CRED_:
- D2DS_LOGE( "NOT SUPPORTED YET.");
- break;
- /*
- if(provisionCred())
- {
- D2D_LOGE( "_41_PROVISION_CRED_: error");
- }
- break;
- */
- case _99_EXIT_PRVN_CLT_:
- goto PMCLT_ERROR;
- default:
- printf(">> Entered Wrong Number. Please Enter Again\n\n");
- break;
- }
- }
-
-PMCLT_ERROR:
- if(OC_STACK_OK != OCStop())
- {
- //D2D_LOGE( "OCStack stop error");
- }
- OCDeleteDiscoveredDevices(g_own_list); // after here |g_own_list| points nothing
- OCDeleteDiscoveredDevices(g_unown_list); // after here |g_unown_list| points nothing
- OCDeleteDiscoveredDevices(g_motdev_list); // after here |g_motdev_list| points nothing
-
- if(g_svr_fname)
- {
- OICFree(g_svr_fname); // after here |g_svr_fname| points nothing
- }
- if(g_prvn_fname)
- {
- OICFree(g_prvn_fname); // after here |g_prvn_fname| points nothing
- }
- return 0; // always return normal case
-}
-
-#ifdef __cplusplus
-}
-#endif //__cplusplus
-
+++ /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.d2dm">\r
- <!-- Method definitions -->\r
- <method name="find_peer">\r
- <arg type="i" name="result" direction="out"/>\r
- </method>\r
-\r
- <!-- Signal (D-Bus) definitions -->\r
- <signal name="proxy_enabled">\r
- <arg type="i" name="result" direction="out"/>\r
- </signal>\r
- <signal name="find_peer_done">\r
- </signal>\r
- </interface>\r
-</node>\r
+++ /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.d2ds.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.d2ds. \
- --generate-c-code d2ds-generated-code \
- --c-generate-object-manager \
- --generate-docbook generated-docs \
- d2ds.xml \
- enabler.xml