#define SERVICE_CACHE_TIMEOUT (5 * 1000)
+#define hdev_is_powered(hdev) (test_bit(HCI_UP, &hdev->flags) && \
+ !test_bit(HCI_AUTO_OFF, &hdev->dev_flags))
+
struct pending_cmd {
struct list_head list;
u16 opcode;
struct mgmt_mode *cp = data;
struct hci_dev *hdev;
struct pending_cmd *cmd;
- int err, up;
+ int err;
BT_DBG("request for hci%u", index);
}
}
- up = test_bit(HCI_UP, &hdev->flags);
- if ((cp->val && up) || (!cp->val && !up)) {
+ if (!!cp->val == hdev_is_powered(hdev)) {
err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev);
goto failed;
}
hci_dev_lock(hdev);
- if (!test_bit(HCI_UP, &hdev->flags)) {
+ if (!hdev_is_powered(hdev)) {
err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE,
MGMT_STATUS_NOT_POWERED);
goto failed;
hci_dev_lock(hdev);
- if (!test_bit(HCI_UP, &hdev->flags)) {
+ if (!hdev_is_powered(hdev)) {
err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE,
MGMT_STATUS_NOT_POWERED);
goto failed;
hci_dev_lock(hdev);
- if (!test_bit(HCI_UP, &hdev->flags)) {
+ if (!hdev_is_powered(hdev)) {
err = cmd_status(sk, index, MGMT_OP_SET_LINK_SECURITY,
MGMT_STATUS_NOT_POWERED);
goto failed;
hci_dev_lock(hdev);
- if (!test_bit(HCI_UP, &hdev->flags)) {
+ if (!hdev_is_powered(hdev)) {
err = cmd_status(sk, index, MGMT_OP_SET_SSP,
MGMT_STATUS_NOT_POWERED);
goto failed;
hci_dev_lock(hdev);
- if (!test_bit(HCI_UP, &hdev->flags)) {
+ if (!hdev_is_powered(hdev)) {
err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY,
MGMT_STATUS_NOT_POWERED);
goto failed;
hci_dev_lock(hdev);
- if (!test_bit(HCI_UP, &hdev->flags)) {
+ if (!hdev_is_powered(hdev)) {
err = cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY,
MGMT_STATUS_NOT_POWERED);
goto failed;
hci_dev_lock(hdev);
- if (!test_bit(HCI_UP, &hdev->flags)) {
+ if (!hdev_is_powered(hdev)) {
err = cmd_status(sk, index, mgmt_op, MGMT_STATUS_NOT_POWERED);
goto done;
}
hci_dev_lock(hdev);
- if (!test_bit(HCI_UP, &hdev->flags)) {
+ if (!hdev_is_powered(hdev)) {
err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
MGMT_STATUS_NOT_POWERED);
goto unlock;
hci_dev_lock(hdev);
- if (!test_bit(HCI_UP, &hdev->flags)) {
+ if (!hdev_is_powered(hdev)) {
err = cmd_status(sk, index, MGMT_OP_START_DISCOVERY,
MGMT_STATUS_NOT_POWERED);
goto failed;