aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-07-01 15:09:47 -0400
committerMarcel Holtmann <marcel@holtmann.org>2014-07-03 11:42:54 -0400
commit2a8357f2393d89a34b5a77051d29951af9646406 (patch)
treed7ef5335b4809ec6052181fee3e1f835eef6f880 /net
parentc83ed19d23909db10a4402d4c6c0164bab9a9cf0 (diff)
Bluetooth: Fix redundant device (un)blocked events
For the Block/Unblock Device mgmt commands we should only emit the Blocked/Unblocked events on any socket except for the one which received the command. The code was previously incorrectly trying to look up a non-existent pending command and thereby ending up not skipping the command socket for the event. We can simplify the code a lot by simply sending the event directly from the command handler functions. We have the reference to the command socket available there which makes it easy to pass to the mgmt_event function for skipping. The only notable side-effect of this is that the old blacklisting ioctl's no-longer cause mgmt events to be emitted, however as user space versions using these ioctl's are not mgmt-aware this is acceptable. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/hci_core.c4
-rw-r--r--net/bluetooth/mgmt.c50
2 files changed, 18 insertions, 36 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 25ed6d3de410..72eb41424d04 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3275,7 +3275,7 @@ int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
3275 3275
3276 list_add(&entry->list, &hdev->blacklist); 3276 list_add(&entry->list, &hdev->blacklist);
3277 3277
3278 return mgmt_device_blocked(hdev, bdaddr, type); 3278 return 0;
3279} 3279}
3280 3280
3281int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) 3281int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
@@ -3294,7 +3294,7 @@ int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
3294 list_del(&entry->list); 3294 list_del(&entry->list);
3295 kfree(entry); 3295 kfree(entry);
3296 3296
3297 return mgmt_device_unblocked(hdev, bdaddr, type); 3297 return 0;
3298} 3298}
3299 3299
3300struct bdaddr_list *hci_white_list_lookup(struct hci_dev *hdev, 3300struct bdaddr_list *hci_white_list_lookup(struct hci_dev *hdev,
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 408468c07a8a..ba5e215a7561 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3773,11 +3773,16 @@ static int block_device(struct sock *sk, struct hci_dev *hdev, void *data,
3773 hci_dev_lock(hdev); 3773 hci_dev_lock(hdev);
3774 3774
3775 err = hci_blacklist_add(hdev, &cp->addr.bdaddr, cp->addr.type); 3775 err = hci_blacklist_add(hdev, &cp->addr.bdaddr, cp->addr.type);
3776 if (err < 0) 3776 if (err < 0) {
3777 status = MGMT_STATUS_FAILED; 3777 status = MGMT_STATUS_FAILED;
3778 else 3778 goto done;
3779 status = MGMT_STATUS_SUCCESS; 3779 }
3780
3781 mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &cp->addr, sizeof(cp->addr),
3782 sk);
3783 status = MGMT_STATUS_SUCCESS;
3780 3784
3785done:
3781 err = cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status, 3786 err = cmd_complete(sk, hdev->id, MGMT_OP_BLOCK_DEVICE, status,
3782 &cp->addr, sizeof(cp->addr)); 3787 &cp->addr, sizeof(cp->addr));
3783 3788
@@ -3803,11 +3808,16 @@ static int unblock_device(struct sock *sk, struct hci_dev *hdev, void *data,
3803 hci_dev_lock(hdev); 3808 hci_dev_lock(hdev);
3804 3809
3805 err = hci_blacklist_del(hdev, &cp->addr.bdaddr, cp->addr.type); 3810 err = hci_blacklist_del(hdev, &cp->addr.bdaddr, cp->addr.type);
3806 if (err < 0) 3811 if (err < 0) {
3807 status = MGMT_STATUS_INVALID_PARAMS; 3812 status = MGMT_STATUS_INVALID_PARAMS;
3808 else 3813 goto done;
3809 status = MGMT_STATUS_SUCCESS; 3814 }
3815
3816 mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &cp->addr, sizeof(cp->addr),
3817 sk);
3818 status = MGMT_STATUS_SUCCESS;
3810 3819
3820done:
3811 err = cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status, 3821 err = cmd_complete(sk, hdev->id, MGMT_OP_UNBLOCK_DEVICE, status,
3812 &cp->addr, sizeof(cp->addr)); 3822 &cp->addr, sizeof(cp->addr));
3813 3823
@@ -6346,34 +6356,6 @@ void mgmt_discovering(struct hci_dev *hdev, u8 discovering)
6346 mgmt_event(MGMT_EV_DISCOVERING, hdev, &ev, sizeof(ev), NULL); 6356 mgmt_event(MGMT_EV_DISCOVERING, hdev, &ev, sizeof(ev), NULL);
6347} 6357}
6348 6358
6349int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
6350{
6351 struct pending_cmd *cmd;
6352 struct mgmt_ev_device_blocked ev;
6353
6354 cmd = mgmt_pending_find(MGMT_OP_BLOCK_DEVICE, hdev);
6355
6356 bacpy(&ev.addr.bdaddr, bdaddr);
6357 ev.addr.type = type;
6358
6359 return mgmt_event(MGMT_EV_DEVICE_BLOCKED, hdev, &ev, sizeof(ev),
6360 cmd ? cmd->sk : NULL);
6361}
6362
6363int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
6364{
6365 struct pending_cmd *cmd;
6366 struct mgmt_ev_device_unblocked ev;
6367
6368 cmd = mgmt_pending_find(MGMT_OP_UNBLOCK_DEVICE, hdev);
6369
6370 bacpy(&ev.addr.bdaddr, bdaddr);
6371 ev.addr.type = type;
6372
6373 return mgmt_event(MGMT_EV_DEVICE_UNBLOCKED, hdev, &ev, sizeof(ev),
6374 cmd ? cmd->sk : NULL);
6375}
6376
6377static void adv_enable_complete(struct hci_dev *hdev, u8 status) 6359static void adv_enable_complete(struct hci_dev *hdev, u8 status)
6378{ 6360{
6379 BT_DBG("%s status %u", hdev->name, status); 6361 BT_DBG("%s status %u", hdev->name, status);