| /* |
| BlueZ - Bluetooth protocol stack for Linux |
| Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved. |
| Copyright 2023 NXP |
| |
| Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License version 2 as |
| published by the Free Software Foundation; |
| |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. |
| IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY |
| CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES |
| WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| |
| ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
| SOFTWARE IS DISCLAIMED. |
| */ |
| |
| /* Bluetooth HCI event handling. */ |
| |
| #include <asm/unaligned.h> |
| |
| #include <net/bluetooth/bluetooth.h> |
| #include <net/bluetooth/hci_core.h> |
| #include <net/bluetooth/mgmt.h> |
| |
| #include "hci_request.h" |
| #include "hci_debugfs.h" |
| #include "a2mp.h" |
| #include "amp.h" |
| #include "smp.h" |
| #include "msft.h" |
| #include "eir.h" |
| |
| #define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \ |
| "\x00\x00\x00\x00\x00\x00\x00\x00" |
| |
| #define secs_to_jiffies(_secs) msecs_to_jiffies((_secs) * 1000) |
| |
| /* Handle HCI Event packets */ |
| |
| static void *hci_ev_skb_pull(struct hci_dev *hdev, struct sk_buff *skb, |
| u8 ev, size_t len) |
| { |
| void *data; |
| |
| data = skb_pull_data(skb, len); |
| if (!data) |
| bt_dev_err(hdev, "Malformed Event: 0x%2.2x", ev); |
| |
| return data; |
| } |
| |
| static void *hci_cc_skb_pull(struct hci_dev *hdev, struct sk_buff *skb, |
| u16 op, size_t len) |
| { |
| void *data; |
| |
| data = skb_pull_data(skb, len); |
| if (!data) |
| bt_dev_err(hdev, "Malformed Command Complete: 0x%4.4x", op); |
| |
| return data; |
| } |
| |
| static void *hci_le_ev_skb_pull(struct hci_dev *hdev, struct sk_buff *skb, |
| u8 ev, size_t len) |
| { |
| void *data; |
| |
| data = skb_pull_data(skb, len); |
| if (!data) |
| bt_dev_err(hdev, "Malformed LE Event: 0x%2.2x", ev); |
| |
| return data; |
| } |
| |
| static u8 hci_cc_inquiry_cancel(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| /* It is possible that we receive Inquiry Complete event right |
| * before we receive Inquiry Cancel Command Complete event, in |
| * which case the latter event should have status of Command |
| * Disallowed (0x0c). This should not be treated as error, since |
| * we actually achieve what Inquiry Cancel wants to achieve, |
| * which is to end the last Inquiry session. |
| */ |
| if (rp->status == 0x0c && !test_bit(HCI_INQUIRY, &hdev->flags)) { |
| bt_dev_warn(hdev, "Ignoring error of Inquiry Cancel command"); |
| rp->status = 0x00; |
| } |
| |
| if (rp->status) |
| return rp->status; |
| |
| clear_bit(HCI_INQUIRY, &hdev->flags); |
| smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */ |
| wake_up_bit(&hdev->flags, HCI_INQUIRY); |
| |
| hci_dev_lock(hdev); |
| /* Set discovery state to stopped if we're not doing LE active |
| * scanning. |
| */ |
| if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| hdev->le_scan_type != LE_SCAN_ACTIVE) |
| hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| hci_dev_unlock(hdev); |
| |
| hci_conn_check_pending(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_periodic_inq(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hci_dev_set_flag(hdev, HCI_PERIODIC_INQ); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_exit_periodic_inq(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); |
| |
| hci_conn_check_pending(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_remote_name_req_cancel(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_role_discovery(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_role_discovery *rp = data; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| if (conn) |
| conn->role = rp->role; |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_link_policy(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_link_policy *rp = data; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| if (conn) |
| conn->link_policy = __le16_to_cpu(rp->policy); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_link_policy(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_write_link_policy *rp = data; |
| struct hci_conn *conn; |
| void *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| if (conn) |
| conn->link_policy = get_unaligned_le16(sent + 2); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_def_link_policy(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_def_link_policy *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->link_policy = __le16_to_cpu(rp->policy); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_def_link_policy(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| void *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY); |
| if (!sent) |
| return rp->status; |
| |
| hdev->link_policy = get_unaligned_le16(sent); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_reset(struct hci_dev *hdev, void *data, struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| clear_bit(HCI_RESET, &hdev->flags); |
| |
| if (rp->status) |
| return rp->status; |
| |
| /* Reset all non-persistent flags */ |
| hci_dev_clear_volatile_flags(hdev); |
| |
| hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| |
| hdev->inq_tx_power = HCI_TX_POWER_INVALID; |
| hdev->adv_tx_power = HCI_TX_POWER_INVALID; |
| |
| memset(hdev->adv_data, 0, sizeof(hdev->adv_data)); |
| hdev->adv_data_len = 0; |
| |
| memset(hdev->scan_rsp_data, 0, sizeof(hdev->scan_rsp_data)); |
| hdev->scan_rsp_data_len = 0; |
| |
| hdev->le_scan_type = LE_SCAN_PASSIVE; |
| |
| hdev->ssp_debug_mode = 0; |
| |
| hci_bdaddr_list_clear(&hdev->le_accept_list); |
| hci_bdaddr_list_clear(&hdev->le_resolv_list); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_stored_link_key(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_stored_link_key *rp = data; |
| struct hci_cp_read_stored_link_key *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_READ_STORED_LINK_KEY); |
| if (!sent) |
| return rp->status; |
| |
| if (!rp->status && sent->read_all == 0x01) { |
| hdev->stored_max_keys = le16_to_cpu(rp->max_keys); |
| hdev->stored_num_keys = le16_to_cpu(rp->num_keys); |
| } |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_delete_stored_link_key(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_delete_stored_link_key *rp = data; |
| u16 num_keys; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| num_keys = le16_to_cpu(rp->num_keys); |
| |
| if (num_keys <= hdev->stored_num_keys) |
| hdev->stored_num_keys -= num_keys; |
| else |
| hdev->stored_num_keys = 0; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_local_name(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| void *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| if (hci_dev_test_flag(hdev, HCI_MGMT)) |
| mgmt_set_local_name_complete(hdev, sent, rp->status); |
| else if (!rp->status) |
| memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_local_name(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_local_name *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| hci_dev_test_flag(hdev, HCI_CONFIG)) |
| memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_auth_enable(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| void *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| if (!rp->status) { |
| __u8 param = *((__u8 *) sent); |
| |
| if (param == AUTH_ENABLED) |
| set_bit(HCI_AUTH, &hdev->flags); |
| else |
| clear_bit(HCI_AUTH, &hdev->flags); |
| } |
| |
| if (hci_dev_test_flag(hdev, HCI_MGMT)) |
| mgmt_auth_enable_complete(hdev, rp->status); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_encrypt_mode(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| __u8 param; |
| void *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE); |
| if (!sent) |
| return rp->status; |
| |
| param = *((__u8 *) sent); |
| |
| if (param) |
| set_bit(HCI_ENCRYPT, &hdev->flags); |
| else |
| clear_bit(HCI_ENCRYPT, &hdev->flags); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_scan_enable(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| __u8 param; |
| void *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE); |
| if (!sent) |
| return rp->status; |
| |
| param = *((__u8 *) sent); |
| |
| hci_dev_lock(hdev); |
| |
| if (rp->status) { |
| hdev->discov_timeout = 0; |
| goto done; |
| } |
| |
| if (param & SCAN_INQUIRY) |
| set_bit(HCI_ISCAN, &hdev->flags); |
| else |
| clear_bit(HCI_ISCAN, &hdev->flags); |
| |
| if (param & SCAN_PAGE) |
| set_bit(HCI_PSCAN, &hdev->flags); |
| else |
| clear_bit(HCI_PSCAN, &hdev->flags); |
| |
| done: |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_set_event_filter(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| struct hci_cp_set_event_filter *cp; |
| void *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_SET_EVENT_FLT); |
| if (!sent) |
| return rp->status; |
| |
| cp = (struct hci_cp_set_event_filter *)sent; |
| |
| if (cp->flt_type == HCI_FLT_CLEAR_ALL) |
| hci_dev_clear_flag(hdev, HCI_EVENT_FILTER_CONFIGURED); |
| else |
| hci_dev_set_flag(hdev, HCI_EVENT_FILTER_CONFIGURED); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_class_of_dev(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_class_of_dev *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| memcpy(hdev->dev_class, rp->dev_class, 3); |
| |
| bt_dev_dbg(hdev, "class 0x%.2x%.2x%.2x", hdev->dev_class[2], |
| hdev->dev_class[1], hdev->dev_class[0]); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_class_of_dev(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| void *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| if (!rp->status) |
| memcpy(hdev->dev_class, sent, 3); |
| |
| if (hci_dev_test_flag(hdev, HCI_MGMT)) |
| mgmt_set_class_of_dev_complete(hdev, sent, rp->status); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_voice_setting(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_voice_setting *rp = data; |
| __u16 setting; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| setting = __le16_to_cpu(rp->voice_setting); |
| |
| if (hdev->voice_setting == setting) |
| return rp->status; |
| |
| hdev->voice_setting = setting; |
| |
| bt_dev_dbg(hdev, "voice setting 0x%4.4x", setting); |
| |
| if (hdev->notify) |
| hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_voice_setting(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| __u16 setting; |
| void *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING); |
| if (!sent) |
| return rp->status; |
| |
| setting = get_unaligned_le16(sent); |
| |
| if (hdev->voice_setting == setting) |
| return rp->status; |
| |
| hdev->voice_setting = setting; |
| |
| bt_dev_dbg(hdev, "voice setting 0x%4.4x", setting); |
| |
| if (hdev->notify) |
| hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_num_supported_iac(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_num_supported_iac *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->num_iac = rp->num_iac; |
| |
| bt_dev_dbg(hdev, "num iac %d", hdev->num_iac); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_ssp_mode(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| struct hci_cp_write_ssp_mode *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| if (!rp->status) { |
| if (sent->mode) |
| hdev->features[1][0] |= LMP_HOST_SSP; |
| else |
| hdev->features[1][0] &= ~LMP_HOST_SSP; |
| } |
| |
| if (!rp->status) { |
| if (sent->mode) |
| hci_dev_set_flag(hdev, HCI_SSP_ENABLED); |
| else |
| hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); |
| } |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_sc_support(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| struct hci_cp_write_sc_support *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SC_SUPPORT); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| if (!rp->status) { |
| if (sent->support) |
| hdev->features[1][0] |= LMP_HOST_SC; |
| else |
| hdev->features[1][0] &= ~LMP_HOST_SC; |
| } |
| |
| if (!hci_dev_test_flag(hdev, HCI_MGMT) && !rp->status) { |
| if (sent->support) |
| hci_dev_set_flag(hdev, HCI_SC_ENABLED); |
| else |
| hci_dev_clear_flag(hdev, HCI_SC_ENABLED); |
| } |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_local_version(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_local_version *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| hci_dev_test_flag(hdev, HCI_CONFIG)) { |
| hdev->hci_ver = rp->hci_ver; |
| hdev->hci_rev = __le16_to_cpu(rp->hci_rev); |
| hdev->lmp_ver = rp->lmp_ver; |
| hdev->manufacturer = __le16_to_cpu(rp->manufacturer); |
| hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver); |
| } |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_enc_key_size(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_enc_key_size *rp = data; |
| struct hci_conn *conn; |
| u16 handle; |
| u8 status = rp->status; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| handle = le16_to_cpu(rp->handle); |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, handle); |
| if (!conn) { |
| status = 0xFF; |
| goto done; |
| } |
| |
| /* While unexpected, the read_enc_key_size command may fail. The most |
| * secure approach is to then assume the key size is 0 to force a |
| * disconnection. |
| */ |
| if (status) { |
| bt_dev_err(hdev, "failed to read key size for handle %u", |
| handle); |
| conn->enc_key_size = 0; |
| } else { |
| conn->enc_key_size = rp->key_size; |
| status = 0; |
| } |
| |
| hci_encrypt_cfm(conn, 0); |
| |
| done: |
| hci_dev_unlock(hdev); |
| |
| return status; |
| } |
| |
| static u8 hci_cc_read_local_commands(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_local_commands *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| hci_dev_test_flag(hdev, HCI_CONFIG)) |
| memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_auth_payload_timeout(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_auth_payload_to *rp = data; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| if (conn) |
| conn->auth_payload_timeout = __le16_to_cpu(rp->timeout); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_auth_payload_timeout(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_write_auth_payload_to *rp = data; |
| struct hci_conn *conn; |
| void *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| if (!conn) { |
| rp->status = 0xff; |
| goto unlock; |
| } |
| |
| if (!rp->status) |
| conn->auth_payload_timeout = get_unaligned_le16(sent + 2); |
| |
| hci_encrypt_cfm(conn, 0); |
| |
| unlock: |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_local_features(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_local_features *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| memcpy(hdev->features, rp->features, 8); |
| |
| /* Adjust default settings according to features |
| * supported by device. */ |
| |
| if (hdev->features[0][0] & LMP_3SLOT) |
| hdev->pkt_type |= (HCI_DM3 | HCI_DH3); |
| |
| if (hdev->features[0][0] & LMP_5SLOT) |
| hdev->pkt_type |= (HCI_DM5 | HCI_DH5); |
| |
| if (hdev->features[0][1] & LMP_HV2) { |
| hdev->pkt_type |= (HCI_HV2); |
| hdev->esco_type |= (ESCO_HV2); |
| } |
| |
| if (hdev->features[0][1] & LMP_HV3) { |
| hdev->pkt_type |= (HCI_HV3); |
| hdev->esco_type |= (ESCO_HV3); |
| } |
| |
| if (lmp_esco_capable(hdev)) |
| hdev->esco_type |= (ESCO_EV3); |
| |
| if (hdev->features[0][4] & LMP_EV4) |
| hdev->esco_type |= (ESCO_EV4); |
| |
| if (hdev->features[0][4] & LMP_EV5) |
| hdev->esco_type |= (ESCO_EV5); |
| |
| if (hdev->features[0][5] & LMP_EDR_ESCO_2M) |
| hdev->esco_type |= (ESCO_2EV3); |
| |
| if (hdev->features[0][5] & LMP_EDR_ESCO_3M) |
| hdev->esco_type |= (ESCO_3EV3); |
| |
| if (hdev->features[0][5] & LMP_EDR_3S_ESCO) |
| hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_local_ext_features(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_local_ext_features *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| if (hdev->max_page < rp->max_page) { |
| if (test_bit(HCI_QUIRK_BROKEN_LOCAL_EXT_FEATURES_PAGE_2, |
| &hdev->quirks)) |
| bt_dev_warn(hdev, "broken local ext features page 2"); |
| else |
| hdev->max_page = rp->max_page; |
| } |
| |
| if (rp->page < HCI_MAX_PAGES) |
| memcpy(hdev->features[rp->page], rp->features, 8); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_flow_control_mode(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_flow_control_mode *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->flow_ctl_mode = rp->mode; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_buffer_size(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_buffer_size *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu); |
| hdev->sco_mtu = rp->sco_mtu; |
| hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt); |
| hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt); |
| |
| if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) { |
| hdev->sco_mtu = 64; |
| hdev->sco_pkts = 8; |
| } |
| |
| hdev->acl_cnt = hdev->acl_pkts; |
| hdev->sco_cnt = hdev->sco_pkts; |
| |
| BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu, |
| hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_bd_addr(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_bd_addr *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| if (test_bit(HCI_INIT, &hdev->flags)) |
| bacpy(&hdev->bdaddr, &rp->bdaddr); |
| |
| if (hci_dev_test_flag(hdev, HCI_SETUP)) |
| bacpy(&hdev->setup_addr, &rp->bdaddr); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_local_pairing_opts(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_local_pairing_opts *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| hci_dev_test_flag(hdev, HCI_CONFIG)) { |
| hdev->pairing_opts = rp->pairing_opts; |
| hdev->max_enc_key_size = rp->max_key_size; |
| } |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_page_scan_activity(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_page_scan_activity *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| if (test_bit(HCI_INIT, &hdev->flags)) { |
| hdev->page_scan_interval = __le16_to_cpu(rp->interval); |
| hdev->page_scan_window = __le16_to_cpu(rp->window); |
| } |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_page_scan_activity(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| struct hci_cp_write_page_scan_activity *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY); |
| if (!sent) |
| return rp->status; |
| |
| hdev->page_scan_interval = __le16_to_cpu(sent->interval); |
| hdev->page_scan_window = __le16_to_cpu(sent->window); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_page_scan_type(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_page_scan_type *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| if (test_bit(HCI_INIT, &hdev->flags)) |
| hdev->page_scan_type = rp->type; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_page_scan_type(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| u8 *type; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| type = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE); |
| if (type) |
| hdev->page_scan_type = *type; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_data_block_size(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_data_block_size *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->block_mtu = __le16_to_cpu(rp->max_acl_len); |
| hdev->block_len = __le16_to_cpu(rp->block_len); |
| hdev->num_blocks = __le16_to_cpu(rp->num_blocks); |
| |
| hdev->block_cnt = hdev->num_blocks; |
| |
| BT_DBG("%s blk mtu %d cnt %d len %d", hdev->name, hdev->block_mtu, |
| hdev->block_cnt, hdev->block_len); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_clock(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_clock *rp = data; |
| struct hci_cp_read_clock *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK); |
| if (!cp) |
| goto unlock; |
| |
| if (cp->which == 0x00) { |
| hdev->clock = le32_to_cpu(rp->clock); |
| goto unlock; |
| } |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| if (conn) { |
| conn->clock = le32_to_cpu(rp->clock); |
| conn->clock_accuracy = le16_to_cpu(rp->accuracy); |
| } |
| |
| unlock: |
| hci_dev_unlock(hdev); |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_local_amp_info(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_local_amp_info *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->amp_status = rp->amp_status; |
| hdev->amp_total_bw = __le32_to_cpu(rp->total_bw); |
| hdev->amp_max_bw = __le32_to_cpu(rp->max_bw); |
| hdev->amp_min_latency = __le32_to_cpu(rp->min_latency); |
| hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu); |
| hdev->amp_type = rp->amp_type; |
| hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap); |
| hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size); |
| hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to); |
| hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_inq_rsp_tx_power *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->inq_tx_power = rp->tx_power; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_def_err_data_reporting(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_def_err_data_reporting *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->err_data_reporting = rp->err_data_reporting; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_def_err_data_reporting(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| struct hci_cp_write_def_err_data_reporting *cp; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING); |
| if (!cp) |
| return rp->status; |
| |
| hdev->err_data_reporting = cp->err_data_reporting; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_pin_code_reply(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_pin_code_reply *rp = data; |
| struct hci_cp_pin_code_reply *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| hci_dev_lock(hdev); |
| |
| if (hci_dev_test_flag(hdev, HCI_MGMT)) |
| mgmt_pin_code_reply_complete(hdev, &rp->bdaddr, rp->status); |
| |
| if (rp->status) |
| goto unlock; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY); |
| if (!cp) |
| goto unlock; |
| |
| conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| if (conn) |
| conn->pin_length = cp->pin_len; |
| |
| unlock: |
| hci_dev_unlock(hdev); |
| return rp->status; |
| } |
| |
| static u8 hci_cc_pin_code_neg_reply(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_pin_code_neg_reply *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| hci_dev_lock(hdev); |
| |
| if (hci_dev_test_flag(hdev, HCI_MGMT)) |
| mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr, |
| rp->status); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_read_buffer_size(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_le_read_buffer_size *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->le_mtu = __le16_to_cpu(rp->le_mtu); |
| hdev->le_pkts = rp->le_max_pkt; |
| |
| hdev->le_cnt = hdev->le_pkts; |
| |
| BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_read_local_features(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_le_read_local_features *rp = data; |
| |
| BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| memcpy(hdev->le_features, rp->features, 8); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_read_adv_tx_power(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_le_read_adv_tx_power *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->adv_tx_power = rp->tx_power; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_user_confirm_reply(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_user_confirm_reply *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| hci_dev_lock(hdev); |
| |
| if (hci_dev_test_flag(hdev, HCI_MGMT)) |
| mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0, |
| rp->status); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_user_confirm_neg_reply(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_user_confirm_reply *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| hci_dev_lock(hdev); |
| |
| if (hci_dev_test_flag(hdev, HCI_MGMT)) |
| mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr, |
| ACL_LINK, 0, rp->status); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_user_passkey_reply(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_user_confirm_reply *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| hci_dev_lock(hdev); |
| |
| if (hci_dev_test_flag(hdev, HCI_MGMT)) |
| mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK, |
| 0, rp->status); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_user_passkey_neg_reply(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_user_confirm_reply *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| hci_dev_lock(hdev); |
| |
| if (hci_dev_test_flag(hdev, HCI_MGMT)) |
| mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr, |
| ACL_LINK, 0, rp->status); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_local_oob_data(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_local_oob_data *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_local_oob_ext_data(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_local_oob_ext_data *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_set_random_addr(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| bdaddr_t *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_RANDOM_ADDR); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| bacpy(&hdev->random_addr, sent); |
| |
| if (!bacmp(&hdev->rpa, sent)) { |
| hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); |
| queue_delayed_work(hdev->workqueue, &hdev->rpa_expired, |
| secs_to_jiffies(hdev->rpa_timeout)); |
| } |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_set_default_phy(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| struct hci_cp_le_set_default_phy *cp; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_DEFAULT_PHY); |
| if (!cp) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| hdev->le_tx_def_phys = cp->tx_phys; |
| hdev->le_rx_def_phys = cp->rx_phys; |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| struct hci_cp_le_set_adv_set_rand_addr *cp; |
| struct adv_info *adv; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR); |
| /* Update only in case the adv instance since handle 0x00 shall be using |
| * HCI_OP_LE_SET_RANDOM_ADDR since that allows both extended and |
| * non-extended adverting. |
| */ |
| if (!cp || !cp->handle) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| adv = hci_find_adv_instance(hdev, cp->handle); |
| if (adv) { |
| bacpy(&adv->random_addr, &cp->bdaddr); |
| if (!bacmp(&hdev->rpa, &cp->bdaddr)) { |
| adv->rpa_expired = false; |
| queue_delayed_work(hdev->workqueue, |
| &adv->rpa_expired_cb, |
| secs_to_jiffies(hdev->rpa_timeout)); |
| } |
| } |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_remove_adv_set(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| u8 *instance; |
| int err; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| instance = hci_sent_cmd_data(hdev, HCI_OP_LE_REMOVE_ADV_SET); |
| if (!instance) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| err = hci_remove_adv_instance(hdev, *instance); |
| if (!err) |
| mgmt_advertising_removed(hci_skb_sk(hdev->sent_cmd), hdev, |
| *instance); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_clear_adv_sets(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| struct adv_info *adv, *n; |
| int err; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| if (!hci_sent_cmd_data(hdev, HCI_OP_LE_CLEAR_ADV_SETS)) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { |
| u8 instance = adv->instance; |
| |
| err = hci_remove_adv_instance(hdev, instance); |
| if (!err) |
| mgmt_advertising_removed(hci_skb_sk(hdev->sent_cmd), |
| hdev, instance); |
| } |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_read_transmit_power(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_le_read_transmit_power *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->min_le_tx_power = rp->min_le_tx_power; |
| hdev->max_le_tx_power = rp->max_le_tx_power; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_set_privacy_mode(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| struct hci_cp_le_set_privacy_mode *cp; |
| struct hci_conn_params *params; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_PRIVACY_MODE); |
| if (!cp) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| params = hci_conn_params_lookup(hdev, &cp->bdaddr, cp->bdaddr_type); |
| if (params) |
| params->privacy_mode = cp->mode; |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_set_adv_enable(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| __u8 *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| /* If we're doing connection initiation as peripheral. Set a |
| * timeout in case something goes wrong. |
| */ |
| if (*sent) { |
| struct hci_conn *conn; |
| |
| hci_dev_set_flag(hdev, HCI_LE_ADV); |
| |
| conn = hci_lookup_le_connect(hdev); |
| if (conn) |
| queue_delayed_work(hdev->workqueue, |
| &conn->le_conn_timeout, |
| conn->conn_timeout); |
| } else { |
| hci_dev_clear_flag(hdev, HCI_LE_ADV); |
| } |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_le_set_ext_adv_enable *cp; |
| struct hci_cp_ext_adv_set *set; |
| struct adv_info *adv = NULL, *n; |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE); |
| if (!cp) |
| return rp->status; |
| |
| set = (void *)cp->data; |
| |
| hci_dev_lock(hdev); |
| |
| if (cp->num_of_sets) |
| adv = hci_find_adv_instance(hdev, set->handle); |
| |
| if (cp->enable) { |
| struct hci_conn *conn; |
| |
| hci_dev_set_flag(hdev, HCI_LE_ADV); |
| |
| if (adv) |
| adv->enabled = true; |
| |
| conn = hci_lookup_le_connect(hdev); |
| if (conn) |
| queue_delayed_work(hdev->workqueue, |
| &conn->le_conn_timeout, |
| conn->conn_timeout); |
| } else { |
| if (cp->num_of_sets) { |
| if (adv) |
| adv->enabled = false; |
| |
| /* If just one instance was disabled check if there are |
| * any other instance enabled before clearing HCI_LE_ADV |
| */ |
| list_for_each_entry_safe(adv, n, &hdev->adv_instances, |
| list) { |
| if (adv->enabled) |
| goto unlock; |
| } |
| } else { |
| /* All instances shall be considered disabled */ |
| list_for_each_entry_safe(adv, n, &hdev->adv_instances, |
| list) |
| adv->enabled = false; |
| } |
| |
| hci_dev_clear_flag(hdev, HCI_LE_ADV); |
| } |
| |
| unlock: |
| hci_dev_unlock(hdev); |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_set_scan_param(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_le_set_scan_param *cp; |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_PARAM); |
| if (!cp) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| hdev->le_scan_type = cp->type; |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_set_ext_scan_param(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_le_set_ext_scan_params *cp; |
| struct hci_ev_status *rp = data; |
| struct hci_cp_le_scan_phy_params *phy_param; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS); |
| if (!cp) |
| return rp->status; |
| |
| phy_param = (void *)cp->data; |
| |
| hci_dev_lock(hdev); |
| |
| hdev->le_scan_type = phy_param->type; |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static bool has_pending_adv_report(struct hci_dev *hdev) |
| { |
| struct discovery_state *d = &hdev->discovery; |
| |
| return bacmp(&d->last_adv_addr, BDADDR_ANY); |
| } |
| |
| static void clear_pending_adv_report(struct hci_dev *hdev) |
| { |
| struct discovery_state *d = &hdev->discovery; |
| |
| bacpy(&d->last_adv_addr, BDADDR_ANY); |
| d->last_adv_data_len = 0; |
| } |
| |
| static void store_pending_adv_report(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| u8 bdaddr_type, s8 rssi, u32 flags, |
| u8 *data, u8 len) |
| { |
| struct discovery_state *d = &hdev->discovery; |
| |
| if (len > HCI_MAX_AD_LENGTH) |
| return; |
| |
| bacpy(&d->last_adv_addr, bdaddr); |
| d->last_adv_addr_type = bdaddr_type; |
| d->last_adv_rssi = rssi; |
| d->last_adv_flags = flags; |
| memcpy(d->last_adv_data, data, len); |
| d->last_adv_data_len = len; |
| } |
| |
| static void le_set_scan_enable_complete(struct hci_dev *hdev, u8 enable) |
| { |
| hci_dev_lock(hdev); |
| |
| switch (enable) { |
| case LE_SCAN_ENABLE: |
| hci_dev_set_flag(hdev, HCI_LE_SCAN); |
| if (hdev->le_scan_type == LE_SCAN_ACTIVE) |
| clear_pending_adv_report(hdev); |
| if (hci_dev_test_flag(hdev, HCI_MESH)) |
| hci_discovery_set_state(hdev, DISCOVERY_FINDING); |
| break; |
| |
| case LE_SCAN_DISABLE: |
| /* We do this here instead of when setting DISCOVERY_STOPPED |
| * since the latter would potentially require waiting for |
| * inquiry to stop too. |
| */ |
| if (has_pending_adv_report(hdev)) { |
| struct discovery_state *d = &hdev->discovery; |
| |
| mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK, |
| d->last_adv_addr_type, NULL, |
| d->last_adv_rssi, d->last_adv_flags, |
| d->last_adv_data, |
| d->last_adv_data_len, NULL, 0, 0); |
| } |
| |
| /* Cancel this timer so that we don't try to disable scanning |
| * when it's already disabled. |
| */ |
| cancel_delayed_work(&hdev->le_scan_disable); |
| |
| hci_dev_clear_flag(hdev, HCI_LE_SCAN); |
| |
| /* The HCI_LE_SCAN_INTERRUPTED flag indicates that we |
| * interrupted scanning due to a connect request. Mark |
| * therefore discovery as stopped. |
| */ |
| if (hci_dev_test_and_clear_flag(hdev, HCI_LE_SCAN_INTERRUPTED)) |
| hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| else if (!hci_dev_test_flag(hdev, HCI_LE_ADV) && |
| hdev->discovery.state == DISCOVERY_FINDING) |
| queue_work(hdev->workqueue, &hdev->reenable_adv_work); |
| |
| break; |
| |
| default: |
| bt_dev_err(hdev, "use of reserved LE_Scan_Enable param %d", |
| enable); |
| break; |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static u8 hci_cc_le_set_scan_enable(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_le_set_scan_enable *cp; |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE); |
| if (!cp) |
| return rp->status; |
| |
| le_set_scan_enable_complete(hdev, cp->enable); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_set_ext_scan_enable(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_le_set_ext_scan_enable *cp; |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE); |
| if (!cp) |
| return rp->status; |
| |
| le_set_scan_enable_complete(hdev, cp->enable); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_read_num_adv_sets(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_le_read_num_supported_adv_sets *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x No of Adv sets %u", rp->status, |
| rp->num_of_sets); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->le_num_of_adv_sets = rp->num_of_sets; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_read_accept_list_size(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_le_read_accept_list_size *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x size %u", rp->status, rp->size); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->le_accept_list_size = rp->size; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_clear_accept_list(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| hci_bdaddr_list_clear(&hdev->le_accept_list); |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_add_to_accept_list(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_le_add_to_accept_list *sent; |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| hci_bdaddr_list_add(&hdev->le_accept_list, &sent->bdaddr, |
| sent->bdaddr_type); |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_del_from_accept_list(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_le_del_from_accept_list *sent; |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| hci_bdaddr_list_del(&hdev->le_accept_list, &sent->bdaddr, |
| sent->bdaddr_type); |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_read_supported_states(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_le_read_supported_states *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| memcpy(hdev->le_states, rp->le_states, 8); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_read_def_data_len(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_le_read_def_data_len *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->le_def_tx_len = le16_to_cpu(rp->tx_len); |
| hdev->le_def_tx_time = le16_to_cpu(rp->tx_time); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_write_def_data_len(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_le_write_def_data_len *sent; |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN); |
| if (!sent) |
| return rp->status; |
| |
| hdev->le_def_tx_len = le16_to_cpu(sent->tx_len); |
| hdev->le_def_tx_time = le16_to_cpu(sent->tx_time); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_add_to_resolv_list(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_le_add_to_resolv_list *sent; |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| hci_bdaddr_list_add_with_irk(&hdev->le_resolv_list, &sent->bdaddr, |
| sent->bdaddr_type, sent->peer_irk, |
| sent->local_irk); |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_del_from_resolv_list(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_le_del_from_resolv_list *sent; |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| hci_bdaddr_list_del_with_irk(&hdev->le_resolv_list, &sent->bdaddr, |
| sent->bdaddr_type); |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_clear_resolv_list(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| hci_bdaddr_list_clear(&hdev->le_resolv_list); |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_read_resolv_list_size(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_le_read_resolv_list_size *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x size %u", rp->status, rp->size); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->le_resolv_list_size = rp->size; |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_set_addr_resolution_enable(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| __u8 *sent; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| if (*sent) |
| hci_dev_set_flag(hdev, HCI_LL_RPA_RESOLUTION); |
| else |
| hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_le_read_max_data_len(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_le_read_max_data_len *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hdev->le_max_tx_len = le16_to_cpu(rp->tx_len); |
| hdev->le_max_tx_time = le16_to_cpu(rp->tx_time); |
| hdev->le_max_rx_len = le16_to_cpu(rp->rx_len); |
| hdev->le_max_rx_time = le16_to_cpu(rp->rx_time); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_le_host_supported(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_write_le_host_supported *sent; |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| if (sent->le) { |
| hdev->features[1][0] |= LMP_HOST_LE; |
| hci_dev_set_flag(hdev, HCI_LE_ENABLED); |
| } else { |
| hdev->features[1][0] &= ~LMP_HOST_LE; |
| hci_dev_clear_flag(hdev, HCI_LE_ENABLED); |
| hci_dev_clear_flag(hdev, HCI_ADVERTISING); |
| } |
| |
| if (sent->simul) |
| hdev->features[1][0] |= LMP_HOST_LE_BREDR; |
| else |
| hdev->features[1][0] &= ~LMP_HOST_LE_BREDR; |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_set_adv_param(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_le_set_adv_param *cp; |
| struct hci_ev_status *rp = data; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_PARAM); |
| if (!cp) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| hdev->adv_addr_type = cp->own_address_type; |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_set_ext_adv_param(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_le_set_ext_adv_params *rp = data; |
| struct hci_cp_le_set_ext_adv_params *cp; |
| struct adv_info *adv_instance; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS); |
| if (!cp) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| hdev->adv_addr_type = cp->own_addr_type; |
| if (!cp->handle) { |
| /* Store in hdev for instance 0 */ |
| hdev->adv_tx_power = rp->tx_power; |
| } else { |
| adv_instance = hci_find_adv_instance(hdev, cp->handle); |
| if (adv_instance) |
| adv_instance->tx_power = rp->tx_power; |
| } |
| /* Update adv data as tx power is known now */ |
| hci_update_adv_data(hdev, cp->handle); |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_rssi(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_rp_read_rssi *rp = data; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| if (conn) |
| conn->rssi = rp->rssi; |
| |
| hci_dev_unlock(hdev); |
| |
| return rp->status; |
| } |
| |
| static u8 hci_cc_read_tx_power(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_cp_read_tx_power *sent; |
| struct hci_rp_read_tx_power *rp = data; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| sent = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER); |
| if (!sent) |
| return rp->status; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| if (!conn) |
| goto unlock; |
| |
| switch (sent->type) { |
| case 0x00: |
| conn->tx_power = rp->tx_power; |
| break; |
| case 0x01: |
| conn->max_tx_power = rp->tx_power; |
| break; |
| } |
| |
| unlock: |
| hci_dev_unlock(hdev); |
| return rp->status; |
| } |
| |
| static u8 hci_cc_write_ssp_debug_mode(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *rp = data; |
| u8 *mode; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| |
| if (rp->status) |
| return rp->status; |
| |
| mode = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE); |
| if (mode) |
| hdev->ssp_debug_mode = *mode; |
| |
| return rp->status; |
| } |
| |
| static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) |
| { |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (status) { |
| hci_conn_check_pending(hdev); |
| return; |
| } |
| |
| set_bit(HCI_INQUIRY, &hdev->flags); |
| } |
| |
| static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) |
| { |
| struct hci_cp_create_conn *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| |
| bt_dev_dbg(hdev, "bdaddr %pMR hcon %p", &cp->bdaddr, conn); |
| |
| if (status) { |
| if (conn && conn->state == BT_CONNECT) { |
| if (status != 0x0c || conn->attempt > 2) { |
| conn->state = BT_CLOSED; |
| hci_connect_cfm(conn, status); |
| hci_conn_del(conn); |
| } else |
| conn->state = BT_CONNECT2; |
| } |
| } else { |
| if (!conn) { |
| conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr, |
| HCI_ROLE_MASTER); |
| if (!conn) |
| bt_dev_err(hdev, "no memory for new connection"); |
| } |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status) |
| { |
| struct hci_cp_add_sco *cp; |
| struct hci_conn *acl; |
| struct hci_link *link; |
| __u16 handle; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO); |
| if (!cp) |
| return; |
| |
| handle = __le16_to_cpu(cp->handle); |
| |
| bt_dev_dbg(hdev, "handle 0x%4.4x", handle); |
| |
| hci_dev_lock(hdev); |
| |
| acl = hci_conn_hash_lookup_handle(hdev, handle); |
| if (acl) { |
| link = list_first_entry_or_null(&acl->link_list, |
| struct hci_link, list); |
| if (link && link->conn) { |
| link->conn->state = BT_CLOSED; |
| |
| hci_connect_cfm(link->conn, status); |
| hci_conn_del(link->conn); |
| } |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status) |
| { |
| struct hci_cp_auth_requested *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| if (conn) { |
| if (conn->state == BT_CONFIG) { |
| hci_connect_cfm(conn, status); |
| hci_conn_drop(conn); |
| } |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status) |
| { |
| struct hci_cp_set_conn_encrypt *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| if (conn) { |
| if (conn->state == BT_CONFIG) { |
| hci_connect_cfm(conn, status); |
| hci_conn_drop(conn); |
| } |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static int hci_outgoing_auth_needed(struct hci_dev *hdev, |
| struct hci_conn *conn) |
| { |
| if (conn->state != BT_CONFIG || !conn->out) |
| return 0; |
| |
| if (conn->pending_sec_level == BT_SECURITY_SDP) |
| return 0; |
| |
| /* Only request authentication for SSP connections or non-SSP |
| * devices with sec_level MEDIUM or HIGH or if MITM protection |
| * is requested. |
| */ |
| if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) && |
| conn->pending_sec_level != BT_SECURITY_FIPS && |
| conn->pending_sec_level != BT_SECURITY_HIGH && |
| conn->pending_sec_level != BT_SECURITY_MEDIUM) |
| return 0; |
| |
| return 1; |
| } |
| |
| static int hci_resolve_name(struct hci_dev *hdev, |
| struct inquiry_entry *e) |
| { |
| struct hci_cp_remote_name_req cp; |
| |
| memset(&cp, 0, sizeof(cp)); |
| |
| bacpy(&cp.bdaddr, &e->data.bdaddr); |
| cp.pscan_rep_mode = e->data.pscan_rep_mode; |
| cp.pscan_mode = e->data.pscan_mode; |
| cp.clock_offset = e->data.clock_offset; |
| |
| return hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
| } |
| |
| static bool hci_resolve_next_name(struct hci_dev *hdev) |
| { |
| struct discovery_state *discov = &hdev->discovery; |
| struct inquiry_entry *e; |
| |
| if (list_empty(&discov->resolve)) |
| return false; |
| |
| /* We should stop if we already spent too much time resolving names. */ |
| if (time_after(jiffies, discov->name_resolve_timeout)) { |
| bt_dev_warn_ratelimited(hdev, "Name resolve takes too long."); |
| return false; |
| } |
| |
| e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED); |
| if (!e) |
| return false; |
| |
| if (hci_resolve_name(hdev, e) == 0) { |
| e->name_state = NAME_PENDING; |
| return true; |
| } |
| |
| return false; |
| } |
| |
| static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn, |
| bdaddr_t *bdaddr, u8 *name, u8 name_len) |
| { |
| struct discovery_state *discov = &hdev->discovery; |
| struct inquiry_entry *e; |
| |
| /* Update the mgmt connected state if necessary. Be careful with |
| * conn objects that exist but are not (yet) connected however. |
| * Only those in BT_CONFIG or BT_CONNECTED states can be |
| * considered connected. |
| */ |
| if (conn && |
| (conn->state == BT_CONFIG || conn->state == BT_CONNECTED) && |
| !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
| mgmt_device_connected(hdev, conn, name, name_len); |
| |
| if (discov->state == DISCOVERY_STOPPED) |
| return; |
| |
| if (discov->state == DISCOVERY_STOPPING) |
| goto discov_complete; |
| |
| if (discov->state != DISCOVERY_RESOLVING) |
| return; |
| |
| e = hci_inquiry_cache_lookup_resolve(hdev, bdaddr, NAME_PENDING); |
| /* If the device was not found in a list of found devices names of which |
| * are pending. there is no need to continue resolving a next name as it |
| * will be done upon receiving another Remote Name Request Complete |
| * Event */ |
| if (!e) |
| return; |
| |
| list_del(&e->list); |
| |
| e->name_state = name ? NAME_KNOWN : NAME_NOT_KNOWN; |
| mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00, e->data.rssi, |
| name, name_len); |
| |
| if (hci_resolve_next_name(hdev)) |
| return; |
| |
| discov_complete: |
| hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| } |
| |
| static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status) |
| { |
| struct hci_cp_remote_name_req *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| /* If successful wait for the name req complete event before |
| * checking for the need to do authentication */ |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| |
| if (hci_dev_test_flag(hdev, HCI_MGMT)) |
| hci_check_pending_name(hdev, conn, &cp->bdaddr, NULL, 0); |
| |
| if (!conn) |
| goto unlock; |
| |
| if (!hci_outgoing_auth_needed(hdev, conn)) |
| goto unlock; |
| |
| if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { |
| struct hci_cp_auth_requested auth_cp; |
| |
| set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); |
| |
| auth_cp.handle = __cpu_to_le16(conn->handle); |
| hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, |
| sizeof(auth_cp), &auth_cp); |
| } |
| |
| unlock: |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status) |
| { |
| struct hci_cp_read_remote_features *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| if (conn) { |
| if (conn->state == BT_CONFIG) { |
| hci_connect_cfm(conn, status); |
| hci_conn_drop(conn); |
| } |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status) |
| { |
| struct hci_cp_read_remote_ext_features *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| if (conn) { |
| if (conn->state == BT_CONFIG) { |
| hci_connect_cfm(conn, status); |
| hci_conn_drop(conn); |
| } |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_setup_sync_conn_status(struct hci_dev *hdev, __u16 handle, |
| __u8 status) |
| { |
| struct hci_conn *acl; |
| struct hci_link *link; |
| |
| bt_dev_dbg(hdev, "handle 0x%4.4x status 0x%2.2x", handle, status); |
| |
| hci_dev_lock(hdev); |
| |
| acl = hci_conn_hash_lookup_handle(hdev, handle); |
| if (acl) { |
| link = list_first_entry_or_null(&acl->link_list, |
| struct hci_link, list); |
| if (link && link->conn) { |
| link->conn->state = BT_CLOSED; |
| |
| hci_connect_cfm(link->conn, status); |
| hci_conn_del(link->conn); |
| } |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status) |
| { |
| struct hci_cp_setup_sync_conn *cp; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN); |
| if (!cp) |
| return; |
| |
| hci_setup_sync_conn_status(hdev, __le16_to_cpu(cp->handle), status); |
| } |
| |
| static void hci_cs_enhanced_setup_sync_conn(struct hci_dev *hdev, __u8 status) |
| { |
| struct hci_cp_enhanced_setup_sync_conn *cp; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_ENHANCED_SETUP_SYNC_CONN); |
| if (!cp) |
| return; |
| |
| hci_setup_sync_conn_status(hdev, __le16_to_cpu(cp->handle), status); |
| } |
| |
| static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status) |
| { |
| struct hci_cp_sniff_mode *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| if (conn) { |
| clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); |
| |
| if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
| hci_sco_setup(conn, status); |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status) |
| { |
| struct hci_cp_exit_sniff_mode *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| if (conn) { |
| clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); |
| |
| if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
| hci_sco_setup(conn, status); |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) |
| { |
| struct hci_cp_disconnect *cp; |
| struct hci_conn_params *params; |
| struct hci_conn *conn; |
| bool mgmt_conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| /* Wait for HCI_EV_DISCONN_COMPLETE if status 0x00 and not suspended |
| * otherwise cleanup the connection immediately. |
| */ |
| if (!status && !hdev->suspended) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| if (!conn) |
| goto unlock; |
| |
| if (status) { |
| mgmt_disconnect_failed(hdev, &conn->dst, conn->type, |
| conn->dst_type, status); |
| |
| if (conn->type == LE_LINK && conn->role == HCI_ROLE_SLAVE) { |
| hdev->cur_adv_instance = conn->adv_instance; |
| hci_enable_advertising(hdev); |
| } |
| |
| goto done; |
| } |
| |
| mgmt_conn = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); |
| |
| if (conn->type == ACL_LINK) { |
| if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) |
| hci_remove_link_key(hdev, &conn->dst); |
| } |
| |
| params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); |
| if (params) { |
| switch (params->auto_connect) { |
| case HCI_AUTO_CONN_LINK_LOSS: |
| if (cp->reason != HCI_ERROR_CONNECTION_TIMEOUT) |
| break; |
| fallthrough; |
| |
| case HCI_AUTO_CONN_DIRECT: |
| case HCI_AUTO_CONN_ALWAYS: |
| list_del_init(¶ms->action); |
| list_add(¶ms->action, &hdev->pend_le_conns); |
| break; |
| |
| default: |
| break; |
| } |
| } |
| |
| mgmt_device_disconnected(hdev, &conn->dst, conn->type, conn->dst_type, |
| cp->reason, mgmt_conn); |
| |
| hci_disconn_cfm(conn, cp->reason); |
| |
| done: |
| /* If the disconnection failed for any reason, the upper layer |
| * does not retry to disconnect in current implementation. |
| * Hence, we need to do some basic cleanup here and re-enable |
| * advertising if necessary. |
| */ |
| hci_conn_del(conn); |
| unlock: |
| hci_dev_unlock(hdev); |
| } |
| |
| static u8 ev_bdaddr_type(struct hci_dev *hdev, u8 type, bool *resolved) |
| { |
| /* When using controller based address resolution, then the new |
| * address types 0x02 and 0x03 are used. These types need to be |
| * converted back into either public address or random address type |
| */ |
| switch (type) { |
| case ADDR_LE_DEV_PUBLIC_RESOLVED: |
| if (resolved) |
| *resolved = true; |
| return ADDR_LE_DEV_PUBLIC; |
| case ADDR_LE_DEV_RANDOM_RESOLVED: |
| if (resolved) |
| *resolved = true; |
| return ADDR_LE_DEV_RANDOM; |
| } |
| |
| if (resolved) |
| *resolved = false; |
| return type; |
| } |
| |
| static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, |
| u8 peer_addr_type, u8 own_address_type, |
| u8 filter_policy) |
| { |
| struct hci_conn *conn; |
| |
| conn = hci_conn_hash_lookup_le(hdev, peer_addr, |
| peer_addr_type); |
| if (!conn) |
| return; |
| |
| own_address_type = ev_bdaddr_type(hdev, own_address_type, NULL); |
| |
| /* Store the initiator and responder address information which |
| * is needed for SMP. These values will not change during the |
| * lifetime of the connection. |
| */ |
| conn->init_addr_type = own_address_type; |
| if (own_address_type == ADDR_LE_DEV_RANDOM) |
| bacpy(&conn->init_addr, &hdev->random_addr); |
| else |
| bacpy(&conn->init_addr, &hdev->bdaddr); |
| |
| conn->resp_addr_type = peer_addr_type; |
| bacpy(&conn->resp_addr, peer_addr); |
| } |
| |
| static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status) |
| { |
| struct hci_cp_le_create_conn *cp; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| /* All connection failure handling is taken care of by the |
| * hci_conn_failed function which is triggered by the HCI |
| * request completion callbacks used for connecting. |
| */ |
| if (status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| cs_le_create_conn(hdev, &cp->peer_addr, cp->peer_addr_type, |
| cp->own_address_type, cp->filter_policy); |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_le_ext_create_conn(struct hci_dev *hdev, u8 status) |
| { |
| struct hci_cp_le_ext_create_conn *cp; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| /* All connection failure handling is taken care of by the |
| * hci_conn_failed function which is triggered by the HCI |
| * request completion callbacks used for connecting. |
| */ |
| if (status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_EXT_CREATE_CONN); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| cs_le_create_conn(hdev, &cp->peer_addr, cp->peer_addr_type, |
| cp->own_addr_type, cp->filter_policy); |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_le_read_remote_features(struct hci_dev *hdev, u8 status) |
| { |
| struct hci_cp_le_read_remote_features *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_READ_REMOTE_FEATURES); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| if (conn) { |
| if (conn->state == BT_CONFIG) { |
| hci_connect_cfm(conn, status); |
| hci_conn_drop(conn); |
| } |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status) |
| { |
| struct hci_cp_le_start_enc *cp; |
| struct hci_conn *conn; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| if (!status) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_LE_START_ENC); |
| if (!cp) |
| goto unlock; |
| |
| conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| if (!conn) |
| goto unlock; |
| |
| if (conn->state != BT_CONNECTED) |
| goto unlock; |
| |
| hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); |
| hci_conn_drop(conn); |
| |
| unlock: |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_cs_switch_role(struct hci_dev *hdev, u8 status) |
| { |
| struct hci_cp_switch_role *cp; |
| struct hci_conn *conn; |
| |
| BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| |
| if (!status) |
| return; |
| |
| cp = hci_sent_cmd_data(hdev, HCI_OP_SWITCH_ROLE); |
| if (!cp) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| if (conn) |
| clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_inquiry_complete_evt(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_status *ev = data; |
| struct discovery_state *discov = &hdev->discovery; |
| struct inquiry_entry *e; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", ev->status); |
| |
| hci_conn_check_pending(hdev); |
| |
| if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) |
| return; |
| |
| smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */ |
| wake_up_bit(&hdev->flags, HCI_INQUIRY); |
| |
| if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| if (discov->state != DISCOVERY_FINDING) |
| goto unlock; |
| |
| if (list_empty(&discov->resolve)) { |
| /* When BR/EDR inquiry is active and no LE scanning is in |
| * progress, then change discovery state to indicate completion. |
| * |
| * When running LE scanning and BR/EDR inquiry simultaneously |
| * and the LE scan already finished, then change the discovery |
| * state to indicate completion. |
| */ |
| if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) |
| hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| goto unlock; |
| } |
| |
| e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED); |
| if (e && hci_resolve_name(hdev, e) == 0) { |
| e->name_state = NAME_PENDING; |
| hci_discovery_set_state(hdev, DISCOVERY_RESOLVING); |
| discov->name_resolve_timeout = jiffies + NAME_RESOLVE_DURATION; |
| } else { |
| /* When BR/EDR inquiry is active and no LE scanning is in |
| * progress, then change discovery state to indicate completion. |
| * |
| * When running LE scanning and BR/EDR inquiry simultaneously |
| * and the LE scan already finished, then change the discovery |
| * state to indicate completion. |
| */ |
| if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) |
| hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| } |
| |
| unlock: |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_inquiry_result_evt(struct hci_dev *hdev, void *edata, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_inquiry_result *ev = edata; |
| struct inquiry_data data; |
| int i; |
| |
| if (!hci_ev_skb_pull(hdev, skb, HCI_EV_INQUIRY_RESULT, |
| flex_array_size(ev, info, ev->num))) |
| return; |
| |
| bt_dev_dbg(hdev, "num %d", ev->num); |
| |
| if (!ev->num) |
| return; |
| |
| if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
| return; |
| |
| hci_dev_lock(hdev); |
| |
| for (i = 0; i < ev->num; i++) { |
| struct inquiry_info *info = &ev->info[i]; |
| u32 flags; |
| |
| bacpy(&data.bdaddr, &info->bdaddr); |
| data.pscan_rep_mode = info->pscan_rep_mode; |
| data.pscan_period_mode = info->pscan_period_mode; |
| data.pscan_mode = info->pscan_mode; |
| memcpy(data.dev_class, info->dev_class, 3); |
| data.clock_offset = info->clock_offset; |
| data.rssi = HCI_RSSI_INVALID; |
| data.ssp_mode = 0x00; |
| |
| flags = hci_inquiry_cache_update(hdev, &data, false); |
| |
| mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
| info->dev_class, HCI_RSSI_INVALID, |
| flags, NULL, 0, NULL, 0, 0); |
| } |
| |
| hci_dev_unlock(hdev); |
| } |
| |
| static void hci_conn_complete_evt(struct hci_dev *hdev, void *data, |
| struct sk_buff *skb) |
| { |
| struct hci_ev_conn_complete *ev = data; |
| struct hci_conn *conn; |
| u8 status = ev->status; |
| |
| bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| |
| hci_dev_lock(hdev); |
| |
| conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
| if (!conn) { |
| /* In case of error status and there is no connection pending |
| * just unlock as there is nothing to cleanup. |
| */ |
| if (ev->status) |
| goto unlock; |
| |
| /* Connection may not exist if auto-connected. Check the bredr |
| * allowlist to see if this device is allowed to auto connect. |
| * If link is an ACL type, create a connection class |
| * automatically. |
| * |
| * Auto-connect will only occur if the event filter is |
| * programmed with a given address. Right now, event filter is |
| * only used during suspend. |
| */ |
| if (ev->link_type == ACL_LINK && |
| hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, |
| &ev->bdaddr, |
| BDADDR_BREDR)) { |
| conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr, |
| HCI_ROLE_SLAVE); |
| if (!conn) { |
| bt_dev_err(hdev, "no memory for new conn"); |
| goto unlock; |
| } |
| } else { |
| if (ev->link_type != SCO_LINK) |
| goto unlock; |
| |
| conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, |
| &ev->bdaddr); |
| if (!conn) |
| goto unlock; |
| |
| conn->type = SCO_LINK; |
| } |
| } |
| |
| /* The HCI_Connection_Complete event is only sent once per connection. |
| * Processing it more than once per connection can corrupt kernel memory. |
| * |
| * As the connection handle is set here for the first time, it indicates |
| * whether the connection is already set up. |
| */ |
| if<
|