Skip to contentSkip to conversation

Patches to fix kernel side init/deinit of adapters

PATCH New [email protected] 1 participant 3 messages Dec 14, 2010

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

Hi,

Before I start implementing support for powering on and off adapters through the management interface some basic things in the current code need fixing. The first issue is that the __hci_request doesn't work the way it's supposed to when called from hci_open_dev. It's supposed to return when the entire request is complete but right now it returns as soon as the first command in the request is complete.

The first patch in this set is needed to make it possible to take advantage of the HCI_INIT flag in the second patch.

Johan

#1 lore raw

PATCH 1/2 Bluetooth: Introduce a new HCI_CLOSE flag for hci_dev_close()

From: Johan Hedberg <[email protected]>

To be able to handle the intialization state differently from the closing state (e.g. different sets of HCI commands are sent in them) a distinct state flag should be used when closing a device.

---
 include/net/bluetooth/hci.h |    1 +
 net/bluetooth/hci_core.c    |   10 ++++++----
 2 files changed, 7 insertions(+), 4 deletions(-)
include/net/bluetooth/hci.h +1 -0
index 29a7a8c..517a652 100644
@@ -68,6 +68,7 @@ enum {
 	HCI_UP,
 	HCI_INIT,
 	HCI_RUNNING,
+	HCI_CLOSE,
 
 	HCI_PSCAN,
 	HCI_ISCAN,
net/bluetooth/hci_core.c +6 -4
index 1a4ec97..6374054 100644
@@ -581,10 +581,10 @@ static int hci_dev_do_close(struct hci_dev *hdev)
 	skb_queue_purge(&hdev->cmd_q);
 	atomic_set(&hdev->cmd_cnt, 1);
 	if (!test_bit(HCI_RAW, &hdev->flags)) {
-		set_bit(HCI_INIT, &hdev->flags);
+		set_bit(HCI_CLOSE, &hdev->flags);
 		__hci_request(hdev, hci_reset_req, 0,
 					msecs_to_jiffies(250));
-		clear_bit(HCI_INIT, &hdev->flags);
+		clear_bit(HCI_CLOSE, &hdev->flags);
 	}
 
 	/* Kill cmd task */
@@ -1029,7 +1029,8 @@ int hci_recv_frame(struct sk_buff *skb)
 {
 	struct hci_dev *hdev = (struct hci_dev *) skb->dev;
 	if (!hdev || (!test_bit(HCI_UP, &hdev->flags)
-				&& !test_bit(HCI_INIT, &hdev->flags))) {
+				&& !test_bit(HCI_INIT, &hdev->flags)
+				&& !test_bit(HCI_CLOSE, &hdev->flags))) {
 		kfree_skb(skb);
 		return -ENXIO;
 	}
@@ -1695,7 +1696,8 @@ static void hci_rx_task(unsigned long arg)
 			continue;
 		}
 
-		if (test_bit(HCI_INIT, &hdev->flags)) {
+		if (test_bit(HCI_INIT, &hdev->flags) ||
+					test_bit(HCI_CLOSE, &hdev->flags)) {
 			/* Don't process data packets in this states. */
 			switch (bt_cb(skb)->pkt_type) {
 			case HCI_ACLDATA_PKT:
Signature · 1 line
1.7.2.3
#2 lore raw

PATCH 2/2 Bluetooth: Fix __hci_request synchronization for hci_open_dev

In reply to [email protected]

From: Johan Hedberg <[email protected]>

The initialization function used by hci_open_dev (hci_init_req) sends many different HCI commands. The __hci_request function should only return when all of these commands have completed (or a timeout occurs). Several of these commands cause hci_req_complete to be called which causes __hci_request to return prematurely.

This patch fixes the issue by making use of the HCI_INIT flag which is set during the initialization procedure. The hci_req_comple function will no longer do anything when this flag is set and a new hci_init_complete function is added which ignores the flag and gets called when the last hci_init_req HCI command completes.

---
 include/net/bluetooth/hci_core.h |    1 +
 net/bluetooth/hci_core.c         |   14 ++++++++++++++
 net/bluetooth/hci_event.c        |   14 ++++++++++++++
 3 files changed, 29 insertions(+), 0 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
index 3786ee8..1f421df 100644
@@ -694,5 +694,6 @@ struct hci_sec_filter {
 #define hci_req_unlock(d)	mutex_unlock(&d->req_lock)
 
 void hci_req_complete(struct hci_dev *hdev, int result);
+void hci_init_complete(struct hci_dev *hdev, int result);
 
 #endif /* __HCI_CORE_H */
net/bluetooth/hci_core.c +14 -0
index 6374054..8d08538 100644
@@ -91,10 +91,24 @@ static void hci_notify(struct hci_dev *hdev, int event)
 
 /* ---- HCI requests ---- */
 
+void hci_init_complete(struct hci_dev *hdev, int result)
+{
+	BT_DBG("%s result 0x%2.2x", hdev->name, result);
+
+	if (hdev->req_status == HCI_REQ_PEND) {
+		hdev->req_result = result;
+		hdev->req_status = HCI_REQ_DONE;
+		wake_up_interruptible(&hdev->req_wait_q);
+	}
+}
+
 void hci_req_complete(struct hci_dev *hdev, int result)
 {
 	BT_DBG("%s result 0x%2.2x", hdev->name, result);
 
+	if (test_bit(HCI_INIT, &hdev->flags))
+		return;
+
 	if (hdev->req_status == HCI_REQ_PEND) {
 		hdev->req_result = result;
 		hdev->req_status = HCI_REQ_DONE;
net/bluetooth/hci_event.c +14 -0
index 8923b36..939ba9f 100644
@@ -539,6 +539,16 @@ static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
 	hci_req_complete(hdev, rp->status);
 }
 
+static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	__u8 status = *((__u8 *) skb->data);
+
+	BT_DBG("%s status 0x%x", hdev->name, status);
+
+	if (test_bit(HCI_INIT, &hdev->flags))
+		hci_init_complete(hdev, status);
+}
+
 static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
 {
 	BT_DBG("%s status 0x%x", hdev->name, status);
@@ -1379,6 +1389,10 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
 		hci_cc_read_bd_addr(hdev, skb);
 		break;
 
+	case HCI_OP_WRITE_CA_TIMEOUT:
+		hci_cc_write_ca_timeout(hdev, skb);
+		break;
+
 	default:
 		BT_DBG("%s opcode 0x%x", hdev->name, opcode);
 		break;
Signature · 1 line
1.7.2.3