Bluetooth: Refactor service discovery filter logic
This patch refactor code responsible for filtering when service discovery method is used. Previously this code was mixed with mgmt_device found logic. Now when it's in one place whole logic can be greatly simplified. That includes removing no longer necessary length field and merging checks for eir and scan_rsp. Signed-off-by: Jakub Pawlowski <jpawlowski@google.com> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
48f86b7f26
commit
2976cdeb27
@ -7283,8 +7283,6 @@ static void restart_le_scan(struct hci_dev *hdev)
|
|||||||
static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir,
|
static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir,
|
||||||
u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len)
|
u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len)
|
||||||
{
|
{
|
||||||
bool match;
|
|
||||||
|
|
||||||
/* If a RSSI threshold has been specified, and
|
/* If a RSSI threshold has been specified, and
|
||||||
* HCI_QUIRK_STRICT_DUPLICATE_FILTER is not set, then all results with
|
* HCI_QUIRK_STRICT_DUPLICATE_FILTER is not set, then all results with
|
||||||
* a RSSI smaller than the RSSI threshold will be dropped. If the quirk
|
* a RSSI smaller than the RSSI threshold will be dropped. If the quirk
|
||||||
@ -7300,78 +7298,29 @@ static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir,
|
|||||||
!test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks))))
|
!test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks))))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (hdev->discovery.uuid_count != 0) {
|
||||||
if (eir_len > 0) {
|
/* If a list of UUIDs is provided in filter, results with no
|
||||||
/* When using service discovery and a list of UUID is
|
* matching UUID should be dropped.
|
||||||
* provided, results with no matching UUID should be
|
|
||||||
* dropped. In case there is a match the result is
|
|
||||||
* kept and checking possible scan response data
|
|
||||||
* will be skipped.
|
|
||||||
*/
|
*/
|
||||||
if (hdev->discovery.uuid_count > 0) {
|
if (!eir_has_uuids(eir, eir_len, hdev->discovery.uuid_count,
|
||||||
match = eir_has_uuids(eir, eir_len,
|
hdev->discovery.uuids) &&
|
||||||
hdev->discovery.uuid_count,
|
!eir_has_uuids(scan_rsp, scan_rsp_len,
|
||||||
hdev->discovery.uuids);
|
|
||||||
/* If duplicate filtering does not report RSSI changes,
|
|
||||||
* then restart scanning to ensure updated result with
|
|
||||||
* updated RSSI values.
|
|
||||||
*/
|
|
||||||
if (match && test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER,
|
|
||||||
&hdev->quirks))
|
|
||||||
restart_le_scan(hdev);
|
|
||||||
} else {
|
|
||||||
match = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!match && !scan_rsp_len)
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
/* When using service discovery and a list of UUID is
|
|
||||||
* provided, results with empty EIR or advertising data
|
|
||||||
* should be dropped since they do not match any UUID.
|
|
||||||
*/
|
|
||||||
if (hdev->discovery.uuid_count > 0 && !scan_rsp_len)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
match = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scan_rsp_len > 0) {
|
|
||||||
/* When using service discovery and a list of UUID is
|
|
||||||
* provided, results with no matching UUID should be
|
|
||||||
* dropped if there is no previous match from the
|
|
||||||
* advertising data.
|
|
||||||
*/
|
|
||||||
if (hdev->discovery.uuid_count > 0) {
|
|
||||||
if (!match && !eir_has_uuids(scan_rsp, scan_rsp_len,
|
|
||||||
hdev->discovery.uuid_count,
|
hdev->discovery.uuid_count,
|
||||||
hdev->discovery.uuids))
|
hdev->discovery.uuids))
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* If duplicate filtering does not report RSSI changes,
|
/* If duplicate filtering does not report RSSI changes, then restart
|
||||||
* then restart scanning to ensure updated result with
|
* scanning to ensure updated result with updated RSSI values.
|
||||||
* updated RSSI values.
|
|
||||||
*/
|
*/
|
||||||
if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER,
|
if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)) {
|
||||||
&hdev->quirks))
|
|
||||||
restart_le_scan(hdev);
|
restart_le_scan(hdev);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* When using service discovery and a list of UUID is
|
|
||||||
* provided, results with empty scan response and no
|
|
||||||
* previous matched advertising data should be dropped.
|
|
||||||
*/
|
|
||||||
if (hdev->discovery.uuid_count > 0 && !match)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Validate the reported RSSI value against the RSSI threshold once more
|
/* Validate RSSI value against the RSSI threshold once more. */
|
||||||
* incase HCI_QUIRK_STRICT_DUPLICATE_FILTER forced a restart of LE
|
|
||||||
* scanning.
|
|
||||||
*/
|
|
||||||
if (hdev->discovery.rssi != HCI_RSSI_INVALID &&
|
if (hdev->discovery.rssi != HCI_RSSI_INVALID &&
|
||||||
rssi < hdev->discovery.rssi)
|
rssi < hdev->discovery.rssi)
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user