Skip to contentSkip to conversation

Bluetooth: Fix notifying discovery state upon reset

PATCH In review Johan Hedberg 2 participants 5 messages Jan 28, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Bluetooth: Fix notifying discovery state upon reset

From: Johan Hedberg <[email protected]>

When HCI_Reset is issued the discovery state is assumed to be stopped. The hci_cc_reset() handler was trying to set the state but it was doing it without using the hci_discovery_set_state() function. Because of this e.g. the mgmt Discovering event could go without being sent. This patch fixes the code to use the hci_discovery_set_state() function instead of just blindly setting the state value.

---
 net/bluetooth/hci_event.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/bluetooth/hci_event.c +2 -1
index 00c160634e7b..4175470ff48e 100644
@@ -200,7 +200,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
 	/* Reset all non-persistent flags */
 	hdev->dev_flags &= ~HCI_PERSISTENT_MASK;
 
-	hdev->discovery.state = DISCOVERY_STOPPED;
+	hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
+
 	hdev->inq_tx_power = HCI_TX_POWER_INVALID;
 	hdev->adv_tx_power = HCI_TX_POWER_INVALID;
 
Signature · 1 line
2.1.0
#1 lore raw

PATCH 2/3 Bluetooth: Fix notifying discovery state when powering off

From: Johan Hedberg <[email protected]>

The discovery state should be set to stopped when the HCI device is powered off. This patch adds the appropriate call to the hci_discovery_set_state() function from hci_dev_do_close() which is responsible for the power-off procedure.

---
 net/bluetooth/hci_core.c | 2 ++
 1 file changed, 2 insertions(+)
net/bluetooth/hci_core.c +2 -0
index bb831d678868..46aa702c189d 100644
@@ -1628,6 +1628,8 @@ static int hci_dev_do_close(struct hci_dev *hdev)
 
 	hci_dev_lock(hdev);
 
+	hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
+
 	if (!test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags)) {
 		if (hdev->dev_type == HCI_BREDR)
 			mgmt_powered(hdev, 0);
Signature · 1 line
2.1.0
maintainer
#2 lore raw

Re: [PATCH 2/3] Bluetooth: Fix notifying discovery state when powering off

Hi Johan,

Quoted 9 lines

The discovery state should be set to stopped when the HCI device is powered off. This patch adds the appropriate call to the hci_discovery_set_state() function from hci_dev_do_close() which is responsible for the power-off procedure.

---
net/bluetooth/hci_core.c | 2 ++

1 file changed, 2 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel

#3 lore raw

PATCH 3/3 Bluetooth: Perform a power cycle when receiving a HW Error

In reply to Johan Hedberg

From: Johan Hedberg <[email protected]>

When we receive a Hardware Error HCI event the controller should be assumed to be non-functional until a full reset procedure has been performed with it. This patch adds a new hci_reset() helper function that can be triggered through a workqueue, and schedules the function to be called whenever a Hardware Error event occurs.

---
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/hci_core.c         | 15 +++++++++++++++
 net/bluetooth/hci_event.c        |  2 ++
 3 files changed, 18 insertions(+)
include/net/bluetooth/hci_core.h +1 -0
index 0f5e59f1e3cb..3e3380c1e2d9 100644
@@ -293,6 +293,7 @@ struct hci_dev {
 
 	struct work_struct	power_on;
 	struct delayed_work	power_off;
+	struct work_struct	reset;
 
 	__u16			discov_timeout;
 	struct delayed_work	discov_off;
net/bluetooth/hci_core.c +15 -0
index 46aa702c189d..a6afce413842 100644
@@ -2140,6 +2140,20 @@ static void hci_power_off(struct work_struct *work)
 	smp_unregister(hdev);
 }
 
+static void hci_reset(struct work_struct *work)
+{
+	struct hci_dev *hdev = container_of(work, struct hci_dev, reset);
+
+	BT_DBG("%s", hdev->name);
+
+	if (hci_dev_do_close(hdev))
+		return;
+
+	smp_unregister(hdev);
+
+	hci_dev_do_open(hdev);
+}
+
 static void hci_discov_off(struct work_struct *work)
 {
 	struct hci_dev *hdev;
@@ -2932,6 +2946,7 @@ struct hci_dev *hci_alloc_dev(void)
 	INIT_WORK(&hdev->cmd_work, hci_cmd_work);
 	INIT_WORK(&hdev->tx_work, hci_tx_work);
 	INIT_WORK(&hdev->power_on, hci_power_on);
+	INIT_WORK(&hdev->reset, hci_reset);
 
 	INIT_DELAYED_WORK(&hdev->power_off, hci_power_off);
 	INIT_DELAYED_WORK(&hdev->discov_off, hci_discov_off);
net/bluetooth/hci_event.c +2 -0
index 4175470ff48e..0fd6f4d97b4a 100644
@@ -3101,6 +3101,8 @@ static void hci_hardware_error_evt(struct hci_dev *hdev, struct sk_buff *skb)
 	struct hci_ev_hardware_error *ev = (void *) skb->data;
 
 	BT_ERR("%s hardware error 0x%2.2x", hdev->name, ev->code);
+
+	queue_work(hdev->req_workqueue, &hdev->reset);
 }
 
 static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
Signature · 1 line
2.1.0
maintainer
#4 lore raw
In reply to Johan Hedberg

Hi Johan,

Quoted 11 lines

When HCI_Reset is issued the discovery state is assumed to be stopped. The hci_cc_reset() handler was trying to set the state but it was doing it without using the hci_discovery_set_state() function. Because of this e.g. the mgmt Discovering event could go without being sent. This patch fixes the code to use the hci_discovery_set_state() function instead of just blindly setting the state value.

---
net/bluetooth/hci_event.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel