Skip to content

Commit 5157b8a

Browse files
Jakub Pawlowskiholtmann
authored andcommitted
Bluetooth: Fix initializing conn_params in scan phase
This patch makes sure that conn_params that were created just for explicit_connect, will get properly deleted during cleanup. Signed-off-by: Jakub Pawlowski <jpawlowski@google.com> Acked-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 9ad3e6f commit 5157b8a

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

net/bluetooth/hci_conn.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,15 +1008,23 @@ static int hci_explicit_conn_params_set(struct hci_request *req,
10081008
if (is_connected(hdev, addr, addr_type))
10091009
return -EISCONN;
10101010

1011-
params = hci_conn_params_add(hdev, addr, addr_type);
1012-
if (!params)
1013-
return -EIO;
1011+
params = hci_conn_params_lookup(hdev, addr, addr_type);
1012+
if (!params) {
1013+
params = hci_conn_params_add(hdev, addr, addr_type);
1014+
if (!params)
1015+
return -ENOMEM;
1016+
1017+
/* If we created new params, mark them to be deleted in
1018+
* hci_connect_le_scan_cleanup. It's different case than
1019+
* existing disabled params, those will stay after cleanup.
1020+
*/
1021+
params->auto_connect = HCI_AUTO_CONN_EXPLICIT;
1022+
}
10141023

1015-
/* If we created new params, or existing params were marked as disabled,
1016-
* mark them to be used just once to connect.
1017-
*/
1024+
/* We're trying to connect, so make sure params are at pend_le_conns */
10181025
if (params->auto_connect == HCI_AUTO_CONN_DISABLED ||
1019-
params->auto_connect == HCI_AUTO_CONN_REPORT) {
1026+
params->auto_connect == HCI_AUTO_CONN_REPORT ||
1027+
params->auto_connect == HCI_AUTO_CONN_EXPLICIT) {
10201028
list_del_init(&params->action);
10211029
list_add(&params->action, &hdev->pend_le_conns);
10221030
}

net/bluetooth/mgmt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3545,6 +3545,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
35453545
auth_type);
35463546
} else {
35473547
u8 addr_type;
3548+
struct hci_conn_params *p;
35483549

35493550
/* Convert from L2CAP channel address type to HCI address type
35503551
*/
@@ -3562,7 +3563,10 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
35623563
* If connection parameters already exist, then they
35633564
* will be kept and this function does nothing.
35643565
*/
3565-
hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type);
3566+
p = hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type);
3567+
3568+
if (p->auto_connect == HCI_AUTO_CONN_EXPLICIT)
3569+
p->auto_connect = HCI_AUTO_CONN_DISABLED;
35663570

35673571
conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr,
35683572
addr_type, sec_level,

0 commit comments

Comments
 (0)