Fix BLE HoG reconnect issues

Combination of three patches sent upstream:
[PATCH 1/3] core: Fix stop_passive_scanning_complete()

Consider MGMT_STATUS_REJECTED as success for stop_passive_scanning().
MGMT_STATUS_REJECTED may be returned from kernel because the passive
scan timer had expired in kernel and passive scan was disabled just
around the time we called stop_passive_scanning().

This issue can be seen with BLE HoG devices trying to reconnect to BlueZ:
bluetoothd[931]: src/adapter.c:device_found_callback() hci0 addr ...
bluetoothd[931]: src/device.c:device_set_legacy() legacy 0
bluetoothd[931]: src/device.c:device_set_rssi() rssi -75
bluetoothd[931]: src/adapter.c:stop_passive_scanning()
bluetoothd[931]: src/adapter.c:discovering_callback() hci0 type 6 discovering 0
bluetoothd[931]: src/adapter.c:trigger_passive_scanning()
bluetoothd[931]: src/adapter.c:stop_passive_scanning_complete() status 0x0b (Rejected)
bluetoothd[931]: Stopping passive scanning failed: Rejected

[PATCH 2/3] core: Fix discovering_callback()

discovering_callback() should not call trigger_passive_scanning() when
outgoing BLE connection is pending.

This issue can be seen with BLE HoG devices trying to reconnect to BlueZ:
bluetoothd[931]: src/adapter.c:device_found_callback() hci0 addr ...
bluetoothd[931]: src/device.c:device_set_legacy() legacy 0
bluetoothd[931]: src/device.c:device_set_rssi() rssi -75
bluetoothd[931]: src/adapter.c:stop_passive_scanning()
bluetoothd[931]: src/adapter.c:discovering_callback() hci0 type 6 discovering 0
bluetoothd[931]: src/adapter.c:trigger_passive_scanning()
bluetoothd[931]: src/adapter.c:stop_passive_scanning_complete() status 0x0b (Rejected)
bluetoothd[931]: Stopping passive scanning failed: Rejected

[PATCH 3/3] core: Fix adapter_connect_list_add()

adapter_connect_list_add() needs to ensure that trigger_passive_scanning() is
called even for existing devices on the connect list.

This issue can be seen with BLE HoG remotes trying to reconnect to BlueZ. If
the connection fails, att_error_cb() adds the failed device back to connect
list, but since the device is already on the list, no code ends up calling
trigger_passive_scanning(). After this point, passive scanning is disabled
and remains disabled for good, and BLE reconnects to BlueZ no longer work.

bluetoothd[931]: src/adapter.c:device_found_callback() hci0 addr ...
bluetoothd[931]: src/device.c:device_set_legacy() legacy 0
bluetoothd[931]: src/adapter.c:stop_passive_scanning()
bluetoothd[931]: src/adapter.c:stop_passive_scanning_complete() status 0x00 (Success)
bluetoothd[931]: src/device.c:device_connect_le() Connection attempt to: ...
bluetoothd[931]: src/adapter.c:discovering_callback() hci0 type 6 discovering 0
bluetoothd[931]: src/adapter.c:connect_failed_callback() hci0 ... status 2
bluetoothd[931]: plugins/policy.c:conn_fail_cb() status 2
bluetoothd[931]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr ... type 1 status 0x2
bluetoothd[931]: src/device.c:device_bonding_complete() bonding (nil) status 0x02
bluetoothd[931]: src/device.c:device_bonding_failed() status 2
bluetoothd[931]: src/adapter.c:resume_discovery()
bluetoothd[931]: src/device.c:att_connect_cb() connect error: Transport endpoint is not connected (134)
bluetoothd[931]: src/device.c:att_error_cb() Enabling automatic connections
bluetoothd[931]: src/adapter.c:adapter_connect_list_add() ignoring already added device ...
... passive scan is disabled and remains disabled for good ...

Change-Id: I0d3ea3554541673f5bd96a27ce5f63f3eb633b83
1 file changed