From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.70.43.100 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796227504; b=o/kAS3PdkgVY7Ut9h5cpcEAIu/8kPbkCgvOAlF1jh+y+O5MISl8EQWy1ZlvUbQqZlv67 ouiErBLzQOcDyBzpqxjD9zg1af5uZkmigYP3R9d75u3iSfTot5WOmRRShdMIbMPFv8DRc fusXccTedr24bBieroe/1SGqj6/RngTB1G9cgGUyaznCn7MvcvgfX0Vl5UHYXxmrglwYU bLwF2U0P95iX89fKpzYdfPCVrRhkKhLhcjdLupTazbS1QBSU1TGhpWmWzkCfKS9jTma2x bSnc96AuUFL4woB98e/4UmDj29XlKAmSddghmI0S4rnRHe1eSC+r49tnCP+V+cQH9FQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796227504; h=DMARC-Filter:DKIM-Signature:Date:To:From:Cc:Subject:Message-ID: Feedback-ID:X-Pm-Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=E/7HSgccG7taUEl/PbVd7R8YeyLXIiLy3zMsDSqLx5E=; b=Pg1Hb76LOAEGErpe7GxXl9VB6dUUSbgk9hJ7DpfDu15TXCU6bI0THxMK8lG/tZGyHamF DXnol+IbDizKozof+gOZxSgYinpcnupuKeJuol5voGQgXSjfNebwHdFICPEsUWjU4nhNn HD5IvHLrZf1ksr9M9Ys7SEUkqxVyvxwEve/pSf/dtTo8K4hg+nUzOjOhRnEXA9JO2m1kP 71N+A1fAI6bVp14U+6i6ndj6i7LCDAWl64GoZuvjLyKH+AXarKWzQjnGyt2pHBMTpVTQ+ ta21WyNO208s+jczNPZrO2OQzS8tX0b18O/rc9rZuHo298/RZRcttN6272zCYfxYHhw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=nec3ijwehrhw5pkuop24n6fngu.protonmail2 header.b=wOp9pj3C; arc=none smtp.remote-ip=185.70.43.100 Received: from mail-43100.protonmail.ch (mail-43100.protonmail.ch [185.70.43.100]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9692606A31A for ; Wed, 2 Dec 2026 16:05:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B9692606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=nec3ijwehrhw5pkuop24n6fngu.protonmail2 header.b=wOp9pj3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=nec3ijwehrhw5pkuop24n6fngu.protonmail2; t=1796227498; x=1796486698; bh=E/7HSgccG7taUEl/PbVd7R8YeyLXIiLy3zMsDSqLx5E=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=wOp9pj3CNs4oPckzDiyvK7cYlAv3MRk3OM93I2c8j1RwVzmCvTc0S/Zz43ore3M5q +4TU2F2Rm9yeQJ0DP6qoi4Y/A2qCkv5DTRLsCUfuAWo06yo6Lc6mDD2PtHC15pEgBQ bPBu/j3hiDny9ucc18vo5auCxuL/t+fBTkTPaEO9daanBARd9/6JuEVKapiKm/WDgr h0RltAmlrZbeMELI9VNYKVjvZ3xRexlgjhI+icqGQDgzSj+Rdn6n3WFHCc9a7ZwRhA z8X8p6+F05tbZLy6AH/Sc4pXzOKselWWoeOzjIyDH057rE9X79K0hMi8nSz1Q8zHBt XbaLhDeNF8jow== Date: Wed, 02 Dec 2026 16:04:55 +0000 To: linux-bluetooth@vger.kernel.org From: Kyle Pepper Cc: marcel@holtmann.org, luiz.dentz@gmail.com Subject: [RFC PATCH BlueZ] asha: Wait for connection event length requests Message-ID: <20261202160403.226082-1-cochcoder@proton.me> Feedback-ID: 97716137:user:proton X-Pm-Message-ID: 80d2c4faacaf78bf450a5c746ba22fbaa185ba17 X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Request at least 7.5 ms connection event length hints for ASHA and restore the previous preference on stop if no later writer replaced it. Wait asynchronously for the kernel request to complete before START. Bound the wait, propagate errors, cancel pending connection callbacks during teardown, and continue waiting for AudioStatus after START. Retain playback on kernels without completion reporting. Propagate socket request errors before START, including on legacy getters. Assisted-by: Codex:GPT-6 --- Base: BlueZ eecfd959cf5ae9a24ee007975439747779804be1. Requires the separate Linux BT_LE_CONN_EVENT_LEN RFC. No verified dependenc= y submission URL is available at preparation. This is the first public CE RFC, with no previous CE email available for threading. PHY and observed-interval notification are already in this base: https://github.com/bluez/bluez/commit/9659adb6819d7e0284d0d2ba226a3894423d8= db4 https://github.com/bluez/bluez/commit/353011d828a7822ef05e5d9939da56a142cb0= f61 The older STATUS v6 exports are not a prerequisite for this revision. Connection interval, latency and supervision defaults are unchanged. Validation: the preceding source passed 37 native programs. This local review passes all seven profile cases natively and with ASan/UBSan/leak checks, including ten completion and five connection-lifetime scenarios. New regressions reproduce on the preceding source with both legacy and completion-aware getters; the prior gate-bypass control also failed. The existing interval fixture also covers the new CE lifecycle and late connection callbacks; no new test executable or file is added. The saved stable integration passed a 900-second human trial, but included other local changes. This exact upstream revision has no hardware or PTS result. The hint is advisory; restoration is a value comparison, not atomic arbitration with another application. Human source review is required. doc/l2cap-protocol.rst | 52 ++++++ lib/bluetooth/bluetooth.h | 11 ++ profiles/audio/asha.c | 310 +++++++++++++++++++++++++++++--- unit/test-asha-conn.c | 450 ++++++++++++++++++++++++++++++++++++++++++= ++-- 4 files changed, 792 insertions(+), 31 deletions(-) diff --git a/doc/l2cap-protocol.rst b/doc/l2cap-protocol.rst index 8f0af9b8a..a721e0def 100644 --- a/doc/l2cap-protocol.rst +++ b/doc/l2cap-protocol.rst @@ -246,6 +246,58 @@ High-speed (AMP) channel policy, possible values: **BT_CHANNEL_POLICY_BREDR_PREFERRED**, 1, BR/EDR Preferred **BT_CHANNEL_POLICY_BREDR_PREFERRED**, 2, AMP Preferred =20 +BT_LE_CONN_EVENT_LEN +~~~~~~~~~~~~~~~~~~~~ + +Request local LE connection event length hints using:: + + struct bt_le_conn_event_len { + uint16_t min; + uint16_t max; + }; + +Both fields use 0.625 ms units; zero means no preference. The minimum must +not exceed the maximum. These are advisory controller scheduling hints, +not reserved airtime or measured event lengths. + +The socket must be connected to an LE link. Setting the option requires +the local Central role. A successful setsockopt queues an asynchronous +LE Connection Update preserving the live interval, latency and supervision +timeout. It does not confirm controller acceptance. Getsockopt returns +the latest local request, including requests awaiting controller completio= n. + +The request belongs to the underlying connection, shared by its sockets. +The latest request replaces earlier values. Closing the socket does not +reset the request; disconnecting the link does. Applications sharing a +connection must coordinate requests and restoration. Subsequent local +connection parameter updates preserve these hints. + +Older kernels return ENOPROTOOPT. An unconnected socket returns ENOTCONN; +a BR/EDR link or a setter in the Peripheral role returns EOPNOTSUPP. +A setter with a size other than sizeof(struct bt_le_conn_event_len), or +with min greater than max, returns EINVAL. + +An eight-byte getsockopt buffer may use:: + + struct bt_le_conn_event_len_state { + struct bt_le_conn_event_len request; + int32_t status; + }; + +The first four bytes retain the requested min/max values. The optional sig= ned, +native-endian status is -EINPROGRESS while CE work is queued or executing, +zero after the latest queued CE command completes successfully, or a negat= ive +errno after failure. An older completion does not clear a newer pending re= quest. +Zero on a connection with no CE request means no work is pending, not that= a +nonzero airtime hint was applied. Applications must also check the request= ed +values. Successful completion confirms the HCI command, not reserved airti= me. +The setter remains exactly four bytes. Older kernels return only that four= -byte +prefix; callers must inspect the returned length before reading status. +Some experimental CE v1 kernels leave the supplied length unchanged after +copying four bytes. Initialize status to INT32_MIN before the call; an unc= hanged +sentinel means completion reporting is unavailable. Kernel status values a= re +zero or a negated errno, so they cannot equal this sentinel. + BT_PHY (since Linux 5.10) ------------------------- =20 diff --git a/lib/bluetooth/bluetooth.h b/lib/bluetooth/bluetooth.h index 58bb65d7b..1e662666a 100644 --- a/lib/bluetooth/bluetooth.h +++ b/lib/bluetooth/bluetooth.h @@ -376,6 +376,17 @@ enum { =20 #define BT_SCM_PKT_SEQNUM=090x05 =20 +#define BT_LE_CONN_EVENT_LEN 23 +struct bt_le_conn_event_len { +=09uint16_t min; +=09uint16_t max; +}; + +struct bt_le_conn_event_len_state { +=09struct bt_le_conn_event_len request; +=09int32_t status; +}; + /* Byte order conversions */ #if __BYTE_ORDER =3D=3D __LITTLE_ENDIAN #define htobs(d) (d) diff --git a/profiles/audio/asha.c b/profiles/audio/asha.c index e6a9ded62..f5f391273 100644 --- a/profiles/audio/asha.c +++ b/profiles/audio/asha.c @@ -55,6 +55,7 @@ #define ASHA_MIN_MTU 163 /* The default of 672 does not work */ #define ASHA_CONNECTION_MTU 512 +#define ASHA_START_TIMEOUT 10 =20 /* HCI handles include zero; a zero cached interval means unknown. */ #define ASHA_NUM_HANDLES 0x0f00 @@ -68,14 +69,32 @@ struct asha_adapter { static struct queue *asha_adapters; static struct queue *asha_streams; =20 +struct asha_start_wait { +=09bt_asha_cb_t callback; +=09void *user_data; +=09unsigned int source_id; +=09unsigned int retry_id; +=09int error; +=09bool connected; +=09bool sent; +}; + +struct connect_data { +=09struct bt_asha_device *asha_dev; +}; + struct bt_asha_device { =09struct bt_asha *asha; =09struct btd_device *device; =09struct media_transport *transport; =20 =09GIOChannel *io; +=09struct connect_data *connect_data; =09uint16_t imtu, omtu; =20 +=09struct bt_le_conn_event_len ce_previous, ce_requested; +=09bool ce_changed; +=09struct asha_start_wait *start_wait; =09unsigned int resume_id; }; =20 @@ -276,6 +295,239 @@ static void asha_adapter_remove(struct btd_profile *p= rofile, =09} } =20 +static void asha_start_wait_cancel(struct bt_asha_device *asha_dev) +{ +=09struct asha_start_wait *wait =3D asha_dev->start_wait; + +=09if (!wait) +=09=09return; + +=09asha_dev->start_wait =3D NULL; + +=09if (wait->retry_id) +=09=09g_source_remove(wait->retry_id); + +=09if (wait->source_id) +=09=09g_source_remove(wait->source_id); + +=09g_free(wait); +} + +static void asha_cancel_connect(struct bt_asha_device *asha_dev) +{ +=09if (!asha_dev->connect_data) +=09=09return; + +=09asha_dev->connect_data->asha_dev =3D NULL; +=09asha_dev->connect_data =3D NULL; +} + +static gboolean asha_start_wait_error(gpointer user_data) +{ +=09struct bt_asha_device *asha_dev =3D user_data; +=09struct asha_start_wait *wait =3D asha_dev->start_wait; +=09bt_asha_cb_t callback =3D wait->callback; +=09void *data =3D wait->user_data; +=09int err =3D wait->error; + +=09wait->source_id =3D 0; +=09bt_asha_device_stop(asha_dev); + +=09/* The owner callback may remove the device. */ +=09if (callback) +=09=09callback(err, data); + +=09return G_SOURCE_REMOVE; +} + +static gboolean asha_start_wait_timeout(gpointer user_data) +{ +=09struct bt_asha_device *asha_dev =3D user_data; + +=09asha_dev->start_wait->error =3D -ETIMEDOUT; +=09return asha_start_wait_error(asha_dev); +} + +static void asha_start_wait_fail(struct bt_asha_device *asha_dev, int err) +{ +=09struct asha_start_wait *wait =3D asha_dev->start_wait; + +=09if (!wait || wait->error) +=09=09return; + +=09if (wait->source_id) +=09=09g_source_remove(wait->source_id); + +=09wait->error =3D err; +=09/* Do not call the owner from inside the HCI stream iteration. */ +=09wait->source_id =3D g_idle_add(asha_start_wait_error, asha_dev); +} + +static void asha_start_complete(int status, void *user_data) +{ +=09struct bt_asha_device *asha_dev =3D user_data; +=09struct asha_start_wait *wait =3D asha_dev->start_wait; +=09bt_asha_cb_t callback; +=09void *data; + +=09if (!wait || wait->error) +=09=09return; + +=09if (status) { +=09=09asha_start_wait_fail(asha_dev, -EIO); +=09=09return; +=09} + +=09callback =3D wait->callback; +=09data =3D wait->user_data; +=09asha_start_wait_cancel(asha_dev); + +=09if (callback) +=09=09callback(0, data); +} + +static int asha_event_len_ready(struct bt_asha_device *asha_dev) +{ +=09struct bt_le_conn_event_len_state state =3D { .status =3D INT32_MIN }; +=09socklen_t len =3D sizeof(state); +=09int fd =3D g_io_channel_unix_get_fd(asha_dev->io); + +=09if (getsockopt(fd, SOL_BLUETOOTH, BT_LE_CONN_EVENT_LEN, +=09=09=09=09=09=09=09&state, &len) < 0) +=09=09return errno =3D=3D ENOPROTOOPT ? 1 : -errno; + +=09/* Older CE kernels return only the requested four-byte prefix. */ +=09if (len =3D=3D sizeof(state.request)) +=09=09return 1; +=09if (len !=3D sizeof(state)) +=09=09return -EIO; +=09/* CE v1 did not shorten optlen after copying its four-byte value. */ +=09if (state.status =3D=3D INT32_MIN) +=09=09return 1; +=09if (state.status =3D=3D -EINPROGRESS) +=09=09return 0; +=09if (state.status) +=09=09return state.status < 0 ? state.status : -EIO; +=09if (state.request.min < 12 || state.request.max < 12) +=09=09return -ECANCELED; + +=09return 1; +} + +static gboolean asha_start_wait_retry(gpointer user_data); + +static void asha_start_wait_try(struct bt_asha_device *asha_dev) +{ +=09struct asha_start_wait *wait =3D asha_dev->start_wait; +=09int ready; + +=09if (!wait || wait->error || !wait->connected || wait->sent) +=09=09return; + +=09ready =3D asha_event_len_ready(asha_dev); +=09if (ready < 0) { +=09=09asha_start_wait_fail(asha_dev, ready); +=09=09return; +=09} +=09if (!ready) { +=09=09/* The kernel publishes completion after the HCI event. +=09=09 * Query it again without blocking the main loop. +=09=09 */ +=09=09if (!wait->retry_id) +=09=09=09wait->retry_id =3D g_timeout_add(20, +=09=09=09=09=09asha_start_wait_retry, asha_dev); +=09=09return; +=09} +=09if (wait->retry_id) { +=09=09g_source_remove(wait->retry_id); +=09=09wait->retry_id =3D 0; +=09} + +=09asha_send_interval(asha_dev); + +=09wait->sent =3D true; + +=09if (bt_asha_start(asha_dev->asha, asha_start_complete, asha_dev)) +=09=09asha_start_wait_fail(asha_dev, -EIO); +} + +static gboolean asha_start_wait_retry(gpointer user_data) +{ +=09struct bt_asha_device *asha_dev =3D user_data; + +=09asha_dev->start_wait->retry_id =3D 0; +=09asha_start_wait_try(asha_dev); +=09return G_SOURCE_REMOVE; +} + +static void asha_start_wait_begin(struct bt_asha_device *asha_dev, +=09=09=09=09=09bt_asha_cb_t callback, void *user_data) +{ +=09struct asha_start_wait *wait; + +=09wait =3D g_new0(struct asha_start_wait, 1); +=09wait->callback =3D callback; +=09wait->user_data =3D user_data; +=09asha_dev->start_wait =3D wait; +=09wait->source_id =3D g_timeout_add_seconds(ASHA_START_TIMEOUT, +=09=09=09=09=09asha_start_wait_timeout, asha_dev); +} + +static int asha_request_event_len(struct bt_asha_device *asha_dev) +{ +=09struct bt_le_conn_event_len previous, requested; +=09socklen_t len =3D sizeof(previous); +=09int fd =3D g_io_channel_unix_get_fd(asha_dev->io); + +=09if (getsockopt(fd, SOL_BLUETOOTH, BT_LE_CONN_EVENT_LEN, +=09=09=09=09=09=09&previous, &len) < 0) +=09=09return errno =3D=3D ENOPROTOOPT ? 0 : -errno; + +=09if (len !=3D sizeof(previous)) +=09=09return -EIO; + +=09requested.min =3D MAX(previous.min, 12); +=09requested.max =3D MAX(previous.max, 12); +=09if (requested.min =3D=3D previous.min && requested.max =3D=3D previous.= max) +=09=09return 0; + +=09if (setsockopt(fd, SOL_BLUETOOTH, BT_LE_CONN_EVENT_LEN, +=09=09=09=09=09&requested, sizeof(requested)) < 0) +=09=09return -errno; + +=09asha_dev->ce_previous =3D previous; +=09asha_dev->ce_requested =3D requested; +=09asha_dev->ce_changed =3D true; + +=09return 0; +} + +static void asha_release_event_len(struct bt_asha_device *asha_dev) +{ +=09struct bt_le_conn_event_len current; +=09socklen_t len =3D sizeof(current); +=09int fd; + +=09if (!asha_dev->ce_changed) +=09=09return; + +=09asha_dev->ce_changed =3D false; +=09fd =3D g_io_channel_unix_get_fd(asha_dev->io); +=09if (getsockopt(fd, SOL_BLUETOOTH, BT_LE_CONN_EVENT_LEN, +=09=09=09=09=09=09¤t, &len) < 0 || +=09=09=09=09=09=09len !=3D sizeof(current)) +=09=09return; + +=09/* Leave a later request from another user of this link untouched. */ +=09if (current.min !=3D asha_dev->ce_requested.min || +=09=09=09=09current.max !=3D asha_dev->ce_requested.max) +=09=09return; + +=09if (setsockopt(fd, SOL_BLUETOOTH, BT_LE_CONN_EVENT_LEN, +=09=09=09&asha_dev->ce_previous, sizeof(current)) < 0) +=09=09DBG("Could not restore ASHA event length: %s", strerror(errno)); +} + static char *make_endpoint_path(struct bt_asha_device *asha_dev) { =09char *path; @@ -291,22 +543,23 @@ static char *make_endpoint_path(struct bt_asha_device= *asha_dev) =09return path; } =20 -struct connect_data { -=09struct bt_asha_device *asha_dev; -=09bt_asha_cb_t cb; -=09void *cb_user_data; -}; - static void connect_cb(GIOChannel *io, GError *err, gpointer user_data) { =09struct connect_data *conn_data =3D user_data; =09struct bt_asha_device *asha_dev =3D conn_data->asha_dev; =09GError *gerr =3D NULL; =09uint32_t phys; -=09int fd; +=09int fd, ret; + +=09if (!asha_dev) +=09=09return; + +=09asha_dev->connect_data =3D NULL; =20 =09if (err) { =09=09error("%s", err->message); + +=09=09asha_start_wait_fail(asha_dev, -EIO); =09=09return; =09} =20 @@ -330,12 +583,14 @@ static void connect_cb(GIOChannel *io, GError *err, g= pointer user_data) =09if (setsockopt(fd, SOL_BLUETOOTH, BT_PHY, &phys, sizeof(phys)) < 0) =09=09DBG("Could not set LE 2M PHY preference: %s", strerror(errno)); =20 -=09asha_dev->io =3D io; - -=09asha_send_interval(asha_dev); +=09ret =3D asha_request_event_len(asha_dev); +=09if (ret < 0) { +=09=09asha_start_wait_fail(asha_dev, ret); +=09=09return; +=09} =20 -=09bt_asha_start(asha_dev->asha, conn_data->cb, -=09=09=09=09=09conn_data->cb_user_data); +=09asha_dev->start_wait->connected =3D true; +=09asha_start_wait_try(asha_dev); } =20 static int asha_connect_socket(struct bt_asha_device *asha_dev, @@ -345,21 +600,22 @@ static int asha_connect_socket(struct bt_asha_device = *asha_dev, =09const bdaddr_t *src_addr; =09struct connect_data *conn_data; =20 -=09if (asha_dev->asha->state !=3D ASHA_STOPPED) { +=09if (asha_dev->io || asha_dev->start_wait || +=09=09=09=09=09asha_dev->asha->state !=3D ASHA_STOPPED) { =09=09error("ASHA device connect failed. Bad state %d", =09=09=09=09=09=09=09asha_dev->asha->state); -=09=09return 0; +=09=09return -EBUSY; =09} =20 =09conn_data =3D g_new0(struct connect_data, 1); =09conn_data->asha_dev =3D asha_dev; -=09conn_data->cb =3D cb; -=09conn_data->cb_user_data =3D user_data; +=09asha_dev->connect_data =3D conn_data; +=09asha_start_wait_begin(asha_dev, cb, user_data); =20 =09src_addr =3D btd_adapter_get_address( =09=09=09device_get_adapter(asha_dev->device)); =20 -=09if (!bt_io_connect(connect_cb, conn_data, +=09asha_dev->io =3D bt_io_connect(connect_cb, conn_data, =09=09=09=09g_free, &gerr, =09=09=09=09BT_IO_OPT_MODE, BT_IO_MODE_LE_FLOWCTL, =09=09=09=09BT_IO_OPT_SOURCE_TYPE, BDADDR_LE_PUBLIC, @@ -370,9 +626,13 @@ static int asha_connect_socket(struct bt_asha_device *= asha_dev, =09=09=09=09BT_IO_OPT_PSM, asha_dev->asha->psm, =09=09=09=09BT_IO_OPT_OMTU, ASHA_MIN_MTU, =09=09=09=09BT_IO_OPT_IMTU, ASHA_CONNECTION_MTU, -=09=09=09=09BT_IO_OPT_INVALID)) { +=09=09=09=09BT_IO_OPT_INVALID); +=09if (!asha_dev->io) { =09=09error("Could not open L2CAP CoC socket: %s", gerr->message); =09=09g_error_free(gerr); +=09=09asha_dev->connect_data =3D NULL; +=09=09g_free(conn_data); +=09=09asha_start_wait_cancel(asha_dev); =09=09goto error; =09} =20 @@ -404,9 +664,13 @@ unsigned int bt_asha_device_start(struct bt_asha_devic= e *asha_dev, =20 unsigned int bt_asha_device_stop(struct bt_asha_device *asha_dev) { +=09asha_start_wait_cancel(asha_dev); +=09asha_cancel_connect(asha_dev); =09bt_asha_stop(asha_dev->asha); +=09bt_asha_state_reset(asha_dev->asha); =20 =09if (asha_dev->io) { +=09=09asha_release_event_len(asha_dev); =09=09g_io_channel_shutdown(asha_dev->io, TRUE, NULL); =09=09g_io_channel_unref(asha_dev->io); =09=09asha_dev->io =3D NULL; @@ -417,15 +681,17 @@ unsigned int bt_asha_device_stop(struct bt_asha_devic= e *asha_dev) =20 void bt_asha_device_state_reset(struct bt_asha_device *asha_dev) { +=09asha_start_wait_cancel(asha_dev); +=09asha_cancel_connect(asha_dev); + =09if (asha_dev->io) { +=09=09asha_release_event_len(asha_dev); =09=09g_io_channel_shutdown(asha_dev->io, TRUE, NULL); =09=09g_io_channel_unref(asha_dev->io); =09=09asha_dev->io =3D NULL; =09}; =20 =09bt_asha_state_reset(asha_dev->asha); - -=09asha_dev->resume_id =3D 0; } =20 unsigned int bt_asha_device_device_get_resume_id( @@ -437,6 +703,9 @@ unsigned int bt_asha_device_device_get_resume_id( enum bt_asha_state_t bt_asha_device_get_state( =09=09=09=09=09struct bt_asha_device *asha_dev) { +=09if (asha_dev->start_wait) +=09=09return ASHA_STARTING; + =09return asha_dev->asha->state; } =20 @@ -610,6 +879,7 @@ static void asha_source_device_remove(struct btd_servic= e *service) =09=09asha_streams =3D NULL; =09} =20 +=09bt_asha_device_state_reset(asha_dev); =09bt_asha_free(asha_dev->asha); =09g_free(asha_dev); } diff --git a/unit/test-asha-conn.c b/unit/test-asha-conn.c index efdac837b..4b9e6ed08 100644 --- a/unit/test-asha-conn.c +++ b/unit/test-asha-conn.c @@ -10,12 +10,14 @@ #define bt_att_get_fd test_att_fd #define bt_asha_set_connection_interval test_set_interval #define bt_asha_start test_start +#define bt_asha_stop test_stop #define bt_io_get test_io_get #include "profiles/audio/asha.c" #undef bt_gatt_client_get_att #undef bt_att_get_fd #undef bt_asha_set_connection_interval #undef bt_asha_start +#undef bt_asha_stop #undef bt_io_get #include "bluetooth/hci.h" #include "src/shared/tester.h" @@ -38,19 +40,25 @@ const char *device_get_path(const struct btd_device *de= vice) =20 const bdaddr_t *device_get_address(struct btd_device *device) { -=09assert(false); +=09static const bdaddr_t address; + +=09return &address; } =20 const bdaddr_t *btd_adapter_get_address(struct btd_adapter *adapter) { -=09assert(false); +=09static const bdaddr_t address; + +=09return &address; } =20 void btd_device_set_conn_param(struct btd_device *device, =09=09=09=09uint16_t min_interval, uint16_t max_interval, =09=09=09=09=09uint16_t latency, uint16_t timeout) { -=09assert(false); +=09assert(min_interval =3D=3D 16 && max_interval =3D=3D 16); +=09assert(latency =3D=3D 10); +=09assert(timeout =3D=3D 100); } =20 struct gatt_db *btd_device_get_gatt_db(struct btd_device *device) @@ -132,25 +140,53 @@ const char *media_transport_get_path(struct media_tra= nsport *transport) =09assert(false); } =20 +static BtIOConnect pending_connect; +static GDestroyNotify pending_destroy; +static void *pending_data; +static GIOChannel *pending_io; +static int connect_peer; +static bool connect_error; + GIOChannel *bt_io_connect(BtIOConnect connect, gpointer user_data, =09=09=09=09GDestroyNotify destroy, GError **gerr, =09=09=09=09=09=09=09BtIOOption opt1, ...) { -=09assert(false); +=09int fds[2]; + +=09if (connect_error) { +=09=09g_set_error_literal(gerr, g_quark_from_static_string("test"), +=09=09=09=09=09=09=09EIO, "connect failed"); +=09=09return NULL; +=09} + +=09assert(!pending_io); +=09assert(!socketpair(AF_UNIX, SOCK_STREAM, 0, fds)); +=09pending_io =3D g_io_channel_unix_new(fds[0]); +=09g_io_channel_set_close_on_unref(pending_io, TRUE); +=09pending_connect =3D connect; +=09pending_data =3D user_data; +=09pending_destroy =3D destroy; +=09connect_peer =3D fds[1]; +=09return g_io_channel_ref(pending_io); } =20 static int peer_fd[2]; static int observer_fd[2]; static int pending_peer; static unsigned int writes; +static unsigned int starts; +static bool start_error; +static bool interval_error; +static bt_asha_cb_t start_callback; +static void *start_data; static uint16_t last_interval; static struct bt_asha *last_asha; static bool socket_ready =3D true; static bool fail_socket; static int att_fd =3D 100; +static uint16_t att_handle =3D 16; static unsigned int handle_reads; static socklen_t conninfo_length =3D sizeof(struct l2cap_conninfo); -static uint16_t att_handle =3D 16; =20 int __wrap_socket(int domain, int type, int protocol) { @@ -183,9 +219,27 @@ int __wrap_bind(int fd, const struct sockaddr *addr, s= ocklen_t length) =09return 0; } =20 +static struct bt_le_conn_event_len ce_value; +static bool ce_supported, ce_set_fail, ce_get_fail, ce_short; +static unsigned int ce_sets; +static int ce_set_error =3D ENOPROTOOPT; +static bool ce_extended, ce_legacy_len; +static int32_t ce_status; + int __wrap_setsockopt(int fd, int level, int opt, const void *value, =09=09=09=09=09=09=09socklen_t length) { +=09if (level =3D=3D SOL_BLUETOOTH && opt =3D=3D BT_LE_CONN_EVENT_LEN) { +=09=09assert(length =3D=3D sizeof(ce_value)); +=09=09ce_sets++; +=09=09if (!ce_supported || ce_set_fail) { +=09=09=09errno =3D ce_set_error; +=09=09=09return -1; +=09=09} +=09=09memcpy(&ce_value, value, length); +=09=09return 0; +=09} + =09if (level =3D=3D SOL_HCI) =09=09return 0; =20 @@ -197,6 +251,30 @@ int __wrap_getsockopt(int fd, int level, int opt, void= *value, { =09struct l2cap_conninfo *info =3D value; =20 +=09if (level =3D=3D SOL_BLUETOOTH && opt =3D=3D BT_LE_CONN_EVENT_LEN) { +=09=09if (!ce_supported || ce_get_fail) { +=09=09=09errno =3D ENOPROTOOPT; +=09=09=09return -1; +=09=09} +=09=09if (*length =3D=3D sizeof(struct bt_le_conn_event_len_state) && +=09=09=09=09=09=09=09ce_extended) { +=09=09=09struct bt_le_conn_event_len_state state =3D { +=09=09=09=09.request =3D ce_value, .status =3D ce_status, +=09=09=09}; +=09=09=09memcpy(value, &state, sizeof(state)); +=09=09=09*length =3D ce_short ? 1 : sizeof(state); +=09=09} else { +=09=09=09assert(*length >=3D sizeof(ce_value)); +=09=09=09memcpy(value, &ce_value, sizeof(ce_value)); +=09=09=09if (ce_legacy_len) +=09=09=09=09assert(((struct bt_le_conn_event_len_state *) +=09=09=09=09=09=09value)->status =3D=3D INT32_MIN); +=09=09=09*length =3D ce_short ? 1 : ce_legacy_len ? +=09=09=09=09=09=09*length : sizeof(ce_value); +=09=09} +=09=09return 0; +=09} + =09assert(level =3D=3D SOL_L2CAP && opt =3D=3D L2CAP_CONNINFO); =09handle_reads++; =20 @@ -243,14 +321,26 @@ bool test_set_interval(struct bt_asha *asha, =09writes++; =09last_asha =3D asha; =09last_interval =3D interval; -=09return true; +=09return !interval_error; } =20 unsigned int test_start(struct bt_asha *asha, bt_asha_cb_t cb, =09=09=09=09=09=09=09void *user_data) { -=09assert(writes =3D=3D 1 && last_asha =3D=3D asha && last_interval =3D=3D= 24); +=09starts++; + +=09if (start_error) +=09=09return -1; + =09asha->state =3D ASHA_STARTING; +=09start_callback =3D cb; +=09start_data =3D user_data; +=09return 0; +} + +unsigned int test_stop(struct bt_asha *asha) +{ +=09bt_asha_state_reset(asha); =09return 0; } =20 @@ -272,11 +362,335 @@ static void event(unsigned int adapter, uint8_t sube= vent, const void *value, =09=09; } =20 +struct gate_result { +=09struct bt_asha_device *device; +=09unsigned int calls; +=09int error; +=09bool remove; +}; + +static void gate_callback(int status, void *user_data) +{ +=09struct gate_result *result =3D user_data; + +=09assert(!result->device->start_wait); + +=09if (status) { +=09=09assert(!result->device->io); +=09=09assert(bt_asha_device_get_state(result->device) =3D=3D +=09=09=09=09=09=09=09ASHA_STOPPED); +=09} else { +=09=09assert(result->device->io); +=09=09assert(bt_asha_device_get_state(result->device) =3D=3D +=09=09=09=09=09=09=09ASHA_STARTED); +=09} +=09result->calls++; +=09result->error =3D status; + +=09if (result->remove) { +=09=09queue_remove(asha_streams, result->device); +=09=09bt_asha_device_state_reset(result->device); +=09=09g_free(result->device); +=09=09result->device =3D NULL; +=09} +} + +static void finish_connect(bool failed) +{ +=09GError *err =3D NULL; + +=09if (failed) +=09=09g_set_error_literal(&err, g_quark_from_static_string("test"), +=09=09=09=09=09=09=09EIO, "connect failed"); + +=09pending_connect(pending_io, err, pending_data); +=09pending_destroy(pending_data); +=09g_io_channel_unref(pending_io); +=09pending_io =3D NULL; +=09g_clear_error(&err); +=09close(connect_peer); +} + +static void test_event_len(const void *user_data) +{ +=09struct bt_asha_device dev =3D {}; +=09int fds[2]; +=09unsigned int before; + +=09assert(!pipe(fds)); +=09dev.io =3D g_io_channel_unix_new(fds[0]); + +=09/* An older kernel must not prevent playback or attempt a restore. */ +=09ce_supported =3D false; +=09ce_sets =3D 0; +=09asha_request_event_len(&dev); +=09asha_release_event_len(&dev); +=09assert(!dev.ce_changed && !ce_sets); + +=09ce_supported =3D true; +=09ce_value =3D (struct bt_le_conn_event_len) { 0, 0 }; +=09asha_request_event_len(&dev); +=09assert(dev.ce_changed && ce_value.min =3D=3D 12 && ce_value.max =3D=3D = 12); +=09asha_release_event_len(&dev); +=09assert(!dev.ce_changed && !ce_value.min && !ce_value.max); +=09before =3D ce_sets; +=09asha_release_event_len(&dev); +=09assert(ce_sets =3D=3D before); + +=09/* Preserve both stronger and asymmetric requests. */ +=09ce_value =3D (struct bt_le_conn_event_len) { 16, 20 }; +=09asha_request_event_len(&dev); +=09assert(!dev.ce_changed && ce_sets =3D=3D before); +=09ce_value =3D (struct bt_le_conn_event_len) { 8, 20 }; +=09asha_request_event_len(&dev); +=09assert(dev.ce_changed && ce_value.min =3D=3D 12 && ce_value.max =3D=3D = 20); +=09asha_release_event_len(&dev); +=09assert(ce_value.min =3D=3D 8 && ce_value.max =3D=3D 20); + +=09/* A later writer owns the current connection preference. */ +=09ce_value =3D (struct bt_le_conn_event_len) { 0, 0 }; +=09asha_request_event_len(&dev); +=09ce_value.min =3D ce_value.max =3D 24; +=09before =3D ce_sets; +=09asha_release_event_len(&dev); +=09assert(!dev.ce_changed && ce_sets =3D=3D before && ce_value.min =3D=3D = 24); + +=09ce_value =3D (struct bt_le_conn_event_len) { 0, 0 }; +=09ce_set_fail =3D true; +=09asha_request_event_len(&dev); +=09assert(!dev.ce_changed && !ce_value.min); +=09ce_set_fail =3D false; +=09ce_short =3D true; +=09before =3D ce_sets; +=09asha_request_event_len(&dev); +=09assert(!dev.ce_changed && ce_sets =3D=3D before); +=09ce_short =3D false; + +=09asha_request_event_len(&dev); +=09assert(dev.ce_changed); +=09ce_get_fail =3D true; +=09before =3D ce_sets; +=09asha_release_event_len(&dev); +=09assert(!dev.ce_changed && ce_sets =3D=3D before); +=09ce_get_fail =3D false; + +=09/* Resume/reconnect must snapshot this connection's preference again. *= / +=09ce_value =3D (struct bt_le_conn_event_len) { 4, 8 }; +=09asha_request_event_len(&dev); +=09assert(dev.ce_previous.min =3D=3D 4 && dev.ce_previous.max =3D=3D 8); +=09asha_release_event_len(&dev); +=09assert(ce_value.min =3D=3D 4 && ce_value.max =3D=3D 8); +=09ce_supported =3D false; +=09g_io_channel_unref(dev.io); +=09close(fds[0]); +=09close(fds[1]); +=09tester_test_passed(); +} + +static void test_completion_gate(const void *user_data) +{ +=09for (unsigned int scenario =3D 0; scenario < 10; scenario++) { +=09=09struct bt_asha asha =3D { .client =3D (void *) 1 }; +=09=09struct bt_asha_device dev =3D { +=09=09=09.asha =3D &asha, .device =3D (void *) 1, +=09=09}; +=09=09struct gate_result result =3D { .device =3D &dev }; +=09=09struct bt_hci_evt_le_conn_complete complete =3D { +=09=09=09.handle =3D cpu_to_le16(16), .interval =3D cpu_to_le16(16), +=09=09}; +=09=09struct bt_hci_evt_le_conn_update_complete update =3D { +=09=09=09.handle =3D cpu_to_le16(16), .interval =3D cpu_to_le16(16), +=09=09}; +=09=09unsigned int retry; +=09=09GSource *timer; +=09=09int fds[2]; + +=09=09starts =3D writes =3D 0; +=09=09start_error =3D interval_error =3D false; +=09=09ce_supported =3D ce_extended =3D true; +=09=09ce_status =3D -EINPROGRESS; +=09=09ce_value =3D (struct bt_le_conn_event_len) { 12, 12 }; +=09=09assert(!pipe(fds)); +=09=09assert(!asha_adapter_probe(NULL, (void *) 1)); +=09=09asha_streams =3D queue_new(); +=09=09queue_push_tail(asha_streams, &dev); +=09=09event(0, BT_HCI_EVT_LE_CONN_COMPLETE, &complete, +=09=09=09=09=09=09=09sizeof(complete)); +=09=09writes =3D 0; +=09=09dev.io =3D g_io_channel_unix_new(fds[0]); +=09=09g_io_channel_set_close_on_unref(dev.io, TRUE); +=09=09asha_start_wait_begin(&dev, gate_callback, &result); +=09=09dev.start_wait->connected =3D true; +=09=09asha_start_wait_try(&dev); +=09=09assert(!starts && !writes && dev.start_wait->retry_id); +=09=09retry =3D dev.start_wait->retry_id; + +=09=09/* Cached intervals and older updates cannot release START. */ +=09=09event(0, BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE, &update, +=09=09=09=09=09=09=09sizeof(update)); +=09=09assert(!starts && writes =3D=3D 1); +=09=09assert(dev.start_wait->retry_id =3D=3D retry); +=09=09writes =3D 0; + +=09=09switch (scenario) { +=09=09case 0: +=09=09=09ce_status =3D 0; +=09=09=09timer =3D g_main_context_find_source_by_id(NULL, retry); +=09=09=09g_source_set_ready_time(timer, 0); +=09=09=09while (g_main_context_iteration(NULL, FALSE)) +=09=09=09=09; +=09=09=09assert(starts =3D=3D 1 && writes =3D=3D 1); +=09=09=09assert(!dev.start_wait->retry_id); +=09=09=09/* Notify while awaiting AudioStatus too. */ +=09=09=09event(0, BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE, &update, +=09=09=09=09=09=09=09=09sizeof(update)); +=09=09=09assert(starts =3D=3D 1 && writes =3D=3D 2); +=09=09=09asha.state =3D ASHA_STARTED; +=09=09=09start_callback(0, start_data); +=09=09=09assert(result.calls =3D=3D 1 && !result.error); +=09=09=09assert(!dev.start_wait); +=09=09=09break; +=09=09case 1: +=09=09=09ce_status =3D -EIO; +=09=09=09asha_start_wait_try(&dev); +=09=09=09while (g_main_context_iteration(NULL, FALSE)) +=09=09=09=09; +=09=09=09assert(!starts && result.calls =3D=3D 1); +=09=09=09assert(result.error =3D=3D -EIO); +=09=09=09break; +=09=09case 2: +=09=09=09bt_asha_device_state_reset(&dev); +=09=09=09assert(!g_main_context_find_source_by_id(NULL, retry)); +=09=09=09while (g_main_context_iteration(NULL, FALSE)) +=09=09=09=09; +=09=09=09assert(!starts && !result.calls); +=09=09=09break; +=09=09case 3: +=09=09=09timer =3D g_main_context_find_source_by_id(NULL, +=09=09=09=09=09=09dev.start_wait->source_id); +=09=09=09g_source_set_ready_time(timer, 0); +=09=09=09while (g_main_context_iteration(NULL, FALSE)) +=09=09=09=09; +=09=09=09assert(!starts && result.calls =3D=3D 1); +=09=09=09assert(result.error =3D=3D -ETIMEDOUT); +=09=09=09assert(!g_main_context_find_source_by_id(NULL, retry)); +=09=09=09break; +=09=09case 4: +=09=09=09ce_status =3D 0; +=09=09=09ce_value.min =3D ce_value.max =3D 0; +=09=09=09asha_start_wait_try(&dev); +=09=09=09while (g_main_context_iteration(NULL, FALSE)) +=09=09=09=09; +=09=09=09assert(!starts && result.calls =3D=3D 1); +=09=09=09assert(result.error =3D=3D -ECANCELED); +=09=09=09break; +=09=09case 5: +=09=09=09ce_legacy_len =3D true; +=09=09=09ce_extended =3D false; +=09=09=09asha_start_wait_try(&dev); +=09=09=09assert(starts =3D=3D 1 && !dev.start_wait->retry_id); +=09=09=09break; +=09=09case 9: +=09=09=09ce_extended =3D false; +=09=09=09asha_start_wait_try(&dev); +=09=09=09assert(starts =3D=3D 1 && !dev.start_wait->retry_id); +=09=09=09break; +=09=09case 6: +=09=09=09ce_supported =3D false; +=09=09=09asha_start_wait_try(&dev); +=09=09=09assert(starts =3D=3D 1 && !dev.start_wait->retry_id); +=09=09=09break; +=09=09case 7: +=09=09=09ce_short =3D true; +=09=09=09asha_start_wait_try(&dev); +=09=09=09while (g_main_context_iteration(NULL, FALSE)) +=09=09=09=09; +=09=09=09assert(!starts && result.calls =3D=3D 1); +=09=09=09assert(result.error =3D=3D -EIO); +=09=09=09ce_short =3D false; +=09=09=09break; +=09=09case 8: +=09=09=09ce_status =3D 0; +=09=09=09ce_value =3D (struct bt_le_conn_event_len) { 16, 20 }; +=09=09=09asha_start_wait_try(&dev); +=09=09=09assert(starts =3D=3D 1 && !dev.start_wait->retry_id); +=09=09=09break; +=09=09} +=09=09bt_asha_device_state_reset(&dev); +=09=09queue_destroy(asha_streams, NULL); +=09=09asha_streams =3D NULL; +=09=09asha_adapter_remove(NULL, (void *) 1); +=09=09close(peer_fd[0]); +=09=09close(fds[1]); +=09=09ce_supported =3D ce_extended =3D false; +=09=09ce_legacy_len =3D false; +=09} +=09starts =3D writes =3D 0; +=09tester_test_passed(); +} + +static void test_connect_lifetime(const void *user_data) +{ +=09for (unsigned int scenario =3D 0; scenario < 5; scenario++) { +=09=09struct bt_asha asha =3D { .state =3D ASHA_STOPPED }; +=09=09struct bt_asha_device dev =3D { +=09=09=09.asha =3D &asha, .device =3D (void *) 1, +=09=09}; +=09=09struct gate_result result =3D { .device =3D &dev }; +=09=09unsigned int timer; + +=09=09ce_supported =3D scenario >=3D 3; +=09=09ce_extended =3D scenario =3D=3D 4; +=09=09ce_value =3D (struct bt_le_conn_event_len) { 0, 0 }; +=09=09ce_set_fail =3D scenario >=3D 3; +=09=09ce_set_error =3D EIO; +=09=09ce_status =3D 0; +=09=09starts =3D 0; +=09=09assert(!asha_connect_socket(&dev, gate_callback, &result)); +=09=09assert(dev.io && dev.start_wait && dev.connect_data); +=09=09assert(asha_connect_socket(&dev, gate_callback, +=09=09=09=09=09=09&result) =3D=3D -EBUSY); +=09=09timer =3D dev.start_wait->source_id; +=09=09if (scenario =3D=3D 0) { +=09=09=09bt_asha_device_state_reset(&dev); +=09=09=09finish_connect(false); +=09=09=09assert(!starts && !result.calls); +=09=09=09assert(!dev.io && !dev.start_wait); +=09=09} else if (scenario =3D=3D 1) { +=09=09=09finish_connect(true); +=09=09=09while (g_main_context_iteration(NULL, FALSE)) +=09=09=09=09; +=09=09=09assert(result.calls =3D=3D 1 && result.error =3D=3D -EIO); +=09=09} else if (scenario >=3D 3) { +=09=09=09/* Failed requests must not start on old getters or +=09=09=09 * lose the setter error on completion-aware kernels. +=09=09=09 */ +=09=09=09finish_connect(false); +=09=09=09while (g_main_context_iteration(NULL, FALSE)) +=09=09=09=09; +=09=09=09assert(!starts && result.calls =3D=3D 1); +=09=09=09assert(result.error =3D=3D -EIO); +=09=09} else { +=09=09=09/* Keep old-kernel playback. */ +=09=09=09finish_connect(false); +=09=09=09assert(starts =3D=3D 1 && dev.start_wait->sent); +=09=09=09bt_asha_device_state_reset(&dev); +=09=09} +=09=09assert(!g_main_context_find_source_by_id(NULL, timer)); +=09=09assert(!dev.connect_data); +=09} +=09ce_set_fail =3D ce_extended =3D ce_supported =3D false; +=09ce_set_error =3D ENOPROTOOPT; +=09tester_test_passed(); +} + static void test_connection(const void *user_data) { =09struct bt_asha asha =3D { .acp_handle =3D 0x79 }; =09struct bt_asha other =3D { .acp_handle =3D 0x79 }; -=09struct bt_asha_device dev =3D { .asha =3D &asha, .device =3D (void *) 1= }; +=09struct bt_asha_device dev =3D { +=09=09=09.asha =3D &asha, .device =3D (void *) 1, +=09=09}; =09struct bt_asha_device dev2 =3D { .asha =3D &other, .device =3D (void *)= 2 }; =09struct connect_data conn =3D { .asha_dev =3D &dev }; =09GIOChannel *io; @@ -313,7 +727,10 @@ static void test_connection(const void *user_data) =09event(0, BT_HCI_EVT_LE_CONN_COMPLETE, &complete, sizeof(complete)); =09assert(writes =3D=3D 0); =09asha.client =3D (void *) 1; +=09dev.io =3D io; +=09asha_start_wait_begin(&dev, NULL, NULL); =09connect_cb(io, NULL, &conn); +=09asha_start_wait_cancel(&dev); =09assert(writes =3D=3D 1 && last_interval =3D=3D 24); =20 =09/* Identical handles on different controllers are separate links. */ @@ -395,7 +812,9 @@ static void test_handle_bounds(const void *user_data) =09const uint16_t handles[] =3D { 0, ASHA_NUM_HANDLES - 1, =09=09=09=09=09ASHA_NUM_HANDLES, UINT16_MAX }; =09struct bt_asha asha =3D { .client =3D (void *) 1, .acp_handle =3D 0x79 = }; -=09struct bt_asha_device dev =3D { .asha =3D &asha, .device =3D (void *) 1= }; +=09struct bt_asha_device dev =3D { +=09=09=09.asha =3D &asha, .device =3D (void *) 1, +=09=09}; =09struct bt_hci_evt_le_conn_complete complete =3D { =09=09.interval =3D cpu_to_le16(24), =09}; @@ -460,7 +879,9 @@ static void test_late_connection(const void *user_data) { =09struct bt_asha asha =3D { .client =3D (void *) 1, .acp_handle =3D 0x79, =09=09=09=09=09=09=09.state =3D ASHA_STARTED }; -=09struct bt_asha_device dev =3D { .asha =3D &asha, .device =3D (void *) 1= }; +=09struct bt_asha_device dev =3D { +=09=09=09.asha =3D &asha, .device =3D (void *) 1, +=09=09}; =09struct bt_hci_evt_le_conn_complete complete =3D { =09=09.handle =3D cpu_to_le16(16), .interval =3D cpu_to_le16(24), =09}; @@ -492,7 +913,9 @@ static void test_late_connection(const void *user_data) static void test_observer_lifecycle(const void *user_data) { =09struct bt_asha asha =3D { .acp_handle =3D 0x79 }; -=09struct bt_asha_device dev =3D { .asha =3D &asha, .device =3D (void *) 1= }; +=09struct bt_asha_device dev =3D { +=09=09=09.asha =3D &asha, .device =3D (void *) 1, +=09=09}; =09struct bt_hci_evt_le_conn_complete complete =3D { =09=09.handle =3D cpu_to_le16(16), .interval =3D cpu_to_le16(24), =09}; @@ -568,6 +991,11 @@ static void test_observer_lifecycle(const void *user_d= ata) int main(int argc, char *argv[]) { =09tester_init(&argc, &argv); +=09tester_add("ASHA/CE/lifecycle", NULL, NULL, test_event_len, NULL); +=09tester_add("ASHA/CE/completion", NULL, NULL, +=09=09=09=09=09=09test_completion_gate, NULL); +=09tester_add("ASHA/CE/connect-lifetime", NULL, NULL, +=09=09=09=09=09=09test_connect_lifetime, NULL); =09tester_add("ASHA/interval/HCI", NULL, NULL, test_connection, NULL); =09tester_add("ASHA/interval/handle-bounds", NULL, NULL, =09=09=09=09=09=09test_handle_bounds, NULL);