diff --git a/mesh/node.c b/mesh/node.c
index f8acc78..1f328bd 100644
--- a/mesh/node.c
+++ b/mesh/node.c
free_node_dbus_resources(node);
}
-static void get_sig_models_from_properties(struct node_element *ele,
+static bool get_sig_models_from_properties(struct node_element *ele,
struct l_dbus_message_iter *property)
{
struct l_dbus_message_iter ids;
ele->models = l_queue_new();
if (!l_dbus_message_iter_get_variant(property, "aq", &ids))
- return;
+ return false;
/* Bluetooth SIG defined models */
while (l_dbus_message_iter_next_entry(&ids, &mod_id)) {
struct mesh_model *mod;
uint32_t id = mod_id | VENDOR_ID_MASK;
+ /* Allow Config Server Model only on the primary element */
+ if (ele->idx != PRIMARY_ELE_IDX && id == CONFIG_SRV_MODEL)
+ return false;
+
+ /* Disallow duplicates */
if (l_queue_find(ele->models, match_model_id,
L_UINT_TO_PTR(id)))
- continue;
+ return false;
mod = mesh_model_new(ele->idx, id);
l_queue_insert(ele->models, mod, compare_model_id, NULL);
}
+
+ return true;
}
-static void get_vendor_models_from_properties(struct node_element *ele,
+static bool get_vendor_models_from_properties(struct node_element *ele,
struct l_dbus_message_iter *property)
{
struct l_dbus_message_iter ids;
ele->models = l_queue_new();
if (!l_dbus_message_iter_get_variant(property, "a(qq)", &ids))
- return;
+ return false;
/* Vendor defined models */
while (l_dbus_message_iter_next_entry(&ids, &vendor_id, &mod_id)) {
struct mesh_model *mod;
uint32_t id = mod_id | (vendor_id << 16);
+ /* Disallow duplicates */
if (l_queue_find(ele->models, match_model_id,
L_UINT_TO_PTR(id)))
- continue;
+ return false;
mod = mesh_model_new(ele->idx, id);
l_queue_insert(ele->models, mod, compare_model_id, NULL);
}
+
+ return true;
}
static bool get_element_properties(struct mesh_node *node, const char *path,
ele->location = DEFAULT_LOCATION;
while (l_dbus_message_iter_next_entry(properties, &key, &var)) {
- if (!idx && !strcmp(key, "Index")) {
- if (!l_dbus_message_iter_get_variant(&var, "y",
+ if (!strcmp(key, "Index")) {
+
+ if (idx || !l_dbus_message_iter_get_variant(&var, "y",
&ele->idx))
goto fail;
+
idx = true;
- continue;
- }
- if (!mods && !strcmp(key, "Models")) {
- get_sig_models_from_properties(ele, &var);
+ } else if (!strcmp(key, "Models")) {
+
+ if (mods || !get_sig_models_from_properties(ele, &var))
+ goto fail;
+
mods = true;
- continue;
- }
+ } else if (!strcmp(key, "VendorModels")) {
+
+ if (vendor_mods ||
+ !get_vendor_models_from_properties(ele, &var))
+ goto fail;
- if (!vendor_mods && !strcmp(key, "VendorModels")) {
- get_vendor_models_from_properties(ele, &var);
vendor_mods = true;
- continue;
- }
- if (!strcmp(key, "Location")) {
+ } else if (!strcmp(key, "Location")) {
if (!l_dbus_message_iter_get_variant(&var, "q",
&ele->location))
goto fail;
- continue;
}
}
+ /* Check for the presence of the required properties */
if (!idx || !mods || !vendor_mods)
goto fail;