Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 266334
b: refs/heads/master
c: 5e76244
h: refs/heads/master
v: v3
  • Loading branch information
Antti Julku authored and Gustavo F. Padovan committed Sep 21, 2011
1 parent 5e760c9 commit 0141707
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 35 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c908df362c20be0eeef506fe62e13d835a4633f9
refs/heads/master: 5e762444b0d3e56bbd66f5092434c4a1ba698313
2 changes: 2 additions & 0 deletions trunk/include/net/bluetooth/hci_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ int mgmt_device_found(u16 index, bdaddr_t *bdaddr, u8 *dev_class, s8 rssi,
u8 *eir);
int mgmt_remote_name(u16 index, bdaddr_t *bdaddr, u8 *name);
int mgmt_discovering(u16 index, u8 discovering);
int mgmt_device_blocked(u16 index, bdaddr_t *bdaddr);
int mgmt_device_unblocked(u16 index, bdaddr_t *bdaddr);

/* HCI info for socket */
#define hci_pi(sk) ((struct hci_pinfo *) sk)
Expand Down
10 changes: 10 additions & 0 deletions trunk/include/net/bluetooth/mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,13 @@ struct mgmt_ev_remote_name {
} __packed;

#define MGMT_EV_DISCOVERING 0x0014

#define MGMT_EV_DEVICE_BLOCKED 0x0015
struct mgmt_ev_device_blocked {
bdaddr_t bdaddr;
} __packed;

#define MGMT_EV_DEVICE_UNBLOCKED 0x0016
struct mgmt_ev_device_unblocked {
bdaddr_t bdaddr;
} __packed;
34 changes: 8 additions & 26 deletions trunk/net/bluetooth/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,59 +1312,41 @@ int hci_blacklist_clear(struct hci_dev *hdev)
int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr)
{
struct bdaddr_list *entry;
int err;

if (bacmp(bdaddr, BDADDR_ANY) == 0)
return -EBADF;

hci_dev_lock_bh(hdev);

if (hci_blacklist_lookup(hdev, bdaddr)) {
err = -EEXIST;
goto err;
}
if (hci_blacklist_lookup(hdev, bdaddr))
return -EEXIST;

entry = kzalloc(sizeof(struct bdaddr_list), GFP_KERNEL);
if (!entry) {
err = -ENOMEM;
goto err;
}
if (!entry)
return -ENOMEM;

bacpy(&entry->bdaddr, bdaddr);

list_add(&entry->list, &hdev->blacklist);

err = 0;

err:
hci_dev_unlock_bh(hdev);
return err;
return mgmt_device_blocked(hdev->id, bdaddr);
}

int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr)
{
struct bdaddr_list *entry;
int err = 0;

hci_dev_lock_bh(hdev);

if (bacmp(bdaddr, BDADDR_ANY) == 0) {
hci_blacklist_clear(hdev);
goto done;
return hci_blacklist_clear(hdev);
}

entry = hci_blacklist_lookup(hdev, bdaddr);
if (!entry) {
err = -ENOENT;
goto done;
return -ENOENT;
}

list_del(&entry->list);
kfree(entry);

done:
hci_dev_unlock_bh(hdev);
return err;
return mgmt_device_unblocked(hdev->id, bdaddr);
}

static void hci_clear_adv_cache(unsigned long arg)
Expand Down
18 changes: 16 additions & 2 deletions trunk/net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,35 @@ static int hci_sock_release(struct socket *sock)
static int hci_sock_blacklist_add(struct hci_dev *hdev, void __user *arg)
{
bdaddr_t bdaddr;
int err;

if (copy_from_user(&bdaddr, arg, sizeof(bdaddr)))
return -EFAULT;

return hci_blacklist_add(hdev, &bdaddr);
hci_dev_lock_bh(hdev);

err = hci_blacklist_add(hdev, &bdaddr);

hci_dev_unlock_bh(hdev);

return err;
}

