pmaports/temp/pulseaudio/0007-bluetooth-Always-reply-to-AT-CIND.patch
Dylan Van Assche f9c7ffa9b6
temp/pulseaudio: fork for Bluetooth HFP/HSP support (MR 3080)
PulseAudio is used for handling all audio on postmarketOS.
This also involves Bluetooth audio such as A2DP, HSP and HFP audio.
In the case of HFP/HSP, the HF and AG can interact with each other
through AT commands defined in the Bluetooth HFP 1.8 spec.

This set of patches implements HFP support to allow Bluetooth devices
to accept/reject/hangup calls, dial numbers, DTMF tone generation,
query signal strength, roaming status, service status, AG battery level,
call status, etc.

More details in the upstream MR:
https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/693

Available in edge for testing this merge request with a broader user
base. Not intended for backporting to stable branches.

[ci:skip-build]: already built successfully in CI
2022-06-16 09:33:35 +02:00

61 lines
2.6 KiB
Diff

From 81045feccb25b627c2c6cfc105c27b2599573fd2 Mon Sep 17 00:00:00 2001
From: Dylan Van Assche <me@dylanvanassche.be>
Date: Wed, 13 Apr 2022 18:29:08 +0200
Subject: [PATCH 07/26] bluetooth: Always reply to AT+CIND
Once the stateful negotiation is complete, still reply
to AT+CIND? and AT+CIND=? since we will report actual data here
such as cellular service status, roaming, signal, and battery level.
---
src/modules/bluetooth/backend-native.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/modules/bluetooth/backend-native.c b/src/modules/bluetooth/backend-native.c
index 1fadb4b14..77792146a 100644
--- a/src/modules/bluetooth/backend-native.c
+++ b/src/modules/bluetooth/backend-native.c
@@ -686,7 +686,7 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
/* no state change */
return true;
- } else if (c->state == 1 && pa_startswith(buf, "AT+CIND=?")) {
+ } else if (c->state >= 1 && pa_startswith(buf, "AT+CIND=?")) {
/* UPower backend available, declare support for more indicators */
if (discovery->native_backend->upower) {
rfcomm_write_response(fd, "+CIND: "
@@ -700,15 +700,29 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
MANDATORY_CALL_INDICATORS ","
"(\"service\",(0-1))");
}
- c->state = 2;
+
+ /*
+ * Only change codec negotiation state when the first AT+CIND=? command is received
+ * Bluetooth HFP 1.8 specification specifies that this AT command is issued 'at least once'.
+ */
+ if (c->state < 2)
+ c->state = 2;
return true;
- } else if (c->state == 2 && pa_startswith(buf, "AT+CIND?")) {
+ } else if (c->state >= 2 && pa_startswith(buf, "AT+CIND?")) {
if (discovery->native_backend->upower)
rfcomm_write_response(fd, "+CIND: 0,0,0,0,%u", pa_upower_get_battery_level(discovery->native_backend->upower));
else
rfcomm_write_response(fd, "+CIND: 0,0,0,0");
- c->state = 3;
+
+ /*
+ * Only change codec negotiation state when the first AT+CIND? command is received.
+ * The Bluetooth HFP 1.8 specification does not define how many times this command is issued.
+ * Some HF devices issue this one multiple times breaking the codec negotiation stateful state,
+ * so only update the state once.
+ */
+ if (c->state < 3)
+ c->state = 3;
return true;
} else if ((c->state == 2 || c->state == 3) && pa_startswith(buf, "AT+CMER=")) {
--
2.35.1