diff --git a/mesh/mesh-db.c b/mesh/mesh-db.c
index f1bf8d8..64e33cd 100644
--- a/mesh/mesh-db.c
+++ b/mesh/mesh-db.c
return true;
}
+static bool add_u64_value(json_object *jobject, const char *desc,
+ const uint8_t u64[8])
+{
+ json_object *jstring;
+ char hexstr[17];
+
+ hex2str((uint8_t *) u64, 8, hexstr, 17);
+ jstring = json_object_new_string(hexstr);
+ if (!jstring)
+ return false;
+
+ json_object_object_add(jobject, desc, jstring);
+ return true;
+}
+
static bool add_key_value(json_object *jobject, const char *desc,
const uint8_t key[16])
{
return true;
}
+bool mesh_db_read_token(json_object *jobj, uint8_t token[8])
+{
+ json_object *jvalue;
+ char *str;
+
+ if (!token)
+ return false;
+
+ if (!json_object_object_get_ex(jobj, "token", &jvalue))
+ return false;
+
+ str = (char *)json_object_get_string(jvalue);
+ if (!str2hex(str, strlen(str), token, 8))
+ return false;
+
+ return true;
+}
+
bool mesh_db_read_device_key(json_object *jobj, uint8_t key_buf[16])
{
json_object *jvalue;
return add_key_value(jnode, "deviceKey", key);
}
+bool mesh_db_write_token(json_object *jnode, uint8_t *token)
+{
+ return add_u64_value(jnode, "token", token);
+}
+
bool mesh_db_app_key_add(json_object *jobj, uint16_t net_idx, uint16_t app_idx,
const uint8_t key[16])
{
diff --git a/mesh/mesh-db.h b/mesh/mesh-db.h
index b9af120..06aba1f 100644
--- a/mesh/mesh-db.h
+++ b/mesh/mesh-db.h
bool mesh_db_add_node(json_object *jnode, struct mesh_db_node *node);
bool mesh_db_read_iv_index(json_object *jobj, uint32_t *idx, bool *update);
bool mesh_db_read_device_key(json_object *jobj, uint8_t key_buf[16]);
+bool mesh_db_read_token(json_object *jobj, uint8_t token[8]);
bool mesh_db_read_net_transmit(json_object *jobj, uint8_t *cnt,
uint16_t *interval);
bool mesh_db_write_net_transmit(json_object *jobj, uint8_t cnt,
bool mesh_db_read_app_keys(json_object *jobj, mesh_db_app_key_cb cb,
void *user_data);
bool mesh_db_write_device_key(json_object *jobj, uint8_t *key);
+bool mesh_db_write_token(json_object *jobj, uint8_t *token);
bool mesh_db_write_network_key(json_object *jobj, uint16_t idx, uint8_t *key,
uint8_t *new_key, int phase);
bool mesh_db_write_app_key(json_object *jobj, uint16_t net_idx,
diff --git a/mesh/mesh.c b/mesh/mesh.c
index a0a9a7c..e7eef04 100644
--- a/mesh/mesh.c
+++ b/mesh/mesh.c
struct l_dbus_message *msg;
const char *owner;
const char *path;
- const uint8_t *dev_key;
+ const uint8_t *token;
l_debug("Provisioning complete %s", prov_status_str(status));
return false;
}
- dev_key = node_get_device_key(join_pending->node);
+ token = node_get_token(join_pending->node);
msg = l_dbus_message_new_method_call(dbus, owner, path,
MESH_APPLICATION_INTERFACE,
"JoinComplete");
- l_dbus_message_set_arguments(msg, "t", l_get_u64(dev_key));
+ l_dbus_message_set_arguments(msg, "t", l_get_be64(token));
l_dbus_send(dbus_get_bus(), msg);
diff --git a/mesh/node.c b/mesh/node.c
index 79221b5..dae9a4b 100644
--- a/mesh/node.c
+++ b/mesh/node.c
} relay;
uint8_t dev_uuid[16];
uint8_t dev_key[16];
+ uint8_t token[8];
uint8_t num_ele;
uint8_t ttl;
uint8_t lpn;
{
const struct mesh_node *node = a;
const uint64_t *token = b;
- const uint64_t tmp = l_get_u64(node->dev_key);
+ const uint64_t tmp = l_get_be64(node->token);
return *token == tmp;
}
return node->dev_key;
}
+void node_set_token(struct mesh_node *node, uint8_t token[8])
+{
+ memcpy(node->token, token, 8);
+}
+
+const uint8_t *node_get_token(struct mesh_node *node)
+{
+ if (!node)
+ return NULL;
+ else
+ return node->token;
+}
+
uint8_t node_get_num_elements(struct mesh_node *node)
{
return node->num_ele;
struct attach_obj_request *req = user_data;
struct mesh_node *node = req->node;
const char *path;
- uint64_t token = l_get_u64(node->dev_key);
+ uint64_t token = l_get_be64(node->token);
uint8_t num_ele;
if (l_dbus_message_is_error(msg)) {
node->primary = info->unicast;
mesh_net_register_unicast(node->net, info->unicast, node->num_ele);
+ l_getrandom(node->token, sizeof(node->token));
+ if (!mesh_db_write_token(node->jconfig, node->token))
+ return false;
+
memcpy(node->dev_key, info->device_key, 16);
if (!mesh_db_write_device_key(node->jconfig, info->device_key))
return false;
diff --git a/mesh/node.h b/mesh/node.h
index 954dfca..ebc82ff 100644
--- a/mesh/node.h
+++ b/mesh/node.h
uint16_t net_idx, uint16_t idx);
uint16_t node_get_primary(struct mesh_node *node);
uint16_t node_get_primary_net_idx(struct mesh_node *node);
+void node_set_token(struct mesh_node *node, uint8_t token[8]);
+const uint8_t *node_get_token(struct mesh_node *node);
void node_set_device_key(struct mesh_node *node, uint8_t key[16]);
const uint8_t *node_get_device_key(struct mesh_node *node);
void node_set_num_elements(struct mesh_node *node, uint8_t num_ele);
diff --git a/mesh/storage.c b/mesh/storage.c
index f04e3ec..8a70b56 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
if (!mesh_db_read_net_keys(jnode, read_net_keys_cb, net))
return false;
+ if (!mesh_db_read_token(jnode, key_buf))
+ return false;
+
+ node_set_token(node, key_buf);
+
if (!mesh_db_read_device_key(jnode, key_buf))
return false;