Bluetooth: Fix mgmt handling of power on failures
Subsystems (2)
PATCH 1/1 Bluetooth: Fix mgmt handling of power on failures
From: Johan Hedberg <[email protected]>
If hci_dev_open fails we need to ensure that the corresponding mgmt_set_powered command gets an appropriate response. This patch fixes the missing response by adding a new mgmt_set_powered_failed function that's used to indicate a power on failure to mgmt.
--- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 6 +++++- net/bluetooth/mgmt.c | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -1118,6 +1118,7 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event);int mgmt_control (struct sock *sk,struct msghdr *msg,size_t len);int mgmt_index_added (struct hci_dev *hdev);int mgmt_index_removed (struct hci_dev *hdev); +int mgmt_set_powered_failed (struct hci_dev *hdev,int err);int mgmt_powered (struct hci_dev *hdev,u8 powered);int mgmt_discoverable (struct hci_dev *hdev,u8 discoverable);int mgmt_connectable (struct hci_dev *hdev,u8 connectable);
net/bluetooth/hci_core.c +5 -1
@@ -1598,11 +1598,15 @@ static const struct rfkill_ops hci_rfkill_ops = {static void hci_power_on (struct work_struct *work) { struct hci_dev *hdev = container_of(work, struct hci_dev, power_on); +int err;BT_DBG ("%s" , hdev->name); -if (hci_dev_open (hdev->id) <0 ) + err =hci_dev_open (hdev->id); +if (err <0 ) { +mgmt_set_powered_failed (hdev, err);return ; + }if (test_bit (HCI_AUTO_OFF , &hdev->dev_flags)) queue_delayed_work(hdev->req_workqueue, &hdev->power_off,
net/bluetooth/mgmt.c +16 -0
@@ -3533,6 +3533,22 @@ new_settings:return err; } +int mgmt_set_powered_failed (struct hci_dev *hdev,int err) +{ +struct pending_cmd *cmd; + + cmd =mgmt_pending_find (MGMT_OP_SET_POWERED , hdev); +if (!cmd) +return -ENOENT ; + + err =cmd_status (cmd->sk, hdev->id,MGMT_OP_SET_POWERED , +MGMT_STATUS_FAILED ); + +mgmt_pending_remove (cmd); + +return err; +} +int mgmt_discoverable (struct hci_dev *hdev,u8 discoverable) {struct cmd_lookup match = {NULL , hdev };
Signature · 1 line
1.7.10.4
Hi Johan,
Quoted 6 lines · Johan Hedberg
net/bluetooth/mgmt.c +6
-0+int mgmt_set_powered_failed (struct hci_dev *hdev,int err) +{ +struct pending_cmd *cmd; + + cmd =mgmt_pending_find (MGMT_OP_SET_POWERED , hdev); +if (!cmd)
net/bluetooth/mgmt.c new_settings: · line 3551
Quoted 10 lines
net/bluetooth/mgmt.c +10
-0+return -ENOENT ; + + err =cmd_status (cmd->sk, hdev->id,MGMT_OP_SET_POWERED , +MGMT_STATUS_FAILED ); + +mgmt_pending_remove (cmd); + +return err; +} +
Was the "err" parameter value supposed to be used on this function?
Best Regards,
Signature · 3 lines
Anderson Lizardo Instituto Nokia de Tecnologia - INdT Manaus - Brazil
Hi Lizardo,
Quoted 11 lines · Anderson Lizardo
Quoted 10 lines · Johan Hedberg
net/bluetooth/mgmt.c +10
-0+int mgmt_set_powered_failed (struct hci_dev *hdev,int err) +{ +struct pending_cmd *cmd; + + cmd =mgmt_pending_find (MGMT_OP_SET_POWERED , hdev); +if (!cmd) +return -ENOENT ; + + err =cmd_status (cmd->sk, hdev->id,MGMT_OP_SET_POWERED , +MGMT_STATUS_FAILED );
Quoted 8 lines
net/bluetooth/mgmt.c new_settings: · line 3551
Quoted 6 lines
net/bluetooth/mgmt.c +6
-0+ +mgmt_pending_remove (cmd); + +return err; +} +Was the "err" parameter value supposed to be used on this function?
As I mentioned in my reply to Marcel it's there so this can be easily extended to have a special mapping to the exact mgmt error returned (and now it seems that this mapping will be implemented before this goes upstream).
Johan
Hi Johan,
Quoted 7 lines · Johan Hedberg
From: Johan Hedberg <[email protected]>
If
hci_dev_openfails we need to ensure that the correspondingmgmt_set_poweredcommand gets an appropriate response. This patch fixes the missing response by adding a newmgmt_set_powered_failedfunction that's used to indicate a power on failure to mgmt.
Quoted 6 lines
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 6 +++++- net/bluetooth/mgmt.c | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-)
Patch has been applied to bluetooth.git. Thanks.
Gustavo
Marcel Holtmann
maintainerHi Gustavo,
Quoted 5 lines
Quoted 5 lines
If
hci_dev_openfails we need to ensure that the correspondingmgmt_set_poweredcommand gets an appropriate response. This patch fixes the missing response by adding a newmgmt_set_powered_failedfunction that's used to indicate a power on failure to mgmt.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Johan Hedberg <[email protected]>---
include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 6 +++++- net/bluetooth/mgmt.c | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-)Patch has been applied to bluetooth.git. Thanks.
I rather have this fixed properly with a new error for specifically ERFKILL. Having one stable kernel return rejected and another rfkill is a bad idea.
Regards
Marcel
PATCH v2 1/1 Bluetooth: Fix mgmt handling of power on failures
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
If hci_dev_open fails we need to ensure that the corresponding mgmt_set_powered command gets an appropriate response. This patch fixes the missing response by adding a new mgmt_set_powered_failed function that's used to indicate a power on failure to mgmt. Since a sutuation with the device being rfkilled may require special handling in user space the patch uses a new dedicated mgmt status code for this.
---
v2: Added dedicated mgmt error for the ERFKILL case
include/net/bluetooth/hci_core.h | 1 + include/net/bluetooth/mgmt.h | 1 + net/bluetooth/hci_core.c | 6 +++++- net/bluetooth/mgmt.c | 21 +++++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -1118,6 +1118,7 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event);int mgmt_control (struct sock *sk,struct msghdr *msg,size_t len);int mgmt_index_added (struct hci_dev *hdev);int mgmt_index_removed (struct hci_dev *hdev); +int mgmt_set_powered_failed (struct hci_dev *hdev,int err);int mgmt_powered (struct hci_dev *hdev,u8 powered);int mgmt_discoverable (struct hci_dev *hdev,u8 discoverable);int mgmt_connectable (struct hci_dev *hdev,u8 connectable);
include/net/bluetooth/mgmt.h +1 -0
@@ -42,6 +42,7 @@#define MGMT_STATUS_NOT_POWERED 0x0f#define MGMT_STATUS_CANCELLED 0x10#define MGMT_STATUS_INVALID_INDEX 0x11 +#define MGMT_STATUS_RFKILLED 0x12struct mgmt_hdr {__le16 opcode;
net/bluetooth/hci_core.c +5 -1
@@ -1598,11 +1598,15 @@ static const struct rfkill_ops hci_rfkill_ops = {static void hci_power_on (struct work_struct *work) { struct hci_dev *hdev = container_of(work, struct hci_dev, power_on); +int err;BT_DBG ("%s" , hdev->name); -if (hci_dev_open (hdev->id) <0 ) + err =hci_dev_open (hdev->id); +if (err <0 ) { +mgmt_set_powered_failed (hdev, err);return ; + }if (test_bit (HCI_AUTO_OFF , &hdev->dev_flags)) queue_delayed_work(hdev->req_workqueue, &hdev->power_off,
net/bluetooth/mgmt.c +21 -0
@@ -3533,6 +3533,27 @@ new_settings:return err; } +int mgmt_set_powered_failed (struct hci_dev *hdev,int err) +{ +struct pending_cmd *cmd; +u8 status; + + cmd =mgmt_pending_find (MGMT_OP_SET_POWERED , hdev); +if (!cmd) +return -ENOENT ; + +if (err == -ERFKILL ) + status =MGMT_STATUS_RFKILLED ; +else + status =MGMT_STATUS_FAILED ; + + err =cmd_status (cmd->sk, hdev->id,MGMT_OP_SET_POWERED , status); + +mgmt_pending_remove (cmd); + +return err; +} +int mgmt_discoverable (struct hci_dev *hdev,u8 discoverable) {struct cmd_lookup match = {NULL , hdev };
Signature · 1 line
1.7.10.4
Hi Johan,
Quoted 4 lines
If
hci_dev_openfails we need to ensure that the correspondingmgmt_set_poweredcommand gets an appropriate response. This patch fixes the missing response by adding a newmgmt_set_powered_failedfunction that's used to indicate a power on failure to mgmt. Since a situation
might want to fix this typo.
Quoted 81 lines
with the device being rfkilled may require special handling in user space the patch uses a new dedicated mgmt status code for this.
Signed-off-by Johan Hedberg <[email protected]>---
v2: Added dedicated mgmt error for the ERFKILL caseinclude/net/bluetooth/hci_core.h | 1 + include/net/bluetooth/mgmt.h | 1 + net/bluetooth/hci_core.c | 6 +++++- net/bluetooth/mgmt.c | 21 +++++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-)include/net/bluetooth/hci_core.h +1
-0@@ -1118,6 +1118,7 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event);int mgmt_control (struct sock *sk,struct msghdr *msg,size_t len);int mgmt_index_added (struct hci_dev *hdev);int mgmt_index_removed (struct hci_dev *hdev); +int mgmt_set_powered_failed (struct hci_dev *hdev,int err);int mgmt_powered (struct hci_dev *hdev,u8 powered);int mgmt_discoverable (struct hci_dev *hdev,u8 discoverable);int mgmt_connectable (struct hci_dev *hdev,u8 connectable);include/net/bluetooth/mgmt.h +1
-0@@ -42,6 +42,7 @@#define MGMT_STATUS_NOT_POWERED 0x0f#define MGMT_STATUS_CANCELLED 0x10#define MGMT_STATUS_INVALID_INDEX 0x11 +#define MGMT_STATUS_RFKILLED 0x12struct mgmt_hdr {__le16 opcode;net/bluetooth/hci_core.c +5
-1@@ -1598,11 +1598,15 @@ static const struct rfkill_ops hci_rfkill_ops = {static void hci_power_on (struct work_struct *work) { struct hci_dev *hdev = container_of(work, struct hci_dev, power_on); +int err;BT_DBG ("%s" , hdev->name); -if (hci_dev_open (hdev->id) <0 ) + err =hci_dev_open (hdev->id); +if (err <0 ) { +mgmt_set_powered_failed (hdev, err);return ; + }if (test_bit (HCI_AUTO_OFF , &hdev->dev_flags)) queue_delayed_work(hdev->req_workqueue, &hdev->power_off,net/bluetooth/mgmt.c +14
-0@@ -3533,6 +3533,27 @@ new_settings:return err; } +int mgmt_set_powered_failed (struct hci_dev *hdev,int err) +{ +struct pending_cmd *cmd; +u8 status; + + cmd =mgmt_pending_find (MGMT_OP_SET_POWERED , hdev); +if (!cmd) +return -ENOENT ; + +if (err == -ERFKILL ) + status =MGMT_STATUS_RFKILLED ; +else + status =MGMT_STATUS_FAILED ; +
net/bluetooth/mgmt.c new_settings: · line 3559
Quoted 10 lines
net/bluetooth/mgmt.c +7
-0+ err =cmd_status (cmd->sk, hdev->id,MGMT_OP_SET_POWERED , status); + +mgmt_pending_remove (cmd); + +return err; +} +int mgmt_discoverable (struct hci_dev *hdev,u8 discoverable) {struct cmd_lookup match = {NULL , hdev };
We do not need to do this in this patch, but I think we need to get rid of all the return values for the status notification functions. Since we never use them, it is pointless to keep them around. Or are we doing anything useful with them.
Anyhow, this patch is fine with me.
Regards
Marcel
Hi Johan,
Quoted 11 lines · Johan Hedberg
From: Johan Hedberg <[email protected]>
If
hci_dev_openfails we need to ensure that the correspondingmgmt_set_poweredcommand gets an appropriate response. This patch fixes the missing response by adding a newmgmt_set_powered_failedfunction that's used to indicate a power on failure to mgmt. Since a sutuation with the device being rfkilled may require special handling in user space the patch uses a new dedicated mgmt status code for this.Signed-off-by Johan Hedberg <[email protected]>
Quoted 8 lines
---
v2: Added dedicated mgmt error for the ERFKILL caseinclude/net/bluetooth/hci_core.h | 1 + include/net/bluetooth/mgmt.h | 1 + net/bluetooth/hci_core.c | 6 +++++- net/bluetooth/mgmt.c | 21 +++++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-)
Patch has been applied, I fixed the typo too. Thanks.
Gustavo