All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address
@ 2014-02-23 17:42 johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 02/13] Bluetooth: Set the correct values for Identity Address Information johan.hedberg
                   ` (12 more replies)
  0 siblings, 13 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

To be consistent with the remote address info in hci_conn we want it to
also contain the local identity address information. This patch updates
the code to use the hci_copy_identity_address function to copy the right
values in place whenever an LE connection has been established.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/hci_event.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 4327b129d38e..84a475ac2e7f 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3625,6 +3625,26 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		}
 	}
 
+	/* Ensure that the hci_conn contains the identity address type
+	 * regardless of which address the connection was made with.
+	 *
+	 * If the controller has a public BD_ADDR, then by default
+	 * use that one. If this is a LE only controller without
+	 * a public address, default to the random address.
+	 *
+	 * For debugging purposes it is possible to force
+	 * controllers with a public address to use the
+	 * random address instead.
+	 */
+	if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) ||
+	    !bacmp(&hdev->bdaddr, BDADDR_ANY)) {
+		bacpy(&conn->src, &hdev->static_addr);
+		conn->src_type = ADDR_LE_DEV_RANDOM;
+	} else {
+		bacpy(&conn->src, &hdev->bdaddr);
+		conn->src_type = ADDR_LE_DEV_PUBLIC;
+	}
+
 	/* Lookup the identity address from the stored connection
 	 * address and address type.
 	 *
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 02/13] Bluetooth: Set the correct values for Identity Address Information
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 03/13] Bluetooth: Add SMP function for generating RPAs johan.hedberg
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

The SMP Identity Address Information PDU should contain our Identity
Address. This patch updates the code to copy the correct values from the
hci_conn object.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/smp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 8ef50c790b96..a5920e8cea59 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -1196,9 +1196,8 @@ int smp_distribute_keys(struct l2cap_conn *conn, __u8 force)
 
 		smp_send_cmd(conn, SMP_CMD_IDENT_INFO, sizeof(idinfo), &idinfo);
 
-		/* Just public address */
-		memset(&addrinfo, 0, sizeof(addrinfo));
 		bacpy(&addrinfo.bdaddr, &hcon->src);
+		addrinfo.addr_type = hcon->src_type;
 
 		smp_send_cmd(conn, SMP_CMD_IDENT_ADDR_INFO, sizeof(addrinfo),
 			     &addrinfo);
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 03/13] Bluetooth: Add SMP function for generating RPAs
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 02/13] Bluetooth: Set the correct values for Identity Address Information johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 04/13] Bluetooth: Add timer for regenerating local RPA johan.hedberg
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

We need a function in smp.c to generate Resolvable Random Addresses in
order to support privacy. The local RPA will need to be generated before
advertising, scanning or connecting and regenerated at periodic
intervals. This patch adds the necessary function for RPA generation.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/smp.c | 18 ++++++++++++++++++
 net/bluetooth/smp.h |  1 +
 2 files changed, 19 insertions(+)

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index a5920e8cea59..88ff4d11cc19 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -124,6 +124,24 @@ bool smp_irk_matches(struct crypto_blkcipher *tfm, u8 irk[16],
 	return !memcmp(bdaddr->b, hash, 3);
 }
 
+int smp_generate_rpa(struct crypto_blkcipher *tfm, u8 irk[16], bdaddr_t *rpa)
+{
+	int err;
+
+	get_random_bytes(&rpa->b[3], 3);
+
+	rpa->b[5] &= 0x3f;
+	rpa->b[5] |= 0x40;
+
+	err = smp_ah(tfm, irk, &rpa->b[3], rpa->b);
+	if (err < 0)
+		return err;
+
+	BT_DBG("RPA %pMR", rpa);
+
+	return 0;
+}
+
 static int smp_c1(struct crypto_blkcipher *tfm, u8 k[16], u8 r[16],
 		  u8 preq[7], u8 pres[7], u8 _iat, bdaddr_t *ia,
 		  u8 _rat, bdaddr_t *ra, u8 res[16])
diff --git a/net/bluetooth/smp.h b/net/bluetooth/smp.h
index d8cc543f523c..f32f1212f650 100644
--- a/net/bluetooth/smp.h
+++ b/net/bluetooth/smp.h
@@ -152,5 +152,6 @@ void smp_chan_destroy(struct l2cap_conn *conn);
 
 bool smp_irk_matches(struct crypto_blkcipher *tfm, u8 irk[16],
 		     bdaddr_t *bdaddr);
+int smp_generate_rpa(struct crypto_blkcipher *tfm, u8 irk[16], bdaddr_t *rpa);
 
 #endif /* __SMP_H */
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 04/13] Bluetooth: Add timer for regenerating local RPA
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 02/13] Bluetooth: Set the correct values for Identity Address Information johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 03/13] Bluetooth: Add SMP function for generating RPAs johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 05/13] Bluetooth: Add hci_update_random_address() convenience function johan.hedberg
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds a timer for updating the local RPA periodically. The
default timeout is set to 15 minutes.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci.h      |  1 +
 include/net/bluetooth/hci_core.h |  5 +++++
 net/bluetooth/hci_core.c         |  4 ++++
 net/bluetooth/mgmt.c             | 23 +++++++++++++++++++++++
 4 files changed, 33 insertions(+)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 5ff885ff29df..1bb45a47a78a 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -127,6 +127,7 @@ enum {
 	HCI_SC_ENABLED,
 	HCI_SC_ONLY,
 	HCI_PRIVACY,
+	HCI_RPA_EXPIRED,
 	HCI_RPA_RESOLVING,
 	HCI_HS_ENABLED,
 	HCI_LE_ENABLED,
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 68bbcabdd9fd..6415514e4f17 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -130,6 +130,9 @@ struct oob_data {
 
 #define HCI_MAX_SHORT_NAME_LENGTH	10
 
+/* Default LE RPA expiry time, 15 minutes */
+#define HCI_DEFAULT_RPA_TIMEOUT		(15 * 60)
+
 struct amp_assoc {
 	__u16	len;
 	__u16	offset;
@@ -304,6 +307,8 @@ struct hci_dev {
 	__u8			scan_rsp_data_len;
 
 	__u8			irk[16];
+	__u32			rpa_timeout;
+	struct delayed_work	rpa_expired;
 
 	int (*open)(struct hci_dev *hdev);
 	int (*close)(struct hci_dev *hdev);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 964aa8deb009..92d35811b61e 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2102,6 +2102,7 @@ static int hci_dev_do_open(struct hci_dev *hdev)
 
 	if (!ret) {
 		hci_dev_hold(hdev);
+		set_bit(HCI_RPA_EXPIRED, &hdev->dev_flags);
 		set_bit(HCI_UP, &hdev->flags);
 		hci_notify(hdev, HCI_DEV_UP);
 		if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
@@ -2199,6 +2200,7 @@ static int hci_dev_do_close(struct hci_dev *hdev)
 		cancel_delayed_work(&hdev->service_cache);
 
 	cancel_delayed_work_sync(&hdev->le_scan_disable);
+	cancel_delayed_work_sync(&hdev->rpa_expired);
 
 	hci_dev_lock(hdev);
 	hci_inquiry_cache_flush(hdev);
@@ -3300,6 +3302,8 @@ struct hci_dev *hci_alloc_dev(void)
 	hdev->le_conn_min_interval = 0x0028;
 	hdev->le_conn_max_interval = 0x0038;
 
+	hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT;
+
 	mutex_init(&hdev->lock);
 	mutex_init(&hdev->req_lock);
 
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 301b18a1c6a0..09316dd2cce1 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -881,12 +881,35 @@ static void service_cache_off(struct work_struct *work)
 	hci_req_run(&req, NULL);
 }
 
+static void rpa_expired(struct work_struct *work)
+{
+	struct hci_dev *hdev = container_of(work, struct hci_dev,
+					    rpa_expired.work);
+	struct hci_request req;
+
+	BT_DBG("");
+
+	set_bit(HCI_RPA_EXPIRED, &hdev->dev_flags);
+
+	if (!test_bit(HCI_ADVERTISING, &hdev->dev_flags) ||
+	    hci_conn_num(hdev, LE_LINK) > 0)
+		return;
+
+	hci_req_init(&req, hdev);
+
+	disable_advertising(&req);
+	enable_advertising(&req);
+
+	hci_req_run(&req, NULL);
+}
+
 static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev)
 {
 	if (test_and_set_bit(HCI_MGMT, &hdev->dev_flags))
 		return;
 
 	INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off);
+	INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired);
 
 	/* Non-mgmt controlled devices get this bit set
 	 * implicitly so that pairing works for them, however
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 05/13] Bluetooth: Add hci_update_random_address() convenience function
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
                   ` (2 preceding siblings ...)
  2014-02-23 17:42 ` [PATCH v3 04/13] Bluetooth: Add timer for regenerating local RPA johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 06/13] Bluetooth: Use hci_update_random_address() when connecting LE johan.hedberg
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds a convenience function for updating the local random
address which is needed before advertising, scanning and initiating LE
connections.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_core.c         | 55 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 6415514e4f17..2506963c7a06 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]);
 
+int hci_update_random_address(struct hci_request *req, u8 *own_addr_type);
+
 #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..7bc67b4e47a7 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3276,6 +3276,61 @@ static void le_scan_disable_work(struct work_struct *work)
 		BT_ERR("Disable LE scanning request failed: err %d", err);
 }
 
+int hci_update_random_address(struct hci_request *req, u8 *own_addr_type)
+{
+	struct hci_dev *hdev = req->hdev;
+	int err;
+
+	/* If privacy is enabled use a resolvable private address. If
+	 * the current RPA has expired or there's something else than an
+	 * RPA currently in use regenerate a new one.
+	 */
+	if (test_bit(HCI_PRIVACY, &hdev->dev_flags)) {
+		bdaddr_t rpa;
+		int to;
+
+		*own_addr_type = ADDR_LE_DEV_RANDOM;
+
+		if (!test_and_clear_bit(HCI_RPA_EXPIRED, &hdev->dev_flags) &&
+		    hci_bdaddr_is_rpa(&hdev->random_addr, ADDR_LE_DEV_RANDOM))
+			return 0;
+
+		err = smp_generate_rpa(hdev->tfm_aes, hdev->irk, &rpa);
+		if (err < 0) {
+			BT_ERR("%s failed to generate new RPA", hdev->name);
+			return err;
+		}
+
+		hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6, &rpa);
+
+		to = msecs_to_jiffies(hdev->rpa_timeout * 1000);
+		queue_delayed_work(hdev->workqueue, &hdev->rpa_expired, to);
+
+		return 0;
+	}
+
+	/* If forcing static address is in use or there is no public
+	 * address use the static address as random address (but skip
+	 * the HCI command if the current random address is already the
+	 * static one.
+	 */
+	if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) ||
+	    !bacmp(&hdev->bdaddr, BDADDR_ANY)) {
+		*own_addr_type = ADDR_LE_DEV_RANDOM;
+		if (bacmp(&hdev->static_addr, &hdev->random_addr))
+			hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6,
+				    &hdev->static_addr);
+		return 0;
+	}
+
+	/* Neither privacy nor static address is being used so use a
+	 * public address.
+	 */
+	*own_addr_type = ADDR_LE_DEV_PUBLIC;
+
+	return 0;
+}
+
 /* Alloc HCI device */
 struct hci_dev *hci_alloc_dev(void)
 {
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 06/13] Bluetooth: Use hci_update_random_address() when connecting LE
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
                   ` (3 preceding siblings ...)
  2014-02-23 17:42 ` [PATCH v3 05/13] Bluetooth: Add hci_update_random_address() convenience function johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 07/13] Bluetooth: Use hci_update_random_address() for enabling advertising johan.hedberg
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

When we initiate LE connections we need to update the local random
address if necessary. This patch updates the LE connection creation
mechanism to use the new hci_update_random_address() function to set the
own_address_type parameter and to update the local random address if
necessary.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/hci_conn.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index bd66c52eff95..4cb337d6401f 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -556,16 +556,22 @@ static int hci_create_le_conn(struct hci_conn *conn)
 	struct hci_dev *hdev = conn->hdev;
 	struct hci_cp_le_create_conn cp;
 	struct hci_request req;
+	u8 own_addr_type;
 	int err;
 
 	hci_req_init(&req, hdev);
 
 	memset(&cp, 0, sizeof(cp));
+
+	err = hci_update_random_address(&req, &own_addr_type);
+	if (err < 0)
+		return err;
+
 	cp.scan_interval = cpu_to_le16(hdev->le_scan_interval);
 	cp.scan_window = cpu_to_le16(hdev->le_scan_window);
 	bacpy(&cp.peer_addr, &conn->dst);
 	cp.peer_addr_type = conn->dst_type;
-	cp.own_address_type = conn->src_type;
+	cp.own_address_type = own_addr_type;
 	cp.conn_interval_min = cpu_to_le16(conn->le_conn_min_interval);
 	cp.conn_interval_max = cpu_to_le16(conn->le_conn_max_interval);
 	cp.supervision_timeout = __constant_cpu_to_le16(0x002a);
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 07/13] Bluetooth: Use hci_update_random_address() for enabling advertising
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
                   ` (4 preceding siblings ...)
  2014-02-23 17:42 ` [PATCH v3 06/13] Bluetooth: Use hci_update_random_address() when connecting LE johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 08/13] Bluetooth: Use hci_update_random_address() for initiating LE scan johan.hedberg
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

When we enable advertising we need to update the local random address if
necessary. This patch takes advantage of the hci_update_random_address()
function to set the own_address_type variable and to update the local
random address if necessary.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/mgmt.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 09316dd2cce1..14de8505c054 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -839,13 +839,17 @@ static void enable_advertising(struct hci_request *req)
 {
 	struct hci_dev *hdev = req->hdev;
 	struct hci_cp_le_set_adv_param cp;
-	u8 enable = 0x01;
+	u8 own_addr_type, enable = 0x01;
 
 	memset(&cp, 0, sizeof(cp));
+
+	if (hci_update_random_address(req, &own_addr_type) < 0)
+		return;
+
 	cp.min_interval = __constant_cpu_to_le16(0x0800);
 	cp.max_interval = __constant_cpu_to_le16(0x0800);
 	cp.type = get_adv_type(hdev);
-	cp.own_address_type = hdev->own_addr_type;
+	cp.own_address_type = own_addr_type;
 	cp.channel_map = hdev->le_adv_channel_map;
 
 	hci_req_add(req, HCI_OP_LE_SET_ADV_PARAM, sizeof(cp), &cp);
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 08/13] Bluetooth: Use hci_update_random_address() for initiating LE scan
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
                   ` (5 preceding siblings ...)
  2014-02-23 17:42 ` [PATCH v3 07/13] Bluetooth: Use hci_update_random_address() for enabling advertising johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 09/13] Bluetooth: Don't write static address during power on johan.hedberg
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

When we start LE scanning we need to update the local random address if
necessary. This patch updates the code to use hci_update_random_address()
for setting the own_address_type scan parameter and updating the local
random address if necessary.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/mgmt.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 14de8505c054..92f776318a6b 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3290,7 +3290,7 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
 	struct hci_request req;
 	/* General inquiry access code (GIAC) */
 	u8 lap[3] = { 0x33, 0x8b, 0x9e };
-	u8 status;
+	u8 status, own_addr_type;
 	int err;
 
 	BT_DBG("%s", hdev->name);
@@ -3383,10 +3383,19 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
 		}
 
 		memset(&param_cp, 0, sizeof(param_cp));
+
+		err = hci_update_random_address(&req, &own_addr_type);
+		if (err < 0) {
+			err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
+					 MGMT_STATUS_FAILED);
+			mgmt_pending_remove(cmd);
+			goto failed;
+		}
+
 		param_cp.type = LE_SCAN_ACTIVE;
 		param_cp.interval = cpu_to_le16(DISCOV_LE_SCAN_INT);
 		param_cp.window = cpu_to_le16(DISCOV_LE_SCAN_WIN);
-		param_cp.own_address_type = hdev->own_addr_type;
+		param_cp.own_address_type = own_addr_type;
 		hci_req_add(&req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp),
 			    &param_cp);
 
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 09/13] Bluetooth: Don't write static address during power on
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
                   ` (6 preceding siblings ...)
  2014-02-23 17:42 ` [PATCH v3 08/13] Bluetooth: Use hci_update_random_address() for initiating LE scan johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 10/13] Bluetooth: Add debugfs entry for RPA regeneration timeout johan.hedberg
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

Since we always update the random address before enabling advertising,
scanning and initiating LE connections there is no need to write the
random address add power on.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/mgmt.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 92f776318a6b..905684ab7e05 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -4604,11 +4604,6 @@ static int powered_update_hci(struct hci_dev *hdev)
 	}
 
 	if (lmp_le_capable(hdev)) {
-		/* Set random address to static address if configured */
-		if (bacmp(&hdev->static_addr, BDADDR_ANY))
-			hci_req_add(&req, HCI_OP_LE_SET_RANDOM_ADDR, 6,
-				    &hdev->static_addr);
-
 		/* Make sure the controller has a good default for
 		 * advertising data. This also applies to the case
 		 * where BR/EDR was toggled during the AUTO_OFF phase.
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 10/13] Bluetooth: Add debugfs entry for RPA regeneration timeout
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
                   ` (7 preceding siblings ...)
  2014-02-23 17:42 ` [PATCH v3 09/13] Bluetooth: Don't write static address during power on johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 11/13] Bluetooth: Add support for Set Privacy command johan.hedberg
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds a rpa_timeout debugfs entry which can be used to set the
RPA regeneration timeout to something else than the default 15 minutes.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/hci_core.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 7bc67b4e47a7..629919be071c 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -492,6 +492,37 @@ static int idle_timeout_get(void *data, u64 *val)
 DEFINE_SIMPLE_ATTRIBUTE(idle_timeout_fops, idle_timeout_get,
 			idle_timeout_set, "%llu\n");
 
+static int rpa_timeout_set(void *data, u64 val)
+{
+	struct hci_dev *hdev = data;
+
+	/* Require the RPA timeout to be at least 30 seconds and at most
+	 * 24 hours.
+	 */
+	if (val < 30 || val > (60 * 60 * 24))
+		return -EINVAL;
+
+	hci_dev_lock(hdev);
+	hdev->rpa_timeout = val;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+static int rpa_timeout_get(void *data, u64 *val)
+{
+	struct hci_dev *hdev = data;
+
+	hci_dev_lock(hdev);
+	*val = hdev->rpa_timeout;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(rpa_timeout_fops, rpa_timeout_get,
+			rpa_timeout_set, "%llu\n");
+
 static int sniff_min_interval_set(void *data, u64 val)
 {
 	struct hci_dev *hdev = data;
@@ -1612,6 +1643,8 @@ static int __hci_init(struct hci_dev *hdev)
 				    hdev, &random_address_fops);
 		debugfs_create_file("static_address", 0444, hdev->debugfs,
 				    hdev, &static_address_fops);
+		debugfs_create_file("rpa_timeout", 0644, hdev->debugfs,
+				    hdev, &rpa_timeout_fops);
 
 		/* For controllers with a public address, provide a debug
 		 * option to force the usage of the configured static
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 11/13] Bluetooth: Add support for Set Privacy command
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
                   ` (8 preceding siblings ...)
  2014-02-23 17:42 ` [PATCH v3 10/13] Bluetooth: Add debugfs entry for RPA regeneration timeout johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 12/13] Bluetooth: Fix setting correct src_type when connecting LE johan.hedberg
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds support for handing the Set Privacy mgmt command,
including copying the value to hdev->irk and toggling the HCI_PRIVACY
flag.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/mgmt.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 905684ab7e05..16a02aa337e6 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -81,6 +81,7 @@ static const u16 mgmt_commands[] = {
 	MGMT_OP_SET_SCAN_PARAMS,
 	MGMT_OP_SET_SECURE_CONN,
 	MGMT_OP_SET_DEBUG_KEYS,
+	MGMT_OP_SET_PRIVACY,
 	MGMT_OP_LOAD_IRKS,
 };
 
@@ -4223,6 +4224,51 @@ unlock:
 	return err;
 }
 
+static int set_privacy(struct sock *sk, struct hci_dev *hdev, void *cp_data,
+		       u16 len)
+{
+	struct mgmt_cp_set_privacy *cp = cp_data;
+	bool changed;
+	int err;
+
+	BT_DBG("request for %s", hdev->name);
+
+	if (!lmp_le_capable(hdev))
+		return cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY,
+				  MGMT_STATUS_NOT_SUPPORTED);
+
+	if (cp->privacy != 0x00 && cp->privacy != 0x01)
+		return cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY,
+				  MGMT_STATUS_INVALID_PARAMS);
+
+	if (hdev_is_powered(hdev))
+		return cmd_status(sk, hdev->id, MGMT_OP_SET_PRIVACY,
+				  MGMT_STATUS_REJECTED);
+
+	hci_dev_lock(hdev);
+
+	if (cp->privacy) {
+		changed = !test_and_set_bit(HCI_PRIVACY, &hdev->dev_flags);
+		memcpy(hdev->irk, cp->irk, sizeof(hdev->irk));
+		set_bit(HCI_RPA_EXPIRED, &hdev->dev_flags);
+	} else {
+		changed = test_and_clear_bit(HCI_PRIVACY, &hdev->dev_flags);
+		memset(hdev->irk, 0, sizeof(hdev->irk));
+		clear_bit(HCI_RPA_EXPIRED, &hdev->dev_flags);
+	}
+
+	err = send_settings_rsp(sk, MGMT_OP_SET_PRIVACY, hdev);
+	if (err < 0)
+		goto unlock;
+
+	if (changed)
+		err = new_settings(hdev, sk);
+
+unlock:
+	hci_dev_unlock(hdev);
+	return err;
+}
+
 static bool irk_is_valid(struct mgmt_irk_info *irk)
 {
 	switch (irk->addr.type) {
@@ -4437,7 +4483,7 @@ static const struct mgmt_handler {
 	{ set_scan_params,        false, MGMT_SET_SCAN_PARAMS_SIZE },
 	{ set_secure_conn,        false, MGMT_SETTING_SIZE },
 	{ set_debug_keys,         false, MGMT_SETTING_SIZE },
-	{ },
+	{ set_privacy,            false, MGMT_SET_PRIVACY_SIZE },
 	{ load_irks,              true,  MGMT_LOAD_IRKS_SIZE },
 };
 
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 12/13] Bluetooth: Fix setting correct src_type when connecting LE
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
                   ` (9 preceding siblings ...)
  2014-02-23 17:42 ` [PATCH v3 11/13] Bluetooth: Add support for Set Privacy command johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 17:42 ` [PATCH v3 13/13] Bluetooth: Remove unneeded hdev->own_addr_type johan.hedberg
  2014-02-23 20:07 ` [PATCH v4] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch ensures that conn->src_type contains the same address type as
is used for initiating the connection while the connection attempt is in
progress. Once connected this value will be overwritten with the
identity address type.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/hci_conn.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 4cb337d6401f..a1efa1c62de8 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -567,6 +567,8 @@ static int hci_create_le_conn(struct hci_conn *conn)
 	if (err < 0)
 		return err;
 
+	conn->src_type = own_addr_type;
+
 	cp.scan_interval = cpu_to_le16(hdev->le_scan_interval);
 	cp.scan_window = cpu_to_le16(hdev->le_scan_window);
 	bacpy(&cp.peer_addr, &conn->dst);
@@ -653,7 +655,6 @@ static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
 		return ERR_PTR(-ENOMEM);
 
 	conn->dst_type = dst_type;
-	conn->src_type = hdev->own_addr_type;
 
 	conn->state = BT_CONNECT;
 	conn->out = true;
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 13/13] Bluetooth: Remove unneeded hdev->own_addr_type
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
                   ` (10 preceding siblings ...)
  2014-02-23 17:42 ` [PATCH v3 12/13] Bluetooth: Fix setting correct src_type when connecting LE johan.hedberg
@ 2014-02-23 17:42 ` johan.hedberg
  2014-02-23 20:07 ` [PATCH v4] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
  12 siblings, 0 replies; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 17:42 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

Now that the identity address type is always looked up for all
successful connections using the hci_copy_identity_address function the
hdev->own_addr_type variable has become completely unnecessary. Simply
remove it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h |  1 -
 net/bluetooth/hci_core.c         | 17 +----------------
 2 files changed, 1 insertion(+), 17 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 2506963c7a06..43b6d1131c4d 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -156,7 +156,6 @@ struct hci_dev {
 	bdaddr_t	bdaddr;
 	bdaddr_t	random_addr;
 	bdaddr_t	static_addr;
-	__u8		own_addr_type;
 	__u8		dev_name[HCI_MAX_NAME_LENGTH];
 	__u8		short_name[HCI_MAX_SHORT_NAME_LENGTH];
 	__u8		eir[HCI_MAX_EIR_LENGTH];
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 629919be071c..1651de959d9c 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1506,23 +1506,8 @@ static void hci_init3_req(struct hci_request *req, unsigned long opt)
 	if (hdev->commands[5] & 0x10)
 		hci_setup_link_policy(req);
 
-	if (lmp_le_capable(hdev)) {
-		/* If the controller has a public BD_ADDR, then by default
-		 * use that one. If this is a LE only controller without
-		 * a public address, default to the random address.
-		 *
-		 * For debugging purposes it is possible to force
-		 * controllers with a public address to use the
-		 * random address instead.
-		 */
-		if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) ||
-		    !bacmp(&hdev->bdaddr, BDADDR_ANY))
-			hdev->own_addr_type = ADDR_LE_DEV_RANDOM;
-		else
-			hdev->own_addr_type = ADDR_LE_DEV_PUBLIC;
-
+	if (lmp_le_capable(hdev))
 		hci_set_le_support(req);
-	}
 
 	/* Read features beyond page 1 if available */
 	for (p = 2; p < HCI_MAX_PAGES && p <= hdev->max_page; p++) {
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4] Bluetooth: Ensure hci_conn always contains the local identity address
  2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
                   ` (11 preceding siblings ...)
  2014-02-23 17:42 ` [PATCH v3 13/13] Bluetooth: Remove unneeded hdev->own_addr_type johan.hedberg
@ 2014-02-23 20:07 ` johan.hedberg
  2014-02-23 20:44   ` Marcel Holtmann
  12 siblings, 1 reply; 15+ messages in thread
From: johan.hedberg @ 2014-02-23 20:07 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

To be consistent with the remote address info in hci_conn we want it to
also contain the local identity address information. The struct will
contain the actual address used for the connection while a connection
process is in place but as soon as we have a successful connection the
identity address should be tracked instead.

This patch updates the code to set the src and src_type values to point
at the identity address in the hci_le_conn_complete_evt function. The
identity address can either be a public address or a static random
address.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
v4: Fix commit message not to refer to non-existent functions

 net/bluetooth/hci_event.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 4327b129d38e..84a475ac2e7f 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3625,6 +3625,26 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		}
 	}
 
+	/* Ensure that the hci_conn contains the identity address type
+	 * regardless of which address the connection was made with.
+	 *
+	 * If the controller has a public BD_ADDR, then by default
+	 * use that one. If this is a LE only controller without
+	 * a public address, default to the random address.
+	 *
+	 * For debugging purposes it is possible to force
+	 * controllers with a public address to use the
+	 * random address instead.
+	 */
+	if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) ||
+	    !bacmp(&hdev->bdaddr, BDADDR_ANY)) {
+		bacpy(&conn->src, &hdev->static_addr);
+		conn->src_type = ADDR_LE_DEV_RANDOM;
+	} else {
+		bacpy(&conn->src, &hdev->bdaddr);
+		conn->src_type = ADDR_LE_DEV_PUBLIC;
+	}
+
 	/* Lookup the identity address from the stored connection
 	 * address and address type.
 	 *
-- 
1.8.5.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v4] Bluetooth: Ensure hci_conn always contains the local identity address
  2014-02-23 20:07 ` [PATCH v4] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
