Files
BPI-CM9-Linux/amlbian/scripts/bt/files/0004-bluez-fix-pair-interrupt-error.patch
T
2026-08-24 10:03:24 +08:00

119 lines
3.4 KiB
Diff

From 14b282fd82aa5246ade19086e03ca3ec1c61097d Mon Sep 17 00:00:00 2001
From: Jun Zhang <[email protected]>
Date: Wed, 12 Feb 2025 11:23:04 +0800
Subject: [PATCH 4/4] bluez: fix pair interrupt error
BT: fix pair RC interrupted error [1/1]
PD#SWPL-97637
Problem:
1. when paring RC interrupted, smp is not finished, but
gatt add the devices, causing always reconnect RC.
Solution:
1. finish smp before gatt begin
2. do not handle gatt affairs in smp
Verify:
AP222
Note:
PD#KAR-516
Change-Id: I06650005f6338747a776eae8c650ce30c8ffee3b
Signed-off-by: Weiguang Ruan <[email protected]>
---
src/device.c | 59 +++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 47 insertions(+), 12 deletions(-)
diff --git a/src/device.c b/src/device.c
index 9a4f2ce..5629f9f 100644
--- a/src/device.c
+++ b/src/device.c
@@ -5125,6 +5125,25 @@ static void gatt_debug(const char *str, void *user_data)
DBG_IDX(0xffff, "%s", str);
}
+static gboolean gatt_client_delay_init(struct btd_device *device)
+{
+ static int retry = 3;
+
+ if (device->connect || btd_opts.reverse_discovery) {
+ DBG("device state %d %d", device->connect, btd_opts.reverse_discovery);
+ DBG("current paired state %d", device->le_state.paired);
+ if (device->le_state.paired) {
+ gatt_client_init(device);
+ } else {
+ DBG("Device not paired, pending gatt actions");
+ if (retry--)
+ return true;
+ }
+ }
+ retry = 3;
+ return false; //stop the timer
+}
+
static void gatt_client_init(struct btd_device *device)
{
gatt_client_cleanup(device);
@@ -5317,7 +5336,14 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io)
load_gatt_db(dev, btd_adapter_get_storage_dir(dev->adapter),
dstaddr);
- gatt_client_init(dev);
+ DBG("current paired state %d", dev->le_state.paired);
+ if (dev->le_state.paired) {
+ gatt_client_init(dev);
+ } else {
+ DBG("Timer to start gatt_client_delay_init");
+ gatt_client_cleanup(dev);
+ g_timeout_add_seconds(1, gatt_client_delay_init, dev);
+ }
gatt_server_init(dev, database);
/*
@@ -6045,19 +6071,28 @@ void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type,
device_set_paired(device, bdaddr_type);
- /* If services are already resolved just reply to the pairing
- * request
- */
- if (state->svc_resolved && bonding) {
- /* Attept to store services for this device failed because it
- * was not paired. Now that we're paired retry. */
- store_gatt_db(device);
+ if (bdaddr_type == BDADDR_BREDR) {
+ /* If services are already resolved just reply to the pairing
+ * request
+ */
+ if (state->svc_resolved && bonding) {
+ /* Attept to store services for this device failed because it
+ * was not paired. Now that we're paired retry. */
+ store_gatt_db(device);
- g_dbus_send_reply(dbus_conn, bonding->msg, DBUS_TYPE_INVALID);
- bonding_request_free(bonding);
- return;
+ g_dbus_send_reply(dbus_conn, bonding->msg, DBUS_TYPE_INVALID);
+ bonding_request_free(bonding);
+ return;
+ }
+ } else {
+ /* For BLE, just reply the request, gatt services affairs would be done
+ * at gatt_client.c. */
+ if (bonding) {
+ g_dbus_send_reply(dbus_conn, bonding->msg, DBUS_TYPE_INVALID);
+ bonding_request_free(bonding);
+ return;
+ }
}
-
/* If we were initiators start service discovery immediately.
* However if the other end was the initator wait a few seconds
* before SDP. This is due to potential IOP issues if the other
--
2.25.1