bluetooth: Try to reconnect SCO

When the SCO connection is in use, if you disconnect first and then connect,
the SCO connection will occasionally fail, and the Bluetooth error code is 42
(0x2A in hexadecimal). This is usually because an error occurred when the SCO
connection was initiated, we need to try to reconnect to optimize the handling
of this problem. The log returned by the kernel is as follows:

Bluetooth: sco_connect_cfm: hcon 0000000003328902 bdaddr 40:ef:4c:0c:11:f0 status 42
Bluetooth: sco_sock_connect status is -38
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/622>
This commit is contained in:
Chengyi Zhao 2021-08-18 20:38:27 +08:00 committed by PulseAudio Marge Bot
parent f5b94eff76
commit 7fd89e491f

View file

@ -108,6 +108,9 @@ static uint32_t hfp_features =
* The choice seems to be a bit arbitrary -- it looks like at least channels 2, 4 and 5 also work*/
#define HSP_HS_DEFAULT_CHANNEL 3
/* Total number of trying to reconnect */
#define SCO_RECONNECTION_COUNT 3
#define PROFILE_INTROSPECT_XML \
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
"<node>" \
@ -320,11 +323,22 @@ fail:
static int sco_acquire_cb(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu) {
int sock;
socklen_t len;
int i;
if (optional)
sock = sco_do_accept(t);
else
sock = sco_do_connect(t);
else {
for (i = 0; i < SCO_RECONNECTION_COUNT; i++) {
sock = sco_do_connect(t);
if (sock < 0) {
pa_log_debug("err is %s and reconnection count is %d", pa_cstrerror(errno), i);
pa_msleep(300);
continue;
} else
break;
}
}
if (sock < 0)
goto fail;