Skip to content

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

Merged

Conversation

trond-snekvik
Copy link
Collaborator

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

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)) {
Copy link
Member

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.

Copy link
Member

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)

Copy link
Collaborator Author

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.


shell_print(shell, "\tElement @ 0x%04x:", loc);
while (!bt_mesh_comp_elem_pull(&comp, &elem)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

}

elem->_buf =
(uint8_t *)net_buf_simple_pull_mem(page->_buf, modlist_size);
Copy link
Member

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

* @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);
Copy link
Collaborator

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?

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.
Copy link
Collaborator

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.

};

/** Composition data page 0 element representation */
struct bt_mesh_comp_elem {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

return 0;
}

int bt_mesh_comp_elem_pull(const struct bt_mesh_comp_page_0 *page,
Copy link
Collaborator

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]);
Copy link
Member

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?

Copy link
Collaborator Author

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;
Copy link
Member

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?

@trond-snekvik
Copy link
Collaborator Author

Marking with DNM until @pabigot's comments in #33476 are resolved

@trond-snekvik trond-snekvik added the DNM This PR should not be merged (Do Not Merge) label Mar 24, 2021
Comment on lines 2114 to 2117
if (idx >= elem->nsig) {
return 0xffff;
}
Copy link
Member

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.

Copy link
Collaborator Author

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]>
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]>
@pabigot
Copy link
Collaborator

pabigot commented Mar 28, 2021

This needs to be merged to complete the resolution of #31031.

@trond-snekvik trond-snekvik removed the DNM This PR should not be merged (Do Not Merge) label Mar 29, 2021
Comment on lines +2075 to +2077
if (buf->len < 10) {
return -EINVAL;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHECKIF() here as well?

Copy link
Collaborator Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Makes sense.

@jhedberg jhedberg merged commit d24810c into zephyrproject-rtos:master Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants