Skip to content

Commit 4fc9857

Browse files
Vudentzholtmann
authored andcommitted
Bluetooth: hci_sync: Add check simultaneous roles support
This attempts to check if the controller can act as both central and peripheral simultaneously and in case it does skip suspending advertising or in case of directed advertising don't fail if scanning. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 6cd29ec commit 4fc9857

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,12 @@ extern struct mutex hci_cb_list_lock;
783783
hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT); \
784784
} while (0)
785785

786+
#define hci_dev_le_state_simultaneous(hdev) \
787+
(test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) && \
788+
(hdev->le_states[4] & 0x08) && /* Central */ \
789+
(hdev->le_states[4] & 0x40) && /* Peripheral */ \
790+
(hdev->le_states[3] & 0x10)) /* Simultaneous */
791+
786792
/* ----- HCI interface to upper protocols ----- */
787793
int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
788794
int l2cap_disconn_ind(struct hci_conn *hcon);

net/bluetooth/hci_sync.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5195,30 +5195,29 @@ int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn)
51955195
u8 own_addr_type;
51965196
int err;
51975197

5198-
/* Disable advertising if we're active. For central role
5199-
* connections most controllers will refuse to connect if
5200-
* advertising is enabled, and for peripheral role connections we
5201-
* anyway have to disable it in order to start directed
5202-
* advertising. Any registered advertisements will be
5203-
* re-enabled after the connection attempt is finished.
5204-
*/
5205-
hci_pause_advertising_sync(hdev);
5206-
52075198
/* If requested to connect as peripheral use directed advertising */
52085199
if (conn->role == HCI_ROLE_SLAVE) {
5209-
/* If we're active scanning most controllers are unable
5210-
* to initiate advertising. Simply reject the attempt.
5200+
/* If we're active scanning and the controller doesn't support
5201+
* simultaneous roles simply reject the attempt.
52115202
*/
52125203
if (hci_dev_test_flag(hdev, HCI_LE_SCAN) &&
5213-
hdev->le_scan_type == LE_SCAN_ACTIVE) {
5204+
hdev->le_scan_type == LE_SCAN_ACTIVE &&
5205+
!hci_dev_le_state_simultaneous(hdev)) {
52145206
hci_conn_del(conn);
52155207
return -EBUSY;
52165208
}
52175209

5210+
/* Pause advertising while doing directed advertising. */
5211+
hci_pause_advertising_sync(hdev);
5212+
52185213
err = hci_le_directed_advertising_sync(hdev, conn);
52195214
goto done;
52205215
}
52215216

5217+
/* Disable advertising if simultaneous roles is not supported. */
5218+
if (!hci_dev_le_state_simultaneous(hdev))
5219+
hci_pause_advertising_sync(hdev);
5220+
52225221
params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
52235222
if (params) {
52245223
conn->le_conn_min_interval = params->conn_min_interval;
@@ -5276,6 +5275,7 @@ int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn)
52765275
HCI_CMD_TIMEOUT, NULL);
52775276

52785277
done:
5278+
/* Re-enable advertising after the connection attempt is finished. */
52795279
hci_resume_advertising_sync(hdev);
52805280
return err;
52815281
}

net/bluetooth/mgmt.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,10 +3916,7 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
39163916
#endif
39173917

39183918
if (hdev) {
3919-
if (test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) &&
3920-
(hdev->le_states[4] & 0x08) && /* Central */
3921-
(hdev->le_states[4] & 0x40) && /* Peripheral */
3922-
(hdev->le_states[3] & 0x10)) /* Simultaneous */
3919+
if (hci_dev_le_state_simultaneous(hdev))
39233920
flags = BIT(0);
39243921
else
39253922
flags = 0;

0 commit comments

Comments
 (0)