return __bt_mesh_save_configruation_file(cfg);
}
+bool _bt_mesh_is_group_subscribed(_bt_mesh_cdb_t *cfg, uint16_t group_addr)
+{
+ json_object *jnodes;
+ int i, sz = 0;
+
+ if (!cfg || !cfg->jcfg)
+ return false;
+
+ json_object_object_get_ex(cfg->jcfg, "nodes", &jnodes);
+ if (!jnodes || json_object_get_type(jnodes) != json_type_array)
+ return false;
+
+ sz = json_object_array_length(jnodes);
+
+ for (i = 0; i < sz; ++i) {
+ json_object *jnode, *jarray;
+ int ele_cnt;
+ int j;
+
+ jnode = json_object_array_get_idx(jnodes, i);
+ if (!jnode)
+ continue;
+
+ if (!json_object_object_get_ex(jnode, "elements", &jarray))
+ return false;
+
+ if (!jarray || json_object_get_type(jarray) != json_type_array)
+ return false;
+
+ ele_cnt = json_object_array_length(jarray);
+
+ for (j = 0; j < ele_cnt; ++j) {
+ json_object *jentry, *jval, *jmods;
+ int32_t index;
+ int k, mod_cnt;
+
+ jentry = json_object_array_get_idx(jarray, j);
+ if (!json_object_object_get_ex(jentry, "index", &jval))
+ return false;
+
+ index = json_object_get_int(jval);
+ if (index > 0xff)
+ return false;
+
+ if (!json_object_object_get_ex(jentry, "models", &jmods))
+ continue;
+
+ mod_cnt = json_object_array_length(jmods);
+ BT_INFO("Mesh: Total Model count in element Index [%d] is [%d]",
+ index, mod_cnt);
+
+ for (k = 0; k < mod_cnt; ++k) {
+ json_object *jmod;
+ json_object *jgroups, *jgroup;
+
+ jmod = json_object_array_get_idx(jmods, k);
+
+ if (!json_object_object_get_ex(jmod, "sub-addr", &jgroups))
+ continue;
+
+ /* Find existing sub-addr group */
+ jgroup = __mesh_get_sub_group(jgroups, group_addr);
+ if (jgroup) {
+ BT_DBG("sub-addr present in list");
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
bool _bt_mesh_conf_set_network_friendly_name(_bt_mesh_cdb_t *cfg,
const char *network_name)
{
}
grp = (_bt_mesh_group_t*)l1->data;
+ /* Do not delete group if a model is subscribed to this */
+ if (_bt_mesh_is_group_subscribed(cdb_cfg, req->group_addr)) {
+ BT_ERR("Mesh: Failed to remove Group: [0x%2.2x]", req->group_addr);
+ return BLUETOOTH_ERROR_AUTHENTICATION_REJECTED;
+ }
+
BT_INFO("Mesh: To be Removed Group: [0x%2.2x]", req->group_addr);
if (!_bt_mesh_conf_delete_group_entry(cdb_cfg, req->group_addr)) {
BT_ERR("Mesh: Failed to remove Group: [0x%2.2x]", req->group_addr);