aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2014-02-19 22:31:26 -0500
committerJohan Hedberg <johan.hedberg@intel.com>2014-02-20 01:19:37 -0500
commitb32bba6ced5696593a6bae5fdc69dc79c0a97ef5 (patch)
tree4508b0efe6a4d8b067ef716c4ee140d8d01cf26b /net
parent5192d30114771ac5956d750ec506dc574411cc70 (diff)
Bluetooth: Replace own_address_type with force_static_address debugfs
The own_address_type debugfs option does not providing enough flexibity for interacting with the upcoming LE privacy support. What really is needed is an option to force using the static address compared to the public address. The new force_static_address debugfs option does exactly that. In addition it is also only available when the controller does actually have a public address. For single mode LE only controllers this option will not be available. 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_core.c95
1 files changed, 62 insertions, 33 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 3711c7626cb2..b25a36c3064b 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -571,33 +571,52 @@ static const struct file_operations static_address_fops = {
571 .release = single_release, 571 .release = single_release,
572}; 572};
573 573
574static int own_address_type_set(void *data, u64 val) 574static ssize_t force_static_address_read(struct file *file,
575 char __user *user_buf,
576 size_t count, loff_t *ppos)
575{ 577{
576 struct hci_dev *hdev = data; 578 struct hci_dev *hdev = file->private_data;
577 579 char buf[3];
578 if (val != 0 && val != 1)
579 return -EINVAL;
580
581 hci_dev_lock(hdev);
582 hdev->own_addr_type = val;
583 hci_dev_unlock(hdev);
584 580
585 return 0; 581 buf[0] = test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) ? 'Y': 'N';
582 buf[1] = '\n';
583 buf[2] = '\0';
584 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
586} 585}
587 586
588static int own_address_type_get(void *data, u64 *val) 587static ssize_t force_static_address_write(struct file *file,
588 const char __user *user_buf,
589 size_t count, loff_t *ppos)
589{ 590{
590 struct hci_dev *hdev = data; 591 struct hci_dev *hdev = file->private_data;
592 char buf[32];
593 size_t buf_size = min(count, (sizeof(buf)-1));
594 bool enable;
591 595
592 hci_dev_lock(hdev); 596 if (test_bit(HCI_UP, &hdev->flags))
593 *val = hdev->own_addr_type; 597 return -EBUSY;
594 hci_dev_unlock(hdev);
595 598
596 return 0; 599 if (copy_from_user(buf, user_buf, buf_size))
600 return -EFAULT;
601
602 buf[buf_size] = '\0';
603 if (strtobool(buf, &enable))
604 return -EINVAL;
605
606 if (enable == test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags))
607 return -EALREADY;
608
609 change_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags);
610
611 return count;
597} 612}
598 613
599DEFINE_SIMPLE_ATTRIBUTE(own_address_type_fops, own_address_type_get, 614static const struct file_operations force_static_address_fops = {
600 own_address_type_set, "%llu\n"); 615 .open = simple_open,
616 .read = force_static_address_read,
617 .write = force_static_address_write,
618 .llseek = default_llseek,
619};
601 620
602static int identity_resolving_keys_show(struct seq_file *f, void *ptr) 621static int identity_resolving_keys_show(struct seq_file *f, void *ptr)
603{ 622{
@@ -1406,17 +1425,19 @@ static void hci_init3_req(struct hci_request *req, unsigned long opt)
1406 hci_setup_link_policy(req); 1425 hci_setup_link_policy(req);
1407 1426
1408 if (lmp_le_capable(hdev)) { 1427 if (lmp_le_capable(hdev)) {
1409 if (test_bit(HCI_SETUP, &hdev->dev_flags)) { 1428 /* If the controller has a public BD_ADDR, then by default
1410 /* If the controller has a public BD_ADDR, then 1429 * use that one. If this is a LE only controller without
1411 * by default use that one. If this is a LE only 1430 * a public address, default to the random address.
1412 * controller without a public address, default 1431 *
1413 * to the random address. 1432 * For debugging purposes it is possible to force
1414 */ 1433 * controllers with a public address to use the
1415 if (bacmp(&hdev->bdaddr, BDADDR_ANY)) 1434 * random address instead.
1416 hdev->own_addr_type = ADDR_LE_DEV_PUBLIC; 1435 */
1417 else 1436 if (test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dev_flags) ||
1418 hdev->own_addr_type = ADDR_LE_DEV_RANDOM; 1437 !bacmp(&hdev->bdaddr, BDADDR_ANY))
1419 } 1438 hdev->own_addr_type = ADDR_LE_DEV_RANDOM;
1439 else
1440 hdev->own_addr_type = ADDR_LE_DEV_PUBLIC;
1420 1441
1421 hci_set_le_support(req); 1442 hci_set_le_support(req);
1422 } 1443 }
@@ -1536,12 +1557,20 @@ static int __hci_init(struct hci_dev *hdev)
1536 } 1557 }
1537 1558
1538 if (lmp_le_capable(hdev)) { 1559 if (lmp_le_capable(hdev)) {
1560 debugfs_create_file("static_address", 0444, hdev->debugfs,
1561 hdev, &static_address_fops);
1562
1563 /* For controllers with a public address, provide a debug
1564 * option to force the usage of the configured static
1565 * address. By default the public address is used.
1566 */
1567 if (bacmp(&hdev->bdaddr, BDADDR_ANY))
1568 debugfs_create_file("force_static_address", 0644,
1569 hdev->debugfs, hdev,
1570 &force_static_address_fops);
1571
1539 debugfs_create_u8("white_list_size", 0444, hdev->debugfs, 1572 debugfs_create_u8("white_list_size", 0444, hdev->debugfs,
1540 &hdev->le_white_list_size); 1573 &hdev->le_white_list_size);
1541 debugfs_create_file("static_address", 0444, hdev->debugfs,
1542 hdev, &static_address_fops);
1543 debugfs_create_file("own_address_type", 0644, hdev->debugfs,
1544 hdev, &own_address_type_fops);
1545 debugfs_create_file("identity_resolving_keys", 0400, 1574 debugfs_create_file("identity_resolving_keys", 0400,
1546 hdev->debugfs, hdev, 1575 hdev->debugfs, hdev,
1547 &identity_resolving_keys_fops); 1576 &identity_resolving_keys_fops);