aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2014-12-07 14:13:17 -0500
committerJohan Hedberg <johan.hedberg@intel.com>2014-12-08 02:21:14 -0500
commit9437d2edc39ed8f7e40536281ee53ec3fd5a14ca (patch)
tree8b27ff6119909ebf1da97f58e4dfbe03ae8edc15 /net
parent08f63cc5026f20b9124828619c9025738ecb5a5e (diff)
Bluetooth: Fix generation of non-resolvable private addresses
When the host decides to use a non-resolvable private address, it must ensure that this generated address does not match the public address of the controller. Add an extra check to ensure this required behavior. In addition rename the variable from urpa to nrpa and fix all of the comments in the code that use the term unresolvable instead of the term non-resolvable as used in the Bluetooth specification. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/hci_conn.c2
-rw-r--r--net/bluetooth/hci_core.c24
-rw-r--r--net/bluetooth/mgmt.c2
3 files changed, 20 insertions, 8 deletions
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 79d84b88b8f0..fe18825cc8a4 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -661,7 +661,7 @@ static void hci_req_add_le_create_conn(struct hci_request *req,
661 memset(&cp, 0, sizeof(cp)); 661 memset(&cp, 0, sizeof(cp));
662 662
663 /* Update random address, but set require_privacy to false so 663 /* Update random address, but set require_privacy to false so
664 * that we never connect with an unresolvable address. 664 * that we never connect with an non-resolvable address.
665 */ 665 */
666 if (hci_update_random_address(req, false, &own_addr_type)) 666 if (hci_update_random_address(req, false, &own_addr_type))
667 return; 667 return;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 93f92a085506..96e7321c57a4 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3959,17 +3959,29 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy,
3959 } 3959 }
3960 3960
3961 /* In case of required privacy without resolvable private address, 3961 /* In case of required privacy without resolvable private address,
3962 * use an unresolvable private address. This is useful for active 3962 * use an non-resolvable private address. This is useful for active
3963 * scanning and non-connectable advertising. 3963 * scanning and non-connectable advertising.
3964 */ 3964 */
3965 if (require_privacy) { 3965 if (require_privacy) {
3966 bdaddr_t urpa; 3966 bdaddr_t nrpa;
3967 3967
3968 get_random_bytes(&urpa, 6); 3968 while (true) {
3969 urpa.b[5] &= 0x3f; /* Clear two most significant bits */ 3969 /* The non-resolvable private address is generated
3970 * from random six bytes with the two most significant
3971 * bits cleared.
3972 */
3973 get_random_bytes(&nrpa, 6);
3974 nrpa.b[5] &= 0x3f;
3975
3976 /* The non-resolvable private address shall not be
3977 * equal to the public address.
3978 */
3979 if (bacmp(&hdev->bdaddr, &nrpa))
3980 break;
3981 }
3970 3982
3971 *own_addr_type = ADDR_LE_DEV_RANDOM; 3983 *own_addr_type = ADDR_LE_DEV_RANDOM;
3972 set_random_addr(req, &urpa); 3984 set_random_addr(req, &nrpa);
3973 return 0; 3985 return 0;
3974 } 3986 }
3975 3987
@@ -5625,7 +5637,7 @@ void hci_req_add_le_passive_scan(struct hci_request *req)
5625 u8 filter_policy; 5637 u8 filter_policy;
5626 5638
5627 /* Set require_privacy to false since no SCAN_REQ are send 5639 /* Set require_privacy to false since no SCAN_REQ are send
5628 * during passive scanning. Not using an unresolvable address 5640 * during passive scanning. Not using an non-resolvable address
5629 * here is important so that peer devices using direct 5641 * here is important so that peer devices using direct
5630 * advertising with our address will be correctly reported 5642 * advertising with our address will be correctly reported
5631 * by the controller. 5643 * by the controller.
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index a91e484886fe..44b20deb6038 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3791,7 +3791,7 @@ static bool trigger_discovery(struct hci_request *req, u8 *status)
3791 3791
3792 /* All active scans will be done with either a resolvable 3792 /* All active scans will be done with either a resolvable
3793 * private address (when privacy feature has been enabled) 3793 * private address (when privacy feature has been enabled)
3794 * or unresolvable private address. 3794 * or non-resolvable private address.
3795 */ 3795 */
3796 err = hci_update_random_address(req, true, &own_addr_type); 3796 err = hci_update_random_address(req, true, &own_addr_type);
3797 if (err < 0) { 3797 if (err < 0) {