* [PATCH BlueZ 1/3] mesh: Add "create" command to test app
2019-05-14 20:15 [PATCH BlueZ 0/3] mesh: add Keyring to CreateNetwork Brian Gix
@ 2019-05-14 20:15 ` Brian Gix
2019-05-14 20:15 ` [PATCH BlueZ 2/3] mesh: Fix file open error checking and permissions Brian Gix
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Brian Gix @ 2019-05-14 20:15 UTC (permalink / raw)
To: linux-bluetooth; +Cc: inga.stotland, brian.gix, michal.lowas-rzechonek
Like "join" this command generates a UUID and calls CreateNetwork()
and displays the UUID and token.
---
test/test-mesh | 46 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/test/test-mesh b/test/test-mesh
index 7201669a8..f1d2b4e39 100755
--- a/test/test-mesh
+++ b/test/test-mesh
@@ -23,6 +23,7 @@
#
# The main menu:
# token
+# create
# join
# attach
# remove
@@ -37,6 +38,15 @@
# The token can be set from command line arguments as
# well.
#
+# create
+# Creates a new mesh network, with it's first local
+# node. The test generates device UUID to store the node
+# as.
+# In case of successful creation, the application
+# automatically attaches as a node to the daemon. A node
+# 'token' is returned to the application and is used
+# for the runtime of the test.
+#
# join
# Request provisioning of a device to become a node
# on a mesh network. The test generates device UUID
@@ -57,8 +67,8 @@
# For the call to be successful, the valid node token must
# be already set, either from command arguments or by
# executing "set token" operation or automatically after
-# successfully executing "join" operation in the same test
-# run.
+# successfully executing "join" or "create" operation in
+# the same test run.
#
# remove
# Permanently removes any node configuration from daemon
@@ -241,6 +251,22 @@ def join_cb():
def join_error_cb(reason):
print('Join procedure failed: ', reason)
+def create_cb(value):
+ global token
+ global have_token
+ global attach
+
+ print(set_yellow('Created mesh network with token ') +
+ set_green(format(value, '16x')))
+
+ token = value
+ have_token = True
+ if attached == False:
+ attach(token)
+
+def create_error_cb(reason):
+ print('Create procedure failed: ', reason)
+
def remove_node_cb():
global attached
global have_token
@@ -737,6 +763,8 @@ class MainMenu(Menu):
menu_items = {
'token': MenuItem(' - set node ID (token)',
self.__cmd_set_token),
+ 'create': MenuItem(' - create mesh network',
+ self.__cmd_create),
'join': MenuItem(' - join mesh network',
self.__cmd_join),
'attach': MenuItem(' - attach mesh node',
@@ -790,6 +818,20 @@ class MainMenu(Menu):
user_input = INPUT_MESSAGE_PAYLOAD;
print(set_cyan('Enter message payload (hex):'))
+ def __cmd_create(self):
+ if agent == None:
+ print(set_error('Provisioning agent not found'))
+ return
+
+ uuid = bytearray.fromhex("0a0102030405060708090A0B0C0D0E0F")
+ random.shuffle(uuid)
+ uuid_str = array_to_string(uuid)
+
+ print(set_yellow('Creating with UUID ') + set_green(uuid_str))
+ mesh_net.CreateNetwork(app.get_path(), uuid,
+ reply_handler=create_cb,
+ error_handler=create_error_cb)
+
def __cmd_join(self):
if agent == None:
print(set_error('Provisioning agent not found'))
--
2.14.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH BlueZ 2/3] mesh: Fix file open error checking and permissions
2019-05-14 20:15 [PATCH BlueZ 0/3] mesh: add Keyring to CreateNetwork Brian Gix
2019-05-14 20:15 ` [PATCH BlueZ 1/3] mesh: Add "create" command to test app Brian Gix
@ 2019-05-14 20:15 ` Brian Gix
2019-05-14 20:15 ` [PATCH BlueZ 3/3] mesh: Save generated Net and Dev keys in KeyRing Brian Gix
2019-05-15 16:46 ` [PATCH BlueZ 0/3] mesh: add Keyring to CreateNetwork Gix, Brian
3 siblings, 0 replies; 5+ messages in thread
From: Brian Gix @ 2019-05-14 20:15 UTC (permalink / raw)
To: linux-bluetooth; +Cc: inga.stotland, brian.gix, michal.lowas-rzechonek
---
mesh/keyring.c | 8 +++++---
mesh/storage.c | 2 +-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/mesh/keyring.c b/mesh/keyring.c
index 59aa1eaf4..4b1460aa8 100644
--- a/mesh/keyring.c
+++ b/mesh/keyring.c
@@ -67,7 +67,7 @@ bool keyring_put_net_key(struct mesh_node *node, uint16_t net_idx,
net_idx);
l_debug("Put Net Key %s", key_file);
- fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd >= 0) {
if (write(fd, key, sizeof(*key)) == sizeof(*key))
result = true;
@@ -112,7 +112,8 @@ bool keyring_put_app_key(struct mesh_node *node, uint16_t app_idx,
}
lseek(fd, 0, SEEK_SET);
} else
- fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR);
if (fd >= 0) {
if (write(fd, key, sizeof(*key)) == sizeof(*key))
@@ -148,7 +149,8 @@ bool keyring_put_remote_dev_key(struct mesh_node *node, uint16_t unicast,
dev_key_dir, unicast + i);
l_debug("Put Dev Key %s", key_file);
- fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = open(key_file, O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR);
if (fd >= 0) {
if (write(fd, dev_key, 16) != 16)
result = false;
diff --git a/mesh/storage.c b/mesh/storage.c
index f4e23bf49..8893b93cb 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
@@ -197,7 +197,7 @@ static bool parse_config(char *in_file, char *out_dir, const uint8_t uuid[16])
l_info("Loading configuration from %s", in_file);
fd = open(in_file, O_RDONLY);
- if (!fd)
+ if (fd < 0)
return false;
if (fstat(fd, &st) == -1) {
--
2.14.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH BlueZ 3/3] mesh: Save generated Net and Dev keys in KeyRing
2019-05-14 20:15 [PATCH BlueZ 0/3] mesh: add Keyring to CreateNetwork Brian Gix
2019-05-14 20:15 ` [PATCH BlueZ 1/3] mesh: Add "create" command to test app Brian Gix
2019-05-14 20:15 ` [PATCH BlueZ 2/3] mesh: Fix file open error checking and permissions Brian Gix
@ 2019-05-14 20:15 ` Brian Gix
2019-05-15 16:46 ` [PATCH BlueZ 0/3] mesh: add Keyring to CreateNetwork Gix, Brian
3 siblings, 0 replies; 5+ messages in thread
From: Brian Gix @ 2019-05-14 20:15 UTC (permalink / raw)
To: linux-bluetooth; +Cc: inga.stotland, brian.gix, michal.lowas-rzechonek
When creating a network from scratch, we need to save all
keys that are created into the KeyRing for use by Config
Client application.
---
mesh/node.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/mesh/node.c b/mesh/node.c
index 3618595b3..5318e2b69 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -35,6 +35,7 @@
#include "mesh/mesh-db.h"
#include "mesh/provision.h"
#include "mesh/storage.h"
+#include "mesh/keyring.h"
#include "mesh/appkey.h"
#include "mesh/model.h"
#include "mesh/cfgmod.h"
@@ -1549,8 +1550,8 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
} else {
/* Callback for create node request */
node_ready_func_t cb = req->cb;
+ struct keyring_net_key net_key;
uint8_t dev_key[16];
- uint8_t net_key[16];
node->num_ele = num_ele;
set_defaults(node);
@@ -1561,11 +1562,22 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
/* Generate device and primary network keys */
l_getrandom(dev_key, sizeof(dev_key));
- l_getrandom(net_key, sizeof(net_key));
+ l_getrandom(net_key.old_key, sizeof(net_key.old_key));
+ net_key.net_idx = DEFAULT_PRIMARY_NET_INDEX;
+ net_key.phase = 0;
if (!add_local_node(node, DEFAULT_NEW_UNICAST, false, false,
- DEFAULT_IV_INDEX, dev_key,
- DEFAULT_PRIMARY_NET_INDEX, net_key))
+ DEFAULT_IV_INDEX, dev_key,
+ DEFAULT_PRIMARY_NET_INDEX,
+ net_key.old_key))
+ goto fail;
+
+ if (!keyring_put_remote_dev_key(node, DEFAULT_NEW_UNICAST,
+ num_ele, dev_key))
+ goto fail;
+
+ if (!keyring_put_net_key(node, DEFAULT_PRIMARY_NET_INDEX,
+ &net_key))
goto fail;
cb(req->user_data, MESH_ERROR_NONE, node);
--
2.14.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH BlueZ 0/3] mesh: add Keyring to CreateNetwork
2019-05-14 20:15 [PATCH BlueZ 0/3] mesh: add Keyring to CreateNetwork Brian Gix
` (2 preceding siblings ...)
2019-05-14 20:15 ` [PATCH BlueZ 3/3] mesh: Save generated Net and Dev keys in KeyRing Brian Gix
@ 2019-05-15 16:46 ` Gix, Brian
3 siblings, 0 replies; 5+ messages in thread
From: Gix, Brian @ 2019-05-15 16:46 UTC (permalink / raw)
To: linux-bluetooth; +Cc: michal.lowas-rzechonek, Stotland, Inga
Patch-set applied, with minor edit to test-mesh comments
On Tue, 2019-05-14 at 13:15 -0700, Brian Gix wrote:
> Patch-set also fixes some file creation permissions and adds CreateNetwork
> test.
>
> Brian Gix (3):
> mesh: Add "create" command to test app
> mesh: Fix file open error checking and permissions
> mesh: Save generated Net and Dev keys in KeyRing
>
> mesh/keyring.c | 8 +++++---
> mesh/node.c | 20 ++++++++++++++++----
> mesh/storage.c | 2 +-
> test/test-mesh | 46 ++++++++++++++++++++++++++++++++++++++++++++--
> 4 files changed, 66 insertions(+), 10 deletions(-)
>
^ permalink raw reply [flat|nested] 5+ messages in thread