Lines Matching +full:x +full:- +full:rp
1 // SPDX-License-Identifier: GPL-2.0-only
14 #define MSFT_RSSI_THRESHOLD_VALUE_MIN -127
146 struct msft_rp_read_supported_features *rp; in read_supported_features() local
151 skb = __hci_cmd_sync(hdev, hdev->msft_opcode, sizeof(cp), &cp, in read_supported_features()
159 if (skb->len < sizeof(*rp)) { in read_supported_features()
164 rp = (struct msft_rp_read_supported_features *)skb->data; in read_supported_features()
166 if (rp->sub_opcode != MSFT_OP_READ_SUPPORTED_FEATURES) in read_supported_features()
169 if (rp->evt_prefix_len > 0) { in read_supported_features()
170 msft->evt_prefix = kmemdup(rp->evt_prefix, rp->evt_prefix_len, in read_supported_features()
172 if (!msft->evt_prefix) in read_supported_features()
176 msft->evt_prefix_len = rp->evt_prefix_len; in read_supported_features()
177 msft->features = __le64_to_cpu(rp->features); in read_supported_features()
179 if (msft->features & MSFT_FEATURE_MASK_CURVE_VALIDITY) in read_supported_features()
180 hdev->msft_curve_validity = true; in read_supported_features()
192 * This function requires the caller holds hdev->lock
198 struct msft_data *msft = hdev->msft_data; in msft_find_handle_data()
200 list_for_each_entry(entry, &msft->handle_map, list) { in msft_find_handle_data()
201 if (is_mgmt && entry->mgmt_handle == handle) in msft_find_handle_data()
203 if (!is_mgmt && entry->msft_handle == handle) in msft_find_handle_data()
210 /* This function requires the caller holds msft->filter_lock */
216 struct msft_data *msft = hdev->msft_data; in msft_find_address_data()
218 list_for_each_entry(entry, &msft->address_filters, list) { in msft_find_address_data()
219 if (entry->pattern_handle == pattern_handle && in msft_find_address_data()
220 addr_type == entry->addr_type && in msft_find_address_data()
221 !bacmp(addr, &entry->bdaddr)) in msft_find_address_data()
228 /* This function requires the caller holds hdev->lock */
236 list_for_each_entry_safe(dev, tmp, &hdev->monitored_devices, list) { in msft_monitor_device_del()
241 if ((!mgmt_handle || dev->handle == mgmt_handle) && in msft_monitor_device_del()
242 (!bdaddr || (!bacmp(bdaddr, &dev->bdaddr) && in msft_monitor_device_del()
243 addr_type == dev->addr_type))) { in msft_monitor_device_del()
244 if (notify && dev->notified) { in msft_monitor_device_del()
245 mgmt_adv_monitor_device_lost(hdev, dev->handle, in msft_monitor_device_del()
246 &dev->bdaddr, in msft_monitor_device_del()
247 dev->addr_type); in msft_monitor_device_del()
250 list_del(&dev->list); in msft_monitor_device_del()
263 struct msft_rp_le_monitor_advertisement *rp; in msft_le_monitor_advertisement_cb() local
265 struct msft_data *msft = hdev->msft_data; in msft_le_monitor_advertisement_cb()
270 rp = (struct msft_rp_le_monitor_advertisement *)skb->data; in msft_le_monitor_advertisement_cb()
271 if (skb->len < sizeof(*rp)) { in msft_le_monitor_advertisement_cb()
276 status = rp->status; in msft_le_monitor_advertisement_cb()
286 handle_data->mgmt_handle = monitor->handle; in msft_le_monitor_advertisement_cb()
287 handle_data->msft_handle = rp->handle; in msft_le_monitor_advertisement_cb()
288 handle_data->cond_type = MSFT_MONITOR_ADVERTISEMENT_TYPE_PATTERN; in msft_le_monitor_advertisement_cb()
289 INIT_LIST_HEAD(&handle_data->list); in msft_le_monitor_advertisement_cb()
290 list_add(&handle_data->list, &msft->handle_map); in msft_le_monitor_advertisement_cb()
292 monitor->state = ADV_MONITOR_STATE_OFFLOADED; in msft_le_monitor_advertisement_cb()
308 struct msft_data *msft = hdev->msft_data; in msft_remove_addr_filters_sync()
315 mutex_lock(&msft->filter_lock); in msft_remove_addr_filters_sync()
317 list_for_each_entry_safe(address_filter, n, &msft->address_filters, in msft_remove_addr_filters_sync()
319 if (address_filter->pattern_handle != handle) in msft_remove_addr_filters_sync()
322 list_del(&address_filter->list); in msft_remove_addr_filters_sync()
328 if (address_filter->state == AF_STATE_ADDING) { in msft_remove_addr_filters_sync()
329 address_filter->state = AF_STATE_REMOVING; in msft_remove_addr_filters_sync()
337 if (address_filter->state == AF_STATE_REMOVING) in msft_remove_addr_filters_sync()
340 list_add_tail(&address_filter->list, &head); in msft_remove_addr_filters_sync()
343 mutex_unlock(&msft->filter_lock); in msft_remove_addr_filters_sync()
346 list_del(&address_filter->list); in msft_remove_addr_filters_sync()
349 cp.handle = address_filter->msft_handle; in msft_remove_addr_filters_sync()
351 skb = __hci_cmd_sync(hdev, hdev->msft_opcode, sizeof(cp), &cp, in msft_remove_addr_filters_sync()
361 &address_filter->bdaddr); in msft_remove_addr_filters_sync()
372 struct msft_rp_le_cancel_monitor_advertisement *rp; in msft_le_cancel_monitor_advertisement_cb() local
374 struct msft_data *msft = hdev->msft_data; in msft_le_cancel_monitor_advertisement_cb()
378 rp = (struct msft_rp_le_cancel_monitor_advertisement *)skb->data; in msft_le_cancel_monitor_advertisement_cb()
379 if (skb->len < sizeof(*rp)) { in msft_le_cancel_monitor_advertisement_cb()
384 status = rp->status; in msft_le_cancel_monitor_advertisement_cb()
390 handle_data = msft_find_handle_data(hdev, monitor->handle, true); in msft_le_cancel_monitor_advertisement_cb()
393 if (monitor->state == ADV_MONITOR_STATE_OFFLOADED) in msft_le_cancel_monitor_advertisement_cb()
394 monitor->state = ADV_MONITOR_STATE_REGISTERED; in msft_le_cancel_monitor_advertisement_cb()
397 * suspend. It will be re-monitored on resume. in msft_le_cancel_monitor_advertisement_cb()
399 if (!msft->suspending) { in msft_le_cancel_monitor_advertisement_cb()
403 msft_monitor_device_del(hdev, handle_data->mgmt_handle, in msft_le_cancel_monitor_advertisement_cb()
407 msft_handle = handle_data->msft_handle; in msft_le_cancel_monitor_advertisement_cb()
409 list_del(&handle_data->list); in msft_le_cancel_monitor_advertisement_cb()
431 handle_data = msft_find_handle_data(hdev, monitor->handle, true); in msft_remove_monitor_sync()
435 return -ENOENT; in msft_remove_monitor_sync()
438 cp.handle = handle_data->msft_handle; in msft_remove_monitor_sync()
440 skb = __hci_cmd_sync(hdev, hdev->msft_opcode, sizeof(cp), &cp, in msft_remove_monitor_sync()
445 return msft_le_cancel_monitor_advertisement_cb(hdev, hdev->msft_opcode, in msft_remove_monitor_sync()
452 struct msft_data *msft = hdev->msft_data; in msft_suspend_sync()
459 msft->suspending = true; in msft_suspend_sync()
462 monitor = idr_get_next(&hdev->adv_monitors_idr, &handle); in msft_suspend_sync()
472 msft->suspending = false; in msft_suspend_sync()
479 struct adv_rssi_thresholds *r = &monitor->rssi; in msft_monitor_rssi_valid()
481 if (r->high_threshold < MSFT_RSSI_THRESHOLD_VALUE_MIN || in msft_monitor_rssi_valid()
482 r->high_threshold > MSFT_RSSI_THRESHOLD_VALUE_MAX || in msft_monitor_rssi_valid()
483 r->low_threshold < MSFT_RSSI_THRESHOLD_VALUE_MIN || in msft_monitor_rssi_valid()
484 r->low_threshold > MSFT_RSSI_THRESHOLD_VALUE_MAX) in msft_monitor_rssi_valid()
490 if (r->high_threshold_timeout != 0) in msft_monitor_rssi_valid()
493 if (r->low_threshold_timeout > MSFT_RSSI_LOW_TIMEOUT_MAX) in msft_monitor_rssi_valid()
503 /* No additional check needed for pattern-based monitor */ in msft_monitor_pattern_valid()
521 return -EINVAL; in msft_add_monitor_sync()
523 list_for_each_entry(entry, &monitor->patterns, list) { in msft_add_monitor_sync()
525 total_size += sizeof(*pattern) + entry->length; in msft_add_monitor_sync()
530 return -ENOMEM; in msft_add_monitor_sync()
532 cp->sub_opcode = MSFT_OP_LE_MONITOR_ADVERTISEMENT; in msft_add_monitor_sync()
533 cp->rssi_high = monitor->rssi.high_threshold; in msft_add_monitor_sync()
534 cp->rssi_low = monitor->rssi.low_threshold; in msft_add_monitor_sync()
535 cp->rssi_low_interval = (u8)monitor->rssi.low_threshold_timeout; in msft_add_monitor_sync()
536 cp->rssi_sampling_period = monitor->rssi.sampling_period; in msft_add_monitor_sync()
538 cp->cond_type = MSFT_MONITOR_ADVERTISEMENT_TYPE_PATTERN; in msft_add_monitor_sync()
540 pattern_data = (void *)cp->data; in msft_add_monitor_sync()
541 pattern_data->count = pattern_count; in msft_add_monitor_sync()
543 list_for_each_entry(entry, &monitor->patterns, list) { in msft_add_monitor_sync()
544 pattern = (void *)(pattern_data->data + offset); in msft_add_monitor_sync()
546 pattern->length = entry->length + 2; in msft_add_monitor_sync()
547 pattern->data_type = entry->ad_type; in msft_add_monitor_sync()
548 pattern->start_byte = entry->offset; in msft_add_monitor_sync()
549 memcpy(pattern->pattern, entry->value, entry->length); in msft_add_monitor_sync()
550 offset += sizeof(*pattern) + entry->length; in msft_add_monitor_sync()
553 skb = __hci_cmd_sync(hdev, hdev->msft_opcode, total_size, cp, in msft_add_monitor_sync()
561 err = msft_le_monitor_advertisement_cb(hdev, hdev->msft_opcode, in msft_add_monitor_sync()
566 handle_data = msft_find_handle_data(hdev, monitor->handle, true); in msft_add_monitor_sync()
568 err = -ENODATA; in msft_add_monitor_sync()
572 handle_data->rssi_high = cp->rssi_high; in msft_add_monitor_sync()
573 handle_data->rssi_low = cp->rssi_low; in msft_add_monitor_sync()
574 handle_data->rssi_low_interval = cp->rssi_low_interval; in msft_add_monitor_sync()
575 handle_data->rssi_sampling_period = cp->rssi_sampling_period; in msft_add_monitor_sync()
586 struct msft_data *msft = hdev->msft_data; in reregister_monitor()
592 msft->resuming = true; in reregister_monitor()
595 monitor = idr_get_next(&hdev->adv_monitors_idr, &handle); in reregister_monitor()
605 msft->resuming = false; in reregister_monitor()
611 struct msft_data *msft = hdev->msft_data; in msft_resume_sync()
621 hdev->advmon_pend_notify = false; in msft_resume_sync()
634 struct msft_data *msft = hdev->msft_data; in msft_do_open()
636 if (hdev->msft_opcode == HCI_OP_NOP) in msft_do_open()
646 /* Reset existing MSFT data before re-reading */ in msft_do_open()
647 kfree(msft->evt_prefix); in msft_do_open()
648 msft->evt_prefix = NULL; in msft_do_open()
649 msft->evt_prefix_len = 0; in msft_do_open()
650 msft->features = 0; in msft_do_open()
653 hdev->msft_data = NULL; in msft_do_open()
659 msft->resuming = true; in msft_do_open()
662 * tell the controller to re-monitor. in msft_do_open()
670 struct msft_data *msft = hdev->msft_data; in msft_do_close()
683 list_for_each_entry_safe(handle_data, tmp, &msft->handle_map, list) { in msft_do_close()
684 monitor = idr_find(&hdev->adv_monitors_idr, in msft_do_close()
685 handle_data->mgmt_handle); in msft_do_close()
687 if (monitor && monitor->state == ADV_MONITOR_STATE_OFFLOADED) in msft_do_close()
688 monitor->state = ADV_MONITOR_STATE_REGISTERED; in msft_do_close()
690 list_del(&handle_data->list); in msft_do_close()
694 mutex_lock(&msft->filter_lock); in msft_do_close()
695 list_for_each_entry_safe(address_filter, n, &msft->address_filters, in msft_do_close()
697 list_del(&address_filter->list); in msft_do_close()
700 mutex_unlock(&msft->filter_lock); in msft_do_close()
705 hdev->advmon_pend_notify = false; in msft_do_close()
715 struct msft_data *msft = hdev->msft_data; in msft_cancel_address_filter_sync()
721 return -EINVAL; in msft_cancel_address_filter_sync()
725 if (!test_bit(HCI_UP, &hdev->flags)) in msft_cancel_address_filter_sync()
728 mutex_lock(&msft->filter_lock); in msft_cancel_address_filter_sync()
729 list_del(&address_filter->list); in msft_cancel_address_filter_sync()
730 mutex_unlock(&msft->filter_lock); in msft_cancel_address_filter_sync()
733 cp.handle = address_filter->msft_handle; in msft_cancel_address_filter_sync()
735 skb = __hci_cmd_sync(hdev, hdev->msft_opcode, sizeof(cp), &cp, in msft_cancel_address_filter_sync()
739 &address_filter->bdaddr); in msft_cancel_address_filter_sync()
746 &address_filter->bdaddr); in msft_cancel_address_filter_sync()
766 INIT_LIST_HEAD(&msft->handle_map); in msft_register()
767 INIT_LIST_HEAD(&msft->address_filters); in msft_register()
768 hdev->msft_data = msft; in msft_register()
769 mutex_init(&msft->filter_lock); in msft_register()
774 struct msft_data *msft = hdev->msft_data; in msft_release()
781 hdev->msft_data = NULL; in msft_release()
783 kfree(msft->evt_prefix); in msft_release()
784 mutex_destroy(&msft->filter_lock); in msft_release()
788 /* This function requires the caller holds hdev->lock */
801 bacpy(&dev->bdaddr, bdaddr); in msft_device_found()
802 dev->addr_type = addr_type; in msft_device_found()
803 dev->handle = mgmt_handle; in msft_device_found()
804 dev->notified = false; in msft_device_found()
806 INIT_LIST_HEAD(&dev->list); in msft_device_found()
807 list_add(&dev->list, &hdev->monitored_devices); in msft_device_found()
808 hdev->advmon_pend_notify = true; in msft_device_found()
811 /* This function requires the caller holds hdev->lock */
829 bt_dev_err(hdev, "Malformed MSFT vendor event: 0x%02x", ev); in msft_skb_pull()
837 struct msft_rp_le_monitor_advertisement *rp; in msft_add_address_filter_sync() local
839 struct msft_data *msft = hdev->msft_data; in msft_add_address_filter_sync()
846 return -EINVAL; in msft_add_address_filter_sync()
850 if (!test_bit(HCI_UP, &hdev->flags)) in msft_add_address_filter_sync()
851 return -ENODEV; in msft_add_address_filter_sync()
861 if (address_filter->state == AF_STATE_REMOVING) { in msft_add_address_filter_sync()
862 mutex_lock(&msft->filter_lock); in msft_add_address_filter_sync()
863 list_del(&address_filter->list); in msft_add_address_filter_sync()
864 mutex_unlock(&msft->filter_lock); in msft_add_address_filter_sync()
870 sizeof(address_filter->addr_type) + in msft_add_address_filter_sync()
871 sizeof(address_filter->bdaddr); in msft_add_address_filter_sync()
879 cp->sub_opcode = MSFT_OP_LE_MONITOR_ADVERTISEMENT; in msft_add_address_filter_sync()
880 cp->rssi_high = address_filter->rssi_high; in msft_add_address_filter_sync()
881 cp->rssi_low = address_filter->rssi_low; in msft_add_address_filter_sync()
882 cp->rssi_low_interval = address_filter->rssi_low_interval; in msft_add_address_filter_sync()
883 cp->rssi_sampling_period = address_filter->rssi_sampling_period; in msft_add_address_filter_sync()
884 cp->cond_type = MSFT_MONITOR_ADVERTISEMENT_TYPE_ADDR; in msft_add_address_filter_sync()
885 cp->data[0] = address_filter->addr_type; in msft_add_address_filter_sync()
886 memcpy(&cp->data[1], &address_filter->bdaddr, in msft_add_address_filter_sync()
887 sizeof(address_filter->bdaddr)); in msft_add_address_filter_sync()
889 skb = __hci_cmd_sync(hdev, hdev->msft_opcode, size, cp, in msft_add_address_filter_sync()
895 &address_filter->bdaddr); in msft_add_address_filter_sync()
901 rp = skb_pull_data(skb, sizeof(*rp)); in msft_add_address_filter_sync()
902 if (!rp || rp->sub_opcode != MSFT_OP_LE_MONITOR_ADVERTISEMENT || in msft_add_address_filter_sync()
903 rp->status) in msft_add_address_filter_sync()
907 mutex_lock(&msft->filter_lock); in msft_add_address_filter_sync()
911 &address_filter->bdaddr); in msft_add_address_filter_sync()
912 list_del(&address_filter->list); in msft_add_address_filter_sync()
915 address_filter->state = AF_STATE_ADDED; in msft_add_address_filter_sync()
916 address_filter->msft_handle = rp->handle; in msft_add_address_filter_sync()
918 &address_filter->bdaddr); in msft_add_address_filter_sync()
920 mutex_unlock(&msft->filter_lock); in msft_add_address_filter_sync()
927 /* This function requires the caller holds msft->filter_lock */
933 struct msft_data *msft = hdev->msft_data; in msft_add_address_filter()
940 address_filter->state = AF_STATE_ADDING; in msft_add_address_filter()
941 address_filter->msft_handle = 0xff; in msft_add_address_filter()
942 address_filter->pattern_handle = handle_data->msft_handle; in msft_add_address_filter()
943 address_filter->mgmt_handle = handle_data->mgmt_handle; in msft_add_address_filter()
944 address_filter->rssi_high = handle_data->rssi_high; in msft_add_address_filter()
945 address_filter->rssi_low = handle_data->rssi_low; in msft_add_address_filter()
946 address_filter->rssi_low_interval = handle_data->rssi_low_interval; in msft_add_address_filter()
947 address_filter->rssi_sampling_period = handle_data->rssi_sampling_period; in msft_add_address_filter()
948 address_filter->addr_type = addr_type; in msft_add_address_filter()
949 bacpy(&address_filter->bdaddr, bdaddr); in msft_add_address_filter()
955 list_add_tail(&address_filter->list, &msft->address_filters); in msft_add_address_filter()
961 list_del(&address_filter->list); in msft_add_address_filter()
967 &address_filter->bdaddr); in msft_add_address_filter()
972 /* This function requires the caller holds hdev->lock */
978 struct msft_data *msft = hdev->msft_data; in msft_monitor_device_evt()
987 "MSFT vendor event 0x%02x: handle 0x%04x state %d addr %pMR", in msft_monitor_device_evt()
988 MSFT_EV_LE_MONITOR_DEVICE, ev->monitor_handle, in msft_monitor_device_evt()
989 ev->monitor_state, &ev->bdaddr); in msft_monitor_device_evt()
991 handle_data = msft_find_handle_data(hdev, ev->monitor_handle, false); in msft_monitor_device_evt()
993 if (!test_bit(HCI_QUIRK_USE_MSFT_EXT_ADDRESS_FILTER, &hdev->quirks)) { in msft_monitor_device_evt()
996 mgmt_handle = handle_data->mgmt_handle; in msft_monitor_device_evt()
1006 address_filter = msft_find_address_data(hdev, ev->addr_type, in msft_monitor_device_evt()
1007 &ev->bdaddr, in msft_monitor_device_evt()
1008 handle_data->msft_handle); in msft_monitor_device_evt()
1012 if (ev->monitor_state && handle_data->cond_type == in msft_monitor_device_evt()
1014 msft_add_address_filter(hdev, ev->addr_type, in msft_monitor_device_evt()
1015 &ev->bdaddr, handle_data); in msft_monitor_device_evt()
1023 list_for_each_entry(n, &msft->address_filters, list) { in msft_monitor_device_evt()
1024 if (n->state == AF_STATE_ADDED && in msft_monitor_device_evt()
1025 n->msft_handle == ev->monitor_handle) { in msft_monitor_device_evt()
1026 mgmt_handle = n->mgmt_handle; in msft_monitor_device_evt()
1034 &ev->bdaddr, ev->monitor_handle, ev->monitor_state); in msft_monitor_device_evt()
1039 switch (ev->addr_type) { in msft_monitor_device_evt()
1050 "MSFT vendor event 0x%02x: unknown addr type 0x%02x", in msft_monitor_device_evt()
1051 MSFT_EV_LE_MONITOR_DEVICE, ev->addr_type); in msft_monitor_device_evt()
1055 if (ev->monitor_state) { in msft_monitor_device_evt()
1056 msft_device_found(hdev, &ev->bdaddr, addr_type, mgmt_handle); in msft_monitor_device_evt()
1058 if (address_filter && address_filter->state == AF_STATE_ADDED) { in msft_monitor_device_evt()
1059 address_filter->state = AF_STATE_REMOVING; in msft_monitor_device_evt()
1065 msft_device_lost(hdev, &ev->bdaddr, addr_type, mgmt_handle); in msft_monitor_device_evt()
1071 struct msft_data *msft = hdev->msft_data; in msft_vendor_evt()
1081 if (msft->evt_prefix_len > 0) { in msft_vendor_evt()
1082 evt_prefix = msft_skb_pull(hdev, skb, 0, msft->evt_prefix_len); in msft_vendor_evt()
1086 if (memcmp(evt_prefix, msft->evt_prefix, msft->evt_prefix_len)) in msft_vendor_evt()
1093 if (skb->len < 1) in msft_vendor_evt()
1104 mutex_lock(&msft->filter_lock); in msft_vendor_evt()
1106 mutex_unlock(&msft->filter_lock); in msft_vendor_evt()
1110 bt_dev_dbg(hdev, "MSFT vendor event 0x%02x", *evt); in msft_vendor_evt()
1119 struct msft_data *msft = hdev->msft_data; in msft_get_features()
1121 return msft ? msft->features : 0; in msft_get_features()
1129 struct msft_data *msft = hdev->msft_data; in msft_le_set_advertisement_filter_enable_cb()
1143 msft->filter_enabled = cp->enable; in msft_le_set_advertisement_filter_enable_cb()
1147 cp->enable ? "on" : "off"); in msft_le_set_advertisement_filter_enable_cb()
1155 struct msft_data *msft = hdev->msft_data; in msft_add_monitor_pattern()
1158 return -EOPNOTSUPP; in msft_add_monitor_pattern()
1160 if (msft->resuming || msft->suspending) in msft_add_monitor_pattern()
1161 return -EBUSY; in msft_add_monitor_pattern()
1169 struct msft_data *msft = hdev->msft_data; in msft_remove_monitor()
1172 return -EOPNOTSUPP; in msft_remove_monitor()
1174 if (msft->resuming || msft->suspending) in msft_remove_monitor()
1175 return -EBUSY; in msft_remove_monitor()
1183 struct msft_data *msft = hdev->msft_data; in msft_set_filter_enable()
1187 return -EOPNOTSUPP; in msft_set_filter_enable()
1191 err = __hci_cmd_sync_status(hdev, hdev->msft_opcode, sizeof(cp), &cp, in msft_set_filter_enable()
1201 return hdev->msft_curve_validity; in msft_curve_validity()