diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2014-07-09 11:59:14 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-07-09 12:25:27 +0200 |
commit | 6659358efe617bb46237e62f7303c76e10568d70 (patch) | |
tree | cc4f21038000dd5a617580a7adc542a91c1c592c /net/bluetooth/mgmt.c | |
parent | Bluetooth: Unify helpers for bdaddr_list manipulations (diff) | |
download | linux-6659358efe617bb46237e62f7303c76e10568d70.tar.xz linux-6659358efe617bb46237e62f7303c76e10568d70.zip |
Bluetooth: Introduce a whitelist for BR/EDR devices
This patch extends the Add/Remove device commands by letting user space
pass BR/EDR addresses to them. The resulting entries get stored in a new
hdev->whitelist list. The idea is that we can now selectively accept
connections from devices in the list even though HCI_CONNECTABLE is not
set (the actual implementation of this is coming in a subsequent patch).
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to '')
-rw-r--r-- | net/bluetooth/mgmt.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 592e73eea76d..49581e99685c 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -5219,7 +5219,7 @@ static int add_device(struct sock *sk, struct hci_dev *hdev, BT_DBG("%s", hdev->name); - if (!bdaddr_type_is_le(cp->addr.type) || + if (!bdaddr_type_is_valid(cp->addr.type) || !bacmp(&cp->addr.bdaddr, BDADDR_ANY)) return cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, MGMT_STATUS_INVALID_PARAMS, @@ -5232,6 +5232,22 @@ static int add_device(struct sock *sk, struct hci_dev *hdev, hci_dev_lock(hdev); + if (cp->addr.type == BDADDR_BREDR) { + /* Only "connect" action supported for now */ + if (cp->action != 0x01) { + err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, + MGMT_STATUS_INVALID_PARAMS, + &cp->addr, sizeof(cp->addr)); + goto unlock; + } + + err = hci_bdaddr_list_add(&hdev->whitelist, &cp->addr.bdaddr, + cp->addr.type); + if (err) + goto unlock; + goto added; + } + if (cp->addr.type == BDADDR_LE_PUBLIC) addr_type = ADDR_LE_DEV_PUBLIC; else @@ -5253,6 +5269,7 @@ static int add_device(struct sock *sk, struct hci_dev *hdev, goto unlock; } +added: device_added(sk, hdev, &cp->addr.bdaddr, cp->addr.type, cp->action); err = cmd_complete(sk, hdev->id, MGMT_OP_ADD_DEVICE, @@ -5288,13 +5305,30 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev, struct hci_conn_params *params; u8 addr_type; - if (!bdaddr_type_is_le(cp->addr.type)) { + if (!bdaddr_type_is_valid(cp->addr.type)) { err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, MGMT_STATUS_INVALID_PARAMS, &cp->addr, sizeof(cp->addr)); goto unlock; } + if (cp->addr.type == BDADDR_BREDR) { + err = hci_bdaddr_list_del(&hdev->whitelist, + &cp->addr.bdaddr, + cp->addr.type); + if (err) { + err = cmd_complete(sk, hdev->id, + MGMT_OP_REMOVE_DEVICE, + MGMT_STATUS_INVALID_PARAMS, + &cp->addr, sizeof(cp->addr)); + goto unlock; + } + + device_removed(sk, hdev, &cp->addr.bdaddr, + cp->addr.type); + goto complete; + } + if (cp->addr.type == BDADDR_LE_PUBLIC) addr_type = ADDR_LE_DEV_PUBLIC; else @@ -5324,6 +5358,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev, device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type); } else { struct hci_conn_params *p, *tmp; + struct bdaddr_list *b, *btmp; if (cp->addr.type) { err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, @@ -5332,6 +5367,12 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev, goto unlock; } + list_for_each_entry_safe(b, btmp, &hdev->whitelist, list) { + device_removed(sk, hdev, &b->bdaddr, b->bdaddr_type); + list_del(&b->list); + kfree(b); + } + list_for_each_entry_safe(p, tmp, &hdev->le_conn_params, list) { if (p->auto_connect == HCI_AUTO_CONN_DISABLED) continue; @@ -5346,6 +5387,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev, hci_update_background_scan(hdev); } +complete: err = cmd_complete(sk, hdev->id, MGMT_OP_REMOVE_DEVICE, MGMT_STATUS_SUCCESS, &cp->addr, sizeof(cp->addr)); |