diff --git a/subsys/bluetooth/mesh/access.c b/subsys/bluetooth/mesh/access.c index 24259165e05..2ea7ece90df 100644 --- a/subsys/bluetooth/mesh/access.c +++ b/subsys/bluetooth/mesh/access.c @@ -2562,3 +2562,30 @@ void bt_mesh_model_data_store_schedule(struct bt_mesh_model *mod) mod->flags |= BT_MESH_MOD_DATA_PENDING; bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_MOD_PENDING); } + +uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf) +{ + uint8_t page = net_buf_simple_pull_u8(buf); + + if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && + (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 130U; + } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && + (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 129U; + } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || + IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { + page = 128U; + } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { + page = 2U; + } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { + page = 1U; + } else if (page != 0U) { + LOG_DBG("Composition page %u not available", page); + page = 0U; + } + + return page; +} diff --git a/subsys/bluetooth/mesh/access.h b/subsys/bluetooth/mesh/access.h index 6027768ea94..f58c6f1d449 100644 --- a/subsys/bluetooth/mesh/access.h +++ b/subsys/bluetooth/mesh/access.h @@ -64,6 +64,7 @@ int bt_mesh_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf); int bt_mesh_comp_register(const struct bt_mesh_comp *comp); int bt_mesh_comp_store(void); int bt_mesh_comp_read(struct net_buf_simple *buf, uint8_t page); +uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf); int bt_mesh_models_metadata_store(void); int bt_mesh_models_metadata_read(struct net_buf_simple *buf, size_t offset); diff --git a/subsys/bluetooth/mesh/cfg_srv.c b/subsys/bluetooth/mesh/cfg_srv.c index eb732a34910..f65d2cba3c7 100644 --- a/subsys/bluetooth/mesh/cfg_srv.c +++ b/subsys/bluetooth/mesh/cfg_srv.c @@ -59,27 +59,7 @@ static int dev_comp_data_get(struct bt_mesh_model *model, LOG_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, bt_hex(buf->data, buf->len)); - page = net_buf_simple_pull_u8(buf); - - if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 130U; - } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 129U; - } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 128U; - } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { - page = 2U; - } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { - page = 1U; - } else if (page != 0U) { - LOG_DBG("Composition page %u not available", page); - page = 0U; - } + page = bt_mesh_comp_parse_page(buf); LOG_DBG("Preparing Composition data page %d", page); bt_mesh_model_msg_init(&sdu, OP_DEV_COMP_DATA_STATUS); diff --git a/subsys/bluetooth/mesh/large_comp_data_srv.c b/subsys/bluetooth/mesh/large_comp_data_srv.c index 12497d053a2..4ee591d9efd 100644 --- a/subsys/bluetooth/mesh/large_comp_data_srv.c +++ b/subsys/bluetooth/mesh/large_comp_data_srv.c @@ -53,32 +53,12 @@ static int handle_large_comp_data_get(struct bt_mesh_model *model, struct bt_mes ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, bt_hex(buf->data, buf->len)); - page = net_buf_simple_pull_u8(buf); + page = bt_mesh_comp_parse_page(buf); offset = net_buf_simple_pull_le16(buf); LOG_DBG("page %u offset %u", page, offset); bt_mesh_model_msg_init(&rsp, OP_LARGE_COMP_DATA_STATUS); - if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 130U; - } else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) && - (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 129U; - } else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) || - IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) { - page = 128U; - } else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) { - page = 2U; - } else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) { - page = 1U; - } else if (page != 0U) { - LOG_DBG("Composition page %u not available", page); - page = 0U; - } - net_buf_simple_add_u8(&rsp, page); net_buf_simple_add_le16(&rsp, offset);