-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Bluetooth: Mesh: Composition data page 0 traversal #33614
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: Composition data page 0 traversal #33614
Conversation
The first byte of the composition data status message is the returned page index, not the status of the request. This is now reflected in the API. Signed-off-by: Trond Einar Snekvik <[email protected]>
return; | ||
} | ||
|
||
elem_addr = node->addr; | ||
while (!bt_mesh_comp_elem_pull(&comp, &elem)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
== 0
would be clearer to not make the reader think the function returns bool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, rethink the return value type (bool, enum, give back the elem pointer, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now returning a pointer, to avoid returning bool to indicate errors.
subsys/bluetooth/mesh/shell.c
Outdated
|
||
shell_print(shell, "\tElement @ 0x%04x:", loc); | ||
while (!bt_mesh_comp_elem_pull(&comp, &elem)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
subsys/bluetooth/mesh/cfg_cli.c
Outdated
} | ||
|
||
elem->_buf = | ||
(uint8_t *)net_buf_simple_pull_mem(page->_buf, modlist_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like an unnecessary type cast
include/bluetooth/mesh/cfg_cli.h
Outdated
* @return The model ID of the vendor model at the given index. | ||
*/ | ||
struct bt_mesh_mod_id_vnd | ||
bt_mesh_comp_elem_mod_vnd(struct bt_mesh_comp_elem *elem, int idx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont' have to break this line perhaps?
include/bluetooth/mesh/cfg_cli.h
Outdated
int bt_mesh_comp_page_0_get(struct bt_mesh_comp_page_0 *comp, | ||
struct net_buf_simple *buf); | ||
|
||
/** @brief Pull an element from a composition data page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from a composition data page 0?
More instances in this function API description.
If I'm following this right.
include/bluetooth/mesh/cfg_cli.h
Outdated
}; | ||
|
||
/** Composition data page 0 element representation */ | ||
struct bt_mesh_comp_elem { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would bt_mesh_comp_page_0_elem
be more clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, yes. I renamed both the composition data page and the elem to use a bt_mesh_comp_p0
prefix.
subsys/bluetooth/mesh/cfg_cli.c
Outdated
return 0; | ||
} | ||
|
||
int bt_mesh_comp_elem_pull(const struct bt_mesh_comp_page_0 *page, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly, would bt_mesh_comp_page_0_elem_pull
be more clear?
|
||
uint16_t bt_mesh_comp_elem_mod(struct bt_mesh_comp_elem *elem, int idx) | ||
{ | ||
return sys_get_le16(&elem->_buf[idx * 2]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you check elem->nsig first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a bounds check, but there's no room for an error code in the return types of these functions, so I have made them return 0xffff
. This can also be a valid return value though, so I think it's the lesser of two evils. I'd prefer not to change the return type, as this would mess up the vnd function.
struct bt_mesh_mod_id_vnd | ||
bt_mesh_comp_elem_mod_vnd(struct bt_mesh_comp_elem *elem, int idx) | ||
{ | ||
size_t offset = elem->nsig * 2 + idx * 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, since this is a public API we might want to do a bounds check first?
7204124
to
593b668
Compare
subsys/bluetooth/mesh/cfg_cli.c
Outdated
if (idx >= elem->nsig) { | ||
return 0xffff; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to take into use CHECKIF()
from include/sys/check.h
? I've seen that used in many Bluetooth audio related patches. It seems the general trend is to move toward that for all input parameter checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware of this. Makes sense, I'll change it.
Adds a parsing mechanism for Composition data page 0 in the Config Client API, and uses it in the shell module to parse the incoming composition data. Signed-off-by: Trond Einar Snekvik <[email protected]>
Instead of only configuring the Health Server model of the provisioned device, the Provisioner will instead walk the target's composition data, and bind each model to the same AppKey. This allows the provisioner to be used with the base mesh sample, and demonstrates the new composition data page 0 API. Signed-off-by: Trond Einar Snekvik <[email protected]>
Runs the Provisioner sample's main thread in a cooperative priority to avoid calling the Bluetooth APIs from a preemptive thread. Signed-off-by: Trond Einar Snekvik <[email protected]>
Adds blocking operation to the self configuration step by waiting for the status response. This ensures that the provisioner is fully configured, and reduces the number of loopback buffers required for the self-configuring. Signed-off-by: Trond Einar Snekvik <[email protected]>
fc66ea5
to
d2a70bd
Compare
Ups the CDB_NODE_COUNT config to fit 16 nodes, to make the sample more usable for general mesh testing. Signed-off-by: Trond Einar Snekvik <[email protected]>
This needs to be merged to complete the resolution of #31031. |
if (buf->len < 10) { | ||
return -EINVAL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHECKIF()
here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left it out on purpose, as it's doing a comparison on on-air data. With CHECKIF
, it can turn into an assert or be skipped, which would force the application to do their own check. This would sort of negate the intended effect of this macro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Makes sense.
Adds a parsing mechanism for Composition data page 0 in the Config
Client API, and uses it in the shell module to parse the incoming
composition data.
Demonstrates this API in the mesh_provisioner sample, allowing it to provision the basic mesh sample, as suggested by @pabigot in #33476.
cc @tsvehagen