2020-08-12 19:04:38

by Stotland, Inga

[permalink] [raw]
Subject: [PATCH BlueZ 1/2] mesh: Fix model ID prior to calling mesh config functions

Model IDs for SIG defined models need to be stripped off SIG_VENDOR
value used for internal housekeeping prior to calling functions
that save new model state in node configuration.

Also, remove duplicate statements for model lookup in node config.
---
mesh/mesh-config-json.c | 7 +------
mesh/model.c | 12 ++++++++----
2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index a40f92c01..086d618b1 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -169,11 +169,6 @@ static json_object *get_element_model(json_object *jnode, int ele_idx,
size_t len;
char buf[9];

- if (!vendor)
- snprintf(buf, 5, "%4.4x", (uint16_t)mod_id);
- else
- snprintf(buf, 9, "%8.8x", mod_id);
-
if (!json_object_object_get_ex(jnode, "elements", &jelements))
return NULL;

@@ -189,7 +184,7 @@ static json_object *get_element_model(json_object *jnode, int ele_idx,
return NULL;

if (!vendor) {
- snprintf(buf, 5, "%4.4x", mod_id);
+ snprintf(buf, 5, "%4.4x", (uint16_t)mod_id);
len = 4;
} else {
snprintf(buf, 9, "%8.8x", mod_id);
diff --git a/mesh/model.c b/mesh/model.c
index 23afb93a8..136edb194 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -628,6 +628,7 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id,
uint16_t app_idx, bool unbind)
{
struct mesh_model *mod;
+ bool vendor;
int ele_idx = node_get_element_idx(node, addr);

if (ele_idx < 0)
@@ -651,11 +652,15 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id,
if (unbind ^ has_binding(mod->bindings, app_idx))
return MESH_STATUS_SUCCESS;

+ vendor = IS_VENDOR(id);
+ id = vendor ? id : MODEL_ID(id);
+
if (unbind) {
model_unbind_idx(node, ele_idx, mod, app_idx);
+
if (!mesh_config_model_binding_del(node_config_get(node),
- addr, IS_VENDOR(id),
- id, app_idx))
+ addr, vendor, id,
+ app_idx))
return MESH_STATUS_STORAGE_FAIL;

l_debug("Unbind key %4.4x to model %8.8x", app_idx, mod->id);
@@ -666,13 +671,12 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id,
return MESH_STATUS_INSUFF_RESOURCES;

if (!mesh_config_model_binding_add(node_config_get(node), addr,
- IS_VENDOR(id), id, app_idx))
+ vendor, id, app_idx))
return MESH_STATUS_STORAGE_FAIL;

model_bind_idx(node, ele_idx, mod, app_idx);

return MESH_STATUS_SUCCESS;
-
}

static struct mesh_virtual *add_virtual(const uint8_t *v)
--
2.26.2


2020-08-12 19:07:32

by Stotland, Inga

[permalink] [raw]
Subject: [PATCH BlueZ 2/2] mesh: Make mesh config model binding API consistent

This changes the order of function arguments in
mesh_config_model_binding_add() and mesh_config_model_binding_del()
to make them consistent with the rest of mesh_config_model... APIs
---
mesh/mesh-config-json.c | 4 ++--
mesh/mesh-config.h | 4 ++--
mesh/model.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index 086d618b1..a145388d6 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -837,7 +837,7 @@ bool mesh_config_app_key_del(struct mesh_config *cfg, uint16_t net_idx,
}

