Skip to contentSkip to conversation

mesh: clean up

PATCH In review Inga Stotland 3 participants 6 messages Dec 6, 2019 – Dec 11, 2019 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

cover mesh: clean up

This set of patches claens up some cruft in node.c and some in net.c The dtaaflow is a bit more deterministic now.

Inga Stotland (3):
mesh: Delete unused function
mesh: Clean up node.c
mesh: Initialize net modes based on node configuration

 mesh/mesh-defs.h |   2 +
 mesh/model.c     |  17 +-
 mesh/model.h     |   4 +-
 mesh/net.c       |  15 +-
 mesh/node.c      | 503 ++++++++++++++++++-----------------------------
 mesh/node.h      |   1 -
 6 files changed, 200 insertions(+), 342 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/3 mesh: Delete unused function

This removes node_parse_composition() implementation as it is not used anywhere in the rest of the code base.

---
 mesh/node.c | 131 ----------------------------------------------------
 mesh/node.h |   1 -
 2 files changed, 132 deletions(-)
mesh/node.c +0 -131
index 7b4ee0505..b8c30c30a 100644
@@ -994,137 +994,6 @@ element_done:
 	return n;
 }
 
-
-#define MIN_COMPOSITION_LEN 16
-
-bool node_parse_composition(struct mesh_node *node, uint8_t *data,
-								uint16_t len)
-{
-	struct node_composition *comp;
-	uint16_t features;
-	uint8_t num_ele;
-	bool mode;
-
-	if (!len)
-		return false;
-
-	/* Skip page -- We only support Page Zero */
-	data++;
-	len--;
-
-	if (len < MIN_COMPOSITION_LEN)
-		return false;
-
-	comp = l_new(struct node_composition, 1);
-	if (!comp)
-		return false;
-
-	node->elements = l_queue_new();
-	if (!node->elements) {
-		l_free(comp);
-		return false;
-	}
-
-	node->comp = l_new(struct node_composition, 1);
-	comp->cid = l_get_le16(&data[0]);
-	comp->pid = l_get_le16(&data[2]);
-	comp->vid = l_get_le16(&data[4]);
-	comp->crpl = l_get_le16(&data[6]);
-	features = l_get_le16(&data[8]);
-	data += 10;
-	len -= 10;
-
-	mode = !!(features & FEATURE_PROXY);
-	node->proxy = mode ? MESH_MODE_DISABLED : MESH_MODE_UNSUPPORTED;
-
-	mode = !!(features & FEATURE_LPN);
-	node->lpn = mode ? MESH_MODE_DISABLED : MESH_MODE_UNSUPPORTED;
-
-	mode = !!(features & FEATURE_FRIEND);
-	node->friend = mode ? MESH_MODE_DISABLED : MESH_MODE_UNSUPPORTED;
-
-	mode = !!(features & FEATURE_RELAY);
-	node->relay.mode = mode ? MESH_MODE_DISABLED : MESH_MODE_UNSUPPORTED;
-
-	num_ele = 0;
-
-	do {
-		uint8_t m, v;
-		uint16_t mod_id;
-		uint16_t vendor_id;
-		struct node_element *ele;
-		struct mesh_model *mod;
-
-		ele = l_new(struct node_element, 1);
-		if (!ele)
-			return false;
-
-		ele->idx = num_ele;
-		ele->location = l_get_le16(data);
-		len -= 2;
-		data += 2;
-
-		m = *data++;
-		v = *data++;
-		len -= 2;
-
-		/* Parse SIG models */
-		while (len >= 2 && m--) {
-			mod_id = l_get_le16(data);
-			mod = mesh_model_new(ele->idx, mod_id);
-			if (!mod || !element_add_model(ele, mod)) {
-				mesh_model_free(mod);
-				element_free(ele);
-				goto fail;
-			}
-
-			data += 2;
-			len -= 2;
-		}
-
-		if (v && len < 4) {
-			element_free(ele);
-			goto fail;
-		}
-
-		/* Parse vendor models */
-		while (len >= 4 && v--) {
-			mod_id = l_get_le16(data + 2);
-			vendor_id = l_get_le16(data);
-			mod_id |= (vendor_id << 16);
-			mod = mesh_model_vendor_new(ele->idx, vendor_id,
-									mod_id);
-			if (!mod || !element_add_model(ele, mod)) {
-				mesh_model_free(mod);
-				element_free(ele);
-				goto fail;
-			}
-
-			data += 4;
-			len -= 4;
-		}
-
-		num_ele++;
-		l_queue_push_tail(node->elements, ele);
-
-	} while (len >= 6);
-
-	/* Check the consistency for the remote node */
-	if (node->num_ele > num_ele)
-		goto fail;
-
-	node->comp = comp;
-	node->num_ele = num_ele;
-
-	return true;
-
-fail:
-	l_queue_destroy(node->elements, element_free);
-	l_free(comp);
-
-	return false;
-}
-
 static void attach_io(void *a, void *b)
 {
 	struct mesh_node *node = a;
mesh/node.h +0 -1
index be57d5e67..7448756ae 100644
@@ -50,7 +50,6 @@ 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);
 uint8_t node_get_num_elements(struct mesh_node *node);
-bool node_parse_composition(struct mesh_node *node, uint8_t *buf, uint16_t len);
 bool node_add_binding(struct mesh_node *node, uint8_t ele_idx,
 			uint32_t model_id, uint16_t app_idx);
 bool node_del_binding(struct mesh_node *node, uint8_t ele_idx,
Signature · 1 line
2.21.0
#2 lore raw

PATCH 2/3 mesh: Clean up node.c

In reply to Inga Stotland

This change makes the node initialization a bit easier to follow. Replace if-else with switch when processing request type, descriptive function names, more predictable code flow.

---
 mesh/model.c |  17 +--
 mesh/model.h |   4 +-
 mesh/node.c  | 331 ++++++++++++++++++++++++++-------------------------
 3 files changed, 171 insertions(+), 181 deletions(-)
mesh/model.c +2 -15
index 4091881ec..acdd94f7b 100644
@@ -1249,7 +1249,7 @@ void mesh_model_free(void *data)
 	l_free(mod);
 }
 
-static struct mesh_model *model_new(uint8_t ele_idx, uint32_t id)
+struct mesh_model *mesh_model_new(uint8_t ele_idx, uint32_t id)
 {
 	struct mesh_model *mod = l_new(struct mesh_model, 1);
 
@@ -1259,19 +1259,6 @@ static struct mesh_model *model_new(uint8_t ele_idx, uint32_t id)
 	return mod;
 }
 
