diff options
-rw-r--r-- | net/bluetooth/mgmt.c | 46 |
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 | ||
1384 | static 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 | |||
1384 | static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data, | 1410 | static 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 | ||