Bluetooth: Mesh: Shell support for comp data page2
Adds shell support for composition data page 2 and 130 Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
This commit is contained in:
parent
0e966cceb2
commit
6b627771c8
3 changed files with 108 additions and 3 deletions
|
@ -2443,3 +2443,38 @@ struct bt_mesh_comp_p1_ext_item *bt_mesh_comp_p1_pull_ext_item(
|
|||
}
|
||||
return ext_item;
|
||||
}
|
||||
|
||||
struct bt_mesh_comp_p2_record *bt_mesh_comp_p2_record_pull(struct net_buf_simple *buf,
|
||||
struct bt_mesh_comp_p2_record *record)
|
||||
{
|
||||
if (buf->len < 8) {
|
||||
LOG_DBG("No more elements to pull or missing data");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t elem_offset_cnt;
|
||||
uint16_t data_len;
|
||||
|
||||
record->id = net_buf_simple_pull_le16(buf);
|
||||
record->version.x = net_buf_simple_pull_u8(buf);
|
||||
record->version.y = net_buf_simple_pull_u8(buf);
|
||||
record->version.z = net_buf_simple_pull_u8(buf);
|
||||
elem_offset_cnt = net_buf_simple_pull_u8(buf);
|
||||
if (buf->len < elem_offset_cnt + 2) {
|
||||
LOG_WRN("Invalid composition data offset count");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
net_buf_simple_init_with_data(record->elem_buf,
|
||||
net_buf_simple_pull_mem(buf, elem_offset_cnt),
|
||||
elem_offset_cnt);
|
||||
data_len = net_buf_simple_pull_le16(buf);
|
||||
if (buf->len < data_len) {
|
||||
LOG_WRN("Invalid composition data additional data length");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
net_buf_simple_init_with_data(record->data_buf,
|
||||
net_buf_simple_pull_mem(buf, data_len), data_len);
|
||||
return record;
|
||||
}
|
||||
|
|
|
@ -98,9 +98,10 @@ static int cmd_get_comp(const struct shell *sh, size_t argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (page != 0 && page != 1 && page != 128 && page != 129) {
|
||||
shell_print(sh, "Got page %d. No parser available.",
|
||||
page);
|
||||
if (page != 0 && page != 128 &&
|
||||
((page != 1 && page != 129) || !IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_1)) &&
|
||||
((page != 2 && page != 130) || !IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2))) {
|
||||
shell_print(sh, "Got page %d. No parser available.", page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -254,6 +255,41 @@ static int cmd_get_comp(const struct shell *sh, size_t argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_MESH_COMP_PAGE_2) && (page == 2 || page == 130)) {
|
||||
/* size of 32 is chosen arbitrary, as sufficient for testing purposes */
|
||||
NET_BUF_SIMPLE_DEFINE(p2_elem_offset_buf, 32);
|
||||
NET_BUF_SIMPLE_DEFINE(p2_data_buf, 32);
|
||||
struct bt_mesh_comp_p2_record p2_elem = {
|
||||
.elem_buf = &p2_elem_offset_buf,
|
||||
.data_buf = &p2_data_buf
|
||||
};
|
||||
|
||||
if (!buf.len) {
|
||||
shell_error(sh, "Composition data empty");
|
||||
return 0;
|
||||
}
|
||||
shell_print(sh, "Got Composition Data for 0x%04x, page: %d:",
|
||||
bt_mesh_shell_target_ctx.dst, page);
|
||||
|
||||
while (bt_mesh_comp_p2_record_pull(&buf, &p2_elem)) {
|
||||
|
||||
shell_print(sh, "\tMesh Profile id: %04x ", p2_elem.id);
|
||||
shell_print(sh, "\t\tVersion: %d.%d.%d ", p2_elem.version.x,
|
||||
p2_elem.version.y, p2_elem.version.z);
|
||||
shell_print(sh, "\t\tElement offsets:");
|
||||
|
||||
while (p2_elem.elem_buf->len) {
|
||||
shell_print(sh, "\t\t\t%d ",
|
||||
net_buf_simple_pull_u8(p2_elem.elem_buf));
|
||||
}
|
||||
|
||||
if (p2_elem.data_buf->len) {
|
||||
shell_print(sh, "\t\t%d bytes of additional data is available",
|
||||
p2_elem.data_buf->len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (buf.len) {
|
||||
shell_print(sh, "\t\t...truncated data!");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue