From 17049abd040a2bff8f1c514e4f1e3400c4c6a54c Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Wed, 25 Jan 2023 20:38:11 +0200 Subject: [PATCH] bluez5: backend-native: fixup HFP command handling Strip initial \n from commands: some devices (Sennheiser HD 350BT) send them. Only reply OK to empty command with terminated command line; non-terminated lines are invalid. Add some debug in case the RFCOMM reply contains non-printable characters. --- spa/plugins/bluez5/backend-native.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spa/plugins/bluez5/backend-native.c b/spa/plugins/bluez5/backend-native.c index 77dd637ba..5eec82c34 100644 --- a/spa/plugins/bluez5/backend-native.c +++ b/spa/plugins/bluez5/backend-native.c @@ -36,6 +36,8 @@ #include +#include +#include #include #include #include @@ -779,6 +781,12 @@ static bool rfcomm_hfp_ag(struct rfcomm *rfcomm, char* buf) int xapl_product; int xapl_features; + spa_debug_log_mem(backend->log, SPA_LOG_LEVEL_DEBUG, 2, buf, strlen(buf)); + + /* Some devices send initial \n: be permissive */ + while (*buf == '\n') + ++buf; + if (sscanf(buf, "AT+BRSF=%u", &features) == 1) { unsigned int ag_features = SPA_BT_HFP_AG_FEATURE_NONE; @@ -880,7 +888,7 @@ static bool rfcomm_hfp_ag(struct rfcomm *rfcomm, char* buf) rfcomm_emit_volume_changed(rfcomm, -1, SPA_BT_VOLUME_INVALID); } } - } else if (strspn(buf, " ") == strlen(buf)) { + } else if (spa_streq(buf, "\r")) { /* No commands, reply OK (ITU-T Rec. V.250 Sec. 5.2.1 & 5.6) */ rfcomm_send_reply(rfcomm, "OK"); } else if (!rfcomm->slc_configured) {