From 0ee4fea03d9832129de075a249fb794cf7eef7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Sat, 24 Sep 2022 01:59:53 +0200 Subject: [PATCH] spa: bluez: backend-native: fix HF/HS to AG message terminator Both HFP and HSP require an AT command from HF/HS to AG to be terminated by CR, not LF. (HFP 1.8, 4.34.1; HSP 1.2, 4.8.1) See #2463 Fixes: 0b2d3730b6b9 ("bluez5: Add HFP HF support") --- spa/plugins/bluez5/backend-native.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/spa/plugins/bluez5/backend-native.c b/spa/plugins/bluez5/backend-native.c index afb8d571f..7b57ba2f1 100644 --- a/spa/plugins/bluez5/backend-native.c +++ b/spa/plugins/bluez5/backend-native.c @@ -259,6 +259,7 @@ static void rfcomm_free(struct rfcomm *rfcomm) #define RFCOMM_MESSAGE_MAX_LENGTH 256 +/* from HF/HS to AG */ SPA_PRINTF_FUNC(2, 3) static ssize_t rfcomm_send_cmd(const struct rfcomm *rfcomm, const char *format, ...) { @@ -279,7 +280,14 @@ static ssize_t rfcomm_send_cmd(const struct rfcomm *rfcomm, const char *format, spa_log_debug(backend->log, "RFCOMM >> %s", message); - message[len] = '\n'; + /* + * The format of an AT command from the HF to the AG shall be: + * - HFP 1.8, 4.34.1 + * + * The format for a command from the HS to the AG is thus: AT= + * - HSP 1.2, 4.8.1 + */ + message[len] = '\r'; /* `message` is no longer null-terminated */ len = write(rfcomm->source.fd, message, len + 1); @@ -293,6 +301,7 @@ static ssize_t rfcomm_send_cmd(const struct rfcomm *rfcomm, const char *format, return len; } +/* from AG to HF/HS */ SPA_PRINTF_FUNC(2, 3) static ssize_t rfcomm_send_reply(const struct rfcomm *rfcomm, const char *format, ...) { @@ -313,6 +322,18 @@ static ssize_t rfcomm_send_reply(const struct rfcomm *rfcomm, const char *format spa_log_debug(backend->log, "RFCOMM >> %s", &message[2]); + /* + * The format of the OK code from the AG to the HF shall be: OK + * The format of the generic ERROR code from the AG to the HF shall be: ERROR + * The format of an unsolicited result code from the AG to the HF shall be: + * - HFP 1.8, 4.34.1 + * + * If the command is processed successfully, the resulting response from the AG to the HS is: OK + * If the command is not processed successfully, or is not recognized, + * the resulting response from the AG to the HS is: ERROR + * The format for an unsolicited result code (such as RING) from the AG to the HS is: + * - HSP 1.2, 4.8.1 + */ message[0] = '\r'; message[1] = '\n'; message[len + 2] = '\r';