Add options to Models and VendorModels
v2 cover Add options to Models and VendorModels
v2:
Changes constaned to patch 0002:
- Fixed returned status in config pub/sub model calls
- Consistent use of pub_enabled & sub_enabled in the code
************
If a model does not support either subscription mechanism,
Config Server is supposed to return "Not a Subscribe Model" if a Config Client sends a subscription add/overwrite message.
Similarly, if a model does not support publication, "Invalid Publish Parameters" should be returned in response to Publication Set message.
Since config server is running even when an app is not attached, the only way to collect these model capabilities is on Attach, Join, Create, Import methods when the object manager collects app info.
To address this issue, signatures for properties "Models" and "VendorModels" on Element interface change to include "options" dictionary:
Models: signature change "aq" -> "a(qa{sv})"
VendorModels: signature change "a(qq)" -> "a(qqa{sv})"The defined keywords for the options dictionary are:
"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.
Inga Stotland (4):
doc/mesh-api: Add dictionary to model properties
mesh: Check app model settings of pub/sub support tools/mesh-cfgclient: Add options to "Models" property test/test-mesh: Add options to "Models" property
doc/mesh-api.txt | 40 ++++++++-- mesh/mesh-config-json.c | 76 +++++++++++++++++- mesh/mesh-config.h | 8 ++ mesh/model.c | 98 +++++++++++++++++++---- mesh/model.h | 6 ++ mesh/node.c | 168 ++++++++++++++++++++++++++++++++-------- test/test-mesh | 21 ++--- tools/mesh-cfgclient.c | 25 ++++-- 8 files changed, 374 insertions(+), 68 deletions(-)
Signature · 1 line
2.26.2
PATCH v2 1/4 doc/mesh-api: Add dictionary to model properties
This changes the signature of "Models" and "VendorModels" properties on org.bluez.mesh.Element1 interface to contain a dictionary with model options.
Models: signature change "aq" -> "a(qa{sv})"
VendorModels: signature change "a(qq)" -> "a(qqa{sv})"
Currently, the defined keywords for the options dictionary are "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.
The dictionary allowed to be empty.
--- doc/mesh-api.txt | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-)
doc/mesh-api.txt +34 -6
@@ -888,15 +888,43 @@ Properties: Element index. It is required that the application follows sequential numbering scheme for the elements, starting with 0. - array{uint16} Models [read-only] + array{(uint16 id, dict caps)} Models [read-only] - An array of SIG Model Identifiers. The array may be empty. + An array of SIG Models: - array{(uint16, uint16)} VendorModels [read-only] + id - SIG Model Identifier - An array of pairs (vendor, model ID): vendor is a 16-bit - Bluetooth-assigned Company ID as defined by Bluetooth SIG. - model ID is a 16-bit vendor-assigned Model Identifier + options - a dictionary that may contain additional model + info. The following keys are defined: + + boolean Publish - indicates whether the model + supports publication mechanism. If not + present, publication is enabled. + + boolean Subscribe - indicates whether the model + supports subscription mechanism. If not + present, subscriptons are enabled. + + The array may be empty. + + + array{(uint16 vendor, uint16 id, dict options)} VendorModels [read-only] + + An array of Vendor Models: + + vendor - a 16-bit Bluetooth-assigned Company ID as + defined by Bluetooth SIG. + + id - a 16-bit vendor-assigned Model Identifier + + options - a dictionary that may contain additional model + info. The following keys are defined: + + boolean Publish - indicates whether the model + supports publication mechanism + + boolean Subscribe - indicates whether the model + supports subscription mechanism The array may be empty.
Signature · 1 line
2.26.2
PATCH v2 2/4 mesh: Check app model settings of pub/sub support
In reply to Inga StotlandThis 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.
--- mesh/mesh-config-json.c | 76 +++++++++++++++++- mesh/mesh-config.h | 8 ++ mesh/model.c | 98 +++++++++++++++++++---- mesh/model.h | 6 ++ mesh/node.c | 168 ++++++++++++++++++++++++++++++++-------- 5 files changed, 309 insertions(+), 47 deletions(-)
mesh/mesh-config-json.c +75 -1
@@ -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) {
mesh/mesh-config.h +8 -0
@@ -45,6 +45,8 @@ struct mesh_config_model {uint16_t *bindings;uint32_t id;bool vendor; +bool sub_enabled; +bool pub_enabled;uint32_t num_bindings;uint32_t num_subs; };
@@ -156,6 +158,12 @@ bool mesh_config_model_sub_del(struct mesh_config *cfg, uint16_t ele_addr, struct mesh_config_sub *sub);bool mesh_config_model_sub_del_all (struct mesh_config *cfg,uint16_t ele_addr,uint32_t mod_id,bool vendor); +bool mesh_config_model_pub_enable (struct mesh_config *cfg,uint16_t ele_addr, +uint32_t mod_id,bool vendor, +bool enable); +bool mesh_config_model_sub_enable (struct mesh_config *cfg,uint16_t ele_addr, +uint32_t mod_id,bool vendor, +bool enable);bool mesh_config_app_key_add (struct mesh_config *cfg,uint16_t net_idx,uint16_t app_idx,const uint8_t key[16 ]); bool mesh_config_app_key_update(struct mesh_config *cfg, uint16_t app_idx,
mesh/model.c +84 -14
181 lines not on this page · raw message
mesh/model.h +6 -0
@@ -112,5 +112,11 @@ bool mesh_model_opcode_get(const uint8_t *buf, uint16_t size, uint32_t *opcode, uint16_t *n);void model_build_config (void *model,void *msg_builder); +void mesh_model_enable_pub (struct mesh_model *mod,bool enable); +bool mesh_model_is_pub_enabled (struct mesh_model *mod); +void mesh_model_enable_sub (struct mesh_node *node,struct mesh_model *mod, +bool enable); +bool mesh_model_is_sub_enabled (struct mesh_model *mod); +void mesh_model_init (void );void mesh_model_cleanup (void );
mesh/node.c +136 -32
240 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 3/4 tools/mesh-cfgclient: Add options to "Models" property
In reply to Inga StotlandThis adds options dictionary to "Models" property to stay in sync with mesh-api changes.
--- tools/mesh-cfgclient.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
tools/mesh-cfgclient.c +19 -6
@@ -1448,14 +1448,26 @@ static void proxy_removed(struct l_dbus_proxy *proxy, void *user_data) } } +static void build_model (struct l_dbus_message_builder *builder,uint16_t mod_id, +bool pub_enable,bool sub_enable) +{ +l_dbus_message_builder_enter_struct (builder,"qa{sv}" ); +l_dbus_message_builder_append_basic (builder,'q' , &mod_id); +l_dbus_message_builder_enter_array (builder,"{sv}" ); +append_dict_entry_basic (builder,"Subscribe" ,"b" , &sub_enable); +append_dict_entry_basic (builder,"Publish" ,"b" , &pub_enable); +l_dbus_message_builder_leave_array (builder); +l_dbus_message_builder_leave_struct (builder); +} +static bool mod_getter (struct l_dbus *dbus,struct l_dbus_message *message,struct l_dbus_message_builder *builder,void *user_data) { -l_dbus_message_builder_enter_array (builder,"q" ); -l_dbus_message_builder_append_basic (builder,'q' , &app.ele.mods[0 ]); -l_dbus_message_builder_append_basic (builder,'q' , &app.ele.mods[1 ]); +l_dbus_message_builder_enter_array (builder,"(qa{sv})" ); +build_model (builder, app.ele.mods[0 ], false, false); +build_model (builder, app.ele.mods[1 ], false, false);l_dbus_message_builder_leave_array (builder);return true;
@@ -1466,7 +1478,7 @@ static bool vmod_getter(struct l_dbus *dbus,struct l_dbus_message_builder *builder, void *user_data) { - l_dbus_message_builder_enter_array(builder, "(qq)"); + l_dbus_message_builder_enter_array(builder, "(qqa{sv})");l_dbus_message_builder_leave_array (builder);return true;
@@ -1517,9 +1529,10 @@ static void setup_ele_iface(struct l_dbus_interface *iface)/* Properties */ l_dbus_interface_property (iface,"Index" ,0 ,"y" , ele_idx_getter,NULL ); -l_dbus_interface_property (iface,"VendorModels" ,0 ,"a(qq)" , +l_dbus_interface_property (iface,"VendorModels" ,0 ,"a(qqa{sv})" , vmod_getter,NULL ); -l_dbus_interface_property (iface,"Models" ,0 ,"aq" , mod_getter,NULL ); +l_dbus_interface_property (iface,"Models" ,0 ,"a(qa{sv})" , mod_getter, +NULL );/* Methods */ l_dbus_interface_method(iface, "DevKeyMessageReceived", 0,
Signature · 1 line
2.26.2
PATCH v2 4/4 test/test-mesh: Add options to "Models" property
In reply to Inga StotlandThis adds options dictionary to "Models" property to stay in sync with mesh-api changes.
--- test/test-mesh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
test/test-mesh +12 -9
@@ -430,32 +430,35 @@ class Element(dbus.service.Object): dbus.service.Object.__init__(self, bus, self.path) def _get_sig_models(self): - ids = [] + mods = [] for model in self.models: + opts = [] id = model.get_id() vendor = model.get_vendor() if vendor == VENDOR_ID_NONE: - ids.append(id) - return ids + mod = (id, opts) + mods.append(mod) + return mods def _get_v_models(self): - ids = [] + mods = [] for model in self.models: + opts = [] id = model.get_id() v = model.get_vendor() if v != VENDOR_ID_NONE: - vendor_id = (v, id) - ids.append(vendor_id) - return ids + mod = (v, id, opts) + mods.append(mod) + return mods def get_properties(self): vendor_models = self._get_v_models() sig_models = self._get_sig_models() props = {'Index' : dbus.Byte(self.index)} - props['Models'] = dbus.Array(sig_models, signature='q') + props['Models'] = dbus.Array(sig_models, signature='(qa{sv})') props['VendorModels'] = dbus.Array(vendor_models, - signature='(qq)') + signature='(qqa{sv})') #print(props) return { MESH_ELEMENT_IFACE: props }
Signature · 1 line
2.26.2
Patchset Applied
Quoted 46 lines · Inga Stotland
v2:
Changes constaned to patch 0002:
- Fixed returned status in config pub/sub model calls
- Consistent use ofpub_enabled&sub_enabledin the code************
If a model does not support either subscription mechanism,
Config Server is supposed to return "Not a Subscribe Model" if a Config Client sends a subscription add/overwrite message.Similarly, if a model does not support publication, "Invalid Publish Parameters" should be returned in response to Publication Set message.
Since config server is running even when an app is not attached, the only way to collect these model capabilities is on Attach, Join, Create, Import methods when the object manager collects app info.
To address this issue, signatures for properties "Models" and "VendorModels" on Element interface change to include "options" dictionary:
Models: signature change "aq" -> "a(qa{sv})" VendorModels: signature change "a(qq)" -> "a(qqa{sv})"The defined keywords for the options dictionary are:
"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.Inga Stotland (4):
doc/mesh-api: Add dictionary to model properties
mesh: Check app model settings of pub/sub supporttools/mesh-cfgclient: Add options to "Models" property test/test-mesh: Add options to "Models" propertydoc/mesh-api.txt | 40 ++++++++-- mesh/mesh-config-json.c | 76 +++++++++++++++++- mesh/mesh-config.h | 8 ++ mesh/model.c | 98 +++++++++++++++++++---- mesh/model.h | 6 ++ mesh/node.c | 168 ++++++++++++++++++++++++++++++++-------- test/test-mesh | 21 ++--- tools/mesh-cfgclient.c | 25 ++++-- 8 files changed, 374 insertions(+), 68 deletions(-)