summaryrefslogtreecommitdiff
path: root/mesh/mesh-config-json.c
diff options
context:
space:
mode:
authorInga Stotland <inga.stotland@intel.com>2020-06-30 11:56:15 -0700
committerBrian Gix <brian.gix@intel.com>2020-07-01 12:06:07 -0700
commite803b54864aa2d222eabc02f4814af9b467de34a (patch)
treeb01c71488ab6807ba2296411ae2df48a0fb91a34 /mesh/mesh-config-json.c
parent807886eb5717902cd10ff8ad13e91d9200f0549d (diff)
downloadbluez-e803b54864aa2d222eabc02f4814af9b467de34a.tar.gz
mesh: Check app model settings of pub/sub support
This adds handling of new options dictionary included with "Models" and "VendorModels" properties on org.bluez.mesh.Element1 interface. Supported (optional) dictionary entries: "Publish" - indicates whether the model supports publication mechanism. If not present, publication is enabled. "Subscribe" - indicates whether the model supports subscription mechanism. If not present, subscriptions are enabled. If a config message related to subscription state is received for a model that does not support subscription mechanism, an error code 0x08, ("Not A Subscribe Model") is sent in response. If a config message related to publication state is received for a model that does not support publication mechanism, an error code 0x07 ("Invalid Publish Parameters") is sent in response.
Diffstat (limited to 'mesh/mesh-config-json.c')
-rw-r--r--mesh/mesh-config-json.c76
1 files changed, 75 insertions, 1 deletions
diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index 05b2a5651..661775f95 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -1096,6 +1096,16 @@ static bool parse_models(json_object *jmodels, struct mesh_config_element *ele)
goto fail;
}
+ if (json_object_object_get_ex(jmodel, "pubEnabled", &jvalue))
+ mod->pub_enabled = json_object_get_boolean(jvalue);
+ else
+ mod->pub_enabled = true;
+
+ if (json_object_object_get_ex(jmodel, "subEnabled", &jvalue))
+ mod->sub_enabled = json_object_get_boolean(jvalue);
+ else
+ mod->sub_enabled = true;
+
if (json_object_object_get_ex(jmodel, "publish", &jvalue)) {
mod->pub = parse_model_publication(jvalue);
if (!mod->pub)
@@ -1562,7 +1572,7 @@ bool mesh_config_write_iv_index(struct mesh_config *cfg, uint32_t idx,
static void add_model(void *a, void *b)
{
struct mesh_config_model *mod = a;
- json_object *jmodels = b, *jmodel;
+ json_object *jmodels = b, *jmodel, *jval;
jmodel = json_object_new_object();
if (!jmodel)
@@ -1574,6 +1584,12 @@ static void add_model(void *a, void *b)
else
write_uint32_hex(jmodel, "modelId", mod->id);
+ jval = json_object_new_boolean(mod->sub_enabled);
+ json_object_object_add(jmodel, "subEnabled", jval);
+
+ jval = json_object_new_boolean(mod->pub_enabled);
+ json_object_object_add(jmodel, "pubEnabled", jval);
+
json_object_array_add(jmodels, jmodel);
}
@@ -1974,6 +1990,64 @@ bool mesh_config_model_sub_del_all(struct mesh_config *cfg, uint16_t addr,
return save_config(cfg->jnode, cfg->node_dir_path);
}
+bool mesh_config_model_pub_enable(struct mesh_config *cfg, uint16_t ele_addr,
+ uint32_t mod_id, bool vendor,
+ bool enable)
+{
+ json_object *jmodel, *jval;
+ int ele_idx;
+
+ if (!cfg)
+ return false;
+
+ ele_idx = get_element_index(cfg->jnode, ele_addr);
+ if (ele_idx < 0)
+ return false;
+
+ jmodel = get_element_model(cfg->jnode, ele_idx, mod_id, vendor);
+ if (!jmodel)
+ return false;
+
+ json_object_object_del(jmodel, "pubDisabled");
+
+ jval = json_object_new_boolean(!enable);
+ json_object_object_add(jmodel, "pubDisabled", jval);
+
+ if (!enable)
+ json_object_object_del(jmodel, "publish");
+
+ return save_config(cfg->jnode, cfg->node_dir_path);
+}
+
+bool mesh_config_model_sub_enable(struct mesh_config *cfg, uint16_t ele_addr,
+ uint32_t mod_id, bool vendor,
+ bool enable)
+{
+ json_object *jmodel, *jval;
+ int ele_idx;
+
+ if (!cfg)
+ return false;
+
+ ele_idx = get_element_index(cfg->jnode, ele_addr);
+ if (ele_idx < 0)
+ return false;
+
+ jmodel = get_element_model(cfg->jnode, ele_idx, mod_id, vendor);
+ if (!jmodel)
+ return false;
+
+ json_object_object_del(jmodel, "subEnabled");
+
+ jval = json_object_new_boolean(enable);
+ json_object_object_add(jmodel, "subEnabled", jval);
+
+ if (!enable)
+ json_object_object_del(jmodel, "subscribe");
+
+ return save_config(cfg->jnode, cfg->node_dir_path);
+}
+
bool mesh_config_write_seq_number(struct mesh_config *cfg, uint32_t seq,
bool cache)
{