diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index cafa2fd..198fef5 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
return save_config(jnode, cfg->node_dir_path);
}
-bool mesh_config_model_binding_add(struct mesh_config *cfg, uint8_t ele_idx,
- bool vendor, uint32_t mod_id,
+bool mesh_config_model_binding_add(struct mesh_config *cfg, uint16_t ele_addr,
+ bool vendor, uint32_t mod_id,
uint16_t app_idx)
{
json_object *jnode, *jmodel, *jstring, *jarray = NULL;
+ int ele_idx;
char buf[5];
if (!cfg)
jnode = cfg->jnode;
+ ele_idx = get_element_index(jnode, ele_addr);
+ if (ele_idx < 0)
+ return false;
+
jmodel = get_element_model(jnode, ele_idx, mod_id, vendor);
if (!jmodel)
return false;
return save_config(jnode, cfg->node_dir_path);
}
-bool mesh_config_model_binding_del(struct mesh_config *cfg, uint8_t ele_idx,
- bool vendor, uint32_t mod_id,
+bool mesh_config_model_binding_del(struct mesh_config *cfg, uint16_t ele_addr,
+ bool vendor, uint32_t mod_id,
uint16_t app_idx)
{
json_object *jnode, *jmodel, *jarray, *jarray_new;
+ int ele_idx;
char buf[5];
if (!cfg)
jnode = cfg->jnode;
+ ele_idx = get_element_index(jnode, ele_addr);
+ if (ele_idx < 0)
+ return false;
+
jmodel = get_element_model(jnode, ele_idx, mod_id, vendor);
if (!jmodel)
return false;
return save_config(jnode, cfg->node_dir_path);
}
-bool mesh_config_model_pub_add(struct mesh_config *cfg, uint16_t addr,
+bool mesh_config_model_pub_add(struct mesh_config *cfg, uint16_t ele_addr,
uint32_t mod_id, bool vendor,
struct mesh_config_pub *pub)
{
jnode = cfg->jnode;
- ele_idx = get_element_index(jnode, addr);
+ ele_idx = get_element_index(jnode, ele_addr);
if (ele_idx < 0)
return false;
return false;
}
-static bool delete_model_property(json_object *jnode, uint16_t addr,
+static bool delete_model_property(json_object *jnode, uint16_t ele_addr,
uint32_t mod_id, bool vendor, const char *keyword)
{
json_object *jmodel;
int ele_idx;
- ele_idx = get_element_index(jnode, addr);
+ ele_idx = get_element_index(jnode, ele_addr);
if (ele_idx < 0)
return false;
return save_config(cfg->jnode, cfg->node_dir_path);
}
-bool mesh_config_model_sub_add(struct mesh_config *cfg, uint16_t addr,
+bool mesh_config_model_sub_add(struct mesh_config *cfg, uint16_t ele_addr,
uint32_t mod_id, bool vendor,
struct mesh_config_sub *sub)
{
jnode = cfg->jnode;
- ele_idx = get_element_index(jnode, addr);
+ ele_idx = get_element_index(jnode, ele_addr);
if (ele_idx < 0)
return false;
return save_config(jnode, cfg->node_dir_path);
}
-bool mesh_config_model_sub_del(struct mesh_config *cfg, uint16_t addr,
+bool mesh_config_model_sub_del(struct mesh_config *cfg, uint16_t ele_addr,
uint32_t mod_id, bool vendor,
struct mesh_config_sub *sub)
{
jnode = cfg->jnode;
- ele_idx = get_element_index(jnode, addr);
+ ele_idx = get_element_index(jnode, ele_addr);
if (ele_idx < 0)
return false;
diff --git a/mesh/mesh-config.h b/mesh/mesh-config.h
index cf1f8b2..a5b12bb 100644
--- a/mesh/mesh-config.h
+++ b/mesh/mesh-config.h
uint8_t dev_key[16];
uint8_t token[8];
};
+
typedef void (*mesh_config_status_func_t)(void *user_data, bool result);
typedef bool (*mesh_config_node_func_t)(struct mesh_config_node *node,
const uint8_t uuid[16],
bool mesh_config_write_ttl(struct mesh_config *cfg, uint8_t ttl);
bool mesh_config_write_mode(struct mesh_config *cfg, const char *keyword,
int value);
-bool mesh_config_model_binding_add(struct mesh_config *cfg, uint8_t ele_idx,
+bool mesh_config_model_binding_add(struct mesh_config *cfg, uint16_t ele_addr,
bool vendor, uint32_t mod_id,
uint16_t app_idx);
-bool mesh_config_model_binding_del(struct mesh_config *cfg, uint8_t ele_idx,
+bool mesh_config_model_binding_del(struct mesh_config *cfg, uint16_t ele_addr,
bool vendor, uint32_t mod_id,
uint16_t app_idx);
bool mesh_config_model_pub_add(struct mesh_config *cfg, uint16_t ele_addr,
struct mesh_config_pub *pub);
bool mesh_config_model_pub_del(struct mesh_config *cfg, uint16_t ele_addr,
uint32_t mod_id, bool vendor);
-bool mesh_config_model_sub_add(struct mesh_config *cfg, uint16_t addr,
+bool mesh_config_model_sub_add(struct mesh_config *cfg, uint16_t ele_addr,
uint32_t mod_id, bool vendor,
struct mesh_config_sub *sub);
-bool mesh_config_model_sub_del(struct mesh_config *cfg, uint16_t addr,
+bool mesh_config_model_sub_del(struct mesh_config *cfg, uint16_t ele_addr,
uint32_t mod_id, bool vendor,
struct mesh_config_sub *sub);
-bool mesh_config_model_sub_del_all(struct mesh_config *cfg, uint16_t addr,
+bool mesh_config_model_sub_del_all(struct mesh_config *cfg, uint16_t ele_addr,
uint32_t mod_id, bool vendor);
bool mesh_config_app_key_add(struct mesh_config *cfg, uint16_t net_idx,
uint16_t app_idx, const uint8_t key[16]);
diff --git a/mesh/model.c b/mesh/model.c
index a06b684..f4b8561 100644
--- a/mesh/model.c
+++ b/mesh/model.c
int status;
struct mesh_model *mod;
bool is_present, is_vendor;
- uint8_t ele_idx;
mod = find_model(node, addr, id, &status);
if (!mod) {
if (is_present && !unbind)
return MESH_STATUS_SUCCESS;
- ele_idx = (uint8_t) node_get_element_idx(node, addr);
-
if (unbind) {
model_unbind_idx(node, mod, app_idx);
if (!mesh_config_model_binding_del(node_config_get(node),
- ele_idx, is_vendor, id, app_idx))
+ addr, is_vendor, id, app_idx))
return MESH_STATUS_STORAGE_FAIL;
return MESH_STATUS_SUCCESS;
return MESH_STATUS_INSUFF_RESOURCES;
if (!mesh_config_model_binding_add(node_config_get(node),
- ele_idx, is_vendor, id, app_idx))
+ addr, is_vendor, id, app_idx))
return MESH_STATUS_STORAGE_FAIL;
model_bind_idx(node, mod, app_idx);