Lines Matching refs:hdev
323 static int mgmt_index_event(u16 event, struct hci_dev *hdev, void *data, in mgmt_index_event() argument
326 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_index_event()
330 static int mgmt_limited_event(u16 event, struct hci_dev *hdev, void *data, in mgmt_limited_event() argument
333 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_limited_event()
337 static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, u16 len, in mgmt_event() argument
340 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_event()
366 static int read_version(struct sock *sk, struct hci_dev *hdev, void *data, in read_version() argument
371 bt_dev_dbg(hdev, "sock %p", sk); in read_version()
379 static int read_commands(struct sock *sk, struct hci_dev *hdev, void *data, in read_commands() argument
387 bt_dev_dbg(hdev, "sock %p", sk); in read_commands()
431 static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data, in read_index_list() argument
440 bt_dev_dbg(hdev, "sock %p", sk); in read_index_list()
474 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_index_list()
491 static int read_unconf_index_list(struct sock *sk, struct hci_dev *hdev, in read_unconf_index_list() argument
500 bt_dev_dbg(hdev, "sock %p", sk); in read_unconf_index_list()
534 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_unconf_index_list()
551 static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev, in read_ext_index_list() argument
559 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_index_list()
601 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_ext_index_list()
625 static bool is_configured(struct hci_dev *hdev) in is_configured() argument
627 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in is_configured()
628 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in is_configured()
631 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in is_configured()
632 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in is_configured()
633 !bacmp(&hdev->public_addr, BDADDR_ANY)) in is_configured()
639 static __le32 get_missing_options(struct hci_dev *hdev) in get_missing_options() argument
643 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in get_missing_options()
644 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in get_missing_options()
647 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in get_missing_options()
648 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in get_missing_options()
649 !bacmp(&hdev->public_addr, BDADDR_ANY)) in get_missing_options()
655 static int new_options(struct hci_dev *hdev, struct sock *skip) in new_options() argument
657 __le32 options = get_missing_options(hdev); in new_options()
659 return mgmt_limited_event(MGMT_EV_NEW_CONFIG_OPTIONS, hdev, &options, in new_options()
663 static int send_options_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_options_rsp() argument
665 __le32 options = get_missing_options(hdev); in send_options_rsp()
667 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &options, in send_options_rsp()
671 static int read_config_info(struct sock *sk, struct hci_dev *hdev, in read_config_info() argument
677 bt_dev_dbg(hdev, "sock %p", sk); in read_config_info()
679 hci_dev_lock(hdev); in read_config_info()
682 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_config_info()
684 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in read_config_info()
687 if (hdev->set_bdaddr) in read_config_info()
691 rp.missing_options = get_missing_options(hdev); in read_config_info()
693 hci_dev_unlock(hdev); in read_config_info()
695 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONFIG_INFO, 0, in read_config_info()
699 static u32 get_supported_phys(struct hci_dev *hdev) in get_supported_phys() argument
703 if (lmp_bredr_capable(hdev)) { in get_supported_phys()
706 if (hdev->features[0][0] & LMP_3SLOT) in get_supported_phys()
709 if (hdev->features[0][0] & LMP_5SLOT) in get_supported_phys()
712 if (lmp_edr_2m_capable(hdev)) { in get_supported_phys()
715 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
718 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
721 if (lmp_edr_3m_capable(hdev)) { in get_supported_phys()
724 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
727 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
733 if (lmp_le_capable(hdev)) { in get_supported_phys()
737 if (hdev->le_features[1] & HCI_LE_PHY_2M) { in get_supported_phys()
742 if (hdev->le_features[1] & HCI_LE_PHY_CODED) { in get_supported_phys()
751 static u32 get_selected_phys(struct hci_dev *hdev) in get_selected_phys() argument
755 if (lmp_bredr_capable(hdev)) { in get_selected_phys()
758 if (hdev->pkt_type & (HCI_DM3 | HCI_DH3)) in get_selected_phys()
761 if (hdev->pkt_type & (HCI_DM5 | HCI_DH5)) in get_selected_phys()
764 if (lmp_edr_2m_capable(hdev)) { in get_selected_phys()
765 if (!(hdev->pkt_type & HCI_2DH1)) in get_selected_phys()
768 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
769 !(hdev->pkt_type & HCI_2DH3)) in get_selected_phys()
772 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
773 !(hdev->pkt_type & HCI_2DH5)) in get_selected_phys()
776 if (lmp_edr_3m_capable(hdev)) { in get_selected_phys()
777 if (!(hdev->pkt_type & HCI_3DH1)) in get_selected_phys()
780 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
781 !(hdev->pkt_type & HCI_3DH3)) in get_selected_phys()
784 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
785 !(hdev->pkt_type & HCI_3DH5)) in get_selected_phys()
791 if (lmp_le_capable(hdev)) { in get_selected_phys()
792 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
795 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
798 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
801 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
804 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
807 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
814 static u32 get_configurable_phys(struct hci_dev *hdev) in get_configurable_phys() argument
816 return (get_supported_phys(hdev) & ~MGMT_PHY_BR_1M_1SLOT & in get_configurable_phys()
820 static u32 get_supported_settings(struct hci_dev *hdev) in get_supported_settings() argument
830 if (lmp_bredr_capable(hdev)) { in get_supported_settings()
831 if (hdev->hci_ver >= BLUETOOTH_VER_1_2) in get_supported_settings()
836 if (lmp_ssp_capable(hdev)) { in get_supported_settings()
842 if (lmp_sc_capable(hdev)) in get_supported_settings()
846 &hdev->quirks)) in get_supported_settings()
850 if (lmp_le_capable(hdev)) { in get_supported_settings()
858 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in get_supported_settings()
859 hdev->set_bdaddr) in get_supported_settings()
867 static u32 get_current_settings(struct hci_dev *hdev) in get_current_settings() argument
871 if (hdev_is_powered(hdev)) in get_current_settings()
874 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in get_current_settings()
877 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in get_current_settings()
880 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in get_current_settings()
883 if (hci_dev_test_flag(hdev, HCI_BONDABLE)) in get_current_settings()
886 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in get_current_settings()
889 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in get_current_settings()
892 if (hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) in get_current_settings()
895 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in get_current_settings()
898 if (hci_dev_test_flag(hdev, HCI_HS_ENABLED)) in get_current_settings()
901 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in get_current_settings()
904 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) in get_current_settings()
907 if (hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) in get_current_settings()
910 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in get_current_settings()
925 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in get_current_settings()
926 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in get_current_settings()
927 !bacmp(&hdev->bdaddr, BDADDR_ANY)) { in get_current_settings()
928 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in get_current_settings()
932 if (hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED)) in get_current_settings()
938 static struct mgmt_pending_cmd *pending_find(u16 opcode, struct hci_dev *hdev) in pending_find() argument
940 return mgmt_pending_find(HCI_CHANNEL_CONTROL, opcode, hdev); in pending_find()
943 u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev) in mgmt_get_adv_discov_flags() argument
950 cmd = pending_find(MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_get_adv_discov_flags()
958 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
960 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
967 bool mgmt_get_connectable(struct hci_dev *hdev) in mgmt_get_connectable() argument
974 cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_get_connectable()
981 return hci_dev_test_flag(hdev, HCI_CONNECTABLE); in mgmt_get_connectable()
984 static int service_cache_sync(struct hci_dev *hdev, void *data) in service_cache_sync() argument
986 hci_update_eir_sync(hdev); in service_cache_sync()
987 hci_update_class_sync(hdev); in service_cache_sync()
994 struct hci_dev *hdev = container_of(work, struct hci_dev, in service_cache_off() local
997 if (!hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in service_cache_off()
1000 hci_cmd_sync_queue(hdev, service_cache_sync, NULL, NULL); in service_cache_off()
1003 static int rpa_expired_sync(struct hci_dev *hdev, void *data) in rpa_expired_sync() argument
1009 if (ext_adv_capable(hdev)) in rpa_expired_sync()
1010 return hci_start_ext_adv_sync(hdev, hdev->cur_adv_instance); in rpa_expired_sync()
1012 return hci_enable_advertising_sync(hdev); in rpa_expired_sync()
1017 struct hci_dev *hdev = container_of(work, struct hci_dev, in rpa_expired() local
1020 bt_dev_dbg(hdev, ""); in rpa_expired()
1022 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in rpa_expired()
1024 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING)) in rpa_expired()
1027 hci_cmd_sync_queue(hdev, rpa_expired_sync, NULL, NULL); in rpa_expired()
1032 struct hci_dev *hdev = container_of(work, struct hci_dev, in discov_off() local
1035 bt_dev_dbg(hdev, ""); in discov_off()
1037 hci_dev_lock(hdev); in discov_off()
1044 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in discov_off()
1045 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in discov_off()
1046 hdev->discov_timeout = 0; in discov_off()
1048 hci_update_discoverable(hdev); in discov_off()
1050 mgmt_new_settings(hdev); in discov_off()
1052 hci_dev_unlock(hdev); in discov_off()
1055 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev);
1057 static void mesh_send_complete(struct hci_dev *hdev, in mesh_send_complete() argument
1063 mgmt_event(MGMT_EV_MESH_PACKET_CMPLT, hdev, &handle, in mesh_send_complete()
1069 static int mesh_send_done_sync(struct hci_dev *hdev, void *data) in mesh_send_done_sync() argument
1073 hci_dev_clear_flag(hdev, HCI_MESH_SENDING); in mesh_send_done_sync()
1074 hci_disable_advertising_sync(hdev); in mesh_send_done_sync()
1075 mesh_tx = mgmt_mesh_next(hdev, NULL); in mesh_send_done_sync()
1078 mesh_send_complete(hdev, mesh_tx, false); in mesh_send_done_sync()
1083 static int mesh_send_sync(struct hci_dev *hdev, void *data);
1084 static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err);
1085 static void mesh_next(struct hci_dev *hdev, void *data, int err) in mesh_next() argument
1087 struct mgmt_mesh_tx *mesh_tx = mgmt_mesh_next(hdev, NULL); in mesh_next()
1092 err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx, in mesh_next()
1096 mesh_send_complete(hdev, mesh_tx, false); in mesh_next()
1098 hci_dev_set_flag(hdev, HCI_MESH_SENDING); in mesh_next()
1103 struct hci_dev *hdev = container_of(work, struct hci_dev, in mesh_send_done() local
1106 if (!hci_dev_test_flag(hdev, HCI_MESH_SENDING)) in mesh_send_done()
1109 hci_cmd_sync_queue(hdev, mesh_send_done_sync, NULL, mesh_next); in mesh_send_done()
1112 static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev) in mgmt_init_hdev() argument
1114 if (hci_dev_test_flag(hdev, HCI_MGMT)) in mgmt_init_hdev()
1119 INIT_DELAYED_WORK(&hdev->discov_off, discov_off); in mgmt_init_hdev()
1120 INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off); in mgmt_init_hdev()
1121 INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired); in mgmt_init_hdev()
1122 INIT_DELAYED_WORK(&hdev->mesh_send_done, mesh_send_done); in mgmt_init_hdev()
1129 hci_dev_clear_flag(hdev, HCI_BONDABLE); in mgmt_init_hdev()
1131 hci_dev_set_flag(hdev, HCI_MGMT); in mgmt_init_hdev()
1134 static int read_controller_info(struct sock *sk, struct hci_dev *hdev, in read_controller_info() argument
1139 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_info()
1141 hci_dev_lock(hdev); in read_controller_info()
1145 bacpy(&rp.bdaddr, &hdev->bdaddr); in read_controller_info()
1147 rp.version = hdev->hci_ver; in read_controller_info()
1148 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_controller_info()
1150 rp.supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_controller_info()
1151 rp.current_settings = cpu_to_le32(get_current_settings(hdev)); in read_controller_info()
1153 memcpy(rp.dev_class, hdev->dev_class, 3); in read_controller_info()
1155 memcpy(rp.name, hdev->dev_name, sizeof(hdev->dev_name)); in read_controller_info()
1156 memcpy(rp.short_name, hdev->short_name, sizeof(hdev->short_name)); in read_controller_info()
1158 hci_dev_unlock(hdev); in read_controller_info()
1160 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_INFO, 0, &rp, in read_controller_info()
1164 static u16 append_eir_data_to_buf(struct hci_dev *hdev, u8 *eir) in append_eir_data_to_buf() argument
1169 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in append_eir_data_to_buf()
1171 hdev->dev_class, 3); in append_eir_data_to_buf()
1173 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in append_eir_data_to_buf()
1175 hdev->appearance); in append_eir_data_to_buf()
1177 name_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name)); in append_eir_data_to_buf()
1179 hdev->dev_name, name_len); in append_eir_data_to_buf()
1181 name_len = strnlen(hdev->short_name, sizeof(hdev->short_name)); in append_eir_data_to_buf()
1183 hdev->short_name, name_len); in append_eir_data_to_buf()
1188 static int read_ext_controller_info(struct sock *sk, struct hci_dev *hdev, in read_ext_controller_info() argument
1195 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_controller_info()
1199 hci_dev_lock(hdev); in read_ext_controller_info()
1201 bacpy(&rp->bdaddr, &hdev->bdaddr); in read_ext_controller_info()
1203 rp->version = hdev->hci_ver; in read_ext_controller_info()
1204 rp->manufacturer = cpu_to_le16(hdev->manufacturer); in read_ext_controller_info()
1206 rp->supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_ext_controller_info()
1207 rp->current_settings = cpu_to_le32(get_current_settings(hdev)); in read_ext_controller_info()
1210 eir_len = append_eir_data_to_buf(hdev, rp->eir); in read_ext_controller_info()
1213 hci_dev_unlock(hdev); in read_ext_controller_info()
1224 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_EXT_INFO, 0, rp, in read_ext_controller_info()
1228 static int ext_info_changed(struct hci_dev *hdev, struct sock *skip) in ext_info_changed() argument
1236 eir_len = append_eir_data_to_buf(hdev, ev->eir); in ext_info_changed()
1239 return mgmt_limited_event(MGMT_EV_EXT_INFO_CHANGED, hdev, ev, in ext_info_changed()
1244 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_settings_rsp() argument
1246 __le32 settings = cpu_to_le32(get_current_settings(hdev)); in send_settings_rsp()
1248 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &settings, in send_settings_rsp()
1252 void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev, u8 instance) in mgmt_advertising_added() argument
1258 mgmt_event(MGMT_EV_ADVERTISING_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_added()
1261 void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev, in mgmt_advertising_removed() argument
1268 mgmt_event(MGMT_EV_ADVERTISING_REMOVED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_removed()
1271 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
1273 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
1274 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
1275 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
1280 static void restart_le_actions(struct hci_dev *hdev) in restart_le_actions() argument
1284 list_for_each_entry(p, &hdev->le_conn_params, list) { in restart_le_actions()
1293 list_add(&p->action, &hdev->pend_le_conns); in restart_le_actions()
1296 list_add(&p->action, &hdev->pend_le_reports); in restart_le_actions()
1304 static int new_settings(struct hci_dev *hdev, struct sock *skip) in new_settings() argument
1306 __le32 ev = cpu_to_le32(get_current_settings(hdev)); in new_settings()
1308 return mgmt_limited_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, in new_settings()
1312 static void mgmt_set_powered_complete(struct hci_dev *hdev, void *data, int err) in mgmt_set_powered_complete() argument
1318 if (cmd != pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_powered_complete()
1323 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_powered_complete()
1327 hci_dev_lock(hdev); in mgmt_set_powered_complete()
1328 restart_le_actions(hdev); in mgmt_set_powered_complete()
1329 hci_update_passive_scan(hdev); in mgmt_set_powered_complete()
1330 hci_dev_unlock(hdev); in mgmt_set_powered_complete()
1333 send_settings_rsp(cmd->sk, cmd->opcode, hdev); in mgmt_set_powered_complete()
1339 new_settings(hdev, cmd->sk); in mgmt_set_powered_complete()
1341 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, in mgmt_set_powered_complete()
1348 static int set_powered_sync(struct hci_dev *hdev, void *data) in set_powered_sync() argument
1353 BT_DBG("%s", hdev->name); in set_powered_sync()
1355 return hci_set_powered_sync(hdev, cp->val); in set_powered_sync()
1358 static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, in set_powered() argument
1365 bt_dev_dbg(hdev, "sock %p", sk); in set_powered()
1368 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1371 hci_dev_lock(hdev); in set_powered()
1373 if (pending_find(MGMT_OP_SET_POWERED, hdev)) { in set_powered()
1374 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1379 if (!!cp->val == hdev_is_powered(hdev)) { in set_powered()
1380 err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev); in set_powered()
1384 cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, hdev, data, len); in set_powered()
1390 err = hci_cmd_sync_queue(hdev, set_powered_sync, cmd, in set_powered()
1397 hci_dev_unlock(hdev); in set_powered()
1401 int mgmt_new_settings(struct hci_dev *hdev) in mgmt_new_settings() argument
1403 return new_settings(hdev, NULL); in mgmt_new_settings()
1408 struct hci_dev *hdev; member
1416 send_settings_rsp(cmd->sk, cmd->opcode, match->hdev); in settings_rsp()
1462 static u8 mgmt_bredr_support(struct hci_dev *hdev) in mgmt_bredr_support() argument
1464 if (!lmp_bredr_capable(hdev)) in mgmt_bredr_support()
1466 else if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in mgmt_bredr_support()
1472 static u8 mgmt_le_support(struct hci_dev *hdev) in mgmt_le_support() argument
1474 if (!lmp_le_capable(hdev)) in mgmt_le_support()
1476 else if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mgmt_le_support()
1482 static void mgmt_set_discoverable_complete(struct hci_dev *hdev, void *data, in mgmt_set_discoverable_complete() argument
1487 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_discoverable_complete()
1490 if (cmd != pending_find(MGMT_OP_SET_DISCOVERABLE, hdev)) in mgmt_set_discoverable_complete()
1493 hci_dev_lock(hdev); in mgmt_set_discoverable_complete()
1498 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in mgmt_set_discoverable_complete()
1502 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in mgmt_set_discoverable_complete()
1503 hdev->discov_timeout > 0) { in mgmt_set_discoverable_complete()
1504 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in mgmt_set_discoverable_complete()
1505 queue_delayed_work(hdev->req_workqueue, &hdev->discov_off, to); in mgmt_set_discoverable_complete()
1508 send_settings_rsp(cmd->sk, MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_set_discoverable_complete()
1509 new_settings(hdev, cmd->sk); in mgmt_set_discoverable_complete()
1513 hci_dev_unlock(hdev); in mgmt_set_discoverable_complete()
1516 static int set_discoverable_sync(struct hci_dev *hdev, void *data) in set_discoverable_sync() argument
1518 BT_DBG("%s", hdev->name); in set_discoverable_sync()
1520 return hci_update_discoverable_sync(hdev); in set_discoverable_sync()
1523 static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, in set_discoverable() argument
1531 bt_dev_dbg(hdev, "sock %p", sk); in set_discoverable()
1533 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_discoverable()
1534 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_discoverable()
1535 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1539 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1549 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1552 hci_dev_lock(hdev); in set_discoverable()
1554 if (!hdev_is_powered(hdev) && timeout > 0) { in set_discoverable()
1555 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1560 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_discoverable()
1561 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_discoverable()
1562 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1567 if (!hci_dev_test_flag(hdev, HCI_CONNECTABLE)) { in set_discoverable()
1568 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1573 if (hdev->advertising_paused) { in set_discoverable()
1574 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1579 if (!hdev_is_powered(hdev)) { in set_discoverable()
1586 if (!!cp->val != hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) { in set_discoverable()
1587 hci_dev_change_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1591 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1596 err = new_settings(hdev, sk); in set_discoverable()
1605 if (!!cp->val == hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in set_discoverable()
1606 (cp->val == 0x02) == hci_dev_test_flag(hdev, in set_discoverable()
1608 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1609 hdev->discov_timeout = timeout; in set_discoverable()
1611 if (cp->val && hdev->discov_timeout > 0) { in set_discoverable()
1612 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in set_discoverable()
1613 queue_delayed_work(hdev->req_workqueue, in set_discoverable()
1614 &hdev->discov_off, to); in set_discoverable()
1617 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1621 cmd = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, hdev, data, len); in set_discoverable()
1631 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1632 hdev->discov_timeout = timeout; in set_discoverable()
1635 hci_dev_set_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1637 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1641 hci_dev_set_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1643 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1645 err = hci_cmd_sync_queue(hdev, set_discoverable_sync, cmd, in set_discoverable()
1652 hci_dev_unlock(hdev); in set_discoverable()
1656 static void mgmt_set_connectable_complete(struct hci_dev *hdev, void *data, in mgmt_set_connectable_complete() argument
1661 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_connectable_complete()
1664 if (cmd != pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) in mgmt_set_connectable_complete()
1667 hci_dev_lock(hdev); in mgmt_set_connectable_complete()
1675 send_settings_rsp(cmd->sk, MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_set_connectable_complete()
1676 new_settings(hdev, cmd->sk); in mgmt_set_connectable_complete()
1682 hci_dev_unlock(hdev); in mgmt_set_connectable_complete()
1685 static int set_connectable_update_settings(struct hci_dev *hdev, in set_connectable_update_settings() argument
1691 if (!!val != hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in set_connectable_update_settings()
1695 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1697 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1698 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable_update_settings()
1701 err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev); in set_connectable_update_settings()
1706 hci_update_scan(hdev); in set_connectable_update_settings()
1707 hci_update_passive_scan(hdev); in set_connectable_update_settings()
1708 return new_settings(hdev, sk); in set_connectable_update_settings()
1714 static int set_connectable_sync(struct hci_dev *hdev, void *data) in set_connectable_sync() argument
1716 BT_DBG("%s", hdev->name); in set_connectable_sync()
1718 return hci_update_connectable_sync(hdev); in set_connectable_sync()
1721 static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data, in set_connectable() argument
1728 bt_dev_dbg(hdev, "sock %p", sk); in set_connectable()
1730 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_connectable()
1731 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_connectable()
1732 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1736 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1739 hci_dev_lock(hdev); in set_connectable()
1741 if (!hdev_is_powered(hdev)) { in set_connectable()
1742 err = set_connectable_update_settings(hdev, sk, cp->val); in set_connectable()
1746 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_connectable()
1747 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_connectable()
1748 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1753 cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len); in set_connectable()
1760 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1762 if (hdev->discov_timeout > 0) in set_connectable()
1763 cancel_delayed_work(&hdev->discov_off); in set_connectable()
1765 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_connectable()
1766 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable()
1767 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1770 err = hci_cmd_sync_queue(hdev, set_connectable_sync, cmd, in set_connectable()
1777 hci_dev_unlock(hdev); in set_connectable()
1781 static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data, in set_bondable() argument
1788 bt_dev_dbg(hdev, "sock %p", sk); in set_bondable()
1791 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BONDABLE, in set_bondable()
1794 hci_dev_lock(hdev); in set_bondable()
1797 changed = !hci_dev_test_and_set_flag(hdev, HCI_BONDABLE); in set_bondable()
1799 changed = hci_dev_test_and_clear_flag(hdev, HCI_BONDABLE); in set_bondable()
1801 err = send_settings_rsp(sk, MGMT_OP_SET_BONDABLE, hdev); in set_bondable()
1809 hci_update_discoverable(hdev); in set_bondable()
1811 err = new_settings(hdev, sk); in set_bondable()
1815 hci_dev_unlock(hdev); in set_bondable()
1819 static int set_link_security(struct sock *sk, struct hci_dev *hdev, void *data, in set_link_security() argument
1827 bt_dev_dbg(hdev, "sock %p", sk); in set_link_security()
1829 status = mgmt_bredr_support(hdev); in set_link_security()
1831 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1835 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1838 hci_dev_lock(hdev); in set_link_security()
1840 if (!hdev_is_powered(hdev)) { in set_link_security()
1843 if (!!cp->val != hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) { in set_link_security()
1844 hci_dev_change_flag(hdev, HCI_LINK_SECURITY); in set_link_security()
1848 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1853 err = new_settings(hdev, sk); in set_link_security()
1858 if (pending_find(MGMT_OP_SET_LINK_SECURITY, hdev)) { in set_link_security()
1859 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1866 if (test_bit(HCI_AUTH, &hdev->flags) == val) { in set_link_security()
1867 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1871 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LINK_SECURITY, hdev, data, len); in set_link_security()
1877 err = hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, sizeof(val), &val); in set_link_security()
1884 hci_dev_unlock(hdev); in set_link_security()
1888 static void set_ssp_complete(struct hci_dev *hdev, void *data, int err) in set_ssp_complete() argument
1890 struct cmd_lookup match = { NULL, hdev }; in set_ssp_complete()
1897 if (cmd != pending_find(MGMT_OP_SET_SSP, hdev)) in set_ssp_complete()
1903 if (enable && hci_dev_test_and_clear_flag(hdev, in set_ssp_complete()
1905 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_ssp_complete()
1906 new_settings(hdev, NULL); in set_ssp_complete()
1909 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, cmd_status_rsp, in set_ssp_complete()
1915 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in set_ssp_complete()
1917 changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED); in set_ssp_complete()
1920 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp_complete()
1923 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_ssp_complete()
1926 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, settings_rsp, &match); in set_ssp_complete()
1929 new_settings(hdev, match.sk); in set_ssp_complete()
1934 hci_update_eir_sync(hdev); in set_ssp_complete()
1937 static int set_ssp_sync(struct hci_dev *hdev, void *data) in set_ssp_sync() argument
1945 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in set_ssp_sync()
1947 err = hci_write_ssp_mode_sync(hdev, cp->val); in set_ssp_sync()
1950 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_ssp_sync()
1955 static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_ssp() argument
1962 bt_dev_dbg(hdev, "sock %p", sk); in set_ssp()
1964 status = mgmt_bredr_support(hdev); in set_ssp()
1966 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, status); in set_ssp()
1968 if (!lmp_ssp_capable(hdev)) in set_ssp()
1969 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1973 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1976 hci_dev_lock(hdev); in set_ssp()
1978 if (!hdev_is_powered(hdev)) { in set_ssp()
1982 changed = !hci_dev_test_and_set_flag(hdev, in set_ssp()
1985 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
1988 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
1991 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_ssp()
1994 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
1999 err = new_settings(hdev, sk); in set_ssp()
2004 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_ssp()
2005 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2010 if (!!cp->val == hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_ssp()
2011 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
2015 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SSP, hdev, data, len); in set_ssp()
2019 err = hci_cmd_sync_queue(hdev, set_ssp_sync, cmd, in set_ssp()
2023 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2031 hci_dev_unlock(hdev); in set_ssp()
2035 static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_hs() argument
2042 bt_dev_dbg(hdev, "sock %p", sk); in set_hs()
2045 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2048 status = mgmt_bredr_support(hdev); in set_hs()
2050 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, status); in set_hs()
2052 if (!lmp_ssp_capable(hdev)) in set_hs()
2053 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2056 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_hs()
2057 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2061 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2064 hci_dev_lock(hdev); in set_hs()
2066 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_hs()
2067 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2073 changed = !hci_dev_test_and_set_flag(hdev, HCI_HS_ENABLED); in set_hs()
2075 if (hdev_is_powered(hdev)) { in set_hs()
2076 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2081 changed = hci_dev_test_and_clear_flag(hdev, HCI_HS_ENABLED); in set_hs()
2084 err = send_settings_rsp(sk, MGMT_OP_SET_HS, hdev); in set_hs()
2089 err = new_settings(hdev, sk); in set_hs()
2092 hci_dev_unlock(hdev); in set_hs()
2096 static void set_le_complete(struct hci_dev *hdev, void *data, int err) in set_le_complete() argument
2098 struct cmd_lookup match = { NULL, hdev }; in set_le_complete()
2101 bt_dev_dbg(hdev, "err %d", err); in set_le_complete()
2104 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp, in set_le_complete()
2109 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match); in set_le_complete()
2111 new_settings(hdev, match.sk); in set_le_complete()
2117 static int set_le_sync(struct hci_dev *hdev, void *data) in set_le_sync() argument
2125 hci_clear_adv_instance_sync(hdev, NULL, 0x00, true); in set_le_sync()
2127 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_le_sync()
2128 hci_disable_advertising_sync(hdev); in set_le_sync()
2130 if (ext_adv_capable(hdev)) in set_le_sync()
2131 hci_remove_ext_adv_instance_sync(hdev, 0, cmd->sk); in set_le_sync()
2133 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in set_le_sync()
2136 err = hci_write_le_host_supported_sync(hdev, val, 0); in set_le_sync()
2143 if (!err && hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le_sync()
2144 if (ext_adv_capable(hdev)) { in set_le_sync()
2147 status = hci_setup_ext_adv_instance_sync(hdev, 0x00); in set_le_sync()
2149 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_le_sync()
2151 hci_update_adv_data_sync(hdev, 0x00); in set_le_sync()
2152 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_le_sync()
2155 hci_update_passive_scan(hdev); in set_le_sync()
2161 static void set_mesh_complete(struct hci_dev *hdev, void *data, int err) in set_mesh_complete() argument
2168 mgmt_pending_foreach(MGMT_OP_SET_MESH_RECEIVER, hdev, in set_mesh_complete()
2174 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, 0, NULL, 0); in set_mesh_complete()
2177 static int set_mesh_sync(struct hci_dev *hdev, void *data) in set_mesh_sync() argument
2183 memset(hdev->mesh_ad_types, 0, sizeof(hdev->mesh_ad_types)); in set_mesh_sync()
2186 hci_dev_set_flag(hdev, HCI_MESH); in set_mesh_sync()
2188 hci_dev_clear_flag(hdev, HCI_MESH); in set_mesh_sync()
2193 if (len <= sizeof(hdev->mesh_ad_types)) in set_mesh_sync()
2194 memcpy(hdev->mesh_ad_types, cp->ad_types, len); in set_mesh_sync()
2196 hci_update_passive_scan_sync(hdev); in set_mesh_sync()
2200 static int set_mesh(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_mesh() argument
2206 bt_dev_dbg(hdev, "sock %p", sk); in set_mesh()
2208 if (!lmp_le_capable(hdev) || in set_mesh()
2209 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in set_mesh()
2210 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2214 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2217 hci_dev_lock(hdev); in set_mesh()
2219 cmd = mgmt_pending_add(sk, MGMT_OP_SET_MESH_RECEIVER, hdev, data, len); in set_mesh()
2223 err = hci_cmd_sync_queue(hdev, set_mesh_sync, cmd, in set_mesh()
2227 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2234 hci_dev_unlock(hdev); in set_mesh()
2238 static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err) in mesh_send_start_complete() argument
2248 hci_dev_clear_flag(hdev, HCI_MESH_SENDING); in mesh_send_start_complete()
2250 mesh_send_complete(hdev, mesh_tx, false); in mesh_send_start_complete()
2255 queue_delayed_work(hdev->req_workqueue, &hdev->mesh_send_done, in mesh_send_start_complete()
2259 static int mesh_send_sync(struct hci_dev *hdev, void *data) in mesh_send_sync() argument
2264 u8 instance = hdev->le_num_of_adv_sets + 1; in mesh_send_sync()
2268 if (hdev->le_num_of_adv_sets <= hdev->adv_instance_cnt) in mesh_send_sync()
2272 duration = send->cnt * INTERVAL_TO_MS(hdev->le_adv_max_interval); in mesh_send_sync()
2273 adv = hci_add_adv_instance(hdev, instance, 0, in mesh_send_sync()
2278 hdev->le_adv_min_interval, in mesh_send_sync()
2279 hdev->le_adv_max_interval, in mesh_send_sync()
2287 if (hdev->cur_adv_instance == instance) { in mesh_send_sync()
2293 cancel_adv_timeout(hdev); in mesh_send_sync()
2295 next_instance = hci_get_next_instance(hdev, instance); in mesh_send_sync()
2300 } else if (hdev->adv_instance_timeout) { in mesh_send_sync()
2308 return hci_schedule_adv_instance_sync(hdev, instance, true); in mesh_send_sync()
2323 static int mesh_features(struct sock *sk, struct hci_dev *hdev, in mesh_features() argument
2328 if (!lmp_le_capable(hdev) || in mesh_features()
2329 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_features()
2330 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_READ_FEATURES, in mesh_features()
2334 rp.index = cpu_to_le16(hdev->id); in mesh_features()
2335 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mesh_features()
2338 hci_dev_lock(hdev); in mesh_features()
2341 mgmt_mesh_foreach(hdev, send_count, &rp, sk); in mesh_features()
2343 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_MESH_READ_FEATURES, 0, &rp, in mesh_features()
2346 hci_dev_unlock(hdev); in mesh_features()
2350 static int send_cancel(struct hci_dev *hdev, void *data) in send_cancel() argument
2358 mesh_tx = mgmt_mesh_next(hdev, cmd->sk); in send_cancel()
2361 mesh_send_complete(hdev, mesh_tx, false); in send_cancel()
2364 mesh_tx = mgmt_mesh_find(hdev, cancel->handle); in send_cancel()
2367 mesh_send_complete(hdev, mesh_tx, false); in send_cancel()
2370 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in send_cancel()
2377 static int mesh_send_cancel(struct sock *sk, struct hci_dev *hdev, in mesh_send_cancel() argument
2383 if (!lmp_le_capable(hdev) || in mesh_send_cancel()
2384 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_send_cancel()
2385 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2388 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mesh_send_cancel()
2389 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2392 hci_dev_lock(hdev); in mesh_send_cancel()
2393 cmd = mgmt_pending_new(sk, MGMT_OP_MESH_SEND_CANCEL, hdev, data, len); in mesh_send_cancel()
2397 err = hci_cmd_sync_queue(hdev, send_cancel, cmd, NULL); in mesh_send_cancel()
2400 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2407 hci_dev_unlock(hdev); in mesh_send_cancel()
2411 static int mesh_send(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in mesh_send() argument
2419 if (!lmp_le_capable(hdev) || in mesh_send()
2420 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_send()
2421 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2423 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) || in mesh_send()
2426 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2429 hci_dev_lock(hdev); in mesh_send()
2434 mgmt_mesh_foreach(hdev, send_count, &rp, sk); in mesh_send()
2437 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2442 sending = hci_dev_test_flag(hdev, HCI_MESH_SENDING); in mesh_send()
2443 mesh_tx = mgmt_mesh_add(sk, hdev, send, len); in mesh_send()
2448 err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx, in mesh_send()
2452 bt_dev_err(hdev, "Send Mesh Failed %d", err); in mesh_send()
2453 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2461 hci_dev_set_flag(hdev, HCI_MESH_SENDING); in mesh_send()
2463 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_MESH_SEND, 0, in mesh_send()
2468 hci_dev_unlock(hdev); in mesh_send()
2472 static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_le() argument
2479 bt_dev_dbg(hdev, "sock %p", sk); in set_le()
2481 if (!lmp_le_capable(hdev)) in set_le()
2482 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2486 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2498 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_le()
2500 return send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
2502 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2506 hci_dev_lock(hdev); in set_le()
2509 enabled = lmp_host_le_capable(hdev); in set_le()
2511 if (!hdev_is_powered(hdev) || val == enabled) { in set_le()
2514 if (val != hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le()
2515 hci_dev_change_flag(hdev, HCI_LE_ENABLED); in set_le()
2519 if (!val && hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in set_le()
2520 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_le()
2524 err = send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
2529 err = new_settings(hdev, sk); in set_le()
2534 if (pending_find(MGMT_OP_SET_LE, hdev) || in set_le()
2535 pending_find(MGMT_OP_SET_ADVERTISING, hdev)) { in set_le()
2536 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2541 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LE, hdev, data, len); in set_le()
2545 err = hci_cmd_sync_queue(hdev, set_le_sync, cmd, in set_le()
2549 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2557 hci_dev_unlock(hdev); in set_le()
2567 static bool pending_eir_or_class(struct hci_dev *hdev) in pending_eir_or_class() argument
2571 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in pending_eir_or_class()
2603 static void mgmt_class_complete(struct hci_dev *hdev, void *data, int err) in mgmt_class_complete() argument
2607 bt_dev_dbg(hdev, "err %d", err); in mgmt_class_complete()
2610 mgmt_status(err), hdev->dev_class, 3); in mgmt_class_complete()
2615 static int add_uuid_sync(struct hci_dev *hdev, void *data) in add_uuid_sync() argument
2619 err = hci_update_class_sync(hdev); in add_uuid_sync()
2623 return hci_update_eir_sync(hdev); in add_uuid_sync()
2626 static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in add_uuid() argument
2633 bt_dev_dbg(hdev, "sock %p", sk); in add_uuid()
2635 hci_dev_lock(hdev); in add_uuid()
2637 if (pending_eir_or_class(hdev)) { in add_uuid()
2638 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_UUID, in add_uuid()
2653 list_add_tail(&uuid->list, &hdev->uuids); in add_uuid()
2655 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_UUID, hdev, data, len); in add_uuid()
2661 err = hci_cmd_sync_queue(hdev, add_uuid_sync, cmd, mgmt_class_complete); in add_uuid()
2668 hci_dev_unlock(hdev); in add_uuid()
2672 static bool enable_service_cache(struct hci_dev *hdev) in enable_service_cache() argument
2674 if (!hdev_is_powered(hdev)) in enable_service_cache()
2677 if (!hci_dev_test_and_set_flag(hdev, HCI_SERVICE_CACHE)) { in enable_service_cache()
2678 queue_delayed_work(hdev->workqueue, &hdev->service_cache, in enable_service_cache()
2686 static int remove_uuid_sync(struct hci_dev *hdev, void *data) in remove_uuid_sync() argument
2690 err = hci_update_class_sync(hdev); in remove_uuid_sync()
2694 return hci_update_eir_sync(hdev); in remove_uuid_sync()
2697 static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data, in remove_uuid() argument
2708 bt_dev_dbg(hdev, "sock %p", sk); in remove_uuid()
2710 hci_dev_lock(hdev); in remove_uuid()
2712 if (pending_eir_or_class(hdev)) { in remove_uuid()
2713 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2719 hci_uuids_clear(hdev); in remove_uuid()
2721 if (enable_service_cache(hdev)) { in remove_uuid()
2722 err = mgmt_cmd_complete(sk, hdev->id, in remove_uuid()
2724 0, hdev->dev_class, 3); in remove_uuid()
2733 list_for_each_entry_safe(match, tmp, &hdev->uuids, list) { in remove_uuid()
2743 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2749 cmd = mgmt_pending_new(sk, MGMT_OP_REMOVE_UUID, hdev, data, len); in remove_uuid()
2755 err = hci_cmd_sync_queue(hdev, remove_uuid_sync, cmd, in remove_uuid()
2761 hci_dev_unlock(hdev); in remove_uuid()
2765 static int set_class_sync(struct hci_dev *hdev, void *data) in set_class_sync() argument
2769 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) { in set_class_sync()
2770 cancel_delayed_work_sync(&hdev->service_cache); in set_class_sync()
2771 err = hci_update_eir_sync(hdev); in set_class_sync()
2777 return hci_update_class_sync(hdev); in set_class_sync()
2780 static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data, in set_dev_class() argument
2787 bt_dev_dbg(hdev, "sock %p", sk); in set_dev_class()
2789 if (!lmp_bredr_capable(hdev)) in set_dev_class()
2790 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2793 hci_dev_lock(hdev); in set_dev_class()
2795 if (pending_eir_or_class(hdev)) { in set_dev_class()
2796 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2802 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2807 hdev->major_class = cp->major; in set_dev_class()
2808 hdev->minor_class = cp->minor; in set_dev_class()
2810 if (!hdev_is_powered(hdev)) { in set_dev_class()
2811 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, in set_dev_class()
2812 hdev->dev_class, 3); in set_dev_class()
2816 cmd = mgmt_pending_new(sk, MGMT_OP_SET_DEV_CLASS, hdev, data, len); in set_dev_class()
2822 err = hci_cmd_sync_queue(hdev, set_class_sync, cmd, in set_dev_class()
2828 hci_dev_unlock(hdev); in set_dev_class()
2832 static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data, in load_link_keys() argument
2842 bt_dev_dbg(hdev, "sock %p", sk); in load_link_keys()
2844 if (!lmp_bredr_capable(hdev)) in load_link_keys()
2845 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2850 bt_dev_err(hdev, "load_link_keys: too big key_count value %u", in load_link_keys()
2852 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2858 bt_dev_err(hdev, "load_link_keys: expected %u bytes, got %u bytes", in load_link_keys()
2860 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2865 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2868 bt_dev_dbg(hdev, "debug_keys %u key_count %u", cp->debug_keys, in load_link_keys()
2875 return mgmt_cmd_status(sk, hdev->id, in load_link_keys()
2880 hci_dev_lock(hdev); in load_link_keys()
2882 hci_link_keys_clear(hdev); in load_link_keys()
2885 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in load_link_keys()
2887 changed = hci_dev_test_and_clear_flag(hdev, in load_link_keys()
2891 new_settings(hdev, NULL); in load_link_keys()
2896 if (hci_is_blocked_key(hdev, in load_link_keys()
2899 bt_dev_warn(hdev, "Skipping blocked link key for %pMR", in load_link_keys()
2910 hci_add_link_key(hdev, NULL, &key->addr.bdaddr, key->val, in load_link_keys()
2914 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0); in load_link_keys()
2916 hci_dev_unlock(hdev); in load_link_keys()
2921 static int device_unpaired(struct hci_dev *hdev, bdaddr_t *bdaddr, in device_unpaired() argument
2929 return mgmt_event(MGMT_EV_DEVICE_UNPAIRED, hdev, &ev, sizeof(ev), in device_unpaired()
2933 static void unpair_device_complete(struct hci_dev *hdev, void *data, int err) in unpair_device_complete() argument
2939 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_complete()
2945 static int unpair_device_sync(struct hci_dev *hdev, void *data) in unpair_device_sync() argument
2952 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device_sync()
2955 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in unpair_device_sync()
2961 return hci_abort_conn_sync(hdev, conn, HCI_ERROR_REMOTE_USER_TERM); in unpair_device_sync()
2964 static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data, in unpair_device() argument
2980 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2985 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2989 hci_dev_lock(hdev); in unpair_device()
2991 if (!hdev_is_powered(hdev)) { in unpair_device()
2992 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3007 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device()
3012 err = hci_remove_link_key(hdev, &cp->addr.bdaddr); in unpair_device()
3014 err = mgmt_cmd_complete(sk, hdev->id, in unpair_device()
3028 err = smp_cancel_and_remove_pairing(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3030 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3036 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3038 hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3049 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3068 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0, in unpair_device()
3070 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk); in unpair_device()
3074 cmd = mgmt_pending_new(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp, in unpair_device()
3083 err = hci_cmd_sync_queue(hdev, unpair_device_sync, cmd, in unpair_device()
3089 hci_dev_unlock(hdev); in unpair_device()
3093 static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data, in disconnect() argument
3102 bt_dev_dbg(hdev, "sock %p", sk); in disconnect()
3109 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3113 hci_dev_lock(hdev); in disconnect()
3115 if (!test_bit(HCI_UP, &hdev->flags)) { in disconnect()
3116 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3122 if (pending_find(MGMT_OP_DISCONNECT, hdev)) { in disconnect()
3123 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3129 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in disconnect()
3132 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in disconnect()
3136 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3142 cmd = mgmt_pending_add(sk, MGMT_OP_DISCONNECT, hdev, data, len); in disconnect()
3155 hci_dev_unlock(hdev); in disconnect()
3178 static int get_connections(struct sock *sk, struct hci_dev *hdev, void *data, in get_connections() argument
3186 bt_dev_dbg(hdev, "sock %p", sk); in get_connections()
3188 hci_dev_lock(hdev); in get_connections()
3190 if (!hdev_is_powered(hdev)) { in get_connections()
3191 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, in get_connections()
3197 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
3209 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
3222 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, 0, rp, in get_connections()
3228 hci_dev_unlock(hdev); in get_connections()
3232 static int send_pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in send_pin_code_neg_reply() argument
3238 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, hdev, cp, in send_pin_code_neg_reply()
3245 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, in send_pin_code_neg_reply()
3253 static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data, in pin_code_reply() argument
3262 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_reply()
3264 hci_dev_lock(hdev); in pin_code_reply()
3266 if (!hdev_is_powered(hdev)) { in pin_code_reply()
3267 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3272 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in pin_code_reply()
3274 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3284 bt_dev_err(hdev, "PIN code is not 16 bytes long"); in pin_code_reply()
3286 err = send_pin_code_neg_reply(sk, hdev, &ncp); in pin_code_reply()
3288 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3294 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data, len); in pin_code_reply()
3306 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_REPLY, sizeof(reply), &reply); in pin_code_reply()
3311 hci_dev_unlock(hdev); in pin_code_reply()
3315 static int set_io_capability(struct sock *sk, struct hci_dev *hdev, void *data, in set_io_capability() argument
3320 bt_dev_dbg(hdev, "sock %p", sk); in set_io_capability()
3323 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, in set_io_capability()
3326 hci_dev_lock(hdev); in set_io_capability()
3328 hdev->io_capability = cp->io_capability; in set_io_capability()
3330 bt_dev_dbg(hdev, "IO capability set to 0x%02x", hdev->io_capability); in set_io_capability()
3332 hci_dev_unlock(hdev); in set_io_capability()
3334 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, 0, in set_io_capability()
3340 struct hci_dev *hdev = conn->hdev; in find_pairing() local
3343 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in find_pairing()
3432 static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in pair_device() argument
3442 bt_dev_dbg(hdev, "sock %p", sk); in pair_device()
3449 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3454 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3458 hci_dev_lock(hdev); in pair_device()
3460 if (!hdev_is_powered(hdev)) { in pair_device()
3461 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3467 if (hci_bdaddr_is_paired(hdev, &cp->addr.bdaddr, cp->addr.type)) { in pair_device()
3468 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3478 conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level, in pair_device()
3493 p = hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type); in pair_device()
3498 conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr, addr_type, in pair_device()
3515 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3522 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3527 cmd = mgmt_pending_add(sk, MGMT_OP_PAIR_DEVICE, hdev, data, len); in pair_device()
3559 hci_dev_unlock(hdev); in pair_device()
3563 static int abort_conn_sync(struct hci_dev *hdev, void *data) in abort_conn_sync() argument
3568 conn = hci_conn_hash_lookup_handle(hdev, handle); in abort_conn_sync()
3572 return hci_abort_conn_sync(hdev, conn, HCI_ERROR_REMOTE_USER_TERM); in abort_conn_sync()
3575 static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in cancel_pair_device() argument
3583 bt_dev_dbg(hdev, "sock %p", sk); in cancel_pair_device()
3585 hci_dev_lock(hdev); in cancel_pair_device()
3587 if (!hdev_is_powered(hdev)) { in cancel_pair_device()
3588 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3593 cmd = pending_find(MGMT_OP_PAIR_DEVICE, hdev); in cancel_pair_device()
3595 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3603 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3611 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0, in cancel_pair_device()
3619 hci_remove_link_key(hdev, &addr->bdaddr); in cancel_pair_device()
3621 smp_cancel_and_remove_pairing(hdev, &addr->bdaddr, in cancel_pair_device()
3625 hci_cmd_sync_queue(hdev, abort_conn_sync, ERR_PTR(conn->handle), in cancel_pair_device()
3629 hci_dev_unlock(hdev); in cancel_pair_device()
3633 static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev, in user_pairing_resp() argument
3641 hci_dev_lock(hdev); in user_pairing_resp()
3643 if (!hdev_is_powered(hdev)) { in user_pairing_resp()
3644 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3651 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &addr->bdaddr); in user_pairing_resp()
3653 conn = hci_conn_hash_lookup_le(hdev, &addr->bdaddr, in user_pairing_resp()
3657 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3666 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3670 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3677 cmd = mgmt_pending_add(sk, mgmt_op, hdev, addr, sizeof(*addr)); in user_pairing_resp()
3691 err = hci_send_cmd(hdev, hci_op, sizeof(cp), &cp); in user_pairing_resp()
3693 err = hci_send_cmd(hdev, hci_op, sizeof(addr->bdaddr), in user_pairing_resp()
3700 hci_dev_unlock(hdev); in user_pairing_resp()
3704 static int pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in pin_code_neg_reply() argument
3709 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_neg_reply()
3711 return user_pairing_resp(sk, hdev, &cp->addr, in pin_code_neg_reply()
3716 static int user_confirm_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_confirm_reply() argument
3721 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_reply()
3724 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_USER_CONFIRM_REPLY, in user_confirm_reply()
3727 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_reply()
3732 static int user_confirm_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_confirm_neg_reply() argument
3737 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_neg_reply()
3739 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_neg_reply()
3744 static int user_passkey_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_passkey_reply() argument
3749 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_reply()
3751 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_reply()
3756 static int user_passkey_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_passkey_neg_reply() argument
3761 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_neg_reply()
3763 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_neg_reply()
3768 static int adv_expire_sync(struct hci_dev *hdev, u32 flags) in adv_expire_sync() argument
3772 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in adv_expire_sync()
3780 cancel_adv_timeout(hdev); in adv_expire_sync()
3782 adv_instance = hci_get_next_instance(hdev, adv_instance->instance); in adv_expire_sync()
3786 hci_schedule_adv_instance_sync(hdev, adv_instance->instance, true); in adv_expire_sync()
3791 static int name_changed_sync(struct hci_dev *hdev, void *data) in name_changed_sync() argument
3793 return adv_expire_sync(hdev, MGMT_ADV_FLAG_LOCAL_NAME); in name_changed_sync()
3796 static void set_name_complete(struct hci_dev *hdev, void *data, int err) in set_name_complete() argument
3802 bt_dev_dbg(hdev, "err %d", err); in set_name_complete()
3804 if (cmd != pending_find(MGMT_OP_SET_LOCAL_NAME, hdev)) in set_name_complete()
3808 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_name_complete()
3811 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_name_complete()
3814 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_name_complete()
3815 hci_cmd_sync_queue(hdev, name_changed_sync, NULL, NULL); in set_name_complete()
3821 static int set_name_sync(struct hci_dev *hdev, void *data) in set_name_sync() argument
3823 if (lmp_bredr_capable(hdev)) { in set_name_sync()
3824 hci_update_name_sync(hdev); in set_name_sync()
3825 hci_update_eir_sync(hdev); in set_name_sync()
3831 if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING)) in set_name_sync()
3832 hci_update_scan_rsp_data_sync(hdev, hdev->cur_adv_instance); in set_name_sync()
3837 static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data, in set_local_name() argument
3844 bt_dev_dbg(hdev, "sock %p", sk); in set_local_name()
3846 hci_dev_lock(hdev); in set_local_name()
3851 if (!memcmp(hdev->dev_name, cp->name, sizeof(hdev->dev_name)) && in set_local_name()
3852 !memcmp(hdev->short_name, cp->short_name, in set_local_name()
3853 sizeof(hdev->short_name))) { in set_local_name()
3854 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3859 memcpy(hdev->short_name, cp->short_name, sizeof(hdev->short_name)); in set_local_name()
3861 if (!hdev_is_powered(hdev)) { in set_local_name()
3862 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3864 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3869 err = mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, data, in set_local_name()
3871 ext_info_changed(hdev, sk); in set_local_name()
3876 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len); in set_local_name()
3880 err = hci_cmd_sync_queue(hdev, set_name_sync, cmd, in set_local_name()
3884 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_local_name()
3893 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3896 hci_dev_unlock(hdev); in set_local_name()
3900 static int appearance_changed_sync(struct hci_dev *hdev, void *data) in appearance_changed_sync() argument
3902 return adv_expire_sync(hdev, MGMT_ADV_FLAG_APPEARANCE); in appearance_changed_sync()
3905 static int set_appearance(struct sock *sk, struct hci_dev *hdev, void *data, in set_appearance() argument
3912 bt_dev_dbg(hdev, "sock %p", sk); in set_appearance()
3914 if (!lmp_le_capable(hdev)) in set_appearance()
3915 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_APPEARANCE, in set_appearance()
3920 hci_dev_lock(hdev); in set_appearance()
3922 if (hdev->appearance != appearance) { in set_appearance()
3923 hdev->appearance = appearance; in set_appearance()
3925 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_appearance()
3926 hci_cmd_sync_queue(hdev, appearance_changed_sync, NULL, in set_appearance()
3929 ext_info_changed(hdev, sk); in set_appearance()
3932 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_APPEARANCE, 0, NULL, in set_appearance()
3935 hci_dev_unlock(hdev); in set_appearance()
3940 static int get_phy_configuration(struct sock *sk, struct hci_dev *hdev, in get_phy_configuration() argument
3945 bt_dev_dbg(hdev, "sock %p", sk); in get_phy_configuration()
3947 hci_dev_lock(hdev); in get_phy_configuration()
3951 rp.supported_phys = cpu_to_le32(get_supported_phys(hdev)); in get_phy_configuration()
3952 rp.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in get_phy_configuration()
3953 rp.configurable_phys = cpu_to_le32(get_configurable_phys(hdev)); in get_phy_configuration()
3955 hci_dev_unlock(hdev); in get_phy_configuration()
3957 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_PHY_CONFIGURATION, 0, in get_phy_configuration()
3961 int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip) in mgmt_phy_configuration_changed() argument
3967 ev.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in mgmt_phy_configuration_changed()
3969 return mgmt_event(MGMT_EV_PHY_CONFIGURATION_CHANGED, hdev, &ev, in mgmt_phy_configuration_changed()
3973 static void set_default_phy_complete(struct hci_dev *hdev, void *data, int err) in set_default_phy_complete() argument
3979 if (cmd != pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) in set_default_phy_complete()
3991 bt_dev_dbg(hdev, "status %d", status); in set_default_phy_complete()
3994 mgmt_cmd_status(cmd->sk, hdev->id, in set_default_phy_complete()
3997 mgmt_cmd_complete(cmd->sk, hdev->id, in set_default_phy_complete()
4001 mgmt_phy_configuration_changed(hdev, cmd->sk); in set_default_phy_complete()
4010 static int set_default_phy_sync(struct hci_dev *hdev, void *data) in set_default_phy_sync() argument
4043 cmd->skb = __hci_cmd_sync(hdev, HCI_OP_LE_SET_DEFAULT_PHY, in set_default_phy_sync()
4049 static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, in set_phy_configuration() argument
4059 bt_dev_dbg(hdev, "sock %p", sk); in set_phy_configuration()
4061 configurable_phys = get_configurable_phys(hdev); in set_phy_configuration()
4062 supported_phys = get_supported_phys(hdev); in set_phy_configuration()
4066 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4073 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4077 if (selected_phys == get_selected_phys(hdev)) in set_phy_configuration()
4078 return mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
4082 hci_dev_lock(hdev); in set_phy_configuration()
4084 if (!hdev_is_powered(hdev)) { in set_phy_configuration()
4085 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4091 if (pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) { in set_phy_configuration()
4092 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4138 if (pkt_type != hdev->pkt_type) { in set_phy_configuration()
4139 hdev->pkt_type = pkt_type; in set_phy_configuration()
4144 (get_selected_phys(hdev) & MGMT_PHY_LE_MASK)) { in set_phy_configuration()
4146 mgmt_phy_configuration_changed(hdev, sk); in set_phy_configuration()
4148 err = mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
4155 cmd = mgmt_pending_add(sk, MGMT_OP_SET_PHY_CONFIGURATION, hdev, data, in set_phy_configuration()
4160 err = hci_cmd_sync_queue(hdev, set_default_phy_sync, cmd, in set_phy_configuration()
4164 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4173 hci_dev_unlock(hdev); in set_phy_configuration()
4178 static int set_blocked_keys(struct sock *sk, struct hci_dev *hdev, void *data, in set_blocked_keys() argument
4188 bt_dev_dbg(hdev, "sock %p", sk); in set_blocked_keys()
4192 bt_dev_err(hdev, "too big key_count value %u", key_count); in set_blocked_keys()
4193 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4199 bt_dev_err(hdev, "expected %u bytes, got %u bytes", in set_blocked_keys()
4201 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4205 hci_dev_lock(hdev); in set_blocked_keys()
4207 hci_blocked_keys_clear(hdev); in set_blocked_keys()
4219 list_add_rcu(&b->list, &hdev->blocked_keys); in set_blocked_keys()
4221 hci_dev_unlock(hdev); in set_blocked_keys()
4223 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4227 static int set_wideband_speech(struct sock *sk, struct hci_dev *hdev, in set_wideband_speech() argument
4234 bt_dev_dbg(hdev, "sock %p", sk); in set_wideband_speech()
4236 if (!test_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks)) in set_wideband_speech()
4237 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4242 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4246 hci_dev_lock(hdev); in set_wideband_speech()
4248 if (hdev_is_powered(hdev) && in set_wideband_speech()
4249 !!cp->val != hci_dev_test_flag(hdev, in set_wideband_speech()
4251 err = mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4258 changed = !hci_dev_test_and_set_flag(hdev, in set_wideband_speech()
4261 changed = hci_dev_test_and_clear_flag(hdev, in set_wideband_speech()
4264 err = send_settings_rsp(sk, MGMT_OP_SET_WIDEBAND_SPEECH, hdev); in set_wideband_speech()
4269 err = new_settings(hdev, sk); in set_wideband_speech()
4272 hci_dev_unlock(hdev); in set_wideband_speech()
4276 static int read_controller_cap(struct sock *sk, struct hci_dev *hdev, in read_controller_cap() argument
4285 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_cap()
4289 hci_dev_lock(hdev); in read_controller_cap()
4297 if ((hdev->commands[41] & 0x08) || msft_curve_validity(hdev)) in read_controller_cap()
4305 if (hdev->commands[20] & 0x10) in read_controller_cap()
4316 if (hdev->commands[41] & 0x08) in read_controller_cap()
4319 hdev->max_enc_key_size); in read_controller_cap()
4328 if (hdev->commands[38] & 0x80) { in read_controller_cap()
4329 memcpy(&tx_power_range[0], &hdev->min_le_tx_power, 1); in read_controller_cap()
4330 memcpy(&tx_power_range[1], &hdev->max_le_tx_power, 1); in read_controller_cap()
4337 hci_dev_unlock(hdev); in read_controller_cap()
4339 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONTROLLER_CAP, 0, in read_controller_cap()
4387 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, in read_exp_features_info() argument
4396 bt_dev_dbg(hdev, "sock %p", sk); in read_exp_features_info()
4405 if (!hdev) { in read_exp_features_info()
4414 if (hdev && hci_dev_le_state_simultaneous(hdev)) { in read_exp_features_info()
4415 if (hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) in read_exp_features_info()
4425 if (hdev && ll_privacy_capable(hdev)) { in read_exp_features_info()
4426 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in read_exp_features_info()
4436 if (hdev && (aosp_has_quality_report(hdev) || in read_exp_features_info()
4437 hdev->set_quality_report)) { in read_exp_features_info()
4438 if (hci_dev_test_flag(hdev, HCI_QUALITY_REPORT)) in read_exp_features_info()
4448 if (hdev && hdev->get_data_path_id) { in read_exp_features_info()
4449 if (hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)) in read_exp_features_info()
4466 if (hdev && lmp_le_capable(hdev)) { in read_exp_features_info()
4467 if (hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in read_exp_features_info()
4484 status = mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in read_exp_features_info()
4492 static int exp_ll_privacy_feature_changed(bool enabled, struct hci_dev *hdev, in exp_ll_privacy_feature_changed() argument
4502 if (enabled && privacy_mode_capable(hdev)) in exp_ll_privacy_feature_changed()
4503 hdev->conn_flags |= HCI_CONN_FLAG_DEVICE_PRIVACY; in exp_ll_privacy_feature_changed()
4505 hdev->conn_flags &= ~HCI_CONN_FLAG_DEVICE_PRIVACY; in exp_ll_privacy_feature_changed()
4507 return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, in exp_ll_privacy_feature_changed()
4513 static int exp_feature_changed(struct hci_dev *hdev, const u8 *uuid, in exp_feature_changed() argument
4522 return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, in exp_feature_changed()
4534 static int set_zero_key_func(struct sock *sk, struct hci_dev *hdev, in set_zero_key_func() argument
4543 if (!hdev) { in set_zero_key_func()
4553 if (hdev && use_ll_privacy(hdev) && !hdev_is_powered(hdev)) { in set_zero_key_func()
4556 changed = hci_dev_test_and_clear_flag(hdev, in set_zero_key_func()
4559 exp_feature_changed(hdev, rpa_resolution_uuid, false, in set_zero_key_func()
4565 return mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_zero_key_func()
4571 static int set_debug_func(struct sock *sk, struct hci_dev *hdev, in set_debug_func() argument
4580 if (hdev) in set_debug_func()
4581 return mgmt_cmd_status(sk, hdev->id, in set_debug_func()
4611 exp_feature_changed(hdev, debug_uuid, val, sk); in set_debug_func()
4617 static int set_mgmt_mesh_func(struct sock *sk, struct hci_dev *hdev, in set_mgmt_mesh_func() argument
4625 if (!hdev) in set_mgmt_mesh_func()
4631 if (hdev_is_powered(hdev)) in set_mgmt_mesh_func()
4632 return mgmt_cmd_status(sk, hdev->id, in set_mgmt_mesh_func()
4638 return mgmt_cmd_status(sk, hdev->id, in set_mgmt_mesh_func()
4644 return mgmt_cmd_status(sk, hdev->id, in set_mgmt_mesh_func()
4651 changed = !hci_dev_test_and_set_flag(hdev, in set_mgmt_mesh_func()
4654 hci_dev_clear_flag(hdev, HCI_MESH); in set_mgmt_mesh_func()
4655 changed = hci_dev_test_and_clear_flag(hdev, in set_mgmt_mesh_func()
4664 err = mgmt_cmd_complete(sk, hdev->id, in set_mgmt_mesh_func()
4669 exp_feature_changed(hdev, mgmt_mesh_uuid, val, sk); in set_mgmt_mesh_func()
4674 static int set_rpa_resolution_func(struct sock *sk, struct hci_dev *hdev, in set_rpa_resolution_func() argument
4684 if (!hdev) in set_rpa_resolution_func()
4690 if (hdev_is_powered(hdev)) in set_rpa_resolution_func()
4691 return mgmt_cmd_status(sk, hdev->id, in set_rpa_resolution_func()
4697 return mgmt_cmd_status(sk, hdev->id, in set_rpa_resolution_func()
4703 return mgmt_cmd_status(sk, hdev->id, in set_rpa_resolution_func()
4710 changed = !hci_dev_test_and_set_flag(hdev, in set_rpa_resolution_func()
4712 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_rpa_resolution_func()
4717 changed = hci_dev_test_and_clear_flag(hdev, in set_rpa_resolution_func()
4729 err = mgmt_cmd_complete(sk, hdev->id, in set_rpa_resolution_func()
4734 exp_ll_privacy_feature_changed(val, hdev, sk); in set_rpa_resolution_func()
4739 static int set_quality_report_func(struct sock *sk, struct hci_dev *hdev, in set_quality_report_func() argument
4748 if (!hdev) in set_quality_report_func()
4755 return mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4761 return mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4765 hci_req_sync_lock(hdev); in set_quality_report_func()
4768 changed = (val != hci_dev_test_flag(hdev, HCI_QUALITY_REPORT)); in set_quality_report_func()
4770 if (!aosp_has_quality_report(hdev) && !hdev->set_quality_report) { in set_quality_report_func()
4771 err = mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4778 if (hdev->set_quality_report) in set_quality_report_func()
4779 err = hdev->set_quality_report(hdev, val); in set_quality_report_func()
4781 err = aosp_set_quality_report(hdev, val); in set_quality_report_func()
4784 err = mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4791 hci_dev_set_flag(hdev, HCI_QUALITY_REPORT); in set_quality_report_func()
4793 hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT); in set_quality_report_func()
4796 bt_dev_dbg(hdev, "quality report enable %d changed %d", val, changed); in set_quality_report_func()
4802 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_EXP_FEATURE, 0, in set_quality_report_func()
4806 exp_feature_changed(hdev, quality_report_uuid, val, sk); in set_quality_report_func()
4809 hci_req_sync_unlock(hdev); in set_quality_report_func()
4813 static int set_offload_codec_func(struct sock *sk, struct hci_dev *hdev, in set_offload_codec_func() argument
4822 if (!hdev) in set_offload_codec_func()
4829 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4835 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4840 changed = (val != hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)); in set_offload_codec_func()
4842 if (!hdev->get_data_path_id) { in set_offload_codec_func()
4843 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4850 hci_dev_set_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED); in set_offload_codec_func()
4852 hci_dev_clear_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED); in set_offload_codec_func()
4855 bt_dev_info(hdev, "offload codecs enable %d changed %d", in set_offload_codec_func()
4861 err = mgmt_cmd_complete(sk, hdev->id, in set_offload_codec_func()
4866 exp_feature_changed(hdev, offload_codecs_uuid, val, sk); in set_offload_codec_func()
4871 static int set_le_simultaneous_roles_func(struct sock *sk, struct hci_dev *hdev, in set_le_simultaneous_roles_func() argument
4880 if (!hdev) in set_le_simultaneous_roles_func()
4887 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4893 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4898 changed = (val != hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)); in set_le_simultaneous_roles_func()
4900 if (!hci_dev_le_state_simultaneous(hdev)) { in set_le_simultaneous_roles_func()
4901 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4908 hci_dev_set_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); in set_le_simultaneous_roles_func()
4910 hci_dev_clear_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); in set_le_simultaneous_roles_func()
4913 bt_dev_info(hdev, "LE simultaneous roles enable %d changed %d", in set_le_simultaneous_roles_func()
4919 err = mgmt_cmd_complete(sk, hdev->id, in set_le_simultaneous_roles_func()
4924 exp_feature_changed(hdev, le_simultaneous_roles_uuid, val, sk); in set_le_simultaneous_roles_func()
4930 static int set_iso_socket_func(struct sock *sk, struct hci_dev *hdev, in set_iso_socket_func() argument
4938 if (hdev) in set_iso_socket_func()
4939 return mgmt_cmd_status(sk, hdev->id, in set_iso_socket_func()
4974 exp_feature_changed(hdev, iso_socket_uuid, val, sk); in set_iso_socket_func()
4982 int (*set_func)(struct sock *sk, struct hci_dev *hdev,
5002 static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, in set_exp_feature() argument
5008 bt_dev_dbg(hdev, "sock %p", sk); in set_exp_feature()
5012 return exp_features[i].set_func(sk, hdev, cp, data_len); in set_exp_feature()
5015 return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_exp_feature()
5020 static u32 get_params_flags(struct hci_dev *hdev, in get_params_flags() argument
5023 u32 flags = hdev->conn_flags; in get_params_flags()
5029 if ((flags & HCI_CONN_FLAG_REMOTE_WAKEUP) && !use_ll_privacy(hdev) && in get_params_flags()
5030 hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type)) in get_params_flags()
5036 static int get_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in get_device_flags() argument
5047 bt_dev_dbg(hdev, "Get device flags %pMR (type 0x%x)\n", in get_device_flags()
5050 hci_dev_lock(hdev); in get_device_flags()
5052 supported_flags = hdev->conn_flags; in get_device_flags()
5057 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, in get_device_flags()
5065 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in get_device_flags()
5070 supported_flags = get_params_flags(hdev, params); in get_device_flags()
5082 hci_dev_unlock(hdev); in get_device_flags()
5084 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_DEVICE_FLAGS, status, in get_device_flags()
5088 static void device_flags_changed(struct sock *sk, struct hci_dev *hdev, in device_flags_changed() argument
5099 mgmt_event(MGMT_EV_DEVICE_FLAGS_CHANGED, hdev, &ev, sizeof(ev), sk); in device_flags_changed()
5102 static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_flags() argument
5112 bt_dev_dbg(hdev, "Set device flags %pMR (type 0x%x) = 0x%x", in set_device_flags()
5116 supported_flags = hdev->conn_flags; in set_device_flags()
5119 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
5124 hci_dev_lock(hdev); in set_device_flags()
5127 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, in set_device_flags()
5135 bt_dev_warn(hdev, "No such BR/EDR device %pMR (0x%x)", in set_device_flags()
5142 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in set_device_flags()
5145 bt_dev_warn(hdev, "No such LE device %pMR (0x%x)", in set_device_flags()
5150 supported_flags = get_params_flags(hdev, params); in set_device_flags()
5153 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
5165 hci_update_passive_scan(hdev); in set_device_flags()
5168 hci_dev_unlock(hdev); in set_device_flags()
5172 device_flags_changed(sk, hdev, &cp->addr.bdaddr, cp->addr.type, in set_device_flags()
5175 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_FLAGS, status, in set_device_flags()
5179 static void mgmt_adv_monitor_added(struct sock *sk, struct hci_dev *hdev, in mgmt_adv_monitor_added() argument
5186 mgmt_event(MGMT_EV_ADV_MONITOR_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_adv_monitor_added()
5189 void mgmt_adv_monitor_removed(struct hci_dev *hdev, u16 handle) in mgmt_adv_monitor_removed() argument
5196 cmd = pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev); in mgmt_adv_monitor_removed()
5206 mgmt_event(MGMT_EV_ADV_MONITOR_REMOVED, hdev, &ev, sizeof(ev), sk_skip); in mgmt_adv_monitor_removed()
5209 static int read_adv_mon_features(struct sock *sk, struct hci_dev *hdev, in read_adv_mon_features() argument
5221 BT_DBG("request for %s", hdev->name); in read_adv_mon_features()
5223 hci_dev_lock(hdev); in read_adv_mon_features()
5225 if (msft_monitor_supported(hdev)) in read_adv_mon_features()
5228 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) in read_adv_mon_features()
5231 hci_dev_unlock(hdev); in read_adv_mon_features()
5249 err = mgmt_cmd_complete(sk, hdev->id, in read_adv_mon_features()
5258 static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, in mgmt_add_adv_patterns_monitor_complete() argument
5265 hci_dev_lock(hdev); in mgmt_add_adv_patterns_monitor_complete()
5270 mgmt_adv_monitor_added(cmd->sk, hdev, monitor->handle); in mgmt_add_adv_patterns_monitor_complete()
5271 hdev->adv_monitors_cnt++; in mgmt_add_adv_patterns_monitor_complete()
5274 hci_update_passive_scan(hdev); in mgmt_add_adv_patterns_monitor_complete()
5281 hci_dev_unlock(hdev); in mgmt_add_adv_patterns_monitor_complete()
5282 bt_dev_dbg(hdev, "add monitor %d complete, status %d", in mgmt_add_adv_patterns_monitor_complete()
5286 static int mgmt_add_adv_patterns_monitor_sync(struct hci_dev *hdev, void *data) in mgmt_add_adv_patterns_monitor_sync() argument
5291 return hci_add_adv_monitor(hdev, monitor); in mgmt_add_adv_patterns_monitor_sync()
5294 static int __add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in __add_adv_patterns_monitor() argument
5301 hci_dev_lock(hdev); in __add_adv_patterns_monitor()
5306 if (pending_find(MGMT_OP_SET_LE, hdev) || in __add_adv_patterns_monitor()
5307 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR, hdev) || in __add_adv_patterns_monitor()
5308 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI, hdev) || in __add_adv_patterns_monitor()
5309 pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev)) { in __add_adv_patterns_monitor()
5314 cmd = mgmt_pending_add(sk, op, hdev, data, len); in __add_adv_patterns_monitor()
5321 err = hci_cmd_sync_queue(hdev, mgmt_add_adv_patterns_monitor_sync, cmd, in __add_adv_patterns_monitor()
5332 hci_dev_unlock(hdev); in __add_adv_patterns_monitor()
5337 hci_free_adv_monitor(hdev, m); in __add_adv_patterns_monitor()
5338 hci_dev_unlock(hdev); in __add_adv_patterns_monitor()
5339 return mgmt_cmd_status(sk, hdev->id, op, status); in __add_adv_patterns_monitor()
5398 static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor() argument
5406 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor()
5431 return __add_adv_patterns_monitor(sk, hdev, m, status, data, len, in add_adv_patterns_monitor()
5435 static int add_adv_patterns_monitor_rssi(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor_rssi() argument
5443 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor_rssi()
5468 return __add_adv_patterns_monitor(sk, hdev, m, status, data, len, in add_adv_patterns_monitor_rssi()
5472 static void mgmt_remove_adv_monitor_complete(struct hci_dev *hdev, in mgmt_remove_adv_monitor_complete() argument
5479 hci_dev_lock(hdev); in mgmt_remove_adv_monitor_complete()
5484 hci_update_passive_scan(hdev); in mgmt_remove_adv_monitor_complete()
5490 hci_dev_unlock(hdev); in mgmt_remove_adv_monitor_complete()
5491 bt_dev_dbg(hdev, "remove monitor %d complete, status %d", in mgmt_remove_adv_monitor_complete()
5495 static int mgmt_remove_adv_monitor_sync(struct hci_dev *hdev, void *data) in mgmt_remove_adv_monitor_sync() argument
5502 return hci_remove_all_adv_monitor(hdev); in mgmt_remove_adv_monitor_sync()
5504 return hci_remove_single_adv_monitor(hdev, handle); in mgmt_remove_adv_monitor_sync()
5507 static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev, in remove_adv_monitor() argument
5513 hci_dev_lock(hdev); in remove_adv_monitor()
5515 if (pending_find(MGMT_OP_SET_LE, hdev) || in remove_adv_monitor()
5516 pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev) || in remove_adv_monitor()
5517 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR, hdev) || in remove_adv_monitor()
5518 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI, hdev)) { in remove_adv_monitor()
5523 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_ADV_MONITOR, hdev, data, len); in remove_adv_monitor()
5529 err = hci_cmd_sync_queue(hdev, mgmt_remove_adv_monitor_sync, cmd, in remove_adv_monitor()
5543 hci_dev_unlock(hdev); in remove_adv_monitor()
5548 hci_dev_unlock(hdev); in remove_adv_monitor()
5549 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, in remove_adv_monitor()
5553 static void read_local_oob_data_complete(struct hci_dev *hdev, void *data, int err) in read_local_oob_data_complete() argument
5570 bt_dev_dbg(hdev, "status %d", status); in read_local_oob_data_complete()
5573 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, status); in read_local_oob_data_complete()
5579 if (!bredr_sc_enabled(hdev)) { in read_local_oob_data_complete()
5583 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
5597 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
5610 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data_complete()
5620 static int read_local_oob_data_sync(struct hci_dev *hdev, void *data) in read_local_oob_data_sync() argument
5624 if (bredr_sc_enabled(hdev)) in read_local_oob_data_sync()
5625 cmd->skb = hci_read_local_oob_data_sync(hdev, true, cmd->sk); in read_local_oob_data_sync()
5627 cmd->skb = hci_read_local_oob_data_sync(hdev, false, cmd->sk); in read_local_oob_data_sync()
5635 static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_data() argument
5641 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_data()
5643 hci_dev_lock(hdev); in read_local_oob_data()
5645 if (!hdev_is_powered(hdev)) { in read_local_oob_data()
5646 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5651 if (!lmp_ssp_capable(hdev)) { in read_local_oob_data()
5652 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5657 cmd = mgmt_pending_new(sk, MGMT_OP_READ_LOCAL_OOB_DATA, hdev, NULL, 0); in read_local_oob_data()
5661 err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd, in read_local_oob_data()
5665 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5673 hci_dev_unlock(hdev); in read_local_oob_data()
5677 static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in add_remote_oob_data() argument
5683 bt_dev_dbg(hdev, "sock %p", sk); in add_remote_oob_data()
5686 return mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5691 hci_dev_lock(hdev); in add_remote_oob_data()
5698 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5705 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
5713 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5727 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5762 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
5770 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5774 bt_dev_err(hdev, "add_remote_oob_data: invalid len of %u bytes", in add_remote_oob_data()
5776 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, in add_remote_oob_data()
5781 hci_dev_unlock(hdev); in add_remote_oob_data()
5785 static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in remove_remote_oob_data() argument
5792 bt_dev_dbg(hdev, "sock %p", sk); in remove_remote_oob_data()
5795 return mgmt_cmd_complete(sk, hdev->id, in remove_remote_oob_data()
5800 hci_dev_lock(hdev); in remove_remote_oob_data()
5803 hci_remote_oob_data_clear(hdev); in remove_remote_oob_data()
5808 err = hci_remove_remote_oob_data(hdev, &cp->addr.bdaddr, cp->addr.type); in remove_remote_oob_data()
5815 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA, in remove_remote_oob_data()
5818 hci_dev_unlock(hdev); in remove_remote_oob_data()
5822 void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_start_discovery_complete() argument
5826 bt_dev_dbg(hdev, "status %u", status); in mgmt_start_discovery_complete()
5828 hci_dev_lock(hdev); in mgmt_start_discovery_complete()
5830 cmd = pending_find(MGMT_OP_START_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5832 cmd = pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5835 cmd = pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5842 hci_dev_unlock(hdev); in mgmt_start_discovery_complete()
5845 static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, in discovery_type_is_valid() argument
5850 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
5855 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
5860 *mgmt_status = mgmt_bredr_support(hdev); in discovery_type_is_valid()
5872 static void start_discovery_complete(struct hci_dev *hdev, void *data, int err) in start_discovery_complete() argument
5876 if (cmd != pending_find(MGMT_OP_START_DISCOVERY, hdev) && in start_discovery_complete()
5877 cmd != pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev) && in start_discovery_complete()
5878 cmd != pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev)) in start_discovery_complete()
5881 bt_dev_dbg(hdev, "err %d", err); in start_discovery_complete()
5887 hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED: in start_discovery_complete()
5891 static int start_discovery_sync(struct hci_dev *hdev, void *data) in start_discovery_sync() argument
5893 return hci_start_discovery_sync(hdev); in start_discovery_sync()
5896 static int start_discovery_internal(struct sock *sk, struct hci_dev *hdev, in start_discovery_internal() argument
5904 bt_dev_dbg(hdev, "sock %p", sk); in start_discovery_internal()
5906 hci_dev_lock(hdev); in start_discovery_internal()
5908 if (!hdev_is_powered(hdev)) { in start_discovery_internal()
5909 err = mgmt_cmd_complete(sk, hdev->id, op, in start_discovery_internal()
5915 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_discovery_internal()
5916 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_discovery_internal()
5917 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
5922 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_discovery_internal()
5923 err = mgmt_cmd_complete(sk, hdev->id, op, status, in start_discovery_internal()
5929 if (hdev->discovery_paused) { in start_discovery_internal()
5930 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
5938 hci_discovery_filter_clear(hdev); in start_discovery_internal()
5940 hdev->discovery.type = cp->type; in start_discovery_internal()
5941 hdev->discovery.report_invalid_rssi = false; in start_discovery_internal()
5943 hdev->discovery.limited = true; in start_discovery_internal()
5945 hdev->discovery.limited = false; in start_discovery_internal()
5947 cmd = mgmt_pending_add(sk, op, hdev, data, len); in start_discovery_internal()
5953 err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd, in start_discovery_internal()
5960 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_discovery_internal()
5963 hci_dev_unlock(hdev); in start_discovery_internal()
5967 static int start_discovery(struct sock *sk, struct hci_dev *hdev, in start_discovery() argument
5970 return start_discovery_internal(sk, hdev, MGMT_OP_START_DISCOVERY, in start_discovery()
5974 static int start_limited_discovery(struct sock *sk, struct hci_dev *hdev, in start_limited_discovery() argument
5977 return start_discovery_internal(sk, hdev, in start_limited_discovery()
5982 static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, in start_service_discovery() argument
5992 bt_dev_dbg(hdev, "sock %p", sk); in start_service_discovery()
5994 hci_dev_lock(hdev); in start_service_discovery()
5996 if (!hdev_is_powered(hdev)) { in start_service_discovery()
5997 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6004 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_service_discovery()
6005 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_service_discovery()
6006 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6013 if (hdev->discovery_paused) { in start_service_discovery()
6014 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6023 bt_dev_err(hdev, "service_discovery: too big uuid_count value %u", in start_service_discovery()
6025 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6034 bt_dev_err(hdev, "service_discovery: expected %u bytes, got %u bytes", in start_service_discovery()
6036 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6043 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_service_discovery()
6044 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6051 hdev, data, len); in start_service_discovery()
6060 hci_discovery_filter_clear(hdev); in start_service_discovery()
6062 hdev->discovery.result_filtering = true; in start_service_discovery()
6063 hdev->discovery.type = cp->type; in start_service_discovery()
6064 hdev->discovery.rssi = cp->rssi; in start_service_discovery()
6065 hdev->discovery.uuid_count = uuid_count; in start_service_discovery()
6068 hdev->discovery.uuids = kmemdup(cp->uuids, uuid_count * 16, in start_service_discovery()
6070 if (!hdev->discovery.uuids) { in start_service_discovery()
6071 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6080 err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd, in start_service_discovery()
6087 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_service_discovery()
6090 hci_dev_unlock(hdev); in start_service_discovery()
6094 void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_stop_discovery_complete() argument
6098 bt_dev_dbg(hdev, "status %u", status); in mgmt_stop_discovery_complete()
6100 hci_dev_lock(hdev); in mgmt_stop_discovery_complete()
6102 cmd = pending_find(MGMT_OP_STOP_DISCOVERY, hdev); in mgmt_stop_discovery_complete()
6108 hci_dev_unlock(hdev); in mgmt_stop_discovery_complete()
6111 static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) in stop_discovery_complete() argument
6115 if (cmd != pending_find(MGMT_OP_STOP_DISCOVERY, hdev)) in stop_discovery_complete()
6118 bt_dev_dbg(hdev, "err %d", err); in stop_discovery_complete()
6125 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in stop_discovery_complete()
6128 static int stop_discovery_sync(struct hci_dev *hdev, void *data) in stop_discovery_sync() argument
6130 return hci_stop_discovery_sync(hdev); in stop_discovery_sync()
6133 static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, in stop_discovery() argument
6140 bt_dev_dbg(hdev, "sock %p", sk); in stop_discovery()
6142 hci_dev_lock(hdev); in stop_discovery()
6144 if (!hci_discovery_active(hdev)) { in stop_discovery()
6145 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
6151 if (hdev->discovery.type != mgmt_cp->type) { in stop_discovery()
6152 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
6158 cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, hdev, data, len); in stop_discovery()
6164 err = hci_cmd_sync_queue(hdev, stop_discovery_sync, cmd, in stop_discovery()
6171 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in stop_discovery()
6174 hci_dev_unlock(hdev); in stop_discovery()
6178 static int confirm_name(struct sock *sk, struct hci_dev *hdev, void *data, in confirm_name() argument
6185 bt_dev_dbg(hdev, "sock %p", sk); in confirm_name()
6187 hci_dev_lock(hdev); in confirm_name()
6189 if (!hci_discovery_active(hdev)) { in confirm_name()
6190 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
6196 e = hci_inquiry_cache_lookup_unknown(hdev, &cp->addr.bdaddr); in confirm_name()
6198 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
6209 hci_inquiry_cache_update_resolve(hdev, e); in confirm_name()
6212 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, 0, in confirm_name()
6216 hci_dev_unlock(hdev); in confirm_name()
6220 static int block_device(struct sock *sk, struct hci_dev *hdev, void *data, in block_device() argument
6227 bt_dev_dbg(hdev, "sock %p", sk); in block_device()
6230 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, in block_device()
6234 hci_dev_lock(hdev); in block_device()
6236 err = hci_bdaddr_list_add(&hdev->reject_list, &cp->addr.bdaddr, in block_device()
6243 mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &cp->addr, sizeof(cp->addr), in block_device()
6248 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status, in block_device()
6251 hci_dev_unlock(hdev); in block_device()
6256 static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data, in unblock_device() argument
6263 bt_dev_dbg(hdev, "sock %p", sk); in unblock_device()
6266 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, in unblock_device()
6270 hci_dev_lock(hdev); in unblock_device()
6272 err = hci_bdaddr_list_del(&hdev->reject_list, &cp->addr.bdaddr, in unblock_device()
6279 mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &cp->addr, sizeof(cp->addr), in unblock_device()
6284 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status, in unblock_device()
6287 hci_dev_unlock(hdev); in unblock_device()
6292 static int set_device_id_sync(struct hci_dev *hdev, void *data) in set_device_id_sync() argument
6294 return hci_update_eir_sync(hdev); in set_device_id_sync()
6297 static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_id() argument
6304 bt_dev_dbg(hdev, "sock %p", sk); in set_device_id()
6309 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, in set_device_id()
6312 hci_dev_lock(hdev); in set_device_id()
6314 hdev->devid_source = source; in set_device_id()
6315 hdev->devid_vendor = __le16_to_cpu(cp->vendor); in set_device_id()
6316 hdev->devid_product = __le16_to_cpu(cp->product); in set_device_id()
6317 hdev->devid_version = __le16_to_cpu(cp->version); in set_device_id()
6319 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, 0, in set_device_id()
6322 hci_cmd_sync_queue(hdev, set_device_id_sync, NULL, NULL); in set_device_id()
6324 hci_dev_unlock(hdev); in set_device_id()
6329 static void enable_advertising_instance(struct hci_dev *hdev, int err) in enable_advertising_instance() argument
6332 bt_dev_err(hdev, "failed to re-configure advertising %d", err); in enable_advertising_instance()
6334 bt_dev_dbg(hdev, "status %d", err); in enable_advertising_instance()
6337 static void set_advertising_complete(struct hci_dev *hdev, void *data, int err) in set_advertising_complete() argument
6339 struct cmd_lookup match = { NULL, hdev }; in set_advertising_complete()
6345 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, in set_advertising_complete()
6350 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_advertising_complete()
6351 hci_dev_set_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
6353 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
6355 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, settings_rsp, in set_advertising_complete()
6358 new_settings(hdev, match.sk); in set_advertising_complete()
6366 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in set_advertising_complete()
6367 list_empty(&hdev->adv_instances)) in set_advertising_complete()
6370 instance = hdev->cur_adv_instance; in set_advertising_complete()
6372 adv_instance = list_first_entry_or_null(&hdev->adv_instances, in set_advertising_complete()
6380 err = hci_schedule_adv_instance_sync(hdev, instance, true); in set_advertising_complete()
6382 enable_advertising_instance(hdev, err); in set_advertising_complete()
6385 static int set_adv_sync(struct hci_dev *hdev, void *data) in set_adv_sync() argument
6392 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_adv_sync()
6394 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_adv_sync()
6396 cancel_adv_timeout(hdev); in set_adv_sync()
6403 hdev->cur_adv_instance = 0x00; in set_adv_sync()
6405 if (ext_adv_capable(hdev)) { in set_adv_sync()
6406 hci_start_ext_adv_sync(hdev, 0x00); in set_adv_sync()
6408 hci_update_adv_data_sync(hdev, 0x00); in set_adv_sync()
6409 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_adv_sync()
6410 hci_enable_advertising_sync(hdev); in set_adv_sync()
6413 hci_disable_advertising_sync(hdev); in set_adv_sync()
6419 static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, in set_advertising() argument
6427 bt_dev_dbg(hdev, "sock %p", sk); in set_advertising()
6429 status = mgmt_le_support(hdev); in set_advertising()
6431 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6435 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6438 if (hdev->advertising_paused) in set_advertising()
6439 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6442 hci_dev_lock(hdev); in set_advertising()
6451 if (!hdev_is_powered(hdev) || in set_advertising()
6452 (val == hci_dev_test_flag(hdev, HCI_ADVERTISING) && in set_advertising()
6453 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) || in set_advertising()
6454 hci_dev_test_flag(hdev, HCI_MESH) || in set_advertising()
6455 hci_conn_num(hdev, LE_LINK) > 0 || in set_advertising()
6456 (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_advertising()
6457 hdev->le_scan_type == LE_SCAN_ACTIVE)) { in set_advertising()
6461 hdev->cur_adv_instance = 0x00; in set_advertising()
6462 changed = !hci_dev_test_and_set_flag(hdev, HCI_ADVERTISING); in set_advertising()
6464 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6466 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6468 changed = hci_dev_test_and_clear_flag(hdev, HCI_ADVERTISING); in set_advertising()
6469 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6472 err = send_settings_rsp(sk, MGMT_OP_SET_ADVERTISING, hdev); in set_advertising()
6477 err = new_settings(hdev, sk); in set_advertising()
6482 if (pending_find(MGMT_OP_SET_ADVERTISING, hdev) || in set_advertising()
6483 pending_find(MGMT_OP_SET_LE, hdev)) { in set_advertising()
6484 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6489 cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING, hdev, data, len); in set_advertising()
6493 err = hci_cmd_sync_queue(hdev, set_adv_sync, cmd, in set_advertising()
6500 hci_dev_unlock(hdev); in set_advertising()
6504 static int set_static_address(struct sock *sk, struct hci_dev *hdev, in set_static_address() argument
6510 bt_dev_dbg(hdev, "sock %p", sk); in set_static_address()
6512 if (!lmp_le_capable(hdev)) in set_static_address()
6513 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
6516 if (hdev_is_powered(hdev)) in set_static_address()
6517 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
6522 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
6528 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
6533 hci_dev_lock(hdev); in set_static_address()
6535 bacpy(&hdev->static_addr, &cp->bdaddr); in set_static_address()
6537 err = send_settings_rsp(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev); in set_static_address()
6541 err = new_settings(hdev, sk); in set_static_address()
6544 hci_dev_unlock(hdev); in set_static_address()
6548 static int set_scan_params(struct sock *sk, struct hci_dev *hdev, in set_scan_params() argument
6555 bt_dev_dbg(hdev, "sock %p", sk); in set_scan_params()
6557 if (!lmp_le_capable(hdev)) in set_scan_params()
6558 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6564 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6570 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6574 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6577 hci_dev_lock(hdev); in set_scan_params()
6579 hdev->le_scan_interval = interval; in set_scan_params()
6580 hdev->le_scan_window = window; in set_scan_params()
6582 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, 0, in set_scan_params()
6588 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_scan_params()
6589 hdev->discovery.state == DISCOVERY_STOPPED) in set_scan_params()
6590 hci_update_passive_scan(hdev); in set_scan_params()
6592 hci_dev_unlock(hdev); in set_scan_params()
6597 static void fast_connectable_complete(struct hci_dev *hdev, void *data, int err) in fast_connectable_complete() argument
6601 bt_dev_dbg(hdev, "err %d", err); in fast_connectable_complete()
6604 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in fast_connectable_complete()
6610 hci_dev_set_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
6612 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
6614 send_settings_rsp(cmd->sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in fast_connectable_complete()
6615 new_settings(hdev, cmd->sk); in fast_connectable_complete()
6621 static int write_fast_connectable_sync(struct hci_dev *hdev, void *data) in write_fast_connectable_sync() argument
6626 return hci_write_fast_connectable_sync(hdev, cp->val); in write_fast_connectable_sync()
6629 static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev, in set_fast_connectable() argument
6636 bt_dev_dbg(hdev, "sock %p", sk); in set_fast_connectable()
6638 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in set_fast_connectable()
6639 hdev->hci_ver < BLUETOOTH_VER_1_2) in set_fast_connectable()
6640 return mgmt_cmd_status(sk, hdev->id, in set_fast_connectable()
6645 return mgmt_cmd_status(sk, hdev->id, in set_fast_connectable()
6649 hci_dev_lock(hdev); in set_fast_connectable()
6651 if (!!cp->val == hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) { in set_fast_connectable()
6652 err = send_settings_rsp(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in set_fast_connectable()
6656 if (!hdev_is_powered(hdev)) { in set_fast_connectable()
6657 hci_dev_change_flag(hdev, HCI_FAST_CONNECTABLE); in set_fast_connectable()
6658 err = send_settings_rsp(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in set_fast_connectable()
6659 new_settings(hdev, sk); in set_fast_connectable()
6663 cmd = mgmt_pending_new(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev, data, in set_fast_connectable()
6668 err = hci_cmd_sync_queue(hdev, write_fast_connectable_sync, cmd, in set_fast_connectable()
6672 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
6680 hci_dev_unlock(hdev); in set_fast_connectable()
6685 static void set_bredr_complete(struct hci_dev *hdev, void *data, int err) in set_bredr_complete() argument
6689 bt_dev_dbg(hdev, "err %d", err); in set_bredr_complete()
6697 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in set_bredr_complete()
6701 send_settings_rsp(cmd->sk, MGMT_OP_SET_BREDR, hdev); in set_bredr_complete()
6702 new_settings(hdev, cmd->sk); in set_bredr_complete()
6708 static int set_bredr_sync(struct hci_dev *hdev, void *data) in set_bredr_sync() argument
6712 status = hci_write_fast_connectable_sync(hdev, false); in set_bredr_sync()
6715 status = hci_update_scan_sync(hdev); in set_bredr_sync()
6721 status = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in set_bredr_sync()
6726 static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_bredr() argument
6732 bt_dev_dbg(hdev, "sock %p", sk); in set_bredr()
6734 if (!lmp_bredr_capable(hdev) || !lmp_le_capable(hdev)) in set_bredr()
6735 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6738 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_bredr()
6739 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6743 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6746 hci_dev_lock(hdev); in set_bredr()
6748 if (cp->val == hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_bredr()
6749 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
6753 if (!hdev_is_powered(hdev)) { in set_bredr()
6755 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_bredr()
6756 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_bredr()
6757 hci_dev_clear_flag(hdev, HCI_LINK_SECURITY); in set_bredr()
6758 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in set_bredr()
6759 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_bredr()
6762 hci_dev_change_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
6764 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
6768 err = new_settings(hdev, sk); in set_bredr()
6774 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6792 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_bredr()
6793 (bacmp(&hdev->static_addr, BDADDR_ANY) || in set_bredr()
6794 hci_dev_test_flag(hdev, HCI_SC_ENABLED))) { in set_bredr()
6795 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6801 cmd = mgmt_pending_new(sk, MGMT_OP_SET_BREDR, hdev, data, len); in set_bredr()
6805 err = hci_cmd_sync_queue(hdev, set_bredr_sync, cmd, in set_bredr()
6809 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6820 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
6823 hci_dev_unlock(hdev); in set_bredr()
6827 static void set_secure_conn_complete(struct hci_dev *hdev, void *data, int err) in set_secure_conn_complete() argument
6832 bt_dev_dbg(hdev, "err %d", err); in set_secure_conn_complete()
6845 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6846 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6849 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6850 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6853 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6854 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6858 send_settings_rsp(cmd->sk, cmd->opcode, hdev); in set_secure_conn_complete()
6859 new_settings(hdev, cmd->sk); in set_secure_conn_complete()
6865 static int set_secure_conn_sync(struct hci_dev *hdev, void *data) in set_secure_conn_sync() argument
6872 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_sync()
6874 return hci_write_sc_support_sync(hdev, val); in set_secure_conn_sync()
6877 static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, in set_secure_conn() argument
6885 bt_dev_dbg(hdev, "sock %p", sk); in set_secure_conn()
6887 if (!lmp_sc_capable(hdev) && in set_secure_conn()
6888 !hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_secure_conn()
6889 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6892 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_secure_conn()
6893 lmp_sc_capable(hdev) && in set_secure_conn()
6894 !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_secure_conn()
6895 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6899 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6902 hci_dev_lock(hdev); in set_secure_conn()
6904 if (!hdev_is_powered(hdev) || !lmp_sc_capable(hdev) || in set_secure_conn()
6905 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_secure_conn()
6909 changed = !hci_dev_test_and_set_flag(hdev, in set_secure_conn()
6912 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6914 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6916 changed = hci_dev_test_and_clear_flag(hdev, in set_secure_conn()
6918 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6921 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
6926 err = new_settings(hdev, sk); in set_secure_conn()
6933 if (val == hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in set_secure_conn()
6934 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in set_secure_conn()
6935 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
6939 cmd = mgmt_pending_new(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len); in set_secure_conn()
6943 err = hci_cmd_sync_queue(hdev, set_secure_conn_sync, cmd, in set_secure_conn()
6947 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6954 hci_dev_unlock(hdev); in set_secure_conn()
6958 static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, in set_debug_keys() argument
6965 bt_dev_dbg(hdev, "sock %p", sk); in set_debug_keys()
6968 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEBUG_KEYS, in set_debug_keys()
6971 hci_dev_lock(hdev); in set_debug_keys()
6974 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in set_debug_keys()
6976 changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
6980 use_changed = !hci_dev_test_and_set_flag(hdev, in set_debug_keys()
6983 use_changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
6986 if (hdev_is_powered(hdev) && use_changed && in set_debug_keys()
6987 hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_debug_keys()
6989 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in set_debug_keys()
6993 err = send_settings_rsp(sk, MGMT_OP_SET_DEBUG_KEYS, hdev); in set_debug_keys()
6998 err = new_settings(hdev, sk); in set_debug_keys()
7001 hci_dev_unlock(hdev); in set_debug_keys()
7005 static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data, in set_privacy() argument
7012 bt_dev_dbg(hdev, "sock %p", sk); in set_privacy()
7014 if (!lmp_le_capable(hdev)) in set_privacy()
7015 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
7019 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
7022 if (hdev_is_powered(hdev)) in set_privacy()
7023 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
7026 hci_dev_lock(hdev); in set_privacy()
7031 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in set_privacy()
7034 changed = !hci_dev_test_and_set_flag(hdev, HCI_PRIVACY); in set_privacy()
7035 memcpy(hdev->irk, cp->irk, sizeof(hdev->irk)); in set_privacy()
7036 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
7037 hci_adv_instances_set_rpa_expired(hdev, true); in set_privacy()
7039 hci_dev_set_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
7041 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
7043 changed = hci_dev_test_and_clear_flag(hdev, HCI_PRIVACY); in set_privacy()
7044 memset(hdev->irk, 0, sizeof(hdev->irk)); in set_privacy()
7045 hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
7046 hci_adv_instances_set_rpa_expired(hdev, false); in set_privacy()
7047 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
7050 err = send_settings_rsp(sk, MGMT_OP_SET_PRIVACY, hdev); in set_privacy()
7055 err = new_settings(hdev, sk); in set_privacy()
7058 hci_dev_unlock(hdev); in set_privacy()
7078 static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data, in load_irks() argument
7087 bt_dev_dbg(hdev, "sock %p", sk); in load_irks()
7089 if (!lmp_le_capable(hdev)) in load_irks()
7090 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7095 bt_dev_err(hdev, "load_irks: too big irk_count value %u", in load_irks()
7097 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7103 bt_dev_err(hdev, "load_irks: expected %u bytes, got %u bytes", in load_irks()
7105 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7109 bt_dev_dbg(hdev, "irk_count %u", irk_count); in load_irks()
7115 return mgmt_cmd_status(sk, hdev->id, in load_irks()
7120 hci_dev_lock(hdev); in load_irks()
7122 hci_smp_irks_clear(hdev); in load_irks()
7127 if (hci_is_blocked_key(hdev, in load_irks()
7130 bt_dev_warn(hdev, "Skipping blocked IRK for %pMR", in load_irks()
7135 hci_add_irk(hdev, &irk->addr.bdaddr, in load_irks()
7140 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in load_irks()
7142 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_IRKS, 0, NULL, 0); in load_irks()
7144 hci_dev_unlock(hdev); in load_irks()
7168 static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev, in load_long_term_keys() argument
7177 bt_dev_dbg(hdev, "sock %p", sk); in load_long_term_keys()
7179 if (!lmp_le_capable(hdev)) in load_long_term_keys()
7180 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7185 bt_dev_err(hdev, "load_ltks: too big key_count value %u", in load_long_term_keys()
7187 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7193 bt_dev_err(hdev, "load_keys: expected %u bytes, got %u bytes", in load_long_term_keys()
7195 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7199 bt_dev_dbg(hdev, "key_count %u", key_count); in load_long_term_keys()
7205 return mgmt_cmd_status(sk, hdev->id, in load_long_term_keys()
7210 hci_dev_lock(hdev); in load_long_term_keys()
7212 hci_smp_ltks_clear(hdev); in load_long_term_keys()
7218 if (hci_is_blocked_key(hdev, in load_long_term_keys()
7221 bt_dev_warn(hdev, "Skipping blocked LTK for %pMR", in load_long_term_keys()
7251 hci_add_ltk(hdev, &key->addr.bdaddr, in load_long_term_keys()
7256 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 0, in load_long_term_keys()
7259 hci_dev_unlock(hdev); in load_long_term_keys()
7264 static void get_conn_info_complete(struct hci_dev *hdev, void *data, int err) in get_conn_info_complete() argument
7272 bt_dev_dbg(hdev, "err %d", err); in get_conn_info_complete()
7293 static int get_conn_info_sync(struct hci_dev *hdev, void *data) in get_conn_info_sync() argument
7303 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info_sync()
7306 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info_sync()
7315 err = hci_read_rssi_sync(hdev, handle); in get_conn_info_sync()
7322 err = hci_read_tx_power_sync(hdev, handle, 0x00); in get_conn_info_sync()
7326 err = hci_read_tx_power_sync(hdev, handle, 0x01); in get_conn_info_sync()
7331 static int get_conn_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_conn_info() argument
7340 bt_dev_dbg(hdev, "sock %p", sk); in get_conn_info()
7347 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7351 hci_dev_lock(hdev); in get_conn_info()
7353 if (!hdev_is_powered(hdev)) { in get_conn_info()
7354 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7361 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info()
7364 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info()
7367 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7376 conn_info_age = hdev->conn_info_min_age + in get_conn_info()
7377 prandom_u32_max(hdev->conn_info_max_age - in get_conn_info()
7378 hdev->conn_info_min_age); in get_conn_info()
7388 cmd = mgmt_pending_new(sk, MGMT_OP_GET_CONN_INFO, hdev, data, in get_conn_info()
7393 err = hci_cmd_sync_queue(hdev, get_conn_info_sync, in get_conn_info()
7398 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7414 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7419 hci_dev_unlock(hdev); in get_conn_info()
7423 static void get_clock_info_complete(struct hci_dev *hdev, void *data, int err) in get_clock_info_complete() argument
7431 bt_dev_dbg(hdev, "err %d", err); in get_clock_info_complete()
7440 rp.local_clock = cpu_to_le32(hdev->clock); in get_clock_info_complete()
7454 static int get_clock_info_sync(struct hci_dev *hdev, void *data) in get_clock_info_sync() argument
7462 hci_read_clock_sync(hdev, &hci_cp); in get_clock_info_sync()
7465 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in get_clock_info_sync()
7473 return hci_read_clock_sync(hdev, &hci_cp); in get_clock_info_sync()
7476 static int get_clock_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_clock_info() argument
7485 bt_dev_dbg(hdev, "sock %p", sk); in get_clock_info()
7492 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7496 hci_dev_lock(hdev); in get_clock_info()
7498 if (!hdev_is_powered(hdev)) { in get_clock_info()
7499 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7506 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_clock_info()
7509 err = mgmt_cmd_complete(sk, hdev->id, in get_clock_info()
7519 cmd = mgmt_pending_new(sk, MGMT_OP_GET_CLOCK_INFO, hdev, data, len); in get_clock_info()
7523 err = hci_cmd_sync_queue(hdev, get_clock_info_sync, cmd, in get_clock_info()
7527 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7536 hci_dev_unlock(hdev); in get_clock_info()
7540 static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type) in is_connected() argument
7544 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, addr); in is_connected()
7558 static int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, in hci_conn_params_set() argument
7563 params = hci_conn_params_add(hdev, addr, addr_type); in hci_conn_params_set()
7579 list_add(¶ms->action, &hdev->pend_le_conns); in hci_conn_params_set()
7583 list_add(¶ms->action, &hdev->pend_le_conns); in hci_conn_params_set()
7585 list_add(¶ms->action, &hdev->pend_le_reports); in hci_conn_params_set()
7589 if (!is_connected(hdev, addr, addr_type)) in hci_conn_params_set()
7590 list_add(¶ms->action, &hdev->pend_le_conns); in hci_conn_params_set()
7596 bt_dev_dbg(hdev, "addr %pMR (type %u) auto_connect %u", in hci_conn_params_set()
7602 static void device_added(struct sock *sk, struct hci_dev *hdev, in device_added() argument
7611 mgmt_event(MGMT_EV_DEVICE_ADDED, hdev, &ev, sizeof(ev), sk); in device_added()
7614 static int add_device_sync(struct hci_dev *hdev, void *data) in add_device_sync() argument
7616 return hci_update_passive_scan_sync(hdev); in add_device_sync()
7619 static int add_device(struct sock *sk, struct hci_dev *hdev, in add_device() argument
7629 bt_dev_dbg(hdev, "sock %p", sk); in add_device()
7633 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7638 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7642 hci_dev_lock(hdev); in add_device()
7647 err = mgmt_cmd_complete(sk, hdev->id, in add_device()
7654 err = hci_bdaddr_list_add_with_flags(&hdev->accept_list, in add_device()
7660 hci_update_scan(hdev); in add_device()
7680 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7689 if (hci_conn_params_set(hdev, &cp->addr.bdaddr, addr_type, in add_device()
7691 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7696 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in add_device()
7702 err = hci_cmd_sync_queue(hdev, add_device_sync, NULL, NULL); in add_device()
7707 device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action); in add_device()
7708 supported_flags = hdev->conn_flags; in add_device()
7709 device_flags_changed(NULL, hdev, &cp->addr.bdaddr, cp->addr.type, in add_device()
7712 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7717 hci_dev_unlock(hdev); in add_device()
7721 static void device_removed(struct sock *sk, struct hci_dev *hdev, in device_removed() argument
7729 mgmt_event(MGMT_EV_DEVICE_REMOVED, hdev, &ev, sizeof(ev), sk); in device_removed()
7732 static int remove_device_sync(struct hci_dev *hdev, void *data) in remove_device_sync() argument
7734 return hci_update_passive_scan_sync(hdev); in remove_device_sync()
7737 static int remove_device(struct sock *sk, struct hci_dev *hdev, in remove_device() argument
7743 bt_dev_dbg(hdev, "sock %p", sk); in remove_device()
7745 hci_dev_lock(hdev); in remove_device()
7752 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7760 err = hci_bdaddr_list_del(&hdev->accept_list, in remove_device()
7764 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7772 hci_update_scan(hdev); in remove_device()
7774 device_removed(sk, hdev, &cp->addr.bdaddr, in remove_device()
7787 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7794 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in remove_device()
7797 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7806 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7817 device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type); in remove_device()
7823 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7830 list_for_each_entry_safe(b, btmp, &hdev->accept_list, list) { in remove_device()
7831 device_removed(sk, hdev, &b->bdaddr, b->bdaddr_type); in remove_device()
7836 hci_update_scan(hdev); in remove_device()
7838 list_for_each_entry_safe(p, tmp, &hdev->le_conn_params, list) { in remove_device()
7841 device_removed(sk, hdev, &p->addr, p->addr_type); in remove_device()
7851 bt_dev_dbg(hdev, "All LE connection parameters were removed"); in remove_device()
7854 hci_cmd_sync_queue(hdev, remove_device_sync, NULL, NULL); in remove_device()
7857 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, in remove_device()
7861 hci_dev_unlock(hdev); in remove_device()
7865 static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data, in load_conn_param() argument
7874 if (!lmp_le_capable(hdev)) in load_conn_param()
7875 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7880 bt_dev_err(hdev, "load_conn_param: too big param_count value %u", in load_conn_param()
7882 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7888 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes", in load_conn_param()
7890 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7894 bt_dev_dbg(hdev, "param_count %u", param_count); in load_conn_param()
7896 hci_dev_lock(hdev); in load_conn_param()
7898 hci_conn_params_clear_disabled(hdev); in load_conn_param()
7906 bt_dev_dbg(hdev, "Adding %pMR (type %u)", ¶m->addr.bdaddr, in load_conn_param()
7914 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
7923 bt_dev_dbg(hdev, "min 0x%04x max 0x%04x latency 0x%04x timeout 0x%04x", in load_conn_param()
7927 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
7931 hci_param = hci_conn_params_add(hdev, ¶m->addr.bdaddr, in load_conn_param()
7934 bt_dev_err(hdev, "failed to add connection parameters"); in load_conn_param()
7944 hci_dev_unlock(hdev); in load_conn_param()
7946 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 0, in load_conn_param()
7950 static int set_external_config(struct sock *sk, struct hci_dev *hdev, in set_external_config() argument
7957 bt_dev_dbg(hdev, "sock %p", sk); in set_external_config()
7959 if (hdev_is_powered(hdev)) in set_external_config()
7960 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7964 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7967 if (!test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in set_external_config()
7968 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7971 hci_dev_lock(hdev); in set_external_config()
7974 changed = !hci_dev_test_and_set_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
7976 changed = hci_dev_test_and_clear_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
7978 err = send_options_rsp(sk, MGMT_OP_SET_EXTERNAL_CONFIG, hdev); in set_external_config()
7985 err = new_options(hdev, sk); in set_external_config()
7987 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) == is_configured(hdev)) { in set_external_config()
7988 mgmt_index_removed(hdev); in set_external_config()
7990 if (hci_dev_test_and_change_flag(hdev, HCI_UNCONFIGURED)) { in set_external_config()
7991 hci_dev_set_flag(hdev, HCI_CONFIG); in set_external_config()
7992 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_external_config()
7994 queue_work(hdev->req_workqueue, &hdev->power_on); in set_external_config()
7996 set_bit(HCI_RAW, &hdev->flags); in set_external_config()
7997 mgmt_index_added(hdev); in set_external_config()
8002 hci_dev_unlock(hdev); in set_external_config()
8006 static int set_public_address(struct sock *sk, struct hci_dev *hdev, in set_public_address() argument
8013 bt_dev_dbg(hdev, "sock %p", sk); in set_public_address()
8015 if (hdev_is_powered(hdev)) in set_public_address()
8016 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8020 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8023 if (!hdev->set_bdaddr) in set_public_address()
8024 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8027 hci_dev_lock(hdev); in set_public_address()
8029 changed = !!bacmp(&hdev->public_addr, &cp->bdaddr); in set_public_address()
8030 bacpy(&hdev->public_addr, &cp->bdaddr); in set_public_address()
8032 err = send_options_rsp(sk, MGMT_OP_SET_PUBLIC_ADDRESS, hdev); in set_public_address()
8039 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in set_public_address()
8040 err = new_options(hdev, sk); in set_public_address()
8042 if (is_configured(hdev)) { in set_public_address()
8043 mgmt_index_removed(hdev); in set_public_address()
8045 hci_dev_clear_flag(hdev, HCI_UNCONFIGURED); in set_public_address()
8047 hci_dev_set_flag(hdev, HCI_CONFIG); in set_public_address()
8048 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_public_address()
8050 queue_work(hdev->req_workqueue, &hdev->power_on); in set_public_address()
8054 hci_dev_unlock(hdev); in set_public_address()
8058 static void read_local_oob_ext_data_complete(struct hci_dev *hdev, void *data, in read_local_oob_ext_data_complete() argument
8069 if (cmd != pending_find(MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev)) in read_local_oob_ext_data_complete()
8081 bt_dev_dbg(hdev, "status %u", status); in read_local_oob_ext_data_complete()
8093 } else if (!bredr_sc_enabled(hdev)) { in read_local_oob_ext_data_complete()
8119 if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in read_local_oob_ext_data_complete()
8142 hdev->dev_class, 3); in read_local_oob_ext_data_complete()
8162 err = mgmt_cmd_complete(cmd->sk, hdev->id, in read_local_oob_ext_data_complete()
8170 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data_complete()
8181 static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk, in read_local_ssp_oob_req() argument
8187 cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev, in read_local_ssp_oob_req()
8192 err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd, in read_local_ssp_oob_req()
8203 static int read_local_oob_ext_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_ext_data() argument
8213 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_ext_data()
8215 if (hdev_is_powered(hdev)) { in read_local_oob_ext_data()
8218 status = mgmt_bredr_support(hdev); in read_local_oob_ext_data()
8225 status = mgmt_le_support(hdev); in read_local_oob_ext_data()
8246 if (!status && !lmp_ssp_capable(hdev)) { in read_local_oob_ext_data()
8254 hci_dev_lock(hdev); in read_local_oob_ext_data()
8259 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in read_local_oob_ext_data()
8260 err = read_local_ssp_oob_req(hdev, sk, cp); in read_local_oob_ext_data()
8261 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8270 hdev->dev_class, 3); in read_local_oob_ext_data()
8274 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in read_local_oob_ext_data()
8275 smp_generate_oob(hdev, hash, rand) < 0) { in read_local_oob_ext_data()
8276 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8291 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { in read_local_oob_ext_data()
8292 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8297 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in read_local_oob_ext_data()
8298 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in read_local_oob_ext_data()
8299 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in read_local_oob_ext_data()
8300 bacmp(&hdev->static_addr, BDADDR_ANY))) { in read_local_oob_ext_data()
8301 memcpy(addr, &hdev->static_addr, 6); in read_local_oob_ext_data()
8304 memcpy(addr, &hdev->bdaddr, 6); in read_local_oob_ext_data()
8311 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in read_local_oob_ext_data()
8319 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) { in read_local_oob_ext_data()
8329 flags = mgmt_get_adv_discov_flags(hdev); in read_local_oob_ext_data()
8331 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in read_local_oob_ext_data()
8339 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8349 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, in read_local_oob_ext_data()
8354 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data()
8364 static u32 get_supported_adv_flags(struct hci_dev *hdev) in get_supported_adv_flags() argument
8383 if (hdev->adv_tx_power != HCI_TX_POWER_INVALID || ext_adv_capable(hdev)) in get_supported_adv_flags()
8386 if (ext_adv_capable(hdev)) { in get_supported_adv_flags()
8391 if (hdev->le_features[1] & HCI_LE_PHY_2M) in get_supported_adv_flags()
8394 if (hdev->le_features[1] & HCI_LE_PHY_CODED) in get_supported_adv_flags()
8401 static int read_adv_features(struct sock *sk, struct hci_dev *hdev, in read_adv_features() argument
8411 bt_dev_dbg(hdev, "sock %p", sk); in read_adv_features()
8413 if (!lmp_le_capable(hdev)) in read_adv_features()
8414 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
8417 hci_dev_lock(hdev); in read_adv_features()
8419 rp_len = sizeof(*rp) + hdev->adv_instance_cnt; in read_adv_features()
8422 hci_dev_unlock(hdev); in read_adv_features()
8426 supported_flags = get_supported_adv_flags(hdev); in read_adv_features()
8431 rp->max_instances = hdev->le_num_of_adv_sets; in read_adv_features()
8432 rp->num_instances = hdev->adv_instance_cnt; in read_adv_features()
8435 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in read_adv_features()
8437 if (adv_instance->instance <= hdev->adv_instance_cnt) { in read_adv_features()
8446 hci_dev_unlock(hdev); in read_adv_features()
8448 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
8456 static u8 calculate_name_len(struct hci_dev *hdev) in calculate_name_len() argument
8460 return eir_append_local_name(hdev, buf, 0); in calculate_name_len()
8463 static u8 tlv_data_max_len(struct hci_dev *hdev, u32 adv_flags, in tlv_data_max_len() argument
8478 max_len -= calculate_name_len(hdev); in tlv_data_max_len()
8509 static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data, in tlv_data_is_valid() argument
8515 max_len = tlv_data_max_len(hdev, adv_flags, is_adv_data); in tlv_data_is_valid()
8554 static bool requested_adv_flags_are_valid(struct hci_dev *hdev, u32 adv_flags) in requested_adv_flags_are_valid() argument
8561 supported_flags = get_supported_adv_flags(hdev); in requested_adv_flags_are_valid()
8570 static bool adv_busy(struct hci_dev *hdev) in adv_busy() argument
8572 return pending_find(MGMT_OP_SET_LE, hdev); in adv_busy()
8575 static void add_adv_complete(struct hci_dev *hdev, struct sock *sk, u8 instance, in add_adv_complete() argument
8580 bt_dev_dbg(hdev, "err %d", err); in add_adv_complete()
8582 hci_dev_lock(hdev); in add_adv_complete()
8584 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in add_adv_complete()
8597 if (hdev->cur_adv_instance == instance) in add_adv_complete()
8598 cancel_adv_timeout(hdev); in add_adv_complete()
8600 hci_remove_adv_instance(hdev, instance); in add_adv_complete()
8601 mgmt_advertising_removed(sk, hdev, instance); in add_adv_complete()
8604 hci_dev_unlock(hdev); in add_adv_complete()
8607 static void add_advertising_complete(struct hci_dev *hdev, void *data, int err) in add_advertising_complete() argument
8624 add_adv_complete(hdev, cmd->sk, cp->instance, err); in add_advertising_complete()
8629 static int add_advertising_sync(struct hci_dev *hdev, void *data) in add_advertising_sync() argument
8634 return hci_schedule_adv_instance_sync(hdev, cp->instance, true); in add_advertising_sync()
8637 static int add_advertising(struct sock *sk, struct hci_dev *hdev, in add_advertising() argument
8651 bt_dev_dbg(hdev, "sock %p", sk); in add_advertising()
8653 status = mgmt_le_support(hdev); in add_advertising()
8655 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8658 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_advertising()
8659 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8663 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8670 if (!requested_adv_flags_are_valid(hdev, flags)) in add_advertising()
8671 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8674 hci_dev_lock(hdev); in add_advertising()
8676 if (timeout && !hdev_is_powered(hdev)) { in add_advertising()
8677 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8682 if (adv_busy(hdev)) { in add_advertising()
8683 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8688 if (!tlv_data_is_valid(hdev, flags, cp->data, cp->adv_data_len, true) || in add_advertising()
8689 !tlv_data_is_valid(hdev, flags, cp->data + cp->adv_data_len, in add_advertising()
8691 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8696 prev_instance_cnt = hdev->adv_instance_cnt; in add_advertising()
8698 adv = hci_add_adv_instance(hdev, cp->instance, flags, in add_advertising()
8704 hdev->le_adv_min_interval, in add_advertising()
8705 hdev->le_adv_max_interval, 0); in add_advertising()
8707 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8715 if (hdev->adv_instance_cnt > prev_instance_cnt) in add_advertising()
8716 mgmt_advertising_added(sk, hdev, cp->instance); in add_advertising()
8718 if (hdev->cur_adv_instance == cp->instance) { in add_advertising()
8724 cancel_adv_timeout(hdev); in add_advertising()
8726 next_instance = hci_get_next_instance(hdev, cp->instance); in add_advertising()
8729 } else if (!hdev->adv_instance_timeout) { in add_advertising()
8740 if (!hdev_is_powered(hdev) || in add_advertising()
8741 hci_dev_test_flag(hdev, HCI_ADVERTISING) || in add_advertising()
8744 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8752 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_ADVERTISING, hdev, data, in add_advertising()
8761 err = hci_cmd_sync_queue(hdev, add_advertising_sync, cmd, in add_advertising()
8767 hci_dev_unlock(hdev); in add_advertising()
8772 static void add_ext_adv_params_complete(struct hci_dev *hdev, void *data, in add_ext_adv_params_complete() argument
8781 BT_DBG("%s", hdev->name); in add_ext_adv_params_complete()
8783 hci_dev_lock(hdev); in add_ext_adv_params_complete()
8785 adv = hci_find_adv_instance(hdev, cp->instance); in add_ext_adv_params_complete()
8796 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in add_ext_adv_params_complete()
8797 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in add_ext_adv_params_complete()
8805 mgmt_advertising_removed(cmd->sk, hdev, cp->instance); in add_ext_adv_params_complete()
8807 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_params_complete()
8820 hci_dev_unlock(hdev); in add_ext_adv_params_complete()
8823 static int add_ext_adv_params_sync(struct hci_dev *hdev, void *data) in add_ext_adv_params_sync() argument
8828 return hci_setup_ext_adv_instance_sync(hdev, cp->instance); in add_ext_adv_params_sync()
8831 static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev, in add_ext_adv_params() argument
8844 BT_DBG("%s", hdev->name); in add_ext_adv_params()
8846 status = mgmt_le_support(hdev); in add_ext_adv_params()
8848 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8851 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_ext_adv_params()
8852 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8862 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_ext_adv_params()
8867 if (!requested_adv_flags_are_valid(hdev, flags)) in add_ext_adv_params()
8868 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8871 hci_dev_lock(hdev); in add_ext_adv_params()
8874 if (!hdev_is_powered(hdev)) { in add_ext_adv_params()
8875 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8880 if (adv_busy(hdev)) { in add_ext_adv_params()
8881 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8892 hdev->def_multi_adv_rotation_duration; in add_ext_adv_params()
8896 hdev->le_adv_min_interval; in add_ext_adv_params()
8900 hdev->le_adv_max_interval; in add_ext_adv_params()
8907 adv = hci_add_adv_instance(hdev, cp->instance, flags, 0, NULL, 0, NULL, in add_ext_adv_params()
8912 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8918 if (ext_adv_capable(hdev)) { in add_ext_adv_params()
8919 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_EXT_ADV_PARAMS, hdev, in add_ext_adv_params()
8923 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_params()
8927 err = hci_cmd_sync_queue(hdev, add_ext_adv_params_sync, cmd, in add_ext_adv_params()
8934 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in add_ext_adv_params()
8935 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in add_ext_adv_params()
8936 err = mgmt_cmd_complete(sk, hdev->id, in add_ext_adv_params()
8942 hci_dev_unlock(hdev); in add_ext_adv_params()
8947 static void add_ext_adv_data_complete(struct hci_dev *hdev, void *data, int err) in add_ext_adv_data_complete() argument
8953 add_adv_complete(hdev, cmd->sk, cp->instance, err); in add_ext_adv_data_complete()
8969 static int add_ext_adv_data_sync(struct hci_dev *hdev, void *data) in add_ext_adv_data_sync() argument
8975 if (ext_adv_capable(hdev)) { in add_ext_adv_data_sync()
8976 err = hci_update_adv_data_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8980 err = hci_update_scan_rsp_data_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8984 return hci_enable_ext_advertising_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8987 return hci_schedule_adv_instance_sync(hdev, cp->instance, true); in add_ext_adv_data_sync()
8990 static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data, in add_ext_adv_data() argument
9001 BT_DBG("%s", hdev->name); in add_ext_adv_data()
9003 hci_dev_lock(hdev); in add_ext_adv_data()
9005 adv_instance = hci_find_adv_instance(hdev, cp->instance); in add_ext_adv_data()
9008 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9014 if (!hdev_is_powered(hdev)) { in add_ext_adv_data()
9015 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9020 if (adv_busy(hdev)) { in add_ext_adv_data()
9021 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9027 if (!tlv_data_is_valid(hdev, adv_instance->flags, cp->data, in add_ext_adv_data()
9029 !tlv_data_is_valid(hdev, adv_instance->flags, cp->data + in add_ext_adv_data()
9031 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9037 hci_set_adv_instance_data(hdev, cp->instance, cp->adv_data_len, in add_ext_adv_data()
9042 if (hdev->cur_adv_instance == cp->instance) { in add_ext_adv_data()
9049 cancel_adv_timeout(hdev); in add_ext_adv_data()
9051 next_instance = hci_get_next_instance(hdev, cp->instance); in add_ext_adv_data()
9054 } else if (!hdev->adv_instance_timeout) { in add_ext_adv_data()
9065 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || !schedule_instance) { in add_ext_adv_data()
9067 mgmt_advertising_added(sk, hdev, cp->instance); in add_ext_adv_data()
9071 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9076 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_EXT_ADV_DATA, hdev, data, in add_ext_adv_data()
9083 err = hci_cmd_sync_queue(hdev, add_ext_adv_data_sync, cmd, in add_ext_adv_data()
9096 mgmt_advertising_added(sk, hdev, cp->instance); in add_ext_adv_data()
9101 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_data()
9104 hci_dev_unlock(hdev); in add_ext_adv_data()
9109 static void remove_advertising_complete(struct hci_dev *hdev, void *data, in remove_advertising_complete() argument
9116 bt_dev_dbg(hdev, "err %d", err); in remove_advertising_complete()
9131 static int remove_advertising_sync(struct hci_dev *hdev, void *data) in remove_advertising_sync() argument
9137 err = hci_remove_advertising_sync(hdev, cmd->sk, cp->instance, true); in remove_advertising_sync()
9141 if (list_empty(&hdev->adv_instances)) in remove_advertising_sync()
9142 err = hci_disable_advertising_sync(hdev); in remove_advertising_sync()
9147 static int remove_advertising(struct sock *sk, struct hci_dev *hdev, in remove_advertising() argument
9154 bt_dev_dbg(hdev, "sock %p", sk); in remove_advertising()
9156 hci_dev_lock(hdev); in remove_advertising()
9158 if (cp->instance && !hci_find_adv_instance(hdev, cp->instance)) { in remove_advertising()
9159 err = mgmt_cmd_status(sk, hdev->id, in remove_advertising()
9165 if (pending_find(MGMT_OP_SET_LE, hdev)) { in remove_advertising()
9166 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
9171 if (list_empty(&hdev->adv_instances)) { in remove_advertising()
9172 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
9177 cmd = mgmt_pending_new(sk, MGMT_OP_REMOVE_ADVERTISING, hdev, data, in remove_advertising()
9184 err = hci_cmd_sync_queue(hdev, remove_advertising_sync, cmd, in remove_advertising()
9190 hci_dev_unlock(hdev); in remove_advertising()
9195 static int get_adv_size_info(struct sock *sk, struct hci_dev *hdev, in get_adv_size_info() argument
9202 bt_dev_dbg(hdev, "sock %p", sk); in get_adv_size_info()
9204 if (!lmp_le_capable(hdev)) in get_adv_size_info()
9205 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9208 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in get_adv_size_info()
9209 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9217 supported_flags = get_supported_adv_flags(hdev); in get_adv_size_info()
9219 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9224 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in get_adv_size_info()
9225 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in get_adv_size_info()
9227 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9364 void mgmt_index_added(struct hci_dev *hdev) in mgmt_index_added() argument
9368 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_added()
9371 switch (hdev->dev_type) { in mgmt_index_added()
9373 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_added()
9374 mgmt_index_event(MGMT_EV_UNCONF_INDEX_ADDED, hdev, in mgmt_index_added()
9378 mgmt_index_event(MGMT_EV_INDEX_ADDED, hdev, NULL, 0, in mgmt_index_added()
9390 ev.bus = hdev->bus; in mgmt_index_added()
9392 mgmt_index_event(MGMT_EV_EXT_INDEX_ADDED, hdev, &ev, sizeof(ev), in mgmt_index_added()
9396 void mgmt_index_removed(struct hci_dev *hdev) in mgmt_index_removed() argument
9401 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_removed()
9404 switch (hdev->dev_type) { in mgmt_index_removed()
9406 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status); in mgmt_index_removed()
9408 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_removed()
9409 mgmt_index_event(MGMT_EV_UNCONF_INDEX_REMOVED, hdev, in mgmt_index_removed()
9413 mgmt_index_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, in mgmt_index_removed()
9425 ev.bus = hdev->bus; in mgmt_index_removed()
9427 mgmt_index_event(MGMT_EV_EXT_INDEX_REMOVED, hdev, &ev, sizeof(ev), in mgmt_index_removed()
9431 if (!hci_dev_test_flag(hdev, HCI_MGMT)) in mgmt_index_removed()
9433 cancel_delayed_work_sync(&hdev->discov_off); in mgmt_index_removed()
9434 cancel_delayed_work_sync(&hdev->service_cache); in mgmt_index_removed()
9435 cancel_delayed_work_sync(&hdev->rpa_expired); in mgmt_index_removed()
9438 void mgmt_power_on(struct hci_dev *hdev, int err) in mgmt_power_on() argument
9440 struct cmd_lookup match = { NULL, hdev }; in mgmt_power_on()
9442 bt_dev_dbg(hdev, "err %d", err); in mgmt_power_on()
9444 hci_dev_lock(hdev); in mgmt_power_on()
9447 restart_le_actions(hdev); in mgmt_power_on()
9448 hci_update_passive_scan(hdev); in mgmt_power_on()
9451 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in mgmt_power_on()
9453 new_settings(hdev, match.sk); in mgmt_power_on()
9458 hci_dev_unlock(hdev); in mgmt_power_on()
9461 void __mgmt_power_off(struct hci_dev *hdev) in __mgmt_power_off() argument
9463 struct cmd_lookup match = { NULL, hdev }; in __mgmt_power_off()
9466 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in __mgmt_power_off()
9475 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) in __mgmt_power_off()
9480 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status); in __mgmt_power_off()
9482 if (memcmp(hdev->dev_class, zero_cod, sizeof(zero_cod)) != 0) { in __mgmt_power_off()
9483 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, in __mgmt_power_off()
9486 ext_info_changed(hdev, NULL); in __mgmt_power_off()
9489 new_settings(hdev, match.sk); in __mgmt_power_off()
9495 void mgmt_set_powered_failed(struct hci_dev *hdev, int err) in mgmt_set_powered_failed() argument
9500 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_set_powered_failed()
9509 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, status); in mgmt_set_powered_failed()
9514 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, in mgmt_new_link_key() argument
9528 mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_link_key()
9550 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent) in mgmt_new_ltk() argument
9590 mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_ltk()
9593 void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent) in mgmt_new_irk() argument
9606 mgmt_event(MGMT_EV_NEW_IRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_irk()
9609 void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, in mgmt_new_csrk() argument
9636 mgmt_event(MGMT_EV_NEW_CSRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_csrk()
9639 void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_new_conn_param() argument
9657 mgmt_event(MGMT_EV_NEW_CONN_PARAM, hdev, &ev, sizeof(ev), NULL); in mgmt_new_conn_param()
9660 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, in mgmt_device_connected() argument
9670 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, in mgmt_device_connected()
9673 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, in mgmt_device_connected()
9721 struct hci_dev *hdev = data; in unpair_device_rsp() local
9724 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_rsp()
9730 bool mgmt_powering_down(struct hci_dev *hdev) in mgmt_powering_down() argument
9735 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_powering_down()
9746 void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_device_disconnected() argument
9756 if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { in mgmt_device_disconnected()
9757 cancel_delayed_work(&hdev->power_off); in mgmt_device_disconnected()
9758 queue_work(hdev->req_workqueue, &hdev->power_off.work); in mgmt_device_disconnected()
9767 mgmt_pending_foreach(MGMT_OP_DISCONNECT, hdev, disconnect_rsp, &sk); in mgmt_device_disconnected()
9774 if (hdev->suspended) in mgmt_device_disconnected()
9777 mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev), sk); in mgmt_device_disconnected()
9782 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_device_disconnected()
9783 hdev); in mgmt_device_disconnected()
9786 void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_disconnect_failed() argument
9793 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_disconnect_failed()
9794 hdev); in mgmt_disconnect_failed()
9796 cmd = pending_find(MGMT_OP_DISCONNECT, hdev); in mgmt_disconnect_failed()
9812 void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_connect_failed() argument
9820 if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { in mgmt_connect_failed()
9821 cancel_delayed_work(&hdev->power_off); in mgmt_connect_failed()
9822 queue_work(hdev->req_workqueue, &hdev->power_off.work); in mgmt_connect_failed()
9829 mgmt_event(MGMT_EV_CONNECT_FAILED, hdev, &ev, sizeof(ev), NULL); in mgmt_connect_failed()
9832 void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure) in mgmt_pin_code_request() argument
9840 mgmt_event(MGMT_EV_PIN_CODE_REQUEST, hdev, &ev, sizeof(ev), NULL); in mgmt_pin_code_request()
9843 void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_reply_complete() argument
9848 cmd = pending_find(MGMT_OP_PIN_CODE_REPLY, hdev); in mgmt_pin_code_reply_complete()
9856 void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_neg_reply_complete() argument
9861 cmd = pending_find(MGMT_OP_PIN_CODE_NEG_REPLY, hdev); in mgmt_pin_code_neg_reply_complete()
9869 int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_request() argument
9875 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_confirm_request()
9882 return mgmt_event(MGMT_EV_USER_CONFIRM_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_confirm_request()
9886 int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_request() argument
9891 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_request()
9896 return mgmt_event(MGMT_EV_USER_PASSKEY_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_passkey_request()
9900 static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in user_pairing_resp_complete() argument
9906 cmd = pending_find(opcode, hdev); in user_pairing_resp_complete()
9916 int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_reply_complete() argument
9919 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_reply_complete()
9923 int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_neg_reply_complete() argument
9926 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_neg_reply_complete()
9931 int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_reply_complete() argument
9934 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_reply_complete()
9938 int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_neg_reply_complete() argument
9941 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_neg_reply_complete()
9946 int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_notify() argument
9952 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_notify()
9959 return mgmt_event(MGMT_EV_PASSKEY_NOTIFY, hdev, &ev, sizeof(ev), NULL); in mgmt_user_passkey_notify()
9974 mgmt_event(MGMT_EV_AUTH_FAILED, conn->hdev, &ev, sizeof(ev), in mgmt_auth_failed()
9983 void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status) in mgmt_auth_enable_complete() argument
9985 struct cmd_lookup match = { NULL, hdev }; in mgmt_auth_enable_complete()
9990 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, in mgmt_auth_enable_complete()
9995 if (test_bit(HCI_AUTH, &hdev->flags)) in mgmt_auth_enable_complete()
9996 changed = !hci_dev_test_and_set_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
9998 changed = hci_dev_test_and_clear_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
10000 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, settings_rsp, in mgmt_auth_enable_complete()
10004 new_settings(hdev, match.sk); in mgmt_auth_enable_complete()
10020 void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, in mgmt_set_class_of_dev_complete() argument
10023 struct cmd_lookup match = { NULL, hdev, mgmt_status(status) }; in mgmt_set_class_of_dev_complete()
10025 mgmt_pending_foreach(MGMT_OP_SET_DEV_CLASS, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
10026 mgmt_pending_foreach(MGMT_OP_ADD_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
10027 mgmt_pending_foreach(MGMT_OP_REMOVE_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
10030 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, dev_class, in mgmt_set_class_of_dev_complete()
10032 ext_info_changed(hdev, NULL); in mgmt_set_class_of_dev_complete()
10039 void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status) in mgmt_set_local_name_complete() argument
10049 memcpy(ev.short_name, hdev->short_name, HCI_MAX_SHORT_NAME_LENGTH); in mgmt_set_local_name_complete()
10051 cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev); in mgmt_set_local_name_complete()
10053 memcpy(hdev->dev_name, name, sizeof(hdev->dev_name)); in mgmt_set_local_name_complete()
10058 if (pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_local_name_complete()
10062 mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev, sizeof(ev), in mgmt_set_local_name_complete()
10064 ext_info_changed(hdev, cmd ? cmd->sk : NULL); in mgmt_set_local_name_complete()
10134 static void restart_le_scan(struct hci_dev *hdev) in restart_le_scan() argument
10137 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in restart_le_scan()
10141 hdev->discovery.scan_start + in restart_le_scan()
10142 hdev->discovery.scan_duration)) in restart_le_scan()
10145 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_restart, in restart_le_scan()
10149 static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir, in is_filter_match() argument
10161 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
10163 (rssi < hdev->discovery.rssi && in is_filter_match()
10164 !test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)))) in is_filter_match()
10167 if (hdev->discovery.uuid_count != 0) { in is_filter_match()
10171 if (!eir_has_uuids(eir, eir_len, hdev->discovery.uuid_count, in is_filter_match()
10172 hdev->discovery.uuids) && in is_filter_match()
10174 hdev->discovery.uuid_count, in is_filter_match()
10175 hdev->discovery.uuids)) in is_filter_match()
10182 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)) { in is_filter_match()
10183 restart_le_scan(hdev); in is_filter_match()
10186 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
10187 rssi < hdev->discovery.rssi) in is_filter_match()
10194 void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle, in mgmt_adv_monitor_device_lost() argument
10203 mgmt_event(MGMT_EV_ADV_MONITOR_DEVICE_LOST, hdev, &ev, sizeof(ev), in mgmt_adv_monitor_device_lost()
10207 static void mgmt_send_adv_monitor_device_found(struct hci_dev *hdev, in mgmt_send_adv_monitor_device_found() argument
10221 advmon_skb = mgmt_alloc_skb(hdev, MGMT_EV_ADV_MONITOR_DEVICE_FOUND, in mgmt_send_adv_monitor_device_found()
10237 static void mgmt_adv_monitor_device_found(struct hci_dev *hdev, in mgmt_adv_monitor_device_found() argument
10261 if (report_device && !hdev->advmon_pend_notify) { in mgmt_adv_monitor_device_found()
10266 hdev->advmon_pend_notify = false; in mgmt_adv_monitor_device_found()
10268 list_for_each_entry_safe(dev, tmp, &hdev->monitored_devices, list) { in mgmt_adv_monitor_device_found()
10273 mgmt_send_adv_monitor_device_found(hdev, skb, in mgmt_adv_monitor_device_found()
10282 hdev->advmon_pend_notify = true; in mgmt_adv_monitor_device_found()
10286 ((matched && !notified) || !msft_monitor_supported(hdev))) { in mgmt_adv_monitor_device_found()
10292 mgmt_send_adv_monitor_device_found(hdev, skb, skip_sk, 0); in mgmt_adv_monitor_device_found()
10301 static void mesh_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, in mesh_device_found() argument
10310 if (!hdev->mesh_ad_types[0]) in mesh_device_found()
10316 for (j = 0; j < sizeof(hdev->mesh_ad_types); j++) { in mesh_device_found()
10317 if (!hdev->mesh_ad_types[j]) in mesh_device_found()
10320 if (hdev->mesh_ad_types[j] == eir[i + 1]) in mesh_device_found()
10328 for (j = 0; j < sizeof(hdev->mesh_ad_types); j++) { in mesh_device_found()
10329 if (!hdev->mesh_ad_types[j]) in mesh_device_found()
10332 if (hdev->mesh_ad_types[j] == scan_rsp[i + 1]) in mesh_device_found()
10341 skb = mgmt_alloc_skb(hdev, MGMT_EV_MESH_DEVICE_FOUND, in mesh_device_found()
10367 void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_device_found() argument
10374 bool report_device = hci_discovery_active(hdev); in mgmt_device_found()
10376 if (hci_dev_test_flag(hdev, HCI_MESH) && link_type == LE_LINK) in mgmt_device_found()
10377 mesh_device_found(hdev, bdaddr, addr_type, rssi, flags, in mgmt_device_found()
10385 if (!hci_discovery_active(hdev)) { in mgmt_device_found()
10388 if (link_type == LE_LINK && !list_empty(&hdev->pend_le_reports)) in mgmt_device_found()
10390 else if (!hci_is_adv_monitoring(hdev)) in mgmt_device_found()
10394 if (hdev->discovery.result_filtering) { in mgmt_device_found()
10396 if (!is_filter_match(hdev, rssi, eir, eir_len, scan_rsp, in mgmt_device_found()
10401 if (hdev->discovery.limited) { in mgmt_device_found()
10414 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, in mgmt_device_found()
10429 if (rssi == HCI_RSSI_INVALID && !hdev->discovery.report_invalid_rssi && in mgmt_device_found()
10456 mgmt_adv_monitor_device_found(hdev, bdaddr, report_device, skb, NULL); in mgmt_device_found()
10459 void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_remote_name() argument
10467 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, in mgmt_remote_name()
10486 void mgmt_discovering(struct hci_dev *hdev, u8 discovering) in mgmt_discovering() argument
10490 bt_dev_dbg(hdev, "discovering %u", discovering); in mgmt_discovering()
10493 ev.type = hdev->discovery.type; in mgmt_discovering()
10496 mgmt_event(MGMT_EV_DISCOVERING, hdev, &ev, sizeof(ev), NULL); in mgmt_discovering()
10499 void mgmt_suspending(struct hci_dev *hdev, u8 state) in mgmt_suspending() argument
10504 mgmt_event(MGMT_EV_CONTROLLER_SUSPEND, hdev, &ev, sizeof(ev), NULL); in mgmt_suspending()
10507 void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr, in mgmt_resuming() argument
10520 mgmt_event(MGMT_EV_CONTROLLER_RESUME, hdev, &ev, sizeof(ev), NULL); in mgmt_resuming()
10543 struct hci_dev *hdev; in mgmt_cleanup() local
10547 list_for_each_entry(hdev, &hci_dev_list, list) { in mgmt_cleanup()
10549 mesh_tx = mgmt_mesh_next(hdev, sk); in mgmt_cleanup()
10552 mesh_send_complete(hdev, mesh_tx, true); in mgmt_cleanup()