Skip to content

Commit fd41aa4

Browse files
committed
[nrf fromtree] Bluetooth: Host: Log when connecting while scanning may give bad params
The API documentation already states that the controller may require the scan interval and window used for scanning and connection establishment to be equal to obtain the best performance. This commit prints out a warning when this is not the case. The code size is unchanged when `CONFIG_BT_SCAN_AND_INITIATE_IN_PARALLEL=n`. This makes application developers aware that using the parameters `BT_LE_SCAN_ACTIVE_CONTINUOUS` with `BT_CONN_LE_CREATE_CONN` may not give the best performance. Signed-off-by: Rubin Gerritsen <[email protected]> (cherry picked from commit 56a22cb)
1 parent 8bc628d commit fd41aa4

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

subsys/bluetooth/host/conn.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3756,6 +3756,12 @@ int bt_conn_le_create(const bt_addr_le_t *peer, const struct bt_conn_le_create_p
37563756
return -ENOMEM;
37573757
}
37583758

3759+
if (BT_LE_STATES_SCAN_INIT(bt_dev.le.states) &&
3760+
bt_le_explicit_scanner_running() &&
3761+
!bt_le_explicit_scanner_uses_same_params(create_param)) {
3762+
LOG_WRN("Use same scan and connection create params to obtain best performance");
3763+
}
3764+
37593765
create_param_setup(create_param);
37603766

37613767
#if defined(CONFIG_BT_SMP)

subsys/bluetooth/host/scan.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,3 +2414,20 @@ bool bt_le_explicit_scanner_running(void)
24142414
{
24152415
return atomic_test_bit(scan_state.scan_flags, BT_LE_SCAN_USER_EXPLICIT_SCAN);
24162416
}
2417+
2418+
bool bt_le_explicit_scanner_uses_same_params(const struct bt_conn_le_create_param *create_param)
2419+
{
2420+
if (scan_state.explicit_scan_param.window != create_param->window ||
2421+
scan_state.explicit_scan_param.interval != create_param->interval){
2422+
return false;
2423+
}
2424+
2425+
if (scan_state.explicit_scan_param.options & BT_LE_SCAN_OPT_CODED) {
2426+
if (scan_state.explicit_scan_param.window_coded != create_param->window_coded ||
2427+
scan_state.explicit_scan_param.interval_coded != create_param->interval_coded){
2428+
return false;
2429+
}
2430+
}
2431+
2432+
return true;
2433+
}

subsys/bluetooth/host/scan.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,14 @@ int bt_le_scan_user_remove(enum bt_le_scan_user flag);
121121
* Check if the explicit scanner was enabled.
122122
*/
123123
bool bt_le_explicit_scanner_running(void);
124+
125+
/**
126+
* Check if an explicit scanner uses the same parameters
127+
*
128+
* @param create_param Parameters used for connection establishment.
129+
*
130+
* @return true If explicit scanner uses the same parameters
131+
* @return false If explicit scanner uses different parameters
132+
*/
133+
bool bt_le_explicit_scanner_uses_same_params(const struct bt_conn_le_create_param *create_param);
124134
#endif /* defined SUBSYS_BLUETOOTH_HOST_SCAN_H_ */

0 commit comments

Comments
 (0)