* [PATCH 1/2] Bluetooth: Introduce a new HCI_CLOSE flag for hci_dev_close()
2010-12-14 12:04 Patches to fix kernel side init/deinit of adapters johan.hedberg
@ 2010-12-14 12:04 ` johan.hedberg
2010-12-14 12:04 ` [PATCH 2/2] Bluetooth: Fix __hci_request synchronization for hci_open_dev johan.hedberg
1 sibling, 0 replies; 3+ messages in thread
From: johan.hedberg @ 2010-12-14 12:04 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
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.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
include/net/bluetooth/hci.h | 1 +
net/bluetooth/hci_core.c | 10 ++++++----
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 29a7a8c..517a652 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -68,6 +68,7 @@ enum {
HCI_UP,
HCI_INIT,
HCI_RUNNING,
+ HCI_CLOSE,
HCI_PSCAN,
HCI_ISCAN,
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 1a4ec97..6374054 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -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:
--
1.7.2.3
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] Bluetooth: Fix __hci_request synchronization for hci_open_dev
2010-12-14 12:04 Patches to fix kernel side init/deinit of adapters johan.hedberg
2010-12-14 12:04 ` [PATCH 1/2] Bluetooth: Introduce a new HCI_CLOSE flag for hci_dev_close() johan.hedberg
@ 2010-12-14 12:04 ` johan.hedberg
1 sibling, 0 replies; 3+ messages in thread
From: johan.hedberg @ 2010-12-14 12:04 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@nokia.com>
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.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
---
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(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 3786ee8..1f421df 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -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 */
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 6374054..8d08538 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -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;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8923b36..939ba9f 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -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;
--
1.7.2.3
^ permalink raw reply related [flat|nested] 3+ messages in thread