Lines Matching refs:hdev
323 static int mgmt_index_event(u16 event, struct hci_dev *hdev, void *data, in mgmt_index_event() argument
326 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_index_event()
330 static int mgmt_limited_event(u16 event, struct hci_dev *hdev, void *data, in mgmt_limited_event() argument
333 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_limited_event()
337 static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, u16 len, in mgmt_event() argument
340 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_event()
366 static int read_version(struct sock *sk, struct hci_dev *hdev, void *data, in read_version() argument
371 bt_dev_dbg(hdev, "sock %p", sk); in read_version()
379 static int read_commands(struct sock *sk, struct hci_dev *hdev, void *data, in read_commands() argument
387 bt_dev_dbg(hdev, "sock %p", sk); in read_commands()
431 static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data, in read_index_list() argument
440 bt_dev_dbg(hdev, "sock %p", sk); in read_index_list()
474 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_index_list()
491 static int read_unconf_index_list(struct sock *sk, struct hci_dev *hdev, in read_unconf_index_list() argument
500 bt_dev_dbg(hdev, "sock %p", sk); in read_unconf_index_list()
534 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_unconf_index_list()
551 static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev, in read_ext_index_list() argument
559 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_index_list()
601 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_ext_index_list()
625 static bool is_configured(struct hci_dev *hdev) in is_configured() argument
627 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in is_configured()
628 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in is_configured()
631 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in is_configured()
632 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in is_configured()
633 !bacmp(&hdev->public_addr, BDADDR_ANY)) in is_configured()
639 static __le32 get_missing_options(struct hci_dev *hdev) in get_missing_options() argument
643 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in get_missing_options()
644 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in get_missing_options()
647 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in get_missing_options()
648 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in get_missing_options()
649 !bacmp(&hdev->public_addr, BDADDR_ANY)) in get_missing_options()
655 static int new_options(struct hci_dev *hdev, struct sock *skip) in new_options() argument
657 __le32 options = get_missing_options(hdev); in new_options()
659 return mgmt_limited_event(MGMT_EV_NEW_CONFIG_OPTIONS, hdev, &options, in new_options()
663 static int send_options_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_options_rsp() argument
665 __le32 options = get_missing_options(hdev); in send_options_rsp()
667 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &options, in send_options_rsp()
671 static int read_config_info(struct sock *sk, struct hci_dev *hdev, in read_config_info() argument
677 bt_dev_dbg(hdev, "sock %p", sk); in read_config_info()
679 hci_dev_lock(hdev); in read_config_info()
682 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_config_info()
684 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in read_config_info()
687 if (hdev->set_bdaddr) in read_config_info()
691 rp.missing_options = get_missing_options(hdev); in read_config_info()
693 hci_dev_unlock(hdev); in read_config_info()
695 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONFIG_INFO, 0, in read_config_info()
699 static u32 get_supported_phys(struct hci_dev *hdev) in get_supported_phys() argument
703 if (lmp_bredr_capable(hdev)) { in get_supported_phys()
706 if (hdev->features[0][0] & LMP_3SLOT) in get_supported_phys()
709 if (hdev->features[0][0] & LMP_5SLOT) in get_supported_phys()
712 if (lmp_edr_2m_capable(hdev)) { in get_supported_phys()
715 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
718 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
721 if (lmp_edr_3m_capable(hdev)) { in get_supported_phys()
724 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
727 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
733 if (lmp_le_capable(hdev)) { in get_supported_phys()
737 if (hdev->le_features[1] & HCI_LE_PHY_2M) { in get_supported_phys()
742 if (hdev->le_features[1] & HCI_LE_PHY_CODED) { in get_supported_phys()
751 static u32 get_selected_phys(struct hci_dev *hdev) in get_selected_phys() argument
755 if (lmp_bredr_capable(hdev)) { in get_selected_phys()
758 if (hdev->pkt_type & (HCI_DM3 | HCI_DH3)) in get_selected_phys()
761 if (hdev->pkt_type & (HCI_DM5 | HCI_DH5)) in get_selected_phys()
764 if (lmp_edr_2m_capable(hdev)) { in get_selected_phys()
765 if (!(hdev->pkt_type & HCI_2DH1)) in get_selected_phys()
768 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
769 !(hdev->pkt_type & HCI_2DH3)) in get_selected_phys()
772 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
773 !(hdev->pkt_type & HCI_2DH5)) in get_selected_phys()
776 if (lmp_edr_3m_capable(hdev)) { in get_selected_phys()
777 if (!(hdev->pkt_type & HCI_3DH1)) in get_selected_phys()
780 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
781 !(hdev->pkt_type & HCI_3DH3)) in get_selected_phys()
784 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
785 !(hdev->pkt_type & HCI_3DH5)) in get_selected_phys()
791 if (lmp_le_capable(hdev)) { in get_selected_phys()
792 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
795 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
798 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
801 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
804 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
807 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
814 static u32 get_configurable_phys(struct hci_dev *hdev) in get_configurable_phys() argument
816 return (get_supported_phys(hdev) & ~MGMT_PHY_BR_1M_1SLOT & in get_configurable_phys()
820 static u32 get_supported_settings(struct hci_dev *hdev) in get_supported_settings() argument
830 if (lmp_bredr_capable(hdev)) { in get_supported_settings()
831 if (hdev->hci_ver >= BLUETOOTH_VER_1_2) in get_supported_settings()
836 if (lmp_ssp_capable(hdev)) { in get_supported_settings()
842 if (lmp_sc_capable(hdev)) in get_supported_settings()
846 &hdev->quirks)) in get_supported_settings()
850 if (lmp_le_capable(hdev)) { in get_supported_settings()
858 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in get_supported_settings()
859 hdev->set_bdaddr) in get_supported_settings()
862 if (cis_central_capable(hdev)) in get_supported_settings()
865 if (cis_peripheral_capable(hdev)) in get_supported_settings()
873 static u32 get_current_settings(struct hci_dev *hdev) in get_current_settings() argument
877 if (hdev_is_powered(hdev)) in get_current_settings()
880 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in get_current_settings()
883 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in get_current_settings()
886 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in get_current_settings()
889 if (hci_dev_test_flag(hdev, HCI_BONDABLE)) in get_current_settings()
892 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in get_current_settings()
895 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in get_current_settings()
898 if (hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) in get_current_settings()
901 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in get_current_settings()
904 if (hci_dev_test_flag(hdev, HCI_HS_ENABLED)) in get_current_settings()
907 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in get_current_settings()
910 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) in get_current_settings()
913 if (hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) in get_current_settings()
916 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in get_current_settings()
931 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in get_current_settings()
932 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in get_current_settings()
933 !bacmp(&hdev->bdaddr, BDADDR_ANY)) { in get_current_settings()
934 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in get_current_settings()
938 if (hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED)) in get_current_settings()
941 if (cis_central_capable(hdev)) in get_current_settings()
944 if (cis_peripheral_capable(hdev)) in get_current_settings()
947 if (bis_capable(hdev)) in get_current_settings()
950 if (sync_recv_capable(hdev)) in get_current_settings()
956 static struct mgmt_pending_cmd *pending_find(u16 opcode, struct hci_dev *hdev) in pending_find() argument
958 return mgmt_pending_find(HCI_CHANNEL_CONTROL, opcode, hdev); in pending_find()
961 u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev) in mgmt_get_adv_discov_flags() argument
968 cmd = pending_find(MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_get_adv_discov_flags()
976 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
978 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
985 bool mgmt_get_connectable(struct hci_dev *hdev) in mgmt_get_connectable() argument
992 cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_get_connectable()
999 return hci_dev_test_flag(hdev, HCI_CONNECTABLE); in mgmt_get_connectable()
1002 static int service_cache_sync(struct hci_dev *hdev, void *data) in service_cache_sync() argument
1004 hci_update_eir_sync(hdev); in service_cache_sync()
1005 hci_update_class_sync(hdev); in service_cache_sync()
1012 struct hci_dev *hdev = container_of(work, struct hci_dev, in service_cache_off() local
1015 if (!hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in service_cache_off()
1018 hci_cmd_sync_queue(hdev, service_cache_sync, NULL, NULL); in service_cache_off()
1021 static int rpa_expired_sync(struct hci_dev *hdev, void *data) in rpa_expired_sync() argument
1027 if (ext_adv_capable(hdev)) in rpa_expired_sync()
1028 return hci_start_ext_adv_sync(hdev, hdev->cur_adv_instance); in rpa_expired_sync()
1030 return hci_enable_advertising_sync(hdev); in rpa_expired_sync()
1035 struct hci_dev *hdev = container_of(work, struct hci_dev, in rpa_expired() local
1038 bt_dev_dbg(hdev, ""); in rpa_expired()
1040 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in rpa_expired()
1042 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING)) in rpa_expired()
1045 hci_cmd_sync_queue(hdev, rpa_expired_sync, NULL, NULL); in rpa_expired()
1050 struct hci_dev *hdev = container_of(work, struct hci_dev, in discov_off() local
1053 bt_dev_dbg(hdev, ""); in discov_off()
1055 hci_dev_lock(hdev); in discov_off()
1062 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in discov_off()
1063 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in discov_off()
1064 hdev->discov_timeout = 0; in discov_off()
1066 hci_update_discoverable(hdev); in discov_off()
1068 mgmt_new_settings(hdev); in discov_off()
1070 hci_dev_unlock(hdev); in discov_off()
1073 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev);
1075 static void mesh_send_complete(struct hci_dev *hdev, in mesh_send_complete() argument
1081 mgmt_event(MGMT_EV_MESH_PACKET_CMPLT, hdev, &handle, in mesh_send_complete()
1087 static int mesh_send_done_sync(struct hci_dev *hdev, void *data) in mesh_send_done_sync() argument
1091 hci_dev_clear_flag(hdev, HCI_MESH_SENDING); in mesh_send_done_sync()
1092 hci_disable_advertising_sync(hdev); in mesh_send_done_sync()
1093 mesh_tx = mgmt_mesh_next(hdev, NULL); in mesh_send_done_sync()
1096 mesh_send_complete(hdev, mesh_tx, false); in mesh_send_done_sync()
1101 static int mesh_send_sync(struct hci_dev *hdev, void *data);
1102 static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err);
1103 static void mesh_next(struct hci_dev *hdev, void *data, int err) in mesh_next() argument
1105 struct mgmt_mesh_tx *mesh_tx = mgmt_mesh_next(hdev, NULL); in mesh_next()
1110 err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx, in mesh_next()
1114 mesh_send_complete(hdev, mesh_tx, false); in mesh_next()
1116 hci_dev_set_flag(hdev, HCI_MESH_SENDING); in mesh_next()
1121 struct hci_dev *hdev = container_of(work, struct hci_dev, in mesh_send_done() local
1124 if (!hci_dev_test_flag(hdev, HCI_MESH_SENDING)) in mesh_send_done()
1127 hci_cmd_sync_queue(hdev, mesh_send_done_sync, NULL, mesh_next); in mesh_send_done()
1130 static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev) in mgmt_init_hdev() argument
1132 if (hci_dev_test_flag(hdev, HCI_MGMT)) in mgmt_init_hdev()
1137 INIT_DELAYED_WORK(&hdev->discov_off, discov_off); in mgmt_init_hdev()
1138 INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off); in mgmt_init_hdev()
1139 INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired); in mgmt_init_hdev()
1140 INIT_DELAYED_WORK(&hdev->mesh_send_done, mesh_send_done); in mgmt_init_hdev()
1147 hci_dev_clear_flag(hdev, HCI_BONDABLE); in mgmt_init_hdev()
1149 hci_dev_set_flag(hdev, HCI_MGMT); in mgmt_init_hdev()
1152 static int read_controller_info(struct sock *sk, struct hci_dev *hdev, in read_controller_info() argument
1157 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_info()
1159 hci_dev_lock(hdev); in read_controller_info()
1163 bacpy(&rp.bdaddr, &hdev->bdaddr); in read_controller_info()
1165 rp.version = hdev->hci_ver; in read_controller_info()
1166 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_controller_info()
1168 rp.supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_controller_info()
1169 rp.current_settings = cpu_to_le32(get_current_settings(hdev)); in read_controller_info()
1171 memcpy(rp.dev_class, hdev->dev_class, 3); in read_controller_info()
1173 memcpy(rp.name, hdev->dev_name, sizeof(hdev->dev_name)); in read_controller_info()
1174 memcpy(rp.short_name, hdev->short_name, sizeof(hdev->short_name)); in read_controller_info()
1176 hci_dev_unlock(hdev); in read_controller_info()
1178 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_INFO, 0, &rp, in read_controller_info()
1182 static u16 append_eir_data_to_buf(struct hci_dev *hdev, u8 *eir) in append_eir_data_to_buf() argument
1187 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in append_eir_data_to_buf()
1189 hdev->dev_class, 3); in append_eir_data_to_buf()
1191 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in append_eir_data_to_buf()
1193 hdev->appearance); in append_eir_data_to_buf()
1195 name_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name)); in append_eir_data_to_buf()
1197 hdev->dev_name, name_len); in append_eir_data_to_buf()
1199 name_len = strnlen(hdev->short_name, sizeof(hdev->short_name)); in append_eir_data_to_buf()
1201 hdev->short_name, name_len); in append_eir_data_to_buf()
1206 static int read_ext_controller_info(struct sock *sk, struct hci_dev *hdev, in read_ext_controller_info() argument
1213 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_controller_info()
1217 hci_dev_lock(hdev); in read_ext_controller_info()
1219 bacpy(&rp->bdaddr, &hdev->bdaddr); in read_ext_controller_info()
1221 rp->version = hdev->hci_ver; in read_ext_controller_info()
1222 rp->manufacturer = cpu_to_le16(hdev->manufacturer); in read_ext_controller_info()
1224 rp->supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_ext_controller_info()
1225 rp->current_settings = cpu_to_le32(get_current_settings(hdev)); in read_ext_controller_info()
1228 eir_len = append_eir_data_to_buf(hdev, rp->eir); in read_ext_controller_info()
1231 hci_dev_unlock(hdev); in read_ext_controller_info()
1242 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_EXT_INFO, 0, rp, in read_ext_controller_info()
1246 static int ext_info_changed(struct hci_dev *hdev, struct sock *skip) in ext_info_changed() argument
1254 eir_len = append_eir_data_to_buf(hdev, ev->eir); in ext_info_changed()
1257 return mgmt_limited_event(MGMT_EV_EXT_INFO_CHANGED, hdev, ev, in ext_info_changed()
1262 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_settings_rsp() argument
1264 __le32 settings = cpu_to_le32(get_current_settings(hdev)); in send_settings_rsp()
1266 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &settings, in send_settings_rsp()
1270 void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev, u8 instance) in mgmt_advertising_added() argument
1276 mgmt_event(MGMT_EV_ADVERTISING_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_added()
1279 void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev, in mgmt_advertising_removed() argument
1286 mgmt_event(MGMT_EV_ADVERTISING_REMOVED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_removed()
1289 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
1291 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
1292 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
1293 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
1298 static void restart_le_actions(struct hci_dev *hdev) in restart_le_actions() argument
1302 list_for_each_entry(p, &hdev->le_conn_params, list) { in restart_le_actions()
1311 hci_pend_le_list_add(p, &hdev->pend_le_conns); in restart_le_actions()
1314 hci_pend_le_list_add(p, &hdev->pend_le_reports); in restart_le_actions()
1322 static int new_settings(struct hci_dev *hdev, struct sock *skip) in new_settings() argument
1324 __le32 ev = cpu_to_le32(get_current_settings(hdev)); in new_settings()
1326 return mgmt_limited_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, in new_settings()
1330 static void mgmt_set_powered_complete(struct hci_dev *hdev, void *data, int err) in mgmt_set_powered_complete() argument
1336 if (cmd != pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_powered_complete()
1341 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_powered_complete()
1345 hci_dev_lock(hdev); in mgmt_set_powered_complete()
1346 restart_le_actions(hdev); in mgmt_set_powered_complete()
1347 hci_update_passive_scan(hdev); in mgmt_set_powered_complete()
1348 hci_dev_unlock(hdev); in mgmt_set_powered_complete()
1351 send_settings_rsp(cmd->sk, cmd->opcode, hdev); in mgmt_set_powered_complete()
1357 new_settings(hdev, cmd->sk); in mgmt_set_powered_complete()
1359 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, in mgmt_set_powered_complete()
1366 static int set_powered_sync(struct hci_dev *hdev, void *data) in set_powered_sync() argument
1371 BT_DBG("%s", hdev->name); in set_powered_sync()
1373 return hci_set_powered_sync(hdev, cp->val); in set_powered_sync()
1376 static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, in set_powered() argument
1383 bt_dev_dbg(hdev, "sock %p", sk); in set_powered()
1386 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1389 hci_dev_lock(hdev); 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(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()
1488 static u8 mgmt_bredr_support(struct hci_dev *hdev) in mgmt_bredr_support() argument
1490 if (!lmp_bredr_capable(hdev)) in mgmt_bredr_support()
1492 else if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in mgmt_bredr_support()
1498 static u8 mgmt_le_support(struct hci_dev *hdev) in mgmt_le_support() argument
1500 if (!lmp_le_capable(hdev)) in mgmt_le_support()
1502 else if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mgmt_le_support()
1508 static void mgmt_set_discoverable_complete(struct hci_dev *hdev, void *data, in mgmt_set_discoverable_complete() argument
1513 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_discoverable_complete()
1516 if (cmd != pending_find(MGMT_OP_SET_DISCOVERABLE, hdev)) in mgmt_set_discoverable_complete()
1519 hci_dev_lock(hdev); in mgmt_set_discoverable_complete()
1524 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in mgmt_set_discoverable_complete()
1528 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in mgmt_set_discoverable_complete()
1529 hdev->discov_timeout > 0) { in mgmt_set_discoverable_complete()
1530 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in mgmt_set_discoverable_complete()
1531 queue_delayed_work(hdev->req_workqueue, &hdev->discov_off, to); in mgmt_set_discoverable_complete()
1534 send_settings_rsp(cmd->sk, MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_set_discoverable_complete()
1535 new_settings(hdev, cmd->sk); in mgmt_set_discoverable_complete()
1539 hci_dev_unlock(hdev); in mgmt_set_discoverable_complete()
1542 static int set_discoverable_sync(struct hci_dev *hdev, void *data) in set_discoverable_sync() argument
1544 BT_DBG("%s", hdev->name); in set_discoverable_sync()
1546 return hci_update_discoverable_sync(hdev); in set_discoverable_sync()
1549 static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, in set_discoverable() argument
1557 bt_dev_dbg(hdev, "sock %p", sk); in set_discoverable()
1559 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_discoverable()
1560 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_discoverable()
1561 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1565 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1575 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1578 hci_dev_lock(hdev); in set_discoverable()
1580 if (!hdev_is_powered(hdev) && timeout > 0) { in set_discoverable()
1581 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1586 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_discoverable()
1587 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_discoverable()
1588 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1593 if (!hci_dev_test_flag(hdev, HCI_CONNECTABLE)) { in set_discoverable()
1594 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1599 if (hdev->advertising_paused) { in set_discoverable()
1600 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1605 if (!hdev_is_powered(hdev)) { in set_discoverable()
1612 if (!!cp->val != hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) { in set_discoverable()
1613 hci_dev_change_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1617 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1622 err = new_settings(hdev, sk); in set_discoverable()
1631 if (!!cp->val == hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in set_discoverable()
1632 (cp->val == 0x02) == hci_dev_test_flag(hdev, in set_discoverable()
1634 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1635 hdev->discov_timeout = timeout; in set_discoverable()
1637 if (cp->val && hdev->discov_timeout > 0) { in set_discoverable()
1638 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in set_discoverable()
1639 queue_delayed_work(hdev->req_workqueue, in set_discoverable()
1640 &hdev->discov_off, to); in set_discoverable()
1643 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1647 cmd = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, hdev, data, len); in set_discoverable()
1657 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1658 hdev->discov_timeout = timeout; in set_discoverable()
1661 hci_dev_set_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1663 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1667 hci_dev_set_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1669 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1671 err = hci_cmd_sync_queue(hdev, set_discoverable_sync, cmd, in set_discoverable()
1678 hci_dev_unlock(hdev); in set_discoverable()
1682 static void mgmt_set_connectable_complete(struct hci_dev *hdev, void *data, in mgmt_set_connectable_complete() argument
1687 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_connectable_complete()
1690 if (cmd != pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) in mgmt_set_connectable_complete()
1693 hci_dev_lock(hdev); in mgmt_set_connectable_complete()
1701 send_settings_rsp(cmd->sk, MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_set_connectable_complete()
1702 new_settings(hdev, cmd->sk); in mgmt_set_connectable_complete()
1708 hci_dev_unlock(hdev); in mgmt_set_connectable_complete()
1711 static int set_connectable_update_settings(struct hci_dev *hdev, in set_connectable_update_settings() argument
1717 if (!!val != hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in set_connectable_update_settings()
1721 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1723 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1724 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable_update_settings()
1727 err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev); in set_connectable_update_settings()
1732 hci_update_scan(hdev); in set_connectable_update_settings()
1733 hci_update_passive_scan(hdev); in set_connectable_update_settings()
1734 return new_settings(hdev, sk); in set_connectable_update_settings()
1740 static int set_connectable_sync(struct hci_dev *hdev, void *data) in set_connectable_sync() argument
1742 BT_DBG("%s", hdev->name); in set_connectable_sync()
1744 return hci_update_connectable_sync(hdev); in set_connectable_sync()
1747 static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data, in set_connectable() argument
1754 bt_dev_dbg(hdev, "sock %p", sk); in set_connectable()
1756 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_connectable()
1757 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_connectable()
1758 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1762 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1765 hci_dev_lock(hdev); in set_connectable()
1767 if (!hdev_is_powered(hdev)) { in set_connectable()
1768 err = set_connectable_update_settings(hdev, sk, cp->val); in set_connectable()
1772 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_connectable()
1773 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_connectable()
1774 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1779 cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len); in set_connectable()
1786 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1788 if (hdev->discov_timeout > 0) in set_connectable()
1789 cancel_delayed_work(&hdev->discov_off); in set_connectable()
1791 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_connectable()
1792 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable()
1793 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1796 err = hci_cmd_sync_queue(hdev, set_connectable_sync, cmd, in set_connectable()
1803 hci_dev_unlock(hdev); in set_connectable()
1807 static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data, in set_bondable() argument
1814 bt_dev_dbg(hdev, "sock %p", sk); in set_bondable()
1817 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BONDABLE, in set_bondable()
1820 hci_dev_lock(hdev); in set_bondable()
1823 changed = !hci_dev_test_and_set_flag(hdev, HCI_BONDABLE); in set_bondable()
1825 changed = hci_dev_test_and_clear_flag(hdev, HCI_BONDABLE); in set_bondable()
1827 err = send_settings_rsp(sk, MGMT_OP_SET_BONDABLE, hdev); in set_bondable()
1835 hci_update_discoverable(hdev); in set_bondable()
1837 err = new_settings(hdev, sk); in set_bondable()
1841 hci_dev_unlock(hdev); in set_bondable()
1845 static int set_link_security(struct sock *sk, struct hci_dev *hdev, void *data, in set_link_security() argument
1853 bt_dev_dbg(hdev, "sock %p", sk); in set_link_security()
1855 status = mgmt_bredr_support(hdev); in set_link_security()
1857 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1861 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1864 hci_dev_lock(hdev); in set_link_security()
1866 if (!hdev_is_powered(hdev)) { in set_link_security()
1869 if (!!cp->val != hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) { in set_link_security()
1870 hci_dev_change_flag(hdev, HCI_LINK_SECURITY); in set_link_security()
1874 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1879 err = new_settings(hdev, sk); in set_link_security()
1884 if (pending_find(MGMT_OP_SET_LINK_SECURITY, hdev)) { in set_link_security()
1885 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1892 if (test_bit(HCI_AUTH, &hdev->flags) == val) { in set_link_security()
1893 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1897 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LINK_SECURITY, hdev, data, len); in set_link_security()
1903 err = hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, sizeof(val), &val); in set_link_security()
1910 hci_dev_unlock(hdev); in set_link_security()
1914 static void set_ssp_complete(struct hci_dev *hdev, void *data, int err) in set_ssp_complete() argument
1916 struct cmd_lookup match = { NULL, hdev }; in set_ssp_complete()
1923 if (cmd != pending_find(MGMT_OP_SET_SSP, hdev)) in set_ssp_complete()
1929 if (enable && hci_dev_test_and_clear_flag(hdev, in set_ssp_complete()
1931 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_ssp_complete()
1932 new_settings(hdev, NULL); in set_ssp_complete()
1935 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, cmd_status_rsp, in set_ssp_complete()
1941 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in set_ssp_complete()
1943 changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED); in set_ssp_complete()
1946 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp_complete()
1949 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_ssp_complete()
1952 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, settings_rsp, &match); in set_ssp_complete()
1955 new_settings(hdev, match.sk); in set_ssp_complete()
1960 hci_update_eir_sync(hdev); in set_ssp_complete()
1963 static int set_ssp_sync(struct hci_dev *hdev, void *data) in set_ssp_sync() argument
1971 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in set_ssp_sync()
1973 err = hci_write_ssp_mode_sync(hdev, cp->val); in set_ssp_sync()
1976 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_ssp_sync()
1981 static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_ssp() argument
1988 bt_dev_dbg(hdev, "sock %p", sk); in set_ssp()
1990 status = mgmt_bredr_support(hdev); in set_ssp()
1992 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, status); in set_ssp()
1994 if (!lmp_ssp_capable(hdev)) in set_ssp()
1995 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1999 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2002 hci_dev_lock(hdev); in set_ssp()
2004 if (!hdev_is_powered(hdev)) { in set_ssp()
2008 changed = !hci_dev_test_and_set_flag(hdev, in set_ssp()
2011 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
2014 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
2017 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_ssp()
2020 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
2025 err = new_settings(hdev, sk); in set_ssp()
2030 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_ssp()
2031 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2036 if (!!cp->val == hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_ssp()
2037 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
2041 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SSP, hdev, data, len); in set_ssp()
2045 err = hci_cmd_sync_queue(hdev, set_ssp_sync, cmd, in set_ssp()
2049 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2057 hci_dev_unlock(hdev); in set_ssp()
2061 static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_hs() argument
2068 bt_dev_dbg(hdev, "sock %p", sk); in set_hs()
2071 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2074 status = mgmt_bredr_support(hdev); in set_hs()
2076 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, status); in set_hs()
2078 if (!lmp_ssp_capable(hdev)) in set_hs()
2079 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2082 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_hs()
2083 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2087 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2090 hci_dev_lock(hdev); in set_hs()
2092 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_hs()
2093 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2099 changed = !hci_dev_test_and_set_flag(hdev, HCI_HS_ENABLED); in set_hs()
2101 if (hdev_is_powered(hdev)) { in set_hs()
2102 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2107 changed = hci_dev_test_and_clear_flag(hdev, HCI_HS_ENABLED); in set_hs()
2110 err = send_settings_rsp(sk, MGMT_OP_SET_HS, hdev); in set_hs()
2115 err = new_settings(hdev, sk); in set_hs()
2118 hci_dev_unlock(hdev); in set_hs()
2122 static void set_le_complete(struct hci_dev *hdev, void *data, int err) in set_le_complete() argument
2124 struct cmd_lookup match = { NULL, hdev }; in set_le_complete()
2127 bt_dev_dbg(hdev, "err %d", err); in set_le_complete()
2130 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp, in set_le_complete()
2135 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match); in set_le_complete()
2137 new_settings(hdev, match.sk); in set_le_complete()
2143 static int set_le_sync(struct hci_dev *hdev, void *data) in set_le_sync() argument
2151 hci_clear_adv_instance_sync(hdev, NULL, 0x00, true); in set_le_sync()
2153 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_le_sync()
2154 hci_disable_advertising_sync(hdev); in set_le_sync()
2156 if (ext_adv_capable(hdev)) in set_le_sync()
2157 hci_remove_ext_adv_instance_sync(hdev, 0, cmd->sk); in set_le_sync()
2159 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in set_le_sync()
2162 err = hci_write_le_host_supported_sync(hdev, val, 0); in set_le_sync()
2169 if (!err && hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le_sync()
2170 if (ext_adv_capable(hdev)) { in set_le_sync()
2173 status = hci_setup_ext_adv_instance_sync(hdev, 0x00); in set_le_sync()
2175 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_le_sync()
2177 hci_update_adv_data_sync(hdev, 0x00); in set_le_sync()
2178 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_le_sync()
2181 hci_update_passive_scan(hdev); in set_le_sync()
2187 static void set_mesh_complete(struct hci_dev *hdev, void *data, int err) in set_mesh_complete() argument
2194 mgmt_pending_foreach(MGMT_OP_SET_MESH_RECEIVER, hdev, in set_mesh_complete()
2200 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, 0, NULL, 0); in set_mesh_complete()
2203 static int set_mesh_sync(struct hci_dev *hdev, void *data) in set_mesh_sync() argument
2209 memset(hdev->mesh_ad_types, 0, sizeof(hdev->mesh_ad_types)); in set_mesh_sync()
2212 hci_dev_set_flag(hdev, HCI_MESH); in set_mesh_sync()
2214 hci_dev_clear_flag(hdev, HCI_MESH); in set_mesh_sync()
2219 if (len <= sizeof(hdev->mesh_ad_types)) in set_mesh_sync()
2220 memcpy(hdev->mesh_ad_types, cp->ad_types, len); in set_mesh_sync()
2222 hci_update_passive_scan_sync(hdev); in set_mesh_sync()
2226 static int set_mesh(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_mesh() argument
2232 bt_dev_dbg(hdev, "sock %p", sk); in set_mesh()
2234 if (!lmp_le_capable(hdev) || in set_mesh()
2235 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in set_mesh()
2236 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2240 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2243 hci_dev_lock(hdev); in set_mesh()
2245 cmd = mgmt_pending_add(sk, MGMT_OP_SET_MESH_RECEIVER, hdev, data, len); in set_mesh()
2249 err = hci_cmd_sync_queue(hdev, set_mesh_sync, cmd, in set_mesh()
2253 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2260 hci_dev_unlock(hdev); in set_mesh()
2264 static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err) in mesh_send_start_complete() argument
2274 hci_dev_clear_flag(hdev, HCI_MESH_SENDING); in mesh_send_start_complete()
2276 mesh_send_complete(hdev, mesh_tx, false); in mesh_send_start_complete()
2281 queue_delayed_work(hdev->req_workqueue, &hdev->mesh_send_done, in mesh_send_start_complete()
2285 static int mesh_send_sync(struct hci_dev *hdev, void *data) in mesh_send_sync() argument
2290 u8 instance = hdev->le_num_of_adv_sets + 1; in mesh_send_sync()
2294 if (hdev->le_num_of_adv_sets <= hdev->adv_instance_cnt) in mesh_send_sync()
2298 duration = send->cnt * INTERVAL_TO_MS(hdev->le_adv_max_interval); in mesh_send_sync()
2299 adv = hci_add_adv_instance(hdev, instance, 0, in mesh_send_sync()
2304 hdev->le_adv_min_interval, in mesh_send_sync()
2305 hdev->le_adv_max_interval, in mesh_send_sync()
2313 if (hdev->cur_adv_instance == instance) { in mesh_send_sync()
2319 cancel_adv_timeout(hdev); in mesh_send_sync()
2321 next_instance = hci_get_next_instance(hdev, instance); in mesh_send_sync()
2326 } else if (hdev->adv_instance_timeout) { in mesh_send_sync()
2334 return hci_schedule_adv_instance_sync(hdev, instance, true); in mesh_send_sync()
2349 static int mesh_features(struct sock *sk, struct hci_dev *hdev, in mesh_features() argument
2354 if (!lmp_le_capable(hdev) || in mesh_features()
2355 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_features()
2356 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_READ_FEATURES, in mesh_features()
2360 rp.index = cpu_to_le16(hdev->id); in mesh_features()
2361 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mesh_features()
2364 hci_dev_lock(hdev); in mesh_features()
2367 mgmt_mesh_foreach(hdev, send_count, &rp, sk); in mesh_features()
2369 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_MESH_READ_FEATURES, 0, &rp, in mesh_features()
2372 hci_dev_unlock(hdev); in mesh_features()
2376 static int send_cancel(struct hci_dev *hdev, void *data) in send_cancel() argument
2384 mesh_tx = mgmt_mesh_next(hdev, cmd->sk); in send_cancel()
2387 mesh_send_complete(hdev, mesh_tx, false); in send_cancel()
2390 mesh_tx = mgmt_mesh_find(hdev, cancel->handle); in send_cancel()
2393 mesh_send_complete(hdev, mesh_tx, false); in send_cancel()
2396 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in send_cancel()
2403 static int mesh_send_cancel(struct sock *sk, struct hci_dev *hdev, in mesh_send_cancel() argument
2409 if (!lmp_le_capable(hdev) || in mesh_send_cancel()
2410 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_send_cancel()
2411 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2414 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mesh_send_cancel()
2415 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2418 hci_dev_lock(hdev); in mesh_send_cancel()
2419 cmd = mgmt_pending_new(sk, MGMT_OP_MESH_SEND_CANCEL, hdev, data, len); in mesh_send_cancel()
2423 err = hci_cmd_sync_queue(hdev, send_cancel, cmd, NULL); in mesh_send_cancel()
2426 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2433 hci_dev_unlock(hdev); in mesh_send_cancel()
2437 static int mesh_send(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in mesh_send() argument
2445 if (!lmp_le_capable(hdev) || in mesh_send()
2446 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_send()
2447 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2449 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) || in mesh_send()
2452 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2455 hci_dev_lock(hdev); in mesh_send()
2460 mgmt_mesh_foreach(hdev, send_count, &rp, sk); in mesh_send()
2463 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2468 sending = hci_dev_test_flag(hdev, HCI_MESH_SENDING); in mesh_send()
2469 mesh_tx = mgmt_mesh_add(sk, hdev, send, len); in mesh_send()
2474 err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx, in mesh_send()
2478 bt_dev_err(hdev, "Send Mesh Failed %d", err); in mesh_send()
2479 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2487 hci_dev_set_flag(hdev, HCI_MESH_SENDING); in mesh_send()
2489 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_MESH_SEND, 0, in mesh_send()
2494 hci_dev_unlock(hdev); in mesh_send()
2498 static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_le() argument
2505 bt_dev_dbg(hdev, "sock %p", sk); in set_le()
2507 if (!lmp_le_capable(hdev)) in set_le()
2508 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2512 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2524 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_le()
2526 return send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
2528 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2532 hci_dev_lock(hdev); in set_le()
2535 enabled = lmp_host_le_capable(hdev); in set_le()
2537 if (!hdev_is_powered(hdev) || val == enabled) { in set_le()
2540 if (val != hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le()
2541 hci_dev_change_flag(hdev, HCI_LE_ENABLED); in set_le()
2545 if (!val && hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in set_le()
2546 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_le()
2550 err = send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
2555 err = new_settings(hdev, sk); in set_le()
2560 if (pending_find(MGMT_OP_SET_LE, hdev) || in set_le()
2561 pending_find(MGMT_OP_SET_ADVERTISING, hdev)) { in set_le()
2562 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2567 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LE, hdev, data, len); in set_le()
2571 err = hci_cmd_sync_queue(hdev, set_le_sync, cmd, in set_le()
2575 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2583 hci_dev_unlock(hdev); in set_le()
2593 static bool pending_eir_or_class(struct hci_dev *hdev) in pending_eir_or_class() argument
2597 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in pending_eir_or_class()
2629 static void mgmt_class_complete(struct hci_dev *hdev, void *data, int err) in mgmt_class_complete() argument
2633 bt_dev_dbg(hdev, "err %d", err); in mgmt_class_complete()
2636 mgmt_status(err), hdev->dev_class, 3); in mgmt_class_complete()
2641 static int add_uuid_sync(struct hci_dev *hdev, void *data) in add_uuid_sync() argument
2645 err = hci_update_class_sync(hdev); in add_uuid_sync()
2649 return hci_update_eir_sync(hdev); in add_uuid_sync()
2652 static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in add_uuid() argument
2659 bt_dev_dbg(hdev, "sock %p", sk); in add_uuid()
2661 hci_dev_lock(hdev); in add_uuid()
2663 if (pending_eir_or_class(hdev)) { in add_uuid()
2664 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_UUID, in add_uuid()
2679 list_add_tail(&uuid->list, &hdev->uuids); in add_uuid()
2681 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_UUID, hdev, data, len); in add_uuid()
2687 err = hci_cmd_sync_queue(hdev, add_uuid_sync, cmd, mgmt_class_complete); in add_uuid()
2694 hci_dev_unlock(hdev); in add_uuid()
2698 static bool enable_service_cache(struct hci_dev *hdev) in enable_service_cache() argument
2700 if (!hdev_is_powered(hdev)) in enable_service_cache()
2703 if (!hci_dev_test_and_set_flag(hdev, HCI_SERVICE_CACHE)) { in enable_service_cache()
2704 queue_delayed_work(hdev->workqueue, &hdev->service_cache, in enable_service_cache()
2712 static int remove_uuid_sync(struct hci_dev *hdev, void *data) in remove_uuid_sync() argument
2716 err = hci_update_class_sync(hdev); in remove_uuid_sync()
2720 return hci_update_eir_sync(hdev); in remove_uuid_sync()
2723 static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data, in remove_uuid() argument
2734 bt_dev_dbg(hdev, "sock %p", sk); in remove_uuid()
2736 hci_dev_lock(hdev); in remove_uuid()
2738 if (pending_eir_or_class(hdev)) { in remove_uuid()
2739 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2745 hci_uuids_clear(hdev); in remove_uuid()
2747 if (enable_service_cache(hdev)) { in remove_uuid()
2748 err = mgmt_cmd_complete(sk, hdev->id, in remove_uuid()
2750 0, hdev->dev_class, 3); in remove_uuid()
2759 list_for_each_entry_safe(match, tmp, &hdev->uuids, list) { in remove_uuid()
2769 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2775 cmd = mgmt_pending_new(sk, MGMT_OP_REMOVE_UUID, hdev, data, len); in remove_uuid()
2781 err = hci_cmd_sync_queue(hdev, remove_uuid_sync, cmd, in remove_uuid()
2787 hci_dev_unlock(hdev); in remove_uuid()
2791 static int set_class_sync(struct hci_dev *hdev, void *data) in set_class_sync() argument
2795 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) { in set_class_sync()
2796 cancel_delayed_work_sync(&hdev->service_cache); in set_class_sync()
2797 err = hci_update_eir_sync(hdev); in set_class_sync()
2803 return hci_update_class_sync(hdev); in set_class_sync()
2806 static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data, in set_dev_class() argument
2813 bt_dev_dbg(hdev, "sock %p", sk); in set_dev_class()
2815 if (!lmp_bredr_capable(hdev)) in set_dev_class()
2816 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2819 hci_dev_lock(hdev); in set_dev_class()
2821 if (pending_eir_or_class(hdev)) { in set_dev_class()
2822 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2828 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2833 hdev->major_class = cp->major; in set_dev_class()
2834 hdev->minor_class = cp->minor; in set_dev_class()
2836 if (!hdev_is_powered(hdev)) { in set_dev_class()
2837 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, in set_dev_class()
2838 hdev->dev_class, 3); in set_dev_class()
2842 cmd = mgmt_pending_new(sk, MGMT_OP_SET_DEV_CLASS, hdev, data, len); in set_dev_class()
2848 err = hci_cmd_sync_queue(hdev, set_class_sync, cmd, in set_dev_class()
2854 hci_dev_unlock(hdev); in set_dev_class()
2858 static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data, in load_link_keys() argument
2868 bt_dev_dbg(hdev, "sock %p", sk); in load_link_keys()
2870 if (!lmp_bredr_capable(hdev)) in load_link_keys()
2871 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2876 bt_dev_err(hdev, "load_link_keys: too big key_count value %u", in load_link_keys()
2878 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2884 bt_dev_err(hdev, "load_link_keys: expected %u bytes, got %u bytes", in load_link_keys()
2886 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2891 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2894 bt_dev_dbg(hdev, "debug_keys %u key_count %u", cp->debug_keys, in load_link_keys()
2901 return mgmt_cmd_status(sk, hdev->id, 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()
2936 hci_add_link_key(hdev, NULL, &key->addr.bdaddr, key->val, in load_link_keys()
2940 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0); in load_link_keys()
2942 hci_dev_unlock(hdev); in load_link_keys()
2947 static int device_unpaired(struct hci_dev *hdev, bdaddr_t *bdaddr, in device_unpaired() argument
2955 return mgmt_event(MGMT_EV_DEVICE_UNPAIRED, hdev, &ev, sizeof(ev), in device_unpaired()
2959 static void unpair_device_complete(struct hci_dev *hdev, void *data, int err) in unpair_device_complete() argument
2965 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_complete()
2971 static int unpair_device_sync(struct hci_dev *hdev, void *data) in unpair_device_sync() argument
2978 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device_sync()
2981 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in unpair_device_sync()
2987 return hci_abort_conn_sync(hdev, conn, HCI_ERROR_REMOTE_USER_TERM); in unpair_device_sync()
2990 static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data, in unpair_device() argument
3006 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3011 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3015 hci_dev_lock(hdev); in unpair_device()
3017 if (!hdev_is_powered(hdev)) { in unpair_device()
3018 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3033 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device()
3038 err = hci_remove_link_key(hdev, &cp->addr.bdaddr); in unpair_device()
3040 err = mgmt_cmd_complete(sk, hdev->id, in unpair_device()
3054 err = smp_cancel_and_remove_pairing(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3056 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3062 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3064 hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3075 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3094 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0, in unpair_device()
3096 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk); in unpair_device()
3100 cmd = mgmt_pending_new(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp, in unpair_device()
3109 err = hci_cmd_sync_queue(hdev, unpair_device_sync, cmd, in unpair_device()
3115 hci_dev_unlock(hdev); in unpair_device()
3119 static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data, in disconnect() argument
3128 bt_dev_dbg(hdev, "sock %p", sk); in disconnect()
3135 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3139 hci_dev_lock(hdev); in disconnect()
3141 if (!test_bit(HCI_UP, &hdev->flags)) { in disconnect()
3142 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3148 if (pending_find(MGMT_OP_DISCONNECT, hdev)) { in disconnect()
3149 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3155 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in disconnect()
3158 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in disconnect()
3162 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3168 cmd = mgmt_pending_add(sk, MGMT_OP_DISCONNECT, hdev, data, len); in disconnect()
3181 hci_dev_unlock(hdev); in disconnect()
3204 static int get_connections(struct sock *sk, struct hci_dev *hdev, void *data, in get_connections() argument
3212 bt_dev_dbg(hdev, "sock %p", sk); in get_connections()
3214 hci_dev_lock(hdev); in get_connections()
3216 if (!hdev_is_powered(hdev)) { in get_connections()
3217 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, in get_connections()
3223 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
3235 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
3248 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, 0, rp, in get_connections()
3254 hci_dev_unlock(hdev); in get_connections()
3258 static int send_pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in send_pin_code_neg_reply() argument
3264 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, hdev, cp, in send_pin_code_neg_reply()
3271 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, in send_pin_code_neg_reply()
3279 static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data, in pin_code_reply() argument
3288 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_reply()
3290 hci_dev_lock(hdev); in pin_code_reply()
3292 if (!hdev_is_powered(hdev)) { in pin_code_reply()
3293 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3298 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in pin_code_reply()
3300 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3310 bt_dev_err(hdev, "PIN code is not 16 bytes long"); in pin_code_reply()
3312 err = send_pin_code_neg_reply(sk, hdev, &ncp); in pin_code_reply()
3314 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3320 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data, len); in pin_code_reply()
3332 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_REPLY, sizeof(reply), &reply); in pin_code_reply()
3337 hci_dev_unlock(hdev); in pin_code_reply()
3341 static int set_io_capability(struct sock *sk, struct hci_dev *hdev, void *data, in set_io_capability() argument
3346 bt_dev_dbg(hdev, "sock %p", sk); in set_io_capability()
3349 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, in set_io_capability()
3352 hci_dev_lock(hdev); in set_io_capability()
3354 hdev->io_capability = cp->io_capability; in set_io_capability()
3356 bt_dev_dbg(hdev, "IO capability set to 0x%02x", hdev->io_capability); in set_io_capability()
3358 hci_dev_unlock(hdev); in set_io_capability()
3360 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, 0, in set_io_capability()
3366 struct hci_dev *hdev = conn->hdev; in find_pairing() local
3369 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in find_pairing()
3458 static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in pair_device() argument
3468 bt_dev_dbg(hdev, "sock %p", sk); in pair_device()
3475 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3480 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3484 hci_dev_lock(hdev); in pair_device()
3486 if (!hdev_is_powered(hdev)) { in pair_device()
3487 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3493 if (hci_bdaddr_is_paired(hdev, &cp->addr.bdaddr, cp->addr.type)) { in pair_device()
3494 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3504 conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level, in pair_device()
3519 p = hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type); in pair_device()
3524 conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr, addr_type, in pair_device()
3541 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3548 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3553 cmd = mgmt_pending_add(sk, MGMT_OP_PAIR_DEVICE, hdev, data, len); in pair_device()
3585 hci_dev_unlock(hdev); in pair_device()
3589 static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in cancel_pair_device() argument
3597 bt_dev_dbg(hdev, "sock %p", sk); in cancel_pair_device()
3599 hci_dev_lock(hdev); in cancel_pair_device()
3601 if (!hdev_is_powered(hdev)) { in cancel_pair_device()
3602 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3607 cmd = pending_find(MGMT_OP_PAIR_DEVICE, hdev); in cancel_pair_device()
3609 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3617 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3625 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0, in cancel_pair_device()
3633 hci_remove_link_key(hdev, &addr->bdaddr); in cancel_pair_device()
3635 smp_cancel_and_remove_pairing(hdev, &addr->bdaddr, in cancel_pair_device()
3642 hci_dev_unlock(hdev); in cancel_pair_device()
3646 static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev, in user_pairing_resp() argument
3654 hci_dev_lock(hdev); in user_pairing_resp()
3656 if (!hdev_is_powered(hdev)) { in user_pairing_resp()
3657 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3664 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &addr->bdaddr); in user_pairing_resp()
3666 conn = hci_conn_hash_lookup_le(hdev, &addr->bdaddr, in user_pairing_resp()
3670 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3679 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3683 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3690 cmd = mgmt_pending_add(sk, mgmt_op, hdev, addr, sizeof(*addr)); in user_pairing_resp()
3704 err = hci_send_cmd(hdev, hci_op, sizeof(cp), &cp); in user_pairing_resp()
3706 err = hci_send_cmd(hdev, hci_op, sizeof(addr->bdaddr), in user_pairing_resp()
3713 hci_dev_unlock(hdev); in user_pairing_resp()
3717 static int pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in pin_code_neg_reply() argument
3722 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_neg_reply()
3724 return user_pairing_resp(sk, hdev, &cp->addr, in pin_code_neg_reply()
3729 static int user_confirm_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_confirm_reply() argument
3734 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_reply()
3737 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_USER_CONFIRM_REPLY, in user_confirm_reply()
3740 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_reply()
3745 static int user_confirm_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_confirm_neg_reply() argument
3750 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_neg_reply()
3752 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_neg_reply()
3757 static int user_passkey_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_passkey_reply() argument
3762 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_reply()
3764 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_reply()
3769 static int user_passkey_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_passkey_neg_reply() argument
3774 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_neg_reply()
3776 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_neg_reply()
3781 static int adv_expire_sync(struct hci_dev *hdev, u32 flags) in adv_expire_sync() argument
3785 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in adv_expire_sync()
3793 cancel_adv_timeout(hdev); in adv_expire_sync()
3795 adv_instance = hci_get_next_instance(hdev, adv_instance->instance); in adv_expire_sync()
3799 hci_schedule_adv_instance_sync(hdev, adv_instance->instance, true); in adv_expire_sync()
3804 static int name_changed_sync(struct hci_dev *hdev, void *data) in name_changed_sync() argument
3806 return adv_expire_sync(hdev, MGMT_ADV_FLAG_LOCAL_NAME); in name_changed_sync()
3809 static void set_name_complete(struct hci_dev *hdev, void *data, int err) in set_name_complete() argument
3815 bt_dev_dbg(hdev, "err %d", err); in set_name_complete()
3817 if (cmd != pending_find(MGMT_OP_SET_LOCAL_NAME, hdev)) in set_name_complete()
3821 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_name_complete()
3824 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_name_complete()
3827 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_name_complete()
3828 hci_cmd_sync_queue(hdev, name_changed_sync, NULL, NULL); in set_name_complete()
3834 static int set_name_sync(struct hci_dev *hdev, void *data) in set_name_sync() argument
3836 if (lmp_bredr_capable(hdev)) { in set_name_sync()
3837 hci_update_name_sync(hdev); in set_name_sync()
3838 hci_update_eir_sync(hdev); in set_name_sync()
3844 if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING)) in set_name_sync()
3845 hci_update_scan_rsp_data_sync(hdev, hdev->cur_adv_instance); in set_name_sync()
3850 static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data, in set_local_name() argument
3857 bt_dev_dbg(hdev, "sock %p", sk); in set_local_name()
3859 hci_dev_lock(hdev); in set_local_name()
3864 if (!memcmp(hdev->dev_name, cp->name, sizeof(hdev->dev_name)) && in set_local_name()
3865 !memcmp(hdev->short_name, cp->short_name, in set_local_name()
3866 sizeof(hdev->short_name))) { in set_local_name()
3867 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3872 memcpy(hdev->short_name, cp->short_name, sizeof(hdev->short_name)); in set_local_name()
3874 if (!hdev_is_powered(hdev)) { in set_local_name()
3875 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3877 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3882 err = mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, data, in set_local_name()
3884 ext_info_changed(hdev, sk); in set_local_name()
3889 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len); in set_local_name()
3893 err = hci_cmd_sync_queue(hdev, set_name_sync, cmd, in set_local_name()
3897 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_local_name()
3906 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3909 hci_dev_unlock(hdev); in set_local_name()
3913 static int appearance_changed_sync(struct hci_dev *hdev, void *data) in appearance_changed_sync() argument
3915 return adv_expire_sync(hdev, MGMT_ADV_FLAG_APPEARANCE); in appearance_changed_sync()
3918 static int set_appearance(struct sock *sk, struct hci_dev *hdev, void *data, in set_appearance() argument
3925 bt_dev_dbg(hdev, "sock %p", sk); in set_appearance()
3927 if (!lmp_le_capable(hdev)) in set_appearance()
3928 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_APPEARANCE, in set_appearance()
3933 hci_dev_lock(hdev); in set_appearance()
3935 if (hdev->appearance != appearance) { in set_appearance()
3936 hdev->appearance = appearance; in set_appearance()
3938 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_appearance()
3939 hci_cmd_sync_queue(hdev, appearance_changed_sync, NULL, in set_appearance()
3942 ext_info_changed(hdev, sk); in set_appearance()
3945 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_APPEARANCE, 0, NULL, in set_appearance()
3948 hci_dev_unlock(hdev); in set_appearance()
3953 static int get_phy_configuration(struct sock *sk, struct hci_dev *hdev, in get_phy_configuration() argument
3958 bt_dev_dbg(hdev, "sock %p", sk); in get_phy_configuration()
3960 hci_dev_lock(hdev); in get_phy_configuration()
3964 rp.supported_phys = cpu_to_le32(get_supported_phys(hdev)); in get_phy_configuration()
3965 rp.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in get_phy_configuration()
3966 rp.configurable_phys = cpu_to_le32(get_configurable_phys(hdev)); in get_phy_configuration()
3968 hci_dev_unlock(hdev); in get_phy_configuration()
3970 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_PHY_CONFIGURATION, 0, in get_phy_configuration()
3974 int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip) in mgmt_phy_configuration_changed() argument
3980 ev.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in mgmt_phy_configuration_changed()
3982 return mgmt_event(MGMT_EV_PHY_CONFIGURATION_CHANGED, hdev, &ev, in mgmt_phy_configuration_changed()
3986 static void set_default_phy_complete(struct hci_dev *hdev, void *data, int err) in set_default_phy_complete() argument
3992 if (cmd != pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) in set_default_phy_complete()
4004 bt_dev_dbg(hdev, "status %d", status); in set_default_phy_complete()
4007 mgmt_cmd_status(cmd->sk, hdev->id, in set_default_phy_complete()
4010 mgmt_cmd_complete(cmd->sk, hdev->id, in set_default_phy_complete()
4014 mgmt_phy_configuration_changed(hdev, cmd->sk); in set_default_phy_complete()
4023 static int set_default_phy_sync(struct hci_dev *hdev, void *data) in set_default_phy_sync() argument
4056 cmd->skb = __hci_cmd_sync(hdev, HCI_OP_LE_SET_DEFAULT_PHY, in set_default_phy_sync()
4062 static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, in set_phy_configuration() argument
4072 bt_dev_dbg(hdev, "sock %p", sk); in set_phy_configuration()
4074 configurable_phys = get_configurable_phys(hdev); in set_phy_configuration()
4075 supported_phys = get_supported_phys(hdev); in set_phy_configuration()
4079 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4086 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4090 if (selected_phys == get_selected_phys(hdev)) in set_phy_configuration()
4091 return mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
4095 hci_dev_lock(hdev); in set_phy_configuration()
4097 if (!hdev_is_powered(hdev)) { in set_phy_configuration()
4098 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4104 if (pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) { in set_phy_configuration()
4105 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4151 if (pkt_type != hdev->pkt_type) { in set_phy_configuration()
4152 hdev->pkt_type = pkt_type; in set_phy_configuration()
4157 (get_selected_phys(hdev) & MGMT_PHY_LE_MASK)) { in set_phy_configuration()
4159 mgmt_phy_configuration_changed(hdev, sk); in set_phy_configuration()
4161 err = mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
4168 cmd = mgmt_pending_add(sk, MGMT_OP_SET_PHY_CONFIGURATION, hdev, data, in set_phy_configuration()
4173 err = hci_cmd_sync_queue(hdev, set_default_phy_sync, cmd, in set_phy_configuration()
4177 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4186 hci_dev_unlock(hdev); in set_phy_configuration()
4191 static int set_blocked_keys(struct sock *sk, struct hci_dev *hdev, void *data, in set_blocked_keys() argument
4201 bt_dev_dbg(hdev, "sock %p", sk); in set_blocked_keys()
4205 bt_dev_err(hdev, "too big key_count value %u", key_count); in set_blocked_keys()
4206 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4212 bt_dev_err(hdev, "expected %u bytes, got %u bytes", in set_blocked_keys()
4214 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4218 hci_dev_lock(hdev); in set_blocked_keys()
4220 hci_blocked_keys_clear(hdev); in set_blocked_keys()
4232 list_add_rcu(&b->list, &hdev->blocked_keys); in set_blocked_keys()
4234 hci_dev_unlock(hdev); in set_blocked_keys()
4236 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4240 static int set_wideband_speech(struct sock *sk, struct hci_dev *hdev, in set_wideband_speech() argument
4247 bt_dev_dbg(hdev, "sock %p", sk); in set_wideband_speech()
4249 if (!test_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks)) in set_wideband_speech()
4250 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4255 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4259 hci_dev_lock(hdev); in set_wideband_speech()
4261 if (hdev_is_powered(hdev) && in set_wideband_speech()
4262 !!cp->val != hci_dev_test_flag(hdev, in set_wideband_speech()
4264 err = mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4271 changed = !hci_dev_test_and_set_flag(hdev, in set_wideband_speech()
4274 changed = hci_dev_test_and_clear_flag(hdev, in set_wideband_speech()
4277 err = send_settings_rsp(sk, MGMT_OP_SET_WIDEBAND_SPEECH, hdev); in set_wideband_speech()
4282 err = new_settings(hdev, sk); in set_wideband_speech()
4285 hci_dev_unlock(hdev); in set_wideband_speech()
4289 static int read_controller_cap(struct sock *sk, struct hci_dev *hdev, in read_controller_cap() argument
4298 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_cap()
4302 hci_dev_lock(hdev); in read_controller_cap()
4310 if ((hdev->commands[41] & 0x08) || msft_curve_validity(hdev)) in read_controller_cap()
4318 if (hdev->commands[20] & 0x10) in read_controller_cap()
4329 if (hdev->commands[41] & 0x08) in read_controller_cap()
4332 hdev->max_enc_key_size); in read_controller_cap()
4341 if (hdev->commands[38] & 0x80) { in read_controller_cap()
4342 memcpy(&tx_power_range[0], &hdev->min_le_tx_power, 1); in read_controller_cap()
4343 memcpy(&tx_power_range[1], &hdev->max_le_tx_power, 1); in read_controller_cap()
4350 hci_dev_unlock(hdev); in read_controller_cap()
4352 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONTROLLER_CAP, 0, in read_controller_cap()
4400 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, in read_exp_features_info() argument
4409 bt_dev_dbg(hdev, "sock %p", sk); in read_exp_features_info()
4418 if (!hdev) { in read_exp_features_info()
4427 if (hdev && hci_dev_le_state_simultaneous(hdev)) { in read_exp_features_info()
4428 if (hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) in read_exp_features_info()
4438 if (hdev && ll_privacy_capable(hdev)) { in read_exp_features_info()
4439 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in read_exp_features_info()
4449 if (hdev && (aosp_has_quality_report(hdev) || in read_exp_features_info()
4450 hdev->set_quality_report)) { in read_exp_features_info()
4451 if (hci_dev_test_flag(hdev, HCI_QUALITY_REPORT)) in read_exp_features_info()
4461 if (hdev && hdev->get_data_path_id) { in read_exp_features_info()
4462 if (hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)) in read_exp_features_info()
4479 if (hdev && lmp_le_capable(hdev)) { in read_exp_features_info()
4480 if (hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in read_exp_features_info()
4497 status = mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in read_exp_features_info()
4505 static int exp_ll_privacy_feature_changed(bool enabled, struct hci_dev *hdev, in exp_ll_privacy_feature_changed() argument
4515 if (enabled && privacy_mode_capable(hdev)) in exp_ll_privacy_feature_changed()
4516 hdev->conn_flags |= HCI_CONN_FLAG_DEVICE_PRIVACY; in exp_ll_privacy_feature_changed()
4518 hdev->conn_flags &= ~HCI_CONN_FLAG_DEVICE_PRIVACY; in exp_ll_privacy_feature_changed()
4520 return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, in exp_ll_privacy_feature_changed()
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()
4566 if (hdev && use_ll_privacy(hdev) && !hdev_is_powered(hdev)) { in set_zero_key_func()
4569 changed = hci_dev_test_and_clear_flag(hdev, in set_zero_key_func()
4572 exp_feature_changed(hdev, rpa_resolution_uuid, false, in set_zero_key_func()
4578 return mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_zero_key_func()
4584 static int set_debug_func(struct sock *sk, struct hci_dev *hdev, in set_debug_func() argument
4593 if (hdev) in set_debug_func()
4594 return mgmt_cmd_status(sk, hdev->id, in set_debug_func()
4624 exp_feature_changed(hdev, debug_uuid, val, sk); in set_debug_func()
4630 static int set_mgmt_mesh_func(struct sock *sk, struct hci_dev *hdev, in set_mgmt_mesh_func() argument
4638 if (!hdev) in set_mgmt_mesh_func()
4645 return mgmt_cmd_status(sk, hdev->id, in set_mgmt_mesh_func()
4651 return mgmt_cmd_status(sk, hdev->id, in set_mgmt_mesh_func()
4658 changed = !hci_dev_test_and_set_flag(hdev, in set_mgmt_mesh_func()
4661 hci_dev_clear_flag(hdev, HCI_MESH); in set_mgmt_mesh_func()
4662 changed = hci_dev_test_and_clear_flag(hdev, in set_mgmt_mesh_func()
4671 err = mgmt_cmd_complete(sk, hdev->id, in set_mgmt_mesh_func()
4676 exp_feature_changed(hdev, mgmt_mesh_uuid, val, sk); in set_mgmt_mesh_func()
4681 static int set_rpa_resolution_func(struct sock *sk, struct hci_dev *hdev, in set_rpa_resolution_func() argument
4691 if (!hdev) in set_rpa_resolution_func()
4697 if (hdev_is_powered(hdev)) in set_rpa_resolution_func()
4698 return mgmt_cmd_status(sk, hdev->id, in set_rpa_resolution_func()
4704 return mgmt_cmd_status(sk, hdev->id, in set_rpa_resolution_func()
4710 return mgmt_cmd_status(sk, hdev->id, in set_rpa_resolution_func()
4717 changed = !hci_dev_test_and_set_flag(hdev, in set_rpa_resolution_func()
4719 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_rpa_resolution_func()
4724 changed = hci_dev_test_and_clear_flag(hdev, in set_rpa_resolution_func()
4736 err = mgmt_cmd_complete(sk, hdev->id, in set_rpa_resolution_func()
4741 exp_ll_privacy_feature_changed(val, hdev, sk); in set_rpa_resolution_func()
4746 static int set_quality_report_func(struct sock *sk, struct hci_dev *hdev, in set_quality_report_func() argument
4755 if (!hdev) in set_quality_report_func()
4762 return mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4768 return mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4772 hci_req_sync_lock(hdev); in set_quality_report_func()
4775 changed = (val != hci_dev_test_flag(hdev, HCI_QUALITY_REPORT)); in set_quality_report_func()
4777 if (!aosp_has_quality_report(hdev) && !hdev->set_quality_report) { in set_quality_report_func()
4778 err = mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4785 if (hdev->set_quality_report) in set_quality_report_func()
4786 err = hdev->set_quality_report(hdev, val); in set_quality_report_func()
4788 err = aosp_set_quality_report(hdev, val); in set_quality_report_func()
4791 err = mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4798 hci_dev_set_flag(hdev, HCI_QUALITY_REPORT); in set_quality_report_func()
4800 hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT); in set_quality_report_func()
4803 bt_dev_dbg(hdev, "quality report enable %d changed %d", val, changed); in set_quality_report_func()
4809 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_EXP_FEATURE, 0, in set_quality_report_func()
4813 exp_feature_changed(hdev, quality_report_uuid, val, sk); in set_quality_report_func()
4816 hci_req_sync_unlock(hdev); in set_quality_report_func()
4820 static int set_offload_codec_func(struct sock *sk, struct hci_dev *hdev, in set_offload_codec_func() argument
4829 if (!hdev) in set_offload_codec_func()
4836 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4842 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4847 changed = (val != hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)); in set_offload_codec_func()
4849 if (!hdev->get_data_path_id) { in set_offload_codec_func()
4850 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4857 hci_dev_set_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED); in set_offload_codec_func()
4859 hci_dev_clear_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED); in set_offload_codec_func()
4862 bt_dev_info(hdev, "offload codecs enable %d changed %d", in set_offload_codec_func()
4868 err = mgmt_cmd_complete(sk, hdev->id, in set_offload_codec_func()
4873 exp_feature_changed(hdev, offload_codecs_uuid, val, sk); in set_offload_codec_func()
4878 static int set_le_simultaneous_roles_func(struct sock *sk, struct hci_dev *hdev, in set_le_simultaneous_roles_func() argument
4887 if (!hdev) in set_le_simultaneous_roles_func()
4894 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4900 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4905 changed = (val != hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)); in set_le_simultaneous_roles_func()
4907 if (!hci_dev_le_state_simultaneous(hdev)) { in set_le_simultaneous_roles_func()
4908 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4915 hci_dev_set_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); in set_le_simultaneous_roles_func()
4917 hci_dev_clear_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); in set_le_simultaneous_roles_func()
4920 bt_dev_info(hdev, "LE simultaneous roles enable %d changed %d", in set_le_simultaneous_roles_func()
4926 err = mgmt_cmd_complete(sk, hdev->id, in set_le_simultaneous_roles_func()
4931 exp_feature_changed(hdev, le_simultaneous_roles_uuid, val, sk); in set_le_simultaneous_roles_func()
4937 static int set_iso_socket_func(struct sock *sk, struct hci_dev *hdev, in set_iso_socket_func() argument
4945 if (hdev) in set_iso_socket_func()
4946 return mgmt_cmd_status(sk, hdev->id, in set_iso_socket_func()
4981 exp_feature_changed(hdev, iso_socket_uuid, val, sk); in set_iso_socket_func()
4989 int (*set_func)(struct sock *sk, struct hci_dev *hdev,
5009 static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, in set_exp_feature() argument
5015 bt_dev_dbg(hdev, "sock %p", sk); in set_exp_feature()
5019 return exp_features[i].set_func(sk, hdev, cp, data_len); in set_exp_feature()
5022 return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_exp_feature()
5027 static u32 get_params_flags(struct hci_dev *hdev, in get_params_flags() argument
5030 u32 flags = hdev->conn_flags; in get_params_flags()
5036 if ((flags & HCI_CONN_FLAG_REMOTE_WAKEUP) && !use_ll_privacy(hdev) && in get_params_flags()
5037 hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type)) in get_params_flags()
5043 static int get_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in get_device_flags() argument
5054 bt_dev_dbg(hdev, "Get device flags %pMR (type 0x%x)\n", in get_device_flags()
5057 hci_dev_lock(hdev); in get_device_flags()
5059 supported_flags = hdev->conn_flags; in get_device_flags()
5064 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, in get_device_flags()
5072 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in get_device_flags()
5077 supported_flags = get_params_flags(hdev, params); in get_device_flags()
5089 hci_dev_unlock(hdev); in get_device_flags()
5091 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_DEVICE_FLAGS, status, in get_device_flags()
5095 static void device_flags_changed(struct sock *sk, struct hci_dev *hdev, in device_flags_changed() argument
5106 mgmt_event(MGMT_EV_DEVICE_FLAGS_CHANGED, hdev, &ev, sizeof(ev), sk); in device_flags_changed()
5109 static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_flags() argument
5119 bt_dev_dbg(hdev, "Set device flags %pMR (type 0x%x) = 0x%x", in set_device_flags()
5123 supported_flags = hdev->conn_flags; in set_device_flags()
5126 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
5131 hci_dev_lock(hdev); in set_device_flags()
5134 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, in set_device_flags()
5142 bt_dev_warn(hdev, "No such BR/EDR device %pMR (0x%x)", in set_device_flags()
5149 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in set_device_flags()
5152 bt_dev_warn(hdev, "No such LE device %pMR (0x%x)", in set_device_flags()
5157 supported_flags = get_params_flags(hdev, params); in set_device_flags()
5160 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
5172 hci_update_passive_scan(hdev); in set_device_flags()
5175 hci_dev_unlock(hdev); in set_device_flags()
5179 device_flags_changed(sk, hdev, &cp->addr.bdaddr, cp->addr.type, in set_device_flags()
5182 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_FLAGS, status, in set_device_flags()
5186 static void mgmt_adv_monitor_added(struct sock *sk, struct hci_dev *hdev, in mgmt_adv_monitor_added() argument
5193 mgmt_event(MGMT_EV_ADV_MONITOR_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_adv_monitor_added()
5196 void mgmt_adv_monitor_removed(struct hci_dev *hdev, u16 handle) in mgmt_adv_monitor_removed() argument
5203 cmd = pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev); in mgmt_adv_monitor_removed()
5213 mgmt_event(MGMT_EV_ADV_MONITOR_REMOVED, hdev, &ev, sizeof(ev), sk_skip); in mgmt_adv_monitor_removed()
5216 static int read_adv_mon_features(struct sock *sk, struct hci_dev *hdev, in read_adv_mon_features() argument
5228 BT_DBG("request for %s", hdev->name); in read_adv_mon_features()
5230 hci_dev_lock(hdev); in read_adv_mon_features()
5232 if (msft_monitor_supported(hdev)) in read_adv_mon_features()
5235 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) in read_adv_mon_features()
5238 hci_dev_unlock(hdev); in read_adv_mon_features()
5256 err = mgmt_cmd_complete(sk, hdev->id, in read_adv_mon_features()
5265 static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, in mgmt_add_adv_patterns_monitor_complete() argument
5272 hci_dev_lock(hdev); in mgmt_add_adv_patterns_monitor_complete()
5277 mgmt_adv_monitor_added(cmd->sk, hdev, monitor->handle); in mgmt_add_adv_patterns_monitor_complete()
5278 hdev->adv_monitors_cnt++; in mgmt_add_adv_patterns_monitor_complete()
5281 hci_update_passive_scan(hdev); in mgmt_add_adv_patterns_monitor_complete()
5288 hci_dev_unlock(hdev); in mgmt_add_adv_patterns_monitor_complete()
5289 bt_dev_dbg(hdev, "add monitor %d complete, status %d", in mgmt_add_adv_patterns_monitor_complete()
5293 static int mgmt_add_adv_patterns_monitor_sync(struct hci_dev *hdev, void *data) in mgmt_add_adv_patterns_monitor_sync() argument
5298 return hci_add_adv_monitor(hdev, monitor); in mgmt_add_adv_patterns_monitor_sync()
5301 static int __add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in __add_adv_patterns_monitor() argument
5308 hci_dev_lock(hdev); in __add_adv_patterns_monitor()
5313 if (pending_find(MGMT_OP_SET_LE, hdev) || in __add_adv_patterns_monitor()
5314 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR, hdev) || in __add_adv_patterns_monitor()
5315 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI, hdev) || in __add_adv_patterns_monitor()
5316 pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev)) { in __add_adv_patterns_monitor()
5321 cmd = mgmt_pending_add(sk, op, hdev, data, len); in __add_adv_patterns_monitor()
5328 err = hci_cmd_sync_queue(hdev, mgmt_add_adv_patterns_monitor_sync, cmd, in __add_adv_patterns_monitor()
5339 hci_dev_unlock(hdev); in __add_adv_patterns_monitor()
5344 hci_free_adv_monitor(hdev, m); in __add_adv_patterns_monitor()
5345 hci_dev_unlock(hdev); in __add_adv_patterns_monitor()
5346 return mgmt_cmd_status(sk, hdev->id, op, status); in __add_adv_patterns_monitor()
5405 static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor() argument
5413 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor()
5438 return __add_adv_patterns_monitor(sk, hdev, m, status, data, len, in add_adv_patterns_monitor()
5442 static int add_adv_patterns_monitor_rssi(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor_rssi() argument
5450 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor_rssi()
5475 return __add_adv_patterns_monitor(sk, hdev, m, status, data, len, in add_adv_patterns_monitor_rssi()
5479 static void mgmt_remove_adv_monitor_complete(struct hci_dev *hdev, in mgmt_remove_adv_monitor_complete() argument
5486 hci_dev_lock(hdev); in mgmt_remove_adv_monitor_complete()
5491 hci_update_passive_scan(hdev); in mgmt_remove_adv_monitor_complete()
5497 hci_dev_unlock(hdev); in mgmt_remove_adv_monitor_complete()
5498 bt_dev_dbg(hdev, "remove monitor %d complete, status %d", in mgmt_remove_adv_monitor_complete()
5502 static int mgmt_remove_adv_monitor_sync(struct hci_dev *hdev, void *data) in mgmt_remove_adv_monitor_sync() argument
5509 return hci_remove_all_adv_monitor(hdev); in mgmt_remove_adv_monitor_sync()
5511 return hci_remove_single_adv_monitor(hdev, handle); in mgmt_remove_adv_monitor_sync()
5514 static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev, in remove_adv_monitor() argument
5520 hci_dev_lock(hdev); in remove_adv_monitor()
5522 if (pending_find(MGMT_OP_SET_LE, hdev) || in remove_adv_monitor()
5523 pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev) || in remove_adv_monitor()
5524 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR, hdev) || in remove_adv_monitor()
5525 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI, hdev)) { in remove_adv_monitor()
5530 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_ADV_MONITOR, hdev, data, len); in remove_adv_monitor()
5536 err = hci_cmd_sync_queue(hdev, mgmt_remove_adv_monitor_sync, cmd, in remove_adv_monitor()
5550 hci_dev_unlock(hdev); in remove_adv_monitor()
5555 hci_dev_unlock(hdev); in remove_adv_monitor()
5556 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, in remove_adv_monitor()
5560 static void read_local_oob_data_complete(struct hci_dev *hdev, void *data, int err) in read_local_oob_data_complete() argument
5577 bt_dev_dbg(hdev, "status %d", status); in read_local_oob_data_complete()
5580 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, status); in read_local_oob_data_complete()
5586 if (!bredr_sc_enabled(hdev)) { in read_local_oob_data_complete()
5590 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
5604 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
5617 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data_complete()
5627 static int read_local_oob_data_sync(struct hci_dev *hdev, void *data) in read_local_oob_data_sync() argument
5631 if (bredr_sc_enabled(hdev)) in read_local_oob_data_sync()
5632 cmd->skb = hci_read_local_oob_data_sync(hdev, true, cmd->sk); in read_local_oob_data_sync()
5634 cmd->skb = hci_read_local_oob_data_sync(hdev, false, cmd->sk); in read_local_oob_data_sync()
5642 static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_data() argument
5648 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_data()
5650 hci_dev_lock(hdev); in read_local_oob_data()
5652 if (!hdev_is_powered(hdev)) { in read_local_oob_data()
5653 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5658 if (!lmp_ssp_capable(hdev)) { in read_local_oob_data()
5659 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5664 cmd = mgmt_pending_new(sk, MGMT_OP_READ_LOCAL_OOB_DATA, hdev, NULL, 0); in read_local_oob_data()
5668 err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd, in read_local_oob_data()
5672 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5680 hci_dev_unlock(hdev); in read_local_oob_data()
5684 static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in add_remote_oob_data() argument
5690 bt_dev_dbg(hdev, "sock %p", sk); in add_remote_oob_data()
5693 return mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5698 hci_dev_lock(hdev); in add_remote_oob_data()
5705 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5712 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
5720 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5734 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5769 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
5777 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5781 bt_dev_err(hdev, "add_remote_oob_data: invalid len of %u bytes", in add_remote_oob_data()
5783 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, in add_remote_oob_data()
5788 hci_dev_unlock(hdev); in add_remote_oob_data()
5792 static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in remove_remote_oob_data() argument
5799 bt_dev_dbg(hdev, "sock %p", sk); in remove_remote_oob_data()
5802 return mgmt_cmd_complete(sk, hdev->id, in remove_remote_oob_data()
5807 hci_dev_lock(hdev); in remove_remote_oob_data()
5810 hci_remote_oob_data_clear(hdev); in remove_remote_oob_data()
5815 err = hci_remove_remote_oob_data(hdev, &cp->addr.bdaddr, cp->addr.type); in remove_remote_oob_data()
5822 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA, in remove_remote_oob_data()
5825 hci_dev_unlock(hdev); in remove_remote_oob_data()
5829 void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_start_discovery_complete() argument
5833 bt_dev_dbg(hdev, "status %u", status); in mgmt_start_discovery_complete()
5835 hci_dev_lock(hdev); in mgmt_start_discovery_complete()
5837 cmd = pending_find(MGMT_OP_START_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5839 cmd = pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5842 cmd = pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5849 hci_dev_unlock(hdev); in mgmt_start_discovery_complete()
5852 static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, in discovery_type_is_valid() argument
5857 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
5862 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
5867 *mgmt_status = mgmt_bredr_support(hdev); in discovery_type_is_valid()
5879 static void start_discovery_complete(struct hci_dev *hdev, void *data, int err) in start_discovery_complete() argument
5883 if (cmd != pending_find(MGMT_OP_START_DISCOVERY, hdev) && in start_discovery_complete()
5884 cmd != pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev) && in start_discovery_complete()
5885 cmd != pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev)) in start_discovery_complete()
5888 bt_dev_dbg(hdev, "err %d", err); in start_discovery_complete()
5894 hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED: in start_discovery_complete()
5898 static int start_discovery_sync(struct hci_dev *hdev, void *data) in start_discovery_sync() argument
5900 return hci_start_discovery_sync(hdev); in start_discovery_sync()
5903 static int start_discovery_internal(struct sock *sk, struct hci_dev *hdev, in start_discovery_internal() argument
5911 bt_dev_dbg(hdev, "sock %p", sk); in start_discovery_internal()
5913 hci_dev_lock(hdev); in start_discovery_internal()
5915 if (!hdev_is_powered(hdev)) { in start_discovery_internal()
5916 err = mgmt_cmd_complete(sk, hdev->id, op, in start_discovery_internal()
5922 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_discovery_internal()
5923 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_discovery_internal()
5924 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
5929 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_discovery_internal()
5930 err = mgmt_cmd_complete(sk, hdev->id, op, status, in start_discovery_internal()
5936 if (hdev->discovery_paused) { in start_discovery_internal()
5937 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
5945 hci_discovery_filter_clear(hdev); in start_discovery_internal()
5947 hdev->discovery.type = cp->type; in start_discovery_internal()
5948 hdev->discovery.report_invalid_rssi = false; in start_discovery_internal()
5950 hdev->discovery.limited = true; in start_discovery_internal()
5952 hdev->discovery.limited = false; in start_discovery_internal()
5954 cmd = mgmt_pending_add(sk, op, hdev, data, len); in start_discovery_internal()
5960 err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd, in start_discovery_internal()
5967 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_discovery_internal()
5970 hci_dev_unlock(hdev); in start_discovery_internal()
5974 static int start_discovery(struct sock *sk, struct hci_dev *hdev, in start_discovery() argument
5977 return start_discovery_internal(sk, hdev, MGMT_OP_START_DISCOVERY, in start_discovery()
5981 static int start_limited_discovery(struct sock *sk, struct hci_dev *hdev, in start_limited_discovery() argument
5984 return start_discovery_internal(sk, hdev, in start_limited_discovery()
5989 static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, in start_service_discovery() argument
5999 bt_dev_dbg(hdev, "sock %p", sk); in start_service_discovery()
6001 hci_dev_lock(hdev); in start_service_discovery()
6003 if (!hdev_is_powered(hdev)) { in start_service_discovery()
6004 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6011 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_service_discovery()
6012 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_service_discovery()
6013 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6020 if (hdev->discovery_paused) { in start_service_discovery()
6021 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6030 bt_dev_err(hdev, "service_discovery: too big uuid_count value %u", in start_service_discovery()
6032 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6041 bt_dev_err(hdev, "service_discovery: expected %u bytes, got %u bytes", in start_service_discovery()
6043 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6050 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_service_discovery()
6051 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6058 hdev, data, len); in start_service_discovery()
6067 hci_discovery_filter_clear(hdev); in start_service_discovery()
6069 hdev->discovery.result_filtering = true; in start_service_discovery()
6070 hdev->discovery.type = cp->type; in start_service_discovery()
6071 hdev->discovery.rssi = cp->rssi; in start_service_discovery()
6072 hdev->discovery.uuid_count = uuid_count; in start_service_discovery()
6075 hdev->discovery.uuids = kmemdup(cp->uuids, uuid_count * 16, in start_service_discovery()
6077 if (!hdev->discovery.uuids) { in start_service_discovery()
6078 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6087 err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd, in start_service_discovery()
6094 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_service_discovery()
6097 hci_dev_unlock(hdev); in start_service_discovery()
6101 void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_stop_discovery_complete() argument
6105 bt_dev_dbg(hdev, "status %u", status); in mgmt_stop_discovery_complete()
6107 hci_dev_lock(hdev); in mgmt_stop_discovery_complete()
6109 cmd = pending_find(MGMT_OP_STOP_DISCOVERY, hdev); in mgmt_stop_discovery_complete()
6115 hci_dev_unlock(hdev); in mgmt_stop_discovery_complete()
6118 static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) in stop_discovery_complete() argument
6122 if (cmd != pending_find(MGMT_OP_STOP_DISCOVERY, hdev)) in stop_discovery_complete()
6125 bt_dev_dbg(hdev, "err %d", err); in stop_discovery_complete()
6132 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in stop_discovery_complete()
6135 static int stop_discovery_sync(struct hci_dev *hdev, void *data) in stop_discovery_sync() argument
6137 return hci_stop_discovery_sync(hdev); in stop_discovery_sync()
6140 static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, in stop_discovery() argument
6147 bt_dev_dbg(hdev, "sock %p", sk); in stop_discovery()
6149 hci_dev_lock(hdev); in stop_discovery()
6151 if (!hci_discovery_active(hdev)) { in stop_discovery()
6152 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
6158 if (hdev->discovery.type != mgmt_cp->type) { in stop_discovery()
6159 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
6165 cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, hdev, data, len); in stop_discovery()
6171 err = hci_cmd_sync_queue(hdev, stop_discovery_sync, cmd, in stop_discovery()
6178 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in stop_discovery()
6181 hci_dev_unlock(hdev); in stop_discovery()
6185 static int confirm_name(struct sock *sk, struct hci_dev *hdev, void *data, in confirm_name() argument
6192 bt_dev_dbg(hdev, "sock %p", sk); in confirm_name()
6194 hci_dev_lock(hdev); in confirm_name()
6196 if (!hci_discovery_active(hdev)) { in confirm_name()
6197 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
6203 e = hci_inquiry_cache_lookup_unknown(hdev, &cp->addr.bdaddr); in confirm_name()
6205 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
6216 hci_inquiry_cache_update_resolve(hdev, e); in confirm_name()
6219 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, 0, in confirm_name()
6223 hci_dev_unlock(hdev); in confirm_name()
6227 static int block_device(struct sock *sk, struct hci_dev *hdev, void *data, in block_device() argument
6234 bt_dev_dbg(hdev, "sock %p", sk); in block_device()
6237 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, in block_device()
6241 hci_dev_lock(hdev); in block_device()
6243 err = hci_bdaddr_list_add(&hdev->reject_list, &cp->addr.bdaddr, in block_device()
6250 mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &cp->addr, sizeof(cp->addr), in block_device()
6255 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status, in block_device()
6258 hci_dev_unlock(hdev); in block_device()
6263 static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data, in unblock_device() argument
6270 bt_dev_dbg(hdev, "sock %p", sk); in unblock_device()
6273 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, in unblock_device()
6277 hci_dev_lock(hdev); in unblock_device()
6279 err = hci_bdaddr_list_del(&hdev->reject_list, &cp->addr.bdaddr, in unblock_device()
6286 mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &cp->addr, sizeof(cp->addr), in unblock_device()
6291 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status, in unblock_device()
6294 hci_dev_unlock(hdev); in unblock_device()
6299 static int set_device_id_sync(struct hci_dev *hdev, void *data) in set_device_id_sync() argument
6301 return hci_update_eir_sync(hdev); in set_device_id_sync()
6304 static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_id() argument
6311 bt_dev_dbg(hdev, "sock %p", sk); in set_device_id()
6316 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, in set_device_id()
6319 hci_dev_lock(hdev); in set_device_id()
6321 hdev->devid_source = source; in set_device_id()
6322 hdev->devid_vendor = __le16_to_cpu(cp->vendor); in set_device_id()
6323 hdev->devid_product = __le16_to_cpu(cp->product); in set_device_id()
6324 hdev->devid_version = __le16_to_cpu(cp->version); in set_device_id()
6326 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, 0, in set_device_id()
6329 hci_cmd_sync_queue(hdev, set_device_id_sync, NULL, NULL); in set_device_id()
6331 hci_dev_unlock(hdev); in set_device_id()
6336 static void enable_advertising_instance(struct hci_dev *hdev, int err) in enable_advertising_instance() argument
6339 bt_dev_err(hdev, "failed to re-configure advertising %d", err); in enable_advertising_instance()
6341 bt_dev_dbg(hdev, "status %d", err); in enable_advertising_instance()
6344 static void set_advertising_complete(struct hci_dev *hdev, void *data, int err) in set_advertising_complete() argument
6346 struct cmd_lookup match = { NULL, hdev }; in set_advertising_complete()
6352 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, in set_advertising_complete()
6357 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_advertising_complete()
6358 hci_dev_set_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
6360 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
6362 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, settings_rsp, in set_advertising_complete()
6365 new_settings(hdev, match.sk); in set_advertising_complete()
6373 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in set_advertising_complete()
6374 list_empty(&hdev->adv_instances)) in set_advertising_complete()
6377 instance = hdev->cur_adv_instance; in set_advertising_complete()
6379 adv_instance = list_first_entry_or_null(&hdev->adv_instances, in set_advertising_complete()
6387 err = hci_schedule_adv_instance_sync(hdev, instance, true); in set_advertising_complete()
6389 enable_advertising_instance(hdev, err); in set_advertising_complete()
6392 static int set_adv_sync(struct hci_dev *hdev, void *data) in set_adv_sync() argument
6399 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_adv_sync()
6401 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_adv_sync()
6403 cancel_adv_timeout(hdev); in set_adv_sync()
6410 hdev->cur_adv_instance = 0x00; in set_adv_sync()
6412 if (ext_adv_capable(hdev)) { in set_adv_sync()
6413 hci_start_ext_adv_sync(hdev, 0x00); in set_adv_sync()
6415 hci_update_adv_data_sync(hdev, 0x00); in set_adv_sync()
6416 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_adv_sync()
6417 hci_enable_advertising_sync(hdev); in set_adv_sync()
6420 hci_disable_advertising_sync(hdev); in set_adv_sync()
6426 static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, in set_advertising() argument
6434 bt_dev_dbg(hdev, "sock %p", sk); in set_advertising()
6436 status = mgmt_le_support(hdev); in set_advertising()
6438 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6442 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6445 if (hdev->advertising_paused) in set_advertising()
6446 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6449 hci_dev_lock(hdev); in set_advertising()
6458 if (!hdev_is_powered(hdev) || in set_advertising()
6459 (val == hci_dev_test_flag(hdev, HCI_ADVERTISING) && in set_advertising()
6460 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) || in set_advertising()
6461 hci_dev_test_flag(hdev, HCI_MESH) || in set_advertising()
6462 hci_conn_num(hdev, LE_LINK) > 0 || in set_advertising()
6463 (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_advertising()
6464 hdev->le_scan_type == LE_SCAN_ACTIVE)) { in set_advertising()
6468 hdev->cur_adv_instance = 0x00; in set_advertising()
6469 changed = !hci_dev_test_and_set_flag(hdev, HCI_ADVERTISING); in set_advertising()
6471 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6473 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6475 changed = hci_dev_test_and_clear_flag(hdev, HCI_ADVERTISING); in set_advertising()
6476 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6479 err = send_settings_rsp(sk, MGMT_OP_SET_ADVERTISING, hdev); in set_advertising()
6484 err = new_settings(hdev, sk); in set_advertising()
6489 if (pending_find(MGMT_OP_SET_ADVERTISING, hdev) || in set_advertising()
6490 pending_find(MGMT_OP_SET_LE, hdev)) { in set_advertising()
6491 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6496 cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING, hdev, data, len); in set_advertising()
6500 err = hci_cmd_sync_queue(hdev, set_adv_sync, cmd, in set_advertising()
6507 hci_dev_unlock(hdev); in set_advertising()
6511 static int set_static_address(struct sock *sk, struct hci_dev *hdev, in set_static_address() argument
6517 bt_dev_dbg(hdev, "sock %p", sk); in set_static_address()
6519 if (!lmp_le_capable(hdev)) in set_static_address()
6520 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
6523 if (hdev_is_powered(hdev)) in set_static_address()
6524 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
6529 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
6535 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
6540 hci_dev_lock(hdev); in set_static_address()
6542 bacpy(&hdev->static_addr, &cp->bdaddr); in set_static_address()
6544 err = send_settings_rsp(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev); in set_static_address()
6548 err = new_settings(hdev, sk); in set_static_address()
6551 hci_dev_unlock(hdev); in set_static_address()
6555 static int set_scan_params(struct sock *sk, struct hci_dev *hdev, in set_scan_params() argument
6562 bt_dev_dbg(hdev, "sock %p", sk); in set_scan_params()
6564 if (!lmp_le_capable(hdev)) in set_scan_params()
6565 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6571 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6577 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6581 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6584 hci_dev_lock(hdev); in set_scan_params()
6586 hdev->le_scan_interval = interval; in set_scan_params()
6587 hdev->le_scan_window = window; in set_scan_params()
6589 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, 0, in set_scan_params()
6595 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_scan_params()
6596 hdev->discovery.state == DISCOVERY_STOPPED) in set_scan_params()
6597 hci_update_passive_scan(hdev); in set_scan_params()
6599 hci_dev_unlock(hdev); in set_scan_params()
6604 static void fast_connectable_complete(struct hci_dev *hdev, void *data, int err) in fast_connectable_complete() argument
6608 bt_dev_dbg(hdev, "err %d", err); in fast_connectable_complete()
6611 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in fast_connectable_complete()
6617 hci_dev_set_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
6619 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
6621 send_settings_rsp(cmd->sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in fast_connectable_complete()
6622 new_settings(hdev, cmd->sk); in fast_connectable_complete()
6628 static int write_fast_connectable_sync(struct hci_dev *hdev, void *data) in write_fast_connectable_sync() argument
6633 return hci_write_fast_connectable_sync(hdev, cp->val); in write_fast_connectable_sync()
6636 static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev, in set_fast_connectable() argument
6643 bt_dev_dbg(hdev, "sock %p", sk); in set_fast_connectable()
6645 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in set_fast_connectable()
6646 hdev->hci_ver < BLUETOOTH_VER_1_2) in set_fast_connectable()
6647 return mgmt_cmd_status(sk, hdev->id, in set_fast_connectable()
6652 return mgmt_cmd_status(sk, hdev->id, in set_fast_connectable()
6656 hci_dev_lock(hdev); in set_fast_connectable()
6658 if (!!cp->val == hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) { in set_fast_connectable()
6659 err = send_settings_rsp(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in set_fast_connectable()
6663 if (!hdev_is_powered(hdev)) { in set_fast_connectable()
6664 hci_dev_change_flag(hdev, HCI_FAST_CONNECTABLE); in set_fast_connectable()
6665 err = send_settings_rsp(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in set_fast_connectable()
6666 new_settings(hdev, sk); in set_fast_connectable()
6670 cmd = mgmt_pending_new(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev, data, in set_fast_connectable()
6675 err = hci_cmd_sync_queue(hdev, write_fast_connectable_sync, cmd, in set_fast_connectable()
6679 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
6687 hci_dev_unlock(hdev); in set_fast_connectable()
6692 static void set_bredr_complete(struct hci_dev *hdev, void *data, int err) in set_bredr_complete() argument
6696 bt_dev_dbg(hdev, "err %d", err); in set_bredr_complete()
6704 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in set_bredr_complete()
6708 send_settings_rsp(cmd->sk, MGMT_OP_SET_BREDR, hdev); in set_bredr_complete()
6709 new_settings(hdev, cmd->sk); in set_bredr_complete()
6715 static int set_bredr_sync(struct hci_dev *hdev, void *data) in set_bredr_sync() argument
6719 status = hci_write_fast_connectable_sync(hdev, false); in set_bredr_sync()
6722 status = hci_update_scan_sync(hdev); in set_bredr_sync()
6728 status = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in set_bredr_sync()
6733 static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_bredr() argument
6739 bt_dev_dbg(hdev, "sock %p", sk); in set_bredr()
6741 if (!lmp_bredr_capable(hdev) || !lmp_le_capable(hdev)) in set_bredr()
6742 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6745 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_bredr()
6746 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6750 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6753 hci_dev_lock(hdev); in set_bredr()
6755 if (cp->val == hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_bredr()
6756 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
6760 if (!hdev_is_powered(hdev)) { in set_bredr()
6762 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_bredr()
6763 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_bredr()
6764 hci_dev_clear_flag(hdev, HCI_LINK_SECURITY); in set_bredr()
6765 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in set_bredr()
6766 hci_dev_clear_flag(hdev, HCI_HS_ENABLED); in set_bredr()
6769 hci_dev_change_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
6771 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
6775 err = new_settings(hdev, sk); in set_bredr()
6781 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6799 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_bredr()
6800 (bacmp(&hdev->static_addr, BDADDR_ANY) || in set_bredr()
6801 hci_dev_test_flag(hdev, HCI_SC_ENABLED))) { in set_bredr()
6802 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6808 cmd = mgmt_pending_new(sk, MGMT_OP_SET_BREDR, hdev, data, len); in set_bredr()
6812 err = hci_cmd_sync_queue(hdev, set_bredr_sync, cmd, in set_bredr()
6816 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6827 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
6830 hci_dev_unlock(hdev); in set_bredr()
6834 static void set_secure_conn_complete(struct hci_dev *hdev, void *data, int err) in set_secure_conn_complete() argument
6839 bt_dev_dbg(hdev, "err %d", err); in set_secure_conn_complete()
6852 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6853 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6856 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6857 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6860 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6861 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6865 send_settings_rsp(cmd->sk, cmd->opcode, hdev); in set_secure_conn_complete()
6866 new_settings(hdev, cmd->sk); in set_secure_conn_complete()
6872 static int set_secure_conn_sync(struct hci_dev *hdev, void *data) in set_secure_conn_sync() argument
6879 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_sync()
6881 return hci_write_sc_support_sync(hdev, val); in set_secure_conn_sync()
6884 static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, in set_secure_conn() argument
6892 bt_dev_dbg(hdev, "sock %p", sk); in set_secure_conn()
6894 if (!lmp_sc_capable(hdev) && in set_secure_conn()
6895 !hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_secure_conn()
6896 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6899 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_secure_conn()
6900 lmp_sc_capable(hdev) && in set_secure_conn()
6901 !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_secure_conn()
6902 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6906 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6909 hci_dev_lock(hdev); in set_secure_conn()
6911 if (!hdev_is_powered(hdev) || !lmp_sc_capable(hdev) || in set_secure_conn()
6912 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_secure_conn()
6916 changed = !hci_dev_test_and_set_flag(hdev, in set_secure_conn()
6919 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6921 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6923 changed = hci_dev_test_and_clear_flag(hdev, in set_secure_conn()
6925 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6928 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
6933 err = new_settings(hdev, sk); in set_secure_conn()
6940 if (val == hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in set_secure_conn()
6941 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in set_secure_conn()
6942 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
6946 cmd = mgmt_pending_new(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len); in set_secure_conn()
6950 err = hci_cmd_sync_queue(hdev, set_secure_conn_sync, cmd, in set_secure_conn()
6954 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6961 hci_dev_unlock(hdev); in set_secure_conn()
6965 static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, in set_debug_keys() argument
6972 bt_dev_dbg(hdev, "sock %p", sk); in set_debug_keys()
6975 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEBUG_KEYS, in set_debug_keys()
6978 hci_dev_lock(hdev); in set_debug_keys()
6981 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in set_debug_keys()
6983 changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
6987 use_changed = !hci_dev_test_and_set_flag(hdev, in set_debug_keys()
6990 use_changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
6993 if (hdev_is_powered(hdev) && use_changed && in set_debug_keys()
6994 hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_debug_keys()
6996 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in set_debug_keys()
7000 err = send_settings_rsp(sk, MGMT_OP_SET_DEBUG_KEYS, hdev); in set_debug_keys()
7005 err = new_settings(hdev, sk); in set_debug_keys()
7008 hci_dev_unlock(hdev); in set_debug_keys()
7012 static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data, in set_privacy() argument
7019 bt_dev_dbg(hdev, "sock %p", sk); in set_privacy()
7021 if (!lmp_le_capable(hdev)) in set_privacy()
7022 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
7026 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
7029 if (hdev_is_powered(hdev)) in set_privacy()
7030 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
7033 hci_dev_lock(hdev); in set_privacy()
7038 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in set_privacy()
7041 changed = !hci_dev_test_and_set_flag(hdev, HCI_PRIVACY); in set_privacy()
7042 memcpy(hdev->irk, cp->irk, sizeof(hdev->irk)); in set_privacy()
7043 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
7044 hci_adv_instances_set_rpa_expired(hdev, true); in set_privacy()
7046 hci_dev_set_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
7048 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
7050 changed = hci_dev_test_and_clear_flag(hdev, HCI_PRIVACY); in set_privacy()
7051 memset(hdev->irk, 0, sizeof(hdev->irk)); in set_privacy()
7052 hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
7053 hci_adv_instances_set_rpa_expired(hdev, false); in set_privacy()
7054 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
7057 err = send_settings_rsp(sk, MGMT_OP_SET_PRIVACY, hdev); in set_privacy()
7062 err = new_settings(hdev, sk); in set_privacy()
7065 hci_dev_unlock(hdev); in set_privacy()
7085 static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data, in load_irks() argument
7094 bt_dev_dbg(hdev, "sock %p", sk); in load_irks()
7096 if (!lmp_le_capable(hdev)) in load_irks()
7097 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7102 bt_dev_err(hdev, "load_irks: too big irk_count value %u", in load_irks()
7104 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7110 bt_dev_err(hdev, "load_irks: expected %u bytes, got %u bytes", in load_irks()
7112 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7116 bt_dev_dbg(hdev, "irk_count %u", irk_count); in load_irks()
7122 return mgmt_cmd_status(sk, hdev->id, in load_irks()
7127 hci_dev_lock(hdev); in load_irks()
7129 hci_smp_irks_clear(hdev); in load_irks()
7134 if (hci_is_blocked_key(hdev, in load_irks()
7137 bt_dev_warn(hdev, "Skipping blocked IRK for %pMR", in load_irks()
7142 hci_add_irk(hdev, &irk->addr.bdaddr, in load_irks()
7147 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in load_irks()
7149 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_IRKS, 0, NULL, 0); in load_irks()
7151 hci_dev_unlock(hdev); in load_irks()
7175 static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev, in load_long_term_keys() argument
7184 bt_dev_dbg(hdev, "sock %p", sk); in load_long_term_keys()
7186 if (!lmp_le_capable(hdev)) in load_long_term_keys()
7187 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7192 bt_dev_err(hdev, "load_ltks: too big key_count value %u", in load_long_term_keys()
7194 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7200 bt_dev_err(hdev, "load_keys: expected %u bytes, got %u bytes", in load_long_term_keys()
7202 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7206 bt_dev_dbg(hdev, "key_count %u", key_count); in load_long_term_keys()
7212 return mgmt_cmd_status(sk, hdev->id, in load_long_term_keys()
7217 hci_dev_lock(hdev); in load_long_term_keys()
7219 hci_smp_ltks_clear(hdev); in load_long_term_keys()
7225 if (hci_is_blocked_key(hdev, in load_long_term_keys()
7228 bt_dev_warn(hdev, "Skipping blocked LTK for %pMR", in load_long_term_keys()
7258 hci_add_ltk(hdev, &key->addr.bdaddr, in load_long_term_keys()
7263 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 0, in load_long_term_keys()
7266 hci_dev_unlock(hdev); in load_long_term_keys()
7271 static void get_conn_info_complete(struct hci_dev *hdev, void *data, int err) in get_conn_info_complete() argument
7279 bt_dev_dbg(hdev, "err %d", err); in get_conn_info_complete()
7300 static int get_conn_info_sync(struct hci_dev *hdev, void *data) in get_conn_info_sync() argument
7310 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info_sync()
7313 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info_sync()
7322 err = hci_read_rssi_sync(hdev, handle); in get_conn_info_sync()
7329 err = hci_read_tx_power_sync(hdev, handle, 0x00); in get_conn_info_sync()
7333 err = hci_read_tx_power_sync(hdev, handle, 0x01); in get_conn_info_sync()
7338 static int get_conn_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_conn_info() argument
7347 bt_dev_dbg(hdev, "sock %p", sk); in get_conn_info()
7354 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7358 hci_dev_lock(hdev); in get_conn_info()
7360 if (!hdev_is_powered(hdev)) { in get_conn_info()
7361 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7368 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info()
7371 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info()
7374 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7383 conn_info_age = get_random_u32_inclusive(hdev->conn_info_min_age, in get_conn_info()
7384 hdev->conn_info_max_age - 1); in get_conn_info()
7394 cmd = mgmt_pending_new(sk, MGMT_OP_GET_CONN_INFO, hdev, data, in get_conn_info()
7399 err = hci_cmd_sync_queue(hdev, get_conn_info_sync, in get_conn_info()
7404 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7420 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7425 hci_dev_unlock(hdev); in get_conn_info()
7429 static void get_clock_info_complete(struct hci_dev *hdev, void *data, int err) in get_clock_info_complete() argument
7437 bt_dev_dbg(hdev, "err %d", err); in get_clock_info_complete()
7446 rp.local_clock = cpu_to_le32(hdev->clock); in get_clock_info_complete()
7460 static int get_clock_info_sync(struct hci_dev *hdev, void *data) in get_clock_info_sync() argument
7468 hci_read_clock_sync(hdev, &hci_cp); in get_clock_info_sync()
7471 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in get_clock_info_sync()
7479 return hci_read_clock_sync(hdev, &hci_cp); in get_clock_info_sync()
7482 static int get_clock_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_clock_info() argument
7491 bt_dev_dbg(hdev, "sock %p", sk); in get_clock_info()
7498 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7502 hci_dev_lock(hdev); in get_clock_info()
7504 if (!hdev_is_powered(hdev)) { in get_clock_info()
7505 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7512 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_clock_info()
7515 err = mgmt_cmd_complete(sk, hdev->id, in get_clock_info()
7525 cmd = mgmt_pending_new(sk, MGMT_OP_GET_CLOCK_INFO, hdev, data, len); in get_clock_info()
7529 err = hci_cmd_sync_queue(hdev, get_clock_info_sync, cmd, in get_clock_info()
7533 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7542 hci_dev_unlock(hdev); in get_clock_info()
7546 static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type) in is_connected() argument
7550 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, addr); in is_connected()
7564 static int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, in hci_conn_params_set() argument
7569 params = hci_conn_params_add(hdev, addr, addr_type); in hci_conn_params_set()
7585 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7589 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7591 hci_pend_le_list_add(params, &hdev->pend_le_reports); in hci_conn_params_set()
7595 if (!is_connected(hdev, addr, addr_type)) in hci_conn_params_set()
7596 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7602 bt_dev_dbg(hdev, "addr %pMR (type %u) auto_connect %u", in hci_conn_params_set()
7608 static void device_added(struct sock *sk, struct hci_dev *hdev, in device_added() argument
7617 mgmt_event(MGMT_EV_DEVICE_ADDED, hdev, &ev, sizeof(ev), sk); in device_added()
7620 static int add_device_sync(struct hci_dev *hdev, void *data) in add_device_sync() argument
7622 return hci_update_passive_scan_sync(hdev); in add_device_sync()
7625 static int add_device(struct sock *sk, struct hci_dev *hdev, in add_device() argument
7635 bt_dev_dbg(hdev, "sock %p", sk); in add_device()
7639 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7644 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7648 hci_dev_lock(hdev); in add_device()
7653 err = mgmt_cmd_complete(sk, hdev->id, in add_device()
7660 err = hci_bdaddr_list_add_with_flags(&hdev->accept_list, in add_device()
7666 hci_update_scan(hdev); in add_device()
7686 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7695 if (hci_conn_params_set(hdev, &cp->addr.bdaddr, addr_type, in add_device()
7697 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7702 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in add_device()
7708 err = hci_cmd_sync_queue(hdev, add_device_sync, NULL, NULL); in add_device()
7713 device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action); in add_device()
7714 supported_flags = hdev->conn_flags; in add_device()
7715 device_flags_changed(NULL, hdev, &cp->addr.bdaddr, cp->addr.type, in add_device()
7718 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7723 hci_dev_unlock(hdev); in add_device()
7727 static void device_removed(struct sock *sk, struct hci_dev *hdev, in device_removed() argument
7735 mgmt_event(MGMT_EV_DEVICE_REMOVED, hdev, &ev, sizeof(ev), sk); in device_removed()
7738 static int remove_device_sync(struct hci_dev *hdev, void *data) in remove_device_sync() argument
7740 return hci_update_passive_scan_sync(hdev); in remove_device_sync()
7743 static int remove_device(struct sock *sk, struct hci_dev *hdev, in remove_device() argument
7749 bt_dev_dbg(hdev, "sock %p", sk); in remove_device()
7751 hci_dev_lock(hdev); in remove_device()
7758 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7766 err = hci_bdaddr_list_del(&hdev->accept_list, in remove_device()
7770 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7778 hci_update_scan(hdev); in remove_device()
7780 device_removed(sk, hdev, &cp->addr.bdaddr, in remove_device()
7793 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7800 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in remove_device()
7803 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7812 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7821 device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type); in remove_device()
7827 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7834 list_for_each_entry_safe(b, btmp, &hdev->accept_list, list) { in remove_device()
7835 device_removed(sk, hdev, &b->bdaddr, b->bdaddr_type); in remove_device()
7840 hci_update_scan(hdev); in remove_device()
7842 list_for_each_entry_safe(p, tmp, &hdev->le_conn_params, list) { in remove_device()
7845 device_removed(sk, hdev, &p->addr, p->addr_type); in remove_device()
7853 bt_dev_dbg(hdev, "All LE connection parameters were removed"); in remove_device()
7856 hci_cmd_sync_queue(hdev, remove_device_sync, NULL, NULL); in remove_device()
7859 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, in remove_device()
7863 hci_dev_unlock(hdev); in remove_device()
7867 static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data, in load_conn_param() argument
7876 if (!lmp_le_capable(hdev)) in load_conn_param()
7877 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7882 bt_dev_err(hdev, "load_conn_param: too big param_count value %u", in load_conn_param()
7884 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7890 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes", in load_conn_param()
7892 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7896 bt_dev_dbg(hdev, "param_count %u", param_count); in load_conn_param()
7898 hci_dev_lock(hdev); in load_conn_param()
7900 hci_conn_params_clear_disabled(hdev); in load_conn_param()
7908 bt_dev_dbg(hdev, "Adding %pMR (type %u)", ¶m->addr.bdaddr, in load_conn_param()
7916 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
7925 bt_dev_dbg(hdev, "min 0x%04x max 0x%04x latency 0x%04x timeout 0x%04x", in load_conn_param()
7929 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
7933 hci_param = hci_conn_params_add(hdev, ¶m->addr.bdaddr, in load_conn_param()
7936 bt_dev_err(hdev, "failed to add connection parameters"); in load_conn_param()
7946 hci_dev_unlock(hdev); in load_conn_param()
7948 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 0, in load_conn_param()
7952 static int set_external_config(struct sock *sk, struct hci_dev *hdev, in set_external_config() argument
7959 bt_dev_dbg(hdev, "sock %p", sk); in set_external_config()
7961 if (hdev_is_powered(hdev)) in set_external_config()
7962 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7966 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7969 if (!test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in set_external_config()
7970 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7973 hci_dev_lock(hdev); in set_external_config()
7976 changed = !hci_dev_test_and_set_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
7978 changed = hci_dev_test_and_clear_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
7980 err = send_options_rsp(sk, MGMT_OP_SET_EXTERNAL_CONFIG, hdev); in set_external_config()
7987 err = new_options(hdev, sk); in set_external_config()
7989 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) == is_configured(hdev)) { in set_external_config()
7990 mgmt_index_removed(hdev); in set_external_config()
7992 if (hci_dev_test_and_change_flag(hdev, HCI_UNCONFIGURED)) { in set_external_config()
7993 hci_dev_set_flag(hdev, HCI_CONFIG); in set_external_config()
7994 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_external_config()
7996 queue_work(hdev->req_workqueue, &hdev->power_on); in set_external_config()
7998 set_bit(HCI_RAW, &hdev->flags); in set_external_config()
7999 mgmt_index_added(hdev); in set_external_config()
8004 hci_dev_unlock(hdev); in set_external_config()
8008 static int set_public_address(struct sock *sk, struct hci_dev *hdev, in set_public_address() argument
8015 bt_dev_dbg(hdev, "sock %p", sk); in set_public_address()
8017 if (hdev_is_powered(hdev)) in set_public_address()
8018 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8022 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8025 if (!hdev->set_bdaddr) in set_public_address()
8026 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8029 hci_dev_lock(hdev); in set_public_address()
8031 changed = !!bacmp(&hdev->public_addr, &cp->bdaddr); in set_public_address()
8032 bacpy(&hdev->public_addr, &cp->bdaddr); in set_public_address()
8034 err = send_options_rsp(sk, MGMT_OP_SET_PUBLIC_ADDRESS, hdev); in set_public_address()
8041 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in set_public_address()
8042 err = new_options(hdev, sk); in set_public_address()
8044 if (is_configured(hdev)) { in set_public_address()
8045 mgmt_index_removed(hdev); in set_public_address()
8047 hci_dev_clear_flag(hdev, HCI_UNCONFIGURED); in set_public_address()
8049 hci_dev_set_flag(hdev, HCI_CONFIG); in set_public_address()
8050 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_public_address()
8052 queue_work(hdev->req_workqueue, &hdev->power_on); in set_public_address()
8056 hci_dev_unlock(hdev); in set_public_address()
8060 static void read_local_oob_ext_data_complete(struct hci_dev *hdev, void *data, in read_local_oob_ext_data_complete() argument
8071 if (cmd != pending_find(MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev)) in read_local_oob_ext_data_complete()
8083 bt_dev_dbg(hdev, "status %u", status); in read_local_oob_ext_data_complete()
8095 } else if (!bredr_sc_enabled(hdev)) { in read_local_oob_ext_data_complete()
8121 if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in read_local_oob_ext_data_complete()
8144 hdev->dev_class, 3); in read_local_oob_ext_data_complete()
8164 err = mgmt_cmd_complete(cmd->sk, hdev->id, in read_local_oob_ext_data_complete()
8172 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data_complete()
8183 static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk, in read_local_ssp_oob_req() argument
8189 cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev, in read_local_ssp_oob_req()
8194 err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd, in read_local_ssp_oob_req()
8205 static int read_local_oob_ext_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_ext_data() argument
8215 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_ext_data()
8217 if (hdev_is_powered(hdev)) { in read_local_oob_ext_data()
8220 status = mgmt_bredr_support(hdev); in read_local_oob_ext_data()
8227 status = mgmt_le_support(hdev); in read_local_oob_ext_data()
8248 if (!status && !lmp_ssp_capable(hdev)) { in read_local_oob_ext_data()
8256 hci_dev_lock(hdev); in read_local_oob_ext_data()
8261 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in read_local_oob_ext_data()
8262 err = read_local_ssp_oob_req(hdev, sk, cp); in read_local_oob_ext_data()
8263 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8272 hdev->dev_class, 3); in read_local_oob_ext_data()
8276 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in read_local_oob_ext_data()
8277 smp_generate_oob(hdev, hash, rand) < 0) { in read_local_oob_ext_data()
8278 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8293 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { in read_local_oob_ext_data()
8294 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8299 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in read_local_oob_ext_data()
8300 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in read_local_oob_ext_data()
8301 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in read_local_oob_ext_data()
8302 bacmp(&hdev->static_addr, BDADDR_ANY))) { in read_local_oob_ext_data()
8303 memcpy(addr, &hdev->static_addr, 6); in read_local_oob_ext_data()
8306 memcpy(addr, &hdev->bdaddr, 6); in read_local_oob_ext_data()
8313 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in read_local_oob_ext_data()
8321 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) { in read_local_oob_ext_data()
8331 flags = mgmt_get_adv_discov_flags(hdev); in read_local_oob_ext_data()
8333 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in read_local_oob_ext_data()
8341 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8351 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, in read_local_oob_ext_data()
8356 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data()
8366 static u32 get_supported_adv_flags(struct hci_dev *hdev) in get_supported_adv_flags() argument
8385 if (hdev->adv_tx_power != HCI_TX_POWER_INVALID || ext_adv_capable(hdev)) in get_supported_adv_flags()
8388 if (ext_adv_capable(hdev)) { in get_supported_adv_flags()
8393 if (le_2m_capable(hdev)) in get_supported_adv_flags()
8396 if (le_coded_capable(hdev)) in get_supported_adv_flags()
8403 static int read_adv_features(struct sock *sk, struct hci_dev *hdev, in read_adv_features() argument
8413 bt_dev_dbg(hdev, "sock %p", sk); in read_adv_features()
8415 if (!lmp_le_capable(hdev)) in read_adv_features()
8416 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
8419 hci_dev_lock(hdev); in read_adv_features()
8421 rp_len = sizeof(*rp) + hdev->adv_instance_cnt; in read_adv_features()
8424 hci_dev_unlock(hdev); in read_adv_features()
8428 supported_flags = get_supported_adv_flags(hdev); in read_adv_features()
8431 rp->max_adv_data_len = max_adv_len(hdev); in read_adv_features()
8432 rp->max_scan_rsp_len = max_adv_len(hdev); in read_adv_features()
8433 rp->max_instances = hdev->le_num_of_adv_sets; in read_adv_features()
8434 rp->num_instances = hdev->adv_instance_cnt; in read_adv_features()
8437 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in read_adv_features()
8439 if (adv_instance->instance <= hdev->adv_instance_cnt) { in read_adv_features()
8448 hci_dev_unlock(hdev); in read_adv_features()
8450 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
8458 static u8 calculate_name_len(struct hci_dev *hdev) in calculate_name_len() argument
8462 return eir_append_local_name(hdev, buf, 0); in calculate_name_len()
8465 static u8 tlv_data_max_len(struct hci_dev *hdev, u32 adv_flags, in tlv_data_max_len() argument
8468 u8 max_len = max_adv_len(hdev); in tlv_data_max_len()
8480 max_len -= calculate_name_len(hdev); in tlv_data_max_len()
8511 static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data, in tlv_data_is_valid() argument
8517 max_len = tlv_data_max_len(hdev, adv_flags, is_adv_data); in tlv_data_is_valid()
8556 static bool requested_adv_flags_are_valid(struct hci_dev *hdev, u32 adv_flags) in requested_adv_flags_are_valid() argument
8563 supported_flags = get_supported_adv_flags(hdev); in requested_adv_flags_are_valid()
8572 static bool adv_busy(struct hci_dev *hdev) in adv_busy() argument
8574 return pending_find(MGMT_OP_SET_LE, hdev); in adv_busy()
8577 static void add_adv_complete(struct hci_dev *hdev, struct sock *sk, u8 instance, in add_adv_complete() argument
8582 bt_dev_dbg(hdev, "err %d", err); in add_adv_complete()
8584 hci_dev_lock(hdev); in add_adv_complete()
8586 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in add_adv_complete()
8599 if (hdev->cur_adv_instance == instance) in add_adv_complete()
8600 cancel_adv_timeout(hdev); in add_adv_complete()
8602 hci_remove_adv_instance(hdev, instance); in add_adv_complete()
8603 mgmt_advertising_removed(sk, hdev, instance); in add_adv_complete()
8606 hci_dev_unlock(hdev); in add_adv_complete()
8609 static void add_advertising_complete(struct hci_dev *hdev, void *data, int err) in add_advertising_complete() argument
8626 add_adv_complete(hdev, cmd->sk, cp->instance, err); in add_advertising_complete()
8631 static int add_advertising_sync(struct hci_dev *hdev, void *data) in add_advertising_sync() argument
8636 return hci_schedule_adv_instance_sync(hdev, cp->instance, true); in add_advertising_sync()
8639 static int add_advertising(struct sock *sk, struct hci_dev *hdev, in add_advertising() argument
8653 bt_dev_dbg(hdev, "sock %p", sk); in add_advertising()
8655 status = mgmt_le_support(hdev); in add_advertising()
8657 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8660 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_advertising()
8661 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8665 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8672 if (!requested_adv_flags_are_valid(hdev, flags)) in add_advertising()
8673 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8676 hci_dev_lock(hdev); in add_advertising()
8678 if (timeout && !hdev_is_powered(hdev)) { in add_advertising()
8679 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8684 if (adv_busy(hdev)) { in add_advertising()
8685 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8690 if (!tlv_data_is_valid(hdev, flags, cp->data, cp->adv_data_len, true) || in add_advertising()
8691 !tlv_data_is_valid(hdev, flags, cp->data + cp->adv_data_len, in add_advertising()
8693 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8698 prev_instance_cnt = hdev->adv_instance_cnt; in add_advertising()
8700 adv = hci_add_adv_instance(hdev, cp->instance, flags, in add_advertising()
8706 hdev->le_adv_min_interval, in add_advertising()
8707 hdev->le_adv_max_interval, 0); in add_advertising()
8709 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8717 if (hdev->adv_instance_cnt > prev_instance_cnt) in add_advertising()
8718 mgmt_advertising_added(sk, hdev, cp->instance); in add_advertising()
8720 if (hdev->cur_adv_instance == cp->instance) { in add_advertising()
8726 cancel_adv_timeout(hdev); in add_advertising()
8728 next_instance = hci_get_next_instance(hdev, cp->instance); in add_advertising()
8731 } else if (!hdev->adv_instance_timeout) { in add_advertising()
8742 if (!hdev_is_powered(hdev) || in add_advertising()
8743 hci_dev_test_flag(hdev, HCI_ADVERTISING) || in add_advertising()
8746 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8754 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_ADVERTISING, hdev, data, in add_advertising()
8763 err = hci_cmd_sync_queue(hdev, add_advertising_sync, cmd, in add_advertising()
8769 hci_dev_unlock(hdev); in add_advertising()
8774 static void add_ext_adv_params_complete(struct hci_dev *hdev, void *data, in add_ext_adv_params_complete() argument
8783 BT_DBG("%s", hdev->name); in add_ext_adv_params_complete()
8785 hci_dev_lock(hdev); in add_ext_adv_params_complete()
8787 adv = hci_find_adv_instance(hdev, cp->instance); in add_ext_adv_params_complete()
8798 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in add_ext_adv_params_complete()
8799 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in add_ext_adv_params_complete()
8807 mgmt_advertising_removed(cmd->sk, hdev, cp->instance); in add_ext_adv_params_complete()
8809 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_params_complete()
8822 hci_dev_unlock(hdev); in add_ext_adv_params_complete()
8825 static int add_ext_adv_params_sync(struct hci_dev *hdev, void *data) in add_ext_adv_params_sync() argument
8830 return hci_setup_ext_adv_instance_sync(hdev, cp->instance); in add_ext_adv_params_sync()
8833 static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev, in add_ext_adv_params() argument
8846 BT_DBG("%s", hdev->name); in add_ext_adv_params()
8848 status = mgmt_le_support(hdev); in add_ext_adv_params()
8850 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8853 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_ext_adv_params()
8854 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8864 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8869 if (!requested_adv_flags_are_valid(hdev, flags)) in add_ext_adv_params()
8870 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8873 hci_dev_lock(hdev); in add_ext_adv_params()
8876 if (!hdev_is_powered(hdev)) { in add_ext_adv_params()
8877 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8882 if (adv_busy(hdev)) { in add_ext_adv_params()
8883 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8894 hdev->def_multi_adv_rotation_duration; in add_ext_adv_params()
8898 hdev->le_adv_min_interval; in add_ext_adv_params()
8902 hdev->le_adv_max_interval; in add_ext_adv_params()
8909 adv = hci_add_adv_instance(hdev, cp->instance, flags, 0, NULL, 0, NULL, in add_ext_adv_params()
8914 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8920 if (ext_adv_capable(hdev)) { in add_ext_adv_params()
8921 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_EXT_ADV_PARAMS, hdev, in add_ext_adv_params()
8925 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_params()
8929 err = hci_cmd_sync_queue(hdev, add_ext_adv_params_sync, cmd, in add_ext_adv_params()
8936 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in add_ext_adv_params()
8937 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in add_ext_adv_params()
8938 err = mgmt_cmd_complete(sk, hdev->id, in add_ext_adv_params()
8944 hci_dev_unlock(hdev); in add_ext_adv_params()
8949 static void add_ext_adv_data_complete(struct hci_dev *hdev, void *data, int err) in add_ext_adv_data_complete() argument
8955 add_adv_complete(hdev, cmd->sk, cp->instance, err); in add_ext_adv_data_complete()
8971 static int add_ext_adv_data_sync(struct hci_dev *hdev, void *data) in add_ext_adv_data_sync() argument
8977 if (ext_adv_capable(hdev)) { in add_ext_adv_data_sync()
8978 err = hci_update_adv_data_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8982 err = hci_update_scan_rsp_data_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8986 return hci_enable_ext_advertising_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8989 return hci_schedule_adv_instance_sync(hdev, cp->instance, true); in add_ext_adv_data_sync()
8992 static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data, in add_ext_adv_data() argument
9003 BT_DBG("%s", hdev->name); in add_ext_adv_data()
9005 hci_dev_lock(hdev); in add_ext_adv_data()
9007 adv_instance = hci_find_adv_instance(hdev, cp->instance); in add_ext_adv_data()
9010 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9016 if (!hdev_is_powered(hdev)) { in add_ext_adv_data()
9017 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9022 if (adv_busy(hdev)) { in add_ext_adv_data()
9023 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9029 if (!tlv_data_is_valid(hdev, adv_instance->flags, cp->data, in add_ext_adv_data()
9031 !tlv_data_is_valid(hdev, adv_instance->flags, cp->data + in add_ext_adv_data()
9033 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9039 hci_set_adv_instance_data(hdev, cp->instance, cp->adv_data_len, in add_ext_adv_data()
9044 if (hdev->cur_adv_instance == cp->instance) { in add_ext_adv_data()
9051 cancel_adv_timeout(hdev); in add_ext_adv_data()
9053 next_instance = hci_get_next_instance(hdev, cp->instance); in add_ext_adv_data()
9056 } else if (!hdev->adv_instance_timeout) { in add_ext_adv_data()
9067 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || !schedule_instance) { in add_ext_adv_data()
9069 mgmt_advertising_added(sk, hdev, cp->instance); in add_ext_adv_data()
9073 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9078 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_EXT_ADV_DATA, hdev, data, in add_ext_adv_data()
9085 err = hci_cmd_sync_queue(hdev, add_ext_adv_data_sync, cmd, in add_ext_adv_data()
9098 mgmt_advertising_added(sk, hdev, cp->instance); in add_ext_adv_data()
9103 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_data()
9106 hci_dev_unlock(hdev); in add_ext_adv_data()
9111 static void remove_advertising_complete(struct hci_dev *hdev, void *data, in remove_advertising_complete() argument
9118 bt_dev_dbg(hdev, "err %d", err); in remove_advertising_complete()
9133 static int remove_advertising_sync(struct hci_dev *hdev, void *data) in remove_advertising_sync() argument
9139 err = hci_remove_advertising_sync(hdev, cmd->sk, cp->instance, true); in remove_advertising_sync()
9143 if (list_empty(&hdev->adv_instances)) in remove_advertising_sync()
9144 err = hci_disable_advertising_sync(hdev); in remove_advertising_sync()
9149 static int remove_advertising(struct sock *sk, struct hci_dev *hdev, in remove_advertising() argument
9156 bt_dev_dbg(hdev, "sock %p", sk); in remove_advertising()
9158 hci_dev_lock(hdev); in remove_advertising()
9160 if (cp->instance && !hci_find_adv_instance(hdev, cp->instance)) { in remove_advertising()
9161 err = mgmt_cmd_status(sk, hdev->id, in remove_advertising()
9167 if (pending_find(MGMT_OP_SET_LE, hdev)) { in remove_advertising()
9168 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
9173 if (list_empty(&hdev->adv_instances)) { in remove_advertising()
9174 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
9179 cmd = mgmt_pending_new(sk, MGMT_OP_REMOVE_ADVERTISING, hdev, data, in remove_advertising()
9186 err = hci_cmd_sync_queue(hdev, remove_advertising_sync, cmd, in remove_advertising()
9192 hci_dev_unlock(hdev); in remove_advertising()
9197 static int get_adv_size_info(struct sock *sk, struct hci_dev *hdev, in get_adv_size_info() argument
9204 bt_dev_dbg(hdev, "sock %p", sk); in get_adv_size_info()
9206 if (!lmp_le_capable(hdev)) in get_adv_size_info()
9207 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9210 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in get_adv_size_info()
9211 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9219 supported_flags = get_supported_adv_flags(hdev); in get_adv_size_info()
9221 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9226 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in get_adv_size_info()
9227 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in get_adv_size_info()
9229 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9367 void mgmt_index_added(struct hci_dev *hdev) in mgmt_index_added() argument
9371 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_added()
9374 switch (hdev->dev_type) { in mgmt_index_added()
9376 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_added()
9377 mgmt_index_event(MGMT_EV_UNCONF_INDEX_ADDED, hdev, in mgmt_index_added()
9381 mgmt_index_event(MGMT_EV_INDEX_ADDED, hdev, NULL, 0, in mgmt_index_added()
9393 ev.bus = hdev->bus; in mgmt_index_added()
9395 mgmt_index_event(MGMT_EV_EXT_INDEX_ADDED, hdev, &ev, sizeof(ev), in mgmt_index_added()
9399 void mgmt_index_removed(struct hci_dev *hdev) in mgmt_index_removed() argument
9404 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_removed()
9407 switch (hdev->dev_type) { in mgmt_index_removed()
9409 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status); in mgmt_index_removed()
9411 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_removed()
9412 mgmt_index_event(MGMT_EV_UNCONF_INDEX_REMOVED, hdev, in mgmt_index_removed()
9416 mgmt_index_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, in mgmt_index_removed()
9428 ev.bus = hdev->bus; in mgmt_index_removed()
9430 mgmt_index_event(MGMT_EV_EXT_INDEX_REMOVED, hdev, &ev, sizeof(ev), in mgmt_index_removed()
9434 if (!hci_dev_test_flag(hdev, HCI_MGMT)) in mgmt_index_removed()
9436 cancel_delayed_work_sync(&hdev->discov_off); in mgmt_index_removed()
9437 cancel_delayed_work_sync(&hdev->service_cache); in mgmt_index_removed()
9438 cancel_delayed_work_sync(&hdev->rpa_expired); in mgmt_index_removed()
9441 void mgmt_power_on(struct hci_dev *hdev, int err) in mgmt_power_on() argument
9443 struct cmd_lookup match = { NULL, hdev }; in mgmt_power_on()
9445 bt_dev_dbg(hdev, "err %d", err); in mgmt_power_on()
9447 hci_dev_lock(hdev); in mgmt_power_on()
9450 restart_le_actions(hdev); in mgmt_power_on()
9451 hci_update_passive_scan(hdev); in mgmt_power_on()
9454 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in mgmt_power_on()
9456 new_settings(hdev, match.sk); in mgmt_power_on()
9461 hci_dev_unlock(hdev); in mgmt_power_on()
9464 void __mgmt_power_off(struct hci_dev *hdev) in __mgmt_power_off() argument
9466 struct cmd_lookup match = { NULL, hdev }; in __mgmt_power_off()
9469 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in __mgmt_power_off()
9478 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) in __mgmt_power_off()
9483 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &status); in __mgmt_power_off()
9485 if (memcmp(hdev->dev_class, zero_cod, sizeof(zero_cod)) != 0) { in __mgmt_power_off()
9486 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, in __mgmt_power_off()
9489 ext_info_changed(hdev, NULL); in __mgmt_power_off()
9492 new_settings(hdev, match.sk); in __mgmt_power_off()
9498 void mgmt_set_powered_failed(struct hci_dev *hdev, int err) in mgmt_set_powered_failed() argument
9503 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_set_powered_failed()
9512 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, status); in mgmt_set_powered_failed()
9517 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, in mgmt_new_link_key() argument
9531 mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_link_key()
9553 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent) in mgmt_new_ltk() argument
9593 mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_ltk()
9596 void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent) in mgmt_new_irk() argument
9609 mgmt_event(MGMT_EV_NEW_IRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_irk()
9612 void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, in mgmt_new_csrk() argument
9639 mgmt_event(MGMT_EV_NEW_CSRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_csrk()
9642 void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_new_conn_param() argument
9660 mgmt_event(MGMT_EV_NEW_CONN_PARAM, hdev, &ev, sizeof(ev), NULL); in mgmt_new_conn_param()
9663 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, in mgmt_device_connected() argument
9673 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, in mgmt_device_connected()
9676 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, in mgmt_device_connected()
9724 struct hci_dev *hdev = data; in unpair_device_rsp() local
9727 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_rsp()
9733 bool mgmt_powering_down(struct hci_dev *hdev) in mgmt_powering_down() argument
9738 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_powering_down()
9749 void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_device_disconnected() argument
9759 if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { in mgmt_device_disconnected()
9760 cancel_delayed_work(&hdev->power_off); in mgmt_device_disconnected()
9761 queue_work(hdev->req_workqueue, &hdev->power_off.work); in mgmt_device_disconnected()
9770 mgmt_pending_foreach(MGMT_OP_DISCONNECT, hdev, disconnect_rsp, &sk); in mgmt_device_disconnected()
9777 if (hdev->suspended) in mgmt_device_disconnected()
9780 mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev), sk); in mgmt_device_disconnected()
9785 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_device_disconnected()
9786 hdev); in mgmt_device_disconnected()
9789 void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_disconnect_failed() argument
9796 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_disconnect_failed()
9797 hdev); in mgmt_disconnect_failed()
9799 cmd = pending_find(MGMT_OP_DISCONNECT, hdev); in mgmt_disconnect_failed()
9815 void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_connect_failed() argument
9823 if (mgmt_powering_down(hdev) && hci_conn_count(hdev) == 1) { in mgmt_connect_failed()
9824 cancel_delayed_work(&hdev->power_off); in mgmt_connect_failed()
9825 queue_work(hdev->req_workqueue, &hdev->power_off.work); in mgmt_connect_failed()
9832 mgmt_event(MGMT_EV_CONNECT_FAILED, hdev, &ev, sizeof(ev), NULL); in mgmt_connect_failed()
9835 void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure) in mgmt_pin_code_request() argument
9843 mgmt_event(MGMT_EV_PIN_CODE_REQUEST, hdev, &ev, sizeof(ev), NULL); in mgmt_pin_code_request()
9846 void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_reply_complete() argument
9851 cmd = pending_find(MGMT_OP_PIN_CODE_REPLY, hdev); in mgmt_pin_code_reply_complete()
9859 void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_neg_reply_complete() argument
9864 cmd = pending_find(MGMT_OP_PIN_CODE_NEG_REPLY, hdev); in mgmt_pin_code_neg_reply_complete()
9872 int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_request() argument
9878 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_confirm_request()
9885 return mgmt_event(MGMT_EV_USER_CONFIRM_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_confirm_request()
9889 int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_request() argument
9894 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_request()
9899 return mgmt_event(MGMT_EV_USER_PASSKEY_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_passkey_request()
9903 static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in user_pairing_resp_complete() argument
9909 cmd = pending_find(opcode, hdev); in user_pairing_resp_complete()
9919 int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_reply_complete() argument
9922 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_reply_complete()
9926 int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_neg_reply_complete() argument
9929 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_neg_reply_complete()
9934 int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_reply_complete() argument
9937 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_reply_complete()
9941 int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_neg_reply_complete() argument
9944 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_neg_reply_complete()
9949 int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_notify() argument
9955 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_notify()
9962 return mgmt_event(MGMT_EV_PASSKEY_NOTIFY, hdev, &ev, sizeof(ev), NULL); in mgmt_user_passkey_notify()
9977 mgmt_event(MGMT_EV_AUTH_FAILED, conn->hdev, &ev, sizeof(ev), in mgmt_auth_failed()
9986 void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status) in mgmt_auth_enable_complete() argument
9988 struct cmd_lookup match = { NULL, hdev }; in mgmt_auth_enable_complete()
9993 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, in mgmt_auth_enable_complete()
9998 if (test_bit(HCI_AUTH, &hdev->flags)) in mgmt_auth_enable_complete()
9999 changed = !hci_dev_test_and_set_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
10001 changed = hci_dev_test_and_clear_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
10003 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, settings_rsp, in mgmt_auth_enable_complete()
10007 new_settings(hdev, match.sk); in mgmt_auth_enable_complete()
10023 void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, in mgmt_set_class_of_dev_complete() argument
10026 struct cmd_lookup match = { NULL, hdev, mgmt_status(status) }; in mgmt_set_class_of_dev_complete()
10028 mgmt_pending_foreach(MGMT_OP_SET_DEV_CLASS, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
10029 mgmt_pending_foreach(MGMT_OP_ADD_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
10030 mgmt_pending_foreach(MGMT_OP_REMOVE_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
10033 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, dev_class, in mgmt_set_class_of_dev_complete()
10035 ext_info_changed(hdev, NULL); in mgmt_set_class_of_dev_complete()
10042 void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status) in mgmt_set_local_name_complete() argument
10052 memcpy(ev.short_name, hdev->short_name, HCI_MAX_SHORT_NAME_LENGTH); in mgmt_set_local_name_complete()
10054 cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev); in mgmt_set_local_name_complete()
10056 memcpy(hdev->dev_name, name, sizeof(hdev->dev_name)); in mgmt_set_local_name_complete()
10061 if (pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_local_name_complete()
10065 mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev, sizeof(ev), in mgmt_set_local_name_complete()
10067 ext_info_changed(hdev, cmd ? cmd->sk : NULL); in mgmt_set_local_name_complete()
10137 static void restart_le_scan(struct hci_dev *hdev) in restart_le_scan() argument
10140 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in restart_le_scan()
10144 hdev->discovery.scan_start + in restart_le_scan()
10145 hdev->discovery.scan_duration)) in restart_le_scan()
10148 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_restart, in restart_le_scan()
10152 static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir, in is_filter_match() argument
10164 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
10166 (rssi < hdev->discovery.rssi && in is_filter_match()
10167 !test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)))) in is_filter_match()
10170 if (hdev->discovery.uuid_count != 0) { in is_filter_match()
10174 if (!eir_has_uuids(eir, eir_len, hdev->discovery.uuid_count, in is_filter_match()
10175 hdev->discovery.uuids) && in is_filter_match()
10177 hdev->discovery.uuid_count, in is_filter_match()
10178 hdev->discovery.uuids)) in is_filter_match()
10185 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)) { in is_filter_match()
10186 restart_le_scan(hdev); in is_filter_match()
10189 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
10190 rssi < hdev->discovery.rssi) in is_filter_match()
10197 void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle, in mgmt_adv_monitor_device_lost() argument
10206 mgmt_event(MGMT_EV_ADV_MONITOR_DEVICE_LOST, hdev, &ev, sizeof(ev), in mgmt_adv_monitor_device_lost()
10210 static void mgmt_send_adv_monitor_device_found(struct hci_dev *hdev, in mgmt_send_adv_monitor_device_found() argument
10224 advmon_skb = mgmt_alloc_skb(hdev, MGMT_EV_ADV_MONITOR_DEVICE_FOUND, in mgmt_send_adv_monitor_device_found()
10240 static void mgmt_adv_monitor_device_found(struct hci_dev *hdev, in mgmt_adv_monitor_device_found() argument
10264 if (report_device && !hdev->advmon_pend_notify) { in mgmt_adv_monitor_device_found()
10269 hdev->advmon_pend_notify = false; in mgmt_adv_monitor_device_found()
10271 list_for_each_entry_safe(dev, tmp, &hdev->monitored_devices, list) { in mgmt_adv_monitor_device_found()
10276 mgmt_send_adv_monitor_device_found(hdev, skb, in mgmt_adv_monitor_device_found()
10285 hdev->advmon_pend_notify = true; in mgmt_adv_monitor_device_found()
10289 ((matched && !notified) || !msft_monitor_supported(hdev))) { in mgmt_adv_monitor_device_found()
10295 mgmt_send_adv_monitor_device_found(hdev, skb, skip_sk, 0); in mgmt_adv_monitor_device_found()
10304 static void mesh_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, in mesh_device_found() argument
10313 if (!hdev->mesh_ad_types[0]) in mesh_device_found()
10319 for (j = 0; j < sizeof(hdev->mesh_ad_types); j++) { in mesh_device_found()
10320 if (!hdev->mesh_ad_types[j]) in mesh_device_found()
10323 if (hdev->mesh_ad_types[j] == eir[i + 1]) in mesh_device_found()
10331 for (j = 0; j < sizeof(hdev->mesh_ad_types); j++) { in mesh_device_found()
10332 if (!hdev->mesh_ad_types[j]) in mesh_device_found()
10335 if (hdev->mesh_ad_types[j] == scan_rsp[i + 1]) in mesh_device_found()
10344 skb = mgmt_alloc_skb(hdev, MGMT_EV_MESH_DEVICE_FOUND, in mesh_device_found()
10370 void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_device_found() argument
10377 bool report_device = hci_discovery_active(hdev); in mgmt_device_found()
10379 if (hci_dev_test_flag(hdev, HCI_MESH) && link_type == LE_LINK) in mgmt_device_found()
10380 mesh_device_found(hdev, bdaddr, addr_type, rssi, flags, in mgmt_device_found()
10388 if (!hci_discovery_active(hdev)) { in mgmt_device_found()
10391 if (link_type == LE_LINK && !list_empty(&hdev->pend_le_reports)) in mgmt_device_found()
10393 else if (!hci_is_adv_monitoring(hdev)) in mgmt_device_found()
10397 if (hdev->discovery.result_filtering) { in mgmt_device_found()
10399 if (!is_filter_match(hdev, rssi, eir, eir_len, scan_rsp, in mgmt_device_found()
10404 if (hdev->discovery.limited) { in mgmt_device_found()
10417 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, in mgmt_device_found()
10432 if (rssi == HCI_RSSI_INVALID && !hdev->discovery.report_invalid_rssi && in mgmt_device_found()
10459 mgmt_adv_monitor_device_found(hdev, bdaddr, report_device, skb, NULL); in mgmt_device_found()
10462 void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_remote_name() argument
10470 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, in mgmt_remote_name()
10489 void mgmt_discovering(struct hci_dev *hdev, u8 discovering) in mgmt_discovering() argument
10493 bt_dev_dbg(hdev, "discovering %u", discovering); in mgmt_discovering()
10496 ev.type = hdev->discovery.type; in mgmt_discovering()
10499 mgmt_event(MGMT_EV_DISCOVERING, hdev, &ev, sizeof(ev), NULL); in mgmt_discovering()
10502 void mgmt_suspending(struct hci_dev *hdev, u8 state) in mgmt_suspending() argument
10507 mgmt_event(MGMT_EV_CONTROLLER_SUSPEND, hdev, &ev, sizeof(ev), NULL); in mgmt_suspending()
10510 void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr, in mgmt_resuming() argument
10523 mgmt_event(MGMT_EV_CONTROLLER_RESUME, hdev, &ev, sizeof(ev), NULL); in mgmt_resuming()
10546 struct hci_dev *hdev; in mgmt_cleanup() local
10550 list_for_each_entry(hdev, &hci_dev_list, list) { in mgmt_cleanup()
10552 mesh_tx = mgmt_mesh_next(hdev, sk); in mgmt_cleanup()
10555 mesh_send_complete(hdev, mesh_tx, true); in mgmt_cleanup()