Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: Mesh: Move dfu mbt models into their own elements #81531

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions subsys/bluetooth/mesh/dfd_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions subsys/bluetooth/mesh/dfu_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

const struct bt_mesh_model *blob_cli =
bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_BLOB_CLI);

if (mod->rt->elem_idx != 0) {
LOG_ERR("DFU update client must be instantiated on first elem");
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);
Expand Down
15 changes: 13 additions & 2 deletions subsys/bluetooth/mesh/dfu_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion subsys/bluetooth/mesh/priv_beacon_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/bluetooth/tester/overlay-mesh.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CONFIG_BT_MESH_HEALTH_CLI=y
CONFIG_BT_MESH_FRIEND=y
CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=32
CONFIG_BT_MESH_RX_SEG_MAX=13
CONFIG_BT_MESH_TX_SEG_MAX=7
CONFIG_BT_MESH_TX_SEG_MAX=8
CONFIG_BT_MESH_TX_SEG_MSG_COUNT=3
CONFIG_BT_MESH_LPN_POLL_TIMEOUT=100
CONFIG_BT_MESH_PROVISIONER=y
Expand Down
67 changes: 42 additions & 25 deletions tests/bluetooth/tester/src/btp_mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ static void oob_store_handler(struct k_work *work)
#endif /* CONFIG_BT_MESH_DFD_SRV_OOB_UPLOAD */
#endif

#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV)
#if defined(CONFIG_BT_MESH_BLOB_CLI)
static struct {
struct bt_mesh_blob_cli_inputs inputs;
struct bt_mesh_blob_target targets[32];
Expand Down Expand Up @@ -1023,7 +1023,7 @@ static uint8_t proxy_solicit(const void *cmd, uint16_t cmd_len,
static struct bt_mesh_brg_cfg_cli brg_cfg_cli;
#endif /* CONFIG_BT_MESH_BRG_CFG_CLI */

static const struct bt_mesh_model root_models[] = {
static const struct bt_mesh_model primary_models[] = {
BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub, health_srv_meta),
Expand Down Expand Up @@ -1052,15 +1052,6 @@ static const struct bt_mesh_model root_models[] = {
#if defined(CONFIG_BT_MESH_RPR_SRV)
BT_MESH_MODEL_RPR_SRV,
#endif
#if defined(CONFIG_BT_MESH_DFD_SRV)
BT_MESH_MODEL_DFD_SRV(&dfd_srv),
#endif
#if defined(CONFIG_BT_MESH_DFU_SRV)
BT_MESH_MODEL_DFU_SRV(&dfu_srv),
#endif
#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV)
BT_MESH_MODEL_BLOB_CLI(&blob_cli),
#endif
#if defined(CONFIG_BT_MESH_PRIV_BEACON_SRV)
BT_MESH_MODEL_PRIV_BEACON_SRV,
#endif
Expand All @@ -1085,7 +1076,23 @@ static const struct bt_mesh_model root_models[] = {

};

static const struct bt_mesh_model root_models_alt[] = {
#if defined(CONFIG_BT_MESH_DFD_SRV)
static const struct bt_mesh_model dfu_distributor_models[] = {BT_MESH_MODEL_DFD_SRV(&dfd_srv)};
#endif

#if defined(CONFIG_BT_MESH_DFU_SRV)
static const struct bt_mesh_model dfu_target_models[] = {
BT_MESH_MODEL_DFU_SRV(&dfu_srv),
};
#endif

#if defined(CONFIG_BT_MESH_BLOB_CLI)
static const struct bt_mesh_model blob_client_models[] = {
BT_MESH_MODEL_BLOB_CLI(&blob_cli),
};
#endif

static const struct bt_mesh_model primary_models_alt[] = {
BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub, health_srv_meta_alt),
Expand Down Expand Up @@ -1114,15 +1121,6 @@ static const struct bt_mesh_model root_models_alt[] = {
#if defined(CONFIG_BT_MESH_RPR_SRV)
BT_MESH_MODEL_RPR_SRV,
#endif
#if defined(CONFIG_BT_MESH_DFD_SRV)
alxelax marked this conversation as resolved.
Show resolved Hide resolved
BT_MESH_MODEL_DFD_SRV(&dfd_srv),
#endif
#if defined(CONFIG_BT_MESH_DFU_SRV)
BT_MESH_MODEL_DFU_SRV(&dfu_srv),
#endif
#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV)
BT_MESH_MODEL_BLOB_CLI(&blob_cli),
#endif
#if defined(CONFIG_BT_MESH_PRIV_BEACON_SRV)
BT_MESH_MODEL_PRIV_BEACON_SRV,
#endif
Expand All @@ -1146,6 +1144,7 @@ static const struct bt_mesh_model root_models_alt[] = {
#endif

};

struct model_data *lookup_model_bound(uint16_t id)
{
int i;
Expand All @@ -1164,11 +1163,29 @@ static const struct bt_mesh_model vnd_models[] = {
};

static const struct bt_mesh_elem elements[] = {
BT_MESH_ELEM(0, root_models, vnd_models),
BT_MESH_ELEM(0, primary_models, vnd_models),
#if defined(CONFIG_BT_MESH_DFD_SRV)
BT_MESH_ELEM(0, dfu_distributor_models, BT_MESH_MODEL_NONE),
#endif
#if defined(CONFIG_BT_MESH_DFU_SRV)
BT_MESH_ELEM(0, dfu_target_models, BT_MESH_MODEL_NONE),
#endif
#if defined(CONFIG_BT_MESH_BLOB_CLI)
BT_MESH_ELEM(0, blob_client_models, BT_MESH_MODEL_NONE),
#endif
};

static const struct bt_mesh_elem elements_alt[] = {
BT_MESH_ELEM(0, root_models_alt, vnd_models),
BT_MESH_ELEM(0, primary_models_alt, vnd_models),
#if defined(CONFIG_BT_MESH_DFD_SRV)
BT_MESH_ELEM(0, dfu_distributor_models, BT_MESH_MODEL_NONE),
#endif
#if defined(CONFIG_BT_MESH_DFU_SRV)
BT_MESH_ELEM(0, dfu_target_models, BT_MESH_MODEL_NONE),
#endif
#if defined(CONFIG_BT_MESH_BLOB_CLI)
BT_MESH_ELEM(0, blob_client_models, BT_MESH_MODEL_NONE),
#endif
};

static void link_open(bt_mesh_prov_bearer_t bearer)
Expand Down Expand Up @@ -4492,7 +4509,7 @@ static uint8_t dfu_firmware_update_apply(const void *cmd, uint16_t cmd_len,
}
#endif

#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV)
#if defined(CONFIG_BT_MESH_BLOB_CLI)
static void blob_cli_inputs_prepare(uint16_t group, uint16_t app_idx)
{
int i;
Expand Down Expand Up @@ -5315,7 +5332,7 @@ static const struct btp_handler mdl_handlers[] = {
.func = dfu_firmware_update_apply,
},
#endif
#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV)
#if defined(CONFIG_BT_MESH_BLOB_CLI)
{
.opcode = BTP_MMDL_BLOB_INFO_GET,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
Expand Down
Loading