Bluetooth: AMP: Check that AMP is present and active
authorAndrei Emeltchenko <andrei.emeltchenko@intel.com>
Thu, 29 Nov 2012 15:46:05 +0000 (17:46 +0200)
committerGustavo Padovan <gustavo.padovan@collabora.co.uk>
Mon, 3 Dec 2012 18:00:00 +0000 (16:00 -0200)
Before starting quering remote AMP controllers make sure
that there is local active AMP controller.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
include/net/bluetooth/hci_core.h
net/bluetooth/l2cap_core.c

index 2f2b743f5b109c455db951ab1407aad203e9a69e..014a2eaa53899d40e1d1eb91f54ba3870e09e9f4 100644 (file)
@@ -779,6 +779,22 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
 #define lmp_host_le_capable(dev)   !!((dev)->host_features[0] & LMP_HOST_LE)
 #define lmp_host_le_br_capable(dev) !!((dev)->host_features[0] & LMP_HOST_LE_BREDR)
 
+/* returns true if at least one AMP active */
+static inline bool hci_amp_capable(void)
+{
+       struct hci_dev *hdev;
+       bool ret = false;
+
+       read_lock(&hci_dev_list_lock);
+       list_for_each_entry(hdev, &hci_dev_list, list)
+               if (hdev->amp_type == HCI_AMP &&
+                   test_bit(HCI_UP, &hdev->flags))
+                       ret = true;
+       read_unlock(&hci_dev_list_lock);
+
+       return ret;
+}
+
 /* ----- HCI protocols ----- */
 #define HCI_PROTO_DEFER             0x01
 
index f7ee037c7934bfad4d104a63970af0a335af0146..d8cffdbf0d37c2692b9348f54069370ca357450d 100644 (file)
@@ -1013,6 +1013,7 @@ static bool __amp_capable(struct l2cap_chan *chan)
        struct l2cap_conn *conn = chan->conn;
 
        if (enable_hs &&
+           hci_amp_capable() &&
            chan->chan_policy == BT_CHANNEL_POLICY_AMP_PREFERRED &&
            conn->fixed_chan_mask & L2CAP_FC_A2MP)
                return true;