summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2015-04-02 06:41:13 -0400
committerMarcel Holtmann <marcel@holtmann.org>2015-04-02 10:09:29 -0400
commit1b9441f8ec426223f6f54f2af10ee01c8b743e5b (patch)
treeba49ce98295f26b3ca08ebfcdfd5e314b85b0da4
parent757aa0b56da5d1089c55bf349fa15836dae22b6f (diff)
Bluetooth: Convert local OOB data reading to use HCI request
Now that there's a HCI request API available where the callback receives the resulting skb, we can convert the local OOB data reading to use this new API. This patch does the necessary update in mgmt.c (which also requires moving the callback higher up since it's now a static function) and removes the custom calls from hci_event.c that are no-longer necessary. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--include/net/bluetooth/hci_core.h3
-rw-r--r--net/bluetooth/hci_event.c11
-rw-r--r--net/bluetooth/mgmt.c105
3 files changed, 65 insertions, 54 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 12686e8e9343..93fd3e756b8a 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1391,9 +1391,6 @@ void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
1391void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, 1391void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
1392 u8 status); 1392 u8 status);
1393void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); 1393void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
1394void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192,
1395 u8 *rand192, u8 *hash256, u8 *rand256,
1396 u8 status);
1397void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1394void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1398 u8 addr_type, u8 *dev_class, s8 rssi, u32 flags, 1395 u8 addr_type, u8 *dev_class, s8 rssi, u32 flags,
1399 u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len); 1396 u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index c2483cb6ffbd..01031038eb0e 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1045,11 +1045,6 @@ static void hci_cc_read_local_oob_data(struct hci_dev *hdev,
1045 struct hci_rp_read_local_oob_data *rp = (void *) skb->data; 1045 struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
1046 1046
1047 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); 1047 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1048
1049 hci_dev_lock(hdev);
1050 mgmt_read_local_oob_data_complete(hdev, rp->hash, rp->rand, NULL, NULL,
1051 rp->status);
1052 hci_dev_unlock(hdev);
1053} 1048}
1054 1049
1055static void hci_cc_read_local_oob_ext_data(struct hci_dev *hdev, 1050static void hci_cc_read_local_oob_ext_data(struct hci_dev *hdev,
@@ -1058,12 +1053,6 @@ static void hci_cc_read_local_oob_ext_data(struct hci_dev *hdev,
1058 struct hci_rp_read_local_oob_ext_data *rp = (void *) skb->data; 1053 struct hci_rp_read_local_oob_ext_data *rp = (void *) skb->data;
1059 1054
1060 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); 1055 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1061
1062 hci_dev_lock(hdev);
1063 mgmt_read_local_oob_data_complete(hdev, rp->hash192, rp->rand192,
1064 rp->hash256, rp->rand256,
1065 rp->status);
1066 hci_dev_unlock(hdev);
1067} 1056}
1068 1057
1069static void hci_cc_le_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb) 1058static void hci_cc_le_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 3048092b1264..bb0c53ac4c66 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3783,10 +3783,70 @@ failed:
3783 return err; 3783 return err;
3784} 3784}
3785 3785
3786static void read_local_oob_data_complete(struct hci_dev *hdev, u8 status,
3787 u16 opcode, struct sk_buff *skb)
3788{
3789 struct mgmt_rp_read_local_oob_data mgmt_rp;
3790 size_t rp_size = sizeof(mgmt_rp);
3791 struct mgmt_pending_cmd *cmd;
3792
3793 BT_DBG("%s status %u", hdev->name, status);
3794
3795 cmd = pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev);
3796 if (!cmd)
3797 return;
3798
3799 if (status || !skb) {
3800 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA,
3801 status ? mgmt_status(status) : MGMT_STATUS_FAILED);
3802 goto remove;
3803 }
3804
3805 memset(&mgmt_rp, 0, sizeof(mgmt_rp));
3806
3807 if (opcode == HCI_OP_READ_LOCAL_OOB_DATA) {
3808 struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
3809
3810 if (skb->len < sizeof(*rp)) {
3811 mgmt_cmd_status(cmd->sk, hdev->id,
3812 MGMT_OP_READ_LOCAL_OOB_DATA,
3813 MGMT_STATUS_FAILED);
3814 goto remove;
3815 }
3816
3817 memcpy(mgmt_rp.hash192, rp->hash, sizeof(rp->hash));
3818 memcpy(mgmt_rp.rand192, rp->rand, sizeof(rp->rand));
3819
3820 rp_size -= sizeof(mgmt_rp.hash256) + sizeof(mgmt_rp.rand256);
3821 } else {
3822 struct hci_rp_read_local_oob_ext_data *rp = (void *) skb->data;
3823
3824 if (skb->len < sizeof(*rp)) {
3825 mgmt_cmd_status(cmd->sk, hdev->id,
3826 MGMT_OP_READ_LOCAL_OOB_DATA,
3827 MGMT_STATUS_FAILED);
3828 goto remove;
3829 }
3830
3831 memcpy(mgmt_rp.hash192, rp->hash192, sizeof(rp->hash192));
3832 memcpy(mgmt_rp.rand192, rp->rand192, sizeof(rp->rand192));
3833
3834 memcpy(mgmt_rp.hash256, rp->hash256, sizeof(rp->hash256));
3835 memcpy(mgmt_rp.rand256, rp->rand256, sizeof(rp->rand256));
3836 }
3837
3838 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA,
3839 MGMT_STATUS_SUCCESS, &mgmt_rp, rp_size);
3840
3841remove:
3842 mgmt_pending_remove(cmd);
3843}
3844
3786static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev, 3845static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev,
3787 void *data, u16 data_len) 3846 void *data, u16 data_len)
3788{ 3847{
3789 struct mgmt_pending_cmd *cmd; 3848 struct mgmt_pending_cmd *cmd;
3849 struct hci_request req;
3790 int err; 3850 int err;
3791 3851
3792 BT_DBG("%s", hdev->name); 3852 BT_DBG("%s", hdev->name);
@@ -3817,12 +3877,14 @@ static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev,
3817 goto unlock; 3877 goto unlock;
3818 } 3878 }
3819 3879
3880 hci_req_init(&req, hdev);
3881
3820 if (bredr_sc_enabled(hdev)) 3882 if (bredr_sc_enabled(hdev))
3821 err = hci_send_cmd(hdev, HCI_OP_READ_LOCAL_OOB_EXT_DATA, 3883 hci_req_add(&req, HCI_OP_READ_LOCAL_OOB_EXT_DATA, 0, NULL);
3822 0, NULL);
3823 else 3884 else
3824 err = hci_send_cmd(hdev, HCI_OP_READ_LOCAL_OOB_DATA, 0, NULL); 3885 hci_req_add(&req, HCI_OP_READ_LOCAL_OOB_DATA, 0, NULL);
3825 3886
3887 err = hci_req_run_skb(&req, read_local_oob_data_complete);
3826 if (err < 0) 3888 if (err < 0)
3827 mgmt_pending_remove(cmd); 3889 mgmt_pending_remove(cmd);
3828 3890
@@ -7920,43 +7982,6 @@ void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status)
7920 cmd ? cmd->sk : NULL); 7982 cmd ? cmd->sk : NULL);
7921} 7983}
7922 7984
7923void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192,
7924 u8 *rand192, u8 *hash256, u8 *rand256,
7925 u8 status)
7926{
7927 struct mgmt_pending_cmd *cmd;
7928
7929 BT_DBG("%s status %u", hdev->name, status);
7930
7931 cmd = pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev);
7932 if (!cmd)
7933 return;
7934
7935 if (status) {
7936 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA,
7937 mgmt_status(status));
7938 } else {
7939 struct mgmt_rp_read_local_oob_data rp;
7940 size_t rp_size = sizeof(rp);
7941
7942 memcpy(rp.hash192, hash192, sizeof(rp.hash192));
7943 memcpy(rp.rand192, rand192, sizeof(rp.rand192));
7944
7945 if (bredr_sc_enabled(hdev) && hash256 && rand256) {
7946 memcpy(rp.hash256, hash256, sizeof(rp.hash256));
7947 memcpy(rp.rand256, rand256, sizeof(rp.rand256));
7948 } else {
7949 rp_size -= sizeof(rp.hash256) + sizeof(rp.rand256);
7950 }
7951
7952 mgmt_cmd_complete(cmd->sk, hdev->id,
7953 MGMT_OP_READ_LOCAL_OOB_DATA, 0,
7954 &rp, rp_size);
7955 }
7956
7957 mgmt_pending_remove(cmd);
7958}
7959
7960static inline bool has_uuid(u8 *uuid, u16 uuid_count, u8 (*uuids)[16]) 7985static inline bool has_uuid(u8 *uuid, u16 uuid_count, u8 (*uuids)[16])
7961{ 7986{
7962 int i; 7987 int i;