From: Johan Hedberg <johan.hedberg@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 01/12 v2] Bluetooth: Add initial hooks for HCI transaction support
Date: Fri, 15 Feb 2013 10:30:23 +0200 [thread overview]
Message-ID: <1360917034-5503-2-git-send-email-johan.hedberg@gmail.com> (raw)
In-Reply-To: <1360917034-5503-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
This patch adds the initial context variables and functions for HCI
transaction support. HCI transactions are essentially just groups of HCI
commands with an optional callback for notifying the completion of the
transaction.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/hci_core.h | 17 +++++++++++++++++
net/bluetooth/hci_core.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 90cf75a..0e53032 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -134,6 +134,15 @@ struct amp_assoc {
__u8 data[HCI_MAX_AMP_ASSOC_SIZE];
};
+struct hci_dev;
+
+struct hci_transaction {
+ struct list_head list;
+ struct sk_buff_head cmd_q;
+ void (*complete)(struct hci_dev *hdev,
+ __u16 last_cmd, int hci_err);
+};
+
#define NUM_REASSEMBLY 4
struct hci_dev {
struct list_head list;
@@ -240,6 +249,11 @@ struct hci_dev {
struct sk_buff_head raw_q;
struct sk_buff_head cmd_q;
+ struct mutex transaction_lock;
+ struct hci_transaction *build_transaction;
+ struct hci_transaction *current_transaction;
+ struct list_head transaction_q;
+
struct sk_buff *sent_cmd;
struct sk_buff *reassembly[NUM_REASSEMBLY];
@@ -1041,6 +1055,9 @@ static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
int hci_register_cb(struct hci_cb *hcb);
int hci_unregister_cb(struct hci_cb *hcb);
+#define hci_transaction_lock(d) mutex_lock(&d->transaction_lock)
+#define hci_transaction_unlock(d) mutex_unlock(&d->transaction_lock)
+
int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param);
void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 22e77a7..05e2e8b 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -689,6 +689,36 @@ unlock:
return err;
}
+static void __transaction_free(struct hci_transaction *transaction)
+{
+ skb_queue_purge(&transaction->cmd_q);
+ kfree(transaction);
+}
+
+static void hci_transaction_cleanup(struct hci_dev *hdev)
+{
+ struct hci_transaction *transact, *tmp;
+
+ hci_transaction_lock(hdev);
+
+ if (hdev->build_transaction) {
+ __transaction_free(hdev->build_transaction);
+ hdev->build_transaction = NULL;
+ }
+
+ if (hdev->current_transaction) {
+ __transaction_free(hdev->current_transaction);
+ hdev->current_transaction = NULL;
+ }
+
+ list_for_each_entry_safe(transact, tmp, &hdev->transaction_q, list) {
+ list_del(&transact->list);
+ __transaction_free(transact);
+ }
+
+ hci_transaction_unlock(hdev);
+}
+
/* ---- HCI ioctl helpers ---- */
int hci_dev_open(__u16 dev)
@@ -759,6 +789,7 @@ int hci_dev_open(__u16 dev)
flush_work(&hdev->cmd_work);
flush_work(&hdev->rx_work);
+ hci_transaction_cleanup(hdev);
skb_queue_purge(&hdev->cmd_q);
skb_queue_purge(&hdev->rx_q);
@@ -823,6 +854,7 @@ static int hci_dev_do_close(struct hci_dev *hdev)
hdev->flush(hdev);
/* Reset device */
+ hci_transaction_cleanup(hdev);
skb_queue_purge(&hdev->cmd_q);
atomic_set(&hdev->cmd_cnt, 1);
if (!test_bit(HCI_RAW, &hdev->flags) &&
@@ -838,6 +870,7 @@ static int hci_dev_do_close(struct hci_dev *hdev)
/* Drop queues */
skb_queue_purge(&hdev->rx_q);
skb_queue_purge(&hdev->cmd_q);
+ hci_transaction_cleanup(hdev);
skb_queue_purge(&hdev->raw_q);
/* Drop last sent command */
@@ -908,6 +941,7 @@ int hci_dev_reset(__u16 dev)
/* Drop queues */
skb_queue_purge(&hdev->rx_q);
skb_queue_purge(&hdev->cmd_q);
+ hci_transaction_cleanup(hdev);
hci_dev_lock(hdev);
inquiry_cache_flush(hdev);
@@ -1710,6 +1744,7 @@ struct hci_dev *hci_alloc_dev(void)
mutex_init(&hdev->lock);
mutex_init(&hdev->req_lock);
+ mutex_init(&hdev->transaction_lock);
INIT_LIST_HEAD(&hdev->mgmt_pending);
INIT_LIST_HEAD(&hdev->blacklist);
@@ -1718,6 +1753,7 @@ struct hci_dev *hci_alloc_dev(void)
INIT_LIST_HEAD(&hdev->long_term_keys);
INIT_LIST_HEAD(&hdev->remote_oob_data);
INIT_LIST_HEAD(&hdev->conn_hash.list);
+ INIT_LIST_HEAD(&hdev->transaction_q);
INIT_WORK(&hdev->rx_work, hci_rx_work);
INIT_WORK(&hdev->cmd_work, hci_cmd_work);
--
1.7.10.4
next prev parent reply other threads:[~2013-02-15 8:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-15 8:30 [PATCH 00/12 v2] Bluetooth: Asynchronous HCI transaction API Johan Hedberg
2013-02-15 8:30 ` Johan Hedberg [this message]
2013-02-15 8:30 ` [PATCH 02/12 v2] Bluetooth: Add basic start/complete HCI transaction functions Johan Hedberg
2013-02-15 8:30 ` [PATCH 03/12 v2] Bluetooth: Add hci_transaction_cmd_complete function Johan Hedberg
2013-02-15 8:30 ` [PATCH 04/12 v2] Bluetooth: Add hci_transaction_from_skb function Johan Hedberg
2013-02-15 8:30 ` [PATCH 05/12 v2] Bluetooth: Switch from hdev->cmd_q to using transactions Johan Hedberg
2013-02-15 8:30 ` [PATCH 06/12 v2] Bluetooth: Remove unused hdev->cmd_q HCI command queue Johan Hedberg
2013-02-15 8:30 ` [PATCH 07/12 v2] Bluetooth: Fix mgmt powered indication by using a HCI transaction Johan Hedberg
2013-02-15 8:30 ` [PATCH 08/12 v2] Bluetooth: Enable HCI transaction support cmd_status 0 Johan Hedberg
2013-02-15 8:30 ` [PATCH 09/12 v2] Bluetooth: Add HCI init sequence support for HCI transactions Johan Hedberg
2013-02-15 8:30 ` [PATCH 10/12 v2] Bluetooth: Convert hci_request to use " Johan Hedberg
2013-02-15 8:30 ` [PATCH 11/12 v2] Bluetooth: Remove unused hdev->init_last_cmd Johan Hedberg
2013-02-15 8:30 ` [PATCH 12/12 v2] Bluetooth: Remove empty HCI event handlers Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1360917034-5503-2-git-send-email-johan.hedberg@gmail.com \
--to=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).