-
Notifications
You must be signed in to change notification settings - Fork 7k
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: Host: Add support for getting controller values in public API #86092
base: main
Are you sure you want to change the base?
Bluetooth: Host: Add support for getting controller values in public API #86092
Conversation
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 pretty good
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.
Sounds like a good idea to expose such info!
Added some suggestions and questions
|
||
* Host | ||
|
||
* :c:func:`bt_le_get_local_features` |
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 know it is possible to click on the link, but it would still be nice to add a short description of what it does :)
* :c:func:`bt_le_get_local_features` | |
* :c:func:`bt_le_get_local_features` returns the feature set supported by the Bluetooth Controller. |
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.
Normally I'd do that too, but the text right above says:
Link to new APIs here, in a group if you think it's necessary, no need to get
fancy just list the link, that should contain the documentation. If you feel
like you need to add more details, add them in the API documentation code
instead.
I read that as we should only provide links here and then the documentation of the added function should provide the rest
include/zephyr/bluetooth/bluetooth.h
Outdated
* | ||
* The value of 8 correspond to page 0 in the LE Controller supported features | ||
*/ | ||
#define BT_LE_LOCAL_SUPPOTRED_FEATURES_SIZE 8 |
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.
#define BT_LE_LOCAL_SUPPOTRED_FEATURES_SIZE 8 | |
#define BT_LE_LOCAL_SUPPORTED_FEATURES_SIZE 8 |
include/zephyr/bluetooth/bluetooth.h
Outdated
@@ -48,6 +49,13 @@ extern "C" { | |||
*/ | |||
#define BT_ID_DEFAULT 0 | |||
|
|||
/** | |||
* @brief Number of octets for local supporte |
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.
* @brief Number of octets for local supporte | |
* @brief Number of octets for local supported |
include/zephyr/bluetooth/bluetooth.h
Outdated
* | ||
* The value of 8 correspond to page 0 in the LE Controller supported features | ||
*/ | ||
#define BT_LE_LOCAL_SUPPOTRED_FEATURES_SIZE 8 |
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.
Do we need this define in the first place or can we hardcode it in the definition of struct bt_le_local_features
. If we hardcode it there, we reduce the amount of documentation needed.
We could consider adding ifdefs in the struct definition to remove entries which are not needed.
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.
Yeah I didn't write that in the commit message.
The reason why I've added it here, is that today the Zephyr only supports page 0, but there are actually more than 1 page now.
Once we add support for reading all pages, then it would be trivial to simply increase this from e.g. 8 to 16.
If that doesn't really make sense, let me know :)
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.
Hmm, perhaps it should be an internal Kconfig option instead?
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 was wondering if we need an entry at all: uint8_t features[8];
. A Kconfig option is probably not needed
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 just really dislike magic numbers in the public API like 8
would be :D (and especially when it should fit the same size of a different struct's field)
Could add a define for PAGE_SIZE in hci_types.h
, but that doesn't solve anything either.
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 see that it is also used inside hci_core.h, so it is probably a good idea to keep it as is
include/zephyr/bluetooth/bluetooth.h
Outdated
* | ||
* Refer to BT_LE_FEAT_BIT_* for values. | ||
* Refer to the BT_FEAT_LE_* macros for value comparionson. | ||
* See Bluetooth Core Specification 6.0, Vol 6, Part B, Section 4.6 table 4.10 |
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 believe we can leave out Core revision and Table number here. Older and newer revisions will have it in the same place:
* See Bluetooth Core Specification 6.0, Vol 6, Part B, Section 4.6 table 4.10 | |
* See Bluetooth Core Specification, Vol 6, Part B, Section 4.6. |
I have no strong preference on this.
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.
You are probably correct. Looks like when sections are removed they are still kept and marked as "This section is no longer used", so perhaps we can consider section numbers static across versions.
include/zephyr/bluetooth/bluetooth.h
Outdated
/** Total number of ISO data packets */ | ||
uint8_t iso_pkts; | ||
|
||
/** Size of the controller resolving list */ |
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.
The actual size can be smaller depending on controller implementation
/** Size of the controller resolving list */ | |
/** Maximum size of the controller resolving list. | |
* | |
* See Bluetooth Core Specification, Vol 6, Part E, Section 7.8.41. | |
*/ |
include/zephyr/bluetooth/bluetooth.h
Outdated
/** Number of entries in the resolving list. | ||
* | ||
* @ref bt_le_local_features.rl_entries > @ref bt_le_local_features.rl_size means that | ||
* host-side resolving is used. | ||
*/ | ||
uint8_t rl_entries; |
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.
rl_entries
is representing state of the Bluetooth stack and is not static. Suggest to leave it out.
include/zephyr/bluetooth/bluetooth.h
Outdated
/** Maximum advertising data length */ | ||
uint16_t max_adv_data_len; |
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.
/** Maximum advertising data length */ | |
uint16_t max_adv_data_len; | |
/** Maximum advertising data length | |
* | |
* @note The maximum advertising data length also depends on advertising | |
* type. | |
* See Bluetooth Core Specification, Vol 6, Part E, Section 7.8.57. | |
*/ | |
uint16_t max_adv_data_len; |
@@ -517,6 +525,60 @@ size_t bt_data_get_len(const struct bt_data data[], size_t data_count); | |||
*/ | |||
size_t bt_data_serialize(const struct bt_data *input, uint8_t *output); | |||
|
|||
struct bt_le_local_features { |
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.
Do we want to add Filter accept list size to this struct?
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 think that would make sense, but the Zephyr host isn't reading that at the moment, so that would be a new feature
@@ -517,6 +525,60 @@ size_t bt_data_get_len(const struct bt_data data[], size_t data_count); | |||
*/ | |||
size_t bt_data_serialize(const struct bt_data *input, uint8_t *output); | |||
|
|||
struct bt_le_local_features { |
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 assume we want to extend this struct whenever the spec defines a new feature set. Eventually this struct can become very large. Is this something we want to do?
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.
It's a good question. Similar to the other info
structs, it's only stack allocated so it wouldn't be taking up much memory, but might run into stack overflows in some cases I guess.
An alternative would be to do similar to what I did for ISO where the internal state uses the public state to store information: https://github.com/zephyrproject-rtos/zephyr/blob/main/subsys/bluetooth/host/conn_internal.h#L182-L183
Today we are still doing an allocation + copy, but we could in theory return a const
pointer directly to that struct, which would effectively require no additional memory.
e965ad3
to
cb40744
Compare
cb40744
to
38500c6
Compare
The function supports reading multiple controller-based values. It is effectively a copy of struct bt_dev_le but in a more application-oriented definition. It was chosen to keep the features as an array rather than a 64-bit value, as the comparison macros work on arrays and that there already exists new bits > 64 in the core spec which is not yet supported by Zephyr. It is being smoke tested in a generic GATT client test, as the individual values may depend on several Kconfig options. Signed-off-by: Emil Gydesen <[email protected]>
The connection object is, and should not, be modified by the function. Making it const makes it possible to do this simple operation in functions that also won't change the conn object (i.e. that uses `const`). Signed-off-by: Emil Gydesen <[email protected]>
Use the recently added bt_le_get_local_features function as well as bt_conn_get_remote_info to avoid using internal APIs to check for PAST supported. Signed-off-by: Emil Gydesen <[email protected]>
38500c6
to
987b6f4
Compare
Adds a new API to get LE controller info.
Adds a test and a use of the new API
fixes #81872