Skip to content

Commit 2f2eb0c

Browse files
bgixholtmann
authored andcommitted
Bluetooth: hci_sync: Convert MGMT_OP_SET_SECURE_CONN
Synchronous version of MGMT_OP_SET_SECURE_CONN. Signed-off-by: Brian Gix <brian.gix@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 47db6b4 commit 2f2eb0c

File tree

3 files changed

+49
-36
lines changed

3 files changed

+49
-36
lines changed

include/net/bluetooth/hci_sync.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ int hci_update_passive_scan_sync(struct hci_dev *hdev);
6969
int hci_update_passive_scan(struct hci_dev *hdev);
7070
int hci_read_rssi_sync(struct hci_dev *hdev, __le16 handle);
7171
int hci_read_tx_power_sync(struct hci_dev *hdev, __le16 handle, u8 type);
72+
int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val);
7273

7374
int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable);
7475
int hci_update_scan_sync(struct hci_dev *hdev);

net/bluetooth/hci_sync.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,13 +2104,27 @@ int hci_update_passive_scan(struct hci_dev *hdev)
21042104
return hci_cmd_sync_queue(hdev, update_passive_scan_sync, NULL, NULL);
21052105
}
21062106

2107-
static int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val)
2107+
int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val)
21082108
{
2109+
int err;
2110+
21092111
if (!bredr_sc_enabled(hdev) || lmp_host_sc_capable(hdev))
21102112
return 0;
21112113

2112-
return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT,
2114+
err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT,
21132115
sizeof(val), &val, HCI_CMD_TIMEOUT);
2116+
2117+
if (!err) {
2118+
if (val) {
2119+
hdev->features[1][0] |= LMP_HOST_SC;
2120+
hci_dev_set_flag(hdev, HCI_SC_ENABLED);
2121+
} else {
2122+
hdev->features[1][0] &= ~LMP_HOST_SC;
2123+
hci_dev_clear_flag(hdev, HCI_SC_ENABLED);
2124+
}
2125+
}
2126+
2127+
return err;
21142128
}
21152129

21162130
static int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode)

net/bluetooth/mgmt.c

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6094,23 +6094,18 @@ static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
60946094
return err;
60956095
}
60966096

6097-
static void sc_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode)
6097+
static void set_secure_conn_complete(struct hci_dev *hdev, void *data, int err)
60986098
{
6099-
struct mgmt_pending_cmd *cmd;
6099+
struct mgmt_pending_cmd *cmd = data;
61006100
struct mgmt_mode *cp;
61016101

6102-
bt_dev_dbg(hdev, "status %u", status);
6103-
6104-
hci_dev_lock(hdev);
6102+
bt_dev_dbg(hdev, "err %d", err);
61056103

6106-
cmd = pending_find(MGMT_OP_SET_SECURE_CONN, hdev);
6107-
if (!cmd)
6108-
goto unlock;
6104+
if (err) {
6105+
u8 mgmt_err = mgmt_status(err);
61096106

6110-
if (status) {
6111-
mgmt_cmd_status(cmd->sk, cmd->index, cmd->opcode,
6112-
mgmt_status(status));
6113-
goto remove;
6107+
mgmt_cmd_status(cmd->sk, cmd->index, cmd->opcode, mgmt_err);
6108+
goto done;
61146109
}
61156110

61166111
cp = cmd->param;
@@ -6130,21 +6125,30 @@ static void sc_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode)
61306125
break;
61316126
}
61326127

6133-
send_settings_rsp(cmd->sk, MGMT_OP_SET_SECURE_CONN, hdev);
6128+
send_settings_rsp(cmd->sk, cmd->opcode, hdev);
61346129
new_settings(hdev, cmd->sk);
61356130

6136-
remove:
6137-
mgmt_pending_remove(cmd);
6138-
unlock:
6139-
hci_dev_unlock(hdev);
6131+
done:
6132+
mgmt_pending_free(cmd);
6133+
}
6134+
6135+
static int set_secure_conn_sync(struct hci_dev *hdev, void *data)
6136+
{
6137+
struct mgmt_pending_cmd *cmd = data;
6138+
struct mgmt_mode *cp = cmd->param;
6139+
u8 val = !!cp->val;
6140+
6141+
/* Force write of val */
6142+
hci_dev_set_flag(hdev, HCI_SC_ENABLED);
6143+
6144+
return hci_write_sc_support_sync(hdev, val);
61406145
}
61416146

61426147
static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
61436148
void *data, u16 len)
61446149
{
61456150
struct mgmt_mode *cp = data;
61466151
struct mgmt_pending_cmd *cmd;
6147-
struct hci_request req;
61486152
u8 val;
61496153
int err;
61506154

@@ -6163,7 +6167,7 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
61636167

61646168
if (cp->val != 0x00 && cp->val != 0x01 && cp->val != 0x02)
61656169
return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN,
6166-
MGMT_STATUS_INVALID_PARAMS);
6170+
MGMT_STATUS_INVALID_PARAMS);
61676171

61686172
hci_dev_lock(hdev);
61696173

@@ -6194,12 +6198,6 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
61946198
goto failed;
61956199
}
61966200

6197-
if (pending_find(MGMT_OP_SET_SECURE_CONN, hdev)) {
6198-
err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN,
6199-
MGMT_STATUS_BUSY);
6200-
goto failed;
6201-
}
6202-
62036201
val = !!cp->val;
62046202

62056203
if (val == hci_dev_test_flag(hdev, HCI_SC_ENABLED) &&
@@ -6208,18 +6206,18 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
62086206
goto failed;
62096207
}
62106208

6211-
cmd = mgmt_pending_add(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len);
6212-
if (!cmd) {
6209+
cmd = mgmt_pending_new(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len);
6210+
if (!cmd)
62136211
err = -ENOMEM;
6214-
goto failed;
6215-
}
6212+
else
6213+
err = hci_cmd_sync_queue(hdev, set_secure_conn_sync, cmd,
6214+
set_secure_conn_complete);
62166215

6217-
hci_req_init(&req, hdev);
6218-
hci_req_add(&req, HCI_OP_WRITE_SC_SUPPORT, 1, &val);
6219-
err = hci_req_run(&req, sc_enable_complete);
62206216
if (err < 0) {
6221-
mgmt_pending_remove(cmd);
6222-
goto failed;
6217+
mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN,
6218+
MGMT_STATUS_FAILED);
6219+
if (cmd)
6220+
mgmt_pending_free(cmd);
62236221
}
62246222

62256223
failed:

0 commit comments

Comments
 (0)