Skip to content

Commit d04e197

Browse files
joerchancarlescufi
authored andcommitted
Bluetooth: host: Improve multiple DHKey handling
Improve multiple DHKey handling by allowing the next DHKey calculation to be started in the dhkey ready callback. Return error code EALREADY if the provided callback is the current callback generating the DHKey. Signed-off-by: Joakim Andersson <[email protected]>
1 parent 07bb612 commit d04e197

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

subsys/bluetooth/host/hci_core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3860,8 +3860,10 @@ static void le_dhkey_complete(struct net_buf *buf)
38603860
BT_DBG("status: 0x%02x", evt->status);
38613861

38623862
if (dh_key_cb) {
3863-
dh_key_cb(evt->status ? NULL : evt->dhkey);
3863+
bt_dh_key_cb_t cb = dh_key_cb;
3864+
38643865
dh_key_cb = NULL;
3866+
cb(evt->status ? NULL : evt->dhkey);
38653867
}
38663868
}
38673869
#endif /* CONFIG_BT_ECC */
@@ -9326,6 +9328,10 @@ int bt_dh_key_gen(const uint8_t remote_pk[64], bt_dh_key_cb_t cb)
93269328
struct net_buf *buf;
93279329
int err;
93289330

9331+
if (dh_key_cb == cb) {
9332+
return -EALREADY;
9333+
}
9334+
93299335
if (dh_key_cb || atomic_test_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY)) {
93309336
return -EBUSY;
93319337
}

0 commit comments

Comments
 (0)