linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brian Gix <brian.gix@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: inga.stotland@intel.com, brian.gix@intel.com,
	michal.lowas-rzechonek@silvair.com
Subject: [PATCH BlueZ 3/3] mesh: Save generated Net and Dev keys in KeyRing
Date: Tue, 14 May 2019 13:15:25 -0700	[thread overview]
Message-ID: <20190514201525.16067-4-brian.gix@intel.com> (raw)
In-Reply-To: <20190514201525.16067-1-brian.gix@intel.com>

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


  parent reply	other threads:[~2019-05-14 20:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-05-15 16:46 ` [PATCH BlueZ 0/3] mesh: add Keyring to CreateNetwork Gix, Brian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190514201525.16067-4-brian.gix@intel.com \
    --to=brian.gix@intel.com \
    --cc=inga.stotland@intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=michal.lowas-rzechonek@silvair.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).