aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorAntti Julku <antti.julku@nokia.com>2011-06-15 05:01:15 -0400
committerGustavo F. Padovan <padovan@profusion.mobi>2011-06-16 17:57:04 -0400
commit7fbec224cfb44074ab88720c878aa3bdb3158377 (patch)
treed8a1487b9e5781b14c28b8b3921219f961d9c0dc /net
parentb2a66aad8620337e38d6692f03d94a03d5129840 (diff)
Bluetooth: Add blacklisting support for mgmt interface
Management interface commands for blocking and unblocking devices. Signed-off-by: Antti Julku <antti.julku@nokia.com> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/mgmt.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d19208903be4..64c0418a6221 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1666,6 +1666,70 @@ failed:
1666 return err; 1666 return err;
1667} 1667}
1668 1668
1669static int block_device(struct sock *sk, u16 index, unsigned char *data,
1670 u16 len)
1671{
1672 struct hci_dev *hdev;
1673 struct mgmt_cp_block_device *cp;
1674 int err;
1675
1676 BT_DBG("hci%u", index);
1677
1678 cp = (void *) data;
1679
1680 if (len != sizeof(*cp))
1681 return cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE,
1682 EINVAL);
1683
1684 hdev = hci_dev_get(index);
1685 if (!hdev)
1686 return cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE,
1687 ENODEV);
1688
1689 err = hci_blacklist_add(hdev, &cp->bdaddr);
1690
1691 if (err < 0)
1692 err = cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE, -err);
1693 else
1694 err = cmd_complete(sk, index, MGMT_OP_BLOCK_DEVICE,
1695 NULL, 0);
1696 hci_dev_put(hdev);
1697
1698 return err;
1699}
1700
1701static int unblock_device(struct sock *sk, u16 index, unsigned char *data,
1702 u16 len)
1703{
1704 struct hci_dev *hdev;
1705 struct mgmt_cp_unblock_device *cp;
1706 int err;
1707
1708 BT_DBG("hci%u", index);
1709
1710 cp = (void *) data;
1711
1712 if (len != sizeof(*cp))
1713 return cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE,
1714 EINVAL);
1715
1716 hdev = hci_dev_get(index);
1717 if (!hdev)
1718 return cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE,
1719 ENODEV);
1720
1721 err = hci_blacklist_del(hdev, &cp->bdaddr);
1722
1723 if (err < 0)
1724 err = cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE, -err);
1725 else
1726 err = cmd_complete(sk, index, MGMT_OP_UNBLOCK_DEVICE,
1727 NULL, 0);
1728 hci_dev_put(hdev);
1729
1730 return err;
1731}
1732
1669int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) 1733int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
1670{ 1734{
1671 unsigned char *buf; 1735 unsigned char *buf;
@@ -1780,6 +1844,12 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
1780 case MGMT_OP_STOP_DISCOVERY: 1844 case MGMT_OP_STOP_DISCOVERY:
1781 err = stop_discovery(sk, index); 1845 err = stop_discovery(sk, index);
1782 break; 1846 break;
1847 case MGMT_OP_BLOCK_DEVICE:
1848 err = block_device(sk, index, buf + sizeof(*hdr), len);
1849 break;
1850 case MGMT_OP_UNBLOCK_DEVICE:
1851 err = unblock_device(sk, index, buf + sizeof(*hdr), len);
1852 break;
1783 default: 1853 default:
1784 BT_DBG("Unknown op %u", opcode); 1854 BT_DBG("Unknown op %u", opcode);
1785 err = cmd_status(sk, index, opcode, 0x01); 1855 err = cmd_status(sk, index, opcode, 0x01);