bool mesh_config_model_binding_add(struct mesh_config *cfg, uint16_t ele_addr,
- bool vendor, uint32_t mod_id,
+ uint32_t mod_id, bool vendor,
uint16_t app_idx)
{
json_object *jnode, *jmodel, *jstring, *jarray = NULL;
@@ -882,7 +882,7 @@ bool mesh_config_model_binding_add(struct mesh_config *cfg, uint16_t ele_addr,
}

bool mesh_config_model_binding_del(struct mesh_config *cfg, uint16_t ele_addr,
- bool vendor, uint32_t mod_id,
+ uint32_t mod_id, bool vendor,
uint16_t app_idx)
{
json_object *jnode, *jmodel, *jarray;
diff --git a/mesh/mesh-config.h b/mesh/mesh-config.h
index f15f3f376..50a55d51e 100644
--- a/mesh/mesh-config.h
+++ b/mesh/mesh-config.h
@@ -152,10 +152,10 @@ bool mesh_config_comp_page_add(struct mesh_config *cfg, uint8_t page,
uint8_t *data, uint16_t size);
bool mesh_config_comp_page_mv(struct mesh_config *cfg, uint8_t old, uint8_t nw);
bool mesh_config_model_binding_add(struct mesh_config *cfg, uint16_t ele_addr,
- bool vendor, uint32_t mod_id,
+ uint32_t mod_id, bool vendor,
uint16_t app_idx);
bool mesh_config_model_binding_del(struct mesh_config *cfg, uint16_t ele_addr,
- bool vendor, uint32_t mod_id,
+ uint32_t mod_id, bool vendor,
uint16_t app_idx);
bool mesh_config_model_pub_add(struct mesh_config *cfg, uint16_t ele_addr,
uint32_t mod_id, bool vendor,
diff --git a/mesh/model.c b/mesh/model.c
index 136edb194..961391f13 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -659,7 +659,7 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id,
model_unbind_idx(node, ele_idx, mod, app_idx);

if (!mesh_config_model_binding_del(node_config_get(node),
- addr, vendor, id,
+ addr, id, vendor,
app_idx))
return MESH_STATUS_STORAGE_FAIL;

@@ -671,7 +671,7 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id,
return MESH_STATUS_INSUFF_RESOURCES;

if (!mesh_config_model_binding_add(node_config_get(node), addr,
- vendor, id, app_idx))
+ id, vendor, app_idx))
return MESH_STATUS_STORAGE_FAIL;

model_bind_idx(node, ele_idx, mod, app_idx);
--
2.26.2

2020-08-13 22:06:39

by Gix, Brian

[permalink] [raw]
Subject: Re: [PATCH BlueZ 1/2] mesh: Fix model ID prior to calling mesh config functions

Applied Patchset

On Wed, 2020-08-12 at 12:03 -0700, Inga Stotland wrote:
> Model IDs for SIG defined models need to be stripped off SIG_VENDOR
> value used for internal housekeeping prior to calling functions
> that save new model state in node configuration.
>
> Also, remove duplicate statements for model lookup in node config.
> ---
> mesh/mesh-config-json.c | 7 +------
> mesh/model.c | 12 ++++++++----
> 2 files changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
> index a40f92c01..086d618b1 100644
> --- a/mesh/mesh-config-json.c
> +++ b/mesh/mesh-config-json.c
> @@ -169,11 +169,6 @@ static json_object *get_element_model(json_object *jnode, int ele_idx,
> size_t len;
> char buf[9];
>
> - if (!vendor)
> - snprintf(buf, 5, "%4.4x", (uint16_t)mod_id);
> - else
> - snprintf(buf, 9, "%8.8x", mod_id);
> -
> if (!json_object_object_get_ex(jnode, "elements", &jelements))
> return NULL;
>
> @@ -189,7 +184,7 @@ static json_object *get_element_model(json_object *jnode, int ele_idx,
> return NULL;
>
> if (!vendor) {
> - snprintf(buf, 5, "%4.4x", mod_id);
> + snprintf(buf, 5, "%4.4x", (uint16_t)mod_id);
> len = 4;
> } else {
> snprintf(buf, 9, "%8.8x", mod_id);
> diff --git a/mesh/model.c b/mesh/model.c
> index 23afb93a8..136edb194 100644
> --- a/mesh/model.c
> +++ b/mesh/model.c
> @@ -628,6 +628,7 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id,
> uint16_t app_idx, bool unbind)
> {
> struct mesh_model *mod;
> + bool vendor;
> int ele_idx = node_get_element_idx(node, addr);
>
> if (ele_idx < 0)
> @@ -651,11 +652,15 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id,
> if (unbind ^ has_binding(mod->bindings, app_idx))
> return MESH_STATUS_SUCCESS;
>
> + vendor = IS_VENDOR(id);
> + id = vendor ? id : MODEL_ID(id);
> +
> if (unbind) {
> model_unbind_idx(node, ele_idx, mod, app_idx);
> +
> if (!mesh_config_model_binding_del(node_config_get(node),
> - addr, IS_VENDOR(id),
> - id, app_idx))
> + addr, vendor, id,
> + app_idx))
> return MESH_STATUS_STORAGE_FAIL;
>
> l_debug("Unbind key %4.4x to model %8.8x", app_idx, mod->id);
> @@ -666,13 +671,12 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id,
> return MESH_STATUS_INSUFF_RESOURCES;
>
> if (!mesh_config_model_binding_add(node_config_get(node), addr,
> - IS_VENDOR(id), id, app_idx))
> + vendor, id, app_idx))
> return MESH_STATUS_STORAGE_FAIL;
>
> model_bind_idx(node, ele_idx, mod, app_idx);
>
> return MESH_STATUS_SUCCESS;
> -
> }
>
> static struct mesh_virtual *add_virtual(const uint8_t *v)