fix(ble_audio): Miscellaneous fixes for ISO & LE Audio (stage 2)

This commit is contained in:
Liu Linyan
2026-09-04 09:26:24 +08:00
parent 30fd193df0
commit d4133e9751
113 changed files with 4547 additions and 2104 deletions
@@ -41,7 +41,6 @@
#endif /* CONFIG_BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER */
#define CONFIG_BT_MAX_CONN CONFIG_BT_ACL_CONNECTIONS
#define CONFIG_BT_SMP CONFIG_BT_BLE_SMP_ENABLE
#define CONFIG_BT_MAX_PAIRED CONFIG_BT_SMP_MAX_BONDS
#if CONFIG_BT_ISO_UNICAST && CONFIG_BT_ISO_BROADCAST
@@ -57,7 +56,6 @@ _Static_assert(CONFIG_BT_ISO_MAX_CHAN == 0, "Too large ISO channels");
#else /* CONFIG_BT_BLUEDROID_ENABLED */
#define CONFIG_BT_MAX_CONN CONFIG_BT_NIMBLE_MAX_CONNECTIONS
#define CONFIG_BT_SMP CONFIG_BT_NIMBLE_SECURITY_ENABLE
#define CONFIG_BT_MAX_PAIRED CONFIG_BT_NIMBLE_MAX_BONDS
#if CONFIG_BT_NIMBLE_MAX_EXT_ADV_INSTANCES
@@ -231,44 +231,6 @@ int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info);
*/
int bt_conn_disconnect(struct bt_conn *conn, uint8_t reason);
/** @brief Set security level for a connection.
*
* This function enable security (encryption) for a connection. If the device
* has bond information for the peer with sufficiently strong key encryption
* will be enabled. If the connection is already encrypted with sufficiently
* strong key this function does nothing.
*
* If the device has no bond information for the peer and is not already paired
* then the pairing procedure will be initiated. Note that @p sec has no effect
* on the security level selected for the pairing process. The selection is
* instead controlled by the values of the registered @ref bt_conn_auth_cb. If
* the device has bond information or is already paired and the keys are too
* weak then the pairing procedure will be initiated.
*
* This function may return an error if the required level of security defined using
* @p sec is not possible to achieve due to local or remote device limitation
* (e.g., input output capabilities), or if the maximum number of paired devices
* has been reached.
*
* This function may return an error if the pairing procedure has already been
* initiated by the local device or the peer device.
*
* @note When @kconfig{CONFIG_BT_SMP_SC_ONLY} is enabled then the security
* level will always be level 4.
*
* @note When @kconfig{CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY} is enabled then the
* security level will always be level 3.
*
* @note When @ref BT_SECURITY_FORCE_PAIR within @p sec is enabled then the pairing
* procedure will always be initiated.
*
* @param conn Connection object.
* @param sec Requested minimum security level.
*
* @return 0 on success or negative error
*/
int bt_conn_set_security(struct bt_conn *conn, bt_security_t sec);
enum bt_security_err {
/** Security procedure successful. */
BT_SECURITY_ERR_SUCCESS,
@@ -417,6 +379,7 @@ int bt_conn_cb_register_safe(struct bt_conn_cb *cb);
* @retval -ENOENT if @p cb was not registered
*/
int bt_conn_cb_unregister(struct bt_conn_cb *cb);
int bt_conn_cb_unregister_safe(struct bt_conn_cb *cb);
/**
* @brief Register a callback structure for connection events.
@@ -1294,6 +1294,8 @@ int bt_iso_big_terminate_safe(struct bt_iso_big *big);
*
* @return 0 in case of success or negative value in case of error.
*/
int bt_iso_big_sync(struct bt_le_per_adv_sync *sync, struct bt_iso_big_sync_param *param,
struct bt_iso_big **out_big);
int bt_iso_big_sync_safe(struct bt_le_per_adv_sync *sync, struct bt_iso_big_sync_param *param,
struct bt_iso_big **out_big);
@@ -9,7 +9,6 @@
#include <stddef.h>
#include <stdint.h>
#include <assert.h>
#include <errno.h>
#include <zephyr/sys/slist.h>
@@ -21,6 +20,8 @@
#include "freertos/semphr.h"
#include "toolchain.h"
#include "utils/assert.h"
#ifdef __cplusplus
extern "C" {
#endif
@@ -36,17 +37,17 @@ struct k_mutex {
static inline void k_mutex_create(struct k_mutex *mutex)
{
assert(mutex);
assert(mutex->handle == NULL);
BT_LE_ASSERT(mutex);
BT_LE_ASSERT(mutex->handle == NULL);
mutex->handle = xSemaphoreCreateRecursiveMutex();
assert(mutex->handle);
BT_LE_ASSERT(mutex->handle);
}
static inline void k_mutex_delete(struct k_mutex *mutex)
{
assert(mutex);
assert(mutex->handle);
BT_LE_ASSERT(mutex);
BT_LE_ASSERT(mutex->handle);
vSemaphoreDelete(mutex->handle);
mutex->handle = NULL;
@@ -65,8 +66,8 @@ static inline void k_mutex_delete(struct k_mutex *mutex)
static inline int k_mutex_lock(struct k_mutex *mutex, uint32_t timeout)
{
assert(mutex);
assert(mutex->handle);
BT_LE_ASSERT(mutex);
BT_LE_ASSERT(mutex->handle);
if (xSemaphoreTakeRecursive(mutex->handle, timeout) == pdTRUE) {
return 0;
@@ -89,8 +90,8 @@ static inline int k_mutex_lock(struct k_mutex *mutex, uint32_t timeout)
static inline int k_mutex_unlock(struct k_mutex *mutex)
{
assert(mutex);
assert(mutex->handle);
BT_LE_ASSERT(mutex);
BT_LE_ASSERT(mutex->handle);
if (xSemaphoreGiveRecursive(mutex->handle) != pdTRUE) {
K_MUTEX_LOG_ERR("UnlockFail");
@@ -112,18 +113,18 @@ struct k_sem {
static inline void k_sem_create(struct k_sem *sem)
{
assert(sem);
assert(sem->handle == NULL);
BT_LE_ASSERT(sem);
BT_LE_ASSERT(sem->handle == NULL);
sem->handle = xSemaphoreCreateBinary();
assert(sem->handle);
BT_LE_ASSERT(sem->handle);
sem->result = 0;
}
static inline void k_sem_delete(struct k_sem *sem)
{
assert(sem);
assert(sem->handle);
BT_LE_ASSERT(sem);
BT_LE_ASSERT(sem->handle);
vSemaphoreDelete(sem->handle);
sem->handle = NULL;
@@ -141,8 +142,8 @@ static inline void k_sem_delete(struct k_sem *sem)
static inline int k_sem_take(struct k_sem *sem, uint32_t timeout)
{
assert(sem);
assert(sem->handle);
BT_LE_ASSERT(sem);
BT_LE_ASSERT(sem->handle);
/* Do NOT touch sem->result here. The producer may have already written
* it and called k_sem_give before this take ran (BTU/HCI cb on a
@@ -164,8 +165,8 @@ static inline int k_sem_take(struct k_sem *sem, uint32_t timeout)
static inline int k_sem_give(struct k_sem *sem)
{
assert(sem);
assert(sem->handle);
BT_LE_ASSERT(sem);
BT_LE_ASSERT(sem->handle);
if (xSemaphoreGive(sem->handle) != pdTRUE) {
K_SEM_LOG_ERR("GiveFail");
@@ -181,13 +182,20 @@ static inline int k_sem_give(struct k_sem *sem)
* caller would see uninitialized response data. */
static inline void k_sem_reset(struct k_sem *sem)
{
assert(sem);
assert(sem->handle);
BT_LE_ASSERT(sem);
BT_LE_ASSERT(sem->handle);
xQueueReset(sem->handle);
sem->result = 0;
}
/* Queue */
/* Bounded wait for a reliable-tier task-queue post instead of portMAX_DELAY,
* so a wedged consumer can't freeze an external producer (esp_timer / host
* task) and stall the ISO data path. */
#define K_QUEUE_SHORT (1000 / portTICK_PERIOD_MS)
/* Timer */
typedef uint32_t k_timeout_t;
@@ -202,6 +210,10 @@ typedef uint32_t k_timeout_t;
#define K_MINUTES(m) K_SECONDS((m) * 60)
#define K_HOURS(h) K_MINUTES((h) * 60)
/* Defer work onto iso_task. In this port K_NO_WAIT runs the handler INLINE
* (timer.c), which fires e.g. GATT indications before the CP write response. */
#define K_NO_WAIT_ASYNC K_MSEC(1)
struct k_work;
typedef void (*k_work_handler_t)(struct k_work *work);
@@ -211,6 +223,8 @@ struct k_work {
k_work_handler_t handler;
int64_t timeout_us;
void *user_data;
uint32_t gen; /* Bumped on (re)schedule/cancel/deinit so a timer event
* queued before the change is skipped (see timer.c). */
};
struct k_work_sync {
@@ -15,6 +15,8 @@
#include "esp_log.h"
#include "utils/assert.h"
/* esp_ble_iso, esp_ble_audio and any future ISO consumer are compiled
* under the unified BLE_ISO compression channel and share one
* iso_log_index.h with one monotonic log-id counter — no per-consumer
@@ -112,13 +114,13 @@ extern "C" {
#define NET_BUF_WARN(fmt, args...) /* TBD */
#define NET_BUF_INFO(fmt, args...) /* TBD */
#define NET_BUF_DBG(fmt, args...) /* TBD */
#define NET_BUF_ASSERT assert
#define NET_BUF_ASSERT BT_LE_ASSERT
#define NET_BUF_SIMPLE_ERR(fmt, args...) /* TBD */
#define NET_BUF_SIMPLE_WARN(fmt, args...) /* TBD */
#define NET_BUF_SIMPLE_INFO(fmt, args...) /* TBD */
#define NET_BUF_SIMPLE_DBG(fmt, args...) /* TBD */
#define NET_BUF_SIMPLE_ASSERT assert
#define NET_BUF_SIMPLE_ASSERT BT_LE_ASSERT
#ifdef __cplusplus
}
@@ -8,15 +8,17 @@
#define ZEPHYR_INCLUDE_SYS_ASSERT_H_
#include <stdint.h>
#include <assert.h>
#include "utils/assert.h"
#ifdef __cplusplus
extern "C" {
#endif
#define __ASSERT_NO_MSG(test) assert(test)
#define __ASSERT_NO_MSG(test) BT_LE_ASSERT(test)
#define __ASSERT(test, fmt, ...) assert(test)
/* fmt is dropped as before; BT_LE_ASSERT logs the stringified test instead. */
#define __ASSERT(test, fmt, ...) BT_LE_ASSERT(test)
#ifdef __cplusplus
}
@@ -11,8 +11,6 @@
#include <zephyr/types.h>
#include <zephyr/sys/atomic.h>
#define SYS_INIT(init_fn, level, prio) int init_fn ## _v2(void) { return init_fn(); }
#ifndef BUILD_ASSERT
#define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, ## MSG)
#endif