-struct mesh_model *mesh_model_new(uint8_t ele_idx, uint16_t id)
-{
-	return model_new(ele_idx, id | VENDOR_ID_MASK);
-}
-
-struct mesh_model *mesh_model_vendor_new(uint8_t ele_idx, uint16_t vendor_id,
-								uint16_t mod_id)
-{
-	uint32_t id = mod_id | (vendor_id << 16);
-
-	return model_new(ele_idx, id);
-}
-
 /* Internal models only */
 static void restore_model_state(struct mesh_model *mod)
 {
@@ -1600,7 +1587,7 @@ struct mesh_model *mesh_model_setup(struct mesh_node *node, uint8_t ele_idx,
 		return NULL;
 	}
 
-	mod = model_new(ele_idx, db_mod->vendor ? db_mod->id :
+	mod = mesh_model_new(ele_idx, db_mod->vendor ? db_mod->id :
 						db_mod->id | VENDOR_ID_MASK);
 
 	/* Implicitly bind config server model to device key */
mesh/model.h +1 -3
index f30ca2e38..9c7ce9334 100644
@@ -62,9 +62,7 @@ struct mesh_model_ops {
 	mesh_model_sub_cb sub;
 };
 
-struct mesh_model *mesh_model_new(uint8_t ele_idx, uint16_t mod_id);
-struct mesh_model *mesh_model_vendor_new(uint8_t ele_idx, uint16_t vendor_id,
-							uint16_t mod_id);
+struct mesh_model *mesh_model_new(uint8_t ele_idx, uint32_t mod_id);
 void mesh_model_free(void *data);
 uint32_t mesh_model_get_model_id(const struct mesh_model *model);
 bool mesh_model_register(struct mesh_node *node, uint8_t ele_idx,
mesh/node.c +168 -163

591 lines not on this page · raw message

Signature · 1 line
2.21.0
#3 lore raw

Re: [PATCH BlueZ 2/3] mesh: Clean up node.c

Hi Inga,

Quoted 20 lines · Inga Stotland
mesh/node.c +0 -5
@@ -876,8 +902,6 @@ uint16_t node_generate_comp(struct mesh_node *node, uint8_t *buf, uint16_t sz)
 {
 	uint16_t n, features;
 	uint16_t num_ele = 0;
-	uint8_t *cfgmod_idx = NULL;
-
 	const struct l_queue_entry *ele_entry;
 
 	if (!node || !node->comp || sz < MIN_COMP_SIZE)
@@ -940,9 +964,6 @@ uint16_t node_generate_comp(struct mesh_node *node, uint8_t *buf, uint16_t sz)
 			mod_id = mesh_model_get_model_id(
 					(const struct mesh_model *) mod);
 
-			if (mod_id == CONFIG_SRV_MODEL)
-				cfgmod_idx = &ele->idx;
-
 			if ((mod_id & VENDOR_ID_MASK) == VENDOR_ID_MASK) {
 				if (n + 2 > sz)
 					goto element_done;

mesh/node.c element_done: · line 1013

Quoted 8 lines
mesh/node.c +0 -3
@@ -988,9 +1009,6 @@ element_done:
 	if (!num_ele)
 		return 0;
 
-	if (!cfgmod_idx || *cfgmod_idx != PRIMARY_ELE_IDX)
-		return 0;
-
 	return n;
 }

Note that this cause the daemon to no longer reject applications that declare presence of Config Server Model on non-primary element.

Signature · 3 lines
Michał Lowas-Rzechonek <[email protected]>
Silvair http://silvair.com
Jasnogórska 44, 31-358 Krakow, POLAND
#4 lore raw

PATCH 3/3 mesh: Initialize net modes based on node configuration

In reply to Inga Stotland

This correctly initializes net settings related to node features based on node configuration: either defaults in the case of a newly node created/provisioned/imported node or the configured values read from stored existing node.

---
 mesh/mesh-defs.h |  2 ++
 mesh/net.c       | 15 ++-------------
 mesh/node.c      | 45 +++++++++++++++++++++++++++------------------
 3 files changed, 31 insertions(+), 31 deletions(-)
mesh/mesh-defs.h +2 -0
index 8f28fc89b..9353d7351 100644
@@ -109,6 +109,8 @@
 #define APP_IDX_DEV_REMOTE	0x6fff
 #define APP_IDX_DEV_LOCAL	0x7fff
 
+#define DEFAULT_SEQUENCE_NUMBER 0x000000
+
 #define IS_UNASSIGNED(x)	((x) == UNASSIGNED_ADDRESS)
 #define IS_UNICAST(x)		(((x) > UNASSIGNED_ADDRESS) && \
 					((x) < VIRTUAL_ADDRESS_LOW))
mesh/net.c +2 -13
index 17dbf2ec2..f662d8a91 100644
@@ -679,20 +679,9 @@ struct mesh_net *mesh_net_new(struct mesh_node *node)
 	net = l_new(struct mesh_net, 1);
 
 	net->node = node;
-	net->pkt_id = 0;
-	net->bea_id = 0;
-
-	net->beacon_enable = true;
-	net->proxy_enable = false;
-	net->relay.enable = false;
-
-	net->seq_num = 0x000000;
-	net->src_addr = 0x0000;
-	net->default_ttl = 0x7f;
-
-	net->provisioner = false;
+	net->seq_num = DEFAULT_SEQUENCE_NUMBER;
+	net->default_ttl = TTL_MASK;
 
-	net->test_mode = false;
 	memset(&net->prov_caps, 0, sizeof(net->prov_caps));
 	net->prov_caps.algorithms = 1;
 
mesh/node.c +27 -18

80 lines not on this page · raw message

Signature · 1 line
2.21.0
#5 lore raw
In reply to Inga Stotland

Patchset Applied

Quoted 16 lines · Inga Stotland

This set of patches claens up some cruft in node.c and some in net.c The dtaaflow is a bit more deterministic now.

Inga Stotland (3):
mesh: Delete unused function
mesh: Clean up node.c
mesh: Initialize net modes based on node configuration

 mesh/mesh-defs.h |   2 +
 mesh/model.c     |  17 +-
 mesh/model.h     |   4 +-
 mesh/net.c       |  15 +-
 mesh/node.c      | 503 ++++++++++++++++++-----------------------------
 mesh/node.h      |   1 -
 6 files changed, 200 insertions(+), 342 deletions(-)