Lines Matching refs:hdev
278 static int mgmt_index_event(u16 event, struct hci_dev *hdev, void *data, in mgmt_index_event() argument
281 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_index_event()
285 static int mgmt_limited_event(u16 event, struct hci_dev *hdev, void *data, in mgmt_limited_event() argument
288 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_limited_event()
292 static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, u16 len, in mgmt_event() argument
295 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_event()
315 static int read_version(struct sock *sk, struct hci_dev *hdev, void *data, in read_version() argument
320 bt_dev_dbg(hdev, "sock %p", sk); in read_version()
328 static int read_commands(struct sock *sk, struct hci_dev *hdev, void *data, in read_commands() argument
336 bt_dev_dbg(hdev, "sock %p", sk); in read_commands()
380 static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data, in read_index_list() argument
389 bt_dev_dbg(hdev, "sock %p", sk); in read_index_list()
423 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_index_list()
440 static int read_unconf_index_list(struct sock *sk, struct hci_dev *hdev, in read_unconf_index_list() argument
449 bt_dev_dbg(hdev, "sock %p", sk); in read_unconf_index_list()
483 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_unconf_index_list()
500 static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev, in read_ext_index_list() argument
508 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_index_list()
550 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_ext_index_list()
574 static bool is_configured(struct hci_dev *hdev) in is_configured() argument
576 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in is_configured()
577 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in is_configured()
580 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in is_configured()
581 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in is_configured()
582 !bacmp(&hdev->public_addr, BDADDR_ANY)) in is_configured()
588 static __le32 get_missing_options(struct hci_dev *hdev) in get_missing_options() argument
592 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in get_missing_options()
593 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in get_missing_options()
596 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in get_missing_options()
597 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in get_missing_options()
598 !bacmp(&hdev->public_addr, BDADDR_ANY)) in get_missing_options()
604 static int new_options(struct hci_dev *hdev, struct sock *skip) in new_options() argument
606 __le32 options = get_missing_options(hdev); in new_options()
608 return mgmt_limited_event(MGMT_EV_NEW_CONFIG_OPTIONS, hdev, &options, in new_options()
612 static int send_options_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_options_rsp() argument
614 __le32 options = get_missing_options(hdev); in send_options_rsp()
616 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &options, in send_options_rsp()
620 static int read_config_info(struct sock *sk, struct hci_dev *hdev, in read_config_info() argument
626 bt_dev_dbg(hdev, "sock %p", sk); in read_config_info()
628 hci_dev_lock(hdev); in read_config_info()
631 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_config_info()
633 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in read_config_info()
636 if (hdev->set_bdaddr) in read_config_info()
640 rp.missing_options = get_missing_options(hdev); in read_config_info()
642 hci_dev_unlock(hdev); in read_config_info()
644 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONFIG_INFO, 0, in read_config_info()
648 static u32 get_supported_phys(struct hci_dev *hdev) in get_supported_phys() argument
652 if (lmp_bredr_capable(hdev)) { in get_supported_phys()
655 if (hdev->features[0][0] & LMP_3SLOT) in get_supported_phys()
658 if (hdev->features[0][0] & LMP_5SLOT) in get_supported_phys()
661 if (lmp_edr_2m_capable(hdev)) { in get_supported_phys()
664 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
667 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
670 if (lmp_edr_3m_capable(hdev)) { in get_supported_phys()
673 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
676 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
682 if (lmp_le_capable(hdev)) { in get_supported_phys()
686 if (hdev->le_features[1] & HCI_LE_PHY_2M) { in get_supported_phys()
691 if (hdev->le_features[1] & HCI_LE_PHY_CODED) { in get_supported_phys()
700 static u32 get_selected_phys(struct hci_dev *hdev) in get_selected_phys() argument
704 if (lmp_bredr_capable(hdev)) { in get_selected_phys()
707 if (hdev->pkt_type & (HCI_DM3 | HCI_DH3)) in get_selected_phys()
710 if (hdev->pkt_type & (HCI_DM5 | HCI_DH5)) in get_selected_phys()
713 if (lmp_edr_2m_capable(hdev)) { in get_selected_phys()
714 if (!(hdev->pkt_type & HCI_2DH1)) in get_selected_phys()
717 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
718 !(hdev->pkt_type & HCI_2DH3)) in get_selected_phys()
721 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
722 !(hdev->pkt_type & HCI_2DH5)) in get_selected_phys()
725 if (lmp_edr_3m_capable(hdev)) { in get_selected_phys()
726 if (!(hdev->pkt_type & HCI_3DH1)) in get_selected_phys()
729 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
730 !(hdev->pkt_type & HCI_3DH3)) in get_selected_phys()
733 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
734 !(hdev->pkt_type & HCI_3DH5)) in get_selected_phys()
740 if (lmp_le_capable(hdev)) { in get_selected_phys()
741 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
744 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
747 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
750 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
753 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
756 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
763 static u32 get_configurable_phys(struct hci_dev *hdev) in get_configurable_phys() argument
765 return (get_supported_phys(hdev) & ~MGMT_PHY_BR_1M_1SLOT & in get_configurable_phys()
769 static u32 get_supported_settings(struct hci_dev *hdev) in get_supported_settings() argument
779 if (lmp_bredr_capable(hdev)) { in get_supported_settings()
780 if (hdev->hci_ver >= BLUETOOTH_VER_1_2) in get_supported_settings()
785 if (lmp_ssp_capable(hdev)) { in get_supported_settings()
791 if (lmp_sc_capable(hdev)) in get_supported_settings()
795 &hdev->quirks)) in get_supported_settings()
799 if (lmp_le_capable(hdev)) { in get_supported_settings()
808 if (!hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in get_supported_settings()
812 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in get_supported_settings()
813 hdev->set_bdaddr) in get_supported_settings()
821 static u32 get_current_settings(struct hci_dev *hdev) in get_current_settings() argument
825 if (hdev_is_powered(hdev)) in get_current_settings()
828 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in get_current_settings()
831 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in get_current_settings()
834 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in get_current_settings()
837 if (hci_dev_test_flag(hdev, HCI_BONDABLE)) in get_current_settings()
840 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in get_current_settings()
843 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in get_current_settings()
846 if (hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) in get_current_settings()
849 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in get_current_settings()
852 if (hci_dev_test_flag(hdev, HCI_HS_ENABLED)) in get_current_settings()
855 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in get_current_settings()
858 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) in get_current_settings()
861 if (hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) in get_current_settings()
864 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in get_current_settings()
879 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in get_current_settings()
880 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in get_current_settings()
881 !bacmp(&hdev->bdaddr, BDADDR_ANY)) { in get_current_settings()
882 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in get_current_settings()
886 if (hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED)) in get_current_settings()
892 static struct mgmt_pending_cmd *pending_find(u16 opcode, struct hci_dev *hdev) in pending_find() argument
894 return mgmt_pending_find(HCI_CHANNEL_CONTROL, opcode, hdev); in pending_find()
898 struct hci_dev *hdev, in pending_find_data() argument
901 return mgmt_pending_find_data(HCI_CHANNEL_CONTROL, opcode, hdev, data); in pending_find_data()
904 u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev) in mgmt_get_adv_discov_flags() argument
911 cmd = pending_find(MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_get_adv_discov_flags()
919 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
921 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
928 bool mgmt_get_connectable(struct hci_dev *hdev) in mgmt_get_connectable() argument
935 cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_get_connectable()
942 return hci_dev_test_flag(hdev, HCI_CONNECTABLE); in mgmt_get_connectable()
947 struct hci_dev *hdev = container_of(work, struct hci_dev, in service_cache_off() local
951 if (!hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in service_cache_off()
954 hci_req_init(&req, hdev); in service_cache_off()
956 hci_dev_lock(hdev); in service_cache_off()
961 hci_dev_unlock(hdev); in service_cache_off()
968 struct hci_dev *hdev = container_of(work, struct hci_dev, in rpa_expired() local
972 bt_dev_dbg(hdev, ""); in rpa_expired()
974 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in rpa_expired()
976 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING)) in rpa_expired()
983 hci_req_init(&req, hdev); in rpa_expired()
984 if (ext_adv_capable(hdev)) in rpa_expired()
985 __hci_req_start_ext_adv(&req, hdev->cur_adv_instance); in rpa_expired()
991 static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev) in mgmt_init_hdev() argument
993 if (hci_dev_test_and_set_flag(hdev, HCI_MGMT)) in mgmt_init_hdev()
996 INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off); in mgmt_init_hdev()
997 INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired); in mgmt_init_hdev()
1004 hci_dev_clear_flag(hdev, HCI_BONDABLE); in mgmt_init_hdev()
1007 static int read_controller_info(struct sock *sk, struct hci_dev *hdev, in read_controller_info() argument
1012 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_info()
1014 hci_dev_lock(hdev); in read_controller_info()
1018 bacpy(&rp.bdaddr, &hdev->bdaddr); in read_controller_info()
1020 rp.version = hdev->hci_ver; in read_controller_info()
1021 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_controller_info()
1023 rp.supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_controller_info()
1024 rp.current_settings = cpu_to_le32(get_current_settings(hdev)); in read_controller_info()
1026 memcpy(rp.dev_class, hdev->dev_class, 3); in read_controller_info()
1028 memcpy(rp.name, hdev->dev_name, sizeof(hdev->dev_name)); in read_controller_info()
1029 memcpy(rp.short_name, hdev->short_name, sizeof(hdev->short_name)); in read_controller_info()
1031 hci_dev_unlock(hdev); in read_controller_info()
1033 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_INFO, 0, &rp, in read_controller_info()
1037 static u16 append_eir_data_to_buf(struct hci_dev *hdev, u8 *eir) in append_eir_data_to_buf() argument
1042 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in append_eir_data_to_buf()
1044 hdev->dev_class, 3); in append_eir_data_to_buf()
1046 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in append_eir_data_to_buf()
1048 hdev->appearance); in append_eir_data_to_buf()
1050 name_len = strlen(hdev->dev_name); in append_eir_data_to_buf()
1052 hdev->dev_name, name_len); in append_eir_data_to_buf()
1054 name_len = strlen(hdev->short_name); in append_eir_data_to_buf()
1056 hdev->short_name, name_len); in append_eir_data_to_buf()
1061 static int read_ext_controller_info(struct sock *sk, struct hci_dev *hdev, in read_ext_controller_info() argument
1068 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_controller_info()
1072 hci_dev_lock(hdev); in read_ext_controller_info()
1074 bacpy(&rp->bdaddr, &hdev->bdaddr); in read_ext_controller_info()
1076 rp->version = hdev->hci_ver; in read_ext_controller_info()
1077 rp->manufacturer = cpu_to_le16(hdev->manufacturer); in read_ext_controller_info()
1079 rp->supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_ext_controller_info()
1080 rp->current_settings = cpu_to_le32(get_current_settings(hdev)); in read_ext_controller_info()
1083 eir_len = append_eir_data_to_buf(hdev, rp->eir); in read_ext_controller_info()
1086 hci_dev_unlock(hdev); in read_ext_controller_info()
1097 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_EXT_INFO, 0, rp, in read_ext_controller_info()
1101 static int ext_info_changed(struct hci_dev *hdev, struct sock *skip) in ext_info_changed() argument
1109 eir_len = append_eir_data_to_buf(hdev, ev->eir); in ext_info_changed()
1112 return mgmt_limited_event(MGMT_EV_EXT_INFO_CHANGED, hdev, ev, in ext_info_changed()
1117 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_settings_rsp() argument
1119 __le32 settings = cpu_to_le32(get_current_settings(hdev)); in send_settings_rsp()
1121 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &settings, in send_settings_rsp()
1125 static void clean_up_hci_complete(struct hci_dev *hdev, u8 status, u16 opcode) in clean_up_hci_complete() argument
1127 bt_dev_dbg(hdev, "status 0x%02x", status); in clean_up_hci_complete()
1129 if (hci_conn_count(hdev) == 0) { in clean_up_hci_complete()
1130 cancel_delayed_work(&hdev->power_off); in clean_up_hci_complete()
1131 queue_work(hdev->req_workqueue, &hdev->power_off.work); in clean_up_hci_complete()
1135 void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev, u8 instance) in mgmt_advertising_added() argument
1141 mgmt_event(MGMT_EV_ADVERTISING_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_added()
1144 void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev, in mgmt_advertising_removed() argument
1151 mgmt_event(MGMT_EV_ADVERTISING_REMOVED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_removed()
1154 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
1156 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
1157 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
1158 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
1162 static int clean_up_hci_state(struct hci_dev *hdev) in clean_up_hci_state() argument
1169 hci_req_init(&req, hdev); in clean_up_hci_state()
1171 if (test_bit(HCI_ISCAN, &hdev->flags) || in clean_up_hci_state()
1172 test_bit(HCI_PSCAN, &hdev->flags)) { in clean_up_hci_state()
1177 hci_req_clear_adv_instance(hdev, NULL, NULL, 0x00, false); in clean_up_hci_state()
1179 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in clean_up_hci_state()
1184 list_for_each_entry(conn, &hdev->conn_hash.list, list) { in clean_up_hci_state()
1191 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in clean_up_hci_state()
1196 static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, in set_powered() argument
1203 bt_dev_dbg(hdev, "sock %p", sk); in set_powered()
1206 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1209 hci_dev_lock(hdev); in set_powered()
1211 if (pending_find(MGMT_OP_SET_POWERED, hdev)) { in set_powered()
1212 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1217 if (!!cp->val == hdev_is_powered(hdev)) { in set_powered()
1218 err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev); in set_powered()
1222 cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, hdev, data, len); in set_powered()
1229 queue_work(hdev->req_workqueue, &hdev->power_on); in set_powered()
1233 err = clean_up_hci_state(hdev); in set_powered()
1235 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in set_powered()
1240 cancel_delayed_work(&hdev->power_off); in set_powered()
1241 queue_work(hdev->req_workqueue, &hdev->power_off.work); in set_powered()
1247 hci_dev_unlock(hdev); in set_powered()
1251 static int new_settings(struct hci_dev *hdev, struct sock *skip) in new_settings() argument
1253 __le32 ev = cpu_to_le32(get_current_settings(hdev)); in new_settings()
1255 return mgmt_limited_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, in new_settings()
1259 int mgmt_new_settings(struct hci_dev *hdev) in mgmt_new_settings() argument
1261 return new_settings(hdev, NULL); in mgmt_new_settings()
1266 struct hci_dev *hdev; member
1274 send_settings_rsp(cmd->sk, cmd->opcode, match->hdev); in settings_rsp()
1320 static u8 mgmt_bredr_support(struct hci_dev *hdev) in mgmt_bredr_support() argument
1322 if (!lmp_bredr_capable(hdev)) in mgmt_bredr_support()
1324 else if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in mgmt_bredr_support()
1330 static u8 mgmt_le_support(struct hci_dev *hdev) in mgmt_le_support() argument
1332 if (!lmp_le_capable(hdev)) in mgmt_le_support()
1334 else if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mgmt_le_support()
1340 void mgmt_set_discoverable_complete(struct hci_dev *hdev, u8 status) in mgmt_set_discoverable_complete() argument
1344 bt_dev_dbg(hdev, "status 0x%02x", status); in mgmt_set_discoverable_complete()
1346 hci_dev_lock(hdev); in mgmt_set_discoverable_complete()
1348 cmd = pending_find(MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_set_discoverable_complete()
1355 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in mgmt_set_discoverable_complete()
1359 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in mgmt_set_discoverable_complete()
1360 hdev->discov_timeout > 0) { in mgmt_set_discoverable_complete()
1361 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in mgmt_set_discoverable_complete()
1362 queue_delayed_work(hdev->req_workqueue, &hdev->discov_off, to); in mgmt_set_discoverable_complete()
1365 send_settings_rsp(cmd->sk, MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_set_discoverable_complete()
1366 new_settings(hdev, cmd->sk); in mgmt_set_discoverable_complete()
1372 hci_dev_unlock(hdev); in mgmt_set_discoverable_complete()
1375 static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, in set_discoverable() argument
1383 bt_dev_dbg(hdev, "sock %p", sk); in set_discoverable()
1385 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_discoverable()
1386 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_discoverable()
1387 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1391 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1401 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1404 hci_dev_lock(hdev); in set_discoverable()
1406 if (!hdev_is_powered(hdev) && timeout > 0) { in set_discoverable()
1407 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1412 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_discoverable()
1413 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_discoverable()
1414 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1419 if (!hci_dev_test_flag(hdev, HCI_CONNECTABLE)) { in set_discoverable()
1420 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1425 if (hdev->advertising_paused) { in set_discoverable()
1426 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1431 if (!hdev_is_powered(hdev)) { in set_discoverable()
1438 if (!!cp->val != hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) { in set_discoverable()
1439 hci_dev_change_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1443 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1448 err = new_settings(hdev, sk); in set_discoverable()
1457 if (!!cp->val == hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in set_discoverable()
1458 (cp->val == 0x02) == hci_dev_test_flag(hdev, in set_discoverable()
1460 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1461 hdev->discov_timeout = timeout; in set_discoverable()
1463 if (cp->val && hdev->discov_timeout > 0) { in set_discoverable()
1464 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in set_discoverable()
1465 queue_delayed_work(hdev->req_workqueue, in set_discoverable()
1466 &hdev->discov_off, to); in set_discoverable()
1469 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1473 cmd = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, hdev, data, len); in set_discoverable()
1483 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1484 hdev->discov_timeout = timeout; in set_discoverable()
1487 hci_dev_set_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1489 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1493 hci_dev_set_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1495 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1497 queue_work(hdev->req_workqueue, &hdev->discoverable_update); in set_discoverable()
1501 hci_dev_unlock(hdev); in set_discoverable()
1505 void mgmt_set_connectable_complete(struct hci_dev *hdev, u8 status) in mgmt_set_connectable_complete() argument
1509 bt_dev_dbg(hdev, "status 0x%02x", status); in mgmt_set_connectable_complete()
1511 hci_dev_lock(hdev); in mgmt_set_connectable_complete()
1513 cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_set_connectable_complete()
1523 send_settings_rsp(cmd->sk, MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_set_connectable_complete()
1524 new_settings(hdev, cmd->sk); in mgmt_set_connectable_complete()
1530 hci_dev_unlock(hdev); in mgmt_set_connectable_complete()
1533 static int set_connectable_update_settings(struct hci_dev *hdev, in set_connectable_update_settings() argument
1539 if (!!val != hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in set_connectable_update_settings()
1543 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1545 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1546 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable_update_settings()
1549 err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev); in set_connectable_update_settings()
1554 hci_req_update_scan(hdev); in set_connectable_update_settings()
1555 hci_update_background_scan(hdev); in set_connectable_update_settings()
1556 return new_settings(hdev, sk); in set_connectable_update_settings()
1562 static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data, in set_connectable() argument
1569 bt_dev_dbg(hdev, "sock %p", sk); in set_connectable()
1571 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_connectable()
1572 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_connectable()
1573 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1577 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1580 hci_dev_lock(hdev); in set_connectable()
1582 if (!hdev_is_powered(hdev)) { in set_connectable()
1583 err = set_connectable_update_settings(hdev, sk, cp->val); in set_connectable()
1587 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_connectable()
1588 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_connectable()
1589 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1594 cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len); in set_connectable()
1601 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1603 if (hdev->discov_timeout > 0) in set_connectable()
1604 cancel_delayed_work(&hdev->discov_off); in set_connectable()
1606 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_connectable()
1607 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable()
1608 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1611 queue_work(hdev->req_workqueue, &hdev->connectable_update); in set_connectable()
1615 hci_dev_unlock(hdev); in set_connectable()
1619 static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data, in set_bondable() argument
1626 bt_dev_dbg(hdev, "sock %p", sk); in set_bondable()
1629 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BONDABLE, in set_bondable()
1632 hci_dev_lock(hdev); in set_bondable()
1635 changed = !hci_dev_test_and_set_flag(hdev, HCI_BONDABLE); in set_bondable()
1637 changed = hci_dev_test_and_clear_flag(hdev, HCI_BONDABLE); in set_bondable()
1639 err = send_settings_rsp(sk, MGMT_OP_SET_BONDABLE, hdev); in set_bondable()
1647 if (hdev_is_powered(hdev) && in set_bondable()
1648 hci_dev_test_flag(hdev, HCI_ADVERTISING) && in set_bondable()
1649 hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in set_bondable()
1650 hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in set_bondable()
1651 queue_work(hdev->req_workqueue, in set_bondable()
1652 &hdev->discoverable_update); in set_bondable()
1654 err = new_settings(hdev, sk); in set_bondable()
1658 hci_dev_unlock(hdev); in set_bondable()
1662 static int set_link_security(struct sock *sk, struct hci_dev *hdev, void *data, in set_link_security() argument
1670 bt_dev_dbg(hdev, "sock %p", sk); in set_link_security()
1672 status = mgmt_bredr_support(hdev); in set_link_security()
1674 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1678 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1681 hci_dev_lock(hdev); in set_link_security()
1683 if (!hdev_is_powered(hdev)) { in set_link_security()
1686 if (!!cp->val != hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) { in set_link_security()
1687 hci_dev_change_flag(hdev, HCI_LINK_SECURITY); in set_link_security()
1691 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1696 err = new_settings(hdev, sk); in set_link_security()
1701 if (pending_find(MGMT_OP_SET_LINK_SECURITY, hdev)) { in set_link_security()
1702 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1709 if (test_bit(HCI_AUTH, &hdev->flags) == val) { in set_link_security()
1710 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1714 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LINK_SECURITY, hdev, data, len); in set_link_security()
1720 err = hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, sizeof(val), &val); in set_link_security()
1727 hci_dev_unlock(hdev); in set_link_security()
1731 static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_ssp() argument
1738 bt_dev_dbg(hdev, "sock %p", sk); in set_ssp()
1740 status = mgmt_bredr_support(hdev); in set_ssp()
1742 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, status); in set_ssp()
1744 if (!lmp_ssp_capable(hdev)) in set_ssp()
1745 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1749 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1752 hci_dev_lock(hdev); in set_ssp()
1754 if (!hdev_is_powered(hdev)) { in set_ssp()
1758 changed = !hci_dev_test_and_set_flag(hdev, in set_ssp()
1761 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
1764 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
1767 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_ssp()
1770 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
1775 err = new_settings(hdev, sk); in set_ssp()
1780 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_ssp()
1781 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1786 if (!!cp->val == hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_ssp()
1787 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
1791 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SSP, hdev, data, len); in set_ssp()
1797 if (!cp->val && hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) in set_ssp()
1798 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in set_ssp()
1801 err = hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, 1, &cp->val); in set_ssp()
1808 hci_dev_unlock(hdev); in set_ssp()
1812 static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_hs() argument
1819 bt_dev_dbg(hdev, "sock %p", sk); in set_hs()
1822 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1825 status = mgmt_bredr_support(hdev); in set_hs()
1827 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, status); in set_hs()
1829 if (!lmp_ssp_capable(hdev)) in set_hs()
1830 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1833 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_hs()
1834 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1838 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1841 hci_dev_lock(hdev); in set_hs()
1843 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_hs()
1844 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1850 changed = !hci_dev_test_and_set_flag(hdev, HCI_HS_ENABLED); in set_hs()
1852 if (hdev_is_powered(hdev)) { in set_hs()
1853 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
1858 changed = hci_dev_test_and_clear_flag(hdev, HCI_HS_ENABLED); in set_hs()
1861 err = send_settings_rsp(sk, MGMT_OP_SET_HS, hdev); in set_hs()
1866 err = new_settings(hdev, sk); in set_hs()
1869 hci_dev_unlock(hdev); in set_hs()
1873 static void le_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) in le_enable_complete() argument
1875 struct cmd_lookup match = { NULL, hdev }; in le_enable_complete()
1877 hci_dev_lock(hdev); in le_enable_complete()
1882 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp, in le_enable_complete()
1887 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match); in le_enable_complete()
1889 new_settings(hdev, match.sk); in le_enable_complete()
1899 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in le_enable_complete()
1901 hci_req_init(&req, hdev); in le_enable_complete()
1902 if (ext_adv_capable(hdev)) { in le_enable_complete()
1913 hci_update_background_scan(hdev); in le_enable_complete()
1917 hci_dev_unlock(hdev); in le_enable_complete()
1920 static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_le() argument
1929 bt_dev_dbg(hdev, "sock %p", sk); in set_le()
1931 if (!lmp_le_capable(hdev)) in set_le()
1932 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1936 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1948 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_le()
1950 return send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
1952 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1956 hci_dev_lock(hdev); in set_le()
1959 enabled = lmp_host_le_capable(hdev); in set_le()
1962 hci_req_clear_adv_instance(hdev, NULL, NULL, 0x00, true); in set_le()
1964 if (!hdev_is_powered(hdev) || val == enabled) { in set_le()
1967 if (val != hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le()
1968 hci_dev_change_flag(hdev, HCI_LE_ENABLED); in set_le()
1972 if (!val && hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in set_le()
1973 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_le()
1977 err = send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
1982 err = new_settings(hdev, sk); in set_le()
1987 if (pending_find(MGMT_OP_SET_LE, hdev) || in set_le()
1988 pending_find(MGMT_OP_SET_ADVERTISING, hdev)) { in set_le()
1989 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
1994 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LE, hdev, data, len); in set_le()
2000 hci_req_init(&req, hdev); in set_le()
2008 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_le()
2011 if (ext_adv_capable(hdev)) in set_le()
2023 hci_dev_unlock(hdev); in set_le()
2033 static bool pending_eir_or_class(struct hci_dev *hdev) in pending_eir_or_class() argument
2037 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in pending_eir_or_class()
2069 static void mgmt_class_complete(struct hci_dev *hdev, u16 mgmt_op, u8 status) in mgmt_class_complete() argument
2073 hci_dev_lock(hdev); in mgmt_class_complete()
2075 cmd = pending_find(mgmt_op, hdev); in mgmt_class_complete()
2080 mgmt_status(status), hdev->dev_class, 3); in mgmt_class_complete()
2085 hci_dev_unlock(hdev); in mgmt_class_complete()
2088 static void add_uuid_complete(struct hci_dev *hdev, u8 status, u16 opcode) in add_uuid_complete() argument
2090 bt_dev_dbg(hdev, "status 0x%02x", status); in add_uuid_complete()
2092 mgmt_class_complete(hdev, MGMT_OP_ADD_UUID, status); in add_uuid_complete()
2095 static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in add_uuid() argument
2103 bt_dev_dbg(hdev, "sock %p", sk); in add_uuid()
2105 hci_dev_lock(hdev); in add_uuid()
2107 if (pending_eir_or_class(hdev)) { in add_uuid()
2108 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_UUID, in add_uuid()
2123 list_add_tail(&uuid->list, &hdev->uuids); in add_uuid()
2125 hci_req_init(&req, hdev); in add_uuid()
2135 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_UUID, 0, in add_uuid()
2136 hdev->dev_class, 3); in add_uuid()
2140 cmd = mgmt_pending_add(sk, MGMT_OP_ADD_UUID, hdev, data, len); in add_uuid()
2149 hci_dev_unlock(hdev); in add_uuid()
2153 static bool enable_service_cache(struct hci_dev *hdev) in enable_service_cache() argument
2155 if (!hdev_is_powered(hdev)) in enable_service_cache()
2158 if (!hci_dev_test_and_set_flag(hdev, HCI_SERVICE_CACHE)) { in enable_service_cache()
2159 queue_delayed_work(hdev->workqueue, &hdev->service_cache, in enable_service_cache()
2167 static void remove_uuid_complete(struct hci_dev *hdev, u8 status, u16 opcode) in remove_uuid_complete() argument
2169 bt_dev_dbg(hdev, "status 0x%02x", status); in remove_uuid_complete()
2171 mgmt_class_complete(hdev, MGMT_OP_REMOVE_UUID, status); in remove_uuid_complete()
2174 static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data, in remove_uuid() argument
2184 bt_dev_dbg(hdev, "sock %p", sk); in remove_uuid()
2186 hci_dev_lock(hdev); in remove_uuid()
2188 if (pending_eir_or_class(hdev)) { in remove_uuid()
2189 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2195 hci_uuids_clear(hdev); in remove_uuid()
2197 if (enable_service_cache(hdev)) { in remove_uuid()
2198 err = mgmt_cmd_complete(sk, hdev->id, in remove_uuid()
2200 0, hdev->dev_class, 3); in remove_uuid()
2209 list_for_each_entry_safe(match, tmp, &hdev->uuids, list) { in remove_uuid()
2219 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2225 hci_req_init(&req, hdev); in remove_uuid()
2235 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_UUID, 0, in remove_uuid()
2236 hdev->dev_class, 3); in remove_uuid()
2240 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_UUID, hdev, data, len); in remove_uuid()
2249 hci_dev_unlock(hdev); in remove_uuid()
2253 static void set_class_complete(struct hci_dev *hdev, u8 status, u16 opcode) in set_class_complete() argument
2255 bt_dev_dbg(hdev, "status 0x%02x", status); in set_class_complete()
2257 mgmt_class_complete(hdev, MGMT_OP_SET_DEV_CLASS, status); in set_class_complete()
2260 static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data, in set_dev_class() argument
2268 bt_dev_dbg(hdev, "sock %p", sk); in set_dev_class()
2270 if (!lmp_bredr_capable(hdev)) in set_dev_class()
2271 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2274 hci_dev_lock(hdev); in set_dev_class()
2276 if (pending_eir_or_class(hdev)) { in set_dev_class()
2277 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2283 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2288 hdev->major_class = cp->major; in set_dev_class()
2289 hdev->minor_class = cp->minor; in set_dev_class()
2291 if (!hdev_is_powered(hdev)) { in set_dev_class()
2292 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, in set_dev_class()
2293 hdev->dev_class, 3); in set_dev_class()
2297 hci_req_init(&req, hdev); in set_dev_class()
2299 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) { in set_dev_class()
2300 hci_dev_unlock(hdev); in set_dev_class()
2301 cancel_delayed_work_sync(&hdev->service_cache); in set_dev_class()
2302 hci_dev_lock(hdev); in set_dev_class()
2313 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, in set_dev_class()
2314 hdev->dev_class, 3); in set_dev_class()
2318 cmd = mgmt_pending_add(sk, MGMT_OP_SET_DEV_CLASS, hdev, data, len); in set_dev_class()
2327 hci_dev_unlock(hdev); in set_dev_class()
2331 static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data, in load_link_keys() argument
2341 bt_dev_dbg(hdev, "sock %p", sk); in load_link_keys()
2343 if (!lmp_bredr_capable(hdev)) in load_link_keys()
2344 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2349 bt_dev_err(hdev, "load_link_keys: too big key_count value %u", in load_link_keys()
2351 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2357 bt_dev_err(hdev, "load_link_keys: expected %u bytes, got %u bytes", in load_link_keys()
2359 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2364 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2367 bt_dev_dbg(hdev, "debug_keys %u key_count %u", cp->debug_keys, in load_link_keys()
2374 return mgmt_cmd_status(sk, hdev->id, in load_link_keys()
2379 hci_dev_lock(hdev); in load_link_keys()
2381 hci_link_keys_clear(hdev); in load_link_keys()
2384 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in load_link_keys()
2386 changed = hci_dev_test_and_clear_flag(hdev, in load_link_keys()
2390 new_settings(hdev, NULL); in load_link_keys()
2395 if (hci_is_blocked_key(hdev, in load_link_keys()
2398 bt_dev_warn(hdev, "Skipping blocked link key for %pMR", in load_link_keys()
2409 hci_add_link_key(hdev, NULL, &key->addr.bdaddr, key->val, in load_link_keys()
2413 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0); in load_link_keys()
2415 hci_dev_unlock(hdev); in load_link_keys()
2420 static int device_unpaired(struct hci_dev *hdev, bdaddr_t *bdaddr, in device_unpaired() argument
2428 return mgmt_event(MGMT_EV_DEVICE_UNPAIRED, hdev, &ev, sizeof(ev), in device_unpaired()
2432 static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data, in unpair_device() argument
2448 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2453 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2457 hci_dev_lock(hdev); in unpair_device()
2459 if (!hdev_is_powered(hdev)) { in unpair_device()
2460 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2475 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device()
2480 err = hci_remove_link_key(hdev, &cp->addr.bdaddr); in unpair_device()
2482 err = mgmt_cmd_complete(sk, hdev->id, in unpair_device()
2496 err = smp_cancel_and_remove_pairing(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2498 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2504 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2506 hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2517 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
2536 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0, in unpair_device()
2538 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk); in unpair_device()
2542 cmd = mgmt_pending_add(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp, in unpair_device()
2556 hci_dev_unlock(hdev); in unpair_device()
2560 static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data, in disconnect() argument
2569 bt_dev_dbg(hdev, "sock %p", sk); in disconnect()
2576 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2580 hci_dev_lock(hdev); in disconnect()
2582 if (!test_bit(HCI_UP, &hdev->flags)) { in disconnect()
2583 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2589 if (pending_find(MGMT_OP_DISCONNECT, hdev)) { in disconnect()
2590 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2596 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in disconnect()
2599 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in disconnect()
2603 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
2609 cmd = mgmt_pending_add(sk, MGMT_OP_DISCONNECT, hdev, data, len); in disconnect()
2622 hci_dev_unlock(hdev); in disconnect()
2645 static int get_connections(struct sock *sk, struct hci_dev *hdev, void *data, in get_connections() argument
2653 bt_dev_dbg(hdev, "sock %p", sk); in get_connections()
2655 hci_dev_lock(hdev); in get_connections()
2657 if (!hdev_is_powered(hdev)) { in get_connections()
2658 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, in get_connections()
2664 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
2676 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
2689 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, 0, rp, in get_connections()
2695 hci_dev_unlock(hdev); in get_connections()
2699 static int send_pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in send_pin_code_neg_reply() argument
2705 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, hdev, cp, in send_pin_code_neg_reply()
2712 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, in send_pin_code_neg_reply()
2720 static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data, in pin_code_reply() argument
2729 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_reply()
2731 hci_dev_lock(hdev); in pin_code_reply()
2733 if (!hdev_is_powered(hdev)) { in pin_code_reply()
2734 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
2739 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in pin_code_reply()
2741 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
2751 bt_dev_err(hdev, "PIN code is not 16 bytes long"); in pin_code_reply()
2753 err = send_pin_code_neg_reply(sk, hdev, &ncp); in pin_code_reply()
2755 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
2761 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data, len); in pin_code_reply()
2773 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_REPLY, sizeof(reply), &reply); in pin_code_reply()
2778 hci_dev_unlock(hdev); in pin_code_reply()
2782 static int set_io_capability(struct sock *sk, struct hci_dev *hdev, void *data, in set_io_capability() argument
2787 bt_dev_dbg(hdev, "sock %p", sk); in set_io_capability()
2790 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, in set_io_capability()
2793 hci_dev_lock(hdev); in set_io_capability()
2795 hdev->io_capability = cp->io_capability; in set_io_capability()
2797 bt_dev_dbg(hdev, "IO capability set to 0x%02x", hdev->io_capability); in set_io_capability()
2799 hci_dev_unlock(hdev); in set_io_capability()
2801 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, 0, in set_io_capability()
2807 struct hci_dev *hdev = conn->hdev; in find_pairing() local
2810 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in find_pairing()
2899 static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in pair_device() argument
2909 bt_dev_dbg(hdev, "sock %p", sk); in pair_device()
2916 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2921 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2925 hci_dev_lock(hdev); in pair_device()
2927 if (!hdev_is_powered(hdev)) { in pair_device()
2928 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2934 if (hci_bdaddr_is_paired(hdev, &cp->addr.bdaddr, cp->addr.type)) { in pair_device()
2935 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2945 conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level, in pair_device()
2960 p = hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type); in pair_device()
2965 conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr, addr_type, in pair_device()
2982 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2989 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
2994 cmd = mgmt_pending_add(sk, MGMT_OP_PAIR_DEVICE, hdev, data, len); in pair_device()
3026 hci_dev_unlock(hdev); in pair_device()
3030 static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in cancel_pair_device() argument
3038 bt_dev_dbg(hdev, "sock %p", sk); in cancel_pair_device()
3040 hci_dev_lock(hdev); in cancel_pair_device()
3042 if (!hdev_is_powered(hdev)) { in cancel_pair_device()
3043 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3048 cmd = pending_find(MGMT_OP_PAIR_DEVICE, hdev); in cancel_pair_device()
3050 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3058 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3066 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0, in cancel_pair_device()
3074 hci_remove_link_key(hdev, &addr->bdaddr); in cancel_pair_device()
3076 smp_cancel_and_remove_pairing(hdev, &addr->bdaddr, in cancel_pair_device()
3083 hci_dev_unlock(hdev); in cancel_pair_device()
3087 static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev, in user_pairing_resp() argument
3095 hci_dev_lock(hdev); in user_pairing_resp()
3097 if (!hdev_is_powered(hdev)) { in user_pairing_resp()
3098 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3105 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &addr->bdaddr); in user_pairing_resp()
3107 conn = hci_conn_hash_lookup_le(hdev, &addr->bdaddr, in user_pairing_resp()
3111 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3120 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3124 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3131 cmd = mgmt_pending_add(sk, mgmt_op, hdev, addr, sizeof(*addr)); in user_pairing_resp()
3145 err = hci_send_cmd(hdev, hci_op, sizeof(cp), &cp); in user_pairing_resp()
3147 err = hci_send_cmd(hdev, hci_op, sizeof(addr->bdaddr), in user_pairing_resp()
3154 hci_dev_unlock(hdev); in user_pairing_resp()
3158 static int pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in pin_code_neg_reply() argument
3163 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_neg_reply()
3165 return user_pairing_resp(sk, hdev, &cp->addr, in pin_code_neg_reply()
3170 static int user_confirm_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_confirm_reply() argument
3175 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_reply()
3178 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_USER_CONFIRM_REPLY, in user_confirm_reply()
3181 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_reply()
3186 static int user_confirm_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_confirm_neg_reply() argument
3191 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_neg_reply()
3193 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_neg_reply()
3198 static int user_passkey_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_passkey_reply() argument
3203 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_reply()
3205 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_reply()
3210 static int user_passkey_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_passkey_neg_reply() argument
3215 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_neg_reply()
3217 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_neg_reply()
3222 static void adv_expire(struct hci_dev *hdev, u32 flags) in adv_expire() argument
3228 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in adv_expire()
3236 cancel_adv_timeout(hdev); in adv_expire()
3238 adv_instance = hci_get_next_instance(hdev, adv_instance->instance); in adv_expire()
3242 hci_req_init(&req, hdev); in adv_expire()
3251 static void set_name_complete(struct hci_dev *hdev, u8 status, u16 opcode) in set_name_complete() argument
3256 bt_dev_dbg(hdev, "status 0x%02x", status); in set_name_complete()
3258 hci_dev_lock(hdev); in set_name_complete()
3260 cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev); in set_name_complete()
3267 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_name_complete()
3270 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_name_complete()
3273 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_name_complete()
3274 adv_expire(hdev, MGMT_ADV_FLAG_LOCAL_NAME); in set_name_complete()
3280 hci_dev_unlock(hdev); in set_name_complete()
3283 static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data, in set_local_name() argument
3291 bt_dev_dbg(hdev, "sock %p", sk); in set_local_name()
3293 hci_dev_lock(hdev); in set_local_name()
3298 if (!memcmp(hdev->dev_name, cp->name, sizeof(hdev->dev_name)) && in set_local_name()
3299 !memcmp(hdev->short_name, cp->short_name, in set_local_name()
3300 sizeof(hdev->short_name))) { in set_local_name()
3301 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3306 memcpy(hdev->short_name, cp->short_name, sizeof(hdev->short_name)); in set_local_name()
3308 if (!hdev_is_powered(hdev)) { in set_local_name()
3309 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3311 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3316 err = mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, data, in set_local_name()
3318 ext_info_changed(hdev, sk); in set_local_name()
3323 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len); in set_local_name()
3329 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3331 hci_req_init(&req, hdev); in set_local_name()
3333 if (lmp_bredr_capable(hdev)) { in set_local_name()
3341 if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING)) in set_local_name()
3342 __hci_req_update_scan_rsp_data(&req, hdev->cur_adv_instance); in set_local_name()
3349 hci_dev_unlock(hdev); in set_local_name()
3353 static int set_appearance(struct sock *sk, struct hci_dev *hdev, void *data, in set_appearance() argument
3360 bt_dev_dbg(hdev, "sock %p", sk); in set_appearance()
3362 if (!lmp_le_capable(hdev)) in set_appearance()
3363 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_APPEARANCE, in set_appearance()
3368 hci_dev_lock(hdev); in set_appearance()
3370 if (hdev->appearance != appearance) { in set_appearance()
3371 hdev->appearance = appearance; in set_appearance()
3373 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_appearance()
3374 adv_expire(hdev, MGMT_ADV_FLAG_APPEARANCE); in set_appearance()
3376 ext_info_changed(hdev, sk); in set_appearance()
3379 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_APPEARANCE, 0, NULL, in set_appearance()
3382 hci_dev_unlock(hdev); in set_appearance()
3387 static int get_phy_configuration(struct sock *sk, struct hci_dev *hdev, in get_phy_configuration() argument
3392 bt_dev_dbg(hdev, "sock %p", sk); in get_phy_configuration()
3394 hci_dev_lock(hdev); in get_phy_configuration()
3398 rp.supported_phys = cpu_to_le32(get_supported_phys(hdev)); in get_phy_configuration()
3399 rp.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in get_phy_configuration()
3400 rp.configurable_phys = cpu_to_le32(get_configurable_phys(hdev)); in get_phy_configuration()
3402 hci_dev_unlock(hdev); in get_phy_configuration()
3404 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_PHY_CONFIGURATION, 0, in get_phy_configuration()
3408 int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip) in mgmt_phy_configuration_changed() argument
3414 ev.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in mgmt_phy_configuration_changed()
3416 return mgmt_event(MGMT_EV_PHY_CONFIGURATION_CHANGED, hdev, &ev, in mgmt_phy_configuration_changed()
3420 static void set_default_phy_complete(struct hci_dev *hdev, u8 status, in set_default_phy_complete() argument
3425 bt_dev_dbg(hdev, "status 0x%02x", status); in set_default_phy_complete()
3427 hci_dev_lock(hdev); in set_default_phy_complete()
3429 cmd = pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev); in set_default_phy_complete()
3434 mgmt_cmd_status(cmd->sk, hdev->id, in set_default_phy_complete()
3438 mgmt_cmd_complete(cmd->sk, hdev->id, in set_default_phy_complete()
3442 mgmt_phy_configuration_changed(hdev, cmd->sk); in set_default_phy_complete()
3448 hci_dev_unlock(hdev); in set_default_phy_complete()
3451 static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, in set_phy_configuration() argument
3463 bt_dev_dbg(hdev, "sock %p", sk); in set_phy_configuration()
3465 configurable_phys = get_configurable_phys(hdev); in set_phy_configuration()
3466 supported_phys = get_supported_phys(hdev); in set_phy_configuration()
3470 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3477 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3481 if (selected_phys == get_selected_phys(hdev)) in set_phy_configuration()
3482 return mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
3486 hci_dev_lock(hdev); in set_phy_configuration()
3488 if (!hdev_is_powered(hdev)) { in set_phy_configuration()
3489 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3495 if (pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) { in set_phy_configuration()
3496 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
3542 if (pkt_type != hdev->pkt_type) { in set_phy_configuration()
3543 hdev->pkt_type = pkt_type; in set_phy_configuration()
3548 (get_selected_phys(hdev) & MGMT_PHY_LE_MASK)) { in set_phy_configuration()
3550 mgmt_phy_configuration_changed(hdev, sk); in set_phy_configuration()
3552 err = mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
3559 cmd = mgmt_pending_add(sk, MGMT_OP_SET_PHY_CONFIGURATION, hdev, data, in set_phy_configuration()
3566 hci_req_init(&req, hdev); in set_phy_configuration()
3601 hci_dev_unlock(hdev); in set_phy_configuration()
3606 static int set_blocked_keys(struct sock *sk, struct hci_dev *hdev, void *data, in set_blocked_keys() argument
3616 bt_dev_dbg(hdev, "sock %p", sk); in set_blocked_keys()
3620 bt_dev_err(hdev, "too big key_count value %u", key_count); in set_blocked_keys()
3621 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
3627 bt_dev_err(hdev, "expected %u bytes, got %u bytes", in set_blocked_keys()
3629 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
3633 hci_dev_lock(hdev); in set_blocked_keys()
3635 hci_blocked_keys_clear(hdev); in set_blocked_keys()
3647 list_add_rcu(&b->list, &hdev->blocked_keys); in set_blocked_keys()
3649 hci_dev_unlock(hdev); in set_blocked_keys()
3651 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
3655 static int set_wideband_speech(struct sock *sk, struct hci_dev *hdev, in set_wideband_speech() argument
3662 bt_dev_dbg(hdev, "sock %p", sk); in set_wideband_speech()
3664 if (!test_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks)) in set_wideband_speech()
3665 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
3670 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
3674 hci_dev_lock(hdev); in set_wideband_speech()
3676 if (pending_find(MGMT_OP_SET_WIDEBAND_SPEECH, hdev)) { in set_wideband_speech()
3677 err = mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
3683 if (hdev_is_powered(hdev) && in set_wideband_speech()
3684 !!cp->val != hci_dev_test_flag(hdev, in set_wideband_speech()
3686 err = mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
3693 changed = !hci_dev_test_and_set_flag(hdev, in set_wideband_speech()
3696 changed = hci_dev_test_and_clear_flag(hdev, in set_wideband_speech()
3699 err = send_settings_rsp(sk, MGMT_OP_SET_WIDEBAND_SPEECH, hdev); in set_wideband_speech()
3704 err = new_settings(hdev, sk); in set_wideband_speech()
3707 hci_dev_unlock(hdev); in set_wideband_speech()
3711 static int read_security_info(struct sock *sk, struct hci_dev *hdev, in read_security_info() argument
3719 bt_dev_dbg(hdev, "sock %p", sk); in read_security_info()
3723 hci_dev_lock(hdev); in read_security_info()
3728 if (hdev->commands[41] & 0x08) in read_security_info()
3736 if (hdev->commands[20] & 0x10) in read_security_info()
3746 if (hdev->commands[41] & 0x08) in read_security_info()
3748 hdev->max_enc_key_size); in read_security_info()
3754 hci_dev_unlock(hdev); in read_security_info()
3756 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_SECURITY_INFO, 0, in read_security_info()
3780 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, in read_exp_features_info() argument
3788 bt_dev_dbg(hdev, "sock %p", sk); in read_exp_features_info()
3793 if (!hdev) { in read_exp_features_info()
3802 if (hdev) { in read_exp_features_info()
3803 if (test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) && in read_exp_features_info()
3804 (hdev->le_states[4] & 0x08) && /* Central */ in read_exp_features_info()
3805 (hdev->le_states[4] & 0x40) && /* Peripheral */ in read_exp_features_info()
3806 (hdev->le_states[3] & 0x10)) /* Simultaneous */ in read_exp_features_info()
3816 if (hdev && use_ll_privacy(hdev)) { in read_exp_features_info()
3817 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in read_exp_features_info()
3834 return mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in read_exp_features_info()
3839 static int exp_ll_privacy_feature_changed(bool enabled, struct hci_dev *hdev, in exp_ll_privacy_feature_changed() argument
3848 return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, in exp_ll_privacy_feature_changed()
3869 static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, in set_exp_feature() argument
3875 bt_dev_dbg(hdev, "sock %p", sk); in set_exp_feature()
3882 if (!hdev) { in set_exp_feature()
3892 if (hdev && use_ll_privacy(hdev) && !hdev_is_powered(hdev)) { in set_exp_feature()
3893 bool changed = hci_dev_test_flag(hdev, in set_exp_feature()
3896 hci_dev_clear_flag(hdev, HCI_ENABLE_LL_PRIVACY); in set_exp_feature()
3899 exp_ll_privacy_feature_changed(false, hdev, sk); in set_exp_feature()
3904 return mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_exp_feature()
3915 if (hdev) in set_exp_feature()
3916 return mgmt_cmd_status(sk, hdev->id, in set_exp_feature()
3958 if (!hdev) in set_exp_feature()
3964 if (hdev_is_powered(hdev)) in set_exp_feature()
3965 return mgmt_cmd_status(sk, hdev->id, in set_exp_feature()
3971 return mgmt_cmd_status(sk, hdev->id, in set_exp_feature()
3977 return mgmt_cmd_status(sk, hdev->id, in set_exp_feature()
3984 changed = !hci_dev_test_flag(hdev, in set_exp_feature()
3986 hci_dev_set_flag(hdev, HCI_ENABLE_LL_PRIVACY); in set_exp_feature()
3987 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_exp_feature()
3992 changed = hci_dev_test_flag(hdev, in set_exp_feature()
3994 hci_dev_clear_flag(hdev, HCI_ENABLE_LL_PRIVACY); in set_exp_feature()
4005 err = mgmt_cmd_complete(sk, hdev->id, in set_exp_feature()
4010 exp_ll_privacy_feature_changed(val, hdev, sk); in set_exp_feature()
4015 return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_exp_feature()
4022 static int get_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in get_device_flags() argument
4033 bt_dev_dbg(hdev, "Get device flags %pMR (type 0x%x)\n", in get_device_flags()
4036 hci_dev_lock(hdev); in get_device_flags()
4039 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->whitelist, in get_device_flags()
4047 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in get_device_flags()
4064 hci_dev_unlock(hdev); in get_device_flags()
4066 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_DEVICE_FLAGS, status, in get_device_flags()
4070 static void device_flags_changed(struct sock *sk, struct hci_dev *hdev, in device_flags_changed() argument
4081 mgmt_event(MGMT_EV_DEVICE_FLAGS_CHANGED, hdev, &ev, sizeof(ev), sk); in device_flags_changed()
4084 static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_flags() argument
4094 bt_dev_dbg(hdev, "Set device flags %pMR (type 0x%x) = 0x%x", in set_device_flags()
4099 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
4104 hci_dev_lock(hdev); in set_device_flags()
4107 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->whitelist, in set_device_flags()
4115 bt_dev_warn(hdev, "No such BR/EDR device %pMR (0x%x)", in set_device_flags()
4119 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in set_device_flags()
4125 bt_dev_warn(hdev, "No such LE device %pMR (0x%x)", in set_device_flags()
4132 hci_dev_unlock(hdev); in set_device_flags()
4135 device_flags_changed(sk, hdev, &cp->addr.bdaddr, cp->addr.type, in set_device_flags()
4138 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_FLAGS, status, in set_device_flags()
4142 static void mgmt_adv_monitor_added(struct sock *sk, struct hci_dev *hdev, in mgmt_adv_monitor_added() argument
4149 mgmt_event(MGMT_EV_ADV_MONITOR_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_adv_monitor_added()
4152 static void mgmt_adv_monitor_removed(struct sock *sk, struct hci_dev *hdev, in mgmt_adv_monitor_removed() argument
4159 mgmt_event(MGMT_EV_ADV_MONITOR_REMOVED, hdev, &ev, sizeof(ev), sk); in mgmt_adv_monitor_removed()
4162 static int read_adv_mon_features(struct sock *sk, struct hci_dev *hdev, in read_adv_mon_features() argument
4173 BT_DBG("request for %s", hdev->name); in read_adv_mon_features()
4175 hci_dev_lock(hdev); in read_adv_mon_features()
4177 if (msft_get_features(hdev) & MSFT_FEATURE_MASK_LE_ADV_MONITOR) in read_adv_mon_features()
4180 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) { in read_adv_mon_features()
4184 hci_dev_unlock(hdev); in read_adv_mon_features()
4202 err = mgmt_cmd_complete(sk, hdev->id, in read_adv_mon_features()
4211 static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor() argument
4222 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor()
4225 err = mgmt_cmd_status(sk, hdev->id, in add_adv_patterns_monitor()
4242 err = mgmt_cmd_status(sk, hdev->id, in add_adv_patterns_monitor()
4253 err = mgmt_cmd_status(sk, hdev->id, in add_adv_patterns_monitor()
4275 err = mgmt_cmd_status(sk, hdev->id, in add_adv_patterns_monitor()
4281 hci_dev_lock(hdev); in add_adv_patterns_monitor()
4283 prev_adv_monitors_cnt = hdev->adv_monitors_cnt; in add_adv_patterns_monitor()
4285 err = hci_add_adv_monitor(hdev, m); in add_adv_patterns_monitor()
4288 mgmt_cmd_status(sk, hdev->id, in add_adv_patterns_monitor()
4295 if (hdev->adv_monitors_cnt > prev_adv_monitors_cnt) in add_adv_patterns_monitor()
4296 mgmt_adv_monitor_added(sk, hdev, m->handle); in add_adv_patterns_monitor()
4298 hci_dev_unlock(hdev); in add_adv_patterns_monitor()
4302 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADV_PATTERNS_MONITOR, in add_adv_patterns_monitor()
4306 hci_dev_unlock(hdev); in add_adv_patterns_monitor()
4313 static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev, in remove_adv_monitor() argument
4322 BT_DBG("request for %s", hdev->name); in remove_adv_monitor()
4324 hci_dev_lock(hdev); in remove_adv_monitor()
4327 prev_adv_monitors_cnt = hdev->adv_monitors_cnt; in remove_adv_monitor()
4329 err = hci_remove_adv_monitor(hdev, handle); in remove_adv_monitor()
4331 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, in remove_adv_monitor()
4336 if (hdev->adv_monitors_cnt < prev_adv_monitors_cnt) in remove_adv_monitor()
4337 mgmt_adv_monitor_removed(sk, hdev, handle); in remove_adv_monitor()
4339 hci_dev_unlock(hdev); in remove_adv_monitor()
4343 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, in remove_adv_monitor()
4347 hci_dev_unlock(hdev); in remove_adv_monitor()
4351 static void read_local_oob_data_complete(struct hci_dev *hdev, u8 status, in read_local_oob_data_complete() argument
4358 bt_dev_dbg(hdev, "status %u", status); in read_local_oob_data_complete()
4360 cmd = pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev); in read_local_oob_data_complete()
4365 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data_complete()
4376 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
4390 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
4403 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data_complete()
4410 static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_data() argument
4417 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_data()
4419 hci_dev_lock(hdev); in read_local_oob_data()
4421 if (!hdev_is_powered(hdev)) { in read_local_oob_data()
4422 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
4427 if (!lmp_ssp_capable(hdev)) { in read_local_oob_data()
4428 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
4433 if (pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev)) { in read_local_oob_data()
4434 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
4439 cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_DATA, hdev, NULL, 0); in read_local_oob_data()
4445 hci_req_init(&req, hdev); in read_local_oob_data()
4447 if (bredr_sc_enabled(hdev)) in read_local_oob_data()
4457 hci_dev_unlock(hdev); in read_local_oob_data()
4461 static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in add_remote_oob_data() argument
4467 bt_dev_dbg(hdev, "sock %p", sk); in add_remote_oob_data()
4470 return mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
4475 hci_dev_lock(hdev); in add_remote_oob_data()
4482 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
4489 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
4497 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
4511 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
4546 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
4554 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
4558 bt_dev_err(hdev, "add_remote_oob_data: invalid len of %u bytes", in add_remote_oob_data()
4560 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, in add_remote_oob_data()
4565 hci_dev_unlock(hdev); in add_remote_oob_data()
4569 static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in remove_remote_oob_data() argument
4576 bt_dev_dbg(hdev, "sock %p", sk); in remove_remote_oob_data()
4579 return mgmt_cmd_complete(sk, hdev->id, in remove_remote_oob_data()
4584 hci_dev_lock(hdev); in remove_remote_oob_data()
4587 hci_remote_oob_data_clear(hdev); in remove_remote_oob_data()
4592 err = hci_remove_remote_oob_data(hdev, &cp->addr.bdaddr, cp->addr.type); in remove_remote_oob_data()
4599 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA, in remove_remote_oob_data()
4602 hci_dev_unlock(hdev); in remove_remote_oob_data()
4606 void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_start_discovery_complete() argument
4610 bt_dev_dbg(hdev, "status %d", status); in mgmt_start_discovery_complete()
4612 hci_dev_lock(hdev); in mgmt_start_discovery_complete()
4614 cmd = pending_find(MGMT_OP_START_DISCOVERY, hdev); in mgmt_start_discovery_complete()
4616 cmd = pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev); in mgmt_start_discovery_complete()
4619 cmd = pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev); in mgmt_start_discovery_complete()
4626 hci_dev_unlock(hdev); in mgmt_start_discovery_complete()
4630 hdev->suspend_tasks)) { in mgmt_start_discovery_complete()
4631 bt_dev_dbg(hdev, "Unpaused discovery"); in mgmt_start_discovery_complete()
4632 wake_up(&hdev->suspend_wait_q); in mgmt_start_discovery_complete()
4636 static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, in discovery_type_is_valid() argument
4641 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
4646 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
4651 *mgmt_status = mgmt_bredr_support(hdev); in discovery_type_is_valid()
4663 static int start_discovery_internal(struct sock *sk, struct hci_dev *hdev, in start_discovery_internal() argument
4671 bt_dev_dbg(hdev, "sock %p", sk); in start_discovery_internal()
4673 hci_dev_lock(hdev); in start_discovery_internal()
4675 if (!hdev_is_powered(hdev)) { in start_discovery_internal()
4676 err = mgmt_cmd_complete(sk, hdev->id, op, in start_discovery_internal()
4682 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_discovery_internal()
4683 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_discovery_internal()
4684 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
4689 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_discovery_internal()
4690 err = mgmt_cmd_complete(sk, hdev->id, op, status, in start_discovery_internal()
4696 if (hdev->discovery_paused) { in start_discovery_internal()
4697 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
4705 hci_discovery_filter_clear(hdev); in start_discovery_internal()
4707 hdev->discovery.type = cp->type; in start_discovery_internal()
4708 hdev->discovery.report_invalid_rssi = false; in start_discovery_internal()
4710 hdev->discovery.limited = true; in start_discovery_internal()
4712 hdev->discovery.limited = false; in start_discovery_internal()
4714 cmd = mgmt_pending_add(sk, op, hdev, data, len); in start_discovery_internal()
4722 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_discovery_internal()
4723 queue_work(hdev->req_workqueue, &hdev->discov_update); in start_discovery_internal()
4727 hci_dev_unlock(hdev); in start_discovery_internal()
4731 static int start_discovery(struct sock *sk, struct hci_dev *hdev, in start_discovery() argument
4734 return start_discovery_internal(sk, hdev, MGMT_OP_START_DISCOVERY, in start_discovery()
4738 static int start_limited_discovery(struct sock *sk, struct hci_dev *hdev, in start_limited_discovery() argument
4741 return start_discovery_internal(sk, hdev, in start_limited_discovery()
4753 static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, in start_service_discovery() argument
4763 bt_dev_dbg(hdev, "sock %p", sk); in start_service_discovery()
4765 hci_dev_lock(hdev); in start_service_discovery()
4767 if (!hdev_is_powered(hdev)) { in start_service_discovery()
4768 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4775 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_service_discovery()
4776 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_service_discovery()
4777 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4786 bt_dev_err(hdev, "service_discovery: too big uuid_count value %u", in start_service_discovery()
4788 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4797 bt_dev_err(hdev, "service_discovery: expected %u bytes, got %u bytes", in start_service_discovery()
4799 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4806 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_service_discovery()
4807 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4814 hdev, data, len); in start_service_discovery()
4825 hci_discovery_filter_clear(hdev); in start_service_discovery()
4827 hdev->discovery.result_filtering = true; in start_service_discovery()
4828 hdev->discovery.type = cp->type; in start_service_discovery()
4829 hdev->discovery.rssi = cp->rssi; in start_service_discovery()
4830 hdev->discovery.uuid_count = uuid_count; in start_service_discovery()
4833 hdev->discovery.uuids = kmemdup(cp->uuids, uuid_count * 16, in start_service_discovery()
4835 if (!hdev->discovery.uuids) { in start_service_discovery()
4836 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
4845 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_service_discovery()
4846 queue_work(hdev->req_workqueue, &hdev->discov_update); in start_service_discovery()
4850 hci_dev_unlock(hdev); in start_service_discovery()
4854 void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_stop_discovery_complete() argument
4858 bt_dev_dbg(hdev, "status %d", status); in mgmt_stop_discovery_complete()
4860 hci_dev_lock(hdev); in mgmt_stop_discovery_complete()
4862 cmd = pending_find(MGMT_OP_STOP_DISCOVERY, hdev); in mgmt_stop_discovery_complete()
4868 hci_dev_unlock(hdev); in mgmt_stop_discovery_complete()
4871 if (test_and_clear_bit(SUSPEND_PAUSE_DISCOVERY, hdev->suspend_tasks)) { in mgmt_stop_discovery_complete()
4872 bt_dev_dbg(hdev, "Paused discovery"); in mgmt_stop_discovery_complete()
4873 wake_up(&hdev->suspend_wait_q); in mgmt_stop_discovery_complete()
4877 static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, in stop_discovery() argument
4884 bt_dev_dbg(hdev, "sock %p", sk); in stop_discovery()
4886 hci_dev_lock(hdev); in stop_discovery()
4888 if (!hci_discovery_active(hdev)) { in stop_discovery()
4889 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
4895 if (hdev->discovery.type != mgmt_cp->type) { in stop_discovery()
4896 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
4902 cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, hdev, data, len); in stop_discovery()
4910 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in stop_discovery()
4911 queue_work(hdev->req_workqueue, &hdev->discov_update); in stop_discovery()
4915 hci_dev_unlock(hdev); in stop_discovery()
4919 static int confirm_name(struct sock *sk, struct hci_dev *hdev, void *data, in confirm_name() argument
4926 bt_dev_dbg(hdev, "sock %p", sk); in confirm_name()
4928 hci_dev_lock(hdev); in confirm_name()
4930 if (!hci_discovery_active(hdev)) { in confirm_name()
4931 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
4937 e = hci_inquiry_cache_lookup_unknown(hdev, &cp->addr.bdaddr); in confirm_name()
4939 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
4950 hci_inquiry_cache_update_resolve(hdev, e); in confirm_name()
4953 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, 0, in confirm_name()
4957 hci_dev_unlock(hdev); in confirm_name()
4961 static int block_device(struct sock *sk, struct hci_dev *hdev, void *data, in block_device() argument
4968 bt_dev_dbg(hdev, "sock %p", sk); in block_device()
4971 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, in block_device()
4975 hci_dev_lock(hdev); in block_device()
4977 err = hci_bdaddr_list_add(&hdev->blacklist, &cp->addr.bdaddr, in block_device()
4984 mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &cp->addr, sizeof(cp->addr), in block_device()
4989 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status, in block_device()
4992 hci_dev_unlock(hdev); in block_device()
4997 static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data, in unblock_device() argument
5004 bt_dev_dbg(hdev, "sock %p", sk); in unblock_device()
5007 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, in unblock_device()
5011 hci_dev_lock(hdev); in unblock_device()
5013 err = hci_bdaddr_list_del(&hdev->blacklist, &cp->addr.bdaddr, in unblock_device()
5020 mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &cp->addr, sizeof(cp->addr), in unblock_device()
5025 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status, in unblock_device()
5028 hci_dev_unlock(hdev); in unblock_device()
5033 static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_id() argument
5041 bt_dev_dbg(hdev, "sock %p", sk); in set_device_id()
5046 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, in set_device_id()
5049 hci_dev_lock(hdev); in set_device_id()
5051 hdev->devid_source = source; in set_device_id()
5052 hdev->devid_vendor = __le16_to_cpu(cp->vendor); in set_device_id()
5053 hdev->devid_product = __le16_to_cpu(cp->product); in set_device_id()
5054 hdev->devid_version = __le16_to_cpu(cp->version); in set_device_id()
5056 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, 0, in set_device_id()
5059 hci_req_init(&req, hdev); in set_device_id()
5063 hci_dev_unlock(hdev); in set_device_id()
5068 static void enable_advertising_instance(struct hci_dev *hdev, u8 status, in enable_advertising_instance() argument
5071 bt_dev_dbg(hdev, "status %d", status); in enable_advertising_instance()
5074 static void set_advertising_complete(struct hci_dev *hdev, u8 status, in set_advertising_complete() argument
5077 struct cmd_lookup match = { NULL, hdev }; in set_advertising_complete()
5083 hci_dev_lock(hdev); in set_advertising_complete()
5088 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, in set_advertising_complete()
5093 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_advertising_complete()
5094 hci_dev_set_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
5096 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
5098 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, settings_rsp, in set_advertising_complete()
5101 new_settings(hdev, match.sk); in set_advertising_complete()
5108 hdev->suspend_tasks)) { in set_advertising_complete()
5109 bt_dev_dbg(hdev, "Paused advertising"); in set_advertising_complete()
5110 wake_up(&hdev->suspend_wait_q); in set_advertising_complete()
5112 hdev->suspend_tasks)) { in set_advertising_complete()
5113 bt_dev_dbg(hdev, "Unpaused advertising"); in set_advertising_complete()
5114 wake_up(&hdev->suspend_wait_q); in set_advertising_complete()
5120 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in set_advertising_complete()
5121 list_empty(&hdev->adv_instances)) in set_advertising_complete()
5124 instance = hdev->cur_adv_instance; in set_advertising_complete()
5126 adv_instance = list_first_entry_or_null(&hdev->adv_instances, in set_advertising_complete()
5134 hci_req_init(&req, hdev); in set_advertising_complete()
5142 bt_dev_err(hdev, "failed to re-configure advertising"); in set_advertising_complete()
5145 hci_dev_unlock(hdev); in set_advertising_complete()
5148 static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, in set_advertising() argument
5157 bt_dev_dbg(hdev, "sock %p", sk); in set_advertising()
5159 status = mgmt_le_support(hdev); in set_advertising()
5161 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
5167 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in set_advertising()
5168 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
5172 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
5175 if (hdev->advertising_paused) in set_advertising()
5176 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
5179 hci_dev_lock(hdev); in set_advertising()
5188 if (!hdev_is_powered(hdev) || in set_advertising()
5189 (val == hci_dev_test_flag(hdev, HCI_ADVERTISING) && in set_advertising()
5190 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) || in set_advertising()
5191 hci_conn_num(hdev, LE_LINK) > 0 || in set_advertising()
5192 (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_advertising()
5193 hdev->le_scan_type == LE_SCAN_ACTIVE)) { in set_advertising()
5197 hdev->cur_adv_instance = 0x00; in set_advertising()
5198 changed = !hci_dev_test_and_set_flag(hdev, HCI_ADVERTISING); in set_advertising()
5200 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
5202 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
5204 changed = hci_dev_test_and_clear_flag(hdev, HCI_ADVERTISING); in set_advertising()
5205 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
5208 err = send_settings_rsp(sk, MGMT_OP_SET_ADVERTISING, hdev); in set_advertising()
5213 err = new_settings(hdev, sk); in set_advertising()
5218 if (pending_find(MGMT_OP_SET_ADVERTISING, hdev) || in set_advertising()
5219 pending_find(MGMT_OP_SET_LE, hdev)) { in set_advertising()
5220 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
5225 cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING, hdev, data, len); in set_advertising()
5231 hci_req_init(&req, hdev); in set_advertising()
5234 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
5236 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
5238 cancel_adv_timeout(hdev); in set_advertising()
5245 hdev->cur_adv_instance = 0x00; in set_advertising()
5247 if (ext_adv_capable(hdev)) { in set_advertising()
5263 hci_dev_unlock(hdev); in set_advertising()
5267 static int set_static_address(struct sock *sk, struct hci_dev *hdev, in set_static_address() argument
5273 bt_dev_dbg(hdev, "sock %p", sk); in set_static_address()
5275 if (!lmp_le_capable(hdev)) in set_static_address()
5276 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
5279 if (hdev_is_powered(hdev)) in set_static_address()
5280 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
5285 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
5291 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
5296 hci_dev_lock(hdev); in set_static_address()
5298 bacpy(&hdev->static_addr, &cp->bdaddr); in set_static_address()
5300 err = send_settings_rsp(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev); in set_static_address()
5304 err = new_settings(hdev, sk); in set_static_address()
5307 hci_dev_unlock(hdev); in set_static_address()
5311 static int set_scan_params(struct sock *sk, struct hci_dev *hdev, in set_scan_params() argument
5318 bt_dev_dbg(hdev, "sock %p", sk); in set_scan_params()
5320 if (!lmp_le_capable(hdev)) in set_scan_params()
5321 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
5327 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
5333 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
5337 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
5340 hci_dev_lock(hdev); in set_scan_params()
5342 hdev->le_scan_interval = interval; in set_scan_params()
5343 hdev->le_scan_window = window; in set_scan_params()
5345 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, 0, in set_scan_params()
5351 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_scan_params()
5352 hdev->discovery.state == DISCOVERY_STOPPED) { in set_scan_params()
5355 hci_req_init(&req, hdev); in set_scan_params()
5363 hci_dev_unlock(hdev); in set_scan_params()
5368 static void fast_connectable_complete(struct hci_dev *hdev, u8 status, in fast_connectable_complete() argument
5373 bt_dev_dbg(hdev, "status 0x%02x", status); in fast_connectable_complete()
5375 hci_dev_lock(hdev); in fast_connectable_complete()
5377 cmd = pending_find(MGMT_OP_SET_FAST_CONNECTABLE, hdev); in fast_connectable_complete()
5382 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in fast_connectable_complete()
5388 hci_dev_set_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
5390 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
5392 send_settings_rsp(cmd->sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in fast_connectable_complete()
5393 new_settings(hdev, cmd->sk); in fast_connectable_complete()
5399 hci_dev_unlock(hdev); in fast_connectable_complete()
5402 static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev, in set_fast_connectable() argument
5410 bt_dev_dbg(hdev, "sock %p", sk); in set_fast_connectable()
5412 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in set_fast_connectable()
5413 hdev->hci_ver < BLUETOOTH_VER_1_2) in set_fast_connectable()
5414 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
5418 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
5421 hci_dev_lock(hdev); in set_fast_connectable()
5423 if (pending_find(MGMT_OP_SET_FAST_CONNECTABLE, hdev)) { in set_fast_connectable()
5424 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
5429 if (!!cp->val == hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) { in set_fast_connectable()
5431 hdev); in set_fast_connectable()
5435 if (!hdev_is_powered(hdev)) { in set_fast_connectable()
5436 hci_dev_change_flag(hdev, HCI_FAST_CONNECTABLE); in set_fast_connectable()
5438 hdev); in set_fast_connectable()
5439 new_settings(hdev, sk); in set_fast_connectable()
5443 cmd = mgmt_pending_add(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev, in set_fast_connectable()
5450 hci_req_init(&req, hdev); in set_fast_connectable()
5456 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
5462 hci_dev_unlock(hdev); in set_fast_connectable()
5467 static void set_bredr_complete(struct hci_dev *hdev, u8 status, u16 opcode) in set_bredr_complete() argument
5471 bt_dev_dbg(hdev, "status 0x%02x", status); in set_bredr_complete()
5473 hci_dev_lock(hdev); in set_bredr_complete()
5475 cmd = pending_find(MGMT_OP_SET_BREDR, hdev); in set_bredr_complete()
5485 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in set_bredr_complete()
5489 send_settings_rsp(cmd->sk, MGMT_OP_SET_BREDR, hdev); in set_bredr_complete()
5490 new_settings(hdev, cmd->sk); in set_bredr_complete()
5496 hci_dev_unlock(hdev); in set_bredr_complete()
5499 static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_bredr() argument
5506 bt_dev_dbg(hdev, "sock %p", sk); in set_bredr()
5508 if (!lmp_bredr_capable(hdev) || !lmp_le_capable(hdev)) in set_bredr()
5509 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5512 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_bredr()
5513 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5517 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5520 hci_dev_lock(hdev); in set_bredr()
5522 if (cp->val == hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_bredr()
5523 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
5527 if (!hdev_is_powered(hdev)) { in set_bredr()
5529 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_bredr()
5530 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_bredr()
5531 hci_dev_clear_flag(hdev, HCI_LINK_SECURITY); in set_bredr()
5532 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in set_bredr()
5533 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_bredr()
5536 hci_dev_change_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
5538 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
5542 err = new_settings(hdev, sk); in set_bredr()
5548 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5566 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_bredr()
5567 (bacmp(&hdev->static_addr, BDADDR_ANY) || in set_bredr()
5568 hci_dev_test_flag(hdev, HCI_SC_ENABLED))) { in set_bredr()
5569 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5575 if (pending_find(MGMT_OP_SET_BREDR, hdev)) { in set_bredr()
5576 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
5581 cmd = mgmt_pending_add(sk, MGMT_OP_SET_BREDR, hdev, data, len); in set_bredr()
5590 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
5592 hci_req_init(&req, hdev); in set_bredr()
5600 __hci_req_update_adv_data(&req, hdev->cur_adv_instance); in set_bredr()
5607 hci_dev_unlock(hdev); in set_bredr()
5611 static void sc_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) in sc_enable_complete() argument
5616 bt_dev_dbg(hdev, "status %u", status); in sc_enable_complete()
5618 hci_dev_lock(hdev); in sc_enable_complete()
5620 cmd = pending_find(MGMT_OP_SET_SECURE_CONN, hdev); in sc_enable_complete()
5634 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in sc_enable_complete()
5635 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in sc_enable_complete()
5638 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in sc_enable_complete()
5639 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in sc_enable_complete()
5642 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in sc_enable_complete()
5643 hci_dev_set_flag(hdev, HCI_SC_ONLY); in sc_enable_complete()
5647 send_settings_rsp(cmd->sk, MGMT_OP_SET_SECURE_CONN, hdev); in sc_enable_complete()
5648 new_settings(hdev, cmd->sk); in sc_enable_complete()
5653 hci_dev_unlock(hdev); in sc_enable_complete()
5656 static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, in set_secure_conn() argument
5665 bt_dev_dbg(hdev, "sock %p", sk); in set_secure_conn()
5667 if (!lmp_sc_capable(hdev) && in set_secure_conn()
5668 !hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_secure_conn()
5669 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
5672 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_secure_conn()
5673 lmp_sc_capable(hdev) && in set_secure_conn()
5674 !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_secure_conn()
5675 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
5679 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
5682 hci_dev_lock(hdev); in set_secure_conn()
5684 if (!hdev_is_powered(hdev) || !lmp_sc_capable(hdev) || in set_secure_conn()
5685 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_secure_conn()
5689 changed = !hci_dev_test_and_set_flag(hdev, in set_secure_conn()
5692 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
5694 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
5696 changed = hci_dev_test_and_clear_flag(hdev, in set_secure_conn()
5698 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
5701 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
5706 err = new_settings(hdev, sk); in set_secure_conn()
5711 if (pending_find(MGMT_OP_SET_SECURE_CONN, hdev)) { in set_secure_conn()
5712 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
5719 if (val == hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in set_secure_conn()
5720 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in set_secure_conn()
5721 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
5725 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len); in set_secure_conn()
5731 hci_req_init(&req, hdev); in set_secure_conn()
5740 hci_dev_unlock(hdev); in set_secure_conn()
5744 static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, in set_debug_keys() argument
5751 bt_dev_dbg(hdev, "sock %p", sk); in set_debug_keys()
5754 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEBUG_KEYS, in set_debug_keys()
5757 hci_dev_lock(hdev); in set_debug_keys()
5760 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in set_debug_keys()
5762 changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
5766 use_changed = !hci_dev_test_and_set_flag(hdev, in set_debug_keys()
5769 use_changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
5772 if (hdev_is_powered(hdev) && use_changed && in set_debug_keys()
5773 hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_debug_keys()
5775 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in set_debug_keys()
5779 err = send_settings_rsp(sk, MGMT_OP_SET_DEBUG_KEYS, hdev); in set_debug_keys()
5784 err = new_settings(hdev, sk); in set_debug_keys()
5787 hci_dev_unlock(hdev); in set_debug_keys()
5791 static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data, in set_privacy() argument
5798 bt_dev_dbg(hdev, "sock %p", sk); in set_privacy()
5800 if (!lmp_le_capable(hdev)) in set_privacy()
5801 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
5805 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
5808 if (hdev_is_powered(hdev)) in set_privacy()
5809 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
5812 hci_dev_lock(hdev); in set_privacy()
5817 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in set_privacy()
5820 changed = !hci_dev_test_and_set_flag(hdev, HCI_PRIVACY); in set_privacy()
5821 memcpy(hdev->irk, cp->irk, sizeof(hdev->irk)); in set_privacy()
5822 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
5823 hci_adv_instances_set_rpa_expired(hdev, true); in set_privacy()
5825 hci_dev_set_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
5827 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
5829 changed = hci_dev_test_and_clear_flag(hdev, HCI_PRIVACY); in set_privacy()
5830 memset(hdev->irk, 0, sizeof(hdev->irk)); in set_privacy()
5831 hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
5832 hci_adv_instances_set_rpa_expired(hdev, false); in set_privacy()
5833 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
5836 err = send_settings_rsp(sk, MGMT_OP_SET_PRIVACY, hdev); in set_privacy()
5841 err = new_settings(hdev, sk); in set_privacy()
5844 hci_dev_unlock(hdev); in set_privacy()
5864 static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data, in load_irks() argument
5873 bt_dev_dbg(hdev, "sock %p", sk); in load_irks()
5875 if (!lmp_le_capable(hdev)) in load_irks()
5876 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
5881 bt_dev_err(hdev, "load_irks: too big irk_count value %u", in load_irks()
5883 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
5889 bt_dev_err(hdev, "load_irks: expected %u bytes, got %u bytes", in load_irks()
5891 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
5895 bt_dev_dbg(hdev, "irk_count %u", irk_count); in load_irks()
5901 return mgmt_cmd_status(sk, hdev->id, in load_irks()
5906 hci_dev_lock(hdev); in load_irks()
5908 hci_smp_irks_clear(hdev); in load_irks()
5913 if (hci_is_blocked_key(hdev, in load_irks()
5916 bt_dev_warn(hdev, "Skipping blocked IRK for %pMR", in load_irks()
5921 hci_add_irk(hdev, &irk->addr.bdaddr, in load_irks()
5926 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in load_irks()
5928 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_IRKS, 0, NULL, 0); in load_irks()
5930 hci_dev_unlock(hdev); in load_irks()
5954 static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev, in load_long_term_keys() argument
5963 bt_dev_dbg(hdev, "sock %p", sk); in load_long_term_keys()
5965 if (!lmp_le_capable(hdev)) in load_long_term_keys()
5966 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
5971 bt_dev_err(hdev, "load_ltks: too big key_count value %u", in load_long_term_keys()
5973 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
5979 bt_dev_err(hdev, "load_keys: expected %u bytes, got %u bytes", in load_long_term_keys()
5981 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
5985 bt_dev_dbg(hdev, "key_count %u", key_count); in load_long_term_keys()
5991 return mgmt_cmd_status(sk, hdev->id, in load_long_term_keys()
5996 hci_dev_lock(hdev); in load_long_term_keys()
5998 hci_smp_ltks_clear(hdev); in load_long_term_keys()
6004 if (hci_is_blocked_key(hdev, in load_long_term_keys()
6007 bt_dev_warn(hdev, "Skipping blocked LTK for %pMR", in load_long_term_keys()
6037 hci_add_ltk(hdev, &key->addr.bdaddr, in load_long_term_keys()
6042 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 0, in load_long_term_keys()
6045 hci_dev_unlock(hdev); in load_long_term_keys()
6077 static void conn_info_refresh_complete(struct hci_dev *hdev, u8 hci_status, in conn_info_refresh_complete() argument
6086 bt_dev_dbg(hdev, "status 0x%02x", hci_status); in conn_info_refresh_complete()
6088 hci_dev_lock(hdev); in conn_info_refresh_complete()
6099 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_RSSI); in conn_info_refresh_complete()
6101 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER); in conn_info_refresh_complete()
6108 bt_dev_err(hdev, "invalid sent_cmd in conn_info response"); in conn_info_refresh_complete()
6113 conn = hci_conn_hash_lookup_handle(hdev, handle); in conn_info_refresh_complete()
6115 bt_dev_err(hdev, "unknown handle (%d) in conn_info response", in conn_info_refresh_complete()
6120 cmd = pending_find_data(MGMT_OP_GET_CONN_INFO, hdev, conn); in conn_info_refresh_complete()
6128 hci_dev_unlock(hdev); in conn_info_refresh_complete()
6131 static int get_conn_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_conn_info() argument
6140 bt_dev_dbg(hdev, "sock %p", sk); in get_conn_info()
6147 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
6151 hci_dev_lock(hdev); in get_conn_info()
6153 if (!hdev_is_powered(hdev)) { in get_conn_info()
6154 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
6161 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info()
6164 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info()
6167 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
6173 if (pending_find_data(MGMT_OP_GET_CONN_INFO, hdev, conn)) { in get_conn_info()
6174 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
6182 conn_info_age = hdev->conn_info_min_age + in get_conn_info()
6183 prandom_u32_max(hdev->conn_info_max_age - in get_conn_info()
6184 hdev->conn_info_min_age); in get_conn_info()
6197 hci_req_init(&req, hdev); in get_conn_info()
6225 cmd = mgmt_pending_add(sk, MGMT_OP_GET_CONN_INFO, hdev, in get_conn_info()
6243 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
6248 hci_dev_unlock(hdev); in get_conn_info()
6256 struct hci_dev *hdev; in clock_info_cmd_complete() local
6265 hdev = hci_dev_get(cmd->index); in clock_info_cmd_complete()
6266 if (hdev) { in clock_info_cmd_complete()
6267 rp.local_clock = cpu_to_le32(hdev->clock); in clock_info_cmd_complete()
6268 hci_dev_put(hdev); in clock_info_cmd_complete()
6288 static void get_clock_info_complete(struct hci_dev *hdev, u8 status, u16 opcode) in get_clock_info_complete() argument
6294 bt_dev_dbg(hdev, "status %u", status); in get_clock_info_complete()
6296 hci_dev_lock(hdev); in get_clock_info_complete()
6298 hci_cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK); in get_clock_info_complete()
6304 conn = hci_conn_hash_lookup_handle(hdev, handle); in get_clock_info_complete()
6309 cmd = pending_find_data(MGMT_OP_GET_CLOCK_INFO, hdev, conn); in get_clock_info_complete()
6317 hci_dev_unlock(hdev); in get_clock_info_complete()
6320 static int get_clock_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_clock_info() argument
6331 bt_dev_dbg(hdev, "sock %p", sk); in get_clock_info()
6338 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
6342 hci_dev_lock(hdev); in get_clock_info()
6344 if (!hdev_is_powered(hdev)) { in get_clock_info()
6345 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
6352 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_clock_info()
6355 err = mgmt_cmd_complete(sk, hdev->id, in get_clock_info()
6365 cmd = mgmt_pending_add(sk, MGMT_OP_GET_CLOCK_INFO, hdev, data, len); in get_clock_info()
6373 hci_req_init(&req, hdev); in get_clock_info()
6392 hci_dev_unlock(hdev); in get_clock_info()
6396 static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type) in is_connected() argument
6400 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, addr); in is_connected()
6414 static int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, in hci_conn_params_set() argument
6419 params = hci_conn_params_add(hdev, addr, addr_type); in hci_conn_params_set()
6435 list_add(¶ms->action, &hdev->pend_le_conns); in hci_conn_params_set()
6439 list_add(¶ms->action, &hdev->pend_le_conns); in hci_conn_params_set()
6441 list_add(¶ms->action, &hdev->pend_le_reports); in hci_conn_params_set()
6445 if (!is_connected(hdev, addr, addr_type)) in hci_conn_params_set()
6446 list_add(¶ms->action, &hdev->pend_le_conns); in hci_conn_params_set()
6452 bt_dev_dbg(hdev, "addr %pMR (type %u) auto_connect %u", in hci_conn_params_set()
6458 static void device_added(struct sock *sk, struct hci_dev *hdev, in device_added() argument
6467 mgmt_event(MGMT_EV_DEVICE_ADDED, hdev, &ev, sizeof(ev), sk); in device_added()
6470 static int add_device(struct sock *sk, struct hci_dev *hdev, in add_device() argument
6479 bt_dev_dbg(hdev, "sock %p", sk); in add_device()
6483 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
6488 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
6492 hci_dev_lock(hdev); in add_device()
6497 err = mgmt_cmd_complete(sk, hdev->id, in add_device()
6504 err = hci_bdaddr_list_add_with_flags(&hdev->whitelist, in add_device()
6510 hci_req_update_scan(hdev); in add_device()
6530 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
6539 if (hci_conn_params_set(hdev, &cp->addr.bdaddr, addr_type, in add_device()
6541 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
6546 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in add_device()
6552 hci_update_background_scan(hdev); in add_device()
6555 device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action); in add_device()
6556 device_flags_changed(NULL, hdev, &cp->addr.bdaddr, cp->addr.type, in add_device()
6559 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
6564 hci_dev_unlock(hdev); in add_device()
6568 static void device_removed(struct sock *sk, struct hci_dev *hdev, in device_removed() argument
6576 mgmt_event(MGMT_EV_DEVICE_REMOVED, hdev, &ev, sizeof(ev), sk); in device_removed()
6579 static int remove_device(struct sock *sk, struct hci_dev *hdev, in remove_device() argument
6585 bt_dev_dbg(hdev, "sock %p", sk); in remove_device()
6587 hci_dev_lock(hdev); in remove_device()
6594 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6602 err = hci_bdaddr_list_del(&hdev->whitelist, in remove_device()
6606 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6614 hci_req_update_scan(hdev); in remove_device()
6616 device_removed(sk, hdev, &cp->addr.bdaddr, in remove_device()
6629 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6636 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in remove_device()
6639 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6648 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6658 hci_update_background_scan(hdev); in remove_device()
6660 device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type); in remove_device()
6666 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
6673 list_for_each_entry_safe(b, btmp, &hdev->whitelist, list) { in remove_device()
6674 device_removed(sk, hdev, &b->bdaddr, b->bdaddr_type); in remove_device()
6679 hci_req_update_scan(hdev); in remove_device()
6681 list_for_each_entry_safe(p, tmp, &hdev->le_conn_params, list) { in remove_device()
6684 device_removed(sk, hdev, &p->addr, p->addr_type); in remove_device()
6694 bt_dev_dbg(hdev, "All LE connection parameters were removed"); in remove_device()
6696 hci_update_background_scan(hdev); in remove_device()
6700 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, in remove_device()
6704 hci_dev_unlock(hdev); in remove_device()
6708 static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data, in load_conn_param() argument
6717 if (!lmp_le_capable(hdev)) in load_conn_param()
6718 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
6723 bt_dev_err(hdev, "load_conn_param: too big param_count value %u", in load_conn_param()
6725 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
6731 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes", in load_conn_param()
6733 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
6737 bt_dev_dbg(hdev, "param_count %u", param_count); in load_conn_param()
6739 hci_dev_lock(hdev); in load_conn_param()
6741 hci_conn_params_clear_disabled(hdev); in load_conn_param()
6749 bt_dev_dbg(hdev, "Adding %pMR (type %u)", ¶m->addr.bdaddr, in load_conn_param()
6757 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
6766 bt_dev_dbg(hdev, "min 0x%04x max 0x%04x latency 0x%04x timeout 0x%04x", in load_conn_param()
6770 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
6774 hci_param = hci_conn_params_add(hdev, ¶m->addr.bdaddr, in load_conn_param()
6777 bt_dev_err(hdev, "failed to add connection parameters"); in load_conn_param()
6787 hci_dev_unlock(hdev); in load_conn_param()
6789 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 0, in load_conn_param()
6793 static int set_external_config(struct sock *sk, struct hci_dev *hdev, in set_external_config() argument
6800 bt_dev_dbg(hdev, "sock %p", sk); in set_external_config()
6802 if (hdev_is_powered(hdev)) in set_external_config()
6803 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
6807 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
6810 if (!test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in set_external_config()
6811 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
6814 hci_dev_lock(hdev); in set_external_config()
6817 changed = !hci_dev_test_and_set_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
6819 changed = hci_dev_test_and_clear_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
6821 err = send_options_rsp(sk, MGMT_OP_SET_EXTERNAL_CONFIG, hdev); in set_external_config()
6828 err = new_options(hdev, sk); in set_external_config()
6830 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) == is_configured(hdev)) { in set_external_config()
6831 mgmt_index_removed(hdev); in set_external_config()
6833 if (hci_dev_test_and_change_flag(hdev, HCI_UNCONFIGURED)) { in set_external_config()
6834 hci_dev_set_flag(hdev, HCI_CONFIG); in set_external_config()
6835 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_external_config()
6837 queue_work(hdev->req_workqueue, &hdev->power_on); in set_external_config()
6839 set_bit(HCI_RAW, &hdev->flags); in set_external_config()
6840 mgmt_index_added(hdev); in set_external_config()
6845 hci_dev_unlock(hdev); in set_external_config()
6849 static int set_public_address(struct sock *sk, struct hci_dev *hdev, in set_public_address() argument
6856 bt_dev_dbg(hdev, "sock %p", sk); in set_public_address()
6858 if (hdev_is_powered(hdev)) in set_public_address()
6859 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
6863 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
6866 if (!hdev->set_bdaddr) in set_public_address()
6867 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
6870 hci_dev_lock(hdev); in set_public_address()
6872 changed = !!bacmp(&hdev->public_addr, &cp->bdaddr); in set_public_address()
6873 bacpy(&hdev->public_addr, &cp->bdaddr); in set_public_address()
6875 err = send_options_rsp(sk, MGMT_OP_SET_PUBLIC_ADDRESS, hdev); in set_public_address()
6882 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in set_public_address()
6883 err = new_options(hdev, sk); in set_public_address()
6885 if (is_configured(hdev)) { in set_public_address()
6886 mgmt_index_removed(hdev); in set_public_address()
6888 hci_dev_clear_flag(hdev, HCI_UNCONFIGURED); in set_public_address()
6890 hci_dev_set_flag(hdev, HCI_CONFIG); in set_public_address()
6891 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_public_address()
6893 queue_work(hdev->req_workqueue, &hdev->power_on); in set_public_address()
6897 hci_dev_unlock(hdev); in set_public_address()
6901 static void read_local_oob_ext_data_complete(struct hci_dev *hdev, u8 status, in read_local_oob_ext_data_complete() argument
6911 bt_dev_dbg(hdev, "status %u", status); in read_local_oob_ext_data_complete()
6913 cmd = pending_find(MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev); in read_local_oob_ext_data_complete()
6953 if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in read_local_oob_ext_data_complete()
6976 hdev->dev_class, 3); in read_local_oob_ext_data_complete()
6996 err = mgmt_cmd_complete(cmd->sk, hdev->id, in read_local_oob_ext_data_complete()
7004 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data_complete()
7012 static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk, in read_local_ssp_oob_req() argument
7019 cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev, in read_local_ssp_oob_req()
7024 hci_req_init(&req, hdev); in read_local_ssp_oob_req()
7026 if (bredr_sc_enabled(hdev)) in read_local_ssp_oob_req()
7040 static int read_local_oob_ext_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_ext_data() argument
7050 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_ext_data()
7052 if (hdev_is_powered(hdev)) { in read_local_oob_ext_data()
7055 status = mgmt_bredr_support(hdev); in read_local_oob_ext_data()
7062 status = mgmt_le_support(hdev); in read_local_oob_ext_data()
7086 hci_dev_lock(hdev); in read_local_oob_ext_data()
7091 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in read_local_oob_ext_data()
7092 err = read_local_ssp_oob_req(hdev, sk, cp); in read_local_oob_ext_data()
7093 hci_dev_unlock(hdev); in read_local_oob_ext_data()
7102 hdev->dev_class, 3); in read_local_oob_ext_data()
7106 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in read_local_oob_ext_data()
7107 smp_generate_oob(hdev, hash, rand) < 0) { in read_local_oob_ext_data()
7108 hci_dev_unlock(hdev); in read_local_oob_ext_data()
7123 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { in read_local_oob_ext_data()
7124 hci_dev_unlock(hdev); in read_local_oob_ext_data()
7129 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in read_local_oob_ext_data()
7130 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in read_local_oob_ext_data()
7131 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in read_local_oob_ext_data()
7132 bacmp(&hdev->static_addr, BDADDR_ANY))) { in read_local_oob_ext_data()
7133 memcpy(addr, &hdev->static_addr, 6); in read_local_oob_ext_data()
7136 memcpy(addr, &hdev->bdaddr, 6); in read_local_oob_ext_data()
7143 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in read_local_oob_ext_data()
7151 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) { in read_local_oob_ext_data()
7161 flags = mgmt_get_adv_discov_flags(hdev); in read_local_oob_ext_data()
7163 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in read_local_oob_ext_data()
7171 hci_dev_unlock(hdev); in read_local_oob_ext_data()
7181 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, in read_local_oob_ext_data()
7186 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data()
7196 static u32 get_supported_adv_flags(struct hci_dev *hdev) in get_supported_adv_flags() argument
7210 if ((hdev->adv_tx_power != HCI_TX_POWER_INVALID) || in get_supported_adv_flags()
7211 ext_adv_capable(hdev)) in get_supported_adv_flags()
7214 if (ext_adv_capable(hdev)) { in get_supported_adv_flags()
7219 if (hdev->le_features[1] & HCI_LE_PHY_2M) in get_supported_adv_flags()
7222 if (hdev->le_features[1] & HCI_LE_PHY_CODED) in get_supported_adv_flags()
7229 static int read_adv_features(struct sock *sk, struct hci_dev *hdev, in read_adv_features() argument
7239 bt_dev_dbg(hdev, "sock %p", sk); in read_adv_features()
7241 if (!lmp_le_capable(hdev)) in read_adv_features()
7242 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
7248 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in read_adv_features()
7249 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in read_adv_features()
7252 hci_dev_lock(hdev); in read_adv_features()
7254 rp_len = sizeof(*rp) + hdev->adv_instance_cnt; in read_adv_features()
7257 hci_dev_unlock(hdev); in read_adv_features()
7261 supported_flags = get_supported_adv_flags(hdev); in read_adv_features()
7266 rp->max_instances = hdev->le_num_of_adv_sets; in read_adv_features()
7267 rp->num_instances = hdev->adv_instance_cnt; in read_adv_features()
7270 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in read_adv_features()
7275 hci_dev_unlock(hdev); in read_adv_features()
7277 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
7285 static u8 calculate_name_len(struct hci_dev *hdev) in calculate_name_len() argument
7289 return append_local_name(hdev, buf, 0); in calculate_name_len()
7292 static u8 tlv_data_max_len(struct hci_dev *hdev, u32 adv_flags, in tlv_data_max_len() argument
7307 max_len -= calculate_name_len(hdev); in tlv_data_max_len()
7338 static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data, in tlv_data_is_valid() argument
7344 max_len = tlv_data_max_len(hdev, adv_flags, is_adv_data); in tlv_data_is_valid()
7380 static void add_advertising_complete(struct hci_dev *hdev, u8 status, in add_advertising_complete() argument
7389 bt_dev_dbg(hdev, "status %d", status); in add_advertising_complete()
7391 hci_dev_lock(hdev); in add_advertising_complete()
7393 cmd = pending_find(MGMT_OP_ADD_ADVERTISING, hdev); in add_advertising_complete()
7395 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) { in add_advertising_complete()
7406 if (hdev->cur_adv_instance == instance) in add_advertising_complete()
7407 cancel_adv_timeout(hdev); in add_advertising_complete()
7409 hci_remove_adv_instance(hdev, instance); in add_advertising_complete()
7410 mgmt_advertising_removed(cmd ? cmd->sk : NULL, hdev, instance); in add_advertising_complete()
7429 hci_dev_unlock(hdev); in add_advertising_complete()
7432 static int add_advertising(struct sock *sk, struct hci_dev *hdev, in add_advertising() argument
7441 unsigned int prev_instance_cnt = hdev->adv_instance_cnt; in add_advertising()
7448 bt_dev_dbg(hdev, "sock %p", sk); in add_advertising()
7450 status = mgmt_le_support(hdev); in add_advertising()
7452 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7458 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in add_advertising()
7459 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in add_advertising()
7462 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_advertising()
7463 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7467 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7477 supported_flags = get_supported_adv_flags(hdev); in add_advertising()
7481 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7484 hci_dev_lock(hdev); in add_advertising()
7486 if (timeout && !hdev_is_powered(hdev)) { in add_advertising()
7487 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7492 if (pending_find(MGMT_OP_ADD_ADVERTISING, hdev) || in add_advertising()
7493 pending_find(MGMT_OP_REMOVE_ADVERTISING, hdev) || in add_advertising()
7494 pending_find(MGMT_OP_SET_LE, hdev)) { in add_advertising()
7495 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7500 if (!tlv_data_is_valid(hdev, flags, cp->data, cp->adv_data_len, true) || in add_advertising()
7501 !tlv_data_is_valid(hdev, flags, cp->data + cp->adv_data_len, in add_advertising()
7503 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7508 err = hci_add_adv_instance(hdev, cp->instance, flags, in add_advertising()
7514 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7522 if (hdev->adv_instance_cnt > prev_instance_cnt) in add_advertising()
7523 mgmt_advertising_added(sk, hdev, cp->instance); in add_advertising()
7525 if (hdev->cur_adv_instance == cp->instance) { in add_advertising()
7531 cancel_adv_timeout(hdev); in add_advertising()
7533 next_instance = hci_get_next_instance(hdev, cp->instance); in add_advertising()
7536 } else if (!hdev->adv_instance_timeout) { in add_advertising()
7547 if (!hdev_is_powered(hdev) || in add_advertising()
7548 hci_dev_test_flag(hdev, HCI_ADVERTISING) || in add_advertising()
7551 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7559 cmd = mgmt_pending_add(sk, MGMT_OP_ADD_ADVERTISING, hdev, data, in add_advertising()
7566 hci_req_init(&req, hdev); in add_advertising()
7574 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
7580 hci_dev_unlock(hdev); in add_advertising()
7585 static void remove_advertising_complete(struct hci_dev *hdev, u8 status, in remove_advertising_complete() argument
7592 bt_dev_dbg(hdev, "status %d", status); in remove_advertising_complete()
7594 hci_dev_lock(hdev); in remove_advertising_complete()
7600 cmd = pending_find(MGMT_OP_REMOVE_ADVERTISING, hdev); in remove_advertising_complete()
7612 hci_dev_unlock(hdev); in remove_advertising_complete()
7615 static int remove_advertising(struct sock *sk, struct hci_dev *hdev, in remove_advertising() argument
7624 bt_dev_dbg(hdev, "sock %p", sk); in remove_advertising()
7629 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in remove_advertising()
7630 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in remove_advertising()
7633 hci_dev_lock(hdev); in remove_advertising()
7635 if (cp->instance && !hci_find_adv_instance(hdev, cp->instance)) { in remove_advertising()
7636 err = mgmt_cmd_status(sk, hdev->id, in remove_advertising()
7642 if (pending_find(MGMT_OP_ADD_ADVERTISING, hdev) || in remove_advertising()
7643 pending_find(MGMT_OP_REMOVE_ADVERTISING, hdev) || in remove_advertising()
7644 pending_find(MGMT_OP_SET_LE, hdev)) { in remove_advertising()
7645 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
7650 if (list_empty(&hdev->adv_instances)) { in remove_advertising()
7651 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
7656 hci_req_init(&req, hdev); in remove_advertising()
7659 if (ext_adv_capable(hdev)) { in remove_advertising()
7664 hci_req_clear_adv_instance(hdev, sk, &req, cp->instance, true); in remove_advertising()
7666 if (list_empty(&hdev->adv_instances)) in remove_advertising()
7674 !hdev_is_powered(hdev) || in remove_advertising()
7675 hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in remove_advertising()
7678 err = mgmt_cmd_complete(sk, hdev->id, in remove_advertising()
7684 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_ADVERTISING, hdev, data, in remove_advertising()
7696 hci_dev_unlock(hdev); in remove_advertising()
7701 static int get_adv_size_info(struct sock *sk, struct hci_dev *hdev, in get_adv_size_info() argument
7709 bt_dev_dbg(hdev, "sock %p", sk); in get_adv_size_info()
7711 if (!lmp_le_capable(hdev)) in get_adv_size_info()
7712 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
7715 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in get_adv_size_info()
7716 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
7724 supported_flags = get_supported_adv_flags(hdev); in get_adv_size_info()
7726 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
7731 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in get_adv_size_info()
7732 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in get_adv_size_info()
7734 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
7861 void mgmt_index_added(struct hci_dev *hdev) in mgmt_index_added() argument
7865 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_added()
7868 switch (hdev->dev_type) { in mgmt_index_added()
7870 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_added()
7871 mgmt_index_event(MGMT_EV_UNCONF_INDEX_ADDED, hdev, in mgmt_index_added()
7875 mgmt_index_event(MGMT_EV_INDEX_ADDED, hdev, NULL, 0, in mgmt_index_added()
7887 ev.bus = hdev->bus; in mgmt_index_added()
7889 mgmt_index_event(MGMT_EV_EXT_INDEX_ADDED, hdev, &ev, sizeof(ev), in mgmt_index_added()
7893 void mgmt_index_removed(struct hci_dev *hdev) in mgmt_index_removed() argument
7898 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_removed()
7901 switch (hdev->dev_type) { in mgmt_index_removed()
7903 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status); in mgmt_index_removed()
7905 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_removed()
7906 mgmt_index_event(MGMT_EV_UNCONF_INDEX_REMOVED, hdev, in mgmt_index_removed()
7910 mgmt_index_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, in mgmt_index_removed()
7922 ev.bus = hdev->bus; in mgmt_index_removed()
7924 mgmt_index_event(MGMT_EV_EXT_INDEX_REMOVED, hdev, &ev, sizeof(ev), in mgmt_index_removed()
7929 static void restart_le_actions(struct hci_dev *hdev) in restart_le_actions() argument
7933 list_for_each_entry(p, &hdev->le_conn_params, list) { in restart_le_actions()
7942 list_add(&p->action, &hdev->pend_le_conns); in restart_le_actions()
7945 list_add(&p->action, &hdev->pend_le_reports); in restart_le_actions()
7953 void mgmt_power_on(struct hci_dev *hdev, int err) in mgmt_power_on() argument
7955 struct cmd_lookup match = { NULL, hdev }; in mgmt_power_on()
7957 bt_dev_dbg(hdev, "err %d", err); in mgmt_power_on()
7959 hci_dev_lock(hdev); in mgmt_power_on()
7962 restart_le_actions(hdev); in mgmt_power_on()
7963 hci_update_background_scan(hdev); in mgmt_power_on()
7966 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in mgmt_power_on()
7968 new_settings(hdev, match.sk); in mgmt_power_on()
7973 hci_dev_unlock(hdev); in mgmt_power_on()
7976 void __mgmt_power_off(struct hci_dev *hdev) in __mgmt_power_off() argument
7978 struct cmd_lookup match = { NULL, hdev }; in __mgmt_power_off()
7981 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in __mgmt_power_off()
7990 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) in __mgmt_power_off()
7995 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status); in __mgmt_power_off()
7997 if (memcmp(hdev->dev_class, zero_cod, sizeof(zero_cod)) != 0) { in __mgmt_power_off()
7998 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, in __mgmt_power_off()
8001 ext_info_changed(hdev, NULL); in __mgmt_power_off()
8004 new_settings(hdev, match.sk); in __mgmt_power_off()
8010 void mgmt_set_powered_failed(struct hci_dev *hdev, int err) in mgmt_set_powered_failed() argument
8015 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_set_powered_failed()
8024 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, status); in mgmt_set_powered_failed()
8029 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, in mgmt_new_link_key() argument
8043 mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_link_key()
8065 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent) in mgmt_new_ltk() argument
8105 mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_ltk()
8108 void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent) in mgmt_new_irk() argument
8121 mgmt_event(MGMT_EV_NEW_IRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_irk()
8124 void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, in mgmt_new_csrk() argument
8151 mgmt_event(MGMT_EV_NEW_CSRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_csrk()
8154 void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_new_conn_param() argument
8172 mgmt_event(MGMT_EV_NEW_CONN_PARAM, hdev, &ev, sizeof(ev), NULL); in mgmt_new_conn_param()
8175 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, in mgmt_device_connected() argument
8208 mgmt_event(MGMT_EV_DEVICE_CONNECTED, hdev, buf, in mgmt_device_connected()
8226 struct hci_dev *hdev = data; in unpair_device_rsp() local
8229 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_rsp()
8235 bool mgmt_powering_down(struct hci_dev *hdev) in mgmt_powering_down() argument
8240 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_powering_down()
8251 void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_device_disconnected() argument
8261 if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { in mgmt_device_disconnected()
8262 cancel_delayed_work(&hdev->power_off); in mgmt_device_disconnected()
8263 queue_work(hdev->req_workqueue, &hdev->power_off.work); in mgmt_device_disconnected()
8272 mgmt_pending_foreach(MGMT_OP_DISCONNECT, hdev, disconnect_rsp, &sk); in mgmt_device_disconnected()
8279 if (hdev->suspended) in mgmt_device_disconnected()
8282 mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev), sk); in mgmt_device_disconnected()
8287 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_device_disconnected()
8288 hdev); in mgmt_device_disconnected()
8291 void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_disconnect_failed() argument
8298 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_disconnect_failed()
8299 hdev); in mgmt_disconnect_failed()
8301 cmd = pending_find(MGMT_OP_DISCONNECT, hdev); in mgmt_disconnect_failed()
8317 void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_connect_failed() argument
8325 if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { in mgmt_connect_failed()
8326 cancel_delayed_work(&hdev->power_off); in mgmt_connect_failed()
8327 queue_work(hdev->req_workqueue, &hdev->power_off.work); in mgmt_connect_failed()
8334 mgmt_event(MGMT_EV_CONNECT_FAILED, hdev, &ev, sizeof(ev), NULL); in mgmt_connect_failed()
8337 void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure) in mgmt_pin_code_request() argument
8345 mgmt_event(MGMT_EV_PIN_CODE_REQUEST, hdev, &ev, sizeof(ev), NULL); in mgmt_pin_code_request()
8348 void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_reply_complete() argument
8353 cmd = pending_find(MGMT_OP_PIN_CODE_REPLY, hdev); in mgmt_pin_code_reply_complete()
8361 void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_neg_reply_complete() argument
8366 cmd = pending_find(MGMT_OP_PIN_CODE_NEG_REPLY, hdev); in mgmt_pin_code_neg_reply_complete()
8374 int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_request() argument
8380 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_confirm_request()
8387 return mgmt_event(MGMT_EV_USER_CONFIRM_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_confirm_request()
8391 int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_request() argument
8396 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_request()
8401 return mgmt_event(MGMT_EV_USER_PASSKEY_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_passkey_request()
8405 static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in user_pairing_resp_complete() argument
8411 cmd = pending_find(opcode, hdev); in user_pairing_resp_complete()
8421 int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_reply_complete() argument
8424 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_reply_complete()
8428 int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_neg_reply_complete() argument
8431 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_neg_reply_complete()
8436 int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_reply_complete() argument
8439 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_reply_complete()
8443 int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_neg_reply_complete() argument
8446 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_neg_reply_complete()
8451 int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_notify() argument
8457 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_notify()
8464 return mgmt_event(MGMT_EV_PASSKEY_NOTIFY, hdev, &ev, sizeof(ev), NULL); in mgmt_user_passkey_notify()
8479 mgmt_event(MGMT_EV_AUTH_FAILED, conn->hdev, &ev, sizeof(ev), in mgmt_auth_failed()
8488 void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status) in mgmt_auth_enable_complete() argument
8490 struct cmd_lookup match = { NULL, hdev }; in mgmt_auth_enable_complete()
8495 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, in mgmt_auth_enable_complete()
8500 if (test_bit(HCI_AUTH, &hdev->flags)) in mgmt_auth_enable_complete()
8501 changed = !hci_dev_test_and_set_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
8503 changed = hci_dev_test_and_clear_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
8505 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, settings_rsp, in mgmt_auth_enable_complete()
8509 new_settings(hdev, match.sk); in mgmt_auth_enable_complete()
8517 struct hci_dev *hdev = req->hdev; in clear_eir() local
8520 if (!lmp_ext_inq_capable(hdev)) in clear_eir()
8523 memset(hdev->eir, 0, sizeof(hdev->eir)); in clear_eir()
8530 void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status) in mgmt_ssp_enable_complete() argument
8532 struct cmd_lookup match = { NULL, hdev }; in mgmt_ssp_enable_complete()
8539 if (enable && hci_dev_test_and_clear_flag(hdev, in mgmt_ssp_enable_complete()
8541 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in mgmt_ssp_enable_complete()
8542 new_settings(hdev, NULL); in mgmt_ssp_enable_complete()
8545 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, cmd_status_rsp, in mgmt_ssp_enable_complete()
8551 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in mgmt_ssp_enable_complete()
8553 changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED); in mgmt_ssp_enable_complete()
8555 changed = hci_dev_test_and_clear_flag(hdev, in mgmt_ssp_enable_complete()
8558 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in mgmt_ssp_enable_complete()
8561 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, settings_rsp, &match); in mgmt_ssp_enable_complete()
8564 new_settings(hdev, match.sk); in mgmt_ssp_enable_complete()
8569 hci_req_init(&req, hdev); in mgmt_ssp_enable_complete()
8571 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in mgmt_ssp_enable_complete()
8572 if (hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) in mgmt_ssp_enable_complete()
8593 void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, in mgmt_set_class_of_dev_complete() argument
8596 struct cmd_lookup match = { NULL, hdev, mgmt_status(status) }; in mgmt_set_class_of_dev_complete()
8598 mgmt_pending_foreach(MGMT_OP_SET_DEV_CLASS, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
8599 mgmt_pending_foreach(MGMT_OP_ADD_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
8600 mgmt_pending_foreach(MGMT_OP_REMOVE_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
8603 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, dev_class, in mgmt_set_class_of_dev_complete()
8605 ext_info_changed(hdev, NULL); in mgmt_set_class_of_dev_complete()
8612 void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status) in mgmt_set_local_name_complete() argument
8622 memcpy(ev.short_name, hdev->short_name, HCI_MAX_SHORT_NAME_LENGTH); in mgmt_set_local_name_complete()
8624 cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev); in mgmt_set_local_name_complete()
8626 memcpy(hdev->dev_name, name, sizeof(hdev->dev_name)); in mgmt_set_local_name_complete()
8631 if (pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_local_name_complete()
8635 mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev, sizeof(ev), in mgmt_set_local_name_complete()
8637 ext_info_changed(hdev, cmd ? cmd->sk : NULL); in mgmt_set_local_name_complete()
8707 static void restart_le_scan(struct hci_dev *hdev) in restart_le_scan() argument
8710 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in restart_le_scan()
8714 hdev->discovery.scan_start + in restart_le_scan()
8715 hdev->discovery.scan_duration)) in restart_le_scan()
8718 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_restart, in restart_le_scan()
8722 static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir, in is_filter_match() argument
8734 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
8736 (rssi < hdev->discovery.rssi && in is_filter_match()
8737 !test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)))) in is_filter_match()
8740 if (hdev->discovery.uuid_count != 0) { in is_filter_match()
8744 if (!eir_has_uuids(eir, eir_len, hdev->discovery.uuid_count, in is_filter_match()
8745 hdev->discovery.uuids) && in is_filter_match()
8747 hdev->discovery.uuid_count, in is_filter_match()
8748 hdev->discovery.uuids)) in is_filter_match()
8755 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)) { in is_filter_match()
8756 restart_le_scan(hdev); in is_filter_match()
8759 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
8760 rssi < hdev->discovery.rssi) in is_filter_match()
8767 void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_device_found() argument
8779 if (!hci_discovery_active(hdev)) { in mgmt_device_found()
8783 list_empty(&hdev->pend_le_reports) && in mgmt_device_found()
8784 !hci_is_adv_monitoring(hdev)) { in mgmt_device_found()
8789 if (hdev->discovery.result_filtering) { in mgmt_device_found()
8791 if (!is_filter_match(hdev, rssi, eir, eir_len, scan_rsp, in mgmt_device_found()
8796 if (hdev->discovery.limited) { in mgmt_device_found()
8824 if (rssi == HCI_RSSI_INVALID && !hdev->discovery.report_invalid_rssi && in mgmt_device_found()
8849 mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, ev_size, NULL); in mgmt_device_found()
8852 void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_remote_name() argument
8872 mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, sizeof(*ev) + eir_len, NULL); in mgmt_remote_name()
8875 void mgmt_discovering(struct hci_dev *hdev, u8 discovering) in mgmt_discovering() argument
8879 bt_dev_dbg(hdev, "discovering %u", discovering); in mgmt_discovering()
8882 ev.type = hdev->discovery.type; in mgmt_discovering()
8885 mgmt_event(MGMT_EV_DISCOVERING, hdev, &ev, sizeof(ev), NULL); in mgmt_discovering()
8888 void mgmt_suspending(struct hci_dev *hdev, u8 state) in mgmt_suspending() argument
8893 mgmt_event(MGMT_EV_CONTROLLER_SUSPEND, hdev, &ev, sizeof(ev), NULL); in mgmt_suspending()
8896 void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr, in mgmt_resuming() argument
8909 mgmt_event(MGMT_EV_CONTROLLER_RESUME, hdev, &ev, sizeof(ev), NULL); in mgmt_resuming()