static int hci_sock_blacklist_del(struct hci_dev *hdev, void __user *arg)
{
bdaddr_t bdaddr;
int err;

if (copy_from_user(&bdaddr, arg, sizeof(bdaddr)))
return -EFAULT;

return hci_blacklist_del(hdev, &bdaddr);
hci_dev_lock_bh(hdev);

err = hci_blacklist_del(hdev, &bdaddr);

hci_dev_unlock_bh(hdev);

return err;
}

/* Ioctls that require bound socket */
Expand Down
62 changes: 56 additions & 6 deletions trunk/net/bluetooth/mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1698,13 +1698,12 @@ static int block_device(struct sock *sk, u16 index, unsigned char *data,
u16 len)
{
struct hci_dev *hdev;
struct mgmt_cp_block_device *cp;
struct pending_cmd *cmd;
struct mgmt_cp_block_device *cp = (void *) data;
int err;

BT_DBG("hci%u", index);

cp = (void *) data;

if (len != sizeof(*cp))
return cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE,
EINVAL);
Expand All @@ -1714,13 +1713,26 @@ static int block_device(struct sock *sk, u16 index, unsigned char *data,
return cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE,
ENODEV);

hci_dev_lock_bh(hdev);

cmd = mgmt_pending_add(sk, MGMT_OP_BLOCK_DEVICE, index, NULL, 0);
if (!cmd) {
err = -ENOMEM;
goto failed;
}

err = hci_blacklist_add(hdev, &cp->bdaddr);

if (err < 0)
err = cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE, -err);
else
err = cmd_complete(sk, index, MGMT_OP_BLOCK_DEVICE,
NULL, 0);

mgmt_pending_remove(cmd);

failed:
hci_dev_unlock_bh(hdev);
hci_dev_put(hdev);

return err;
Expand All @@ -1730,13 +1742,12 @@ static int unblock_device(struct sock *sk, u16 index, unsigned char *data,
u16 len)
{
struct hci_dev *hdev;
struct mgmt_cp_unblock_device *cp;
struct pending_cmd *cmd;
struct mgmt_cp_unblock_device *cp = (void *) data;
int err;

BT_DBG("hci%u", index);

cp = (void *) data;

if (len != sizeof(*cp))
return cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE,
EINVAL);
Expand All @@ -1746,13 +1757,26 @@ static int unblock_device(struct sock *sk, u16 index, unsigned char *data,
return cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE,
ENODEV);

hci_dev_lock_bh(hdev);

cmd = mgmt_pending_add(sk, MGMT_OP_UNBLOCK_DEVICE, index, NULL, 0);
if (!cmd) {
err = -ENOMEM;
goto failed;
}

err = hci_blacklist_del(hdev, &cp->bdaddr);

if (err < 0)
err = cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE, -err);
else
err = cmd_complete(sk, index, MGMT_OP_UNBLOCK_DEVICE,
NULL, 0);

mgmt_pending_remove(cmd);

failed:
hci_dev_unlock_bh(hdev);
hci_dev_put(hdev);

return err;
Expand Down Expand Up @@ -2356,3 +2380,29 @@ int mgmt_discovering(u16 index, u8 discovering)
return mgmt_event(MGMT_EV_DISCOVERING, index, &discovering,
sizeof(discovering), NULL);
}

int mgmt_device_blocked(u16 index, bdaddr_t *bdaddr)
{
struct pending_cmd *cmd;
struct mgmt_ev_device_blocked ev;

cmd = mgmt_pending_find(MGMT_OP_BLOCK_DEVICE, index);

bacpy(&ev.bdaddr, bdaddr);

return mgmt_event(MGMT_EV_DEVICE_BLOCKED, index, &ev, sizeof(ev),
cmd ? cmd->sk : NULL);
}

int mgmt_device_unblocked(u16 index, bdaddr_t *bdaddr)
{
struct pending_cmd *cmd;
struct mgmt_ev_device_unblocked ev;

cmd = mgmt_pending_find(MGMT_OP_UNBLOCK_DEVICE, index);

bacpy(&ev.bdaddr, bdaddr);

return mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, index, &ev, sizeof(ev),
cmd ? cmd->sk : NULL);
}

0 comments on commit 0141707

Please sign in to comment.