@ 2014-02-23 20:44   ` Marcel Holtmann
  0 siblings, 0 replies; 15+ messages in thread
From: Marcel Holtmann @ 2014-02-23 20:44 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: bluez mailin list (linux-bluetooth@vger.kernel.org)

Hi Johan,

> To be consistent with the remote address info in hci_conn we want it to
> also contain the local identity address information. The struct will
> contain the actual address used for the connection while a connection
> process is in place but as soon as we have a successful connection the
> identity address should be tracked instead.
> 
> This patch updates the code to set the src and src_type values to point
> at the identity address in the hci_le_conn_complete_evt function. The
> identity address can either be a public address or a static random
> address.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> v4: Fix commit message not to refer to non-existent functions

I fixed up the commit messages and add some extra comments. Now all 13 patches have been applied bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-02-23 20:44 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-23 17:42 [PATCH v3 01/13] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
2014-02-23 17:42 ` [PATCH v3 02/13] Bluetooth: Set the correct values for Identity Address Information johan.hedberg
2014-02-23 17:42 ` [PATCH v3 03/13] Bluetooth: Add SMP function for generating RPAs johan.hedberg
2014-02-23 17:42 ` [PATCH v3 04/13] Bluetooth: Add timer for regenerating local RPA johan.hedberg
2014-02-23 17:42 ` [PATCH v3 05/13] Bluetooth: Add hci_update_random_address() convenience function johan.hedberg
2014-02-23 17:42 ` [PATCH v3 06/13] Bluetooth: Use hci_update_random_address() when connecting LE johan.hedberg
2014-02-23 17:42 ` [PATCH v3 07/13] Bluetooth: Use hci_update_random_address() for enabling advertising johan.hedberg
2014-02-23 17:42 ` [PATCH v3 08/13] Bluetooth: Use hci_update_random_address() for initiating LE scan johan.hedberg
2014-02-23 17:42 ` [PATCH v3 09/13] Bluetooth: Don't write static address during power on johan.hedberg
2014-02-23 17:42 ` [PATCH v3 10/13] Bluetooth: Add debugfs entry for RPA regeneration timeout johan.hedberg
2014-02-23 17:42 ` [PATCH v3 11/13] Bluetooth: Add support for Set Privacy command johan.hedberg
2014-02-23 17:42 ` [PATCH v3 12/13] Bluetooth: Fix setting correct src_type when connecting LE johan.hedberg
2014-02-23 17:42 ` [PATCH v3 13/13] Bluetooth: Remove unneeded hdev->own_addr_type johan.hedberg
2014-02-23 20:07 ` [PATCH v4] Bluetooth: Ensure hci_conn always contains the local identity address johan.hedberg
2014-02-23 20:44   ` Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.