Skip to content

Commit 1a942de

Browse files
bgixVudentz
authored andcommitted
Bluetooth: Move hci_abort_conn to hci_conn.c
hci_abort_conn() is a wrapper around a number of DISCONNECT and CREATE_CONN_CANCEL commands that was being invoked from hci_request request queues, which are now deprecated. There are two versions: hci_abort_conn() which can be invoked from the hci_event thread, and hci_abort_conn_sync() which can be invoked within a hci_sync cmd chain. Signed-off-by: Brian Gix <brian.gix@intel.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 278d933 commit 1a942de

File tree

5 files changed

+91
-95
lines changed

5 files changed

+91
-95
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,7 @@ int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip);
20752075
void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle,
20762076
bdaddr_t *bdaddr, u8 addr_type);
20772077

2078+
int hci_abort_conn(struct hci_conn *conn, u8 reason);
20782079
u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency,
20792080
u16 to_multiplier);
20802081
void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,

net/bluetooth/hci_conn.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,3 +2760,79 @@ u32 hci_conn_get_phy(struct hci_conn *conn)
27602760

27612761
return phys;
27622762
}
2763+
2764+
int hci_abort_conn(struct hci_conn *conn, u8 reason)
2765+
{
2766+
int r = 0;
2767+
2768+
switch (conn->state) {
2769+
case BT_CONNECTED:
2770+
case BT_CONFIG:
2771+
if (conn->type == AMP_LINK) {
2772+
struct hci_cp_disconn_phy_link cp;
2773+
2774+
cp.phy_handle = HCI_PHY_HANDLE(conn->handle);
2775+
cp.reason = reason;
2776+
r = hci_send_cmd(conn->hdev, HCI_OP_DISCONN_PHY_LINK,
2777+
sizeof(cp), &cp);
2778+
} else {
2779+
struct hci_cp_disconnect dc;
2780+
2781+
dc.handle = cpu_to_le16(conn->handle);
2782+
dc.reason = reason;
2783+
r = hci_send_cmd(conn->hdev, HCI_OP_DISCONNECT,
2784+
sizeof(dc), &dc);
2785+
}
2786+
2787+
conn->state = BT_DISCONN;
2788+
2789+
break;
2790+
case BT_CONNECT:
2791+
if (conn->type == LE_LINK) {
2792+
if (test_bit(HCI_CONN_SCANNING, &conn->flags))
2793+
break;
2794+
r = hci_send_cmd(conn->hdev,
2795+
HCI_OP_LE_CREATE_CONN_CANCEL, 0, NULL);
2796+
} else if (conn->type == ACL_LINK) {
2797+
if (conn->hdev->hci_ver < BLUETOOTH_VER_1_2)
2798+
break;
2799+
r = hci_send_cmd(conn->hdev,
2800+
HCI_OP_CREATE_CONN_CANCEL,
2801+
6, &conn->dst);
2802+
}
2803+
break;
2804+
case BT_CONNECT2:
2805+
if (conn->type == ACL_LINK) {
2806+
struct hci_cp_reject_conn_req rej;
2807+
2808+
bacpy(&rej.bdaddr, &conn->dst);
2809+
rej.reason = reason;
2810+
2811+
r = hci_send_cmd(conn->hdev,
2812+
HCI_OP_REJECT_CONN_REQ,
2813+
sizeof(rej), &rej);
2814+
} else if (conn->type == SCO_LINK || conn->type == ESCO_LINK) {
2815+
struct hci_cp_reject_sync_conn_req rej;
2816+
2817+
bacpy(&rej.bdaddr, &conn->dst);
2818+
2819+
/* SCO rejection has its own limited set of
2820+
* allowed error values (0x0D-0x0F) which isn't
2821+
* compatible with most values passed to this
2822+
* function. To be safe hard-code one of the
2823+
* values that's suitable for SCO.
2824+
*/
2825+
rej.reason = HCI_ERROR_REJ_LIMITED_RESOURCES;
2826+
2827+
r = hci_send_cmd(conn->hdev,
2828+
HCI_OP_REJECT_SYNC_CONN_REQ,
2829+
sizeof(rej), &rej);
2830+
}
2831+
break;
2832+
default:
2833+
conn->state = BT_CLOSED;
2834+
break;
2835+
}
2836+
2837+
return r;
2838+
}

net/bluetooth/hci_request.c

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -909,99 +909,6 @@ static void set_random_addr(struct hci_request *req, bdaddr_t *rpa)
909909
hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6, rpa);
910910
}
911911

