aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorJakub Pawlowski <jpawlowski@google.com>2015-03-04 19:24:25 -0500
committerJohan Hedberg <johan.hedberg@intel.com>2015-03-05 02:50:50 -0500
commit2976cdeb27c83c83bf010a314309f07659ead228 (patch)
tree22057c69c57c204342c723b2362d33c819d9ba1a /net/bluetooth
parent48f86b7f2673352d075e567a8f3425c548be8424 (diff)
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>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/mgmt.c89
1 files changed, 19 insertions, 70 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index a41a5efa4391..bc09c5a37032 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -7283,8 +7283,6 @@ static void restart_le_scan(struct hci_dev *hdev)
7283static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir, 7283static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir,
7284 u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len) 7284 u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len)
7285{ 7285{
7286 bool match;
7287
7288 /* If a RSSI threshold has been specified, and 7286 /* If a RSSI threshold has been specified, and
7289 * HCI_QUIRK_STRICT_DUPLICATE_FILTER is not set, then all results with 7287 * HCI_QUIRK_STRICT_DUPLICATE_FILTER is not set, then all results with
7290 * a RSSI smaller than the RSSI threshold will be dropped. If the quirk 7288 * 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,
7300 !test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)))) 7298 !test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks))))
7301 return false; 7299 return false;
7302 7300
7303 7301 if (hdev->discovery.uuid_count != 0) {
7304 if (eir_len > 0) { 7302 /* If a list of UUIDs is provided in filter, results with no
7305 /* When using service discovery and a list of UUID is 7303 * matching UUID should be dropped.
7306 * provided, results with no matching UUID should be
7307 * dropped. In case there is a match the result is
7308 * kept and checking possible scan response data
7309 * will be skipped.
7310 */
7311 if (hdev->discovery.uuid_count > 0) {
7312 match = eir_has_uuids(eir, eir_len,
7313 hdev->discovery.uuid_count,
7314 hdev->discovery.uuids);
7315 /* If duplicate filtering does not report RSSI changes,
7316 * then restart scanning to ensure updated result with
7317 * updated RSSI values.
7318 */
7319 if (match && test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER,
7320 &hdev->quirks))
7321 restart_le_scan(hdev);
7322 } else {
7323 match = true;
7324 }
7325
7326 if (!match && !scan_rsp_len)
7327 return false;
7328 } else {
7329 /* When using service discovery and a list of UUID is
7330 * provided, results with empty EIR or advertising data
7331 * should be dropped since they do not match any UUID.
7332 */
7333 if (hdev->discovery.uuid_count > 0 && !scan_rsp_len)
7334 return false;
7335
7336 match = false;
7337 }
7338
7339 if (scan_rsp_len > 0) {
7340 /* When using service discovery and a list of UUID is
7341 * provided, results with no matching UUID should be
7342 * dropped if there is no previous match from the
7343 * advertising data.
7344 */
7345 if (hdev->discovery.uuid_count > 0) {
7346 if (!match && !eir_has_uuids(scan_rsp, scan_rsp_len,
7347 hdev->discovery.uuid_count,
7348 hdev->discovery.uuids))
7349 return false;
7350
7351 /* If duplicate filtering does not report RSSI changes,
7352 * then restart scanning to ensure updated result with
7353 * updated RSSI values.
7354 */
7355 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER,
7356 &hdev->quirks))
7357 restart_le_scan(hdev);
7358 }
7359 } else {
7360 /* When using service discovery and a list of UUID is
7361 * provided, results with empty scan response and no
7362 * previous matched advertising data should be dropped.
7363 */ 7304 */
7364 if (hdev->discovery.uuid_count > 0 && !match) 7305 if (!eir_has_uuids(eir, eir_len, hdev->discovery.uuid_count,
7365 return false; 7306 hdev->discovery.uuids) &&
7307 !eir_has_uuids(scan_rsp, scan_rsp_len,
7308 hdev->discovery.uuid_count,
7309 hdev->discovery.uuids))
7310 return false;
7366 } 7311 }
7367 7312
7368 /* Validate the reported RSSI value against the RSSI threshold once more 7313 /* If duplicate filtering does not report RSSI changes, then restart
7369 * incase HCI_QUIRK_STRICT_DUPLICATE_FILTER forced a restart of LE 7314 * scanning to ensure updated result with updated RSSI values.
7370 * scanning.
7371 */ 7315 */
7372 if (hdev->discovery.rssi != HCI_RSSI_INVALID && 7316 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks)) {
7373 rssi < hdev->discovery.rssi) 7317 restart_le_scan(hdev);
7374 return false; 7318
7319 /* Validate RSSI value against the RSSI threshold once more. */
7320 if (hdev->discovery.rssi != HCI_RSSI_INVALID &&
7321 rssi < hdev->discovery.rssi)
7322 return false;
7323 }
7375 7324
7376 return true; 7325 return true;
7377} 7326}