Skip to content

Conversation

@cvinayak
Copy link
Contributor

@cvinayak cvinayak commented May 7, 2019

Fix the encryption setup queueing implementation to avoid
overlapping with local initiated Length Update Procedure.

Fixes #15733.
Relates to #15335, and #15186.

Signed-off-by: Vinayak Kariappa Chettimada vich@nordicsemi.no

Fix the encryption setup queueing implementation to avoid
overlapping with local initiated Length Update Procedure.

Fixes zephyrproject-rtos#15733.
Relates to zephyrproject-rtos#15335, and zephyrproject-rtos#15186.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
@cvinayak cvinayak added bug The issue is a bug, or the PR is fixing a bug area: Bluetooth backport v1.14-branch labels May 7, 2019
@mped-oticon mped-oticon self-requested a review May 7, 2019 10:40
#endif /* CONFIG_BT_CTLR_LE_ENC */
0) &&
/* Encryption setup queued or data paused */
(pause_tx || (conn->pkt_tx_head != conn->pkt_tx_ctrl)))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for comments, that helps a lot.
But it is not obvious if all the corner cases of this massive-if are properly handled.

For complex branching like this, I personally like to factor out the logical meaning across const booleans, and let the booleans derive from the previous ones. With those, I can name them and comment on them to attain more readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree this is complex (have been on my mind, and gave it almost a week before I pushed ;-) ). It is this way trying to short circuit as early as possible to reduce CPU usage. But I may be incorrect based on how the compiler/linker could optimize if the code was written in a more readable fashion.

Example, a connection with only empty) packets use less CPU in comparison to when data is in the queue. And during a active encryption procedure, the call to is_enc_req_pause_tx is completely bypassed by conn->pause_tx, etc.

I am open to alternative implementations that meet the constraints.

Copy link
Contributor

@mped-oticon mped-oticon left a comment

Choose a reason for hiding this comment

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

I can't really tell if this fixes anything though, because the code is still complex.
But I will not gate the change because of readability.

@mped-oticon mped-oticon requested a review from mtpr-ot May 7, 2019 10:54
@nashif nashif merged commit 019d282 into zephyrproject-rtos:master May 8, 2019
cvinayak added a commit to cvinayak/zephyr that referenced this pull request Jun 4, 2019
Port the fix for the controller implementation to make start
encryption queueable if there is any control procedure in
progress.

Refer to zephyrproject-rtos#15335.
Relates to zephyrproject-rtos#15335, zephyrproject-rtos#15186, zephyrproject-rtos#15958 and zephyrproject-rtos#14636.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
carlescufi pushed a commit that referenced this pull request Jun 6, 2019
Port the fix for the controller implementation to make start
encryption queueable if there is any control procedure in
progress.

Refer to #15335.
Relates to #15335, #15186, #15958 and #14636.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
@cvinayak cvinayak deleted the github_15733_fix branch March 1, 2021 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Bluetooth bug The issue is a bug, or the PR is fixing a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bluetooth: controller: Central Encryption setup overlaps Length Request procedure

3 participants