Commit 7fbec224cfb44074ab88720c878aa3bdb3158377

Authored by Antti Julku
Committed by Gustavo F. Padovan
1 parent b2a66aad86

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>

Showing 2 changed files with 80 additions and 0 deletions Side-by-side Diff

include/net/bluetooth/mgmt.h
... ... @@ -199,6 +199,16 @@
199 199  
200 200 #define MGMT_OP_STOP_DISCOVERY 0x001C
201 201  
  202 +#define MGMT_OP_BLOCK_DEVICE 0x001D
  203 +struct mgmt_cp_block_device {
  204 + bdaddr_t bdaddr;
  205 +} __packed;
  206 +
  207 +#define MGMT_OP_UNBLOCK_DEVICE 0x001E
  208 +struct mgmt_cp_unblock_device {
  209 + bdaddr_t bdaddr;
  210 +} __packed;
  211 +
202 212 #define MGMT_EV_CMD_COMPLETE 0x0001
203 213 struct mgmt_ev_cmd_complete {
204 214 __le16 opcode;
net/bluetooth/mgmt.c
... ... @@ -1666,6 +1666,70 @@
1666 1666 return err;
1667 1667 }
1668 1668  
  1669 +static 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 +
  1701 +static 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 +
1669 1733 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
1670 1734 {
1671 1735 unsigned char *buf;
... ... @@ -1779,6 +1843,12 @@
1779 1843 break;
1780 1844 case MGMT_OP_STOP_DISCOVERY:
1781 1845 err = stop_discovery(sk, index);
  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);
1782 1852 break;
1783 1853 default:
1784 1854 BT_DBG("Unknown op %u", opcode);