Lines Matching refs:hdev
322 static int mgmt_index_event(u16 event, struct hci_dev *hdev, void *data, in mgmt_index_event() argument
325 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_index_event()
329 static int mgmt_limited_event(u16 event, struct hci_dev *hdev, void *data, in mgmt_limited_event() argument
332 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_limited_event()
336 static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, u16 len, in mgmt_event() argument
339 return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, in mgmt_event()
365 static int read_version(struct sock *sk, struct hci_dev *hdev, void *data, in read_version() argument
370 bt_dev_dbg(hdev, "sock %p", sk); in read_version()
378 static int read_commands(struct sock *sk, struct hci_dev *hdev, void *data, in read_commands() argument
386 bt_dev_dbg(hdev, "sock %p", sk); in read_commands()
430 static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data, in read_index_list() argument
439 bt_dev_dbg(hdev, "sock %p", sk); in read_index_list()
471 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_index_list()
488 static int read_unconf_index_list(struct sock *sk, struct hci_dev *hdev, in read_unconf_index_list() argument
497 bt_dev_dbg(hdev, "sock %p", sk); in read_unconf_index_list()
529 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_unconf_index_list()
546 static int read_ext_index_list(struct sock *sk, struct hci_dev *hdev, in read_ext_index_list() argument
554 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_index_list()
588 bt_dev_dbg(hdev, "Added hci%u", d->id); in read_ext_index_list()
612 static bool is_configured(struct hci_dev *hdev) in is_configured() argument
614 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in is_configured()
615 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in is_configured()
618 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in is_configured()
619 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in is_configured()
620 !bacmp(&hdev->public_addr, BDADDR_ANY)) in is_configured()
626 static __le32 get_missing_options(struct hci_dev *hdev) in get_missing_options() argument
630 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) && in get_missing_options()
631 !hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED)) in get_missing_options()
634 if ((test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in get_missing_options()
635 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) && in get_missing_options()
636 !bacmp(&hdev->public_addr, BDADDR_ANY)) in get_missing_options()
642 static int new_options(struct hci_dev *hdev, struct sock *skip) in new_options() argument
644 __le32 options = get_missing_options(hdev); in new_options()
646 return mgmt_limited_event(MGMT_EV_NEW_CONFIG_OPTIONS, hdev, &options, in new_options()
650 static int send_options_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_options_rsp() argument
652 __le32 options = get_missing_options(hdev); in send_options_rsp()
654 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &options, in send_options_rsp()
658 static int read_config_info(struct sock *sk, struct hci_dev *hdev, in read_config_info() argument
664 bt_dev_dbg(hdev, "sock %p", sk); in read_config_info()
666 hci_dev_lock(hdev); in read_config_info()
669 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_config_info()
671 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in read_config_info()
674 if (hdev->set_bdaddr) in read_config_info()
678 rp.missing_options = get_missing_options(hdev); in read_config_info()
680 hci_dev_unlock(hdev); in read_config_info()
682 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONFIG_INFO, 0, in read_config_info()
686 static u32 get_supported_phys(struct hci_dev *hdev) in get_supported_phys() argument
690 if (lmp_bredr_capable(hdev)) { in get_supported_phys()
693 if (hdev->features[0][0] & LMP_3SLOT) in get_supported_phys()
696 if (hdev->features[0][0] & LMP_5SLOT) in get_supported_phys()
699 if (lmp_edr_2m_capable(hdev)) { in get_supported_phys()
702 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
705 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
708 if (lmp_edr_3m_capable(hdev)) { in get_supported_phys()
711 if (lmp_edr_3slot_capable(hdev)) in get_supported_phys()
714 if (lmp_edr_5slot_capable(hdev)) in get_supported_phys()
720 if (lmp_le_capable(hdev)) { in get_supported_phys()
724 if (hdev->le_features[1] & HCI_LE_PHY_2M) { in get_supported_phys()
729 if (hdev->le_features[1] & HCI_LE_PHY_CODED) { in get_supported_phys()
738 static u32 get_selected_phys(struct hci_dev *hdev) in get_selected_phys() argument
742 if (lmp_bredr_capable(hdev)) { in get_selected_phys()
745 if (hdev->pkt_type & (HCI_DM3 | HCI_DH3)) in get_selected_phys()
748 if (hdev->pkt_type & (HCI_DM5 | HCI_DH5)) in get_selected_phys()
751 if (lmp_edr_2m_capable(hdev)) { in get_selected_phys()
752 if (!(hdev->pkt_type & HCI_2DH1)) in get_selected_phys()
755 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
756 !(hdev->pkt_type & HCI_2DH3)) in get_selected_phys()
759 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
760 !(hdev->pkt_type & HCI_2DH5)) in get_selected_phys()
763 if (lmp_edr_3m_capable(hdev)) { in get_selected_phys()
764 if (!(hdev->pkt_type & HCI_3DH1)) in get_selected_phys()
767 if (lmp_edr_3slot_capable(hdev) && in get_selected_phys()
768 !(hdev->pkt_type & HCI_3DH3)) in get_selected_phys()
771 if (lmp_edr_5slot_capable(hdev) && in get_selected_phys()
772 !(hdev->pkt_type & HCI_3DH5)) in get_selected_phys()
778 if (lmp_le_capable(hdev)) { in get_selected_phys()
779 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
782 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_1M) in get_selected_phys()
785 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
788 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_2M) in get_selected_phys()
791 if (hdev->le_tx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
794 if (hdev->le_rx_def_phys & HCI_LE_SET_PHY_CODED) in get_selected_phys()
801 static u32 get_configurable_phys(struct hci_dev *hdev) in get_configurable_phys() argument
803 return (get_supported_phys(hdev) & ~MGMT_PHY_BR_1M_1SLOT & in get_configurable_phys()
807 static u32 get_supported_settings(struct hci_dev *hdev) in get_supported_settings() argument
817 if (lmp_bredr_capable(hdev)) { in get_supported_settings()
818 if (hdev->hci_ver >= BLUETOOTH_VER_1_2) in get_supported_settings()
823 if (lmp_ssp_capable(hdev)) { in get_supported_settings()
827 if (lmp_sc_capable(hdev)) in get_supported_settings()
831 &hdev->quirks)) in get_supported_settings()
835 if (lmp_le_capable(hdev)) { in get_supported_settings()
843 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in get_supported_settings()
844 hdev->set_bdaddr) in get_supported_settings()
847 if (cis_central_capable(hdev)) in get_supported_settings()
850 if (cis_peripheral_capable(hdev)) in get_supported_settings()
858 static u32 get_current_settings(struct hci_dev *hdev) in get_current_settings() argument
862 if (hdev_is_powered(hdev)) in get_current_settings()
865 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in get_current_settings()
868 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in get_current_settings()
871 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in get_current_settings()
874 if (hci_dev_test_flag(hdev, HCI_BONDABLE)) in get_current_settings()
877 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in get_current_settings()
880 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in get_current_settings()
883 if (hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) in get_current_settings()
886 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in get_current_settings()
889 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in get_current_settings()
892 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) in get_current_settings()
895 if (hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) in get_current_settings()
898 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in get_current_settings()
913 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in get_current_settings()
914 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in get_current_settings()
915 !bacmp(&hdev->bdaddr, BDADDR_ANY)) { in get_current_settings()
916 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in get_current_settings()
920 if (hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED)) in get_current_settings()
923 if (cis_central_capable(hdev)) in get_current_settings()
926 if (cis_peripheral_capable(hdev)) in get_current_settings()
929 if (bis_capable(hdev)) in get_current_settings()
932 if (sync_recv_capable(hdev)) in get_current_settings()
938 static struct mgmt_pending_cmd *pending_find(u16 opcode, struct hci_dev *hdev) in pending_find() argument
940 return mgmt_pending_find(HCI_CHANNEL_CONTROL, opcode, hdev); in pending_find()
943 u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev) in mgmt_get_adv_discov_flags() argument
950 cmd = pending_find(MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_get_adv_discov_flags()
958 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
960 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in mgmt_get_adv_discov_flags()
967 bool mgmt_get_connectable(struct hci_dev *hdev) in mgmt_get_connectable() argument
974 cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_get_connectable()
981 return hci_dev_test_flag(hdev, HCI_CONNECTABLE); in mgmt_get_connectable()
984 static int service_cache_sync(struct hci_dev *hdev, void *data) in service_cache_sync() argument
986 hci_update_eir_sync(hdev); in service_cache_sync()
987 hci_update_class_sync(hdev); in service_cache_sync()
994 struct hci_dev *hdev = container_of(work, struct hci_dev, in service_cache_off() local
997 if (!hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in service_cache_off()
1000 hci_cmd_sync_queue(hdev, service_cache_sync, NULL, NULL); in service_cache_off()
1003 static int rpa_expired_sync(struct hci_dev *hdev, void *data) in rpa_expired_sync() argument
1009 if (ext_adv_capable(hdev)) in rpa_expired_sync()
1010 return hci_start_ext_adv_sync(hdev, hdev->cur_adv_instance); in rpa_expired_sync()
1012 return hci_enable_advertising_sync(hdev); in rpa_expired_sync()
1017 struct hci_dev *hdev = container_of(work, struct hci_dev, in rpa_expired() local
1020 bt_dev_dbg(hdev, ""); in rpa_expired()
1022 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in rpa_expired()
1024 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING)) in rpa_expired()
1027 hci_cmd_sync_queue(hdev, rpa_expired_sync, NULL, NULL); in rpa_expired()
1030 static int set_discoverable_sync(struct hci_dev *hdev, void *data);
1034 struct hci_dev *hdev = container_of(work, struct hci_dev, in discov_off() local
1037 bt_dev_dbg(hdev, ""); in discov_off()
1039 hci_dev_lock(hdev); in discov_off()
1046 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in discov_off()
1047 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in discov_off()
1048 hdev->discov_timeout = 0; in discov_off()
1050 hci_cmd_sync_queue(hdev, set_discoverable_sync, NULL, NULL); in discov_off()
1052 mgmt_new_settings(hdev); in discov_off()
1054 hci_dev_unlock(hdev); in discov_off()
1057 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev);
1059 static void mesh_send_complete(struct hci_dev *hdev, in mesh_send_complete() argument
1065 mgmt_event(MGMT_EV_MESH_PACKET_CMPLT, hdev, &handle, in mesh_send_complete()
1071 static int mesh_send_done_sync(struct hci_dev *hdev, void *data) in mesh_send_done_sync() argument
1075 hci_dev_clear_flag(hdev, HCI_MESH_SENDING); in mesh_send_done_sync()
1076 hci_disable_advertising_sync(hdev); in mesh_send_done_sync()
1077 mesh_tx = mgmt_mesh_next(hdev, NULL); in mesh_send_done_sync()
1080 mesh_send_complete(hdev, mesh_tx, false); in mesh_send_done_sync()
1085 static int mesh_send_sync(struct hci_dev *hdev, void *data);
1086 static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err);
1087 static void mesh_next(struct hci_dev *hdev, void *data, int err) in mesh_next() argument
1089 struct mgmt_mesh_tx *mesh_tx = mgmt_mesh_next(hdev, NULL); in mesh_next()
1094 err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx, in mesh_next()
1098 mesh_send_complete(hdev, mesh_tx, false); in mesh_next()
1100 hci_dev_set_flag(hdev, HCI_MESH_SENDING); in mesh_next()
1105 struct hci_dev *hdev = container_of(work, struct hci_dev, in mesh_send_done() local
1108 if (!hci_dev_test_flag(hdev, HCI_MESH_SENDING)) in mesh_send_done()
1111 hci_cmd_sync_queue(hdev, mesh_send_done_sync, NULL, mesh_next); in mesh_send_done()
1114 static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev) in mgmt_init_hdev() argument
1116 if (hci_dev_test_flag(hdev, HCI_MGMT)) in mgmt_init_hdev()
1121 INIT_DELAYED_WORK(&hdev->discov_off, discov_off); in mgmt_init_hdev()
1122 INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off); in mgmt_init_hdev()
1123 INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired); in mgmt_init_hdev()
1124 INIT_DELAYED_WORK(&hdev->mesh_send_done, mesh_send_done); in mgmt_init_hdev()
1131 hci_dev_clear_flag(hdev, HCI_BONDABLE); in mgmt_init_hdev()
1133 hci_dev_set_flag(hdev, HCI_MGMT); in mgmt_init_hdev()
1136 static int read_controller_info(struct sock *sk, struct hci_dev *hdev, in read_controller_info() argument
1141 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_info()
1143 hci_dev_lock(hdev); in read_controller_info()
1147 bacpy(&rp.bdaddr, &hdev->bdaddr); in read_controller_info()
1149 rp.version = hdev->hci_ver; in read_controller_info()
1150 rp.manufacturer = cpu_to_le16(hdev->manufacturer); in read_controller_info()
1152 rp.supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_controller_info()
1153 rp.current_settings = cpu_to_le32(get_current_settings(hdev)); in read_controller_info()
1155 memcpy(rp.dev_class, hdev->dev_class, 3); in read_controller_info()
1157 memcpy(rp.name, hdev->dev_name, sizeof(hdev->dev_name)); in read_controller_info()
1158 memcpy(rp.short_name, hdev->short_name, sizeof(hdev->short_name)); in read_controller_info()
1160 hci_dev_unlock(hdev); in read_controller_info()
1162 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_INFO, 0, &rp, in read_controller_info()
1166 static u16 append_eir_data_to_buf(struct hci_dev *hdev, u8 *eir) in append_eir_data_to_buf() argument
1171 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in append_eir_data_to_buf()
1173 hdev->dev_class, 3); in append_eir_data_to_buf()
1175 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in append_eir_data_to_buf()
1177 hdev->appearance); in append_eir_data_to_buf()
1179 name_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name)); in append_eir_data_to_buf()
1181 hdev->dev_name, name_len); in append_eir_data_to_buf()
1183 name_len = strnlen(hdev->short_name, sizeof(hdev->short_name)); in append_eir_data_to_buf()
1185 hdev->short_name, name_len); in append_eir_data_to_buf()
1190 static int read_ext_controller_info(struct sock *sk, struct hci_dev *hdev, in read_ext_controller_info() argument
1197 bt_dev_dbg(hdev, "sock %p", sk); in read_ext_controller_info()
1201 hci_dev_lock(hdev); in read_ext_controller_info()
1203 bacpy(&rp->bdaddr, &hdev->bdaddr); in read_ext_controller_info()
1205 rp->version = hdev->hci_ver; in read_ext_controller_info()
1206 rp->manufacturer = cpu_to_le16(hdev->manufacturer); in read_ext_controller_info()
1208 rp->supported_settings = cpu_to_le32(get_supported_settings(hdev)); in read_ext_controller_info()
1209 rp->current_settings = cpu_to_le32(get_current_settings(hdev)); in read_ext_controller_info()
1212 eir_len = append_eir_data_to_buf(hdev, rp->eir); in read_ext_controller_info()
1215 hci_dev_unlock(hdev); in read_ext_controller_info()
1226 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_EXT_INFO, 0, rp, in read_ext_controller_info()
1230 static int ext_info_changed(struct hci_dev *hdev, struct sock *skip) in ext_info_changed() argument
1238 eir_len = append_eir_data_to_buf(hdev, ev->eir); in ext_info_changed()
1241 return mgmt_limited_event(MGMT_EV_EXT_INFO_CHANGED, hdev, ev, in ext_info_changed()
1246 static int send_settings_rsp(struct sock *sk, u16 opcode, struct hci_dev *hdev) in send_settings_rsp() argument
1248 __le32 settings = cpu_to_le32(get_current_settings(hdev)); in send_settings_rsp()
1250 return mgmt_cmd_complete(sk, hdev->id, opcode, 0, &settings, in send_settings_rsp()
1254 void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev, u8 instance) in mgmt_advertising_added() argument
1260 mgmt_event(MGMT_EV_ADVERTISING_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_added()
1263 void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev, in mgmt_advertising_removed() argument
1270 mgmt_event(MGMT_EV_ADVERTISING_REMOVED, hdev, &ev, sizeof(ev), sk); in mgmt_advertising_removed()
1273 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
1275 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
1276 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
1277 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
1282 static void restart_le_actions(struct hci_dev *hdev) in restart_le_actions() argument
1286 list_for_each_entry(p, &hdev->le_conn_params, list) { in restart_le_actions()
1295 hci_pend_le_list_add(p, &hdev->pend_le_conns); in restart_le_actions()
1298 hci_pend_le_list_add(p, &hdev->pend_le_reports); in restart_le_actions()
1306 static int new_settings(struct hci_dev *hdev, struct sock *skip) in new_settings() argument
1308 __le32 ev = cpu_to_le32(get_current_settings(hdev)); in new_settings()
1310 return mgmt_limited_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, in new_settings()
1314 static void mgmt_set_powered_complete(struct hci_dev *hdev, void *data, int err) in mgmt_set_powered_complete() argument
1320 if (cmd != pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_powered_complete()
1325 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_powered_complete()
1329 hci_dev_lock(hdev); in mgmt_set_powered_complete()
1330 restart_le_actions(hdev); in mgmt_set_powered_complete()
1331 hci_update_passive_scan(hdev); in mgmt_set_powered_complete()
1332 hci_dev_unlock(hdev); in mgmt_set_powered_complete()
1335 send_settings_rsp(cmd->sk, cmd->opcode, hdev); in mgmt_set_powered_complete()
1341 new_settings(hdev, cmd->sk); in mgmt_set_powered_complete()
1343 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, in mgmt_set_powered_complete()
1350 static int set_powered_sync(struct hci_dev *hdev, void *data) in set_powered_sync() argument
1355 BT_DBG("%s", hdev->name); in set_powered_sync()
1357 return hci_set_powered_sync(hdev, cp->val); in set_powered_sync()
1360 static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, in set_powered() argument
1367 bt_dev_dbg(hdev, "sock %p", sk); in set_powered()
1370 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1373 hci_dev_lock(hdev); in set_powered()
1376 if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) { in set_powered()
1377 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1383 if (pending_find(MGMT_OP_SET_POWERED, hdev)) { in set_powered()
1384 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_POWERED, in set_powered()
1389 if (!!cp->val == hdev_is_powered(hdev)) { in set_powered()
1390 err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev); in set_powered()
1394 cmd = mgmt_pending_add(sk, MGMT_OP_SET_POWERED, hdev, data, len); in set_powered()
1402 hci_cmd_sync_cancel_sync(hdev, -EHOSTDOWN); in set_powered()
1403 err = hci_cmd_sync_queue(hdev, set_powered_sync, cmd, in set_powered()
1407 err = hci_cmd_sync_submit(hdev, set_powered_sync, cmd, in set_powered()
1415 hci_dev_unlock(hdev); in set_powered()
1419 int mgmt_new_settings(struct hci_dev *hdev) in mgmt_new_settings() argument
1421 return new_settings(hdev, NULL); in mgmt_new_settings()
1426 struct hci_dev *hdev; member
1434 send_settings_rsp(cmd->sk, cmd->opcode, match->hdev); in settings_rsp()
1461 hci_cmd_sync_dequeue(match->hdev, NULL, cmd, NULL); in cmd_complete_rsp()
1485 static u8 mgmt_bredr_support(struct hci_dev *hdev) in mgmt_bredr_support() argument
1487 if (!lmp_bredr_capable(hdev)) in mgmt_bredr_support()
1489 else if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in mgmt_bredr_support()
1495 static u8 mgmt_le_support(struct hci_dev *hdev) in mgmt_le_support() argument
1497 if (!lmp_le_capable(hdev)) in mgmt_le_support()
1499 else if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mgmt_le_support()
1505 static void mgmt_set_discoverable_complete(struct hci_dev *hdev, void *data, in mgmt_set_discoverable_complete() argument
1510 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_discoverable_complete()
1513 if (cmd != pending_find(MGMT_OP_SET_DISCOVERABLE, hdev)) in mgmt_set_discoverable_complete()
1516 hci_dev_lock(hdev); in mgmt_set_discoverable_complete()
1521 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in mgmt_set_discoverable_complete()
1525 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in mgmt_set_discoverable_complete()
1526 hdev->discov_timeout > 0) { in mgmt_set_discoverable_complete()
1527 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in mgmt_set_discoverable_complete()
1528 queue_delayed_work(hdev->req_workqueue, &hdev->discov_off, to); in mgmt_set_discoverable_complete()
1531 send_settings_rsp(cmd->sk, MGMT_OP_SET_DISCOVERABLE, hdev); in mgmt_set_discoverable_complete()
1532 new_settings(hdev, cmd->sk); in mgmt_set_discoverable_complete()
1536 hci_dev_unlock(hdev); in mgmt_set_discoverable_complete()
1539 static int set_discoverable_sync(struct hci_dev *hdev, void *data) in set_discoverable_sync() argument
1541 BT_DBG("%s", hdev->name); in set_discoverable_sync()
1543 return hci_update_discoverable_sync(hdev); in set_discoverable_sync()
1546 static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, in set_discoverable() argument
1554 bt_dev_dbg(hdev, "sock %p", sk); in set_discoverable()
1556 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_discoverable()
1557 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_discoverable()
1558 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1562 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1572 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1575 hci_dev_lock(hdev); in set_discoverable()
1577 if (!hdev_is_powered(hdev) && timeout > 0) { in set_discoverable()
1578 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1583 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_discoverable()
1584 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_discoverable()
1585 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1590 if (!hci_dev_test_flag(hdev, HCI_CONNECTABLE)) { in set_discoverable()
1591 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1596 if (hdev->advertising_paused) { in set_discoverable()
1597 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, in set_discoverable()
1602 if (!hdev_is_powered(hdev)) { in set_discoverable()
1609 if (!!cp->val != hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) { in set_discoverable()
1610 hci_dev_change_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1614 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1619 err = new_settings(hdev, sk); in set_discoverable()
1628 if (!!cp->val == hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in set_discoverable()
1629 (cp->val == 0x02) == hci_dev_test_flag(hdev, in set_discoverable()
1631 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1632 hdev->discov_timeout = timeout; in set_discoverable()
1634 if (cp->val && hdev->discov_timeout > 0) { in set_discoverable()
1635 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); in set_discoverable()
1636 queue_delayed_work(hdev->req_workqueue, in set_discoverable()
1637 &hdev->discov_off, to); in set_discoverable()
1640 err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev); in set_discoverable()
1644 cmd = mgmt_pending_add(sk, MGMT_OP_SET_DISCOVERABLE, hdev, data, len); in set_discoverable()
1654 cancel_delayed_work(&hdev->discov_off); in set_discoverable()
1655 hdev->discov_timeout = timeout; in set_discoverable()
1658 hci_dev_set_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1660 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_discoverable()
1664 hci_dev_set_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1666 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_discoverable()
1668 err = hci_cmd_sync_queue(hdev, set_discoverable_sync, cmd, in set_discoverable()
1675 hci_dev_unlock(hdev); in set_discoverable()
1679 static void mgmt_set_connectable_complete(struct hci_dev *hdev, void *data, in mgmt_set_connectable_complete() argument
1684 bt_dev_dbg(hdev, "err %d", err); in mgmt_set_connectable_complete()
1687 if (cmd != pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) in mgmt_set_connectable_complete()
1690 hci_dev_lock(hdev); in mgmt_set_connectable_complete()
1698 send_settings_rsp(cmd->sk, MGMT_OP_SET_CONNECTABLE, hdev); in mgmt_set_connectable_complete()
1699 new_settings(hdev, cmd->sk); in mgmt_set_connectable_complete()
1704 hci_dev_unlock(hdev); in mgmt_set_connectable_complete()
1707 static int set_connectable_update_settings(struct hci_dev *hdev, in set_connectable_update_settings() argument
1713 if (!!val != hci_dev_test_flag(hdev, HCI_CONNECTABLE)) in set_connectable_update_settings()
1717 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1719 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable_update_settings()
1720 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable_update_settings()
1723 err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev); in set_connectable_update_settings()
1728 hci_update_scan(hdev); in set_connectable_update_settings()
1729 hci_update_passive_scan(hdev); in set_connectable_update_settings()
1730 return new_settings(hdev, sk); in set_connectable_update_settings()
1736 static int set_connectable_sync(struct hci_dev *hdev, void *data) in set_connectable_sync() argument
1738 BT_DBG("%s", hdev->name); in set_connectable_sync()
1740 return hci_update_connectable_sync(hdev); in set_connectable_sync()
1743 static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data, in set_connectable() argument
1750 bt_dev_dbg(hdev, "sock %p", sk); in set_connectable()
1752 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in set_connectable()
1753 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in set_connectable()
1754 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1758 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1761 hci_dev_lock(hdev); in set_connectable()
1763 if (!hdev_is_powered(hdev)) { in set_connectable()
1764 err = set_connectable_update_settings(hdev, sk, cp->val); in set_connectable()
1768 if (pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || in set_connectable()
1769 pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { in set_connectable()
1770 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, in set_connectable()
1775 cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len); in set_connectable()
1782 hci_dev_set_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1784 if (hdev->discov_timeout > 0) in set_connectable()
1785 cancel_delayed_work(&hdev->discov_off); in set_connectable()
1787 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in set_connectable()
1788 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_connectable()
1789 hci_dev_clear_flag(hdev, HCI_CONNECTABLE); in set_connectable()
1792 err = hci_cmd_sync_queue(hdev, set_connectable_sync, cmd, in set_connectable()
1799 hci_dev_unlock(hdev); in set_connectable()
1803 static int set_bondable(struct sock *sk, struct hci_dev *hdev, void *data, in set_bondable() argument
1810 bt_dev_dbg(hdev, "sock %p", sk); in set_bondable()
1813 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BONDABLE, in set_bondable()
1816 hci_dev_lock(hdev); in set_bondable()
1819 changed = !hci_dev_test_and_set_flag(hdev, HCI_BONDABLE); in set_bondable()
1821 changed = hci_dev_test_and_clear_flag(hdev, HCI_BONDABLE); in set_bondable()
1823 err = send_settings_rsp(sk, MGMT_OP_SET_BONDABLE, hdev); in set_bondable()
1831 hci_update_discoverable(hdev); in set_bondable()
1833 err = new_settings(hdev, sk); in set_bondable()
1837 hci_dev_unlock(hdev); in set_bondable()
1841 static int set_link_security(struct sock *sk, struct hci_dev *hdev, void *data, in set_link_security() argument
1849 bt_dev_dbg(hdev, "sock %p", sk); in set_link_security()
1851 status = mgmt_bredr_support(hdev); in set_link_security()
1853 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1857 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1860 hci_dev_lock(hdev); in set_link_security()
1862 if (!hdev_is_powered(hdev)) { in set_link_security()
1865 if (!!cp->val != hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) { in set_link_security()
1866 hci_dev_change_flag(hdev, HCI_LINK_SECURITY); in set_link_security()
1870 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1875 err = new_settings(hdev, sk); in set_link_security()
1880 if (pending_find(MGMT_OP_SET_LINK_SECURITY, hdev)) { in set_link_security()
1881 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LINK_SECURITY, in set_link_security()
1888 if (test_bit(HCI_AUTH, &hdev->flags) == val) { in set_link_security()
1889 err = send_settings_rsp(sk, MGMT_OP_SET_LINK_SECURITY, hdev); in set_link_security()
1893 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LINK_SECURITY, hdev, data, len); in set_link_security()
1899 err = hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, sizeof(val), &val); in set_link_security()
1906 hci_dev_unlock(hdev); in set_link_security()
1910 static void set_ssp_complete(struct hci_dev *hdev, void *data, int err) in set_ssp_complete() argument
1912 struct cmd_lookup match = { NULL, hdev }; in set_ssp_complete()
1919 if (cmd != pending_find(MGMT_OP_SET_SSP, hdev)) in set_ssp_complete()
1925 if (enable && hci_dev_test_and_clear_flag(hdev, in set_ssp_complete()
1927 new_settings(hdev, NULL); in set_ssp_complete()
1930 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, cmd_status_rsp, in set_ssp_complete()
1936 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in set_ssp_complete()
1938 changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED); in set_ssp_complete()
1941 mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, settings_rsp, &match); in set_ssp_complete()
1944 new_settings(hdev, match.sk); in set_ssp_complete()
1949 hci_update_eir_sync(hdev); in set_ssp_complete()
1952 static int set_ssp_sync(struct hci_dev *hdev, void *data) in set_ssp_sync() argument
1960 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED); in set_ssp_sync()
1962 err = hci_write_ssp_mode_sync(hdev, cp->val); in set_ssp_sync()
1965 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_ssp_sync()
1970 static int set_ssp(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_ssp() argument
1977 bt_dev_dbg(hdev, "sock %p", sk); in set_ssp()
1979 status = mgmt_bredr_support(hdev); in set_ssp()
1981 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, status); in set_ssp()
1983 if (!lmp_ssp_capable(hdev)) in set_ssp()
1984 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1988 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
1991 hci_dev_lock(hdev); in set_ssp()
1993 if (!hdev_is_powered(hdev)) { in set_ssp()
1997 changed = !hci_dev_test_and_set_flag(hdev, in set_ssp()
2000 changed = hci_dev_test_and_clear_flag(hdev, in set_ssp()
2004 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
2009 err = new_settings(hdev, sk); in set_ssp()
2014 if (pending_find(MGMT_OP_SET_SSP, hdev)) { in set_ssp()
2015 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2020 if (!!cp->val == hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_ssp()
2021 err = send_settings_rsp(sk, MGMT_OP_SET_SSP, hdev); in set_ssp()
2025 cmd = mgmt_pending_add(sk, MGMT_OP_SET_SSP, hdev, data, len); in set_ssp()
2029 err = hci_cmd_sync_queue(hdev, set_ssp_sync, cmd, in set_ssp()
2033 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SSP, in set_ssp()
2041 hci_dev_unlock(hdev); in set_ssp()
2045 static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_hs() argument
2047 bt_dev_dbg(hdev, "sock %p", sk); in set_hs()
2049 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_HS, in set_hs()
2053 static void set_le_complete(struct hci_dev *hdev, void *data, int err) in set_le_complete() argument
2055 struct cmd_lookup match = { NULL, hdev }; in set_le_complete()
2058 bt_dev_dbg(hdev, "err %d", err); in set_le_complete()
2061 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, cmd_status_rsp, in set_le_complete()
2066 mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, settings_rsp, &match); in set_le_complete()
2068 new_settings(hdev, match.sk); in set_le_complete()
2074 static int set_le_sync(struct hci_dev *hdev, void *data) in set_le_sync() argument
2082 hci_clear_adv_instance_sync(hdev, NULL, 0x00, true); in set_le_sync()
2084 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_le_sync()
2085 hci_disable_advertising_sync(hdev); in set_le_sync()
2087 if (ext_adv_capable(hdev)) in set_le_sync()
2088 hci_remove_ext_adv_instance_sync(hdev, 0, cmd->sk); in set_le_sync()
2090 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in set_le_sync()
2093 err = hci_write_le_host_supported_sync(hdev, val, 0); in set_le_sync()
2100 if (!err && hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le_sync()
2101 if (ext_adv_capable(hdev)) { in set_le_sync()
2104 status = hci_setup_ext_adv_instance_sync(hdev, 0x00); in set_le_sync()
2106 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_le_sync()
2108 hci_update_adv_data_sync(hdev, 0x00); in set_le_sync()
2109 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_le_sync()
2112 hci_update_passive_scan(hdev); in set_le_sync()
2118 static void set_mesh_complete(struct hci_dev *hdev, void *data, int err) in set_mesh_complete() argument
2125 mgmt_pending_foreach(MGMT_OP_SET_MESH_RECEIVER, hdev, in set_mesh_complete()
2131 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, 0, NULL, 0); in set_mesh_complete()
2134 static int set_mesh_sync(struct hci_dev *hdev, void *data) in set_mesh_sync() argument
2140 memset(hdev->mesh_ad_types, 0, sizeof(hdev->mesh_ad_types)); in set_mesh_sync()
2143 hci_dev_set_flag(hdev, HCI_MESH); in set_mesh_sync()
2145 hci_dev_clear_flag(hdev, HCI_MESH); in set_mesh_sync()
2150 if (len <= sizeof(hdev->mesh_ad_types)) in set_mesh_sync()
2151 memcpy(hdev->mesh_ad_types, cp->ad_types, len); in set_mesh_sync()
2153 hci_update_passive_scan_sync(hdev); in set_mesh_sync()
2157 static int set_mesh(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_mesh() argument
2163 bt_dev_dbg(hdev, "sock %p", sk); in set_mesh()
2165 if (!lmp_le_capable(hdev) || in set_mesh()
2166 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in set_mesh()
2167 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2171 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2174 hci_dev_lock(hdev); in set_mesh()
2176 cmd = mgmt_pending_add(sk, MGMT_OP_SET_MESH_RECEIVER, hdev, data, len); in set_mesh()
2180 err = hci_cmd_sync_queue(hdev, set_mesh_sync, cmd, in set_mesh()
2184 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_MESH_RECEIVER, in set_mesh()
2191 hci_dev_unlock(hdev); in set_mesh()
2195 static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err) in mesh_send_start_complete() argument
2205 hci_dev_clear_flag(hdev, HCI_MESH_SENDING); in mesh_send_start_complete()
2207 mesh_send_complete(hdev, mesh_tx, false); in mesh_send_start_complete()
2212 queue_delayed_work(hdev->req_workqueue, &hdev->mesh_send_done, in mesh_send_start_complete()
2216 static int mesh_send_sync(struct hci_dev *hdev, void *data) in mesh_send_sync() argument
2221 u8 instance = hdev->le_num_of_adv_sets + 1; in mesh_send_sync()
2225 if (hdev->le_num_of_adv_sets <= hdev->adv_instance_cnt) in mesh_send_sync()
2229 duration = send->cnt * INTERVAL_TO_MS(hdev->le_adv_max_interval); in mesh_send_sync()
2230 adv = hci_add_adv_instance(hdev, instance, 0, in mesh_send_sync()
2235 hdev->le_adv_min_interval, in mesh_send_sync()
2236 hdev->le_adv_max_interval, in mesh_send_sync()
2244 if (hdev->cur_adv_instance == instance) { in mesh_send_sync()
2250 cancel_adv_timeout(hdev); in mesh_send_sync()
2252 next_instance = hci_get_next_instance(hdev, instance); in mesh_send_sync()
2257 } else if (hdev->adv_instance_timeout) { in mesh_send_sync()
2265 return hci_schedule_adv_instance_sync(hdev, instance, true); in mesh_send_sync()
2280 static int mesh_features(struct sock *sk, struct hci_dev *hdev, in mesh_features() argument
2285 if (!lmp_le_capable(hdev) || in mesh_features()
2286 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_features()
2287 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_READ_FEATURES, in mesh_features()
2291 rp.index = cpu_to_le16(hdev->id); in mesh_features()
2292 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mesh_features()
2295 hci_dev_lock(hdev); in mesh_features()
2298 mgmt_mesh_foreach(hdev, send_count, &rp, sk); in mesh_features()
2300 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_MESH_READ_FEATURES, 0, &rp, in mesh_features()
2303 hci_dev_unlock(hdev); in mesh_features()
2307 static int send_cancel(struct hci_dev *hdev, void *data) in send_cancel() argument
2315 mesh_tx = mgmt_mesh_next(hdev, cmd->sk); in send_cancel()
2318 mesh_send_complete(hdev, mesh_tx, false); in send_cancel()
2321 mesh_tx = mgmt_mesh_find(hdev, cancel->handle); in send_cancel()
2324 mesh_send_complete(hdev, mesh_tx, false); in send_cancel()
2327 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in send_cancel()
2334 static int mesh_send_cancel(struct sock *sk, struct hci_dev *hdev, in mesh_send_cancel() argument
2340 if (!lmp_le_capable(hdev) || in mesh_send_cancel()
2341 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_send_cancel()
2342 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2345 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in mesh_send_cancel()
2346 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2349 hci_dev_lock(hdev); in mesh_send_cancel()
2350 cmd = mgmt_pending_new(sk, MGMT_OP_MESH_SEND_CANCEL, hdev, data, len); in mesh_send_cancel()
2354 err = hci_cmd_sync_queue(hdev, send_cancel, cmd, NULL); in mesh_send_cancel()
2357 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND_CANCEL, in mesh_send_cancel()
2364 hci_dev_unlock(hdev); in mesh_send_cancel()
2368 static int mesh_send(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in mesh_send() argument
2376 if (!lmp_le_capable(hdev) || in mesh_send()
2377 !hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in mesh_send()
2378 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2380 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) || in mesh_send()
2383 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2386 hci_dev_lock(hdev); in mesh_send()
2391 mgmt_mesh_foreach(hdev, send_count, &rp, sk); in mesh_send()
2394 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2399 sending = hci_dev_test_flag(hdev, HCI_MESH_SENDING); in mesh_send()
2400 mesh_tx = mgmt_mesh_add(sk, hdev, send, len); in mesh_send()
2405 err = hci_cmd_sync_queue(hdev, mesh_send_sync, mesh_tx, in mesh_send()
2409 bt_dev_err(hdev, "Send Mesh Failed %d", err); in mesh_send()
2410 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND, in mesh_send()
2418 hci_dev_set_flag(hdev, HCI_MESH_SENDING); in mesh_send()
2420 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_MESH_SEND, 0, in mesh_send()
2425 hci_dev_unlock(hdev); in mesh_send()
2429 static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_le() argument
2436 bt_dev_dbg(hdev, "sock %p", sk); in set_le()
2438 if (!lmp_le_capable(hdev)) in set_le()
2439 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2443 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2455 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_le()
2457 return send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
2459 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2463 hci_dev_lock(hdev); in set_le()
2466 enabled = lmp_host_le_capable(hdev); in set_le()
2468 if (!hdev_is_powered(hdev) || val == enabled) { in set_le()
2471 if (val != hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in set_le()
2472 hci_dev_change_flag(hdev, HCI_LE_ENABLED); in set_le()
2476 if (!val && hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in set_le()
2477 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_le()
2481 err = send_settings_rsp(sk, MGMT_OP_SET_LE, hdev); in set_le()
2486 err = new_settings(hdev, sk); in set_le()
2491 if (pending_find(MGMT_OP_SET_LE, hdev) || in set_le()
2492 pending_find(MGMT_OP_SET_ADVERTISING, hdev)) { in set_le()
2493 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2498 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LE, hdev, data, len); in set_le()
2502 err = hci_cmd_sync_queue(hdev, set_le_sync, cmd, in set_le()
2506 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LE, in set_le()
2514 hci_dev_unlock(hdev); in set_le()
2524 static bool pending_eir_or_class(struct hci_dev *hdev) in pending_eir_or_class() argument
2528 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in pending_eir_or_class()
2560 static void mgmt_class_complete(struct hci_dev *hdev, void *data, int err) in mgmt_class_complete() argument
2564 bt_dev_dbg(hdev, "err %d", err); in mgmt_class_complete()
2567 mgmt_status(err), hdev->dev_class, 3); in mgmt_class_complete()
2572 static int add_uuid_sync(struct hci_dev *hdev, void *data) in add_uuid_sync() argument
2576 err = hci_update_class_sync(hdev); in add_uuid_sync()
2580 return hci_update_eir_sync(hdev); in add_uuid_sync()
2583 static int add_uuid(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in add_uuid() argument
2590 bt_dev_dbg(hdev, "sock %p", sk); in add_uuid()
2592 hci_dev_lock(hdev); in add_uuid()
2594 if (pending_eir_or_class(hdev)) { in add_uuid()
2595 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_UUID, in add_uuid()
2610 list_add_tail(&uuid->list, &hdev->uuids); in add_uuid()
2612 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_UUID, hdev, data, len); in add_uuid()
2621 err = hci_cmd_sync_submit(hdev, add_uuid_sync, cmd, in add_uuid()
2629 hci_dev_unlock(hdev); in add_uuid()
2633 static bool enable_service_cache(struct hci_dev *hdev) in enable_service_cache() argument
2635 if (!hdev_is_powered(hdev)) in enable_service_cache()
2638 if (!hci_dev_test_and_set_flag(hdev, HCI_SERVICE_CACHE)) { in enable_service_cache()
2639 queue_delayed_work(hdev->workqueue, &hdev->service_cache, in enable_service_cache()
2647 static int remove_uuid_sync(struct hci_dev *hdev, void *data) in remove_uuid_sync() argument
2651 err = hci_update_class_sync(hdev); in remove_uuid_sync()
2655 return hci_update_eir_sync(hdev); in remove_uuid_sync()
2658 static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data, in remove_uuid() argument
2669 bt_dev_dbg(hdev, "sock %p", sk); in remove_uuid()
2671 hci_dev_lock(hdev); in remove_uuid()
2673 if (pending_eir_or_class(hdev)) { in remove_uuid()
2674 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2680 hci_uuids_clear(hdev); in remove_uuid()
2682 if (enable_service_cache(hdev)) { in remove_uuid()
2683 err = mgmt_cmd_complete(sk, hdev->id, in remove_uuid()
2685 0, hdev->dev_class, 3); in remove_uuid()
2694 list_for_each_entry_safe(match, tmp, &hdev->uuids, list) { in remove_uuid()
2704 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_UUID, in remove_uuid()
2710 cmd = mgmt_pending_new(sk, MGMT_OP_REMOVE_UUID, hdev, data, len); in remove_uuid()
2719 err = hci_cmd_sync_submit(hdev, remove_uuid_sync, cmd, in remove_uuid()
2725 hci_dev_unlock(hdev); in remove_uuid()
2729 static int set_class_sync(struct hci_dev *hdev, void *data) in set_class_sync() argument
2733 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) { in set_class_sync()
2734 cancel_delayed_work_sync(&hdev->service_cache); in set_class_sync()
2735 err = hci_update_eir_sync(hdev); in set_class_sync()
2741 return hci_update_class_sync(hdev); in set_class_sync()
2744 static int set_dev_class(struct sock *sk, struct hci_dev *hdev, void *data, in set_dev_class() argument
2751 bt_dev_dbg(hdev, "sock %p", sk); in set_dev_class()
2753 if (!lmp_bredr_capable(hdev)) in set_dev_class()
2754 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2757 hci_dev_lock(hdev); in set_dev_class()
2759 if (pending_eir_or_class(hdev)) { in set_dev_class()
2760 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2766 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, in set_dev_class()
2771 hdev->major_class = cp->major; in set_dev_class()
2772 hdev->minor_class = cp->minor; in set_dev_class()
2774 if (!hdev_is_powered(hdev)) { in set_dev_class()
2775 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEV_CLASS, 0, in set_dev_class()
2776 hdev->dev_class, 3); in set_dev_class()
2780 cmd = mgmt_pending_new(sk, MGMT_OP_SET_DEV_CLASS, hdev, data, len); in set_dev_class()
2789 err = hci_cmd_sync_submit(hdev, set_class_sync, cmd, in set_dev_class()
2795 hci_dev_unlock(hdev); in set_dev_class()
2799 static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data, in load_link_keys() argument
2809 bt_dev_dbg(hdev, "sock %p", sk); in load_link_keys()
2811 if (!lmp_bredr_capable(hdev)) in load_link_keys()
2812 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2817 bt_dev_err(hdev, "load_link_keys: too big key_count value %u", in load_link_keys()
2819 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2825 bt_dev_err(hdev, "load_link_keys: expected %u bytes, got %u bytes", in load_link_keys()
2827 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2832 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, in load_link_keys()
2835 bt_dev_dbg(hdev, "debug_keys %u key_count %u", cp->debug_keys, in load_link_keys()
2838 hci_dev_lock(hdev); in load_link_keys()
2840 hci_link_keys_clear(hdev); in load_link_keys()
2843 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in load_link_keys()
2845 changed = hci_dev_test_and_clear_flag(hdev, in load_link_keys()
2849 new_settings(hdev, NULL); in load_link_keys()
2854 if (hci_is_blocked_key(hdev, in load_link_keys()
2857 bt_dev_warn(hdev, "Skipping blocked link key for %pMR", in load_link_keys()
2863 bt_dev_warn(hdev, in load_link_keys()
2870 bt_dev_warn(hdev, "Invalid link key type %u for %pMR", in load_link_keys()
2881 hci_add_link_key(hdev, NULL, &key->addr.bdaddr, key->val, in load_link_keys()
2885 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0); in load_link_keys()
2887 hci_dev_unlock(hdev); in load_link_keys()
2892 static int device_unpaired(struct hci_dev *hdev, bdaddr_t *bdaddr, in device_unpaired() argument
2900 return mgmt_event(MGMT_EV_DEVICE_UNPAIRED, hdev, &ev, sizeof(ev), in device_unpaired()
2904 static void unpair_device_complete(struct hci_dev *hdev, void *data, int err) in unpair_device_complete() argument
2910 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_complete()
2916 static int unpair_device_sync(struct hci_dev *hdev, void *data) in unpair_device_sync() argument
2923 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device_sync()
2926 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in unpair_device_sync()
2940 static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data, in unpair_device() argument
2956 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2961 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2965 hci_dev_lock(hdev); in unpair_device()
2967 if (!hdev_is_powered(hdev)) { in unpair_device()
2968 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
2983 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in unpair_device()
2988 err = hci_remove_link_key(hdev, &cp->addr.bdaddr); in unpair_device()
2990 err = mgmt_cmd_complete(sk, hdev->id, in unpair_device()
3004 err = smp_cancel_and_remove_pairing(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3006 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, in unpair_device()
3012 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3014 hci_conn_params_del(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3025 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, addr_type); in unpair_device()
3044 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNPAIR_DEVICE, 0, in unpair_device()
3046 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk); in unpair_device()
3050 cmd = mgmt_pending_new(sk, MGMT_OP_UNPAIR_DEVICE, hdev, cp, in unpair_device()
3059 err = hci_cmd_sync_queue(hdev, unpair_device_sync, cmd, in unpair_device()
3065 hci_dev_unlock(hdev); in unpair_device()
3069 static void disconnect_complete(struct hci_dev *hdev, void *data, int err) in disconnect_complete() argument
3077 static int disconnect_sync(struct hci_dev *hdev, void *data) in disconnect_sync() argument
3084 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in disconnect_sync()
3087 conn = hci_conn_hash_lookup_le(hdev, &cp->addr.bdaddr, in disconnect_sync()
3101 static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data, in disconnect() argument
3109 bt_dev_dbg(hdev, "sock %p", sk); in disconnect()
3116 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3120 hci_dev_lock(hdev); in disconnect()
3122 if (!test_bit(HCI_UP, &hdev->flags)) { in disconnect()
3123 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_DISCONNECT, in disconnect()
3129 cmd = mgmt_pending_new(sk, MGMT_OP_DISCONNECT, hdev, data, len); in disconnect()
3137 err = hci_cmd_sync_queue(hdev, disconnect_sync, cmd, in disconnect()
3143 hci_dev_unlock(hdev); in disconnect()
3167 static int get_connections(struct sock *sk, struct hci_dev *hdev, void *data, in get_connections() argument
3175 bt_dev_dbg(hdev, "sock %p", sk); in get_connections()
3177 hci_dev_lock(hdev); in get_connections()
3179 if (!hdev_is_powered(hdev)) { in get_connections()
3180 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, in get_connections()
3186 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
3198 list_for_each_entry(c, &hdev->conn_hash.list, list) { in get_connections()
3211 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONNECTIONS, 0, rp, in get_connections()
3217 hci_dev_unlock(hdev); in get_connections()
3221 static int send_pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in send_pin_code_neg_reply() argument
3227 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_NEG_REPLY, hdev, cp, in send_pin_code_neg_reply()
3234 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, in send_pin_code_neg_reply()
3242 static int pin_code_reply(struct sock *sk, struct hci_dev *hdev, void *data, in pin_code_reply() argument
3251 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_reply()
3253 hci_dev_lock(hdev); in pin_code_reply()
3255 if (!hdev_is_powered(hdev)) { in pin_code_reply()
3256 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3261 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in pin_code_reply()
3263 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3273 bt_dev_err(hdev, "PIN code is not 16 bytes long"); in pin_code_reply()
3275 err = send_pin_code_neg_reply(sk, hdev, &ncp); in pin_code_reply()
3277 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, in pin_code_reply()
3283 cmd = mgmt_pending_add(sk, MGMT_OP_PIN_CODE_REPLY, hdev, data, len); in pin_code_reply()
3295 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_REPLY, sizeof(reply), &reply); in pin_code_reply()
3300 hci_dev_unlock(hdev); in pin_code_reply()
3304 static int set_io_capability(struct sock *sk, struct hci_dev *hdev, void *data, in set_io_capability() argument
3309 bt_dev_dbg(hdev, "sock %p", sk); in set_io_capability()
3312 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, in set_io_capability()
3315 hci_dev_lock(hdev); in set_io_capability()
3317 hdev->io_capability = cp->io_capability; in set_io_capability()
3319 bt_dev_dbg(hdev, "IO capability set to 0x%02x", hdev->io_capability); in set_io_capability()
3321 hci_dev_unlock(hdev); in set_io_capability()
3323 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_IO_CAPABILITY, 0, in set_io_capability()
3329 struct hci_dev *hdev = conn->hdev; in find_pairing() local
3332 list_for_each_entry(cmd, &hdev->mgmt_pending, list) { in find_pairing()
3421 static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in pair_device() argument
3431 bt_dev_dbg(hdev, "sock %p", sk); in pair_device()
3438 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3443 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3447 hci_dev_lock(hdev); in pair_device()
3449 if (!hdev_is_powered(hdev)) { in pair_device()
3450 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3456 if (hci_bdaddr_is_paired(hdev, &cp->addr.bdaddr, cp->addr.type)) { in pair_device()
3457 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3467 conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level, in pair_device()
3483 p = hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type); in pair_device()
3492 conn = hci_connect_le_scan(hdev, &cp->addr.bdaddr, addr_type, in pair_device()
3509 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3516 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, in pair_device()
3521 cmd = mgmt_pending_add(sk, MGMT_OP_PAIR_DEVICE, hdev, data, len); in pair_device()
3553 hci_dev_unlock(hdev); in pair_device()
3557 static int cancel_pair_device(struct sock *sk, struct hci_dev *hdev, void *data, in cancel_pair_device() argument
3565 bt_dev_dbg(hdev, "sock %p", sk); in cancel_pair_device()
3567 hci_dev_lock(hdev); in cancel_pair_device()
3569 if (!hdev_is_powered(hdev)) { in cancel_pair_device()
3570 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3575 cmd = pending_find(MGMT_OP_PAIR_DEVICE, hdev); in cancel_pair_device()
3577 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3585 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, in cancel_pair_device()
3593 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CANCEL_PAIR_DEVICE, 0, in cancel_pair_device()
3601 hci_remove_link_key(hdev, &addr->bdaddr); in cancel_pair_device()
3603 smp_cancel_and_remove_pairing(hdev, &addr->bdaddr, in cancel_pair_device()
3610 hci_dev_unlock(hdev); in cancel_pair_device()
3614 static int user_pairing_resp(struct sock *sk, struct hci_dev *hdev, in user_pairing_resp() argument
3622 hci_dev_lock(hdev); in user_pairing_resp()
3624 if (!hdev_is_powered(hdev)) { in user_pairing_resp()
3625 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3632 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &addr->bdaddr); in user_pairing_resp()
3634 conn = hci_conn_hash_lookup_le(hdev, &addr->bdaddr, in user_pairing_resp()
3638 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3647 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3651 err = mgmt_cmd_complete(sk, hdev->id, mgmt_op, in user_pairing_resp()
3658 cmd = mgmt_pending_add(sk, mgmt_op, hdev, addr, sizeof(*addr)); in user_pairing_resp()
3672 err = hci_send_cmd(hdev, hci_op, sizeof(cp), &cp); in user_pairing_resp()
3674 err = hci_send_cmd(hdev, hci_op, sizeof(addr->bdaddr), in user_pairing_resp()
3681 hci_dev_unlock(hdev); in user_pairing_resp()
3685 static int pin_code_neg_reply(struct sock *sk, struct hci_dev *hdev, in pin_code_neg_reply() argument
3690 bt_dev_dbg(hdev, "sock %p", sk); in pin_code_neg_reply()
3692 return user_pairing_resp(sk, hdev, &cp->addr, in pin_code_neg_reply()
3697 static int user_confirm_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_confirm_reply() argument
3702 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_reply()
3705 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_USER_CONFIRM_REPLY, in user_confirm_reply()
3708 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_reply()
3713 static int user_confirm_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_confirm_neg_reply() argument
3718 bt_dev_dbg(hdev, "sock %p", sk); in user_confirm_neg_reply()
3720 return user_pairing_resp(sk, hdev, &cp->addr, in user_confirm_neg_reply()
3725 static int user_passkey_reply(struct sock *sk, struct hci_dev *hdev, void *data, in user_passkey_reply() argument
3730 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_reply()
3732 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_reply()
3737 static int user_passkey_neg_reply(struct sock *sk, struct hci_dev *hdev, in user_passkey_neg_reply() argument
3742 bt_dev_dbg(hdev, "sock %p", sk); in user_passkey_neg_reply()
3744 return user_pairing_resp(sk, hdev, &cp->addr, in user_passkey_neg_reply()
3749 static int adv_expire_sync(struct hci_dev *hdev, u32 flags) in adv_expire_sync() argument
3753 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in adv_expire_sync()
3761 cancel_adv_timeout(hdev); in adv_expire_sync()
3763 adv_instance = hci_get_next_instance(hdev, adv_instance->instance); in adv_expire_sync()
3767 hci_schedule_adv_instance_sync(hdev, adv_instance->instance, true); in adv_expire_sync()
3772 static int name_changed_sync(struct hci_dev *hdev, void *data) in name_changed_sync() argument
3774 return adv_expire_sync(hdev, MGMT_ADV_FLAG_LOCAL_NAME); in name_changed_sync()
3777 static void set_name_complete(struct hci_dev *hdev, void *data, int err) in set_name_complete() argument
3783 bt_dev_dbg(hdev, "err %d", err); in set_name_complete()
3785 if (cmd != pending_find(MGMT_OP_SET_LOCAL_NAME, hdev)) in set_name_complete()
3789 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_name_complete()
3792 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_name_complete()
3795 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_name_complete()
3796 hci_cmd_sync_queue(hdev, name_changed_sync, NULL, NULL); in set_name_complete()
3802 static int set_name_sync(struct hci_dev *hdev, void *data) in set_name_sync() argument
3804 if (lmp_bredr_capable(hdev)) { in set_name_sync()
3805 hci_update_name_sync(hdev); in set_name_sync()
3806 hci_update_eir_sync(hdev); in set_name_sync()
3812 if (lmp_le_capable(hdev) && hci_dev_test_flag(hdev, HCI_ADVERTISING)) in set_name_sync()
3813 hci_update_scan_rsp_data_sync(hdev, hdev->cur_adv_instance); in set_name_sync()
3818 static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data, in set_local_name() argument
3825 bt_dev_dbg(hdev, "sock %p", sk); in set_local_name()
3827 hci_dev_lock(hdev); in set_local_name()
3832 if (!memcmp(hdev->dev_name, cp->name, sizeof(hdev->dev_name)) && in set_local_name()
3833 !memcmp(hdev->short_name, cp->short_name, in set_local_name()
3834 sizeof(hdev->short_name))) { in set_local_name()
3835 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3840 memcpy(hdev->short_name, cp->short_name, sizeof(hdev->short_name)); in set_local_name()
3842 if (!hdev_is_powered(hdev)) { in set_local_name()
3843 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3845 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, in set_local_name()
3850 err = mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, data, in set_local_name()
3852 ext_info_changed(hdev, sk); in set_local_name()
3857 cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len); in set_local_name()
3861 err = hci_cmd_sync_queue(hdev, set_name_sync, cmd, in set_local_name()
3865 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, in set_local_name()
3874 memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name)); in set_local_name()
3877 hci_dev_unlock(hdev); in set_local_name()
3881 static int appearance_changed_sync(struct hci_dev *hdev, void *data) in appearance_changed_sync() argument
3883 return adv_expire_sync(hdev, MGMT_ADV_FLAG_APPEARANCE); in appearance_changed_sync()
3886 static int set_appearance(struct sock *sk, struct hci_dev *hdev, void *data, in set_appearance() argument
3893 bt_dev_dbg(hdev, "sock %p", sk); in set_appearance()
3895 if (!lmp_le_capable(hdev)) in set_appearance()
3896 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_APPEARANCE, in set_appearance()
3901 hci_dev_lock(hdev); in set_appearance()
3903 if (hdev->appearance != appearance) { in set_appearance()
3904 hdev->appearance = appearance; in set_appearance()
3906 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_appearance()
3907 hci_cmd_sync_queue(hdev, appearance_changed_sync, NULL, in set_appearance()
3910 ext_info_changed(hdev, sk); in set_appearance()
3913 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_APPEARANCE, 0, NULL, in set_appearance()
3916 hci_dev_unlock(hdev); in set_appearance()
3921 static int get_phy_configuration(struct sock *sk, struct hci_dev *hdev, in get_phy_configuration() argument
3926 bt_dev_dbg(hdev, "sock %p", sk); in get_phy_configuration()
3928 hci_dev_lock(hdev); in get_phy_configuration()
3932 rp.supported_phys = cpu_to_le32(get_supported_phys(hdev)); in get_phy_configuration()
3933 rp.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in get_phy_configuration()
3934 rp.configurable_phys = cpu_to_le32(get_configurable_phys(hdev)); in get_phy_configuration()
3936 hci_dev_unlock(hdev); in get_phy_configuration()
3938 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_PHY_CONFIGURATION, 0, in get_phy_configuration()
3942 int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip) in mgmt_phy_configuration_changed() argument
3948 ev.selected_phys = cpu_to_le32(get_selected_phys(hdev)); in mgmt_phy_configuration_changed()
3950 return mgmt_event(MGMT_EV_PHY_CONFIGURATION_CHANGED, hdev, &ev, in mgmt_phy_configuration_changed()
3954 static void set_default_phy_complete(struct hci_dev *hdev, void *data, int err) in set_default_phy_complete() argument
3960 if (cmd != pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) in set_default_phy_complete()
3972 bt_dev_dbg(hdev, "status %d", status); in set_default_phy_complete()
3975 mgmt_cmd_status(cmd->sk, hdev->id, in set_default_phy_complete()
3978 mgmt_cmd_complete(cmd->sk, hdev->id, in set_default_phy_complete()
3982 mgmt_phy_configuration_changed(hdev, cmd->sk); in set_default_phy_complete()
3991 static int set_default_phy_sync(struct hci_dev *hdev, void *data) in set_default_phy_sync() argument
4024 cmd->skb = __hci_cmd_sync(hdev, HCI_OP_LE_SET_DEFAULT_PHY, in set_default_phy_sync()
4030 static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, in set_phy_configuration() argument
4040 bt_dev_dbg(hdev, "sock %p", sk); in set_phy_configuration()
4042 configurable_phys = get_configurable_phys(hdev); in set_phy_configuration()
4043 supported_phys = get_supported_phys(hdev); in set_phy_configuration()
4047 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4054 return mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4058 if (selected_phys == get_selected_phys(hdev)) in set_phy_configuration()
4059 return mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
4063 hci_dev_lock(hdev); in set_phy_configuration()
4065 if (!hdev_is_powered(hdev)) { in set_phy_configuration()
4066 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4072 if (pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev)) { in set_phy_configuration()
4073 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4119 if (pkt_type != hdev->pkt_type) { in set_phy_configuration()
4120 hdev->pkt_type = pkt_type; in set_phy_configuration()
4125 (get_selected_phys(hdev) & MGMT_PHY_LE_MASK)) { in set_phy_configuration()
4127 mgmt_phy_configuration_changed(hdev, sk); in set_phy_configuration()
4129 err = mgmt_cmd_complete(sk, hdev->id, in set_phy_configuration()
4136 cmd = mgmt_pending_add(sk, MGMT_OP_SET_PHY_CONFIGURATION, hdev, data, in set_phy_configuration()
4141 err = hci_cmd_sync_queue(hdev, set_default_phy_sync, cmd, in set_phy_configuration()
4145 err = mgmt_cmd_status(sk, hdev->id, in set_phy_configuration()
4154 hci_dev_unlock(hdev); in set_phy_configuration()
4159 static int set_blocked_keys(struct sock *sk, struct hci_dev *hdev, void *data, in set_blocked_keys() argument
4169 bt_dev_dbg(hdev, "sock %p", sk); in set_blocked_keys()
4173 bt_dev_err(hdev, "too big key_count value %u", key_count); in set_blocked_keys()
4174 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4180 bt_dev_err(hdev, "expected %u bytes, got %u bytes", in set_blocked_keys()
4182 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4186 hci_dev_lock(hdev); in set_blocked_keys()
4188 hci_blocked_keys_clear(hdev); in set_blocked_keys()
4200 list_add_rcu(&b->list, &hdev->blocked_keys); in set_blocked_keys()
4202 hci_dev_unlock(hdev); in set_blocked_keys()
4204 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_BLOCKED_KEYS, in set_blocked_keys()
4208 static int set_wideband_speech(struct sock *sk, struct hci_dev *hdev, in set_wideband_speech() argument
4215 bt_dev_dbg(hdev, "sock %p", sk); in set_wideband_speech()
4217 if (!test_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks)) in set_wideband_speech()
4218 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4223 return mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4227 hci_dev_lock(hdev); in set_wideband_speech()
4229 if (hdev_is_powered(hdev) && in set_wideband_speech()
4230 !!cp->val != hci_dev_test_flag(hdev, in set_wideband_speech()
4232 err = mgmt_cmd_status(sk, hdev->id, in set_wideband_speech()
4239 changed = !hci_dev_test_and_set_flag(hdev, in set_wideband_speech()
4242 changed = hci_dev_test_and_clear_flag(hdev, in set_wideband_speech()
4245 err = send_settings_rsp(sk, MGMT_OP_SET_WIDEBAND_SPEECH, hdev); in set_wideband_speech()
4250 err = new_settings(hdev, sk); in set_wideband_speech()
4253 hci_dev_unlock(hdev); in set_wideband_speech()
4257 static int read_controller_cap(struct sock *sk, struct hci_dev *hdev, in read_controller_cap() argument
4266 bt_dev_dbg(hdev, "sock %p", sk); in read_controller_cap()
4270 hci_dev_lock(hdev); in read_controller_cap()
4278 if ((hdev->commands[41] & 0x08) || msft_curve_validity(hdev)) in read_controller_cap()
4286 if (hdev->commands[20] & 0x10) in read_controller_cap()
4297 if (hdev->commands[41] & 0x08) in read_controller_cap()
4300 hdev->max_enc_key_size); in read_controller_cap()
4309 if (hdev->commands[38] & 0x80) { in read_controller_cap()
4310 memcpy(&tx_power_range[0], &hdev->min_le_tx_power, 1); in read_controller_cap()
4311 memcpy(&tx_power_range[1], &hdev->max_le_tx_power, 1); in read_controller_cap()
4318 hci_dev_unlock(hdev); in read_controller_cap()
4320 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONTROLLER_CAP, 0, in read_controller_cap()
4368 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev, in read_exp_features_info() argument
4377 bt_dev_dbg(hdev, "sock %p", sk); in read_exp_features_info()
4386 if (!hdev) { in read_exp_features_info()
4395 if (hdev && hci_dev_le_state_simultaneous(hdev)) { in read_exp_features_info()
4396 if (hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) in read_exp_features_info()
4406 if (hdev && ll_privacy_capable(hdev)) { in read_exp_features_info()
4407 if (hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in read_exp_features_info()
4417 if (hdev && (aosp_has_quality_report(hdev) || in read_exp_features_info()
4418 hdev->set_quality_report)) { in read_exp_features_info()
4419 if (hci_dev_test_flag(hdev, HCI_QUALITY_REPORT)) in read_exp_features_info()
4429 if (hdev && hdev->get_data_path_id) { in read_exp_features_info()
4430 if (hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)) in read_exp_features_info()
4447 if (hdev && lmp_le_capable(hdev)) { in read_exp_features_info()
4448 if (hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL)) in read_exp_features_info()
4465 status = mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in read_exp_features_info()
4473 static int exp_ll_privacy_feature_changed(bool enabled, struct hci_dev *hdev, in exp_ll_privacy_feature_changed() argument
4483 if (enabled && privacy_mode_capable(hdev)) in exp_ll_privacy_feature_changed()
4484 hdev->conn_flags |= HCI_CONN_FLAG_DEVICE_PRIVACY; in exp_ll_privacy_feature_changed()
4486 hdev->conn_flags &= ~HCI_CONN_FLAG_DEVICE_PRIVACY; in exp_ll_privacy_feature_changed()
4488 return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, in exp_ll_privacy_feature_changed()
4494 static int exp_feature_changed(struct hci_dev *hdev, const u8 *uuid, in exp_feature_changed() argument
4503 return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, hdev, in exp_feature_changed()
4515 static int set_zero_key_func(struct sock *sk, struct hci_dev *hdev, in set_zero_key_func() argument
4524 if (!hdev) { in set_zero_key_func()
4534 if (hdev && use_ll_privacy(hdev) && !hdev_is_powered(hdev)) { in set_zero_key_func()
4537 changed = hci_dev_test_and_clear_flag(hdev, in set_zero_key_func()
4540 exp_feature_changed(hdev, rpa_resolution_uuid, false, in set_zero_key_func()
4546 return mgmt_cmd_complete(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_zero_key_func()
4552 static int set_debug_func(struct sock *sk, struct hci_dev *hdev, in set_debug_func() argument
4561 if (hdev) in set_debug_func()
4562 return mgmt_cmd_status(sk, hdev->id, in set_debug_func()
4592 exp_feature_changed(hdev, debug_uuid, val, sk); in set_debug_func()
4598 static int set_mgmt_mesh_func(struct sock *sk, struct hci_dev *hdev, in set_mgmt_mesh_func() argument
4606 if (!hdev) in set_mgmt_mesh_func()
4613 return mgmt_cmd_status(sk, hdev->id, in set_mgmt_mesh_func()
4619 return mgmt_cmd_status(sk, hdev->id, in set_mgmt_mesh_func()
4626 changed = !hci_dev_test_and_set_flag(hdev, in set_mgmt_mesh_func()
4629 hci_dev_clear_flag(hdev, HCI_MESH); in set_mgmt_mesh_func()
4630 changed = hci_dev_test_and_clear_flag(hdev, in set_mgmt_mesh_func()
4639 err = mgmt_cmd_complete(sk, hdev->id, in set_mgmt_mesh_func()
4644 exp_feature_changed(hdev, mgmt_mesh_uuid, val, sk); in set_mgmt_mesh_func()
4649 static int set_rpa_resolution_func(struct sock *sk, struct hci_dev *hdev, in set_rpa_resolution_func() argument
4659 if (!hdev) in set_rpa_resolution_func()
4665 if (hdev_is_powered(hdev)) in set_rpa_resolution_func()
4666 return mgmt_cmd_status(sk, hdev->id, in set_rpa_resolution_func()
4672 return mgmt_cmd_status(sk, hdev->id, in set_rpa_resolution_func()
4678 return mgmt_cmd_status(sk, hdev->id, in set_rpa_resolution_func()
4685 changed = !hci_dev_test_and_set_flag(hdev, in set_rpa_resolution_func()
4687 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_rpa_resolution_func()
4692 changed = hci_dev_test_and_clear_flag(hdev, in set_rpa_resolution_func()
4704 err = mgmt_cmd_complete(sk, hdev->id, in set_rpa_resolution_func()
4709 exp_ll_privacy_feature_changed(val, hdev, sk); in set_rpa_resolution_func()
4714 static int set_quality_report_func(struct sock *sk, struct hci_dev *hdev, in set_quality_report_func() argument
4723 if (!hdev) in set_quality_report_func()
4730 return mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4736 return mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4740 hci_req_sync_lock(hdev); in set_quality_report_func()
4743 changed = (val != hci_dev_test_flag(hdev, HCI_QUALITY_REPORT)); in set_quality_report_func()
4745 if (!aosp_has_quality_report(hdev) && !hdev->set_quality_report) { in set_quality_report_func()
4746 err = mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4753 if (hdev->set_quality_report) in set_quality_report_func()
4754 err = hdev->set_quality_report(hdev, val); in set_quality_report_func()
4756 err = aosp_set_quality_report(hdev, val); in set_quality_report_func()
4759 err = mgmt_cmd_status(sk, hdev->id, in set_quality_report_func()
4766 hci_dev_set_flag(hdev, HCI_QUALITY_REPORT); in set_quality_report_func()
4768 hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT); in set_quality_report_func()
4771 bt_dev_dbg(hdev, "quality report enable %d changed %d", val, changed); in set_quality_report_func()
4777 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_EXP_FEATURE, 0, in set_quality_report_func()
4781 exp_feature_changed(hdev, quality_report_uuid, val, sk); in set_quality_report_func()
4784 hci_req_sync_unlock(hdev); in set_quality_report_func()
4788 static int set_offload_codec_func(struct sock *sk, struct hci_dev *hdev, in set_offload_codec_func() argument
4797 if (!hdev) in set_offload_codec_func()
4804 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4810 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4815 changed = (val != hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)); in set_offload_codec_func()
4817 if (!hdev->get_data_path_id) { in set_offload_codec_func()
4818 return mgmt_cmd_status(sk, hdev->id, in set_offload_codec_func()
4825 hci_dev_set_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED); in set_offload_codec_func()
4827 hci_dev_clear_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED); in set_offload_codec_func()
4830 bt_dev_info(hdev, "offload codecs enable %d changed %d", in set_offload_codec_func()
4836 err = mgmt_cmd_complete(sk, hdev->id, in set_offload_codec_func()
4841 exp_feature_changed(hdev, offload_codecs_uuid, val, sk); in set_offload_codec_func()
4846 static int set_le_simultaneous_roles_func(struct sock *sk, struct hci_dev *hdev, in set_le_simultaneous_roles_func() argument
4855 if (!hdev) in set_le_simultaneous_roles_func()
4862 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4868 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4873 changed = (val != hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)); in set_le_simultaneous_roles_func()
4875 if (!hci_dev_le_state_simultaneous(hdev)) { in set_le_simultaneous_roles_func()
4876 return mgmt_cmd_status(sk, hdev->id, in set_le_simultaneous_roles_func()
4883 hci_dev_set_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); in set_le_simultaneous_roles_func()
4885 hci_dev_clear_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES); in set_le_simultaneous_roles_func()
4888 bt_dev_info(hdev, "LE simultaneous roles enable %d changed %d", in set_le_simultaneous_roles_func()
4894 err = mgmt_cmd_complete(sk, hdev->id, in set_le_simultaneous_roles_func()
4899 exp_feature_changed(hdev, le_simultaneous_roles_uuid, val, sk); in set_le_simultaneous_roles_func()
4905 static int set_iso_socket_func(struct sock *sk, struct hci_dev *hdev, in set_iso_socket_func() argument
4913 if (hdev) in set_iso_socket_func()
4914 return mgmt_cmd_status(sk, hdev->id, in set_iso_socket_func()
4949 exp_feature_changed(hdev, iso_socket_uuid, val, sk); in set_iso_socket_func()
4957 int (*set_func)(struct sock *sk, struct hci_dev *hdev,
4977 static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, in set_exp_feature() argument
4983 bt_dev_dbg(hdev, "sock %p", sk); in set_exp_feature()
4987 return exp_features[i].set_func(sk, hdev, cp, data_len); in set_exp_feature()
4990 return mgmt_cmd_status(sk, hdev ? hdev->id : MGMT_INDEX_NONE, in set_exp_feature()
4995 static u32 get_params_flags(struct hci_dev *hdev, in get_params_flags() argument
4998 u32 flags = hdev->conn_flags; in get_params_flags()
5004 if ((flags & HCI_CONN_FLAG_REMOTE_WAKEUP) && !use_ll_privacy(hdev) && in get_params_flags()
5005 hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type)) in get_params_flags()
5011 static int get_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in get_device_flags() argument
5022 bt_dev_dbg(hdev, "Get device flags %pMR (type 0x%x)\n", in get_device_flags()
5025 hci_dev_lock(hdev); in get_device_flags()
5027 supported_flags = hdev->conn_flags; in get_device_flags()
5032 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, in get_device_flags()
5040 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in get_device_flags()
5045 supported_flags = get_params_flags(hdev, params); in get_device_flags()
5057 hci_dev_unlock(hdev); in get_device_flags()
5059 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_DEVICE_FLAGS, status, in get_device_flags()
5063 static void device_flags_changed(struct sock *sk, struct hci_dev *hdev, in device_flags_changed() argument
5074 mgmt_event(MGMT_EV_DEVICE_FLAGS_CHANGED, hdev, &ev, sizeof(ev), sk); in device_flags_changed()
5077 static int set_device_flags(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_flags() argument
5087 bt_dev_dbg(hdev, "Set device flags %pMR (type 0x%x) = 0x%x", in set_device_flags()
5091 supported_flags = hdev->conn_flags; in set_device_flags()
5094 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
5099 hci_dev_lock(hdev); in set_device_flags()
5102 br_params = hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, in set_device_flags()
5110 bt_dev_warn(hdev, "No such BR/EDR device %pMR (0x%x)", in set_device_flags()
5117 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in set_device_flags()
5120 bt_dev_warn(hdev, "No such LE device %pMR (0x%x)", in set_device_flags()
5125 supported_flags = get_params_flags(hdev, params); in set_device_flags()
5128 bt_dev_warn(hdev, "Bad flag given (0x%x) vs supported (0x%0x)", in set_device_flags()
5140 hci_update_passive_scan(hdev); in set_device_flags()
5143 hci_dev_unlock(hdev); in set_device_flags()
5147 device_flags_changed(sk, hdev, &cp->addr.bdaddr, cp->addr.type, in set_device_flags()
5150 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_FLAGS, status, in set_device_flags()
5154 static void mgmt_adv_monitor_added(struct sock *sk, struct hci_dev *hdev, in mgmt_adv_monitor_added() argument
5161 mgmt_event(MGMT_EV_ADV_MONITOR_ADDED, hdev, &ev, sizeof(ev), sk); in mgmt_adv_monitor_added()
5164 void mgmt_adv_monitor_removed(struct hci_dev *hdev, u16 handle) in mgmt_adv_monitor_removed() argument
5171 cmd = pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev); in mgmt_adv_monitor_removed()
5181 mgmt_event(MGMT_EV_ADV_MONITOR_REMOVED, hdev, &ev, sizeof(ev), sk_skip); in mgmt_adv_monitor_removed()
5184 static int read_adv_mon_features(struct sock *sk, struct hci_dev *hdev, in read_adv_mon_features() argument
5196 BT_DBG("request for %s", hdev->name); in read_adv_mon_features()
5198 hci_dev_lock(hdev); in read_adv_mon_features()
5200 if (msft_monitor_supported(hdev)) in read_adv_mon_features()
5203 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) in read_adv_mon_features()
5206 hci_dev_unlock(hdev); in read_adv_mon_features()
5224 err = mgmt_cmd_complete(sk, hdev->id, in read_adv_mon_features()
5233 static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, in mgmt_add_adv_patterns_monitor_complete() argument
5240 hci_dev_lock(hdev); in mgmt_add_adv_patterns_monitor_complete()
5245 mgmt_adv_monitor_added(cmd->sk, hdev, monitor->handle); in mgmt_add_adv_patterns_monitor_complete()
5246 hdev->adv_monitors_cnt++; in mgmt_add_adv_patterns_monitor_complete()
5249 hci_update_passive_scan(hdev); in mgmt_add_adv_patterns_monitor_complete()
5256 hci_dev_unlock(hdev); in mgmt_add_adv_patterns_monitor_complete()
5257 bt_dev_dbg(hdev, "add monitor %d complete, status %d", in mgmt_add_adv_patterns_monitor_complete()
5261 static int mgmt_add_adv_patterns_monitor_sync(struct hci_dev *hdev, void *data) in mgmt_add_adv_patterns_monitor_sync() argument
5266 return hci_add_adv_monitor(hdev, monitor); in mgmt_add_adv_patterns_monitor_sync()
5269 static int __add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in __add_adv_patterns_monitor() argument
5276 hci_dev_lock(hdev); in __add_adv_patterns_monitor()
5281 if (pending_find(MGMT_OP_SET_LE, hdev) || in __add_adv_patterns_monitor()
5282 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR, hdev) || in __add_adv_patterns_monitor()
5283 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI, hdev) || in __add_adv_patterns_monitor()
5284 pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev)) { in __add_adv_patterns_monitor()
5289 cmd = mgmt_pending_add(sk, op, hdev, data, len); in __add_adv_patterns_monitor()
5296 err = hci_cmd_sync_queue(hdev, mgmt_add_adv_patterns_monitor_sync, cmd, in __add_adv_patterns_monitor()
5307 hci_dev_unlock(hdev); in __add_adv_patterns_monitor()
5312 hci_free_adv_monitor(hdev, m); in __add_adv_patterns_monitor()
5313 hci_dev_unlock(hdev); in __add_adv_patterns_monitor()
5314 return mgmt_cmd_status(sk, hdev->id, op, status); in __add_adv_patterns_monitor()
5373 static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor() argument
5381 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor()
5406 return __add_adv_patterns_monitor(sk, hdev, m, status, data, len, in add_adv_patterns_monitor()
5410 static int add_adv_patterns_monitor_rssi(struct sock *sk, struct hci_dev *hdev, in add_adv_patterns_monitor_rssi() argument
5418 BT_DBG("request for %s", hdev->name); in add_adv_patterns_monitor_rssi()
5443 return __add_adv_patterns_monitor(sk, hdev, m, status, data, len, in add_adv_patterns_monitor_rssi()
5447 static void mgmt_remove_adv_monitor_complete(struct hci_dev *hdev, in mgmt_remove_adv_monitor_complete() argument
5454 hci_dev_lock(hdev); in mgmt_remove_adv_monitor_complete()
5459 hci_update_passive_scan(hdev); in mgmt_remove_adv_monitor_complete()
5465 hci_dev_unlock(hdev); in mgmt_remove_adv_monitor_complete()
5466 bt_dev_dbg(hdev, "remove monitor %d complete, status %d", in mgmt_remove_adv_monitor_complete()
5470 static int mgmt_remove_adv_monitor_sync(struct hci_dev *hdev, void *data) in mgmt_remove_adv_monitor_sync() argument
5477 return hci_remove_all_adv_monitor(hdev); in mgmt_remove_adv_monitor_sync()
5479 return hci_remove_single_adv_monitor(hdev, handle); in mgmt_remove_adv_monitor_sync()
5482 static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev, in remove_adv_monitor() argument
5488 hci_dev_lock(hdev); in remove_adv_monitor()
5490 if (pending_find(MGMT_OP_SET_LE, hdev) || in remove_adv_monitor()
5491 pending_find(MGMT_OP_REMOVE_ADV_MONITOR, hdev) || in remove_adv_monitor()
5492 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR, hdev) || in remove_adv_monitor()
5493 pending_find(MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI, hdev)) { in remove_adv_monitor()
5498 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_ADV_MONITOR, hdev, data, len); in remove_adv_monitor()
5504 err = hci_cmd_sync_submit(hdev, mgmt_remove_adv_monitor_sync, cmd, in remove_adv_monitor()
5518 hci_dev_unlock(hdev); in remove_adv_monitor()
5523 hci_dev_unlock(hdev); in remove_adv_monitor()
5524 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, in remove_adv_monitor()
5528 static void read_local_oob_data_complete(struct hci_dev *hdev, void *data, int err) in read_local_oob_data_complete() argument
5545 bt_dev_dbg(hdev, "status %d", status); in read_local_oob_data_complete()
5548 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, status); in read_local_oob_data_complete()
5554 if (!bredr_sc_enabled(hdev)) { in read_local_oob_data_complete()
5558 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
5572 mgmt_cmd_status(cmd->sk, hdev->id, in read_local_oob_data_complete()
5585 mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data_complete()
5595 static int read_local_oob_data_sync(struct hci_dev *hdev, void *data) in read_local_oob_data_sync() argument
5599 if (bredr_sc_enabled(hdev)) in read_local_oob_data_sync()
5600 cmd->skb = hci_read_local_oob_data_sync(hdev, true, cmd->sk); in read_local_oob_data_sync()
5602 cmd->skb = hci_read_local_oob_data_sync(hdev, false, cmd->sk); in read_local_oob_data_sync()
5610 static int read_local_oob_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_data() argument
5616 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_data()
5618 hci_dev_lock(hdev); in read_local_oob_data()
5620 if (!hdev_is_powered(hdev)) { in read_local_oob_data()
5621 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5626 if (!lmp_ssp_capable(hdev)) { in read_local_oob_data()
5627 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5632 cmd = mgmt_pending_new(sk, MGMT_OP_READ_LOCAL_OOB_DATA, hdev, NULL, 0); in read_local_oob_data()
5636 err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd, in read_local_oob_data()
5640 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, in read_local_oob_data()
5648 hci_dev_unlock(hdev); in read_local_oob_data()
5652 static int add_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in add_remote_oob_data() argument
5658 bt_dev_dbg(hdev, "sock %p", sk); in add_remote_oob_data()
5661 return mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5666 hci_dev_lock(hdev); in add_remote_oob_data()
5673 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5680 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
5688 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5702 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5737 err = hci_add_remote_oob_data(hdev, &cp->addr.bdaddr, in add_remote_oob_data()
5745 err = mgmt_cmd_complete(sk, hdev->id, in add_remote_oob_data()
5749 bt_dev_err(hdev, "add_remote_oob_data: invalid len of %u bytes", in add_remote_oob_data()
5751 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, in add_remote_oob_data()
5756 hci_dev_unlock(hdev); in add_remote_oob_data()
5760 static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev, in remove_remote_oob_data() argument
5767 bt_dev_dbg(hdev, "sock %p", sk); in remove_remote_oob_data()
5770 return mgmt_cmd_complete(sk, hdev->id, in remove_remote_oob_data()
5775 hci_dev_lock(hdev); in remove_remote_oob_data()
5778 hci_remote_oob_data_clear(hdev); in remove_remote_oob_data()
5783 err = hci_remove_remote_oob_data(hdev, &cp->addr.bdaddr, cp->addr.type); in remove_remote_oob_data()
5790 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_REMOTE_OOB_DATA, in remove_remote_oob_data()
5793 hci_dev_unlock(hdev); in remove_remote_oob_data()
5797 void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_start_discovery_complete() argument
5801 bt_dev_dbg(hdev, "status %u", status); in mgmt_start_discovery_complete()
5803 hci_dev_lock(hdev); in mgmt_start_discovery_complete()
5805 cmd = pending_find(MGMT_OP_START_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5807 cmd = pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5810 cmd = pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev); in mgmt_start_discovery_complete()
5817 hci_dev_unlock(hdev); in mgmt_start_discovery_complete()
5820 static bool discovery_type_is_valid(struct hci_dev *hdev, uint8_t type, in discovery_type_is_valid() argument
5825 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
5830 *mgmt_status = mgmt_le_support(hdev); in discovery_type_is_valid()
5835 *mgmt_status = mgmt_bredr_support(hdev); in discovery_type_is_valid()
5847 static void start_discovery_complete(struct hci_dev *hdev, void *data, int err) in start_discovery_complete() argument
5851 if (cmd != pending_find(MGMT_OP_START_DISCOVERY, hdev) && in start_discovery_complete()
5852 cmd != pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev) && in start_discovery_complete()
5853 cmd != pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev)) in start_discovery_complete()
5856 bt_dev_dbg(hdev, "err %d", err); in start_discovery_complete()
5862 hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED: in start_discovery_complete()
5866 static int start_discovery_sync(struct hci_dev *hdev, void *data) in start_discovery_sync() argument
5868 return hci_start_discovery_sync(hdev); in start_discovery_sync()
5871 static int start_discovery_internal(struct sock *sk, struct hci_dev *hdev, in start_discovery_internal() argument
5879 bt_dev_dbg(hdev, "sock %p", sk); in start_discovery_internal()
5881 hci_dev_lock(hdev); in start_discovery_internal()
5883 if (!hdev_is_powered(hdev)) { in start_discovery_internal()
5884 err = mgmt_cmd_complete(sk, hdev->id, op, in start_discovery_internal()
5890 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_discovery_internal()
5891 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_discovery_internal()
5892 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
5897 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_discovery_internal()
5898 err = mgmt_cmd_complete(sk, hdev->id, op, status, in start_discovery_internal()
5904 if (hdev->discovery_paused) { in start_discovery_internal()
5905 err = mgmt_cmd_complete(sk, hdev->id, op, MGMT_STATUS_BUSY, in start_discovery_internal()
5913 hci_discovery_filter_clear(hdev); in start_discovery_internal()
5915 hdev->discovery.type = cp->type; in start_discovery_internal()
5916 hdev->discovery.report_invalid_rssi = false; in start_discovery_internal()
5918 hdev->discovery.limited = true; in start_discovery_internal()
5920 hdev->discovery.limited = false; in start_discovery_internal()
5922 cmd = mgmt_pending_add(sk, op, hdev, data, len); in start_discovery_internal()
5928 err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd, in start_discovery_internal()
5935 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_discovery_internal()
5938 hci_dev_unlock(hdev); in start_discovery_internal()
5942 static int start_discovery(struct sock *sk, struct hci_dev *hdev, in start_discovery() argument
5945 return start_discovery_internal(sk, hdev, MGMT_OP_START_DISCOVERY, in start_discovery()
5949 static int start_limited_discovery(struct sock *sk, struct hci_dev *hdev, in start_limited_discovery() argument
5952 return start_discovery_internal(sk, hdev, in start_limited_discovery()
5957 static int start_service_discovery(struct sock *sk, struct hci_dev *hdev, in start_service_discovery() argument
5967 bt_dev_dbg(hdev, "sock %p", sk); in start_service_discovery()
5969 hci_dev_lock(hdev); in start_service_discovery()
5971 if (!hdev_is_powered(hdev)) { in start_service_discovery()
5972 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5979 if (hdev->discovery.state != DISCOVERY_STOPPED || in start_service_discovery()
5980 hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) { in start_service_discovery()
5981 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5988 if (hdev->discovery_paused) { in start_service_discovery()
5989 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
5998 bt_dev_err(hdev, "service_discovery: too big uuid_count value %u", in start_service_discovery()
6000 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6009 bt_dev_err(hdev, "service_discovery: expected %u bytes, got %u bytes", in start_service_discovery()
6011 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6018 if (!discovery_type_is_valid(hdev, cp->type, &status)) { in start_service_discovery()
6019 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6026 hdev, data, len); in start_service_discovery()
6035 hci_discovery_filter_clear(hdev); in start_service_discovery()
6037 hdev->discovery.result_filtering = true; in start_service_discovery()
6038 hdev->discovery.type = cp->type; in start_service_discovery()
6039 hdev->discovery.rssi = cp->rssi; in start_service_discovery()
6040 hdev->discovery.uuid_count = uuid_count; in start_service_discovery()
6043 hdev->discovery.uuids = kmemdup(cp->uuids, uuid_count * 16, in start_service_discovery()
6045 if (!hdev->discovery.uuids) { in start_service_discovery()
6046 err = mgmt_cmd_complete(sk, hdev->id, in start_service_discovery()
6055 err = hci_cmd_sync_queue(hdev, start_discovery_sync, cmd, in start_service_discovery()
6062 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in start_service_discovery()
6065 hci_dev_unlock(hdev); in start_service_discovery()
6069 void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status) in mgmt_stop_discovery_complete() argument
6073 bt_dev_dbg(hdev, "status %u", status); in mgmt_stop_discovery_complete()
6075 hci_dev_lock(hdev); in mgmt_stop_discovery_complete()
6077 cmd = pending_find(MGMT_OP_STOP_DISCOVERY, hdev); in mgmt_stop_discovery_complete()
6083 hci_dev_unlock(hdev); in mgmt_stop_discovery_complete()
6086 static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) in stop_discovery_complete() argument
6090 if (cmd != pending_find(MGMT_OP_STOP_DISCOVERY, hdev)) in stop_discovery_complete()
6093 bt_dev_dbg(hdev, "err %d", err); in stop_discovery_complete()
6100 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in stop_discovery_complete()
6103 static int stop_discovery_sync(struct hci_dev *hdev, void *data) in stop_discovery_sync() argument
6105 return hci_stop_discovery_sync(hdev); in stop_discovery_sync()
6108 static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, in stop_discovery() argument
6115 bt_dev_dbg(hdev, "sock %p", sk); in stop_discovery()
6117 hci_dev_lock(hdev); in stop_discovery()
6119 if (!hci_discovery_active(hdev)) { in stop_discovery()
6120 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
6126 if (hdev->discovery.type != mgmt_cp->type) { in stop_discovery()
6127 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, in stop_discovery()
6133 cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, hdev, data, len); in stop_discovery()
6139 err = hci_cmd_sync_queue(hdev, stop_discovery_sync, cmd, in stop_discovery()
6146 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in stop_discovery()
6149 hci_dev_unlock(hdev); in stop_discovery()
6153 static int confirm_name(struct sock *sk, struct hci_dev *hdev, void *data, in confirm_name() argument
6160 bt_dev_dbg(hdev, "sock %p", sk); in confirm_name()
6162 hci_dev_lock(hdev); in confirm_name()
6164 if (!hci_discovery_active(hdev)) { in confirm_name()
6165 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
6171 e = hci_inquiry_cache_lookup_unknown(hdev, &cp->addr.bdaddr); in confirm_name()
6173 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, in confirm_name()
6184 hci_inquiry_cache_update_resolve(hdev, e); in confirm_name()
6187 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_CONFIRM_NAME, 0, in confirm_name()
6191 hci_dev_unlock(hdev); in confirm_name()
6195 static int block_device(struct sock *sk, struct hci_dev *hdev, void *data, in block_device() argument
6202 bt_dev_dbg(hdev, "sock %p", sk); in block_device()
6205 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, in block_device()
6209 hci_dev_lock(hdev); in block_device()
6211 err = hci_bdaddr_list_add(&hdev->reject_list, &cp->addr.bdaddr, in block_device()
6218 mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &cp->addr, sizeof(cp->addr), in block_device()
6223 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status, in block_device()
6226 hci_dev_unlock(hdev); in block_device()
6231 static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data, in unblock_device() argument
6238 bt_dev_dbg(hdev, "sock %p", sk); in unblock_device()
6241 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, in unblock_device()
6245 hci_dev_lock(hdev); in unblock_device()
6247 err = hci_bdaddr_list_del(&hdev->reject_list, &cp->addr.bdaddr, in unblock_device()
6254 mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &cp->addr, sizeof(cp->addr), in unblock_device()
6259 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status, in unblock_device()
6262 hci_dev_unlock(hdev); in unblock_device()
6267 static int set_device_id_sync(struct hci_dev *hdev, void *data) in set_device_id_sync() argument
6269 return hci_update_eir_sync(hdev); in set_device_id_sync()
6272 static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data, in set_device_id() argument
6279 bt_dev_dbg(hdev, "sock %p", sk); in set_device_id()
6284 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, in set_device_id()
6287 hci_dev_lock(hdev); in set_device_id()
6289 hdev->devid_source = source; in set_device_id()
6290 hdev->devid_vendor = __le16_to_cpu(cp->vendor); in set_device_id()
6291 hdev->devid_product = __le16_to_cpu(cp->product); in set_device_id()
6292 hdev->devid_version = __le16_to_cpu(cp->version); in set_device_id()
6294 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_DEVICE_ID, 0, in set_device_id()
6297 hci_cmd_sync_queue(hdev, set_device_id_sync, NULL, NULL); in set_device_id()
6299 hci_dev_unlock(hdev); in set_device_id()
6304 static void enable_advertising_instance(struct hci_dev *hdev, int err) in enable_advertising_instance() argument
6307 bt_dev_err(hdev, "failed to re-configure advertising %d", err); in enable_advertising_instance()
6309 bt_dev_dbg(hdev, "status %d", err); in enable_advertising_instance()
6312 static void set_advertising_complete(struct hci_dev *hdev, void *data, int err) in set_advertising_complete() argument
6314 struct cmd_lookup match = { NULL, hdev }; in set_advertising_complete()
6320 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, in set_advertising_complete()
6325 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in set_advertising_complete()
6326 hci_dev_set_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
6328 hci_dev_clear_flag(hdev, HCI_ADVERTISING); in set_advertising_complete()
6330 mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, settings_rsp, in set_advertising_complete()
6333 new_settings(hdev, match.sk); in set_advertising_complete()
6341 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in set_advertising_complete()
6342 list_empty(&hdev->adv_instances)) in set_advertising_complete()
6345 instance = hdev->cur_adv_instance; in set_advertising_complete()
6347 adv_instance = list_first_entry_or_null(&hdev->adv_instances, in set_advertising_complete()
6355 err = hci_schedule_adv_instance_sync(hdev, instance, true); in set_advertising_complete()
6357 enable_advertising_instance(hdev, err); in set_advertising_complete()
6360 static int set_adv_sync(struct hci_dev *hdev, void *data) in set_adv_sync() argument
6367 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_adv_sync()
6369 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_adv_sync()
6371 cancel_adv_timeout(hdev); in set_adv_sync()
6378 hdev->cur_adv_instance = 0x00; in set_adv_sync()
6380 if (ext_adv_capable(hdev)) { in set_adv_sync()
6381 hci_start_ext_adv_sync(hdev, 0x00); in set_adv_sync()
6383 hci_update_adv_data_sync(hdev, 0x00); in set_adv_sync()
6384 hci_update_scan_rsp_data_sync(hdev, 0x00); in set_adv_sync()
6385 hci_enable_advertising_sync(hdev); in set_adv_sync()
6388 hci_disable_advertising_sync(hdev); in set_adv_sync()
6394 static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, in set_advertising() argument
6402 bt_dev_dbg(hdev, "sock %p", sk); in set_advertising()
6404 status = mgmt_le_support(hdev); in set_advertising()
6406 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6410 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6413 if (hdev->advertising_paused) in set_advertising()
6414 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6417 hci_dev_lock(hdev); in set_advertising()
6426 if (!hdev_is_powered(hdev) || in set_advertising()
6427 (val == hci_dev_test_flag(hdev, HCI_ADVERTISING) && in set_advertising()
6428 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) || in set_advertising()
6429 hci_dev_test_flag(hdev, HCI_MESH) || in set_advertising()
6430 hci_conn_num(hdev, LE_LINK) > 0 || in set_advertising()
6431 (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_advertising()
6432 hdev->le_scan_type == LE_SCAN_ACTIVE)) { in set_advertising()
6436 hdev->cur_adv_instance = 0x00; in set_advertising()
6437 changed = !hci_dev_test_and_set_flag(hdev, HCI_ADVERTISING); in set_advertising()
6439 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6441 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6443 changed = hci_dev_test_and_clear_flag(hdev, HCI_ADVERTISING); in set_advertising()
6444 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE); in set_advertising()
6447 err = send_settings_rsp(sk, MGMT_OP_SET_ADVERTISING, hdev); in set_advertising()
6452 err = new_settings(hdev, sk); in set_advertising()
6457 if (pending_find(MGMT_OP_SET_ADVERTISING, hdev) || in set_advertising()
6458 pending_find(MGMT_OP_SET_LE, hdev)) { in set_advertising()
6459 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_ADVERTISING, in set_advertising()
6464 cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING, hdev, data, len); in set_advertising()
6468 err = hci_cmd_sync_queue(hdev, set_adv_sync, cmd, in set_advertising()
6475 hci_dev_unlock(hdev); in set_advertising()
6479 static int set_static_address(struct sock *sk, struct hci_dev *hdev, in set_static_address() argument
6485 bt_dev_dbg(hdev, "sock %p", sk); in set_static_address()
6487 if (!lmp_le_capable(hdev)) in set_static_address()
6488 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
6491 if (hdev_is_powered(hdev)) in set_static_address()
6492 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_STATIC_ADDRESS, in set_static_address()
6497 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
6503 return mgmt_cmd_status(sk, hdev->id, in set_static_address()
6508 hci_dev_lock(hdev); in set_static_address()
6510 bacpy(&hdev->static_addr, &cp->bdaddr); in set_static_address()
6512 err = send_settings_rsp(sk, MGMT_OP_SET_STATIC_ADDRESS, hdev); in set_static_address()
6516 err = new_settings(hdev, sk); in set_static_address()
6519 hci_dev_unlock(hdev); in set_static_address()
6523 static int set_scan_params(struct sock *sk, struct hci_dev *hdev, in set_scan_params() argument
6530 bt_dev_dbg(hdev, "sock %p", sk); in set_scan_params()
6532 if (!lmp_le_capable(hdev)) in set_scan_params()
6533 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6539 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6545 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6549 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, in set_scan_params()
6552 hci_dev_lock(hdev); in set_scan_params()
6554 hdev->le_scan_interval = interval; in set_scan_params()
6555 hdev->le_scan_window = window; in set_scan_params()
6557 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_SCAN_PARAMS, 0, in set_scan_params()
6563 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in set_scan_params()
6564 hdev->discovery.state == DISCOVERY_STOPPED) in set_scan_params()
6565 hci_update_passive_scan(hdev); in set_scan_params()
6567 hci_dev_unlock(hdev); in set_scan_params()
6572 static void fast_connectable_complete(struct hci_dev *hdev, void *data, int err) in fast_connectable_complete() argument
6576 bt_dev_dbg(hdev, "err %d", err); in fast_connectable_complete()
6579 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in fast_connectable_complete()
6585 hci_dev_set_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
6587 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in fast_connectable_complete()
6589 send_settings_rsp(cmd->sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in fast_connectable_complete()
6590 new_settings(hdev, cmd->sk); in fast_connectable_complete()
6596 static int write_fast_connectable_sync(struct hci_dev *hdev, void *data) in write_fast_connectable_sync() argument
6601 return hci_write_fast_connectable_sync(hdev, cp->val); in write_fast_connectable_sync()
6604 static int set_fast_connectable(struct sock *sk, struct hci_dev *hdev, in set_fast_connectable() argument
6611 bt_dev_dbg(hdev, "sock %p", sk); in set_fast_connectable()
6613 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) || in set_fast_connectable()
6614 hdev->hci_ver < BLUETOOTH_VER_1_2) in set_fast_connectable()
6615 return mgmt_cmd_status(sk, hdev->id, in set_fast_connectable()
6620 return mgmt_cmd_status(sk, hdev->id, in set_fast_connectable()
6624 hci_dev_lock(hdev); in set_fast_connectable()
6626 if (!!cp->val == hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) { in set_fast_connectable()
6627 err = send_settings_rsp(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in set_fast_connectable()
6631 if (!hdev_is_powered(hdev)) { in set_fast_connectable()
6632 hci_dev_change_flag(hdev, HCI_FAST_CONNECTABLE); in set_fast_connectable()
6633 err = send_settings_rsp(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev); in set_fast_connectable()
6634 new_settings(hdev, sk); in set_fast_connectable()
6638 cmd = mgmt_pending_new(sk, MGMT_OP_SET_FAST_CONNECTABLE, hdev, data, in set_fast_connectable()
6643 err = hci_cmd_sync_queue(hdev, write_fast_connectable_sync, cmd, in set_fast_connectable()
6647 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_FAST_CONNECTABLE, in set_fast_connectable()
6655 hci_dev_unlock(hdev); in set_fast_connectable()
6660 static void set_bredr_complete(struct hci_dev *hdev, void *data, int err) in set_bredr_complete() argument
6664 bt_dev_dbg(hdev, "err %d", err); in set_bredr_complete()
6672 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in set_bredr_complete()
6676 send_settings_rsp(cmd->sk, MGMT_OP_SET_BREDR, hdev); in set_bredr_complete()
6677 new_settings(hdev, cmd->sk); in set_bredr_complete()
6683 static int set_bredr_sync(struct hci_dev *hdev, void *data) in set_bredr_sync() argument
6687 status = hci_write_fast_connectable_sync(hdev, false); in set_bredr_sync()
6690 status = hci_update_scan_sync(hdev); in set_bredr_sync()
6696 status = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in set_bredr_sync()
6701 static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) in set_bredr() argument
6707 bt_dev_dbg(hdev, "sock %p", sk); in set_bredr()
6709 if (!lmp_bredr_capable(hdev) || !lmp_le_capable(hdev)) in set_bredr()
6710 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6713 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_bredr()
6714 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6718 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6721 hci_dev_lock(hdev); in set_bredr()
6723 if (cp->val == hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_bredr()
6724 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
6728 if (!hdev_is_powered(hdev)) { in set_bredr()
6730 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in set_bredr()
6731 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); in set_bredr()
6732 hci_dev_clear_flag(hdev, HCI_LINK_SECURITY); in set_bredr()
6733 hci_dev_clear_flag(hdev, HCI_FAST_CONNECTABLE); in set_bredr()
6736 hci_dev_change_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
6738 err = send_settings_rsp(sk, MGMT_OP_SET_BREDR, hdev); in set_bredr()
6742 err = new_settings(hdev, sk); in set_bredr()
6748 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6766 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_bredr()
6767 (bacmp(&hdev->static_addr, BDADDR_ANY) || in set_bredr()
6768 hci_dev_test_flag(hdev, HCI_SC_ENABLED))) { in set_bredr()
6769 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6775 cmd = mgmt_pending_new(sk, MGMT_OP_SET_BREDR, hdev, data, len); in set_bredr()
6779 err = hci_cmd_sync_queue(hdev, set_bredr_sync, cmd, in set_bredr()
6783 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_BREDR, in set_bredr()
6794 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in set_bredr()
6797 hci_dev_unlock(hdev); in set_bredr()
6801 static void set_secure_conn_complete(struct hci_dev *hdev, void *data, int err) in set_secure_conn_complete() argument
6806 bt_dev_dbg(hdev, "err %d", err); in set_secure_conn_complete()
6819 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6820 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6823 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6824 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6827 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_complete()
6828 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn_complete()
6832 send_settings_rsp(cmd->sk, cmd->opcode, hdev); in set_secure_conn_complete()
6833 new_settings(hdev, cmd->sk); in set_secure_conn_complete()
6839 static int set_secure_conn_sync(struct hci_dev *hdev, void *data) in set_secure_conn_sync() argument
6846 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in set_secure_conn_sync()
6848 return hci_write_sc_support_sync(hdev, val); in set_secure_conn_sync()
6851 static int set_secure_conn(struct sock *sk, struct hci_dev *hdev, in set_secure_conn() argument
6859 bt_dev_dbg(hdev, "sock %p", sk); in set_secure_conn()
6861 if (!lmp_sc_capable(hdev) && in set_secure_conn()
6862 !hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in set_secure_conn()
6863 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6866 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in set_secure_conn()
6867 lmp_sc_capable(hdev) && in set_secure_conn()
6868 !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in set_secure_conn()
6869 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6873 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6876 hci_dev_lock(hdev); in set_secure_conn()
6878 if (!hdev_is_powered(hdev) || !lmp_sc_capable(hdev) || in set_secure_conn()
6879 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in set_secure_conn()
6883 changed = !hci_dev_test_and_set_flag(hdev, in set_secure_conn()
6886 hci_dev_set_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6888 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6890 changed = hci_dev_test_and_clear_flag(hdev, in set_secure_conn()
6892 hci_dev_clear_flag(hdev, HCI_SC_ONLY); in set_secure_conn()
6895 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
6900 err = new_settings(hdev, sk); in set_secure_conn()
6907 if (val == hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in set_secure_conn()
6908 (cp->val == 0x02) == hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in set_secure_conn()
6909 err = send_settings_rsp(sk, MGMT_OP_SET_SECURE_CONN, hdev); in set_secure_conn()
6913 cmd = mgmt_pending_new(sk, MGMT_OP_SET_SECURE_CONN, hdev, data, len); in set_secure_conn()
6917 err = hci_cmd_sync_queue(hdev, set_secure_conn_sync, cmd, in set_secure_conn()
6921 mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SECURE_CONN, in set_secure_conn()
6928 hci_dev_unlock(hdev); in set_secure_conn()
6932 static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, in set_debug_keys() argument
6939 bt_dev_dbg(hdev, "sock %p", sk); in set_debug_keys()
6942 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEBUG_KEYS, in set_debug_keys()
6945 hci_dev_lock(hdev); in set_debug_keys()
6948 changed = !hci_dev_test_and_set_flag(hdev, HCI_KEEP_DEBUG_KEYS); in set_debug_keys()
6950 changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
6954 use_changed = !hci_dev_test_and_set_flag(hdev, in set_debug_keys()
6957 use_changed = hci_dev_test_and_clear_flag(hdev, in set_debug_keys()
6960 if (hdev_is_powered(hdev) && use_changed && in set_debug_keys()
6961 hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in set_debug_keys()
6963 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in set_debug_keys()
6967 err = send_settings_rsp(sk, MGMT_OP_SET_DEBUG_KEYS, hdev); in set_debug_keys()
6972 err = new_settings(hdev, sk); in set_debug_keys()
6975 hci_dev_unlock(hdev); in set_debug_keys()
6979 static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data, in set_privacy() argument
6986 bt_dev_dbg(hdev, "sock %p", sk); in set_privacy()
6988 if (!lmp_le_capable(hdev)) in set_privacy()
6989 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
6993 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
6996 if (hdev_is_powered(hdev)) in set_privacy()
6997 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY, in set_privacy()
7000 hci_dev_lock(hdev); in set_privacy()
7005 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in set_privacy()
7008 changed = !hci_dev_test_and_set_flag(hdev, HCI_PRIVACY); in set_privacy()
7009 memcpy(hdev->irk, cp->irk, sizeof(hdev->irk)); in set_privacy()
7010 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
7011 hci_adv_instances_set_rpa_expired(hdev, true); in set_privacy()
7013 hci_dev_set_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
7015 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
7017 changed = hci_dev_test_and_clear_flag(hdev, HCI_PRIVACY); in set_privacy()
7018 memset(hdev->irk, 0, sizeof(hdev->irk)); in set_privacy()
7019 hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); in set_privacy()
7020 hci_adv_instances_set_rpa_expired(hdev, false); in set_privacy()
7021 hci_dev_clear_flag(hdev, HCI_LIMITED_PRIVACY); in set_privacy()
7024 err = send_settings_rsp(sk, MGMT_OP_SET_PRIVACY, hdev); in set_privacy()
7029 err = new_settings(hdev, sk); in set_privacy()
7032 hci_dev_unlock(hdev); in set_privacy()
7052 static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data, in load_irks() argument
7061 bt_dev_dbg(hdev, "sock %p", sk); in load_irks()
7063 if (!lmp_le_capable(hdev)) in load_irks()
7064 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7069 bt_dev_err(hdev, "load_irks: too big irk_count value %u", in load_irks()
7071 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7077 bt_dev_err(hdev, "load_irks: expected %u bytes, got %u bytes", in load_irks()
7079 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, in load_irks()
7083 bt_dev_dbg(hdev, "irk_count %u", irk_count); in load_irks()
7089 return mgmt_cmd_status(sk, hdev->id, in load_irks()
7094 hci_dev_lock(hdev); in load_irks()
7096 hci_smp_irks_clear(hdev); in load_irks()
7101 if (hci_is_blocked_key(hdev, in load_irks()
7104 bt_dev_warn(hdev, "Skipping blocked IRK for %pMR", in load_irks()
7109 hci_add_irk(hdev, &irk->addr.bdaddr, in load_irks()
7114 hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); in load_irks()
7116 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_IRKS, 0, NULL, 0); in load_irks()
7118 hci_dev_unlock(hdev); in load_irks()
7142 static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev, in load_long_term_keys() argument
7151 bt_dev_dbg(hdev, "sock %p", sk); in load_long_term_keys()
7153 if (!lmp_le_capable(hdev)) in load_long_term_keys()
7154 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7159 bt_dev_err(hdev, "load_ltks: too big key_count value %u", in load_long_term_keys()
7161 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7167 bt_dev_err(hdev, "load_keys: expected %u bytes, got %u bytes", in load_long_term_keys()
7169 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, in load_long_term_keys()
7173 bt_dev_dbg(hdev, "key_count %u", key_count); in load_long_term_keys()
7175 hci_dev_lock(hdev); in load_long_term_keys()
7177 hci_smp_ltks_clear(hdev); in load_long_term_keys()
7183 if (hci_is_blocked_key(hdev, in load_long_term_keys()
7186 bt_dev_warn(hdev, "Skipping blocked LTK for %pMR", in load_long_term_keys()
7192 bt_dev_warn(hdev, "Invalid LTK for %pMR", in load_long_term_keys()
7222 hci_add_ltk(hdev, &key->addr.bdaddr, in load_long_term_keys()
7227 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 0, in load_long_term_keys()
7230 hci_dev_unlock(hdev); in load_long_term_keys()
7235 static void get_conn_info_complete(struct hci_dev *hdev, void *data, int err) in get_conn_info_complete() argument
7243 bt_dev_dbg(hdev, "err %d", err); in get_conn_info_complete()
7264 static int get_conn_info_sync(struct hci_dev *hdev, void *data) in get_conn_info_sync() argument
7274 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info_sync()
7277 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info_sync()
7286 err = hci_read_rssi_sync(hdev, handle); in get_conn_info_sync()
7293 err = hci_read_tx_power_sync(hdev, handle, 0x00); in get_conn_info_sync()
7297 err = hci_read_tx_power_sync(hdev, handle, 0x01); in get_conn_info_sync()
7302 static int get_conn_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_conn_info() argument
7311 bt_dev_dbg(hdev, "sock %p", sk); in get_conn_info()
7318 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7322 hci_dev_lock(hdev); in get_conn_info()
7324 if (!hdev_is_powered(hdev)) { in get_conn_info()
7325 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7332 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_conn_info()
7335 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); in get_conn_info()
7338 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7347 conn_info_age = get_random_u32_inclusive(hdev->conn_info_min_age, in get_conn_info()
7348 hdev->conn_info_max_age - 1); in get_conn_info()
7358 cmd = mgmt_pending_new(sk, MGMT_OP_GET_CONN_INFO, hdev, data, in get_conn_info()
7363 err = hci_cmd_sync_queue(hdev, get_conn_info_sync, in get_conn_info()
7368 mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7384 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO, in get_conn_info()
7389 hci_dev_unlock(hdev); in get_conn_info()
7393 static void get_clock_info_complete(struct hci_dev *hdev, void *data, int err) in get_clock_info_complete() argument
7401 bt_dev_dbg(hdev, "err %d", err); in get_clock_info_complete()
7410 rp.local_clock = cpu_to_le32(hdev->clock); in get_clock_info_complete()
7424 static int get_clock_info_sync(struct hci_dev *hdev, void *data) in get_clock_info_sync() argument
7432 hci_read_clock_sync(hdev, &hci_cp); in get_clock_info_sync()
7435 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); in get_clock_info_sync()
7443 return hci_read_clock_sync(hdev, &hci_cp); in get_clock_info_sync()
7446 static int get_clock_info(struct sock *sk, struct hci_dev *hdev, void *data, in get_clock_info() argument
7455 bt_dev_dbg(hdev, "sock %p", sk); in get_clock_info()
7462 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7466 hci_dev_lock(hdev); in get_clock_info()
7468 if (!hdev_is_powered(hdev)) { in get_clock_info()
7469 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7476 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, in get_clock_info()
7479 err = mgmt_cmd_complete(sk, hdev->id, in get_clock_info()
7489 cmd = mgmt_pending_new(sk, MGMT_OP_GET_CLOCK_INFO, hdev, data, len); in get_clock_info()
7493 err = hci_cmd_sync_queue(hdev, get_clock_info_sync, cmd, in get_clock_info()
7497 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_CLOCK_INFO, in get_clock_info()
7506 hci_dev_unlock(hdev); in get_clock_info()
7510 static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type) in is_connected() argument
7514 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, addr); in is_connected()
7528 static int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, in hci_conn_params_set() argument
7533 params = hci_conn_params_add(hdev, addr, addr_type); in hci_conn_params_set()
7549 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7553 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7555 hci_pend_le_list_add(params, &hdev->pend_le_reports); in hci_conn_params_set()
7559 if (!is_connected(hdev, addr, addr_type)) in hci_conn_params_set()
7560 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_conn_params_set()
7566 bt_dev_dbg(hdev, "addr %pMR (type %u) auto_connect %u", in hci_conn_params_set()
7572 static void device_added(struct sock *sk, struct hci_dev *hdev, in device_added() argument
7581 mgmt_event(MGMT_EV_DEVICE_ADDED, hdev, &ev, sizeof(ev), sk); in device_added()
7584 static int add_device_sync(struct hci_dev *hdev, void *data) in add_device_sync() argument
7586 return hci_update_passive_scan_sync(hdev); in add_device_sync()
7589 static int add_device(struct sock *sk, struct hci_dev *hdev, in add_device() argument
7599 bt_dev_dbg(hdev, "sock %p", sk); in add_device()
7603 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7608 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7612 hci_dev_lock(hdev); in add_device()
7617 err = mgmt_cmd_complete(sk, hdev->id, in add_device()
7624 err = hci_bdaddr_list_add_with_flags(&hdev->accept_list, in add_device()
7630 hci_update_scan(hdev); in add_device()
7650 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7659 if (hci_conn_params_set(hdev, &cp->addr.bdaddr, addr_type, in add_device()
7661 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7666 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in add_device()
7672 err = hci_cmd_sync_queue(hdev, add_device_sync, NULL, NULL); in add_device()
7677 device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action); in add_device()
7678 supported_flags = hdev->conn_flags; in add_device()
7679 device_flags_changed(NULL, hdev, &cp->addr.bdaddr, cp->addr.type, in add_device()
7682 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, in add_device()
7687 hci_dev_unlock(hdev); in add_device()
7691 static void device_removed(struct sock *sk, struct hci_dev *hdev, in device_removed() argument
7699 mgmt_event(MGMT_EV_DEVICE_REMOVED, hdev, &ev, sizeof(ev), sk); in device_removed()
7702 static int remove_device_sync(struct hci_dev *hdev, void *data) in remove_device_sync() argument
7704 return hci_update_passive_scan_sync(hdev); in remove_device_sync()
7707 static int remove_device(struct sock *sk, struct hci_dev *hdev, in remove_device() argument
7713 bt_dev_dbg(hdev, "sock %p", sk); in remove_device()
7715 hci_dev_lock(hdev); in remove_device()
7722 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7730 err = hci_bdaddr_list_del(&hdev->accept_list, in remove_device()
7734 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7742 hci_update_scan(hdev); in remove_device()
7744 device_removed(sk, hdev, &cp->addr.bdaddr, in remove_device()
7757 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7764 params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr, in remove_device()
7767 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7776 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7785 device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type); in remove_device()
7791 err = mgmt_cmd_complete(sk, hdev->id, in remove_device()
7798 list_for_each_entry_safe(b, btmp, &hdev->accept_list, list) { in remove_device()
7799 device_removed(sk, hdev, &b->bdaddr, b->bdaddr_type); in remove_device()
7804 hci_update_scan(hdev); in remove_device()
7806 list_for_each_entry_safe(p, tmp, &hdev->le_conn_params, list) { in remove_device()
7809 device_removed(sk, hdev, &p->addr, p->addr_type); in remove_device()
7817 bt_dev_dbg(hdev, "All LE connection parameters were removed"); in remove_device()
7820 hci_cmd_sync_queue(hdev, remove_device_sync, NULL, NULL); in remove_device()
7823 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, in remove_device()
7827 hci_dev_unlock(hdev); in remove_device()
7831 static int conn_update_sync(struct hci_dev *hdev, void *data) in conn_update_sync() argument
7836 conn = hci_conn_hash_lookup_le(hdev, ¶ms->addr, params->addr_type); in conn_update_sync()
7840 return hci_le_conn_update_sync(hdev, conn, params); in conn_update_sync()
7843 static int load_conn_param(struct sock *sk, struct hci_dev *hdev, void *data, in load_conn_param() argument
7852 if (!lmp_le_capable(hdev)) in load_conn_param()
7853 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7858 bt_dev_err(hdev, "load_conn_param: too big param_count value %u", in load_conn_param()
7860 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7866 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes", in load_conn_param()
7868 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, in load_conn_param()
7872 bt_dev_dbg(hdev, "param_count %u", param_count); in load_conn_param()
7874 hci_dev_lock(hdev); in load_conn_param()
7877 hci_conn_params_clear_disabled(hdev); in load_conn_param()
7886 bt_dev_dbg(hdev, "Adding %pMR (type %u)", ¶m->addr.bdaddr, in load_conn_param()
7894 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
7903 bt_dev_dbg(hdev, "min 0x%04x max 0x%04x latency 0x%04x timeout 0x%04x", in load_conn_param()
7907 bt_dev_err(hdev, "ignoring invalid connection parameters"); in load_conn_param()
7915 hci_param = hci_conn_params_lookup(hdev, in load_conn_param()
7921 hci_conn_params_clear_disabled(hdev); in load_conn_param()
7924 hci_param = hci_conn_params_add(hdev, ¶m->addr.bdaddr, in load_conn_param()
7927 bt_dev_err(hdev, "failed to add connection parameters"); in load_conn_param()
7944 conn = hci_conn_hash_lookup_le(hdev, &hci_param->addr, in load_conn_param()
7951 hci_cmd_sync_queue(hdev, conn_update_sync, in load_conn_param()
7956 hci_dev_unlock(hdev); in load_conn_param()
7958 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 0, in load_conn_param()
7962 static int set_external_config(struct sock *sk, struct hci_dev *hdev, in set_external_config() argument
7969 bt_dev_dbg(hdev, "sock %p", sk); in set_external_config()
7971 if (hdev_is_powered(hdev)) in set_external_config()
7972 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7976 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7979 if (!test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks)) in set_external_config()
7980 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_EXTERNAL_CONFIG, in set_external_config()
7983 hci_dev_lock(hdev); in set_external_config()
7986 changed = !hci_dev_test_and_set_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
7988 changed = hci_dev_test_and_clear_flag(hdev, HCI_EXT_CONFIGURED); in set_external_config()
7990 err = send_options_rsp(sk, MGMT_OP_SET_EXTERNAL_CONFIG, hdev); in set_external_config()
7997 err = new_options(hdev, sk); in set_external_config()
7999 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) == is_configured(hdev)) { in set_external_config()
8000 mgmt_index_removed(hdev); in set_external_config()
8002 if (hci_dev_test_and_change_flag(hdev, HCI_UNCONFIGURED)) { in set_external_config()
8003 hci_dev_set_flag(hdev, HCI_CONFIG); in set_external_config()
8004 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_external_config()
8006 queue_work(hdev->req_workqueue, &hdev->power_on); in set_external_config()
8008 set_bit(HCI_RAW, &hdev->flags); in set_external_config()
8009 mgmt_index_added(hdev); in set_external_config()
8014 hci_dev_unlock(hdev); in set_external_config()
8018 static int set_public_address(struct sock *sk, struct hci_dev *hdev, in set_public_address() argument
8025 bt_dev_dbg(hdev, "sock %p", sk); in set_public_address()
8027 if (hdev_is_powered(hdev)) in set_public_address()
8028 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8032 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8035 if (!hdev->set_bdaddr) in set_public_address()
8036 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_PUBLIC_ADDRESS, in set_public_address()
8039 hci_dev_lock(hdev); in set_public_address()
8041 changed = !!bacmp(&hdev->public_addr, &cp->bdaddr); in set_public_address()
8042 bacpy(&hdev->public_addr, &cp->bdaddr); in set_public_address()
8044 err = send_options_rsp(sk, MGMT_OP_SET_PUBLIC_ADDRESS, hdev); in set_public_address()
8051 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in set_public_address()
8052 err = new_options(hdev, sk); in set_public_address()
8054 if (is_configured(hdev)) { in set_public_address()
8055 mgmt_index_removed(hdev); in set_public_address()
8057 hci_dev_clear_flag(hdev, HCI_UNCONFIGURED); in set_public_address()
8059 hci_dev_set_flag(hdev, HCI_CONFIG); in set_public_address()
8060 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in set_public_address()
8062 queue_work(hdev->req_workqueue, &hdev->power_on); in set_public_address()
8066 hci_dev_unlock(hdev); in set_public_address()
8070 static void read_local_oob_ext_data_complete(struct hci_dev *hdev, void *data, in read_local_oob_ext_data_complete() argument
8081 if (cmd != pending_find(MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev)) in read_local_oob_ext_data_complete()
8093 bt_dev_dbg(hdev, "status %u", status); in read_local_oob_ext_data_complete()
8105 } else if (!bredr_sc_enabled(hdev)) { in read_local_oob_ext_data_complete()
8131 if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) { in read_local_oob_ext_data_complete()
8154 hdev->dev_class, 3); in read_local_oob_ext_data_complete()
8174 err = mgmt_cmd_complete(cmd->sk, hdev->id, in read_local_oob_ext_data_complete()
8182 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data_complete()
8193 static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk, in read_local_ssp_oob_req() argument
8199 cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev, in read_local_ssp_oob_req()
8204 err = hci_cmd_sync_queue(hdev, read_local_oob_data_sync, cmd, in read_local_ssp_oob_req()
8215 static int read_local_oob_ext_data(struct sock *sk, struct hci_dev *hdev, in read_local_oob_ext_data() argument
8225 bt_dev_dbg(hdev, "sock %p", sk); in read_local_oob_ext_data()
8227 if (hdev_is_powered(hdev)) { in read_local_oob_ext_data()
8230 status = mgmt_bredr_support(hdev); in read_local_oob_ext_data()
8237 status = mgmt_le_support(hdev); in read_local_oob_ext_data()
8258 if (!status && !lmp_ssp_capable(hdev)) { in read_local_oob_ext_data()
8266 hci_dev_lock(hdev); in read_local_oob_ext_data()
8271 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in read_local_oob_ext_data()
8272 err = read_local_ssp_oob_req(hdev, sk, cp); in read_local_oob_ext_data()
8273 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8282 hdev->dev_class, 3); in read_local_oob_ext_data()
8286 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED) && in read_local_oob_ext_data()
8287 smp_generate_oob(hdev, hash, rand) < 0) { in read_local_oob_ext_data()
8288 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8303 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { in read_local_oob_ext_data()
8304 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8309 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in read_local_oob_ext_data()
8310 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in read_local_oob_ext_data()
8311 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in read_local_oob_ext_data()
8312 bacmp(&hdev->static_addr, BDADDR_ANY))) { in read_local_oob_ext_data()
8313 memcpy(addr, &hdev->static_addr, 6); in read_local_oob_ext_data()
8316 memcpy(addr, &hdev->bdaddr, 6); in read_local_oob_ext_data()
8323 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in read_local_oob_ext_data()
8331 if (hci_dev_test_flag(hdev, HCI_SC_ENABLED)) { in read_local_oob_ext_data()
8341 flags = mgmt_get_adv_discov_flags(hdev); in read_local_oob_ext_data()
8343 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in read_local_oob_ext_data()
8351 hci_dev_unlock(hdev); in read_local_oob_ext_data()
8361 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, in read_local_oob_ext_data()
8366 err = mgmt_limited_event(MGMT_EV_LOCAL_OOB_DATA_UPDATED, hdev, in read_local_oob_ext_data()
8376 static u32 get_supported_adv_flags(struct hci_dev *hdev) in get_supported_adv_flags() argument
8395 if (hdev->adv_tx_power != HCI_TX_POWER_INVALID || ext_adv_capable(hdev)) in get_supported_adv_flags()
8398 if (ext_adv_capable(hdev)) { in get_supported_adv_flags()
8403 if (le_2m_capable(hdev)) in get_supported_adv_flags()
8406 if (le_coded_capable(hdev)) in get_supported_adv_flags()
8413 static int read_adv_features(struct sock *sk, struct hci_dev *hdev, in read_adv_features() argument
8423 bt_dev_dbg(hdev, "sock %p", sk); in read_adv_features()
8425 if (!lmp_le_capable(hdev)) in read_adv_features()
8426 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
8429 hci_dev_lock(hdev); in read_adv_features()
8431 rp_len = sizeof(*rp) + hdev->adv_instance_cnt; in read_adv_features()
8434 hci_dev_unlock(hdev); in read_adv_features()
8438 supported_flags = get_supported_adv_flags(hdev); in read_adv_features()
8441 rp->max_adv_data_len = max_adv_len(hdev); in read_adv_features()
8442 rp->max_scan_rsp_len = max_adv_len(hdev); in read_adv_features()
8443 rp->max_instances = hdev->le_num_of_adv_sets; in read_adv_features()
8444 rp->num_instances = hdev->adv_instance_cnt; in read_adv_features()
8447 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in read_adv_features()
8449 if (adv_instance->instance <= hdev->adv_instance_cnt) { in read_adv_features()
8458 hci_dev_unlock(hdev); in read_adv_features()
8460 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_ADV_FEATURES, in read_adv_features()
8468 static u8 calculate_name_len(struct hci_dev *hdev) in calculate_name_len() argument
8472 return eir_append_local_name(hdev, buf, 0); in calculate_name_len()
8475 static u8 tlv_data_max_len(struct hci_dev *hdev, u32 adv_flags, in tlv_data_max_len() argument
8478 u8 max_len = max_adv_len(hdev); in tlv_data_max_len()
8490 max_len -= calculate_name_len(hdev); in tlv_data_max_len()
8521 static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data, in tlv_data_is_valid() argument
8527 max_len = tlv_data_max_len(hdev, adv_flags, is_adv_data); in tlv_data_is_valid()
8566 static bool requested_adv_flags_are_valid(struct hci_dev *hdev, u32 adv_flags) in requested_adv_flags_are_valid() argument
8573 supported_flags = get_supported_adv_flags(hdev); in requested_adv_flags_are_valid()
8582 static bool adv_busy(struct hci_dev *hdev) in adv_busy() argument
8584 return pending_find(MGMT_OP_SET_LE, hdev); in adv_busy()
8587 static void add_adv_complete(struct hci_dev *hdev, struct sock *sk, u8 instance, in add_adv_complete() argument
8592 bt_dev_dbg(hdev, "err %d", err); in add_adv_complete()
8594 hci_dev_lock(hdev); in add_adv_complete()
8596 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in add_adv_complete()
8609 if (hdev->cur_adv_instance == instance) in add_adv_complete()
8610 cancel_adv_timeout(hdev); in add_adv_complete()
8612 hci_remove_adv_instance(hdev, instance); in add_adv_complete()
8613 mgmt_advertising_removed(sk, hdev, instance); in add_adv_complete()
8616 hci_dev_unlock(hdev); in add_adv_complete()
8619 static void add_advertising_complete(struct hci_dev *hdev, void *data, int err) in add_advertising_complete() argument
8636 add_adv_complete(hdev, cmd->sk, cp->instance, err); in add_advertising_complete()
8641 static int add_advertising_sync(struct hci_dev *hdev, void *data) in add_advertising_sync() argument
8646 return hci_schedule_adv_instance_sync(hdev, cp->instance, true); in add_advertising_sync()
8649 static int add_advertising(struct sock *sk, struct hci_dev *hdev, in add_advertising() argument
8663 bt_dev_dbg(hdev, "sock %p", sk); in add_advertising()
8665 status = mgmt_le_support(hdev); in add_advertising()
8667 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8670 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_advertising()
8671 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8675 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8682 if (!requested_adv_flags_are_valid(hdev, flags)) in add_advertising()
8683 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8686 hci_dev_lock(hdev); in add_advertising()
8688 if (timeout && !hdev_is_powered(hdev)) { in add_advertising()
8689 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8694 if (adv_busy(hdev)) { in add_advertising()
8695 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8700 if (!tlv_data_is_valid(hdev, flags, cp->data, cp->adv_data_len, true) || in add_advertising()
8701 !tlv_data_is_valid(hdev, flags, cp->data + cp->adv_data_len, in add_advertising()
8703 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8708 prev_instance_cnt = hdev->adv_instance_cnt; in add_advertising()
8710 adv = hci_add_adv_instance(hdev, cp->instance, flags, in add_advertising()
8716 hdev->le_adv_min_interval, in add_advertising()
8717 hdev->le_adv_max_interval, 0); in add_advertising()
8719 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8727 if (hdev->adv_instance_cnt > prev_instance_cnt) in add_advertising()
8728 mgmt_advertising_added(sk, hdev, cp->instance); in add_advertising()
8730 if (hdev->cur_adv_instance == cp->instance) { in add_advertising()
8736 cancel_adv_timeout(hdev); in add_advertising()
8738 next_instance = hci_get_next_instance(hdev, cp->instance); in add_advertising()
8741 } else if (!hdev->adv_instance_timeout) { in add_advertising()
8752 if (!hdev_is_powered(hdev) || in add_advertising()
8753 hci_dev_test_flag(hdev, HCI_ADVERTISING) || in add_advertising()
8756 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_ADVERTISING, in add_advertising()
8764 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_ADVERTISING, hdev, data, in add_advertising()
8773 err = hci_cmd_sync_queue(hdev, add_advertising_sync, cmd, in add_advertising()
8779 hci_dev_unlock(hdev); in add_advertising()
8784 static void add_ext_adv_params_complete(struct hci_dev *hdev, void *data, in add_ext_adv_params_complete() argument
8793 BT_DBG("%s", hdev->name); in add_ext_adv_params_complete()
8795 hci_dev_lock(hdev); in add_ext_adv_params_complete()
8797 adv = hci_find_adv_instance(hdev, cp->instance); in add_ext_adv_params_complete()
8808 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in add_ext_adv_params_complete()
8809 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in add_ext_adv_params_complete()
8817 mgmt_advertising_removed(cmd->sk, hdev, cp->instance); in add_ext_adv_params_complete()
8819 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_params_complete()
8831 hci_dev_unlock(hdev); in add_ext_adv_params_complete()
8834 static int add_ext_adv_params_sync(struct hci_dev *hdev, void *data) in add_ext_adv_params_sync() argument
8839 return hci_setup_ext_adv_instance_sync(hdev, cp->instance); in add_ext_adv_params_sync()
8842 static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev, in add_ext_adv_params() argument
8855 BT_DBG("%s", hdev->name); in add_ext_adv_params()
8857 status = mgmt_le_support(hdev); in add_ext_adv_params()
8859 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8862 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in add_ext_adv_params()
8863 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8873 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8878 if (!requested_adv_flags_are_valid(hdev, flags)) in add_ext_adv_params()
8879 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8882 hci_dev_lock(hdev); in add_ext_adv_params()
8885 if (!hdev_is_powered(hdev)) { in add_ext_adv_params()
8886 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8891 if (adv_busy(hdev)) { in add_ext_adv_params()
8892 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8903 hdev->def_multi_adv_rotation_duration; in add_ext_adv_params()
8907 hdev->le_adv_min_interval; in add_ext_adv_params()
8911 hdev->le_adv_max_interval; in add_ext_adv_params()
8918 adv = hci_add_adv_instance(hdev, cp->instance, flags, 0, NULL, 0, NULL, in add_ext_adv_params()
8923 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS, in add_ext_adv_params()
8929 if (ext_adv_capable(hdev)) { in add_ext_adv_params()
8930 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_EXT_ADV_PARAMS, hdev, in add_ext_adv_params()
8934 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_params()
8938 err = hci_cmd_sync_queue(hdev, add_ext_adv_params_sync, cmd, in add_ext_adv_params()
8945 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in add_ext_adv_params()
8946 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in add_ext_adv_params()
8947 err = mgmt_cmd_complete(sk, hdev->id, in add_ext_adv_params()
8953 hci_dev_unlock(hdev); in add_ext_adv_params()
8958 static void add_ext_adv_data_complete(struct hci_dev *hdev, void *data, int err) in add_ext_adv_data_complete() argument
8964 add_adv_complete(hdev, cmd->sk, cp->instance, err); in add_ext_adv_data_complete()
8980 static int add_ext_adv_data_sync(struct hci_dev *hdev, void *data) in add_ext_adv_data_sync() argument
8986 if (ext_adv_capable(hdev)) { in add_ext_adv_data_sync()
8987 err = hci_update_adv_data_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8991 err = hci_update_scan_rsp_data_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8995 return hci_enable_ext_advertising_sync(hdev, cp->instance); in add_ext_adv_data_sync()
8998 return hci_schedule_adv_instance_sync(hdev, cp->instance, true); in add_ext_adv_data_sync()
9001 static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data, in add_ext_adv_data() argument
9012 BT_DBG("%s", hdev->name); in add_ext_adv_data()
9014 hci_dev_lock(hdev); in add_ext_adv_data()
9016 adv_instance = hci_find_adv_instance(hdev, cp->instance); in add_ext_adv_data()
9019 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9025 if (!hdev_is_powered(hdev)) { in add_ext_adv_data()
9026 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9031 if (adv_busy(hdev)) { in add_ext_adv_data()
9032 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9038 if (!tlv_data_is_valid(hdev, adv_instance->flags, cp->data, in add_ext_adv_data()
9040 !tlv_data_is_valid(hdev, adv_instance->flags, cp->data + in add_ext_adv_data()
9042 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9048 hci_set_adv_instance_data(hdev, cp->instance, cp->adv_data_len, in add_ext_adv_data()
9053 if (hdev->cur_adv_instance == cp->instance) { in add_ext_adv_data()
9060 cancel_adv_timeout(hdev); in add_ext_adv_data()
9062 next_instance = hci_get_next_instance(hdev, cp->instance); in add_ext_adv_data()
9065 } else if (!hdev->adv_instance_timeout) { in add_ext_adv_data()
9076 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || !schedule_instance) { in add_ext_adv_data()
9078 mgmt_advertising_added(sk, hdev, cp->instance); in add_ext_adv_data()
9082 err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_DATA, in add_ext_adv_data()
9087 cmd = mgmt_pending_new(sk, MGMT_OP_ADD_EXT_ADV_DATA, hdev, data, in add_ext_adv_data()
9094 err = hci_cmd_sync_queue(hdev, add_ext_adv_data_sync, cmd, in add_ext_adv_data()
9107 mgmt_advertising_added(sk, hdev, cp->instance); in add_ext_adv_data()
9112 hci_remove_adv_instance(hdev, cp->instance); in add_ext_adv_data()
9115 hci_dev_unlock(hdev); in add_ext_adv_data()
9120 static void remove_advertising_complete(struct hci_dev *hdev, void *data, in remove_advertising_complete() argument
9127 bt_dev_dbg(hdev, "err %d", err); in remove_advertising_complete()
9142 static int remove_advertising_sync(struct hci_dev *hdev, void *data) in remove_advertising_sync() argument
9148 err = hci_remove_advertising_sync(hdev, cmd->sk, cp->instance, true); in remove_advertising_sync()
9152 if (list_empty(&hdev->adv_instances)) in remove_advertising_sync()
9153 err = hci_disable_advertising_sync(hdev); in remove_advertising_sync()
9158 static int remove_advertising(struct sock *sk, struct hci_dev *hdev, in remove_advertising() argument
9165 bt_dev_dbg(hdev, "sock %p", sk); in remove_advertising()
9167 hci_dev_lock(hdev); in remove_advertising()
9169 if (cp->instance && !hci_find_adv_instance(hdev, cp->instance)) { in remove_advertising()
9170 err = mgmt_cmd_status(sk, hdev->id, in remove_advertising()
9176 if (pending_find(MGMT_OP_SET_LE, hdev)) { in remove_advertising()
9177 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
9182 if (list_empty(&hdev->adv_instances)) { in remove_advertising()
9183 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADVERTISING, in remove_advertising()
9188 cmd = mgmt_pending_new(sk, MGMT_OP_REMOVE_ADVERTISING, hdev, data, in remove_advertising()
9195 err = hci_cmd_sync_queue(hdev, remove_advertising_sync, cmd, in remove_advertising()
9201 hci_dev_unlock(hdev); in remove_advertising()
9206 static int get_adv_size_info(struct sock *sk, struct hci_dev *hdev, in get_adv_size_info() argument
9213 bt_dev_dbg(hdev, "sock %p", sk); in get_adv_size_info()
9215 if (!lmp_le_capable(hdev)) in get_adv_size_info()
9216 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9219 if (cp->instance < 1 || cp->instance > hdev->le_num_of_adv_sets) in get_adv_size_info()
9220 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9228 supported_flags = get_supported_adv_flags(hdev); in get_adv_size_info()
9230 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9235 rp.max_adv_data_len = tlv_data_max_len(hdev, flags, true); in get_adv_size_info()
9236 rp.max_scan_rsp_len = tlv_data_max_len(hdev, flags, false); in get_adv_size_info()
9238 return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_GET_ADV_SIZE_INFO, in get_adv_size_info()
9376 void mgmt_index_added(struct hci_dev *hdev) in mgmt_index_added() argument
9380 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_added()
9383 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_added()
9384 mgmt_index_event(MGMT_EV_UNCONF_INDEX_ADDED, hdev, NULL, 0, in mgmt_index_added()
9388 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
9402 struct cmd_lookup match = { NULL, hdev, MGMT_STATUS_INVALID_INDEX }; in mgmt_index_removed()
9404 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in mgmt_index_removed()
9407 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &match); in mgmt_index_removed()
9409 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in mgmt_index_removed()
9410 mgmt_index_event(MGMT_EV_UNCONF_INDEX_REMOVED, hdev, NULL, 0, in mgmt_index_removed()
9414 mgmt_index_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, in mgmt_index_removed()
9419 ev.bus = hdev->bus; in mgmt_index_removed()
9421 mgmt_index_event(MGMT_EV_EXT_INDEX_REMOVED, hdev, &ev, sizeof(ev), in mgmt_index_removed()
9425 if (!hci_dev_test_flag(hdev, HCI_MGMT)) in mgmt_index_removed()
9427 cancel_delayed_work_sync(&hdev->discov_off); in mgmt_index_removed()
9428 cancel_delayed_work_sync(&hdev->service_cache); in mgmt_index_removed()
9429 cancel_delayed_work_sync(&hdev->rpa_expired); in mgmt_index_removed()
9432 void mgmt_power_on(struct hci_dev *hdev, int err) in mgmt_power_on() argument
9434 struct cmd_lookup match = { NULL, hdev }; in mgmt_power_on()
9436 bt_dev_dbg(hdev, "err %d", err); in mgmt_power_on()
9438 hci_dev_lock(hdev); in mgmt_power_on()
9441 restart_le_actions(hdev); in mgmt_power_on()
9442 hci_update_passive_scan(hdev); in mgmt_power_on()
9445 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in mgmt_power_on()
9447 new_settings(hdev, match.sk); in mgmt_power_on()
9452 hci_dev_unlock(hdev); in mgmt_power_on()
9455 void __mgmt_power_off(struct hci_dev *hdev) in __mgmt_power_off() argument
9457 struct cmd_lookup match = { NULL, hdev }; in __mgmt_power_off()
9460 mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match); in __mgmt_power_off()
9469 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) in __mgmt_power_off()
9474 mgmt_pending_foreach(0, hdev, cmd_complete_rsp, &match); in __mgmt_power_off()
9476 if (memcmp(hdev->dev_class, zero_cod, sizeof(zero_cod)) != 0) { in __mgmt_power_off()
9477 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, in __mgmt_power_off()
9480 ext_info_changed(hdev, NULL); in __mgmt_power_off()
9483 new_settings(hdev, match.sk); in __mgmt_power_off()
9489 void mgmt_set_powered_failed(struct hci_dev *hdev, int err) in mgmt_set_powered_failed() argument
9494 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_set_powered_failed()
9503 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_POWERED, status); in mgmt_set_powered_failed()
9508 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, in mgmt_new_link_key() argument
9522 mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_link_key()
9544 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent) in mgmt_new_ltk() argument
9584 mgmt_event(MGMT_EV_NEW_LONG_TERM_KEY, hdev, &ev, sizeof(ev), NULL); in mgmt_new_ltk()
9587 void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent) in mgmt_new_irk() argument
9600 mgmt_event(MGMT_EV_NEW_IRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_irk()
9603 void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, in mgmt_new_csrk() argument
9630 mgmt_event(MGMT_EV_NEW_CSRK, hdev, &ev, sizeof(ev), NULL); in mgmt_new_csrk()
9633 void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_new_conn_param() argument
9651 mgmt_event(MGMT_EV_NEW_CONN_PARAM, hdev, &ev, sizeof(ev), NULL); in mgmt_new_conn_param()
9654 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, in mgmt_device_connected() argument
9667 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, in mgmt_device_connected()
9670 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_CONNECTED, in mgmt_device_connected()
9706 struct hci_dev *hdev = data; in unpair_device_rsp() local
9709 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, cmd->sk); in unpair_device_rsp()
9715 bool mgmt_powering_down(struct hci_dev *hdev) in mgmt_powering_down() argument
9720 if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) in mgmt_powering_down()
9723 cmd = pending_find(MGMT_OP_SET_POWERED, hdev); in mgmt_powering_down()
9734 void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_device_disconnected() argument
9752 if (hdev->suspended) in mgmt_device_disconnected()
9755 mgmt_event(MGMT_EV_DEVICE_DISCONNECTED, hdev, &ev, sizeof(ev), sk); in mgmt_device_disconnected()
9761 void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_disconnect_failed() argument
9768 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, in mgmt_disconnect_failed()
9769 hdev); in mgmt_disconnect_failed()
9771 cmd = pending_find(MGMT_OP_DISCONNECT, hdev); in mgmt_disconnect_failed()
9787 void mgmt_connect_failed(struct hci_dev *hdev, struct hci_conn *conn, u8 status) in mgmt_connect_failed() argument
9792 mgmt_device_disconnected(hdev, &conn->dst, conn->type, in mgmt_connect_failed()
9801 mgmt_event(MGMT_EV_CONNECT_FAILED, hdev, &ev, sizeof(ev), NULL); in mgmt_connect_failed()
9804 void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure) in mgmt_pin_code_request() argument
9812 mgmt_event(MGMT_EV_PIN_CODE_REQUEST, hdev, &ev, sizeof(ev), NULL); in mgmt_pin_code_request()
9815 void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_reply_complete() argument
9820 cmd = pending_find(MGMT_OP_PIN_CODE_REPLY, hdev); in mgmt_pin_code_reply_complete()
9828 void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_pin_code_neg_reply_complete() argument
9833 cmd = pending_find(MGMT_OP_PIN_CODE_NEG_REPLY, hdev); in mgmt_pin_code_neg_reply_complete()
9841 int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_request() argument
9847 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_confirm_request()
9854 return mgmt_event(MGMT_EV_USER_CONFIRM_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_confirm_request()
9858 int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_request() argument
9863 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_request()
9868 return mgmt_event(MGMT_EV_USER_PASSKEY_REQUEST, hdev, &ev, sizeof(ev), in mgmt_user_passkey_request()
9872 static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in user_pairing_resp_complete() argument
9878 cmd = pending_find(opcode, hdev); in user_pairing_resp_complete()
9888 int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_reply_complete() argument
9891 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_reply_complete()
9895 int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_confirm_neg_reply_complete() argument
9898 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_confirm_neg_reply_complete()
9903 int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_reply_complete() argument
9906 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_reply_complete()
9910 int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_neg_reply_complete() argument
9913 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, in mgmt_user_passkey_neg_reply_complete()
9918 int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, in mgmt_user_passkey_notify() argument
9924 bt_dev_dbg(hdev, "bdaddr %pMR", bdaddr); in mgmt_user_passkey_notify()
9931 return mgmt_event(MGMT_EV_PASSKEY_NOTIFY, hdev, &ev, sizeof(ev), NULL); in mgmt_user_passkey_notify()
9946 mgmt_event(MGMT_EV_AUTH_FAILED, conn->hdev, &ev, sizeof(ev), in mgmt_auth_failed()
9955 void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status) in mgmt_auth_enable_complete() argument
9957 struct cmd_lookup match = { NULL, hdev }; in mgmt_auth_enable_complete()
9962 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, in mgmt_auth_enable_complete()
9967 if (test_bit(HCI_AUTH, &hdev->flags)) in mgmt_auth_enable_complete()
9968 changed = !hci_dev_test_and_set_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
9970 changed = hci_dev_test_and_clear_flag(hdev, HCI_LINK_SECURITY); in mgmt_auth_enable_complete()
9972 mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, settings_rsp, in mgmt_auth_enable_complete()
9976 new_settings(hdev, match.sk); in mgmt_auth_enable_complete()
9992 void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, in mgmt_set_class_of_dev_complete() argument
9995 struct cmd_lookup match = { NULL, hdev, mgmt_status(status) }; in mgmt_set_class_of_dev_complete()
9997 mgmt_pending_foreach(MGMT_OP_SET_DEV_CLASS, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
9998 mgmt_pending_foreach(MGMT_OP_ADD_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
9999 mgmt_pending_foreach(MGMT_OP_REMOVE_UUID, hdev, sk_lookup, &match); in mgmt_set_class_of_dev_complete()
10002 mgmt_limited_event(MGMT_EV_CLASS_OF_DEV_CHANGED, hdev, dev_class, in mgmt_set_class_of_dev_complete()
10004 ext_info_changed(hdev, NULL); in mgmt_set_class_of_dev_complete()
10011 void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status) in mgmt_set_local_name_complete() argument
10021 memcpy(ev.short_name, hdev->short_name, HCI_MAX_SHORT_NAME_LENGTH); in mgmt_set_local_name_complete()
10023 cmd = pending_find(MGMT_OP_SET_LOCAL_NAME, hdev); in mgmt_set_local_name_complete()
10025 memcpy(hdev->dev_name, name, sizeof(hdev->dev_name)); in mgmt_set_local_name_complete()
10030 if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) in mgmt_set_local_name_complete()
10033 if (pending_find(MGMT_OP_SET_POWERED, hdev)) in mgmt_set_local_name_complete()
10037 mgmt_limited_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev, sizeof(ev), in mgmt_set_local_name_complete()
10039 ext_info_changed(hdev, cmd ? cmd->sk : NULL); in mgmt_set_local_name_complete()
10109 static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir, in is_filter_match() argument
10121 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
10123 (rssi < hdev->discovery.rssi && in is_filter_match()
10124 !test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)))) in is_filter_match()
10127 if (hdev->discovery.uuid_count != 0) { in is_filter_match()
10131 if (!eir_has_uuids(eir, eir_len, hdev->discovery.uuid_count, in is_filter_match()
10132 hdev->discovery.uuids) && in is_filter_match()
10134 hdev->discovery.uuid_count, in is_filter_match()
10135 hdev->discovery.uuids)) in is_filter_match()
10142 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)) { in is_filter_match()
10144 if (hdev->discovery.rssi != HCI_RSSI_INVALID && in is_filter_match()
10145 rssi < hdev->discovery.rssi) in is_filter_match()
10152 void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle, in mgmt_adv_monitor_device_lost() argument
10161 mgmt_event(MGMT_EV_ADV_MONITOR_DEVICE_LOST, hdev, &ev, sizeof(ev), in mgmt_adv_monitor_device_lost()
10165 static void mgmt_send_adv_monitor_device_found(struct hci_dev *hdev, in mgmt_send_adv_monitor_device_found() argument
10179 advmon_skb = mgmt_alloc_skb(hdev, MGMT_EV_ADV_MONITOR_DEVICE_FOUND, in mgmt_send_adv_monitor_device_found()
10195 static void mgmt_adv_monitor_device_found(struct hci_dev *hdev, in mgmt_adv_monitor_device_found() argument
10219 if (report_device && !hdev->advmon_pend_notify) { in mgmt_adv_monitor_device_found()
10224 hdev->advmon_pend_notify = false; in mgmt_adv_monitor_device_found()
10226 list_for_each_entry_safe(dev, tmp, &hdev->monitored_devices, list) { in mgmt_adv_monitor_device_found()
10231 mgmt_send_adv_monitor_device_found(hdev, skb, in mgmt_adv_monitor_device_found()
10240 hdev->advmon_pend_notify = true; in mgmt_adv_monitor_device_found()
10244 ((matched && !notified) || !msft_monitor_supported(hdev))) { in mgmt_adv_monitor_device_found()
10250 mgmt_send_adv_monitor_device_found(hdev, skb, skip_sk, 0); in mgmt_adv_monitor_device_found()
10259 static void mesh_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, in mesh_device_found() argument
10268 if (!hdev->mesh_ad_types[0]) in mesh_device_found()
10274 for (j = 0; j < sizeof(hdev->mesh_ad_types); j++) { in mesh_device_found()
10275 if (!hdev->mesh_ad_types[j]) in mesh_device_found()
10278 if (hdev->mesh_ad_types[j] == eir[i + 1]) in mesh_device_found()
10286 for (j = 0; j < sizeof(hdev->mesh_ad_types); j++) { in mesh_device_found()
10287 if (!hdev->mesh_ad_types[j]) in mesh_device_found()
10290 if (hdev->mesh_ad_types[j] == scan_rsp[i + 1]) in mesh_device_found()
10299 skb = mgmt_alloc_skb(hdev, MGMT_EV_MESH_DEVICE_FOUND, in mesh_device_found()
10325 void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_device_found() argument
10332 bool report_device = hci_discovery_active(hdev); in mgmt_device_found()
10334 if (hci_dev_test_flag(hdev, HCI_MESH) && link_type == LE_LINK) in mgmt_device_found()
10335 mesh_device_found(hdev, bdaddr, addr_type, rssi, flags, in mgmt_device_found()
10343 if (!hci_discovery_active(hdev)) { in mgmt_device_found()
10346 if (link_type == LE_LINK && !list_empty(&hdev->pend_le_reports)) in mgmt_device_found()
10348 else if (!hci_is_adv_monitoring(hdev)) in mgmt_device_found()
10352 if (hdev->discovery.result_filtering) { in mgmt_device_found()
10354 if (!is_filter_match(hdev, rssi, eir, eir_len, scan_rsp, in mgmt_device_found()
10359 if (hdev->discovery.limited) { in mgmt_device_found()
10372 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, in mgmt_device_found()
10387 if (rssi == HCI_RSSI_INVALID && !hdev->discovery.report_invalid_rssi && in mgmt_device_found()
10414 mgmt_adv_monitor_device_found(hdev, bdaddr, report_device, skb, NULL); in mgmt_device_found()
10417 void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, in mgmt_remote_name() argument
10425 skb = mgmt_alloc_skb(hdev, MGMT_EV_DEVICE_FOUND, in mgmt_remote_name()
10444 void mgmt_discovering(struct hci_dev *hdev, u8 discovering) in mgmt_discovering() argument
10448 bt_dev_dbg(hdev, "discovering %u", discovering); in mgmt_discovering()
10451 ev.type = hdev->discovery.type; in mgmt_discovering()
10454 mgmt_event(MGMT_EV_DISCOVERING, hdev, &ev, sizeof(ev), NULL); in mgmt_discovering()
10457 void mgmt_suspending(struct hci_dev *hdev, u8 state) in mgmt_suspending() argument
10462 mgmt_event(MGMT_EV_CONTROLLER_SUSPEND, hdev, &ev, sizeof(ev), NULL); in mgmt_suspending()
10465 void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr, in mgmt_resuming() argument
10478 mgmt_event(MGMT_EV_CONTROLLER_RESUME, hdev, &ev, sizeof(ev), NULL); in mgmt_resuming()
10501 struct hci_dev *hdev; in mgmt_cleanup() local
10505 list_for_each_entry(hdev, &hci_dev_list, list) { in mgmt_cleanup()
10507 mesh_tx = mgmt_mesh_next(hdev, sk); in mgmt_cleanup()
10510 mesh_send_complete(hdev, mesh_tx, true); in mgmt_cleanup()