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()
859 static u32 get_current_settings(struct hci_dev *hdev) in get_current_settings() argument
863 if (hdev_is_powered(hdev)) in get_current_settings()
866 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in get_current_settings()
869 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in get_current_settings()
872 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in get_current_settings()
875 if (hci_dev_test_flag(hdev, HCI_BONDABLE)) in get_current_settings()
878 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in get_current_settings()
881 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in get_current_settings()
884 if (hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) in get_current_settings()
887 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in get_current_settings()
890 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in get_current_settings()
893 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) in get_current_settings()
896 if (hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) in get_current_settings()
899 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in get_current_settings()
914 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in get_current_settings()
915 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in get_current_settings()
916 !bacmp(&hdev->bdaddr, BDADDR_ANY)) { in get_current_settings()
917 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in get_current_settings()
921 if (hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED)) in get_current_settings()
924 if (cis_central_capable(hdev)) in get_current_settings()
927 if (cis_peripheral_capable(hdev)) in get_current_settings()
930 if (bis_capable(hdev)) in get_current_settings()
933 if (sync_recv_capable(hdev)) in get_current_settings()
939 static struct mgmt_pending_cmd *pending_find(u16 opcode, struct hci_dev *hdev) in pending_find() argument
941 return mgmt_pending_find(HCI_CHANNEL_CONTROL, opcode, hdev); in pending_find()
944 u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev) in mgmt_get_adv_discov_flags() argument
951 cmd = pending_find(MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_get_adv_discov_flags()
959 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
961 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
968 bool mgmt_get_connectable(struct hci_dev *hdev) in mgmt_get_connectable() argument
975 cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_get_connectable()
982 return hci_dev_test_flag(hdev, HCI_CONNECTABLE); in mgmt_get_connectable()
985 static int service_cache_sync(struct hci_dev *hdev, void *data) in service_cache_sync() argument
987 hci_update_eir_sync(hdev); in service_cache_sync()
988 hci_update_class_sync(hdev); in service_cache_sync()
995 struct hci_dev *hdev = container_of(work, struct hci_dev, in service_cache_off() local
998 if (!hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in service_cache_off()
1001 hci_cmd_sync_queue(hdev, service_cache_sync, NULL, NULL); in service_cache_off()
1004 static int rpa_expired_sync(struct hci_dev *hdev, void *data) in rpa_expired_sync() argument
1010 if (ext_adv_capable(hdev)) in rpa_expired_sync()
1011 return hci_start_ext_adv_sync(hdev, hdev->cur_adv_instance); in rpa_expired_sync()
1013 return hci_enable_advertising_sync(hdev); in rpa_expired_sync()
1018 struct hci_dev *hdev = container_of(work, struct hci_dev, in rpa_expired() local
1021 bt_dev_dbg(hdev, ""); in rpa_expired()
1023 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in rpa_expired()
1025 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING)) in rpa_expired()
1028 hci_cmd_sync_queue(hdev, rpa_expired_sync, NULL, NULL); in rpa_expired()
1031 static int set_discoverable_sync(struct hci_dev *hdev, void *data);
1035 struct hci_dev *hdev = container_of(work, struct hci_dev, in discov_off() local
1038 bt_dev_dbg(hdev, ""); in discov_off()
1040 hci_dev_lock(hdev); in discov_off()
1047 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in discov_off()
1048 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in discov_off()
1049 hdev->discov_timeout = 0; in discov_off()
1051 hci_cmd_sync_queue(hdev, set_discoverable_sync, NULL, NULL); in discov_off()
1053 mgmt_new_settings(hdev); in discov_off()
1055 hci_dev_unlock(hdev); in discov_off()
1058 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev);
1060 static void mesh_send_complete(struct hci_dev *hdev, in mesh_send_complete() argument
1066 mgmt_event(MGMT_EV_MESH_PACKET_CMPLT, hdev, &handle, in mesh_send_complete()
1072 static int mesh_send_done_sync(struct hci_dev *hdev, void *data) in mesh_send_done_sync() argument
1076 hci_dev_clear_flag(hdev, HCI_MESH_SENDING); in mesh_send_done_sync()
1077 hci_disable_advertising_sync(hdev); in mesh_send_done_sync()
1078 mesh_tx = mgmt_mesh_next(hdev, NULL); in mesh_send_done_sync()
1081 mesh_send_complete(hdev, mesh_tx, false); in mesh_send_done_sync()
1086 static int mesh_send_sync(struct hci_dev *hdev, void *data);
1087 static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err);
1088 static void mesh_next(struct hci_dev *hdev, void *data, int err) in mesh_next() argument
1090 struct mgmt_mesh_tx *mesh_tx = mgmt_mesh_next(hdev, NULL); in mesh_next()
1095 err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx, in mesh_next()
1099 mesh_send_complete(hdev, mesh_tx, false); in mesh_next()
1101 hci_dev_set_flag(hdev, HCI_MESH_SENDING); in mesh_next()
1106 struct hci_dev *hdev = container_of(work, struct hci_dev, in mesh_send_done() local
1109 if (!hci_dev_test_flag(hdev, HCI_MESH_SENDING)) in mesh_send_done()
1112 hci_cmd_sync_queue(hdev, mesh_send_done_sync, NULL, mesh_next); in mesh_send_done()
1115 static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev) in mgmt_init_hdev() argument
1117 if (hci_dev_test_flag(hdev, HCI_MGMT)) in mgmt_init_hdev()
1122 INIT_DELAYED_WORK(&hdev->discov_off, discov_off); in mgmt_init_hdev()
1123 INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off); in mgmt_init_hdev()
1124 INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired); in mgmt_init_hdev()
1125 INIT_DELAYED_WORK(&hdev->mesh_send_done, mesh_send_done); in mgmt_init_hdev()
1132 hci_dev_clear_flag(hdev, HCI_BONDABLE); in mgmt_init_hdev()
1134 hci_dev_set_flag(hdev, HCI_MGMT); in mgmt_init_hdev()
1137 static int read_controller_info(struct sock *sk, struct hci_dev *hdev, in read_controller_info() argument
1142 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_info()
1144 hci_dev_lock(hdev); in read_controller_info()
1148 bacpy(&rp.bdaddr, &hdev->bdaddr); in read_controller_info()
1150 rp.version = hdev->hci_ver; in read_controller_info()
1151 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_controller_info()
1153 rp.supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_controller_info()
1154 rp.current_settings = cpu_to_le32(get_current_settings(hdev)); in read_controller_info()
1156 memcpy(rp.dev_class, hdev->dev_class, 3); in read_controller_info()
1158 memcpy(rp.name, hdev->dev_name, sizeof(hdev->dev_name)); in read_controller_info()
1159 memcpy(rp.short_name, hdev->short_name, sizeof(hdev->short_name)); in read_controller_info()
1161 hci_dev_unlock(hdev); in read_controller_info()
1163 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_INFO, 0, &rp, in read_controller_info()
1167 static u16 append_eir_data_to_buf(struct hci_dev *hdev, u8 *eir) in append_eir_data_to_buf() argument
1172 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in append_eir_data_to_buf()
1174 hdev->dev_class, 3); in append_eir_data_to_buf()
1176 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in append_eir_data_to_buf()
1178 hdev->appearance); in append_eir_data_to_buf()
1180 name_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name)); in append_eir_data_to_buf()
1182 hdev->dev_name, name_len); in append_eir_data_to_buf()
1184 name_len = strnlen(hdev->short_name, sizeof(hdev->short_name)); in append_eir_data_to_buf()
1186 hdev->short_name, name_len); in append_eir_data_to_buf()
1191 static int read_ext_controller_info(struct sock *sk, struct hci_dev *hdev, in read_ext_controller_info() argument
1198 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_controller_info()
1202 hci_dev_lock(hdev); in read_ext_controller_info()
1204 bacpy(&rp->bdaddr, &hdev->bdaddr); in read_ext_controller_info()
1206 rp->version = hdev->hci_ver; in read_ext_controller_info()
1207 rp->manufacturer = cpu_to_le16(hdev->manufacturer); in read_ext_controller_info()
1209 rp->supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_ext_controller_info()
1210 rp->current_settings = cpu_to_le32(get_current_settings(hdev)); in read_ext_controller_info()
1213 eir_len = append_eir_data_to_buf(hdev, rp->eir); in read_ext_controller_info()
1216 hci_dev_unlock(hdev); in read_ext_controller_info()
1227 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_EXT_INFO, 0, rp, in read_ext_controller_info()
1231 static int ext_info_changed(struct hci_dev *hdev, struct sock *skip) in ext_info_changed() argument
1239 eir_len = append_eir_data_to_buf(hdev, ev->eir); in ext_info_changed()
1242 return mgmt_limited_event(MGMT_EV_EXT_INFO_CHANGED, hdev, ev, in ext_info_changed()
1247 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_settings_rsp() argument
1249 __le32 settings = cpu_to_le32(get_current_settings(hdev)); in send_settings_rsp()
1251 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &settings, in send_settings_rsp()
1255 void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev, u8 instance) in mgmt_advertising_added() argument
1261 mgmt_event(MGMT_EV_ADVERTISING_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_added()
1264 void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev, in mgmt_advertising_removed() argument
1271 mgmt_event(MGMT_EV_ADVERTISING_REMOVED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_removed()
1274 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
1276 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
1277 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
1278 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
1283 static void restart_le_actions(struct hci_dev *hdev) in restart_le_actions() argument
1287 list_for_each_entry(p, &hdev->le_conn_params, list) { in restart_le_actions()
1296 hci_pend_le_list_add(p, &hdev->pend_le_conns); in restart_le_actions()
1299 hci_pend_le_list_add(p, &hdev->pend_le_reports); in restart_le_actions()
1307 static int new_settings(struct hci_dev *hdev, struct sock *skip) in new_settings() argument
1309 __le32 ev = cpu_to_le32(get_current_settings(hdev)); in new_settings()
1311 return mgmt_limited_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, in new_settings()
1315 static void mgmt_set_powered_complete(struct hci_dev *hdev, void *data, int err) in mgmt_set_powered_complete() argument
1322 cmd != pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_powered_complete()
1327 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_powered_complete()
1331 hci_dev_lock(hdev); in mgmt_set_powered_complete()
1332 restart_le_actions(hdev); in mgmt_set_powered_complete()
1333 hci_update_passive_scan(hdev); in mgmt_set_powered_complete()
1334 hci_dev_unlock(hdev); in mgmt_set_powered_complete()
1337 send_settings_rsp(cmd->sk, cmd->opcode, hdev); in mgmt_set_powered_complete()
1343 new_settings(hdev, cmd->sk); in mgmt_set_powered_complete()
1345 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, in mgmt_set_powered_complete()
1352 static int set_powered_sync(struct hci_dev *hdev, void *data) in set_powered_sync() argument
1358 if (cmd != pending_find(MGMT_OP_SET_POWERED, hdev)) in set_powered_sync()
1363 BT_DBG("%s", hdev->name); in set_powered_sync()
1365 return hci_set_powered_sync(hdev, cp->val); in set_powered_sync()
1368 static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, in set_powered() argument
1375 bt_dev_dbg(hdev, "sock %p", sk); in set_powered()
1378 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1381 hci_dev_lock(hdev); in set_powered()
1384 if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) { in set_powered()
1385 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1391 if (pending_find(MGMT_OP_SET_POWERED, hdev)) { in set_powered()
1392 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1397 if (!!cp->val == hdev_is_powered(hdev)) { in set_powered()
1398 err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev); in set_powered()
1402 cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, hdev, data, len); in set_powered()
1410 hci_cmd_sync_cancel_sync(hdev, -EHOSTDOWN); in set_powered()
1411 err = hci_cmd_sync_queue(hdev, set_powered_sync, cmd, in set_powered()
1415 err = hci_cmd_sync_submit(hdev, set_powered_sync, cmd, in set_powered()
1423 hci_dev_unlock(hdev); in set_powered()
1427 int mgmt_new_settings(struct hci_dev *hdev) in mgmt_new_settings() argument
1429 return new_settings(hdev, NULL); in mgmt_new_settings()
1434 struct hci_dev *hdev; member
1442 send_settings_rsp(cmd->sk, cmd->opcode, match->hdev); in settings_rsp()
1469 hci_cmd_sync_dequeue(match->hdev, NULL, cmd, NULL); in cmd_complete_rsp()
1493 static u8 mgmt_bredr_support(struct hci_dev *hdev) in mgmt_bredr_support() argument
1495 if (!lmp_bredr_capable(hdev)) in mgmt_bredr_support()
1497 else if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in mgmt_bredr_support()
1503 static u8 mgmt_le_support(struct hci_dev *hdev) in mgmt_le_support() argument
1505 if (!lmp_le_capable(hdev)) in mgmt_le_support()
1507 else if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mgmt_le_support()
1513 static void mgmt_set_discoverable_complete(struct hci_dev *hdev, void *data, in mgmt_set_discoverable_complete() argument
1518 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_discoverable_complete()
1522 cmd != pending_find(MGMT_OP_SET_DISCOVERABLE, hdev)) in mgmt_set_discoverable_complete()
1525 hci_dev_lock(hdev); in mgmt_set_discoverable_complete()
1530 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in mgmt_set_discoverable_complete()
1534 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in mgmt_set_discoverable_complete()
1535 hdev->discov_timeout > 0) { in mgmt_set_discoverable_complete()
1536 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in mgmt_set_discoverable_complete()
1537 queue_delayed_work(hdev->req_workqueue, &hdev->discov_off, to); in mgmt_set_discoverable_complete()
1540 send_settings_rsp(cmd->sk, MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_set_discoverable_complete()
1541 new_settings(hdev, cmd->sk); in mgmt_set_discoverable_complete()
1545 hci_dev_unlock(hdev); in mgmt_set_discoverable_complete()
1548 static int set_discoverable_sync(struct hci_dev *hdev, void *data) in set_discoverable_sync() argument
1550 BT_DBG("%s", hdev->name); in set_discoverable_sync()
1552 return hci_update_discoverable_sync(hdev); in set_discoverable_sync()
1555 static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, in set_discoverable() argument
1563 bt_dev_dbg(hdev, "sock %p", sk); in set_discoverable()
1565 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_discoverable()
1566 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_discoverable()
1567 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1571 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1581 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1584 hci_dev_lock(hdev); in set_discoverable()
1586 if (!hdev_is_powered(hdev) && timeout > 0) { in set_discoverable()
1587 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1592 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_discoverable()
1593 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_discoverable()
1594 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1599 if (!hci_dev_test_flag(hdev, HCI_CONNECTABLE)) { in set_discoverable()
1600 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1605 if (hdev->advertising_paused) { in set_discoverable()
1606 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1611 if (!hdev_is_powered(hdev)) { in set_discoverable()
1618 if (!!cp->val != hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) { in set_discoverable()
1619 hci_dev_change_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1623 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1628 err = new_settings(hdev, sk); in set_discoverable()
1637 if (!!cp->val == hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in set_discoverable()
1638 (cp->val == 0x02) == hci_dev_test_flag(hdev, in set_discoverable()
1640 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1641 hdev->discov_timeout = timeout; in set_discoverable()
1643 if (cp->val && hdev->discov_timeout > 0) { in set_discoverable()
1644 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in set_discoverable()
1645 queue_delayed_work(hdev->req_workqueue, in set_discoverable()
1646 &hdev->discov_off, to); in set_discoverable()
1649 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1653 cmd = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, hdev, data, len); in set_discoverable()
1663 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1664 hdev->discov_timeout = timeout; in set_discoverable()
1667 hci_dev_set_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1669 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1673 hci_dev_set_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1675 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1677 err = hci_cmd_sync_queue(hdev, set_discoverable_sync, cmd, in set_discoverable()
1684 hci_dev_unlock(hdev); in set_discoverable()
1688 static void mgmt_set_connectable_complete(struct hci_dev *hdev, void *data, in mgmt_set_connectable_complete() argument
1693 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_connectable_complete()
1697 cmd != pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) in mgmt_set_connectable_complete()
1700 hci_dev_lock(hdev); in mgmt_set_connectable_complete()
1708 send_settings_rsp(cmd->sk, MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_set_connectable_complete()
1709 new_settings(hdev, cmd->sk); in mgmt_set_connectable_complete()
1714 hci_dev_unlock(hdev); in mgmt_set_connectable_complete()
1717 static int set_connectable_update_settings(struct hci_dev *hdev, in set_connectable_update_settings() argument
1723 if (!!val != hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in set_connectable_update_settings()
1727 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1729 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1730 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable_update_settings()
1733 err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev); in set_connectable_update_settings()
1738 hci_update_scan(hdev); in set_connectable_update_settings()
1739 hci_update_passive_scan(hdev); in set_connectable_update_settings()
1740 return new_settings(hdev, sk); in set_connectable_update_settings()
1746 static int set_connectable_sync(struct hci_dev *hdev, void *data) in set_connectable_sync() argument
1748 BT_DBG("%s", hdev->name); in set_connectable_sync()
1750 return hci_update_connectable_sync(hdev); in set_connectable_sync()
1753 static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data, in set_connectable() argument
1760 bt_dev_dbg(hdev, "sock %p", sk); in set_connectable()
1762 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_connectable()
1763 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_connectable()
1764 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1768 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1771 hci_dev_lock(hdev); in set_connectable()
1773 if (!hdev_is_powered(hdev)) { in set_connectable()
1774 err = set_connectable_update_settings(hdev, sk, cp->val); in set_connectable()
1778 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_connectable()
1779 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_connectable()
1780 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1785 cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len); in set_connectable()
1792 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1794 if (hdev->discov_timeout > 0) in set_connectable()
1795 cancel_delayed_work(&hdev->discov_off); in set_connectable()
1797 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_connectable()
1798 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable()
1799 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1802 err = hci_cmd_sync_queue(hdev, set_connectable_sync, cmd, in set_connectable()
1809 hci_dev_unlock(hdev); in set_connectable()
1813 static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data, in set_bondable() argument
1820 bt_dev_dbg(hdev, "sock %p", sk); in set_bondable()
1823 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BONDABLE, in set_bondable()
1826 hci_dev_lock(hdev); in set_bondable()
1829 changed = !hci_dev_test_and_set_flag(hdev, HCI_BONDABLE); in set_bondable()
1831 changed = hci_dev_test_and_clear_flag(hdev, HCI_BONDABLE); in set_bondable()
1833 err = send_settings_rsp(sk, MGMT_OP_SET_BONDABLE, hdev); in set_bondable()
1841 hci_update_discoverable(hdev); in set_bondable()
1843 err = new_settings(hdev, sk); in set_bondable()
1847 hci_dev_unlock(hdev); in set_bondable()
1851 static int set_link_security(struct sock *sk, struct hci_dev *hdev, void *data, in set_link_security() argument
1859 bt_dev_dbg(hdev, "sock %p", sk); in set_link_security()
1861 status = mgmt_bredr_support(hdev); in set_link_security()
1863 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1867 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1870 hci_dev_lock(hdev); in set_link_security()
1872 if (!hdev_is_powered(hdev)) { in set_link_security()
1875 if (!!cp->val != hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) { in set_link_security()
1876 hci_dev_change_flag(hdev, HCI_LINK_SECURITY); in set_link_security()
1880 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1885 err = new_settings(hdev, sk); in set_link_security()
1890 if (pending_find(MGMT_OP_SET_LINK_SECURITY, hdev)) { in set_link_security()
1891 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1898 if (test_bit(HCI_AUTH, &hdev->flags) == val) { in set_link_security()
1899 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1903 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LINK_SECURITY, hdev, data, len); in set_link_security()
1909 err = hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, sizeof(val), &val); in set_link_security()
1916 hci_dev_unlock(hdev); in set_link_security()
1920 static void set_ssp_complete(struct hci_dev *hdev, void *data, int err) in set_ssp_complete() argument
1922 struct cmd_lookup match = { NULL, hdev }; in set_ssp_complete()
1929 if (err == -ECANCELED || cmd != pending_find(MGMT_OP_SET_SSP, hdev)) in set_ssp_complete()
1935 if (enable && hci_dev_test_and_clear_flag(hdev, in set_ssp_complete()
1937 new_settings(hdev, NULL); in set_ssp_complete()
1940 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, cmd_status_rsp, in set_ssp_complete()
1946 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in set_ssp_complete()
1948 changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED); in set_ssp_complete()
1951 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, settings_rsp, &match); in set_ssp_complete()
1954 new_settings(hdev, match.sk); in set_ssp_complete()
1959 hci_update_eir_sync(hdev); in set_ssp_complete()
1962 static int set_ssp_sync(struct hci_dev *hdev, void *data) in set_ssp_sync() argument
1970 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in set_ssp_sync()
1972 err = hci_write_ssp_mode_sync(hdev, cp->val); in set_ssp_sync()
1975 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_ssp_sync()
1980 static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_ssp() argument
1987 bt_dev_dbg(hdev, "sock %p", sk); in set_ssp()
1989 status = mgmt_bredr_support(hdev); in set_ssp()
1991 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, status); in set_ssp()
1993 if (!lmp_ssp_capable(hdev)) in set_ssp()
1994 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1998 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2001 hci_dev_lock(hdev); in set_ssp()
2003 if (!hdev_is_powered(hdev)) { in set_ssp()
2007 changed = !hci_dev_test_and_set_flag(hdev, in set_ssp()
2010 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
2014 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
2019 err = new_settings(hdev, sk); in set_ssp()
2024 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_ssp()
2025 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2030 if (!!cp->val == hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_ssp()
2031 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
2035 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SSP, hdev, data, len); in set_ssp()
2039 err = hci_cmd_sync_queue(hdev, set_ssp_sync, cmd, in set_ssp()
2043 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2051 hci_dev_unlock(hdev); in set_ssp()
2055 static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_hs() argument
2057 bt_dev_dbg(hdev, "sock %p", sk); in set_hs()
2059 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2063 static void set_le_complete(struct hci_dev *hdev, void *data, int err) in set_le_complete() argument
2065 struct cmd_lookup match = { NULL, hdev }; in set_le_complete()
2068 bt_dev_dbg(hdev, "err %d", err); in set_le_complete()
2071 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp, in set_le_complete()
2076 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match); in set_le_complete()
2078 new_settings(hdev, match.sk); in set_le_complete()
2084 static int set_le_sync(struct hci_dev *hdev, void *data) in set_le_sync() argument
2092 hci_clear_adv_instance_sync(hdev, NULL, 0x00, true); in set_le_sync()
2094 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_le_sync()
2095 hci_disable_advertising_sync(hdev); in set_le_sync()
2097 if (ext_adv_capable(hdev)) in set_le_sync()
2098 hci_remove_ext_adv_instance_sync(hdev, 0, cmd->sk); in set_le_sync()
2100 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in set_le_sync()
2103 err = hci_write_le_host_supported_sync(hdev, val, 0); in set_le_sync()
2110 if (!err && hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le_sync()
2111 if (ext_adv_capable(hdev)) { in set_le_sync()
2114 status = hci_setup_ext_adv_instance_sync(hdev, 0x00); in set_le_sync()
2116 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_le_sync()
2118 hci_update_adv_data_sync(hdev, 0x00); in set_le_sync()
2119 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_le_sync()
2122 hci_update_passive_scan(hdev); in set_le_sync()
2128 static void set_mesh_complete(struct hci_dev *hdev, void *data, int err) in set_mesh_complete() argument
2135 mgmt_pending_foreach(MGMT_OP_SET_MESH_RECEIVER, hdev, in set_mesh_complete()
2141 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, 0, NULL, 0); in set_mesh_complete()
2144 static int set_mesh_sync(struct hci_dev *hdev, void *data) in set_mesh_sync() argument
2150 memset(hdev->mesh_ad_types, 0, sizeof(hdev->mesh_ad_types)); in set_mesh_sync()
2153 hci_dev_set_flag(hdev, HCI_MESH); in set_mesh_sync()
2155 hci_dev_clear_flag(hdev, HCI_MESH); in set_mesh_sync()
2160 if (len <= sizeof(hdev->mesh_ad_types)) in set_mesh_sync()
2161 memcpy(hdev->mesh_ad_types, cp->ad_types, len); in set_mesh_sync()
2163 hci_update_passive_scan_sync(hdev); in set_mesh_sync()
2167 static int set_mesh(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_mesh() argument
2173 bt_dev_dbg(hdev, "sock %p", sk); in set_mesh()
2175 if (!lmp_le_capable(hdev) || in set_mesh()
2176 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in set_mesh()
2177 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2181 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2184 hci_dev_lock(hdev); in set_mesh()
2186 cmd = mgmt_pending_add(sk, MGMT_OP_SET_MESH_RECEIVER, hdev, data, len); in set_mesh()
2190 err = hci_cmd_sync_queue(hdev, set_mesh_sync, cmd, in set_mesh()
2194 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2201 hci_dev_unlock(hdev); in set_mesh()
2205 static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err) in mesh_send_start_complete() argument
2215 hci_dev_clear_flag(hdev, HCI_MESH_SENDING); in mesh_send_start_complete()
2217 mesh_send_complete(hdev, mesh_tx, false); in mesh_send_start_complete()
2222 queue_delayed_work(hdev->req_workqueue, &hdev->mesh_send_done, in mesh_send_start_complete()
2226 static int mesh_send_sync(struct hci_dev *hdev, void *data) in mesh_send_sync() argument
2231 u8 instance = hdev->le_num_of_adv_sets + 1; in mesh_send_sync()
2235 if (hdev->le_num_of_adv_sets <= hdev->adv_instance_cnt) in mesh_send_sync()
2239 duration = send->cnt * INTERVAL_TO_MS(hdev->le_adv_max_interval); in mesh_send_sync()
2240 adv = hci_add_adv_instance(hdev, instance, 0, in mesh_send_sync()
2245 hdev->le_adv_min_interval, in mesh_send_sync()
2246 hdev->le_adv_max_interval, in mesh_send_sync()
2254 if (hdev->cur_adv_instance == instance) { in mesh_send_sync()
2260 cancel_adv_timeout(hdev); in mesh_send_sync()
2262 next_instance = hci_get_next_instance(hdev, instance); in mesh_send_sync()
2267 } else if (hdev->adv_instance_timeout) { in mesh_send_sync()
2275 return hci_schedule_adv_instance_sync(hdev, instance, true); in mesh_send_sync()
2290 static int mesh_features(struct sock *sk, struct hci_dev *hdev, in mesh_features() argument
2295 if (!lmp_le_capable(hdev) || in mesh_features()
2296 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_features()
2297 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_READ_FEATURES, in mesh_features()
2301 rp.index = cpu_to_le16(hdev->id); in mesh_features()
2302 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mesh_features()
2305 hci_dev_lock(hdev); in mesh_features()
2308 mgmt_mesh_foreach(hdev, send_count, &rp, sk); in mesh_features()
2310 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_MESH_READ_FEATURES, 0, &rp, in mesh_features()
2313 hci_dev_unlock(hdev); in mesh_features()
2317 static int send_cancel(struct hci_dev *hdev, void *data) in send_cancel() argument
2325 mesh_tx = mgmt_mesh_next(hdev, cmd->sk); in send_cancel()
2328 mesh_send_complete(hdev, mesh_tx, false); in send_cancel()
2331 mesh_tx = mgmt_mesh_find(hdev, cancel->handle); in send_cancel()
2334 mesh_send_complete(hdev, mesh_tx, false); in send_cancel()
2337 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in send_cancel()
2344 static int mesh_send_cancel(struct sock *sk, struct hci_dev *hdev, in mesh_send_cancel() argument
2350 if (!lmp_le_capable(hdev) || in mesh_send_cancel()
2351 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_send_cancel()
2352 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2355 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mesh_send_cancel()
2356 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2359 hci_dev_lock(hdev); in mesh_send_cancel()
2360 cmd = mgmt_pending_new(sk, MGMT_OP_MESH_SEND_CANCEL, hdev, data, len); in mesh_send_cancel()
2364 err = hci_cmd_sync_queue(hdev, send_cancel, cmd, NULL); in mesh_send_cancel()
2367 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2374 hci_dev_unlock(hdev); in mesh_send_cancel()
2378 static int mesh_send(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in mesh_send() argument
2386 if (!lmp_le_capable(hdev) || in mesh_send()
2387 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_send()
2388 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2390 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) || in mesh_send()
2393 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2396 hci_dev_lock(hdev); in mesh_send()
2401 mgmt_mesh_foreach(hdev, send_count, &rp, sk); in mesh_send()
2404 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2409 sending = hci_dev_test_flag(hdev, HCI_MESH_SENDING); in mesh_send()
2410 mesh_tx = mgmt_mesh_add(sk, hdev, send, len); in mesh_send()
2415 err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx, in mesh_send()
2419 bt_dev_err(hdev, "Send Mesh Failed %d", err); in mesh_send()
2420 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2428 hci_dev_set_flag(hdev, HCI_MESH_SENDING); in mesh_send()
2430 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_MESH_SEND, 0, in mesh_send()
2435 hci_dev_unlock(hdev); in mesh_send()
2439 static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_le() argument
2446 bt_dev_dbg(hdev, "sock %p", sk); in set_le()
2448 if (!lmp_le_capable(hdev)) in set_le()
2449 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2453 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2465 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_le()
2467 return send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
2469 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2473 hci_dev_lock(hdev); in set_le()
2476 enabled = lmp_host_le_capable(hdev); in set_le()
2478 if (!hdev_is_powered(hdev) || val == enabled) { in set_le()
2481 if (val != hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le()
2482 hci_dev_change_flag(hdev, HCI_LE_ENABLED); in set_le()
2486 if (!val && hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in set_le()
2487 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_le()
2491 err = send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
2496 err = new_settings(hdev, sk); in set_le()
2501 if (pending_find(MGMT_OP_SET_LE, hdev) || in set_le()
2502 pending_find(MGMT_OP_SET_ADVERTISING, hdev)) { in set_le()
2503 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2508 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LE, hdev, data, len); in set_le()
2512 err = hci_cmd_sync_queue(hdev, set_le_sync, cmd, in set_le()
2516 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2524 hci_dev_unlock(hdev); in set_le()
2528 static int send_hci_cmd_sync(struct hci_dev *hdev, void *data) in send_hci_cmd_sync() argument
2534 skb = __hci_cmd_sync_ev(hdev, le16_to_cpu(cp->opcode), in send_hci_cmd_sync()
2540 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_HCI_CMD_SYNC, in send_hci_cmd_sync()
2545 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_HCI_CMD_SYNC, 0, in send_hci_cmd_sync()
2556 static int mgmt_hci_cmd_sync(struct sock *sk, struct hci_dev *hdev, in mgmt_hci_cmd_sync() argument
2564 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_HCI_CMD_SYNC, in mgmt_hci_cmd_sync()
2567 hci_dev_lock(hdev); in mgmt_hci_cmd_sync()
2568 cmd = mgmt_pending_new(sk, MGMT_OP_HCI_CMD_SYNC, hdev, data, len); in mgmt_hci_cmd_sync()
2572 err = hci_cmd_sync_queue(hdev, send_hci_cmd_sync, cmd, NULL); in mgmt_hci_cmd_sync()
2575 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_HCI_CMD_SYNC, in mgmt_hci_cmd_sync()
2582 hci_dev_unlock(hdev); in mgmt_hci_cmd_sync()
2592 static bool pending_eir_or_class(struct hci_dev *hdev) in pending_eir_or_class() argument
2596 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in pending_eir_or_class()
2628 static void mgmt_class_complete(struct hci_dev *hdev, void *data, int err) in mgmt_class_complete() argument
2632 bt_dev_dbg(hdev, "err %d", err); in mgmt_class_complete()
2635 mgmt_status(err), hdev->dev_class, 3); in mgmt_class_complete()
2640 static int add_uuid_sync(struct hci_dev *hdev, void *data) in add_uuid_sync() argument
2644 err = hci_update_class_sync(hdev); in add_uuid_sync()
2648 return hci_update_eir_sync(hdev); in add_uuid_sync()
2651 static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in add_uuid() argument
2658 bt_dev_dbg(hdev, "sock %p", sk); in add_uuid()
2660 hci_dev_lock(hdev); in add_uuid()
2662 if (pending_eir_or_class(hdev)) { in add_uuid()
2663 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_UUID, in add_uuid()
2678 list_add_tail(&uuid->list, &hdev->uuids); in add_uuid()
2680 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_UUID, hdev, data, len); in add_uuid()
2689 err = hci_cmd_sync_submit(hdev, add_uuid_sync, cmd, in add_uuid()
2697 hci_dev_unlock(hdev); in add_uuid()
2701 static bool enable_service_cache(struct hci_dev *hdev) in enable_service_cache() argument
2703 if (!hdev_is_powered(hdev)) in enable_service_cache()
2706 if (!hci_dev_test_and_set_flag(hdev, HCI_SERVICE_CACHE)) { in enable_service_cache()
2707 queue_delayed_work(hdev->workqueue, &hdev->service_cache, in enable_service_cache()
2715 static int remove_uuid_sync(struct hci_dev *hdev, void *data) in remove_uuid_sync() argument
2719 err = hci_update_class_sync(hdev); in remove_uuid_sync()
2723 return hci_update_eir_sync(hdev); in remove_uuid_sync()
2726 static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data, in remove_uuid() argument
2737 bt_dev_dbg(hdev, "sock %p", sk); in remove_uuid()
2739 hci_dev_lock(hdev); in remove_uuid()
2741 if (pending_eir_or_class(hdev)) { in remove_uuid()
2742 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2748 hci_uuids_clear(hdev); in remove_uuid()
2750 if (enable_service_cache(hdev)) { in remove_uuid()
2751 err = mgmt_cmd_complete(sk, hdev->id, in remove_uuid()
2753 0, hdev->dev_class, 3); in remove_uuid()
2762 list_for_each_entry_safe(match, tmp, &hdev->uuids, list) { in remove_uuid()
2772 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2778 cmd = mgmt_pending_new(sk, MGMT_OP_REMOVE_UUID, hdev, data, len); in remove_uuid()
2787 err = hci_cmd_sync_submit(hdev, remove_uuid_sync, cmd, in remove_uuid()
2793 hci_dev_unlock(hdev); in remove_uuid()
2797 static int set_class_sync(struct hci_dev *hdev, void *data) in set_class_sync() argument
2801 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) { in set_class_sync()
2802 cancel_delayed_work_sync(&hdev->service_cache); in set_class_sync()
2803 err = hci_update_eir_sync(hdev); in set_class_sync()
2809 return hci_update_class_sync(hdev); in set_class_sync()
2812 static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data, in set_dev_class() argument
2819 bt_dev_dbg(hdev, "sock %p", sk); in set_dev_class()
2821 if (!lmp_bredr_capable(hdev)) in set_dev_class()
2822 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2825 hci_dev_lock(hdev); in set_dev_class()
2827 if (pending_eir_or_class(hdev)) { in set_dev_class()
2828 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2834 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2839 hdev->major_class = cp->major; in set_dev_class()
2840 hdev->minor_class = cp->minor; in set_dev_class()
2842 if (!hdev_is_powered(hdev)) { in set_dev_class()
2843 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, in set_dev_class()
2844 hdev->dev_class, 3); in set_dev_class()
2848 cmd = mgmt_pending_new(sk, MGMT_OP_SET_DEV_CLASS, hdev, data, len); in set_dev_class()
2857 err = hci_cmd_sync_submit(hdev, set_class_sync, cmd, in set_dev_class()
2863 hci_dev_unlock(hdev); in set_dev_class()
2867 static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data, in load_link_keys() argument
2877 bt_dev_dbg(hdev, "sock %p", sk); in load_link_keys()
2879 if (!lmp_bredr_capable(hdev)) in load_link_keys()
2880 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2885 bt_dev_err(hdev, "load_link_keys: too big key_count value %u", in load_link_keys()
2887 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2893 bt_dev_err(hdev, "load_link_keys: expected %u bytes, got %u bytes", in load_link_keys()
2895 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2900 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2903 bt_dev_dbg(hdev, "debug_keys %u key_count %u", cp->debug_keys, in load_link_keys()
2906 hci_dev_lock(hdev); in load_link_keys()
2908 hci_link_keys_clear(hdev); in load_link_keys()
2911 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in load_link_keys()
2913 changed = hci_dev_test_and_clear_flag(hdev, in load_link_keys()
2917 new_settings(hdev, NULL); in load_link_keys()
2922 if (hci_is_blocked_key(hdev, in load_link_keys()
2925 bt_dev_warn(hdev, "Skipping blocked link key for %pMR", in load_link_keys()
2931 bt_dev_warn(hdev, in load_link_keys()
2938 bt_dev_warn(hdev, "Invalid link key type %u for %pMR", in load_link_keys()
2949 hci_add_link_key(hdev, NULL, &key->addr.bdaddr, key->val, in load_link_keys()
2953 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0); in load_link_keys()
2955 hci_dev_unlock(hdev); in load_link_keys()
2960 static int device_unpaired(struct hci_dev *hdev, bdaddr_t *bdaddr, in device_unpaired() argument
2968 return mgmt_event(MGMT_EV_DEVICE_UNPAIRED, hdev, &ev, sizeof(ev), in device_unpaired()
2972 static void unpair_device_complete(struct hci_dev *hdev, void *data, int err) in unpair_device_complete() argument
2978 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_complete()
2984 static int unpair_device_sync(struct hci_dev *hdev, void *data) in unpair_device_sync() argument
2991 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device_sync()
2994 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in unpair_device_sync()
3008 static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data, in unpair_device() argument
3024 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3029 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3033 hci_dev_lock(hdev); in unpair_device()
3035 if (!hdev_is_powered(hdev)) { in unpair_device()
3036 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3051 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device()
3056 err = hci_remove_link_key(hdev, &cp->addr.bdaddr); in unpair_device()
3058 err = mgmt_cmd_complete(sk, hdev->id, in unpair_device()
3072 err = smp_cancel_and_remove_pairing(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3074 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3080 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3082 hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3093 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3112 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0, in unpair_device()
3114 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk); in unpair_device()
3118 cmd = mgmt_pending_new(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp, in unpair_device()
3127 err = hci_cmd_sync_queue(hdev, unpair_device_sync, cmd, in unpair_device()
3133 hci_dev_unlock(hdev); in unpair_device()
3137 static void disconnect_complete(struct hci_dev *hdev, void *data, int err) in disconnect_complete() argument
3145 static int disconnect_sync(struct hci_dev *hdev, void *data) in disconnect_sync() argument
3152 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in disconnect_sync()
3155 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in disconnect_sync()
3169 static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data, in disconnect() argument
3177 bt_dev_dbg(hdev, "sock %p", sk); in disconnect()
3184 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3188 hci_dev_lock(hdev); in disconnect()
3190 if (!test_bit(HCI_UP, &hdev->flags)) { in disconnect()
3191 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3197 cmd = mgmt_pending_new(sk, MGMT_OP_DISCONNECT, hdev, data, len); in disconnect()
3205 err = hci_cmd_sync_queue(hdev, disconnect_sync, cmd, in disconnect()
3211 hci_dev_unlock(hdev); in disconnect()
3235 static int get_connections(struct sock *sk, struct hci_dev *hdev, void *data, in get_connections() argument
3243 bt_dev_dbg(hdev, "sock %p", sk); in get_connections()
3245 hci_dev_lock(hdev); in get_connections()
3247 if (!hdev_is_powered(hdev)) { in get_connections()
3248 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, in get_connections()
3254 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
3266 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
3279 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, 0, rp, in get_connections()
3285 hci_dev_unlock(hdev); in get_connections()
3289 static int send_pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in send_pin_code_neg_reply() argument
3295 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, hdev, cp, in send_pin_code_neg_reply()
3302 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, in send_pin_code_neg_reply()
3310 static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data, in pin_code_reply() argument
3319 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_reply()
3321 hci_dev_lock(hdev); in pin_code_reply()
3323 if (!hdev_is_powered(hdev)) { in pin_code_reply()
3324 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3329 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in pin_code_reply()
3331 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3341 bt_dev_err(hdev, "PIN code is not 16 bytes long"); in pin_code_reply()
3343 err = send_pin_code_neg_reply(sk, hdev, &ncp); in pin_code_reply()
3345 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3351 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data, len); in pin_code_reply()
3363 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_REPLY, sizeof(reply), &reply); in pin_code_reply()
3368 hci_dev_unlock(hdev); in pin_code_reply()
3372 static int set_io_capability(struct sock *sk, struct hci_dev *hdev, void *data, in set_io_capability() argument
3377 bt_dev_dbg(hdev, "sock %p", sk); in set_io_capability()
3380 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, in set_io_capability()
3383 hci_dev_lock(hdev); in set_io_capability()
3385 hdev->io_capability = cp->io_capability; in set_io_capability()
3387 bt_dev_dbg(hdev, "IO capability set to 0x%02x", hdev->io_capability); in set_io_capability()
3389 hci_dev_unlock(hdev); in set_io_capability()
3391 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, 0, in set_io_capability()
3397 struct hci_dev *hdev = conn->hdev; in find_pairing() local
3400 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in find_pairing()
3489 static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in pair_device() argument
3499 bt_dev_dbg(hdev, "sock %p", sk); in pair_device()
3506 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3511 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3515 hci_dev_lock(hdev); in pair_device()
3517 if (!hdev_is_powered(hdev)) { in pair_device()
3518 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3524 if (hci_bdaddr_is_paired(hdev, &cp->addr.bdaddr, cp->addr.type)) { in pair_device()
3525 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3535 conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level, in pair_device()
3551 p = hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type); in pair_device()
3560 conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr, addr_type, in pair_device()
3577 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3584 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3589 cmd = mgmt_pending_add(sk, MGMT_OP_PAIR_DEVICE, hdev, data, len); in pair_device()
3621 hci_dev_unlock(hdev); in pair_device()
3625 static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in cancel_pair_device() argument
3633 bt_dev_dbg(hdev, "sock %p", sk); in cancel_pair_device()
3635 hci_dev_lock(hdev); in cancel_pair_device()
3637 if (!hdev_is_powered(hdev)) { in cancel_pair_device()
3638 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3643 cmd = pending_find(MGMT_OP_PAIR_DEVICE, hdev); in cancel_pair_device()
3645 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3653 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3661 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0, in cancel_pair_device()
3669 hci_remove_link_key(hdev, &addr->bdaddr); in cancel_pair_device()
3671 smp_cancel_and_remove_pairing(hdev, &addr->bdaddr, in cancel_pair_device()
3678 hci_dev_unlock(hdev); in cancel_pair_device()
3682 static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev, in user_pairing_resp() argument
3690 hci_dev_lock(hdev); in user_pairing_resp()
3692 if (!hdev_is_powered(hdev)) { in user_pairing_resp()
3693 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3700 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &addr->bdaddr); in user_pairing_resp()
3702 conn = hci_conn_hash_lookup_le(hdev, &addr->bdaddr, in user_pairing_resp()
3706 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3715 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3719 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3726 cmd = mgmt_pending_add(sk, mgmt_op, hdev, addr, sizeof(*addr)); in user_pairing_resp()
3740 err = hci_send_cmd(hdev, hci_op, sizeof(cp), &cp); in user_pairing_resp()
3742 err = hci_send_cmd(hdev, hci_op, sizeof(addr->bdaddr), in user_pairing_resp()
3749 hci_dev_unlock(hdev); in user_pairing_resp()
3753 static int pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in pin_code_neg_reply() argument
3758 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_neg_reply()
3760 return user_pairing_resp(sk, hdev, &cp->addr, in pin_code_neg_reply()
3765 static int user_confirm_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_confirm_reply() argument
3770 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_reply()
3773 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_USER_CONFIRM_REPLY, in user_confirm_reply()
3776 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_reply()
3781 static int user_confirm_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_confirm_neg_reply() argument
3786 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_neg_reply()
3788 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_neg_reply()
3793 static int user_passkey_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_passkey_reply() argument
3798 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_reply()
3800 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_reply()
3805 static int user_passkey_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_passkey_neg_reply() argument
3810 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_neg_reply()
3812 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_neg_reply()
3817 static int adv_expire_sync(struct hci_dev *hdev, u32 flags) in adv_expire_sync() argument
3821 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in adv_expire_sync()
3829 cancel_adv_timeout(hdev); in adv_expire_sync()
3831 adv_instance = hci_get_next_instance(hdev, adv_instance->instance); in adv_expire_sync()
3835 hci_schedule_adv_instance_sync(hdev, adv_instance->instance, true); in adv_expire_sync()
3840 static int name_changed_sync(struct hci_dev *hdev, void *data) in name_changed_sync() argument
3842 return adv_expire_sync(hdev, MGMT_ADV_FLAG_LOCAL_NAME); in name_changed_sync()
3845 static void set_name_complete(struct hci_dev *hdev, void *data, int err) in set_name_complete() argument
3851 bt_dev_dbg(hdev, "err %d", err); in set_name_complete()
3854 cmd != pending_find(MGMT_OP_SET_LOCAL_NAME, hdev)) in set_name_complete()
3858 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_name_complete()
3861 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_name_complete()
3864 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_name_complete()
3865 hci_cmd_sync_queue(hdev, name_changed_sync, NULL, NULL); in set_name_complete()
3871 static int set_name_sync(struct hci_dev *hdev, void *data) in set_name_sync() argument
3873 if (lmp_bredr_capable(hdev)) { in set_name_sync()
3874 hci_update_name_sync(hdev); in set_name_sync()
3875 hci_update_eir_sync(hdev); in set_name_sync()
3881 if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING)) in set_name_sync()
3882 hci_update_scan_rsp_data_sync(hdev, hdev->cur_adv_instance); in set_name_sync()
3887 static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data, in set_local_name() argument
3894 bt_dev_dbg(hdev, "sock %p", sk); in set_local_name()
3896 hci_dev_lock(hdev); in set_local_name()
3901 if (!memcmp(hdev->dev_name, cp->name, sizeof(hdev->dev_name)) && in set_local_name()
3902 !memcmp(hdev->short_name, cp->short_name, in set_local_name()
3903 sizeof(hdev->short_name))) { in set_local_name()
3904 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3909 memcpy(hdev->short_name, cp->short_name, sizeof(hdev->short_name)); in set_local_name()
3911 if (!hdev_is_powered(hdev)) { in set_local_name()
3912 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3914 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3919 err = mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, data, in set_local_name()
3921 ext_info_changed(hdev, sk); in set_local_name()
3926 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len); in set_local_name()
3930 err = hci_cmd_sync_queue(hdev, set_name_sync, cmd, in set_local_name()
3934 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_local_name()
3943 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3946 hci_dev_unlock(hdev); in set_local_name()
3950 static int appearance_changed_sync(struct hci_dev *hdev, void *data) in appearance_changed_sync() argument
3952 return adv_expire_sync(hdev, MGMT_ADV_FLAG_APPEARANCE); in appearance_changed_sync()
3955 static int set_appearance(struct sock *sk, struct hci_dev *hdev, void *data, in set_appearance() argument
3962 bt_dev_dbg(hdev, "sock %p", sk); in set_appearance()
3964 if (!lmp_le_capable(hdev)) in set_appearance()
3965 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_APPEARANCE, in set_appearance()
3970 hci_dev_lock(hdev); in set_appearance()
3972 if (hdev->appearance != appearance) { in set_appearance()
3973 hdev->appearance = appearance; in set_appearance()
3975 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_appearance()
3976 hci_cmd_sync_queue(hdev, appearance_changed_sync, NULL, in set_appearance()
3979 ext_info_changed(hdev, sk); in set_appearance()
3982 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_APPEARANCE, 0, NULL, in set_appearance()
3985 hci_dev_unlock(hdev); in set_appearance()
3990 static int get_phy_configuration(struct sock *sk, struct hci_dev *hdev, in get_phy_configuration() argument
3995 bt_dev_dbg(hdev, "sock %p", sk); in get_phy_configuration()
3997 hci_dev_lock(hdev); in get_phy_configuration()
4001 rp.supported_phys = cpu_to_le32(get_supported_phys(hdev)); in get_phy_configuration()
4002 rp.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in get_phy_configuration()
4003 rp.configurable_phys = cpu_to_le32(get_configurable_phys(hdev)); in get_phy_configuration()
4005 hci_dev_unlock(hdev); in get_phy_configuration()
4007 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_PHY_CONFIGURATION, 0, in get_phy_configuration()
4011 int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip) in mgmt_phy_configuration_changed() argument
4017 ev.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in mgmt_phy_configuration_changed()
4019 return mgmt_event(MGMT_EV_PHY_CONFIGURATION_CHANGED, hdev, &ev, in mgmt_phy_configuration_changed()
4023 static void set_default_phy_complete(struct hci_dev *hdev, void *data, int err) in set_default_phy_complete() argument
4030 cmd != pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) in set_default_phy_complete()
4042 bt_dev_dbg(hdev, "status %d", status); in set_default_phy_complete()
4045 mgmt_cmd_status(cmd->sk, hdev->id, in set_default_phy_complete()
4048 mgmt_cmd_complete(cmd->sk, hdev->id, in set_default_phy_complete()
4052 mgmt_phy_configuration_changed(hdev, cmd->sk); in set_default_phy_complete()
4061 static int set_default_phy_sync(struct hci_dev *hdev, void *data) in set_default_phy_sync() argument
4094 cmd->skb = __hci_cmd_sync(hdev, HCI_OP_LE_SET_DEFAULT_PHY, in set_default_phy_sync()
4100 static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, in set_phy_configuration() argument
4110 bt_dev_dbg(hdev, "sock %p", sk); in set_phy_configuration()
4112 configurable_phys = get_configurable_phys(hdev); in set_phy_configuration()
4113 supported_phys = get_supported_phys(hdev); in set_phy_configuration()
4117 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4124 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4128 if (selected_phys == get_selected_phys(hdev)) in set_phy_configuration()
4129 return mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
4133 hci_dev_lock(hdev); in set_phy_configuration()
4135 if (!hdev_is_powered(hdev)) { in set_phy_configuration()
4136 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4142 if (pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) { in set_phy_configuration()
4143 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4189 if (pkt_type != hdev->pkt_type) { in set_phy_configuration()
4190 hdev->pkt_type = pkt_type; in set_phy_configuration()
4195 (get_selected_phys(hdev) & MGMT_PHY_LE_MASK)) { in set_phy_configuration()
4197 mgmt_phy_configuration_changed(hdev, sk); in set_phy_configuration()
4199 err = mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
4206 cmd = mgmt_pending_add(sk, MGMT_OP_SET_PHY_CONFIGURATION, hdev, data, in set_phy_configuration()
4211 err = hci_cmd_sync_queue(hdev, set_default_phy_sync, cmd, in set_phy_configuration()
4215 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4224 hci_dev_unlock(hdev); in set_phy_configuration()
4229 static int set_blocked_keys(struct sock *sk, struct hci_dev *hdev, void *data, in set_blocked_keys() argument
4239 bt_dev_dbg(hdev, "sock %p", sk); in set_blocked_keys()
4243 bt_dev_err(hdev, "too big key_count value %u", key_count); in set_blocked_keys()
4244 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4250 bt_dev_err(hdev, "expected %u bytes, got %u bytes", in set_blocked_keys()
4252 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4256 hci_dev_lock(hdev); in set_blocked_keys()
4258 hci_blocked_keys_clear(hdev); in set_blocked_keys()
4270 list_add_rcu(&b->list, &hdev->blocked_keys); in set_blocked_keys()
4272 hci_dev_unlock(hdev); in set_blocked_keys()
4274 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4278 static int set_wideband_speech(struct sock *sk, struct hci_dev *hdev, in set_wideband_speech() argument
4285 bt_dev_dbg(hdev, "sock %p", sk); in set_wideband_speech()
4287 if (!test_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks)) in set_wideband_speech()
4288 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4293 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4297 hci_dev_lock(hdev); in set_wideband_speech()
4299 if (hdev_is_powered(hdev) && in set_wideband_speech()
4300 !!cp->val != hci_dev_test_flag(hdev, in set_wideband_speech()
4302 err = mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4309 changed = !hci_dev_test_and_set_flag(hdev, in set_wideband_speech()
4312 changed = hci_dev_test_and_clear_flag(hdev, in set_wideband_speech()
4315 err = send_settings_rsp(sk, MGMT_OP_SET_WIDEBAND_SPEECH, hdev); in set_wideband_speech()
4320 err = new_settings(hdev, sk); in set_wideband_speech()
4323 hci_dev_unlock(hdev); in set_wideband_speech()
4327 static int read_controller_cap(struct sock *sk, struct hci_dev *hdev, in read_controller_cap() argument
4336 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_cap()
4340 hci_dev_lock(hdev); in read_controller_cap()
4348 if ((hdev->commands[41] & 0x08) || msft_curve_validity(hdev)) in read_controller_cap()
4356 if (hdev->commands[20] & 0x10) in read_controller_cap()
4367 if (hdev->commands[41] & 0x08) in read_controller_cap()
4370 hdev->max_enc_key_size); in read_controller_cap()
4379 if (hdev->commands[38] & 0x80) { in read_controller_cap()
4380 memcpy(&tx_power_range[0], &hdev->min_le_tx_power, 1); in read_controller_cap()
4381 memcpy(&tx_power_range[1], &hdev->max_le_tx_power, 1); in read_controller_cap()
4388 hci_dev_unlock(hdev); in read_controller_cap()
4390 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONTROLLER_CAP, 0, in read_controller_cap()
4432 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, in read_exp_features_info() argument
4441 bt_dev_dbg(hdev, "sock %p", sk); in read_exp_features_info()
4450 if (!hdev) { in read_exp_features_info()
4459 if (hdev && hci_dev_le_state_simultaneous(hdev)) { in read_exp_features_info()
4460 if (hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) in read_exp_features_info()
4470 if (hdev && (aosp_has_quality_report(hdev) || in read_exp_features_info()
4471 hdev->set_quality_report)) { in read_exp_features_info()
4472 if (hci_dev_test_flag(hdev, HCI_QUALITY_REPORT)) in read_exp_features_info()
4482 if (hdev && hdev->get_data_path_id) { in read_exp_features_info()
4483 if (hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)) in read_exp_features_info()
4500 if (hdev && lmp_le_capable(hdev)) { in read_exp_features_info()
4501 if (hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in read_exp_features_info()
4518 status = mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in read_exp_features_info()
4526 static int exp_feature_changed(struct hci_dev *hdev, const u8 *uuid, in exp_feature_changed() argument
4535 return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, in exp_feature_changed()
4547 static int set_zero_key_func(struct sock *sk, struct hci_dev *hdev, in set_zero_key_func() argument
4556 if (!hdev) { in set_zero_key_func()
4568 return mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_zero_key_func()
4574 static int set_debug_func(struct sock *sk, struct hci_dev *hdev, in set_debug_func() argument
4583 if (hdev) in set_debug_func()
4584 return mgmt_cmd_status(sk, hdev->id, in set_debug_func()
4614 exp_feature_changed(hdev, debug_uuid, val, sk); in set_debug_func()
4620 static int set_mgmt_mesh_func(struct sock *sk, struct hci_dev *hdev, in set_mgmt_mesh_func() argument
4628 if (!hdev) in set_mgmt_mesh_func()
4635 return mgmt_cmd_status(sk, hdev->id, in set_mgmt_mesh_func()
4641 return mgmt_cmd_status(sk, hdev->id, in set_mgmt_mesh_func()
4648 changed = !hci_dev_test_and_set_flag(hdev, in set_mgmt_mesh_func()
4651 hci_dev_clear_flag(hdev, HCI_MESH); in set_mgmt_mesh_func()
4652 changed = hci_dev_test_and_clear_flag(hdev, in set_mgmt_mesh_func()
4661 err = mgmt_cmd_complete(sk, hdev->id, in set_mgmt_mesh_func()
4666 exp_feature_changed(hdev, mgmt_mesh_uuid, val, sk); in set_mgmt_mesh_func()
4671 static int set_quality_report_func(struct sock *sk, struct hci_dev *hdev, in set_quality_report_func() argument
4680 if (!hdev) in set_quality_report_func()
4687 return mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4693 return mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4697 hci_req_sync_lock(hdev); in set_quality_report_func()
4700 changed = (val != hci_dev_test_flag(hdev, HCI_QUALITY_REPORT)); in set_quality_report_func()
4702 if (!aosp_has_quality_report(hdev) && !hdev->set_quality_report) { in set_quality_report_func()
4703 err = mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4710 if (hdev->set_quality_report) in set_quality_report_func()
4711 err = hdev->set_quality_report(hdev, val); in set_quality_report_func()
4713 err = aosp_set_quality_report(hdev, val); in set_quality_report_func()
4716 err = mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4723 hci_dev_set_flag(hdev, HCI_QUALITY_REPORT); in set_quality_report_func()
4725 hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT); in set_quality_report_func()
4728 bt_dev_dbg(hdev, "quality report enable %d changed %d", val, changed); in set_quality_report_func()
4734 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_EXP_FEATURE, 0, in set_quality_report_func()
4738 exp_feature_changed(hdev, quality_report_uuid, val, sk); in set_quality_report_func()
4741 hci_req_sync_unlock(hdev); in set_quality_report_func()
4745 static int set_offload_codec_func(struct sock *sk, struct hci_dev *hdev, in set_offload_codec_func() argument
4754 if (!hdev) in set_offload_codec_func()
4761 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4767 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4772 changed = (val != hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)); in set_offload_codec_func()
4774 if (!hdev->get_data_path_id) { in set_offload_codec_func()
4775 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4782 hci_dev_set_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED); in set_offload_codec_func()
4784 hci_dev_clear_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED); in set_offload_codec_func()
4787 bt_dev_info(hdev, "offload codecs enable %d changed %d", in set_offload_codec_func()
4793 err = mgmt_cmd_complete(sk, hdev->id, in set_offload_codec_func()
4798 exp_feature_changed(hdev, offload_codecs_uuid, val, sk); in set_offload_codec_func()
4803 static int set_le_simultaneous_roles_func(struct sock *sk, struct hci_dev *hdev, in set_le_simultaneous_roles_func() argument
4812 if (!hdev) in set_le_simultaneous_roles_func()
4819 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4825 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4830 changed = (val != hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)); in set_le_simultaneous_roles_func()
4832 if (!hci_dev_le_state_simultaneous(hdev)) { in set_le_simultaneous_roles_func()
4833 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4840 hci_dev_set_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); in set_le_simultaneous_roles_func()
4842 hci_dev_clear_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); in set_le_simultaneous_roles_func()
4845 bt_dev_info(hdev, "LE simultaneous roles enable %d changed %d", in set_le_simultaneous_roles_func()
4851 err = mgmt_cmd_complete(sk, hdev->id, in set_le_simultaneous_roles_func()
4856 exp_feature_changed(hdev, le_simultaneous_roles_uuid, val, sk); in set_le_simultaneous_roles_func()
4862 static int set_iso_socket_func(struct sock *sk, struct hci_dev *hdev, in set_iso_socket_func() argument
4870 if (hdev) in set_iso_socket_func()
4871 return mgmt_cmd_status(sk, hdev->id, in set_iso_socket_func()
4906 exp_feature_changed(hdev, iso_socket_uuid, val, sk); in set_iso_socket_func()
4914 int (*set_func)(struct sock *sk, struct hci_dev *hdev,
4933 static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, in set_exp_feature() argument
4939 bt_dev_dbg(hdev, "sock %p", sk); in set_exp_feature()
4943 return exp_features[i].set_func(sk, hdev, cp, data_len); in set_exp_feature()
4946 return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_exp_feature()
4951 static int get_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in get_device_flags() argument
4962 bt_dev_dbg(hdev, "Get device flags %pMR (type 0x%x)\n", in get_device_flags()
4965 hci_dev_lock(hdev); in get_device_flags()
4967 supported_flags = hdev->conn_flags; in get_device_flags()
4972 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, in get_device_flags()
4980 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in get_device_flags()
4996 hci_dev_unlock(hdev); in get_device_flags()
4998 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_DEVICE_FLAGS, status, in get_device_flags()
5002 static void device_flags_changed(struct sock *sk, struct hci_dev *hdev, in device_flags_changed() argument
5013 mgmt_event(MGMT_EV_DEVICE_FLAGS_CHANGED, hdev, &ev, sizeof(ev), sk); in device_flags_changed()
5016 static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_flags() argument
5026 bt_dev_dbg(hdev, "Set device flags %pMR (type 0x%x) = 0x%x", in set_device_flags()
5030 supported_flags = hdev->conn_flags; in set_device_flags()
5033 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
5038 hci_dev_lock(hdev); in set_device_flags()
5041 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, in set_device_flags()
5049 bt_dev_warn(hdev, "No such BR/EDR device %pMR (0x%x)", in set_device_flags()
5056 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in set_device_flags()
5059 bt_dev_warn(hdev, "No such LE device %pMR (0x%x)", in set_device_flags()
5064 supported_flags = hdev->conn_flags; in set_device_flags()
5067 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
5079 hci_update_passive_scan(hdev); in set_device_flags()
5082 hci_dev_unlock(hdev); in set_device_flags()
5086 device_flags_changed(sk, hdev, &cp->addr.bdaddr, cp->addr.type, in set_device_flags()
5089 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_FLAGS, status, in set_device_flags()
5093 static void mgmt_adv_monitor_added(struct sock *sk, struct hci_dev *hdev, in mgmt_adv_monitor_added() argument
5100 mgmt_event(MGMT_EV_ADV_MONITOR_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_adv_monitor_added()
5103 void mgmt_adv_monitor_removed(struct hci_dev *hdev, u16 handle) in mgmt_adv_monitor_removed() argument
5110 cmd = pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev); in mgmt_adv_monitor_removed()
5120 mgmt_event(MGMT_EV_ADV_MONITOR_REMOVED, hdev, &ev, sizeof(ev), sk_skip); in mgmt_adv_monitor_removed()
5123 static int read_adv_mon_features(struct sock *sk, struct hci_dev *hdev, in read_adv_mon_features() argument
5135 BT_DBG("request for %s", hdev->name); in read_adv_mon_features()
5137 hci_dev_lock(hdev); in read_adv_mon_features()
5139 if (msft_monitor_supported(hdev)) in read_adv_mon_features()
5142 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) in read_adv_mon_features()
5145 hci_dev_unlock(hdev); in read_adv_mon_features()
5163 err = mgmt_cmd_complete(sk, hdev->id, in read_adv_mon_features()
5172 static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, in mgmt_add_adv_patterns_monitor_complete() argument
5179 hci_dev_lock(hdev); in mgmt_add_adv_patterns_monitor_complete()
5184 mgmt_adv_monitor_added(cmd->sk, hdev, monitor->handle); in mgmt_add_adv_patterns_monitor_complete()
5185 hdev->adv_monitors_cnt++; in mgmt_add_adv_patterns_monitor_complete()
5188 hci_update_passive_scan(hdev); in mgmt_add_adv_patterns_monitor_complete()
5195 hci_dev_unlock(hdev); in mgmt_add_adv_patterns_monitor_complete()
5196 bt_dev_dbg(hdev, "add monitor %d complete, status %d", in mgmt_add_adv_patterns_monitor_complete()
5200 static int mgmt_add_adv_patterns_monitor_sync(struct hci_dev *hdev, void *data) in mgmt_add_adv_patterns_monitor_sync() argument
5205 return hci_add_adv_monitor(hdev, monitor); in mgmt_add_adv_patterns_monitor_sync()
5208 static int __add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in __add_adv_patterns_monitor() argument
5215 hci_dev_lock(hdev); in __add_adv_patterns_monitor()
5220 if (pending_find(MGMT_OP_SET_LE, hdev) || in __add_adv_patterns_monitor()
5221 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR, hdev) || in __add_adv_patterns_monitor()
5222 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI, hdev) || in __add_adv_patterns_monitor()
5223 pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev)) { in __add_adv_patterns_monitor()
5228 cmd = mgmt_pending_add(sk, op, hdev, data, len); in __add_adv_patterns_monitor()
5235 err = hci_cmd_sync_queue(hdev, mgmt_add_adv_patterns_monitor_sync, cmd, in __add_adv_patterns_monitor()
5246 hci_dev_unlock(hdev); in __add_adv_patterns_monitor()
5251 hci_free_adv_monitor(hdev, m); in __add_adv_patterns_monitor()
5252 hci_dev_unlock(hdev); in __add_adv_patterns_monitor()
5253 return mgmt_cmd_status(sk, hdev->id, op, status); in __add_adv_patterns_monitor()
5312 static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor() argument
5320 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor()
5345 return __add_adv_patterns_monitor(sk, hdev, m, status, data, len, in add_adv_patterns_monitor()
5349 static int add_adv_patterns_monitor_rssi(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor_rssi() argument
5357 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor_rssi()
5382 return __add_adv_patterns_monitor(sk, hdev, m, status, data, len, in add_adv_patterns_monitor_rssi()
5386 static void mgmt_remove_adv_monitor_complete(struct hci_dev *hdev, in mgmt_remove_adv_monitor_complete() argument
5394 cmd != pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev)) in mgmt_remove_adv_monitor_complete()
5397 hci_dev_lock(hdev); in mgmt_remove_adv_monitor_complete()
5404 hci_update_passive_scan(hdev); in mgmt_remove_adv_monitor_complete()
5410 hci_dev_unlock(hdev); in mgmt_remove_adv_monitor_complete()
5411 bt_dev_dbg(hdev, "remove monitor %d complete, status %d", in mgmt_remove_adv_monitor_complete()
5415 static int mgmt_remove_adv_monitor_sync(struct hci_dev *hdev, void *data) in mgmt_remove_adv_monitor_sync() argument
5419 if (cmd != pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev)) in mgmt_remove_adv_monitor_sync()
5426 return hci_remove_all_adv_monitor(hdev); in mgmt_remove_adv_monitor_sync()
5428 return hci_remove_single_adv_monitor(hdev, handle); in mgmt_remove_adv_monitor_sync()
5431 static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev, in remove_adv_monitor() argument
5437 hci_dev_lock(hdev); in remove_adv_monitor()
5439 if (pending_find(MGMT_OP_SET_LE, hdev) || in remove_adv_monitor()
5440 pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev) || in remove_adv_monitor()
5441 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR, hdev) || in remove_adv_monitor()
5442 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI, hdev)) { in remove_adv_monitor()
5447 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_ADV_MONITOR, hdev, data, len); in remove_adv_monitor()
5453 err = hci_cmd_sync_submit(hdev, mgmt_remove_adv_monitor_sync, cmd, in remove_adv_monitor()
5467 hci_dev_unlock(hdev); in remove_adv_monitor()
5472 hci_dev_unlock(hdev); in remove_adv_monitor()
5473 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, in remove_adv_monitor()
5477 static void read_local_oob_data_complete(struct hci_dev *hdev, void *data, int err) in read_local_oob_data_complete() argument
5494 bt_dev_dbg(hdev, "status %d", status); in read_local_oob_data_complete()
5497 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, status); in read_local_oob_data_complete()
5503 if (!bredr_sc_enabled(hdev)) { in read_local_oob_data_complete()
5507 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
5521 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
5534 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data_complete()
5544 static int read_local_oob_data_sync(struct hci_dev *hdev, void *data) in read_local_oob_data_sync() argument
5548 if (bredr_sc_enabled(hdev)) in read_local_oob_data_sync()
5549 cmd->skb = hci_read_local_oob_data_sync(hdev, true, cmd->sk); in read_local_oob_data_sync()
5551 cmd->skb = hci_read_local_oob_data_sync(hdev, false, cmd->sk); in read_local_oob_data_sync()
5559 static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_data() argument
5565 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_data()
5567 hci_dev_lock(hdev); in read_local_oob_data()
5569 if (!hdev_is_powered(hdev)) { in read_local_oob_data()
5570 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5575 if (!lmp_ssp_capable(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 cmd = mgmt_pending_new(sk, MGMT_OP_READ_LOCAL_OOB_DATA, hdev, NULL, 0); in read_local_oob_data()
5585 err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd, in read_local_oob_data()
5589 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5597 hci_dev_unlock(hdev); in read_local_oob_data()
5601 static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in add_remote_oob_data() argument
5607 bt_dev_dbg(hdev, "sock %p", sk); in add_remote_oob_data()
5610 return mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5615 hci_dev_lock(hdev); in add_remote_oob_data()
5622 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5629 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
5637 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5651 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5686 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
5694 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5698 bt_dev_err(hdev, "add_remote_oob_data: invalid len of %u bytes", in add_remote_oob_data()
5700 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, in add_remote_oob_data()
5705 hci_dev_unlock(hdev); in add_remote_oob_data()
5709 static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in remove_remote_oob_data() argument
5716 bt_dev_dbg(hdev, "sock %p", sk); in remove_remote_oob_data()
5719 return mgmt_cmd_complete(sk, hdev->id, in remove_remote_oob_data()
5724 hci_dev_lock(hdev); in remove_remote_oob_data()
5727 hci_remote_oob_data_clear(hdev); in remove_remote_oob_data()
5732 err = hci_remove_remote_oob_data(hdev, &cp->addr.bdaddr, cp->addr.type); in remove_remote_oob_data()
5739 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA, in remove_remote_oob_data()
5742 hci_dev_unlock(hdev); in remove_remote_oob_data()
5746 void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_start_discovery_complete() argument
5750 bt_dev_dbg(hdev, "status %u", status); in mgmt_start_discovery_complete()
5752 hci_dev_lock(hdev); in mgmt_start_discovery_complete()
5754 cmd = pending_find(MGMT_OP_START_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5756 cmd = pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5759 cmd = pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5766 hci_dev_unlock(hdev); in mgmt_start_discovery_complete()
5769 static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, in discovery_type_is_valid() argument
5774 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
5779 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
5784 *mgmt_status = mgmt_bredr_support(hdev); in discovery_type_is_valid()
5796 static void start_discovery_complete(struct hci_dev *hdev, void *data, int err) in start_discovery_complete() argument
5800 bt_dev_dbg(hdev, "err %d", err); in start_discovery_complete()
5805 if (cmd != pending_find(MGMT_OP_START_DISCOVERY, hdev) && in start_discovery_complete()
5806 cmd != pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev) && in start_discovery_complete()
5807 cmd != pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev)) in start_discovery_complete()
5814 hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED: in start_discovery_complete()
5818 static int start_discovery_sync(struct hci_dev *hdev, void *data) in start_discovery_sync() argument
5820 return hci_start_discovery_sync(hdev); in start_discovery_sync()
5823 static int start_discovery_internal(struct sock *sk, struct hci_dev *hdev, in start_discovery_internal() argument
5831 bt_dev_dbg(hdev, "sock %p", sk); in start_discovery_internal()
5833 hci_dev_lock(hdev); in start_discovery_internal()
5835 if (!hdev_is_powered(hdev)) { in start_discovery_internal()
5836 err = mgmt_cmd_complete(sk, hdev->id, op, in start_discovery_internal()
5842 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_discovery_internal()
5843 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_discovery_internal()
5844 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
5849 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_discovery_internal()
5850 err = mgmt_cmd_complete(sk, hdev->id, op, status, in start_discovery_internal()
5856 if (hdev->discovery_paused) { in start_discovery_internal()
5857 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
5865 hci_discovery_filter_clear(hdev); in start_discovery_internal()
5867 hdev->discovery.type = cp->type; in start_discovery_internal()
5868 hdev->discovery.report_invalid_rssi = false; in start_discovery_internal()
5870 hdev->discovery.limited = true; in start_discovery_internal()
5872 hdev->discovery.limited = false; in start_discovery_internal()
5874 cmd = mgmt_pending_add(sk, op, hdev, data, len); in start_discovery_internal()
5880 err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd, in start_discovery_internal()
5887 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_discovery_internal()
5890 hci_dev_unlock(hdev); in start_discovery_internal()
5894 static int start_discovery(struct sock *sk, struct hci_dev *hdev, in start_discovery() argument
5897 return start_discovery_internal(sk, hdev, MGMT_OP_START_DISCOVERY, in start_discovery()
5901 static int start_limited_discovery(struct sock *sk, struct hci_dev *hdev, in start_limited_discovery() argument
5904 return start_discovery_internal(sk, hdev, in start_limited_discovery()
5909 static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, in start_service_discovery() argument
5919 bt_dev_dbg(hdev, "sock %p", sk); in start_service_discovery()
5921 hci_dev_lock(hdev); in start_service_discovery()
5923 if (!hdev_is_powered(hdev)) { in start_service_discovery()
5924 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5931 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_service_discovery()
5932 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_service_discovery()
5933 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5940 if (hdev->discovery_paused) { in start_service_discovery()
5941 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5950 bt_dev_err(hdev, "service_discovery: too big uuid_count value %u", in start_service_discovery()
5952 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5961 bt_dev_err(hdev, "service_discovery: expected %u bytes, got %u bytes", in start_service_discovery()
5963 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5970 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_service_discovery()
5971 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5978 hdev, data, len); in start_service_discovery()
5987 hci_discovery_filter_clear(hdev); in start_service_discovery()
5989 hdev->discovery.result_filtering = true; in start_service_discovery()
5990 hdev->discovery.type = cp->type; in start_service_discovery()
5991 hdev->discovery.rssi = cp->rssi; in start_service_discovery()
5992 hdev->discovery.uuid_count = uuid_count; in start_service_discovery()
5995 hdev->discovery.uuids = kmemdup(cp->uuids, uuid_count * 16, in start_service_discovery()
5997 if (!hdev->discovery.uuids) { in start_service_discovery()
5998 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6007 err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd, in start_service_discovery()
6014 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_service_discovery()
6017 hci_dev_unlock(hdev); in start_service_discovery()
6021 void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_stop_discovery_complete() argument
6025 bt_dev_dbg(hdev, "status %u", status); in mgmt_stop_discovery_complete()
6027 hci_dev_lock(hdev); in mgmt_stop_discovery_complete()
6029 cmd = pending_find(MGMT_OP_STOP_DISCOVERY, hdev); in mgmt_stop_discovery_complete()
6035 hci_dev_unlock(hdev); in mgmt_stop_discovery_complete()
6038 static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) in stop_discovery_complete() argument
6043 cmd != pending_find(MGMT_OP_STOP_DISCOVERY, hdev)) in stop_discovery_complete()
6046 bt_dev_dbg(hdev, "err %d", err); in stop_discovery_complete()
6053 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in stop_discovery_complete()
6056 static int stop_discovery_sync(struct hci_dev *hdev, void *data) in stop_discovery_sync() argument
6058 return hci_stop_discovery_sync(hdev); in stop_discovery_sync()
6061 static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, in stop_discovery() argument
6068 bt_dev_dbg(hdev, "sock %p", sk); in stop_discovery()
6070 hci_dev_lock(hdev); in stop_discovery()
6072 if (!hci_discovery_active(hdev)) { in stop_discovery()
6073 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
6079 if (hdev->discovery.type != mgmt_cp->type) { in stop_discovery()
6080 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
6086 cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, hdev, data, len); in stop_discovery()
6092 err = hci_cmd_sync_queue(hdev, stop_discovery_sync, cmd, in stop_discovery()
6099 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in stop_discovery()
6102 hci_dev_unlock(hdev); in stop_discovery()
6106 static int confirm_name(struct sock *sk, struct hci_dev *hdev, void *data, in confirm_name() argument
6113 bt_dev_dbg(hdev, "sock %p", sk); in confirm_name()
6115 hci_dev_lock(hdev); in confirm_name()
6117 if (!hci_discovery_active(hdev)) { in confirm_name()
6118 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
6124 e = hci_inquiry_cache_lookup_unknown(hdev, &cp->addr.bdaddr); in confirm_name()
6126 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
6137 hci_inquiry_cache_update_resolve(hdev, e); in confirm_name()
6140 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, 0, in confirm_name()
6144 hci_dev_unlock(hdev); in confirm_name()
6148 static int block_device(struct sock *sk, struct hci_dev *hdev, void *data, in block_device() argument
6155 bt_dev_dbg(hdev, "sock %p", sk); in block_device()
6158 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, in block_device()
6162 hci_dev_lock(hdev); in block_device()
6164 err = hci_bdaddr_list_add(&hdev->reject_list, &cp->addr.bdaddr, in block_device()
6171 mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &cp->addr, sizeof(cp->addr), in block_device()
6176 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status, in block_device()
6179 hci_dev_unlock(hdev); in block_device()
6184 static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data, in unblock_device() argument
6191 bt_dev_dbg(hdev, "sock %p", sk); in unblock_device()
6194 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, in unblock_device()
6198 hci_dev_lock(hdev); in unblock_device()
6200 err = hci_bdaddr_list_del(&hdev->reject_list, &cp->addr.bdaddr, in unblock_device()
6207 mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &cp->addr, sizeof(cp->addr), in unblock_device()
6212 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status, in unblock_device()
6215 hci_dev_unlock(hdev); in unblock_device()
6220 static int set_device_id_sync(struct hci_dev *hdev, void *data) in set_device_id_sync() argument
6222 return hci_update_eir_sync(hdev); in set_device_id_sync()
6225 static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_id() argument
6232 bt_dev_dbg(hdev, "sock %p", sk); in set_device_id()
6237 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, in set_device_id()
6240 hci_dev_lock(hdev); in set_device_id()
6242 hdev->devid_source = source; in set_device_id()
6243 hdev->devid_vendor = __le16_to_cpu(cp->vendor); in set_device_id()
6244 hdev->devid_product = __le16_to_cpu(cp->product); in set_device_id()
6245 hdev->devid_version = __le16_to_cpu(cp->version); in set_device_id()
6247 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, 0, in set_device_id()
6250 hci_cmd_sync_queue(hdev, set_device_id_sync, NULL, NULL); in set_device_id()
6252 hci_dev_unlock(hdev); in set_device_id()
6257 static void enable_advertising_instance(struct hci_dev *hdev, int err) in enable_advertising_instance() argument
6260 bt_dev_err(hdev, "failed to re-configure advertising %d", err); in enable_advertising_instance()
6262 bt_dev_dbg(hdev, "status %d", err); in enable_advertising_instance()
6265 static void set_advertising_complete(struct hci_dev *hdev, void *data, int err) in set_advertising_complete() argument
6267 struct cmd_lookup match = { NULL, hdev }; in set_advertising_complete()
6273 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, in set_advertising_complete()
6278 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_advertising_complete()
6279 hci_dev_set_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
6281 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
6283 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, settings_rsp, in set_advertising_complete()
6286 new_settings(hdev, match.sk); in set_advertising_complete()
6294 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in set_advertising_complete()
6295 list_empty(&hdev->adv_instances)) in set_advertising_complete()
6298 instance = hdev->cur_adv_instance; in set_advertising_complete()
6300 adv_instance = list_first_entry_or_null(&hdev->adv_instances, in set_advertising_complete()
6308 err = hci_schedule_adv_instance_sync(hdev, instance, true); in set_advertising_complete()
6310 enable_advertising_instance(hdev, err); in set_advertising_complete()
6313 static int set_adv_sync(struct hci_dev *hdev, void *data) in set_adv_sync() argument
6320 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_adv_sync()
6322 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_adv_sync()
6324 cancel_adv_timeout(hdev); in set_adv_sync()
6331 hdev->cur_adv_instance = 0x00; in set_adv_sync()
6333 if (ext_adv_capable(hdev)) { in set_adv_sync()
6334 hci_start_ext_adv_sync(hdev, 0x00); in set_adv_sync()
6336 hci_update_adv_data_sync(hdev, 0x00); in set_adv_sync()
6337 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_adv_sync()
6338 hci_enable_advertising_sync(hdev); in set_adv_sync()
6341 hci_disable_advertising_sync(hdev); in set_adv_sync()
6347 static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, in set_advertising() argument
6355 bt_dev_dbg(hdev, "sock %p", sk); in set_advertising()
6357 status = mgmt_le_support(hdev); in set_advertising()
6359 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6363 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6366 if (hdev->advertising_paused) in set_advertising()
6367 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6370 hci_dev_lock(hdev); in set_advertising()
6379 if (!hdev_is_powered(hdev) || in set_advertising()
6380 (val == hci_dev_test_flag(hdev, HCI_ADVERTISING) && in set_advertising()
6381 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) || in set_advertising()
6382 hci_dev_test_flag(hdev, HCI_MESH) || in set_advertising()
6383 hci_conn_num(hdev, LE_LINK) > 0 || in set_advertising()
6384 (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_advertising()
6385 hdev->le_scan_type == LE_SCAN_ACTIVE)) { in set_advertising()
6389 hdev->cur_adv_instance = 0x00; in set_advertising()
6390 changed = !hci_dev_test_and_set_flag(hdev, HCI_ADVERTISING); in set_advertising()
6392 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6394 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6396 changed = hci_dev_test_and_clear_flag(hdev, HCI_ADVERTISING); in set_advertising()
6397 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6400 err = send_settings_rsp(sk, MGMT_OP_SET_ADVERTISING, hdev); in set_advertising()
6405 err = new_settings(hdev, sk); in set_advertising()
6410 if (pending_find(MGMT_OP_SET_ADVERTISING, hdev) || in set_advertising()
6411 pending_find(MGMT_OP_SET_LE, hdev)) { in set_advertising()
6412 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6417 cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING, hdev, data, len); in set_advertising()
6421 err = hci_cmd_sync_queue(hdev, set_adv_sync, cmd, in set_advertising()
6428 hci_dev_unlock(hdev); in set_advertising()
6432 static int set_static_address(struct sock *sk, struct hci_dev *hdev, in set_static_address() argument
6438 bt_dev_dbg(hdev, "sock %p", sk); in set_static_address()
6440 if (!lmp_le_capable(hdev)) in set_static_address()
6441 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
6444 if (hdev_is_powered(hdev)) in set_static_address()
6445 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
6450 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
6456 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
6461 hci_dev_lock(hdev); in set_static_address()
6463 bacpy(&hdev->static_addr, &cp->bdaddr); in set_static_address()
6465 err = send_settings_rsp(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev); in set_static_address()
6469 err = new_settings(hdev, sk); in set_static_address()
6472 hci_dev_unlock(hdev); in set_static_address()
6476 static int set_scan_params(struct sock *sk, struct hci_dev *hdev, in set_scan_params() argument
6483 bt_dev_dbg(hdev, "sock %p", sk); in set_scan_params()
6485 if (!lmp_le_capable(hdev)) in set_scan_params()
6486 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6492 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6498 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6502 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6505 hci_dev_lock(hdev); in set_scan_params()
6507 hdev->le_scan_interval = interval; in set_scan_params()
6508 hdev->le_scan_window = window; in set_scan_params()
6510 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, 0, in set_scan_params()
6516 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_scan_params()
6517 hdev->discovery.state == DISCOVERY_STOPPED) in set_scan_params()
6518 hci_update_passive_scan(hdev); in set_scan_params()
6520 hci_dev_unlock(hdev); in set_scan_params()
6525 static void fast_connectable_complete(struct hci_dev *hdev, void *data, int err) in fast_connectable_complete() argument
6529 bt_dev_dbg(hdev, "err %d", err); in fast_connectable_complete()
6532 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in fast_connectable_complete()
6538 hci_dev_set_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
6540 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
6542 send_settings_rsp(cmd->sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in fast_connectable_complete()
6543 new_settings(hdev, cmd->sk); in fast_connectable_complete()
6549 static int write_fast_connectable_sync(struct hci_dev *hdev, void *data) in write_fast_connectable_sync() argument
6554 return hci_write_fast_connectable_sync(hdev, cp->val); in write_fast_connectable_sync()
6557 static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev, in set_fast_connectable() argument
6564 bt_dev_dbg(hdev, "sock %p", sk); in set_fast_connectable()
6566 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in set_fast_connectable()
6567 hdev->hci_ver < BLUETOOTH_VER_1_2) in set_fast_connectable()
6568 return mgmt_cmd_status(sk, hdev->id, in set_fast_connectable()
6573 return mgmt_cmd_status(sk, hdev->id, in set_fast_connectable()
6577 hci_dev_lock(hdev); in set_fast_connectable()
6579 if (!!cp->val == hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) { in set_fast_connectable()
6580 err = send_settings_rsp(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in set_fast_connectable()
6584 if (!hdev_is_powered(hdev)) { in set_fast_connectable()
6585 hci_dev_change_flag(hdev, HCI_FAST_CONNECTABLE); in set_fast_connectable()
6586 err = send_settings_rsp(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in set_fast_connectable()
6587 new_settings(hdev, sk); in set_fast_connectable()
6591 cmd = mgmt_pending_new(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev, data, in set_fast_connectable()
6596 err = hci_cmd_sync_queue(hdev, write_fast_connectable_sync, cmd, in set_fast_connectable()
6600 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
6608 hci_dev_unlock(hdev); in set_fast_connectable()
6613 static void set_bredr_complete(struct hci_dev *hdev, void *data, int err) in set_bredr_complete() argument
6617 bt_dev_dbg(hdev, "err %d", err); in set_bredr_complete()
6625 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in set_bredr_complete()
6629 send_settings_rsp(cmd->sk, MGMT_OP_SET_BREDR, hdev); in set_bredr_complete()
6630 new_settings(hdev, cmd->sk); in set_bredr_complete()
6636 static int set_bredr_sync(struct hci_dev *hdev, void *data) in set_bredr_sync() argument
6640 status = hci_write_fast_connectable_sync(hdev, false); in set_bredr_sync()
6643 status = hci_update_scan_sync(hdev); in set_bredr_sync()
6649 status = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in set_bredr_sync()
6654 static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_bredr() argument
6660 bt_dev_dbg(hdev, "sock %p", sk); in set_bredr()
6662 if (!lmp_bredr_capable(hdev) || !lmp_le_capable(hdev)) in set_bredr()
6663 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6666 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_bredr()
6667 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6671 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6674 hci_dev_lock(hdev); in set_bredr()
6676 if (cp->val == hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_bredr()
6677 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
6681 if (!hdev_is_powered(hdev)) { in set_bredr()
6683 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_bredr()
6684 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_bredr()
6685 hci_dev_clear_flag(hdev, HCI_LINK_SECURITY); in set_bredr()
6686 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in set_bredr()
6689 hci_dev_change_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
6691 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
6695 err = new_settings(hdev, sk); in set_bredr()
6701 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6719 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_bredr()
6720 (bacmp(&hdev->static_addr, BDADDR_ANY) || in set_bredr()
6721 hci_dev_test_flag(hdev, HCI_SC_ENABLED))) { in set_bredr()
6722 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6728 cmd = mgmt_pending_new(sk, MGMT_OP_SET_BREDR, hdev, data, len); in set_bredr()
6732 err = hci_cmd_sync_queue(hdev, set_bredr_sync, cmd, in set_bredr()
6736 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6747 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
6750 hci_dev_unlock(hdev); in set_bredr()
6754 static void set_secure_conn_complete(struct hci_dev *hdev, void *data, int err) in set_secure_conn_complete() argument
6759 bt_dev_dbg(hdev, "err %d", err); in set_secure_conn_complete()
6772 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6773 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6776 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6777 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6780 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6781 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6785 send_settings_rsp(cmd->sk, cmd->opcode, hdev); in set_secure_conn_complete()
6786 new_settings(hdev, cmd->sk); in set_secure_conn_complete()
6792 static int set_secure_conn_sync(struct hci_dev *hdev, void *data) in set_secure_conn_sync() argument
6799 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_sync()
6801 return hci_write_sc_support_sync(hdev, val); in set_secure_conn_sync()
6804 static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, in set_secure_conn() argument
6812 bt_dev_dbg(hdev, "sock %p", sk); in set_secure_conn()
6814 if (!lmp_sc_capable(hdev) && in set_secure_conn()
6815 !hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_secure_conn()
6816 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6819 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_secure_conn()
6820 lmp_sc_capable(hdev) && in set_secure_conn()
6821 !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_secure_conn()
6822 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6826 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6829 hci_dev_lock(hdev); in set_secure_conn()
6831 if (!hdev_is_powered(hdev) || !lmp_sc_capable(hdev) || in set_secure_conn()
6832 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_secure_conn()
6836 changed = !hci_dev_test_and_set_flag(hdev, in set_secure_conn()
6839 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6841 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6843 changed = hci_dev_test_and_clear_flag(hdev, in set_secure_conn()
6845 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6848 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
6853 err = new_settings(hdev, sk); in set_secure_conn()
6860 if (val == hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in set_secure_conn()
6861 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in set_secure_conn()
6862 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
6866 cmd = mgmt_pending_new(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len); in set_secure_conn()
6870 err = hci_cmd_sync_queue(hdev, set_secure_conn_sync, cmd, in set_secure_conn()
6874 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6881 hci_dev_unlock(hdev); in set_secure_conn()
6885 static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, in set_debug_keys() argument
6892 bt_dev_dbg(hdev, "sock %p", sk); in set_debug_keys()
6895 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEBUG_KEYS, in set_debug_keys()
6898 hci_dev_lock(hdev); in set_debug_keys()
6901 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in set_debug_keys()
6903 changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
6907 use_changed = !hci_dev_test_and_set_flag(hdev, in set_debug_keys()
6910 use_changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
6913 if (hdev_is_powered(hdev) && use_changed && in set_debug_keys()
6914 hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_debug_keys()
6916 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in set_debug_keys()
6920 err = send_settings_rsp(sk, MGMT_OP_SET_DEBUG_KEYS, hdev); in set_debug_keys()
6925 err = new_settings(hdev, sk); in set_debug_keys()
6928 hci_dev_unlock(hdev); in set_debug_keys()
6932 static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data, in set_privacy() argument
6939 bt_dev_dbg(hdev, "sock %p", sk); in set_privacy()
6941 if (!lmp_le_capable(hdev)) in set_privacy()
6942 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
6946 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
6949 if (hdev_is_powered(hdev)) in set_privacy()
6950 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
6953 hci_dev_lock(hdev); in set_privacy()
6958 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in set_privacy()
6961 changed = !hci_dev_test_and_set_flag(hdev, HCI_PRIVACY); in set_privacy()
6962 memcpy(hdev->irk, cp->irk, sizeof(hdev->irk)); in set_privacy()
6963 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
6964 hci_adv_instances_set_rpa_expired(hdev, true); in set_privacy()
6966 hci_dev_set_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
6968 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
6970 changed = hci_dev_test_and_clear_flag(hdev, HCI_PRIVACY); in set_privacy()
6971 memset(hdev->irk, 0, sizeof(hdev->irk)); in set_privacy()
6972 hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
6973 hci_adv_instances_set_rpa_expired(hdev, false); in set_privacy()
6974 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
6977 err = send_settings_rsp(sk, MGMT_OP_SET_PRIVACY, hdev); in set_privacy()
6982 err = new_settings(hdev, sk); in set_privacy()
6985 hci_dev_unlock(hdev); in set_privacy()
7005 static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data, in load_irks() argument
7014 bt_dev_dbg(hdev, "sock %p", sk); in load_irks()
7016 if (!lmp_le_capable(hdev)) in load_irks()
7017 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7022 bt_dev_err(hdev, "load_irks: too big irk_count value %u", in load_irks()
7024 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7030 bt_dev_err(hdev, "load_irks: expected %u bytes, got %u bytes", in load_irks()
7032 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7036 bt_dev_dbg(hdev, "irk_count %u", irk_count); in load_irks()
7042 return mgmt_cmd_status(sk, hdev->id, in load_irks()
7047 hci_dev_lock(hdev); in load_irks()
7049 hci_smp_irks_clear(hdev); in load_irks()
7054 if (hci_is_blocked_key(hdev, in load_irks()
7057 bt_dev_warn(hdev, "Skipping blocked IRK for %pMR", in load_irks()
7062 hci_add_irk(hdev, &irk->addr.bdaddr, in load_irks()
7067 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in load_irks()
7069 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_IRKS, 0, NULL, 0); in load_irks()
7071 hci_dev_unlock(hdev); in load_irks()
7095 static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev, in load_long_term_keys() argument
7104 bt_dev_dbg(hdev, "sock %p", sk); in load_long_term_keys()
7106 if (!lmp_le_capable(hdev)) in load_long_term_keys()
7107 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7112 bt_dev_err(hdev, "load_ltks: too big key_count value %u", in load_long_term_keys()
7114 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7120 bt_dev_err(hdev, "load_keys: expected %u bytes, got %u bytes", in load_long_term_keys()
7122 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7126 bt_dev_dbg(hdev, "key_count %u", key_count); in load_long_term_keys()
7128 hci_dev_lock(hdev); in load_long_term_keys()
7130 hci_smp_ltks_clear(hdev); in load_long_term_keys()
7136 if (hci_is_blocked_key(hdev, in load_long_term_keys()
7139 bt_dev_warn(hdev, "Skipping blocked LTK for %pMR", in load_long_term_keys()
7145 bt_dev_warn(hdev, "Invalid LTK for %pMR", in load_long_term_keys()
7175 hci_add_ltk(hdev, &key->addr.bdaddr, in load_long_term_keys()
7180 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 0, in load_long_term_keys()
7183 hci_dev_unlock(hdev); in load_long_term_keys()
7188 static void get_conn_info_complete(struct hci_dev *hdev, void *data, int err) in get_conn_info_complete() argument
7196 bt_dev_dbg(hdev, "err %d", err); in get_conn_info_complete()
7217 static int get_conn_info_sync(struct hci_dev *hdev, void *data) in get_conn_info_sync() argument
7227 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info_sync()
7230 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info_sync()
7239 err = hci_read_rssi_sync(hdev, handle); in get_conn_info_sync()
7246 err = hci_read_tx_power_sync(hdev, handle, 0x00); in get_conn_info_sync()
7250 err = hci_read_tx_power_sync(hdev, handle, 0x01); in get_conn_info_sync()
7255 static int get_conn_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_conn_info() argument
7264 bt_dev_dbg(hdev, "sock %p", sk); in get_conn_info()
7271 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7275 hci_dev_lock(hdev); in get_conn_info()
7277 if (!hdev_is_powered(hdev)) { in get_conn_info()
7278 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7285 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info()
7288 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info()
7291 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7300 conn_info_age = get_random_u32_inclusive(hdev->conn_info_min_age, in get_conn_info()
7301 hdev->conn_info_max_age - 1); in get_conn_info()
7311 cmd = mgmt_pending_new(sk, MGMT_OP_GET_CONN_INFO, hdev, data, in get_conn_info()
7316 err = hci_cmd_sync_queue(hdev, get_conn_info_sync, in get_conn_info()
7321 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7337 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7342 hci_dev_unlock(hdev); in get_conn_info()
7346 static void get_clock_info_complete(struct hci_dev *hdev, void *data, int err) in get_clock_info_complete() argument
7354 bt_dev_dbg(hdev, "err %d", err); in get_clock_info_complete()
7363 rp.local_clock = cpu_to_le32(hdev->clock); in get_clock_info_complete()
7377 static int get_clock_info_sync(struct hci_dev *hdev, void *data) in get_clock_info_sync() argument
7385 hci_read_clock_sync(hdev, &hci_cp); in get_clock_info_sync()
7388 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in get_clock_info_sync()
7396 return hci_read_clock_sync(hdev, &hci_cp); in get_clock_info_sync()
7399 static int get_clock_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_clock_info() argument
7408 bt_dev_dbg(hdev, "sock %p", sk); in get_clock_info()
7415 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7419 hci_dev_lock(hdev); in get_clock_info()
7421 if (!hdev_is_powered(hdev)) { in get_clock_info()
7422 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7429 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_clock_info()
7432 err = mgmt_cmd_complete(sk, hdev->id, in get_clock_info()
7442 cmd = mgmt_pending_new(sk, MGMT_OP_GET_CLOCK_INFO, hdev, data, len); in get_clock_info()
7446 err = hci_cmd_sync_queue(hdev, get_clock_info_sync, cmd, in get_clock_info()
7450 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7459 hci_dev_unlock(hdev); in get_clock_info()
7463 static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type) in is_connected() argument
7467 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, addr); in is_connected()
7481 static int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, in hci_conn_params_set() argument
7486 params = hci_conn_params_add(hdev, addr, addr_type); in hci_conn_params_set()
7502 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7506 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7508 hci_pend_le_list_add(params, &hdev->pend_le_reports); in hci_conn_params_set()
7512 if (!is_connected(hdev, addr, addr_type)) in hci_conn_params_set()
7513 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7519 bt_dev_dbg(hdev, "addr %pMR (type %u) auto_connect %u", in hci_conn_params_set()
7525 static void device_added(struct sock *sk, struct hci_dev *hdev, in device_added() argument
7534 mgmt_event(MGMT_EV_DEVICE_ADDED, hdev, &ev, sizeof(ev), sk); in device_added()
7537 static void add_device_complete(struct hci_dev *hdev, void *data, int err) in add_device_complete() argument
7543 device_added(cmd->sk, hdev, &cp->addr.bdaddr, cp->addr.type, in add_device_complete()
7545 device_flags_changed(NULL, hdev, &cp->addr.bdaddr, in add_device_complete()
7546 cp->addr.type, hdev->conn_flags, in add_device_complete()
7550 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device_complete()
7555 static int add_device_sync(struct hci_dev *hdev, void *data) in add_device_sync() argument
7557 return hci_update_passive_scan_sync(hdev); in add_device_sync()
7560 static int add_device(struct sock *sk, struct hci_dev *hdev, in add_device() argument
7571 bt_dev_dbg(hdev, "sock %p", sk); in add_device()
7575 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7580 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7584 hci_dev_lock(hdev); in add_device()
7589 err = mgmt_cmd_complete(sk, hdev->id, in add_device()
7596 err = hci_bdaddr_list_add_with_flags(&hdev->accept_list, in add_device()
7602 hci_update_scan(hdev); in add_device()
7622 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7631 if (hci_conn_params_set(hdev, &cp->addr.bdaddr, addr_type, in add_device()
7633 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7638 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in add_device()
7644 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_DEVICE, hdev, data, len); in add_device()
7652 err = hci_cmd_sync_queue(hdev, add_device_sync, cmd, in add_device()
7655 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7664 device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action); in add_device()
7665 supported_flags = hdev->conn_flags; in add_device()
7666 device_flags_changed(NULL, hdev, &cp->addr.bdaddr, cp->addr.type, in add_device()
7669 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7674 hci_dev_unlock(hdev); in add_device()
7678 static void device_removed(struct sock *sk, struct hci_dev *hdev, in device_removed() argument
7686 mgmt_event(MGMT_EV_DEVICE_REMOVED, hdev, &ev, sizeof(ev), sk); in device_removed()
7689 static int remove_device_sync(struct hci_dev *hdev, void *data) in remove_device_sync() argument
7691 return hci_update_passive_scan_sync(hdev); in remove_device_sync()
7694 static int remove_device(struct sock *sk, struct hci_dev *hdev, in remove_device() argument
7700 bt_dev_dbg(hdev, "sock %p", sk); in remove_device()
7702 hci_dev_lock(hdev); in remove_device()
7709 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7717 err = hci_bdaddr_list_del(&hdev->accept_list, in remove_device()
7721 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7729 hci_update_scan(hdev); in remove_device()
7731 device_removed(sk, hdev, &cp->addr.bdaddr, in remove_device()
7744 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7751 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in remove_device()
7754 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7763 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7772 device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type); in remove_device()
7778 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7785 list_for_each_entry_safe(b, btmp, &hdev->accept_list, list) { in remove_device()
7786 device_removed(sk, hdev, &b->bdaddr, b->bdaddr_type); in remove_device()
7791 hci_update_scan(hdev); in remove_device()
7793 list_for_each_entry_safe(p, tmp, &hdev->le_conn_params, list) { in remove_device()
7796 device_removed(sk, hdev, &p->addr, p->addr_type); in remove_device()
7804 bt_dev_dbg(hdev, "All LE connection parameters were removed"); in remove_device()
7807 hci_cmd_sync_queue(hdev, remove_device_sync, NULL, NULL); in remove_device()
7810 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, in remove_device()
7814 hci_dev_unlock(hdev); in remove_device()
7818 static int conn_update_sync(struct hci_dev *hdev, void *data) in conn_update_sync() argument
7823 conn = hci_conn_hash_lookup_le(hdev, ¶ms->addr, params->addr_type); in conn_update_sync()
7827 return hci_le_conn_update_sync(hdev, conn, params); in conn_update_sync()
7830 static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data, in load_conn_param() argument
7839 if (!lmp_le_capable(hdev)) in load_conn_param()
7840 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7845 bt_dev_err(hdev, "load_conn_param: too big param_count value %u", in load_conn_param()
7847 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7853 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes", in load_conn_param()
7855 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7859 bt_dev_dbg(hdev, "param_count %u", param_count); in load_conn_param()
7861 hci_dev_lock(hdev); in load_conn_param()
7864 hci_conn_params_clear_disabled(hdev); in load_conn_param()
7873 bt_dev_dbg(hdev, "Adding %pMR (type %u)", ¶m->addr.bdaddr, in load_conn_param()
7881 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
7890 bt_dev_dbg(hdev, "min 0x%04x max 0x%04x latency 0x%04x timeout 0x%04x", in load_conn_param()
7894 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
7902 hci_param = hci_conn_params_lookup(hdev, in load_conn_param()
7908 hci_conn_params_clear_disabled(hdev); in load_conn_param()
7911 hci_param = hci_conn_params_add(hdev, ¶m->addr.bdaddr, in load_conn_param()
7914 bt_dev_err(hdev, "failed to add connection parameters"); in load_conn_param()
7931 conn = hci_conn_hash_lookup_le(hdev, &hci_param->addr, in load_conn_param()
7938 hci_cmd_sync_queue(hdev, conn_update_sync, in load_conn_param()
7943 hci_dev_unlock(hdev); in load_conn_param()
7945 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 0, in load_conn_param()
7949 static int set_external_config(struct sock *sk, struct hci_dev *hdev, in set_external_config() argument
7956 bt_dev_dbg(hdev, "sock %p", sk); in set_external_config()
7958 if (hdev_is_powered(hdev)) in set_external_config()
7959 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7963 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7966 if (!test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in set_external_config()
7967 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7970 hci_dev_lock(hdev); in set_external_config()
7973 changed = !hci_dev_test_and_set_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
7975 changed = hci_dev_test_and_clear_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
7977 err = send_options_rsp(sk, MGMT_OP_SET_EXTERNAL_CONFIG, hdev); in set_external_config()
7984 err = new_options(hdev, sk); in set_external_config()
7986 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) == is_configured(hdev)) { in set_external_config()
7987 mgmt_index_removed(hdev); in set_external_config()
7989 if (hci_dev_test_and_change_flag(hdev, HCI_UNCONFIGURED)) { in set_external_config()
7990 hci_dev_set_flag(hdev, HCI_CONFIG); in set_external_config()
7991 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_external_config()
7993 queue_work(hdev->req_workqueue, &hdev->power_on); in set_external_config()
7995 set_bit(HCI_RAW, &hdev->flags); in set_external_config()
7996 mgmt_index_added(hdev); in set_external_config()
8001 hci_dev_unlock(hdev); in set_external_config()
8005 static int set_public_address(struct sock *sk, struct hci_dev *hdev, in set_public_address() argument
8012 bt_dev_dbg(hdev, "sock %p", sk); in set_public_address()
8014 if (hdev_is_powered(hdev)) in set_public_address()
8015 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8019 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8022 if (!hdev->set_bdaddr) in set_public_address()
8023 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8026 hci_dev_lock(hdev); in set_public_address()
8028 changed = !!bacmp(&hdev->public_addr, &cp->bdaddr); in set_public_address()
8029 bacpy(&hdev->public_addr, &cp->bdaddr); in set_public_address()
8031 err = send_options_rsp(sk, MGMT_OP_SET_PUBLIC_ADDRESS, hdev); in set_public_address()
8038 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in set_public_address()
8039 err = new_options(hdev, sk); in set_public_address()
8041 if (is_configured(hdev)) { in set_public_address()
8042 mgmt_index_removed(hdev); in set_public_address()
8044 hci_dev_clear_flag(hdev, HCI_UNCONFIGURED); in set_public_address()
8046 hci_dev_set_flag(hdev, HCI_CONFIG); in set_public_address()
8047 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_public_address()
8049 queue_work(hdev->req_workqueue, &hdev->power_on); in set_public_address()
8053 hci_dev_unlock(hdev); in set_public_address()
8057 static void read_local_oob_ext_data_complete(struct hci_dev *hdev, void *data, in read_local_oob_ext_data_complete() argument
8069 cmd != pending_find(MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev)) in read_local_oob_ext_data_complete()
8081 bt_dev_dbg(hdev, "status %u", status); in read_local_oob_ext_data_complete()
8093 } else if (!bredr_sc_enabled(hdev)) { in read_local_oob_ext_data_complete()
8119 if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in read_local_oob_ext_data_complete()
8142 hdev->dev_class, 3); in read_local_oob_ext_data_complete()
8162 err = mgmt_cmd_complete(cmd->sk, hdev->id, in read_local_oob_ext_data_complete()
8170 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data_complete()
8181 static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk, in read_local_ssp_oob_req() argument
8187 cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev, in read_local_ssp_oob_req()
8192 err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd, in read_local_ssp_oob_req()
8203 static int read_local_oob_ext_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_ext_data() argument
8213 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_ext_data()
8215 if (hdev_is_powered(hdev)) { in read_local_oob_ext_data()
8218 status = mgmt_bredr_support(hdev); in read_local_oob_ext_data()
8225 status = mgmt_le_support(hdev); in read_local_oob_ext_data()
8246 if (!status && !lmp_ssp_capable(hdev)) { in read_local_oob_ext_data()
8254 hci_dev_lock(hdev); in read_local_oob_ext_data()
8259 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in read_local_oob_ext_data()
8260 err = read_local_ssp_oob_req(hdev, sk, cp); in read_local_oob_ext_data()
8261 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8270 hdev->dev_class, 3); in read_local_oob_ext_data()
8274 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in read_local_oob_ext_data()
8275 smp_generate_oob(hdev, hash, rand) < 0) { in read_local_oob_ext_data()
8276 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8291 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { in read_local_oob_ext_data()
8292 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8297 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in read_local_oob_ext_data()
8298 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in read_local_oob_ext_data()
8299 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in read_local_oob_ext_data()
8300 bacmp(&hdev->static_addr, BDADDR_ANY))) { in read_local_oob_ext_data()
8301 memcpy(addr, &hdev->static_addr, 6); in read_local_oob_ext_data()
8304 memcpy(addr, &hdev->bdaddr, 6); in read_local_oob_ext_data()
8311 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in read_local_oob_ext_data()
8319 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) { in read_local_oob_ext_data()
8329 flags = mgmt_get_adv_discov_flags(hdev); in read_local_oob_ext_data()
8331 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in read_local_oob_ext_data()
8339 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8349 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, in read_local_oob_ext_data()
8354 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data()
8364 static u32 get_supported_adv_flags(struct hci_dev *hdev) in get_supported_adv_flags() argument
8383 if (hdev->adv_tx_power != HCI_TX_POWER_INVALID || ext_adv_capable(hdev)) in get_supported_adv_flags()
8386 if (ext_adv_capable(hdev)) { in get_supported_adv_flags()
8391 if (le_2m_capable(hdev)) in get_supported_adv_flags()
8394 if (le_coded_capable(hdev)) in get_supported_adv_flags()
8401 static int read_adv_features(struct sock *sk, struct hci_dev *hdev, in read_adv_features() argument
8411 bt_dev_dbg(hdev, "sock %p", sk); in read_adv_features()
8413 if (!lmp_le_capable(hdev)) in read_adv_features()
8414 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
8417 hci_dev_lock(hdev); in read_adv_features()
8419 rp_len = sizeof(*rp) + hdev->adv_instance_cnt; in read_adv_features()
8422 hci_dev_unlock(hdev); in read_adv_features()
8426 supported_flags = get_supported_adv_flags(hdev); in read_adv_features()
8429 rp->max_adv_data_len = max_adv_len(hdev); in read_adv_features()
8430 rp->max_scan_rsp_len = max_adv_len(hdev); in read_adv_features()
8431 rp->max_instances = hdev->le_num_of_adv_sets; in read_adv_features()
8432 rp->num_instances = hdev->adv_instance_cnt; in read_adv_features()
8435 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in read_adv_features()
8437 if (adv_instance->instance <= hdev->adv_instance_cnt) { in read_adv_features()
8446 hci_dev_unlock(hdev); in read_adv_features()
8448 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
8456 static u8 calculate_name_len(struct hci_dev *hdev) in calculate_name_len() argument
8460 return eir_append_local_name(hdev, buf, 0); in calculate_name_len()
8463 static u8 tlv_data_max_len(struct hci_dev *hdev, u32 adv_flags, in tlv_data_max_len() argument
8466 u8 max_len = max_adv_len(hdev); in tlv_data_max_len()
8478 max_len -= calculate_name_len(hdev); in tlv_data_max_len()
8509 static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data, in tlv_data_is_valid() argument
8515 max_len = tlv_data_max_len(hdev, adv_flags, is_adv_data); in tlv_data_is_valid()
8554 static bool requested_adv_flags_are_valid(struct hci_dev *hdev, u32 adv_flags) in requested_adv_flags_are_valid() argument
8561 supported_flags = get_supported_adv_flags(hdev); in requested_adv_flags_are_valid()
8570 static bool adv_busy(struct hci_dev *hdev) in adv_busy() argument
8572 return pending_find(MGMT_OP_SET_LE, hdev); in adv_busy()
8575 static void add_adv_complete(struct hci_dev *hdev, struct sock *sk, u8 instance, in add_adv_complete() argument
8580 bt_dev_dbg(hdev, "err %d", err); in add_adv_complete()
8582 hci_dev_lock(hdev); in add_adv_complete()
8584 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in add_adv_complete()
8597 if (hdev->cur_adv_instance == instance) in add_adv_complete()
8598 cancel_adv_timeout(hdev); in add_adv_complete()
8600 hci_remove_adv_instance(hdev, instance); in add_adv_complete()
8601 mgmt_advertising_removed(sk, hdev, instance); in add_adv_complete()
8604 hci_dev_unlock(hdev); in add_adv_complete()
8607 static void add_advertising_complete(struct hci_dev *hdev, void *data, int err) in add_advertising_complete() argument
8624 add_adv_complete(hdev, cmd->sk, cp->instance, err); in add_advertising_complete()
8629 static int add_advertising_sync(struct hci_dev *hdev, void *data) in add_advertising_sync() argument
8634 return hci_schedule_adv_instance_sync(hdev, cp->instance, true); in add_advertising_sync()
8637 static int add_advertising(struct sock *sk, struct hci_dev *hdev, in add_advertising() argument
8651 bt_dev_dbg(hdev, "sock %p", sk); in add_advertising()
8653 status = mgmt_le_support(hdev); in add_advertising()
8655 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8658 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_advertising()
8659 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8663 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8670 if (!requested_adv_flags_are_valid(hdev, flags)) in add_advertising()
8671 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8674 hci_dev_lock(hdev); in add_advertising()
8676 if (timeout && !hdev_is_powered(hdev)) { in add_advertising()
8677 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8682 if (adv_busy(hdev)) { in add_advertising()
8683 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8688 if (!tlv_data_is_valid(hdev, flags, cp->data, cp->adv_data_len, true) || in add_advertising()
8689 !tlv_data_is_valid(hdev, flags, cp->data + cp->adv_data_len, in add_advertising()
8691 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8696 prev_instance_cnt = hdev->adv_instance_cnt; in add_advertising()
8698 adv = hci_add_adv_instance(hdev, cp->instance, flags, in add_advertising()
8704 hdev->le_adv_min_interval, in add_advertising()
8705 hdev->le_adv_max_interval, 0); in add_advertising()
8707 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8715 if (hdev->adv_instance_cnt > prev_instance_cnt) in add_advertising()
8716 mgmt_advertising_added(sk, hdev, cp->instance); in add_advertising()
8718 if (hdev->cur_adv_instance == cp->instance) { in add_advertising()
8724 cancel_adv_timeout(hdev); in add_advertising()
8726 next_instance = hci_get_next_instance(hdev, cp->instance); in add_advertising()
8729 } else if (!hdev->adv_instance_timeout) { in add_advertising()
8740 if (!hdev_is_powered(hdev) || in add_advertising()
8741 hci_dev_test_flag(hdev, HCI_ADVERTISING) || in add_advertising()
8744 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8752 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_ADVERTISING, hdev, data, in add_advertising()
8761 err = hci_cmd_sync_queue(hdev, add_advertising_sync, cmd, in add_advertising()
8767 hci_dev_unlock(hdev); in add_advertising()
8772 static void add_ext_adv_params_complete(struct hci_dev *hdev, void *data, in add_ext_adv_params_complete() argument
8781 BT_DBG("%s", hdev->name); in add_ext_adv_params_complete()
8783 hci_dev_lock(hdev); in add_ext_adv_params_complete()
8785 adv = hci_find_adv_instance(hdev, cp->instance); in add_ext_adv_params_complete()
8796 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in add_ext_adv_params_complete()
8797 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in add_ext_adv_params_complete()
8805 mgmt_advertising_removed(cmd->sk, hdev, cp->instance); in add_ext_adv_params_complete()
8807 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_params_complete()
8819 hci_dev_unlock(hdev); in add_ext_adv_params_complete()
8822 static int add_ext_adv_params_sync(struct hci_dev *hdev, void *data) in add_ext_adv_params_sync() argument
8827 return hci_setup_ext_adv_instance_sync(hdev, cp->instance); in add_ext_adv_params_sync()
8830 static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev, in add_ext_adv_params() argument
8843 BT_DBG("%s", hdev->name); in add_ext_adv_params()
8845 status = mgmt_le_support(hdev); in add_ext_adv_params()
8847 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8850 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_ext_adv_params()
8851 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8861 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8866 if (!requested_adv_flags_are_valid(hdev, flags)) in add_ext_adv_params()
8867 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8870 hci_dev_lock(hdev); in add_ext_adv_params()
8873 if (!hdev_is_powered(hdev)) { in add_ext_adv_params()
8874 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8879 if (adv_busy(hdev)) { in add_ext_adv_params()
8880 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8891 hdev->def_multi_adv_rotation_duration; in add_ext_adv_params()
8895 hdev->le_adv_min_interval; in add_ext_adv_params()
8899 hdev->le_adv_max_interval; in add_ext_adv_params()
8906 adv = hci_add_adv_instance(hdev, cp->instance, flags, 0, NULL, 0, NULL, in add_ext_adv_params()
8911 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8917 if (ext_adv_capable(hdev)) { in add_ext_adv_params()
8918 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_EXT_ADV_PARAMS, hdev, in add_ext_adv_params()
8922 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_params()
8926 err = hci_cmd_sync_queue(hdev, add_ext_adv_params_sync, cmd, in add_ext_adv_params()
8933 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in add_ext_adv_params()
8934 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in add_ext_adv_params()
8935 err = mgmt_cmd_complete(sk, hdev->id, in add_ext_adv_params()
8941 hci_dev_unlock(hdev); in add_ext_adv_params()
8946 static void add_ext_adv_data_complete(struct hci_dev *hdev, void *data, int err) in add_ext_adv_data_complete() argument
8952 add_adv_complete(hdev, cmd->sk, cp->instance, err); in add_ext_adv_data_complete()
8968 static int add_ext_adv_data_sync(struct hci_dev *hdev, void *data) in add_ext_adv_data_sync() argument
8974 if (ext_adv_capable(hdev)) { in add_ext_adv_data_sync()
8975 err = hci_update_adv_data_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8979 err = hci_update_scan_rsp_data_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8983 return hci_enable_ext_advertising_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8986 return hci_schedule_adv_instance_sync(hdev, cp->instance, true); in add_ext_adv_data_sync()
8989 static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data, in add_ext_adv_data() argument
9000 BT_DBG("%s", hdev->name); in add_ext_adv_data()
9002 hci_dev_lock(hdev); in add_ext_adv_data()
9004 adv_instance = hci_find_adv_instance(hdev, cp->instance); in add_ext_adv_data()
9007 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9013 if (!hdev_is_powered(hdev)) { in add_ext_adv_data()
9014 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9019 if (adv_busy(hdev)) { in add_ext_adv_data()
9020 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9026 if (!tlv_data_is_valid(hdev, adv_instance->flags, cp->data, in add_ext_adv_data()
9028 !tlv_data_is_valid(hdev, adv_instance->flags, cp->data + in add_ext_adv_data()
9030 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9036 hci_set_adv_instance_data(hdev, cp->instance, cp->adv_data_len, in add_ext_adv_data()
9041 if (hdev->cur_adv_instance == cp->instance) { in add_ext_adv_data()
9048 cancel_adv_timeout(hdev); in add_ext_adv_data()
9050 next_instance = hci_get_next_instance(hdev, cp->instance); in add_ext_adv_data()
9053 } else if (!hdev->adv_instance_timeout) { in add_ext_adv_data()
9064 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || !schedule_instance) { in add_ext_adv_data()
9066 mgmt_advertising_added(sk, hdev, cp->instance); in add_ext_adv_data()
9070 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9075 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_EXT_ADV_DATA, hdev, data, in add_ext_adv_data()
9082 err = hci_cmd_sync_queue(hdev, add_ext_adv_data_sync, cmd, in add_ext_adv_data()
9095 mgmt_advertising_added(sk, hdev, cp->instance); in add_ext_adv_data()
9100 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_data()
9103 hci_dev_unlock(hdev); in add_ext_adv_data()
9108 static void remove_advertising_complete(struct hci_dev *hdev, void *data, in remove_advertising_complete() argument
9115 bt_dev_dbg(hdev, "err %d", err); in remove_advertising_complete()
9130 static int remove_advertising_sync(struct hci_dev *hdev, void *data) in remove_advertising_sync() argument
9136 err = hci_remove_advertising_sync(hdev, cmd->sk, cp->instance, true); in remove_advertising_sync()
9140 if (list_empty(&hdev->adv_instances)) in remove_advertising_sync()
9141 err = hci_disable_advertising_sync(hdev); in remove_advertising_sync()
9146 static int remove_advertising(struct sock *sk, struct hci_dev *hdev, in remove_advertising() argument
9153 bt_dev_dbg(hdev, "sock %p", sk); in remove_advertising()
9155 hci_dev_lock(hdev); in remove_advertising()
9157 if (cp->instance && !hci_find_adv_instance(hdev, cp->instance)) { in remove_advertising()
9158 err = mgmt_cmd_status(sk, hdev->id, in remove_advertising()
9164 if (pending_find(MGMT_OP_SET_LE, hdev)) { in remove_advertising()
9165 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
9170 if (list_empty(&hdev->adv_instances)) { in remove_advertising()
9171 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
9176 cmd = mgmt_pending_new(sk, MGMT_OP_REMOVE_ADVERTISING, hdev, data, in remove_advertising()
9183 err = hci_cmd_sync_queue(hdev, remove_advertising_sync, cmd, in remove_advertising()
9189 hci_dev_unlock(hdev); in remove_advertising()
9194 static int get_adv_size_info(struct sock *sk, struct hci_dev *hdev, in get_adv_size_info() argument
9201 bt_dev_dbg(hdev, "sock %p", sk); in get_adv_size_info()
9203 if (!lmp_le_capable(hdev)) in get_adv_size_info()
9204 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9207 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in get_adv_size_info()
9208 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9216 supported_flags = get_supported_adv_flags(hdev); in get_adv_size_info()
9218 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9223 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in get_adv_size_info()
9224 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in get_adv_size_info()
9226 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9365 void mgmt_index_added(struct hci_dev *hdev) in mgmt_index_added() argument
9369 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_added()
9372 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_added()
9373 mgmt_index_event(MGMT_EV_UNCONF_INDEX_ADDED, hdev, NULL, 0, in mgmt_index_added()
9377 mgmt_index_event(MGMT_EV_INDEX_ADDED, hdev, NULL, 0, in mgmt_index_added()
9382 ev.bus = hdev->bus; in mgmt_index_added()
9384 mgmt_index_event(MGMT_EV_EXT_INDEX_ADDED, hdev, &ev, sizeof(ev), in mgmt_index_added()
9388 void mgmt_index_removed(struct hci_dev *hdev) in mgmt_index_removed() argument
9391 struct cmd_lookup match = { NULL, hdev, MGMT_STATUS_INVALID_INDEX }; in mgmt_index_removed()
9393 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_removed()
9396 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &match); in mgmt_index_removed()
9398 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_removed()
9399 mgmt_index_event(MGMT_EV_UNCONF_INDEX_REMOVED, hdev, NULL, 0, in mgmt_index_removed()
9403 mgmt_index_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, in mgmt_index_removed()
9408 ev.bus = hdev->bus; in mgmt_index_removed()
9410 mgmt_index_event(MGMT_EV_EXT_INDEX_REMOVED, hdev, &ev, sizeof(ev), in mgmt_index_removed()
9414 if (!hci_dev_test_flag(hdev, HCI_MGMT)) in mgmt_index_removed()
9416 cancel_delayed_work_sync(&hdev->discov_off); in mgmt_index_removed()
9417 cancel_delayed_work_sync(&hdev->service_cache); in mgmt_index_removed()
9418 cancel_delayed_work_sync(&hdev->rpa_expired); in mgmt_index_removed()
9421 void mgmt_power_on(struct hci_dev *hdev, int err) in mgmt_power_on() argument
9423 struct cmd_lookup match = { NULL, hdev }; in mgmt_power_on()
9425 bt_dev_dbg(hdev, "err %d", err); in mgmt_power_on()
9427 hci_dev_lock(hdev); in mgmt_power_on()
9430 restart_le_actions(hdev); in mgmt_power_on()
9431 hci_update_passive_scan(hdev); in mgmt_power_on()
9434 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in mgmt_power_on()
9436 new_settings(hdev, match.sk); in mgmt_power_on()
9441 hci_dev_unlock(hdev); in mgmt_power_on()
9444 void __mgmt_power_off(struct hci_dev *hdev) in __mgmt_power_off() argument
9446 struct cmd_lookup match = { NULL, hdev }; in __mgmt_power_off()
9449 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in __mgmt_power_off()
9458 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) in __mgmt_power_off()
9463 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &match); in __mgmt_power_off()
9465 if (memcmp(hdev->dev_class, zero_cod, sizeof(zero_cod)) != 0) { in __mgmt_power_off()
9466 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, in __mgmt_power_off()
9469 ext_info_changed(hdev, NULL); in __mgmt_power_off()
9472 new_settings(hdev, match.sk); in __mgmt_power_off()
9478 void mgmt_set_powered_failed(struct hci_dev *hdev, int err) in mgmt_set_powered_failed() argument
9483 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_set_powered_failed()
9492 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, status); in mgmt_set_powered_failed()
9497 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, in mgmt_new_link_key() argument
9511 mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_link_key()
9533 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent) in mgmt_new_ltk() argument
9573 mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_ltk()
9576 void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent) in mgmt_new_irk() argument
9589 mgmt_event(MGMT_EV_NEW_IRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_irk()
9592 void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, in mgmt_new_csrk() argument
9619 mgmt_event(MGMT_EV_NEW_CSRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_csrk()
9622 void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_new_conn_param() argument
9640 mgmt_event(MGMT_EV_NEW_CONN_PARAM, hdev, &ev, sizeof(ev), NULL); in mgmt_new_conn_param()
9643 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, in mgmt_device_connected() argument
9656 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, in mgmt_device_connected()
9659 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, in mgmt_device_connected()
9698 struct hci_dev *hdev = data; in unpair_device_rsp() local
9701 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_rsp()
9707 bool mgmt_powering_down(struct hci_dev *hdev) in mgmt_powering_down() argument
9712 if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) in mgmt_powering_down()
9715 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_powering_down()
9726 void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_device_disconnected() argument
9744 if (hdev->suspended) in mgmt_device_disconnected()
9747 mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev), sk); in mgmt_device_disconnected()
9753 void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_disconnect_failed() argument
9760 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_disconnect_failed()
9761 hdev); in mgmt_disconnect_failed()
9763 cmd = pending_find(MGMT_OP_DISCONNECT, hdev); in mgmt_disconnect_failed()
9779 void mgmt_connect_failed(struct hci_dev *hdev, struct hci_conn *conn, u8 status) in mgmt_connect_failed() argument
9784 mgmt_device_disconnected(hdev, &conn->dst, conn->type, in mgmt_connect_failed()
9793 mgmt_event(MGMT_EV_CONNECT_FAILED, hdev, &ev, sizeof(ev), NULL); in mgmt_connect_failed()
9796 void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure) in mgmt_pin_code_request() argument
9804 mgmt_event(MGMT_EV_PIN_CODE_REQUEST, hdev, &ev, sizeof(ev), NULL); in mgmt_pin_code_request()
9807 void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_reply_complete() argument
9812 cmd = pending_find(MGMT_OP_PIN_CODE_REPLY, hdev); in mgmt_pin_code_reply_complete()
9820 void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_neg_reply_complete() argument
9825 cmd = pending_find(MGMT_OP_PIN_CODE_NEG_REPLY, hdev); in mgmt_pin_code_neg_reply_complete()
9833 int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_request() argument
9839 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_confirm_request()
9846 return mgmt_event(MGMT_EV_USER_CONFIRM_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_confirm_request()
9850 int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_request() argument
9855 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_request()
9860 return mgmt_event(MGMT_EV_USER_PASSKEY_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_passkey_request()
9864 static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in user_pairing_resp_complete() argument
9870 cmd = pending_find(opcode, hdev); in user_pairing_resp_complete()
9880 int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_reply_complete() argument
9883 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_reply_complete()
9887 int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_neg_reply_complete() argument
9890 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_neg_reply_complete()
9895 int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_reply_complete() argument
9898 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_reply_complete()
9902 int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_neg_reply_complete() argument
9905 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_neg_reply_complete()
9910 int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_notify() argument
9916 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_notify()
9923 return mgmt_event(MGMT_EV_PASSKEY_NOTIFY, hdev, &ev, sizeof(ev), NULL); in mgmt_user_passkey_notify()
9938 mgmt_event(MGMT_EV_AUTH_FAILED, conn->hdev, &ev, sizeof(ev), in mgmt_auth_failed()
9947 void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status) in mgmt_auth_enable_complete() argument
9949 struct cmd_lookup match = { NULL, hdev }; in mgmt_auth_enable_complete()
9954 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, in mgmt_auth_enable_complete()
9959 if (test_bit(HCI_AUTH, &hdev->flags)) in mgmt_auth_enable_complete()
9960 changed = !hci_dev_test_and_set_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
9962 changed = hci_dev_test_and_clear_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
9964 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, settings_rsp, in mgmt_auth_enable_complete()
9968 new_settings(hdev, match.sk); in mgmt_auth_enable_complete()
9984 void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, in mgmt_set_class_of_dev_complete() argument
9987 struct cmd_lookup match = { NULL, hdev, mgmt_status(status) }; in mgmt_set_class_of_dev_complete()
9989 mgmt_pending_foreach(MGMT_OP_SET_DEV_CLASS, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
9990 mgmt_pending_foreach(MGMT_OP_ADD_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
9991 mgmt_pending_foreach(MGMT_OP_REMOVE_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
9994 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, dev_class, in mgmt_set_class_of_dev_complete()
9996 ext_info_changed(hdev, NULL); in mgmt_set_class_of_dev_complete()
10003 void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status) in mgmt_set_local_name_complete() argument
10013 memcpy(ev.short_name, hdev->short_name, HCI_MAX_SHORT_NAME_LENGTH); in mgmt_set_local_name_complete()
10015 cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev); in mgmt_set_local_name_complete()
10017 memcpy(hdev->dev_name, name, sizeof(hdev->dev_name)); in mgmt_set_local_name_complete()
10022 if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) in mgmt_set_local_name_complete()
10025 if (pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_local_name_complete()
10029 mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev, sizeof(ev), in mgmt_set_local_name_complete()
10031 ext_info_changed(hdev, cmd ? cmd->sk : NULL); in mgmt_set_local_name_complete()
10101 static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir, in is_filter_match() argument
10113 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
10115 (rssi < hdev->discovery.rssi && in is_filter_match()
10116 !test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)))) in is_filter_match()
10119 if (hdev->discovery.uuid_count != 0) { in is_filter_match()
10123 if (!eir_has_uuids(eir, eir_len, hdev->discovery.uuid_count, in is_filter_match()
10124 hdev->discovery.uuids) && in is_filter_match()
10126 hdev->discovery.uuid_count, in is_filter_match()
10127 hdev->discovery.uuids)) in is_filter_match()
10134 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)) { in is_filter_match()
10136 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
10137 rssi < hdev->discovery.rssi) in is_filter_match()
10144 void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle, in mgmt_adv_monitor_device_lost() argument
10153 mgmt_event(MGMT_EV_ADV_MONITOR_DEVICE_LOST, hdev, &ev, sizeof(ev), in mgmt_adv_monitor_device_lost()
10157 static void mgmt_send_adv_monitor_device_found(struct hci_dev *hdev, in mgmt_send_adv_monitor_device_found() argument
10171 advmon_skb = mgmt_alloc_skb(hdev, MGMT_EV_ADV_MONITOR_DEVICE_FOUND, in mgmt_send_adv_monitor_device_found()
10187 static void mgmt_adv_monitor_device_found(struct hci_dev *hdev, in mgmt_adv_monitor_device_found() argument
10211 if (report_device && !hdev->advmon_pend_notify) { in mgmt_adv_monitor_device_found()
10216 hdev->advmon_pend_notify = false; in mgmt_adv_monitor_device_found()
10218 list_for_each_entry_safe(dev, tmp, &hdev->monitored_devices, list) { in mgmt_adv_monitor_device_found()
10223 mgmt_send_adv_monitor_device_found(hdev, skb, in mgmt_adv_monitor_device_found()
10232 hdev->advmon_pend_notify = true; in mgmt_adv_monitor_device_found()
10236 ((matched && !notified) || !msft_monitor_supported(hdev))) { in mgmt_adv_monitor_device_found()
10242 mgmt_send_adv_monitor_device_found(hdev, skb, skip_sk, 0); in mgmt_adv_monitor_device_found()
10251 static void mesh_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, in mesh_device_found() argument
10260 if (!hdev->mesh_ad_types[0]) in mesh_device_found()
10266 for (j = 0; j < sizeof(hdev->mesh_ad_types); j++) { in mesh_device_found()
10267 if (!hdev->mesh_ad_types[j]) in mesh_device_found()
10270 if (hdev->mesh_ad_types[j] == eir[i + 1]) in mesh_device_found()
10278 for (j = 0; j < sizeof(hdev->mesh_ad_types); j++) { in mesh_device_found()
10279 if (!hdev->mesh_ad_types[j]) in mesh_device_found()
10282 if (hdev->mesh_ad_types[j] == scan_rsp[i + 1]) in mesh_device_found()
10291 skb = mgmt_alloc_skb(hdev, MGMT_EV_MESH_DEVICE_FOUND, in mesh_device_found()
10317 void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_device_found() argument
10324 bool report_device = hci_discovery_active(hdev); in mgmt_device_found()
10326 if (hci_dev_test_flag(hdev, HCI_MESH) && link_type == LE_LINK) in mgmt_device_found()
10327 mesh_device_found(hdev, bdaddr, addr_type, rssi, flags, in mgmt_device_found()
10335 if (!hci_discovery_active(hdev)) { in mgmt_device_found()
10338 if (link_type == LE_LINK && !list_empty(&hdev->pend_le_reports)) in mgmt_device_found()
10340 else if (!hci_is_adv_monitoring(hdev)) in mgmt_device_found()
10344 if (hdev->discovery.result_filtering) { in mgmt_device_found()
10346 if (!is_filter_match(hdev, rssi, eir, eir_len, scan_rsp, in mgmt_device_found()
10351 if (hdev->discovery.limited) { in mgmt_device_found()
10364 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, in mgmt_device_found()
10379 if (rssi == HCI_RSSI_INVALID && !hdev->discovery.report_invalid_rssi && in mgmt_device_found()
10406 mgmt_adv_monitor_device_found(hdev, bdaddr, report_device, skb, NULL); in mgmt_device_found()
10409 void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_remote_name() argument
10417 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, in mgmt_remote_name()
10438 void mgmt_discovering(struct hci_dev *hdev, u8 discovering) in mgmt_discovering() argument
10442 bt_dev_dbg(hdev, "discovering %u", discovering); in mgmt_discovering()
10445 ev.type = hdev->discovery.type; in mgmt_discovering()
10448 mgmt_event(MGMT_EV_DISCOVERING, hdev, &ev, sizeof(ev), NULL); in mgmt_discovering()
10451 void mgmt_suspending(struct hci_dev *hdev, u8 state) in mgmt_suspending() argument
10456 mgmt_event(MGMT_EV_CONTROLLER_SUSPEND, hdev, &ev, sizeof(ev), NULL); in mgmt_suspending()
10459 void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr, in mgmt_resuming() argument
10472 mgmt_event(MGMT_EV_CONTROLLER_RESUME, hdev, &ev, sizeof(ev), NULL); in mgmt_resuming()
10495 struct hci_dev *hdev; in mgmt_cleanup() local
10499 list_for_each_entry(hdev, &hci_dev_list, list) { in mgmt_cleanup()
10501 mesh_tx = mgmt_mesh_next(hdev, sk); in mgmt_cleanup()
10504 mesh_send_complete(hdev, mesh_tx, true); in mgmt_cleanup()