Skip to content

Commit 89cbb06

Browse files
Alfonso Acostaholtmann
authored andcommitted
Bluetooth: Defer connection-parameter removal when unpairing
Systematically removing the LE connection parameters and autoconnect action is inconvenient for rebonding without disconnecting from userland (i.e. unpairing followed by repairing without disconnecting). The parameters will be lost after unparing and userland needs to take care of book-keeping them and re-adding them. This patch allows userland to forget about parameter management when rebonding without disconnecting. It defers clearing the connection parameters when unparing without disconnecting, giving a chance of keeping the parameters if a repairing happens before the connection is closed. Signed-off-by: Alfonso Acosta <fons@spotify.com> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
1 parent c37a810 commit 89cbb06

3 files changed

Lines changed: 42 additions & 13 deletions

File tree

‎include/net/bluetooth/hci_core.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ enum {
555555
HCI_CONN_STK_ENCRYPT,
556556
HCI_CONN_AUTH_INITIATOR,
557557
HCI_CONN_DROP,
558+
HCI_CONN_PARAM_REMOVAL_PEND,
558559
};
559560

560561
static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)

‎net/bluetooth/hci_conn.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ int hci_conn_del(struct hci_conn *conn)
544544

545545
hci_conn_del_sysfs(conn);
546546

547+
if (test_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags))
548+
hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type);
549+
547550
hci_dev_put(hdev);
548551

549552
hci_conn_put(conn);

‎net/bluetooth/mgmt.c‎

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,19 +2725,47 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
27252725
}
27262726

27272727
if (cp->addr.type == BDADDR_BREDR) {
2728+
/* If disconnection is requested, then look up the
2729+
* connection. If the remote device is connected, it
2730+
* will be later used to terminate the link.
2731+
*
2732+
* Setting it to NULL explicitly will cause no
2733+
* termination of the link.
2734+
*/
2735+
if (cp->disconnect)
2736+
conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
2737+
&cp->addr.bdaddr);
2738+
else
2739+
conn = NULL;
2740+
27282741
err = hci_remove_link_key(hdev, &cp->addr.bdaddr);
27292742
} else {
27302743
u8 addr_type;
27312744

2745+
conn = hci_conn_hash_lookup_ba(hdev, LE_LINK,
2746+
&cp->addr.bdaddr);
2747+
if (conn) {
2748+
/* Defer clearing up the connection parameters
2749+
* until closing to give a chance of keeping
2750+
* them if a repairing happens.
2751+
*/
2752+
set_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags);
2753+
2754+
/* If disconnection is not requested, then
2755+
* clear the connection variable so that the
2756+
* link is not terminated.
2757+
*/
2758+
if (!cp->disconnect)
2759+
conn = NULL;
2760+
}
2761+
27322762
if (cp->addr.type == BDADDR_LE_PUBLIC)
27332763
addr_type = ADDR_LE_DEV_PUBLIC;
27342764
else
27352765
addr_type = ADDR_LE_DEV_RANDOM;
27362766

27372767
hci_remove_irk(hdev, &cp->addr.bdaddr, addr_type);
27382768

2739-
hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type);
2740-
27412769
err = hci_remove_ltk(hdev, &cp->addr.bdaddr, addr_type);
27422770
}
27432771

@@ -2747,17 +2775,9 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
27472775
goto unlock;
27482776
}
27492777

2750-
if (cp->disconnect) {
2751-
if (cp->addr.type == BDADDR_BREDR)
2752-
conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
2753-
&cp->addr.bdaddr);
2754-
else
2755-
conn = hci_conn_hash_lookup_ba(hdev, LE_LINK,
2756-
&cp->addr.bdaddr);
2757-
} else {
2758-
conn = NULL;
2759-
}
2760-
2778+
/* If the connection variable is set, then termination of the
2779+
* link is requested.
2780+
*/
27612781
if (!conn) {
27622782
err = cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0,
27632783
&rp, sizeof(rp));
@@ -3062,6 +3082,11 @@ static void pairing_complete(struct pending_cmd *cmd, u8 status)
30623082
hci_conn_put(conn);
30633083

30643084
mgmt_pending_remove(cmd);
3085+
3086+
/* The device is paired so there is no need to remove
3087+
* its connection parameters anymore.
3088+
*/
3089+
clear_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags);
30653090
}
30663091

30673092
void mgmt_smp_complete(struct hci_conn *conn, bool complete)

0 commit comments

Comments
 (0)