summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeonghoon Park <jh1979.park@samsung.com>2018-06-14 11:26:04 +0000
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>2018-06-14 11:26:04 +0000
commitd8d03465c325086b9d77737ac845e6415ae7175f (patch)
tree3b58fc96ec7f3d2c980cf7e6f3771543765af825
parent74d41da4597098b79439ccde54087345f55591f9 (diff)
parent7f27067012e5d37f553dece4d103dd15b0fe2970 (diff)
downloadtizen-things-daemon-d8d03465c325086b9d77737ac845e6415ae7175f.tar.gz
tizen-things-daemon-d8d03465c325086b9d77737ac845e6415ae7175f.tar.bz2
tizen-things-daemon-d8d03465c325086b9d77737ac845e6415ae7175f.zip
Merge "Add uuid module"
-rw-r--r--daemon/CMakeLists.txt2
-rw-r--r--daemon/include/ttd-deviceid.h22
-rw-r--r--daemon/include/ttd-wifimgr.h17
-rw-r--r--daemon/res/ttd.conf2
-rw-r--r--daemon/src/ttd-deviceid.c153
-rw-r--r--daemon/src/ttd-wifimgr.c59
-rw-r--r--packaging/tizen-things-daemon.spec2
7 files changed, 257 insertions, 0 deletions
diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt
index 5088899..fb381a3 100644
--- a/daemon/CMakeLists.txt
+++ b/daemon/CMakeLists.txt
@@ -15,6 +15,8 @@ pkg_check_modules(DAEMON_PKGS REQUIRED
capi-appfw-app-control
vconf
capi-network-softap
+ capi-network-wifi-manager
+ uuid
)
FOREACH (flag ${DAEMON_PKGS_CFLAGS})
diff --git a/daemon/include/ttd-deviceid.h b/daemon/include/ttd-deviceid.h
new file mode 100644
index 0000000..8af8aaa
--- /dev/null
+++ b/daemon/include/ttd-deviceid.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+typedef enum {
+ DEVICEID_TYPE_ONLY_MAC = 0,
+ DEVICEID_TYPE_MAC_TIME,
+} deviceid_type_e;
+
+char *ttd_deviceid_get_device_id(deviceid_type_e type);
diff --git a/daemon/include/ttd-wifimgr.h b/daemon/include/ttd-wifimgr.h
new file mode 100644
index 0000000..04176ae
--- /dev/null
+++ b/daemon/include/ttd-wifimgr.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+int ttd_wifimgr_get_mac_address(char **mac_addr);
diff --git a/daemon/res/ttd.conf b/daemon/res/ttd.conf
index 5b6bbc6..20f3146 100644
--- a/daemon/res/ttd.conf
+++ b/daemon/res/ttd.conf
@@ -6,3 +6,5 @@ api_report=/api/report/cmd
appid=
[setting]
network_disconnected_limit=600
+[identifier]
+deviceid=
diff --git a/daemon/src/ttd-deviceid.c b/daemon/src/ttd-deviceid.c
new file mode 100644
index 0000000..c9b4d6a
--- /dev/null
+++ b/daemon/src/ttd-deviceid.c
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 <uuid/uuid.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+
+#include "ttd-log.h"
+#include "ttd-deviceid.h"
+#include "ttd-config.h"
+#include "ttd-wifimgr.h"
+
+#define TTD_IDENTIFIER "identifier"
+#define TTD_IDENTIFIER_DEVICEID "deviceid"
+#define MAC_BUF_SIZE 20
+#define SHA256_LEN 32
+#define MAX_DEVICEID_SIZE 37
+#define UUID_HYPHEN_COUNT 4
+#define UUID_STRING_LENGTH (SHA256_LEN + UUID_HYPHEN_COUNT)
+
+static int __get_mac_addr(char **mac_buf)
+{
+ char *mac_addr = NULL;
+ char **temp_addr;
+
+ if (ttd_wifimgr_get_mac_address(&mac_addr) < 0) {
+ _E("Failed to get mac address");
+ return -1;
+ }
+
+ temp_addr = g_strsplit(mac_addr, ":", 6);
+ g_free(mac_addr);
+
+ *mac_buf = g_strjoinv(NULL, temp_addr);
+ g_strfreev(temp_addr);
+
+ return 0;
+}
+
+static char *__convert_str_to_uuid(char *uuid)
+{
+ char uuid_buf[UUID_STRING_LENGTH + 1] = { '\0', };
+
+ if (!uuid)
+ return NULL;
+
+ /* We discard character after SHA256_DIGEST_LENGTH according to the SmartThings */
+ int j = 0;
+ for (int i = 0; i < SHA256_LEN && j <= UUID_STRING_LENGTH; i++)
+ {
+ if (i == 8 || i == 12 || i == 16 || i == 20)
+ uuid_buf[j++] = '-';
+
+ uuid_buf[j++] = uuid[i];
+ }
+
+ g_free(uuid);
+
+ return g_strdup(uuid_buf);
+}
+
+static char *__generate_deviceid_with_mac(void)
+{
+ char *mac_addr = NULL;
+ char *hashed_addr = NULL;
+ char *uuid = NULL;
+
+ if (__get_mac_addr(&mac_addr) < 0) {
+ _E("Failed to get MAC Address to make device ID");
+ return NULL;
+ }
+
+ hashed_addr = g_compute_checksum_for_string(G_CHECKSUM_SHA256, (const gchar *)mac_addr, -1);
+
+ uuid = __convert_str_to_uuid(hashed_addr);
+
+ return uuid;
+}
+
+static char *__generate_deviceid_with_mac_time(void)
+{
+ uuid_t uuid;
+ char uuid_str[MAX_DEVICEID_SIZE];
+
+ uuid_generate_time_safe(uuid);
+
+ uuid_unparse(uuid, uuid_str);
+ _D("UUID for DeviceID[%s]", uuid_str);
+
+ uuid_clear(uuid);
+
+ return g_strdup(uuid_str);
+}
+
+static char *__generate_device_id(deviceid_type_e type)
+{
+ char *uuid = NULL;
+ switch (type)
+ {
+ case DEVICEID_TYPE_ONLY_MAC:
+ uuid = __generate_deviceid_with_mac();
+ break;
+ case DEVICEID_TYPE_MAC_TIME:
+ uuid = __generate_deviceid_with_mac_time();
+ break;
+ default:
+ _E("Something Strange");
+ return NULL;
+ }
+
+ if (!uuid)
+ return NULL;
+
+ if (ttd_config_write_string(TTD_IDENTIFIER, TTD_IDENTIFIER_DEVICEID, uuid) < 0) {
+ _E("Failed to store Device ID");
+ g_free(uuid);
+ return NULL;
+ }
+
+ return uuid;
+}
+
+char *ttd_deviceid_get_device_id(deviceid_type_e type)
+{
+ char *d_id = NULL;
+ /*
+ * Get deviceID from any where...as a string
+ */
+ if (ttd_config_read_string(TTD_IDENTIFIER, TTD_IDENTIFIER_DEVICEID, &d_id) < 0) {
+ _E("Failed to get Device ID");
+ return NULL;
+ }
+
+ if (!strlen(d_id)) {
+ g_free(d_id);
+ return __generate_device_id(type);
+ }
+ else
+ return d_id;
+}
diff --git a/daemon/src/ttd-wifimgr.c b/daemon/src/ttd-wifimgr.c
new file mode 100644
index 0000000..5e33f54
--- /dev/null
+++ b/daemon/src/ttd-wifimgr.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 <wifi-manager.h>
+
+#include "ttd-log.h"
+#include "ttd-wifimgr.h"
+
+wifi_manager_h wifi_h;
+
+int ttd_wifimgr_init(void)
+{
+ if (wifi_manager_initialize(&wifi_h) != WIFI_MANAGER_ERROR_NONE) {
+ _E("Failed to initialize wifi manager");
+ return -1;
+ }
+
+ return 0;
+}
+
+void ttd_wifimgr_fini(void)
+{
+ if (wifi_h) {
+ wifi_manager_deinitialize(wifi_h);
+ wifi_h = 0;
+ }
+}
+
+int ttd_wifimgr_get_mac_address(char **mac_addr)
+{
+ char *addr = NULL;
+
+ if (!wifi_h) {
+ if (ttd_wifimgr_init() < 0)
+ return -1;
+ }
+
+ if (wifi_manager_get_mac_address(wifi_h, &addr) != WIFI_MANAGER_ERROR_NONE) {
+ _E("Failed to get MAC Address from WIFI manager");
+ return -1;
+ }
+
+ *mac_addr = addr;
+
+ return 0;
+}
diff --git a/packaging/tizen-things-daemon.spec b/packaging/tizen-things-daemon.spec
index 9eb8068..b5efd74 100644
--- a/packaging/tizen-things-daemon.spec
+++ b/packaging/tizen-things-daemon.spec
@@ -21,7 +21,9 @@ BuildRequires: pkgconfig(openssl)
BuildRequires: pkgconfig(capi-appfw-app-control)
BuildRequires: pkgconfig(capi-appfw-app-common)
BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(uuid)
BuildRequires: pkgconfig(capi-network-softap)
+BuildRequires: pkgconfig(capi-network-wifi-manager)
%description
Tizen Things daemon