diff --git a/mesh/keyring.c b/mesh/keyring.c
index 4c6d298..3ea8319 100644
--- a/mesh/keyring.c
+++ b/mesh/keyring.c
bool keyring_put_net_key(struct mesh_node *node, uint16_t net_idx,
struct keyring_net_key *key)
{
- char *node_path;
+ const char *node_path;
char key_file[PATH_MAX];
bool result = false;
int fd;
if (!node || !key)
return false;
- node_path = node_path_get(node);
+ node_path = node_get_storage_dir(node);
if (strlen(node_path) + strlen(net_key_dir) + 1 + 3 >= PATH_MAX)
return false;
bool keyring_put_app_key(struct mesh_node *node, uint16_t app_idx,
uint16_t net_idx, struct keyring_app_key *key)
{
- char *node_path;
+ const char *node_path;
char key_file[PATH_MAX];
bool result = false;
int fd;
if (!node || !key)
return false;
- node_path = node_path_get(node);
+ node_path = node_get_storage_dir(node);
if (strlen(node_path) + strlen(app_key_dir) + 1 + 3 >= PATH_MAX)
return false;
bool keyring_put_remote_dev_key(struct mesh_node *node, uint16_t unicast,
uint8_t count, uint8_t dev_key[16])
{
- char *node_path;
+ const char *node_path;
char key_file[PATH_MAX];
bool result = true;
int fd, i;
if (!node)
return false;
- node_path = node_path_get(node);
+ node_path = node_get_storage_dir(node);
if (strlen(node_path) + strlen(dev_key_dir) + 1 + 4 >= PATH_MAX)
return false;
bool keyring_get_net_key(struct mesh_node *node, uint16_t net_idx,
struct keyring_net_key *key)
{
- char *node_path;
+ const char *node_path;
char key_file[PATH_MAX];
bool result = false;
int fd;
if (!node || !key)
return false;
- node_path = node_path_get(node);
+ node_path = node_get_storage_dir(node);
snprintf(key_file, PATH_MAX, "%s%s/%3.3x", node_path, net_key_dir,
net_idx);
bool keyring_get_app_key(struct mesh_node *node, uint16_t app_idx,
struct keyring_app_key *key)
{
- char *node_path;
+ const char *node_path;
char key_file[PATH_MAX];
bool result = false;
int fd;
if (!node || !key)
return false;
- node_path = node_path_get(node);
+ node_path = node_get_storage_dir(node);
snprintf(key_file, PATH_MAX, "%s%s/%3.3x", node_path, app_key_dir,
app_idx);
bool keyring_get_remote_dev_key(struct mesh_node *node, uint16_t unicast,
uint8_t dev_key[16])
{
- char *node_path;
+ const char *node_path;
char key_file[PATH_MAX];
bool result = false;
int fd;
if (!node)
return false;
- node_path = node_path_get(node);
+ node_path = node_get_storage_dir(node);
snprintf(key_file, PATH_MAX, "%s%s/%4.4x", node_path, dev_key_dir,
unicast);
bool keyring_del_net_key(struct mesh_node *node, uint16_t net_idx)
{
- char *node_path;
+ const char *node_path;
char key_file[PATH_MAX];
if (!node)
return false;
- node_path = node_path_get(node);
+ node_path = node_get_storage_dir(node);
snprintf(key_file, PATH_MAX, "%s%s/%3.3x", node_path, net_key_dir,
net_idx);
l_debug("RM Net Key %s", key_file);
bool keyring_del_app_key(struct mesh_node *node, uint16_t app_idx)
{
- char *node_path;
+ const char *node_path;
char key_file[PATH_MAX];
if (!node)
return false;
- node_path = node_path_get(node);
+ node_path = node_get_storage_dir(node);
snprintf(key_file, PATH_MAX, "%s%s/%3.3x", node_path, app_key_dir,
app_idx);
l_debug("RM App Key %s", key_file);
bool keyring_del_remote_dev_key(struct mesh_node *node, uint16_t unicast,
uint8_t count)
{
- char *node_path;
+ const char *node_path;
char key_file[PATH_MAX];
int i;
if (!node)
return false;
- node_path = node_path_get(node);
+ node_path = node_get_storage_dir(node);
for (i = 0; i < count; i++) {
snprintf(key_file, PATH_MAX, "%s%s/%4.4x", node_path,
dev_key_dir, unicast + i);
diff --git a/mesh/node.c b/mesh/node.c
index 56489a8..79e165f 100644
--- a/mesh/node.c
+++ b/mesh/node.c
#endif
#define _GNU_SOURCE
+#include <dirent.h>
+#include <stdio.h>
#include <sys/time.h>
struct mesh_agent *agent;
char *path;
struct mesh_config *cfg;
- char *node_path;
+ char *storage_dir;
uint32_t disc_watch;
time_t upd_sec;
uint32_t seq_number;
mesh_net_free(node->net);
l_free(node->comp);
+ l_free(node->storage_dir);
l_free(node);
}
return true;
}
+static bool init_storage_dir(struct mesh_node *node)
+{
+ char uuid[33];
+ char dir_name[PATH_MAX];
+
+ if (node->storage_dir)
+ return true;
+
+ if (!hex2str(node->uuid, 16, uuid, sizeof(uuid)))
+ return false;
+
+ snprintf(dir_name, PATH_MAX, "%s/%s", mesh_get_storage_dir(), uuid);
+
+ if (strlen(dir_name) >= PATH_MAX)
+ return false;
+
+ create_dir(dir_name);
+
+ node->storage_dir = l_strdup(dir_name);
+
+ return true;
+}
+
static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
{
struct l_dbus_message_iter objects, interfaces;
net_key.old_key))
goto fail;
+ /* Initialize directory for storing keyring info */
+ init_storage_dir(node);
+
if (!keyring_put_remote_dev_key(node, DEFAULT_NEW_UNICAST,
num_ele, dev_key))
goto fail;
return node->cfg;
}
-void node_path_set(struct mesh_node *node, char *path)
-{
- l_free(node->node_path);
- node->node_path = l_strdup(path);
-}
-
-char *node_path_get(struct mesh_node *node)
+const char *node_get_storage_dir(struct mesh_node *node)
{
- return node->node_path;
+ return node->storage_dir;
}
const char *node_get_app_path(struct mesh_node *node)
diff --git a/mesh/node.h b/mesh/node.h
index e387b4d..56ca796 100644
--- a/mesh/node.h
+++ b/mesh/node.h
bool node_dbus_init(struct l_dbus *bus);
void node_cleanup_all(void);
struct mesh_config *node_config_get(struct mesh_node *node);
-void node_path_set(struct mesh_node *node, char *path);
-char *node_path_get(struct mesh_node *node);
struct mesh_agent *node_get_agent(struct mesh_node *node);
+const char *node_get_storage_dir(struct mesh_node *node);
bool node_load_from_storage(const char *storage_dir);