All of lore.kernel.org
 help / color / mirror / Atom feed
From: Inga Stotland <inga.stotland@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: brian.gix@intel.com, johan.hedberg@gmail.com,
	luiz.dentz@gmail.com, Inga Stotland <inga.stotland@intel.com>
Subject: [PATCH BlueZ 2/3] mesh: Save model subscription updates to config file
Date: Fri,  8 Mar 2019 14:58:19 -0800	[thread overview]
Message-ID: <20190308225820.20561-3-inga.stotland@intel.com> (raw)
In-Reply-To: <20190308225820.20561-1-inga.stotland@intel.com>

This adds functionality in Config Server model to save changes in
node configuration file when model subscriptions are added, deleted or
overwritten.
---
 mesh/cfgmod-server.c | 60 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 2 deletions(-)

diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c
index 9dc82eef6..df2614529 100644
--- a/mesh/cfgmod-server.c
+++ b/mesh/cfgmod-server.c
@@ -37,6 +37,7 @@
 #include "mesh/appkey.h"
 #include "mesh/model.h"
 #include "mesh/storage.h"
+#include "mesh/mesh-db.h"
 
 #include "mesh/cfgmod.h"
 
@@ -195,7 +196,7 @@ static bool config_pub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 	if (IS_UNASSIGNED(ota) && !b_virt)
 		ttl = period = idx = 0;
 
-	if (status >= 0 && !unreliable)
+	if (!unreliable)
 		send_pub_status(node, src, dst, status, ele_addr, ota,
 				mod_id, idx, cred_flag, ttl, period,
 				retransmit);
@@ -285,6 +286,38 @@ static bool config_sub_get(struct mesh_node *node, uint16_t src, uint16_t dst,
 	return true;
 }
 
+static bool save_config_sub(struct mesh_node *node, uint16_t ele_addr,
+					uint32_t mod_id, bool vendor,
+					const uint8_t *addr, bool virt,
+					uint16_t grp, uint32_t opcode)
+{
+	struct mesh_db_sub db_sub = {
+				.virt = virt,
+				.src.addr = grp
+				};
+
+	if (virt)
+		memcpy(db_sub.src.virt_addr, addr, 16);
+
+	if (opcode == OP_CONFIG_MODEL_SUB_VIRT_OVERWRITE ||
+					opcode == OP_CONFIG_MODEL_SUB_OVERWRITE)
+		mesh_db_model_sub_del_all(node_jconfig_get(node),
+				ele_addr, vendor ? mod_id : mod_id & 0x0000ffff,
+									vendor);
+
+	if (opcode != OP_CONFIG_MODEL_SUB_VIRT_DELETE &&
+			opcode != OP_CONFIG_MODEL_SUB_DELETE)
+		return mesh_db_model_sub_add(node_jconfig_get(node),
+					ele_addr,
+					vendor ? mod_id : mod_id & 0x0000ffff,
+					vendor, &db_sub);
+	else
+		return mesh_db_model_sub_del(node_jconfig_get(node),
+					ele_addr,
+					vendor ? mod_id : mod_id & 0x0000ffff,
+					vendor, &db_sub);
+}
+
 static void config_sub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 					const uint8_t *pkt, uint16_t size,
 					bool virt, uint32_t opcode)
@@ -294,6 +327,7 @@ static void config_sub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 	uint32_t mod_id, func;
 	const uint8_t *addr = NULL;
 	int status = 0;
+	bool vendor = false;
 
 	switch (size) {
 	default:
@@ -314,6 +348,7 @@ static void config_sub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 		} else {
 			mod_id = l_get_le16(pkt + 2) << 16;
 			mod_id |= l_get_le16(pkt + 4);
+			vendor = true;
 		}
 		break;
 	case 8:
@@ -321,6 +356,7 @@ static void config_sub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 			return;
 		mod_id = l_get_le16(pkt + 4) << 16;
 		mod_id |= l_get_le16(pkt + 6);
+		vendor = true;
 		break;
 	case 20:
 		if (!virt)
@@ -351,6 +387,11 @@ static void config_sub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 
 	case OP_CONFIG_MODEL_SUB_DELETE_ALL:
 		status = mesh_model_sub_del_all(node, ele_addr, mod_id);
+
+		if (status == MESH_STATUS_SUCCESS)
+			mesh_db_model_sub_del_all(node_jconfig_get(node),
+				ele_addr, vendor ? mod_id : mod_id & 0x0000ffff,
+									vendor);
 		break;
 
 	case OP_CONFIG_MODEL_SUB_VIRT_OVERWRITE:
@@ -359,6 +400,10 @@ static void config_sub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 	case OP_CONFIG_MODEL_SUB_OVERWRITE:
 		status = mesh_model_sub_ovr(node, ele_addr, mod_id,
 							addr, virt, &grp);
+
+		if (status == MESH_STATUS_SUCCESS)
+			save_config_sub(node, ele_addr, mod_id, vendor, addr,
+							virt, grp, opcode);
 		break;
 	case OP_CONFIG_MODEL_SUB_VIRT_ADD:
 		grp = UNASSIGNED_ADDRESS;
@@ -366,6 +411,12 @@ static void config_sub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 	case OP_CONFIG_MODEL_SUB_ADD:
 		status = mesh_model_sub_add(node, ele_addr, mod_id,
 							addr, virt, &grp);
+
+		if (status == MESH_STATUS_SUCCESS &&
+				!save_config_sub(node, ele_addr, mod_id, vendor,
+						addr, virt, grp, opcode))
+			status = MESH_STATUS_STORAGE_FAIL;
+
 		break;
 	case OP_CONFIG_MODEL_SUB_VIRT_DELETE:
 		grp = UNASSIGNED_ADDRESS;
@@ -373,10 +424,15 @@ static void config_sub_set(struct mesh_node *node, uint16_t src, uint16_t dst,
 	case OP_CONFIG_MODEL_SUB_DELETE:
 		status = mesh_model_sub_del(node, ele_addr, mod_id,
 							addr, virt, &grp);
+
+		if (status == MESH_STATUS_SUCCESS)
+			save_config_sub(node, ele_addr, mod_id, vendor, addr,
+							virt, grp, opcode);
+
 		break;
 	}
 
-	if (!unreliable && status >= 0)
+	if (!unreliable)
 		send_sub_status(node, src, dst, status, ele_addr, grp, mod_id);
 
 }
-- 
2.17.2


  parent reply	other threads:[~2019-03-08 22:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08 22:58 [PATCH BlueZ 0/3] Save and restore mesh models pub/sub settings Inga Stotland
2019-03-08 22:58 ` [PATCH BlueZ 1/3] mesh: Add json config functions to save pub/sub updates Inga Stotland
2019-03-08 22:58 ` Inga Stotland [this message]
2019-03-08 22:58 ` [PATCH BlueZ 3/3] mesh: Store model publication settings in config file Inga Stotland
2019-03-11 22:20 ` [PATCH BlueZ 0/3] Save and restore mesh models pub/sub settings 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=20190308225820.20561-3-inga.stotland@intel.com \
    --to=inga.stotland@intel.com \
    --cc=brian.gix@intel.com \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.