Bluetooth: Mesh: Check that required models exists on the same element
Referring to MshDFU_v1.0 Sections 6.1.1, 6.2.1 and 7.1.1 model descriptions: DFU/DFD server/clients extend BLOB Transfer root models and DFD server requires Firmware Update Client on the same element. For this reason we need to make sure that those main models or root models exist on the same element. And also firmware update client can not be forced to be in the first element. For all model extention call return the error code in case of an error. Signed-off-by: alperen sener <alperen.sener@nordicsemi.no>
This commit is contained in:
parent
e642b3bfe4
commit
e653a39ed7
4 changed files with 53 additions and 10 deletions
|
@ -925,12 +925,34 @@ const struct bt_mesh_blob_srv_cb _bt_mesh_dfd_srv_blob_cb = {
|
|||
|
||||
static int dfd_srv_init(const struct bt_mesh_model *mod)
|
||||
{
|
||||
int err;
|
||||
struct bt_mesh_dfd_srv *srv = mod->rt->user_data;
|
||||
|
||||
srv->mod = mod;
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_MESH_MODEL_EXTENSIONS)) {
|
||||
bt_mesh_model_extend(mod, srv->upload.blob.mod);
|
||||
const struct bt_mesh_model *blob_srv =
|
||||
bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_BLOB_SRV);
|
||||
|
||||
if (blob_srv == NULL) {
|
||||
LOG_ERR("Missing BLOB Srv.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/** BLOB client also shall be present on the same element, but it is already checked by
|
||||
* initiation of dfu client which we check here.
|
||||
*/
|
||||
const struct bt_mesh_model *dfu_cli =
|
||||
bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_DFU_CLI);
|
||||
|
||||
if (dfu_cli == NULL) {
|
||||
LOG_ERR("Missing FU Cli.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = bt_mesh_model_extend(mod, srv->upload.blob.mod);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -963,17 +963,22 @@ const struct bt_mesh_model_op _bt_mesh_dfu_cli_op[] = {
|
|||
|
||||
static int dfu_cli_init(const struct bt_mesh_model *mod)
|
||||
{
|
||||
int err;
|
||||
struct bt_mesh_dfu_cli *cli = mod->rt->user_data;
|
||||
cli->mod = mod;
|
||||
|
||||
if (mod->rt->elem_idx != 0) {
|
||||
LOG_ERR("DFU update client must be instantiated on first elem");
|
||||
const struct bt_mesh_model *blob_cli =
|
||||
bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_BLOB_CLI);
|
||||
|
||||
if (blob_cli == NULL) {
|
||||
LOG_ERR("Missing BLOB Cli.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
cli->mod = mod;
|
||||
err = bt_mesh_model_extend(mod, cli->blob.mod);
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_MESH_MODEL_EXTENSIONS)) {
|
||||
bt_mesh_model_extend(mod, cli->blob.mod);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
k_sem_init(&cli->req.sem, 0, 1);
|
||||
|
|
|
@ -440,6 +440,7 @@ const struct bt_mesh_model_op _bt_mesh_dfu_srv_op[] = {
|
|||
|
||||
static int dfu_srv_init(const struct bt_mesh_model *mod)
|
||||
{
|
||||
int err;
|
||||
struct bt_mesh_dfu_srv *srv = mod->rt->user_data;
|
||||
|
||||
srv->mod = mod;
|
||||
|
@ -451,8 +452,18 @@ static int dfu_srv_init(const struct bt_mesh_model *mod)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_MESH_MODEL_EXTENSIONS)) {
|
||||
bt_mesh_model_extend(mod, srv->blob.mod);
|
||||
const struct bt_mesh_model *blob_srv =
|
||||
bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_BLOB_SRV);
|
||||
|
||||
if (blob_srv == NULL) {
|
||||
LOG_ERR("Missing BLOB Srv.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = bt_mesh_model_extend(mod, srv->blob.mod);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -195,6 +195,7 @@ const struct bt_mesh_model_op bt_mesh_priv_beacon_srv_op[] = {
|
|||
|
||||
static int priv_beacon_srv_init(const struct bt_mesh_model *mod)
|
||||
{
|
||||
int err;
|
||||
const struct bt_mesh_model *config_srv =
|
||||
bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_CFG_SRV);
|
||||
|
||||
|
@ -206,7 +207,11 @@ static int priv_beacon_srv_init(const struct bt_mesh_model *mod)
|
|||
priv_beacon_srv = mod;
|
||||
mod->keys[0] = BT_MESH_KEY_DEV_LOCAL;
|
||||
|
||||
bt_mesh_model_extend(mod, config_srv);
|
||||
err = bt_mesh_model_extend(mod, config_srv);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue