From: johan.hedberg@gmail.com
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 04/10] Bluetooth: Add hci_get_own_address_type() convenience function
Date: Sun, 23 Feb 2014 16:23:52 +0200 [thread overview]
Message-ID: <1393165438-13610-5-git-send-email-johan.hedberg@gmail.com> (raw)
In-Reply-To: <1393165438-13610-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
This patch adds a convenience function for fetching the local address
type used for advertising, scanning and initiating LE connections as
well as updating the local random address if necessary.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/hci_core.h | 2 ++
net/bluetooth/hci_core.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 6415514e4f17..996887793d4b 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1257,6 +1257,8 @@ void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
__u8 ltk[16]);
+uint8_t hci_get_own_address_type(struct hci_request *req);
+
#define SCO_AIRMODE_MASK 0x0003
#define SCO_AIRMODE_CVSD 0x0000
#define SCO_AIRMODE_TRANSP 0x0003
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 92d35811b61e..973145ad8bf0 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3276,6 +3276,44 @@ static void le_scan_disable_work(struct work_struct *work)
BT_ERR("Disable LE scanning request failed: err %d", err);
}
+uint8_t hci_get_own_address_type(struct hci_request *req)
+{
+ struct hci_dev *hdev = req->hdev;
+
+ if (test_bit(HCI_PRIVACY, &hdev->dev_flags)) {
+ bdaddr_t rpa;
+
+ if (!test_and_clear_bit(HCI_RPA_EXPIRED, &hdev->dev_flags))
+ return ADDR_LE_DEV_RANDOM;
+
+ if (smp_generate_rpa(hdev->tfm_aes, hdev->irk, &rpa) < 0) {
+ BT_ERR("%s failed to generate new RPA", hdev->name);
+ return hdev->own_addr_type;
+ }
+
+ hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6, &rpa);
+
+ if (hdev->rpa_timeout) {
+ int timeout;
+
+ timeout = msecs_to_jiffies(hdev->rpa_timeout * 1000);
+ queue_delayed_work(hdev->workqueue, &hdev->rpa_expired,
+ timeout);
+ }
+
+ return ADDR_LE_DEV_RANDOM;
+ }
+
+ if (bacmp(&hdev->static_addr, BDADDR_ANY) &&
+ bacmp(&hdev->static_addr, &hdev->random_addr)) {
+ hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6,
+ &hdev->static_addr);
+ return ADDR_LE_DEV_RANDOM;
+ }
+
+ return hdev->own_addr_type;
+}
+
/* Alloc HCI device */
struct hci_dev *hci_alloc_dev(void)
{
--
1.8.5.3
next prev parent reply other threads:[~2014-02-23 14:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-23 14:23 [PATCH v2 00/10] LE Privacy support johan.hedberg
2014-02-23 14:23 ` [PATCH v2 01/10] Bluetooth: Set the correct address type in Identity Address Information johan.hedberg
2014-02-23 14:46 ` Marcel Holtmann
2014-02-23 14:23 ` [PATCH v2 02/10] Bluetooth: Add SMP function for generating RPAs johan.hedberg
2014-02-23 14:23 ` [PATCH v2 03/10] Bluetooth: Add timer for regenerating local RPA johan.hedberg
2014-02-23 14:23 ` johan.hedberg [this message]
2014-02-23 14:23 ` [PATCH v2 05/10] Bluetooth: Use hci_get_own_address_type() when connecting LE johan.hedberg
2014-02-23 14:23 ` [PATCH v2 06/10] Bluetooth: Use hci_get_own_address_type() for enabling advertising johan.hedberg
2014-02-23 14:23 ` [PATCH v2 07/10] Bluetooth: Use hci_get_own_address_type() for initiating LE scan johan.hedberg
2014-02-23 14:23 ` [PATCH v2 08/10] Bluetooth: Don't write static address during power on johan.hedberg
2014-02-23 14:23 ` [PATCH v2 09/10] Bluetooth: Add debugfs entry for RPA regeneration timeout johan.hedberg
2014-02-23 14:23 ` [PATCH v2 10/10] Bluetooth: Add support for Set Privacy command 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=1393165438-13610-5-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