Skip to content

Commit 2e84d8d

Browse files
holtmannjhedberg
authored andcommitted
Bluetooth: Mark controller is down when HCI_AUTO_OFF is set
During the initial setup phase, the controller is powered on and will be powered off again if it is not used within the auto-off timeout. Userspace using ioctl does not know about the difference between the initial setup phase and a controller being present. It is a bad idea to keep the controller powered by just looking at the device list or device information. Instead just tell userspace that the controller is still down. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
1 parent 13a779e commit 2e84d8d

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

‎net/bluetooth/hci_core.c‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,14 +2817,20 @@ int hci_get_dev_list(void __user *arg)
28172817

28182818
read_lock(&hci_dev_list_lock);
28192819
list_for_each_entry(hdev, &hci_dev_list, list) {
2820-
if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags))
2821-
cancel_delayed_work(&hdev->power_off);
2820+
unsigned long flags = hdev->flags;
2821+
2822+
/* When the auto-off is configured it means the transport
2823+
* is running, but in that case still indicate that the
2824+
* device is actually down.
2825+
*/
2826+
if (test_bit(HCI_AUTO_OFF, &hdev->dev_flags))
2827+
flags &= ~BIT(HCI_UP);
28222828

28232829
if (!test_bit(HCI_MGMT, &hdev->dev_flags))
28242830
set_bit(HCI_PAIRABLE, &hdev->dev_flags);
28252831

28262832
(dr + n)->dev_id = hdev->id;
2827-
(dr + n)->dev_opt = hdev->flags;
2833+
(dr + n)->dev_opt = flags;
28282834

28292835
if (++n >= dev_num)
28302836
break;
@@ -2844,6 +2850,7 @@ int hci_get_dev_info(void __user *arg)
28442850
{
28452851
struct hci_dev *hdev;
28462852
struct hci_dev_info di;
2853+
unsigned long flags;
28472854
int err = 0;
28482855

28492856
if (copy_from_user(&di, arg, sizeof(di)))
@@ -2853,16 +2860,22 @@ int hci_get_dev_info(void __user *arg)
28532860
if (!hdev)
28542861
return -ENODEV;
28552862

2856-
if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags))
2857-
cancel_delayed_work_sync(&hdev->power_off);
2863+
/* When the auto-off is configured it means the transport
2864+
* is running, but in that case still indicate that the
2865+
* device is actually down.
2866+
*/
2867+
if (test_bit(HCI_AUTO_OFF, &hdev->dev_flags))
2868+
flags = hdev->flags & ~BIT(HCI_UP);
2869+
else
2870+
flags = hdev->flags;
28582871

28592872
if (!test_bit(HCI_MGMT, &hdev->dev_flags))
28602873
set_bit(HCI_PAIRABLE, &hdev->dev_flags);
28612874

28622875
strcpy(di.name, hdev->name);
28632876
di.bdaddr = hdev->bdaddr;
28642877
di.type = (hdev->bus & 0x0f) | ((hdev->dev_type & 0x03) << 4);
2865-
di.flags = hdev->flags;
2878+
di.flags = flags;
28662879
di.pkt_type = hdev->pkt_type;
28672880
if (lmp_bredr_capable(hdev)) {
28682881
di.acl_mtu = hdev->acl_mtu;

0 commit comments

Comments
 (0)