Skip to content

Commit f892244

Browse files
bgixholtmann
authored andcommitted
Bluetooth: hci_sync: Convert MGMT_OP_READ_LOCAL_OOB_DATA
New functions: hci_read_local_oob_data_sync This function requires all of the data from the cmd cmplt event to be passed up to the caller via the skb. mgmt-tester paths: Read Local OOB Data - Not powered Read Local OOB Data - Legacy pairing Read Local OOB Data - Success SSP Read Local OOB Data - Success SC Signed-off-by: Brian Gix <brian.gix@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent d81a494 commit f892244

File tree

4 files changed

+58
-26
lines changed

4 files changed

+58
-26
lines changed

include/net/bluetooth/hci_sync.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ int hci_update_scan_sync(struct hci_dev *hdev);
7878
int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul);
7979
int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance,
8080
struct sock *sk);
81+
struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev, bool ext,
82+
struct sock *sk);
8183

8284
int hci_dev_open_sync(struct hci_dev *hdev);
8385
int hci_dev_close_sync(struct hci_dev *hdev);

net/bluetooth/hci_sync.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,15 @@ static int hci_resume_advertising_sync(struct hci_dev *hdev)
17031703
return err;
17041704
}
17051705

1706+
struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev,
1707+
bool extended, struct sock *sk)
1708+
{
1709+
u16 opcode = extended ? HCI_OP_READ_LOCAL_OOB_EXT_DATA :
1710+
HCI_OP_READ_LOCAL_OOB_DATA;
1711+
1712+
return __hci_cmd_sync_sk(hdev, opcode, 0, NULL, 0, HCI_CMD_TIMEOUT, sk);
1713+
}
1714+
17061715
/* Device must not be scanning when updating the accept list.
17071716
*
17081717
* Update is done using the following sequence:

net/bluetooth/mgmt.c

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4793,28 +4793,33 @@ static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev,
47934793
status);
47944794
}
47954795

4796-
static void read_local_oob_data_complete(struct hci_dev *hdev, u8 status,
4797-
u16 opcode, struct sk_buff *skb)
4796+
static void read_local_oob_data_complete(struct hci_dev *hdev, void *data, int err)
47984797
{
47994798
struct mgmt_rp_read_local_oob_data mgmt_rp;
48004799
size_t rp_size = sizeof(mgmt_rp);
4801-
struct mgmt_pending_cmd *cmd;
4800+
struct mgmt_pending_cmd *cmd = data;
4801+
struct sk_buff *skb = cmd->skb;
4802+
u8 status = mgmt_status(err);
48024803

4803-
bt_dev_dbg(hdev, "status %u", status);
4804+
if (!status) {
4805+
if (!skb)
4806+
status = MGMT_STATUS_FAILED;
4807+
else if (IS_ERR(skb))
4808+
status = mgmt_status(PTR_ERR(skb));
4809+
else
4810+
status = mgmt_status(skb->data[0]);
4811+
}
48044812

4805-
cmd = pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev);
4806-
if (!cmd)
4807-
return;
4813+
bt_dev_dbg(hdev, "status %d", status);
48084814

4809-
if (status || !skb) {
4810-
mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA,
4811-
status ? mgmt_status(status) : MGMT_STATUS_FAILED);
4815+
if (status) {
4816+
mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, status);
48124817
goto remove;
48134818
}
48144819

48154820
memset(&mgmt_rp, 0, sizeof(mgmt_rp));
48164821

4817-
if (opcode == HCI_OP_READ_LOCAL_OOB_DATA) {
4822+
if (!bredr_sc_enabled(hdev)) {
48184823
struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
48194824

48204825
if (skb->len < sizeof(*rp)) {
@@ -4849,14 +4854,31 @@ static void read_local_oob_data_complete(struct hci_dev *hdev, u8 status,
48494854
MGMT_STATUS_SUCCESS, &mgmt_rp, rp_size);
48504855

48514856
remove:
4852-
mgmt_pending_remove(cmd);
4857+
if (skb && !IS_ERR(skb))
4858+
kfree_skb(skb);
4859+
4860+
mgmt_pending_free(cmd);
4861+
}
4862+
4863+
static int read_local_oob_data_sync(struct hci_dev *hdev, void *data)
4864+
{
4865+
struct mgmt_pending_cmd *cmd = data;
4866+
4867+
if (bredr_sc_enabled(hdev))
4868+
cmd->skb = hci_read_local_oob_data_sync(hdev, true, cmd->sk);
4869+
else
4870+
cmd->skb = hci_read_local_oob_data_sync(hdev, false, cmd->sk);
4871+
4872+
if (IS_ERR(cmd->skb))
4873+
return PTR_ERR(cmd->skb);
4874+
else
4875+
return 0;
48534876
}
48544877

48554878
static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev,
48564879
void *data, u16 data_len)
48574880
{
48584881
struct mgmt_pending_cmd *cmd;
4859-
struct hci_request req;
48604882
int err;
48614883

48624884
bt_dev_dbg(hdev, "sock %p", sk);
@@ -4881,22 +4903,20 @@ static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev,
48814903
goto unlock;
48824904
}
48834905

4884-
cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_DATA, hdev, NULL, 0);
4885-
if (!cmd) {
4906+
cmd = mgmt_pending_new(sk, MGMT_OP_READ_LOCAL_OOB_DATA, hdev, NULL, 0);
4907+
if (!cmd)
48864908
err = -ENOMEM;
4887-
goto unlock;
4888-
}
4889-
4890-
hci_req_init(&req, hdev);
4891-
4892-
if (bredr_sc_enabled(hdev))
4893-
hci_req_add(&req, HCI_OP_READ_LOCAL_OOB_EXT_DATA, 0, NULL);
48944909
else
4895-
hci_req_add(&req, HCI_OP_READ_LOCAL_OOB_DATA, 0, NULL);
4910+
err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd,
4911+
read_local_oob_data_complete);
48964912

4897-
err = hci_req_run_skb(&req, read_local_oob_data_complete);
4898-
if (err < 0)
4899-
mgmt_pending_remove(cmd);
4913+
if (err < 0) {
4914+
err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA,
4915+
MGMT_STATUS_FAILED);
4916+
4917+
if (cmd)
4918+
mgmt_pending_free(cmd);
4919+
}
49004920

49014921
unlock:
49024922
hci_dev_unlock(hdev);

net/bluetooth/mgmt_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct mgmt_pending_cmd {
2727
void *param;
2828
size_t param_len;
2929
struct sock *sk;
30+
struct sk_buff *skb;
3031
void *user_data;
3132
int (*cmd_complete)(struct mgmt_pending_cmd *cmd, u8 status);
3233
};

0 commit comments

Comments
 (0)