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 <mariusz.skamra@codecoup.pl>
This commit is contained in:
Mariusz Skamra 2022-05-20 08:07:33 +02:00 committed by Carles Cufí
commit 893f49ea88
4 changed files with 28 additions and 35 deletions

View file

@ -8,7 +8,6 @@
config BT_ASCS config BT_ASCS
bool "Audio Stream Control Service Support" bool "Audio Stream Control Service Support"
depends on BT_PACS
select BT_SMP_SC_PAIR_ONLY select BT_SMP_SC_PAIR_ONLY
help help
This option enables support for Audio Stream Control Service. This option enables support for Audio Stream Control Service.
@ -29,4 +28,12 @@ config BT_ASCS_ASE_SRC_COUNT
help help
An ASE Source characteristic represents the state of an ASE, which is An ASE Source characteristic represents the state of an ASE, which is
coupled to a single direction of a unicast Audio Stream. 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 endif # BT_ASCS

View file

@ -20,7 +20,6 @@ config BT_AUDIO_UNICAST_SERVER
select BT_ISO_PERIPHERAL select BT_ISO_PERIPHERAL
select BT_GATT_DYNAMIC_DB select BT_GATT_DYNAMIC_DB
select BT_GATT_CACHING select BT_GATT_CACHING
select BT_PACS
select BT_ASCS select BT_ASCS
help help
This option enables support for Bluetooth Unicast Audio Server 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 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 config BT_AUDIO_DEBUG_STREAM
bool "Bluetooth Audio Stream debug" bool "Bluetooth Audio Stream debug"
depends on BT_AUDIO_STREAM depends on BT_AUDIO_STREAM

View file

@ -5,18 +5,12 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
config BT_PACS menu "Published Audio Capabilities (PAC) options"
bool "Published Audio Capabilities Service Support"
select BT_SMP_SC_PAIR_ONLY
help
This option enables support for Published Audio Capabilities Service.
if BT_PACS
config BT_PAC_SNK config BT_PAC_SNK
bool "Sink PAC Characteristic Support" bool "Sink PAC Characteristic Support"
default y if BT_ASCS
help help
This option enables support for Sink PAC Characteristic. This option enables support for Sink Published Audio Capabilities.
if BT_PAC_SNK if BT_PAC_SNK
config BT_PACS_SNK_CONTEXT config BT_PACS_SNK_CONTEXT
@ -55,10 +49,8 @@ endif # BT_PACS_SNK
config BT_PAC_SRC config BT_PAC_SRC
bool "Source PAC Characteristic Support" bool "Source PAC Characteristic Support"
default y if BT_ASCS
default y
help help
This option enables support for Source PAC Characteristic. This option enables support for Source Published Audio Capabilities.
if BT_PAC_SRC if BT_PAC_SRC
config BT_PACS_SRC_CONTEXT config BT_PACS_SRC_CONTEXT
@ -94,4 +86,16 @@ config BT_PAC_SRC_LOC_WRITEABLE
Location Characteristic. Location Characteristic.
endif # BT_PAC_SRC 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

View file

@ -31,7 +31,6 @@
#define PAC_NOTIFY_TIMEOUT K_MSEC(10) #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); 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, 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) void *buf, uint16_t len, uint16_t offset)
{ {
struct bt_pacs_context context = { struct bt_pacs_context context = {
#if defined(CONFIG_BT_PAC_SNK) .snk = COND_CODE_1(CONFIG_BT_PAC_SNK,
.snk = sys_cpu_to_le16(CONFIG_BT_PACS_SNK_CONTEXT), (sys_cpu_to_le16(CONFIG_BT_PACS_SNK_CONTEXT)), (0)),
#endif .src = COND_CODE_1(CONFIG_BT_PAC_SRC,
#if defined(CONFIG_BT_PAC_SRC) (sys_cpu_to_le16(CONFIG_BT_PACS_SRC_CONTEXT)), (0)),
.src = sys_cpu_to_le16(CONFIG_BT_PACS_SRC_CONTEXT),
#endif
}; };
BT_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, 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; return 0;
} }
#endif /* CONFIG_BT_PAC_SNK_LOC || CONFIG_BT_PAC_SRC_LOC */ #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) #if defined(CONFIG_BT_PAC_SNK)
static struct k_work_delayable snks_work; 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_LOC */
#endif /* CONFIG_BT_PAC_SRC */ #endif /* CONFIG_BT_PAC_SRC */
#if defined(CONFIG_BT_PAC_SNK) || defined(CONFIG_BT_PAC_SRC)
BT_GATT_SERVICE_DEFINE(pacs_svc, BT_GATT_SERVICE_DEFINE(pacs_svc,
BT_GATT_PRIMARY_SERVICE(BT_UUID_PACS), BT_GATT_PRIMARY_SERVICE(BT_UUID_PACS),
#if defined(CONFIG_BT_PAC_SNK) #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_CCC(supported_context_cfg_changed,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_ENCRYPT) 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) 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) static void pac_notify_loc(struct k_work *work)
{ {
#if defined(CONFIG_BT_PAC_SNK) || defined(CONFIG_BT_PAC_SRC)
uint32_t location; uint32_t location;
struct bt_uuid *uuid; struct bt_uuid *uuid;
enum bt_audio_dir dir; enum bt_audio_dir dir;
@ -523,13 +516,11 @@ static void pac_notify_loc(struct k_work *work)
if (err != 0) { if (err != 0) {
BT_WARN("PACS notify failed: %d", err); 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 */ #endif /* CONFIG_BT_PAC_SNK_LOC || CONFIG_BT_PAC_SRC_LOC */
static void pac_notify(struct k_work *work) static void pac_notify(struct k_work *work)
{ {
#if defined(CONFIG_BT_PAC_SNK) || defined(CONFIG_BT_PAC_SRC)
struct bt_uuid *uuid; struct bt_uuid *uuid;
enum bt_audio_dir dir; enum bt_audio_dir dir;
int err; int err;
@ -556,7 +547,6 @@ static void pac_notify(struct k_work *work)
if (err != 0) { if (err != 0) {
BT_WARN("PACS notify failed: %d", err); 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) void bt_pacs_add_capability(enum bt_audio_dir dir)