From 369445d2c389fbc8516f12fdca8a783c48698516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Fri, 1 Mar 2024 09:40:42 +0100 Subject: [PATCH] host: refactor BLE Audio This patch refactors BLE Audio library to conform to new directory tree introduced in a9795706bea035d84d1577680e0814ceedc9dc58. LE Audio related files present in host/include, host/src and host/services were moved to corelated folders in host/audio. Experimental system config BLE_AUDIO enabling LE Audio feature was introduced. Naming convention for BLE Audio functions, structures and files was unified - replaced `bcst` shorthand with `broadcast`. For example, ble_audio_pub_bcst_announcement_feat was renamed to ble_audio_pub_broadcast_announcement_feat. Contents of host/include/ble_audio_common.h was incorporated into host/audio/include/audio/ble_audio.h. Apps and Auracast service were adjusted to new config and include paths. --- .github/test_build_apps_syscfg.yml | 1 + apps/auracast/pkg.yml | 2 +- apps/auracast/syscfg.yml | 4 +- apps/btshell/pkg.yml | 3 + apps/btshell/src/btshell.h | 2 +- apps/btshell/src/cmd_leaudio.c | 4 +- apps/btshell/src/main.c | 6 +- apps/leaudio_broadcaster/pkg.yml | 1 + apps/leaudio_broadcaster/src/main.c | 4 +- apps/leaudio_broadcaster/syscfg.yml | 1 + .../include/audio/ble_audio.h} | 291 +++++++++++++++-- .../audio}/ble_audio_broadcast_source.h | 2 +- .../host/audio/include/host/audio/ble_audio.h | 293 ------------------ .../services/auracast/ble_svc_auracast.h | 4 +- .../{ => audio}/services/auracast/pkg.yml | 3 +- .../services/auracast/src/ble_svc_auracast.c | 2 +- nimble/host/audio/src/ble_audio.c | 25 +- .../src/ble_audio_broadcast_source.c | 2 +- nimble/host/audio/src/ble_audio_priv.h | 2 +- .../src/testcases/ble_audio_base_parse_test.c | 2 +- .../ble_audio_listener_register_test.c | 2 +- nimble/host/pkg.yml | 3 + nimble/host/src/ble_hs.c | 4 +- nimble/host/syscfg.yml | 33 +- 24 files changed, 337 insertions(+), 359 deletions(-) rename nimble/host/{include/host/ble_audio_common.h => audio/include/audio/ble_audio.h} (58%) rename nimble/host/{include/host => audio/include/audio}/ble_audio_broadcast_source.h (99%) delete mode 100644 nimble/host/audio/include/host/audio/ble_audio.h rename nimble/host/{ => audio}/services/auracast/include/services/auracast/ble_svc_auracast.h (98%) rename nimble/host/{ => audio}/services/auracast/pkg.yml (93%) rename nimble/host/{ => audio}/services/auracast/src/ble_svc_auracast.c (98%) rename nimble/host/{ => audio}/src/ble_audio_broadcast_source.c (99%) diff --git a/.github/test_build_apps_syscfg.yml b/.github/test_build_apps_syscfg.yml index faafa8a3cb..aabcc2979d 100644 --- a/.github/test_build_apps_syscfg.yml +++ b/.github/test_build_apps_syscfg.yml @@ -27,6 +27,7 @@ syscfg.vals: BLE_PERIODIC_ADV_SYNC_BIGINFO_REPORTS: 1 BLE_ISO: 1 BLE_ISO_TEST: 1 + BLE_AUDIO: 1 BLE_ISO_BROADCAST_SOURCE: 1 BLE_HCI_VS: 1 BLE_POWER_CONTROL: 1 diff --git a/apps/auracast/pkg.yml b/apps/auracast/pkg.yml index 54eb3be599..fa33aa31f5 100644 --- a/apps/auracast/pkg.yml +++ b/apps/auracast/pkg.yml @@ -30,10 +30,10 @@ pkg.deps: - nimble/host/util - nimble/host/services/gap - nimble/host/store/config + - nimble/host/audio/services/auracast - "@apache-mynewt-core/kernel/os" - "@apache-mynewt-core/sys/console" - "@apache-mynewt-core/sys/log" - "@apache-mynewt-core/sys/stats" - "@apache-mynewt-core/sys/sysinit" - "@apache-mynewt-core/sys/id" - - "@apache-mynewt-nimble/nimble/host/services/auracast" diff --git a/apps/auracast/syscfg.yml b/apps/auracast/syscfg.yml index e67af5a00c..471ee75c0f 100644 --- a/apps/auracast/syscfg.yml +++ b/apps/auracast/syscfg.yml @@ -59,4 +59,6 @@ syscfg.vals: BLE_MAX_BIG: 1 BLE_MAX_BIS: 2 - BLE_PHY_NRF52_HEADERMASK_WORKAROUND: 1 \ No newline at end of file + BLE_PHY_NRF52_HEADERMASK_WORKAROUND: 1 + + BLE_AUDIO: 1 diff --git a/apps/btshell/pkg.yml b/apps/btshell/pkg.yml index d98f541f06..26ef4625b3 100644 --- a/apps/btshell/pkg.yml +++ b/apps/btshell/pkg.yml @@ -36,5 +36,8 @@ pkg.deps: - nimble/host/store/config - nimble/host/util +pkg.deps.BLE_AUDIO: + - nimble/host/audio + pkg.deps.BTSHELL_ANS: - nimble/host/services/ans diff --git a/apps/btshell/src/btshell.h b/apps/btshell/src/btshell.h index c457fd7f9f..c2a2eb3e29 100644 --- a/apps/btshell/src/btshell.h +++ b/apps/btshell/src/btshell.h @@ -29,7 +29,7 @@ #include "host/ble_gatt.h" #include "host/ble_gap.h" #if (MYNEWT_VAL(BLE_ISO_BROADCAST_SOURCE)) -#include "host/ble_audio_broadcast_source.h" +#include "audio/ble_audio_broadcast_source.h" #endif #ifdef __cplusplus diff --git a/apps/btshell/src/cmd_leaudio.c b/apps/btshell/src/cmd_leaudio.c index fc4fcd17a2..2f31246cf8 100644 --- a/apps/btshell/src/cmd_leaudio.c +++ b/apps/btshell/src/cmd_leaudio.c @@ -17,13 +17,13 @@ * under the License. */ -#include "host/ble_audio_broadcast_source.h" #include "cmd_leaudio.h" #include "btshell.h" #include "console/console.h" #include "errno.h" -#if (MYNEWT_VAL(BLE_ISO_BROADCAST_SOURCE)) +#if (MYNEWT_VAL(BLE_AUDIO)) +#include "audio/ble_audio_broadcast_source.h" int cmd_leaudio_base_add(int argc, char **argv) { diff --git a/apps/btshell/src/main.c b/apps/btshell/src/main.c index 6424bf6b86..c7a413a4a8 100644 --- a/apps/btshell/src/main.c +++ b/apps/btshell/src/main.c @@ -41,8 +41,10 @@ #include "host/ble_gatt.h" #include "host/ble_store.h" #include "host/ble_sm.h" -#include "host/ble_audio_common.h" -#include "host/ble_audio_broadcast_source.h" +#if MYNEWT_VAL(BLE_AUDIO) +#include "audio/ble_audio_broadcast_source.h" +#include "audio/ble_audio.h" +#endif #include "host/util/util.h" /* Mandatory services. */ diff --git a/apps/leaudio_broadcaster/pkg.yml b/apps/leaudio_broadcaster/pkg.yml index 0955da906b..95439284c7 100644 --- a/apps/leaudio_broadcaster/pkg.yml +++ b/apps/leaudio_broadcaster/pkg.yml @@ -30,6 +30,7 @@ pkg.deps: - nimble/host/util - nimble/host/services/gap - nimble/host/store/config + - nimble/host/audio - "@apache-mynewt-core/kernel/os" - "@apache-mynewt-core/sys/console" - "@apache-mynewt-core/sys/log" diff --git a/apps/leaudio_broadcaster/src/main.c b/apps/leaudio_broadcaster/src/main.c index a4e7bf98ea..94c278332b 100644 --- a/apps/leaudio_broadcaster/src/main.c +++ b/apps/leaudio_broadcaster/src/main.c @@ -24,8 +24,8 @@ #include "host/ble_hs.h" #include "host/util/util.h" -#include "host/ble_audio_broadcast_source.h" -#include "host/ble_audio_common.h" +#include "audio/ble_audio_broadcast_source.h" +#include "audio/ble_audio.h" #include "host/ble_iso.h" #include "hal/hal_gpio.h" diff --git a/apps/leaudio_broadcaster/syscfg.yml b/apps/leaudio_broadcaster/syscfg.yml index bed16f05d2..85a817d112 100644 --- a/apps/leaudio_broadcaster/syscfg.yml +++ b/apps/leaudio_broadcaster/syscfg.yml @@ -52,6 +52,7 @@ syscfg.vals: MSYS_1_BLOCK_COUNT: 32 BLE_VERSION: 54 + BLE_AUDIO: 1 BLE_ISO: 1 BLE_ISO_BROADCAST_SOURCE: 1 BLE_MAX_BIG: 1 diff --git a/nimble/host/include/host/ble_audio_common.h b/nimble/host/audio/include/audio/ble_audio.h similarity index 58% rename from nimble/host/include/host/ble_audio_common.h rename to nimble/host/audio/include/audio/ble_audio.h index 05780c0797..c1ce1dc9c8 100644 --- a/nimble/host/include/host/ble_audio_common.h +++ b/nimble/host/audio/include/audio/ble_audio.h @@ -17,26 +17,16 @@ * under the License. */ -#ifndef H_BLE_AUDIO_COMMON_ -#define H_BLE_AUDIO_COMMON_ +#ifndef H_BLE_AUDIO_ +#define H_BLE_AUDIO_ -/** - * @file ble_audio_common.h - * - * @brief Bluetooth Low Energy Audio Common API - * - * @defgroup bt_le_audio_common Bluetooth LE Audio Common - * @ingroup bt_host - * @{ - */ - -#include "stdint.h" -#include "os/queue.h" +#include +#include /** * @cond * Helper macros for BLE_AUDIO_BUILD_CODEC_CONFIG - * @{ + * @private @{ */ #define FIELD_LEN_2(_len, _type, _field) _len, _type, _field, #define FIELD_LEN_5(_len, _type, _field) _len, _type, _field, \ @@ -276,6 +266,271 @@ struct ble_audio_codec_id { uint16_t vendor_specific; }; +/** @brief Public Broadcast Announcement features bits */ +enum ble_audio_pub_broadcast_announcement_feat { + /** Broadcast Stream Encryption */ + BLE_AUDIO_PUB_BROADCAST_ANNOUNCEMENT_FEAT_ENCRYPTION = 1 << 0, + + /** Standard Quality Public Broadcast Audio */ + BLE_AUDIO_PUB_BROADCAST_ANNOUNCEMENT_FEAT_SQ = 1 << 1, + + /** High Quality Public Broadcast Audio */ + BLE_AUDIO_PUB_BROADCAST_ANNOUNCEMENT_FEAT_HQ = 1 << 2, +}; + +/** @brief Public Broadcast Announcement structure */ +struct ble_audio_pub_broadcast_announcement { + /** Public Broadcast Announcement features bitfield */ + enum ble_audio_pub_broadcast_announcement_feat features; + + /** Metadata length */ + uint8_t metadata_len; + + /** Metadata */ + const uint8_t *metadata; +}; + +struct ble_audio_broadcast_name { + /** Broadcast Name length */ + uint8_t name_len; + + /** Broadcast Name */ + const char *name; +}; + +/** + * @defgroup ble_audio_events Bluetooth Low Energy Audio Events + * @{ + */ + +/** BLE Audio event: Broadcast Announcement */ +#define BLE_AUDIO_EVENT_BROADCAST_ANNOUNCEMENT 0 + +/** @} */ + +/** @brief Broadcast Announcement */ +struct ble_audio_event_broadcast_announcement { + /** Extended advertising report */ + const struct ble_gap_ext_disc_desc *ext_disc; + + /** Broadcast ID */ + uint32_t broadcast_id; + + /** Additional service data included in Broadcast Audio Announcement */ + const uint8_t *svc_data; + + /** Additional service data length */ + uint16_t svc_data_len; + + /** Optional Public Broadcast Announcement data */ + struct ble_audio_pub_broadcast_announcement *pub_announcement_data; + + /** Optional Broadcast Name */ + struct ble_audio_broadcast_name *name; +}; + +/** + * Represents a BLE Audio related event. When such an event occurs, the host + * notifies the application by passing an instance of this structure to an + * application-specified callback. + */ +struct ble_audio_event { + /** + * Indicates the type of BLE Audio event that occurred. This is one of the + * BLE_AUDIO_EVENT codes. + */ + uint8_t type; + + /** + * A discriminated union containing additional details concerning the event. + * The 'type' field indicates which member of the union is valid. + */ + union { + /** + * @ref BLE_AUDIO_EVENT_BROADCAST_ANNOUNCEMENT + * + * Represents a received Broadcast Announcement. + */ + struct ble_audio_event_broadcast_announcement broadcast_announcement; + }; +}; + +/** Callback function type for handling BLE Audio events. */ +typedef int ble_audio_event_fn(struct ble_audio_event *event, void *arg); + +/** + * Event listener structure + * + * This should be used as an opaque structure and not modified manually. + */ +struct ble_audio_event_listener { + /** The function to call when a BLE Audio event occurs. */ + ble_audio_event_fn *fn; + + /** An optional argument to pass to the event handler function. */ + void *arg; + + /** Singly-linked list entry. */ + SLIST_ENTRY(ble_audio_event_listener) next; +}; + +/** + * Registers listener for BLE Audio events + * + * On success listener structure will be initialized automatically and does not + * need to be initialized prior to calling this function. To change callback + * and/or argument unregister listener first and register it again. + * + * @param[in] listener Listener structure + * @param[in] event_mask Optional event mask + * @param[in] fn Callback function + * @param[in] arg Optional callback argument + * + * @return 0 on success + * BLE_HS_EINVAL if no callback is specified + * BLE_HS_EALREADY if listener is already registered + */ +int ble_audio_event_listener_register(struct ble_audio_event_listener *listener, + ble_audio_event_fn *fn, void *arg); + +/** + * Unregisters listener for BLE Audio events + * + * @param[in] listener Listener structure + * + * @return 0 on success + * BLE_HS_ENOENT if listener was not registered + */ +int ble_audio_event_listener_unregister(struct ble_audio_event_listener *listener); + +/** + * BASE iterator + * + * The iterator structure used by @ref ble_audio_base_subgroup_iter and + * @ble_audio_base_bis_iter functions to iterate the BASE Level 2 and 3 elements + * (Subgroups and BISes). + * This should be used as an opaque structure and not modified manually. + * + * Example: + * @code{.c} + * struct ble_audio_base_iter subgroup_iter; + * struct ble_audio_base_iter bis_iter; + * struct ble_audio_base_group group; + * struct ble_audio_base_subgroup subgroup; + * struct ble_audio_base_bis bis; + * + * rc = ble_audio_base_parse(data, data_size, &group, &subgroup_iter); + * if (rc == 0) { + * for (uint8_t i = 0; i < group->num_subgroups; i++) { + * rc = ble_audio_base_subgroup_iter(&subgroup_iter, &subgroup, &bis_iter); + * if (rc == 0) { + * for (uint8_t j = 0; j < subgroup->num_bis; j++) { + * rc = ble_audio_base_bis_iter(&bis_iter, &bis); + * if (rc == 0) { + * foo(&group, &subgroup, &bis); + * } + * } + * } + * } + * } + * @endcode + */ +struct ble_audio_base_iter { + /** Data pointer */ + const uint8_t *data; + + /** Base length */ + uint8_t buf_len; + + /** Original BASE pointer */ + const uint8_t *buf; + + /** Remaining number of elements */ + uint8_t num_elements; +}; + +/** @brief Broadcast Audio Source Endpoint Group structure */ +struct ble_audio_base_group { + /** Presentation Delay */ + uint32_t presentation_delay; + + /** Number of subgroups */ + uint8_t num_subgroups; +}; + +/** + * Parse the BASE received from Basic Audio Announcement data. + * + * @param[in] data Pointer to the BASE data buffer to parse. + * @param[in] data_len Length of the BASE data buffer. + * @param[out] group Group object. + * @param[out] subgroup_iter Subgroup iterator object. + * + * @return 0 on success; nonzero on failure. + */ +int ble_audio_base_parse(const uint8_t *data, uint8_t data_len, + struct ble_audio_base_group *group, + struct ble_audio_base_iter *subgroup_iter); + +/** @brief Broadcast Audio Source Endpoint Subgroup structure */ +struct ble_audio_base_subgroup { + /** Codec information for the subgroup */ + struct ble_audio_codec_id codec_id; + + /** Length of the Codec Specific Configuration for the subgroup */ + uint8_t codec_spec_config_len; + + /** Codec Specific Configuration for the subgroup */ + const uint8_t *codec_spec_config; + + /** Length of the Metadata for the subgroup */ + uint8_t metadata_len; + + /** Series of LTV structures containing Metadata */ + const uint8_t *metadata; + + /** Number of BISes in the subgroup */ + uint8_t num_bis; +}; + +/** + * @brief Basic Audio Announcement Subgroup information + * + * @param[in] subgroup_iter Subgroup iterator object. + * @param[out] subgroup Subgroup object. + * @param[out] bis_iter BIS iterator object. + * + * @return 0 on success; + * A non-zero value on failure. + */ +int ble_audio_base_subgroup_iter(struct ble_audio_base_iter *subgroup_iter, + struct ble_audio_base_subgroup *subgroup, + struct ble_audio_base_iter *bis_iter); + +/** @brief Broadcast Audio Source Endpoint BIS structure */ +struct ble_audio_base_bis { + /** BIS_index value for the BIS */ + uint8_t index; + + /** Length of the Codec Specific Configuration for the BIS */ + uint8_t codec_spec_config_len; + + /** Codec Specific Configuration for the BIS */ + const uint8_t *codec_spec_config; +}; + +/** + * @brief Basic Audio Announcement Subgroup information + * + * @param[in] bis_iter BIS iterator object. + * @param[out] bis BIS object. + * + * @return 0 on success; + * A non-zero value on failure. + */ +int ble_audio_base_bis_iter(struct ble_audio_base_iter *bis_iter, + struct ble_audio_base_bis *bis); + /** Broadcast Isochronous Streams (BIS) */ struct ble_audio_bis { /** Pointer to next BIS in subgroup */ @@ -333,8 +588,4 @@ struct ble_audio_base { STAILQ_HEAD(, ble_audio_big_subgroup) subs; }; -/** - * @} - */ - -#endif /* H_BLE_AUDIO_COMMON_ */ +#endif /* H_BLE_AUDIO_ */ diff --git a/nimble/host/include/host/ble_audio_broadcast_source.h b/nimble/host/audio/include/audio/ble_audio_broadcast_source.h similarity index 99% rename from nimble/host/include/host/ble_audio_broadcast_source.h rename to nimble/host/audio/include/audio/ble_audio_broadcast_source.h index 605aa5b207..839449cbe3 100644 --- a/nimble/host/include/host/ble_audio_broadcast_source.h +++ b/nimble/host/audio/include/audio/ble_audio_broadcast_source.h @@ -33,7 +33,7 @@ #include #include "host/ble_gap.h" #include "host/ble_iso.h" -#include "host/ble_audio_common.h" +#include "ble_audio.h" /** Parameters used for creating BASE configuration. */ struct ble_broadcast_create_params { diff --git a/nimble/host/audio/include/host/audio/ble_audio.h b/nimble/host/audio/include/host/audio/ble_audio.h deleted file mode 100644 index 7d4200bb03..0000000000 --- a/nimble/host/audio/include/host/audio/ble_audio.h +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef H_BLE_AUDIO_ -#define H_BLE_AUDIO_ - -#include -#include - -#include "host/ble_audio_common.h" - -/** @brief Public Broadcast Announcement features bits */ -enum ble_audio_pub_bcst_announcement_feat { - /** Broadcast Stream Encryption */ - BLE_AUDIO_PUB_BCST_ANNOUNCEMENT_FEAT_ENCRYPTION = 1 << 0, - - /** Standard Quality Public Broadcast Audio */ - BLE_AUDIO_PUB_BCST_ANNOUNCEMENT_FEAT_SQ = 1 << 1, - - /** High Quality Public Broadcast Audio */ - BLE_AUDIO_PUB_BCST_ANNOUNCEMENT_FEAT_HQ = 1 << 2, -}; - -/** @brief Public Broadcast Announcement structure */ -struct ble_audio_pub_bcst_announcement { - /** Public Broadcast Announcement features bitfield */ - enum ble_audio_pub_bcst_announcement_feat features; - - /** Metadata length */ - uint8_t metadata_len; - - /** Metadata */ - const uint8_t *metadata; -}; - -struct ble_audio_bcst_name { - /** Broadcast Name length */ - uint8_t name_len; - - /** Broadcast Name */ - const char *name; -}; - -/** - * @defgroup ble_audio_events Bluetooth Low Energy Audio Events - * @{ - */ - -/** BLE Audio event: Broadcast Announcement */ -#define BLE_AUDIO_EVENT_BCST_ANNOUNCEMENT 0 - -/** @} */ - -/** @brief Broadcast Announcement */ -struct ble_audio_event_bcst_announcement { - /** Extended advertising report */ - const struct ble_gap_ext_disc_desc *ext_disc; - - /** Broadcast ID */ - uint32_t broadcast_id; - - /** Additional service data included in Broadcast Audio Announcement */ - const uint8_t *svc_data; - - /** Additional service data length */ - uint16_t svc_data_len; - - /** Optional Public Broadcast Announcement data */ - struct ble_audio_pub_bcst_announcement *pub_announcement_data; - - /** Optional Broadcast Name */ - struct ble_audio_bcst_name *name; -}; - -/** - * Represents a BLE Audio related event. When such an event occurs, the host - * notifies the application by passing an instance of this structure to an - * application-specified callback. - */ -struct ble_audio_event { - /** - * Indicates the type of BLE Audio event that occurred. This is one of the - * BLE_AUDIO_EVENT codes. - */ - uint8_t type; - - /** - * A discriminated union containing additional details concerning the event. - * The 'type' field indicates which member of the union is valid. - */ - union { - /** - * @ref BLE_AUDIO_EVENT_BCST_ANNOUNCEMENT - * - * Represents a received Broadcast Announcement. - */ - struct ble_audio_event_bcst_announcement bcst_announcement; - }; -}; - -/** Callback function type for handling BLE Audio events. */ -typedef int ble_audio_event_fn(struct ble_audio_event *event, void *arg); - -/** - * Event listener structure - * - * This should be used as an opaque structure and not modified manually. - */ -struct ble_audio_event_listener { - /** The function to call when a BLE Audio event occurs. */ - ble_audio_event_fn *fn; - - /** An optional argument to pass to the event handler function. */ - void *arg; - - /** Singly-linked list entry. */ - SLIST_ENTRY(ble_audio_event_listener) next; -}; - -/** - * Registers listener for BLE Audio events - * - * On success listener structure will be initialized automatically and does not - * need to be initialized prior to calling this function. To change callback - * and/or argument unregister listener first and register it again. - * - * @param[in] listener Listener structure - * @param[in] event_mask Optional event mask - * @param[in] fn Callback function - * @param[in] arg Optional callback argument - * - * @return 0 on success - * BLE_HS_EINVAL if no callback is specified - * BLE_HS_EALREADY if listener is already registered - */ -int ble_audio_event_listener_register(struct ble_audio_event_listener *listener, - ble_audio_event_fn *fn, void *arg); - -/** - * Unregisters listener for BLE Audio events - * - * @param[in] listener Listener structure - * - * @return 0 on success - * BLE_HS_ENOENT if listener was not registered - */ -int ble_audio_event_listener_unregister(struct ble_audio_event_listener *listener); - -/** - * BASE iterator - * - * The iterator structure used by @ref ble_audio_base_subgroup_iter and - * @ble_audio_base_bis_iter functions to iterate the BASE Level 2 and 3 elements - * (Subgroups and BISes). - * This should be used as an opaque structure and not modified manually. - * - * Example: - * @code{.c} - * struct ble_audio_base_iter subgroup_iter; - * struct ble_audio_base_iter bis_iter; - * struct ble_audio_base_group group; - * struct ble_audio_base_subgroup subgroup; - * struct ble_audio_base_bis bis; - * - * rc = ble_audio_base_parse(data, data_size, &group, &subgroup_iter); - * if (rc == 0) { - * for (uint8_t i = 0; i < group->num_subgroups; i++) { - * rc = ble_audio_base_subgroup_iter(&subgroup_iter, &subgroup, &bis_iter); - * if (rc == 0) { - * for (uint8_t j = 0; j < subgroup->num_bis; j++) { - * rc = ble_audio_base_bis_iter(&bis_iter, &bis); - * if (rc == 0) { - * foo(&group, &subgroup, &bis); - * } - * } - * } - * } - * } - * @endcode - */ -struct ble_audio_base_iter { - /** Data pointer */ - const uint8_t *data; - - /** Base length */ - uint8_t buf_len; - - /** Original BASE pointer */ - const uint8_t *buf; - - /** Remaining number of elements */ - uint8_t num_elements; -}; - -/** @brief Broadcast Audio Source Endpoint Group structure */ -struct ble_audio_base_group { - /** Presentation Delay */ - uint32_t presentation_delay; - - /** Number of subgroups */ - uint8_t num_subgroups; -}; - -/** - * Parse the BASE received from Basic Audio Announcement data. - * - * @param[in] data Pointer to the BASE data buffer to parse. - * @param[in] data_len Length of the BASE data buffer. - * @param[out] group Group object. - * @param[out] subgroup_iter Subgroup iterator object. - * - * @return 0 on success; nonzero on failure. - */ -int ble_audio_base_parse(const uint8_t *data, uint8_t data_len, - struct ble_audio_base_group *group, - struct ble_audio_base_iter *subgroup_iter); - -/** @brief Broadcast Audio Source Endpoint Subgroup structure */ -struct ble_audio_base_subgroup { - /** Codec information for the subgroup */ - struct ble_audio_codec_id codec_id; - - /** Length of the Codec Specific Configuration for the subgroup */ - uint8_t codec_spec_config_len; - - /** Codec Specific Configuration for the subgroup */ - const uint8_t *codec_spec_config; - - /** Length of the Metadata for the subgroup */ - uint8_t metadata_len; - - /** Series of LTV structures containing Metadata */ - const uint8_t *metadata; - - /** Number of BISes in the subgroup */ - uint8_t num_bis; -}; - -/** - * @brief Basic Audio Announcement Subgroup information - * - * @param[in] subgroup_iter Subgroup iterator object. - * @param[out] subgroup Subgroup object. - * @param[out] bis_iter BIS iterator object. - * - * @return 0 on success; - * A non-zero value on failure. - */ -int ble_audio_base_subgroup_iter(struct ble_audio_base_iter *subgroup_iter, - struct ble_audio_base_subgroup *subgroup, - struct ble_audio_base_iter *bis_iter); - -/** @brief Broadcast Audio Source Endpoint BIS structure */ -struct ble_audio_base_bis { - /** BIS_index value for the BIS */ - uint8_t index; - - /** Length of the Codec Specific Configuration for the BIS */ - uint8_t codec_spec_config_len; - - /** Codec Specific Configuration for the BIS */ - const uint8_t *codec_spec_config; -}; - -/** - * @brief Basic Audio Announcement Subgroup information - * - * @param[in] bis_iter BIS iterator object. - * @param[out] bis BIS object. - * - * @return 0 on success; - * A non-zero value on failure. - */ -int ble_audio_base_bis_iter(struct ble_audio_base_iter *bis_iter, - struct ble_audio_base_bis *bis); - -#endif /* H_BLE_AUDIO_ */ diff --git a/nimble/host/services/auracast/include/services/auracast/ble_svc_auracast.h b/nimble/host/audio/services/auracast/include/services/auracast/ble_svc_auracast.h similarity index 98% rename from nimble/host/services/auracast/include/services/auracast/ble_svc_auracast.h rename to nimble/host/audio/services/auracast/include/services/auracast/ble_svc_auracast.h index 560adb8b19..900b6fddaa 100644 --- a/nimble/host/services/auracast/include/services/auracast/ble_svc_auracast.h +++ b/nimble/host/audio/services/auracast/include/services/auracast/ble_svc_auracast.h @@ -19,8 +19,8 @@ #include #include "host/ble_gap.h" -#include "host/ble_audio_common.h" -#include "host/ble_audio_broadcast_source.h" +#include "audio/ble_audio.h" +#include "audio/ble_audio_broadcast_source.h" struct ble_svc_auracast_create_params { /** Broadcast Audio Source Endpoint */ diff --git a/nimble/host/services/auracast/pkg.yml b/nimble/host/audio/services/auracast/pkg.yml similarity index 93% rename from nimble/host/services/auracast/pkg.yml rename to nimble/host/audio/services/auracast/pkg.yml index a4d0013f93..a2533b29da 100644 --- a/nimble/host/services/auracast/pkg.yml +++ b/nimble/host/audio/services/auracast/pkg.yml @@ -16,7 +16,7 @@ # under the License. # -pkg.name: nimble/host/services/auracast +pkg.name: nimble/host/audio/services/auracast pkg.description: Implements Auracast service pkg.author: "Apache Mynewt " pkg.homepage: "http://mynewt.apache.org/" @@ -28,3 +28,4 @@ pkg.keywords: pkg.deps: - nimble/host + - nimble/host/audio diff --git a/nimble/host/services/auracast/src/ble_svc_auracast.c b/nimble/host/audio/services/auracast/src/ble_svc_auracast.c similarity index 98% rename from nimble/host/services/auracast/src/ble_svc_auracast.c rename to nimble/host/audio/services/auracast/src/ble_svc_auracast.c index 7bd9112dfc..b323e64bf0 100644 --- a/nimble/host/services/auracast/src/ble_svc_auracast.c +++ b/nimble/host/audio/services/auracast/src/ble_svc_auracast.c @@ -21,7 +21,7 @@ #include "host/ble_gap.h" #include "host/ble_hs.h" -#include "host/ble_audio_broadcast_source.h" +#include "audio/ble_audio_broadcast_source.h" #include "services/auracast/ble_svc_auracast.h" int diff --git a/nimble/host/audio/src/ble_audio.c b/nimble/host/audio/src/ble_audio.c index 61c42e4ff8..f7597aaf72 100644 --- a/nimble/host/audio/src/ble_audio.c +++ b/nimble/host/audio/src/ble_audio.c @@ -21,7 +21,7 @@ #include #include "host/ble_hs.h" -#include "host/audio/ble_audio.h" +#include "audio/ble_audio.h" #include "ble_audio_priv.h" @@ -29,24 +29,23 @@ static struct ble_gap_event_listener ble_audio_gap_event_listener; static SLIST_HEAD(, ble_audio_event_listener) ble_audio_event_listener_list = SLIST_HEAD_INITIALIZER(ble_audio_event_listener_list); -struct ble_audio_adv_parse_bcst_announcement_data { +struct ble_audio_adv_parse_broadcast_announcement_data { struct ble_audio_event event; - struct ble_audio_pub_bcst_announcement pub; - struct ble_audio_bcst_name name; + struct ble_audio_pub_broadcast_announcement pub; + struct ble_audio_broadcast_name name; bool success; }; static int -ble_audio_adv_parse_bcst_announcement(const struct ble_hs_adv_field *field, - void *user_data) +ble_audio_adv_parse_broadcast_announcement(const struct ble_hs_adv_field *field, void *user_data) { - struct ble_audio_adv_parse_bcst_announcement_data *data = user_data; - struct ble_audio_event_bcst_announcement *event; + struct ble_audio_adv_parse_broadcast_announcement_data *data = user_data; + struct ble_audio_event_broadcast_announcement *event; const uint8_t value_len = field->length - sizeof(field->length); ble_uuid16_t uuid16 = BLE_UUID16_INIT(0); uint8_t offset = 0; - event = &data->event.bcst_announcement; + event = &data->event.broadcast_announcement; data->success = false; @@ -139,15 +138,15 @@ ble_audio_gap_event(struct ble_gap_event *gap_event, void *arg) { switch (gap_event->type) { case BLE_GAP_EVENT_EXT_DISC: { - struct ble_audio_adv_parse_bcst_announcement_data data = { 0 }; + struct ble_audio_adv_parse_broadcast_announcement_data data = { 0 }; int rc; rc = ble_hs_adv_parse(gap_event->ext_disc.data, gap_event->ext_disc.length_data, - ble_audio_adv_parse_bcst_announcement, &data); + ble_audio_adv_parse_broadcast_announcement, &data); if (rc == 0 && data.success) { - data.event.type = BLE_AUDIO_EVENT_BCST_ANNOUNCEMENT; - data.event.bcst_announcement.ext_disc = &gap_event->ext_disc; + data.event.type = BLE_AUDIO_EVENT_BROADCAST_ANNOUNCEMENT; + data.event.broadcast_announcement.ext_disc = &gap_event->ext_disc; (void)ble_audio_event_listener_call(&data.event); } diff --git a/nimble/host/src/ble_audio_broadcast_source.c b/nimble/host/audio/src/ble_audio_broadcast_source.c similarity index 99% rename from nimble/host/src/ble_audio_broadcast_source.c rename to nimble/host/audio/src/ble_audio_broadcast_source.c index 2891658182..0afdbc550e 100644 --- a/nimble/host/src/ble_audio_broadcast_source.c +++ b/nimble/host/audio/src/ble_audio_broadcast_source.c @@ -18,7 +18,7 @@ */ #include "host/ble_uuid.h" -#include "host/ble_audio_broadcast_source.h" +#include "audio/ble_audio_broadcast_source.h" #include "os/util.h" diff --git a/nimble/host/audio/src/ble_audio_priv.h b/nimble/host/audio/src/ble_audio_priv.h index bedbdaf058..10f0109ddc 100644 --- a/nimble/host/audio/src/ble_audio_priv.h +++ b/nimble/host/audio/src/ble_audio_priv.h @@ -20,7 +20,7 @@ #ifndef H_BLE_AUDIO_PRIV_ #define H_BLE_AUDIO_PRIV_ -#include "host/audio/ble_audio.h" +#include "audio/ble_audio.h" int ble_audio_event_listener_call(struct ble_audio_event *event); diff --git a/nimble/host/audio/test/src/testcases/ble_audio_base_parse_test.c b/nimble/host/audio/test/src/testcases/ble_audio_base_parse_test.c index 2398d62dd2..3231b8539b 100644 --- a/nimble/host/audio/test/src/testcases/ble_audio_base_parse_test.c +++ b/nimble/host/audio/test/src/testcases/ble_audio_base_parse_test.c @@ -20,7 +20,7 @@ #include "testutil/testutil.h" #include "host/ble_hs.h" -#include "host/audio/ble_audio.h" +#include "audio/ble_audio.h" /** * BAP_v1.0.1 Table 3.16 diff --git a/nimble/host/audio/test/src/testcases/ble_audio_listener_register_test.c b/nimble/host/audio/test/src/testcases/ble_audio_listener_register_test.c index f55b51a3c3..363632ecba 100644 --- a/nimble/host/audio/test/src/testcases/ble_audio_listener_register_test.c +++ b/nimble/host/audio/test/src/testcases/ble_audio_listener_register_test.c @@ -20,7 +20,7 @@ #include "testutil/testutil.h" #include "host/ble_hs.h" -#include "host/audio/ble_audio.h" +#include "audio/ble_audio.h" static struct ble_audio_event_listener event_listener; diff --git a/nimble/host/pkg.yml b/nimble/host/pkg.yml index cab496caed..edad3781de 100644 --- a/nimble/host/pkg.yml +++ b/nimble/host/pkg.yml @@ -32,6 +32,9 @@ pkg.deps: - nimble - nimble/transport +pkg.deps.BLE_ISO: + - nimble/host/audio + pkg.deps.BLE_SM_LEGACY: - "@apache-mynewt-core/crypto/tinycrypt" diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c index d084c041a1..147837d9f3 100644 --- a/nimble/host/src/ble_hs.c +++ b/nimble/host/src/ble_hs.c @@ -24,7 +24,9 @@ #include "syscfg/syscfg.h" #include "stats/stats.h" #include "host/ble_hs.h" -#include "host/ble_audio_broadcast_source.h" +#if MYNEWT_VAL(BLE_ISO_BROADCAST_SOURCE) +#include "audio/ble_audio_broadcast_source.h" +#endif #include "ble_hs_priv.h" #include "ble_iso_priv.h" #include "nimble/nimble_npl.h" diff --git a/nimble/host/syscfg.yml b/nimble/host/syscfg.yml index faaaa0052d..897c640e90 100644 --- a/nimble/host/syscfg.yml +++ b/nimble/host/syscfg.yml @@ -440,6 +440,11 @@ syscfg.defs: that have been enabled in the stack, such as GATT support. value: 0 + BLE_AUDIO: + description: 'This option enables Bluetooth LE Audio support' + value: 0 + experimental: 1 + # Flow control settings. BLE_HS_FLOW_CTRL: description: > @@ -493,20 +498,6 @@ syscfg.defs: supported by host. value: 0 - BLE_MAX_BIG: - desciptrion: > - Number of available BIGs - value: 'MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES' - restrictions: - - 'BLE_ISO_BROADCAST_SOURCE if 0' - - BLE_MAX_BIS: - description: > - Number of supported BISes - value: 4 - restrictions: - - 'BLE_ISO_BROADCAST_SOURCE if 0' - ### Log settings. BLE_HS_LOG_MOD: @@ -523,6 +514,20 @@ syscfg.defs: description: 'Minimum level for the BLE EATT log.' value: 1 + BLE_MAX_BIG: + desciptrion: > + Number of available BIGs + value: 'MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES' + restrictions: + - 'BLE_ISO_BROADCAST_SOURCE if 0' + + BLE_MAX_BIS: + description: > + Number of supported BISes + value: 4 + restrictions: + - 'BLE_ISO_BROADCAST_SOURCE if 0' + syscfg.logs: BLE_HS_LOG: module: MYNEWT_VAL(BLE_HS_LOG_MOD)