From 0785e9479dd66c0d985660e3d72e85dce4568e86 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 17 Nov 2021 14:26:40 +0100 Subject: [PATCH] Bluetooth: ISO: Add function to get info of ISO channel The application may want to want the type of an ISO channel, and take action based on what the type is. It has been implemented as a get_info to be consistent with other get_info functions in the Bluetooth subsystem. The bt_iso_info struct can be expanded with more information later as required. Signed-off-by: Emil Gydesen --- include/bluetooth/iso.h | 25 +++++++++++++++++++++++++ subsys/bluetooth/host/iso.c | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/bluetooth/iso.h b/include/bluetooth/iso.h index 61a531a4060..ce901925245 100644 --- a/include/bluetooth/iso.h +++ b/include/bluetooth/iso.h @@ -607,6 +607,31 @@ int bt_iso_chan_disconnect(struct bt_iso_chan *chan); */ int bt_iso_chan_send(struct bt_iso_chan *chan, struct net_buf *buf); +/** ISO channel Info Structure */ +struct bt_iso_info { + /** Channel Type. */ + enum bt_iso_chan_type type; +}; + +/** @brief Get ISO channel info + * + * @param chan Channel object. + * @param info Channel info object. + * + * @return Zero on success or (negative) error code on failure. + */ +int bt_iso_chan_get_info(const struct bt_iso_chan *chan, + struct bt_iso_info *info); + +/** @brief Get the type of an ISO channel + * + * @param chan Channel object. + * + * @return enum bt_iso_chan_type The type of the channel. If @p is NULL this + * will be BT_ISO_CHAN_TYPE_NONE. + */ +enum bt_iso_chan_type bt_iso_chan_get_type(const struct bt_iso_chan *chan); + /** @brief Creates a BIG as a broadcaster * * @param[in] padv Pointer to the periodic advertising object the BIGInfo shall be sent on. diff --git a/subsys/bluetooth/host/iso.c b/subsys/bluetooth/host/iso.c index 63fa848663c..0193fe92a21 100644 --- a/subsys/bluetooth/host/iso.c +++ b/subsys/bluetooth/host/iso.c @@ -560,6 +560,29 @@ void bt_iso_chan_set_state(struct bt_iso_chan *chan, uint8_t state) } #endif /* CONFIG_BT_DEBUG_ISO */ +int bt_iso_chan_get_info(const struct bt_iso_chan *chan, + struct bt_iso_info *info) +{ + CHECKIF(chan == NULL) { + BT_DBG("chan is NULL"); + return -EINVAL; + } + + CHECKIF(chan->iso == NULL) { + BT_DBG("chan->iso is NULL"); + return -EINVAL; + } + + CHECKIF(info == NULL) { + BT_DBG("info is NULL"); + return -EINVAL; + } + + info->type = chan->iso->iso.type; + + return 0; +} + #if defined(CONFIG_BT_ISO_UNICAST) || defined(CONFIG_BT_ISO_SYNC_RECEIVER) struct net_buf *bt_iso_get_rx(k_timeout_t timeout) {