Skip to content

Commit e653a39

Browse files
m-alperen-senerkartben
authored andcommitted
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 <[email protected]>
1 parent e642b3b commit e653a39

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

subsys/bluetooth/mesh/dfd_srv.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,12 +925,34 @@ const struct bt_mesh_blob_srv_cb _bt_mesh_dfd_srv_blob_cb = {
925925

926926
static int dfd_srv_init(const struct bt_mesh_model *mod)
927927
{
928+
int err;
928929
struct bt_mesh_dfd_srv *srv = mod->rt->user_data;
929930

930931
srv->mod = mod;
931932

932-
if (IS_ENABLED(CONFIG_BT_MESH_MODEL_EXTENSIONS)) {
933-
bt_mesh_model_extend(mod, srv->upload.blob.mod);
933+
const struct bt_mesh_model *blob_srv =
934+
bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_BLOB_SRV);
935+
936+
if (blob_srv == NULL) {
937+
LOG_ERR("Missing BLOB Srv.");
938+
return -EINVAL;
939+
}
940+
941+
/** BLOB client also shall be present on the same element, but it is already checked by
942+
* initiation of dfu client which we check here.
943+
*/
944+
const struct bt_mesh_model *dfu_cli =
945+
bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_DFU_CLI);
946+
947+
if (dfu_cli == NULL) {
948+
LOG_ERR("Missing FU Cli.");
949+
return -EINVAL;
950+
}
951+
952+
err = bt_mesh_model_extend(mod, srv->upload.blob.mod);
953+
954+
if (err) {
955+
return err;
934956
}
935957

936958
return 0;

subsys/bluetooth/mesh/dfu_cli.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -963,17 +963,22 @@ const struct bt_mesh_model_op _bt_mesh_dfu_cli_op[] = {
963963

964964
static int dfu_cli_init(const struct bt_mesh_model *mod)
965965
{
966+
int err;
966967
struct bt_mesh_dfu_cli *cli = mod->rt->user_data;
968+
cli->mod = mod;
969+
970+
const struct bt_mesh_model *blob_cli =
971+
bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_BLOB_CLI);
967972

968-
if (mod->rt->elem_idx != 0) {
969-
LOG_ERR("DFU update client must be instantiated on first elem");
973+
if (blob_cli == NULL) {
974+
LOG_ERR("Missing BLOB Cli.");
970975
return -EINVAL;
971976
}
972977

973-
cli->mod = mod;
978+
err = bt_mesh_model_extend(mod, cli->blob.mod);
974979

975-
if (IS_ENABLED(CONFIG_BT_MESH_MODEL_EXTENSIONS)) {
976-
bt_mesh_model_extend(mod, cli->blob.mod);
980+
if (err) {
981+
return err;
977982
}
978983

979984
k_sem_init(&cli->req.sem, 0, 1);

subsys/bluetooth/mesh/dfu_srv.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ const struct bt_mesh_model_op _bt_mesh_dfu_srv_op[] = {
440440

441441
static int dfu_srv_init(const struct bt_mesh_model *mod)
442442
{
443+
int err;
443444
struct bt_mesh_dfu_srv *srv = mod->rt->user_data;
444445

445446
srv->mod = mod;
@@ -451,8 +452,18 @@ static int dfu_srv_init(const struct bt_mesh_model *mod)
451452
return -EINVAL;
452453
}
453454

454-
if (IS_ENABLED(CONFIG_BT_MESH_MODEL_EXTENSIONS)) {
455-
bt_mesh_model_extend(mod, srv->blob.mod);
455+
const struct bt_mesh_model *blob_srv =
456+
bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_BLOB_SRV);
457+
458+
if (blob_srv == NULL) {
459+
LOG_ERR("Missing BLOB Srv.");
460+
return -EINVAL;
461+
}
462+
463+
err = bt_mesh_model_extend(mod, srv->blob.mod);
464+
465+
if (err) {
466+
return err;
456467
}
457468

458469
return 0;

subsys/bluetooth/mesh/priv_beacon_srv.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ const struct bt_mesh_model_op bt_mesh_priv_beacon_srv_op[] = {
195195

196196
static int priv_beacon_srv_init(const struct bt_mesh_model *mod)
197197
{
198+
int err;
198199
const struct bt_mesh_model *config_srv =
199200
bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_CFG_SRV);
200201

@@ -206,7 +207,11 @@ static int priv_beacon_srv_init(const struct bt_mesh_model *mod)
206207
priv_beacon_srv = mod;
207208
mod->keys[0] = BT_MESH_KEY_DEV_LOCAL;
208209

209-
bt_mesh_model_extend(mod, config_srv);
210+
err = bt_mesh_model_extend(mod, config_srv);
211+
212+
if (err) {
213+
return err;
214+
}
210215

211216
return 0;
212217
}

0 commit comments

Comments
 (0)