Bluetooth: Use fast scanning only for initial connection attempt

Change-Id: I68303f1fb98b7ed17eec166639811866df024ea9
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-12-03 22:51:16 +02:00 committed by Anas Nashif
commit a2276b6fce
3 changed files with 17 additions and 8 deletions

View file

@ -815,7 +815,7 @@ int bt_conn_disconnect(struct bt_conn *conn, uint8_t reason)
switch (conn->state) { switch (conn->state) {
case BT_CONN_CONNECT_SCAN: case BT_CONN_CONNECT_SCAN:
bt_conn_set_state(conn, BT_CONN_DISCONNECTED); bt_conn_set_state(conn, BT_CONN_DISCONNECTED);
bt_le_scan_update(); bt_le_scan_update(false);
return 0; return 0;
case BT_CONN_CONNECT: case BT_CONN_CONNECT:
return bt_hci_connect_le_cancel(conn); return bt_hci_connect_le_cancel(conn);
@ -857,7 +857,7 @@ struct bt_conn *bt_conn_create_le(const bt_addr_le_t *peer)
bt_conn_set_state(conn, BT_CONN_CONNECT_SCAN); bt_conn_set_state(conn, BT_CONN_CONNECT_SCAN);
bt_le_scan_update(); bt_le_scan_update(true);
return conn; return conn;
} }

View file

@ -449,7 +449,7 @@ static void hci_disconn_complete(struct net_buf *buf)
if (atomic_test_bit(conn->flags, BT_CONN_AUTO_CONNECT)) { if (atomic_test_bit(conn->flags, BT_CONN_AUTO_CONNECT)) {
bt_conn_set_state(conn, BT_CONN_CONNECT_SCAN); bt_conn_set_state(conn, BT_CONN_CONNECT_SCAN);
bt_le_scan_update(); bt_le_scan_update(false);
} }
bt_conn_unref(conn); bt_conn_unref(conn);
@ -586,7 +586,7 @@ static void le_conn_complete(struct net_buf *buf)
done: done:
bt_conn_unref(conn); bt_conn_unref(conn);
bt_le_scan_update(); bt_le_scan_update(false);
} }
static void le_remote_feat_complete(struct net_buf *buf) static void le_remote_feat_complete(struct net_buf *buf)
@ -1175,7 +1175,7 @@ static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window,
return err; return err;
} }
int bt_le_scan_update(void) int bt_le_scan_update(bool fast_scan)
{ {
if (atomic_test_bit(bt_dev.flags, BT_DEV_SCANNING)) { if (atomic_test_bit(bt_dev.flags, BT_DEV_SCANNING)) {
int err; int err;
@ -1192,6 +1192,7 @@ int bt_le_scan_update(void)
#if defined(CONFIG_BLUETOOTH_CONN) #if defined(CONFIG_BLUETOOTH_CONN)
if (!atomic_test_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN)) { if (!atomic_test_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN)) {
uint16_t interval, window;
struct bt_conn *conn; struct bt_conn *conn;
conn = bt_conn_lookup_state(BT_ADDR_LE_ANY, conn = bt_conn_lookup_state(BT_ADDR_LE_ANY,
@ -1202,7 +1203,15 @@ int bt_le_scan_update(void)
bt_conn_unref(conn); bt_conn_unref(conn);
return start_le_scan(BT_HCI_LE_SCAN_PASSIVE, 0x0060, 0x0030, if (fast_scan) {
interval = 0x0060;
window = 0x0030;
} else {
interval = 0x0800;
window = 0x0012;
}
return start_le_scan(BT_HCI_LE_SCAN_PASSIVE, interval, window,
0x01); 0x01);
} }
#endif /* CONFIG_BLUETOOTH_CONN */ #endif /* CONFIG_BLUETOOTH_CONN */
@ -2137,7 +2146,7 @@ int bt_le_scan_stop(void)
scan_dev_found_cb = NULL; scan_dev_found_cb = NULL;
return bt_le_scan_update(); return bt_le_scan_update(false);
} }
struct net_buf *bt_buf_get_evt(void) struct net_buf *bt_buf_get_evt(void)

View file

@ -204,4 +204,4 @@ const char *bt_addr_str(const bt_addr_t *addr);
const char *bt_addr_le_str(const bt_addr_le_t *addr); const char *bt_addr_le_str(const bt_addr_le_t *addr);
#endif #endif
int bt_le_scan_update(void); int bt_le_scan_update(bool fast_scan);