912-
static void __hci_abort_conn(struct hci_request *req, struct hci_conn *conn,
913-
u8 reason)
914-
{
915-
switch (conn->state) {
916-
case BT_CONNECTED:
917-
case BT_CONFIG:
918-
if (conn->type == AMP_LINK) {
919-
struct hci_cp_disconn_phy_link cp;
920-
921-
cp.phy_handle = HCI_PHY_HANDLE(conn->handle);
922-
cp.reason = reason;
923-
hci_req_add(req, HCI_OP_DISCONN_PHY_LINK, sizeof(cp),
924-
&cp);
925-
} else {
926-
struct hci_cp_disconnect dc;
927-
928-
dc.handle = cpu_to_le16(conn->handle);
929-
dc.reason = reason;
930-
hci_req_add(req, HCI_OP_DISCONNECT, sizeof(dc), &dc);
931-
}
932-
933-
conn->state = BT_DISCONN;
934-
935-
break;
936-
case BT_CONNECT:
937-
if (conn->type == LE_LINK) {
938-
if (test_bit(HCI_CONN_SCANNING, &conn->flags))
939-
break;
940-
hci_req_add(req, HCI_OP_LE_CREATE_CONN_CANCEL,
941-
0, NULL);
942-
} else if (conn->type == ACL_LINK) {
943-
if (req->hdev->hci_ver < BLUETOOTH_VER_1_2)
944-
break;
945-
hci_req_add(req, HCI_OP_CREATE_CONN_CANCEL,
946-
6, &conn->dst);
947-
}
948-
break;
949-
case BT_CONNECT2:
950-
if (conn->type == ACL_LINK) {
951-
struct hci_cp_reject_conn_req rej;
952-
953-
bacpy(&rej.bdaddr, &conn->dst);
954-
rej.reason = reason;
955-
956-
hci_req_add(req, HCI_OP_REJECT_CONN_REQ,
957-
sizeof(rej), &rej);
958-
} else if (conn->type == SCO_LINK || conn->type == ESCO_LINK) {
959-
struct hci_cp_reject_sync_conn_req rej;
960-
961-
bacpy(&rej.bdaddr, &conn->dst);
962-
963-
/* SCO rejection has its own limited set of
964-
* allowed error values (0x0D-0x0F) which isn't
965-
* compatible with most values passed to this
966-
* function. To be safe hard-code one of the
967-
* values that's suitable for SCO.
968-
*/
969-
rej.reason = HCI_ERROR_REJ_LIMITED_RESOURCES;
970-
971-
hci_req_add(req, HCI_OP_REJECT_SYNC_CONN_REQ,
972-
sizeof(rej), &rej);
973-
}
974-
break;
975-
default:
976-
conn->state = BT_CLOSED;
977-
break;
978-
}
979-
}
980-
981-
static void abort_conn_complete(struct hci_dev *hdev, u8 status, u16 opcode)
982-
{
983-
if (status)
984-
bt_dev_dbg(hdev, "Failed to abort connection: status 0x%2.2x", status);
985-
}
986-
987-
int hci_abort_conn(struct hci_conn *conn, u8 reason)
988-
{
989-
struct hci_request req;
990-
int err;
991-
992-
hci_req_init(&req, conn->hdev);
993-
994-
__hci_abort_conn(&req, conn, reason);
995-
996-
err = hci_req_run(&req, abort_conn_complete);
997-
if (err && err != -ENODATA) {
998-
bt_dev_err(conn->hdev, "failed to run HCI request: err %d", err);
999-
return err;
1000-
}
1001-
1002-
return 0;
1003-
}
1004-
1005912
void hci_request_setup(struct hci_dev *hdev)
1006913
{
1007914
INIT_DELAYED_WORK(&hdev->interleave_scan, interleave_scan_work);

net/bluetooth/hci_request.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,5 @@ void hci_req_add_le_passive_scan(struct hci_request *req);
7373

7474
void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next);
7575

76-
int hci_abort_conn(struct hci_conn *conn, u8 reason);
7776
void hci_request_setup(struct hci_dev *hdev);
7877
void hci_request_cancel_all(struct hci_dev *hdev);

net/bluetooth/mgmt.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,18 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
31853185
return err;
31863186
}
31873187

3188+
static int abort_conn_sync(struct hci_dev *hdev, void *data)
3189+
{
3190+
struct hci_conn *conn;
3191+
u16 handle = PTR_ERR(data);
3192+
3193+
conn = hci_conn_hash_lookup_handle(hdev, handle);
3194+
if (!conn)
3195+
return 0;
3196+
3197+
return hci_abort_conn_sync(hdev, conn, HCI_ERROR_REMOTE_USER_TERM);
3198+
}
3199+
31883200
static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
31893201
u16 len)
31903202
{
@@ -3235,7 +3247,8 @@ static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
32353247
le_addr_type(addr->type));
32363248

32373249
if (conn->conn_reason == CONN_REASON_PAIR_DEVICE)
3238-
hci_abort_conn(conn, HCI_ERROR_REMOTE_USER_TERM);
3250+
hci_cmd_sync_queue(hdev, abort_conn_sync, ERR_PTR(conn->handle),
3251+
NULL);
32393252

32403253
unlock:
32413254
hci_dev_unlock(hdev);

0 commit comments

Comments
 (0)