[PATCH BlueZ] mesh: Store node state variables prior to response

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Remotely set node state variables need to be saved to the file system
or other NVM prior to returning success status.
---
 mesh/node.c    |  4 +--
 mesh/storage.c | 99 ++++++++++++++++++++++++++++++++++++++++++++--------------
 mesh/storage.h |  9 +++---
 3 files changed, 83 insertions(+), 29 deletions(-)

diff --git a/mesh/node.c b/mesh/node.c
index 761a67af4..af8eb6bb8 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -497,7 +497,7 @@ bool node_default_ttl_set(struct mesh_node *node, uint8_t ttl)
 	if (!node)
 		return false;
 
-	res = storage_set_ttl(node->jconfig, ttl);
+	res = storage_set_ttl(node, ttl);
 
 	if (res) {
 		node->ttl = ttl;
@@ -621,7 +621,7 @@ bool node_relay_mode_set(struct mesh_node *node, bool enable, uint8_t cnt,
 	if (!node || node->relay.mode == MESH_MODE_UNSUPPORTED)
 		return false;
 
-	res = storage_set_relay(node->jconfig, enable, cnt, interval);
+	res = storage_set_relay(node, enable, cnt, interval);
 
 	if (res) {
 		node->relay.mode = enable ? MESH_MODE_ENABLED :
diff --git a/mesh/storage.c b/mesh/storage.c
index e84c2c933..f04e3ec89 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
@@ -224,27 +224,51 @@ done:
 	return result;
 }
 
-bool storage_set_ttl(json_object *jnode, uint8_t ttl)
+bool storage_set_ttl(struct mesh_node *node, uint8_t ttl)
 {
-	return mesh_db_write_int(jnode, "defaultTTL", ttl);
+	json_object *jnode = node_jconfig_get(node);
+
+	if (!mesh_db_write_int(jnode, "defaultTTL", ttl))
+		return false;
+
+	storage_save_config(node, true, NULL, NULL);
+	return true;
 }
 
-bool storage_set_relay(json_object *jnode, bool enable,
+bool storage_set_relay(struct mesh_node *node, bool enable,
 				uint8_t count, uint8_t interval)
 {
-	return mesh_db_write_relay_mode(jnode, enable, count, interval);
+	json_object *jnode = node_jconfig_get(node);
+
+	if (!mesh_db_write_relay_mode(jnode, enable, count, interval))
+		return false;
+
+	storage_save_config(node, true, NULL, NULL);
+	return true;
 }
 
-bool storage_set_transmit_params(json_object *jnode, uint8_t count,
+bool storage_set_transmit_params(struct mesh_node *node, uint8_t count,
 							uint8_t interval)
 {
-	return mesh_db_write_net_transmit(jnode, count, interval);
+	json_object *jnode = node_jconfig_get(node);
+
+	if (!mesh_db_write_net_transmit(jnode, count, interval))
+		return false;
+
+	storage_save_config(node, true, NULL, NULL);
+	return true;
 }
 
-bool storage_set_mode(json_object *jnode, uint8_t mode,
+bool storage_set_mode(struct mesh_node *node, uint8_t mode,
 						const char *mode_name)
 {
-	return mesh_db_write_mode(jnode, mode_name, mode);
+	json_object *jnode = node_jconfig_get(node);
+
+	if (!mesh_db_write_mode(jnode, mode_name, mode))
+		return false;
+
+	storage_save_config(node, true, NULL, NULL);
+	return true;
 }
 
 bool storage_model_bind(struct mesh_node *node, uint16_t addr, uint32_t mod_id,
@@ -252,7 +276,7 @@ bool storage_model_bind(struct mesh_node *node, uint16_t addr, uint32_t mod_id,
 {
 	json_object *jnode;
 	int ele_idx;
-	bool is_vendor = (mod_id > 0xffff);
+	bool stored, is_vendor = (mod_id > 0xffff);
 
 	ele_idx = node_get_element_idx(node, addr);
 	if (ele_idx < 0)
@@ -261,11 +285,16 @@ bool storage_model_bind(struct mesh_node *node, uint16_t addr, uint32_t mod_id,
 	jnode = node_jconfig_get(node);
 
 	if (unbind)
-		return mesh_db_model_binding_del(jnode, ele_idx, is_vendor,
+		stored = mesh_db_model_binding_del(jnode, ele_idx, is_vendor,
 							mod_id, app_idx);
 	else
-		return mesh_db_model_binding_add(jnode, ele_idx, is_vendor,
+		stored = mesh_db_model_binding_add(jnode, ele_idx, is_vendor,
 							mod_id, app_idx);
+
+	if (stored)
+		storage_save_config(node, true, NULL, NULL);
+
+	return stored;
 }
 
 bool storage_app_key_add(struct mesh_net *net, uint16_t net_idx,
@@ -273,15 +302,21 @@ bool storage_app_key_add(struct mesh_net *net, uint16_t net_idx,
 {
 	json_object *jnode;
 	struct mesh_node *node = mesh_net_node_get(net);
+	bool stored;
 
 	jnode = node_jconfig_get(node);
 	if (!jnode)
 		return false;
 
 	if (update)
-		return mesh_db_app_key_update(jnode, app_idx, key);
+		stored = mesh_db_app_key_update(jnode, app_idx, key);
+	else
+		stored = mesh_db_app_key_add(jnode, net_idx, app_idx, key);
+
+	if (stored)
+		storage_save_config(node, true, NULL, NULL);
 
-	return mesh_db_app_key_add(jnode, net_idx, app_idx, key);
+	return stored;
 }
 
 bool storage_app_key_del(struct mesh_net *net, uint16_t net_idx,
@@ -294,8 +329,11 @@ bool storage_app_key_del(struct mesh_net *net, uint16_t net_idx,
 	if (!jnode)
 		return false;
 
-	return mesh_db_app_key_del(jnode, net_idx, app_idx);
+	if (!mesh_db_app_key_del(jnode, net_idx, app_idx))
+		return false;
 
+	storage_save_config(node, true, NULL, NULL);
+	return true;
 }
 
 bool storage_net_key_add(struct mesh_net *net, uint16_t net_idx,
@@ -303,11 +341,17 @@ bool storage_net_key_add(struct mesh_net *net, uint16_t net_idx,
 {
 	struct mesh_node *node = mesh_net_node_get(net);
 	json_object *jnode = node_jconfig_get(node);
+	bool stored;
 
 	if (!update)
-		return mesh_db_net_key_add(jnode, net_idx, key);
+		stored = mesh_db_net_key_add(jnode, net_idx, key);
 	else
-		return mesh_db_net_key_update(jnode, net_idx, key);
+		stored = mesh_db_net_key_update(jnode, net_idx, key);
+
+	if (stored)
+		storage_save_config(node, true, NULL, NULL);
+
+	return stored;
 }
 
 bool storage_net_key_del(struct mesh_net *net, uint16_t net_idx)
@@ -315,7 +359,11 @@ bool storage_net_key_del(struct mesh_net *net, uint16_t net_idx)
 	struct mesh_node *node = mesh_net_node_get(net);
 	json_object *jnode = node_jconfig_get(node);
 
-	return mesh_db_net_key_del(jnode, net_idx);
+	if (!mesh_db_net_key_del(jnode, net_idx))
+		return false;
+
+	storage_save_config(node, true, NULL, NULL);
+	return true;
 }
 
 bool storage_set_iv_index(struct mesh_net *net, uint32_t iv_index,
@@ -324,7 +372,11 @@ bool storage_set_iv_index(struct mesh_net *net, uint32_t iv_index,
 	struct mesh_node *node = mesh_net_node_get(net);
 	json_object *jnode = node_jconfig_get(node);
 
-	return mesh_db_write_iv_index(jnode, iv_index, update);
+	if (!mesh_db_write_iv_index(jnode, iv_index, update))
+		return false;
+
+	storage_save_config(node, true, NULL, NULL);
+	return true;
 }
 
 bool storage_set_key_refresh_phase(struct mesh_net *net, uint16_t net_idx,
@@ -333,21 +385,22 @@ bool storage_set_key_refresh_phase(struct mesh_net *net, uint16_t net_idx,
 	struct mesh_node *node = mesh_net_node_get(net);
 	json_object *jnode = node_jconfig_get(node);
 
-	return mesh_db_net_key_set_phase(jnode, net_idx, phase);
+	if (!mesh_db_net_key_set_phase(jnode, net_idx, phase))
+		return false;
+
+	storage_save_config(node, true, NULL, NULL);
+	return true;
 }
 
 bool storage_write_sequence_number(struct mesh_net *net, uint32_t seq)
 {
 	struct mesh_node *node = mesh_net_node_get(net);
 	json_object *jnode = node_jconfig_get(node);
-	bool result;
 
-	result = mesh_db_write_int(jnode, "sequenceNumber", seq);
-	if (!result)
+	if (!mesh_db_write_int(jnode, "sequenceNumber", seq))
 		return false;
 
 	storage_save_config(node, false, NULL, NULL);
-
 	return true;
 }
 
diff --git a/mesh/storage.h b/mesh/storage.h
index 8b14c8e8e..d71d11b8e 100644
--- a/mesh/storage.h
+++ b/mesh/storage.h
@@ -28,12 +28,13 @@ void storage_save_config(struct mesh_node *node, bool no_wait,
 bool storage_model_bind(struct mesh_node *node, uint16_t addr, uint32_t id,
 						uint16_t app_idx, bool unbind);
 
-bool storage_set_ttl(json_object *jnode, uint8_t ttl);
-bool storage_set_relay(json_object *jnode, bool enable, uint8_t count,
+bool storage_set_ttl(struct mesh_node *node, uint8_t ttl);
+bool storage_set_relay(struct mesh_node *node, bool enable, uint8_t count,
 							uint8_t interval);
-bool storage_set_transmit_params(json_object *jnode, uint8_t count,
+bool storage_set_transmit_params(struct mesh_node *node, uint8_t count,
 							uint8_t interval);
-bool storage_set_mode(json_object *jnode, uint8_t mode, const char *mode_name);
+bool storage_set_mode(struct mesh_node *node, uint8_t mode,
+						const char *mode_name);
 bool storage_net_key_add(struct mesh_net *net, uint16_t net_idx,
 					const uint8_t key[16], bool update);
 bool storage_net_key_del(struct mesh_net *net, uint16_t net_idx);
-- 
2.14.5




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux