aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2013-10-19 16:38:18 -0400
committerMarcel Holtmann <marcel@holtmann.org>2013-10-20 12:05:40 -0400
commite8ba3a1f08d9386b6e4abe9b00c21e38029a76a4 (patch)
tree6cb40bfcc9b54c01c1c5996c212c5ab7b4ffe9ee /net/bluetooth
parentf87ea1dabb4b0e50f0c3d7140d89f1bb697a1676 (diff)
Bluetooth: Refactor set_connectable settings update to separate function
We will need to directly update the device flags and notify user space of the new settings not just when we're powered off but also if it turns out that there are no HCI commands to send (which can happen in particular when BR/EDR is disabled). Since this is a considerable amount of code, refactor it to a separate function so it can be reused for the "no HCI commands to send" case. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/mgmt.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index c363285c64a8..b74a157bde09 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1381,6 +1381,32 @@ unlock:
1381 hci_dev_unlock(hdev); 1381 hci_dev_unlock(hdev);
1382} 1382}
1383 1383
1384static int set_connectable_update_settings(struct hci_dev *hdev,
1385 struct sock *sk, u8 val)
1386{
1387 bool changed = false;
1388 int err;
1389
1390 if (!!val != test_bit(HCI_CONNECTABLE, &hdev->dev_flags))
1391 changed = true;
1392
1393 if (val) {
1394 set_bit(HCI_CONNECTABLE, &hdev->dev_flags);
1395 } else {
1396 clear_bit(HCI_CONNECTABLE, &hdev->dev_flags);
1397 clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
1398 }
1399
1400 err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev);
1401 if (err < 0)
1402 return err;
1403
1404 if (changed)
1405 return new_settings(hdev, sk);
1406
1407 return 0;
1408}
1409
1384static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data, 1410static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
1385 u16 len) 1411 u16 len)
1386{ 1412{
@@ -1404,25 +1430,7 @@ static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
1404 hci_dev_lock(hdev); 1430 hci_dev_lock(hdev);
1405 1431
1406 if (!hdev_is_powered(hdev)) { 1432 if (!hdev_is_powered(hdev)) {
1407 bool changed = false; 1433 err = set_connectable_update_settings(hdev, sk, cp->val);
1408
1409 if (!!cp->val != test_bit(HCI_CONNECTABLE, &hdev->dev_flags))
1410 changed = true;
1411
1412 if (cp->val) {
1413 set_bit(HCI_CONNECTABLE, &hdev->dev_flags);
1414 } else {
1415 clear_bit(HCI_CONNECTABLE, &hdev->dev_flags);
1416 clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
1417 }
1418
1419 err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev);
1420 if (err < 0)
1421 goto failed;
1422
1423 if (changed)
1424 err = new_settings(hdev, sk);
1425
1426 goto failed; 1434 goto failed;
1427 } 1435 }
1428 1436