aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorAndre Guedes <andre.guedes@openbossa.org>2014-02-26 18:21:42 -0500
committerMarcel Holtmann <marcel@holtmann.org>2014-02-26 22:41:33 -0500
commit2acf3d9066b36e1b05db42bfe43152eee07a5e9e (patch)
treeb677f53f8cef51eb29452a9cec30c259ddf64742 /net/bluetooth
parent06c053fb54c10be49ef30fc9b6b01e42cc9a1b61 (diff)
Bluetooth: Stop scanning on LE connection
Some LE controllers don't support scanning and creating a connection at the same time. So we should always stop scanning in order to establish the connection. Since we may prematurely stop the discovery procedure in favor of the connection establishment, we should also cancel hdev->le_scan_ disable delayed work and set the discovery state to DISCOVERY_STOPPED. This change does a small improvement since it is not mandatory the user stops scanning before connecting anymore. Moreover, this change is required by upcoming LE auto connection mechanism in order to work properly with controllers that don't support background scanning and connection establishment at the same time. In future, we might want to do a small optimization by checking if controller is able to scan and connect at the same time. For now, we want the simplest approach so we always stop scanning (even if the controller is able to carry out both operations). Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/hci_conn.c92
1 files changed, 90 insertions, 2 deletions
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index dc8aad946426..2b8bfda3ea35 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -594,12 +594,86 @@ static int hci_create_le_conn(struct hci_conn *conn)
594 return 0; 594 return 0;
595} 595}
596 596
597static void hci_req_add_le_create_conn(struct hci_request *req,
598 struct hci_conn *conn)
599{
600 struct hci_cp_le_create_conn cp;
601 struct hci_dev *hdev = conn->hdev;
602 u8 own_addr_type;
603
604 memset(&cp, 0, sizeof(cp));
605
606 /* Update random address, but set require_privacy to false so
607 * that we never connect with an unresolvable address.
608 */
609 if (hci_update_random_address(req, false, &own_addr_type))
610 return;
611
612 /* Save the address type used for this connnection attempt so we able
613 * to retrieve this information if we need it.
614 */
615 conn->src_type = own_addr_type;
616
617 cp.scan_interval = cpu_to_le16(hdev->le_scan_interval);
618 cp.scan_window = cpu_to_le16(hdev->le_scan_window);
619 bacpy(&cp.peer_addr, &conn->dst);
620 cp.peer_addr_type = conn->dst_type;
621 cp.own_address_type = own_addr_type;
622 cp.conn_interval_min = cpu_to_le16(conn->le_conn_min_interval);
623 cp.conn_interval_max = cpu_to_le16(conn->le_conn_max_interval);
624 cp.supervision_timeout = __constant_cpu_to_le16(0x002a);
625 cp.min_ce_len = __constant_cpu_to_le16(0x0000);
626 cp.max_ce_len = __constant_cpu_to_le16(0x0000);
627
628 hci_req_add(req, HCI_OP_LE_CREATE_CONN, sizeof(cp), &cp);
629}
630
631static void stop_scan_complete(struct hci_dev *hdev, u8 status)
632{
633 struct hci_request req;
634 struct hci_conn *conn;
635 int err;
636
637 conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
638 if (!conn)
639 return;
640
641 if (status) {
642 BT_DBG("HCI request failed to stop scanning: status 0x%2.2x",
643 status);
644
645 hci_dev_lock(hdev);
646 hci_le_conn_failed(conn, status);
647 hci_dev_unlock(hdev);
648 return;
649 }
650
651 /* Since we may have prematurely stopped discovery procedure, we should
652 * update discovery state.
653 */
654 cancel_delayed_work(&hdev->le_scan_disable);
655 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
656
657 hci_req_init(&req, hdev);
658
659 hci_req_add_le_create_conn(&req, conn);
660
661 err = hci_req_run(&req, create_le_conn_complete);
662 if (err) {
663 hci_dev_lock(hdev);
664 hci_le_conn_failed(conn, HCI_ERROR_MEMORY_EXCEEDED);
665 hci_dev_unlock(hdev);
666 return;
667 }
668}
669
597static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, 670static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
598 u8 dst_type, u8 sec_level, u8 auth_type) 671 u8 dst_type, u8 sec_level, u8 auth_type)
599{ 672{
600 struct hci_conn_params *params; 673 struct hci_conn_params *params;
601 struct hci_conn *conn; 674 struct hci_conn *conn;
602 struct smp_irk *irk; 675 struct smp_irk *irk;
676 struct hci_request req;
603 int err; 677 int err;
604 678
605 if (test_bit(HCI_ADVERTISING, &hdev->flags)) 679 if (test_bit(HCI_ADVERTISING, &hdev->flags))
@@ -675,9 +749,23 @@ static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
675 conn->le_conn_max_interval = hdev->le_conn_max_interval; 749 conn->le_conn_max_interval = hdev->le_conn_max_interval;
676 } 750 }
677 751
678 err = hci_create_le_conn(conn); 752 hci_req_init(&req, hdev);
679 if (err) 753
754 /* If controller is scanning, we stop it since some controllers are
755 * not able to scan and connect at the same time.
756 */
757 if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) {
758 hci_req_add_le_scan_disable(&req);
759 err = hci_req_run(&req, stop_scan_complete);
760 } else {
761 hci_req_add_le_create_conn(&req, conn);
762 err = hci_req_run(&req, create_le_conn_complete);
763 }
764
765 if (err) {
766 hci_conn_del(conn);
680 return ERR_PTR(err); 767 return ERR_PTR(err);
768 }
681 769
682done: 770done:
683 hci_conn_hold(conn); 771 hci_conn_hold(conn);