aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/mgmt.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2013-10-06 05:55:21 -0400
committerJohan Hedberg <johan.hedberg@intel.com>2013-10-06 08:53:25 -0400
commitbba3aa550f614b8abf6614f6696a095030ce2ff6 (patch)
treea34dbb3ef87b373fab347aba5a8ad7b02d8ca53c /net/bluetooth/mgmt.c
parent03d87419defc809261c4953e5b44f9e0c8f9029a (diff)
Bluetooth: Use helper functions for enabling/disabling advertising
The tasks of enabling and disabling advertising are required in many cases. So refactor the actual HCI operations into two common helpers to make the code simpler. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'net/bluetooth/mgmt.c')
-rw-r--r--net/bluetooth/mgmt.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index e09ceff5979b..83866848a215 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1411,6 +1411,20 @@ unlock:
1411 return err; 1411 return err;
1412} 1412}
1413 1413
1414static void enable_advertising(struct hci_request *req)
1415{
1416 u8 adv = 0x01;
1417
1418 hci_req_add(req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(adv), &adv);
1419}
1420
1421static void disable_advertising(struct hci_request *req)
1422{
1423 u8 adv = 0x00;
1424
1425 hci_req_add(req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(adv), &adv);
1426}
1427
1414static void le_enable_complete(struct hci_dev *hdev, u8 status) 1428static void le_enable_complete(struct hci_dev *hdev, u8 status)
1415{ 1429{
1416 struct cmd_lookup match = { NULL, hdev }; 1430 struct cmd_lookup match = { NULL, hdev };
@@ -1505,11 +1519,8 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1505 1519
1506 hci_req_init(&req, hdev); 1520 hci_req_init(&req, hdev);
1507 1521
1508 if (test_bit(HCI_ADVERTISING, &hdev->dev_flags) && !val) { 1522 if (test_bit(HCI_ADVERTISING, &hdev->dev_flags) && !val)
1509 u8 adv = 0x00; 1523 disable_advertising(&req);
1510
1511 hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(adv), &adv);
1512 }
1513 1524
1514 hci_req_add(&req, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(hci_cp), 1525 hci_req_add(&req, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(hci_cp),
1515 &hci_cp); 1526 &hci_cp);
@@ -3283,7 +3294,10 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, u1
3283 3294
3284 hci_req_init(&req, hdev); 3295 hci_req_init(&req, hdev);
3285 3296
3286 hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(val), &val); 3297 if (val)
3298 enable_advertising(&req);
3299 else
3300 disable_advertising(&req);
3287 3301
3288 err = hci_req_run(&req, set_advertising_complete); 3302 err = hci_req_run(&req, set_advertising_complete);
3289 if (err < 0) 3303 if (err < 0)
@@ -3861,12 +3875,9 @@ static int powered_update_hci(struct hci_dev *hdev)
3861 if (bacmp(&hdev->static_addr, BDADDR_ANY)) 3875 if (bacmp(&hdev->static_addr, BDADDR_ANY))
3862 hci_req_add(&req, HCI_OP_LE_SET_RANDOM_ADDR, 6, 3876 hci_req_add(&req, HCI_OP_LE_SET_RANDOM_ADDR, 6,
3863 &hdev->static_addr); 3877 &hdev->static_addr);
3864 }
3865
3866 if (test_bit(HCI_ADVERTISING, &hdev->dev_flags)) {
3867 u8 adv = 0x01;
3868 3878
3869 hci_req_add(&req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(adv), &adv); 3879 if (test_bit(HCI_ADVERTISING, &hdev->dev_flags))
3880 enable_advertising(&req);
3870 } 3881 }
3871 3882
3872 link_sec = test_bit(HCI_LINK_SECURITY, &hdev->dev_flags); 3883 link_sec = test_bit(HCI_LINK_SECURITY, &hdev->dev_flags);