asha: Notify connection interval changes
Subsystems (2)
RFC PATCH v2 1/1 asha: Notify connection interval changes
Omitting the connection-update STATUS notification causes repeated N8 supervision timeouts even with a negotiated 20 ms interval. Restoring the notification alone prevents the reported link failures.
Observe successful LE connection and update events per adapter, associate them with the ATT socket's handle, and announce the observed interval before START and on subsequent successful updates. Clear the observation on disconnect so a reused handle cannot inherit another link's interval. Notify the attached HiSyncId peer as well, matching Android's connection-update STATUS handling, without truncating the interval byte.
Reuse the verified socket handle when delivering a live update.
Add tests for event delivery, controller isolation, disconnect/reuse, pre-START ordering, failed updates and peer notification. Use source-level mocks so the tests remain valid with link-time optimization enabled.
---
Resending unchanged v2 after inactivity closure of the prior CI PR (closure reported October 28). Original source and attribution retained. Prior v2 CI passed as reported; not independently reverified. No new hardware or remote CI result is claimed.
Changes since v1: fix sanitizer-retained daemon references with fail-fast test stubs. Declare socket wrappers in a test header. Refreshed to BlueZ 9dc7e40962f11d1d9a5568f8a7633a695288329c. Strict non-LTO ASan/UBSan build and make check pass; ordinary LTO build and make check pass. Strict LTO has an unchanged upstream peripheral/btsensor warning failure, reproduced without this topic. No new hardware trial or remote functional-lab result is claimed.
Submission review notes (not part of the commit message):
Removing interval STATUS previously caused N8 timeouts; the tested combined package restores it. The observer sends completed values, not requested constants. Raw-HCI access, missed events, startup coordination and observer/connection lifecycle need review. A link predating observer creation remains unknown until a later successful update.
.gitignore | 4 + Makefile.am | 17 ++ profiles/audio/asha.c | 237 +++++++++++++++++++ src/shared/asha.c | 28 +++ src/shared/asha.h | 1 + unit/test-asha-conn.c | 469 ++++++++++++++++++++++++++++++++++++++ unit/test-asha-conn.h | 11 + unit/test-asha-interval.c | 104 +++++++++ 8 files changed, 871 insertions(+) create mode 100644 unit/test-asha-conn.c create mode 100644 unit/test-asha-conn.h create mode 100644 unit/test-asha-interval.c
.gitignore +4 -0
@@ -99,6 +99,8 @@ unit/test-tester unit/test-mainloop unit/test-ringbuf unit/test-queue +unit/test-asha-conn +unit/test-asha-interval unit/test-util unit/test-eir unit/test-uuid
@@ -112,6 +114,8 @@ unit/test-lib unit/test-mgmt unit/test-uhid unit/test-hfp +unit/test-asha-interval +unit/test-asha-conn unit/test-crypto unit/test-ecc unit/test-hog
Makefile.am +17 -0
@@ -706,6 +706,23 @@ unit_test_avrcp_LDADD = lib/libbluetooth-internal.la \ unit_tests += unit/test-hfp +unit_tests += unit/test-asha-interval + +unit_test_asha_interval_SOURCES = unit/test-asha-interval.c +unit_test_asha_interval_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) + +unit_tests += unit/test-asha-conn + +unit_test_asha_conn_SOURCES = unit/test-asha-conn.c unit/test-asha-conn.h +unit_test_asha_conn_CFLAGS = $(AM_CFLAGS) -DBLUETOOTH_PLUGIN_BUILTIN \ + -ffunction-sections -fdata-sections +unit_test_asha_conn_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) $(DBUS_LIBS) +unit_test_asha_conn_LDFLAGS = -Wl,--gc-sections \ + -Wl,--wrap=socket -Wl,--wrap=bind -Wl,--wrap=setsockopt \ + -Wl,--wrap=getsockopt + unit_test_hfp_SOURCES = unit/test-hfp.c unit_test_hfp_LDADD = src/libshared-glib.la $(GLIB_LIBS)
profiles/audio/asha.c +237 -0
279 lines not on this page · raw message
src/shared/asha.c +28 -0
@@ -244,6 +244,34 @@ static int asha_send_acp_without_response(struct bt_asha *asha,return 0 ; } +bool bt_asha_set_connection_interval (struct bt_asha *asha,uint16_t interval) +{ +struct bt_asha_set *set; +struct bt_asha *other =NULL ; +uint8_t cmd[] = {0x03 ,0x02 ,0x00 }; +bool success; + +/* The connection-update STATUS encodes 1.25 ms units in one byte. */ +if (!asha || !asha->client || !asha->acp_handle || + interval <0x0006 || interval >UINT8_MAX ) +return false; + + cmd[2 ] = interval; + success =asha_send_acp_without_response (asha, cmd,sizeof (cmd)) ==0 ; + set =find_asha_set (asha); + +if (set) + other = asha->right_side ? set->left : set->right; + +/* Notify an attached peer even if it has not started streaming yet. */ +if (other && other != asha && other->client && other->acp_handle) { +if (asha_send_acp_without_response (other, cmd,sizeof (cmd)) <0 ) + success = false; + } + +return success; +} +unsigned int bt_asha_start (struct bt_asha *asha,bt_asha_cb_t cb,void *user_data) {
src/shared/asha.h +1 -0
@@ -66,6 +66,7 @@ unsigned int bt_asha_start(struct bt_asha *asha, bt_asha_cb_t cb,unsigned int bt_asha_stop (struct bt_asha *asha);bool bt_asha_set_volume (struct bt_asha *asha,int8_t volume); +bool bt_asha_set_connection_interval (struct bt_asha *asha,uint16_t interval); bool bt_asha_attach(struct bt_asha *asha, struct gatt_db *db, struct bt_gatt_client *client, bt_asha_attach_cb_t probe_cb,
unit/test-asha-conn.c new file +469 -0
469 lines not on this page · raw message
unit/test-asha-conn.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include <sys/socket.h> + +int __wrap_socket (int domain,int type,int protocol); +int __wrap_bind (int fd,const struct sockaddr *addr,socklen_t length); +int __wrap_setsockopt (int fd,int level,int opt,const void *value, +socklen_t length); +int __wrap_getsockopt (int fd,int level,int opt,void *value, +socklen_t *length); +int __real_setsockopt (int fd,int level,int opt,const void *value, +socklen_t length);
unit/test-asha-interval.c new file +104 -0
104 lines not on this page · raw message
base-commit: 9dc7e40962f11d1d9a5568f8a7633a695288329c
Signature · 1 line
2.56.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1195805/
---Test result---
Test Summary:
CheckPatch PASS 0.87 seconds GitLint PASS 0.23 seconds BuildEll PASS 16.24 seconds BluezMake PASS 232.23 seconds MakeCheck PASS 13.77 seconds MakeDistcheck PASS 121.26 seconds CheckValgrind PASS 191.06 seconds CheckSmatch PASS 224.01 seconds bluezmakeextell PASS 76.37 seconds TestFunctional PASS 952.36 seconds IncrementalBuild PASS 234.42 seconds ScanBuild PASS 829.04 seconds
https://github.com/bluez/bluez/pull/2733
---
Regards,
Linux Bluetooth
RFC PATCH v3 1/1 asha: Notify connection interval changes
In reply to Kyle PepperOmitting the connection-update STATUS notification causes repeated N8 supervision timeouts even with a negotiated 20 ms interval. Restoring the notification alone prevents the reported link failures.
Observe successful LE connection and update events per adapter, associate them with the ATT socket's handle, and announce the observed interval before START and on subsequent successful updates. Clear the observation on disconnect so a reused handle cannot inherit another link's interval. Notify the attached HiSyncId peer as well, matching Android's connection-update STATUS handling, without truncating the interval byte.
Reuse the verified socket handle when delivering a live update.
Add tests for event delivery, controller isolation, disconnect/reuse, pre-START ordering, failed updates and peer notification. Use source-level mocks so the tests remain valid with link-time optimization enabled.
---
Small cleanup.
Previous version:
https://lore.kernel.org/r/[email protected]
.gitignore | 2 + Makefile.am | 17 ++ profiles/audio/asha.c | 237 +++++++++++++++++++ src/shared/asha.c | 28 +++ src/shared/asha.h | 1 + unit/test-asha-conn.c | 469 ++++++++++++++++++++++++++++++++++++++ unit/test-asha-conn.h | 11 + unit/test-asha-interval.c | 104 +++++++++ 8 files changed, 869 insertions(+) create mode 100644 unit/test-asha-conn.c create mode 100644 unit/test-asha-conn.h create mode 100644 unit/test-asha-interval.c
.gitignore +2 -0
@@ -99,6 +99,8 @@ unit/test-tester unit/test-mainloop unit/test-ringbuf unit/test-queue +unit/test-asha-conn +unit/test-asha-interval unit/test-util unit/test-eir unit/test-uuid
Makefile.am +17 -0
@@ -709,6 +709,23 @@ unit_test_avrcp_LDADD = lib/libbluetooth-internal.la \ unit_tests += unit/test-hfp +unit_tests += unit/test-asha-interval + +unit_test_asha_interval_SOURCES = unit/test-asha-interval.c +unit_test_asha_interval_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) + +unit_tests += unit/test-asha-conn + +unit_test_asha_conn_SOURCES = unit/test-asha-conn.c unit/test-asha-conn.h +unit_test_asha_conn_CFLAGS = $(AM_CFLAGS) -DBLUETOOTH_PLUGIN_BUILTIN \ + -ffunction-sections -fdata-sections +unit_test_asha_conn_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) $(DBUS_LIBS) +unit_test_asha_conn_LDFLAGS = -Wl,--gc-sections \ + -Wl,--wrap=socket -Wl,--wrap=bind -Wl,--wrap=setsockopt \ + -Wl,--wrap=getsockopt + unit_test_hfp_SOURCES = unit/test-hfp.c unit_test_hfp_LDADD = src/libshared-glib.la $(GLIB_LIBS)
profiles/audio/asha.c +237 -0
279 lines not on this page · raw message
src/shared/asha.c +28 -0
@@ -244,6 +244,34 @@ static int asha_send_acp_without_response(struct bt_asha *asha,return 0 ; } +bool bt_asha_set_connection_interval (struct bt_asha *asha,uint16_t interval) +{ +struct bt_asha_set *set; +struct bt_asha *other =NULL ; +uint8_t cmd[] = {0x03 ,0x02 ,0x00 }; +bool success; + +/* The connection-update STATUS encodes 1.25 ms units in one byte. */ +if (!asha || !asha->client || !asha->acp_handle || + interval <0x0006 || interval >UINT8_MAX ) +return false; + + cmd[2 ] = interval; + success =asha_send_acp_without_response (asha, cmd,sizeof (cmd)) ==0 ; + set =find_asha_set (asha); + +if (set) + other = asha->right_side ? set->left : set->right; + +/* Notify an attached peer even if it has not started streaming yet. */ +if (other && other != asha && other->client && other->acp_handle) { +if (asha_send_acp_without_response (other, cmd,sizeof (cmd)) <0 ) + success = false; + } + +return success; +} +unsigned int bt_asha_start (struct bt_asha *asha,bt_asha_cb_t cb,void *user_data) {
src/shared/asha.h +1 -0
@@ -66,6 +66,7 @@ unsigned int bt_asha_start(struct bt_asha *asha, bt_asha_cb_t cb,unsigned int bt_asha_stop (struct bt_asha *asha);bool bt_asha_set_volume (struct bt_asha *asha,int8_t volume); +bool bt_asha_set_connection_interval (struct bt_asha *asha,uint16_t interval); bool bt_asha_attach(struct bt_asha *asha, struct gatt_db *db, struct bt_gatt_client *client, bt_asha_attach_cb_t probe_cb,
unit/test-asha-conn.c new file +469 -0
469 lines not on this page · raw message
unit/test-asha-conn.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include <sys/socket.h> + +int __wrap_socket (int domain,int type,int protocol); +int __wrap_bind (int fd,const struct sockaddr *addr,socklen_t length); +int __wrap_setsockopt (int fd,int level,int opt,const void *value, +socklen_t length); +int __wrap_getsockopt (int fd,int level,int opt,void *value, +socklen_t *length); +int __real_setsockopt (int fd,int level,int opt,const void *value, +socklen_t length);
unit/test-asha-interval.c new file +104 -0
104 lines not on this page · raw message
base-commit: 34b6f8e0e998728ce9e8e64e280d9d390c511804
Signature · 1 line
2.56.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1204623/
---Test result---
Test Summary:
CheckPatch PASS 1.23 seconds GitLint PASS 0.35 seconds BuildEll PASS 20.73 seconds BluezMake PASS 313.38 seconds MakeCheck PASS 14.75 seconds MakeDistcheck PASS 148.35 seconds CheckValgrind PASS 346.96 seconds CheckSmatch PASS 303.05 seconds bluezmakeextell PASS 99.18 seconds TestFunctional PASS 1177.42 seconds IncrementalBuild PASS 306.77 seconds ScanBuild PASS 1157.23 seconds
https://github.com/bluez/bluez/pull/2773
---
Regards,
Linux Bluetooth
This is an automated email and please do not reply to this email.
Dear Submitter,
This series was picked up by the CI more than 2 weeks ago and the pull request created for it is still open, which means the series was never applied to the tree.
Series: [RFC,v3] asha: Notify connection interval changes
Pull Request: https://github.com/bluez/bluez/pull/2773
Created: 2026-11-07 01:53:25+00:00
The pull request has been closed and no further action is taken on this series.
If the change should still be considered, it must be resent to the Linux Bluetooth mailing list ([email protected]) so that it is picked up again.
---
Regards,
Linux Bluetooth
v4 cover asha: Notify connection interval changes
In reply to Kyle PepperReport observed connection intervals to attached hearing aids. Apply patches 1-4 in order: lifetime fix, shared STATUS helper, profile observer, then tests. No out-of-tree dependency is required.
Changes since v3:
- Unregister ASHA set members by object identity, preserving replacements.
- Split the shared helper, profile observer and tests into separate patches.
- Notify attached devices when an initial connection event arrives late.
- Cover reset, free and same-side replacement in the lifetime tests.
The cached interval is the last successful observation. A requested connection update can still be pending when STATUS precedes START. Links already connected when the observer starts remain unknown until their next observed update. Hardware validation and fresh remote CI remain unverified.
Previous v3 (this cover replies to it):
https://lore.kernel.org/linux-bluetooth/[email protected]/
Previous PR: https://github.com/bluez/bluez/pull/2773
Kyle Pepper (4):
shared/asha: Unregister set members by object
asha: Add connection interval STATUS helper
asha: Notify observed connection intervals
unit: Test ASHA connection interval notifications
.gitignore | 2 + Makefile.am | 17 ++ profiles/audio/asha.c | 231 +++++++++++++++ src/shared/asha.c | 63 ++++- src/shared/asha.h | 1 + unit/test-asha-conn.c | 578 ++++++++++++++++++++++++++++++++++++++ unit/test-asha-conn.h | 11 + unit/test-asha-interval.c | 237 ++++++++++++++++ 8 files changed, 1135 insertions(+), 5 deletions(-) create mode 100644 unit/test-asha-conn.c create mode 100644 unit/test-asha-conn.h create mode 100644 unit/test-asha-interval.c
Signature · 1 line
2.56.1
RFC PATCH v4 1/4 shared/asha: Unregister set members by object
bt_asha_reset() clears the HiSyncId before calling update_asha_set(), whose removal path finds the set by HiSyncId. The lookup then fails and the set keeps pointing at the reset object. bt_asha_free() cannot unregister it either, since the HiSyncId is still clear, so once the object is freed the other side of the pair follows a dangling pointer, for example in asha_set_send_status() when it is stopped.
Find the set that holds the object by pointer and clear only the slot it owns. A reset or freed object that never joined a set, or was already removed, is now a quiet no-op instead of a "Missing ASHA set" error. An object that was replaced by a newer one for the same side also no longer removes its successor when it is released.
--- src/shared/asha.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
src/shared/asha.c +21 -5
@@ -51,6 +51,13 @@ static bool match_hisyncid(const void *data, const void *user_data)return (memcmp (set->hisyncid, asha->hisyncid,8 ) ==0 ); } +static bool match_set_member (const void *data,const void *user_data) +{ +const struct bt_asha_set *set = data; + +return set->left == user_data || set->right == user_data; +} +static struct bt_asha_set *find_asha_set (struct bt_asha *asha) {return queue_find (asha_devices, match_hisyncid, asha);
@@ -83,9 +90,9 @@ static void update_asha_set(struct bt_asha *asha, bool connected) {struct bt_asha_set *set; - set =queue_find (asha_devices, match_hisyncid, asha); -if (connected) { + set =queue_find (asha_devices, match_hisyncid, asha); +if (!set) { set = new0(struct bt_asha_set, 1);memcpy (set->hisyncid, asha->hisyncid,8 );
@@ -101,15 +108,24 @@ static void update_asha_set(struct bt_asha *asha, bool connected)DBG ("Left side registered for ASHA set" ); } }else { +/* +* Find the set by object: the HiSyncId is cleared on reset and +* a replacement for the same side shares it, so it cannot say +* which slot, if any, still belongs to this object. +*/ + set =queue_find (asha_devices, match_set_member, asha); +if (!set) { -error ("Missing ASHA set" ); +DBG ("ASHA object not registered in a set" );return ; } -if (asha->right_side && set->right) { +if (set->right == asha) { set->right =NULL ;DBG ("Right side unregistered for ASHA set" ); - }else if (!asha->right_side && set->left) { + } + +if (set->left == asha) { set->left =NULL ;DBG ("Left side unregistered for ASHA set" ); }
Signature · 1 line
2.56.1
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1220324/
---Test result---
Test Summary:
CheckPatch PASS 1.80 seconds GitLint PASS 0.96 seconds BuildEll PASS 13.56 seconds BluezMake PASS 185.11 seconds MakeCheck PASS 13.05 seconds MakeDistcheck PASS 108.24 seconds CheckValgrind PASS 243.29 seconds CheckSmatch PASS 181.56 seconds bluezmakeextell PASS 62.71 seconds TestFunctional FAIL 932.97 seconds IncrementalBuild PASS 196.23 seconds ScanBuild PASS 631.84 seconds
Details
##############################
Test: TestFunctional - FAIL
Desc: Run test-functional
Output:
FAIL functional.test_bap::test_bass_past_earbuds_transport_acquire[hosts11-vm3]: AssertionError: Failed to acquire: org.bluez.Error.Failed
https://github.com/bluez/bluez/pull/2891
---
Regards,
Linux Bluetooth
RFC PATCH v4 2/4 asha: Add connection interval STATUS helper
In reply to Kyle PepperSend the observed interval to both attached hearing aids, including a peer that has not started streaming. The format follows Android's hearing aid stack, which sends STATUS with a connection update type and the new interval in 1.25 ms units to this side and the other side. Reject intervals that cannot be encoded in the one-byte parameter instead of truncating them.
--- src/shared/asha.c | 37 +++++++++++++++++++++++++++++++++++++ src/shared/asha.h | 1 + 2 files changed, 38 insertions(+)
src/shared/asha.c +37 -0
@@ -260,6 +260,43 @@ static int asha_send_acp_without_response(struct bt_asha *asha,return 0 ; } +bool bt_asha_set_connection_interval (struct bt_asha *asha,uint16_t interval) +{ +struct bt_asha_set *set; +struct bt_asha *other =NULL ; +uint8_t cmd[] = { +0x03 ,/* STATUS */ +0x02 ,/* LE connection parameter update */ +0x00 ,/* Interval, in 1.25 ms units */ + }; +bool success; + +/* +* Android's ASHA document lists only the update type for this STATUS, +* but its hearing aid stack appends the new interval as one more +* byte and sends it to both sides. Reject a value that does not fit +* in that byte instead of truncating it. +*/ +if (!asha || !asha->client || !asha->acp_handle || + interval <0x0006 || interval >UINT8_MAX ) +return false; + + cmd[2 ] = interval; + success =asha_send_acp_without_response (asha, cmd,sizeof (cmd)) ==0 ; + set =find_asha_set (asha); + +if (set) + other = asha->right_side ? set->left : set->right; + +/* Notify an attached peer even if it has not started streaming yet. */ +if (other && other != asha && other->client && other->acp_handle) { +if (asha_send_acp_without_response (other, cmd,sizeof (cmd)) <0 ) + success = false; + } + +return success; +} +unsigned int bt_asha_start (struct bt_asha *asha,bt_asha_cb_t cb,void *user_data) {
src/shared/asha.h +1 -0
@@ -66,6 +66,7 @@ unsigned int bt_asha_start(struct bt_asha *asha, bt_asha_cb_t cb,unsigned int bt_asha_stop (struct bt_asha *asha);bool bt_asha_set_volume (struct bt_asha *asha,int8_t volume); +bool bt_asha_set_connection_interval (struct bt_asha *asha,uint16_t interval); bool bt_asha_attach(struct bt_asha *asha, struct gatt_db *db, struct bt_gatt_client *client, bt_asha_attach_cb_t probe_cb,
Signature · 1 line
2.56.1
RFC PATCH v4 3/4 asha: Notify observed connection intervals
In reply to Kyle PepperCache successful connection intervals per adapter and match each update to the ATT connection handle. Announce the cached value before START and notify attached devices when an initial or updated interval arrives. The cached value is the last one observed; a requested update may still be pending and is announced when it completes. Clear disconnected handles so reused links cannot inherit stale values.
The observer only sees events after the adapter is probed, so a link that was already connected when bluetoothd started has no cached interval until its next update, and nothing is sent for it.
--- profiles/audio/asha.c | 231 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+)
profiles/audio/asha.c +231 -0
@@ -39,6 +39,11 @@#include "src/profile.h" #include "src/service.h" #include "src/shared/util.h" +#include "src/shared/queue.h" +#include "src/shared/hci.h" +#include "src/shared/att.h" +#include "src/shared/gatt-client.h" +#include "monitor/bt.h" #include "profiles/audio/asha.h" #include "profiles/audio/media.h"
@@ -51,6 +56,18 @@/* The default of 672 does not work */ #define ASHA_CONNECTION_MTU 512 +/* HCI handles include zero; a zero cached interval means unknown. */ +#define ASHA_NUM_HANDLES 0x0f00 + +struct asha_adapter { +struct btd_adapter *adapter; +struct bt_hci *hci; +uint16_t intervals[ASHA_NUM_HANDLES ]; +}; + +static struct queue *asha_adapters; +static struct queue *asha_streams; +struct bt_asha_device {struct bt_asha *asha;struct btd_device *device;
@@ -62,6 +79,203 @@ struct bt_asha_device {unsigned int resume_id; }; +static bool match_adapter (const void *data,const void *user_data) +{ +const struct asha_adapter *data_adapter = data; + +return data_adapter->adapter == user_data; +} + +static bool asha_get_handle (struct bt_asha_device *asha_dev,uint16_t *handle) +{ +struct bt_att *att; +struct l2cap_conninfo info; +socklen_t len =sizeof (info); +int fd; + +if (!asha_dev->asha->client) +return false; + + att =bt_gatt_client_get_att (asha_dev->asha->client); + fd =bt_att_get_fd (att); + +/* The ATT socket identifies this link even when CoC is not open. */ +if (fd <0 ||getsockopt (fd,SOL_L2CAP ,L2CAP_CONNINFO , + &info, &len) <0 ) { +DBG ("Could not read ASHA connection handle" ); +return false; + } + +if (len !=sizeof (info) || info.hci_handle >=ASHA_NUM_HANDLES ) +return false; + + *handle = info.hci_handle; +return true; +} + +static void asha_notify_interval (struct bt_asha_device *asha_dev, +uint16_t handle,uint16_t interval) +{ +/* Only announce an interval observed on this connection. */ +if (!interval) +return ; + +DBG ("ASHA connection h%u interval %u" , handle, interval); + +if (!bt_asha_set_connection_interval (asha_dev->asha, interval)) +DBG ("Could not send ASHA connection interval notification" ); +} + +static void asha_send_interval (struct bt_asha_device *asha_dev) +{ +struct asha_adapter *data; +uint16_t handle; + + data =queue_find (asha_adapters, match_adapter, +device_get_adapter (asha_dev->device)); +if (!data || !asha_get_handle (asha_dev, &handle)) +return ; + +asha_notify_interval (asha_dev, handle, data->intervals[handle]); +} + +struct interval_update { +struct asha_adapter *adapter; +uint16_t handle; +}; + +static void asha_update_stream (void *data,void *user_data) +{ +struct bt_asha_device *asha_dev = data; +struct interval_update *update = user_data; +uint16_t handle; + +if (device_get_adapter (asha_dev->device) != update->adapter->adapter || + !asha_get_handle (asha_dev, &handle) || + handle != update->handle) +return ; + +asha_notify_interval (asha_dev, handle, + update->adapter->intervals[handle]); +} + +static void asha_update_interval (struct asha_adapter *data,uint16_t handle, +uint16_t interval) +{ +struct interval_update update = { .adapter = data, .handle = handle }; + +if (handle >=ASHA_NUM_HANDLES ) +return ; + + data->intervals[handle] = interval; +queue_foreach (asha_streams, asha_update_stream, &update); +} + +static void asha_conn_update (const void *param,uint8_t size,void *user_data) +{ +const struct bt_hci_evt_le_conn_update_complete *ev = param; + +if (size !=sizeof (*ev) || ev->status) +return ; + +asha_update_interval (user_data,get_le16 (&ev->handle), +get_le16 (&ev->interval)); +} + +static void asha_conn_complete (const void *param,uint8_t size,void *user_data) +{ +const struct bt_hci_evt_le_conn_complete *ev = param; + +if (size !=sizeof (*ev) || ev->status) +return ; + +asha_update_interval (user_data,get_le16 (&ev->handle), +get_le16 (&ev->interval)); +} + +static void asha_enhanced_conn_complete (const void *param,uint8_t size, +void *user_data) +{ +const struct bt_hci_evt_le_enhanced_conn_complete *ev = param; + +if (size !=sizeof (*ev) || ev->status) +return ; + +asha_update_interval (user_data,get_le16 (&ev->handle), +get_le16 (&ev->interval)); +} + +static void asha_disconn_complete (const void *param,uint8_t size, +void *user_data) +{ +const struct bt_hci_evt_disconnect_complete *ev = param; +struct asha_adapter *data = user_data; +uint16_t handle; + +if (size !=sizeof (*ev) || ev->status) +return ; + + handle =get_le16 (&ev->handle); + +if (handle <ASHA_NUM_HANDLES ) + data->intervals[handle] =0 ; +} + +static int asha_adapter_probe (struct btd_profile *profile, +struct btd_adapter *adapter) +{ +struct asha_adapter *data; + + data = new0(struct asha_adapter, 1); + data->adapter = adapter; + data->hci =bt_hci_new_raw_device (btd_adapter_get_index (adapter)); + +if (!data->hci) + goto fail; + +if (!bt_hci_register_subevent (data->hci,BT_HCI_EVT_LE_CONN_COMPLETE , + asha_conn_complete, data,NULL ) || + !bt_hci_register_subevent (data->hci, +BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE , + asha_enhanced_conn_complete, data,NULL ) || + !bt_hci_register_subevent (data->hci, +BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE , + asha_conn_update, data,NULL ) || + !bt_hci_register (data->hci,BT_HCI_EVT_DISCONNECT_COMPLETE , + asha_disconn_complete, data,NULL )) + goto fail; + +if (!asha_adapters) + asha_adapters =queue_new (); + +queue_push_tail (asha_adapters, data); +return 0 ; + +fail: +bt_hci_unref (data->hci); +free (data); +return -EIO ; +} + +static void asha_adapter_remove (struct btd_profile *profile, +struct btd_adapter *adapter) +{ +struct asha_adapter *data; + + data =queue_remove_if (asha_adapters, match_adapter, adapter); + +if (!data) +return ; + +bt_hci_unref (data->hci); +free (data); + +if (queue_isempty (asha_adapters)) { +queue_destroy (asha_adapters,NULL ); + asha_adapters =NULL ; + } +} +static char *make_endpoint_path (struct bt_asha_device *asha_dev) {char *path;
@@ -118,6 +332,8 @@ static void connect_cb(GIOChannel *io, GError *err, gpointer user_data) asha_dev->io = io; +asha_send_interval (asha_dev); +bt_asha_start (asha_dev->asha, conn_data->cb, conn_data->cb_user_data); }
@@ -361,6 +577,11 @@ static int asha_source_device_probe(struct btd_service *service) asha_dev->asha =bt_asha_new (); asha_dev->io =NULL ; +if (!asha_streams) + asha_streams =queue_new (); + +queue_push_tail (asha_streams, asha_dev); +btd_service_set_user_data (service, asha_dev);return 0 ;
@@ -382,6 +603,13 @@ static void asha_source_device_remove(struct btd_service *service)return ; } +queue_remove (asha_streams, asha_dev); + +if (queue_isempty (asha_streams)) { +queue_destroy (asha_streams,NULL ); + asha_streams =NULL ; + } +bt_asha_free (asha_dev->asha);g_free (asha_dev); }
@@ -514,6 +742,9 @@ static struct btd_profile asha_source_profile = { .remote_uuid = ASHA_PROFILE_UUID, .experimental = true, + .adapter_probe = asha_adapter_probe, + .adapter_remove = asha_adapter_remove, + .device_probe = asha_source_device_probe, .device_remove = asha_source_device_remove,
Signature · 1 line
2.56.1
RFC PATCH v4 4/4 unit: Test ASHA connection interval notifications
In reply to Kyle PepperCover the STATUS helper and the profile observer with mocked GATT and HCI inputs, and cover the lifetime of set members: an object that is reset, freed, or replaced must not stay reachable from the peer's notification path.
--- .gitignore | 2 + Makefile.am | 17 ++ unit/test-asha-conn.c | 578 ++++++++++++++++++++++++++++++++++++++ unit/test-asha-conn.h | 11 + unit/test-asha-interval.c | 237 ++++++++++++++++ 5 files changed, 845 insertions(+) create mode 100644 unit/test-asha-conn.c create mode 100644 unit/test-asha-conn.h create mode 100644 unit/test-asha-interval.c
.gitignore +2 -0
@@ -99,6 +99,8 @@ unit/test-tester unit/test-mainloop unit/test-ringbuf unit/test-queue +unit/test-asha-conn +unit/test-asha-interval unit/test-util unit/test-eir unit/test-uuid
Makefile.am +17 -0
@@ -712,6 +712,23 @@ unit_tests += unit/test-hfp unit_test_hfp_SOURCES = unit/test-hfp.c unit_test_hfp_LDADD = src/libshared-glib.la $(GLIB_LIBS) +unit_tests += unit/test-asha-interval + +unit_test_asha_interval_SOURCES = unit/test-asha-interval.c +unit_test_asha_interval_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) + +unit_tests += unit/test-asha-conn + +unit_test_asha_conn_SOURCES = unit/test-asha-conn.c unit/test-asha-conn.h +unit_test_asha_conn_CFLAGS = $(AM_CFLAGS) -DBLUETOOTH_PLUGIN_BUILTIN \ + -ffunction-sections -fdata-sections +unit_test_asha_conn_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) $(DBUS_LIBS) +unit_test_asha_conn_LDFLAGS = -Wl,--gc-sections \ + -Wl,--wrap=socket -Wl,--wrap=bind -Wl,--wrap=setsockopt \ + -Wl,--wrap=getsockopt + unit_tests += unit/test-gdbus-client unit_test_gdbus_client_SOURCES = unit/test-gdbus-client.c
unit/test-asha-conn.c new file +578 -0
578 lines not on this page · raw message
unit/test-asha-conn.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include <sys/socket.h> + +int __wrap_socket (int domain,int type,int protocol); +int __wrap_bind (int fd,const struct sockaddr *addr,socklen_t length); +int __wrap_setsockopt (int fd,int level,int opt,const void *value, +socklen_t length); +int __wrap_getsockopt (int fd,int level,int opt,void *value, +socklen_t *length); +int __real_setsockopt (int fd,int level,int opt,const void *value, +socklen_t length);
unit/test-asha-interval.c new file +237 -0
237 lines not on this page · raw message
Signature · 1 line
2.56.1
v5 cover asha: Notify connection interval changes
In reply to Kyle PepperReport observed connection intervals to attached hearing aids.
Apply patches 1-4 in order: set lifetime fix, shared STATUS helper, profile observer, then tests. No out-of-tree dependency is required.
Changes since v4:
- Track attached aids separately from previously started aids so a peer receives STATUS before its first START. Remove attachment on reset/free and preserve a replacement when an older object is released.
- Test both directions and ROP/PSM read orders, incomplete discovery and same-side replacement before the older object's release. Keep the START other-connected bit tied to its existing set.
The v4 functional job failed BASS/PAST broadcast earbud acquisition with org.bluez.Error.Failed. This revision fixes a separate ASHA notification gap; it does not claim to resolve that failure. Native functional VM and hardware validation remain unavailable locally.
The observer still reports only its last successful observation. Lost or preexisting events remain unknown until a supported event arrives; LE Enhanced Connection Complete v2 is not registered. Controller power-cycle cache behavior and the profile ownership of the raw observer remain open.
Previous v4 cover (this series replies to it):
https://lore.kernel.org/linux-bluetooth/[email protected]/
Previous PR and functional failure:
https://github.com/bluez/bluez/pull/2891
Kyle Pepper (4):
shared/asha: Unregister set members by object
asha: Add connection interval STATUS helper
asha: Notify observed connection intervals
unit: Test ASHA connection interval notifications
.gitignore | 2 + Makefile.am | 17 ++ profiles/audio/asha.c | 231 +++++++++++++++ src/shared/asha.c | 98 ++++++- src/shared/asha.h | 1 + unit/test-asha-conn.c | 578 ++++++++++++++++++++++++++++++++++++++ unit/test-asha-conn.h | 11 + unit/test-asha-interval.c | 355 +++++++++++++++++++++++ 8 files changed, 1288 insertions(+), 5 deletions(-) create mode 100644 unit/test-asha-conn.c create mode 100644 unit/test-asha-conn.h create mode 100644 unit/test-asha-interval.c
Signature · 1 line
2.56.1
RFC PATCH v5 1/4 shared/asha: Unregister set members by object
bt_asha_reset() clears the HiSyncId before calling update_asha_set(), whose removal path finds the set by HiSyncId. The lookup then fails and the set keeps pointing at the reset object. bt_asha_free() cannot unregister it either, since the HiSyncId is still clear, so once the object is freed the other side of the pair follows a dangling pointer, for example in asha_set_send_status() when it is stopped.
Find the set that holds the object by pointer and clear only the slot it owns. A reset or freed object that never joined a set, or was already removed, is now a quiet no-op instead of a "Missing ASHA set" error. An object that was replaced by a newer one for the same side also no longer removes its successor when it is released.
--- src/shared/asha.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
src/shared/asha.c +21 -5
@@ -51,6 +51,13 @@ static bool match_hisyncid(const void *data, const void *user_data)return (memcmp (set->hisyncid, asha->hisyncid,8 ) ==0 ); } +static bool match_set_member (const void *data,const void *user_data) +{ +const struct bt_asha_set *set = data; + +return set->left == user_data || set->right == user_data; +} +static struct bt_asha_set *find_asha_set (struct bt_asha *asha) {return queue_find (asha_devices, match_hisyncid, asha);
@@ -83,9 +90,9 @@ static void update_asha_set(struct bt_asha *asha, bool connected) {struct bt_asha_set *set; - set =queue_find (asha_devices, match_hisyncid, asha); -if (connected) { + set =queue_find (asha_devices, match_hisyncid, asha); +if (!set) { set = new0(struct bt_asha_set, 1);memcpy (set->hisyncid, asha->hisyncid,8 );
@@ -101,15 +108,24 @@ static void update_asha_set(struct bt_asha *asha, bool connected)DBG ("Left side registered for ASHA set" ); } }else { +/* +* Find the set by object: the HiSyncId is cleared on reset and +* a replacement for the same side shares it, so it cannot say +* which slot, if any, still belongs to this object. +*/ + set =queue_find (asha_devices, match_set_member, asha); +if (!set) { -error ("Missing ASHA set" ); +DBG ("ASHA object not registered in a set" );return ; } -if (asha->right_side && set->right) { +if (set->right == asha) { set->right =NULL ;DBG ("Right side unregistered for ASHA set" ); - }else if (!asha->right_side && set->left) { + } + +if (set->left == asha) { set->left =NULL ;DBG ("Left side unregistered for ASHA set" ); }
Signature · 1 line
2.56.1
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1221082/
---Test result---
Test Summary:
CheckPatch PASS 2.41 seconds GitLint PASS 0.98 seconds BuildEll PASS 18.93 seconds BluezMake PASS 288.27 seconds MakeCheck PASS 14.19 seconds MakeDistcheck PASS 143.26 seconds CheckValgrind PASS 354.39 seconds CheckSmatch PASS 282.45 seconds bluezmakeextell PASS 98.33 seconds TestFunctional PASS 1167.94 seconds IncrementalBuild PASS 322.74 seconds ScanBuild PASS 1106.12 seconds
https://github.com/bluez/bluez/pull/2911
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerHi Kyle,
Quoted 27 lines · On Tue, Nov 24, 2026 at 4:13 PM <[email protected]> wrote:
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1221082/---Test result---
Test Summary:
CheckPatch PASS 2.41 seconds GitLint PASS 0.98 seconds BuildEll PASS 18.93 seconds BluezMake PASS 288.27 seconds MakeCheck PASS 14.19 seconds MakeDistcheck PASS 143.26 seconds CheckValgrind PASS 354.39 seconds CheckSmatch PASS 282.45 seconds bluezmakeextell PASS 98.33 seconds TestFunctional PASS 1167.94 seconds IncrementalBuild PASS 322.74 seconds ScanBuild PASS 1106.12 seconds
Quoted 5 lines
https://github.com/bluez/bluez/pull/2911
---
Regards,
Linux Bluetooth
Copilot flagged a couple of problems:
https://github.com/bluez/bluez/pull/2911
Signature · 1 line
Luiz Augusto von Dentz
RFC PATCH v5 2/4 asha: Add connection interval STATUS helper
In reply to Kyle PepperSend the observed interval to both attached hearing aids, including a peer that has not started streaming. Match the encoding used by Android's hearing aid stack and reject intervals that do not fit in its byte field.
Track attachment after ROP and PSM discovery separately from the set of previously started aids. Remove that membership on reset or free and keep a replacement when an older object for the same side is released.
--- src/shared/asha.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/asha.h | 1 + 2 files changed, 73 insertions(+)
src/shared/asha.c +72 -0
@@ -40,6 +40,7 @@#define ASHA_CHRC_LE_PSM_OUT_UUID "2d410339-82b6-42aa-b34e-e2e01df8cc1a"static struct queue *asha_devices; +static struct queue *asha_attached;static unsigned int bt_asha_status (struct bt_asha *asha,bool connected);
@@ -58,6 +59,34 @@ static bool match_set_member(const void *data, const void *user_data)return set->left == user_data || set->right == user_data; } +static bool match_attached_side (const void *data,const void *user_data) +{ +const struct bt_asha *other = data; +const struct bt_asha *asha = user_data; + +return other->right_side == asha->right_side && + !memcmp (other->hisyncid, asha->hisyncid,8 ); +} + +static bool match_attached_peer (const void *data,const void *user_data) +{ +const struct bt_asha *other = data; +const struct bt_asha *asha = user_data; + +return other->right_side != asha->right_side && + !memcmp (other->hisyncid, asha->hisyncid,8 ); +} + +static void remove_attached (struct bt_asha *asha) +{ +queue_remove (asha_attached, asha); + +if (queue_isempty (asha_attached)) { +queue_destroy (asha_attached,NULL ); + asha_attached =NULL ; + } +} +static struct bt_asha_set *find_asha_set (struct bt_asha *asha) {return queue_find (asha_devices, match_hisyncid, asha);
@@ -179,6 +208,8 @@ struct bt_asha *bt_asha_new(void)void bt_asha_reset (struct bt_asha *asha) { +remove_attached (asha); +if (asha->status_notify_id) {bt_gatt_client_unregister_notify (asha->client, asha->status_notify_id);
@@ -211,6 +242,7 @@ void bt_asha_state_reset(struct bt_asha *asha)void bt_asha_free (struct bt_asha *asha) { +remove_attached (asha);update_asha_set (asha, false);gatt_db_unref (asha->db);bt_gatt_client_unref (asha->client);
@@ -260,6 +292,39 @@ static int asha_send_acp_without_response(struct bt_asha *asha,return 0 ; } +bool bt_asha_set_connection_interval (struct bt_asha *asha,uint16_t interval) +{ +struct bt_asha *other; +uint8_t cmd[] = { +0x03 ,/* STATUS */ +0x02 ,/* LE connection parameter update */ +0x00 ,/* Interval, in 1.25 ms units */ + }; +bool success; + +/* +* Android's ASHA document lists only the update type for this STATUS, +* but its hearing aid stack appends the new interval as one more +* byte and sends it to both sides. Reject a value that does not fit +* in that byte instead of truncating it. +*/ +if (!asha || !asha->client || !asha->acp_handle || + interval <0x0006 || interval >UINT8_MAX ) +return false; + + cmd[2 ] = interval; + success =asha_send_acp_without_response (asha, cmd,sizeof (cmd)) ==0 ; + other =queue_find (asha_attached, match_attached_peer, asha); + +/* Notify an attached peer even if it has not started streaming yet. */ +if (other && other != asha && other->client && other->acp_handle) { +if (asha_send_acp_without_response (other, cmd,sizeof (cmd)) <0 ) + success = false; + } + +return success; +} +unsigned int bt_asha_start (struct bt_asha *asha,bt_asha_cb_t cb,void *user_data) {
@@ -370,6 +435,13 @@ static void check_probe_done(struct bt_asha *asha) sizeof(zeroes)) == 0)return ; +if (!asha_attached) + asha_attached =queue_new (); + +/* Keep attachment separate from the set of previously started aids. */ +queue_remove_if (asha_attached, match_attached_side, asha); +queue_push_tail (asha_attached, asha); +if (asha->attach_cb) { asha->attach_cb (asha->attach_cb_data); asha->attach_cb =NULL ;
src/shared/asha.h +1 -0
@@ -66,6 +66,7 @@ unsigned int bt_asha_start(struct bt_asha *asha, bt_asha_cb_t cb,unsigned int bt_asha_stop (struct bt_asha *asha);bool bt_asha_set_volume (struct bt_asha *asha,int8_t volume); +bool bt_asha_set_connection_interval (struct bt_asha *asha,uint16_t interval); bool bt_asha_attach(struct bt_asha *asha, struct gatt_db *db, struct bt_gatt_client *client, bt_asha_attach_cb_t probe_cb,
Signature · 1 line
2.56.1
RFC PATCH v5 3/4 asha: Notify observed connection intervals
In reply to Kyle PepperCache successful connection intervals per adapter and match each update to the ATT connection handle. Announce the cached value before START and notify attached devices when an initial or updated interval arrives. The cached value is the last one observed; a requested update may still be pending and is announced when it completes. Clear disconnected handles so reused links cannot inherit stale values.
The observer only sees events after the adapter is probed, so a link that was already connected when bluetoothd started has no cached interval until its next update, and nothing is sent for it.
--- profiles/audio/asha.c | 231 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+)
profiles/audio/asha.c +231 -0
@@ -39,6 +39,11 @@#include "src/profile.h" #include "src/service.h" #include "src/shared/util.h" +#include "src/shared/queue.h" +#include "src/shared/hci.h" +#include "src/shared/att.h" +#include "src/shared/gatt-client.h" +#include "monitor/bt.h" #include "profiles/audio/asha.h" #include "profiles/audio/media.h"
@@ -51,6 +56,18 @@/* The default of 672 does not work */ #define ASHA_CONNECTION_MTU 512 +/* HCI handles include zero; a zero cached interval means unknown. */ +#define ASHA_NUM_HANDLES 0x0f00 + +struct asha_adapter { +struct btd_adapter *adapter; +struct bt_hci *hci; +uint16_t intervals[ASHA_NUM_HANDLES ]; +}; + +static struct queue *asha_adapters; +static struct queue *asha_streams; +struct bt_asha_device {struct bt_asha *asha;struct btd_device *device;
@@ -62,6 +79,203 @@ struct bt_asha_device {unsigned int resume_id; }; +static bool match_adapter (const void *data,const void *user_data) +{ +const struct asha_adapter *data_adapter = data; + +return data_adapter->adapter == user_data; +} + +static bool asha_get_handle (struct bt_asha_device *asha_dev,uint16_t *handle) +{ +struct bt_att *att; +struct l2cap_conninfo info; +socklen_t len =sizeof (info); +int fd; + +if (!asha_dev->asha->client) +return false; + + att =bt_gatt_client_get_att (asha_dev->asha->client); + fd =bt_att_get_fd (att); + +/* The ATT socket identifies this link even when CoC is not open. */ +if (fd <0 ||getsockopt (fd,SOL_L2CAP ,L2CAP_CONNINFO , + &info, &len) <0 ) { +DBG ("Could not read ASHA connection handle" ); +return false; + } + +if (len !=sizeof (info) || info.hci_handle >=ASHA_NUM_HANDLES ) +return false; + + *handle = info.hci_handle; +return true; +} + +static void asha_notify_interval (struct bt_asha_device *asha_dev, +uint16_t handle,uint16_t interval) +{ +/* Only announce an interval observed on this connection. */ +if (!interval) +return ; + +DBG ("ASHA connection h%u interval %u" , handle, interval); + +if (!bt_asha_set_connection_interval (asha_dev->asha, interval)) +DBG ("Could not send ASHA connection interval notification" ); +} + +static void asha_send_interval (struct bt_asha_device *asha_dev) +{ +struct asha_adapter *data; +uint16_t handle; + + data =queue_find (asha_adapters, match_adapter, +device_get_adapter (asha_dev->device)); +if (!data || !asha_get_handle (asha_dev, &handle)) +return ; + +asha_notify_interval (asha_dev, handle, data->intervals[handle]); +} + +struct interval_update { +struct asha_adapter *adapter; +uint16_t handle; +}; + +static void asha_update_stream (void *data,void *user_data) +{ +struct bt_asha_device *asha_dev = data; +struct interval_update *update = user_data; +uint16_t handle; + +if (device_get_adapter (asha_dev->device) != update->adapter->adapter || + !asha_get_handle (asha_dev, &handle) || + handle != update->handle) +return ; + +asha_notify_interval (asha_dev, handle, + update->adapter->intervals[handle]); +} + +static void asha_update_interval (struct asha_adapter *data,uint16_t handle, +uint16_t interval) +{ +struct interval_update update = { .adapter = data, .handle = handle }; + +if (handle >=ASHA_NUM_HANDLES ) +return ; + + data->intervals[handle] = interval; +queue_foreach (asha_streams, asha_update_stream, &update); +} + +static void asha_conn_update (const void *param,uint8_t size,void *user_data) +{ +const struct bt_hci_evt_le_conn_update_complete *ev = param; + +if (size !=sizeof (*ev) || ev->status) +return ; + +asha_update_interval (user_data,get_le16 (&ev->handle), +get_le16 (&ev->interval)); +} + +static void asha_conn_complete (const void *param,uint8_t size,void *user_data) +{ +const struct bt_hci_evt_le_conn_complete *ev = param; + +if (size !=sizeof (*ev) || ev->status) +return ; + +asha_update_interval (user_data,get_le16 (&ev->handle), +get_le16 (&ev->interval)); +} + +static void asha_enhanced_conn_complete (const void *param,uint8_t size, +void *user_data) +{ +const struct bt_hci_evt_le_enhanced_conn_complete *ev = param; + +if (size !=sizeof (*ev) || ev->status) +return ; + +asha_update_interval (user_data,get_le16 (&ev->handle), +get_le16 (&ev->interval)); +} + +static void asha_disconn_complete (const void *param,uint8_t size, +void *user_data) +{ +const struct bt_hci_evt_disconnect_complete *ev = param; +struct asha_adapter *data = user_data; +uint16_t handle; + +if (size !=sizeof (*ev) || ev->status) +return ; + + handle =get_le16 (&ev->handle); + +if (handle <ASHA_NUM_HANDLES ) + data->intervals[handle] =0 ; +} + +static int asha_adapter_probe (struct btd_profile *profile, +struct btd_adapter *adapter) +{ +struct asha_adapter *data; + + data = new0(struct asha_adapter, 1); + data->adapter = adapter; + data->hci =bt_hci_new_raw_device (btd_adapter_get_index (adapter)); + +if (!data->hci) + goto fail; + +if (!bt_hci_register_subevent (data->hci,BT_HCI_EVT_LE_CONN_COMPLETE , + asha_conn_complete, data,NULL ) || + !bt_hci_register_subevent (data->hci, +BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE , + asha_enhanced_conn_complete, data,NULL ) || + !bt_hci_register_subevent (data->hci, +BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE , + asha_conn_update, data,NULL ) || + !bt_hci_register (data->hci,BT_HCI_EVT_DISCONNECT_COMPLETE , + asha_disconn_complete, data,NULL )) + goto fail; + +if (!asha_adapters) + asha_adapters =queue_new (); + +queue_push_tail (asha_adapters, data); +return 0 ; + +fail: +bt_hci_unref (data->hci); +free (data); +return -EIO ; +} + +static void asha_adapter_remove (struct btd_profile *profile, +struct btd_adapter *adapter) +{ +struct asha_adapter *data; + + data =queue_remove_if (asha_adapters, match_adapter, adapter); + +if (!data) +return ; + +bt_hci_unref (data->hci); +free (data); + +if (queue_isempty (asha_adapters)) { +queue_destroy (asha_adapters,NULL ); + asha_adapters =NULL ; + } +} +static char *make_endpoint_path (struct bt_asha_device *asha_dev) {char *path;
@@ -118,6 +332,8 @@ static void connect_cb(GIOChannel *io, GError *err, gpointer user_data) asha_dev->io = io; +asha_send_interval (asha_dev); +bt_asha_start (asha_dev->asha, conn_data->cb, conn_data->cb_user_data); }
@@ -361,6 +577,11 @@ static int asha_source_device_probe(struct btd_service *service) asha_dev->asha =bt_asha_new (); asha_dev->io =NULL ; +if (!asha_streams) + asha_streams =queue_new (); + +queue_push_tail (asha_streams, asha_dev); +btd_service_set_user_data (service, asha_dev);return 0 ;
@@ -382,6 +603,13 @@ static void asha_source_device_remove(struct btd_service *service)return ; } +queue_remove (asha_streams, asha_dev); + +if (queue_isempty (asha_streams)) { +queue_destroy (asha_streams,NULL ); + asha_streams =NULL ; + } +bt_asha_free (asha_dev->asha);g_free (asha_dev); }
@@ -514,6 +742,9 @@ static struct btd_profile asha_source_profile = { .remote_uuid = ASHA_PROFILE_UUID, .experimental = true, + .adapter_probe = asha_adapter_probe, + .adapter_remove = asha_adapter_remove, + .device_probe = asha_source_device_probe, .device_remove = asha_source_device_remove,
Signature · 1 line
2.56.1
RFC PATCH v5 4/4 unit: Test ASHA connection interval notifications
In reply to Kyle PepperCover STATUS encoding, independent writes, set lifetime and observed connection intervals. Exercise attachment before either aid starts, both property-read orders, stopped peers, reset/free and replacement. Keep START other-connected state tied to the existing streaming set.
--- .gitignore | 2 + Makefile.am | 17 ++ unit/test-asha-conn.c | 578 ++++++++++++++++++++++++++++++++++++++ unit/test-asha-conn.h | 11 + unit/test-asha-interval.c | 355 +++++++++++++++++++++++ 5 files changed, 963 insertions(+) create mode 100644 unit/test-asha-conn.c create mode 100644 unit/test-asha-conn.h create mode 100644 unit/test-asha-interval.c
.gitignore +2 -0
@@ -99,6 +99,8 @@ unit/test-tester unit/test-mainloop unit/test-ringbuf unit/test-queue +unit/test-asha-conn +unit/test-asha-interval unit/test-util unit/test-eir unit/test-uuid
Makefile.am +17 -0
@@ -712,6 +712,23 @@ unit_tests += unit/test-hfp unit_test_hfp_SOURCES = unit/test-hfp.c unit_test_hfp_LDADD = src/libshared-glib.la $(GLIB_LIBS) +unit_tests += unit/test-asha-interval + +unit_test_asha_interval_SOURCES = unit/test-asha-interval.c +unit_test_asha_interval_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) + +unit_tests += unit/test-asha-conn + +unit_test_asha_conn_SOURCES = unit/test-asha-conn.c unit/test-asha-conn.h +unit_test_asha_conn_CFLAGS = $(AM_CFLAGS) -DBLUETOOTH_PLUGIN_BUILTIN \ + -ffunction-sections -fdata-sections +unit_test_asha_conn_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) $(DBUS_LIBS) +unit_test_asha_conn_LDFLAGS = -Wl,--gc-sections \ + -Wl,--wrap=socket -Wl,--wrap=bind -Wl,--wrap=setsockopt \ + -Wl,--wrap=getsockopt + unit_tests += unit/test-gdbus-client unit_test_gdbus_client_SOURCES = unit/test-gdbus-client.c
unit/test-asha-conn.c new file +578 -0
578 lines not on this page · raw message
unit/test-asha-conn.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include <sys/socket.h> + +int __wrap_socket (int domain,int type,int protocol); +int __wrap_bind (int fd,const struct sockaddr *addr,socklen_t length); +int __wrap_setsockopt (int fd,int level,int opt,const void *value, +socklen_t length); +int __wrap_getsockopt (int fd,int level,int opt,void *value, +socklen_t *length); +int __real_setsockopt (int fd,int level,int opt,const void *value, +socklen_t length);
unit/test-asha-interval.c new file +355 -0
355 lines not on this page · raw message
Signature · 1 line
2.56.1
v6 cover asha: Notify connection interval changes
In reply to Kyle PepperReport observed connection intervals to attached hearing aids.
Apply patches 1-4 in order: set lifetime fix, shared STATUS helper, profile observer, then tests. No out-of-tree dependency is required.
Changes since v5, addressing Copilot's review highlighted by Luiz:
- Recreate the set queue when an attached aid completes START after the only registered aid resets or is freed. Fold the fix into patch 1.
- Define _GNU_SOURCE before system headers in the observer test so older glibc headers declare asprintf. Fold the fix into patch 4.
- Cover successful START after reset/free of the only registered peer, in both directions, followed by reattachment and peer-state checks.
- Rebase onto BlueZ 79162c1089110c896cb48118c3f7eb0db1fa0f2b.
The set bug affects START's other-connected state. Interval STATUS uses the separate attached-aid queue. The header failure is reproducible with glibc 2.35's stdio.h; the unchanged test builds on this host's glibc 2.44.
The v5 bot run passed all 12 jobs, including TestFunctional. No v6 remote CI, native functional VM or hearing-aid validation is claimed.
The observer still reports only its last successful observation. Lost or preexisting events remain unknown until a supported event arrives; LE Enhanced Connection Complete v2 is not registered. Controller power-cycle cache behavior and the profile ownership of the raw observer remain open.
Previous v5 cover (this series replies to it):
https://lore.kernel.org/linux-bluetooth/[email protected]/
Review and CI:
https://github.com/bluez/bluez/pull/2911#pullrequestreview-6046633570
AI assistance: prior OpenCode work is retained; Codex prepared and tested the v6 fixes, regression cases and revision. Copilot identified both bugs.
Kyle Pepper (4):
shared/asha: Unregister set members by object
asha: Add connection interval STATUS helper
asha: Notify observed connection intervals
unit: Test ASHA connection interval notifications
.gitignore | 2 + Makefile.am | 17 ++ profiles/audio/asha.c | 231 +++++++++++++++ src/shared/asha.c | 101 ++++++- src/shared/asha.h | 1 + unit/test-asha-conn.c | 579 ++++++++++++++++++++++++++++++++++++++ unit/test-asha-conn.h | 11 + unit/test-asha-interval.c | 417 +++++++++++++++++++++++++++ 8 files changed, 1354 insertions(+), 5 deletions(-) create mode 100644 unit/test-asha-conn.c create mode 100644 unit/test-asha-conn.h create mode 100644 unit/test-asha-interval.c
base-commit: 79162c1089110c896cb48118c3f7eb0db1fa0f2b
Signature · 1 line
2.56.1
RFC PATCH v6 1/4 shared/asha: Unregister set members by object
bt_asha_reset() clears the HiSyncId before calling update_asha_set(), whose removal path finds the set by HiSyncId. The lookup then fails and the set keeps pointing at the reset object. bt_asha_free() cannot unregister it either, since the HiSyncId is still clear, so once the object is freed the other side of the pair follows a dangling pointer, for example in asha_set_send_status() when it is stopped.
Find the set that holds the object by pointer and clear only the slot it owns. A reset or freed object that never joined a set, or was already removed, is now a quiet no-op instead of a "Missing ASHA set" error. An object that was replaced by a newer one for the same side also no longer removes its successor when it is released.
Recreate the set queue when an attached aid starts after the last registered aid leaves, so registration does not lose the new set.
--- src/shared/asha.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-)
src/shared/asha.c +24 -5
@@ -51,6 +51,13 @@ static bool match_hisyncid(const void *data, const void *user_data)return (memcmp (set->hisyncid, asha->hisyncid,8 ) ==0 ); } +static bool match_set_member (const void *data,const void *user_data) +{ +const struct bt_asha_set *set = data; + +return set->left == user_data || set->right == user_data; +} +static struct bt_asha_set *find_asha_set (struct bt_asha *asha) {return queue_find (asha_devices, match_hisyncid, asha);
@@ -83,9 +90,12 @@ static void update_asha_set(struct bt_asha *asha, bool connected) {struct bt_asha_set *set; - set =queue_find (asha_devices, match_hisyncid, asha); -if (connected) { +if (!asha_devices) + asha_devices =queue_new (); + + set =queue_find (asha_devices, match_hisyncid, asha); +if (!set) { set = new0(struct bt_asha_set, 1);memcpy (set->hisyncid, asha->hisyncid,8 );
@@ -101,15 +111,24 @@ static void update_asha_set(struct bt_asha *asha, bool connected)DBG ("Left side registered for ASHA set" ); } }else { +/* +* Find the set by object: the HiSyncId is cleared on reset and +* a replacement for the same side shares it, so it cannot say +* which slot, if any, still belongs to this object. +*/ + set =queue_find (asha_devices, match_set_member, asha); +if (!set) { -error ("Missing ASHA set" ); +DBG ("ASHA object not registered in a set" );return ; } -if (asha->right_side && set->right) { +if (set->right == asha) { set->right =NULL ;DBG ("Right side unregistered for ASHA set" ); - }else if (!asha->right_side && set->left) { + } + +if (set->left == asha) { set->left =NULL ;DBG ("Left side unregistered for ASHA set" ); }
Signature · 1 line
2.56.1
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1222688/
---Test result---
Test Summary:
CheckPatch PASS 2.32 seconds GitLint PASS 0.82 seconds BuildEll PASS 21.12 seconds BluezMake PASS 314.14 seconds MakeCheck PASS 14.75 seconds MakeDistcheck PASS 147.66 seconds CheckValgrind PASS 351.06 seconds CheckSmatch PASS 318.43 seconds bluezmakeextell PASS 101.07 seconds TestFunctional PASS 1253.58 seconds IncrementalBuild PASS 350.47 seconds ScanBuild PASS 1212.25 seconds
https://github.com/bluez/bluez/pull/2929
---
Regards,
Linux Bluetooth
RFC PATCH v6 2/4 asha: Add connection interval STATUS helper
In reply to Kyle PepperSend the observed interval to both attached hearing aids, including a peer that has not started streaming. Match the encoding used by Android's hearing aid stack and reject intervals that do not fit in its byte field.
Track attachment after ROP and PSM discovery separately from the set of previously started aids. Remove that membership on reset or free and keep a replacement when an older object for the same side is released.
--- src/shared/asha.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/asha.h | 1 + 2 files changed, 73 insertions(+)
src/shared/asha.c +72 -0
@@ -40,6 +40,7 @@#define ASHA_CHRC_LE_PSM_OUT_UUID "2d410339-82b6-42aa-b34e-e2e01df8cc1a"static struct queue *asha_devices; +static struct queue *asha_attached;static unsigned int bt_asha_status (struct bt_asha *asha,bool connected);
@@ -58,6 +59,34 @@ static bool match_set_member(const void *data, const void *user_data)return set->left == user_data || set->right == user_data; } +static bool match_attached_side (const void *data,const void *user_data) +{ +const struct bt_asha *other = data; +const struct bt_asha *asha = user_data; + +return other->right_side == asha->right_side && + !memcmp (other->hisyncid, asha->hisyncid,8 ); +} + +static bool match_attached_peer (const void *data,const void *user_data) +{ +const struct bt_asha *other = data; +const struct bt_asha *asha = user_data; + +return other->right_side != asha->right_side && + !memcmp (other->hisyncid, asha->hisyncid,8 ); +} + +static void remove_attached (struct bt_asha *asha) +{ +queue_remove (asha_attached, asha); + +if (queue_isempty (asha_attached)) { +queue_destroy (asha_attached,NULL ); + asha_attached =NULL ; + } +} +static struct bt_asha_set *find_asha_set (struct bt_asha *asha) {return queue_find (asha_devices, match_hisyncid, asha);
@@ -182,6 +211,8 @@ struct bt_asha *bt_asha_new(void)void bt_asha_reset (struct bt_asha *asha) { +remove_attached (asha); +if (asha->status_notify_id) {bt_gatt_client_unregister_notify (asha->client, asha->status_notify_id);
@@ -214,6 +245,7 @@ void bt_asha_state_reset(struct bt_asha *asha)void bt_asha_free (struct bt_asha *asha) { +remove_attached (asha);update_asha_set (asha, false);gatt_db_unref (asha->db);bt_gatt_client_unref (asha->client);
@@ -263,6 +295,39 @@ static int asha_send_acp_without_response(struct bt_asha *asha,return 0 ; } +bool bt_asha_set_connection_interval (struct bt_asha *asha,uint16_t interval) +{ +struct bt_asha *other; +uint8_t cmd[] = { +0x03 ,/* STATUS */ +0x02 ,/* LE connection parameter update */ +0x00 ,/* Interval, in 1.25 ms units */ + }; +bool success; + +/* +* Android's ASHA document lists only the update type for this STATUS, +* but its hearing aid stack appends the new interval as one more +* byte and sends it to both sides. Reject a value that does not fit +* in that byte instead of truncating it. +*/ +if (!asha || !asha->client || !asha->acp_handle || + interval <0x0006 || interval >UINT8_MAX ) +return false; + + cmd[2 ] = interval; + success =asha_send_acp_without_response (asha, cmd,sizeof (cmd)) ==0 ; + other =queue_find (asha_attached, match_attached_peer, asha); + +/* Notify an attached peer even if it has not started streaming yet. */ +if (other && other != asha && other->client && other->acp_handle) { +if (asha_send_acp_without_response (other, cmd,sizeof (cmd)) <0 ) + success = false; + } + +return success; +} +unsigned int bt_asha_start (struct bt_asha *asha,bt_asha_cb_t cb,void *user_data) {
@@ -373,6 +438,13 @@ static void check_probe_done(struct bt_asha *asha) sizeof(zeroes)) == 0)return ; +if (!asha_attached) + asha_attached =queue_new (); + +/* Keep attachment separate from the set of previously started aids. */ +queue_remove_if (asha_attached, match_attached_side, asha); +queue_push_tail (asha_attached, asha); +if (asha->attach_cb) { asha->attach_cb (asha->attach_cb_data); asha->attach_cb =NULL ;
src/shared/asha.h +1 -0
@@ -66,6 +66,7 @@ unsigned int bt_asha_start(struct bt_asha *asha, bt_asha_cb_t cb,unsigned int bt_asha_stop (struct bt_asha *asha);bool bt_asha_set_volume (struct bt_asha *asha,int8_t volume); +bool bt_asha_set_connection_interval (struct bt_asha *asha,uint16_t interval); bool bt_asha_attach(struct bt_asha *asha, struct gatt_db *db, struct bt_gatt_client *client, bt_asha_attach_cb_t probe_cb,
Signature · 1 line
2.56.1
RFC PATCH v6 3/4 asha: Notify observed connection intervals
In reply to Kyle PepperCache successful connection intervals per adapter and match each update to the ATT connection handle. Announce the cached value before START and notify attached devices when an initial or updated interval arrives. The cached value is the last one observed; a requested update may still be pending and is announced when it completes. Clear disconnected handles so reused links cannot inherit stale values.
The observer only sees events after the adapter is probed, so a link that was already connected when bluetoothd started has no cached interval until its next update, and nothing is sent for it.
--- profiles/audio/asha.c | 231 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+)
profiles/audio/asha.c +231 -0
@@ -39,6 +39,11 @@#include "src/profile.h" #include "src/service.h" #include "src/shared/util.h" +#include "src/shared/queue.h" +#include "src/shared/hci.h" +#include "src/shared/att.h" +#include "src/shared/gatt-client.h" +#include "monitor/bt.h" #include "profiles/audio/asha.h" #include "profiles/audio/media.h"
@@ -51,6 +56,18 @@/* The default of 672 does not work */ #define ASHA_CONNECTION_MTU 512 +/* HCI handles include zero; a zero cached interval means unknown. */ +#define ASHA_NUM_HANDLES 0x0f00 + +struct asha_adapter { +struct btd_adapter *adapter; +struct bt_hci *hci; +uint16_t intervals[ASHA_NUM_HANDLES ]; +}; + +static struct queue *asha_adapters; +static struct queue *asha_streams; +struct bt_asha_device {struct bt_asha *asha;struct btd_device *device;
@@ -62,6 +79,203 @@ struct bt_asha_device {unsigned int resume_id; }; +static bool match_adapter (const void *data,const void *user_data) +{ +const struct asha_adapter *data_adapter = data; + +return data_adapter->adapter == user_data; +} + +static bool asha_get_handle (struct bt_asha_device *asha_dev,uint16_t *handle) +{ +struct bt_att *att; +struct l2cap_conninfo info; +socklen_t len =sizeof (info); +int fd; + +if (!asha_dev->asha->client) +return false; + + att =bt_gatt_client_get_att (asha_dev->asha->client); + fd =bt_att_get_fd (att); + +/* The ATT socket identifies this link even when CoC is not open. */ +if (fd <0 ||getsockopt (fd,SOL_L2CAP ,L2CAP_CONNINFO , + &info, &len) <0 ) { +DBG ("Could not read ASHA connection handle" ); +return false; + } + +if (len !=sizeof (info) || info.hci_handle >=ASHA_NUM_HANDLES ) +return false; + + *handle = info.hci_handle; +return true; +} + +static void asha_notify_interval (struct bt_asha_device *asha_dev, +uint16_t handle,uint16_t interval) +{ +/* Only announce an interval observed on this connection. */ +if (!interval) +return ; + +DBG ("ASHA connection h%u interval %u" , handle, interval); + +if (!bt_asha_set_connection_interval (asha_dev->asha, interval)) +DBG ("Could not send ASHA connection interval notification" ); +} + +static void asha_send_interval (struct bt_asha_device *asha_dev) +{ +struct asha_adapter *data; +uint16_t handle; + + data =queue_find (asha_adapters, match_adapter, +device_get_adapter (asha_dev->device)); +if (!data || !asha_get_handle (asha_dev, &handle)) +return ; + +asha_notify_interval (asha_dev, handle, data->intervals[handle]); +} + +struct interval_update { +struct asha_adapter *adapter; +uint16_t handle; +}; + +static void asha_update_stream (void *data,void *user_data) +{ +struct bt_asha_device *asha_dev = data; +struct interval_update *update = user_data; +uint16_t handle; + +if (device_get_adapter (asha_dev->device) != update->adapter->adapter || + !asha_get_handle (asha_dev, &handle) || + handle != update->handle) +return ; + +asha_notify_interval (asha_dev, handle, + update->adapter->intervals[handle]); +} + +static void asha_update_interval (struct asha_adapter *data,uint16_t handle, +uint16_t interval) +{ +struct interval_update update = { .adapter = data, .handle = handle }; + +if (handle >=ASHA_NUM_HANDLES ) +return ; + + data->intervals[handle] = interval; +queue_foreach (asha_streams, asha_update_stream, &update); +} + +static void asha_conn_update (const void *param,uint8_t size,void *user_data) +{ +const struct bt_hci_evt_le_conn_update_complete *ev = param; + +if (size !=sizeof (*ev) || ev->status) +return ; + +asha_update_interval (user_data,get_le16 (&ev->handle), +get_le16 (&ev->interval)); +} + +static void asha_conn_complete (const void *param,uint8_t size,void *user_data) +{ +const struct bt_hci_evt_le_conn_complete *ev = param; + +if (size !=sizeof (*ev) || ev->status) +return ; + +asha_update_interval (user_data,get_le16 (&ev->handle), +get_le16 (&ev->interval)); +} + +static void asha_enhanced_conn_complete (const void *param,uint8_t size, +void *user_data) +{ +const struct bt_hci_evt_le_enhanced_conn_complete *ev = param; + +if (size !=sizeof (*ev) || ev->status) +return ; + +asha_update_interval (user_data,get_le16 (&ev->handle), +get_le16 (&ev->interval)); +} + +static void asha_disconn_complete (const void *param,uint8_t size, +void *user_data) +{ +const struct bt_hci_evt_disconnect_complete *ev = param; +struct asha_adapter *data = user_data; +uint16_t handle; + +if (size !=sizeof (*ev) || ev->status) +return ; + + handle =get_le16 (&ev->handle); + +if (handle <ASHA_NUM_HANDLES ) + data->intervals[handle] =0 ; +} + +static int asha_adapter_probe (struct btd_profile *profile, +struct btd_adapter *adapter) +{ +struct asha_adapter *data; + + data = new0(struct asha_adapter, 1); + data->adapter = adapter; + data->hci =bt_hci_new_raw_device (btd_adapter_get_index (adapter)); + +if (!data->hci) + goto fail; + +if (!bt_hci_register_subevent (data->hci,BT_HCI_EVT_LE_CONN_COMPLETE , + asha_conn_complete, data,NULL ) || + !bt_hci_register_subevent (data->hci, +BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE , + asha_enhanced_conn_complete, data,NULL ) || + !bt_hci_register_subevent (data->hci, +BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE , + asha_conn_update, data,NULL ) || + !bt_hci_register (data->hci,BT_HCI_EVT_DISCONNECT_COMPLETE , + asha_disconn_complete, data,NULL )) + goto fail; + +if (!asha_adapters) + asha_adapters =queue_new (); + +queue_push_tail (asha_adapters, data); +return 0 ; + +fail: +bt_hci_unref (data->hci); +free (data); +return -EIO ; +} + +static void asha_adapter_remove (struct btd_profile *profile, +struct btd_adapter *adapter) +{ +struct asha_adapter *data; + + data =queue_remove_if (asha_adapters, match_adapter, adapter); + +if (!data) +return ; + +bt_hci_unref (data->hci); +free (data); + +if (queue_isempty (asha_adapters)) { +queue_destroy (asha_adapters,NULL ); + asha_adapters =NULL ; + } +} +static char *make_endpoint_path (struct bt_asha_device *asha_dev) {char *path;
@@ -118,6 +332,8 @@ static void connect_cb(GIOChannel *io, GError *err, gpointer user_data) asha_dev->io = io; +asha_send_interval (asha_dev); +bt_asha_start (asha_dev->asha, conn_data->cb, conn_data->cb_user_data); }
@@ -361,6 +577,11 @@ static int asha_source_device_probe(struct btd_service *service) asha_dev->asha =bt_asha_new (); asha_dev->io =NULL ; +if (!asha_streams) + asha_streams =queue_new (); + +queue_push_tail (asha_streams, asha_dev); +btd_service_set_user_data (service, asha_dev);return 0 ;
@@ -382,6 +603,13 @@ static void asha_source_device_remove(struct btd_service *service)return ; } +queue_remove (asha_streams, asha_dev); + +if (queue_isempty (asha_streams)) { +queue_destroy (asha_streams,NULL ); + asha_streams =NULL ; + } +bt_asha_free (asha_dev->asha);g_free (asha_dev); }
@@ -514,6 +742,9 @@ static struct btd_profile asha_source_profile = { .remote_uuid = ASHA_PROFILE_UUID, .experimental = true, + .adapter_probe = asha_adapter_probe, + .adapter_remove = asha_adapter_remove, + .device_probe = asha_source_device_probe, .device_remove = asha_source_device_remove,
Signature · 1 line
2.56.1
RFC PATCH v6 4/4 unit: Test ASHA connection interval notifications
In reply to Kyle PepperCover STATUS encoding, independent writes, set lifetime and observed connection intervals. Exercise attachment before either aid starts, both property-read orders, stopped peers, reset/free and replacement. Keep START other-connected state tied to the existing streaming set.
Complete START after the only registered peer resets or is freed, in both directions, and verify registration and subsequent peer discovery. Define _GNU_SOURCE before headers so older glibc declares asprintf.
--- .gitignore | 2 + Makefile.am | 17 ++ unit/test-asha-conn.c | 579 ++++++++++++++++++++++++++++++++++++++ unit/test-asha-conn.h | 11 + unit/test-asha-interval.c | 417 +++++++++++++++++++++++++++ 5 files changed, 1026 insertions(+) create mode 100644 unit/test-asha-conn.c create mode 100644 unit/test-asha-conn.h create mode 100644 unit/test-asha-interval.c
.gitignore +2 -0
@@ -99,6 +99,8 @@ unit/test-tester unit/test-mainloop unit/test-ringbuf unit/test-queue +unit/test-asha-conn +unit/test-asha-interval unit/test-util unit/test-eir unit/test-uuid
Makefile.am +17 -0
@@ -712,6 +712,23 @@ unit_tests += unit/test-hfp unit_test_hfp_SOURCES = unit/test-hfp.c unit_test_hfp_LDADD = src/libshared-glib.la $(GLIB_LIBS) +unit_tests += unit/test-asha-interval + +unit_test_asha_interval_SOURCES = unit/test-asha-interval.c +unit_test_asha_interval_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) + +unit_tests += unit/test-asha-conn + +unit_test_asha_conn_SOURCES = unit/test-asha-conn.c unit/test-asha-conn.h +unit_test_asha_conn_CFLAGS = $(AM_CFLAGS) -DBLUETOOTH_PLUGIN_BUILTIN \ + -ffunction-sections -fdata-sections +unit_test_asha_conn_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) $(DBUS_LIBS) +unit_test_asha_conn_LDFLAGS = -Wl,--gc-sections \ + -Wl,--wrap=socket -Wl,--wrap=bind -Wl,--wrap=setsockopt \ + -Wl,--wrap=getsockopt + unit_tests += unit/test-gdbus-client unit_test_gdbus_client_SOURCES = unit/test-gdbus-client.c
unit/test-asha-conn.c new file +579 -0
579 lines not on this page · raw message
unit/test-asha-conn.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include <sys/socket.h> + +int __wrap_socket (int domain,int type,int protocol); +int __wrap_bind (int fd,const struct sockaddr *addr,socklen_t length); +int __wrap_setsockopt (int fd,int level,int opt,const void *value, +socklen_t length); +int __wrap_getsockopt (int fd,int level,int opt,void *value, +socklen_t *length); +int __real_setsockopt (int fd,int level,int opt,const void *value, +socklen_t length);
unit/test-asha-interval.c new file +417 -0
417 lines not on this page · raw message
Signature · 1 line
2.56.1