Lines Matching refs:hdev

250 static int mgmt_index_event(u16 event, struct hci_dev *hdev, void *data,  in mgmt_index_event()  argument
253 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_index_event()
257 static int mgmt_limited_event(u16 event, struct hci_dev *hdev, void *data, in mgmt_limited_event() argument
260 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_limited_event()
264 static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, u16 len, in mgmt_event() argument
267 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_event()
287 static int read_version(struct sock *sk, struct hci_dev *hdev, void *data, in read_version() argument
300 static int read_commands(struct sock *sk, struct hci_dev *hdev, void *data, in read_commands() argument
352 static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data, in read_index_list() argument
412 static int read_unconf_index_list(struct sock *sk, struct hci_dev *hdev, in read_unconf_index_list() argument
472 static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev, in read_ext_index_list() argument
548 static bool is_configured(struct hci_dev *hdev) in is_configured() argument
550 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in is_configured()
551 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in is_configured()
554 if (test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) && in is_configured()
555 !bacmp(&hdev->public_addr, BDADDR_ANY)) in is_configured()
561 static __le32 get_missing_options(struct hci_dev *hdev) in get_missing_options() argument
565 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in get_missing_options()
566 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in get_missing_options()
569 if (test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) && in get_missing_options()
570 !bacmp(&hdev->public_addr, BDADDR_ANY)) in get_missing_options()
576 static int new_options(struct hci_dev *hdev, struct sock *skip) in new_options() argument
578 __le32 options = get_missing_options(hdev); in new_options()
580 return mgmt_limited_event(MGMT_EV_NEW_CONFIG_OPTIONS, hdev, &options, in new_options()
584 static int send_options_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_options_rsp() argument
586 __le32 options = get_missing_options(hdev); in send_options_rsp()
588 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &options, in send_options_rsp()
592 static int read_config_info(struct sock *sk, struct hci_dev *hdev, in read_config_info() argument
598 BT_DBG("sock %p %s", sk, hdev->name); in read_config_info()
600 hci_dev_lock(hdev); in read_config_info()
603 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_config_info()
605 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in read_config_info()
608 if (hdev->set_bdaddr) in read_config_info()
612 rp.missing_options = get_missing_options(hdev); in read_config_info()
614 hci_dev_unlock(hdev); in read_config_info()
616 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONFIG_INFO, 0, in read_config_info()
620 static u32 get_supported_phys(struct hci_dev *hdev) in get_supported_phys() argument
624 if (lmp_bredr_capable(hdev)) { in get_supported_phys()
627 if (hdev->features[0][0] & LMP_3SLOT) in get_supported_phys()
630 if (hdev->features[0][0] & LMP_5SLOT) in get_supported_phys()
633 if (lmp_edr_2m_capable(hdev)) { in get_supported_phys()
636 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
639 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
642 if (lmp_edr_3m_capable(hdev)) { in get_supported_phys()
645 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
648 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
654 if (lmp_le_capable(hdev)) { in get_supported_phys()
658 if (hdev->le_features[1] & HCI_LE_PHY_2M) { in get_supported_phys()
663 if (hdev->le_features[1] & HCI_LE_PHY_CODED) { in get_supported_phys()
672 static u32 get_selected_phys(struct hci_dev *hdev) in get_selected_phys() argument
676 if (lmp_bredr_capable(hdev)) { in get_selected_phys()
679 if (hdev->pkt_type & (HCI_DM3 | HCI_DH3)) in get_selected_phys()
682 if (hdev->pkt_type & (HCI_DM5 | HCI_DH5)) in get_selected_phys()
685 if (lmp_edr_2m_capable(hdev)) { in get_selected_phys()
686 if (!(hdev->pkt_type & HCI_2DH1)) in get_selected_phys()
689 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
690 !(hdev->pkt_type & HCI_2DH3)) in get_selected_phys()
693 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
694 !(hdev->pkt_type & HCI_2DH5)) in get_selected_phys()
697 if (lmp_edr_3m_capable(hdev)) { in get_selected_phys()
698 if (!(hdev->pkt_type & HCI_3DH1)) in get_selected_phys()
701 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
702 !(hdev->pkt_type & HCI_3DH3)) in get_selected_phys()
705 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
706 !(hdev->pkt_type & HCI_3DH5)) in get_selected_phys()
712 if (lmp_le_capable(hdev)) { in get_selected_phys()
713 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
716 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
719 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
722 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
725 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
728 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
735 static u32 get_configurable_phys(struct hci_dev *hdev) in get_configurable_phys() argument
737 return (get_supported_phys(hdev) & ~MGMT_PHY_BR_1M_1SLOT & in get_configurable_phys()
741 static u32 get_supported_settings(struct hci_dev *hdev) in get_supported_settings() argument
751 if (lmp_bredr_capable(hdev)) { in get_supported_settings()
752 if (hdev->hci_ver >= BLUETOOTH_VER_1_2) in get_supported_settings()
757 if (lmp_ssp_capable(hdev)) { in get_supported_settings()
762 if (lmp_sc_capable(hdev)) in get_supported_settings()
766 if (lmp_le_capable(hdev)) { in get_supported_settings()
774 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in get_supported_settings()
775 hdev->set_bdaddr) in get_supported_settings()
783 static u32 get_current_settings(struct hci_dev *hdev) in get_current_settings() argument
787 if (hdev_is_powered(hdev)) in get_current_settings()
790 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in get_current_settings()
793 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in get_current_settings()
796 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in get_current_settings()
799 if (hci_dev_test_flag(hdev, HCI_BONDABLE)) in get_current_settings()
802 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in get_current_settings()
805 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in get_current_settings()
808 if (hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) in get_current_settings()
811 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in get_current_settings()
814 if (hci_dev_test_flag(hdev, HCI_HS_ENABLED)) in get_current_settings()
817 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in get_current_settings()
820 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) in get_current_settings()
823 if (hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) in get_current_settings()
826 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in get_current_settings()
841 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in get_current_settings()
842 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in get_current_settings()
843 !bacmp(&hdev->bdaddr, BDADDR_ANY)) { in get_current_settings()
844 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in get_current_settings()
851 static struct mgmt_pending_cmd *pending_find(u16 opcode, struct hci_dev *hdev) in pending_find() argument
853 return mgmt_pending_find(HCI_CHANNEL_CONTROL, opcode, hdev); in pending_find()
857 struct hci_dev *hdev, in pending_find_data() argument
860 return mgmt_pending_find_data(HCI_CHANNEL_CONTROL, opcode, hdev, data); in pending_find_data()
863 u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev) in mgmt_get_adv_discov_flags() argument
870 cmd = pending_find(MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_get_adv_discov_flags()
878 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
880 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
887 bool mgmt_get_connectable(struct hci_dev *hdev) in mgmt_get_connectable() argument
894 cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_get_connectable()
901 return hci_dev_test_flag(hdev, HCI_CONNECTABLE); in mgmt_get_connectable()
906 struct hci_dev *hdev = container_of(work, struct hci_dev, in service_cache_off() local
910 if (!hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in service_cache_off()
913 hci_req_init(&req, hdev); in service_cache_off()
915 hci_dev_lock(hdev); in service_cache_off()
920 hci_dev_unlock(hdev); in service_cache_off()
927 struct hci_dev *hdev = container_of(work, struct hci_dev, in rpa_expired() local
933 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in rpa_expired()
935 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING)) in rpa_expired()
942 hci_req_init(&req, hdev); in rpa_expired()
943 if (ext_adv_capable(hdev)) in rpa_expired()
944 __hci_req_start_ext_adv(&req, hdev->cur_adv_instance); in rpa_expired()
950 static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev) in mgmt_init_hdev() argument
952 if (hci_dev_test_and_set_flag(hdev, HCI_MGMT)) in mgmt_init_hdev()
955 INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off); in mgmt_init_hdev()
956 INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired); in mgmt_init_hdev()
963 hci_dev_clear_flag(hdev, HCI_BONDABLE); in mgmt_init_hdev()
966 static int read_controller_info(struct sock *sk, struct hci_dev *hdev, in read_controller_info() argument
971 BT_DBG("sock %p %s", sk, hdev->name); in read_controller_info()
973 hci_dev_lock(hdev); in read_controller_info()
977 bacpy(&rp.bdaddr, &hdev->bdaddr); in read_controller_info()
979 rp.version = hdev->hci_ver; in read_controller_info()
980 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_controller_info()
982 rp.supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_controller_info()
983 rp.current_settings = cpu_to_le32(get_current_settings(hdev)); in read_controller_info()
985 memcpy(rp.dev_class, hdev->dev_class, 3); in read_controller_info()
987 memcpy(rp.name, hdev->dev_name, sizeof(hdev->dev_name)); in read_controller_info()
988 memcpy(rp.short_name, hdev->short_name, sizeof(hdev->short_name)); in read_controller_info()
990 hci_dev_unlock(hdev); in read_controller_info()
992 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_INFO, 0, &rp, in read_controller_info()
996 static u16 append_eir_data_to_buf(struct hci_dev *hdev, u8 *eir) in append_eir_data_to_buf() argument
1001 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in append_eir_data_to_buf()
1003 hdev->dev_class, 3); in append_eir_data_to_buf()
1005 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in append_eir_data_to_buf()
1007 hdev->appearance); in append_eir_data_to_buf()
1009 name_len = strlen(hdev->dev_name); in append_eir_data_to_buf()
1011 hdev->dev_name, name_len); in append_eir_data_to_buf()
1013 name_len = strlen(hdev->short_name); in append_eir_data_to_buf()
1015 hdev->short_name, name_len); in append_eir_data_to_buf()
1020 static int read_ext_controller_info(struct sock *sk, struct hci_dev *hdev, in read_ext_controller_info() argument
1027 BT_DBG("sock %p %s", sk, hdev->name); in read_ext_controller_info()
1031 hci_dev_lock(hdev); in read_ext_controller_info()
1033 bacpy(&rp->bdaddr, &hdev->bdaddr); in read_ext_controller_info()
1035 rp->version = hdev->hci_ver; in read_ext_controller_info()
1036 rp->manufacturer = cpu_to_le16(hdev->manufacturer); in read_ext_controller_info()
1038 rp->supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_ext_controller_info()
1039 rp->current_settings = cpu_to_le32(get_current_settings(hdev)); in read_ext_controller_info()
1042 eir_len = append_eir_data_to_buf(hdev, rp->eir); in read_ext_controller_info()
1045 hci_dev_unlock(hdev); in read_ext_controller_info()
1056 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_EXT_INFO, 0, rp, in read_ext_controller_info()
1060 static int ext_info_changed(struct hci_dev *hdev, struct sock *skip) in ext_info_changed() argument
1068 eir_len = append_eir_data_to_buf(hdev, ev->eir); in ext_info_changed()
1071 return mgmt_limited_event(MGMT_EV_EXT_INFO_CHANGED, hdev, ev, in ext_info_changed()
1076 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_settings_rsp() argument
1078 __le32 settings = cpu_to_le32(get_current_settings(hdev)); in send_settings_rsp()
1080 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &settings, in send_settings_rsp()
1084 static void clean_up_hci_complete(struct hci_dev *hdev, u8 status, u16 opcode) in clean_up_hci_complete() argument
1086 BT_DBG("%s status 0x%02x", hdev->name, status); in clean_up_hci_complete()
1088 if (hci_conn_count(hdev) == 0) { in clean_up_hci_complete()
1089 cancel_delayed_work(&hdev->power_off); in clean_up_hci_complete()
1090 queue_work(hdev->req_workqueue, &hdev->power_off.work); in clean_up_hci_complete()
1094 void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev, u8 instance) in mgmt_advertising_added() argument
1100 mgmt_event(MGMT_EV_ADVERTISING_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_added()
1103 void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev, in mgmt_advertising_removed() argument
1110 mgmt_event(MGMT_EV_ADVERTISING_REMOVED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_removed()
1113 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
1115 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
1116 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
1117 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
1121 static int clean_up_hci_state(struct hci_dev *hdev) in clean_up_hci_state() argument
1128 hci_req_init(&req, hdev); in clean_up_hci_state()
1130 if (test_bit(HCI_ISCAN, &hdev->flags) || in clean_up_hci_state()
1131 test_bit(HCI_PSCAN, &hdev->flags)) { in clean_up_hci_state()
1136 hci_req_clear_adv_instance(hdev, NULL, NULL, 0x00, false); in clean_up_hci_state()
1138 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in clean_up_hci_state()
1143 list_for_each_entry(conn, &hdev->conn_hash.list, list) { in clean_up_hci_state()
1150 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in clean_up_hci_state()
1155 static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, in set_powered() argument
1162 BT_DBG("request for %s", hdev->name); in set_powered()
1165 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1168 hci_dev_lock(hdev); in set_powered()
1170 if (pending_find(MGMT_OP_SET_POWERED, hdev)) { in set_powered()
1171 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1176 if (!!cp->val == hdev_is_powered(hdev)) { in set_powered()
1177 err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev); in set_powered()
1181 cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, hdev, data, len); in set_powered()
1188 queue_work(hdev->req_workqueue, &hdev->power_on); in set_powered()
1192 err = clean_up_hci_state(hdev); in set_powered()
1194 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in set_powered()
1199 cancel_delayed_work(&hdev->power_off); in set_powered()
1200 queue_work(hdev->req_workqueue, &hdev->power_off.work); in set_powered()
1206 hci_dev_unlock(hdev); in set_powered()
1210 static int new_settings(struct hci_dev *hdev, struct sock *skip) in new_settings() argument
1212 __le32 ev = cpu_to_le32(get_current_settings(hdev)); in new_settings()
1214 return mgmt_limited_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, in new_settings()
1218 int mgmt_new_settings(struct hci_dev *hdev) in mgmt_new_settings() argument
1220 return new_settings(hdev, NULL); in mgmt_new_settings()
1225 struct hci_dev *hdev; member
1233 send_settings_rsp(cmd->sk, cmd->opcode, match->hdev); in settings_rsp()
1279 static u8 mgmt_bredr_support(struct hci_dev *hdev) in mgmt_bredr_support() argument
1281 if (!lmp_bredr_capable(hdev)) in mgmt_bredr_support()
1283 else if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in mgmt_bredr_support()
1289 static u8 mgmt_le_support(struct hci_dev *hdev) in mgmt_le_support() argument
1291 if (!lmp_le_capable(hdev)) in mgmt_le_support()
1293 else if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mgmt_le_support()
1299 void mgmt_set_discoverable_complete(struct hci_dev *hdev, u8 status) in mgmt_set_discoverable_complete() argument
1305 hci_dev_lock(hdev); in mgmt_set_discoverable_complete()
1307 cmd = pending_find(MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_set_discoverable_complete()
1314 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in mgmt_set_discoverable_complete()
1318 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in mgmt_set_discoverable_complete()
1319 hdev->discov_timeout > 0) { in mgmt_set_discoverable_complete()
1320 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in mgmt_set_discoverable_complete()
1321 queue_delayed_work(hdev->req_workqueue, &hdev->discov_off, to); in mgmt_set_discoverable_complete()
1324 send_settings_rsp(cmd->sk, MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_set_discoverable_complete()
1325 new_settings(hdev, cmd->sk); in mgmt_set_discoverable_complete()
1331 hci_dev_unlock(hdev); in mgmt_set_discoverable_complete()
1334 static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, in set_discoverable() argument
1342 BT_DBG("request for %s", hdev->name); in set_discoverable()
1344 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_discoverable()
1345 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_discoverable()
1346 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1350 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1360 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1363 hci_dev_lock(hdev); in set_discoverable()
1365 if (!hdev_is_powered(hdev) && timeout > 0) { in set_discoverable()
1366 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1371 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_discoverable()
1372 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_discoverable()
1373 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1378 if (!hci_dev_test_flag(hdev, HCI_CONNECTABLE)) { in set_discoverable()
1379 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1384 if (!hdev_is_powered(hdev)) { in set_discoverable()
1391 if (!!cp->val != hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) { in set_discoverable()
1392 hci_dev_change_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1396 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1401 err = new_settings(hdev, sk); in set_discoverable()
1410 if (!!cp->val == hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in set_discoverable()
1411 (cp->val == 0x02) == hci_dev_test_flag(hdev, in set_discoverable()
1413 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1414 hdev->discov_timeout = timeout; in set_discoverable()
1416 if (cp->val && hdev->discov_timeout > 0) { in set_discoverable()
1417 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in set_discoverable()
1418 queue_delayed_work(hdev->req_workqueue, in set_discoverable()
1419 &hdev->discov_off, to); in set_discoverable()
1422 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1426 cmd = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, hdev, data, len); in set_discoverable()
1436 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1437 hdev->discov_timeout = timeout; in set_discoverable()
1440 hci_dev_set_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1442 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1446 hci_dev_set_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1448 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1450 queue_work(hdev->req_workqueue, &hdev->discoverable_update); in set_discoverable()
1454 hci_dev_unlock(hdev); in set_discoverable()
1458 void mgmt_set_connectable_complete(struct hci_dev *hdev, u8 status) in mgmt_set_connectable_complete() argument
1464 hci_dev_lock(hdev); in mgmt_set_connectable_complete()
1466 cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_set_connectable_complete()
1476 send_settings_rsp(cmd->sk, MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_set_connectable_complete()
1477 new_settings(hdev, cmd->sk); in mgmt_set_connectable_complete()
1483 hci_dev_unlock(hdev); in mgmt_set_connectable_complete()
1486 static int set_connectable_update_settings(struct hci_dev *hdev, in set_connectable_update_settings() argument
1492 if (!!val != hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in set_connectable_update_settings()
1496 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1498 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1499 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable_update_settings()
1502 err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev); in set_connectable_update_settings()
1507 hci_req_update_scan(hdev); in set_connectable_update_settings()
1508 hci_update_background_scan(hdev); in set_connectable_update_settings()
1509 return new_settings(hdev, sk); in set_connectable_update_settings()
1515 static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data, in set_connectable() argument
1522 BT_DBG("request for %s", hdev->name); in set_connectable()
1524 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_connectable()
1525 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_connectable()
1526 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1530 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1533 hci_dev_lock(hdev); in set_connectable()
1535 if (!hdev_is_powered(hdev)) { in set_connectable()
1536 err = set_connectable_update_settings(hdev, sk, cp->val); in set_connectable()
1540 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_connectable()
1541 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_connectable()
1542 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1547 cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len); in set_connectable()
1554 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1556 if (hdev->discov_timeout > 0) in set_connectable()
1557 cancel_delayed_work(&hdev->discov_off); in set_connectable()
1559 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_connectable()
1560 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable()
1561 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1564 queue_work(hdev->req_workqueue, &hdev->connectable_update); in set_connectable()
1568 hci_dev_unlock(hdev); in set_connectable()
1572 static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data, in set_bondable() argument
1579 BT_DBG("request for %s", hdev->name); in set_bondable()
1582 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BONDABLE, in set_bondable()
1585 hci_dev_lock(hdev); in set_bondable()
1588 changed = !hci_dev_test_and_set_flag(hdev, HCI_BONDABLE); in set_bondable()
1590 changed = hci_dev_test_and_clear_flag(hdev, HCI_BONDABLE); in set_bondable()
1592 err = send_settings_rsp(sk, MGMT_OP_SET_BONDABLE, hdev); in set_bondable()
1600 if (hdev_is_powered(hdev) && in set_bondable()
1601 hci_dev_test_flag(hdev, HCI_ADVERTISING) && in set_bondable()
1602 hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in set_bondable()
1603 hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in set_bondable()
1604 queue_work(hdev->req_workqueue, in set_bondable()
1605 &hdev->discoverable_update); in set_bondable()
1607 err = new_settings(hdev, sk); in set_bondable()
1611 hci_dev_unlock(hdev); in set_bondable()
1615 static int set_link_security(struct sock *sk, struct hci_dev *hdev, void *data, in set_link_security() argument
1623 BT_DBG("request for %s", hdev->name); in set_link_security()
1625 status = mgmt_bredr_support(hdev); in set_link_security()
1627 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1631 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1634 hci_dev_lock(hdev); in set_link_security()
1636 if (!hdev_is_powered(hdev)) { in set_link_security()
1639 if (!!cp->val != hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) { in set_link_security()
1640 hci_dev_change_flag(hdev, HCI_LINK_SECURITY); in set_link_security()
1644 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1649 err = new_settings(hdev, sk); in set_link_security()
1654 if (pending_find(MGMT_OP_SET_LINK_SECURITY, hdev)) { in set_link_security()
1655 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1662 if (test_bit(HCI_AUTH, &hdev->flags) == val) { in set_link_security()
1663 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1667 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LINK_SECURITY, hdev, data, len); in set_link_security()
1673 err = hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, sizeof(val), &val); in set_link_security()
1680 hci_dev_unlock(hdev); in set_link_security()
1684 static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_ssp() argument
1691 BT_DBG("request for %s", hdev->name); in set_ssp()
1693 status = mgmt_bredr_support(hdev); in set_ssp()
1695 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, status); in set_ssp()
1697 if (!lmp_ssp_capable(hdev)) in set_ssp()
1698 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1702 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1705 hci_dev_lock(hdev); in set_ssp()
1707 if (!hdev_is_powered(hdev)) { in set_ssp()
1711 changed = !hci_dev_test_and_set_flag(hdev, in set_ssp()
1714 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
1717 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
1720 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_ssp()
1723 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
1728 err = new_settings(hdev, sk); in set_ssp()
1733 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_ssp()
1734 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1739 if (!!cp->val == hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_ssp()
1740 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
1744 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SSP, hdev, data, len); in set_ssp()
1750 if (!cp->val && hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) in set_ssp()
1751 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in set_ssp()
1754 err = hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, 1, &cp->val); in set_ssp()
1761 hci_dev_unlock(hdev); in set_ssp()
1765 static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_hs() argument
1772 BT_DBG("request for %s", hdev->name); in set_hs()
1774 status = mgmt_bredr_support(hdev); in set_hs()
1776 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, status); in set_hs()
1778 if (!lmp_ssp_capable(hdev)) in set_hs()
1779 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1782 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_hs()
1783 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1787 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1790 hci_dev_lock(hdev); in set_hs()
1792 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_hs()
1793 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1799 changed = !hci_dev_test_and_set_flag(hdev, HCI_HS_ENABLED); in set_hs()
1801 if (hdev_is_powered(hdev)) { in set_hs()
1802 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1807 changed = hci_dev_test_and_clear_flag(hdev, HCI_HS_ENABLED); in set_hs()
1810 err = send_settings_rsp(sk, MGMT_OP_SET_HS, hdev); in set_hs()
1815 err = new_settings(hdev, sk); in set_hs()
1818 hci_dev_unlock(hdev); in set_hs()
1822 static void le_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) in le_enable_complete() argument
1824 struct cmd_lookup match = { NULL, hdev }; in le_enable_complete()
1826 hci_dev_lock(hdev); in le_enable_complete()
1831 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp, in le_enable_complete()
1836 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match); in le_enable_complete()
1838 new_settings(hdev, match.sk); in le_enable_complete()
1848 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in le_enable_complete()
1850 hci_req_init(&req, hdev); in le_enable_complete()
1851 if (ext_adv_capable(hdev)) { in le_enable_complete()
1862 hci_update_background_scan(hdev); in le_enable_complete()
1866 hci_dev_unlock(hdev); in le_enable_complete()
1869 static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_le() argument
1878 BT_DBG("request for %s", hdev->name); in set_le()
1880 if (!lmp_le_capable(hdev)) in set_le()
1881 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1885 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1897 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_le()
1899 return send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
1901 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1905 hci_dev_lock(hdev); in set_le()
1908 enabled = lmp_host_le_capable(hdev); in set_le()
1911 hci_req_clear_adv_instance(hdev, NULL, NULL, 0x00, true); in set_le()
1913 if (!hdev_is_powered(hdev) || val == enabled) { in set_le()
1916 if (val != hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le()
1917 hci_dev_change_flag(hdev, HCI_LE_ENABLED); in set_le()
1921 if (!val && hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in set_le()
1922 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_le()
1926 err = send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
1931 err = new_settings(hdev, sk); in set_le()
1936 if (pending_find(MGMT_OP_SET_LE, hdev) || in set_le()
1937 pending_find(MGMT_OP_SET_ADVERTISING, hdev)) { in set_le()
1938 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1943 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LE, hdev, data, len); in set_le()
1949 hci_req_init(&req, hdev); in set_le()
1957 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_le()
1960 if (ext_adv_capable(hdev)) in set_le()
1972 hci_dev_unlock(hdev); in set_le()
1982 static bool pending_eir_or_class(struct hci_dev *hdev) in pending_eir_or_class() argument
1986 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in pending_eir_or_class()
2018 static void mgmt_class_complete(struct hci_dev *hdev, u16 mgmt_op, u8 status) in mgmt_class_complete() argument
2022 hci_dev_lock(hdev); in mgmt_class_complete()
2024 cmd = pending_find(mgmt_op, hdev); in mgmt_class_complete()
2029 mgmt_status(status), hdev->dev_class, 3); in mgmt_class_complete()
2034 hci_dev_unlock(hdev); in mgmt_class_complete()
2037 static void add_uuid_complete(struct hci_dev *hdev, u8 status, u16 opcode) in add_uuid_complete() argument
2041 mgmt_class_complete(hdev, MGMT_OP_ADD_UUID, status); in add_uuid_complete()
2044 static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in add_uuid() argument
2052 BT_DBG("request for %s", hdev->name); in add_uuid()
2054 hci_dev_lock(hdev); in add_uuid()
2056 if (pending_eir_or_class(hdev)) { in add_uuid()
2057 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_UUID, in add_uuid()
2072 list_add_tail(&uuid->list, &hdev->uuids); in add_uuid()
2074 hci_req_init(&req, hdev); in add_uuid()
2084 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_UUID, 0, in add_uuid()
2085 hdev->dev_class, 3); in add_uuid()
2089 cmd = mgmt_pending_add(sk, MGMT_OP_ADD_UUID, hdev, data, len); in add_uuid()
2098 hci_dev_unlock(hdev); in add_uuid()
2102 static bool enable_service_cache(struct hci_dev *hdev) in enable_service_cache() argument
2104 if (!hdev_is_powered(hdev)) in enable_service_cache()
2107 if (!hci_dev_test_and_set_flag(hdev, HCI_SERVICE_CACHE)) { in enable_service_cache()
2108 queue_delayed_work(hdev->workqueue, &hdev->service_cache, in enable_service_cache()
2116 static void remove_uuid_complete(struct hci_dev *hdev, u8 status, u16 opcode) in remove_uuid_complete() argument
2120 mgmt_class_complete(hdev, MGMT_OP_REMOVE_UUID, status); in remove_uuid_complete()
2123 static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data, in remove_uuid() argument
2133 BT_DBG("request for %s", hdev->name); in remove_uuid()
2135 hci_dev_lock(hdev); in remove_uuid()
2137 if (pending_eir_or_class(hdev)) { in remove_uuid()
2138 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2144 hci_uuids_clear(hdev); in remove_uuid()
2146 if (enable_service_cache(hdev)) { in remove_uuid()
2147 err = mgmt_cmd_complete(sk, hdev->id, in remove_uuid()
2149 0, hdev->dev_class, 3); in remove_uuid()
2158 list_for_each_entry_safe(match, tmp, &hdev->uuids, list) { in remove_uuid()
2168 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2174 hci_req_init(&req, hdev); in remove_uuid()
2184 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_UUID, 0, in remove_uuid()
2185 hdev->dev_class, 3); in remove_uuid()
2189 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_UUID, hdev, data, len); in remove_uuid()
2198 hci_dev_unlock(hdev); in remove_uuid()
2202 static void set_class_complete(struct hci_dev *hdev, u8 status, u16 opcode) in set_class_complete() argument
2206 mgmt_class_complete(hdev, MGMT_OP_SET_DEV_CLASS, status); in set_class_complete()
2209 static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data, in set_dev_class() argument
2217 BT_DBG("request for %s", hdev->name); in set_dev_class()
2219 if (!lmp_bredr_capable(hdev)) in set_dev_class()
2220 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2223 hci_dev_lock(hdev); in set_dev_class()
2225 if (pending_eir_or_class(hdev)) { in set_dev_class()
2226 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2232 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2237 hdev->major_class = cp->major; in set_dev_class()
2238 hdev->minor_class = cp->minor; in set_dev_class()
2240 if (!hdev_is_powered(hdev)) { in set_dev_class()
2241 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, in set_dev_class()
2242 hdev->dev_class, 3); in set_dev_class()
2246 hci_req_init(&req, hdev); in set_dev_class()
2248 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) { in set_dev_class()
2249 hci_dev_unlock(hdev); in set_dev_class()
2250 cancel_delayed_work_sync(&hdev->service_cache); in set_dev_class()
2251 hci_dev_lock(hdev); in set_dev_class()
2262 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, in set_dev_class()
2263 hdev->dev_class, 3); in set_dev_class()
2267 cmd = mgmt_pending_add(sk, MGMT_OP_SET_DEV_CLASS, hdev, data, len); in set_dev_class()
2276 hci_dev_unlock(hdev); in set_dev_class()
2280 static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data, in load_link_keys() argument
2290 BT_DBG("request for %s", hdev->name); in load_link_keys()
2292 if (!lmp_bredr_capable(hdev)) in load_link_keys()
2293 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2298 bt_dev_err(hdev, "load_link_keys: too big key_count value %u", in load_link_keys()
2300 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2307 bt_dev_err(hdev, "load_link_keys: expected %u bytes, got %u bytes", in load_link_keys()
2309 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2314 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2317 BT_DBG("%s debug_keys %u key_count %u", hdev->name, cp->debug_keys, in load_link_keys()
2324 return mgmt_cmd_status(sk, hdev->id, in load_link_keys()
2329 hci_dev_lock(hdev); in load_link_keys()
2331 hci_link_keys_clear(hdev); in load_link_keys()
2334 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in load_link_keys()
2336 changed = hci_dev_test_and_clear_flag(hdev, in load_link_keys()
2340 new_settings(hdev, NULL); in load_link_keys()
2351 hci_add_link_key(hdev, NULL, &key->addr.bdaddr, key->val, in load_link_keys()
2355 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0); in load_link_keys()
2357 hci_dev_unlock(hdev); in load_link_keys()
2362 static int device_unpaired(struct hci_dev *hdev, bdaddr_t *bdaddr, in device_unpaired() argument
2370 return mgmt_event(MGMT_EV_DEVICE_UNPAIRED, hdev, &ev, sizeof(ev), in device_unpaired()
2374 static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data, in unpair_device() argument
2390 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2395 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2399 hci_dev_lock(hdev); in unpair_device()
2401 if (!hdev_is_powered(hdev)) { in unpair_device()
2402 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2417 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device()
2422 err = hci_remove_link_key(hdev, &cp->addr.bdaddr); in unpair_device()
2424 err = mgmt_cmd_complete(sk, hdev->id, in unpair_device()
2438 err = smp_cancel_and_remove_pairing(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2440 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2446 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2448 hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2459 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2478 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0, in unpair_device()
2480 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk); in unpair_device()
2484 cmd = mgmt_pending_add(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp, in unpair_device()
2498 hci_dev_unlock(hdev); in unpair_device()
2502 static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data, in disconnect() argument
2518 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2522 hci_dev_lock(hdev); in disconnect()
2524 if (!test_bit(HCI_UP, &hdev->flags)) { in disconnect()
2525 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2531 if (pending_find(MGMT_OP_DISCONNECT, hdev)) { in disconnect()
2532 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2538 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in disconnect()
2541 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in disconnect()
2545 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2551 cmd = mgmt_pending_add(sk, MGMT_OP_DISCONNECT, hdev, data, len); in disconnect()
2564 hci_dev_unlock(hdev); in disconnect()
2587 static int get_connections(struct sock *sk, struct hci_dev *hdev, void *data, in get_connections() argument
2598 hci_dev_lock(hdev); in get_connections()
2600 if (!hdev_is_powered(hdev)) { in get_connections()
2601 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, in get_connections()
2607 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
2620 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
2635 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, 0, rp, in get_connections()
2641 hci_dev_unlock(hdev); in get_connections()
2645 static int send_pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in send_pin_code_neg_reply() argument
2651 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, hdev, cp, in send_pin_code_neg_reply()
2658 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, in send_pin_code_neg_reply()
2666 static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data, in pin_code_reply() argument
2677 hci_dev_lock(hdev); in pin_code_reply()
2679 if (!hdev_is_powered(hdev)) { in pin_code_reply()
2680 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
2685 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in pin_code_reply()
2687 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
2697 bt_dev_err(hdev, "PIN code is not 16 bytes long"); in pin_code_reply()
2699 err = send_pin_code_neg_reply(sk, hdev, &ncp); in pin_code_reply()
2701 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
2707 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data, len); in pin_code_reply()
2719 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_REPLY, sizeof(reply), &reply); in pin_code_reply()
2724 hci_dev_unlock(hdev); in pin_code_reply()
2728 static int set_io_capability(struct sock *sk, struct hci_dev *hdev, void *data, in set_io_capability() argument
2736 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, in set_io_capability()
2739 hci_dev_lock(hdev); in set_io_capability()
2741 hdev->io_capability = cp->io_capability; in set_io_capability()
2743 BT_DBG("%s IO capability set to 0x%02x", hdev->name, in set_io_capability()
2744 hdev->io_capability); in set_io_capability()
2746 hci_dev_unlock(hdev); in set_io_capability()
2748 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, 0, in set_io_capability()
2754 struct hci_dev *hdev = conn->hdev; in find_pairing() local
2757 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in find_pairing()
2846 static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in pair_device() argument
2863 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2868 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2872 hci_dev_lock(hdev); in pair_device()
2874 if (!hdev_is_powered(hdev)) { in pair_device()
2875 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2881 if (hci_bdaddr_is_paired(hdev, &cp->addr.bdaddr, cp->addr.type)) { in pair_device()
2882 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2892 conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level, in pair_device()
2907 p = hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type); in pair_device()
2912 conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr, in pair_device()
2929 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2936 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2941 cmd = mgmt_pending_add(sk, MGMT_OP_PAIR_DEVICE, hdev, data, len); in pair_device()
2973 hci_dev_unlock(hdev); in pair_device()
2977 static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in cancel_pair_device() argument
2987 hci_dev_lock(hdev); in cancel_pair_device()
2989 if (!hdev_is_powered(hdev)) { in cancel_pair_device()
2990 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
2995 cmd = pending_find(MGMT_OP_PAIR_DEVICE, hdev); in cancel_pair_device()
2997 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3005 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3013 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0, in cancel_pair_device()
3016 hci_dev_unlock(hdev); in cancel_pair_device()
3020 static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev, in user_pairing_resp() argument
3028 hci_dev_lock(hdev); in user_pairing_resp()
3030 if (!hdev_is_powered(hdev)) { in user_pairing_resp()
3031 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3038 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &addr->bdaddr); in user_pairing_resp()
3040 conn = hci_conn_hash_lookup_le(hdev, &addr->bdaddr, in user_pairing_resp()
3044 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3053 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3057 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3064 cmd = mgmt_pending_add(sk, mgmt_op, hdev, addr, sizeof(*addr)); in user_pairing_resp()
3078 err = hci_send_cmd(hdev, hci_op, sizeof(cp), &cp); in user_pairing_resp()
3080 err = hci_send_cmd(hdev, hci_op, sizeof(addr->bdaddr), in user_pairing_resp()
3087 hci_dev_unlock(hdev); in user_pairing_resp()
3091 static int pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in pin_code_neg_reply() argument
3098 return user_pairing_resp(sk, hdev, &cp->addr, in pin_code_neg_reply()
3103 static int user_confirm_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_confirm_reply() argument
3111 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_USER_CONFIRM_REPLY, in user_confirm_reply()
3114 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_reply()
3119 static int user_confirm_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_confirm_neg_reply() argument
3126 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_neg_reply()
3131 static int user_passkey_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_passkey_reply() argument
3138 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_reply()
3143 static int user_passkey_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_passkey_neg_reply() argument
3150 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_neg_reply()
3155 static void adv_expire(struct hci_dev *hdev, u32 flags) in adv_expire() argument
3161 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in adv_expire()
3169 cancel_adv_timeout(hdev); in adv_expire()
3171 adv_instance = hci_get_next_instance(hdev, adv_instance->instance); in adv_expire()
3175 hci_req_init(&req, hdev); in adv_expire()
3184 static void set_name_complete(struct hci_dev *hdev, u8 status, u16 opcode) in set_name_complete() argument
3191 hci_dev_lock(hdev); in set_name_complete()
3193 cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev); in set_name_complete()
3200 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_name_complete()
3203 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_name_complete()
3206 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_name_complete()
3207 adv_expire(hdev, MGMT_ADV_FLAG_LOCAL_NAME); in set_name_complete()
3213 hci_dev_unlock(hdev); in set_name_complete()
3216 static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data, in set_local_name() argument
3226 hci_dev_lock(hdev); in set_local_name()
3231 if (!memcmp(hdev->dev_name, cp->name, sizeof(hdev->dev_name)) && in set_local_name()
3232 !memcmp(hdev->short_name, cp->short_name, in set_local_name()
3233 sizeof(hdev->short_name))) { in set_local_name()
3234 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3239 memcpy(hdev->short_name, cp->short_name, sizeof(hdev->short_name)); in set_local_name()
3241 if (!hdev_is_powered(hdev)) { in set_local_name()
3242 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3244 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3249 err = mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, data, in set_local_name()
3251 ext_info_changed(hdev, sk); in set_local_name()
3256 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len); in set_local_name()
3262 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3264 hci_req_init(&req, hdev); in set_local_name()
3266 if (lmp_bredr_capable(hdev)) { in set_local_name()
3274 if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING)) in set_local_name()
3275 __hci_req_update_scan_rsp_data(&req, hdev->cur_adv_instance); in set_local_name()
3282 hci_dev_unlock(hdev); in set_local_name()
3286 static int set_appearance(struct sock *sk, struct hci_dev *hdev, void *data, in set_appearance() argument
3295 if (!lmp_le_capable(hdev)) in set_appearance()
3296 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_APPEARANCE, in set_appearance()
3301 hci_dev_lock(hdev); in set_appearance()
3303 if (hdev->appearance != apperance) { in set_appearance()
3304 hdev->appearance = apperance; in set_appearance()
3306 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_appearance()
3307 adv_expire(hdev, MGMT_ADV_FLAG_APPEARANCE); in set_appearance()
3309 ext_info_changed(hdev, sk); in set_appearance()
3312 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_APPEARANCE, 0, NULL, in set_appearance()
3315 hci_dev_unlock(hdev); in set_appearance()
3320 static int get_phy_configuration(struct sock *sk, struct hci_dev *hdev, in get_phy_configuration() argument
3325 BT_DBG("sock %p %s", sk, hdev->name); in get_phy_configuration()
3327 hci_dev_lock(hdev); in get_phy_configuration()
3331 rp.supported_phys = cpu_to_le32(get_supported_phys(hdev)); in get_phy_configuration()
3332 rp.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in get_phy_configuration()
3333 rp.configurable_phys = cpu_to_le32(get_configurable_phys(hdev)); in get_phy_configuration()
3335 hci_dev_unlock(hdev); in get_phy_configuration()
3337 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_PHY_CONFIGURATION, 0, in get_phy_configuration()
3341 int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip) in mgmt_phy_configuration_changed() argument
3347 ev.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in mgmt_phy_configuration_changed()
3349 return mgmt_event(MGMT_EV_PHY_CONFIGURATION_CHANGED, hdev, &ev, in mgmt_phy_configuration_changed()
3353 static void set_default_phy_complete(struct hci_dev *hdev, u8 status, in set_default_phy_complete() argument
3360 hci_dev_lock(hdev); in set_default_phy_complete()
3362 cmd = pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev); in set_default_phy_complete()
3367 mgmt_cmd_status(cmd->sk, hdev->id, in set_default_phy_complete()
3371 mgmt_cmd_complete(cmd->sk, hdev->id, in set_default_phy_complete()
3375 mgmt_phy_configuration_changed(hdev, cmd->sk); in set_default_phy_complete()
3381 hci_dev_unlock(hdev); in set_default_phy_complete()
3384 static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, in set_phy_configuration() argument
3396 BT_DBG("sock %p %s", sk, hdev->name); in set_phy_configuration()
3398 configurable_phys = get_configurable_phys(hdev); in set_phy_configuration()
3399 supported_phys = get_supported_phys(hdev); in set_phy_configuration()
3403 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3410 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3414 if (selected_phys == get_selected_phys(hdev)) in set_phy_configuration()
3415 return mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
3419 hci_dev_lock(hdev); in set_phy_configuration()
3421 if (!hdev_is_powered(hdev)) { in set_phy_configuration()
3422 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3428 if (pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) { in set_phy_configuration()
3429 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3475 if (pkt_type != hdev->pkt_type) { in set_phy_configuration()
3476 hdev->pkt_type = pkt_type; in set_phy_configuration()
3481 (get_selected_phys(hdev) & MGMT_PHY_LE_MASK)) { in set_phy_configuration()
3483 mgmt_phy_configuration_changed(hdev, sk); in set_phy_configuration()
3485 err = mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
3492 cmd = mgmt_pending_add(sk, MGMT_OP_SET_PHY_CONFIGURATION, hdev, data, in set_phy_configuration()
3499 hci_req_init(&req, hdev); in set_phy_configuration()
3534 hci_dev_unlock(hdev); in set_phy_configuration()
3539 static void read_local_oob_data_complete(struct hci_dev *hdev, u8 status, in read_local_oob_data_complete() argument
3546 BT_DBG("%s status %u", hdev->name, status); in read_local_oob_data_complete()
3548 cmd = pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev); in read_local_oob_data_complete()
3553 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data_complete()
3564 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
3578 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
3591 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data_complete()
3598 static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_data() argument
3605 BT_DBG("%s", hdev->name); in read_local_oob_data()
3607 hci_dev_lock(hdev); in read_local_oob_data()
3609 if (!hdev_is_powered(hdev)) { in read_local_oob_data()
3610 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
3615 if (!lmp_ssp_capable(hdev)) { in read_local_oob_data()
3616 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
3621 if (pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev)) { in read_local_oob_data()
3622 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
3627 cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_DATA, hdev, NULL, 0); in read_local_oob_data()
3633 hci_req_init(&req, hdev); in read_local_oob_data()
3635 if (bredr_sc_enabled(hdev)) in read_local_oob_data()
3645 hci_dev_unlock(hdev); in read_local_oob_data()
3649 static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in add_remote_oob_data() argument
3655 BT_DBG("%s ", hdev->name); in add_remote_oob_data()
3658 return mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
3663 hci_dev_lock(hdev); in add_remote_oob_data()
3670 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
3677 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
3685 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
3699 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
3734 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
3742 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
3746 bt_dev_err(hdev, "add_remote_oob_data: invalid len of %u bytes", in add_remote_oob_data()
3748 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, in add_remote_oob_data()
3753 hci_dev_unlock(hdev); in add_remote_oob_data()
3757 static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in remove_remote_oob_data() argument
3764 BT_DBG("%s", hdev->name); in remove_remote_oob_data()
3767 return mgmt_cmd_complete(sk, hdev->id, in remove_remote_oob_data()
3772 hci_dev_lock(hdev); in remove_remote_oob_data()
3775 hci_remote_oob_data_clear(hdev); in remove_remote_oob_data()
3780 err = hci_remove_remote_oob_data(hdev, &cp->addr.bdaddr, cp->addr.type); in remove_remote_oob_data()
3787 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA, in remove_remote_oob_data()
3790 hci_dev_unlock(hdev); in remove_remote_oob_data()
3794 void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_start_discovery_complete() argument
3800 hci_dev_lock(hdev); in mgmt_start_discovery_complete()
3802 cmd = pending_find(MGMT_OP_START_DISCOVERY, hdev); in mgmt_start_discovery_complete()
3804 cmd = pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev); in mgmt_start_discovery_complete()
3807 cmd = pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev); in mgmt_start_discovery_complete()
3814 hci_dev_unlock(hdev); in mgmt_start_discovery_complete()
3817 static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, in discovery_type_is_valid() argument
3822 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
3827 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
3832 *mgmt_status = mgmt_bredr_support(hdev); in discovery_type_is_valid()
3844 static int start_discovery_internal(struct sock *sk, struct hci_dev *hdev, in start_discovery_internal() argument
3852 BT_DBG("%s", hdev->name); in start_discovery_internal()
3854 hci_dev_lock(hdev); in start_discovery_internal()
3856 if (!hdev_is_powered(hdev)) { in start_discovery_internal()
3857 err = mgmt_cmd_complete(sk, hdev->id, op, in start_discovery_internal()
3863 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_discovery_internal()
3864 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_discovery_internal()
3865 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
3870 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_discovery_internal()
3871 err = mgmt_cmd_complete(sk, hdev->id, op, status, in start_discovery_internal()
3879 hci_discovery_filter_clear(hdev); in start_discovery_internal()
3881 hdev->discovery.type = cp->type; in start_discovery_internal()
3882 hdev->discovery.report_invalid_rssi = false; in start_discovery_internal()
3884 hdev->discovery.limited = true; in start_discovery_internal()
3886 hdev->discovery.limited = false; in start_discovery_internal()
3888 cmd = mgmt_pending_add(sk, op, hdev, data, len); in start_discovery_internal()
3896 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_discovery_internal()
3897 queue_work(hdev->req_workqueue, &hdev->discov_update); in start_discovery_internal()
3901 hci_dev_unlock(hdev); in start_discovery_internal()
3905 static int start_discovery(struct sock *sk, struct hci_dev *hdev, in start_discovery() argument
3908 return start_discovery_internal(sk, hdev, MGMT_OP_START_DISCOVERY, in start_discovery()
3912 static int start_limited_discovery(struct sock *sk, struct hci_dev *hdev, in start_limited_discovery() argument
3915 return start_discovery_internal(sk, hdev, in start_limited_discovery()
3927 static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, in start_service_discovery() argument
3937 BT_DBG("%s", hdev->name); in start_service_discovery()
3939 hci_dev_lock(hdev); in start_service_discovery()
3941 if (!hdev_is_powered(hdev)) { in start_service_discovery()
3942 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
3949 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_service_discovery()
3950 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_service_discovery()
3951 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
3960 bt_dev_err(hdev, "service_discovery: too big uuid_count value %u", in start_service_discovery()
3962 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
3971 bt_dev_err(hdev, "service_discovery: expected %u bytes, got %u bytes", in start_service_discovery()
3973 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
3980 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_service_discovery()
3981 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
3988 hdev, data, len); in start_service_discovery()
3999 hci_discovery_filter_clear(hdev); in start_service_discovery()
4001 hdev->discovery.result_filtering = true; in start_service_discovery()
4002 hdev->discovery.type = cp->type; in start_service_discovery()
4003 hdev->discovery.rssi = cp->rssi; in start_service_discovery()
4004 hdev->discovery.uuid_count = uuid_count; in start_service_discovery()
4007 hdev->discovery.uuids = kmemdup(cp->uuids, uuid_count * 16, in start_service_discovery()
4009 if (!hdev->discovery.uuids) { in start_service_discovery()
4010 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4019 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_service_discovery()
4020 queue_work(hdev->req_workqueue, &hdev->discov_update); in start_service_discovery()
4024 hci_dev_unlock(hdev); in start_service_discovery()
4028 void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_stop_discovery_complete() argument
4034 hci_dev_lock(hdev); in mgmt_stop_discovery_complete()
4036 cmd = pending_find(MGMT_OP_STOP_DISCOVERY, hdev); in mgmt_stop_discovery_complete()
4042 hci_dev_unlock(hdev); in mgmt_stop_discovery_complete()
4045 static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, in stop_discovery() argument
4052 BT_DBG("%s", hdev->name); in stop_discovery()
4054 hci_dev_lock(hdev); in stop_discovery()
4056 if (!hci_discovery_active(hdev)) { in stop_discovery()
4057 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
4063 if (hdev->discovery.type != mgmt_cp->type) { in stop_discovery()
4064 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
4070 cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, hdev, data, len); in stop_discovery()
4078 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in stop_discovery()
4079 queue_work(hdev->req_workqueue, &hdev->discov_update); in stop_discovery()
4083 hci_dev_unlock(hdev); in stop_discovery()
4087 static int confirm_name(struct sock *sk, struct hci_dev *hdev, void *data, in confirm_name() argument
4094 BT_DBG("%s", hdev->name); in confirm_name()
4096 hci_dev_lock(hdev); in confirm_name()
4098 if (!hci_discovery_active(hdev)) { in confirm_name()
4099 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
4105 e = hci_inquiry_cache_lookup_unknown(hdev, &cp->addr.bdaddr); in confirm_name()
4107 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
4118 hci_inquiry_cache_update_resolve(hdev, e); in confirm_name()
4121 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, 0, in confirm_name()
4125 hci_dev_unlock(hdev); in confirm_name()
4129 static int block_device(struct sock *sk, struct hci_dev *hdev, void *data, in block_device() argument
4136 BT_DBG("%s", hdev->name); in block_device()
4139 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, in block_device()
4143 hci_dev_lock(hdev); in block_device()
4145 err = hci_bdaddr_list_add(&hdev->blacklist, &cp->addr.bdaddr, in block_device()
4152 mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &cp->addr, sizeof(cp->addr), in block_device()
4157 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status, in block_device()
4160 hci_dev_unlock(hdev); in block_device()
4165 static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data, in unblock_device() argument
4172 BT_DBG("%s", hdev->name); in unblock_device()
4175 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, in unblock_device()
4179 hci_dev_lock(hdev); in unblock_device()
4181 err = hci_bdaddr_list_del(&hdev->blacklist, &cp->addr.bdaddr, in unblock_device()
4188 mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &cp->addr, sizeof(cp->addr), in unblock_device()
4193 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status, in unblock_device()
4196 hci_dev_unlock(hdev); in unblock_device()
4201 static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_id() argument
4209 BT_DBG("%s", hdev->name); in set_device_id()
4214 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, in set_device_id()
4217 hci_dev_lock(hdev); in set_device_id()
4219 hdev->devid_source = source; in set_device_id()
4220 hdev->devid_vendor = __le16_to_cpu(cp->vendor); in set_device_id()
4221 hdev->devid_product = __le16_to_cpu(cp->product); in set_device_id()
4222 hdev->devid_version = __le16_to_cpu(cp->version); in set_device_id()
4224 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, 0, in set_device_id()
4227 hci_req_init(&req, hdev); in set_device_id()
4231 hci_dev_unlock(hdev); in set_device_id()
4236 static void enable_advertising_instance(struct hci_dev *hdev, u8 status, in enable_advertising_instance() argument
4242 static void set_advertising_complete(struct hci_dev *hdev, u8 status, in set_advertising_complete() argument
4245 struct cmd_lookup match = { NULL, hdev }; in set_advertising_complete()
4251 hci_dev_lock(hdev); in set_advertising_complete()
4256 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, in set_advertising_complete()
4261 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_advertising_complete()
4262 hci_dev_set_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
4264 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
4266 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, settings_rsp, in set_advertising_complete()
4269 new_settings(hdev, match.sk); in set_advertising_complete()
4277 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in set_advertising_complete()
4278 list_empty(&hdev->adv_instances)) in set_advertising_complete()
4281 instance = hdev->cur_adv_instance; in set_advertising_complete()
4283 adv_instance = list_first_entry_or_null(&hdev->adv_instances, in set_advertising_complete()
4291 hci_req_init(&req, hdev); in set_advertising_complete()
4299 bt_dev_err(hdev, "failed to re-configure advertising"); in set_advertising_complete()
4302 hci_dev_unlock(hdev); in set_advertising_complete()
4305 static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, in set_advertising() argument
4314 BT_DBG("request for %s", hdev->name); in set_advertising()
4316 status = mgmt_le_support(hdev); in set_advertising()
4318 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
4322 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
4325 hci_dev_lock(hdev); in set_advertising()
4334 if (!hdev_is_powered(hdev) || in set_advertising()
4335 (val == hci_dev_test_flag(hdev, HCI_ADVERTISING) && in set_advertising()
4336 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) || in set_advertising()
4337 hci_conn_num(hdev, LE_LINK) > 0 || in set_advertising()
4338 (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_advertising()
4339 hdev->le_scan_type == LE_SCAN_ACTIVE)) { in set_advertising()
4343 hdev->cur_adv_instance = 0x00; in set_advertising()
4344 changed = !hci_dev_test_and_set_flag(hdev, HCI_ADVERTISING); in set_advertising()
4346 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
4348 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
4350 changed = hci_dev_test_and_clear_flag(hdev, HCI_ADVERTISING); in set_advertising()
4351 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
4354 err = send_settings_rsp(sk, MGMT_OP_SET_ADVERTISING, hdev); in set_advertising()
4359 err = new_settings(hdev, sk); in set_advertising()
4364 if (pending_find(MGMT_OP_SET_ADVERTISING, hdev) || in set_advertising()
4365 pending_find(MGMT_OP_SET_LE, hdev)) { in set_advertising()
4366 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
4371 cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING, hdev, data, len); in set_advertising()
4377 hci_req_init(&req, hdev); in set_advertising()
4380 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
4382 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
4384 cancel_adv_timeout(hdev); in set_advertising()
4391 hdev->cur_adv_instance = 0x00; in set_advertising()
4393 if (ext_adv_capable(hdev)) { in set_advertising()
4409 hci_dev_unlock(hdev); in set_advertising()
4413 static int set_static_address(struct sock *sk, struct hci_dev *hdev, in set_static_address() argument
4419 BT_DBG("%s", hdev->name); in set_static_address()
4421 if (!lmp_le_capable(hdev)) in set_static_address()
4422 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
4425 if (hdev_is_powered(hdev)) in set_static_address()
4426 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
4431 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
4437 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
4442 hci_dev_lock(hdev); in set_static_address()
4444 bacpy(&hdev->static_addr, &cp->bdaddr); in set_static_address()
4446 err = send_settings_rsp(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev); in set_static_address()
4450 err = new_settings(hdev, sk); in set_static_address()
4453 hci_dev_unlock(hdev); in set_static_address()
4457 static int set_scan_params(struct sock *sk, struct hci_dev *hdev, in set_scan_params() argument
4464 BT_DBG("%s", hdev->name); in set_scan_params()
4466 if (!lmp_le_capable(hdev)) in set_scan_params()
4467 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
4473 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
4479 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
4483 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
4486 hci_dev_lock(hdev); in set_scan_params()
4488 hdev->le_scan_interval = interval; in set_scan_params()
4489 hdev->le_scan_window = window; in set_scan_params()
4491 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, 0, in set_scan_params()
4497 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_scan_params()
4498 hdev->discovery.state == DISCOVERY_STOPPED) { in set_scan_params()
4501 hci_req_init(&req, hdev); in set_scan_params()
4509 hci_dev_unlock(hdev); in set_scan_params()
4514 static void fast_connectable_complete(struct hci_dev *hdev, u8 status, in fast_connectable_complete() argument
4521 hci_dev_lock(hdev); in fast_connectable_complete()
4523 cmd = pending_find(MGMT_OP_SET_FAST_CONNECTABLE, hdev); in fast_connectable_complete()
4528 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in fast_connectable_complete()
4534 hci_dev_set_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
4536 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
4538 send_settings_rsp(cmd->sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in fast_connectable_complete()
4539 new_settings(hdev, cmd->sk); in fast_connectable_complete()
4545 hci_dev_unlock(hdev); in fast_connectable_complete()
4548 static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev, in set_fast_connectable() argument
4556 BT_DBG("%s", hdev->name); in set_fast_connectable()
4558 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in set_fast_connectable()
4559 hdev->hci_ver < BLUETOOTH_VER_1_2) in set_fast_connectable()
4560 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
4564 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
4567 hci_dev_lock(hdev); in set_fast_connectable()
4569 if (pending_find(MGMT_OP_SET_FAST_CONNECTABLE, hdev)) { in set_fast_connectable()
4570 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
4575 if (!!cp->val == hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) { in set_fast_connectable()
4577 hdev); in set_fast_connectable()
4581 if (!hdev_is_powered(hdev)) { in set_fast_connectable()
4582 hci_dev_change_flag(hdev, HCI_FAST_CONNECTABLE); in set_fast_connectable()
4584 hdev); in set_fast_connectable()
4585 new_settings(hdev, sk); in set_fast_connectable()
4589 cmd = mgmt_pending_add(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev, in set_fast_connectable()
4596 hci_req_init(&req, hdev); in set_fast_connectable()
4602 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
4608 hci_dev_unlock(hdev); in set_fast_connectable()
4613 static void set_bredr_complete(struct hci_dev *hdev, u8 status, u16 opcode) in set_bredr_complete() argument
4619 hci_dev_lock(hdev); in set_bredr_complete()
4621 cmd = pending_find(MGMT_OP_SET_BREDR, hdev); in set_bredr_complete()
4631 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in set_bredr_complete()
4635 send_settings_rsp(cmd->sk, MGMT_OP_SET_BREDR, hdev); in set_bredr_complete()
4636 new_settings(hdev, cmd->sk); in set_bredr_complete()
4642 hci_dev_unlock(hdev); in set_bredr_complete()
4645 static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_bredr() argument
4652 BT_DBG("request for %s", hdev->name); in set_bredr()
4654 if (!lmp_bredr_capable(hdev) || !lmp_le_capable(hdev)) in set_bredr()
4655 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
4658 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_bredr()
4659 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
4663 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
4666 hci_dev_lock(hdev); in set_bredr()
4668 if (cp->val == hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_bredr()
4669 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
4673 if (!hdev_is_powered(hdev)) { in set_bredr()
4675 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_bredr()
4676 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_bredr()
4677 hci_dev_clear_flag(hdev, HCI_LINK_SECURITY); in set_bredr()
4678 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in set_bredr()
4679 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_bredr()
4682 hci_dev_change_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
4684 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
4688 err = new_settings(hdev, sk); in set_bredr()
4694 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
4712 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_bredr()
4713 (bacmp(&hdev->static_addr, BDADDR_ANY) || in set_bredr()
4714 hci_dev_test_flag(hdev, HCI_SC_ENABLED))) { in set_bredr()
4715 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
4721 if (pending_find(MGMT_OP_SET_BREDR, hdev)) { in set_bredr()
4722 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
4727 cmd = mgmt_pending_add(sk, MGMT_OP_SET_BREDR, hdev, data, len); in set_bredr()
4736 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
4738 hci_req_init(&req, hdev); in set_bredr()
4746 __hci_req_update_adv_data(&req, hdev->cur_adv_instance); in set_bredr()
4753 hci_dev_unlock(hdev); in set_bredr()
4757 static void sc_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) in sc_enable_complete() argument
4762 BT_DBG("%s status %u", hdev->name, status); in sc_enable_complete()
4764 hci_dev_lock(hdev); in sc_enable_complete()
4766 cmd = pending_find(MGMT_OP_SET_SECURE_CONN, hdev); in sc_enable_complete()
4780 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in sc_enable_complete()
4781 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in sc_enable_complete()
4784 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in sc_enable_complete()
4785 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in sc_enable_complete()
4788 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in sc_enable_complete()
4789 hci_dev_set_flag(hdev, HCI_SC_ONLY); in sc_enable_complete()
4793 send_settings_rsp(cmd->sk, MGMT_OP_SET_SECURE_CONN, hdev); in sc_enable_complete()
4794 new_settings(hdev, cmd->sk); in sc_enable_complete()
4799 hci_dev_unlock(hdev); in sc_enable_complete()
4802 static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, in set_secure_conn() argument
4811 BT_DBG("request for %s", hdev->name); in set_secure_conn()
4813 if (!lmp_sc_capable(hdev) && in set_secure_conn()
4814 !hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_secure_conn()
4815 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
4818 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_secure_conn()
4819 lmp_sc_capable(hdev) && in set_secure_conn()
4820 !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_secure_conn()
4821 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
4825 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
4828 hci_dev_lock(hdev); in set_secure_conn()
4830 if (!hdev_is_powered(hdev) || !lmp_sc_capable(hdev) || in set_secure_conn()
4831 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_secure_conn()
4835 changed = !hci_dev_test_and_set_flag(hdev, in set_secure_conn()
4838 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
4840 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
4842 changed = hci_dev_test_and_clear_flag(hdev, in set_secure_conn()
4844 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
4847 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
4852 err = new_settings(hdev, sk); in set_secure_conn()
4857 if (pending_find(MGMT_OP_SET_SECURE_CONN, hdev)) { in set_secure_conn()
4858 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
4865 if (val == hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in set_secure_conn()
4866 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in set_secure_conn()
4867 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
4871 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len); in set_secure_conn()
4877 hci_req_init(&req, hdev); in set_secure_conn()
4886 hci_dev_unlock(hdev); in set_secure_conn()
4890 static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, in set_debug_keys() argument
4897 BT_DBG("request for %s", hdev->name); in set_debug_keys()
4900 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEBUG_KEYS, in set_debug_keys()
4903 hci_dev_lock(hdev); in set_debug_keys()
4906 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in set_debug_keys()
4908 changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
4912 use_changed = !hci_dev_test_and_set_flag(hdev, in set_debug_keys()
4915 use_changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
4918 if (hdev_is_powered(hdev) && use_changed && in set_debug_keys()
4919 hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_debug_keys()
4921 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in set_debug_keys()
4925 err = send_settings_rsp(sk, MGMT_OP_SET_DEBUG_KEYS, hdev); in set_debug_keys()
4930 err = new_settings(hdev, sk); in set_debug_keys()
4933 hci_dev_unlock(hdev); in set_debug_keys()
4937 static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data, in set_privacy() argument
4944 BT_DBG("request for %s", hdev->name); in set_privacy()
4946 if (!lmp_le_capable(hdev)) in set_privacy()
4947 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
4951 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
4954 if (hdev_is_powered(hdev)) in set_privacy()
4955 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
4958 hci_dev_lock(hdev); in set_privacy()
4963 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in set_privacy()
4966 changed = !hci_dev_test_and_set_flag(hdev, HCI_PRIVACY); in set_privacy()
4967 memcpy(hdev->irk, cp->irk, sizeof(hdev->irk)); in set_privacy()
4968 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
4969 hci_adv_instances_set_rpa_expired(hdev, true); in set_privacy()
4971 hci_dev_set_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
4973 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
4975 changed = hci_dev_test_and_clear_flag(hdev, HCI_PRIVACY); in set_privacy()
4976 memset(hdev->irk, 0, sizeof(hdev->irk)); in set_privacy()
4977 hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
4978 hci_adv_instances_set_rpa_expired(hdev, false); in set_privacy()
4979 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
4982 err = send_settings_rsp(sk, MGMT_OP_SET_PRIVACY, hdev); in set_privacy()
4987 err = new_settings(hdev, sk); in set_privacy()
4990 hci_dev_unlock(hdev); in set_privacy()
5010 static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data, in load_irks() argument
5019 BT_DBG("request for %s", hdev->name); in load_irks()
5021 if (!lmp_le_capable(hdev)) in load_irks()
5022 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
5027 bt_dev_err(hdev, "load_irks: too big irk_count value %u", in load_irks()
5029 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
5035 bt_dev_err(hdev, "load_irks: expected %u bytes, got %u bytes", in load_irks()
5037 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
5041 BT_DBG("%s irk_count %u", hdev->name, irk_count); in load_irks()
5047 return mgmt_cmd_status(sk, hdev->id, in load_irks()
5052 hci_dev_lock(hdev); in load_irks()
5054 hci_smp_irks_clear(hdev); in load_irks()
5059 hci_add_irk(hdev, &irk->addr.bdaddr, in load_irks()
5064 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in load_irks()
5066 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_IRKS, 0, NULL, 0); in load_irks()
5068 hci_dev_unlock(hdev); in load_irks()
5092 static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev, in load_long_term_keys() argument
5101 BT_DBG("request for %s", hdev->name); in load_long_term_keys()
5103 if (!lmp_le_capable(hdev)) in load_long_term_keys()
5104 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
5109 bt_dev_err(hdev, "load_ltks: too big key_count value %u", in load_long_term_keys()
5111 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
5118 bt_dev_err(hdev, "load_keys: expected %u bytes, got %u bytes", in load_long_term_keys()
5120 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
5124 BT_DBG("%s key_count %u", hdev->name, key_count); in load_long_term_keys()
5130 return mgmt_cmd_status(sk, hdev->id, in load_long_term_keys()
5135 hci_dev_lock(hdev); in load_long_term_keys()
5137 hci_smp_ltks_clear(hdev); in load_long_term_keys()
5168 hci_add_ltk(hdev, &key->addr.bdaddr, in load_long_term_keys()
5173 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 0, in load_long_term_keys()
5176 hci_dev_unlock(hdev); in load_long_term_keys()
5208 static void conn_info_refresh_complete(struct hci_dev *hdev, u8 hci_status, in conn_info_refresh_complete() argument
5219 hci_dev_lock(hdev); in conn_info_refresh_complete()
5230 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_RSSI); in conn_info_refresh_complete()
5232 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER); in conn_info_refresh_complete()
5239 bt_dev_err(hdev, "invalid sent_cmd in conn_info response"); in conn_info_refresh_complete()
5244 conn = hci_conn_hash_lookup_handle(hdev, handle); in conn_info_refresh_complete()
5246 bt_dev_err(hdev, "unknown handle (%d) in conn_info response", in conn_info_refresh_complete()
5251 cmd = pending_find_data(MGMT_OP_GET_CONN_INFO, hdev, conn); in conn_info_refresh_complete()
5259 hci_dev_unlock(hdev); in conn_info_refresh_complete()
5262 static int get_conn_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_conn_info() argument
5271 BT_DBG("%s", hdev->name); in get_conn_info()
5278 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
5282 hci_dev_lock(hdev); in get_conn_info()
5284 if (!hdev_is_powered(hdev)) { in get_conn_info()
5285 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
5292 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info()
5295 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info()
5298 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
5304 if (pending_find_data(MGMT_OP_GET_CONN_INFO, hdev, conn)) { in get_conn_info()
5305 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
5313 conn_info_age = hdev->conn_info_min_age + in get_conn_info()
5314 prandom_u32_max(hdev->conn_info_max_age - in get_conn_info()
5315 hdev->conn_info_min_age); in get_conn_info()
5328 hci_req_init(&req, hdev); in get_conn_info()
5356 cmd = mgmt_pending_add(sk, MGMT_OP_GET_CONN_INFO, hdev, in get_conn_info()
5374 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
5379 hci_dev_unlock(hdev); in get_conn_info()
5387 struct hci_dev *hdev; in clock_info_cmd_complete() local
5396 hdev = hci_dev_get(cmd->index); in clock_info_cmd_complete()
5397 if (hdev) { in clock_info_cmd_complete()
5398 rp.local_clock = cpu_to_le32(hdev->clock); in clock_info_cmd_complete()
5399 hci_dev_put(hdev); in clock_info_cmd_complete()
5419 static void get_clock_info_complete(struct hci_dev *hdev, u8 status, u16 opcode) in get_clock_info_complete() argument
5425 BT_DBG("%s status %u", hdev->name, status); in get_clock_info_complete()
5427 hci_dev_lock(hdev); in get_clock_info_complete()
5429 hci_cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK); in get_clock_info_complete()
5435 conn = hci_conn_hash_lookup_handle(hdev, handle); in get_clock_info_complete()
5440 cmd = pending_find_data(MGMT_OP_GET_CLOCK_INFO, hdev, conn); in get_clock_info_complete()
5448 hci_dev_unlock(hdev); in get_clock_info_complete()
5451 static int get_clock_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_clock_info() argument
5462 BT_DBG("%s", hdev->name); in get_clock_info()
5469 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
5473 hci_dev_lock(hdev); in get_clock_info()
5475 if (!hdev_is_powered(hdev)) { in get_clock_info()
5476 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
5483 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_clock_info()
5486 err = mgmt_cmd_complete(sk, hdev->id, in get_clock_info()
5496 cmd = mgmt_pending_add(sk, MGMT_OP_GET_CLOCK_INFO, hdev, data, len); in get_clock_info()
5504 hci_req_init(&req, hdev); in get_clock_info()
5523 hci_dev_unlock(hdev); in get_clock_info()
5527 static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type) in is_connected() argument
5531 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, addr); in is_connected()
5545 static int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, in hci_conn_params_set() argument
5550 params = hci_conn_params_add(hdev, addr, addr_type); in hci_conn_params_set()
5566 list_add(&params->action, &hdev->pend_le_conns); in hci_conn_params_set()
5570 list_add(&params->action, &hdev->pend_le_conns); in hci_conn_params_set()
5572 list_add(&params->action, &hdev->pend_le_reports); in hci_conn_params_set()
5576 if (!is_connected(hdev, addr, addr_type)) in hci_conn_params_set()
5577 list_add(&params->action, &hdev->pend_le_conns); in hci_conn_params_set()
5589 static void device_added(struct sock *sk, struct hci_dev *hdev, in device_added() argument
5598 mgmt_event(MGMT_EV_DEVICE_ADDED, hdev, &ev, sizeof(ev), sk); in device_added()
5601 static int add_device(struct sock *sk, struct hci_dev *hdev, in add_device() argument
5608 BT_DBG("%s", hdev->name); in add_device()
5612 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
5617 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
5621 hci_dev_lock(hdev); in add_device()
5626 err = mgmt_cmd_complete(sk, hdev->id, in add_device()
5633 err = hci_bdaddr_list_add(&hdev->whitelist, &cp->addr.bdaddr, in add_device()
5638 hci_req_update_scan(hdev); in add_device()
5658 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
5667 if (hci_conn_params_set(hdev, &cp->addr.bdaddr, addr_type, in add_device()
5669 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
5675 hci_update_background_scan(hdev); in add_device()
5678 device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action); in add_device()
5680 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
5685 hci_dev_unlock(hdev); in add_device()
5689 static void device_removed(struct sock *sk, struct hci_dev *hdev, in device_removed() argument
5697 mgmt_event(MGMT_EV_DEVICE_REMOVED, hdev, &ev, sizeof(ev), sk); in device_removed()
5700 static int remove_device(struct sock *sk, struct hci_dev *hdev, in remove_device() argument
5706 BT_DBG("%s", hdev->name); in remove_device()
5708 hci_dev_lock(hdev); in remove_device()
5715 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
5723 err = hci_bdaddr_list_del(&hdev->whitelist, in remove_device()
5727 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
5735 hci_req_update_scan(hdev); in remove_device()
5737 device_removed(sk, hdev, &cp->addr.bdaddr, in remove_device()
5750 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
5757 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in remove_device()
5760 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
5769 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
5779 hci_update_background_scan(hdev); in remove_device()
5781 device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type); in remove_device()
5787 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
5794 list_for_each_entry_safe(b, btmp, &hdev->whitelist, list) { in remove_device()
5795 device_removed(sk, hdev, &b->bdaddr, b->bdaddr_type); in remove_device()
5800 hci_req_update_scan(hdev); in remove_device()
5802 list_for_each_entry_safe(p, tmp, &hdev->le_conn_params, list) { in remove_device()
5805 device_removed(sk, hdev, &p->addr, p->addr_type); in remove_device()
5817 hci_update_background_scan(hdev); in remove_device()
5821 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, in remove_device()
5825 hci_dev_unlock(hdev); in remove_device()
5829 static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data, in load_conn_param() argument
5838 if (!lmp_le_capable(hdev)) in load_conn_param()
5839 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
5844 bt_dev_err(hdev, "load_conn_param: too big param_count value %u", in load_conn_param()
5846 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
5853 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes", in load_conn_param()
5855 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
5859 BT_DBG("%s param_count %u", hdev->name, param_count); in load_conn_param()
5861 hci_dev_lock(hdev); in load_conn_param()
5863 hci_conn_params_clear_disabled(hdev); in load_conn_param()
5879 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
5892 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
5896 hci_param = hci_conn_params_add(hdev, &param->addr.bdaddr, in load_conn_param()
5899 bt_dev_err(hdev, "failed to add connection parameters"); in load_conn_param()
5909 hci_dev_unlock(hdev); in load_conn_param()
5911 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 0, in load_conn_param()
5915 static int set_external_config(struct sock *sk, struct hci_dev *hdev, in set_external_config() argument
5922 BT_DBG("%s", hdev->name); in set_external_config()
5924 if (hdev_is_powered(hdev)) in set_external_config()
5925 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
5929 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
5932 if (!test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in set_external_config()
5933 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
5936 hci_dev_lock(hdev); in set_external_config()
5939 changed = !hci_dev_test_and_set_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
5941 changed = hci_dev_test_and_clear_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
5943 err = send_options_rsp(sk, MGMT_OP_SET_EXTERNAL_CONFIG, hdev); in set_external_config()
5950 err = new_options(hdev, sk); in set_external_config()
5952 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) == is_configured(hdev)) { in set_external_config()
5953 mgmt_index_removed(hdev); in set_external_config()
5955 if (hci_dev_test_and_change_flag(hdev, HCI_UNCONFIGURED)) { in set_external_config()
5956 hci_dev_set_flag(hdev, HCI_CONFIG); in set_external_config()
5957 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_external_config()
5959 queue_work(hdev->req_workqueue, &hdev->power_on); in set_external_config()
5961 set_bit(HCI_RAW, &hdev->flags); in set_external_config()
5962 mgmt_index_added(hdev); in set_external_config()
5967 hci_dev_unlock(hdev); in set_external_config()
5971 static int set_public_address(struct sock *sk, struct hci_dev *hdev, in set_public_address() argument
5978 BT_DBG("%s", hdev->name); in set_public_address()
5980 if (hdev_is_powered(hdev)) in set_public_address()
5981 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
5985 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
5988 if (!hdev->set_bdaddr) in set_public_address()
5989 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
5992 hci_dev_lock(hdev); in set_public_address()
5994 changed = !!bacmp(&hdev->public_addr, &cp->bdaddr); in set_public_address()
5995 bacpy(&hdev->public_addr, &cp->bdaddr); in set_public_address()
5997 err = send_options_rsp(sk, MGMT_OP_SET_PUBLIC_ADDRESS, hdev); in set_public_address()
6004 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in set_public_address()
6005 err = new_options(hdev, sk); in set_public_address()
6007 if (is_configured(hdev)) { in set_public_address()
6008 mgmt_index_removed(hdev); in set_public_address()
6010 hci_dev_clear_flag(hdev, HCI_UNCONFIGURED); in set_public_address()
6012 hci_dev_set_flag(hdev, HCI_CONFIG); in set_public_address()
6013 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_public_address()
6015 queue_work(hdev->req_workqueue, &hdev->power_on); in set_public_address()
6019 hci_dev_unlock(hdev); in set_public_address()
6023 static void read_local_oob_ext_data_complete(struct hci_dev *hdev, u8 status, in read_local_oob_ext_data_complete() argument
6033 BT_DBG("%s status %u", hdev->name, status); in read_local_oob_ext_data_complete()
6035 cmd = pending_find(MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev); in read_local_oob_ext_data_complete()
6075 if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in read_local_oob_ext_data_complete()
6098 hdev->dev_class, 3); in read_local_oob_ext_data_complete()
6118 err = mgmt_cmd_complete(cmd->sk, hdev->id, in read_local_oob_ext_data_complete()
6126 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data_complete()
6134 static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk, in read_local_ssp_oob_req() argument
6141 cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev, in read_local_ssp_oob_req()
6146 hci_req_init(&req, hdev); in read_local_ssp_oob_req()
6148 if (bredr_sc_enabled(hdev)) in read_local_ssp_oob_req()
6162 static int read_local_oob_ext_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_ext_data() argument
6172 BT_DBG("%s", hdev->name); in read_local_oob_ext_data()
6174 if (hdev_is_powered(hdev)) { in read_local_oob_ext_data()
6177 status = mgmt_bredr_support(hdev); in read_local_oob_ext_data()
6184 status = mgmt_le_support(hdev); in read_local_oob_ext_data()
6208 hci_dev_lock(hdev); in read_local_oob_ext_data()
6213 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in read_local_oob_ext_data()
6214 err = read_local_ssp_oob_req(hdev, sk, cp); in read_local_oob_ext_data()
6215 hci_dev_unlock(hdev); in read_local_oob_ext_data()
6224 hdev->dev_class, 3); in read_local_oob_ext_data()
6228 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in read_local_oob_ext_data()
6229 smp_generate_oob(hdev, hash, rand) < 0) { in read_local_oob_ext_data()
6230 hci_dev_unlock(hdev); in read_local_oob_ext_data()
6245 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { in read_local_oob_ext_data()
6246 hci_dev_unlock(hdev); in read_local_oob_ext_data()
6251 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in read_local_oob_ext_data()
6252 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in read_local_oob_ext_data()
6253 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in read_local_oob_ext_data()
6254 bacmp(&hdev->static_addr, BDADDR_ANY))) { in read_local_oob_ext_data()
6255 memcpy(addr, &hdev->static_addr, 6); in read_local_oob_ext_data()
6258 memcpy(addr, &hdev->bdaddr, 6); in read_local_oob_ext_data()
6265 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in read_local_oob_ext_data()
6273 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) { in read_local_oob_ext_data()
6283 flags = mgmt_get_adv_discov_flags(hdev); in read_local_oob_ext_data()
6285 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in read_local_oob_ext_data()
6293 hci_dev_unlock(hdev); in read_local_oob_ext_data()
6303 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, in read_local_oob_ext_data()
6308 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data()
6318 static u32 get_supported_adv_flags(struct hci_dev *hdev) in get_supported_adv_flags() argument
6332 if ((hdev->adv_tx_power != HCI_TX_POWER_INVALID) || in get_supported_adv_flags()
6333 ext_adv_capable(hdev)) in get_supported_adv_flags()
6336 if (ext_adv_capable(hdev)) { in get_supported_adv_flags()
6339 if (hdev->le_features[1] & HCI_LE_PHY_2M) in get_supported_adv_flags()
6342 if (hdev->le_features[1] & HCI_LE_PHY_CODED) in get_supported_adv_flags()
6349 static int read_adv_features(struct sock *sk, struct hci_dev *hdev, in read_adv_features() argument
6359 BT_DBG("%s", hdev->name); in read_adv_features()
6361 if (!lmp_le_capable(hdev)) in read_adv_features()
6362 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
6365 hci_dev_lock(hdev); in read_adv_features()
6367 rp_len = sizeof(*rp) + hdev->adv_instance_cnt; in read_adv_features()
6370 hci_dev_unlock(hdev); in read_adv_features()
6374 supported_flags = get_supported_adv_flags(hdev); in read_adv_features()
6380 rp->num_instances = hdev->adv_instance_cnt; in read_adv_features()
6383 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in read_adv_features()
6388 hci_dev_unlock(hdev); in read_adv_features()
6390 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
6398 static u8 calculate_name_len(struct hci_dev *hdev) in calculate_name_len() argument
6402 return append_local_name(hdev, buf, 0); in calculate_name_len()
6405 static u8 tlv_data_max_len(struct hci_dev *hdev, u32 adv_flags, in tlv_data_max_len() argument
6420 max_len -= calculate_name_len(hdev); in tlv_data_max_len()
6451 static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data, in tlv_data_is_valid() argument
6457 max_len = tlv_data_max_len(hdev, adv_flags, is_adv_data); in tlv_data_is_valid()
6493 static void add_advertising_complete(struct hci_dev *hdev, u8 status, in add_advertising_complete() argument
6504 hci_dev_lock(hdev); in add_advertising_complete()
6506 cmd = pending_find(MGMT_OP_ADD_ADVERTISING, hdev); in add_advertising_complete()
6508 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) { in add_advertising_complete()
6519 if (hdev->cur_adv_instance == instance) in add_advertising_complete()
6520 cancel_adv_timeout(hdev); in add_advertising_complete()
6522 hci_remove_adv_instance(hdev, instance); in add_advertising_complete()
6523 mgmt_advertising_removed(cmd ? cmd->sk : NULL, hdev, instance); in add_advertising_complete()
6542 hci_dev_unlock(hdev); in add_advertising_complete()
6545 static int add_advertising(struct sock *sk, struct hci_dev *hdev, in add_advertising() argument
6554 unsigned int prev_instance_cnt = hdev->adv_instance_cnt; in add_advertising()
6561 BT_DBG("%s", hdev->name); in add_advertising()
6563 status = mgmt_le_support(hdev); in add_advertising()
6565 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
6569 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
6573 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
6583 supported_flags = get_supported_adv_flags(hdev); in add_advertising()
6587 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
6590 hci_dev_lock(hdev); in add_advertising()
6592 if (timeout && !hdev_is_powered(hdev)) { in add_advertising()
6593 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
6598 if (pending_find(MGMT_OP_ADD_ADVERTISING, hdev) || in add_advertising()
6599 pending_find(MGMT_OP_REMOVE_ADVERTISING, hdev) || in add_advertising()
6600 pending_find(MGMT_OP_SET_LE, hdev)) { in add_advertising()
6601 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
6606 if (!tlv_data_is_valid(hdev, flags, cp->data, cp->adv_data_len, true) || in add_advertising()
6607 !tlv_data_is_valid(hdev, flags, cp->data + cp->adv_data_len, in add_advertising()
6609 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
6614 err = hci_add_adv_instance(hdev, cp->instance, flags, in add_advertising()
6620 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
6628 if (hdev->adv_instance_cnt > prev_instance_cnt) in add_advertising()
6629 mgmt_advertising_added(sk, hdev, cp->instance); in add_advertising()
6631 if (hdev->cur_adv_instance == cp->instance) { in add_advertising()
6637 cancel_adv_timeout(hdev); in add_advertising()
6639 next_instance = hci_get_next_instance(hdev, cp->instance); in add_advertising()
6642 } else if (!hdev->adv_instance_timeout) { in add_advertising()
6653 if (!hdev_is_powered(hdev) || in add_advertising()
6654 hci_dev_test_flag(hdev, HCI_ADVERTISING) || in add_advertising()
6657 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
6665 cmd = mgmt_pending_add(sk, MGMT_OP_ADD_ADVERTISING, hdev, data, in add_advertising()
6672 hci_req_init(&req, hdev); in add_advertising()
6683 hci_dev_unlock(hdev); in add_advertising()
6688 static void remove_advertising_complete(struct hci_dev *hdev, u8 status, in remove_advertising_complete() argument
6697 hci_dev_lock(hdev); in remove_advertising_complete()
6703 cmd = pending_find(MGMT_OP_REMOVE_ADVERTISING, hdev); in remove_advertising_complete()
6715 hci_dev_unlock(hdev); in remove_advertising_complete()
6718 static int remove_advertising(struct sock *sk, struct hci_dev *hdev, in remove_advertising() argument
6727 BT_DBG("%s", hdev->name); in remove_advertising()
6729 hci_dev_lock(hdev); in remove_advertising()
6731 if (cp->instance && !hci_find_adv_instance(hdev, cp->instance)) { in remove_advertising()
6732 err = mgmt_cmd_status(sk, hdev->id, in remove_advertising()
6738 if (pending_find(MGMT_OP_ADD_ADVERTISING, hdev) || in remove_advertising()
6739 pending_find(MGMT_OP_REMOVE_ADVERTISING, hdev) || in remove_advertising()
6740 pending_find(MGMT_OP_SET_LE, hdev)) { in remove_advertising()
6741 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
6746 if (list_empty(&hdev->adv_instances)) { in remove_advertising()
6747 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
6752 hci_req_init(&req, hdev); in remove_advertising()
6754 hci_req_clear_adv_instance(hdev, sk, &req, cp->instance, true); in remove_advertising()
6756 if (list_empty(&hdev->adv_instances)) in remove_advertising()
6764 !hdev_is_powered(hdev) || in remove_advertising()
6765 hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in remove_advertising()
6768 err = mgmt_cmd_complete(sk, hdev->id, in remove_advertising()
6774 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_ADVERTISING, hdev, data, in remove_advertising()
6786 hci_dev_unlock(hdev); in remove_advertising()
6791 static int get_adv_size_info(struct sock *sk, struct hci_dev *hdev, in get_adv_size_info() argument
6799 BT_DBG("%s", hdev->name); in get_adv_size_info()
6801 if (!lmp_le_capable(hdev)) in get_adv_size_info()
6802 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
6806 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
6814 supported_flags = get_supported_adv_flags(hdev); in get_adv_size_info()
6816 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
6821 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in get_adv_size_info()
6822 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in get_adv_size_info()
6824 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
6926 void mgmt_index_added(struct hci_dev *hdev) in mgmt_index_added() argument
6930 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_added()
6933 switch (hdev->dev_type) { in mgmt_index_added()
6935 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_added()
6936 mgmt_index_event(MGMT_EV_UNCONF_INDEX_ADDED, hdev, in mgmt_index_added()
6940 mgmt_index_event(MGMT_EV_INDEX_ADDED, hdev, NULL, 0, in mgmt_index_added()
6952 ev.bus = hdev->bus; in mgmt_index_added()
6954 mgmt_index_event(MGMT_EV_EXT_INDEX_ADDED, hdev, &ev, sizeof(ev), in mgmt_index_added()
6958 void mgmt_index_removed(struct hci_dev *hdev) in mgmt_index_removed() argument
6963 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_removed()
6966 switch (hdev->dev_type) { in mgmt_index_removed()
6968 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status); in mgmt_index_removed()
6970 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_removed()
6971 mgmt_index_event(MGMT_EV_UNCONF_INDEX_REMOVED, hdev, in mgmt_index_removed()
6975 mgmt_index_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, in mgmt_index_removed()
6987 ev.bus = hdev->bus; in mgmt_index_removed()
6989 mgmt_index_event(MGMT_EV_EXT_INDEX_REMOVED, hdev, &ev, sizeof(ev), in mgmt_index_removed()
6994 static void restart_le_actions(struct hci_dev *hdev) in restart_le_actions() argument
6998 list_for_each_entry(p, &hdev->le_conn_params, list) { in restart_le_actions()
7007 list_add(&p->action, &hdev->pend_le_conns); in restart_le_actions()
7010 list_add(&p->action, &hdev->pend_le_reports); in restart_le_actions()
7018 void mgmt_power_on(struct hci_dev *hdev, int err) in mgmt_power_on() argument
7020 struct cmd_lookup match = { NULL, hdev }; in mgmt_power_on()
7024 hci_dev_lock(hdev); in mgmt_power_on()
7027 restart_le_actions(hdev); in mgmt_power_on()
7028 hci_update_background_scan(hdev); in mgmt_power_on()
7031 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in mgmt_power_on()
7033 new_settings(hdev, match.sk); in mgmt_power_on()
7038 hci_dev_unlock(hdev); in mgmt_power_on()
7041 void __mgmt_power_off(struct hci_dev *hdev) in __mgmt_power_off() argument
7043 struct cmd_lookup match = { NULL, hdev }; in __mgmt_power_off()
7046 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in __mgmt_power_off()
7055 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) in __mgmt_power_off()
7060 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status); in __mgmt_power_off()
7062 if (memcmp(hdev->dev_class, zero_cod, sizeof(zero_cod)) != 0) { in __mgmt_power_off()
7063 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, in __mgmt_power_off()
7066 ext_info_changed(hdev, NULL); in __mgmt_power_off()
7069 new_settings(hdev, match.sk); in __mgmt_power_off()
7075 void mgmt_set_powered_failed(struct hci_dev *hdev, int err) in mgmt_set_powered_failed() argument
7080 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_set_powered_failed()
7089 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, status); in mgmt_set_powered_failed()
7094 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, in mgmt_new_link_key() argument
7108 mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_link_key()
7130 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent) in mgmt_new_ltk() argument
7170 mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_ltk()
7173 void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent) in mgmt_new_irk() argument
7186 mgmt_event(MGMT_EV_NEW_IRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_irk()
7189 void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, in mgmt_new_csrk() argument
7216 mgmt_event(MGMT_EV_NEW_CSRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_csrk()
7219 void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_new_conn_param() argument
7237 mgmt_event(MGMT_EV_NEW_CONN_PARAM, hdev, &ev, sizeof(ev), NULL); in mgmt_new_conn_param()
7240 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, in mgmt_device_connected() argument
7273 mgmt_event(MGMT_EV_DEVICE_CONNECTED, hdev, buf, in mgmt_device_connected()
7291 struct hci_dev *hdev = data; in unpair_device_rsp() local
7294 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_rsp()
7300 bool mgmt_powering_down(struct hci_dev *hdev) in mgmt_powering_down() argument
7305 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_powering_down()
7316 void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_device_disconnected() argument
7326 if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { in mgmt_device_disconnected()
7327 cancel_delayed_work(&hdev->power_off); in mgmt_device_disconnected()
7328 queue_work(hdev->req_workqueue, &hdev->power_off.work); in mgmt_device_disconnected()
7337 mgmt_pending_foreach(MGMT_OP_DISCONNECT, hdev, disconnect_rsp, &sk); in mgmt_device_disconnected()
7343 mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev), sk); in mgmt_device_disconnected()
7348 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_device_disconnected()
7349 hdev); in mgmt_device_disconnected()
7352 void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_disconnect_failed() argument
7359 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_disconnect_failed()
7360 hdev); in mgmt_disconnect_failed()
7362 cmd = pending_find(MGMT_OP_DISCONNECT, hdev); in mgmt_disconnect_failed()
7378 void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_connect_failed() argument
7386 if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { in mgmt_connect_failed()
7387 cancel_delayed_work(&hdev->power_off); in mgmt_connect_failed()
7388 queue_work(hdev->req_workqueue, &hdev->power_off.work); in mgmt_connect_failed()
7395 mgmt_event(MGMT_EV_CONNECT_FAILED, hdev, &ev, sizeof(ev), NULL); in mgmt_connect_failed()
7398 void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure) in mgmt_pin_code_request() argument
7406 mgmt_event(MGMT_EV_PIN_CODE_REQUEST, hdev, &ev, sizeof(ev), NULL); in mgmt_pin_code_request()
7409 void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_reply_complete() argument
7414 cmd = pending_find(MGMT_OP_PIN_CODE_REPLY, hdev); in mgmt_pin_code_reply_complete()
7422 void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_neg_reply_complete() argument
7427 cmd = pending_find(MGMT_OP_PIN_CODE_NEG_REPLY, hdev); in mgmt_pin_code_neg_reply_complete()
7435 int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_request() argument
7441 BT_DBG("%s", hdev->name); in mgmt_user_confirm_request()
7448 return mgmt_event(MGMT_EV_USER_CONFIRM_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_confirm_request()
7452 int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_request() argument
7457 BT_DBG("%s", hdev->name); in mgmt_user_passkey_request()
7462 return mgmt_event(MGMT_EV_USER_PASSKEY_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_passkey_request()
7466 static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in user_pairing_resp_complete() argument
7472 cmd = pending_find(opcode, hdev); in user_pairing_resp_complete()
7482 int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_reply_complete() argument
7485 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_reply_complete()
7489 int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_neg_reply_complete() argument
7492 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_neg_reply_complete()
7497 int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_reply_complete() argument
7500 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_reply_complete()
7504 int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_neg_reply_complete() argument
7507 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_neg_reply_complete()
7512 int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_notify() argument
7518 BT_DBG("%s", hdev->name); in mgmt_user_passkey_notify()
7525 return mgmt_event(MGMT_EV_PASSKEY_NOTIFY, hdev, &ev, sizeof(ev), NULL); in mgmt_user_passkey_notify()
7540 mgmt_event(MGMT_EV_AUTH_FAILED, conn->hdev, &ev, sizeof(ev), in mgmt_auth_failed()
7549 void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status) in mgmt_auth_enable_complete() argument
7551 struct cmd_lookup match = { NULL, hdev }; in mgmt_auth_enable_complete()
7556 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, in mgmt_auth_enable_complete()
7561 if (test_bit(HCI_AUTH, &hdev->flags)) in mgmt_auth_enable_complete()
7562 changed = !hci_dev_test_and_set_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
7564 changed = hci_dev_test_and_clear_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
7566 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, settings_rsp, in mgmt_auth_enable_complete()
7570 new_settings(hdev, match.sk); in mgmt_auth_enable_complete()
7578 struct hci_dev *hdev = req->hdev; in clear_eir() local
7581 if (!lmp_ext_inq_capable(hdev)) in clear_eir()
7584 memset(hdev->eir, 0, sizeof(hdev->eir)); in clear_eir()
7591 void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status) in mgmt_ssp_enable_complete() argument
7593 struct cmd_lookup match = { NULL, hdev }; in mgmt_ssp_enable_complete()
7600 if (enable && hci_dev_test_and_clear_flag(hdev, in mgmt_ssp_enable_complete()
7602 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in mgmt_ssp_enable_complete()
7603 new_settings(hdev, NULL); in mgmt_ssp_enable_complete()
7606 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, cmd_status_rsp, in mgmt_ssp_enable_complete()
7612 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in mgmt_ssp_enable_complete()
7614 changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED); in mgmt_ssp_enable_complete()
7616 changed = hci_dev_test_and_clear_flag(hdev, in mgmt_ssp_enable_complete()
7619 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in mgmt_ssp_enable_complete()
7622 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, settings_rsp, &match); in mgmt_ssp_enable_complete()
7625 new_settings(hdev, match.sk); in mgmt_ssp_enable_complete()
7630 hci_req_init(&req, hdev); in mgmt_ssp_enable_complete()
7632 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in mgmt_ssp_enable_complete()
7633 if (hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) in mgmt_ssp_enable_complete()
7654 void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, in mgmt_set_class_of_dev_complete() argument
7657 struct cmd_lookup match = { NULL, hdev, mgmt_status(status) }; in mgmt_set_class_of_dev_complete()
7659 mgmt_pending_foreach(MGMT_OP_SET_DEV_CLASS, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
7660 mgmt_pending_foreach(MGMT_OP_ADD_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
7661 mgmt_pending_foreach(MGMT_OP_REMOVE_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
7664 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, dev_class, in mgmt_set_class_of_dev_complete()
7666 ext_info_changed(hdev, NULL); in mgmt_set_class_of_dev_complete()
7673 void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status) in mgmt_set_local_name_complete() argument
7683 memcpy(ev.short_name, hdev->short_name, HCI_MAX_SHORT_NAME_LENGTH); in mgmt_set_local_name_complete()
7685 cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev); in mgmt_set_local_name_complete()
7687 memcpy(hdev->dev_name, name, sizeof(hdev->dev_name)); in mgmt_set_local_name_complete()
7692 if (pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_local_name_complete()
7696 mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev, sizeof(ev), in mgmt_set_local_name_complete()
7698 ext_info_changed(hdev, cmd ? cmd->sk : NULL); in mgmt_set_local_name_complete()
7768 static void restart_le_scan(struct hci_dev *hdev) in restart_le_scan() argument
7771 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in restart_le_scan()
7775 hdev->discovery.scan_start + in restart_le_scan()
7776 hdev->discovery.scan_duration)) in restart_le_scan()
7779 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_restart, in restart_le_scan()
7783 static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir, in is_filter_match() argument
7795 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
7797 (rssi < hdev->discovery.rssi && in is_filter_match()
7798 !test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)))) in is_filter_match()
7801 if (hdev->discovery.uuid_count != 0) { in is_filter_match()
7805 if (!eir_has_uuids(eir, eir_len, hdev->discovery.uuid_count, in is_filter_match()
7806 hdev->discovery.uuids) && in is_filter_match()
7808 hdev->discovery.uuid_count, in is_filter_match()
7809 hdev->discovery.uuids)) in is_filter_match()
7816 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)) { in is_filter_match()
7817 restart_le_scan(hdev); in is_filter_match()
7820 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
7821 rssi < hdev->discovery.rssi) in is_filter_match()
7828 void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_device_found() argument
7840 if (!hci_discovery_active(hdev)) { in mgmt_device_found()
7843 if (link_type == LE_LINK && list_empty(&hdev->pend_le_reports)) in mgmt_device_found()
7847 if (hdev->discovery.result_filtering) { in mgmt_device_found()
7849 if (!is_filter_match(hdev, rssi, eir, eir_len, scan_rsp, in mgmt_device_found()
7854 if (hdev->discovery.limited) { in mgmt_device_found()
7882 if (rssi == HCI_RSSI_INVALID && !hdev->discovery.report_invalid_rssi && in mgmt_device_found()
7907 mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, ev_size, NULL); in mgmt_device_found()
7910 void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_remote_name() argument
7930 mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, sizeof(*ev) + eir_len, NULL); in mgmt_remote_name()
7933 void mgmt_discovering(struct hci_dev *hdev, u8 discovering) in mgmt_discovering() argument
7937 BT_DBG("%s discovering %u", hdev->name, discovering); in mgmt_discovering()
7940 ev.type = hdev->discovery.type; in mgmt_discovering()
7943 mgmt_event(MGMT_EV_DISCOVERING, hdev, &ev, sizeof(ev), NULL); in mgmt_discovering()