Skip to content

Commit 0ef0831

Browse files
bgixVudentz
authored andcommitted
Bluetooth: Convert delayed discov_off to hci_sync
The timed ending of Discoverability was handled in hci_requst.c, with calls using the deprecated hci_req_add() mechanism. Converted to live inside mgmt.c using the same delayed work queue, but with hci_sync version of hci_update_discoverable(). Signed-off-by: Brian Gix <brian.gix@intel.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent bb87672 commit 0ef0831

File tree

2 files changed

+33
-89
lines changed

2 files changed

+33
-89
lines changed

net/bluetooth/hci_request.c

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,69 +1875,6 @@ void __hci_req_update_class(struct hci_request *req)
18751875
hci_req_add(req, HCI_OP_WRITE_CLASS_OF_DEV, sizeof(cod), cod);
18761876
}
18771877

1878-
static void write_iac(struct hci_request *req)
1879-
{
1880-
struct hci_dev *hdev = req->hdev;
1881-
struct hci_cp_write_current_iac_lap cp;
1882-
1883-
if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE))
1884-
return;
1885-
1886-
if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) {
1887-
/* Limited discoverable mode */
1888-
cp.num_iac = min_t(u8, hdev->num_iac, 2);
1889-
cp.iac_lap[0] = 0x00; /* LIAC */
1890-
cp.iac_lap[1] = 0x8b;
1891-
cp.iac_lap[2] = 0x9e;
1892-
cp.iac_lap[3] = 0x33; /* GIAC */
1893-
cp.iac_lap[4] = 0x8b;
1894-
cp.iac_lap[5] = 0x9e;
1895-
} else {
1896-
/* General discoverable mode */
1897-
cp.num_iac = 1;
1898-
cp.iac_lap[0] = 0x33; /* GIAC */
1899-
cp.iac_lap[1] = 0x8b;
1900-
cp.iac_lap[2] = 0x9e;
1901-
}
1902-
1903-
hci_req_add(req, HCI_OP_WRITE_CURRENT_IAC_LAP,
1904-
(cp.num_iac * 3) + 1, &cp);
1905-
}
1906-
1907-
static int discoverable_update(struct hci_request *req, unsigned long opt)
1908-
{
1909-
struct hci_dev *hdev = req->hdev;
1910-
1911-
hci_dev_lock(hdev);
1912-
1913-
if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) {
1914-
write_iac(req);
1915-
__hci_req_update_scan(req);
1916-
__hci_req_update_class(req);
1917-
}
1918-
1919-
/* Advertising instances don't use the global discoverable setting, so
1920-
* only update AD if advertising was enabled using Set Advertising.
1921-
*/
1922-
if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) {
1923-
__hci_req_update_adv_data(req, 0x00);
1924-
1925-
/* Discoverable mode affects the local advertising
1926-
* address in limited privacy mode.
1927-
*/
1928-
if (hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) {
1929-
if (ext_adv_capable(hdev))
1930-
__hci_req_start_ext_adv(req, 0x00);
1931-
else
1932-
__hci_req_enable_advertising(req);
1933-
}
1934-
}
1935-
1936-
hci_dev_unlock(hdev);
1937-
1938-
return 0;
1939-
}
1940-
19411878
void __hci_abort_conn(struct hci_request *req, struct hci_conn *conn,
19421879
u8 reason)
19431880
{
@@ -2307,33 +2244,8 @@ int hci_req_configure_datapath(struct hci_dev *hdev, struct bt_codec *codec)
23072244
return err;
23082245
}
23092246

2310-
static void discov_off(struct work_struct *work)
2311-
{
2312-
struct hci_dev *hdev = container_of(work, struct hci_dev,
2313-
discov_off.work);
2314-
2315-
bt_dev_dbg(hdev, "");
2316-
2317-
hci_dev_lock(hdev);
2318-
2319-
/* When discoverable timeout triggers, then just make sure
2320-
* the limited discoverable flag is cleared. Even in the case
2321-
* of a timeout triggered from general discoverable, it is
2322-
* safe to unconditionally clear the flag.
2323-
*/
2324-
hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE);
2325-
hci_dev_clear_flag(hdev, HCI_DISCOVERABLE);
2326-
hdev->discov_timeout = 0;
2327-
2328-
hci_dev_unlock(hdev);
2329-
2330-
hci_req_sync(hdev, discoverable_update, 0, HCI_CMD_TIMEOUT, NULL);
2331-
mgmt_new_settings(hdev);
2332-
}
2333-
23342247
void hci_request_setup(struct hci_dev *hdev)
23352248
{
2336-
INIT_DELAYED_WORK(&hdev->discov_off, discov_off);
23372249
INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable_work);
23382250
INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart_work);
23392251
INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire);
@@ -2344,7 +2256,6 @@ void hci_request_cancel_all(struct hci_dev *hdev)
23442256
{
23452257
__hci_cmd_sync_cancel(hdev, ENODEV);
23462258

2347-
cancel_delayed_work_sync(&hdev->discov_off);
23482259
cancel_delayed_work_sync(&hdev->le_scan_disable);
23492260
cancel_delayed_work_sync(&hdev->le_scan_restart);
23502261

net/bluetooth/mgmt.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,11 +1023,39 @@ static void rpa_expired(struct work_struct *work)
10231023
hci_cmd_sync_queue(hdev, rpa_expired_sync, NULL, NULL);
10241024
}
10251025

1026+
static void discov_off(struct work_struct *work)
1027+
{
1028+
struct hci_dev *hdev = container_of(work, struct hci_dev,
1029+
discov_off.work);
1030+
1031+
bt_dev_dbg(hdev, "");
1032+
1033+
hci_dev_lock(hdev);
1034+
1035+
/* When discoverable timeout triggers, then just make sure
1036+
* the limited discoverable flag is cleared. Even in the case
1037+
* of a timeout triggered from general discoverable, it is
1038+
* safe to unconditionally clear the flag.
1039+
*/
1040+
hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE);
1041+
hci_dev_clear_flag(hdev, HCI_DISCOVERABLE);
1042+
hdev->discov_timeout = 0;
1043+
1044+
hci_update_discoverable(hdev);
1045+
1046+
mgmt_new_settings(hdev);
1047+
1048+
hci_dev_unlock(hdev);
1049+
}
1050+
10261051
static void mgmt_init_hdev(struct sock *sk, struct hci_dev *hdev)
10271052
{
10281053
if (hci_dev_test_and_set_flag(hdev, HCI_MGMT))
10291054
return;
10301055

1056+
BT_INFO("MGMT ver %d.%d", MGMT_VERSION, MGMT_REVISION);
1057+
1058+
INIT_DELAYED_WORK(&hdev->discov_off, discov_off);
10311059
INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off);
10321060
INIT_DELAYED_WORK(&hdev->rpa_expired, rpa_expired);
10331061

@@ -8839,6 +8867,11 @@ void mgmt_index_removed(struct hci_dev *hdev)
88398867

88408868
mgmt_index_event(MGMT_EV_EXT_INDEX_REMOVED, hdev, &ev, sizeof(ev),
88418869
HCI_MGMT_EXT_INDEX_EVENTS);
8870+
8871+
/* Cancel any remaining timed work */
8872+
cancel_delayed_work_sync(&hdev->discov_off);
8873+
cancel_delayed_work_sync(&hdev->service_cache);
8874+
cancel_delayed_work_sync(&hdev->rpa_expired);
88428875
}
88438876

88448877
void mgmt_power_on(struct hci_dev *hdev, int err)

0 commit comments

Comments
 (0)