Lines Matching refs:hdev
281 static int mgmt_index_event(u16 event, struct hci_dev *hdev, void *data, in mgmt_index_event() argument
284 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_index_event()
288 static int mgmt_limited_event(u16 event, struct hci_dev *hdev, void *data, in mgmt_limited_event() argument
291 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_limited_event()
295 static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, u16 len, in mgmt_event() argument
298 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_event()
318 static int read_version(struct sock *sk, struct hci_dev *hdev, void *data, in read_version() argument
323 bt_dev_dbg(hdev, "sock %p", sk); in read_version()
331 static int read_commands(struct sock *sk, struct hci_dev *hdev, void *data, in read_commands() argument
339 bt_dev_dbg(hdev, "sock %p", sk); in read_commands()
383 static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data, in read_index_list() argument
392 bt_dev_dbg(hdev, "sock %p", sk); in read_index_list()
426 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_index_list()
443 static int read_unconf_index_list(struct sock *sk, struct hci_dev *hdev, in read_unconf_index_list() argument
452 bt_dev_dbg(hdev, "sock %p", sk); in read_unconf_index_list()
486 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_unconf_index_list()
503 static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev, in read_ext_index_list() argument
511 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_index_list()
553 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_ext_index_list()
577 static bool is_configured(struct hci_dev *hdev) in is_configured() argument
579 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in is_configured()
580 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in is_configured()
583 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in is_configured()
584 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in is_configured()
585 !bacmp(&hdev->public_addr, BDADDR_ANY)) in is_configured()
591 static __le32 get_missing_options(struct hci_dev *hdev) in get_missing_options() argument
595 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in get_missing_options()
596 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in get_missing_options()
599 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in get_missing_options()
600 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in get_missing_options()
601 !bacmp(&hdev->public_addr, BDADDR_ANY)) in get_missing_options()
607 static int new_options(struct hci_dev *hdev, struct sock *skip) in new_options() argument
609 __le32 options = get_missing_options(hdev); in new_options()
611 return mgmt_limited_event(MGMT_EV_NEW_CONFIG_OPTIONS, hdev, &options, in new_options()
615 static int send_options_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_options_rsp() argument
617 __le32 options = get_missing_options(hdev); in send_options_rsp()
619 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &options, in send_options_rsp()
623 static int read_config_info(struct sock *sk, struct hci_dev *hdev, in read_config_info() argument
629 bt_dev_dbg(hdev, "sock %p", sk); in read_config_info()
631 hci_dev_lock(hdev); in read_config_info()
634 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_config_info()
636 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in read_config_info()
639 if (hdev->set_bdaddr) in read_config_info()
643 rp.missing_options = get_missing_options(hdev); in read_config_info()
645 hci_dev_unlock(hdev); in read_config_info()
647 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONFIG_INFO, 0, in read_config_info()
651 static u32 get_supported_phys(struct hci_dev *hdev) in get_supported_phys() argument
655 if (lmp_bredr_capable(hdev)) { in get_supported_phys()
658 if (hdev->features[0][0] & LMP_3SLOT) in get_supported_phys()
661 if (hdev->features[0][0] & LMP_5SLOT) in get_supported_phys()
664 if (lmp_edr_2m_capable(hdev)) { in get_supported_phys()
667 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
670 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
673 if (lmp_edr_3m_capable(hdev)) { in get_supported_phys()
676 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
679 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
685 if (lmp_le_capable(hdev)) { in get_supported_phys()
689 if (hdev->le_features[1] & HCI_LE_PHY_2M) { in get_supported_phys()
694 if (hdev->le_features[1] & HCI_LE_PHY_CODED) { in get_supported_phys()
703 static u32 get_selected_phys(struct hci_dev *hdev) in get_selected_phys() argument
707 if (lmp_bredr_capable(hdev)) { in get_selected_phys()
710 if (hdev->pkt_type & (HCI_DM3 | HCI_DH3)) in get_selected_phys()
713 if (hdev->pkt_type & (HCI_DM5 | HCI_DH5)) in get_selected_phys()
716 if (lmp_edr_2m_capable(hdev)) { in get_selected_phys()
717 if (!(hdev->pkt_type & HCI_2DH1)) in get_selected_phys()
720 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
721 !(hdev->pkt_type & HCI_2DH3)) in get_selected_phys()
724 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
725 !(hdev->pkt_type & HCI_2DH5)) in get_selected_phys()
728 if (lmp_edr_3m_capable(hdev)) { in get_selected_phys()
729 if (!(hdev->pkt_type & HCI_3DH1)) in get_selected_phys()
732 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
733 !(hdev->pkt_type & HCI_3DH3)) in get_selected_phys()
736 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
737 !(hdev->pkt_type & HCI_3DH5)) in get_selected_phys()
743 if (lmp_le_capable(hdev)) { in get_selected_phys()
744 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
747 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
750 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
753 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
756 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
759 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
766 static u32 get_configurable_phys(struct hci_dev *hdev) in get_configurable_phys() argument
768 return (get_supported_phys(hdev) & ~MGMT_PHY_BR_1M_1SLOT & in get_configurable_phys()
772 static u32 get_supported_settings(struct hci_dev *hdev) in get_supported_settings() argument
782 if (lmp_bredr_capable(hdev)) { in get_supported_settings()
783 if (hdev->hci_ver >= BLUETOOTH_VER_1_2) in get_supported_settings()
788 if (lmp_ssp_capable(hdev)) { in get_supported_settings()
794 if (lmp_sc_capable(hdev)) in get_supported_settings()
798 &hdev->quirks)) in get_supported_settings()
802 if (lmp_le_capable(hdev)) { in get_supported_settings()
811 if (!hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in get_supported_settings()
815 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in get_supported_settings()
816 hdev->set_bdaddr) in get_supported_settings()
824 static u32 get_current_settings(struct hci_dev *hdev) in get_current_settings() argument
828 if (hdev_is_powered(hdev)) in get_current_settings()
831 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in get_current_settings()
834 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in get_current_settings()
837 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in get_current_settings()
840 if (hci_dev_test_flag(hdev, HCI_BONDABLE)) in get_current_settings()
843 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in get_current_settings()
846 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in get_current_settings()
849 if (hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) in get_current_settings()
852 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in get_current_settings()
855 if (hci_dev_test_flag(hdev, HCI_HS_ENABLED)) in get_current_settings()
858 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in get_current_settings()
861 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) in get_current_settings()
864 if (hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) in get_current_settings()
867 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in get_current_settings()
882 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in get_current_settings()
883 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in get_current_settings()
884 !bacmp(&hdev->bdaddr, BDADDR_ANY)) { in get_current_settings()
885 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in get_current_settings()
889 if (hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED)) in get_current_settings()
895 static struct mgmt_pending_cmd *pending_find(u16 opcode, struct hci_dev *hdev) in pending_find() argument
897 return mgmt_pending_find(HCI_CHANNEL_CONTROL, opcode, hdev); in pending_find()
901 struct hci_dev *hdev, in pending_find_data() argument
904 return mgmt_pending_find_data(HCI_CHANNEL_CONTROL, opcode, hdev, data); in pending_find_data()
907 u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev) in mgmt_get_adv_discov_flags() argument
914 cmd = pending_find(MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_get_adv_discov_flags()
922 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
924 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
931 bool mgmt_get_connectable(struct hci_dev *hdev) in mgmt_get_connectable() argument
938 cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_get_connectable()
945 return hci_dev_test_flag(hdev, HCI_CONNECTABLE); in mgmt_get_connectable()
950 struct hci_dev *hdev = container_of(work, struct hci_dev, in service_cache_off() local
954 if (!hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in service_cache_off()
957 hci_req_init(&req, hdev); in service_cache_off()
959 hci_dev_lock(hdev); in service_cache_off()
964 hci_dev_unlock(hdev); in service_cache_off()
971 struct hci_dev *hdev = container_of(work, struct hci_dev, in rpa_expired() local
975 bt_dev_dbg(hdev, ""); in rpa_expired()
977 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in rpa_expired()
979 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING)) in rpa_expired()
986 hci_req_init(&req, hdev); in rpa_expired()
987 if (ext_adv_capable(hdev)) in rpa_expired()
988 __hci_req_start_ext_adv(&req, hdev->cur_adv_instance); in rpa_expired()
994 static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev) in mgmt_init_hdev() argument
996 if (hci_dev_test_and_set_flag(hdev, HCI_MGMT)) in mgmt_init_hdev()
999 INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off); in mgmt_init_hdev()
1000 INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired); in mgmt_init_hdev()
1007 hci_dev_clear_flag(hdev, HCI_BONDABLE); in mgmt_init_hdev()
1010 static int read_controller_info(struct sock *sk, struct hci_dev *hdev, in read_controller_info() argument
1015 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_info()
1017 hci_dev_lock(hdev); in read_controller_info()
1021 bacpy(&rp.bdaddr, &hdev->bdaddr); in read_controller_info()
1023 rp.version = hdev->hci_ver; in read_controller_info()
1024 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_controller_info()
1026 rp.supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_controller_info()
1027 rp.current_settings = cpu_to_le32(get_current_settings(hdev)); in read_controller_info()
1029 memcpy(rp.dev_class, hdev->dev_class, 3); in read_controller_info()
1031 memcpy(rp.name, hdev->dev_name, sizeof(hdev->dev_name)); in read_controller_info()
1032 memcpy(rp.short_name, hdev->short_name, sizeof(hdev->short_name)); in read_controller_info()
1034 hci_dev_unlock(hdev); in read_controller_info()
1036 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_INFO, 0, &rp, in read_controller_info()
1040 static u16 append_eir_data_to_buf(struct hci_dev *hdev, u8 *eir) in append_eir_data_to_buf() argument
1045 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in append_eir_data_to_buf()
1047 hdev->dev_class, 3); in append_eir_data_to_buf()
1049 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in append_eir_data_to_buf()
1051 hdev->appearance); in append_eir_data_to_buf()
1053 name_len = strlen(hdev->dev_name); in append_eir_data_to_buf()
1055 hdev->dev_name, name_len); in append_eir_data_to_buf()
1057 name_len = strlen(hdev->short_name); in append_eir_data_to_buf()
1059 hdev->short_name, name_len); in append_eir_data_to_buf()
1064 static int read_ext_controller_info(struct sock *sk, struct hci_dev *hdev, in read_ext_controller_info() argument
1071 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_controller_info()
1075 hci_dev_lock(hdev); in read_ext_controller_info()
1077 bacpy(&rp->bdaddr, &hdev->bdaddr); in read_ext_controller_info()
1079 rp->version = hdev->hci_ver; in read_ext_controller_info()
1080 rp->manufacturer = cpu_to_le16(hdev->manufacturer); in read_ext_controller_info()
1082 rp->supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_ext_controller_info()
1083 rp->current_settings = cpu_to_le32(get_current_settings(hdev)); in read_ext_controller_info()
1086 eir_len = append_eir_data_to_buf(hdev, rp->eir); in read_ext_controller_info()
1089 hci_dev_unlock(hdev); in read_ext_controller_info()
1100 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_EXT_INFO, 0, rp, in read_ext_controller_info()
1104 static int ext_info_changed(struct hci_dev *hdev, struct sock *skip) in ext_info_changed() argument
1112 eir_len = append_eir_data_to_buf(hdev, ev->eir); in ext_info_changed()
1115 return mgmt_limited_event(MGMT_EV_EXT_INFO_CHANGED, hdev, ev, in ext_info_changed()
1120 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_settings_rsp() argument
1122 __le32 settings = cpu_to_le32(get_current_settings(hdev)); in send_settings_rsp()
1124 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &settings, in send_settings_rsp()
1128 static void clean_up_hci_complete(struct hci_dev *hdev, u8 status, u16 opcode) in clean_up_hci_complete() argument
1130 bt_dev_dbg(hdev, "status 0x%02x", status); in clean_up_hci_complete()
1132 if (hci_conn_count(hdev) == 0) { in clean_up_hci_complete()
1133 cancel_delayed_work(&hdev->power_off); in clean_up_hci_complete()
1134 queue_work(hdev->req_workqueue, &hdev->power_off.work); in clean_up_hci_complete()
1138 void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev, u8 instance) in mgmt_advertising_added() argument
1144 mgmt_event(MGMT_EV_ADVERTISING_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_added()
1147 void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev, in mgmt_advertising_removed() argument
1154 mgmt_event(MGMT_EV_ADVERTISING_REMOVED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_removed()
1157 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
1159 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
1160 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
1161 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
1165 static int clean_up_hci_state(struct hci_dev *hdev) in clean_up_hci_state() argument
1172 hci_req_init(&req, hdev); in clean_up_hci_state()
1174 if (test_bit(HCI_ISCAN, &hdev->flags) || in clean_up_hci_state()
1175 test_bit(HCI_PSCAN, &hdev->flags)) { in clean_up_hci_state()
1180 hci_req_clear_adv_instance(hdev, NULL, NULL, 0x00, false); in clean_up_hci_state()
1182 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in clean_up_hci_state()
1187 list_for_each_entry(conn, &hdev->conn_hash.list, list) { in clean_up_hci_state()
1194 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in clean_up_hci_state()
1199 static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, in set_powered() argument
1206 bt_dev_dbg(hdev, "sock %p", sk); in set_powered()
1209 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1212 hci_dev_lock(hdev); in set_powered()
1214 if (pending_find(MGMT_OP_SET_POWERED, hdev)) { in set_powered()
1215 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1220 if (!!cp->val == hdev_is_powered(hdev)) { in set_powered()
1221 err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev); in set_powered()
1225 cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, hdev, data, len); in set_powered()
1232 queue_work(hdev->req_workqueue, &hdev->power_on); in set_powered()
1236 err = clean_up_hci_state(hdev); in set_powered()
1238 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in set_powered()
1243 cancel_delayed_work(&hdev->power_off); in set_powered()
1244 queue_work(hdev->req_workqueue, &hdev->power_off.work); in set_powered()
1250 hci_dev_unlock(hdev); in set_powered()
1254 static int new_settings(struct hci_dev *hdev, struct sock *skip) in new_settings() argument
1256 __le32 ev = cpu_to_le32(get_current_settings(hdev)); in new_settings()
1258 return mgmt_limited_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, in new_settings()
1262 int mgmt_new_settings(struct hci_dev *hdev) in mgmt_new_settings() argument
1264 return new_settings(hdev, NULL); in mgmt_new_settings()
1269 struct hci_dev *hdev; member
1277 send_settings_rsp(cmd->sk, cmd->opcode, match->hdev); in settings_rsp()
1323 static u8 mgmt_bredr_support(struct hci_dev *hdev) in mgmt_bredr_support() argument
1325 if (!lmp_bredr_capable(hdev)) in mgmt_bredr_support()
1327 else if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in mgmt_bredr_support()
1333 static u8 mgmt_le_support(struct hci_dev *hdev) in mgmt_le_support() argument
1335 if (!lmp_le_capable(hdev)) in mgmt_le_support()
1337 else if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mgmt_le_support()
1343 void mgmt_set_discoverable_complete(struct hci_dev *hdev, u8 status) in mgmt_set_discoverable_complete() argument
1347 bt_dev_dbg(hdev, "status 0x%02x", status); in mgmt_set_discoverable_complete()
1349 hci_dev_lock(hdev); in mgmt_set_discoverable_complete()
1351 cmd = pending_find(MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_set_discoverable_complete()
1358 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in mgmt_set_discoverable_complete()
1362 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in mgmt_set_discoverable_complete()
1363 hdev->discov_timeout > 0) { in mgmt_set_discoverable_complete()
1364 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in mgmt_set_discoverable_complete()
1365 queue_delayed_work(hdev->req_workqueue, &hdev->discov_off, to); in mgmt_set_discoverable_complete()
1368 send_settings_rsp(cmd->sk, MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_set_discoverable_complete()
1369 new_settings(hdev, cmd->sk); in mgmt_set_discoverable_complete()
1375 hci_dev_unlock(hdev); in mgmt_set_discoverable_complete()
1378 static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, in set_discoverable() argument
1386 bt_dev_dbg(hdev, "sock %p", sk); in set_discoverable()
1388 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_discoverable()
1389 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_discoverable()
1390 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1394 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1404 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1407 hci_dev_lock(hdev); in set_discoverable()
1409 if (!hdev_is_powered(hdev) && timeout > 0) { in set_discoverable()
1410 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1415 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_discoverable()
1416 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_discoverable()
1417 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1422 if (!hci_dev_test_flag(hdev, HCI_CONNECTABLE)) { in set_discoverable()
1423 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1428 if (hdev->advertising_paused) { in set_discoverable()
1429 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1434 if (!hdev_is_powered(hdev)) { in set_discoverable()
1441 if (!!cp->val != hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) { in set_discoverable()
1442 hci_dev_change_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1446 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1451 err = new_settings(hdev, sk); in set_discoverable()
1460 if (!!cp->val == hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in set_discoverable()
1461 (cp->val == 0x02) == hci_dev_test_flag(hdev, in set_discoverable()
1463 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1464 hdev->discov_timeout = timeout; in set_discoverable()
1466 if (cp->val && hdev->discov_timeout > 0) { in set_discoverable()
1467 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in set_discoverable()
1468 queue_delayed_work(hdev->req_workqueue, in set_discoverable()
1469 &hdev->discov_off, to); in set_discoverable()
1472 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1476 cmd = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, hdev, data, len); in set_discoverable()
1486 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1487 hdev->discov_timeout = timeout; in set_discoverable()
1490 hci_dev_set_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1492 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1496 hci_dev_set_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1498 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1500 queue_work(hdev->req_workqueue, &hdev->discoverable_update); in set_discoverable()
1504 hci_dev_unlock(hdev); in set_discoverable()
1508 void mgmt_set_connectable_complete(struct hci_dev *hdev, u8 status) in mgmt_set_connectable_complete() argument
1512 bt_dev_dbg(hdev, "status 0x%02x", status); in mgmt_set_connectable_complete()
1514 hci_dev_lock(hdev); in mgmt_set_connectable_complete()
1516 cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_set_connectable_complete()
1526 send_settings_rsp(cmd->sk, MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_set_connectable_complete()
1527 new_settings(hdev, cmd->sk); in mgmt_set_connectable_complete()
1533 hci_dev_unlock(hdev); in mgmt_set_connectable_complete()
1536 static int set_connectable_update_settings(struct hci_dev *hdev, in set_connectable_update_settings() argument
1542 if (!!val != hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in set_connectable_update_settings()
1546 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1548 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1549 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable_update_settings()
1552 err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev); in set_connectable_update_settings()
1557 hci_req_update_scan(hdev); in set_connectable_update_settings()
1558 hci_update_background_scan(hdev); in set_connectable_update_settings()
1559 return new_settings(hdev, sk); in set_connectable_update_settings()
1565 static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data, in set_connectable() argument
1572 bt_dev_dbg(hdev, "sock %p", sk); in set_connectable()
1574 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_connectable()
1575 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_connectable()
1576 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1580 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1583 hci_dev_lock(hdev); in set_connectable()
1585 if (!hdev_is_powered(hdev)) { in set_connectable()
1586 err = set_connectable_update_settings(hdev, sk, cp->val); in set_connectable()
1590 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_connectable()
1591 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_connectable()
1592 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1597 cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len); in set_connectable()
1604 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1606 if (hdev->discov_timeout > 0) in set_connectable()
1607 cancel_delayed_work(&hdev->discov_off); in set_connectable()
1609 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_connectable()
1610 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable()
1611 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1614 queue_work(hdev->req_workqueue, &hdev->connectable_update); in set_connectable()
1618 hci_dev_unlock(hdev); in set_connectable()
1622 static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data, in set_bondable() argument
1629 bt_dev_dbg(hdev, "sock %p", sk); in set_bondable()
1632 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BONDABLE, in set_bondable()
1635 hci_dev_lock(hdev); in set_bondable()
1638 changed = !hci_dev_test_and_set_flag(hdev, HCI_BONDABLE); in set_bondable()
1640 changed = hci_dev_test_and_clear_flag(hdev, HCI_BONDABLE); in set_bondable()
1642 err = send_settings_rsp(sk, MGMT_OP_SET_BONDABLE, hdev); in set_bondable()
1650 if (hdev_is_powered(hdev) && in set_bondable()
1651 hci_dev_test_flag(hdev, HCI_ADVERTISING) && in set_bondable()
1652 hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in set_bondable()
1653 hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in set_bondable()
1654 queue_work(hdev->req_workqueue, in set_bondable()
1655 &hdev->discoverable_update); in set_bondable()
1657 err = new_settings(hdev, sk); in set_bondable()
1661 hci_dev_unlock(hdev); in set_bondable()
1665 static int set_link_security(struct sock *sk, struct hci_dev *hdev, void *data, in set_link_security() argument
1673 bt_dev_dbg(hdev, "sock %p", sk); in set_link_security()
1675 status = mgmt_bredr_support(hdev); in set_link_security()
1677 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1681 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1684 hci_dev_lock(hdev); in set_link_security()
1686 if (!hdev_is_powered(hdev)) { in set_link_security()
1689 if (!!cp->val != hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) { in set_link_security()
1690 hci_dev_change_flag(hdev, HCI_LINK_SECURITY); in set_link_security()
1694 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1699 err = new_settings(hdev, sk); in set_link_security()
1704 if (pending_find(MGMT_OP_SET_LINK_SECURITY, hdev)) { in set_link_security()
1705 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1712 if (test_bit(HCI_AUTH, &hdev->flags) == val) { in set_link_security()
1713 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1717 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LINK_SECURITY, hdev, data, len); in set_link_security()
1723 err = hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, sizeof(val), &val); in set_link_security()
1730 hci_dev_unlock(hdev); in set_link_security()
1734 static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_ssp() argument
1741 bt_dev_dbg(hdev, "sock %p", sk); in set_ssp()
1743 status = mgmt_bredr_support(hdev); in set_ssp()
1745 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, status); in set_ssp()
1747 if (!lmp_ssp_capable(hdev)) in set_ssp()
1748 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1752 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1755 hci_dev_lock(hdev); in set_ssp()
1757 if (!hdev_is_powered(hdev)) { in set_ssp()
1761 changed = !hci_dev_test_and_set_flag(hdev, in set_ssp()
1764 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
1767 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
1770 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_ssp()
1773 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
1778 err = new_settings(hdev, sk); in set_ssp()
1783 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_ssp()
1784 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1789 if (!!cp->val == hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_ssp()
1790 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
1794 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SSP, hdev, data, len); in set_ssp()
1800 if (!cp->val && hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) in set_ssp()
1801 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in set_ssp()
1804 err = hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, 1, &cp->val); in set_ssp()
1811 hci_dev_unlock(hdev); in set_ssp()
1815 static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_hs() argument
1822 bt_dev_dbg(hdev, "sock %p", sk); in set_hs()
1825 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1828 status = mgmt_bredr_support(hdev); in set_hs()
1830 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, status); in set_hs()
1832 if (!lmp_ssp_capable(hdev)) in set_hs()
1833 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1836 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_hs()
1837 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1841 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1844 hci_dev_lock(hdev); in set_hs()
1846 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_hs()
1847 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1853 changed = !hci_dev_test_and_set_flag(hdev, HCI_HS_ENABLED); in set_hs()
1855 if (hdev_is_powered(hdev)) { in set_hs()
1856 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1861 changed = hci_dev_test_and_clear_flag(hdev, HCI_HS_ENABLED); in set_hs()
1864 err = send_settings_rsp(sk, MGMT_OP_SET_HS, hdev); in set_hs()
1869 err = new_settings(hdev, sk); in set_hs()
1872 hci_dev_unlock(hdev); in set_hs()
1876 static void le_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) in le_enable_complete() argument
1878 struct cmd_lookup match = { NULL, hdev }; in le_enable_complete()
1880 hci_dev_lock(hdev); in le_enable_complete()
1885 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp, in le_enable_complete()
1890 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match); in le_enable_complete()
1892 new_settings(hdev, match.sk); in le_enable_complete()
1902 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in le_enable_complete()
1904 hci_req_init(&req, hdev); in le_enable_complete()
1905 if (ext_adv_capable(hdev)) { in le_enable_complete()
1916 hci_update_background_scan(hdev); in le_enable_complete()
1920 hci_dev_unlock(hdev); in le_enable_complete()
1923 static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_le() argument
1932 bt_dev_dbg(hdev, "sock %p", sk); in set_le()
1934 if (!lmp_le_capable(hdev)) in set_le()
1935 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1939 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1951 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_le()
1953 return send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
1955 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1959 hci_dev_lock(hdev); in set_le()
1962 enabled = lmp_host_le_capable(hdev); in set_le()
1965 hci_req_clear_adv_instance(hdev, NULL, NULL, 0x00, true); in set_le()
1967 if (!hdev_is_powered(hdev) || val == enabled) { in set_le()
1970 if (val != hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le()
1971 hci_dev_change_flag(hdev, HCI_LE_ENABLED); in set_le()
1975 if (!val && hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in set_le()
1976 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_le()
1980 err = send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
1985 err = new_settings(hdev, sk); in set_le()
1990 if (pending_find(MGMT_OP_SET_LE, hdev) || in set_le()
1991 pending_find(MGMT_OP_SET_ADVERTISING, hdev)) { in set_le()
1992 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1997 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LE, hdev, data, len); in set_le()
2003 hci_req_init(&req, hdev); in set_le()
2011 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_le()
2014 if (ext_adv_capable(hdev)) in set_le()
2026 hci_dev_unlock(hdev); in set_le()
2036 static bool pending_eir_or_class(struct hci_dev *hdev) in pending_eir_or_class() argument
2040 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in pending_eir_or_class()
2072 static void mgmt_class_complete(struct hci_dev *hdev, u16 mgmt_op, u8 status) in mgmt_class_complete() argument
2076 hci_dev_lock(hdev); in mgmt_class_complete()
2078 cmd = pending_find(mgmt_op, hdev); in mgmt_class_complete()
2083 mgmt_status(status), hdev->dev_class, 3); in mgmt_class_complete()
2088 hci_dev_unlock(hdev); in mgmt_class_complete()
2091 static void add_uuid_complete(struct hci_dev *hdev, u8 status, u16 opcode) in add_uuid_complete() argument
2093 bt_dev_dbg(hdev, "status 0x%02x", status); in add_uuid_complete()
2095 mgmt_class_complete(hdev, MGMT_OP_ADD_UUID, status); in add_uuid_complete()
2098 static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in add_uuid() argument
2106 bt_dev_dbg(hdev, "sock %p", sk); in add_uuid()
2108 hci_dev_lock(hdev); in add_uuid()
2110 if (pending_eir_or_class(hdev)) { in add_uuid()
2111 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_UUID, in add_uuid()
2126 list_add_tail(&uuid->list, &hdev->uuids); in add_uuid()
2128 hci_req_init(&req, hdev); in add_uuid()
2138 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_UUID, 0, in add_uuid()
2139 hdev->dev_class, 3); in add_uuid()
2143 cmd = mgmt_pending_add(sk, MGMT_OP_ADD_UUID, hdev, data, len); in add_uuid()
2152 hci_dev_unlock(hdev); in add_uuid()
2156 static bool enable_service_cache(struct hci_dev *hdev) in enable_service_cache() argument
2158 if (!hdev_is_powered(hdev)) in enable_service_cache()
2161 if (!hci_dev_test_and_set_flag(hdev, HCI_SERVICE_CACHE)) { in enable_service_cache()
2162 queue_delayed_work(hdev->workqueue, &hdev->service_cache, in enable_service_cache()
2170 static void remove_uuid_complete(struct hci_dev *hdev, u8 status, u16 opcode) in remove_uuid_complete() argument
2172 bt_dev_dbg(hdev, "status 0x%02x", status); in remove_uuid_complete()
2174 mgmt_class_complete(hdev, MGMT_OP_REMOVE_UUID, status); in remove_uuid_complete()
2177 static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data, in remove_uuid() argument
2187 bt_dev_dbg(hdev, "sock %p", sk); in remove_uuid()
2189 hci_dev_lock(hdev); in remove_uuid()
2191 if (pending_eir_or_class(hdev)) { in remove_uuid()
2192 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2198 hci_uuids_clear(hdev); in remove_uuid()
2200 if (enable_service_cache(hdev)) { in remove_uuid()
2201 err = mgmt_cmd_complete(sk, hdev->id, in remove_uuid()
2203 0, hdev->dev_class, 3); in remove_uuid()
2212 list_for_each_entry_safe(match, tmp, &hdev->uuids, list) { in remove_uuid()
2222 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2228 hci_req_init(&req, hdev); in remove_uuid()
2238 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_UUID, 0, in remove_uuid()
2239 hdev->dev_class, 3); in remove_uuid()
2243 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_UUID, hdev, data, len); in remove_uuid()
2252 hci_dev_unlock(hdev); in remove_uuid()
2256 static void set_class_complete(struct hci_dev *hdev, u8 status, u16 opcode) in set_class_complete() argument
2258 bt_dev_dbg(hdev, "status 0x%02x", status); in set_class_complete()
2260 mgmt_class_complete(hdev, MGMT_OP_SET_DEV_CLASS, status); in set_class_complete()
2263 static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data, in set_dev_class() argument
2271 bt_dev_dbg(hdev, "sock %p", sk); in set_dev_class()
2273 if (!lmp_bredr_capable(hdev)) in set_dev_class()
2274 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2277 hci_dev_lock(hdev); in set_dev_class()
2279 if (pending_eir_or_class(hdev)) { in set_dev_class()
2280 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2286 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2291 hdev->major_class = cp->major; in set_dev_class()
2292 hdev->minor_class = cp->minor; in set_dev_class()
2294 if (!hdev_is_powered(hdev)) { in set_dev_class()
2295 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, in set_dev_class()
2296 hdev->dev_class, 3); in set_dev_class()
2300 hci_req_init(&req, hdev); in set_dev_class()
2302 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) { in set_dev_class()
2303 hci_dev_unlock(hdev); in set_dev_class()
2304 cancel_delayed_work_sync(&hdev->service_cache); in set_dev_class()
2305 hci_dev_lock(hdev); in set_dev_class()
2316 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, in set_dev_class()
2317 hdev->dev_class, 3); in set_dev_class()
2321 cmd = mgmt_pending_add(sk, MGMT_OP_SET_DEV_CLASS, hdev, data, len); in set_dev_class()
2330 hci_dev_unlock(hdev); in set_dev_class()
2334 static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data, in load_link_keys() argument
2344 bt_dev_dbg(hdev, "sock %p", sk); in load_link_keys()
2346 if (!lmp_bredr_capable(hdev)) in load_link_keys()
2347 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2352 bt_dev_err(hdev, "load_link_keys: too big key_count value %u", in load_link_keys()
2354 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2360 bt_dev_err(hdev, "load_link_keys: expected %u bytes, got %u bytes", in load_link_keys()
2362 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2367 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2370 bt_dev_dbg(hdev, "debug_keys %u key_count %u", cp->debug_keys, in load_link_keys()
2377 return mgmt_cmd_status(sk, hdev->id, in load_link_keys()
2382 hci_dev_lock(hdev); in load_link_keys()
2384 hci_link_keys_clear(hdev); in load_link_keys()
2387 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in load_link_keys()
2389 changed = hci_dev_test_and_clear_flag(hdev, in load_link_keys()
2393 new_settings(hdev, NULL); in load_link_keys()
2398 if (hci_is_blocked_key(hdev, in load_link_keys()
2401 bt_dev_warn(hdev, "Skipping blocked link key for %pMR", in load_link_keys()
2412 hci_add_link_key(hdev, NULL, &key->addr.bdaddr, key->val, in load_link_keys()
2416 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0); in load_link_keys()
2418 hci_dev_unlock(hdev); in load_link_keys()
2423 static int device_unpaired(struct hci_dev *hdev, bdaddr_t *bdaddr, in device_unpaired() argument
2431 return mgmt_event(MGMT_EV_DEVICE_UNPAIRED, hdev, &ev, sizeof(ev), in device_unpaired()
2435 static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data, in unpair_device() argument
2451 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2456 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2460 hci_dev_lock(hdev); in unpair_device()
2462 if (!hdev_is_powered(hdev)) { in unpair_device()
2463 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2478 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device()
2483 err = hci_remove_link_key(hdev, &cp->addr.bdaddr); in unpair_device()
2485 err = mgmt_cmd_complete(sk, hdev->id, in unpair_device()
2499 err = smp_cancel_and_remove_pairing(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2501 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2507 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2509 hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2520 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2539 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0, in unpair_device()
2541 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk); in unpair_device()
2545 cmd = mgmt_pending_add(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp, in unpair_device()
2559 hci_dev_unlock(hdev); in unpair_device()
2563 static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data, in disconnect() argument
2572 bt_dev_dbg(hdev, "sock %p", sk); in disconnect()
2579 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2583 hci_dev_lock(hdev); in disconnect()
2585 if (!test_bit(HCI_UP, &hdev->flags)) { in disconnect()
2586 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2592 if (pending_find(MGMT_OP_DISCONNECT, hdev)) { in disconnect()
2593 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2599 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in disconnect()
2602 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in disconnect()
2606 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2612 cmd = mgmt_pending_add(sk, MGMT_OP_DISCONNECT, hdev, data, len); in disconnect()
2625 hci_dev_unlock(hdev); in disconnect()
2648 static int get_connections(struct sock *sk, struct hci_dev *hdev, void *data, in get_connections() argument
2656 bt_dev_dbg(hdev, "sock %p", sk); in get_connections()
2658 hci_dev_lock(hdev); in get_connections()
2660 if (!hdev_is_powered(hdev)) { in get_connections()
2661 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, in get_connections()
2667 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
2679 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
2692 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, 0, rp, in get_connections()
2698 hci_dev_unlock(hdev); in get_connections()
2702 static int send_pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in send_pin_code_neg_reply() argument
2708 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, hdev, cp, in send_pin_code_neg_reply()
2715 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, in send_pin_code_neg_reply()
2723 static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data, in pin_code_reply() argument
2732 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_reply()
2734 hci_dev_lock(hdev); in pin_code_reply()
2736 if (!hdev_is_powered(hdev)) { in pin_code_reply()
2737 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
2742 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in pin_code_reply()
2744 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
2754 bt_dev_err(hdev, "PIN code is not 16 bytes long"); in pin_code_reply()
2756 err = send_pin_code_neg_reply(sk, hdev, &ncp); in pin_code_reply()
2758 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
2764 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data, len); in pin_code_reply()
2776 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_REPLY, sizeof(reply), &reply); in pin_code_reply()
2781 hci_dev_unlock(hdev); in pin_code_reply()
2785 static int set_io_capability(struct sock *sk, struct hci_dev *hdev, void *data, in set_io_capability() argument
2790 bt_dev_dbg(hdev, "sock %p", sk); in set_io_capability()
2793 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, in set_io_capability()
2796 hci_dev_lock(hdev); in set_io_capability()
2798 hdev->io_capability = cp->io_capability; in set_io_capability()
2800 bt_dev_dbg(hdev, "IO capability set to 0x%02x", hdev->io_capability); in set_io_capability()
2802 hci_dev_unlock(hdev); in set_io_capability()
2804 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, 0, in set_io_capability()
2810 struct hci_dev *hdev = conn->hdev; in find_pairing() local
2813 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in find_pairing()
2902 static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in pair_device() argument
2912 bt_dev_dbg(hdev, "sock %p", sk); in pair_device()
2919 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2924 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2928 hci_dev_lock(hdev); in pair_device()
2930 if (!hdev_is_powered(hdev)) { in pair_device()
2931 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2937 if (hci_bdaddr_is_paired(hdev, &cp->addr.bdaddr, cp->addr.type)) { in pair_device()
2938 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2948 conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level, in pair_device()
2963 p = hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type); in pair_device()
2968 conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr, addr_type, in pair_device()
2985 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2992 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2997 cmd = mgmt_pending_add(sk, MGMT_OP_PAIR_DEVICE, hdev, data, len); in pair_device()
3029 hci_dev_unlock(hdev); in pair_device()
3033 static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in cancel_pair_device() argument
3041 bt_dev_dbg(hdev, "sock %p", sk); in cancel_pair_device()
3043 hci_dev_lock(hdev); in cancel_pair_device()
3045 if (!hdev_is_powered(hdev)) { in cancel_pair_device()
3046 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3051 cmd = pending_find(MGMT_OP_PAIR_DEVICE, hdev); in cancel_pair_device()
3053 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3061 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3069 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0, in cancel_pair_device()
3077 hci_remove_link_key(hdev, &addr->bdaddr); in cancel_pair_device()
3079 smp_cancel_and_remove_pairing(hdev, &addr->bdaddr, in cancel_pair_device()
3086 hci_dev_unlock(hdev); in cancel_pair_device()
3090 static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev, in user_pairing_resp() argument
3098 hci_dev_lock(hdev); in user_pairing_resp()
3100 if (!hdev_is_powered(hdev)) { in user_pairing_resp()
3101 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3108 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &addr->bdaddr); in user_pairing_resp()
3110 conn = hci_conn_hash_lookup_le(hdev, &addr->bdaddr, in user_pairing_resp()
3114 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3123 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3127 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3134 cmd = mgmt_pending_add(sk, mgmt_op, hdev, addr, sizeof(*addr)); in user_pairing_resp()
3148 err = hci_send_cmd(hdev, hci_op, sizeof(cp), &cp); in user_pairing_resp()
3150 err = hci_send_cmd(hdev, hci_op, sizeof(addr->bdaddr), in user_pairing_resp()
3157 hci_dev_unlock(hdev); in user_pairing_resp()
3161 static int pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in pin_code_neg_reply() argument
3166 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_neg_reply()
3168 return user_pairing_resp(sk, hdev, &cp->addr, in pin_code_neg_reply()
3173 static int user_confirm_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_confirm_reply() argument
3178 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_reply()
3181 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_USER_CONFIRM_REPLY, in user_confirm_reply()
3184 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_reply()
3189 static int user_confirm_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_confirm_neg_reply() argument
3194 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_neg_reply()
3196 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_neg_reply()
3201 static int user_passkey_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_passkey_reply() argument
3206 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_reply()
3208 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_reply()
3213 static int user_passkey_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_passkey_neg_reply() argument
3218 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_neg_reply()
3220 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_neg_reply()
3225 static void adv_expire(struct hci_dev *hdev, u32 flags) in adv_expire() argument
3231 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in adv_expire()
3239 cancel_adv_timeout(hdev); in adv_expire()
3241 adv_instance = hci_get_next_instance(hdev, adv_instance->instance); in adv_expire()
3245 hci_req_init(&req, hdev); in adv_expire()
3254 static void set_name_complete(struct hci_dev *hdev, u8 status, u16 opcode) in set_name_complete() argument
3259 bt_dev_dbg(hdev, "status 0x%02x", status); in set_name_complete()
3261 hci_dev_lock(hdev); in set_name_complete()
3263 cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev); in set_name_complete()
3270 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_name_complete()
3273 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_name_complete()
3276 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_name_complete()
3277 adv_expire(hdev, MGMT_ADV_FLAG_LOCAL_NAME); in set_name_complete()
3283 hci_dev_unlock(hdev); in set_name_complete()
3286 static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data, in set_local_name() argument
3294 bt_dev_dbg(hdev, "sock %p", sk); in set_local_name()
3296 hci_dev_lock(hdev); in set_local_name()
3301 if (!memcmp(hdev->dev_name, cp->name, sizeof(hdev->dev_name)) && in set_local_name()
3302 !memcmp(hdev->short_name, cp->short_name, in set_local_name()
3303 sizeof(hdev->short_name))) { in set_local_name()
3304 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3309 memcpy(hdev->short_name, cp->short_name, sizeof(hdev->short_name)); in set_local_name()
3311 if (!hdev_is_powered(hdev)) { in set_local_name()
3312 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3314 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3319 err = mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, data, in set_local_name()
3321 ext_info_changed(hdev, sk); in set_local_name()
3326 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len); in set_local_name()
3332 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3334 hci_req_init(&req, hdev); in set_local_name()
3336 if (lmp_bredr_capable(hdev)) { in set_local_name()
3344 if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING)) in set_local_name()
3345 __hci_req_update_scan_rsp_data(&req, hdev->cur_adv_instance); in set_local_name()
3352 hci_dev_unlock(hdev); in set_local_name()
3356 static int set_appearance(struct sock *sk, struct hci_dev *hdev, void *data, in set_appearance() argument
3363 bt_dev_dbg(hdev, "sock %p", sk); in set_appearance()
3365 if (!lmp_le_capable(hdev)) in set_appearance()
3366 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_APPEARANCE, in set_appearance()
3371 hci_dev_lock(hdev); in set_appearance()
3373 if (hdev->appearance != appearance) { in set_appearance()
3374 hdev->appearance = appearance; in set_appearance()
3376 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_appearance()
3377 adv_expire(hdev, MGMT_ADV_FLAG_APPEARANCE); in set_appearance()
3379 ext_info_changed(hdev, sk); in set_appearance()
3382 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_APPEARANCE, 0, NULL, in set_appearance()
3385 hci_dev_unlock(hdev); in set_appearance()
3390 static int get_phy_configuration(struct sock *sk, struct hci_dev *hdev, in get_phy_configuration() argument
3395 bt_dev_dbg(hdev, "sock %p", sk); in get_phy_configuration()
3397 hci_dev_lock(hdev); in get_phy_configuration()
3401 rp.supported_phys = cpu_to_le32(get_supported_phys(hdev)); in get_phy_configuration()
3402 rp.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in get_phy_configuration()
3403 rp.configurable_phys = cpu_to_le32(get_configurable_phys(hdev)); in get_phy_configuration()
3405 hci_dev_unlock(hdev); in get_phy_configuration()
3407 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_PHY_CONFIGURATION, 0, in get_phy_configuration()
3411 int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip) in mgmt_phy_configuration_changed() argument
3417 ev.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in mgmt_phy_configuration_changed()
3419 return mgmt_event(MGMT_EV_PHY_CONFIGURATION_CHANGED, hdev, &ev, in mgmt_phy_configuration_changed()
3423 static void set_default_phy_complete(struct hci_dev *hdev, u8 status, in set_default_phy_complete() argument
3428 bt_dev_dbg(hdev, "status 0x%02x", status); in set_default_phy_complete()
3430 hci_dev_lock(hdev); in set_default_phy_complete()
3432 cmd = pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev); in set_default_phy_complete()
3437 mgmt_cmd_status(cmd->sk, hdev->id, in set_default_phy_complete()
3441 mgmt_cmd_complete(cmd->sk, hdev->id, in set_default_phy_complete()
3445 mgmt_phy_configuration_changed(hdev, cmd->sk); in set_default_phy_complete()
3451 hci_dev_unlock(hdev); in set_default_phy_complete()
3454 static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, in set_phy_configuration() argument
3466 bt_dev_dbg(hdev, "sock %p", sk); in set_phy_configuration()
3468 configurable_phys = get_configurable_phys(hdev); in set_phy_configuration()
3469 supported_phys = get_supported_phys(hdev); in set_phy_configuration()
3473 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3480 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3484 if (selected_phys == get_selected_phys(hdev)) in set_phy_configuration()
3485 return mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
3489 hci_dev_lock(hdev); in set_phy_configuration()
3491 if (!hdev_is_powered(hdev)) { in set_phy_configuration()
3492 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3498 if (pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) { in set_phy_configuration()
3499 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3545 if (pkt_type != hdev->pkt_type) { in set_phy_configuration()
3546 hdev->pkt_type = pkt_type; in set_phy_configuration()
3551 (get_selected_phys(hdev) & MGMT_PHY_LE_MASK)) { in set_phy_configuration()
3553 mgmt_phy_configuration_changed(hdev, sk); in set_phy_configuration()
3555 err = mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
3562 cmd = mgmt_pending_add(sk, MGMT_OP_SET_PHY_CONFIGURATION, hdev, data, in set_phy_configuration()
3569 hci_req_init(&req, hdev); in set_phy_configuration()
3604 hci_dev_unlock(hdev); in set_phy_configuration()
3609 static int set_blocked_keys(struct sock *sk, struct hci_dev *hdev, void *data, in set_blocked_keys() argument
3619 bt_dev_dbg(hdev, "sock %p", sk); in set_blocked_keys()
3623 bt_dev_err(hdev, "too big key_count value %u", key_count); in set_blocked_keys()
3624 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
3630 bt_dev_err(hdev, "expected %u bytes, got %u bytes", in set_blocked_keys()
3632 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
3636 hci_dev_lock(hdev); in set_blocked_keys()
3638 hci_blocked_keys_clear(hdev); in set_blocked_keys()
3650 list_add_rcu(&b->list, &hdev->blocked_keys); in set_blocked_keys()
3652 hci_dev_unlock(hdev); in set_blocked_keys()
3654 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
3658 static int set_wideband_speech(struct sock *sk, struct hci_dev *hdev, in set_wideband_speech() argument
3665 bt_dev_dbg(hdev, "sock %p", sk); in set_wideband_speech()
3667 if (!test_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks)) in set_wideband_speech()
3668 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
3673 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
3677 hci_dev_lock(hdev); in set_wideband_speech()
3679 if (pending_find(MGMT_OP_SET_WIDEBAND_SPEECH, hdev)) { in set_wideband_speech()
3680 err = mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
3686 if (hdev_is_powered(hdev) && in set_wideband_speech()
3687 !!cp->val != hci_dev_test_flag(hdev, in set_wideband_speech()
3689 err = mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
3696 changed = !hci_dev_test_and_set_flag(hdev, in set_wideband_speech()
3699 changed = hci_dev_test_and_clear_flag(hdev, in set_wideband_speech()
3702 err = send_settings_rsp(sk, MGMT_OP_SET_WIDEBAND_SPEECH, hdev); in set_wideband_speech()
3707 err = new_settings(hdev, sk); in set_wideband_speech()
3710 hci_dev_unlock(hdev); in set_wideband_speech()
3714 static int read_security_info(struct sock *sk, struct hci_dev *hdev, in read_security_info() argument
3722 bt_dev_dbg(hdev, "sock %p", sk); in read_security_info()
3726 hci_dev_lock(hdev); in read_security_info()
3731 if (hdev->commands[41] & 0x08) in read_security_info()
3739 if (hdev->commands[20] & 0x10) in read_security_info()
3749 if (hdev->commands[41] & 0x08) in read_security_info()
3751 hdev->max_enc_key_size); in read_security_info()
3757 hci_dev_unlock(hdev); in read_security_info()
3759 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_SECURITY_INFO, 0, in read_security_info()
3783 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, in read_exp_features_info() argument
3791 bt_dev_dbg(hdev, "sock %p", sk); in read_exp_features_info()
3796 if (!hdev) { in read_exp_features_info()
3805 if (hdev) { in read_exp_features_info()
3806 if (test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) && in read_exp_features_info()
3807 (hdev->le_states[4] & 0x08) && /* Central */ in read_exp_features_info()
3808 (hdev->le_states[4] & 0x40) && /* Peripheral */ in read_exp_features_info()
3809 (hdev->le_states[3] & 0x10)) /* Simultaneous */ in read_exp_features_info()
3819 if (hdev && use_ll_privacy(hdev)) { in read_exp_features_info()
3820 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in read_exp_features_info()
3837 return mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in read_exp_features_info()
3842 static int exp_ll_privacy_feature_changed(bool enabled, struct hci_dev *hdev, in exp_ll_privacy_feature_changed() argument
3851 return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, in exp_ll_privacy_feature_changed()
3872 static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, in set_exp_feature() argument
3878 bt_dev_dbg(hdev, "sock %p", sk); in set_exp_feature()
3885 if (!hdev) { in set_exp_feature()
3895 if (hdev && use_ll_privacy(hdev) && !hdev_is_powered(hdev)) { in set_exp_feature()
3896 bool changed = hci_dev_test_flag(hdev, in set_exp_feature()
3899 hci_dev_clear_flag(hdev, HCI_ENABLE_LL_PRIVACY); in set_exp_feature()
3902 exp_ll_privacy_feature_changed(false, hdev, sk); in set_exp_feature()
3907 return mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_exp_feature()
3918 if (hdev) in set_exp_feature()
3919 return mgmt_cmd_status(sk, hdev->id, in set_exp_feature()
3961 if (!hdev) in set_exp_feature()
3967 if (hdev_is_powered(hdev)) in set_exp_feature()
3968 return mgmt_cmd_status(sk, hdev->id, in set_exp_feature()
3974 return mgmt_cmd_status(sk, hdev->id, in set_exp_feature()
3980 return mgmt_cmd_status(sk, hdev->id, in set_exp_feature()
3987 changed = !hci_dev_test_flag(hdev, in set_exp_feature()
3989 hci_dev_set_flag(hdev, HCI_ENABLE_LL_PRIVACY); in set_exp_feature()
3990 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_exp_feature()
3995 changed = hci_dev_test_flag(hdev, in set_exp_feature()
3997 hci_dev_clear_flag(hdev, HCI_ENABLE_LL_PRIVACY); in set_exp_feature()
4008 err = mgmt_cmd_complete(sk, hdev->id, in set_exp_feature()
4013 exp_ll_privacy_feature_changed(val, hdev, sk); in set_exp_feature()
4018 return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_exp_feature()
4025 static int get_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in get_device_flags() argument
4036 bt_dev_dbg(hdev, "Get device flags %pMR (type 0x%x)\n", in get_device_flags()
4039 hci_dev_lock(hdev); in get_device_flags()
4044 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->whitelist, in get_device_flags()
4052 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in get_device_flags()
4069 hci_dev_unlock(hdev); in get_device_flags()
4071 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_DEVICE_FLAGS, status, in get_device_flags()
4075 static void device_flags_changed(struct sock *sk, struct hci_dev *hdev, in device_flags_changed() argument
4086 mgmt_event(MGMT_EV_DEVICE_FLAGS_CHANGED, hdev, &ev, sizeof(ev), sk); in device_flags_changed()
4089 static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_flags() argument
4099 bt_dev_dbg(hdev, "Set device flags %pMR (type 0x%x) = 0x%x", in set_device_flags()
4104 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
4109 hci_dev_lock(hdev); in set_device_flags()
4112 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->whitelist, in set_device_flags()
4120 bt_dev_warn(hdev, "No such BR/EDR device %pMR (0x%x)", in set_device_flags()
4124 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in set_device_flags()
4130 bt_dev_warn(hdev, "No such LE device %pMR (0x%x)", in set_device_flags()
4137 hci_dev_unlock(hdev); in set_device_flags()
4140 device_flags_changed(sk, hdev, &cp->addr.bdaddr, cp->addr.type, in set_device_flags()
4143 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_FLAGS, status, in set_device_flags()
4147 static void mgmt_adv_monitor_added(struct sock *sk, struct hci_dev *hdev, in mgmt_adv_monitor_added() argument
4154 mgmt_event(MGMT_EV_ADV_MONITOR_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_adv_monitor_added()
4157 static void mgmt_adv_monitor_removed(struct sock *sk, struct hci_dev *hdev, in mgmt_adv_monitor_removed() argument
4164 mgmt_event(MGMT_EV_ADV_MONITOR_REMOVED, hdev, &ev, sizeof(ev), sk); in mgmt_adv_monitor_removed()
4167 static int read_adv_mon_features(struct sock *sk, struct hci_dev *hdev, in read_adv_mon_features() argument
4178 BT_DBG("request for %s", hdev->name); in read_adv_mon_features()
4180 hci_dev_lock(hdev); in read_adv_mon_features()
4182 if (msft_get_features(hdev) & MSFT_FEATURE_MASK_LE_ADV_MONITOR) in read_adv_mon_features()
4185 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) { in read_adv_mon_features()
4189 hci_dev_unlock(hdev); in read_adv_mon_features()
4207 err = mgmt_cmd_complete(sk, hdev->id, in read_adv_mon_features()
4216 static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor() argument
4227 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor()
4230 err = mgmt_cmd_status(sk, hdev->id, in add_adv_patterns_monitor()
4247 err = mgmt_cmd_status(sk, hdev->id, in add_adv_patterns_monitor()
4258 err = mgmt_cmd_status(sk, hdev->id, in add_adv_patterns_monitor()
4280 err = mgmt_cmd_status(sk, hdev->id, in add_adv_patterns_monitor()
4286 hci_dev_lock(hdev); in add_adv_patterns_monitor()
4288 prev_adv_monitors_cnt = hdev->adv_monitors_cnt; in add_adv_patterns_monitor()
4290 err = hci_add_adv_monitor(hdev, m); in add_adv_patterns_monitor()
4293 mgmt_cmd_status(sk, hdev->id, in add_adv_patterns_monitor()
4300 if (hdev->adv_monitors_cnt > prev_adv_monitors_cnt) in add_adv_patterns_monitor()
4301 mgmt_adv_monitor_added(sk, hdev, m->handle); in add_adv_patterns_monitor()
4303 hci_dev_unlock(hdev); in add_adv_patterns_monitor()
4307 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADV_PATTERNS_MONITOR, in add_adv_patterns_monitor()
4311 hci_dev_unlock(hdev); in add_adv_patterns_monitor()
4318 static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev, in remove_adv_monitor() argument
4327 BT_DBG("request for %s", hdev->name); in remove_adv_monitor()
4329 hci_dev_lock(hdev); in remove_adv_monitor()
4332 prev_adv_monitors_cnt = hdev->adv_monitors_cnt; in remove_adv_monitor()
4334 err = hci_remove_adv_monitor(hdev, handle); in remove_adv_monitor()
4336 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, in remove_adv_monitor()
4341 if (hdev->adv_monitors_cnt < prev_adv_monitors_cnt) in remove_adv_monitor()
4342 mgmt_adv_monitor_removed(sk, hdev, handle); in remove_adv_monitor()
4344 hci_dev_unlock(hdev); in remove_adv_monitor()
4348 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, in remove_adv_monitor()
4352 hci_dev_unlock(hdev); in remove_adv_monitor()
4356 static void read_local_oob_data_complete(struct hci_dev *hdev, u8 status, in read_local_oob_data_complete() argument
4363 bt_dev_dbg(hdev, "status %u", status); in read_local_oob_data_complete()
4365 cmd = pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev); in read_local_oob_data_complete()
4370 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data_complete()
4381 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
4395 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
4408 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data_complete()
4415 static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_data() argument
4422 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_data()
4424 hci_dev_lock(hdev); in read_local_oob_data()
4426 if (!hdev_is_powered(hdev)) { in read_local_oob_data()
4427 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
4432 if (!lmp_ssp_capable(hdev)) { in read_local_oob_data()
4433 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
4438 if (pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev)) { in read_local_oob_data()
4439 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
4444 cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_DATA, hdev, NULL, 0); in read_local_oob_data()
4450 hci_req_init(&req, hdev); in read_local_oob_data()
4452 if (bredr_sc_enabled(hdev)) in read_local_oob_data()
4462 hci_dev_unlock(hdev); in read_local_oob_data()
4466 static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in add_remote_oob_data() argument
4472 bt_dev_dbg(hdev, "sock %p", sk); in add_remote_oob_data()
4475 return mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
4480 hci_dev_lock(hdev); in add_remote_oob_data()
4487 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
4494 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
4502 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
4516 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
4551 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
4559 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
4563 bt_dev_err(hdev, "add_remote_oob_data: invalid len of %u bytes", in add_remote_oob_data()
4565 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, in add_remote_oob_data()
4570 hci_dev_unlock(hdev); in add_remote_oob_data()
4574 static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in remove_remote_oob_data() argument
4581 bt_dev_dbg(hdev, "sock %p", sk); in remove_remote_oob_data()
4584 return mgmt_cmd_complete(sk, hdev->id, in remove_remote_oob_data()
4589 hci_dev_lock(hdev); in remove_remote_oob_data()
4592 hci_remote_oob_data_clear(hdev); in remove_remote_oob_data()
4597 err = hci_remove_remote_oob_data(hdev, &cp->addr.bdaddr, cp->addr.type); in remove_remote_oob_data()
4604 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA, in remove_remote_oob_data()
4607 hci_dev_unlock(hdev); in remove_remote_oob_data()
4611 void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_start_discovery_complete() argument
4615 bt_dev_dbg(hdev, "status %d", status); in mgmt_start_discovery_complete()
4617 hci_dev_lock(hdev); in mgmt_start_discovery_complete()
4619 cmd = pending_find(MGMT_OP_START_DISCOVERY, hdev); in mgmt_start_discovery_complete()
4621 cmd = pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev); in mgmt_start_discovery_complete()
4624 cmd = pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev); in mgmt_start_discovery_complete()
4631 hci_dev_unlock(hdev); in mgmt_start_discovery_complete()
4635 hdev->suspend_tasks)) { in mgmt_start_discovery_complete()
4636 bt_dev_dbg(hdev, "Unpaused discovery"); in mgmt_start_discovery_complete()
4637 wake_up(&hdev->suspend_wait_q); in mgmt_start_discovery_complete()
4641 static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, in discovery_type_is_valid() argument
4646 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
4651 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
4656 *mgmt_status = mgmt_bredr_support(hdev); in discovery_type_is_valid()
4668 static int start_discovery_internal(struct sock *sk, struct hci_dev *hdev, in start_discovery_internal() argument
4676 bt_dev_dbg(hdev, "sock %p", sk); in start_discovery_internal()
4678 hci_dev_lock(hdev); in start_discovery_internal()
4680 if (!hdev_is_powered(hdev)) { in start_discovery_internal()
4681 err = mgmt_cmd_complete(sk, hdev->id, op, in start_discovery_internal()
4687 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_discovery_internal()
4688 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_discovery_internal()
4689 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
4694 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_discovery_internal()
4695 err = mgmt_cmd_complete(sk, hdev->id, op, status, in start_discovery_internal()
4701 if (hdev->discovery_paused) { in start_discovery_internal()
4702 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
4710 hci_discovery_filter_clear(hdev); in start_discovery_internal()
4712 hdev->discovery.type = cp->type; in start_discovery_internal()
4713 hdev->discovery.report_invalid_rssi = false; in start_discovery_internal()
4715 hdev->discovery.limited = true; in start_discovery_internal()
4717 hdev->discovery.limited = false; in start_discovery_internal()
4719 cmd = mgmt_pending_add(sk, op, hdev, data, len); in start_discovery_internal()
4727 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_discovery_internal()
4728 queue_work(hdev->req_workqueue, &hdev->discov_update); in start_discovery_internal()
4732 hci_dev_unlock(hdev); in start_discovery_internal()
4736 static int start_discovery(struct sock *sk, struct hci_dev *hdev, in start_discovery() argument
4739 return start_discovery_internal(sk, hdev, MGMT_OP_START_DISCOVERY, in start_discovery()
4743 static int start_limited_discovery(struct sock *sk, struct hci_dev *hdev, in start_limited_discovery() argument
4746 return start_discovery_internal(sk, hdev, in start_limited_discovery()
4758 static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, in start_service_discovery() argument
4768 bt_dev_dbg(hdev, "sock %p", sk); in start_service_discovery()
4770 hci_dev_lock(hdev); in start_service_discovery()
4772 if (!hdev_is_powered(hdev)) { in start_service_discovery()
4773 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4780 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_service_discovery()
4781 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_service_discovery()
4782 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4791 bt_dev_err(hdev, "service_discovery: too big uuid_count value %u", in start_service_discovery()
4793 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4802 bt_dev_err(hdev, "service_discovery: expected %u bytes, got %u bytes", in start_service_discovery()
4804 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4811 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_service_discovery()
4812 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4819 hdev, data, len); in start_service_discovery()
4830 hci_discovery_filter_clear(hdev); in start_service_discovery()
4832 hdev->discovery.result_filtering = true; in start_service_discovery()
4833 hdev->discovery.type = cp->type; in start_service_discovery()
4834 hdev->discovery.rssi = cp->rssi; in start_service_discovery()
4835 hdev->discovery.uuid_count = uuid_count; in start_service_discovery()
4838 hdev->discovery.uuids = kmemdup(cp->uuids, uuid_count * 16, in start_service_discovery()
4840 if (!hdev->discovery.uuids) { in start_service_discovery()
4841 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4850 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_service_discovery()
4851 queue_work(hdev->req_workqueue, &hdev->discov_update); in start_service_discovery()
4855 hci_dev_unlock(hdev); in start_service_discovery()
4859 void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_stop_discovery_complete() argument
4863 bt_dev_dbg(hdev, "status %d", status); in mgmt_stop_discovery_complete()
4865 hci_dev_lock(hdev); in mgmt_stop_discovery_complete()
4867 cmd = pending_find(MGMT_OP_STOP_DISCOVERY, hdev); in mgmt_stop_discovery_complete()
4873 hci_dev_unlock(hdev); in mgmt_stop_discovery_complete()
4876 if (test_and_clear_bit(SUSPEND_PAUSE_DISCOVERY, hdev->suspend_tasks)) { in mgmt_stop_discovery_complete()
4877 bt_dev_dbg(hdev, "Paused discovery"); in mgmt_stop_discovery_complete()
4878 wake_up(&hdev->suspend_wait_q); in mgmt_stop_discovery_complete()
4882 static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, in stop_discovery() argument
4889 bt_dev_dbg(hdev, "sock %p", sk); in stop_discovery()
4891 hci_dev_lock(hdev); in stop_discovery()
4893 if (!hci_discovery_active(hdev)) { in stop_discovery()
4894 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
4900 if (hdev->discovery.type != mgmt_cp->type) { in stop_discovery()
4901 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
4907 cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, hdev, data, len); in stop_discovery()
4915 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in stop_discovery()
4916 queue_work(hdev->req_workqueue, &hdev->discov_update); in stop_discovery()
4920 hci_dev_unlock(hdev); in stop_discovery()
4924 static int confirm_name(struct sock *sk, struct hci_dev *hdev, void *data, in confirm_name() argument
4931 bt_dev_dbg(hdev, "sock %p", sk); in confirm_name()
4933 hci_dev_lock(hdev); in confirm_name()
4935 if (!hci_discovery_active(hdev)) { in confirm_name()
4936 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
4942 e = hci_inquiry_cache_lookup_unknown(hdev, &cp->addr.bdaddr); in confirm_name()
4944 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
4955 hci_inquiry_cache_update_resolve(hdev, e); in confirm_name()
4958 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, 0, in confirm_name()
4962 hci_dev_unlock(hdev); in confirm_name()
4966 static int block_device(struct sock *sk, struct hci_dev *hdev, void *data, in block_device() argument
4973 bt_dev_dbg(hdev, "sock %p", sk); in block_device()
4976 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, in block_device()
4980 hci_dev_lock(hdev); in block_device()
4982 err = hci_bdaddr_list_add(&hdev->blacklist, &cp->addr.bdaddr, in block_device()
4989 mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &cp->addr, sizeof(cp->addr), in block_device()
4994 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status, in block_device()
4997 hci_dev_unlock(hdev); in block_device()
5002 static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data, in unblock_device() argument
5009 bt_dev_dbg(hdev, "sock %p", sk); in unblock_device()
5012 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, in unblock_device()
5016 hci_dev_lock(hdev); in unblock_device()
5018 err = hci_bdaddr_list_del(&hdev->blacklist, &cp->addr.bdaddr, in unblock_device()
5025 mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &cp->addr, sizeof(cp->addr), in unblock_device()
5030 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status, in unblock_device()
5033 hci_dev_unlock(hdev); in unblock_device()
5038 static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_id() argument
5046 bt_dev_dbg(hdev, "sock %p", sk); in set_device_id()
5051 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, in set_device_id()
5054 hci_dev_lock(hdev); in set_device_id()
5056 hdev->devid_source = source; in set_device_id()
5057 hdev->devid_vendor = __le16_to_cpu(cp->vendor); in set_device_id()
5058 hdev->devid_product = __le16_to_cpu(cp->product); in set_device_id()
5059 hdev->devid_version = __le16_to_cpu(cp->version); in set_device_id()
5061 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, 0, in set_device_id()
5064 hci_req_init(&req, hdev); in set_device_id()
5068 hci_dev_unlock(hdev); in set_device_id()
5073 static void enable_advertising_instance(struct hci_dev *hdev, u8 status, in enable_advertising_instance() argument
5076 bt_dev_dbg(hdev, "status %d", status); in enable_advertising_instance()
5079 static void set_advertising_complete(struct hci_dev *hdev, u8 status, in set_advertising_complete() argument
5082 struct cmd_lookup match = { NULL, hdev }; in set_advertising_complete()
5088 hci_dev_lock(hdev); in set_advertising_complete()
5093 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, in set_advertising_complete()
5098 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_advertising_complete()
5099 hci_dev_set_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
5101 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
5103 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, settings_rsp, in set_advertising_complete()
5106 new_settings(hdev, match.sk); in set_advertising_complete()
5113 hdev->suspend_tasks)) { in set_advertising_complete()
5114 bt_dev_dbg(hdev, "Paused advertising"); in set_advertising_complete()
5115 wake_up(&hdev->suspend_wait_q); in set_advertising_complete()
5117 hdev->suspend_tasks)) { in set_advertising_complete()
5118 bt_dev_dbg(hdev, "Unpaused advertising"); in set_advertising_complete()
5119 wake_up(&hdev->suspend_wait_q); in set_advertising_complete()
5125 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in set_advertising_complete()
5126 list_empty(&hdev->adv_instances)) in set_advertising_complete()
5129 instance = hdev->cur_adv_instance; in set_advertising_complete()
5131 adv_instance = list_first_entry_or_null(&hdev->adv_instances, in set_advertising_complete()
5139 hci_req_init(&req, hdev); in set_advertising_complete()
5147 bt_dev_err(hdev, "failed to re-configure advertising"); in set_advertising_complete()
5150 hci_dev_unlock(hdev); in set_advertising_complete()
5153 static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, in set_advertising() argument
5162 bt_dev_dbg(hdev, "sock %p", sk); in set_advertising()
5164 status = mgmt_le_support(hdev); in set_advertising()
5166 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
5172 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in set_advertising()
5173 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
5177 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
5180 if (hdev->advertising_paused) in set_advertising()
5181 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
5184 hci_dev_lock(hdev); in set_advertising()
5193 if (!hdev_is_powered(hdev) || in set_advertising()
5194 (val == hci_dev_test_flag(hdev, HCI_ADVERTISING) && in set_advertising()
5195 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) || in set_advertising()
5196 hci_conn_num(hdev, LE_LINK) > 0 || in set_advertising()
5197 (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_advertising()
5198 hdev->le_scan_type == LE_SCAN_ACTIVE)) { in set_advertising()
5202 hdev->cur_adv_instance = 0x00; in set_advertising()
5203 changed = !hci_dev_test_and_set_flag(hdev, HCI_ADVERTISING); in set_advertising()
5205 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
5207 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
5209 changed = hci_dev_test_and_clear_flag(hdev, HCI_ADVERTISING); in set_advertising()
5210 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
5213 err = send_settings_rsp(sk, MGMT_OP_SET_ADVERTISING, hdev); in set_advertising()
5218 err = new_settings(hdev, sk); in set_advertising()
5223 if (pending_find(MGMT_OP_SET_ADVERTISING, hdev) || in set_advertising()
5224 pending_find(MGMT_OP_SET_LE, hdev)) { in set_advertising()
5225 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
5230 cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING, hdev, data, len); in set_advertising()
5236 hci_req_init(&req, hdev); in set_advertising()
5239 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
5241 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
5243 cancel_adv_timeout(hdev); in set_advertising()
5250 hdev->cur_adv_instance = 0x00; in set_advertising()
5252 if (ext_adv_capable(hdev)) { in set_advertising()
5268 hci_dev_unlock(hdev); in set_advertising()
5272 static int set_static_address(struct sock *sk, struct hci_dev *hdev, in set_static_address() argument
5278 bt_dev_dbg(hdev, "sock %p", sk); in set_static_address()
5280 if (!lmp_le_capable(hdev)) in set_static_address()
5281 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
5284 if (hdev_is_powered(hdev)) in set_static_address()
5285 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
5290 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
5296 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
5301 hci_dev_lock(hdev); in set_static_address()
5303 bacpy(&hdev->static_addr, &cp->bdaddr); in set_static_address()
5305 err = send_settings_rsp(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev); in set_static_address()
5309 err = new_settings(hdev, sk); in set_static_address()
5312 hci_dev_unlock(hdev); in set_static_address()
5316 static int set_scan_params(struct sock *sk, struct hci_dev *hdev, in set_scan_params() argument
5323 bt_dev_dbg(hdev, "sock %p", sk); in set_scan_params()
5325 if (!lmp_le_capable(hdev)) in set_scan_params()
5326 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
5332 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
5338 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
5342 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
5345 hci_dev_lock(hdev); in set_scan_params()
5347 hdev->le_scan_interval = interval; in set_scan_params()
5348 hdev->le_scan_window = window; in set_scan_params()
5350 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, 0, in set_scan_params()
5356 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_scan_params()
5357 hdev->discovery.state == DISCOVERY_STOPPED) { in set_scan_params()
5360 hci_req_init(&req, hdev); in set_scan_params()
5368 hci_dev_unlock(hdev); in set_scan_params()
5373 static void fast_connectable_complete(struct hci_dev *hdev, u8 status, in fast_connectable_complete() argument
5378 bt_dev_dbg(hdev, "status 0x%02x", status); in fast_connectable_complete()
5380 hci_dev_lock(hdev); in fast_connectable_complete()
5382 cmd = pending_find(MGMT_OP_SET_FAST_CONNECTABLE, hdev); in fast_connectable_complete()
5387 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in fast_connectable_complete()
5393 hci_dev_set_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
5395 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
5397 send_settings_rsp(cmd->sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in fast_connectable_complete()
5398 new_settings(hdev, cmd->sk); in fast_connectable_complete()
5404 hci_dev_unlock(hdev); in fast_connectable_complete()
5407 static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev, in set_fast_connectable() argument
5415 bt_dev_dbg(hdev, "sock %p", sk); in set_fast_connectable()
5417 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in set_fast_connectable()
5418 hdev->hci_ver < BLUETOOTH_VER_1_2) in set_fast_connectable()
5419 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
5423 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
5426 hci_dev_lock(hdev); in set_fast_connectable()
5428 if (pending_find(MGMT_OP_SET_FAST_CONNECTABLE, hdev)) { in set_fast_connectable()
5429 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
5434 if (!!cp->val == hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) { in set_fast_connectable()
5436 hdev); in set_fast_connectable()
5440 if (!hdev_is_powered(hdev)) { in set_fast_connectable()
5441 hci_dev_change_flag(hdev, HCI_FAST_CONNECTABLE); in set_fast_connectable()
5443 hdev); in set_fast_connectable()
5444 new_settings(hdev, sk); in set_fast_connectable()
5448 cmd = mgmt_pending_add(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev, in set_fast_connectable()
5455 hci_req_init(&req, hdev); in set_fast_connectable()
5461 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
5467 hci_dev_unlock(hdev); in set_fast_connectable()
5472 static void set_bredr_complete(struct hci_dev *hdev, u8 status, u16 opcode) in set_bredr_complete() argument
5476 bt_dev_dbg(hdev, "status 0x%02x", status); in set_bredr_complete()
5478 hci_dev_lock(hdev); in set_bredr_complete()
5480 cmd = pending_find(MGMT_OP_SET_BREDR, hdev); in set_bredr_complete()
5490 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in set_bredr_complete()
5494 send_settings_rsp(cmd->sk, MGMT_OP_SET_BREDR, hdev); in set_bredr_complete()
5495 new_settings(hdev, cmd->sk); in set_bredr_complete()
5501 hci_dev_unlock(hdev); in set_bredr_complete()
5504 static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_bredr() argument
5511 bt_dev_dbg(hdev, "sock %p", sk); in set_bredr()
5513 if (!lmp_bredr_capable(hdev) || !lmp_le_capable(hdev)) in set_bredr()
5514 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5517 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_bredr()
5518 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5522 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5525 hci_dev_lock(hdev); in set_bredr()
5527 if (cp->val == hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_bredr()
5528 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
5532 if (!hdev_is_powered(hdev)) { in set_bredr()
5534 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_bredr()
5535 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_bredr()
5536 hci_dev_clear_flag(hdev, HCI_LINK_SECURITY); in set_bredr()
5537 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in set_bredr()
5538 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_bredr()
5541 hci_dev_change_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
5543 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
5547 err = new_settings(hdev, sk); in set_bredr()
5553 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5571 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_bredr()
5572 (bacmp(&hdev->static_addr, BDADDR_ANY) || in set_bredr()
5573 hci_dev_test_flag(hdev, HCI_SC_ENABLED))) { in set_bredr()
5574 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5580 if (pending_find(MGMT_OP_SET_BREDR, hdev)) { in set_bredr()
5581 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5586 cmd = mgmt_pending_add(sk, MGMT_OP_SET_BREDR, hdev, data, len); in set_bredr()
5595 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
5597 hci_req_init(&req, hdev); in set_bredr()
5605 __hci_req_update_adv_data(&req, hdev->cur_adv_instance); in set_bredr()
5612 hci_dev_unlock(hdev); in set_bredr()
5616 static void sc_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) in sc_enable_complete() argument
5621 bt_dev_dbg(hdev, "status %u", status); in sc_enable_complete()
5623 hci_dev_lock(hdev); in sc_enable_complete()
5625 cmd = pending_find(MGMT_OP_SET_SECURE_CONN, hdev); in sc_enable_complete()
5639 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in sc_enable_complete()
5640 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in sc_enable_complete()
5643 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in sc_enable_complete()
5644 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in sc_enable_complete()
5647 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in sc_enable_complete()
5648 hci_dev_set_flag(hdev, HCI_SC_ONLY); in sc_enable_complete()
5652 send_settings_rsp(cmd->sk, MGMT_OP_SET_SECURE_CONN, hdev); in sc_enable_complete()
5653 new_settings(hdev, cmd->sk); in sc_enable_complete()
5658 hci_dev_unlock(hdev); in sc_enable_complete()
5661 static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, in set_secure_conn() argument
5670 bt_dev_dbg(hdev, "sock %p", sk); in set_secure_conn()
5672 if (!lmp_sc_capable(hdev) && in set_secure_conn()
5673 !hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_secure_conn()
5674 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
5677 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_secure_conn()
5678 lmp_sc_capable(hdev) && in set_secure_conn()
5679 !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_secure_conn()
5680 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
5684 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
5687 hci_dev_lock(hdev); in set_secure_conn()
5689 if (!hdev_is_powered(hdev) || !lmp_sc_capable(hdev) || in set_secure_conn()
5690 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_secure_conn()
5694 changed = !hci_dev_test_and_set_flag(hdev, in set_secure_conn()
5697 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
5699 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
5701 changed = hci_dev_test_and_clear_flag(hdev, in set_secure_conn()
5703 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
5706 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
5711 err = new_settings(hdev, sk); in set_secure_conn()
5716 if (pending_find(MGMT_OP_SET_SECURE_CONN, hdev)) { in set_secure_conn()
5717 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
5724 if (val == hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in set_secure_conn()
5725 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in set_secure_conn()
5726 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
5730 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len); in set_secure_conn()
5736 hci_req_init(&req, hdev); in set_secure_conn()
5745 hci_dev_unlock(hdev); in set_secure_conn()
5749 static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, in set_debug_keys() argument
5756 bt_dev_dbg(hdev, "sock %p", sk); in set_debug_keys()
5759 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEBUG_KEYS, in set_debug_keys()
5762 hci_dev_lock(hdev); in set_debug_keys()
5765 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in set_debug_keys()
5767 changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
5771 use_changed = !hci_dev_test_and_set_flag(hdev, in set_debug_keys()
5774 use_changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
5777 if (hdev_is_powered(hdev) && use_changed && in set_debug_keys()
5778 hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_debug_keys()
5780 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in set_debug_keys()
5784 err = send_settings_rsp(sk, MGMT_OP_SET_DEBUG_KEYS, hdev); in set_debug_keys()
5789 err = new_settings(hdev, sk); in set_debug_keys()
5792 hci_dev_unlock(hdev); in set_debug_keys()
5796 static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data, in set_privacy() argument
5803 bt_dev_dbg(hdev, "sock %p", sk); in set_privacy()
5805 if (!lmp_le_capable(hdev)) in set_privacy()
5806 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
5810 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
5813 if (hdev_is_powered(hdev)) in set_privacy()
5814 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
5817 hci_dev_lock(hdev); in set_privacy()
5822 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in set_privacy()
5825 changed = !hci_dev_test_and_set_flag(hdev, HCI_PRIVACY); in set_privacy()
5826 memcpy(hdev->irk, cp->irk, sizeof(hdev->irk)); in set_privacy()
5827 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
5828 hci_adv_instances_set_rpa_expired(hdev, true); in set_privacy()
5830 hci_dev_set_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
5832 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
5834 changed = hci_dev_test_and_clear_flag(hdev, HCI_PRIVACY); in set_privacy()
5835 memset(hdev->irk, 0, sizeof(hdev->irk)); in set_privacy()
5836 hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
5837 hci_adv_instances_set_rpa_expired(hdev, false); in set_privacy()
5838 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
5841 err = send_settings_rsp(sk, MGMT_OP_SET_PRIVACY, hdev); in set_privacy()
5846 err = new_settings(hdev, sk); in set_privacy()
5849 hci_dev_unlock(hdev); in set_privacy()
5869 static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data, in load_irks() argument
5878 bt_dev_dbg(hdev, "sock %p", sk); in load_irks()
5880 if (!lmp_le_capable(hdev)) in load_irks()
5881 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
5886 bt_dev_err(hdev, "load_irks: too big irk_count value %u", in load_irks()
5888 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
5894 bt_dev_err(hdev, "load_irks: expected %u bytes, got %u bytes", in load_irks()
5896 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
5900 bt_dev_dbg(hdev, "irk_count %u", irk_count); in load_irks()
5906 return mgmt_cmd_status(sk, hdev->id, in load_irks()
5911 hci_dev_lock(hdev); in load_irks()
5913 hci_smp_irks_clear(hdev); in load_irks()
5918 if (hci_is_blocked_key(hdev, in load_irks()
5921 bt_dev_warn(hdev, "Skipping blocked IRK for %pMR", in load_irks()
5926 hci_add_irk(hdev, &irk->addr.bdaddr, in load_irks()
5931 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in load_irks()
5933 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_IRKS, 0, NULL, 0); in load_irks()
5935 hci_dev_unlock(hdev); in load_irks()
5959 static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev, in load_long_term_keys() argument
5968 bt_dev_dbg(hdev, "sock %p", sk); in load_long_term_keys()
5970 if (!lmp_le_capable(hdev)) in load_long_term_keys()
5971 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
5976 bt_dev_err(hdev, "load_ltks: too big key_count value %u", in load_long_term_keys()
5978 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
5984 bt_dev_err(hdev, "load_keys: expected %u bytes, got %u bytes", in load_long_term_keys()
5986 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
5990 bt_dev_dbg(hdev, "key_count %u", key_count); in load_long_term_keys()
5996 return mgmt_cmd_status(sk, hdev->id, in load_long_term_keys()
6001 hci_dev_lock(hdev); in load_long_term_keys()
6003 hci_smp_ltks_clear(hdev); in load_long_term_keys()
6009 if (hci_is_blocked_key(hdev, in load_long_term_keys()
6012 bt_dev_warn(hdev, "Skipping blocked LTK for %pMR", in load_long_term_keys()
6042 hci_add_ltk(hdev, &key->addr.bdaddr, in load_long_term_keys()
6047 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 0, in load_long_term_keys()
6050 hci_dev_unlock(hdev); in load_long_term_keys()
6082 static void conn_info_refresh_complete(struct hci_dev *hdev, u8 hci_status, in conn_info_refresh_complete() argument
6091 bt_dev_dbg(hdev, "status 0x%02x", hci_status); in conn_info_refresh_complete()
6093 hci_dev_lock(hdev); in conn_info_refresh_complete()
6104 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_RSSI); in conn_info_refresh_complete()
6106 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER); in conn_info_refresh_complete()
6113 bt_dev_err(hdev, "invalid sent_cmd in conn_info response"); in conn_info_refresh_complete()
6118 conn = hci_conn_hash_lookup_handle(hdev, handle); in conn_info_refresh_complete()
6120 bt_dev_err(hdev, "unknown handle (%d) in conn_info response", in conn_info_refresh_complete()
6125 cmd = pending_find_data(MGMT_OP_GET_CONN_INFO, hdev, conn); in conn_info_refresh_complete()
6133 hci_dev_unlock(hdev); in conn_info_refresh_complete()
6136 static int get_conn_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_conn_info() argument
6145 bt_dev_dbg(hdev, "sock %p", sk); in get_conn_info()
6152 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
6156 hci_dev_lock(hdev); in get_conn_info()
6158 if (!hdev_is_powered(hdev)) { in get_conn_info()
6159 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
6166 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info()
6169 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info()
6172 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
6178 if (pending_find_data(MGMT_OP_GET_CONN_INFO, hdev, conn)) { in get_conn_info()
6179 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
6187 conn_info_age = hdev->conn_info_min_age + in get_conn_info()
6188 prandom_u32_max(hdev->conn_info_max_age - in get_conn_info()
6189 hdev->conn_info_min_age); in get_conn_info()
6202 hci_req_init(&req, hdev); in get_conn_info()
6230 cmd = mgmt_pending_add(sk, MGMT_OP_GET_CONN_INFO, hdev, in get_conn_info()
6248 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
6253 hci_dev_unlock(hdev); in get_conn_info()
6261 struct hci_dev *hdev; in clock_info_cmd_complete() local
6270 hdev = hci_dev_get(cmd->index); in clock_info_cmd_complete()
6271 if (hdev) { in clock_info_cmd_complete()
6272 rp.local_clock = cpu_to_le32(hdev->clock); in clock_info_cmd_complete()
6273 hci_dev_put(hdev); in clock_info_cmd_complete()
6293 static void get_clock_info_complete(struct hci_dev *hdev, u8 status, u16 opcode) in get_clock_info_complete() argument
6299 bt_dev_dbg(hdev, "status %u", status); in get_clock_info_complete()
6301 hci_dev_lock(hdev); in get_clock_info_complete()
6303 hci_cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK); in get_clock_info_complete()
6309 conn = hci_conn_hash_lookup_handle(hdev, handle); in get_clock_info_complete()
6314 cmd = pending_find_data(MGMT_OP_GET_CLOCK_INFO, hdev, conn); in get_clock_info_complete()
6322 hci_dev_unlock(hdev); in get_clock_info_complete()
6325 static int get_clock_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_clock_info() argument
6336 bt_dev_dbg(hdev, "sock %p", sk); in get_clock_info()
6343 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
6347 hci_dev_lock(hdev); in get_clock_info()
6349 if (!hdev_is_powered(hdev)) { in get_clock_info()
6350 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
6357 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_clock_info()
6360 err = mgmt_cmd_complete(sk, hdev->id, in get_clock_info()
6370 cmd = mgmt_pending_add(sk, MGMT_OP_GET_CLOCK_INFO, hdev, data, len); in get_clock_info()
6378 hci_req_init(&req, hdev); in get_clock_info()
6397 hci_dev_unlock(hdev); in get_clock_info()
6401 static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type) in is_connected() argument
6405 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, addr); in is_connected()
6419 static int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, in hci_conn_params_set() argument
6424 params = hci_conn_params_add(hdev, addr, addr_type); in hci_conn_params_set()
6440 list_add(¶ms->action, &hdev->pend_le_conns); in hci_conn_params_set()
6444 list_add(¶ms->action, &hdev->pend_le_conns); in hci_conn_params_set()
6446 list_add(¶ms->action, &hdev->pend_le_reports); in hci_conn_params_set()
6450 if (!is_connected(hdev, addr, addr_type)) in hci_conn_params_set()
6451 list_add(¶ms->action, &hdev->pend_le_conns); in hci_conn_params_set()
6457 bt_dev_dbg(hdev, "addr %pMR (type %u) auto_connect %u", in hci_conn_params_set()
6463 static void device_added(struct sock *sk, struct hci_dev *hdev, in device_added() argument
6472 mgmt_event(MGMT_EV_DEVICE_ADDED, hdev, &ev, sizeof(ev), sk); in device_added()
6475 static int add_device(struct sock *sk, struct hci_dev *hdev, in add_device() argument
6484 bt_dev_dbg(hdev, "sock %p", sk); in add_device()
6488 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
6493 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
6497 hci_dev_lock(hdev); in add_device()
6502 err = mgmt_cmd_complete(sk, hdev->id, in add_device()
6509 err = hci_bdaddr_list_add_with_flags(&hdev->whitelist, in add_device()
6515 hci_req_update_scan(hdev); in add_device()
6535 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
6544 if (hci_conn_params_set(hdev, &cp->addr.bdaddr, addr_type, in add_device()
6546 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
6551 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in add_device()
6557 hci_update_background_scan(hdev); in add_device()
6560 device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action); in add_device()
6561 device_flags_changed(NULL, hdev, &cp->addr.bdaddr, cp->addr.type, in add_device()
6564 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
6569 hci_dev_unlock(hdev); in add_device()
6573 static void device_removed(struct sock *sk, struct hci_dev *hdev, in device_removed() argument
6581 mgmt_event(MGMT_EV_DEVICE_REMOVED, hdev, &ev, sizeof(ev), sk); in device_removed()
6584 static int remove_device(struct sock *sk, struct hci_dev *hdev, in remove_device() argument
6590 bt_dev_dbg(hdev, "sock %p", sk); in remove_device()
6592 hci_dev_lock(hdev); in remove_device()
6599 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6607 err = hci_bdaddr_list_del(&hdev->whitelist, in remove_device()
6611 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6619 hci_req_update_scan(hdev); in remove_device()
6621 device_removed(sk, hdev, &cp->addr.bdaddr, in remove_device()
6634 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6641 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in remove_device()
6644 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6653 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6663 hci_update_background_scan(hdev); in remove_device()
6665 device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type); in remove_device()
6671 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6678 list_for_each_entry_safe(b, btmp, &hdev->whitelist, list) { in remove_device()
6679 device_removed(sk, hdev, &b->bdaddr, b->bdaddr_type); in remove_device()
6684 hci_req_update_scan(hdev); in remove_device()
6686 list_for_each_entry_safe(p, tmp, &hdev->le_conn_params, list) { in remove_device()
6689 device_removed(sk, hdev, &p->addr, p->addr_type); in remove_device()
6699 bt_dev_dbg(hdev, "All LE connection parameters were removed"); in remove_device()
6701 hci_update_background_scan(hdev); in remove_device()
6705 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, in remove_device()
6709 hci_dev_unlock(hdev); in remove_device()
6713 static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data, in load_conn_param() argument
6722 if (!lmp_le_capable(hdev)) in load_conn_param()
6723 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
6728 bt_dev_err(hdev, "load_conn_param: too big param_count value %u", in load_conn_param()
6730 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
6736 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes", in load_conn_param()
6738 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
6742 bt_dev_dbg(hdev, "param_count %u", param_count); in load_conn_param()
6744 hci_dev_lock(hdev); in load_conn_param()
6746 hci_conn_params_clear_disabled(hdev); in load_conn_param()
6754 bt_dev_dbg(hdev, "Adding %pMR (type %u)", ¶m->addr.bdaddr, in load_conn_param()
6762 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
6771 bt_dev_dbg(hdev, "min 0x%04x max 0x%04x latency 0x%04x timeout 0x%04x", in load_conn_param()
6775 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
6779 hci_param = hci_conn_params_add(hdev, ¶m->addr.bdaddr, in load_conn_param()
6782 bt_dev_err(hdev, "failed to add connection parameters"); in load_conn_param()
6792 hci_dev_unlock(hdev); in load_conn_param()
6794 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 0, in load_conn_param()
6798 static int set_external_config(struct sock *sk, struct hci_dev *hdev, in set_external_config() argument
6805 bt_dev_dbg(hdev, "sock %p", sk); in set_external_config()
6807 if (hdev_is_powered(hdev)) in set_external_config()
6808 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
6812 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
6815 if (!test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in set_external_config()
6816 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
6819 hci_dev_lock(hdev); in set_external_config()
6822 changed = !hci_dev_test_and_set_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
6824 changed = hci_dev_test_and_clear_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
6826 err = send_options_rsp(sk, MGMT_OP_SET_EXTERNAL_CONFIG, hdev); in set_external_config()
6833 err = new_options(hdev, sk); in set_external_config()
6835 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) == is_configured(hdev)) { in set_external_config()
6836 mgmt_index_removed(hdev); in set_external_config()
6838 if (hci_dev_test_and_change_flag(hdev, HCI_UNCONFIGURED)) { in set_external_config()
6839 hci_dev_set_flag(hdev, HCI_CONFIG); in set_external_config()
6840 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_external_config()
6842 queue_work(hdev->req_workqueue, &hdev->power_on); in set_external_config()
6844 set_bit(HCI_RAW, &hdev->flags); in set_external_config()
6845 mgmt_index_added(hdev); in set_external_config()
6850 hci_dev_unlock(hdev); in set_external_config()
6854 static int set_public_address(struct sock *sk, struct hci_dev *hdev, in set_public_address() argument
6861 bt_dev_dbg(hdev, "sock %p", sk); in set_public_address()
6863 if (hdev_is_powered(hdev)) in set_public_address()
6864 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
6868 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
6871 if (!hdev->set_bdaddr) in set_public_address()
6872 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
6875 hci_dev_lock(hdev); in set_public_address()
6877 changed = !!bacmp(&hdev->public_addr, &cp->bdaddr); in set_public_address()
6878 bacpy(&hdev->public_addr, &cp->bdaddr); in set_public_address()
6880 err = send_options_rsp(sk, MGMT_OP_SET_PUBLIC_ADDRESS, hdev); in set_public_address()
6887 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in set_public_address()
6888 err = new_options(hdev, sk); in set_public_address()
6890 if (is_configured(hdev)) { in set_public_address()
6891 mgmt_index_removed(hdev); in set_public_address()
6893 hci_dev_clear_flag(hdev, HCI_UNCONFIGURED); in set_public_address()
6895 hci_dev_set_flag(hdev, HCI_CONFIG); in set_public_address()
6896 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_public_address()
6898 queue_work(hdev->req_workqueue, &hdev->power_on); in set_public_address()
6902 hci_dev_unlock(hdev); in set_public_address()
6906 static void read_local_oob_ext_data_complete(struct hci_dev *hdev, u8 status, in read_local_oob_ext_data_complete() argument
6916 bt_dev_dbg(hdev, "status %u", status); in read_local_oob_ext_data_complete()
6918 cmd = pending_find(MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev); in read_local_oob_ext_data_complete()
6958 if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in read_local_oob_ext_data_complete()
6981 hdev->dev_class, 3); in read_local_oob_ext_data_complete()
7001 err = mgmt_cmd_complete(cmd->sk, hdev->id, in read_local_oob_ext_data_complete()
7009 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data_complete()
7017 static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk, in read_local_ssp_oob_req() argument
7024 cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev, in read_local_ssp_oob_req()
7029 hci_req_init(&req, hdev); in read_local_ssp_oob_req()
7031 if (bredr_sc_enabled(hdev)) in read_local_ssp_oob_req()
7045 static int read_local_oob_ext_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_ext_data() argument
7055 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_ext_data()
7057 if (hdev_is_powered(hdev)) { in read_local_oob_ext_data()
7060 status = mgmt_bredr_support(hdev); in read_local_oob_ext_data()
7067 status = mgmt_le_support(hdev); in read_local_oob_ext_data()
7091 hci_dev_lock(hdev); in read_local_oob_ext_data()
7096 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in read_local_oob_ext_data()
7097 err = read_local_ssp_oob_req(hdev, sk, cp); in read_local_oob_ext_data()
7098 hci_dev_unlock(hdev); in read_local_oob_ext_data()
7107 hdev->dev_class, 3); in read_local_oob_ext_data()
7111 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in read_local_oob_ext_data()
7112 smp_generate_oob(hdev, hash, rand) < 0) { in read_local_oob_ext_data()
7113 hci_dev_unlock(hdev); in read_local_oob_ext_data()
7128 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { in read_local_oob_ext_data()
7129 hci_dev_unlock(hdev); in read_local_oob_ext_data()
7134 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in read_local_oob_ext_data()
7135 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in read_local_oob_ext_data()
7136 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in read_local_oob_ext_data()
7137 bacmp(&hdev->static_addr, BDADDR_ANY))) { in read_local_oob_ext_data()
7138 memcpy(addr, &hdev->static_addr, 6); in read_local_oob_ext_data()
7141 memcpy(addr, &hdev->bdaddr, 6); in read_local_oob_ext_data()
7148 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in read_local_oob_ext_data()
7156 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) { in read_local_oob_ext_data()
7166 flags = mgmt_get_adv_discov_flags(hdev); in read_local_oob_ext_data()
7168 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in read_local_oob_ext_data()
7176 hci_dev_unlock(hdev); in read_local_oob_ext_data()
7186 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, in read_local_oob_ext_data()
7191 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data()
7201 static u32 get_supported_adv_flags(struct hci_dev *hdev) in get_supported_adv_flags() argument
7215 if ((hdev->adv_tx_power != HCI_TX_POWER_INVALID) || in get_supported_adv_flags()
7216 ext_adv_capable(hdev)) in get_supported_adv_flags()
7219 if (ext_adv_capable(hdev)) { in get_supported_adv_flags()
7224 if (hdev->le_features[1] & HCI_LE_PHY_2M) in get_supported_adv_flags()
7227 if (hdev->le_features[1] & HCI_LE_PHY_CODED) in get_supported_adv_flags()
7234 static int read_adv_features(struct sock *sk, struct hci_dev *hdev, in read_adv_features() argument
7244 bt_dev_dbg(hdev, "sock %p", sk); in read_adv_features()
7246 if (!lmp_le_capable(hdev)) in read_adv_features()
7247 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
7253 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in read_adv_features()
7254 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in read_adv_features()
7257 hci_dev_lock(hdev); in read_adv_features()
7259 rp_len = sizeof(*rp) + hdev->adv_instance_cnt; in read_adv_features()
7262 hci_dev_unlock(hdev); in read_adv_features()
7266 supported_flags = get_supported_adv_flags(hdev); in read_adv_features()
7271 rp->max_instances = hdev->le_num_of_adv_sets; in read_adv_features()
7272 rp->num_instances = hdev->adv_instance_cnt; in read_adv_features()
7275 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in read_adv_features()
7280 hci_dev_unlock(hdev); in read_adv_features()
7282 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
7290 static u8 calculate_name_len(struct hci_dev *hdev) in calculate_name_len() argument
7294 return append_local_name(hdev, buf, 0); in calculate_name_len()
7297 static u8 tlv_data_max_len(struct hci_dev *hdev, u32 adv_flags, in tlv_data_max_len() argument
7312 max_len -= calculate_name_len(hdev); in tlv_data_max_len()
7343 static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data, in tlv_data_is_valid() argument
7349 max_len = tlv_data_max_len(hdev, adv_flags, is_adv_data); in tlv_data_is_valid()
7388 static void add_advertising_complete(struct hci_dev *hdev, u8 status, in add_advertising_complete() argument
7397 bt_dev_dbg(hdev, "status %d", status); in add_advertising_complete()
7399 hci_dev_lock(hdev); in add_advertising_complete()
7401 cmd = pending_find(MGMT_OP_ADD_ADVERTISING, hdev); in add_advertising_complete()
7403 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) { in add_advertising_complete()
7414 if (hdev->cur_adv_instance == instance) in add_advertising_complete()
7415 cancel_adv_timeout(hdev); in add_advertising_complete()
7417 hci_remove_adv_instance(hdev, instance); in add_advertising_complete()
7418 mgmt_advertising_removed(cmd ? cmd->sk : NULL, hdev, instance); in add_advertising_complete()
7437 hci_dev_unlock(hdev); in add_advertising_complete()
7440 static int add_advertising(struct sock *sk, struct hci_dev *hdev, in add_advertising() argument
7449 unsigned int prev_instance_cnt = hdev->adv_instance_cnt; in add_advertising()
7456 bt_dev_dbg(hdev, "sock %p", sk); in add_advertising()
7458 status = mgmt_le_support(hdev); in add_advertising()
7460 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7466 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in add_advertising()
7467 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7470 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_advertising()
7471 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7475 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7485 supported_flags = get_supported_adv_flags(hdev); in add_advertising()
7489 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7492 hci_dev_lock(hdev); in add_advertising()
7494 if (timeout && !hdev_is_powered(hdev)) { in add_advertising()
7495 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7500 if (pending_find(MGMT_OP_ADD_ADVERTISING, hdev) || in add_advertising()
7501 pending_find(MGMT_OP_REMOVE_ADVERTISING, hdev) || in add_advertising()
7502 pending_find(MGMT_OP_SET_LE, hdev)) { in add_advertising()
7503 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7508 if (!tlv_data_is_valid(hdev, flags, cp->data, cp->adv_data_len, true) || in add_advertising()
7509 !tlv_data_is_valid(hdev, flags, cp->data + cp->adv_data_len, in add_advertising()
7511 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7516 err = hci_add_adv_instance(hdev, cp->instance, flags, in add_advertising()
7522 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7530 if (hdev->adv_instance_cnt > prev_instance_cnt) in add_advertising()
7531 mgmt_advertising_added(sk, hdev, cp->instance); in add_advertising()
7533 if (hdev->cur_adv_instance == cp->instance) { in add_advertising()
7539 cancel_adv_timeout(hdev); in add_advertising()
7541 next_instance = hci_get_next_instance(hdev, cp->instance); in add_advertising()
7544 } else if (!hdev->adv_instance_timeout) { in add_advertising()
7555 if (!hdev_is_powered(hdev) || in add_advertising()
7556 hci_dev_test_flag(hdev, HCI_ADVERTISING) || in add_advertising()
7559 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7567 cmd = mgmt_pending_add(sk, MGMT_OP_ADD_ADVERTISING, hdev, data, in add_advertising()
7574 hci_req_init(&req, hdev); in add_advertising()
7582 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7588 hci_dev_unlock(hdev); in add_advertising()
7593 static void remove_advertising_complete(struct hci_dev *hdev, u8 status, in remove_advertising_complete() argument
7600 bt_dev_dbg(hdev, "status %d", status); in remove_advertising_complete()
7602 hci_dev_lock(hdev); in remove_advertising_complete()
7608 cmd = pending_find(MGMT_OP_REMOVE_ADVERTISING, hdev); in remove_advertising_complete()
7620 hci_dev_unlock(hdev); in remove_advertising_complete()
7623 static int remove_advertising(struct sock *sk, struct hci_dev *hdev, in remove_advertising() argument
7632 bt_dev_dbg(hdev, "sock %p", sk); in remove_advertising()
7637 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in remove_advertising()
7638 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in remove_advertising()
7641 hci_dev_lock(hdev); in remove_advertising()
7643 if (cp->instance && !hci_find_adv_instance(hdev, cp->instance)) { in remove_advertising()
7644 err = mgmt_cmd_status(sk, hdev->id, in remove_advertising()
7650 if (pending_find(MGMT_OP_ADD_ADVERTISING, hdev) || in remove_advertising()
7651 pending_find(MGMT_OP_REMOVE_ADVERTISING, hdev) || in remove_advertising()
7652 pending_find(MGMT_OP_SET_LE, hdev)) { in remove_advertising()
7653 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
7658 if (list_empty(&hdev->adv_instances)) { in remove_advertising()
7659 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
7664 hci_req_init(&req, hdev); in remove_advertising()
7667 if (ext_adv_capable(hdev)) { in remove_advertising()
7672 hci_req_clear_adv_instance(hdev, sk, &req, cp->instance, true); in remove_advertising()
7674 if (list_empty(&hdev->adv_instances)) in remove_advertising()
7682 !hdev_is_powered(hdev) || in remove_advertising()
7683 hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in remove_advertising()
7686 err = mgmt_cmd_complete(sk, hdev->id, in remove_advertising()
7692 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_ADVERTISING, hdev, data, in remove_advertising()
7704 hci_dev_unlock(hdev); in remove_advertising()
7709 static int get_adv_size_info(struct sock *sk, struct hci_dev *hdev, in get_adv_size_info() argument
7717 bt_dev_dbg(hdev, "sock %p", sk); in get_adv_size_info()
7719 if (!lmp_le_capable(hdev)) in get_adv_size_info()
7720 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
7723 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in get_adv_size_info()
7724 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
7732 supported_flags = get_supported_adv_flags(hdev); in get_adv_size_info()
7734 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
7739 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in get_adv_size_info()
7740 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in get_adv_size_info()
7742 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
7869 void mgmt_index_added(struct hci_dev *hdev) in mgmt_index_added() argument
7873 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_added()
7876 switch (hdev->dev_type) { in mgmt_index_added()
7878 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_added()
7879 mgmt_index_event(MGMT_EV_UNCONF_INDEX_ADDED, hdev, in mgmt_index_added()
7883 mgmt_index_event(MGMT_EV_INDEX_ADDED, hdev, NULL, 0, in mgmt_index_added()
7895 ev.bus = hdev->bus; in mgmt_index_added()
7897 mgmt_index_event(MGMT_EV_EXT_INDEX_ADDED, hdev, &ev, sizeof(ev), in mgmt_index_added()
7901 void mgmt_index_removed(struct hci_dev *hdev) in mgmt_index_removed() argument
7906 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_removed()
7909 switch (hdev->dev_type) { in mgmt_index_removed()
7911 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status); in mgmt_index_removed()
7913 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_removed()
7914 mgmt_index_event(MGMT_EV_UNCONF_INDEX_REMOVED, hdev, in mgmt_index_removed()
7918 mgmt_index_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, in mgmt_index_removed()
7930 ev.bus = hdev->bus; in mgmt_index_removed()
7932 mgmt_index_event(MGMT_EV_EXT_INDEX_REMOVED, hdev, &ev, sizeof(ev), in mgmt_index_removed()
7937 static void restart_le_actions(struct hci_dev *hdev) in restart_le_actions() argument
7941 list_for_each_entry(p, &hdev->le_conn_params, list) { in restart_le_actions()
7950 list_add(&p->action, &hdev->pend_le_conns); in restart_le_actions()
7953 list_add(&p->action, &hdev->pend_le_reports); in restart_le_actions()
7961 void mgmt_power_on(struct hci_dev *hdev, int err) in mgmt_power_on() argument
7963 struct cmd_lookup match = { NULL, hdev }; in mgmt_power_on()
7965 bt_dev_dbg(hdev, "err %d", err); in mgmt_power_on()
7967 hci_dev_lock(hdev); in mgmt_power_on()
7970 restart_le_actions(hdev); in mgmt_power_on()
7971 hci_update_background_scan(hdev); in mgmt_power_on()
7974 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in mgmt_power_on()
7976 new_settings(hdev, match.sk); in mgmt_power_on()
7981 hci_dev_unlock(hdev); in mgmt_power_on()
7984 void __mgmt_power_off(struct hci_dev *hdev) in __mgmt_power_off() argument
7986 struct cmd_lookup match = { NULL, hdev }; in __mgmt_power_off()
7989 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in __mgmt_power_off()
7998 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) in __mgmt_power_off()
8003 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status); in __mgmt_power_off()
8005 if (memcmp(hdev->dev_class, zero_cod, sizeof(zero_cod)) != 0) { in __mgmt_power_off()
8006 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, in __mgmt_power_off()
8009 ext_info_changed(hdev, NULL); in __mgmt_power_off()
8012 new_settings(hdev, match.sk); in __mgmt_power_off()
8018 void mgmt_set_powered_failed(struct hci_dev *hdev, int err) in mgmt_set_powered_failed() argument
8023 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_set_powered_failed()
8032 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, status); in mgmt_set_powered_failed()
8037 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, in mgmt_new_link_key() argument
8051 mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_link_key()
8073 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent) in mgmt_new_ltk() argument
8113 mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_ltk()
8116 void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent) in mgmt_new_irk() argument
8129 mgmt_event(MGMT_EV_NEW_IRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_irk()
8132 void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, in mgmt_new_csrk() argument
8159 mgmt_event(MGMT_EV_NEW_CSRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_csrk()
8162 void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_new_conn_param() argument
8180 mgmt_event(MGMT_EV_NEW_CONN_PARAM, hdev, &ev, sizeof(ev), NULL); in mgmt_new_conn_param()
8183 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, in mgmt_device_connected() argument
8216 mgmt_event(MGMT_EV_DEVICE_CONNECTED, hdev, buf, in mgmt_device_connected()
8234 struct hci_dev *hdev = data; in unpair_device_rsp() local
8237 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_rsp()
8243 bool mgmt_powering_down(struct hci_dev *hdev) in mgmt_powering_down() argument
8248 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_powering_down()
8259 void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_device_disconnected() argument
8269 if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { in mgmt_device_disconnected()
8270 cancel_delayed_work(&hdev->power_off); in mgmt_device_disconnected()
8271 queue_work(hdev->req_workqueue, &hdev->power_off.work); in mgmt_device_disconnected()
8280 mgmt_pending_foreach(MGMT_OP_DISCONNECT, hdev, disconnect_rsp, &sk); in mgmt_device_disconnected()
8287 if (hdev->suspended) in mgmt_device_disconnected()
8290 mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev), sk); in mgmt_device_disconnected()
8295 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_device_disconnected()
8296 hdev); in mgmt_device_disconnected()
8299 void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_disconnect_failed() argument
8306 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_disconnect_failed()
8307 hdev); in mgmt_disconnect_failed()
8309 cmd = pending_find(MGMT_OP_DISCONNECT, hdev); in mgmt_disconnect_failed()
8325 void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_connect_failed() argument
8333 if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { in mgmt_connect_failed()
8334 cancel_delayed_work(&hdev->power_off); in mgmt_connect_failed()
8335 queue_work(hdev->req_workqueue, &hdev->power_off.work); in mgmt_connect_failed()
8342 mgmt_event(MGMT_EV_CONNECT_FAILED, hdev, &ev, sizeof(ev), NULL); in mgmt_connect_failed()
8345 void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure) in mgmt_pin_code_request() argument
8353 mgmt_event(MGMT_EV_PIN_CODE_REQUEST, hdev, &ev, sizeof(ev), NULL); in mgmt_pin_code_request()
8356 void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_reply_complete() argument
8361 cmd = pending_find(MGMT_OP_PIN_CODE_REPLY, hdev); in mgmt_pin_code_reply_complete()
8369 void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_neg_reply_complete() argument
8374 cmd = pending_find(MGMT_OP_PIN_CODE_NEG_REPLY, hdev); in mgmt_pin_code_neg_reply_complete()
8382 int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_request() argument
8388 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_confirm_request()
8395 return mgmt_event(MGMT_EV_USER_CONFIRM_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_confirm_request()
8399 int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_request() argument
8404 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_request()
8409 return mgmt_event(MGMT_EV_USER_PASSKEY_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_passkey_request()
8413 static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in user_pairing_resp_complete() argument
8419 cmd = pending_find(opcode, hdev); in user_pairing_resp_complete()
8429 int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_reply_complete() argument
8432 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_reply_complete()
8436 int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_neg_reply_complete() argument
8439 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_neg_reply_complete()
8444 int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_reply_complete() argument
8447 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_reply_complete()
8451 int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_neg_reply_complete() argument
8454 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_neg_reply_complete()
8459 int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_notify() argument
8465 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_notify()
8472 return mgmt_event(MGMT_EV_PASSKEY_NOTIFY, hdev, &ev, sizeof(ev), NULL); in mgmt_user_passkey_notify()
8487 mgmt_event(MGMT_EV_AUTH_FAILED, conn->hdev, &ev, sizeof(ev), in mgmt_auth_failed()
8496 void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status) in mgmt_auth_enable_complete() argument
8498 struct cmd_lookup match = { NULL, hdev }; in mgmt_auth_enable_complete()
8503 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, in mgmt_auth_enable_complete()
8508 if (test_bit(HCI_AUTH, &hdev->flags)) in mgmt_auth_enable_complete()
8509 changed = !hci_dev_test_and_set_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
8511 changed = hci_dev_test_and_clear_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
8513 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, settings_rsp, in mgmt_auth_enable_complete()
8517 new_settings(hdev, match.sk); in mgmt_auth_enable_complete()
8525 struct hci_dev *hdev = req->hdev; in clear_eir() local
8528 if (!lmp_ext_inq_capable(hdev)) in clear_eir()
8531 memset(hdev->eir, 0, sizeof(hdev->eir)); in clear_eir()
8538 void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status) in mgmt_ssp_enable_complete() argument
8540 struct cmd_lookup match = { NULL, hdev }; in mgmt_ssp_enable_complete()
8547 if (enable && hci_dev_test_and_clear_flag(hdev, in mgmt_ssp_enable_complete()
8549 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in mgmt_ssp_enable_complete()
8550 new_settings(hdev, NULL); in mgmt_ssp_enable_complete()
8553 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, cmd_status_rsp, in mgmt_ssp_enable_complete()
8559 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in mgmt_ssp_enable_complete()
8561 changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED); in mgmt_ssp_enable_complete()
8563 changed = hci_dev_test_and_clear_flag(hdev, in mgmt_ssp_enable_complete()
8566 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in mgmt_ssp_enable_complete()
8569 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, settings_rsp, &match); in mgmt_ssp_enable_complete()
8572 new_settings(hdev, match.sk); in mgmt_ssp_enable_complete()
8577 hci_req_init(&req, hdev); in mgmt_ssp_enable_complete()
8579 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in mgmt_ssp_enable_complete()
8580 if (hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) in mgmt_ssp_enable_complete()
8601 void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, in mgmt_set_class_of_dev_complete() argument
8604 struct cmd_lookup match = { NULL, hdev, mgmt_status(status) }; in mgmt_set_class_of_dev_complete()
8606 mgmt_pending_foreach(MGMT_OP_SET_DEV_CLASS, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
8607 mgmt_pending_foreach(MGMT_OP_ADD_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
8608 mgmt_pending_foreach(MGMT_OP_REMOVE_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
8611 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, dev_class, in mgmt_set_class_of_dev_complete()
8613 ext_info_changed(hdev, NULL); in mgmt_set_class_of_dev_complete()
8620 void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status) in mgmt_set_local_name_complete() argument
8630 memcpy(ev.short_name, hdev->short_name, HCI_MAX_SHORT_NAME_LENGTH); in mgmt_set_local_name_complete()
8632 cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev); in mgmt_set_local_name_complete()
8634 memcpy(hdev->dev_name, name, sizeof(hdev->dev_name)); in mgmt_set_local_name_complete()
8639 if (pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_local_name_complete()
8643 mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev, sizeof(ev), in mgmt_set_local_name_complete()
8645 ext_info_changed(hdev, cmd ? cmd->sk : NULL); in mgmt_set_local_name_complete()
8715 static void restart_le_scan(struct hci_dev *hdev) in restart_le_scan() argument
8718 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in restart_le_scan()
8722 hdev->discovery.scan_start + in restart_le_scan()
8723 hdev->discovery.scan_duration)) in restart_le_scan()
8726 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_restart, in restart_le_scan()
8730 static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir, in is_filter_match() argument
8742 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
8744 (rssi < hdev->discovery.rssi && in is_filter_match()
8745 !test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)))) in is_filter_match()
8748 if (hdev->discovery.uuid_count != 0) { in is_filter_match()
8752 if (!eir_has_uuids(eir, eir_len, hdev->discovery.uuid_count, in is_filter_match()
8753 hdev->discovery.uuids) && in is_filter_match()
8755 hdev->discovery.uuid_count, in is_filter_match()
8756 hdev->discovery.uuids)) in is_filter_match()
8763 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)) { in is_filter_match()
8764 restart_le_scan(hdev); in is_filter_match()
8767 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
8768 rssi < hdev->discovery.rssi) in is_filter_match()
8775 void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_device_found() argument
8787 if (!hci_discovery_active(hdev)) { in mgmt_device_found()
8791 list_empty(&hdev->pend_le_reports) && in mgmt_device_found()
8792 !hci_is_adv_monitoring(hdev)) { in mgmt_device_found()
8797 if (hdev->discovery.result_filtering) { in mgmt_device_found()
8799 if (!is_filter_match(hdev, rssi, eir, eir_len, scan_rsp, in mgmt_device_found()
8804 if (hdev->discovery.limited) { in mgmt_device_found()
8832 if (rssi == HCI_RSSI_INVALID && !hdev->discovery.report_invalid_rssi && in mgmt_device_found()
8857 mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, ev_size, NULL); in mgmt_device_found()
8860 void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_remote_name() argument
8880 mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, sizeof(*ev) + eir_len, NULL); in mgmt_remote_name()
8883 void mgmt_discovering(struct hci_dev *hdev, u8 discovering) in mgmt_discovering() argument
8887 bt_dev_dbg(hdev, "discovering %u", discovering); in mgmt_discovering()
8890 ev.type = hdev->discovery.type; in mgmt_discovering()
8893 mgmt_event(MGMT_EV_DISCOVERING, hdev, &ev, sizeof(ev), NULL); in mgmt_discovering()
8896 void mgmt_suspending(struct hci_dev *hdev, u8 state) in mgmt_suspending() argument
8901 mgmt_event(MGMT_EV_CONTROLLER_SUSPEND, hdev, &ev, sizeof(ev), NULL); in mgmt_suspending()
8904 void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr, in mgmt_resuming() argument
8917 mgmt_event(MGMT_EV_CONTROLLER_RESUME, hdev, &ev, sizeof(ev), NULL); in mgmt_resuming()