Skip to content

Commit 65f029e

Browse files
Andrewpinijhedberg
authored andcommitted
Bluetooth: Mesh: Common comp page parse func
Create common composition page parser function. Signed-off-by: Anders Storrø <[email protected]>
1 parent 2e3ae01 commit 65f029e

File tree

4 files changed

+30
-42
lines changed

4 files changed

+30
-42
lines changed

subsys/bluetooth/mesh/access.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,3 +2562,30 @@ void bt_mesh_model_data_store_schedule(struct bt_mesh_model *mod)
25622562
mod->flags |= BT_MESH_MOD_DATA_PENDING;
25632563
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_MOD_PENDING);
25642564
}
2565+
2566+
uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf)
2567+
{
2568+
uint8_t page = net_buf_simple_pull_u8(buf);
2569+
2570+
if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) &&
2571+
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
2572+
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
2573+
page = 130U;
2574+
} else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) &&
2575+
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
2576+
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
2577+
page = 129U;
2578+
} else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
2579+
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
2580+
page = 128U;
2581+
} else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) {
2582+
page = 2U;
2583+
} else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) {
2584+
page = 1U;
2585+
} else if (page != 0U) {
2586+
LOG_DBG("Composition page %u not available", page);
2587+
page = 0U;
2588+
}
2589+
2590+
return page;
2591+
}

subsys/bluetooth/mesh/access.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ int bt_mesh_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
6464
int bt_mesh_comp_register(const struct bt_mesh_comp *comp);
6565
int bt_mesh_comp_store(void);
6666
int bt_mesh_comp_read(struct net_buf_simple *buf, uint8_t page);
67+
uint8_t bt_mesh_comp_parse_page(struct net_buf_simple *buf);
6768

6869
int bt_mesh_models_metadata_store(void);
6970
int bt_mesh_models_metadata_read(struct net_buf_simple *buf, size_t offset);

subsys/bluetooth/mesh/cfg_srv.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,7 @@ static int dev_comp_data_get(struct bt_mesh_model *model,
5959
LOG_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", ctx->net_idx, ctx->app_idx,
6060
ctx->addr, buf->len, bt_hex(buf->data, buf->len));
6161

62-
page = net_buf_simple_pull_u8(buf);
63-
64-
if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) &&
65-
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
66-
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
67-
page = 130U;
68-
} else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) &&
69-
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
70-
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
71-
page = 129U;
72-
} else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
73-
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
74-
page = 128U;
75-
} else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) {
76-
page = 2U;
77-
} else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) {
78-
page = 1U;
79-
} else if (page != 0U) {
80-
LOG_DBG("Composition page %u not available", page);
81-
page = 0U;
82-
}
62+
page = bt_mesh_comp_parse_page(buf);
8363
LOG_DBG("Preparing Composition data page %d", page);
8464

8565
bt_mesh_model_msg_init(&sdu, OP_DEV_COMP_DATA_STATUS);

subsys/bluetooth/mesh/large_comp_data_srv.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,12 @@ static int handle_large_comp_data_get(struct bt_mesh_model *model, struct bt_mes
5353
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
5454
bt_hex(buf->data, buf->len));
5555

56-
page = net_buf_simple_pull_u8(buf);
56+
page = bt_mesh_comp_parse_page(buf);
5757
offset = net_buf_simple_pull_le16(buf);
5858

5959
LOG_DBG("page %u offset %u", page, offset);
6060

6161
bt_mesh_model_msg_init(&rsp, OP_LARGE_COMP_DATA_STATUS);
62-
if (page >= 130U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) &&
63-
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
64-
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
65-
page = 130U;
66-
} else if (page >= 129U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1) &&
67-
(atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
68-
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
69-
page = 129U;
70-
} else if (page >= 128U && (atomic_test_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY) ||
71-
IS_ENABLED(CONFIG_BT_MESH_RPR_SRV))) {
72-
page = 128U;
73-
} else if (page >= 2U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2)) {
74-
page = 2U;
75-
} else if (page >= 1U && IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) {
76-
page = 1U;
77-
} else if (page != 0U) {
78-
LOG_DBG("Composition page %u not available", page);
79-
page = 0U;
80-
}
81-
8262
net_buf_simple_add_u8(&rsp, page);
8363
net_buf_simple_add_le16(&rsp, offset);
8464

0 commit comments

Comments
 (0)