Skip to contentSkip to conversation

Bluetooth: Add shutdown callback before closing the device

PATCH Superseded Tedd Ho-Jeong An 2 participants 2 messages Feb 5, 2015 – Feb 12, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Bluetooth: Add shutdown callback before closing the device

From: Tedd Ho-Jeong An <[email protected]>

This callback allows a vendor to send the vendor specific commands before cloing the hci interface.

---
 include/net/bluetooth/hci_core.h | 1 +
 net/bluetooth/hci_core.c         | 4 ++++
 2 files changed, 5 insertions(+)
include/net/bluetooth/hci_core.h +1 -0
index 52863c3..1d868b2 100644
@@ -377,6 +377,7 @@ struct hci_dev {
 	void (*notify)(struct hci_dev *hdev, unsigned int evt);
 	void (*hw_error)(struct hci_dev *hdev, u8 code);
 	int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr);
+	int (*shutdown)(struct hci_dev *hdev);
 };
 
 #define HCI_PHY_HANDLE(handle)	(handle & 0xff)
net/bluetooth/hci_core.c +4 -0
index 3322d3f..d151aef 100644
@@ -1591,6 +1591,10 @@ static int hci_dev_do_close(struct hci_dev *hdev)
 {
 	BT_DBG("%s %p", hdev->name, hdev);
 
+	/* allows vendors to send the command before close the device */
+	if (!test_bit(HCI_UNREGISTER, &hdev->dev_flags) && hdev->shutdown)
+		hdev->shutdown(hdev);
+
 	cancel_delayed_work(&hdev->power_off);
 
 	hci_req_cancel(hdev, ENODEV);
Signature · 1 line
1.9.1
maintainer
#1 lore raw

Hi Tedd,

Quoted 14 lines

This callback allows a vendor to send the vendor specific commands before cloing the hci interface.

---
include/net/bluetooth/hci_core.h | 1 +
net/bluetooth/hci_core.c | 4 ++++

2 files changed, 5 insertions(+)
include/net/bluetooth/hci_core.h +0 -0
index 52863c3..1d868b2 100644

include/net/bluetooth/hci_core.h struct hci_dev { · line 380

Quoted 4 lines
include/net/bluetooth/hci_core.h +1 -0
@@ -377,6 +377,7 @@ struct hci_dev {
 	void (*notify)(struct hci_dev *hdev, unsigned int evt);
 	void (*hw_error)(struct hci_dev *hdev, u8 code);
 	int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr);
+	int (*shutdown)(struct hci_dev *hdev);

I think we should move the shutdown higher up. So after setup() should be a good place.

Quoted 8 lines
include/net/bluetooth/hci_core.h +0 -0
 };
 
 #define HCI_PHY_HANDLE(handle)	(handle & 0xff)
net/bluetooth/hci_core.c +0 -0
index 3322d3f..d151aef 100644

net/bluetooth/hci_core.c static int hci_dev_do_close(struct hci_dev *hdev) · line 1597

Quoted 7 lines
net/bluetooth/hci_core.c +4 -0
@@ -1591,6 +1591,10 @@ static int hci_dev_do_close(struct hci_dev *hdev)
 {
 	BT_DBG("%s %p", hdev->name, hdev);
 
+	/* allows vendors to send the command before close the device */
+	if (!test_bit(HCI_UNREGISTER, &hdev->dev_flags) && hdev->shutdown)
+		hdev->shutdown(hdev);
+
	if (!test_bit()) {
		/* ..... */
		if (hdev->shutdown)
			hdev->shutdown(hdev);
	}

I know this is the same code, but I prefer to have the check for the function pointer provided a little bit close to the call so that it is really obvious.

Regards

Marcel