-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Bluetooth: Host: Add advertising state to bt_le_ext_adv_info #90185
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 advertising state to bt_le_ext_adv_info #90185
Conversation
There will be a use of these new fields in #85642:
|
Did also consider to also add the options as field to the info, but I don't have a use case for it at this moment |
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.
Pull Request Overview
Adds tracking and reporting of extended and periodic advertising states to Bluetooth LE advertising info and shell output, with input validation to prevent NULL dereferences.
- Extend
bt_le_ext_adv_info
withext_adv_state
andper_adv_state
enums - Validate arguments and populate new state fields in
bt_le_ext_adv_get_info
- Print the new states in the shell command
cmd_adv_info
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
subsys/bluetooth/host/shell/bt.c | Print extended/periodic advertising states in shell output |
subsys/bluetooth/host/adv.c | Validate inputs and set advertising/periodic state in info struct |
include/zephyr/bluetooth/bluetooth.h | Add enums for advertising states and update struct documentation |
Comments suppressed due to low confidence (1)
subsys/bluetooth/host/shell/bt.c:2573
- [nitpick] Rename the label 'Per Adv state' to 'Periodic Adv state' to more clearly reflect its meaning.
shell_print(sh, "Per Adv state: %d", info.per_adv_state);
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.
Pull Request Overview
This PR extends the advertising information structure to include extended and periodic advertising states, and improves input validation to prevent NULL pointer accesses.
- Adds printing of advertising and periodic advertising states in the shell command output.
- Introduces new pointer validations and state assignments in bt_le_ext_adv_get_info.
- Updates header file with new state enums and refined documentation.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
subsys/bluetooth/host/shell/bt.c | Prints new extended and periodic advertising state information. |
subsys/bluetooth/host/adv.c | Adds NULL checks, state assignments, and initializes info struct. |
include/zephyr/bluetooth/bluetooth.h | Introduces new advertising state enums and updates documentation. |
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.
Pull Request Overview
Adds explicit tracking and display of extended and periodic advertising states in the Bluetooth LE advertising APIs and shell.
- Extend
bt_le_ext_adv_info
withext_adv_state
andper_adv_state
enums. - Add input validation and state population in
bt_le_ext_adv_get_info
. - Update shell command to print the new advertising state fields.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
subsys/bluetooth/host/shell/bt.c | Print extended and periodic advertising states and conditionally show address only when advertising is started. |
subsys/bluetooth/host/adv.c | Validate adv and info pointers, memset info, and set up new state fields based on flags. |
include/zephyr/bluetooth/bluetooth.h | Define enums for extended and periodic advertising states; update struct and function return documentation. |
Comments suppressed due to low confidence (1)
subsys/bluetooth/host/shell/bt.c:2573
- [nitpick] The abbreviation "Per Adv state" may not be immediately clear; consider using "Periodic Adv state" for consistency and clarity.
shell_print(sh, "Per Adv state: %d", info.per_adv_state);
include/zephyr/bluetooth/bluetooth.h
Outdated
/** No state */ | ||
BT_LE_EXT_ADV_STATE_NONE, |
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.
Is this "no state" as in an invalid value?
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 actually unused, so perhaps the starting value of the enum should be BT_LE_EXT_ADV_STATE_CREATED
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.
Continuing my question from #90185 (comment)
Now there is only two values, 0 or 1, please use a boolean instead.
include/zephyr/bluetooth/bluetooth.h
Outdated
/** The advertising set is temporarily paused */ | ||
BT_LE_EXT_ADV_STATE_PAUSED, |
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 the paused state may be a confusing addition to the API. How is the paused state any different to the started state in the eyes of the API user?
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, struggled with this one as well.
In the PAUSED state, we are updating the RPA, which means that printing or copying the address in this state, may not be the same address in 200 milliseconds from now.
But it all depends on whether privacy is enabled and the options used for the advertising set, so I agree that it's pretty vaguely defined, but that's because the actual state, and what it represents, is pretty complex to describe.
I'm OK with removing it and treating the PAUSED state as the ENABLED state, as that is what it is in the eyes of caller
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'm OK with removing it and treating the PAUSED state as the ENABLED state, as that is what it is in the eyes of caller
I'm for that. The paused state is supposed to be very temporary. It will be easier for application developers if they don't have to care. It's basically a workaround for HCI and just an internal detail in the "Host and Controller in one"-box.
include/zephyr/bluetooth/bluetooth.h
Outdated
/** The advertising set has been created but not started */ | ||
BT_LE_EXT_ADV_STATE_CREATED, |
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 advertiser will go into this state after the user stops it, right? I think "stopped" may be a better name for this state rather than "created". What do you think?
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.
Tangent thoughts: I realize that our APIs are "start" and "stop", so we should probably be consistent with that. But especially now that we do not re-enable the advertiser automatically after it creates a connection, we could use "enable" and "disable" terminology like the spec and other resources use.
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.
Sure, that makes sense. Could rename these _ENABLED and _DISABLED
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.
To be clear: I did not mean to demand "enabled". I'm on the fence about myself, since as I said, we also need to be consistent with our API, which is "start" and "stop".
So, "stopped" is also a viable alternative. Which do you prefer?
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.
Prefer ENABLED and DISABLED. STOPPED sounds like more like it has actively been stopped, which isn't always the case.
include/zephyr/bluetooth/bluetooth.h
Outdated
/** No state */ | ||
BT_LE_PER_ADV_STATE_NONE, |
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.
This "no state" seems different to BT_LE_EXT_ADV_STATE_NONE
, since looks to be a valid state? I don't know our periodic advertiser implementation, so I'm not sure. Do you 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.
Correct.
An advertising set can go from being just extended advertising (BT_LE_PER_ADV_STATE_NONE), to be configured for periodic advertising BT_LE_PER_ADV_STATE_CONFIGURED
and finally have periodic advertising enabled, which is a state that isn't tied to the extended advertising state.
8a394cb
to
250a4dd
Compare
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.
Pull Request Overview
Adds explicit advertising and periodic advertising state reporting to the extended advertising API, hardens input validation, and surfaces the new states in the shell.
- Extend
bt_le_ext_adv_info
withext_adv_state
andper_adv_state
enums and fields - Harden
bt_le_ext_adv_get_info()
with null checks, creation checks, and populate new state fields - Update the shell’s
cmd_adv_info
to show the new state fields and improve the error message
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
subsys/bluetooth/host/shell/bt.c | Print extended and periodic advertising states; refine error text |
subsys/bluetooth/host/adv.c | Add NULL/creation checks; set ext_adv_state and per_adv_state fields |
include/zephyr/bluetooth/bluetooth.h | Define new enums and struct fields; expand Doxygen return/value docs |
Comments suppressed due to low confidence (1)
subsys/bluetooth/host/adv.c:1614
- Add unit tests covering the new state assignments in
bt_le_ext_adv_get_info
, including NULL inputs, not-created cases, enabled/disabled, and periodic states.
if (atomic_test_bit(adv->flags, BT_ADV_ENABLED)) {
enum bt_le_ext_adv_state { | ||
/** The advertising set has been created but not enabled. */ | ||
BT_LE_EXT_ADV_STATE_DISABLED, | ||
|
||
/** The advertising set is enabled. */ | ||
BT_LE_EXT_ADV_STATE_ENABLED, | ||
}; |
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.
Why no BT_LE_EXT_ADV_STATE_NONE
?
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.
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 you are asking why there is a none state in one but not the other enum.
The none state in the periodic advertiser case means that no configuration has been set for periodic advertising for this set. We could remove the need for the none state in both of the enums if the Host sets a default configuration for periodic advertising. But this is extra code in the Host, so we should weight up the benefits.
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.
An enabled
boolean member in the info
structure instead is better for application to check.
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 enum is far more extendable if we ever want to add back a state like PAUSED if that becomes a necessity, and it's also more consistent with the per_adv_state which cannot be a boolean
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.
Agreed. No action required from my side.
/** Periodic advertising state. */ | ||
enum bt_le_per_adv_state per_adv_state; |
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 this be guarded by the periodic advertising feature support? according to implementation later in this PR, the referencing to conditionally guarded to always return BT_LE_PER_ADV_STATE_NONE
, instead this member is not required and application code shall fail to compile when periodic advertising is not supported.
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 did consider this, and was also discussed when I added something similar w.r.t. ISO in #86092, but it was, IIRC, decided that a small increase in the struct for something that is short-lived, would be OK.
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.
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.
Ok, as the info struct in typical use is a auto variable, this is acceptable.
enum bt_le_ext_adv_state { | ||
/** The advertising set has been created but not enabled. */ | ||
BT_LE_EXT_ADV_STATE_DISABLED, | ||
|
||
/** The advertising set is enabled. */ | ||
BT_LE_EXT_ADV_STATE_ENABLED, | ||
}; |
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.
An enabled
boolean member in the info
structure instead is better for application to check.
/** Periodic advertising state. */ | ||
enum bt_le_per_adv_state per_adv_state; |
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.
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.
Ok, as the info struct in typical use is a auto variable, this is acceptable.
The bt_le_ext_adv_info struct has been extended to also contain the advertising and periodic advertising states. Additionally, the function verifies the input to avoid NULL pointer access, and the addr field is more properly documented. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
|
The bt_le_ext_adv_info struct has been extended to also contain the advertising and periodic advertising states.
Additionally, the function verifies the input to avoid NULL pointer access, and more importantly does not return 0 with
addr
set to a valid that is notused for advertising.