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()
472 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_index_list()
489 static int read_unconf_index_list(struct sock *sk, struct hci_dev *hdev, in read_unconf_index_list() argument
498 bt_dev_dbg(hdev, "sock %p", sk); in read_unconf_index_list()
530 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_unconf_index_list()
547 static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev, in read_ext_index_list() argument
555 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_index_list()
589 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_ext_index_list()
613 static bool is_configured(struct hci_dev *hdev) in is_configured() argument
615 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in is_configured()
616 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in is_configured()
619 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in is_configured()
620 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in is_configured()
621 !bacmp(&hdev->public_addr, BDADDR_ANY)) in is_configured()
627 static __le32 get_missing_options(struct hci_dev *hdev) in get_missing_options() argument
631 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in get_missing_options()
632 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in get_missing_options()
635 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in get_missing_options()
636 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in get_missing_options()
637 !bacmp(&hdev->public_addr, BDADDR_ANY)) in get_missing_options()
643 static int new_options(struct hci_dev *hdev, struct sock *skip) in new_options() argument
645 __le32 options = get_missing_options(hdev); in new_options()
647 return mgmt_limited_event(MGMT_EV_NEW_CONFIG_OPTIONS, hdev, &options, in new_options()
651 static int send_options_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_options_rsp() argument
653 __le32 options = get_missing_options(hdev); in send_options_rsp()
655 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &options, in send_options_rsp()
659 static int read_config_info(struct sock *sk, struct hci_dev *hdev, in read_config_info() argument
665 bt_dev_dbg(hdev, "sock %p", sk); in read_config_info()
667 hci_dev_lock(hdev); in read_config_info()
670 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_config_info()
672 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in read_config_info()
675 if (hdev->set_bdaddr) in read_config_info()
679 rp.missing_options = get_missing_options(hdev); in read_config_info()
681 hci_dev_unlock(hdev); in read_config_info()
683 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONFIG_INFO, 0, in read_config_info()
687 static u32 get_supported_phys(struct hci_dev *hdev) in get_supported_phys() argument
691 if (lmp_bredr_capable(hdev)) { in get_supported_phys()
694 if (hdev->features[0][0] & LMP_3SLOT) in get_supported_phys()
697 if (hdev->features[0][0] & LMP_5SLOT) in get_supported_phys()
700 if (lmp_edr_2m_capable(hdev)) { in get_supported_phys()
703 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
706 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
709 if (lmp_edr_3m_capable(hdev)) { in get_supported_phys()
712 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
715 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
721 if (lmp_le_capable(hdev)) { in get_supported_phys()
725 if (hdev->le_features[1] & HCI_LE_PHY_2M) { in get_supported_phys()
730 if (hdev->le_features[1] & HCI_LE_PHY_CODED) { in get_supported_phys()
739 static u32 get_selected_phys(struct hci_dev *hdev) in get_selected_phys() argument
743 if (lmp_bredr_capable(hdev)) { in get_selected_phys()
746 if (hdev->pkt_type & (HCI_DM3 | HCI_DH3)) in get_selected_phys()
749 if (hdev->pkt_type & (HCI_DM5 | HCI_DH5)) in get_selected_phys()
752 if (lmp_edr_2m_capable(hdev)) { in get_selected_phys()
753 if (!(hdev->pkt_type & HCI_2DH1)) in get_selected_phys()
756 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
757 !(hdev->pkt_type & HCI_2DH3)) in get_selected_phys()
760 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
761 !(hdev->pkt_type & HCI_2DH5)) in get_selected_phys()
764 if (lmp_edr_3m_capable(hdev)) { in get_selected_phys()
765 if (!(hdev->pkt_type & HCI_3DH1)) in get_selected_phys()
768 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
769 !(hdev->pkt_type & HCI_3DH3)) in get_selected_phys()
772 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
773 !(hdev->pkt_type & HCI_3DH5)) in get_selected_phys()
779 if (lmp_le_capable(hdev)) { in get_selected_phys()
780 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
783 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
786 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
789 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
792 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
795 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
802 static u32 get_configurable_phys(struct hci_dev *hdev) in get_configurable_phys() argument
804 return (get_supported_phys(hdev) & ~MGMT_PHY_BR_1M_1SLOT & in get_configurable_phys()
808 static u32 get_supported_settings(struct hci_dev *hdev) in get_supported_settings() argument
818 if (lmp_bredr_capable(hdev)) { in get_supported_settings()
819 if (hdev->hci_ver >= BLUETOOTH_VER_1_2) in get_supported_settings()
824 if (lmp_ssp_capable(hdev)) { in get_supported_settings()
828 if (lmp_sc_capable(hdev)) in get_supported_settings()
832 &hdev->quirks)) in get_supported_settings()
836 if (lmp_le_capable(hdev)) { in get_supported_settings()
844 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in get_supported_settings()
845 hdev->set_bdaddr) in get_supported_settings()
848 if (cis_central_capable(hdev)) in get_supported_settings()
851 if (cis_peripheral_capable(hdev)) in get_supported_settings()
854 if (ll_privacy_capable(hdev)) in get_supported_settings()
862 static u32 get_current_settings(struct hci_dev *hdev) in get_current_settings() argument
866 if (hdev_is_powered(hdev)) in get_current_settings()
869 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in get_current_settings()
872 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in get_current_settings()
875 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in get_current_settings()
878 if (hci_dev_test_flag(hdev, HCI_BONDABLE)) in get_current_settings()
881 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in get_current_settings()
884 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in get_current_settings()
887 if (hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) in get_current_settings()
890 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in get_current_settings()
893 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in get_current_settings()
896 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) in get_current_settings()
899 if (hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) in get_current_settings()
902 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in get_current_settings()
917 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in get_current_settings()
918 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in get_current_settings()
919 !bacmp(&hdev->bdaddr, BDADDR_ANY)) { in get_current_settings()
920 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in get_current_settings()
924 if (hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED)) in get_current_settings()
927 if (cis_central_capable(hdev)) in get_current_settings()
930 if (cis_peripheral_capable(hdev)) in get_current_settings()
933 if (bis_capable(hdev)) in get_current_settings()
936 if (sync_recv_capable(hdev)) in get_current_settings()
939 if (ll_privacy_capable(hdev)) in get_current_settings()
945 static struct mgmt_pending_cmd *pending_find(u16 opcode, struct hci_dev *hdev) in pending_find() argument
947 return mgmt_pending_find(HCI_CHANNEL_CONTROL, opcode, hdev); in pending_find()
950 u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev) in mgmt_get_adv_discov_flags() argument
957 cmd = pending_find(MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_get_adv_discov_flags()
965 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
967 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
974 bool mgmt_get_connectable(struct hci_dev *hdev) in mgmt_get_connectable() argument
981 cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_get_connectable()
988 return hci_dev_test_flag(hdev, HCI_CONNECTABLE); in mgmt_get_connectable()
991 static int service_cache_sync(struct hci_dev *hdev, void *data) in service_cache_sync() argument
993 hci_update_eir_sync(hdev); in service_cache_sync()
994 hci_update_class_sync(hdev); in service_cache_sync()
1001 struct hci_dev *hdev = container_of(work, struct hci_dev, in service_cache_off() local
1004 if (!hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in service_cache_off()
1007 hci_cmd_sync_queue(hdev, service_cache_sync, NULL, NULL); in service_cache_off()
1010 static int rpa_expired_sync(struct hci_dev *hdev, void *data) in rpa_expired_sync() argument
1016 if (ext_adv_capable(hdev)) in rpa_expired_sync()
1017 return hci_start_ext_adv_sync(hdev, hdev->cur_adv_instance); in rpa_expired_sync()
1019 return hci_enable_advertising_sync(hdev); in rpa_expired_sync()
1024 struct hci_dev *hdev = container_of(work, struct hci_dev, in rpa_expired() local
1027 bt_dev_dbg(hdev, ""); in rpa_expired()
1029 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in rpa_expired()
1031 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING)) in rpa_expired()
1034 hci_cmd_sync_queue(hdev, rpa_expired_sync, NULL, NULL); in rpa_expired()
1037 static int set_discoverable_sync(struct hci_dev *hdev, void *data);
1041 struct hci_dev *hdev = container_of(work, struct hci_dev, in discov_off() local
1044 bt_dev_dbg(hdev, ""); in discov_off()
1046 hci_dev_lock(hdev); in discov_off()
1053 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in discov_off()
1054 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in discov_off()
1055 hdev->discov_timeout = 0; in discov_off()
1057 hci_cmd_sync_queue(hdev, set_discoverable_sync, NULL, NULL); in discov_off()
1059 mgmt_new_settings(hdev); in discov_off()
1061 hci_dev_unlock(hdev); in discov_off()
1064 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev);
1066 static void mesh_send_complete(struct hci_dev *hdev, in mesh_send_complete() argument
1072 mgmt_event(MGMT_EV_MESH_PACKET_CMPLT, hdev, &handle, in mesh_send_complete()
1078 static int mesh_send_done_sync(struct hci_dev *hdev, void *data) in mesh_send_done_sync() argument
1082 hci_dev_clear_flag(hdev, HCI_MESH_SENDING); in mesh_send_done_sync()
1083 hci_disable_advertising_sync(hdev); in mesh_send_done_sync()
1084 mesh_tx = mgmt_mesh_next(hdev, NULL); in mesh_send_done_sync()
1087 mesh_send_complete(hdev, mesh_tx, false); in mesh_send_done_sync()
1092 static int mesh_send_sync(struct hci_dev *hdev, void *data);
1093 static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err);
1094 static void mesh_next(struct hci_dev *hdev, void *data, int err) in mesh_next() argument
1096 struct mgmt_mesh_tx *mesh_tx = mgmt_mesh_next(hdev, NULL); in mesh_next()
1101 err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx, in mesh_next()
1105 mesh_send_complete(hdev, mesh_tx, false); in mesh_next()
1107 hci_dev_set_flag(hdev, HCI_MESH_SENDING); in mesh_next()
1112 struct hci_dev *hdev = container_of(work, struct hci_dev, in mesh_send_done() local
1115 if (!hci_dev_test_flag(hdev, HCI_MESH_SENDING)) in mesh_send_done()
1118 hci_cmd_sync_queue(hdev, mesh_send_done_sync, NULL, mesh_next); in mesh_send_done()
1121 static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev) in mgmt_init_hdev() argument
1123 if (hci_dev_test_flag(hdev, HCI_MGMT)) in mgmt_init_hdev()
1128 INIT_DELAYED_WORK(&hdev->discov_off, discov_off); in mgmt_init_hdev()
1129 INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off); in mgmt_init_hdev()
1130 INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired); in mgmt_init_hdev()
1131 INIT_DELAYED_WORK(&hdev->mesh_send_done, mesh_send_done); in mgmt_init_hdev()
1138 hci_dev_clear_flag(hdev, HCI_BONDABLE); in mgmt_init_hdev()
1140 hci_dev_set_flag(hdev, HCI_MGMT); in mgmt_init_hdev()
1143 static int read_controller_info(struct sock *sk, struct hci_dev *hdev, in read_controller_info() argument
1148 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_info()
1150 hci_dev_lock(hdev); in read_controller_info()
1154 bacpy(&rp.bdaddr, &hdev->bdaddr); in read_controller_info()
1156 rp.version = hdev->hci_ver; in read_controller_info()
1157 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_controller_info()
1159 rp.supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_controller_info()
1160 rp.current_settings = cpu_to_le32(get_current_settings(hdev)); in read_controller_info()
1162 memcpy(rp.dev_class, hdev->dev_class, 3); in read_controller_info()
1164 memcpy(rp.name, hdev->dev_name, sizeof(hdev->dev_name)); in read_controller_info()
1165 memcpy(rp.short_name, hdev->short_name, sizeof(hdev->short_name)); in read_controller_info()
1167 hci_dev_unlock(hdev); in read_controller_info()
1169 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_INFO, 0, &rp, in read_controller_info()
1173 static u16 append_eir_data_to_buf(struct hci_dev *hdev, u8 *eir) in append_eir_data_to_buf() argument
1178 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in append_eir_data_to_buf()
1180 hdev->dev_class, 3); in append_eir_data_to_buf()
1182 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in append_eir_data_to_buf()
1184 hdev->appearance); in append_eir_data_to_buf()
1186 name_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name)); in append_eir_data_to_buf()
1188 hdev->dev_name, name_len); in append_eir_data_to_buf()
1190 name_len = strnlen(hdev->short_name, sizeof(hdev->short_name)); in append_eir_data_to_buf()
1192 hdev->short_name, name_len); in append_eir_data_to_buf()
1197 static int read_ext_controller_info(struct sock *sk, struct hci_dev *hdev, in read_ext_controller_info() argument
1204 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_controller_info()
1208 hci_dev_lock(hdev); in read_ext_controller_info()
1210 bacpy(&rp->bdaddr, &hdev->bdaddr); in read_ext_controller_info()
1212 rp->version = hdev->hci_ver; in read_ext_controller_info()
1213 rp->manufacturer = cpu_to_le16(hdev->manufacturer); in read_ext_controller_info()
1215 rp->supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_ext_controller_info()
1216 rp->current_settings = cpu_to_le32(get_current_settings(hdev)); in read_ext_controller_info()
1219 eir_len = append_eir_data_to_buf(hdev, rp->eir); in read_ext_controller_info()
1222 hci_dev_unlock(hdev); in read_ext_controller_info()
1233 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_EXT_INFO, 0, rp, in read_ext_controller_info()
1237 static int ext_info_changed(struct hci_dev *hdev, struct sock *skip) in ext_info_changed() argument
1245 eir_len = append_eir_data_to_buf(hdev, ev->eir); in ext_info_changed()
1248 return mgmt_limited_event(MGMT_EV_EXT_INFO_CHANGED, hdev, ev, in ext_info_changed()
1253 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_settings_rsp() argument
1255 __le32 settings = cpu_to_le32(get_current_settings(hdev)); in send_settings_rsp()
1257 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &settings, in send_settings_rsp()
1261 void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev, u8 instance) in mgmt_advertising_added() argument
1267 mgmt_event(MGMT_EV_ADVERTISING_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_added()
1270 void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev, in mgmt_advertising_removed() argument
1277 mgmt_event(MGMT_EV_ADVERTISING_REMOVED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_removed()
1280 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
1282 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
1283 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
1284 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
1289 static void restart_le_actions(struct hci_dev *hdev) in restart_le_actions() argument
1293 list_for_each_entry(p, &hdev->le_conn_params, list) { in restart_le_actions()
1302 hci_pend_le_list_add(p, &hdev->pend_le_conns); in restart_le_actions()
1305 hci_pend_le_list_add(p, &hdev->pend_le_reports); in restart_le_actions()
1313 static int new_settings(struct hci_dev *hdev, struct sock *skip) in new_settings() argument
1315 __le32 ev = cpu_to_le32(get_current_settings(hdev)); in new_settings()
1317 return mgmt_limited_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, in new_settings()
1321 static void mgmt_set_powered_complete(struct hci_dev *hdev, void *data, int err) in mgmt_set_powered_complete() argument
1328 cmd != pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_powered_complete()
1333 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_powered_complete()
1337 hci_dev_lock(hdev); in mgmt_set_powered_complete()
1338 restart_le_actions(hdev); in mgmt_set_powered_complete()
1339 hci_update_passive_scan(hdev); in mgmt_set_powered_complete()
1340 hci_dev_unlock(hdev); in mgmt_set_powered_complete()
1343 send_settings_rsp(cmd->sk, cmd->opcode, hdev); in mgmt_set_powered_complete()
1349 new_settings(hdev, cmd->sk); in mgmt_set_powered_complete()
1351 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, in mgmt_set_powered_complete()
1358 static int set_powered_sync(struct hci_dev *hdev, void *data) in set_powered_sync() argument
1364 if (cmd != pending_find(MGMT_OP_SET_POWERED, hdev)) in set_powered_sync()
1369 BT_DBG("%s", hdev->name); in set_powered_sync()
1371 return hci_set_powered_sync(hdev, cp->val); in set_powered_sync()
1374 static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, in set_powered() argument
1381 bt_dev_dbg(hdev, "sock %p", sk); in set_powered()
1384 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1387 hci_dev_lock(hdev); in set_powered()
1390 if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) { in set_powered()
1391 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1397 if (pending_find(MGMT_OP_SET_POWERED, hdev)) { in set_powered()
1398 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1403 if (!!cp->val == hdev_is_powered(hdev)) { in set_powered()
1404 err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev); in set_powered()
1408 cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, hdev, data, len); in set_powered()
1416 hci_cmd_sync_cancel_sync(hdev, -EHOSTDOWN); in set_powered()
1417 err = hci_cmd_sync_queue(hdev, set_powered_sync, cmd, in set_powered()
1421 err = hci_cmd_sync_submit(hdev, set_powered_sync, cmd, in set_powered()
1429 hci_dev_unlock(hdev); in set_powered()
1433 int mgmt_new_settings(struct hci_dev *hdev) in mgmt_new_settings() argument
1435 return new_settings(hdev, NULL); in mgmt_new_settings()
1440 struct hci_dev *hdev; member
1448 send_settings_rsp(cmd->sk, cmd->opcode, match->hdev); in settings_rsp()
1475 hci_cmd_sync_dequeue(match->hdev, NULL, cmd, NULL); in cmd_complete_rsp()
1499 static u8 mgmt_bredr_support(struct hci_dev *hdev) in mgmt_bredr_support() argument
1501 if (!lmp_bredr_capable(hdev)) in mgmt_bredr_support()
1503 else if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in mgmt_bredr_support()
1509 static u8 mgmt_le_support(struct hci_dev *hdev) in mgmt_le_support() argument
1511 if (!lmp_le_capable(hdev)) in mgmt_le_support()
1513 else if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mgmt_le_support()
1519 static void mgmt_set_discoverable_complete(struct hci_dev *hdev, void *data, in mgmt_set_discoverable_complete() argument
1524 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_discoverable_complete()
1528 cmd != pending_find(MGMT_OP_SET_DISCOVERABLE, hdev)) in mgmt_set_discoverable_complete()
1531 hci_dev_lock(hdev); in mgmt_set_discoverable_complete()
1536 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in mgmt_set_discoverable_complete()
1540 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in mgmt_set_discoverable_complete()
1541 hdev->discov_timeout > 0) { in mgmt_set_discoverable_complete()
1542 int to = secs_to_jiffies(hdev->discov_timeout); in mgmt_set_discoverable_complete()
1543 queue_delayed_work(hdev->req_workqueue, &hdev->discov_off, to); in mgmt_set_discoverable_complete()
1546 send_settings_rsp(cmd->sk, MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_set_discoverable_complete()
1547 new_settings(hdev, cmd->sk); in mgmt_set_discoverable_complete()
1551 hci_dev_unlock(hdev); in mgmt_set_discoverable_complete()
1554 static int set_discoverable_sync(struct hci_dev *hdev, void *data) in set_discoverable_sync() argument
1556 BT_DBG("%s", hdev->name); in set_discoverable_sync()
1558 return hci_update_discoverable_sync(hdev); in set_discoverable_sync()
1561 static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, in set_discoverable() argument
1569 bt_dev_dbg(hdev, "sock %p", sk); in set_discoverable()
1571 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_discoverable()
1572 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_discoverable()
1573 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1577 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1587 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1590 hci_dev_lock(hdev); in set_discoverable()
1592 if (!hdev_is_powered(hdev) && timeout > 0) { in set_discoverable()
1593 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1598 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_discoverable()
1599 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_discoverable()
1600 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1605 if (!hci_dev_test_flag(hdev, HCI_CONNECTABLE)) { in set_discoverable()
1606 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1611 if (hdev->advertising_paused) { in set_discoverable()
1612 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1617 if (!hdev_is_powered(hdev)) { in set_discoverable()
1624 if (!!cp->val != hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) { in set_discoverable()
1625 hci_dev_change_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1629 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1634 err = new_settings(hdev, sk); in set_discoverable()
1643 if (!!cp->val == hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in set_discoverable()
1644 (cp->val == 0x02) == hci_dev_test_flag(hdev, in set_discoverable()
1646 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1647 hdev->discov_timeout = timeout; in set_discoverable()
1649 if (cp->val && hdev->discov_timeout > 0) { in set_discoverable()
1650 int to = secs_to_jiffies(hdev->discov_timeout); in set_discoverable()
1651 queue_delayed_work(hdev->req_workqueue, in set_discoverable()
1652 &hdev->discov_off, to); in set_discoverable()
1655 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1659 cmd = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, hdev, data, len); in set_discoverable()
1669 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1670 hdev->discov_timeout = timeout; in set_discoverable()
1673 hci_dev_set_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1675 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1679 hci_dev_set_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1681 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1683 err = hci_cmd_sync_queue(hdev, set_discoverable_sync, cmd, in set_discoverable()
1690 hci_dev_unlock(hdev); in set_discoverable()
1694 static void mgmt_set_connectable_complete(struct hci_dev *hdev, void *data, in mgmt_set_connectable_complete() argument
1699 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_connectable_complete()
1703 cmd != pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) in mgmt_set_connectable_complete()
1706 hci_dev_lock(hdev); in mgmt_set_connectable_complete()
1714 send_settings_rsp(cmd->sk, MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_set_connectable_complete()
1715 new_settings(hdev, cmd->sk); in mgmt_set_connectable_complete()
1720 hci_dev_unlock(hdev); in mgmt_set_connectable_complete()
1723 static int set_connectable_update_settings(struct hci_dev *hdev, in set_connectable_update_settings() argument
1729 if (!!val != hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in set_connectable_update_settings()
1733 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1735 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1736 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable_update_settings()
1739 err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev); in set_connectable_update_settings()
1744 hci_update_scan(hdev); in set_connectable_update_settings()
1745 hci_update_passive_scan(hdev); in set_connectable_update_settings()
1746 return new_settings(hdev, sk); in set_connectable_update_settings()
1752 static int set_connectable_sync(struct hci_dev *hdev, void *data) in set_connectable_sync() argument
1754 BT_DBG("%s", hdev->name); in set_connectable_sync()
1756 return hci_update_connectable_sync(hdev); in set_connectable_sync()
1759 static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data, in set_connectable() argument
1766 bt_dev_dbg(hdev, "sock %p", sk); in set_connectable()
1768 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_connectable()
1769 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_connectable()
1770 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1774 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1777 hci_dev_lock(hdev); in set_connectable()
1779 if (!hdev_is_powered(hdev)) { in set_connectable()
1780 err = set_connectable_update_settings(hdev, sk, cp->val); in set_connectable()
1784 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_connectable()
1785 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_connectable()
1786 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1791 cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len); in set_connectable()
1798 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1800 if (hdev->discov_timeout > 0) in set_connectable()
1801 cancel_delayed_work(&hdev->discov_off); in set_connectable()
1803 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_connectable()
1804 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable()
1805 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1808 err = hci_cmd_sync_queue(hdev, set_connectable_sync, cmd, in set_connectable()
1815 hci_dev_unlock(hdev); in set_connectable()
1819 static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data, in set_bondable() argument
1826 bt_dev_dbg(hdev, "sock %p", sk); in set_bondable()
1829 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BONDABLE, in set_bondable()
1832 hci_dev_lock(hdev); in set_bondable()
1835 changed = !hci_dev_test_and_set_flag(hdev, HCI_BONDABLE); in set_bondable()
1837 changed = hci_dev_test_and_clear_flag(hdev, HCI_BONDABLE); in set_bondable()
1839 err = send_settings_rsp(sk, MGMT_OP_SET_BONDABLE, hdev); in set_bondable()
1847 hci_update_discoverable(hdev); in set_bondable()
1849 err = new_settings(hdev, sk); in set_bondable()
1853 hci_dev_unlock(hdev); in set_bondable()
1857 static int set_link_security(struct sock *sk, struct hci_dev *hdev, void *data, in set_link_security() argument
1865 bt_dev_dbg(hdev, "sock %p", sk); in set_link_security()
1867 status = mgmt_bredr_support(hdev); in set_link_security()
1869 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1873 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1876 hci_dev_lock(hdev); in set_link_security()
1878 if (!hdev_is_powered(hdev)) { in set_link_security()
1881 if (!!cp->val != hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) { in set_link_security()
1882 hci_dev_change_flag(hdev, HCI_LINK_SECURITY); in set_link_security()
1886 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1891 err = new_settings(hdev, sk); in set_link_security()
1896 if (pending_find(MGMT_OP_SET_LINK_SECURITY, hdev)) { in set_link_security()
1897 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1904 if (test_bit(HCI_AUTH, &hdev->flags) == val) { in set_link_security()
1905 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1909 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LINK_SECURITY, hdev, data, len); in set_link_security()
1915 err = hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, sizeof(val), &val); in set_link_security()
1922 hci_dev_unlock(hdev); in set_link_security()
1926 static void set_ssp_complete(struct hci_dev *hdev, void *data, int err) in set_ssp_complete() argument
1928 struct cmd_lookup match = { NULL, hdev }; in set_ssp_complete()
1935 if (err == -ECANCELED || cmd != pending_find(MGMT_OP_SET_SSP, hdev)) in set_ssp_complete()
1941 if (enable && hci_dev_test_and_clear_flag(hdev, in set_ssp_complete()
1943 new_settings(hdev, NULL); in set_ssp_complete()
1946 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, cmd_status_rsp, in set_ssp_complete()
1952 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in set_ssp_complete()
1954 changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED); in set_ssp_complete()
1957 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, settings_rsp, &match); in set_ssp_complete()
1960 new_settings(hdev, match.sk); in set_ssp_complete()
1965 hci_update_eir_sync(hdev); in set_ssp_complete()
1968 static int set_ssp_sync(struct hci_dev *hdev, void *data) in set_ssp_sync() argument
1976 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in set_ssp_sync()
1978 err = hci_write_ssp_mode_sync(hdev, cp->val); in set_ssp_sync()
1981 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_ssp_sync()
1986 static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_ssp() argument
1993 bt_dev_dbg(hdev, "sock %p", sk); in set_ssp()
1995 status = mgmt_bredr_support(hdev); in set_ssp()
1997 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, status); in set_ssp()
1999 if (!lmp_ssp_capable(hdev)) in set_ssp()
2000 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2004 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2007 hci_dev_lock(hdev); in set_ssp()
2009 if (!hdev_is_powered(hdev)) { in set_ssp()
2013 changed = !hci_dev_test_and_set_flag(hdev, in set_ssp()
2016 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
2020 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
2025 err = new_settings(hdev, sk); in set_ssp()
2030 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_ssp()
2031 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2036 if (!!cp->val == hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_ssp()
2037 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
2041 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SSP, hdev, data, len); in set_ssp()
2045 err = hci_cmd_sync_queue(hdev, set_ssp_sync, cmd, in set_ssp()
2049 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2057 hci_dev_unlock(hdev); in set_ssp()
2061 static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_hs() argument
2063 bt_dev_dbg(hdev, "sock %p", sk); in set_hs()
2065 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2069 static void set_le_complete(struct hci_dev *hdev, void *data, int err) in set_le_complete() argument
2071 struct cmd_lookup match = { NULL, hdev }; in set_le_complete()
2074 bt_dev_dbg(hdev, "err %d", err); in set_le_complete()
2077 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp, in set_le_complete()
2082 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match); in set_le_complete()
2084 new_settings(hdev, match.sk); in set_le_complete()
2090 static int set_le_sync(struct hci_dev *hdev, void *data) in set_le_sync() argument
2098 hci_clear_adv_instance_sync(hdev, NULL, 0x00, true); in set_le_sync()
2100 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_le_sync()
2101 hci_disable_advertising_sync(hdev); in set_le_sync()
2103 if (ext_adv_capable(hdev)) in set_le_sync()
2104 hci_remove_ext_adv_instance_sync(hdev, 0, cmd->sk); in set_le_sync()
2106 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in set_le_sync()
2109 err = hci_write_le_host_supported_sync(hdev, val, 0); in set_le_sync()
2116 if (!err && hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le_sync()
2117 if (ext_adv_capable(hdev)) { in set_le_sync()
2120 status = hci_setup_ext_adv_instance_sync(hdev, 0x00); in set_le_sync()
2122 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_le_sync()
2124 hci_update_adv_data_sync(hdev, 0x00); in set_le_sync()
2125 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_le_sync()
2128 hci_update_passive_scan(hdev); in set_le_sync()
2134 static void set_mesh_complete(struct hci_dev *hdev, void *data, int err) in set_mesh_complete() argument
2141 mgmt_pending_foreach(MGMT_OP_SET_MESH_RECEIVER, hdev, in set_mesh_complete()
2147 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, 0, NULL, 0); in set_mesh_complete()
2150 static int set_mesh_sync(struct hci_dev *hdev, void *data) in set_mesh_sync() argument
2156 memset(hdev->mesh_ad_types, 0, sizeof(hdev->mesh_ad_types)); in set_mesh_sync()
2159 hci_dev_set_flag(hdev, HCI_MESH); in set_mesh_sync()
2161 hci_dev_clear_flag(hdev, HCI_MESH); in set_mesh_sync()
2166 if (len <= sizeof(hdev->mesh_ad_types)) in set_mesh_sync()
2167 memcpy(hdev->mesh_ad_types, cp->ad_types, len); in set_mesh_sync()
2169 hci_update_passive_scan_sync(hdev); in set_mesh_sync()
2173 static int set_mesh(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_mesh() argument
2179 bt_dev_dbg(hdev, "sock %p", sk); in set_mesh()
2181 if (!lmp_le_capable(hdev) || in set_mesh()
2182 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in set_mesh()
2183 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2187 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2190 hci_dev_lock(hdev); in set_mesh()
2192 cmd = mgmt_pending_add(sk, MGMT_OP_SET_MESH_RECEIVER, hdev, data, len); in set_mesh()
2196 err = hci_cmd_sync_queue(hdev, set_mesh_sync, cmd, in set_mesh()
2200 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2207 hci_dev_unlock(hdev); in set_mesh()
2211 static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err) in mesh_send_start_complete() argument
2221 hci_dev_clear_flag(hdev, HCI_MESH_SENDING); in mesh_send_start_complete()
2223 mesh_send_complete(hdev, mesh_tx, false); in mesh_send_start_complete()
2228 queue_delayed_work(hdev->req_workqueue, &hdev->mesh_send_done, in mesh_send_start_complete()
2232 static int mesh_send_sync(struct hci_dev *hdev, void *data) in mesh_send_sync() argument
2237 u8 instance = hdev->le_num_of_adv_sets + 1; in mesh_send_sync()
2241 if (hdev->le_num_of_adv_sets <= hdev->adv_instance_cnt) in mesh_send_sync()
2245 duration = send->cnt * INTERVAL_TO_MS(hdev->le_adv_max_interval); in mesh_send_sync()
2246 adv = hci_add_adv_instance(hdev, instance, 0, in mesh_send_sync()
2251 hdev->le_adv_min_interval, in mesh_send_sync()
2252 hdev->le_adv_max_interval, in mesh_send_sync()
2260 if (hdev->cur_adv_instance == instance) { in mesh_send_sync()
2266 cancel_adv_timeout(hdev); in mesh_send_sync()
2268 next_instance = hci_get_next_instance(hdev, instance); in mesh_send_sync()
2273 } else if (hdev->adv_instance_timeout) { in mesh_send_sync()
2281 return hci_schedule_adv_instance_sync(hdev, instance, true); in mesh_send_sync()
2296 static int mesh_features(struct sock *sk, struct hci_dev *hdev, in mesh_features() argument
2301 if (!lmp_le_capable(hdev) || in mesh_features()
2302 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_features()
2303 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_READ_FEATURES, in mesh_features()
2307 rp.index = cpu_to_le16(hdev->id); in mesh_features()
2308 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mesh_features()
2311 hci_dev_lock(hdev); in mesh_features()
2314 mgmt_mesh_foreach(hdev, send_count, &rp, sk); in mesh_features()
2316 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_MESH_READ_FEATURES, 0, &rp, in mesh_features()
2319 hci_dev_unlock(hdev); in mesh_features()
2323 static int send_cancel(struct hci_dev *hdev, void *data) in send_cancel() argument
2331 mesh_tx = mgmt_mesh_next(hdev, cmd->sk); in send_cancel()
2334 mesh_send_complete(hdev, mesh_tx, false); in send_cancel()
2337 mesh_tx = mgmt_mesh_find(hdev, cancel->handle); in send_cancel()
2340 mesh_send_complete(hdev, mesh_tx, false); in send_cancel()
2343 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in send_cancel()
2350 static int mesh_send_cancel(struct sock *sk, struct hci_dev *hdev, in mesh_send_cancel() argument
2356 if (!lmp_le_capable(hdev) || in mesh_send_cancel()
2357 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_send_cancel()
2358 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2361 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mesh_send_cancel()
2362 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2365 hci_dev_lock(hdev); in mesh_send_cancel()
2366 cmd = mgmt_pending_new(sk, MGMT_OP_MESH_SEND_CANCEL, hdev, data, len); in mesh_send_cancel()
2370 err = hci_cmd_sync_queue(hdev, send_cancel, cmd, NULL); in mesh_send_cancel()
2373 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2380 hci_dev_unlock(hdev); in mesh_send_cancel()
2384 static int mesh_send(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in mesh_send() argument
2392 if (!lmp_le_capable(hdev) || in mesh_send()
2393 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_send()
2394 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2396 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) || in mesh_send()
2399 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2402 hci_dev_lock(hdev); in mesh_send()
2407 mgmt_mesh_foreach(hdev, send_count, &rp, sk); in mesh_send()
2410 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2415 sending = hci_dev_test_flag(hdev, HCI_MESH_SENDING); in mesh_send()
2416 mesh_tx = mgmt_mesh_add(sk, hdev, send, len); in mesh_send()
2421 err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx, in mesh_send()
2425 bt_dev_err(hdev, "Send Mesh Failed %d", err); in mesh_send()
2426 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2434 hci_dev_set_flag(hdev, HCI_MESH_SENDING); in mesh_send()
2436 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_MESH_SEND, 0, in mesh_send()
2441 hci_dev_unlock(hdev); in mesh_send()
2445 static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_le() argument
2452 bt_dev_dbg(hdev, "sock %p", sk); in set_le()
2454 if (!lmp_le_capable(hdev)) in set_le()
2455 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2459 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2471 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_le()
2473 return send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
2475 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2479 hci_dev_lock(hdev); in set_le()
2482 enabled = lmp_host_le_capable(hdev); in set_le()
2484 if (!hdev_is_powered(hdev) || val == enabled) { in set_le()
2487 if (val != hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le()
2488 hci_dev_change_flag(hdev, HCI_LE_ENABLED); in set_le()
2492 if (!val && hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in set_le()
2493 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_le()
2497 err = send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
2502 err = new_settings(hdev, sk); in set_le()
2507 if (pending_find(MGMT_OP_SET_LE, hdev) || in set_le()
2508 pending_find(MGMT_OP_SET_ADVERTISING, hdev)) { in set_le()
2509 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2514 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LE, hdev, data, len); in set_le()
2518 err = hci_cmd_sync_queue(hdev, set_le_sync, cmd, in set_le()
2522 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2530 hci_dev_unlock(hdev); in set_le()
2534 static int send_hci_cmd_sync(struct hci_dev *hdev, void *data) in send_hci_cmd_sync() argument
2540 skb = __hci_cmd_sync_ev(hdev, le16_to_cpu(cp->opcode), in send_hci_cmd_sync()
2546 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_HCI_CMD_SYNC, in send_hci_cmd_sync()
2551 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_HCI_CMD_SYNC, 0, in send_hci_cmd_sync()
2562 static int mgmt_hci_cmd_sync(struct sock *sk, struct hci_dev *hdev, in mgmt_hci_cmd_sync() argument
2570 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_HCI_CMD_SYNC, in mgmt_hci_cmd_sync()
2573 hci_dev_lock(hdev); in mgmt_hci_cmd_sync()
2574 cmd = mgmt_pending_new(sk, MGMT_OP_HCI_CMD_SYNC, hdev, data, len); in mgmt_hci_cmd_sync()
2578 err = hci_cmd_sync_queue(hdev, send_hci_cmd_sync, cmd, NULL); in mgmt_hci_cmd_sync()
2581 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_HCI_CMD_SYNC, in mgmt_hci_cmd_sync()
2588 hci_dev_unlock(hdev); in mgmt_hci_cmd_sync()
2598 static bool pending_eir_or_class(struct hci_dev *hdev) in pending_eir_or_class() argument
2602 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in pending_eir_or_class()
2634 static void mgmt_class_complete(struct hci_dev *hdev, void *data, int err) in mgmt_class_complete() argument
2638 bt_dev_dbg(hdev, "err %d", err); in mgmt_class_complete()
2641 mgmt_status(err), hdev->dev_class, 3); in mgmt_class_complete()
2646 static int add_uuid_sync(struct hci_dev *hdev, void *data) in add_uuid_sync() argument
2650 err = hci_update_class_sync(hdev); in add_uuid_sync()
2654 return hci_update_eir_sync(hdev); in add_uuid_sync()
2657 static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in add_uuid() argument
2664 bt_dev_dbg(hdev, "sock %p", sk); in add_uuid()
2666 hci_dev_lock(hdev); in add_uuid()
2668 if (pending_eir_or_class(hdev)) { in add_uuid()
2669 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_UUID, in add_uuid()
2684 list_add_tail(&uuid->list, &hdev->uuids); in add_uuid()
2686 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_UUID, hdev, data, len); in add_uuid()
2695 err = hci_cmd_sync_submit(hdev, add_uuid_sync, cmd, in add_uuid()
2703 hci_dev_unlock(hdev); in add_uuid()
2707 static bool enable_service_cache(struct hci_dev *hdev) in enable_service_cache() argument
2709 if (!hdev_is_powered(hdev)) in enable_service_cache()
2712 if (!hci_dev_test_and_set_flag(hdev, HCI_SERVICE_CACHE)) { in enable_service_cache()
2713 queue_delayed_work(hdev->workqueue, &hdev->service_cache, in enable_service_cache()
2721 static int remove_uuid_sync(struct hci_dev *hdev, void *data) in remove_uuid_sync() argument
2725 err = hci_update_class_sync(hdev); in remove_uuid_sync()
2729 return hci_update_eir_sync(hdev); in remove_uuid_sync()
2732 static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data, in remove_uuid() argument
2743 bt_dev_dbg(hdev, "sock %p", sk); in remove_uuid()
2745 hci_dev_lock(hdev); in remove_uuid()
2747 if (pending_eir_or_class(hdev)) { in remove_uuid()
2748 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2754 hci_uuids_clear(hdev); in remove_uuid()
2756 if (enable_service_cache(hdev)) { in remove_uuid()
2757 err = mgmt_cmd_complete(sk, hdev->id, in remove_uuid()
2759 0, hdev->dev_class, 3); in remove_uuid()
2768 list_for_each_entry_safe(match, tmp, &hdev->uuids, list) { in remove_uuid()
2778 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2784 cmd = mgmt_pending_new(sk, MGMT_OP_REMOVE_UUID, hdev, data, len); in remove_uuid()
2793 err = hci_cmd_sync_submit(hdev, remove_uuid_sync, cmd, in remove_uuid()
2799 hci_dev_unlock(hdev); in remove_uuid()
2803 static int set_class_sync(struct hci_dev *hdev, void *data) in set_class_sync() argument
2807 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) { in set_class_sync()
2808 cancel_delayed_work_sync(&hdev->service_cache); in set_class_sync()
2809 err = hci_update_eir_sync(hdev); in set_class_sync()
2815 return hci_update_class_sync(hdev); in set_class_sync()
2818 static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data, in set_dev_class() argument
2825 bt_dev_dbg(hdev, "sock %p", sk); in set_dev_class()
2827 if (!lmp_bredr_capable(hdev)) in set_dev_class()
2828 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2831 hci_dev_lock(hdev); in set_dev_class()
2833 if (pending_eir_or_class(hdev)) { in set_dev_class()
2834 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2840 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2845 hdev->major_class = cp->major; in set_dev_class()
2846 hdev->minor_class = cp->minor; in set_dev_class()
2848 if (!hdev_is_powered(hdev)) { in set_dev_class()
2849 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, in set_dev_class()
2850 hdev->dev_class, 3); in set_dev_class()
2854 cmd = mgmt_pending_new(sk, MGMT_OP_SET_DEV_CLASS, hdev, data, len); in set_dev_class()
2863 err = hci_cmd_sync_submit(hdev, set_class_sync, cmd, in set_dev_class()
2869 hci_dev_unlock(hdev); in set_dev_class()
2873 static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data, in load_link_keys() argument
2883 bt_dev_dbg(hdev, "sock %p", sk); in load_link_keys()
2885 if (!lmp_bredr_capable(hdev)) in load_link_keys()
2886 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2891 bt_dev_err(hdev, "load_link_keys: too big key_count value %u", in load_link_keys()
2893 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2899 bt_dev_err(hdev, "load_link_keys: expected %u bytes, got %u bytes", in load_link_keys()
2901 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2906 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2909 bt_dev_dbg(hdev, "debug_keys %u key_count %u", cp->debug_keys, in load_link_keys()
2912 hci_dev_lock(hdev); in load_link_keys()
2914 hci_link_keys_clear(hdev); in load_link_keys()
2917 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in load_link_keys()
2919 changed = hci_dev_test_and_clear_flag(hdev, in load_link_keys()
2923 new_settings(hdev, NULL); in load_link_keys()
2928 if (hci_is_blocked_key(hdev, in load_link_keys()
2931 bt_dev_warn(hdev, "Skipping blocked link key for %pMR", in load_link_keys()
2937 bt_dev_warn(hdev, in load_link_keys()
2944 bt_dev_warn(hdev, "Invalid link key type %u for %pMR", in load_link_keys()
2955 hci_add_link_key(hdev, NULL, &key->addr.bdaddr, key->val, in load_link_keys()
2959 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0); in load_link_keys()
2961 hci_dev_unlock(hdev); in load_link_keys()
2966 static int device_unpaired(struct hci_dev *hdev, bdaddr_t *bdaddr, in device_unpaired() argument
2974 return mgmt_event(MGMT_EV_DEVICE_UNPAIRED, hdev, &ev, sizeof(ev), in device_unpaired()
2978 static void unpair_device_complete(struct hci_dev *hdev, void *data, int err) in unpair_device_complete() argument
2984 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_complete()
2990 static int unpair_device_sync(struct hci_dev *hdev, void *data) in unpair_device_sync() argument
2997 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device_sync()
3000 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in unpair_device_sync()
3014 static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data, in unpair_device() argument
3030 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3035 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3039 hci_dev_lock(hdev); in unpair_device()
3041 if (!hdev_is_powered(hdev)) { in unpair_device()
3042 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3057 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device()
3062 err = hci_remove_link_key(hdev, &cp->addr.bdaddr); in unpair_device()
3064 err = mgmt_cmd_complete(sk, hdev->id, in unpair_device()
3078 err = smp_cancel_and_remove_pairing(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3080 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3086 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3088 hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3099 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3118 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0, in unpair_device()
3120 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk); in unpair_device()
3124 cmd = mgmt_pending_new(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp, in unpair_device()
3133 err = hci_cmd_sync_queue(hdev, unpair_device_sync, cmd, in unpair_device()
3139 hci_dev_unlock(hdev); in unpair_device()
3143 static void disconnect_complete(struct hci_dev *hdev, void *data, int err) in disconnect_complete() argument
3151 static int disconnect_sync(struct hci_dev *hdev, void *data) in disconnect_sync() argument
3158 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in disconnect_sync()
3161 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in disconnect_sync()
3175 static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data, in disconnect() argument
3183 bt_dev_dbg(hdev, "sock %p", sk); in disconnect()
3190 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3194 hci_dev_lock(hdev); in disconnect()
3196 if (!test_bit(HCI_UP, &hdev->flags)) { in disconnect()
3197 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3203 cmd = mgmt_pending_new(sk, MGMT_OP_DISCONNECT, hdev, data, len); in disconnect()
3211 err = hci_cmd_sync_queue(hdev, disconnect_sync, cmd, in disconnect()
3217 hci_dev_unlock(hdev); in disconnect()
3241 static int get_connections(struct sock *sk, struct hci_dev *hdev, void *data, in get_connections() argument
3249 bt_dev_dbg(hdev, "sock %p", sk); in get_connections()
3251 hci_dev_lock(hdev); in get_connections()
3253 if (!hdev_is_powered(hdev)) { in get_connections()
3254 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, in get_connections()
3260 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
3272 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
3285 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, 0, rp, in get_connections()
3291 hci_dev_unlock(hdev); in get_connections()
3295 static int send_pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in send_pin_code_neg_reply() argument
3301 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, hdev, cp, in send_pin_code_neg_reply()
3308 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, in send_pin_code_neg_reply()
3316 static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data, in pin_code_reply() argument
3325 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_reply()
3327 hci_dev_lock(hdev); in pin_code_reply()
3329 if (!hdev_is_powered(hdev)) { in pin_code_reply()
3330 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3335 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in pin_code_reply()
3337 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3347 bt_dev_err(hdev, "PIN code is not 16 bytes long"); in pin_code_reply()
3349 err = send_pin_code_neg_reply(sk, hdev, &ncp); in pin_code_reply()
3351 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3357 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data, len); in pin_code_reply()
3369 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_REPLY, sizeof(reply), &reply); in pin_code_reply()
3374 hci_dev_unlock(hdev); in pin_code_reply()
3378 static int set_io_capability(struct sock *sk, struct hci_dev *hdev, void *data, in set_io_capability() argument
3383 bt_dev_dbg(hdev, "sock %p", sk); in set_io_capability()
3386 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, in set_io_capability()
3389 hci_dev_lock(hdev); in set_io_capability()
3391 hdev->io_capability = cp->io_capability; in set_io_capability()
3393 bt_dev_dbg(hdev, "IO capability set to 0x%02x", hdev->io_capability); in set_io_capability()
3395 hci_dev_unlock(hdev); in set_io_capability()
3397 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, 0, in set_io_capability()
3403 struct hci_dev *hdev = conn->hdev; in find_pairing() local
3406 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in find_pairing()
3495 static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in pair_device() argument
3505 bt_dev_dbg(hdev, "sock %p", sk); in pair_device()
3512 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3517 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3521 hci_dev_lock(hdev); in pair_device()
3523 if (!hdev_is_powered(hdev)) { in pair_device()
3524 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3530 if (hci_bdaddr_is_paired(hdev, &cp->addr.bdaddr, cp->addr.type)) { in pair_device()
3531 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3541 conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level, in pair_device()
3557 p = hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type); in pair_device()
3566 conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr, addr_type, in pair_device()
3583 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3590 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3595 cmd = mgmt_pending_add(sk, MGMT_OP_PAIR_DEVICE, hdev, data, len); in pair_device()
3627 hci_dev_unlock(hdev); in pair_device()
3631 static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in cancel_pair_device() argument
3639 bt_dev_dbg(hdev, "sock %p", sk); in cancel_pair_device()
3641 hci_dev_lock(hdev); in cancel_pair_device()
3643 if (!hdev_is_powered(hdev)) { in cancel_pair_device()
3644 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3649 cmd = pending_find(MGMT_OP_PAIR_DEVICE, hdev); in cancel_pair_device()
3651 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3659 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3667 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0, in cancel_pair_device()
3675 hci_remove_link_key(hdev, &addr->bdaddr); in cancel_pair_device()
3677 smp_cancel_and_remove_pairing(hdev, &addr->bdaddr, in cancel_pair_device()
3684 hci_dev_unlock(hdev); in cancel_pair_device()
3688 static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev, in user_pairing_resp() argument
3696 hci_dev_lock(hdev); in user_pairing_resp()
3698 if (!hdev_is_powered(hdev)) { in user_pairing_resp()
3699 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3706 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &addr->bdaddr); in user_pairing_resp()
3708 conn = hci_conn_hash_lookup_le(hdev, &addr->bdaddr, in user_pairing_resp()
3712 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3721 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3725 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3732 cmd = mgmt_pending_add(sk, mgmt_op, hdev, addr, sizeof(*addr)); in user_pairing_resp()
3746 err = hci_send_cmd(hdev, hci_op, sizeof(cp), &cp); in user_pairing_resp()
3748 err = hci_send_cmd(hdev, hci_op, sizeof(addr->bdaddr), in user_pairing_resp()
3755 hci_dev_unlock(hdev); in user_pairing_resp()
3759 static int pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in pin_code_neg_reply() argument
3764 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_neg_reply()
3766 return user_pairing_resp(sk, hdev, &cp->addr, in pin_code_neg_reply()
3771 static int user_confirm_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_confirm_reply() argument
3776 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_reply()
3779 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_USER_CONFIRM_REPLY, in user_confirm_reply()
3782 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_reply()
3787 static int user_confirm_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_confirm_neg_reply() argument
3792 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_neg_reply()
3794 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_neg_reply()
3799 static int user_passkey_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_passkey_reply() argument
3804 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_reply()
3806 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_reply()
3811 static int user_passkey_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_passkey_neg_reply() argument
3816 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_neg_reply()
3818 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_neg_reply()
3823 static int adv_expire_sync(struct hci_dev *hdev, u32 flags) in adv_expire_sync() argument
3827 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in adv_expire_sync()
3835 cancel_adv_timeout(hdev); in adv_expire_sync()
3837 adv_instance = hci_get_next_instance(hdev, adv_instance->instance); in adv_expire_sync()
3841 hci_schedule_adv_instance_sync(hdev, adv_instance->instance, true); in adv_expire_sync()
3846 static int name_changed_sync(struct hci_dev *hdev, void *data) in name_changed_sync() argument
3848 return adv_expire_sync(hdev, MGMT_ADV_FLAG_LOCAL_NAME); in name_changed_sync()
3851 static void set_name_complete(struct hci_dev *hdev, void *data, int err) in set_name_complete() argument
3857 bt_dev_dbg(hdev, "err %d", err); in set_name_complete()
3860 cmd != pending_find(MGMT_OP_SET_LOCAL_NAME, hdev)) in set_name_complete()
3864 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_name_complete()
3867 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_name_complete()
3870 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_name_complete()
3871 hci_cmd_sync_queue(hdev, name_changed_sync, NULL, NULL); in set_name_complete()
3877 static int set_name_sync(struct hci_dev *hdev, void *data) in set_name_sync() argument
3879 if (lmp_bredr_capable(hdev)) { in set_name_sync()
3880 hci_update_name_sync(hdev); in set_name_sync()
3881 hci_update_eir_sync(hdev); in set_name_sync()
3887 if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING)) in set_name_sync()
3888 hci_update_scan_rsp_data_sync(hdev, hdev->cur_adv_instance); in set_name_sync()
3893 static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data, in set_local_name() argument
3900 bt_dev_dbg(hdev, "sock %p", sk); in set_local_name()
3902 hci_dev_lock(hdev); in set_local_name()
3907 if (!memcmp(hdev->dev_name, cp->name, sizeof(hdev->dev_name)) && in set_local_name()
3908 !memcmp(hdev->short_name, cp->short_name, in set_local_name()
3909 sizeof(hdev->short_name))) { in set_local_name()
3910 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3915 memcpy(hdev->short_name, cp->short_name, sizeof(hdev->short_name)); in set_local_name()
3917 if (!hdev_is_powered(hdev)) { in set_local_name()
3918 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3920 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3925 err = mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, data, in set_local_name()
3927 ext_info_changed(hdev, sk); in set_local_name()
3932 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len); in set_local_name()
3936 err = hci_cmd_sync_queue(hdev, set_name_sync, cmd, in set_local_name()
3940 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_local_name()
3949 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3952 hci_dev_unlock(hdev); in set_local_name()
3956 static int appearance_changed_sync(struct hci_dev *hdev, void *data) in appearance_changed_sync() argument
3958 return adv_expire_sync(hdev, MGMT_ADV_FLAG_APPEARANCE); in appearance_changed_sync()
3961 static int set_appearance(struct sock *sk, struct hci_dev *hdev, void *data, in set_appearance() argument
3968 bt_dev_dbg(hdev, "sock %p", sk); in set_appearance()
3970 if (!lmp_le_capable(hdev)) in set_appearance()
3971 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_APPEARANCE, in set_appearance()
3976 hci_dev_lock(hdev); in set_appearance()
3978 if (hdev->appearance != appearance) { in set_appearance()
3979 hdev->appearance = appearance; in set_appearance()
3981 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_appearance()
3982 hci_cmd_sync_queue(hdev, appearance_changed_sync, NULL, in set_appearance()
3985 ext_info_changed(hdev, sk); in set_appearance()
3988 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_APPEARANCE, 0, NULL, in set_appearance()
3991 hci_dev_unlock(hdev); in set_appearance()
3996 static int get_phy_configuration(struct sock *sk, struct hci_dev *hdev, in get_phy_configuration() argument
4001 bt_dev_dbg(hdev, "sock %p", sk); in get_phy_configuration()
4003 hci_dev_lock(hdev); in get_phy_configuration()
4007 rp.supported_phys = cpu_to_le32(get_supported_phys(hdev)); in get_phy_configuration()
4008 rp.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in get_phy_configuration()
4009 rp.configurable_phys = cpu_to_le32(get_configurable_phys(hdev)); in get_phy_configuration()
4011 hci_dev_unlock(hdev); in get_phy_configuration()
4013 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_PHY_CONFIGURATION, 0, in get_phy_configuration()
4017 int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip) in mgmt_phy_configuration_changed() argument
4023 ev.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in mgmt_phy_configuration_changed()
4025 return mgmt_event(MGMT_EV_PHY_CONFIGURATION_CHANGED, hdev, &ev, in mgmt_phy_configuration_changed()
4029 static void set_default_phy_complete(struct hci_dev *hdev, void *data, int err) in set_default_phy_complete() argument
4036 cmd != pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) in set_default_phy_complete()
4048 bt_dev_dbg(hdev, "status %d", status); in set_default_phy_complete()
4051 mgmt_cmd_status(cmd->sk, hdev->id, in set_default_phy_complete()
4054 mgmt_cmd_complete(cmd->sk, hdev->id, in set_default_phy_complete()
4058 mgmt_phy_configuration_changed(hdev, cmd->sk); in set_default_phy_complete()
4067 static int set_default_phy_sync(struct hci_dev *hdev, void *data) in set_default_phy_sync() argument
4100 cmd->skb = __hci_cmd_sync(hdev, HCI_OP_LE_SET_DEFAULT_PHY, in set_default_phy_sync()
4106 static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, in set_phy_configuration() argument
4116 bt_dev_dbg(hdev, "sock %p", sk); in set_phy_configuration()
4118 configurable_phys = get_configurable_phys(hdev); in set_phy_configuration()
4119 supported_phys = get_supported_phys(hdev); in set_phy_configuration()
4123 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4130 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4134 if (selected_phys == get_selected_phys(hdev)) in set_phy_configuration()
4135 return mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
4139 hci_dev_lock(hdev); in set_phy_configuration()
4141 if (!hdev_is_powered(hdev)) { in set_phy_configuration()
4142 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4148 if (pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) { in set_phy_configuration()
4149 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4195 if (pkt_type != hdev->pkt_type) { in set_phy_configuration()
4196 hdev->pkt_type = pkt_type; in set_phy_configuration()
4201 (get_selected_phys(hdev) & MGMT_PHY_LE_MASK)) { in set_phy_configuration()
4203 mgmt_phy_configuration_changed(hdev, sk); in set_phy_configuration()
4205 err = mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
4212 cmd = mgmt_pending_add(sk, MGMT_OP_SET_PHY_CONFIGURATION, hdev, data, in set_phy_configuration()
4217 err = hci_cmd_sync_queue(hdev, set_default_phy_sync, cmd, in set_phy_configuration()
4221 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4230 hci_dev_unlock(hdev); in set_phy_configuration()
4235 static int set_blocked_keys(struct sock *sk, struct hci_dev *hdev, void *data, in set_blocked_keys() argument
4245 bt_dev_dbg(hdev, "sock %p", sk); in set_blocked_keys()
4249 bt_dev_err(hdev, "too big key_count value %u", key_count); in set_blocked_keys()
4250 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4256 bt_dev_err(hdev, "expected %u bytes, got %u bytes", in set_blocked_keys()
4258 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4262 hci_dev_lock(hdev); in set_blocked_keys()
4264 hci_blocked_keys_clear(hdev); in set_blocked_keys()
4276 list_add_rcu(&b->list, &hdev->blocked_keys); in set_blocked_keys()
4278 hci_dev_unlock(hdev); in set_blocked_keys()
4280 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4284 static int set_wideband_speech(struct sock *sk, struct hci_dev *hdev, in set_wideband_speech() argument
4291 bt_dev_dbg(hdev, "sock %p", sk); in set_wideband_speech()
4293 if (!test_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks)) in set_wideband_speech()
4294 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4299 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4303 hci_dev_lock(hdev); in set_wideband_speech()
4305 if (hdev_is_powered(hdev) && in set_wideband_speech()
4306 !!cp->val != hci_dev_test_flag(hdev, in set_wideband_speech()
4308 err = mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4315 changed = !hci_dev_test_and_set_flag(hdev, in set_wideband_speech()
4318 changed = hci_dev_test_and_clear_flag(hdev, in set_wideband_speech()
4321 err = send_settings_rsp(sk, MGMT_OP_SET_WIDEBAND_SPEECH, hdev); in set_wideband_speech()
4326 err = new_settings(hdev, sk); in set_wideband_speech()
4329 hci_dev_unlock(hdev); in set_wideband_speech()
4333 static int read_controller_cap(struct sock *sk, struct hci_dev *hdev, in read_controller_cap() argument
4342 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_cap()
4346 hci_dev_lock(hdev); in read_controller_cap()
4354 if ((hdev->commands[41] & 0x08) || msft_curve_validity(hdev)) in read_controller_cap()
4362 if (hdev->commands[20] & 0x10) in read_controller_cap()
4373 if (hdev->commands[41] & 0x08) in read_controller_cap()
4376 hdev->max_enc_key_size); in read_controller_cap()
4385 if (hdev->commands[38] & 0x80) { in read_controller_cap()
4386 memcpy(&tx_power_range[0], &hdev->min_le_tx_power, 1); in read_controller_cap()
4387 memcpy(&tx_power_range[1], &hdev->max_le_tx_power, 1); in read_controller_cap()
4394 hci_dev_unlock(hdev); in read_controller_cap()
4396 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONTROLLER_CAP, 0, in read_controller_cap()
4438 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, in read_exp_features_info() argument
4447 bt_dev_dbg(hdev, "sock %p", sk); in read_exp_features_info()
4456 if (!hdev) { in read_exp_features_info()
4465 if (hdev && hci_dev_le_state_simultaneous(hdev)) { in read_exp_features_info()
4466 if (hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) in read_exp_features_info()
4476 if (hdev && (aosp_has_quality_report(hdev) || in read_exp_features_info()
4477 hdev->set_quality_report)) { in read_exp_features_info()
4478 if (hci_dev_test_flag(hdev, HCI_QUALITY_REPORT)) in read_exp_features_info()
4488 if (hdev && hdev->get_data_path_id) { in read_exp_features_info()
4489 if (hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)) in read_exp_features_info()
4506 if (hdev && lmp_le_capable(hdev)) { in read_exp_features_info()
4507 if (hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in read_exp_features_info()
4524 status = mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in read_exp_features_info()
4532 static int exp_feature_changed(struct hci_dev *hdev, const u8 *uuid, in exp_feature_changed() argument
4541 return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, in exp_feature_changed()
4553 static int set_zero_key_func(struct sock *sk, struct hci_dev *hdev, in set_zero_key_func() argument
4562 if (!hdev) { in set_zero_key_func()
4574 return mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_zero_key_func()
4580 static int set_debug_func(struct sock *sk, struct hci_dev *hdev, in set_debug_func() argument
4589 if (hdev) in set_debug_func()
4590 return mgmt_cmd_status(sk, hdev->id, in set_debug_func()
4620 exp_feature_changed(hdev, debug_uuid, val, sk); in set_debug_func()
4626 static int set_mgmt_mesh_func(struct sock *sk, struct hci_dev *hdev, in set_mgmt_mesh_func() argument
4634 if (!hdev) in set_mgmt_mesh_func()
4641 return mgmt_cmd_status(sk, hdev->id, in set_mgmt_mesh_func()
4647 return mgmt_cmd_status(sk, hdev->id, in set_mgmt_mesh_func()
4654 changed = !hci_dev_test_and_set_flag(hdev, in set_mgmt_mesh_func()
4657 hci_dev_clear_flag(hdev, HCI_MESH); in set_mgmt_mesh_func()
4658 changed = hci_dev_test_and_clear_flag(hdev, in set_mgmt_mesh_func()
4667 err = mgmt_cmd_complete(sk, hdev->id, in set_mgmt_mesh_func()
4672 exp_feature_changed(hdev, mgmt_mesh_uuid, val, sk); in set_mgmt_mesh_func()
4677 static int set_quality_report_func(struct sock *sk, struct hci_dev *hdev, in set_quality_report_func() argument
4686 if (!hdev) in set_quality_report_func()
4693 return mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4699 return mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4703 hci_req_sync_lock(hdev); in set_quality_report_func()
4706 changed = (val != hci_dev_test_flag(hdev, HCI_QUALITY_REPORT)); in set_quality_report_func()
4708 if (!aosp_has_quality_report(hdev) && !hdev->set_quality_report) { in set_quality_report_func()
4709 err = mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4716 if (hdev->set_quality_report) in set_quality_report_func()
4717 err = hdev->set_quality_report(hdev, val); in set_quality_report_func()
4719 err = aosp_set_quality_report(hdev, val); in set_quality_report_func()
4722 err = mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4729 hci_dev_set_flag(hdev, HCI_QUALITY_REPORT); in set_quality_report_func()
4731 hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT); in set_quality_report_func()
4734 bt_dev_dbg(hdev, "quality report enable %d changed %d", val, changed); in set_quality_report_func()
4740 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_EXP_FEATURE, 0, in set_quality_report_func()
4744 exp_feature_changed(hdev, quality_report_uuid, val, sk); in set_quality_report_func()
4747 hci_req_sync_unlock(hdev); in set_quality_report_func()
4751 static int set_offload_codec_func(struct sock *sk, struct hci_dev *hdev, in set_offload_codec_func() argument
4760 if (!hdev) in set_offload_codec_func()
4767 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4773 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4778 changed = (val != hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)); in set_offload_codec_func()
4780 if (!hdev->get_data_path_id) { in set_offload_codec_func()
4781 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4788 hci_dev_set_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED); in set_offload_codec_func()
4790 hci_dev_clear_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED); in set_offload_codec_func()
4793 bt_dev_info(hdev, "offload codecs enable %d changed %d", in set_offload_codec_func()
4799 err = mgmt_cmd_complete(sk, hdev->id, in set_offload_codec_func()
4804 exp_feature_changed(hdev, offload_codecs_uuid, val, sk); in set_offload_codec_func()
4809 static int set_le_simultaneous_roles_func(struct sock *sk, struct hci_dev *hdev, in set_le_simultaneous_roles_func() argument
4818 if (!hdev) in set_le_simultaneous_roles_func()
4825 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4831 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4836 changed = (val != hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)); in set_le_simultaneous_roles_func()
4838 if (!hci_dev_le_state_simultaneous(hdev)) { in set_le_simultaneous_roles_func()
4839 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4846 hci_dev_set_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); in set_le_simultaneous_roles_func()
4848 hci_dev_clear_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); in set_le_simultaneous_roles_func()
4851 bt_dev_info(hdev, "LE simultaneous roles enable %d changed %d", in set_le_simultaneous_roles_func()
4857 err = mgmt_cmd_complete(sk, hdev->id, in set_le_simultaneous_roles_func()
4862 exp_feature_changed(hdev, le_simultaneous_roles_uuid, val, sk); in set_le_simultaneous_roles_func()
4868 static int set_iso_socket_func(struct sock *sk, struct hci_dev *hdev, in set_iso_socket_func() argument
4876 if (hdev) in set_iso_socket_func()
4877 return mgmt_cmd_status(sk, hdev->id, in set_iso_socket_func()
4912 exp_feature_changed(hdev, iso_socket_uuid, val, sk); in set_iso_socket_func()
4920 int (*set_func)(struct sock *sk, struct hci_dev *hdev,
4939 static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, in set_exp_feature() argument
4945 bt_dev_dbg(hdev, "sock %p", sk); in set_exp_feature()
4949 return exp_features[i].set_func(sk, hdev, cp, data_len); in set_exp_feature()
4952 return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_exp_feature()
4957 static int get_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in get_device_flags() argument
4968 bt_dev_dbg(hdev, "Get device flags %pMR (type 0x%x)\n", in get_device_flags()
4971 hci_dev_lock(hdev); in get_device_flags()
4973 supported_flags = hdev->conn_flags; in get_device_flags()
4978 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, in get_device_flags()
4986 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in get_device_flags()
5002 hci_dev_unlock(hdev); in get_device_flags()
5004 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_DEVICE_FLAGS, status, in get_device_flags()
5008 static void device_flags_changed(struct sock *sk, struct hci_dev *hdev, in device_flags_changed() argument
5019 mgmt_event(MGMT_EV_DEVICE_FLAGS_CHANGED, hdev, &ev, sizeof(ev), sk); in device_flags_changed()
5022 static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_flags() argument
5032 bt_dev_dbg(hdev, "Set device flags %pMR (type 0x%x) = 0x%x", in set_device_flags()
5036 supported_flags = hdev->conn_flags; in set_device_flags()
5039 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
5044 hci_dev_lock(hdev); in set_device_flags()
5047 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, in set_device_flags()
5055 bt_dev_warn(hdev, "No such BR/EDR device %pMR (0x%x)", in set_device_flags()
5062 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in set_device_flags()
5065 bt_dev_warn(hdev, "No such LE device %pMR (0x%x)", in set_device_flags()
5070 supported_flags = hdev->conn_flags; in set_device_flags()
5073 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
5085 hci_update_passive_scan(hdev); in set_device_flags()
5088 hci_dev_unlock(hdev); in set_device_flags()
5092 device_flags_changed(sk, hdev, &cp->addr.bdaddr, cp->addr.type, in set_device_flags()
5095 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_FLAGS, status, in set_device_flags()
5099 static void mgmt_adv_monitor_added(struct sock *sk, struct hci_dev *hdev, in mgmt_adv_monitor_added() argument
5106 mgmt_event(MGMT_EV_ADV_MONITOR_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_adv_monitor_added()
5109 void mgmt_adv_monitor_removed(struct hci_dev *hdev, u16 handle) in mgmt_adv_monitor_removed() argument
5116 cmd = pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev); in mgmt_adv_monitor_removed()
5126 mgmt_event(MGMT_EV_ADV_MONITOR_REMOVED, hdev, &ev, sizeof(ev), sk_skip); in mgmt_adv_monitor_removed()
5129 static int read_adv_mon_features(struct sock *sk, struct hci_dev *hdev, in read_adv_mon_features() argument
5141 BT_DBG("request for %s", hdev->name); in read_adv_mon_features()
5143 hci_dev_lock(hdev); in read_adv_mon_features()
5145 if (msft_monitor_supported(hdev)) in read_adv_mon_features()
5148 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) in read_adv_mon_features()
5151 hci_dev_unlock(hdev); in read_adv_mon_features()
5169 err = mgmt_cmd_complete(sk, hdev->id, in read_adv_mon_features()
5178 static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, in mgmt_add_adv_patterns_monitor_complete() argument
5185 hci_dev_lock(hdev); in mgmt_add_adv_patterns_monitor_complete()
5190 mgmt_adv_monitor_added(cmd->sk, hdev, monitor->handle); in mgmt_add_adv_patterns_monitor_complete()
5191 hdev->adv_monitors_cnt++; in mgmt_add_adv_patterns_monitor_complete()
5194 hci_update_passive_scan(hdev); in mgmt_add_adv_patterns_monitor_complete()
5201 hci_dev_unlock(hdev); in mgmt_add_adv_patterns_monitor_complete()
5202 bt_dev_dbg(hdev, "add monitor %d complete, status %d", in mgmt_add_adv_patterns_monitor_complete()
5206 static int mgmt_add_adv_patterns_monitor_sync(struct hci_dev *hdev, void *data) in mgmt_add_adv_patterns_monitor_sync() argument
5211 return hci_add_adv_monitor(hdev, monitor); in mgmt_add_adv_patterns_monitor_sync()
5214 static int __add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in __add_adv_patterns_monitor() argument
5221 hci_dev_lock(hdev); in __add_adv_patterns_monitor()
5226 if (pending_find(MGMT_OP_SET_LE, hdev) || in __add_adv_patterns_monitor()
5227 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR, hdev) || in __add_adv_patterns_monitor()
5228 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI, hdev) || in __add_adv_patterns_monitor()
5229 pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev)) { in __add_adv_patterns_monitor()
5234 cmd = mgmt_pending_add(sk, op, hdev, data, len); in __add_adv_patterns_monitor()
5241 err = hci_cmd_sync_queue(hdev, mgmt_add_adv_patterns_monitor_sync, cmd, in __add_adv_patterns_monitor()
5252 hci_dev_unlock(hdev); in __add_adv_patterns_monitor()
5257 hci_free_adv_monitor(hdev, m); in __add_adv_patterns_monitor()
5258 hci_dev_unlock(hdev); in __add_adv_patterns_monitor()
5259 return mgmt_cmd_status(sk, hdev->id, op, status); in __add_adv_patterns_monitor()
5318 static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor() argument
5326 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor()
5351 return __add_adv_patterns_monitor(sk, hdev, m, status, data, len, in add_adv_patterns_monitor()
5355 static int add_adv_patterns_monitor_rssi(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor_rssi() argument
5363 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor_rssi()
5388 return __add_adv_patterns_monitor(sk, hdev, m, status, data, len, in add_adv_patterns_monitor_rssi()
5392 static void mgmt_remove_adv_monitor_complete(struct hci_dev *hdev, in mgmt_remove_adv_monitor_complete() argument
5400 cmd != pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev)) in mgmt_remove_adv_monitor_complete()
5403 hci_dev_lock(hdev); in mgmt_remove_adv_monitor_complete()
5410 hci_update_passive_scan(hdev); in mgmt_remove_adv_monitor_complete()
5416 hci_dev_unlock(hdev); in mgmt_remove_adv_monitor_complete()
5417 bt_dev_dbg(hdev, "remove monitor %d complete, status %d", in mgmt_remove_adv_monitor_complete()
5421 static int mgmt_remove_adv_monitor_sync(struct hci_dev *hdev, void *data) in mgmt_remove_adv_monitor_sync() argument
5425 if (cmd != pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev)) in mgmt_remove_adv_monitor_sync()
5432 return hci_remove_all_adv_monitor(hdev); in mgmt_remove_adv_monitor_sync()
5434 return hci_remove_single_adv_monitor(hdev, handle); in mgmt_remove_adv_monitor_sync()
5437 static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev, in remove_adv_monitor() argument
5443 hci_dev_lock(hdev); in remove_adv_monitor()
5445 if (pending_find(MGMT_OP_SET_LE, hdev) || in remove_adv_monitor()
5446 pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev) || in remove_adv_monitor()
5447 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR, hdev) || in remove_adv_monitor()
5448 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI, hdev)) { in remove_adv_monitor()
5453 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_ADV_MONITOR, hdev, data, len); in remove_adv_monitor()
5459 err = hci_cmd_sync_submit(hdev, mgmt_remove_adv_monitor_sync, cmd, in remove_adv_monitor()
5473 hci_dev_unlock(hdev); in remove_adv_monitor()
5478 hci_dev_unlock(hdev); in remove_adv_monitor()
5479 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, in remove_adv_monitor()
5483 static void read_local_oob_data_complete(struct hci_dev *hdev, void *data, int err) in read_local_oob_data_complete() argument
5500 bt_dev_dbg(hdev, "status %d", status); in read_local_oob_data_complete()
5503 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, status); in read_local_oob_data_complete()
5509 if (!bredr_sc_enabled(hdev)) { in read_local_oob_data_complete()
5513 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
5527 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
5540 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data_complete()
5550 static int read_local_oob_data_sync(struct hci_dev *hdev, void *data) in read_local_oob_data_sync() argument
5554 if (bredr_sc_enabled(hdev)) in read_local_oob_data_sync()
5555 cmd->skb = hci_read_local_oob_data_sync(hdev, true, cmd->sk); in read_local_oob_data_sync()
5557 cmd->skb = hci_read_local_oob_data_sync(hdev, false, cmd->sk); in read_local_oob_data_sync()
5565 static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_data() argument
5571 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_data()
5573 hci_dev_lock(hdev); in read_local_oob_data()
5575 if (!hdev_is_powered(hdev)) { in read_local_oob_data()
5576 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5581 if (!lmp_ssp_capable(hdev)) { in read_local_oob_data()
5582 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5587 cmd = mgmt_pending_new(sk, MGMT_OP_READ_LOCAL_OOB_DATA, hdev, NULL, 0); in read_local_oob_data()
5591 err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd, in read_local_oob_data()
5595 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5603 hci_dev_unlock(hdev); in read_local_oob_data()
5607 static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in add_remote_oob_data() argument
5613 bt_dev_dbg(hdev, "sock %p", sk); in add_remote_oob_data()
5616 return mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5621 hci_dev_lock(hdev); in add_remote_oob_data()
5628 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5635 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
5643 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5657 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5692 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
5700 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5704 bt_dev_err(hdev, "add_remote_oob_data: invalid len of %u bytes", in add_remote_oob_data()
5706 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, in add_remote_oob_data()
5711 hci_dev_unlock(hdev); in add_remote_oob_data()
5715 static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in remove_remote_oob_data() argument
5722 bt_dev_dbg(hdev, "sock %p", sk); in remove_remote_oob_data()
5725 return mgmt_cmd_complete(sk, hdev->id, in remove_remote_oob_data()
5730 hci_dev_lock(hdev); in remove_remote_oob_data()
5733 hci_remote_oob_data_clear(hdev); in remove_remote_oob_data()
5738 err = hci_remove_remote_oob_data(hdev, &cp->addr.bdaddr, cp->addr.type); in remove_remote_oob_data()
5745 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA, in remove_remote_oob_data()
5748 hci_dev_unlock(hdev); in remove_remote_oob_data()
5752 static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, in discovery_type_is_valid() argument
5757 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
5762 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
5767 *mgmt_status = mgmt_bredr_support(hdev); in discovery_type_is_valid()
5779 static void start_discovery_complete(struct hci_dev *hdev, void *data, int err) in start_discovery_complete() argument
5783 bt_dev_dbg(hdev, "err %d", err); in start_discovery_complete()
5788 if (cmd != pending_find(MGMT_OP_START_DISCOVERY, hdev) && in start_discovery_complete()
5789 cmd != pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev) && in start_discovery_complete()
5790 cmd != pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev)) in start_discovery_complete()
5797 hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED: in start_discovery_complete()
5801 static int start_discovery_sync(struct hci_dev *hdev, void *data) in start_discovery_sync() argument
5803 return hci_start_discovery_sync(hdev); in start_discovery_sync()
5806 static int start_discovery_internal(struct sock *sk, struct hci_dev *hdev, in start_discovery_internal() argument
5814 bt_dev_dbg(hdev, "sock %p", sk); in start_discovery_internal()
5816 hci_dev_lock(hdev); in start_discovery_internal()
5818 if (!hdev_is_powered(hdev)) { in start_discovery_internal()
5819 err = mgmt_cmd_complete(sk, hdev->id, op, in start_discovery_internal()
5825 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_discovery_internal()
5826 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_discovery_internal()
5827 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
5832 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_discovery_internal()
5833 err = mgmt_cmd_complete(sk, hdev->id, op, status, in start_discovery_internal()
5839 if (hdev->discovery_paused) { in start_discovery_internal()
5840 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
5848 hci_discovery_filter_clear(hdev); in start_discovery_internal()
5850 hdev->discovery.type = cp->type; in start_discovery_internal()
5851 hdev->discovery.report_invalid_rssi = false; in start_discovery_internal()
5853 hdev->discovery.limited = true; in start_discovery_internal()
5855 hdev->discovery.limited = false; in start_discovery_internal()
5857 cmd = mgmt_pending_add(sk, op, hdev, data, len); in start_discovery_internal()
5863 err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd, in start_discovery_internal()
5870 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_discovery_internal()
5873 hci_dev_unlock(hdev); in start_discovery_internal()
5877 static int start_discovery(struct sock *sk, struct hci_dev *hdev, in start_discovery() argument
5880 return start_discovery_internal(sk, hdev, MGMT_OP_START_DISCOVERY, in start_discovery()
5884 static int start_limited_discovery(struct sock *sk, struct hci_dev *hdev, in start_limited_discovery() argument
5887 return start_discovery_internal(sk, hdev, in start_limited_discovery()
5892 static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, in start_service_discovery() argument
5902 bt_dev_dbg(hdev, "sock %p", sk); in start_service_discovery()
5904 hci_dev_lock(hdev); in start_service_discovery()
5906 if (!hdev_is_powered(hdev)) { in start_service_discovery()
5907 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5914 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_service_discovery()
5915 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_service_discovery()
5916 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5923 if (hdev->discovery_paused) { in start_service_discovery()
5924 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5933 bt_dev_err(hdev, "service_discovery: too big uuid_count value %u", in start_service_discovery()
5935 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5944 bt_dev_err(hdev, "service_discovery: expected %u bytes, got %u bytes", in start_service_discovery()
5946 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5953 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_service_discovery()
5954 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5961 hdev, data, len); in start_service_discovery()
5970 hci_discovery_filter_clear(hdev); in start_service_discovery()
5972 hdev->discovery.result_filtering = true; in start_service_discovery()
5973 hdev->discovery.type = cp->type; in start_service_discovery()
5974 hdev->discovery.rssi = cp->rssi; in start_service_discovery()
5975 hdev->discovery.uuid_count = uuid_count; in start_service_discovery()
5978 hdev->discovery.uuids = kmemdup(cp->uuids, uuid_count * 16, in start_service_discovery()
5980 if (!hdev->discovery.uuids) { in start_service_discovery()
5981 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5990 err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd, in start_service_discovery()
5997 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_service_discovery()
6000 hci_dev_unlock(hdev); in start_service_discovery()
6004 static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) in stop_discovery_complete() argument
6009 cmd != pending_find(MGMT_OP_STOP_DISCOVERY, hdev)) in stop_discovery_complete()
6012 bt_dev_dbg(hdev, "err %d", err); in stop_discovery_complete()
6019 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in stop_discovery_complete()
6022 static int stop_discovery_sync(struct hci_dev *hdev, void *data) in stop_discovery_sync() argument
6024 return hci_stop_discovery_sync(hdev); in stop_discovery_sync()
6027 static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, in stop_discovery() argument
6034 bt_dev_dbg(hdev, "sock %p", sk); in stop_discovery()
6036 hci_dev_lock(hdev); in stop_discovery()
6038 if (!hci_discovery_active(hdev)) { in stop_discovery()
6039 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
6045 if (hdev->discovery.type != mgmt_cp->type) { in stop_discovery()
6046 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
6052 cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, hdev, data, len); in stop_discovery()
6058 err = hci_cmd_sync_queue(hdev, stop_discovery_sync, cmd, in stop_discovery()
6065 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in stop_discovery()
6068 hci_dev_unlock(hdev); in stop_discovery()
6072 static int confirm_name(struct sock *sk, struct hci_dev *hdev, void *data, in confirm_name() argument
6079 bt_dev_dbg(hdev, "sock %p", sk); in confirm_name()
6081 hci_dev_lock(hdev); in confirm_name()
6083 if (!hci_discovery_active(hdev)) { in confirm_name()
6084 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
6090 e = hci_inquiry_cache_lookup_unknown(hdev, &cp->addr.bdaddr); in confirm_name()
6092 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
6103 hci_inquiry_cache_update_resolve(hdev, e); in confirm_name()
6106 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, 0, in confirm_name()
6110 hci_dev_unlock(hdev); in confirm_name()
6114 static int block_device(struct sock *sk, struct hci_dev *hdev, void *data, in block_device() argument
6121 bt_dev_dbg(hdev, "sock %p", sk); in block_device()
6124 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, in block_device()
6128 hci_dev_lock(hdev); in block_device()
6130 err = hci_bdaddr_list_add(&hdev->reject_list, &cp->addr.bdaddr, in block_device()
6137 mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &cp->addr, sizeof(cp->addr), in block_device()
6142 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status, in block_device()
6145 hci_dev_unlock(hdev); in block_device()
6150 static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data, in unblock_device() argument
6157 bt_dev_dbg(hdev, "sock %p", sk); in unblock_device()
6160 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, in unblock_device()
6164 hci_dev_lock(hdev); in unblock_device()
6166 err = hci_bdaddr_list_del(&hdev->reject_list, &cp->addr.bdaddr, in unblock_device()
6173 mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &cp->addr, sizeof(cp->addr), in unblock_device()
6178 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status, in unblock_device()
6181 hci_dev_unlock(hdev); in unblock_device()
6186 static int set_device_id_sync(struct hci_dev *hdev, void *data) in set_device_id_sync() argument
6188 return hci_update_eir_sync(hdev); in set_device_id_sync()
6191 static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_id() argument
6198 bt_dev_dbg(hdev, "sock %p", sk); in set_device_id()
6203 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, in set_device_id()
6206 hci_dev_lock(hdev); in set_device_id()
6208 hdev->devid_source = source; in set_device_id()
6209 hdev->devid_vendor = __le16_to_cpu(cp->vendor); in set_device_id()
6210 hdev->devid_product = __le16_to_cpu(cp->product); in set_device_id()
6211 hdev->devid_version = __le16_to_cpu(cp->version); in set_device_id()
6213 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, 0, in set_device_id()
6216 hci_cmd_sync_queue(hdev, set_device_id_sync, NULL, NULL); in set_device_id()
6218 hci_dev_unlock(hdev); in set_device_id()
6223 static void enable_advertising_instance(struct hci_dev *hdev, int err) in enable_advertising_instance() argument
6226 bt_dev_err(hdev, "failed to re-configure advertising %d", err); in enable_advertising_instance()
6228 bt_dev_dbg(hdev, "status %d", err); in enable_advertising_instance()
6231 static void set_advertising_complete(struct hci_dev *hdev, void *data, int err) in set_advertising_complete() argument
6233 struct cmd_lookup match = { NULL, hdev }; in set_advertising_complete()
6239 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, in set_advertising_complete()
6244 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_advertising_complete()
6245 hci_dev_set_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
6247 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
6249 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, settings_rsp, in set_advertising_complete()
6252 new_settings(hdev, match.sk); in set_advertising_complete()
6260 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in set_advertising_complete()
6261 list_empty(&hdev->adv_instances)) in set_advertising_complete()
6264 instance = hdev->cur_adv_instance; in set_advertising_complete()
6266 adv_instance = list_first_entry_or_null(&hdev->adv_instances, in set_advertising_complete()
6274 err = hci_schedule_adv_instance_sync(hdev, instance, true); in set_advertising_complete()
6276 enable_advertising_instance(hdev, err); in set_advertising_complete()
6279 static int set_adv_sync(struct hci_dev *hdev, void *data) in set_adv_sync() argument
6286 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_adv_sync()
6288 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_adv_sync()
6290 cancel_adv_timeout(hdev); in set_adv_sync()
6297 hdev->cur_adv_instance = 0x00; in set_adv_sync()
6299 if (ext_adv_capable(hdev)) { in set_adv_sync()
6300 hci_start_ext_adv_sync(hdev, 0x00); in set_adv_sync()
6302 hci_update_adv_data_sync(hdev, 0x00); in set_adv_sync()
6303 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_adv_sync()
6304 hci_enable_advertising_sync(hdev); in set_adv_sync()
6307 hci_disable_advertising_sync(hdev); in set_adv_sync()
6313 static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, in set_advertising() argument
6321 bt_dev_dbg(hdev, "sock %p", sk); in set_advertising()
6323 status = mgmt_le_support(hdev); in set_advertising()
6325 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6329 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6332 if (hdev->advertising_paused) in set_advertising()
6333 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6336 hci_dev_lock(hdev); in set_advertising()
6345 if (!hdev_is_powered(hdev) || in set_advertising()
6346 (val == hci_dev_test_flag(hdev, HCI_ADVERTISING) && in set_advertising()
6347 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) || in set_advertising()
6348 hci_dev_test_flag(hdev, HCI_MESH) || in set_advertising()
6349 hci_conn_num(hdev, LE_LINK) > 0 || in set_advertising()
6350 (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_advertising()
6351 hdev->le_scan_type == LE_SCAN_ACTIVE)) { in set_advertising()
6355 hdev->cur_adv_instance = 0x00; in set_advertising()
6356 changed = !hci_dev_test_and_set_flag(hdev, HCI_ADVERTISING); in set_advertising()
6358 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6360 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6362 changed = hci_dev_test_and_clear_flag(hdev, HCI_ADVERTISING); in set_advertising()
6363 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6366 err = send_settings_rsp(sk, MGMT_OP_SET_ADVERTISING, hdev); in set_advertising()
6371 err = new_settings(hdev, sk); in set_advertising()
6376 if (pending_find(MGMT_OP_SET_ADVERTISING, hdev) || in set_advertising()
6377 pending_find(MGMT_OP_SET_LE, hdev)) { in set_advertising()
6378 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6383 cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING, hdev, data, len); in set_advertising()
6387 err = hci_cmd_sync_queue(hdev, set_adv_sync, cmd, in set_advertising()
6394 hci_dev_unlock(hdev); in set_advertising()
6398 static int set_static_address(struct sock *sk, struct hci_dev *hdev, in set_static_address() argument
6404 bt_dev_dbg(hdev, "sock %p", sk); in set_static_address()
6406 if (!lmp_le_capable(hdev)) in set_static_address()
6407 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
6410 if (hdev_is_powered(hdev)) in set_static_address()
6411 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
6416 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
6422 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
6427 hci_dev_lock(hdev); in set_static_address()
6429 bacpy(&hdev->static_addr, &cp->bdaddr); in set_static_address()
6431 err = send_settings_rsp(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev); in set_static_address()
6435 err = new_settings(hdev, sk); in set_static_address()
6438 hci_dev_unlock(hdev); in set_static_address()
6442 static int set_scan_params(struct sock *sk, struct hci_dev *hdev, in set_scan_params() argument
6449 bt_dev_dbg(hdev, "sock %p", sk); in set_scan_params()
6451 if (!lmp_le_capable(hdev)) in set_scan_params()
6452 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6458 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6464 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6468 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6471 hci_dev_lock(hdev); in set_scan_params()
6473 hdev->le_scan_interval = interval; in set_scan_params()
6474 hdev->le_scan_window = window; in set_scan_params()
6476 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, 0, in set_scan_params()
6482 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_scan_params()
6483 hdev->discovery.state == DISCOVERY_STOPPED) in set_scan_params()
6484 hci_update_passive_scan(hdev); in set_scan_params()
6486 hci_dev_unlock(hdev); in set_scan_params()
6491 static void fast_connectable_complete(struct hci_dev *hdev, void *data, int err) in fast_connectable_complete() argument
6495 bt_dev_dbg(hdev, "err %d", err); in fast_connectable_complete()
6498 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in fast_connectable_complete()
6504 hci_dev_set_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
6506 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
6508 send_settings_rsp(cmd->sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in fast_connectable_complete()
6509 new_settings(hdev, cmd->sk); in fast_connectable_complete()
6515 static int write_fast_connectable_sync(struct hci_dev *hdev, void *data) in write_fast_connectable_sync() argument
6520 return hci_write_fast_connectable_sync(hdev, cp->val); in write_fast_connectable_sync()
6523 static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev, in set_fast_connectable() argument
6530 bt_dev_dbg(hdev, "sock %p", sk); in set_fast_connectable()
6532 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in set_fast_connectable()
6533 hdev->hci_ver < BLUETOOTH_VER_1_2) in set_fast_connectable()
6534 return mgmt_cmd_status(sk, hdev->id, in set_fast_connectable()
6539 return mgmt_cmd_status(sk, hdev->id, in set_fast_connectable()
6543 hci_dev_lock(hdev); in set_fast_connectable()
6545 if (!!cp->val == hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) { in set_fast_connectable()
6546 err = send_settings_rsp(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in set_fast_connectable()
6550 if (!hdev_is_powered(hdev)) { in set_fast_connectable()
6551 hci_dev_change_flag(hdev, HCI_FAST_CONNECTABLE); in set_fast_connectable()
6552 err = send_settings_rsp(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in set_fast_connectable()
6553 new_settings(hdev, sk); in set_fast_connectable()
6557 cmd = mgmt_pending_new(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev, data, in set_fast_connectable()
6562 err = hci_cmd_sync_queue(hdev, write_fast_connectable_sync, cmd, in set_fast_connectable()
6566 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
6574 hci_dev_unlock(hdev); in set_fast_connectable()
6579 static void set_bredr_complete(struct hci_dev *hdev, void *data, int err) in set_bredr_complete() argument
6583 bt_dev_dbg(hdev, "err %d", err); in set_bredr_complete()
6591 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in set_bredr_complete()
6595 send_settings_rsp(cmd->sk, MGMT_OP_SET_BREDR, hdev); in set_bredr_complete()
6596 new_settings(hdev, cmd->sk); in set_bredr_complete()
6602 static int set_bredr_sync(struct hci_dev *hdev, void *data) in set_bredr_sync() argument
6606 status = hci_write_fast_connectable_sync(hdev, false); in set_bredr_sync()
6609 status = hci_update_scan_sync(hdev); in set_bredr_sync()
6615 status = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in set_bredr_sync()
6620 static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_bredr() argument
6626 bt_dev_dbg(hdev, "sock %p", sk); in set_bredr()
6628 if (!lmp_bredr_capable(hdev) || !lmp_le_capable(hdev)) in set_bredr()
6629 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6632 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_bredr()
6633 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6637 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6640 hci_dev_lock(hdev); in set_bredr()
6642 if (cp->val == hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_bredr()
6643 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
6647 if (!hdev_is_powered(hdev)) { in set_bredr()
6649 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_bredr()
6650 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_bredr()
6651 hci_dev_clear_flag(hdev, HCI_LINK_SECURITY); in set_bredr()
6652 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in set_bredr()
6655 hci_dev_change_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
6657 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
6661 err = new_settings(hdev, sk); in set_bredr()
6667 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6685 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_bredr()
6686 (bacmp(&hdev->static_addr, BDADDR_ANY) || in set_bredr()
6687 hci_dev_test_flag(hdev, HCI_SC_ENABLED))) { in set_bredr()
6688 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6694 cmd = mgmt_pending_new(sk, MGMT_OP_SET_BREDR, hdev, data, len); in set_bredr()
6698 err = hci_cmd_sync_queue(hdev, set_bredr_sync, cmd, in set_bredr()
6702 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6713 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
6716 hci_dev_unlock(hdev); in set_bredr()
6720 static void set_secure_conn_complete(struct hci_dev *hdev, void *data, int err) in set_secure_conn_complete() argument
6725 bt_dev_dbg(hdev, "err %d", err); in set_secure_conn_complete()
6738 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6739 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6742 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6743 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6746 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6747 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6751 send_settings_rsp(cmd->sk, cmd->opcode, hdev); in set_secure_conn_complete()
6752 new_settings(hdev, cmd->sk); in set_secure_conn_complete()
6758 static int set_secure_conn_sync(struct hci_dev *hdev, void *data) in set_secure_conn_sync() argument
6765 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_sync()
6767 return hci_write_sc_support_sync(hdev, val); in set_secure_conn_sync()
6770 static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, in set_secure_conn() argument
6778 bt_dev_dbg(hdev, "sock %p", sk); in set_secure_conn()
6780 if (!lmp_sc_capable(hdev) && in set_secure_conn()
6781 !hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_secure_conn()
6782 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6785 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_secure_conn()
6786 lmp_sc_capable(hdev) && in set_secure_conn()
6787 !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_secure_conn()
6788 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6792 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6795 hci_dev_lock(hdev); in set_secure_conn()
6797 if (!hdev_is_powered(hdev) || !lmp_sc_capable(hdev) || in set_secure_conn()
6798 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_secure_conn()
6802 changed = !hci_dev_test_and_set_flag(hdev, in set_secure_conn()
6805 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6807 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6809 changed = hci_dev_test_and_clear_flag(hdev, in set_secure_conn()
6811 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6814 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
6819 err = new_settings(hdev, sk); in set_secure_conn()
6826 if (val == hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in set_secure_conn()
6827 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in set_secure_conn()
6828 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
6832 cmd = mgmt_pending_new(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len); in set_secure_conn()
6836 err = hci_cmd_sync_queue(hdev, set_secure_conn_sync, cmd, in set_secure_conn()
6840 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6847 hci_dev_unlock(hdev); in set_secure_conn()
6851 static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, in set_debug_keys() argument
6858 bt_dev_dbg(hdev, "sock %p", sk); in set_debug_keys()
6861 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEBUG_KEYS, in set_debug_keys()
6864 hci_dev_lock(hdev); in set_debug_keys()
6867 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in set_debug_keys()
6869 changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
6873 use_changed = !hci_dev_test_and_set_flag(hdev, in set_debug_keys()
6876 use_changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
6879 if (hdev_is_powered(hdev) && use_changed && in set_debug_keys()
6880 hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_debug_keys()
6882 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in set_debug_keys()
6886 err = send_settings_rsp(sk, MGMT_OP_SET_DEBUG_KEYS, hdev); in set_debug_keys()
6891 err = new_settings(hdev, sk); in set_debug_keys()
6894 hci_dev_unlock(hdev); in set_debug_keys()
6898 static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data, in set_privacy() argument
6905 bt_dev_dbg(hdev, "sock %p", sk); in set_privacy()
6907 if (!lmp_le_capable(hdev)) in set_privacy()
6908 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
6912 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
6915 if (hdev_is_powered(hdev)) in set_privacy()
6916 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
6919 hci_dev_lock(hdev); in set_privacy()
6924 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in set_privacy()
6927 changed = !hci_dev_test_and_set_flag(hdev, HCI_PRIVACY); in set_privacy()
6928 memcpy(hdev->irk, cp->irk, sizeof(hdev->irk)); in set_privacy()
6929 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
6930 hci_adv_instances_set_rpa_expired(hdev, true); in set_privacy()
6932 hci_dev_set_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
6934 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
6936 changed = hci_dev_test_and_clear_flag(hdev, HCI_PRIVACY); in set_privacy()
6937 memset(hdev->irk, 0, sizeof(hdev->irk)); in set_privacy()
6938 hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
6939 hci_adv_instances_set_rpa_expired(hdev, false); in set_privacy()
6940 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
6943 err = send_settings_rsp(sk, MGMT_OP_SET_PRIVACY, hdev); in set_privacy()
6948 err = new_settings(hdev, sk); in set_privacy()
6951 hci_dev_unlock(hdev); in set_privacy()
6971 static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data, in load_irks() argument
6980 bt_dev_dbg(hdev, "sock %p", sk); in load_irks()
6982 if (!lmp_le_capable(hdev)) in load_irks()
6983 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
6988 bt_dev_err(hdev, "load_irks: too big irk_count value %u", in load_irks()
6990 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
6996 bt_dev_err(hdev, "load_irks: expected %u bytes, got %u bytes", in load_irks()
6998 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7002 bt_dev_dbg(hdev, "irk_count %u", irk_count); in load_irks()
7008 return mgmt_cmd_status(sk, hdev->id, in load_irks()
7013 hci_dev_lock(hdev); in load_irks()
7015 hci_smp_irks_clear(hdev); in load_irks()
7020 if (hci_is_blocked_key(hdev, in load_irks()
7023 bt_dev_warn(hdev, "Skipping blocked IRK for %pMR", in load_irks()
7028 hci_add_irk(hdev, &irk->addr.bdaddr, in load_irks()
7033 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in load_irks()
7035 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_IRKS, 0, NULL, 0); in load_irks()
7037 hci_dev_unlock(hdev); in load_irks()
7061 static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev, in load_long_term_keys() argument
7070 bt_dev_dbg(hdev, "sock %p", sk); in load_long_term_keys()
7072 if (!lmp_le_capable(hdev)) in load_long_term_keys()
7073 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7078 bt_dev_err(hdev, "load_ltks: too big key_count value %u", in load_long_term_keys()
7080 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7086 bt_dev_err(hdev, "load_keys: expected %u bytes, got %u bytes", in load_long_term_keys()
7088 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7092 bt_dev_dbg(hdev, "key_count %u", key_count); in load_long_term_keys()
7094 hci_dev_lock(hdev); in load_long_term_keys()
7096 hci_smp_ltks_clear(hdev); in load_long_term_keys()
7102 if (hci_is_blocked_key(hdev, in load_long_term_keys()
7105 bt_dev_warn(hdev, "Skipping blocked LTK for %pMR", in load_long_term_keys()
7111 bt_dev_warn(hdev, "Invalid LTK for %pMR", in load_long_term_keys()
7141 hci_add_ltk(hdev, &key->addr.bdaddr, in load_long_term_keys()
7146 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 0, in load_long_term_keys()
7149 hci_dev_unlock(hdev); in load_long_term_keys()
7154 static void get_conn_info_complete(struct hci_dev *hdev, void *data, int err) in get_conn_info_complete() argument
7162 bt_dev_dbg(hdev, "err %d", err); in get_conn_info_complete()
7183 static int get_conn_info_sync(struct hci_dev *hdev, void *data) in get_conn_info_sync() argument
7193 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info_sync()
7196 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info_sync()
7205 err = hci_read_rssi_sync(hdev, handle); in get_conn_info_sync()
7212 err = hci_read_tx_power_sync(hdev, handle, 0x00); in get_conn_info_sync()
7216 err = hci_read_tx_power_sync(hdev, handle, 0x01); in get_conn_info_sync()
7221 static int get_conn_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_conn_info() argument
7230 bt_dev_dbg(hdev, "sock %p", sk); in get_conn_info()
7237 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7241 hci_dev_lock(hdev); in get_conn_info()
7243 if (!hdev_is_powered(hdev)) { in get_conn_info()
7244 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7251 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info()
7254 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info()
7257 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7266 conn_info_age = get_random_u32_inclusive(hdev->conn_info_min_age, in get_conn_info()
7267 hdev->conn_info_max_age - 1); in get_conn_info()
7277 cmd = mgmt_pending_new(sk, MGMT_OP_GET_CONN_INFO, hdev, data, in get_conn_info()
7282 err = hci_cmd_sync_queue(hdev, get_conn_info_sync, in get_conn_info()
7287 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7303 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7308 hci_dev_unlock(hdev); in get_conn_info()
7312 static void get_clock_info_complete(struct hci_dev *hdev, void *data, int err) in get_clock_info_complete() argument
7320 bt_dev_dbg(hdev, "err %d", err); in get_clock_info_complete()
7329 rp.local_clock = cpu_to_le32(hdev->clock); in get_clock_info_complete()
7343 static int get_clock_info_sync(struct hci_dev *hdev, void *data) in get_clock_info_sync() argument
7351 hci_read_clock_sync(hdev, &hci_cp); in get_clock_info_sync()
7354 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in get_clock_info_sync()
7362 return hci_read_clock_sync(hdev, &hci_cp); in get_clock_info_sync()
7365 static int get_clock_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_clock_info() argument
7374 bt_dev_dbg(hdev, "sock %p", sk); in get_clock_info()
7381 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7385 hci_dev_lock(hdev); in get_clock_info()
7387 if (!hdev_is_powered(hdev)) { in get_clock_info()
7388 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7395 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_clock_info()
7398 err = mgmt_cmd_complete(sk, hdev->id, in get_clock_info()
7408 cmd = mgmt_pending_new(sk, MGMT_OP_GET_CLOCK_INFO, hdev, data, len); in get_clock_info()
7412 err = hci_cmd_sync_queue(hdev, get_clock_info_sync, cmd, in get_clock_info()
7416 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7425 hci_dev_unlock(hdev); in get_clock_info()
7429 static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type) in is_connected() argument
7433 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, addr); in is_connected()
7447 static int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, in hci_conn_params_set() argument
7452 params = hci_conn_params_add(hdev, addr, addr_type); in hci_conn_params_set()
7468 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7472 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7474 hci_pend_le_list_add(params, &hdev->pend_le_reports); in hci_conn_params_set()
7478 if (!is_connected(hdev, addr, addr_type)) in hci_conn_params_set()
7479 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7485 bt_dev_dbg(hdev, "addr %pMR (type %u) auto_connect %u", in hci_conn_params_set()
7491 static void device_added(struct sock *sk, struct hci_dev *hdev, in device_added() argument
7500 mgmt_event(MGMT_EV_DEVICE_ADDED, hdev, &ev, sizeof(ev), sk); in device_added()
7503 static void add_device_complete(struct hci_dev *hdev, void *data, int err) in add_device_complete() argument
7511 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in add_device_complete()
7514 device_added(cmd->sk, hdev, &cp->addr.bdaddr, cp->addr.type, in add_device_complete()
7516 device_flags_changed(NULL, hdev, &cp->addr.bdaddr, in add_device_complete()
7517 cp->addr.type, hdev->conn_flags, in add_device_complete()
7521 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device_complete()
7526 static int add_device_sync(struct hci_dev *hdev, void *data) in add_device_sync() argument
7528 return hci_update_passive_scan_sync(hdev); in add_device_sync()
7531 static int add_device(struct sock *sk, struct hci_dev *hdev, in add_device() argument
7542 bt_dev_dbg(hdev, "sock %p", sk); in add_device()
7546 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7551 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7555 hci_dev_lock(hdev); in add_device()
7560 err = mgmt_cmd_complete(sk, hdev->id, in add_device()
7567 err = hci_bdaddr_list_add_with_flags(&hdev->accept_list, in add_device()
7573 hci_update_scan(hdev); in add_device()
7593 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7602 if (hci_conn_params_set(hdev, &cp->addr.bdaddr, addr_type, in add_device()
7604 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7609 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in add_device()
7615 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_DEVICE, hdev, data, len); in add_device()
7621 err = hci_cmd_sync_queue(hdev, add_device_sync, cmd, in add_device()
7624 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7633 device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action); in add_device()
7634 supported_flags = hdev->conn_flags; in add_device()
7635 device_flags_changed(NULL, hdev, &cp->addr.bdaddr, cp->addr.type, in add_device()
7638 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7643 hci_dev_unlock(hdev); in add_device()
7647 static void device_removed(struct sock *sk, struct hci_dev *hdev, in device_removed() argument
7655 mgmt_event(MGMT_EV_DEVICE_REMOVED, hdev, &ev, sizeof(ev), sk); in device_removed()
7658 static int remove_device_sync(struct hci_dev *hdev, void *data) in remove_device_sync() argument
7660 return hci_update_passive_scan_sync(hdev); in remove_device_sync()
7663 static int remove_device(struct sock *sk, struct hci_dev *hdev, in remove_device() argument
7669 bt_dev_dbg(hdev, "sock %p", sk); in remove_device()
7671 hci_dev_lock(hdev); in remove_device()
7678 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7686 err = hci_bdaddr_list_del(&hdev->accept_list, in remove_device()
7690 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7698 hci_update_scan(hdev); in remove_device()
7700 device_removed(sk, hdev, &cp->addr.bdaddr, in remove_device()
7713 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7720 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in remove_device()
7723 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7732 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7741 device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type); in remove_device()
7747 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7754 list_for_each_entry_safe(b, btmp, &hdev->accept_list, list) { in remove_device()
7755 device_removed(sk, hdev, &b->bdaddr, b->bdaddr_type); in remove_device()
7760 hci_update_scan(hdev); in remove_device()
7762 list_for_each_entry_safe(p, tmp, &hdev->le_conn_params, list) { in remove_device()
7765 device_removed(sk, hdev, &p->addr, p->addr_type); in remove_device()
7773 bt_dev_dbg(hdev, "All LE connection parameters were removed"); in remove_device()
7776 hci_cmd_sync_queue(hdev, remove_device_sync, NULL, NULL); in remove_device()
7779 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, in remove_device()
7783 hci_dev_unlock(hdev); in remove_device()
7787 static int conn_update_sync(struct hci_dev *hdev, void *data) in conn_update_sync() argument
7792 conn = hci_conn_hash_lookup_le(hdev, &params->addr, params->addr_type); in conn_update_sync()
7796 return hci_le_conn_update_sync(hdev, conn, params); in conn_update_sync()
7799 static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data, in load_conn_param() argument
7808 if (!lmp_le_capable(hdev)) in load_conn_param()
7809 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7814 bt_dev_err(hdev, "load_conn_param: too big param_count value %u", in load_conn_param()
7816 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7822 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes", in load_conn_param()
7824 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7828 bt_dev_dbg(hdev, "param_count %u", param_count); in load_conn_param()
7830 hci_dev_lock(hdev); in load_conn_param()
7833 hci_conn_params_clear_disabled(hdev); in load_conn_param()
7842 bt_dev_dbg(hdev, "Adding %pMR (type %u)", &param->addr.bdaddr, in load_conn_param()
7850 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
7859 bt_dev_dbg(hdev, "min 0x%04x max 0x%04x latency 0x%04x timeout 0x%04x", in load_conn_param()
7863 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
7871 hci_param = hci_conn_params_lookup(hdev, in load_conn_param()
7877 hci_conn_params_clear_disabled(hdev); in load_conn_param()
7880 hci_param = hci_conn_params_add(hdev, &param->addr.bdaddr, in load_conn_param()
7883 bt_dev_err(hdev, "failed to add connection parameters"); in load_conn_param()
7900 conn = hci_conn_hash_lookup_le(hdev, &hci_param->addr, in load_conn_param()
7907 hci_cmd_sync_queue(hdev, conn_update_sync, in load_conn_param()
7912 hci_dev_unlock(hdev); in load_conn_param()
7914 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 0, in load_conn_param()
7918 static int set_external_config(struct sock *sk, struct hci_dev *hdev, in set_external_config() argument
7925 bt_dev_dbg(hdev, "sock %p", sk); in set_external_config()
7927 if (hdev_is_powered(hdev)) in set_external_config()
7928 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7932 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7935 if (!test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in set_external_config()
7936 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7939 hci_dev_lock(hdev); in set_external_config()
7942 changed = !hci_dev_test_and_set_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
7944 changed = hci_dev_test_and_clear_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
7946 err = send_options_rsp(sk, MGMT_OP_SET_EXTERNAL_CONFIG, hdev); in set_external_config()
7953 err = new_options(hdev, sk); in set_external_config()
7955 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) == is_configured(hdev)) { in set_external_config()
7956 mgmt_index_removed(hdev); in set_external_config()
7958 if (hci_dev_test_and_change_flag(hdev, HCI_UNCONFIGURED)) { in set_external_config()
7959 hci_dev_set_flag(hdev, HCI_CONFIG); in set_external_config()
7960 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_external_config()
7962 queue_work(hdev->req_workqueue, &hdev->power_on); in set_external_config()
7964 set_bit(HCI_RAW, &hdev->flags); in set_external_config()
7965 mgmt_index_added(hdev); in set_external_config()
7970 hci_dev_unlock(hdev); in set_external_config()
7974 static int set_public_address(struct sock *sk, struct hci_dev *hdev, in set_public_address() argument
7981 bt_dev_dbg(hdev, "sock %p", sk); in set_public_address()
7983 if (hdev_is_powered(hdev)) in set_public_address()
7984 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
7988 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
7991 if (!hdev->set_bdaddr) in set_public_address()
7992 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
7995 hci_dev_lock(hdev); in set_public_address()
7997 changed = !!bacmp(&hdev->public_addr, &cp->bdaddr); in set_public_address()
7998 bacpy(&hdev->public_addr, &cp->bdaddr); in set_public_address()
8000 err = send_options_rsp(sk, MGMT_OP_SET_PUBLIC_ADDRESS, hdev); in set_public_address()
8007 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in set_public_address()
8008 err = new_options(hdev, sk); in set_public_address()
8010 if (is_configured(hdev)) { in set_public_address()
8011 mgmt_index_removed(hdev); in set_public_address()
8013 hci_dev_clear_flag(hdev, HCI_UNCONFIGURED); in set_public_address()
8015 hci_dev_set_flag(hdev, HCI_CONFIG); in set_public_address()
8016 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_public_address()
8018 queue_work(hdev->req_workqueue, &hdev->power_on); in set_public_address()
8022 hci_dev_unlock(hdev); in set_public_address()
8026 static void read_local_oob_ext_data_complete(struct hci_dev *hdev, void *data, in read_local_oob_ext_data_complete() argument
8038 cmd != pending_find(MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev)) in read_local_oob_ext_data_complete()
8050 bt_dev_dbg(hdev, "status %u", status); in read_local_oob_ext_data_complete()
8062 } else if (!bredr_sc_enabled(hdev)) { in read_local_oob_ext_data_complete()
8088 if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in read_local_oob_ext_data_complete()
8111 hdev->dev_class, 3); in read_local_oob_ext_data_complete()
8131 err = mgmt_cmd_complete(cmd->sk, hdev->id, in read_local_oob_ext_data_complete()
8139 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data_complete()
8150 static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk, in read_local_ssp_oob_req() argument
8156 cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev, in read_local_ssp_oob_req()
8161 err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd, in read_local_ssp_oob_req()
8172 static int read_local_oob_ext_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_ext_data() argument
8182 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_ext_data()
8184 if (hdev_is_powered(hdev)) { in read_local_oob_ext_data()
8187 status = mgmt_bredr_support(hdev); in read_local_oob_ext_data()
8194 status = mgmt_le_support(hdev); in read_local_oob_ext_data()
8215 if (!status && !lmp_ssp_capable(hdev)) { in read_local_oob_ext_data()
8223 hci_dev_lock(hdev); in read_local_oob_ext_data()
8228 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in read_local_oob_ext_data()
8229 err = read_local_ssp_oob_req(hdev, sk, cp); in read_local_oob_ext_data()
8230 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8239 hdev->dev_class, 3); in read_local_oob_ext_data()
8243 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in read_local_oob_ext_data()
8244 smp_generate_oob(hdev, hash, rand) < 0) { in read_local_oob_ext_data()
8245 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8260 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { in read_local_oob_ext_data()
8261 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8266 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in read_local_oob_ext_data()
8267 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in read_local_oob_ext_data()
8268 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in read_local_oob_ext_data()
8269 bacmp(&hdev->static_addr, BDADDR_ANY))) { in read_local_oob_ext_data()
8270 memcpy(addr, &hdev->static_addr, 6); in read_local_oob_ext_data()
8273 memcpy(addr, &hdev->bdaddr, 6); in read_local_oob_ext_data()
8280 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in read_local_oob_ext_data()
8288 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) { in read_local_oob_ext_data()
8298 flags = mgmt_get_adv_discov_flags(hdev); in read_local_oob_ext_data()
8300 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in read_local_oob_ext_data()
8308 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8318 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, in read_local_oob_ext_data()
8323 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data()
8333 static u32 get_supported_adv_flags(struct hci_dev *hdev) in get_supported_adv_flags() argument
8352 if (hdev->adv_tx_power != HCI_TX_POWER_INVALID || ext_adv_capable(hdev)) in get_supported_adv_flags()
8355 if (ext_adv_capable(hdev)) { in get_supported_adv_flags()
8360 if (le_2m_capable(hdev)) in get_supported_adv_flags()
8363 if (le_coded_capable(hdev)) in get_supported_adv_flags()
8370 static int read_adv_features(struct sock *sk, struct hci_dev *hdev, in read_adv_features() argument
8380 bt_dev_dbg(hdev, "sock %p", sk); in read_adv_features()
8382 if (!lmp_le_capable(hdev)) in read_adv_features()
8383 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
8386 hci_dev_lock(hdev); in read_adv_features()
8388 rp_len = sizeof(*rp) + hdev->adv_instance_cnt; in read_adv_features()
8391 hci_dev_unlock(hdev); in read_adv_features()
8395 supported_flags = get_supported_adv_flags(hdev); in read_adv_features()
8398 rp->max_adv_data_len = max_adv_len(hdev); in read_adv_features()
8399 rp->max_scan_rsp_len = max_adv_len(hdev); in read_adv_features()
8400 rp->max_instances = hdev->le_num_of_adv_sets; in read_adv_features()
8401 rp->num_instances = hdev->adv_instance_cnt; in read_adv_features()
8404 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in read_adv_features()
8406 if (adv_instance->instance <= hdev->adv_instance_cnt) { in read_adv_features()
8415 hci_dev_unlock(hdev); in read_adv_features()
8417 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
8425 static u8 calculate_name_len(struct hci_dev *hdev) in calculate_name_len() argument
8429 return eir_append_local_name(hdev, buf, 0); in calculate_name_len()
8432 static u8 tlv_data_max_len(struct hci_dev *hdev, u32 adv_flags, in tlv_data_max_len() argument
8435 u8 max_len = max_adv_len(hdev); in tlv_data_max_len()
8447 max_len -= calculate_name_len(hdev); in tlv_data_max_len()
8478 static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data, in tlv_data_is_valid() argument
8484 max_len = tlv_data_max_len(hdev, adv_flags, is_adv_data); in tlv_data_is_valid()
8523 static bool requested_adv_flags_are_valid(struct hci_dev *hdev, u32 adv_flags) in requested_adv_flags_are_valid() argument
8530 supported_flags = get_supported_adv_flags(hdev); in requested_adv_flags_are_valid()
8539 static bool adv_busy(struct hci_dev *hdev) in adv_busy() argument
8541 return pending_find(MGMT_OP_SET_LE, hdev); in adv_busy()
8544 static void add_adv_complete(struct hci_dev *hdev, struct sock *sk, u8 instance, in add_adv_complete() argument
8549 bt_dev_dbg(hdev, "err %d", err); in add_adv_complete()
8551 hci_dev_lock(hdev); in add_adv_complete()
8553 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in add_adv_complete()
8566 if (hdev->cur_adv_instance == instance) in add_adv_complete()
8567 cancel_adv_timeout(hdev); in add_adv_complete()
8569 hci_remove_adv_instance(hdev, instance); in add_adv_complete()
8570 mgmt_advertising_removed(sk, hdev, instance); in add_adv_complete()
8573 hci_dev_unlock(hdev); in add_adv_complete()
8576 static void add_advertising_complete(struct hci_dev *hdev, void *data, int err) in add_advertising_complete() argument
8593 add_adv_complete(hdev, cmd->sk, cp->instance, err); in add_advertising_complete()
8598 static int add_advertising_sync(struct hci_dev *hdev, void *data) in add_advertising_sync() argument
8603 return hci_schedule_adv_instance_sync(hdev, cp->instance, true); in add_advertising_sync()
8606 static int add_advertising(struct sock *sk, struct hci_dev *hdev, in add_advertising() argument
8620 bt_dev_dbg(hdev, "sock %p", sk); in add_advertising()
8622 status = mgmt_le_support(hdev); in add_advertising()
8624 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8627 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_advertising()
8628 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8632 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8639 if (!requested_adv_flags_are_valid(hdev, flags)) in add_advertising()
8640 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8643 hci_dev_lock(hdev); in add_advertising()
8645 if (timeout && !hdev_is_powered(hdev)) { in add_advertising()
8646 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8651 if (adv_busy(hdev)) { in add_advertising()
8652 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8657 if (!tlv_data_is_valid(hdev, flags, cp->data, cp->adv_data_len, true) || in add_advertising()
8658 !tlv_data_is_valid(hdev, flags, cp->data + cp->adv_data_len, in add_advertising()
8660 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8665 prev_instance_cnt = hdev->adv_instance_cnt; in add_advertising()
8667 adv = hci_add_adv_instance(hdev, cp->instance, flags, in add_advertising()
8673 hdev->le_adv_min_interval, in add_advertising()
8674 hdev->le_adv_max_interval, 0); in add_advertising()
8676 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8684 if (hdev->adv_instance_cnt > prev_instance_cnt) in add_advertising()
8685 mgmt_advertising_added(sk, hdev, cp->instance); in add_advertising()
8687 if (hdev->cur_adv_instance == cp->instance) { in add_advertising()
8693 cancel_adv_timeout(hdev); in add_advertising()
8695 next_instance = hci_get_next_instance(hdev, cp->instance); in add_advertising()
8698 } else if (!hdev->adv_instance_timeout) { in add_advertising()
8709 if (!hdev_is_powered(hdev) || in add_advertising()
8710 hci_dev_test_flag(hdev, HCI_ADVERTISING) || in add_advertising()
8713 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8721 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_ADVERTISING, hdev, data, in add_advertising()
8730 err = hci_cmd_sync_queue(hdev, add_advertising_sync, cmd, in add_advertising()
8736 hci_dev_unlock(hdev); in add_advertising()
8741 static void add_ext_adv_params_complete(struct hci_dev *hdev, void *data, in add_ext_adv_params_complete() argument
8750 BT_DBG("%s", hdev->name); in add_ext_adv_params_complete()
8752 hci_dev_lock(hdev); in add_ext_adv_params_complete()
8754 adv = hci_find_adv_instance(hdev, cp->instance); in add_ext_adv_params_complete()
8765 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in add_ext_adv_params_complete()
8766 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in add_ext_adv_params_complete()
8774 mgmt_advertising_removed(cmd->sk, hdev, cp->instance); in add_ext_adv_params_complete()
8776 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_params_complete()
8788 hci_dev_unlock(hdev); in add_ext_adv_params_complete()
8791 static int add_ext_adv_params_sync(struct hci_dev *hdev, void *data) in add_ext_adv_params_sync() argument
8796 return hci_setup_ext_adv_instance_sync(hdev, cp->instance); in add_ext_adv_params_sync()
8799 static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev, in add_ext_adv_params() argument
8812 BT_DBG("%s", hdev->name); in add_ext_adv_params()
8814 status = mgmt_le_support(hdev); in add_ext_adv_params()
8816 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8819 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_ext_adv_params()
8820 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8830 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8835 if (!requested_adv_flags_are_valid(hdev, flags)) in add_ext_adv_params()
8836 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8839 hci_dev_lock(hdev); in add_ext_adv_params()
8842 if (!hdev_is_powered(hdev)) { in add_ext_adv_params()
8843 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8848 if (adv_busy(hdev)) { in add_ext_adv_params()
8849 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8860 hdev->def_multi_adv_rotation_duration; in add_ext_adv_params()
8864 hdev->le_adv_min_interval; in add_ext_adv_params()
8868 hdev->le_adv_max_interval; in add_ext_adv_params()
8875 adv = hci_add_adv_instance(hdev, cp->instance, flags, 0, NULL, 0, NULL, in add_ext_adv_params()
8880 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8886 if (ext_adv_capable(hdev)) { in add_ext_adv_params()
8887 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_EXT_ADV_PARAMS, hdev, in add_ext_adv_params()
8891 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_params()
8895 err = hci_cmd_sync_queue(hdev, add_ext_adv_params_sync, cmd, in add_ext_adv_params()
8902 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in add_ext_adv_params()
8903 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in add_ext_adv_params()
8904 err = mgmt_cmd_complete(sk, hdev->id, in add_ext_adv_params()
8910 hci_dev_unlock(hdev); in add_ext_adv_params()
8915 static void add_ext_adv_data_complete(struct hci_dev *hdev, void *data, int err) in add_ext_adv_data_complete() argument
8921 add_adv_complete(hdev, cmd->sk, cp->instance, err); in add_ext_adv_data_complete()
8937 static int add_ext_adv_data_sync(struct hci_dev *hdev, void *data) in add_ext_adv_data_sync() argument
8943 if (ext_adv_capable(hdev)) { in add_ext_adv_data_sync()
8944 err = hci_update_adv_data_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8948 err = hci_update_scan_rsp_data_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8952 return hci_enable_ext_advertising_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8955 return hci_schedule_adv_instance_sync(hdev, cp->instance, true); in add_ext_adv_data_sync()
8958 static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data, in add_ext_adv_data() argument
8969 BT_DBG("%s", hdev->name); in add_ext_adv_data()
8971 hci_dev_lock(hdev); in add_ext_adv_data()
8973 adv_instance = hci_find_adv_instance(hdev, cp->instance); in add_ext_adv_data()
8976 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
8982 if (!hdev_is_powered(hdev)) { in add_ext_adv_data()
8983 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
8988 if (adv_busy(hdev)) { in add_ext_adv_data()
8989 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
8995 if (!tlv_data_is_valid(hdev, adv_instance->flags, cp->data, in add_ext_adv_data()
8997 !tlv_data_is_valid(hdev, adv_instance->flags, cp->data + in add_ext_adv_data()
8999 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9005 hci_set_adv_instance_data(hdev, cp->instance, cp->adv_data_len, in add_ext_adv_data()
9010 if (hdev->cur_adv_instance == cp->instance) { in add_ext_adv_data()
9017 cancel_adv_timeout(hdev); in add_ext_adv_data()
9019 next_instance = hci_get_next_instance(hdev, cp->instance); in add_ext_adv_data()
9022 } else if (!hdev->adv_instance_timeout) { in add_ext_adv_data()
9033 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || !schedule_instance) { in add_ext_adv_data()
9035 mgmt_advertising_added(sk, hdev, cp->instance); in add_ext_adv_data()
9039 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9044 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_EXT_ADV_DATA, hdev, data, in add_ext_adv_data()
9051 err = hci_cmd_sync_queue(hdev, add_ext_adv_data_sync, cmd, in add_ext_adv_data()
9064 mgmt_advertising_added(sk, hdev, cp->instance); in add_ext_adv_data()
9069 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_data()
9072 hci_dev_unlock(hdev); in add_ext_adv_data()
9077 static void remove_advertising_complete(struct hci_dev *hdev, void *data, in remove_advertising_complete() argument
9084 bt_dev_dbg(hdev, "err %d", err); in remove_advertising_complete()
9099 static int remove_advertising_sync(struct hci_dev *hdev, void *data) in remove_advertising_sync() argument
9105 err = hci_remove_advertising_sync(hdev, cmd->sk, cp->instance, true); in remove_advertising_sync()
9109 if (list_empty(&hdev->adv_instances)) in remove_advertising_sync()
9110 err = hci_disable_advertising_sync(hdev); in remove_advertising_sync()
9115 static int remove_advertising(struct sock *sk, struct hci_dev *hdev, in remove_advertising() argument
9122 bt_dev_dbg(hdev, "sock %p", sk); in remove_advertising()
9124 hci_dev_lock(hdev); in remove_advertising()
9126 if (cp->instance && !hci_find_adv_instance(hdev, cp->instance)) { in remove_advertising()
9127 err = mgmt_cmd_status(sk, hdev->id, in remove_advertising()
9133 if (pending_find(MGMT_OP_SET_LE, hdev)) { in remove_advertising()
9134 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
9139 if (list_empty(&hdev->adv_instances)) { in remove_advertising()
9140 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
9145 cmd = mgmt_pending_new(sk, MGMT_OP_REMOVE_ADVERTISING, hdev, data, in remove_advertising()
9152 err = hci_cmd_sync_queue(hdev, remove_advertising_sync, cmd, in remove_advertising()
9158 hci_dev_unlock(hdev); in remove_advertising()
9163 static int get_adv_size_info(struct sock *sk, struct hci_dev *hdev, in get_adv_size_info() argument
9170 bt_dev_dbg(hdev, "sock %p", sk); in get_adv_size_info()
9172 if (!lmp_le_capable(hdev)) in get_adv_size_info()
9173 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9176 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in get_adv_size_info()
9177 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9185 supported_flags = get_supported_adv_flags(hdev); in get_adv_size_info()
9187 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9192 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in get_adv_size_info()
9193 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in get_adv_size_info()
9195 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9334 void mgmt_index_added(struct hci_dev *hdev) in mgmt_index_added() argument
9338 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_added()
9341 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_added()
9342 mgmt_index_event(MGMT_EV_UNCONF_INDEX_ADDED, hdev, NULL, 0, in mgmt_index_added()
9346 mgmt_index_event(MGMT_EV_INDEX_ADDED, hdev, NULL, 0, in mgmt_index_added()
9351 ev.bus = hdev->bus; in mgmt_index_added()
9353 mgmt_index_event(MGMT_EV_EXT_INDEX_ADDED, hdev, &ev, sizeof(ev), in mgmt_index_added()
9357 void mgmt_index_removed(struct hci_dev *hdev) in mgmt_index_removed() argument
9360 struct cmd_lookup match = { NULL, hdev, MGMT_STATUS_INVALID_INDEX }; in mgmt_index_removed()
9362 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_removed()
9365 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &match); in mgmt_index_removed()
9367 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_removed()
9368 mgmt_index_event(MGMT_EV_UNCONF_INDEX_REMOVED, hdev, NULL, 0, in mgmt_index_removed()
9372 mgmt_index_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, in mgmt_index_removed()
9377 ev.bus = hdev->bus; in mgmt_index_removed()
9379 mgmt_index_event(MGMT_EV_EXT_INDEX_REMOVED, hdev, &ev, sizeof(ev), in mgmt_index_removed()
9383 if (!hci_dev_test_flag(hdev, HCI_MGMT)) in mgmt_index_removed()
9385 cancel_delayed_work_sync(&hdev->discov_off); in mgmt_index_removed()
9386 cancel_delayed_work_sync(&hdev->service_cache); in mgmt_index_removed()
9387 cancel_delayed_work_sync(&hdev->rpa_expired); in mgmt_index_removed()
9390 void mgmt_power_on(struct hci_dev *hdev, int err) in mgmt_power_on() argument
9392 struct cmd_lookup match = { NULL, hdev }; in mgmt_power_on()
9394 bt_dev_dbg(hdev, "err %d", err); in mgmt_power_on()
9396 hci_dev_lock(hdev); in mgmt_power_on()
9399 restart_le_actions(hdev); in mgmt_power_on()
9400 hci_update_passive_scan(hdev); in mgmt_power_on()
9403 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in mgmt_power_on()
9405 new_settings(hdev, match.sk); in mgmt_power_on()
9410 hci_dev_unlock(hdev); in mgmt_power_on()
9413 void __mgmt_power_off(struct hci_dev *hdev) in __mgmt_power_off() argument
9415 struct cmd_lookup match = { NULL, hdev }; in __mgmt_power_off()
9418 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in __mgmt_power_off()
9427 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) in __mgmt_power_off()
9432 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &match); in __mgmt_power_off()
9434 if (memcmp(hdev->dev_class, zero_cod, sizeof(zero_cod)) != 0) { in __mgmt_power_off()
9435 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, in __mgmt_power_off()
9438 ext_info_changed(hdev, NULL); in __mgmt_power_off()
9441 new_settings(hdev, match.sk); in __mgmt_power_off()
9447 void mgmt_set_powered_failed(struct hci_dev *hdev, int err) in mgmt_set_powered_failed() argument
9452 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_set_powered_failed()
9461 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, status); in mgmt_set_powered_failed()
9466 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, in mgmt_new_link_key() argument
9480 mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_link_key()
9502 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent) in mgmt_new_ltk() argument
9542 mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_ltk()
9545 void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent) in mgmt_new_irk() argument
9558 mgmt_event(MGMT_EV_NEW_IRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_irk()
9561 void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, in mgmt_new_csrk() argument
9588 mgmt_event(MGMT_EV_NEW_CSRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_csrk()
9591 void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_new_conn_param() argument
9609 mgmt_event(MGMT_EV_NEW_CONN_PARAM, hdev, &ev, sizeof(ev), NULL); in mgmt_new_conn_param()
9612 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, in mgmt_device_connected() argument
9625 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, in mgmt_device_connected()
9628 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, in mgmt_device_connected()
9667 struct hci_dev *hdev = data; in unpair_device_rsp() local
9670 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_rsp()
9676 bool mgmt_powering_down(struct hci_dev *hdev) in mgmt_powering_down() argument
9681 if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) in mgmt_powering_down()
9684 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_powering_down()
9695 void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_device_disconnected() argument
9713 if (hdev->suspended) in mgmt_device_disconnected()
9716 mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev), sk); in mgmt_device_disconnected()
9722 void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_disconnect_failed() argument
9729 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_disconnect_failed()
9730 hdev); in mgmt_disconnect_failed()
9732 cmd = pending_find(MGMT_OP_DISCONNECT, hdev); in mgmt_disconnect_failed()
9748 void mgmt_connect_failed(struct hci_dev *hdev, struct hci_conn *conn, u8 status) in mgmt_connect_failed() argument
9753 mgmt_device_disconnected(hdev, &conn->dst, conn->type, in mgmt_connect_failed()
9762 mgmt_event(MGMT_EV_CONNECT_FAILED, hdev, &ev, sizeof(ev), NULL); in mgmt_connect_failed()
9765 void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure) in mgmt_pin_code_request() argument
9773 mgmt_event(MGMT_EV_PIN_CODE_REQUEST, hdev, &ev, sizeof(ev), NULL); in mgmt_pin_code_request()
9776 void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_reply_complete() argument
9781 cmd = pending_find(MGMT_OP_PIN_CODE_REPLY, hdev); in mgmt_pin_code_reply_complete()
9789 void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_neg_reply_complete() argument
9794 cmd = pending_find(MGMT_OP_PIN_CODE_NEG_REPLY, hdev); in mgmt_pin_code_neg_reply_complete()
9802 int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_request() argument
9808 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_confirm_request()
9815 return mgmt_event(MGMT_EV_USER_CONFIRM_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_confirm_request()
9819 int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_request() argument
9824 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_request()
9829 return mgmt_event(MGMT_EV_USER_PASSKEY_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_passkey_request()
9833 static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in user_pairing_resp_complete() argument
9839 cmd = pending_find(opcode, hdev); in user_pairing_resp_complete()
9849 int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_reply_complete() argument
9852 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_reply_complete()
9856 int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_neg_reply_complete() argument
9859 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_neg_reply_complete()
9864 int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_reply_complete() argument
9867 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_reply_complete()
9871 int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_neg_reply_complete() argument
9874 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_neg_reply_complete()
9879 int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_notify() argument
9885 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_notify()
9892 return mgmt_event(MGMT_EV_PASSKEY_NOTIFY, hdev, &ev, sizeof(ev), NULL); in mgmt_user_passkey_notify()
9907 mgmt_event(MGMT_EV_AUTH_FAILED, conn->hdev, &ev, sizeof(ev), in mgmt_auth_failed()
9916 void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status) in mgmt_auth_enable_complete() argument
9918 struct cmd_lookup match = { NULL, hdev }; in mgmt_auth_enable_complete()
9923 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, in mgmt_auth_enable_complete()
9928 if (test_bit(HCI_AUTH, &hdev->flags)) in mgmt_auth_enable_complete()
9929 changed = !hci_dev_test_and_set_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
9931 changed = hci_dev_test_and_clear_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
9933 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, settings_rsp, in mgmt_auth_enable_complete()
9937 new_settings(hdev, match.sk); in mgmt_auth_enable_complete()
9953 void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, in mgmt_set_class_of_dev_complete() argument
9956 struct cmd_lookup match = { NULL, hdev, mgmt_status(status) }; in mgmt_set_class_of_dev_complete()
9958 mgmt_pending_foreach(MGMT_OP_SET_DEV_CLASS, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
9959 mgmt_pending_foreach(MGMT_OP_ADD_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
9960 mgmt_pending_foreach(MGMT_OP_REMOVE_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
9963 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, dev_class, in mgmt_set_class_of_dev_complete()
9965 ext_info_changed(hdev, NULL); in mgmt_set_class_of_dev_complete()
9972 void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status) in mgmt_set_local_name_complete() argument
9982 memcpy(ev.short_name, hdev->short_name, HCI_MAX_SHORT_NAME_LENGTH); in mgmt_set_local_name_complete()
9984 cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev); in mgmt_set_local_name_complete()
9986 memcpy(hdev->dev_name, name, sizeof(hdev->dev_name)); in mgmt_set_local_name_complete()
9991 if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) in mgmt_set_local_name_complete()
9994 if (pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_local_name_complete()
9998 mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev, sizeof(ev), in mgmt_set_local_name_complete()
10000 ext_info_changed(hdev, cmd ? cmd->sk : NULL); in mgmt_set_local_name_complete()
10070 static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir, in is_filter_match() argument
10082 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
10084 (rssi < hdev->discovery.rssi && in is_filter_match()
10085 !test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)))) in is_filter_match()
10088 if (hdev->discovery.uuid_count != 0) { in is_filter_match()
10092 if (!eir_has_uuids(eir, eir_len, hdev->discovery.uuid_count, in is_filter_match()
10093 hdev->discovery.uuids) && in is_filter_match()
10095 hdev->discovery.uuid_count, in is_filter_match()
10096 hdev->discovery.uuids)) in is_filter_match()
10103 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)) { in is_filter_match()
10105 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
10106 rssi < hdev->discovery.rssi) in is_filter_match()
10113 void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle, in mgmt_adv_monitor_device_lost() argument
10122 mgmt_event(MGMT_EV_ADV_MONITOR_DEVICE_LOST, hdev, &ev, sizeof(ev), in mgmt_adv_monitor_device_lost()
10126 static void mgmt_send_adv_monitor_device_found(struct hci_dev *hdev, in mgmt_send_adv_monitor_device_found() argument
10140 advmon_skb = mgmt_alloc_skb(hdev, MGMT_EV_ADV_MONITOR_DEVICE_FOUND, in mgmt_send_adv_monitor_device_found()
10156 static void mgmt_adv_monitor_device_found(struct hci_dev *hdev, in mgmt_adv_monitor_device_found() argument
10180 if (report_device && !hdev->advmon_pend_notify) { in mgmt_adv_monitor_device_found()
10185 hdev->advmon_pend_notify = false; in mgmt_adv_monitor_device_found()
10187 list_for_each_entry_safe(dev, tmp, &hdev->monitored_devices, list) { in mgmt_adv_monitor_device_found()
10192 mgmt_send_adv_monitor_device_found(hdev, skb, in mgmt_adv_monitor_device_found()
10201 hdev->advmon_pend_notify = true; in mgmt_adv_monitor_device_found()
10205 ((matched && !notified) || !msft_monitor_supported(hdev))) { in mgmt_adv_monitor_device_found()
10211 mgmt_send_adv_monitor_device_found(hdev, skb, skip_sk, 0); in mgmt_adv_monitor_device_found()
10220 static void mesh_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, in mesh_device_found() argument
10229 if (!hdev->mesh_ad_types[0]) in mesh_device_found()
10235 for (j = 0; j < sizeof(hdev->mesh_ad_types); j++) { in mesh_device_found()
10236 if (!hdev->mesh_ad_types[j]) in mesh_device_found()
10239 if (hdev->mesh_ad_types[j] == eir[i + 1]) in mesh_device_found()
10247 for (j = 0; j < sizeof(hdev->mesh_ad_types); j++) { in mesh_device_found()
10248 if (!hdev->mesh_ad_types[j]) in mesh_device_found()
10251 if (hdev->mesh_ad_types[j] == scan_rsp[i + 1]) in mesh_device_found()
10260 skb = mgmt_alloc_skb(hdev, MGMT_EV_MESH_DEVICE_FOUND, in mesh_device_found()
10286 void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_device_found() argument
10293 bool report_device = hci_discovery_active(hdev); in mgmt_device_found()
10295 if (hci_dev_test_flag(hdev, HCI_MESH) && link_type == LE_LINK) in mgmt_device_found()
10296 mesh_device_found(hdev, bdaddr, addr_type, rssi, flags, in mgmt_device_found()
10304 if (!hci_discovery_active(hdev)) { in mgmt_device_found()
10307 if (link_type == LE_LINK && !list_empty(&hdev->pend_le_reports)) in mgmt_device_found()
10309 else if (!hci_is_adv_monitoring(hdev)) in mgmt_device_found()
10313 if (hdev->discovery.result_filtering) { in mgmt_device_found()
10315 if (!is_filter_match(hdev, rssi, eir, eir_len, scan_rsp, in mgmt_device_found()
10320 if (hdev->discovery.limited) { in mgmt_device_found()
10333 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, in mgmt_device_found()
10348 if (rssi == HCI_RSSI_INVALID && !hdev->discovery.report_invalid_rssi && in mgmt_device_found()
10375 mgmt_adv_monitor_device_found(hdev, bdaddr, report_device, skb, NULL); in mgmt_device_found()
10378 void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_remote_name() argument
10386 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, in mgmt_remote_name()
10407 void mgmt_discovering(struct hci_dev *hdev, u8 discovering) in mgmt_discovering() argument
10411 bt_dev_dbg(hdev, "discovering %u", discovering); in mgmt_discovering()
10414 ev.type = hdev->discovery.type; in mgmt_discovering()
10417 mgmt_event(MGMT_EV_DISCOVERING, hdev, &ev, sizeof(ev), NULL); in mgmt_discovering()
10420 void mgmt_suspending(struct hci_dev *hdev, u8 state) in mgmt_suspending() argument
10425 mgmt_event(MGMT_EV_CONTROLLER_SUSPEND, hdev, &ev, sizeof(ev), NULL); in mgmt_suspending()
10428 void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr, in mgmt_resuming() argument
10441 mgmt_event(MGMT_EV_CONTROLLER_RESUME, hdev, &ev, sizeof(ev), NULL); in mgmt_resuming()
10464 struct hci_dev *hdev; in mgmt_cleanup() local
10468 list_for_each_entry(hdev, &hci_dev_list, list) { in mgmt_cleanup()
10470 mesh_tx = mgmt_mesh_next(hdev, sk); in mgmt_cleanup()
10473 mesh_send_complete(hdev, mesh_tx, true); in mgmt_cleanup()