From 0c0dd91a6ce2cf240b8c2e05838d521eb0c26f7a Mon Sep 17 00:00:00 2001 From: natrajmuthusamy <52849136+natrajmuthusamy@users.noreply.github.com> Date: Mon, 20 Jul 2026 15:58:51 +0530 Subject: [PATCH 1/7] RDKOSS-1008: Wait for A2DP disconnect confirmation in BTRMGR_DeInit Reason for change : Added wait time (max 1s) for audio device disconnect confirmation before exiting D-Bus. Without this, btmgr exits while AVDTP CLOSE signaling is still in-flight, causing bluetoothd to crash in clear_endpoint when the response arrives after endpoint destruction. Test Procedure: Regression test cases should be performed. Risks: High Signed-off-by: Natraj --- src/ifce/btrMgr.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ifce/btrMgr.c b/src/ifce/btrMgr.c index 5faefc3..a9badb9 100644 --- a/src/ifce/btrMgr.c +++ b/src/ifce/btrMgr.c @@ -4124,7 +4124,18 @@ BTRMGR_DeInit ( if (BTRCore_DisconnectDevice(ghBTRCoreHdl, lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle, lenBtrCoreDevTy) != enBTRCoreSuccess) { BTRMGRLOG_ERROR ("Failed to Disconnect - %llu\n", lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle); } - } + if (lenBtrCoreDevTy == enBTRCoreSpeakers || lenBtrCoreDevTy == enBTRCoreHeadSet) { + unsigned int ui32PollCount = 10; /* 10 × 100ms = 1s max */ + + do { + usleep(100000); /* 100ms */ + lenBtrCoreRet = BTRCore_GetDeviceDisconnected(ghBTRCoreHdl,lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle,lenBtrCoreDevTy); + } while ((lenBtrCoreRet != enBTRCoreSuccess) && (--ui32PollCount)); + + if (!ui32PollCount) { + BTRMGRLOG_WARN("Disconnect confirmation timeout for device %llu\n", lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle); + } + } } } From e58d8a87be14b7a62f818343ae704fbd529fa46b Mon Sep 17 00:00:00 2001 From: natrajmuthusamy <52849136+natrajmuthusamy@users.noreply.github.com> Date: Mon, 20 Jul 2026 16:03:53 +0530 Subject: [PATCH 2/7] Update btrMgr.c --- src/ifce/btrMgr.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ifce/btrMgr.c b/src/ifce/btrMgr.c index a9badb9..e93c0a3 100644 --- a/src/ifce/btrMgr.c +++ b/src/ifce/btrMgr.c @@ -4127,15 +4127,16 @@ BTRMGR_DeInit ( if (lenBtrCoreDevTy == enBTRCoreSpeakers || lenBtrCoreDevTy == enBTRCoreHeadSet) { unsigned int ui32PollCount = 10; /* 10 × 100ms = 1s max */ - do { - usleep(100000); /* 100ms */ - lenBtrCoreRet = BTRCore_GetDeviceDisconnected(ghBTRCoreHdl,lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle,lenBtrCoreDevTy); - } while ((lenBtrCoreRet != enBTRCoreSuccess) && (--ui32PollCount)); + do { + usleep(100000); /* 100ms */ + lenBtrCoreRet = BTRCore_GetDeviceDisconnected(ghBTRCoreHdl,lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle,lenBtrCoreDevTy); + } while ((lenBtrCoreRet != enBTRCoreSuccess) && (--ui32PollCount)); - if (!ui32PollCount) { - BTRMGRLOG_WARN("Disconnect confirmation timeout for device %llu\n", lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle); - } - } + if (!ui32PollCount) { + BTRMGRLOG_WARN("Disconnect confirmation timeout for device %llu\n", lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle); + } + } + } } } From 0a44cdac2b085ad4e72022a9c49fe0c228b32384 Mon Sep 17 00:00:00 2001 From: natrajmuthusamy <52849136+natrajmuthusamy@users.noreply.github.com> Date: Mon, 20 Jul 2026 16:09:41 +0530 Subject: [PATCH 3/7] Update btrMgr.c --- src/ifce/btrMgr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ifce/btrMgr.c b/src/ifce/btrMgr.c index e93c0a3..2968e1e 100644 --- a/src/ifce/btrMgr.c +++ b/src/ifce/btrMgr.c @@ -4134,7 +4134,9 @@ BTRMGR_DeInit ( if (!ui32PollCount) { BTRMGRLOG_WARN("Disconnect confirmation timeout for device %llu\n", lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle); - } + } else { + BTRMGRLOG_WARN("Disconnect confirmed for device %llu in %dms\n", lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle, (10 - ui32PollCount) * 100); + } } } } From fc33a04eec437f757dc0f7d064a84c49bd384b72 Mon Sep 17 00:00:00 2001 From: natrajmuthusamy <52849136+natrajmuthusamy@users.noreply.github.com> Date: Mon, 20 Jul 2026 18:42:04 +0530 Subject: [PATCH 4/7] Update btrMgr.c --- src/ifce/btrMgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ifce/btrMgr.c b/src/ifce/btrMgr.c index 2968e1e..0d597a0 100644 --- a/src/ifce/btrMgr.c +++ b/src/ifce/btrMgr.c @@ -4125,7 +4125,7 @@ BTRMGR_DeInit ( BTRMGRLOG_ERROR ("Failed to Disconnect - %llu\n", lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle); } if (lenBtrCoreDevTy == enBTRCoreSpeakers || lenBtrCoreDevTy == enBTRCoreHeadSet) { - unsigned int ui32PollCount = 10; /* 10 × 100ms = 1s max */ + unsigned int ui32PollCount = 5; /* 5 × 100ms = 500ms max */ do { usleep(100000); /* 100ms */ From ecb576ca34469be963bd623cf24a19647171db53 Mon Sep 17 00:00:00 2001 From: natrajmuthusamy <52849136+natrajmuthusamy@users.noreply.github.com> Date: Tue, 21 Jul 2026 14:52:31 +0530 Subject: [PATCH 5/7] Update btrMgr.c --- src/ifce/btrMgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ifce/btrMgr.c b/src/ifce/btrMgr.c index 0d597a0..360d730 100644 --- a/src/ifce/btrMgr.c +++ b/src/ifce/btrMgr.c @@ -4125,7 +4125,7 @@ BTRMGR_DeInit ( BTRMGRLOG_ERROR ("Failed to Disconnect - %llu\n", lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle); } if (lenBtrCoreDevTy == enBTRCoreSpeakers || lenBtrCoreDevTy == enBTRCoreHeadSet) { - unsigned int ui32PollCount = 5; /* 5 × 100ms = 500ms max */ + unsigned int ui32PollCount = 10; /* 10 × 100ms = 1000ms max */ do { usleep(100000); /* 100ms */ From f92158675fc12a5e83a5272e05c9e6eeca72c9ae Mon Sep 17 00:00:00 2001 From: natrajmuthusamy <52849136+natrajmuthusamy@users.noreply.github.com> Date: Wed, 22 Jul 2026 12:43:18 +0530 Subject: [PATCH 6/7] decrease the timeout to 700 ms --- src/ifce/btrMgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ifce/btrMgr.c b/src/ifce/btrMgr.c index 360d730..a0792bd 100644 --- a/src/ifce/btrMgr.c +++ b/src/ifce/btrMgr.c @@ -4125,7 +4125,7 @@ BTRMGR_DeInit ( BTRMGRLOG_ERROR ("Failed to Disconnect - %llu\n", lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle); } if (lenBtrCoreDevTy == enBTRCoreSpeakers || lenBtrCoreDevTy == enBTRCoreHeadSet) { - unsigned int ui32PollCount = 10; /* 10 × 100ms = 1000ms max */ + unsigned int ui32PollCount = 7; /* 7 × 100ms = 700ms max */ do { usleep(100000); /* 100ms */ From 95c0d91d11f98e75a2f6278a9bff11d13c8e41c3 Mon Sep 17 00:00:00 2001 From: natrajmuthusamy <52849136+natrajmuthusamy@users.noreply.github.com> Date: Wed, 22 Jul 2026 17:48:09 +0530 Subject: [PATCH 7/7] Increased the delay time to 1000ms to get the disconnection confirmation from bluez --- src/ifce/btrMgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ifce/btrMgr.c b/src/ifce/btrMgr.c index a0792bd..360d730 100644 --- a/src/ifce/btrMgr.c +++ b/src/ifce/btrMgr.c @@ -4125,7 +4125,7 @@ BTRMGR_DeInit ( BTRMGRLOG_ERROR ("Failed to Disconnect - %llu\n", lstConnectedDevices.m_deviceProperty[ui16LoopIdx].m_deviceHandle); } if (lenBtrCoreDevTy == enBTRCoreSpeakers || lenBtrCoreDevTy == enBTRCoreHeadSet) { - unsigned int ui32PollCount = 7; /* 7 × 100ms = 700ms max */ + unsigned int ui32PollCount = 10; /* 10 × 100ms = 1000ms max */ do { usleep(100000); /* 100ms */