Skip to content

Commit d603b76

Browse files
holtmannjhedberg
authored andcommitted
Bluetooth: Run controller setup after external configuration
When the external configuration triggers the switch to a configured controller, it means the setup needs to be run. Controllers that start out unconfigured have only run limited set of HCI commands. This is not enough for complete operation and thus run the setup procedure before announcing the new controller index. This introduces HCI_CONFIG flag as companion to HCI_SETUP flag. The HCI_SETUP flag is only used once for the initial setup procedure. And during that procedure hdev->setup driver callback is called. With the new HCI_CONFIG the switch from unconfigured to configured state is triggering the same setup procedure just without hdev->setup. This is required since bringing a controller back to unconfigured state from configured state is possible. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
1 parent 19de082 commit d603b76

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎include/net/bluetooth/hci.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ enum {
163163
*/
164164
enum {
165165
HCI_SETUP,
166+
HCI_CONFIG,
166167
HCI_AUTO_OFF,
167168
HCI_RFKILLED,
168169
HCI_MGMT,

‎net/bluetooth/hci_core.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,8 @@ static int hci_dev_do_open(struct hci_dev *hdev)
22322232
goto done;
22332233
}
22342234

2235-
if (!test_bit(HCI_SETUP, &hdev->dev_flags)) {
2235+
if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
2236+
!test_bit(HCI_CONFIG, &hdev->dev_flags)) {
22362237
/* Check for rfkill but allow the HCI setup stage to
22372238
* proceed (which in itself doesn't cause any RF activity).
22382239
*/
@@ -2326,6 +2327,7 @@ static int hci_dev_do_open(struct hci_dev *hdev)
23262327
set_bit(HCI_UP, &hdev->flags);
23272328
hci_notify(hdev, HCI_DEV_UP);
23282329
if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
2330+
!test_bit(HCI_CONFIG, &hdev->dev_flags) &&
23292331
!test_bit(HCI_UNCONFIGURED, &hdev->dev_flags) &&
23302332
!test_bit(HCI_USER_CHANNEL, &hdev->dev_flags) &&
23312333
hdev->dev_type == HCI_BREDR) {
@@ -2824,7 +2826,8 @@ static int hci_rfkill_set_block(void *data, bool blocked)
28242826

28252827
if (blocked) {
28262828
set_bit(HCI_RFKILLED, &hdev->dev_flags);
2827-
if (!test_bit(HCI_SETUP, &hdev->dev_flags))
2829+
if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
2830+
!test_bit(HCI_CONFIG, &hdev->dev_flags))
28282831
hci_dev_do_close(hdev);
28292832
} else {
28302833
clear_bit(HCI_RFKILLED, &hdev->dev_flags);
@@ -2881,6 +2884,12 @@ static void hci_power_on(struct work_struct *work)
28812884
* and no event will be send.
28822885
*/
28832886
mgmt_index_added(hdev);
2887+
} else if (test_and_clear_bit(HCI_CONFIG, &hdev->dev_flags)) {
2888+
/* Powering on the controller with HCI_CONFIG set only
2889+
* happens with the transition from unconfigured to
2890+
* configured. This will send the Index Added event.
2891+
*/
2892+
mgmt_index_added(hdev);
28842893
}
28852894
}
28862895

@@ -4045,7 +4054,8 @@ void hci_unregister_dev(struct hci_dev *hdev)
40454054
cancel_work_sync(&hdev->power_on);
40464055

40474056
if (!test_bit(HCI_INIT, &hdev->flags) &&
4048-
!test_bit(HCI_SETUP, &hdev->dev_flags)) {
4057+
!test_bit(HCI_SETUP, &hdev->dev_flags) &&
4058+
!test_bit(HCI_CONFIG, &hdev->dev_flags)) {
40494059
hci_dev_lock(hdev);
40504060
mgmt_index_removed(hdev);
40514061
hci_dev_unlock(hdev);
@@ -5370,6 +5380,7 @@ void hci_update_background_scan(struct hci_dev *hdev)
53705380
if (!test_bit(HCI_UP, &hdev->flags) ||
53715381
test_bit(HCI_INIT, &hdev->flags) ||
53725382
test_bit(HCI_SETUP, &hdev->dev_flags) ||
5383+
test_bit(HCI_CONFIG, &hdev->dev_flags) ||
53735384
test_bit(HCI_AUTO_OFF, &hdev->dev_flags) ||
53745385
test_bit(HCI_UNREGISTER, &hdev->dev_flags))
53755386
return;

‎net/bluetooth/hci_sock.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
693693

694694
if (test_bit(HCI_UP, &hdev->flags) ||
695695
test_bit(HCI_INIT, &hdev->flags) ||
696-
test_bit(HCI_SETUP, &hdev->dev_flags)) {
696+
test_bit(HCI_SETUP, &hdev->dev_flags) ||
697+
test_bit(HCI_CONFIG, &hdev->dev_flags)) {
697698
err = -EBUSY;
698699
hci_dev_put(hdev);
699700
goto done;

‎net/bluetooth/mgmt.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data,
385385
count = 0;
386386
list_for_each_entry(d, &hci_dev_list, list) {
387387
if (test_bit(HCI_SETUP, &d->dev_flags) ||
388+
test_bit(HCI_CONFIG, &d->dev_flags) ||
388389
test_bit(HCI_USER_CHANNEL, &d->dev_flags))
389390
continue;
390391

@@ -444,6 +445,7 @@ static int read_unconf_index_list(struct sock *sk, struct hci_dev *hdev,
444445
count = 0;
445446
list_for_each_entry(d, &hci_dev_list, list) {
446447
if (test_bit(HCI_SETUP, &d->dev_flags) ||
448+
test_bit(HCI_CONFIG, &d->dev_flags) ||
447449
test_bit(HCI_USER_CHANNEL, &d->dev_flags))
448450
continue;
449451

@@ -5441,8 +5443,15 @@ static int set_external_config(struct sock *sk, struct hci_dev *hdev,
54415443

54425444
if (test_bit(HCI_UNCONFIGURED, &hdev->dev_flags) == is_configured(hdev)) {
54435445
mgmt_index_removed(hdev);
5444-
change_bit(HCI_UNCONFIGURED, &hdev->dev_flags);
5445-
mgmt_index_added(hdev);
5446+
5447+
if (test_and_change_bit(HCI_UNCONFIGURED, &hdev->dev_flags)) {
5448+
set_bit(HCI_CONFIG, &hdev->dev_flags);
5449+
set_bit(HCI_AUTO_OFF, &hdev->dev_flags);
5450+
5451+
queue_work(hdev->req_workqueue, &hdev->power_on);
5452+
} else {
5453+
mgmt_index_added(hdev);
5454+
}
54465455
}
54475456

54485457
unlock:
@@ -5558,6 +5567,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
55585567
}
55595568

55605569
if (test_bit(HCI_SETUP, &hdev->dev_flags) ||
5570+
test_bit(HCI_CONFIG, &hdev->dev_flags) ||
55615571
test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
55625572
err = cmd_status(sk, index, opcode,
55635573
MGMT_STATUS_INVALID_INDEX);

0 commit comments

Comments
 (0)