source: Fix segfault if unpaired during connecting

If an A2DP source is performing service discovery when the device is
unpaired, freed memory is accessed leading to a segmentation fault as
described in the traces below. In order to fix this, stop discovery
specifically:

bluetoothd[26047]: audio/avdtp.c:avdtp_ref() 0x55555582f460: ref=1
bluetoothd[26047]: audio/source.c:source_connect() stream creation in progress
bluetoothd[26047]: src/device.c:device_set_temporary() temporary 1
bluetoothd[26047]: src/device.c:device_remove() Removing device /org/bluez/26047/hci0/dev_90_84_0D_B2_C7_04
bluetoothd[26047]: src/device.c:device_set_bonded() bonded 0
bluetoothd[26047]: plugins/mgmtops.c:mgmt_unpair_device() index 0 addr 90:84:0D:B2:C7:04
bluetoothd[26047]: network/manager.c:network_remove() path /org/bluez/26047/hci0/dev_90_84_0D_B2_C7_04
bluetoothd[26047]: network/connection.c:path_unregister() Unregistered interface org.bluez.Network on path /org/bluez/26047/hci0/dev_90_84_0D_B2_C7_04
bluetoothd[26047]: src/device.c:btd_device_unref() 0x555555826bb0: ref=2
bluetoothd[26047]: serial/manager.c:serial_remove() path /org/bluez/26047/hci0/dev_90_84_0D_B2_C7_04
bluetoothd[26047]: serial/port.c:path_unregister() Unregistered interface org.bluez.Serial on path /org/bluez/26047/hci0/dev_90_84_0D_B2_C7_04
bluetoothd[26047]: audio/gateway.c:path_unregister() Unregistered interface org.bluez.HandsfreeGateway on path /org/bluez/26047/hci0/dev_90_84_0D_B2_C7_04
bluetoothd[26047]: audio/gateway.c:gateway_close() discovering 0 tmp_rfcomm=(nil) rfcomm=(nil) msg (nil)
bluetoothd[26047]: audio/source.c:path_unregister() Unregistered interface org.bluez.AudioSource on path /org/bluez/26047/hci0/dev_90_84_0D_B2_C7_04
bluetoothd[26047]: audio/avdtp.c:avdtp_unref() 0x55555582f460: ref=0
bluetoothd[26047]: audio/control.c:path_unregister() Unregistered interface org.bluez.Control on path /org/bluez/26047/hci0/dev_90_84_0D_B2_C7_04
bluetoothd[26047]: src/device.c:btd_device_unref() 0x555555826bb0: ref=1
bluetoothd[26047]: src/device.c:btd_device_unref() 0x555555826bb0: ref=0
bluetoothd[26047]: src/device.c:device_free() 0x555555826bb0
bluetoothd[26047]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[26047]: plugins/mgmtops.c:mgmt_event() Received 16 bytes from management socket
bluetoothd[26047]: plugins/mgmtops.c:mgmt_cmd_complete()
bluetoothd[26047]: plugins/mgmtops.c:mgmt_cmd_complete() unpair_device complete
bluetoothd[26047]: audio/avdtp.c:connection_lost() Disconnected from 90:84:0D:B2:C7:04
bluetoothd[26047]: audio/avdtp.c:avdtp_unref() 0x55555582f460: ref=-1
bluetoothd[26047]: audio/source.c:discovery_complete() connect:connect XCASE detected
bluetoothd[26047]: avdtp_set_state(): no matching audio device
bluetoothd[26047]: audio/source.c:stream_setup_retry() Stream setup failed, after XCASE connect:connect

Program received signal SIGSEGV, Segmentation fault.
gateway: Trivial variable rename to tmp_rfcomm

Follow the naming in headset.c to rename the prior gw->incoming to
gw->tmp_rfcomm, which is more generic.
gateway: Refactor to remove unregister_incoming()

Close the temporary RFCOMM inside gateway_close(), instead of having a
specific function to handle this.
gateway: Fix not closing temporary RFCOMM

If the gateway is closed during the RFCOMM stablishment (after service
records are gathered) the temporary RFCOMM channel was not closed. Fix
this by storing the channel reference in gw->tmp_rfcomm also for
outgoing connections.
gateway: Cancel discovery in gateway_close()

If service discovery is ongoing when gateway_close() is reached, cancel
it immediately.
gateway: Fix missing dbus_message_unref() calls

gw->msg was referenced with dbus_message_ref() but never unreferenced
correspondingly with dbus_message_unref().
gateway: Fix potential messages without reply

If gateway_close() is called while a pending connection call exists,
send a reply with a generic error message.
gateway: Cancel connection attempt if Disconnect()

If a Disconnect() call is received while there is an ongoing connection
attempt, cancel it. If an service discovery is in process or RFCOMM is
being stablished, cancel them.
Propagate disconnect reason to adapter

Internally propagate disconnect reason.
Propagate disconnect reason to device

Internally propagate disconnect reason in order to make it public in the
D-Bus API.
Send D-Bus signal to propagate disconnect reason

Propagate the disconnection reason through D-Bus, allowing other
components to react accordingly.
doc: Add D-Bus signal to provide disconnect reason

This signal is needed to propagate the reason in case of disconnection.
Some use-cases require this information, for example if there is a
policy to automatically reconnect in case of connection timeout.
gateway: Add log traces for connection debugging

Additional log traces can be helpful to distinguish when the different
states of the connection procedure are reached.
media: Increase both hardcoded SCO MTUs

When multiple SCO links are active, the packet size typically doubles.
adapter: Disconnect devices during power down

When the adapter is powered down, make sure all devices are
disconnected.
adapter: Add signal to announce powering down

Send a signal before the power-down procedure begins.
doc: Add adapter's PoweringDown D-Bus signal

An external component might need to distinguish device disconnections
from adapter being powered down (e.g. Bluetooth turned off). Unless a
specific signal is sent in the beginning of the procedure, the client
will first receive a profile state update (e.g. HandsfreeGateway state
set to 'disconnected') and therefore cannot realize what's happening.