From 893f49ea887bb4e6da95e9ba4d6ac90185dc46af Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Fri, 20 May 2022 08:07:33 +0200 Subject: [PATCH] Bluetooth: audio: Build PACS only if Sink or Source enabled This fixes Kconfig that allowed to build PACS without support for sink or source PACS. Few conditionals that no longer apply were removed. Enabling ASCS support in specific direction enables related PACS support. Since PACS does `depends on` anything, it's safe to make use of `select` statement. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/audio/Kconfig.ascs | 9 ++++++++- subsys/bluetooth/audio/Kconfig.baps | 8 -------- subsys/bluetooth/audio/Kconfig.pacs | 28 ++++++++++++++++------------ subsys/bluetooth/audio/pacs.c | 18 ++++-------------- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/subsys/bluetooth/audio/Kconfig.ascs b/subsys/bluetooth/audio/Kconfig.ascs index 4e16fb5c81b..dd3db017ad5 100644 --- a/subsys/bluetooth/audio/Kconfig.ascs +++ b/subsys/bluetooth/audio/Kconfig.ascs @@ -8,7 +8,6 @@ config BT_ASCS bool "Audio Stream Control Service Support" - depends on BT_PACS select BT_SMP_SC_PAIR_ONLY help This option enables support for Audio Stream Control Service. @@ -29,4 +28,12 @@ config BT_ASCS_ASE_SRC_COUNT help An ASE Source characteristic represents the state of an ASE, which is coupled to a single direction of a unicast Audio Stream. + +config BT_ASCS_ASE_SNK + def_bool BT_ASCS_ASE_SNK_COUNT > 0 + select BT_PAC_SNK + +config BT_ASCS_ASE_SRC + def_bool BT_ASCS_ASE_SRC_COUNT > 0 + select BT_PAC_SRC endif # BT_ASCS diff --git a/subsys/bluetooth/audio/Kconfig.baps b/subsys/bluetooth/audio/Kconfig.baps index 4d7e028eff5..0a91bd8cf9f 100644 --- a/subsys/bluetooth/audio/Kconfig.baps +++ b/subsys/bluetooth/audio/Kconfig.baps @@ -20,7 +20,6 @@ config BT_AUDIO_UNICAST_SERVER select BT_ISO_PERIPHERAL select BT_GATT_DYNAMIC_DB select BT_GATT_CACHING - select BT_PACS select BT_ASCS help This option enables support for Bluetooth Unicast Audio Server @@ -185,13 +184,6 @@ config BT_AUDIO_BROADCAST_SNK_STREAM_COUNT endif # BT_AUDIO_BROADCAST_SINK -config BT_DEBUG_PACS - bool "Published Audio Capabilities Service debug" - depends on BT_PACS - help - Use this option to enable Published Audio Capabilities Service debug - logs for the Bluetooth Audio functionality. - config BT_AUDIO_DEBUG_STREAM bool "Bluetooth Audio Stream debug" depends on BT_AUDIO_STREAM diff --git a/subsys/bluetooth/audio/Kconfig.pacs b/subsys/bluetooth/audio/Kconfig.pacs index d8f10889ff1..09b6e3724b9 100644 --- a/subsys/bluetooth/audio/Kconfig.pacs +++ b/subsys/bluetooth/audio/Kconfig.pacs @@ -5,18 +5,12 @@ # SPDX-License-Identifier: Apache-2.0 # -config BT_PACS - bool "Published Audio Capabilities Service Support" - select BT_SMP_SC_PAIR_ONLY - help - This option enables support for Published Audio Capabilities Service. +menu "Published Audio Capabilities (PAC) options" -if BT_PACS config BT_PAC_SNK bool "Sink PAC Characteristic Support" - default y if BT_ASCS help - This option enables support for Sink PAC Characteristic. + This option enables support for Sink Published Audio Capabilities. if BT_PAC_SNK config BT_PACS_SNK_CONTEXT @@ -55,10 +49,8 @@ endif # BT_PACS_SNK config BT_PAC_SRC bool "Source PAC Characteristic Support" - default y if BT_ASCS - default y help - This option enables support for Source PAC Characteristic. + This option enables support for Source Published Audio Capabilities. if BT_PAC_SRC config BT_PACS_SRC_CONTEXT @@ -94,4 +86,16 @@ config BT_PAC_SRC_LOC_WRITEABLE Location Characteristic. endif # BT_PAC_SRC -endif # BT_PACS + +config BT_PACS + def_bool BT_PAC_SNK || BT_PAC_SRC + select BT_SMP_SC_PAIR_ONLY + +config BT_DEBUG_PACS + bool "Published Audio Capabilities Service debug" + depends on BT_PACS + help + Use this option to enable Published Audio Capabilities Service debug + logs for the Bluetooth Audio functionality. + +endmenu diff --git a/subsys/bluetooth/audio/pacs.c b/subsys/bluetooth/audio/pacs.c index 566c920f40b..f2b81dc67ce 100644 --- a/subsys/bluetooth/audio/pacs.c +++ b/subsys/bluetooth/audio/pacs.c @@ -31,7 +31,6 @@ #define PAC_NOTIFY_TIMEOUT K_MSEC(10) -#if defined(CONFIG_BT_PAC_SNK) || defined(CONFIG_BT_PAC_SRC) NET_BUF_SIMPLE_DEFINE_STATIC(read_buf, CONFIG_BT_L2CAP_TX_MTU); static void pac_data_add(struct net_buf_simple *buf, uint8_t num, @@ -157,12 +156,10 @@ static ssize_t supported_context_read(struct bt_conn *conn, void *buf, uint16_t len, uint16_t offset) { struct bt_pacs_context context = { -#if defined(CONFIG_BT_PAC_SNK) - .snk = sys_cpu_to_le16(CONFIG_BT_PACS_SNK_CONTEXT), -#endif -#if defined(CONFIG_BT_PAC_SRC) - .src = sys_cpu_to_le16(CONFIG_BT_PACS_SRC_CONTEXT), -#endif + .snk = COND_CODE_1(CONFIG_BT_PAC_SNK, + (sys_cpu_to_le16(CONFIG_BT_PACS_SNK_CONTEXT)), (0)), + .src = COND_CODE_1(CONFIG_BT_PAC_SRC, + (sys_cpu_to_le16(CONFIG_BT_PACS_SRC_CONTEXT)), (0)), }; BT_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, @@ -194,7 +191,6 @@ static int get_pac_loc(struct bt_conn *conn, enum bt_audio_dir dir, return 0; } #endif /* CONFIG_BT_PAC_SNK_LOC || CONFIG_BT_PAC_SRC_LOC */ -#endif /* CONFIG_BT_PAC_SNK || CONFIG_BT_PAC_SRC */ #if defined(CONFIG_BT_PAC_SNK) static struct k_work_delayable snks_work; @@ -389,7 +385,6 @@ static void src_loc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) #endif /* CONFIG_BT_PAC_SRC_LOC */ #endif /* CONFIG_BT_PAC_SRC */ -#if defined(CONFIG_BT_PAC_SNK) || defined(CONFIG_BT_PAC_SRC) BT_GATT_SERVICE_DEFINE(pacs_svc, BT_GATT_PRIMARY_SERVICE(BT_UUID_PACS), #if defined(CONFIG_BT_PAC_SNK) @@ -453,7 +448,6 @@ BT_GATT_SERVICE_DEFINE(pacs_svc, BT_GATT_CCC(supported_context_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_ENCRYPT) ); -#endif /* CONFIG_BT_PAC_SNK || CONFIG_BT_PAC_SRC */ static struct k_work_delayable *bt_pacs_get_work(enum bt_audio_dir dir) { @@ -490,7 +484,6 @@ static struct k_work_delayable *bt_pacs_get_loc_work(enum bt_audio_dir dir) static void pac_notify_loc(struct k_work *work) { -#if defined(CONFIG_BT_PAC_SNK) || defined(CONFIG_BT_PAC_SRC) uint32_t location; struct bt_uuid *uuid; enum bt_audio_dir dir; @@ -523,13 +516,11 @@ static void pac_notify_loc(struct k_work *work) if (err != 0) { BT_WARN("PACS notify failed: %d", err); } -#endif /* CONFIG_BT_PAC_SNK || CONFIG_BT_PAC_SRC */ } #endif /* CONFIG_BT_PAC_SNK_LOC || CONFIG_BT_PAC_SRC_LOC */ static void pac_notify(struct k_work *work) { -#if defined(CONFIG_BT_PAC_SNK) || defined(CONFIG_BT_PAC_SRC) struct bt_uuid *uuid; enum bt_audio_dir dir; int err; @@ -556,7 +547,6 @@ static void pac_notify(struct k_work *work) if (err != 0) { BT_WARN("PACS notify failed: %d", err); } -#endif /* CONFIG_BT_PAC_SNK || CONFIG_BT_PAC_SRC */ } void bt_pacs_add_capability(enum bt_audio_dir dir)