aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/hci_request.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/bluetooth/hci_request.c')
-rw-r--r--net/bluetooth/hci_request.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index e49f682f1550..5e64ea70a106 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -396,6 +396,62 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy,
396 return 0; 396 return 0;
397} 397}
398 398
399static bool disconnected_whitelist_entries(struct hci_dev *hdev)
400{
401 struct bdaddr_list *b;
402
403 list_for_each_entry(b, &hdev->whitelist, list) {
404 struct hci_conn *conn;
405
406 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr);
407 if (!conn)
408 return true;
409
410 if (conn->state != BT_CONNECTED && conn->state != BT_CONFIG)
411 return true;
412 }
413
414 return false;
415}
416
417void __hci_update_page_scan(struct hci_request *req)
418{
419 struct hci_dev *hdev = req->hdev;
420 u8 scan;
421
422 if (!test_bit(HCI_BREDR_ENABLED, &hdev->dev_flags))
423 return;
424
425 if (!hdev_is_powered(hdev))
426 return;
427
428 if (mgmt_powering_down(hdev))
429 return;
430
431 if (test_bit(HCI_CONNECTABLE, &hdev->dev_flags) ||
432 disconnected_whitelist_entries(hdev))
433 scan = SCAN_PAGE;
434 else
435 scan = SCAN_DISABLED;
436
437 if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE))
438 return;
439
440 if (test_bit(HCI_DISCOVERABLE, &hdev->dev_flags))
441 scan |= SCAN_INQUIRY;
442
443 hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
444}
445
446void hci_update_page_scan(struct hci_dev *hdev)
447{
448 struct hci_request req;
449
450 hci_req_init(&req, hdev);
451 __hci_update_page_scan(&req);
452 hci_req_run(&req, NULL);
453}
454
399/* This function controls the background scanning based on hdev->pend_le_conns 455/* This function controls the background scanning based on hdev->pend_le_conns
400 * list. If there are pending LE connection we start the background scanning, 456 * list. If there are pending LE connection we start the background scanning,
401 * otherwise we stop it. 457 * otherwise we stop it.