-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Bluetooth: Refactor connection type checks across host stack #98040
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
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.
Pull Request Overview
This PR refactors connection type checks throughout the Bluetooth host stack by replacing direct conn->type comparisons with the bt_conn_is_type() macro. The changes maintain identical functionality while improving code consistency and maintainability across all Bluetooth subsystems.
Key changes:
- Replaces direct
conn->type == BT_CONN_TYPE_*comparisons withbt_conn_is_type(conn, BT_CONN_TYPE_*)macro calls - Moves the
bt_conn_is_type()function definition earlier in conn.c (from line 2950 to line 217) to support its use throughout the file - Updates connection type checks across connection management, L2CAP, SMP, and HCI core modules
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| subsys/bluetooth/host/conn.c | Moves bt_conn_is_type() definition and refactors type checks in connection management, security operations, and lookup functions |
| subsys/bluetooth/host/conn_internal.h | Updates ISO connection handle validation to use the macro |
| subsys/bluetooth/host/hci_core.c | Refactors type checks in HCI event handlers for disconnection, encryption, and security operations |
| subsys/bluetooth/host/l2cap.c | Updates L2CAP layer type checks for BR/EDR and LE connection differentiation |
| subsys/bluetooth/host/smp.c | Refactors SMP security manager type checks for LE and BR/EDR connections |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
bcc3df8 to
6b26eb5
Compare
Introduce dedicated helper functions for connection type checking: - bt_conn_is_br() for BR/EDR connections - bt_conn_is_le() for LE connections - bt_conn_is_iso() for ISO connections - bt_conn_is_sco() for SCO connections Replace direct conn->type comparisons with these new helper functions throughout the connection management code. This improves code readability, maintainability, and provides proper configuration checks for each connection type. Signed-off-by: Kai Cheng <[email protected]>
| @@ -2677,7 +2661,7 @@ int bt_conn_set_security(struct bt_conn *conn, bt_security_t sec) | |||
|
|
|||
| bt_security_t bt_conn_get_security(const struct bt_conn *conn) | |||
| { | |||
| if (!bt_conn_is_type(conn, BT_CONN_TYPE_LE | BT_CONN_TYPE_BR)) { | |||
| if (!bt_conn_is_le(conn) && !bt_conn_is_br(conn)) { | |||
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.
if (!is_acl_conn(conn))
| @@ -2637,7 +2621,7 @@ int bt_conn_set_security(struct bt_conn *conn, bt_security_t sec) | |||
| bool force_pair; | |||
| int err; | |||
|
|
|||
| if (!bt_conn_is_type(conn, BT_CONN_TYPE_LE | BT_CONN_TYPE_BR)) { | |||
| if (!bt_conn_is_le(conn) && !bt_conn_is_br(conn)) { | |||
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.
if (!is_acl_conn(conn))
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.
Generally looks good to me.
|



Bluetooth: Add connection type helper functions and refactor type checks
Summary
This PR introduces dedicated helper functions for connection type checking and refactors the entire Bluetooth host stack to use these new functions instead of direct
conn->typecomparisons. This improves code consistency, readability, and maintainability.Changes
New Helper Functions: Added four inline helper functions for connection type checking:
bt_conn_is_br()- Check for BR/EDR connectionsbt_conn_is_le()- Check for LE connectionsbt_conn_is_iso()- Check for ISO connectionsbt_conn_is_sco()- Check for SCO connectionsComprehensive Refactoring: Updated connection type checks throughout the Bluetooth host stack:
conn.c)conn_internal.h)Technical Details
IS_ENABLED()macrosCONFIG_BT_CLASSIC=n), functions returnfalseat compile timeIS_ENABLED()checks scattered throughout the codeBenefits
Impact
Testing
This refactoring establishes a clean, consistent pattern for connection type verification that will make future Bluetooth feature development more straightforward and less error-prone.