aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-02-27 07:05:41 -0500
committerMarcel Holtmann <marcel@holtmann.org>2014-02-27 11:50:21 -0500
commita1f4c3188bb4d51a41d2026ee08a578f56c61e47 (patch)
tree09ece6c79d3caee868ee9a9ad5df23f2947cf140
parent56ed2cb88c7370d5aa88c92a2a0b1cb92c0979b9 (diff)
Bluetooth: Add hci_copy_identity_address convenience function
The number of places needing the local Identity Address are starting to grow so it's better to have a single place for the logic of determining it. This patch adds a convenience function for getting the Identity Address and updates the two current places needing this to use it. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--include/net/bluetooth/hci_core.h2
-rw-r--r--net/bluetooth/hci_core.c35
-rw-r--r--net/bluetooth/hci_event.c17
3 files changed, 28 insertions, 26 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 853376df4f99..093d05eeb3fa 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1292,6 +1292,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
1292 1292
1293int hci_update_random_address(struct hci_request *req, bool require_privacy, 1293int hci_update_random_address(struct hci_request *req, bool require_privacy,
1294 u8 *own_addr_type); 1294 u8 *own_addr_type);
1295void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
1296 u8 *bdaddr_type);
1295 1297
1296#define SCO_AIRMODE_MASK 0x0003 1298#define SCO_AIRMODE_MASK 0x0003
1297#define SCO_AIRMODE_CVSD 0x0000 1299#define SCO_AIRMODE_CVSD 0x0000
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index bbd085d32d78..7113d4cc085f 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -582,21 +582,14 @@ DEFINE_SIMPLE_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get,
582static int identity_show(struct seq_file *f, void *p) 582static int identity_show(struct seq_file *f, void *p)
583{ 583{
584 struct hci_dev *hdev = f->private; 584 struct hci_dev *hdev = f->private;
585 bdaddr_t *addr; 585 bdaddr_t addr;
586 u8 addr_type; 586 u8 addr_type;
587 587
588 hci_dev_lock(hdev); 588 hci_dev_lock(hdev);
589 589
590 if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) || 590 hci_copy_identity_address(hdev, &addr, &addr_type);
591 !bacmp(&hdev->bdaddr, BDADDR_ANY)) {
592 addr = &hdev->static_addr;
593 addr_type = ADDR_LE_DEV_RANDOM;
594 } else {
595 addr = &hdev->bdaddr;
596 addr_type = ADDR_LE_DEV_PUBLIC;
597 }
598 591
599 seq_printf(f, "%pMR (type %u) %*phN %pMR\n", addr, addr_type, 592 seq_printf(f, "%pMR (type %u) %*phN %pMR\n", &addr, addr_type,
600 16, hdev->irk, &hdev->rpa); 593 16, hdev->irk, &hdev->rpa);
601 594
602 hci_dev_unlock(hdev); 595 hci_dev_unlock(hdev);
@@ -3636,6 +3629,28 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy,
3636 return 0; 3629 return 0;
3637} 3630}
3638 3631
3632/* Copy the Identity Address of the controller.
3633 *
3634 * If the controller has a public BD_ADDR, then by default use that one.
3635 * If this is a LE only controller without a public address, default to
3636 * the static random address.
3637 *
3638 * For debugging purposes it is possible to force controllers with a
3639 * public address to use the static random address instead.
3640 */
3641void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
3642 u8 *bdaddr_type)
3643{
3644 if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) ||
3645 !bacmp(&hdev->bdaddr, BDADDR_ANY)) {
3646 bacpy(bdaddr, &hdev->static_addr);
3647 *bdaddr_type = ADDR_LE_DEV_RANDOM;
3648 } else {
3649 bacpy(bdaddr, &hdev->bdaddr);
3650 *bdaddr_type = ADDR_LE_DEV_PUBLIC;
3651 }
3652}
3653
3639/* Alloc HCI device */ 3654/* Alloc HCI device */
3640struct hci_dev *hci_alloc_dev(void) 3655struct hci_dev *hci_alloc_dev(void)
3641{ 3656{
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index f26e91f72930..162235633bf5 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3665,23 +3665,8 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3665 3665
3666 /* Ensure that the hci_conn contains the identity address type 3666 /* Ensure that the hci_conn contains the identity address type
3667 * regardless of which address the connection was made with. 3667 * regardless of which address the connection was made with.
3668 *
3669 * If the controller has a public BD_ADDR, then by default
3670 * use that one. If this is a LE only controller without
3671 * a public address, default to the static random address.
3672 *
3673 * For debugging purposes it is possible to force
3674 * controllers with a public address to use the static
3675 * random address instead.
3676 */ 3668 */
3677 if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) || 3669 hci_copy_identity_address(hdev, &conn->src, &conn->src_type);
3678 !bacmp(&hdev->bdaddr, BDADDR_ANY)) {
3679 bacpy(&conn->src, &hdev->static_addr);
3680 conn->src_type = ADDR_LE_DEV_RANDOM;
3681 } else {
3682 bacpy(&conn->src, &hdev->bdaddr);
3683 conn->src_type = ADDR_LE_DEV_PUBLIC;
3684 }
3685 3670
3686 /* Lookup the identity address from the stored connection 3671 /* Lookup the identity address from the stored connection
3687 * address and address type. 3672 * address and address type.