Bluetooth: Use Zephyr standard log system instead of bluetooth/common/log

The `bluetooth/common/log.h` and `bluetooth/common/log.c` files have been
removed. Files that were using them have been updated to use
`zephyr/logging/log.h` instead.

Those replacement have been done consequently:
- `/BT_DBG/LOG_DBG/`
- `/BT_ERR/LOG_ERR/`
- `/BT_WARN/LOG_WRN/`
- `/BT_INFO/LOG_INF/`
- `/BT_HEXDUMP_DBG/LOG_HEXDUMP_DBG/`
- `/BT_DBG_OBJ_ID/LOG_DBG_OBJ_ID/`

Also, some files were relying on the `common/log.h` include to include
`zephyr/bluetooth/hci.h`, in those cases the include of `hci.h` has
been added.

For files that were including `common/log.h` but not using any logs,
the include has been removed and not replaced.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
This commit is contained in:
Théo Battrel 2022-11-02 14:31:13 +01:00 committed by Carles Cufí
commit e458f5aae6
253 changed files with 7131 additions and 7180 deletions

View file

@ -40,6 +40,11 @@ Changes in this release
* Starting from this release ``zephyr-`` prefixed tags won't be created * Starting from this release ``zephyr-`` prefixed tags won't be created
anymore. The project will continue using ``v`` tags, for example ``v3.3.0``. anymore. The project will continue using ``v`` tags, for example ``v3.3.0``.
* Bluetooth: Deprecate the Bluetooth logging subsystem in favor of the Zephyr
standard logging system. To enable debugging for a particular module in the
Bluetooth subsystem, enable `CONFIG_BT_(module name)_LOG_LEVEL_DBG` instead of
`CONFIG_BT_DEBUG_(module name)`.
Removed APIs in this release Removed APIs in this release
============================ ============================

View file

@ -22,9 +22,10 @@
#include <zephyr/bluetooth/hci.h> #include <zephyr/bluetooth/hci.h>
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/drivers/bluetooth/hci_driver.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#define LOG_MODULE_NAME bt_driver #include <zephyr/logging/log.h>
#include "common/log.h" LOG_MODULE_REGISTER(bt_driver);
#include "common/bt_str.h" #include "common/bt_str.h"
#include "../util.h" #include "../util.h"
@ -76,7 +77,7 @@ static inline void h4_get_type(void)
{ {
/* Get packet type */ /* Get packet type */
if (uart_fifo_read(h4_dev, &rx.type, 1) != 1) { if (uart_fifo_read(h4_dev, &rx.type, 1) != 1) {
BT_WARN("Unable to read H:4 packet type"); LOG_WRN("Unable to read H:4 packet type");
rx.type = H4_NONE; rx.type = H4_NONE;
return; return;
} }
@ -98,7 +99,7 @@ static inline void h4_get_type(void)
} }
__fallthrough; __fallthrough;
default: default:
BT_ERR("Unknown H:4 type 0x%02x", rx.type); LOG_ERR("Unknown H:4 type 0x%02x", rx.type);
rx.type = H4_NONE; rx.type = H4_NONE;
} }
} }
@ -110,7 +111,7 @@ static void h4_read_hdr(void)
ret = uart_fifo_read(h4_dev, rx.hdr + bytes_read, rx.remaining); ret = uart_fifo_read(h4_dev, rx.hdr + bytes_read, rx.remaining);
if (unlikely(ret < 0)) { if (unlikely(ret < 0)) {
BT_ERR("Unable to read from UART (ret %d)", ret); LOG_ERR("Unable to read from UART (ret %d)", ret);
} else { } else {
rx.remaining -= ret; rx.remaining -= ret;
} }
@ -124,7 +125,7 @@ static inline void get_acl_hdr(void)
struct bt_hci_acl_hdr *hdr = &rx.acl; struct bt_hci_acl_hdr *hdr = &rx.acl;
rx.remaining = sys_le16_to_cpu(hdr->len); rx.remaining = sys_le16_to_cpu(hdr->len);
BT_DBG("Got ACL header. Payload %u bytes", rx.remaining); LOG_DBG("Got ACL header. Payload %u bytes", rx.remaining);
rx.have_hdr = true; rx.have_hdr = true;
} }
} }
@ -137,7 +138,7 @@ static inline void get_iso_hdr(void)
struct bt_hci_iso_hdr *hdr = &rx.iso; struct bt_hci_iso_hdr *hdr = &rx.iso;
rx.remaining = bt_iso_hdr_len(sys_le16_to_cpu(hdr->len)); rx.remaining = bt_iso_hdr_len(sys_le16_to_cpu(hdr->len));
BT_DBG("Got ISO header. Payload %u bytes", rx.remaining); LOG_DBG("Got ISO header. Payload %u bytes", rx.remaining);
rx.have_hdr = true; rx.have_hdr = true;
} }
} }
@ -166,12 +167,12 @@ static inline void get_evt_hdr(void)
if (!rx.remaining) { if (!rx.remaining) {
if (rx.evt.evt == BT_HCI_EVT_LE_META_EVENT && if (rx.evt.evt == BT_HCI_EVT_LE_META_EVENT &&
(rx.hdr[sizeof(*hdr)] == BT_HCI_EVT_LE_ADVERTISING_REPORT)) { (rx.hdr[sizeof(*hdr)] == BT_HCI_EVT_LE_ADVERTISING_REPORT)) {
BT_DBG("Marking adv report as discardable"); LOG_DBG("Marking adv report as discardable");
rx.discardable = true; rx.discardable = true;
} }
rx.remaining = hdr->len - (rx.hdr_len - sizeof(*hdr)); rx.remaining = hdr->len - (rx.hdr_len - sizeof(*hdr));
BT_DBG("Got event header. Payload %u bytes", hdr->len); LOG_DBG("Got event header. Payload %u bytes", hdr->len);
rx.have_hdr = true; rx.have_hdr = true;
} }
} }
@ -193,7 +194,7 @@ static void reset_rx(void)
static struct net_buf *get_rx(k_timeout_t timeout) static struct net_buf *get_rx(k_timeout_t timeout)
{ {
BT_DBG("type 0x%02x, evt 0x%02x", rx.type, rx.evt.evt); LOG_DBG("type 0x%02x, evt 0x%02x", rx.type, rx.evt.evt);
switch (rx.type) { switch (rx.type) {
case H4_EVT: case H4_EVT:
@ -217,10 +218,10 @@ static void rx_thread(void *p1, void *p2, void *p3)
ARG_UNUSED(p2); ARG_UNUSED(p2);
ARG_UNUSED(p3); ARG_UNUSED(p3);
BT_DBG("started"); LOG_DBG("started");
while (1) { while (1) {
BT_DBG("rx.buf %p", rx.buf); LOG_DBG("rx.buf %p", rx.buf);
/* We can only do the allocation if we know the initial /* We can only do the allocation if we know the initial
* header, since Command Complete/Status events must use the * header, since Command Complete/Status events must use the
@ -228,9 +229,9 @@ static void rx_thread(void *p1, void *p2, void *p3)
*/ */
if (rx.have_hdr && !rx.buf) { if (rx.have_hdr && !rx.buf) {
rx.buf = get_rx(K_FOREVER); rx.buf = get_rx(K_FOREVER);
BT_DBG("Got rx.buf %p", rx.buf); LOG_DBG("Got rx.buf %p", rx.buf);
if (rx.remaining > net_buf_tailroom(rx.buf)) { if (rx.remaining > net_buf_tailroom(rx.buf)) {
BT_ERR("Not enough space in buffer"); LOG_ERR("Not enough space in buffer");
rx.discard = rx.remaining; rx.discard = rx.remaining;
reset_rx(); reset_rx();
} else { } else {
@ -245,7 +246,7 @@ static void rx_thread(void *p1, void *p2, void *p3)
do { do {
uart_irq_rx_enable(h4_dev); uart_irq_rx_enable(h4_dev);
BT_DBG("Calling bt_recv(%p)", buf); LOG_DBG("Calling bt_recv(%p)", buf);
bt_recv(buf); bt_recv(buf);
/* Give other threads a chance to run if the ISR /* Give other threads a chance to run if the ISR
@ -267,7 +268,7 @@ static size_t h4_discard(const struct device *uart, size_t len)
err = uart_fifo_read(uart, buf, MIN(len, sizeof(buf))); err = uart_fifo_read(uart, buf, MIN(len, sizeof(buf)));
if (unlikely(err < 0)) { if (unlikely(err < 0)) {
BT_ERR("Unable to read from UART (err %d)", err); LOG_ERR("Unable to read from UART (err %d)", err);
return 0; return 0;
} }
@ -286,23 +287,22 @@ static inline void read_payload(void)
rx.buf = get_rx(K_NO_WAIT); rx.buf = get_rx(K_NO_WAIT);
if (!rx.buf) { if (!rx.buf) {
if (rx.discardable) { if (rx.discardable) {
BT_WARN("Discarding event 0x%02x", rx.evt.evt); LOG_WRN("Discarding event 0x%02x", rx.evt.evt);
rx.discard = rx.remaining; rx.discard = rx.remaining;
reset_rx(); reset_rx();
return; return;
} }
BT_WARN("Failed to allocate, deferring to rx_thread"); LOG_WRN("Failed to allocate, deferring to rx_thread");
uart_irq_rx_disable(h4_dev); uart_irq_rx_disable(h4_dev);
return; return;
} }
BT_DBG("Allocated rx.buf %p", rx.buf); LOG_DBG("Allocated rx.buf %p", rx.buf);
buf_tailroom = net_buf_tailroom(rx.buf); buf_tailroom = net_buf_tailroom(rx.buf);
if (buf_tailroom < rx.remaining) { if (buf_tailroom < rx.remaining) {
BT_ERR("Not enough space in buffer %u/%zu", LOG_ERR("Not enough space in buffer %u/%zu", rx.remaining, buf_tailroom);
rx.remaining, buf_tailroom);
rx.discard = rx.remaining; rx.discard = rx.remaining;
reset_rx(); reset_rx();
return; return;
@ -313,16 +313,15 @@ static inline void read_payload(void)
read = uart_fifo_read(h4_dev, net_buf_tail(rx.buf), rx.remaining); read = uart_fifo_read(h4_dev, net_buf_tail(rx.buf), rx.remaining);
if (unlikely(read < 0)) { if (unlikely(read < 0)) {
BT_ERR("Failed to read UART (err %d)", read); LOG_ERR("Failed to read UART (err %d)", read);
return; return;
} }
net_buf_add(rx.buf, read); net_buf_add(rx.buf, read);
rx.remaining -= read; rx.remaining -= read;
BT_DBG("got %d bytes, remaining %u", read, rx.remaining); LOG_DBG("got %d bytes, remaining %u", read, rx.remaining);
BT_DBG("Payload (len %u): %s", rx.buf->len, LOG_DBG("Payload (len %u): %s", rx.buf->len, bt_hex(rx.buf->data, rx.buf->len));
bt_hex(rx.buf->data, rx.buf->len));
if (rx.remaining) { if (rx.remaining) {
return; return;
@ -343,12 +342,12 @@ static inline void read_payload(void)
if (IS_ENABLED(CONFIG_BT_RECV_BLOCKING) && if (IS_ENABLED(CONFIG_BT_RECV_BLOCKING) &&
(evt_flags & BT_HCI_EVT_FLAG_RECV_PRIO)) { (evt_flags & BT_HCI_EVT_FLAG_RECV_PRIO)) {
BT_DBG("Calling bt_recv_prio(%p)", buf); LOG_DBG("Calling bt_recv_prio(%p)", buf);
bt_recv_prio(buf); bt_recv_prio(buf);
} }
if (evt_flags & BT_HCI_EVT_FLAG_RECV) { if (evt_flags & BT_HCI_EVT_FLAG_RECV) {
BT_DBG("Putting buf %p to rx fifo", buf); LOG_DBG("Putting buf %p to rx fifo", buf);
net_buf_put(&rx.fifo, buf); net_buf_put(&rx.fifo, buf);
} }
} }
@ -378,7 +377,7 @@ static inline void read_header(void)
if (rx.have_hdr && rx.buf) { if (rx.have_hdr && rx.buf) {
if (rx.remaining > net_buf_tailroom(rx.buf)) { if (rx.remaining > net_buf_tailroom(rx.buf)) {
BT_ERR("Not enough space in buffer"); LOG_ERR("Not enough space in buffer");
rx.discard = rx.remaining; rx.discard = rx.remaining;
reset_rx(); reset_rx();
} else { } else {
@ -394,7 +393,7 @@ static inline void process_tx(void)
if (!tx.buf) { if (!tx.buf) {
tx.buf = net_buf_get(&tx.fifo, K_NO_WAIT); tx.buf = net_buf_get(&tx.fifo, K_NO_WAIT);
if (!tx.buf) { if (!tx.buf) {
BT_ERR("TX interrupt but no pending buffer!"); LOG_ERR("TX interrupt but no pending buffer!");
uart_irq_tx_disable(h4_dev); uart_irq_tx_disable(h4_dev);
return; return;
} }
@ -415,13 +414,13 @@ static inline void process_tx(void)
} }
__fallthrough; __fallthrough;
default: default:
BT_ERR("Unknown buffer type"); LOG_ERR("Unknown buffer type");
goto done; goto done;
} }
bytes = uart_fifo_fill(h4_dev, &tx.type, 1); bytes = uart_fifo_fill(h4_dev, &tx.type, 1);
if (bytes != 1) { if (bytes != 1) {
BT_WARN("Unable to send H:4 type"); LOG_WRN("Unable to send H:4 type");
tx.type = H4_NONE; tx.type = H4_NONE;
return; return;
} }
@ -429,7 +428,7 @@ static inline void process_tx(void)
bytes = uart_fifo_fill(h4_dev, tx.buf->data, tx.buf->len); bytes = uart_fifo_fill(h4_dev, tx.buf->data, tx.buf->len);
if (unlikely(bytes < 0)) { if (unlikely(bytes < 0)) {
BT_ERR("Unable to write to UART (err %d)", bytes); LOG_ERR("Unable to write to UART (err %d)", bytes);
} else { } else {
net_buf_pull(tx.buf, bytes); net_buf_pull(tx.buf, bytes);
} }
@ -449,9 +448,8 @@ done:
static inline void process_rx(void) static inline void process_rx(void)
{ {
BT_DBG("remaining %u discard %u have_hdr %u rx.buf %p len %u", LOG_DBG("remaining %u discard %u have_hdr %u rx.buf %p len %u", rx.remaining, rx.discard,
rx.remaining, rx.discard, rx.have_hdr, rx.buf, rx.have_hdr, rx.buf, rx.buf ? rx.buf->len : 0);
rx.buf ? rx.buf->len : 0);
if (rx.discard) { if (rx.discard) {
rx.discard -= h4_discard(h4_dev, rx.discard); rx.discard -= h4_discard(h4_dev, rx.discard);
@ -483,7 +481,7 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
static int h4_send(struct net_buf *buf) static int h4_send(struct net_buf *buf)
{ {
BT_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
net_buf_put(&tx.fifo, buf); net_buf_put(&tx.fifo, buf);
uart_irq_tx_enable(h4_dev); uart_irq_tx_enable(h4_dev);
@ -508,7 +506,7 @@ static int h4_open(void)
int ret; int ret;
k_tid_t tid; k_tid_t tid;
BT_DBG(""); LOG_DBG("");
uart_irq_rx_disable(h4_dev); uart_irq_rx_disable(h4_dev);
uart_irq_tx_disable(h4_dev); uart_irq_tx_disable(h4_dev);

View file

@ -23,12 +23,12 @@
#include <zephyr/bluetooth/hci.h> #include <zephyr/bluetooth/hci.h>
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/drivers/bluetooth/hci_driver.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_driver
#include "common/log.h"
#include "../util.h" #include "../util.h"
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_driver);
static K_KERNEL_STACK_DEFINE(tx_stack, 256); static K_KERNEL_STACK_DEFINE(tx_stack, 256);
static K_KERNEL_STACK_DEFINE(rx_stack, 256); static K_KERNEL_STACK_DEFINE(rx_stack, 256);
@ -159,7 +159,7 @@ static int h5_unslip_byte(uint8_t *byte)
*byte = SLIP_ESC; *byte = SLIP_ESC;
break; break;
default: default:
BT_ERR("Invalid escape byte %x\n", *byte); LOG_ERR("Invalid escape byte %x\n", *byte);
return -EIO; return -EIO;
} }
@ -175,8 +175,8 @@ static void process_unack(void)
return; return;
} }
BT_DBG("rx_ack %u tx_ack %u tx_seq %u unack_queue_len %u", LOG_DBG("rx_ack %u tx_ack %u tx_seq %u unack_queue_len %u", h5.rx_ack, h5.tx_ack, h5.tx_seq,
h5.rx_ack, h5.tx_ack, h5.tx_seq, unack_queue_len); unack_queue_len);
while (unack_queue_len > 0) { while (unack_queue_len > 0) {
if (next_seq == h5.rx_ack) { if (next_seq == h5.rx_ack) {
@ -192,22 +192,22 @@ static void process_unack(void)
} }
if (next_seq != h5.rx_ack) { if (next_seq != h5.rx_ack) {
BT_ERR("Wrong sequence: rx_ack %u tx_seq %u next_seq %u", LOG_ERR("Wrong sequence: rx_ack %u tx_seq %u next_seq %u", h5.rx_ack, h5.tx_seq,
h5.rx_ack, h5.tx_seq, next_seq); next_seq);
} }
BT_DBG("Need to remove %u packet from the queue", number_removed); LOG_DBG("Need to remove %u packet from the queue", number_removed);
while (number_removed) { while (number_removed) {
struct net_buf *buf = net_buf_get(&h5.unack_queue, K_NO_WAIT); struct net_buf *buf = net_buf_get(&h5.unack_queue, K_NO_WAIT);
if (!buf) { if (!buf) {
BT_ERR("Unack queue is empty"); LOG_ERR("Unack queue is empty");
break; break;
} }
/* TODO: print or do something with packet */ /* TODO: print or do something with packet */
BT_DBG("Remove buf from the unack_queue"); LOG_DBG("Remove buf from the unack_queue");
net_buf_unref(buf); net_buf_unref(buf);
unack_queue_len--; unack_queue_len--;
@ -218,18 +218,15 @@ static void process_unack(void)
static void h5_print_header(const uint8_t *hdr, const char *str) static void h5_print_header(const uint8_t *hdr, const char *str)
{ {
if (H5_HDR_RELIABLE(hdr)) { if (H5_HDR_RELIABLE(hdr)) {
BT_DBG("%s REL: seq %u ack %u crc %u type %u len %u", LOG_DBG("%s REL: seq %u ack %u crc %u type %u len %u", str, H5_HDR_SEQ(hdr),
str, H5_HDR_SEQ(hdr), H5_HDR_ACK(hdr), H5_HDR_ACK(hdr), H5_HDR_CRC(hdr), H5_HDR_PKT_TYPE(hdr), H5_HDR_LEN(hdr));
H5_HDR_CRC(hdr), H5_HDR_PKT_TYPE(hdr),
H5_HDR_LEN(hdr));
} else { } else {
BT_DBG("%s UNREL: ack %u crc %u type %u len %u", LOG_DBG("%s UNREL: ack %u crc %u type %u len %u", str, H5_HDR_ACK(hdr),
str, H5_HDR_ACK(hdr), H5_HDR_CRC(hdr), H5_HDR_CRC(hdr), H5_HDR_PKT_TYPE(hdr), H5_HDR_LEN(hdr));
H5_HDR_PKT_TYPE(hdr), H5_HDR_LEN(hdr));
} }
} }
#if defined(CONFIG_BT_DEBUG_HCI_DRIVER) #if defined(CONFIG_BT_HCI_DRIVER_LOG_LEVEL_DBG)
static void hexdump(const char *str, const uint8_t *packet, size_t length) static void hexdump(const char *str, const uint8_t *packet, size_t length)
{ {
int n = 0; int n = 0;
@ -327,7 +324,7 @@ static void retx_timeout(struct k_work *work)
{ {
ARG_UNUSED(work); ARG_UNUSED(work);
BT_DBG("unack_queue_len %u", unack_queue_len); LOG_DBG("unack_queue_len %u", unack_queue_len);
if (unack_queue_len) { if (unack_queue_len) {
struct k_fifo tmp_queue; struct k_fifo tmp_queue;
@ -360,7 +357,7 @@ static void ack_timeout(struct k_work *work)
{ {
ARG_UNUSED(work); ARG_UNUSED(work);
BT_DBG(""); LOG_DBG("");
h5_send(NULL, HCI_3WIRE_ACK_PKT, 0); h5_send(NULL, HCI_3WIRE_ACK_PKT, 0);
} }
@ -369,7 +366,7 @@ static void h5_process_complete_packet(uint8_t *hdr)
{ {
struct net_buf *buf; struct net_buf *buf;
BT_DBG(""); LOG_DBG("");
/* rx_ack should be in every packet */ /* rx_ack should be in every packet */
h5.rx_ack = H5_HDR_ACK(hdr); h5.rx_ack = H5_HDR_ACK(hdr);
@ -425,9 +422,9 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
if (!uart_irq_rx_ready(h5_dev)) { if (!uart_irq_rx_ready(h5_dev)) {
if (uart_irq_tx_ready(h5_dev)) { if (uart_irq_tx_ready(h5_dev)) {
BT_DBG("transmit ready"); LOG_DBG("transmit ready");
} else { } else {
BT_DBG("spurious interrupt"); LOG_DBG("spurious interrupt");
} }
/* Only the UART RX path is interrupt-enabled */ /* Only the UART RX path is interrupt-enabled */
break; break;
@ -479,7 +476,7 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
h5.rx_buf = bt_buf_get_rx(BT_BUF_ACL_IN, h5.rx_buf = bt_buf_get_rx(BT_BUF_ACL_IN,
K_NO_WAIT); K_NO_WAIT);
if (!h5.rx_buf) { if (!h5.rx_buf) {
BT_WARN("No available data buffers"); LOG_WRN("No available data buffers");
h5_reset_rx(); h5_reset_rx();
continue; continue;
} }
@ -490,7 +487,7 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
h5.rx_buf = bt_buf_get_rx(BT_BUF_ISO_IN, h5.rx_buf = bt_buf_get_rx(BT_BUF_ISO_IN,
K_NO_WAIT); K_NO_WAIT);
if (!h5.rx_buf) { if (!h5.rx_buf) {
BT_WARN("No available data buffers"); LOG_WRN("No available data buffers");
h5_reset_rx(); h5_reset_rx();
continue; continue;
} }
@ -501,7 +498,7 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
case HCI_3WIRE_ACK_PKT: case HCI_3WIRE_ACK_PKT:
h5.rx_buf = net_buf_alloc(&h5_pool, K_NO_WAIT); h5.rx_buf = net_buf_alloc(&h5_pool, K_NO_WAIT);
if (!h5.rx_buf) { if (!h5.rx_buf) {
BT_WARN("No available signal buffers"); LOG_WRN("No available signal buffers");
h5_reset_rx(); h5_reset_rx();
continue; continue;
} }
@ -509,8 +506,7 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
h5.rx_state = PAYLOAD; h5.rx_state = PAYLOAD;
break; break;
default: default:
BT_ERR("Wrong packet type %u", LOG_ERR("Wrong packet type %u", H5_HDR_PKT_TYPE(hdr));
H5_HDR_PKT_TYPE(hdr));
h5.rx_state = END; h5.rx_state = END;
break; break;
} }
@ -530,7 +526,7 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
if (!h5.rx_buf) { if (!h5.rx_buf) {
h5.rx_buf = get_evt_buf(byte); h5.rx_buf = get_evt_buf(byte);
if (!h5.rx_buf) { if (!h5.rx_buf) {
BT_WARN("No available event buffers"); LOG_WRN("No available event buffers");
h5_reset_rx(); h5_reset_rx();
continue; continue;
} }
@ -538,8 +534,8 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
buf_tailroom = net_buf_tailroom(h5.rx_buf); buf_tailroom = net_buf_tailroom(h5.rx_buf);
if (buf_tailroom < sizeof(byte)) { if (buf_tailroom < sizeof(byte)) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", sizeof(byte),
sizeof(byte), buf_tailroom); buf_tailroom);
h5_reset_rx(); h5_reset_rx();
break; break;
} }
@ -552,13 +548,12 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
break; break;
case END: case END:
if (byte != SLIP_DELIMITER) { if (byte != SLIP_DELIMITER) {
BT_ERR("Missing ending SLIP_DELIMITER"); LOG_ERR("Missing ending SLIP_DELIMITER");
h5_reset_rx(); h5_reset_rx();
break; break;
} }
BT_DBG("Received full packet: type %u", LOG_DBG("Received full packet: type %u", H5_HDR_PKT_TYPE(hdr));
H5_HDR_PKT_TYPE(hdr));
/* Check when full packet is received, it can be done /* Check when full packet is received, it can be done
* when parsing packet header but we need to receive * when parsing packet header but we need to receive
@ -566,8 +561,8 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
*/ */
if (H5_HDR_RELIABLE(hdr) && if (H5_HDR_RELIABLE(hdr) &&
H5_HDR_SEQ(hdr) != h5.tx_ack) { H5_HDR_SEQ(hdr) != h5.tx_ack) {
BT_ERR("Seq expected %u got %u. Drop packet", LOG_ERR("Seq expected %u got %u. Drop packet", h5.tx_ack,
h5.tx_ack, H5_HDR_SEQ(hdr)); H5_HDR_SEQ(hdr));
h5_reset_rx(); h5_reset_rx();
break; break;
} }
@ -588,7 +583,7 @@ static int h5_queue(struct net_buf *buf)
{ {
uint8_t type; uint8_t type;
BT_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
switch (bt_buf_get_type(buf)) { switch (bt_buf_get_type(buf)) {
case BT_BUF_CMD: case BT_BUF_CMD:
@ -601,7 +596,7 @@ static int h5_queue(struct net_buf *buf)
type = HCI_ISODATA_PKT; type = HCI_ISODATA_PKT;
break; break;
default: default:
BT_ERR("Unknown packet type %u", bt_buf_get_type(buf)); LOG_ERR("Unknown packet type %u", bt_buf_get_type(buf));
return -1; return -1;
} }
@ -614,7 +609,7 @@ static int h5_queue(struct net_buf *buf)
static void tx_thread(void) static void tx_thread(void)
{ {
BT_DBG(""); LOG_DBG("");
/* FIXME: make periodic sending */ /* FIXME: make periodic sending */
h5_send(sync_req, HCI_3WIRE_LINK_PKT, sizeof(sync_req)); h5_send(sync_req, HCI_3WIRE_LINK_PKT, sizeof(sync_req));
@ -623,7 +618,7 @@ static void tx_thread(void)
struct net_buf *buf; struct net_buf *buf;
uint8_t type; uint8_t type;
BT_DBG("link_state %u", h5.link_state); LOG_DBG("link_state %u", h5.link_state);
switch (h5.link_state) { switch (h5.link_state) {
case UNINIT: case UNINIT:
@ -660,7 +655,7 @@ static void h5_set_txwin(uint8_t *conf)
static void rx_thread(void) static void rx_thread(void)
{ {
BT_DBG(""); LOG_DBG("");
while (true) { while (true) {
struct net_buf *buf; struct net_buf *buf;
@ -700,11 +695,9 @@ static void rx_thread(void)
h5.tx_win = (buf->data[2] & 0x07); h5.tx_win = (buf->data[2] & 0x07);
} }
BT_DBG("Finished H5 configuration, tx_win %u", LOG_DBG("Finished H5 configuration, tx_win %u", h5.tx_win);
h5.tx_win);
} else { } else {
BT_ERR("Not handled yet %x %x", LOG_ERR("Not handled yet %x %x", buf->data[0], buf->data[1]);
buf->data[0], buf->data[1]);
} }
net_buf_unref(buf); net_buf_unref(buf);
@ -718,7 +711,7 @@ static void rx_thread(void)
static void h5_init(void) static void h5_init(void)
{ {
BT_DBG(""); LOG_DBG("");
h5.link_state = UNINIT; h5.link_state = UNINIT;
h5.rx_state = START; h5.rx_state = START;
@ -751,7 +744,7 @@ static void h5_init(void)
static int h5_open(void) static int h5_open(void)
{ {
BT_DBG(""); LOG_DBG("");
uart_irq_rx_disable(h5_dev); uart_irq_rx_disable(h5_dev);
uart_irq_tx_disable(h5_dev); uart_irq_tx_disable(h5_dev);

View file

@ -4,15 +4,17 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) #include <zephyr/bluetooth/hci.h>
#define LOG_MODULE_NAME bt_hci_driver_b91
#include "common/log.h"
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/drivers/bluetooth/hci_driver.h>
#include <b91_bt.h> #include <b91_bt.h>
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_hci_driver_b91);
#define HCI_CMD 0x01 #define HCI_CMD 0x01
#define HCI_ACL 0x02 #define HCI_ACL 0x02
#define HCI_EVT 0x04 #define HCI_EVT 0x04
@ -54,7 +56,7 @@ static struct net_buf *bt_b91_evt_recv(uint8_t *data, size_t len)
size_t buf_tailroom; size_t buf_tailroom;
if (len < sizeof(hdr)) { if (len < sizeof(hdr)) {
BT_ERR("Not enough data for event header"); LOG_ERR("Not enough data for event header");
return NULL; return NULL;
} }
@ -65,17 +67,17 @@ static struct net_buf *bt_b91_evt_recv(uint8_t *data, size_t len)
len -= sizeof(hdr); len -= sizeof(hdr);
if (len != hdr.len) { if (len != hdr.len) {
BT_ERR("Event payload length is not correct"); LOG_ERR("Event payload length is not correct");
return NULL; return NULL;
} }
BT_DBG("len %u", hdr.len); LOG_DBG("len %u", hdr.len);
buf = bt_buf_get_evt(hdr.evt, discardable, K_NO_WAIT); buf = bt_buf_get_evt(hdr.evt, discardable, K_NO_WAIT);
if (!buf) { if (!buf) {
if (discardable) { if (discardable) {
BT_DBG("Discardable buffer pool full, ignoring event"); LOG_DBG("Discardable buffer pool full, ignoring event");
} else { } else {
BT_ERR("No available event buffers!"); LOG_ERR("No available event buffers!");
} }
return buf; return buf;
} }
@ -84,8 +86,7 @@ static struct net_buf *bt_b91_evt_recv(uint8_t *data, size_t len)
buf_tailroom = net_buf_tailroom(buf); buf_tailroom = net_buf_tailroom(buf);
if (buf_tailroom < len) { if (buf_tailroom < len) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", len, buf_tailroom);
len, buf_tailroom);
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
@ -102,7 +103,7 @@ static struct net_buf *bt_b91_acl_recv(uint8_t *data, size_t len)
size_t buf_tailroom; size_t buf_tailroom;
if (len < sizeof(hdr)) { if (len < sizeof(hdr)) {
BT_ERR("Not enough data for ACL header"); LOG_ERR("Not enough data for ACL header");
return NULL; return NULL;
} }
@ -112,12 +113,12 @@ static struct net_buf *bt_b91_acl_recv(uint8_t *data, size_t len)
data += sizeof(hdr); data += sizeof(hdr);
len -= sizeof(hdr); len -= sizeof(hdr);
} else { } else {
BT_ERR("No available ACL buffers!"); LOG_ERR("No available ACL buffers!");
return NULL; return NULL;
} }
if (len != sys_le16_to_cpu(hdr.len)) { if (len != sys_le16_to_cpu(hdr.len)) {
BT_ERR("ACL payload length is not correct"); LOG_ERR("ACL payload length is not correct");
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
@ -125,13 +126,12 @@ static struct net_buf *bt_b91_acl_recv(uint8_t *data, size_t len)
net_buf_add_mem(buf, &hdr, sizeof(hdr)); net_buf_add_mem(buf, &hdr, sizeof(hdr));
buf_tailroom = net_buf_tailroom(buf); buf_tailroom = net_buf_tailroom(buf);
if (buf_tailroom < len) { if (buf_tailroom < len) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", len, buf_tailroom);
len, buf_tailroom);
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
BT_DBG("len %u", len); LOG_DBG("len %u", len);
net_buf_add_mem(buf, data, len); net_buf_add_mem(buf, data, len);
return buf; return buf;
@ -158,11 +158,11 @@ static void hci_b91_host_rcv_pkt(uint8_t *data, uint16_t len)
default: default:
buf = NULL; buf = NULL;
BT_ERR("Unknown HCI type %u", pkt_indicator); LOG_ERR("Unknown HCI type %u", pkt_indicator);
} }
if (buf) { if (buf) {
BT_DBG("Calling bt_recv(%p)", buf); LOG_DBG("Calling bt_recv(%p)", buf);
bt_recv(buf); bt_recv(buf);
} }
} }
@ -182,7 +182,7 @@ static int bt_b91_send(struct net_buf *buf)
int err = 0; int err = 0;
uint8_t type; uint8_t type;
BT_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
switch (bt_buf_get_type(buf)) { switch (bt_buf_get_type(buf)) {
case BT_BUF_ACL_OUT: case BT_BUF_ACL_OUT:
@ -194,7 +194,7 @@ static int bt_b91_send(struct net_buf *buf)
break; break;
default: default:
BT_ERR("Unknown type %u", bt_buf_get_type(buf)); LOG_ERR("Unknown type %u", bt_buf_get_type(buf));
goto done; goto done;
} }
@ -203,7 +203,7 @@ static int bt_b91_send(struct net_buf *buf)
if (k_sem_take(&hci_send_sem, HCI_BT_B91_TIMEOUT) == 0) { if (k_sem_take(&hci_send_sem, HCI_BT_B91_TIMEOUT) == 0) {
b91_bt_host_send_packet(type, buf->data, buf->len); b91_bt_host_send_packet(type, buf->data, buf->len);
} else { } else {
BT_ERR("Send packet timeout error"); LOG_ERR("Send packet timeout error");
err = -ETIMEDOUT; err = -ETIMEDOUT;
} }
@ -220,13 +220,13 @@ static int hci_b91_open(void)
status = b91_bt_controller_init(); status = b91_bt_controller_init();
if (status) { if (status) {
BT_ERR("Bluetooth controller init failed %d", status); LOG_ERR("Bluetooth controller init failed %d", status);
return status; return status;
} }
b91_bt_host_callback_register(&vhci_host_cb); b91_bt_host_callback_register(&vhci_host_cb);
BT_DBG("B91 BT started"); LOG_DBG("B91 BT started");
return 0; return 0;
} }

View file

@ -4,9 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) #include <zephyr/bluetooth/hci.h>
#define LOG_MODULE_NAME bt_hci_driver_esp32
#include "common/log.h"
#include <zephyr/init.h> #include <zephyr/init.h>
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
@ -15,6 +13,10 @@
#include <esp_bt.h> #include <esp_bt.h>
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_hci_driver_esp32);
#define HCI_CMD 0x01 #define HCI_CMD 0x01
#define HCI_ACL 0x02 #define HCI_ACL 0x02
#define HCI_SCO 0x03 #define HCI_SCO 0x03
@ -58,7 +60,7 @@ static struct net_buf *bt_esp_evt_recv(uint8_t *data, size_t remaining)
size_t buf_tailroom; size_t buf_tailroom;
if (remaining < sizeof(hdr)) { if (remaining < sizeof(hdr)) {
BT_ERR("Not enough data for event header"); LOG_ERR("Not enough data for event header");
return NULL; return NULL;
} }
@ -69,17 +71,17 @@ static struct net_buf *bt_esp_evt_recv(uint8_t *data, size_t remaining)
remaining -= sizeof(hdr); remaining -= sizeof(hdr);
if (remaining != hdr.len) { if (remaining != hdr.len) {
BT_ERR("Event payload length is not correct"); LOG_ERR("Event payload length is not correct");
return NULL; return NULL;
} }
BT_DBG("len %u", hdr.len); LOG_DBG("len %u", hdr.len);
buf = bt_buf_get_evt(hdr.evt, discardable, K_NO_WAIT); buf = bt_buf_get_evt(hdr.evt, discardable, K_NO_WAIT);
if (!buf) { if (!buf) {
if (discardable) { if (discardable) {
BT_DBG("Discardable buffer pool full, ignoring event"); LOG_DBG("Discardable buffer pool full, ignoring event");
} else { } else {
BT_ERR("No available event buffers!"); LOG_ERR("No available event buffers!");
} }
return buf; return buf;
} }
@ -88,8 +90,7 @@ static struct net_buf *bt_esp_evt_recv(uint8_t *data, size_t remaining)
buf_tailroom = net_buf_tailroom(buf); buf_tailroom = net_buf_tailroom(buf);
if (buf_tailroom < remaining) { if (buf_tailroom < remaining) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", remaining, buf_tailroom);
remaining, buf_tailroom);
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
@ -106,7 +107,7 @@ static struct net_buf *bt_esp_acl_recv(uint8_t *data, size_t remaining)
size_t buf_tailroom; size_t buf_tailroom;
if (remaining < sizeof(hdr)) { if (remaining < sizeof(hdr)) {
BT_ERR("Not enough data for ACL header"); LOG_ERR("Not enough data for ACL header");
return NULL; return NULL;
} }
@ -118,25 +119,24 @@ static struct net_buf *bt_esp_acl_recv(uint8_t *data, size_t remaining)
net_buf_add_mem(buf, &hdr, sizeof(hdr)); net_buf_add_mem(buf, &hdr, sizeof(hdr));
} else { } else {
BT_ERR("No available ACL buffers!"); LOG_ERR("No available ACL buffers!");
return NULL; return NULL;
} }
if (remaining != sys_le16_to_cpu(hdr.len)) { if (remaining != sys_le16_to_cpu(hdr.len)) {
BT_ERR("ACL payload length is not correct"); LOG_ERR("ACL payload length is not correct");
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
buf_tailroom = net_buf_tailroom(buf); buf_tailroom = net_buf_tailroom(buf);
if (buf_tailroom < remaining) { if (buf_tailroom < remaining) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", remaining, buf_tailroom);
remaining, buf_tailroom);
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
BT_DBG("len %u", remaining); LOG_DBG("len %u", remaining);
net_buf_add_mem(buf, data, remaining); net_buf_add_mem(buf, data, remaining);
return buf; return buf;
@ -149,7 +149,7 @@ static struct net_buf *bt_esp_iso_recv(uint8_t *data, size_t remaining)
size_t buf_tailroom; size_t buf_tailroom;
if (remaining < sizeof(hdr)) { if (remaining < sizeof(hdr)) {
BT_ERR("Not enough data for ISO header"); LOG_ERR("Not enough data for ISO header");
return NULL; return NULL;
} }
@ -161,25 +161,24 @@ static struct net_buf *bt_esp_iso_recv(uint8_t *data, size_t remaining)
net_buf_add_mem(buf, &hdr, sizeof(hdr)); net_buf_add_mem(buf, &hdr, sizeof(hdr));
} else { } else {
BT_ERR("No available ISO buffers!"); LOG_ERR("No available ISO buffers!");
return NULL; return NULL;
} }
if (remaining != bt_iso_hdr_len(sys_le16_to_cpu(hdr.len))) { if (remaining != bt_iso_hdr_len(sys_le16_to_cpu(hdr.len))) {
BT_ERR("ISO payload length is not correct"); LOG_ERR("ISO payload length is not correct");
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
buf_tailroom = net_buf_tailroom(buf); buf_tailroom = net_buf_tailroom(buf);
if (buf_tailroom < remaining) { if (buf_tailroom < remaining) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", remaining, buf_tailroom);
remaining, buf_tailroom);
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
BT_DBG("len %zu", remaining); LOG_DBG("len %zu", remaining);
net_buf_add_mem(buf, data, remaining); net_buf_add_mem(buf, data, remaining);
return buf; return buf;
@ -210,12 +209,12 @@ static int hci_esp_host_rcv_pkt(uint8_t *data, uint16_t len)
break; break;
default: default:
BT_ERR("Unknown HCI type %u", pkt_indicator); LOG_ERR("Unknown HCI type %u", pkt_indicator);
return -1; return -1;
} }
if (buf) { if (buf) {
BT_DBG("Calling bt_recv(%p)", buf); LOG_DBG("Calling bt_recv(%p)", buf);
bt_recv(buf); bt_recv(buf);
} }
@ -238,7 +237,7 @@ static int bt_esp32_send(struct net_buf *buf)
int err = 0; int err = 0;
uint8_t pkt_indicator; uint8_t pkt_indicator;
BT_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
switch (bt_buf_get_type(buf)) { switch (bt_buf_get_type(buf)) {
case BT_BUF_ACL_OUT: case BT_BUF_ACL_OUT:
@ -251,7 +250,7 @@ static int bt_esp32_send(struct net_buf *buf)
pkt_indicator = HCI_ISO; pkt_indicator = HCI_ISO;
break; break;
default: default:
BT_ERR("Unknown type %u", bt_buf_get_type(buf)); LOG_ERR("Unknown type %u", bt_buf_get_type(buf));
goto done; goto done;
} }
net_buf_push_u8(buf, pkt_indicator); net_buf_push_u8(buf, pkt_indicator);
@ -259,13 +258,13 @@ static int bt_esp32_send(struct net_buf *buf)
LOG_HEXDUMP_DBG(buf->data, buf->len, "Final HCI buffer:"); LOG_HEXDUMP_DBG(buf->data, buf->len, "Final HCI buffer:");
if (!esp_vhci_host_check_send_available()) { if (!esp_vhci_host_check_send_available()) {
BT_WARN("Controller not ready to receive packets"); LOG_WRN("Controller not ready to receive packets");
} }
if (k_sem_take(&hci_send_sem, HCI_BT_ESP32_TIMEOUT) == 0) { if (k_sem_take(&hci_send_sem, HCI_BT_ESP32_TIMEOUT) == 0) {
esp_vhci_host_send_packet(buf->data, buf->len); esp_vhci_host_send_packet(buf->data, buf->len);
} else { } else {
BT_ERR("Send packet timeout error"); LOG_ERR("Send packet timeout error");
err = -ETIMEDOUT; err = -ETIMEDOUT;
} }
@ -289,13 +288,13 @@ static int bt_esp32_ble_init(void)
ret = esp_bt_controller_init(&bt_cfg); ret = esp_bt_controller_init(&bt_cfg);
if (ret) { if (ret) {
BT_ERR("Bluetooth controller init failed %d", ret); LOG_ERR("Bluetooth controller init failed %d", ret);
return ret; return ret;
} }
ret = esp_bt_controller_enable(mode); ret = esp_bt_controller_enable(mode);
if (ret) { if (ret) {
BT_ERR("Bluetooth controller enable failed: %d", ret); LOG_ERR("Bluetooth controller enable failed: %d", ret);
return ret; return ret;
} }
@ -313,7 +312,7 @@ static int bt_esp32_open(void)
return err; return err;
} }
BT_DBG("ESP32 BT started"); LOG_DBG("ESP32 BT started");
return 0; return 0;
} }

View file

@ -37,11 +37,12 @@ PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t
static void syscmd_status_not(SHCI_TL_CmdStatus_t status); static void syscmd_status_not(SHCI_TL_CmdStatus_t status);
static void sysevt_received(void *pdata); static void sysevt_received(void *pdata);
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME hci_ipm
#include "common/log.h"
#include "common/bt_str.h" #include "common/bt_str.h"
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(hci_ipm);
#define HCI_CMD 0x01 #define HCI_CMD 0x01
#define HCI_ACL 0x02 #define HCI_ACL 0x02
#define HCI_SCO 0x03 #define HCI_SCO 0x03
@ -118,7 +119,7 @@ static void sysevt_received(void *pdata)
static void syscmd_status_not(SHCI_TL_CmdStatus_t status) static void syscmd_status_not(SHCI_TL_CmdStatus_t status)
{ {
BT_DBG("status:%d", status); LOG_DBG("status:%d", status);
} }
/* /*
@ -144,7 +145,7 @@ static void tryfix_event(TL_Evt_t *tev)
(void *)((uint8_t *)mev + (sizeof(*mev))); (void *)((uint8_t *)mev + (sizeof(*mev)));
if (!bt_addr_cmp(&evt->peer_addr.a, BT_ADDR_NONE)) { if (!bt_addr_cmp(&evt->peer_addr.a, BT_ADDR_NONE)) {
BT_WARN("Invalid peer addr %s", bt_addr_le_str(&evt->peer_addr)); LOG_WRN("Invalid peer addr %s", bt_addr_le_str(&evt->peer_addr));
bt_addr_copy(&evt->peer_addr.a, &evt->peer_rpa); bt_addr_copy(&evt->peer_addr.a, &evt->peer_rpa);
evt->peer_addr.type = BT_ADDR_LE_RANDOM; evt->peer_addr.type = BT_ADDR_LE_RANDOM;
} }
@ -174,13 +175,13 @@ static void bt_ipm_rx_thread(void)
switch (hcievt->evtserial.type) { switch (hcievt->evtserial.type) {
case HCI_EVT: case HCI_EVT:
BT_DBG("EVT: hcievt->evtserial.evt.evtcode: 0x%02x", LOG_DBG("EVT: hcievt->evtserial.evt.evtcode: 0x%02x",
hcievt->evtserial.evt.evtcode); hcievt->evtserial.evt.evtcode);
switch (hcievt->evtserial.evt.evtcode) { switch (hcievt->evtserial.evt.evtcode) {
case BT_HCI_EVT_VENDOR: case BT_HCI_EVT_VENDOR:
/* Vendor events are currently unsupported */ /* Vendor events are currently unsupported */
BT_ERR("Unknown evtcode type 0x%02x", LOG_ERR("Unknown evtcode type 0x%02x",
hcievt->evtserial.evt.evtcode); hcievt->evtserial.evt.evtcode);
TL_MM_EvtDone(hcievt); TL_MM_EvtDone(hcievt);
goto end_loop; goto end_loop;
default: default:
@ -195,7 +196,7 @@ static void bt_ipm_rx_thread(void)
hcievt->evtserial.evt.evtcode, hcievt->evtserial.evt.evtcode,
discardable, timeout); discardable, timeout);
if (!buf) { if (!buf) {
BT_DBG("Discard adv report due to insufficient buf"); LOG_DBG("Discard adv report due to insufficient buf");
goto end_loop; goto end_loop;
} }
} }
@ -205,8 +206,8 @@ static void bt_ipm_rx_thread(void)
buf_tailroom = net_buf_tailroom(buf); buf_tailroom = net_buf_tailroom(buf);
buf_add_len = hcievt->evtserial.evt.plen + 2; buf_add_len = hcievt->evtserial.evt.plen + 2;
if (buf_tailroom < buf_add_len) { if (buf_tailroom < buf_add_len) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", buf_add_len,
buf_add_len, buf_tailroom); buf_tailroom);
net_buf_unref(buf); net_buf_unref(buf);
goto end_loop; goto end_loop;
} }
@ -219,15 +220,14 @@ static void bt_ipm_rx_thread(void)
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER); buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER);
acl_hdr.handle = acl->handle; acl_hdr.handle = acl->handle;
acl_hdr.len = acl->length; acl_hdr.len = acl->length;
BT_DBG("ACL: handle %x, len %x", LOG_DBG("ACL: handle %x, len %x", acl_hdr.handle, acl_hdr.len);
acl_hdr.handle, acl_hdr.len);
net_buf_add_mem(buf, &acl_hdr, sizeof(acl_hdr)); net_buf_add_mem(buf, &acl_hdr, sizeof(acl_hdr));
buf_tailroom = net_buf_tailroom(buf); buf_tailroom = net_buf_tailroom(buf);
buf_add_len = acl_hdr.len; buf_add_len = acl_hdr.len;
if (buf_tailroom < buf_add_len) { if (buf_tailroom < buf_add_len) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", buf_add_len,
buf_add_len, buf_tailroom); buf_tailroom);
net_buf_unref(buf); net_buf_unref(buf);
goto end_loop; goto end_loop;
} }
@ -236,8 +236,7 @@ static void bt_ipm_rx_thread(void)
buf_add_len); buf_add_len);
break; break;
default: default:
BT_ERR("Unknown BT buf type %d", LOG_ERR("Unknown BT buf type %d", hcievt->evtserial.type);
hcievt->evtserial.type);
TL_MM_EvtDone(hcievt); TL_MM_EvtDone(hcievt);
goto end_loop; goto end_loop;
} }
@ -317,12 +316,12 @@ void transport_init(void)
TL_BLE_InitConf_t tl_ble_config; TL_BLE_InitConf_t tl_ble_config;
SHCI_TL_HciInitConf_t shci_init_config; SHCI_TL_HciInitConf_t shci_init_config;
BT_DBG("BleCmdBuffer: %p", (void *)&BleCmdBuffer); LOG_DBG("BleCmdBuffer: %p", (void *)&BleCmdBuffer);
BT_DBG("HciAclDataBuffer: %p", (void *)&HciAclDataBuffer); LOG_DBG("HciAclDataBuffer: %p", (void *)&HciAclDataBuffer);
BT_DBG("SystemCmdBuffer: %p", (void *)&SystemCmdBuffer); LOG_DBG("SystemCmdBuffer: %p", (void *)&SystemCmdBuffer);
BT_DBG("EvtPool: %p", (void *)&EvtPool); LOG_DBG("EvtPool: %p", (void *)&EvtPool);
BT_DBG("SystemSpareEvtBuffer: %p", (void *)&SystemSpareEvtBuffer); LOG_DBG("SystemSpareEvtBuffer: %p", (void *)&SystemSpareEvtBuffer);
BT_DBG("BleSpareEvtBuffer: %p", (void *)&BleSpareEvtBuffer); LOG_DBG("BleSpareEvtBuffer: %p", (void *)&BleSpareEvtBuffer);
/**< Reference table initialization */ /**< Reference table initialization */
TL_Init(); TL_Init();
@ -357,8 +356,7 @@ static int bt_ipm_send(struct net_buf *buf)
switch (bt_buf_get_type(buf)) { switch (bt_buf_get_type(buf)) {
case BT_BUF_ACL_OUT: case BT_BUF_ACL_OUT:
BT_DBG("ACL: buf %p type %u len %u", buf, bt_buf_get_type(buf), LOG_DBG("ACL: buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
buf->len);
k_sem_take(&acl_data_ack, K_FOREVER); k_sem_take(&acl_data_ack, K_FOREVER);
net_buf_push_u8(buf, HCI_ACL); net_buf_push_u8(buf, HCI_ACL);
memcpy((void *) memcpy((void *)
@ -367,8 +365,7 @@ static int bt_ipm_send(struct net_buf *buf)
TL_BLE_SendAclData(NULL, 0); TL_BLE_SendAclData(NULL, 0);
break; break;
case BT_BUF_CMD: case BT_BUF_CMD:
BT_DBG("CMD: buf %p type %u len %u", buf, bt_buf_get_type(buf), LOG_DBG("CMD: buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
buf->len);
ble_cmd_buff->cmdserial.type = HCI_CMD; ble_cmd_buff->cmdserial.type = HCI_CMD;
ble_cmd_buff->cmdserial.cmd.plen = buf->len; ble_cmd_buff->cmdserial.cmd.plen = buf->len;
memcpy((void *)&ble_cmd_buff->cmdserial.cmd, buf->data, memcpy((void *)&ble_cmd_buff->cmdserial.cmd, buf->data,
@ -377,7 +374,7 @@ static int bt_ipm_send(struct net_buf *buf)
break; break;
default: default:
k_sem_give(&ipm_busy); k_sem_give(&ipm_busy);
BT_ERR("Unsupported type"); LOG_ERR("Unsupported type");
return -EINVAL; return -EINVAL;
} }
@ -506,7 +503,7 @@ static int bt_ipm_ble_init(void)
err = bt_ipm_set_addr(); err = bt_ipm_set_addr();
if (err) { if (err) {
BT_ERR("Can't set BLE UID addr"); LOG_ERR("Can't set BLE UID addr");
} }
/* Send ACI_WRITE_SET_TX_POWER_LEVEL */ /* Send ACI_WRITE_SET_TX_POWER_LEVEL */
buf = bt_hci_cmd_create(ACI_WRITE_SET_TX_POWER_LEVEL, 3); buf = bt_hci_cmd_create(ACI_WRITE_SET_TX_POWER_LEVEL, 3);
@ -541,7 +538,7 @@ static int c2_reset(void)
if (k_sem_take(&c2_started, STM32WB_C2_LOCK_TIMEOUT)) { if (k_sem_take(&c2_started, STM32WB_C2_LOCK_TIMEOUT)) {
return -ETIMEDOUT; return -ETIMEDOUT;
} }
BT_DBG("C2 unlocked"); LOG_DBG("C2 unlocked");
stm32wb_start_ble(); stm32wb_start_ble();
@ -580,7 +577,7 @@ static int bt_ipm_open(void)
} }
#endif /* CONFIG_BT_HCI_HOST */ #endif /* CONFIG_BT_HCI_HOST */
BT_DBG("IPM Channel Open Completed"); LOG_DBG("IPM Channel Open Completed");
return 0; return 0;
} }
@ -593,7 +590,7 @@ static int bt_ipm_close(void)
err = bt_hci_cmd_send_sync(ACI_HAL_STACK_RESET, NULL, &rsp); err = bt_hci_cmd_send_sync(ACI_HAL_STACK_RESET, NULL, &rsp);
if (err) { if (err) {
BT_ERR("IPM Channel Close Issue"); LOG_ERR("IPM Channel Close Issue");
return err; return err;
} }
net_buf_unref(rsp); net_buf_unref(rsp);
@ -606,7 +603,7 @@ static int bt_ipm_close(void)
k_thread_abort(&ipm_rx_thread_data); k_thread_abort(&ipm_rx_thread_data);
BT_DBG("IPM Channel Close Completed"); LOG_DBG("IPM Channel Close Completed");
return err; return err;
} }

View file

@ -14,9 +14,9 @@
#include <zephyr/device.h> #include <zephyr/device.h>
#include <zephyr/ipc/ipc_service.h> #include <zephyr/ipc/ipc_service.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#define LOG_MODULE_NAME bt_hci_driver #include <zephyr/logging/log.h>
#include "common/log.h" LOG_MODULE_REGISTER(bt_hci_driver);
#define RPMSG_CMD 0x01 #define RPMSG_CMD 0x01
#define RPMSG_ACL 0x02 #define RPMSG_ACL 0x02
@ -73,7 +73,7 @@ static struct net_buf *bt_rpmsg_evt_recv(const uint8_t *data, size_t remaining)
size_t buf_tailroom; size_t buf_tailroom;
if (remaining < sizeof(hdr)) { if (remaining < sizeof(hdr)) {
BT_ERR("Not enough data for event header"); LOG_ERR("Not enough data for event header");
return NULL; return NULL;
} }
@ -84,19 +84,19 @@ static struct net_buf *bt_rpmsg_evt_recv(const uint8_t *data, size_t remaining)
remaining -= sizeof(hdr); remaining -= sizeof(hdr);
if (remaining != hdr.len) { if (remaining != hdr.len) {
BT_ERR("Event payload length is not correct"); LOG_ERR("Event payload length is not correct");
return NULL; return NULL;
} }
BT_DBG("len %u", hdr.len); LOG_DBG("len %u", hdr.len);
do { do {
buf = bt_buf_get_evt(hdr.evt, discardable, discardable ? K_NO_WAIT : K_SECONDS(10)); buf = bt_buf_get_evt(hdr.evt, discardable, discardable ? K_NO_WAIT : K_SECONDS(10));
if (!buf) { if (!buf) {
if (discardable) { if (discardable) {
BT_DBG("Discardable buffer pool full, ignoring event"); LOG_DBG("Discardable buffer pool full, ignoring event");
return buf; return buf;
} }
BT_WARN("Couldn't allocate a buffer after waiting 10 seconds."); LOG_WRN("Couldn't allocate a buffer after waiting 10 seconds.");
} }
} while (!buf); } while (!buf);
@ -104,8 +104,7 @@ static struct net_buf *bt_rpmsg_evt_recv(const uint8_t *data, size_t remaining)
buf_tailroom = net_buf_tailroom(buf); buf_tailroom = net_buf_tailroom(buf);
if (buf_tailroom < remaining) { if (buf_tailroom < remaining) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", remaining, buf_tailroom);
remaining, buf_tailroom);
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
@ -122,7 +121,7 @@ static struct net_buf *bt_rpmsg_acl_recv(const uint8_t *data, size_t remaining)
size_t buf_tailroom; size_t buf_tailroom;
if (remaining < sizeof(hdr)) { if (remaining < sizeof(hdr)) {
BT_ERR("Not enough data for ACL header"); LOG_ERR("Not enough data for ACL header");
return NULL; return NULL;
} }
@ -134,25 +133,24 @@ static struct net_buf *bt_rpmsg_acl_recv(const uint8_t *data, size_t remaining)
net_buf_add_mem(buf, &hdr, sizeof(hdr)); net_buf_add_mem(buf, &hdr, sizeof(hdr));
} else { } else {
BT_ERR("No available ACL buffers!"); LOG_ERR("No available ACL buffers!");
return NULL; return NULL;
} }
if (remaining != sys_le16_to_cpu(hdr.len)) { if (remaining != sys_le16_to_cpu(hdr.len)) {
BT_ERR("ACL payload length is not correct"); LOG_ERR("ACL payload length is not correct");
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
buf_tailroom = net_buf_tailroom(buf); buf_tailroom = net_buf_tailroom(buf);
if (buf_tailroom < remaining) { if (buf_tailroom < remaining) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", remaining, buf_tailroom);
remaining, buf_tailroom);
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
BT_DBG("len %u", remaining); LOG_DBG("len %u", remaining);
net_buf_add_mem(buf, data, remaining); net_buf_add_mem(buf, data, remaining);
return buf; return buf;
@ -165,7 +163,7 @@ static struct net_buf *bt_rpmsg_iso_recv(const uint8_t *data, size_t remaining)
size_t buf_tailroom; size_t buf_tailroom;
if (remaining < sizeof(hdr)) { if (remaining < sizeof(hdr)) {
BT_ERR("Not enough data for ISO header"); LOG_ERR("Not enough data for ISO header");
return NULL; return NULL;
} }
@ -177,25 +175,24 @@ static struct net_buf *bt_rpmsg_iso_recv(const uint8_t *data, size_t remaining)
net_buf_add_mem(buf, &hdr, sizeof(hdr)); net_buf_add_mem(buf, &hdr, sizeof(hdr));
} else { } else {
BT_ERR("No available ISO buffers!"); LOG_ERR("No available ISO buffers!");
return NULL; return NULL;
} }
if (remaining != bt_iso_hdr_len(sys_le16_to_cpu(hdr.len))) { if (remaining != bt_iso_hdr_len(sys_le16_to_cpu(hdr.len))) {
BT_ERR("ISO payload length is not correct"); LOG_ERR("ISO payload length is not correct");
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
buf_tailroom = net_buf_tailroom(buf); buf_tailroom = net_buf_tailroom(buf);
if (buf_tailroom < remaining) { if (buf_tailroom < remaining) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", remaining, buf_tailroom);
remaining, buf_tailroom);
net_buf_unref(buf); net_buf_unref(buf);
return NULL; return NULL;
} }
BT_DBG("len %zu", remaining); LOG_DBG("len %zu", remaining);
net_buf_add_mem(buf, data, remaining); net_buf_add_mem(buf, data, remaining);
return buf; return buf;
@ -226,12 +223,12 @@ static void bt_rpmsg_rx(const uint8_t *data, size_t len)
break; break;
default: default:
BT_ERR("Unknown HCI type %u", pkt_indicator); LOG_ERR("Unknown HCI type %u", pkt_indicator);
return; return;
} }
if (buf) { if (buf) {
BT_DBG("Calling bt_recv(%p)", buf); LOG_DBG("Calling bt_recv(%p)", buf);
bt_recv(buf); bt_recv(buf);
@ -244,7 +241,7 @@ static int bt_rpmsg_send(struct net_buf *buf)
int err; int err;
uint8_t pkt_indicator; uint8_t pkt_indicator;
BT_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
switch (bt_buf_get_type(buf)) { switch (bt_buf_get_type(buf)) {
case BT_BUF_ACL_OUT: case BT_BUF_ACL_OUT:
@ -257,7 +254,7 @@ static int bt_rpmsg_send(struct net_buf *buf)
pkt_indicator = RPMSG_ISO; pkt_indicator = RPMSG_ISO;
break; break;
default: default:
BT_ERR("Unknown type %u", bt_buf_get_type(buf)); LOG_ERR("Unknown type %u", bt_buf_get_type(buf));
goto done; goto done;
} }
net_buf_push_u8(buf, pkt_indicator); net_buf_push_u8(buf, pkt_indicator);
@ -265,7 +262,7 @@ static int bt_rpmsg_send(struct net_buf *buf)
LOG_HEXDUMP_DBG(buf->data, buf->len, "Final HCI buffer:"); LOG_HEXDUMP_DBG(buf->data, buf->len, "Final HCI buffer:");
err = ipc_service_send(&hci_ept, buf->data, buf->len); err = ipc_service_send(&hci_ept, buf->data, buf->len);
if (err < 0) { if (err < 0) {
BT_ERR("Failed to send (err %d)", err); LOG_ERR("Failed to send (err %d)", err);
} }
done: done:
@ -297,23 +294,23 @@ static int bt_rpmsg_open(void)
const struct device *hci_ipc_instance = const struct device *hci_ipc_instance =
DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_hci_rpmsg_ipc)); DEVICE_DT_GET(DT_CHOSEN(zephyr_bt_hci_rpmsg_ipc));
BT_DBG(""); LOG_DBG("");
err = ipc_service_open_instance(hci_ipc_instance); err = ipc_service_open_instance(hci_ipc_instance);
if (err && (err != -EALREADY)) { if (err && (err != -EALREADY)) {
BT_ERR("IPC service instance initialization failed: %d\n", err); LOG_ERR("IPC service instance initialization failed: %d\n", err);
return err; return err;
} }
err = ipc_service_register_endpoint(hci_ipc_instance, &hci_ept, &hci_ept_cfg); err = ipc_service_register_endpoint(hci_ipc_instance, &hci_ept, &hci_ept_cfg);
if (err) { if (err) {
BT_ERR("Registering endpoint failed with %d", err); LOG_ERR("Registering endpoint failed with %d", err);
return err; return err;
} }
err = k_sem_take(&ipc_bound_sem, IPC_BOUND_TIMEOUT_IN_MS); err = k_sem_take(&ipc_bound_sem, IPC_BOUND_TIMEOUT_IN_MS);
if (err) { if (err) {
BT_ERR("Endpoint binding failed with %d", err); LOG_ERR("Endpoint binding failed with %d", err);
return err; return err;
} }
@ -338,7 +335,7 @@ static int bt_rpmsg_init(const struct device *unused)
err = bt_hci_driver_register(&drv); err = bt_hci_driver_register(&drv);
if (err < 0) { if (err < 0) {
BT_ERR("Failed to register BT HIC driver (err %d)", err); LOG_ERR("Failed to register BT HIC driver (err %d)", err);
} }
return err; return err;

View file

@ -17,9 +17,9 @@
#include <zephyr/bluetooth/hci.h> #include <zephyr/bluetooth/hci.h>
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/drivers/bluetooth/hci_driver.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#define LOG_MODULE_NAME bt_driver #include <zephyr/logging/log.h>
#include "common/log.h" LOG_MODULE_REGISTER(bt_driver);
#define HCI_CMD 0x01 #define HCI_CMD 0x01
#define HCI_ACL 0x02 #define HCI_ACL 0x02
@ -71,7 +71,7 @@ static K_SEM_DEFINE(sem_busy, 1, 1);
static K_KERNEL_STACK_DEFINE(spi_rx_stack, 512); static K_KERNEL_STACK_DEFINE(spi_rx_stack, 512);
static struct k_thread spi_rx_thread_data; static struct k_thread spi_rx_thread_data;
#if defined(CONFIG_BT_DEBUG_HCI_DRIVER) #if defined(CONFIG_BT_HCI_DRIVER_LOG_LEVEL_DBG)
#include <zephyr/sys/printk.h> #include <zephyr/sys/printk.h>
static inline void spi_dump_message(const uint8_t *pre, uint8_t *buf, static inline void spi_dump_message(const uint8_t *pre, uint8_t *buf,
uint8_t size) uint8_t size)
@ -163,7 +163,7 @@ static void bt_spi_isr(const struct device *unused1,
struct gpio_callback *unused2, struct gpio_callback *unused2,
uint32_t unused3) uint32_t unused3)
{ {
BT_DBG(""); LOG_DBG("");
k_sem_give(&sem_request); k_sem_give(&sem_request);
} }
@ -218,7 +218,7 @@ static bool irq_pin_high(void)
pin_state = gpio_pin_get_dt(&irq_gpio); pin_state = gpio_pin_get_dt(&irq_gpio);
BT_DBG("IRQ Pin: %d", pin_state); LOG_DBG("IRQ Pin: %d", pin_state);
return pin_state > 0; return pin_state > 0;
} }
@ -293,7 +293,7 @@ static void bt_spi_rx_thread(void)
gpio_pin_interrupt_configure_dt(&irq_gpio, GPIO_INT_DISABLE); gpio_pin_interrupt_configure_dt(&irq_gpio, GPIO_INT_DISABLE);
k_sem_take(&sem_busy, K_FOREVER); k_sem_take(&sem_busy, K_FOREVER);
BT_DBG(""); LOG_DBG("");
do { do {
init_irq_high_loop(); init_irq_high_loop();
@ -321,7 +321,7 @@ static void bt_spi_rx_thread(void)
if (ret || size == 0) { if (ret || size == 0) {
if (ret) { if (ret) {
BT_ERR("Error %d", ret); LOG_ERR("Error %d", ret);
} }
continue; continue;
} }
@ -348,14 +348,15 @@ static void bt_spi_rx_thread(void)
buf = bt_buf_get_evt(rxmsg[EVT_HEADER_EVENT], buf = bt_buf_get_evt(rxmsg[EVT_HEADER_EVENT],
discardable, timeout); discardable, timeout);
if (!buf) { if (!buf) {
BT_DBG("Discard adv report due to insufficient buf"); LOG_DBG("Discard adv report due to insufficient "
"buf");
continue; continue;
} }
} }
len = sizeof(struct bt_hci_evt_hdr) + rxmsg[EVT_HEADER_SIZE]; len = sizeof(struct bt_hci_evt_hdr) + rxmsg[EVT_HEADER_SIZE];
if (len > net_buf_tailroom(buf)) { if (len > net_buf_tailroom(buf)) {
BT_ERR("Event too long: %d", len); LOG_ERR("Event too long: %d", len);
net_buf_unref(buf); net_buf_unref(buf);
continue; continue;
} }
@ -366,14 +367,14 @@ static void bt_spi_rx_thread(void)
memcpy(&acl_hdr, &rxmsg[1], sizeof(acl_hdr)); memcpy(&acl_hdr, &rxmsg[1], sizeof(acl_hdr));
len = sizeof(acl_hdr) + sys_le16_to_cpu(acl_hdr.len); len = sizeof(acl_hdr) + sys_le16_to_cpu(acl_hdr.len);
if (len > net_buf_tailroom(buf)) { if (len > net_buf_tailroom(buf)) {
BT_ERR("ACL too long: %d", len); LOG_ERR("ACL too long: %d", len);
net_buf_unref(buf); net_buf_unref(buf);
continue; continue;
} }
net_buf_add_mem(buf, &rxmsg[1], len); net_buf_add_mem(buf, &rxmsg[1], len);
break; break;
default: default:
BT_ERR("Unknown BT buf type %d", rxmsg[0]); LOG_ERR("Unknown BT buf type %d", rxmsg[0]);
continue; continue;
} }
@ -391,11 +392,11 @@ static int bt_spi_send(struct net_buf *buf)
int pending; int pending;
int ret; int ret;
BT_DBG(""); LOG_DBG("");
/* Buffer needs an additional byte for type */ /* Buffer needs an additional byte for type */
if (buf->len >= SPI_MAX_MSG_LEN) { if (buf->len >= SPI_MAX_MSG_LEN) {
BT_ERR("Message too long"); LOG_ERR("Message too long");
return -EINVAL; return -EINVAL;
} }
@ -418,7 +419,7 @@ static int bt_spi_send(struct net_buf *buf)
net_buf_push_u8(buf, HCI_CMD); net_buf_push_u8(buf, HCI_CMD);
break; break;
default: default:
BT_ERR("Unsupported type"); LOG_ERR("Unsupported type");
k_sem_give(&sem_busy); k_sem_give(&sem_busy);
return -EINVAL; return -EINVAL;
} }
@ -449,7 +450,7 @@ static int bt_spi_send(struct net_buf *buf)
k_sem_give(&sem_busy); k_sem_give(&sem_busy);
if (ret) { if (ret) {
BT_ERR("Error %d", ret); LOG_ERR("Error %d", ret);
goto out; goto out;
} }
@ -521,7 +522,7 @@ static int bt_spi_init(const struct device *unused)
ARG_UNUSED(unused); ARG_UNUSED(unused);
if (!spi_is_ready(&bus)) { if (!spi_is_ready(&bus)) {
BT_ERR("SPI device not ready"); LOG_ERR("SPI device not ready");
return -ENODEV; return -ENODEV;
} }
@ -530,19 +531,19 @@ static int bt_spi_init(const struct device *unused)
} }
if (!device_is_ready(irq_gpio.port)) { if (!device_is_ready(irq_gpio.port)) {
BT_ERR("IRQ GPIO device not ready"); LOG_ERR("IRQ GPIO device not ready");
return -ENODEV; return -ENODEV;
} }
if (!device_is_ready(rst_gpio.port)) { if (!device_is_ready(rst_gpio.port)) {
BT_ERR("Reset GPIO device not ready"); LOG_ERR("Reset GPIO device not ready");
return -ENODEV; return -ENODEV;
} }
bt_hci_driver_register(&drv); bt_hci_driver_register(&drv);
BT_DBG("BT SPI initialized"); LOG_DBG("BT SPI initialized");
return 0; return 0;
} }

View file

@ -28,9 +28,9 @@
#include <zephyr/bluetooth/hci.h> #include <zephyr/bluetooth/hci.h>
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/drivers/bluetooth/hci_driver.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#define LOG_MODULE_NAME bt_driver #include <zephyr/logging/log.h>
#include "common/log.h" LOG_MODULE_REGISTER(bt_driver);
#define BTPROTO_HCI 1 #define BTPROTO_HCI 1
struct sockaddr_hci { struct sockaddr_hci {
@ -78,7 +78,7 @@ static struct net_buf *get_rx(const uint8_t *buf)
} }
__fallthrough; __fallthrough;
default: default:
BT_ERR("Unknown packet type: %u", buf[0]); LOG_ERR("Unknown packet type: %u", buf[0]);
} }
return NULL; return NULL;
@ -97,7 +97,7 @@ static void rx_thread(void *p1, void *p2, void *p3)
ARG_UNUSED(p2); ARG_UNUSED(p2);
ARG_UNUSED(p3); ARG_UNUSED(p3);
BT_DBG("started"); LOG_DBG("started");
while (1) { while (1) {
static uint8_t frame[512]; static uint8_t frame[512];
@ -111,7 +111,7 @@ static void rx_thread(void *p1, void *p2, void *p3)
continue; continue;
} }
BT_DBG("calling read()"); LOG_DBG("calling read()");
len = read(uc_fd, frame, sizeof(frame)); len = read(uc_fd, frame, sizeof(frame));
if (len < 0) { if (len < 0) {
@ -120,7 +120,7 @@ static void rx_thread(void *p1, void *p2, void *p3)
continue; continue;
} }
BT_ERR("Reading socket failed, errno %d", errno); LOG_ERR("Reading socket failed, errno %d", errno);
close(uc_fd); close(uc_fd);
uc_fd = -1; uc_fd = -1;
return; return;
@ -128,22 +128,21 @@ static void rx_thread(void *p1, void *p2, void *p3)
buf = get_rx(frame); buf = get_rx(frame);
if (!buf) { if (!buf) {
BT_DBG("Discard adv report due to insufficient buf"); LOG_DBG("Discard adv report due to insufficient buf");
continue; continue;
} }
buf_tailroom = net_buf_tailroom(buf); buf_tailroom = net_buf_tailroom(buf);
buf_add_len = len - 1; buf_add_len = len - 1;
if (buf_tailroom < buf_add_len) { if (buf_tailroom < buf_add_len) {
BT_ERR("Not enough space in buffer %zu/%zu", LOG_ERR("Not enough space in buffer %zu/%zu", buf_add_len, buf_tailroom);
buf_add_len, buf_tailroom);
net_buf_unref(buf); net_buf_unref(buf);
continue; continue;
} }
net_buf_add_mem(buf, &frame[1], buf_add_len); net_buf_add_mem(buf, &frame[1], buf_add_len);
BT_DBG("Calling bt_recv(%p)", buf); LOG_DBG("Calling bt_recv(%p)", buf);
bt_recv(buf); bt_recv(buf);
@ -153,10 +152,10 @@ static void rx_thread(void *p1, void *p2, void *p3)
static int uc_send(struct net_buf *buf) static int uc_send(struct net_buf *buf)
{ {
BT_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len); LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
if (uc_fd < 0) { if (uc_fd < 0) {
BT_ERR("User channel not open"); LOG_ERR("User channel not open");
return -EIO; return -EIO;
} }
@ -174,7 +173,7 @@ static int uc_send(struct net_buf *buf)
} }
__fallthrough; __fallthrough;
default: default:
BT_ERR("Unknown buffer type"); LOG_ERR("Unknown buffer type");
return -EINVAL; return -EINVAL;
} }
@ -215,18 +214,18 @@ static int user_chan_open(uint16_t index)
static int uc_open(void) static int uc_open(void)
{ {
if (bt_dev_index < 0) { if (bt_dev_index < 0) {
BT_ERR("No Bluetooth device specified"); LOG_ERR("No Bluetooth device specified");
return -ENODEV; return -ENODEV;
} }
BT_DBG("hci%d", bt_dev_index); LOG_DBG("hci%d", bt_dev_index);
uc_fd = user_chan_open(bt_dev_index); uc_fd = user_chan_open(bt_dev_index);
if (uc_fd < 0) { if (uc_fd < 0) {
return uc_fd; return uc_fd;
} }
BT_DBG("User Channel opened as fd %d", uc_fd); LOG_DBG("User Channel opened as fd %d", uc_fd);
k_thread_create(&rx_thread_data, rx_thread_stack, k_thread_create(&rx_thread_data, rx_thread_stack,
K_KERNEL_STACK_SIZEOF(rx_thread_stack), K_KERNEL_STACK_SIZEOF(rx_thread_stack),
@ -234,7 +233,7 @@ static int uc_open(void)
K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO),
0, K_NO_WAIT); 0, K_NO_WAIT);
BT_DBG("returning"); LOG_DBG("returning");
return 0; return 0;
} }

View file

@ -326,10 +326,10 @@ int bt_tbs_set_uri_scheme_list(uint8_t bearer_index, const char **uri_list,
*/ */
void bt_tbs_register_cb(struct bt_tbs_cb *cbs); void bt_tbs_register_cb(struct bt_tbs_cb *cbs);
#if defined(CONFIG_BT_DEBUG_TBS) #if defined(CONFIG_BT_TBS_LOG_LEVEL_DBG)
/** @brief Prints all calls of all services to the debug log */ /** @brief Prints all calls of all services to the debug log */
void bt_tbs_dbg_print_calls(void); void bt_tbs_dbg_print_calls(void);
#endif /* defined(CONFIG_BT_DEBUG_TBS) */ #endif /* defined(CONFIG_BT_TBS_LOG_LEVEL_DBG) */
struct bt_tbs_client_call_state { struct bt_tbs_client_call_state {
uint8_t index; uint8_t index;

View file

@ -1074,7 +1074,7 @@ static inline int bt_ots_obj_id_to_str(uint64_t obj_id, char *str, size_t len)
id[5], id[4], id[3], id[2], id[1], id[0]); id[5], id[4], id[3], id[2], id[1], id[0]);
} }
/** @brief Displays one or more object metadata as text with BT_INFO. /** @brief Displays one or more object metadata as text with LOG_INF.
* *
* @param metadata Pointer to the first (or only) metadata in an array. * @param metadata Pointer to the first (or only) metadata in an array.
* @param count Number of metadata objects to display information of. * @param count Number of metadata objects to display information of.

View file

@ -28,9 +28,9 @@
#include <zephyr/logging/log_ctrl.h> #include <zephyr/logging/log_ctrl.h>
#endif /* CONFIG_BT_HCI_VS_FATAL_ERROR */ #endif /* CONFIG_BT_HCI_VS_FATAL_ERROR */
#define BT_DBG_ENABLED 0 #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME hci_rpmsg
#include "common/log.h" LOG_MODULE_REGISTER(hci_rpmsg, CONFIG_BT_LOG_LEVEL);
static struct ipc_ept hci_ept; static struct ipc_ept hci_ept;
@ -211,8 +211,7 @@ static void hci_rpmsg_send(struct net_buf *buf, bool is_fatal_err)
uint8_t retries = 0; uint8_t retries = 0;
int ret; int ret;
LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
buf->len);
LOG_HEXDUMP_DBG(buf->data, buf->len, "Controller buffer:"); LOG_HEXDUMP_DBG(buf->data, buf->len, "Controller buffer:");

View file

@ -51,12 +51,12 @@ CONFIG_BT_MESH_LABEL_COUNT=0
#CONFIG_BT_DEBUG_MONITOR_UART=y #CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_BT_DEBUG_LOG=y #CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_MESH_DEBUG=y #CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_NET=y #CONFIG_BT_MESH_NET_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_PROXY=y #CONFIG_BT_MESH_PROXY_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_TRANS=y #CONFIG_BT_MESH_TRANS_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_PROV=y #CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_BEACON=y #CONFIG_BT_MESH_BEACON_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_CRYPTO=y #CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ADV=y #CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ACCESS=y #CONFIG_BT_MESH_ACCESS_LOG_LEVEL_DBG=y

View file

@ -39,11 +39,11 @@ CONFIG_BT_MESH_LABEL_COUNT=0
#CONFIG_BT_MESH_SELF_TEST=y #CONFIG_BT_MESH_SELF_TEST=y
#CONFIG_BT_MESH_IV_UPDATE_TEST=y #CONFIG_BT_MESH_IV_UPDATE_TEST=y
#CONFIG_BT_MESH_DEBUG=y #CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_NET=y #CONFIG_BT_MESH_NET_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_TRANS=y #CONFIG_BT_MESH_TRANS_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_PROV=y #CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_BEACON=y #CONFIG_BT_MESH_BEACON_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_CRYPTO=y #CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ADV=y #CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ACCESS=y #CONFIG_BT_MESH_ACCESS_LOG_LEVEL_DBG=y

View file

@ -41,5 +41,5 @@ CONFIG_BT_MESH_LABEL_COUNT=3
CONFIG_BT_DEBUG_LOG=y CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_MESH_DEBUG=y CONFIG_BT_MESH_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_DEBUG_MODEL=y CONFIG_BT_MESH_MODEL_LOG_LEVEL_DBG=y

View file

@ -54,11 +54,11 @@ CONFIG_BT_MESH_LABEL_COUNT=0
#CONFIG_BT_DEBUG_LOG=y #CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_MESH_DEBUG=y #CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_NET=y #CONFIG_BT_MESH_NET_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_TRANS=y #CONFIG_BT_MESH_TRANS_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_PROV=y #CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_BEACON=y #CONFIG_BT_MESH_BEACON_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_CRYPTO=y #CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ADV=y #CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ACCESS=y #CONFIG_BT_MESH_ACCESS_LOG_LEVEL_DBG=y

View file

@ -39,16 +39,16 @@ CONFIG_NVS=y
CONFIG_SETTINGS=y CONFIG_SETTINGS=y
CONFIG_BT_MESH_RPL_STORE_TIMEOUT=600 CONFIG_BT_MESH_RPL_STORE_TIMEOUT=600
#CONFIG_BT_MESH_DEBUG=y #CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_SETTINGS=y #CONFIG_BT_MESH_SETTINGS_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_NET=y #CONFIG_BT_MESH_NET_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_MODEL=y #CONFIG_BT_MESH_MODEL_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_TRANS=y #CONFIG_BT_MESH_TRANS_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ACCESS=y #CONFIG_BT_MESH_ACCESS_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_LOW_POWER=y #CONFIG_BT_MESH_LOW_POWER=y
#CONFIG_BT_MESH_DEBUG_PROV=y #CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_LOW_POWER=y #CONFIG_BT_MESH_LOW_POWER_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_BEACON=y #CONFIG_BT_MESH_BEACON_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_CRYPTO=y #CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ADV=y #CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y

View file

@ -66,18 +66,18 @@ CONFIG_UART_CONSOLE=y
CONFIG_BT_DEBUG_LOG=y CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_MESH_DEBUG=y CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_PROV=y #CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_PROXY=y #CONFIG_BT_MESH_PROXY_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_BEACON=y #CONFIG_BT_MESH_BEACON_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_NET=y #CONFIG_BT_MESH_NET_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_TRANS=y #CONFIG_BT_MESH_TRANS_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_LOW_POWER=y #CONFIG_BT_MESH_LOW_POWER_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_FRIEND=y #CONFIG_BT_MESH_FRIEND_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_MODEL=y #CONFIG_BT_MESH_MODEL_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ACCESS=y #CONFIG_BT_MESH_ACCESS_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_CRYPTO=y #CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ADV=y #CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_SELF_TEST=y #CONFIG_BT_MESH_SELF_TEST=y
#CONFIG_BT_HCI_VS_EXT=n #CONFIG_BT_HCI_VS_EXT=n
@ -86,10 +86,10 @@ CONFIG_BT_MESH_DEBUG=y
CONFIG_BT_RX_STACK_SIZE=4096 CONFIG_BT_RX_STACK_SIZE=4096
#CONFIG_BT_DEBUG_HCI_DRIVER=y #CONFIG_BT_HCI_DRIVER_LOG_LEVEL_DBG=y
#CONFIG_BT_DEBUG_HCI_CORE=y #CONFIG_BT_HCI_CORE_LOG_LEVEL_DBG=y
#CONFIG_BT_DEBUG_GATT=y #CONFIG_BT_GATT_LOG_LEVEL_DBG=y
#CONFIG_BT_DEBUG_CONN=y #CONFIG_BT_CONN_LOG_LEVEL_DBG=y
CONFIG_BT_MAX_CONN=1 CONFIG_BT_MAX_CONN=1
CONFIG_BT_CTLR_RX_BUFFERS=6 CONFIG_BT_CTLR_RX_BUFFERS=6

View file

@ -61,24 +61,24 @@ CONFIG_BT_MESH_LABEL_COUNT=3
#CONFIG_BT_DEBUG_MONITOR_UART=y #CONFIG_BT_DEBUG_MONITOR_UART=y
#CONFIG_BT_DEBUG_LOG=y #CONFIG_BT_DEBUG_LOG=y
##CONFIG_BT_MESH_DEBUG=y ##CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_PROV=y #CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_PROXY=y #CONFIG_BT_MESH_PROXY_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_BEACON=y #CONFIG_BT_MESH_BEACON_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_NET=y #CONFIG_BT_MESH_NET_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_TRANS=y #CONFIG_BT_MESH_TRANS_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_SETTINGS=y #CONFIG_BT_MESH_SETTINGS_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_LOW_POWER=y #CONFIG_BT_MESH_LOW_POWER_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_FRIEND=y #CONFIG_BT_MESH_FRIEND_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_MODEL=y #CONFIG_BT_MESH_MODEL_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ACCESS=y #CONFIG_BT_MESH_ACCESS_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_CRYPTO=y #CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ADV=y #CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_SELF_TEST=y #CONFIG_BT_MESH_SELF_TEST=y
CONFIG_GPIO=y CONFIG_GPIO=y
CONFIG_BT_CTLR_ADVANCED_FEATURES=y CONFIG_BT_CTLR_ADVANCED_FEATURES=y
CONFIG_BT_HCI_TX_STACK_SIZE=1024 CONFIG_BT_HCI_TX_STACK_SIZE=1024
#CONFIG_BT_DEBUG_HCI_CORE=y #CONFIG_BT_HCI_CORE_LOG_LEVEL_DBG=y
#CONFIG_BT_DEBUG_HCI_DRIVER=y #CONFIG_BT_HCI_DRIVER_LOG_LEVEL_DBG=y

View file

@ -13,9 +13,9 @@ CONFIG_BT_DEVICE_NAME="reel board"
CONFIG_BT_DEVICE_NAME_MAX=32 CONFIG_BT_DEVICE_NAME_MAX=32
CONFIG_BT_DEBUG_LOG=y CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_MESH_DEBUG=y CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_DEBUG_HCI_CORE=y #CONFIG_BT_HCI_CORE_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_DEBUG_ADV=y #CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y
CONFIG_BT_OBSERVER=y CONFIG_BT_OBSERVER=y
CONFIG_BT_BROADCASTER=y CONFIG_BT_BROADCASTER=y

View file

@ -31,14 +31,21 @@ config BT_AICS_MAX_INPUT_DESCRIPTION_SIZE
range 0 512 range 0 512
help help
This option sets the maximum input description size in octets. This option sets the maximum input description size in octets.
############# DEBUG ############# ############# DEBUG #############
config BT_DEBUG_AICS config BT_DEBUG_AICS
bool "Audio Input Control Service debug" bool "Audio Input Control Service debug"
select DEPRECATED
help help
Use this option to enable Audio Input Control Service debug logs for Use this option to enable Audio Input Control Service debug logs for
the Bluetooth Audio functionality. the Bluetooth Audio functionality.
module = BT_AICS
legacy-debug-sym = BT_DEBUG_AICS
module-str = "Audio Input Control Service"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_AICS endif # BT_AICS
##################### Audio Input Control Service Client ##################### ##################### Audio Input Control Service Client #####################
@ -58,15 +65,20 @@ config BT_AICS_CLIENT
help help
This hidden option enables support for Audio Input Control Service. This hidden option enables support for Audio Input Control Service.
if BT_AICS_CLIENT if BT_AICS_CLIENT
############# DEBUG ############# ############# DEBUG #############
config BT_DEBUG_AICS_CLIENT config BT_DEBUG_AICS_CLIENT
bool "Audio Input Control Service client debug" bool "Audio Input Control Service client debug"
select DEPRECATED
help help
Use this option to enable Audio Input Control Service client debug Use this option to enable Audio Input Control Service client debug
logs for the Bluetooth Audio functionality. logs for the Bluetooth Audio functionality.
module = BT_AICS_CLIENT
legacy-debug-sym = BT_DEBUG_AICS_CLIENT
module-str = "Audio Input Control Service client"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_AICS_CLIENT endif # BT_AICS_CLIENT

View file

@ -262,14 +262,20 @@ endif # BT_BAP_BROADCAST_ASSISTANT
config BT_AUDIO_DEBUG_STREAM config BT_AUDIO_DEBUG_STREAM
bool "Bluetooth Audio Stream debug" bool "Bluetooth Audio Stream debug"
select DEPRECATED
depends on BT_AUDIO_STREAM depends on BT_AUDIO_STREAM
help help
Use this option to enable Bluetooth Audio Stream debug logs for the Use this option to enable Bluetooth Audio Stream debug logs for the
Bluetooth Audio functionality. Bluetooth Audio functionality.
module = BT_AUDIO_STREAM
legacy-debug-sym = BT_AUDIO_DEBUG_STREAM
module-str = "Bluetooth Audio Stream"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
config BT_AUDIO_DEBUG_STREAM_DATA config BT_AUDIO_DEBUG_STREAM_DATA
bool "Bluetooth Audio Stream data debug" bool "Bluetooth Audio Stream data debug"
depends on BT_AUDIO_DEBUG_STREAM depends on BT_AUDIO_STREAM_LOG_LEVEL_DBG
help help
Use this option to enable Bluetooth Audio Stream data debug logs for Use this option to enable Bluetooth Audio Stream data debug logs for
the Bluetooth Audio functionality. This will enable debug logs for all the Bluetooth Audio functionality. This will enable debug logs for all
@ -277,53 +283,95 @@ config BT_AUDIO_DEBUG_STREAM_DATA
config BT_DEBUG_ASCS config BT_DEBUG_ASCS
bool "Audio Stream Control Service debug" bool "Audio Stream Control Service debug"
select DEPRECATED
depends on BT_ASCS depends on BT_ASCS
help help
Use this option to enable Audio Stream Control Service debug logs for Use this option to enable Audio Stream Control Service debug logs for
the Bluetooth Audio functionality. the Bluetooth Audio functionality.
module = BT_ASCS
legacy-debug-sym = BT_DEBUG_ASCS
module-str = "Audio Stream Control Service"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
config BT_AUDIO_DEBUG_UNICAST_SERVER config BT_AUDIO_DEBUG_UNICAST_SERVER
bool "Bluetooth Audio Unicast Server debug" bool "Bluetooth Audio Unicast Server debug"
select DEPRECATED
depends on BT_AUDIO_UNICAST_SERVER depends on BT_AUDIO_UNICAST_SERVER
help help
Use this option to enable Bluetooth Audio Unicast Server debug logs Use this option to enable Bluetooth Audio Unicast Server debug logs
for the Bluetooth Audio functionality. for the Bluetooth Audio functionality.
module = BT_AUDIO_UNICAST_SERVER
legacy-debug-sym = BT_AUDIO_DEBUG_UNICAST_SERVER
module-str = "Bluetooth Audio Unicast Server"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
config BT_AUDIO_DEBUG_UNICAST_CLIENT config BT_AUDIO_DEBUG_UNICAST_CLIENT
bool "Basic Audio Profile debug" bool "Basic Audio Profile debug"
select DEPRECATED
depends on BT_AUDIO_UNICAST_CLIENT depends on BT_AUDIO_UNICAST_CLIENT
help help
Use this option to enable Basic Audio Profile debug logs for the Use this option to enable Basic Audio Profile debug logs for the
Bluetooth Audio functionality. Bluetooth Audio functionality.
module = BT_AUDIO_UNICAST_CLIENT
legacy-debug-sym = BT_AUDIO_DEBUG_UNICAST_CLIENT
module-str = "Basic Audio Profile"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
config BT_AUDIO_DEBUG_BROADCAST_SOURCE config BT_AUDIO_DEBUG_BROADCAST_SOURCE
bool "Bluetooth Audio Broadcast Source debug" bool "Bluetooth Audio Broadcast Source debug"
select DEPRECATED
depends on BT_AUDIO_BROADCAST_SOURCE depends on BT_AUDIO_BROADCAST_SOURCE
help help
Use this option to enable Bluetooth Audio Broadcast Source debug logs Use this option to enable Bluetooth Audio Broadcast Source debug logs
for the Bluetooth Audio functionality. for the Bluetooth Audio functionality.
module = BT_AUDIO_BROADCAST_SOURCE
legacy-debug-sym = BT_AUDIO_DEBUG_BROADCAST_SOURCE
module-str = "Bluetooth Audio Broadcast Source"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
config BT_AUDIO_DEBUG_BROADCAST_SINK config BT_AUDIO_DEBUG_BROADCAST_SINK
bool "Bluetooth Audio Broadcast Sink debug" bool "Bluetooth Audio Broadcast Sink debug"
select DEPRECATED
depends on BT_AUDIO_BROADCAST_SINK depends on BT_AUDIO_BROADCAST_SINK
help help
Use this option to enable Bluetooth Audio Broadcast Sink debug logs Use this option to enable Bluetooth Audio Broadcast Sink debug logs
for the Bluetooth Audio functionality. for the Bluetooth Audio functionality.
module = BT_AUDIO_BROADCAST_SINK
legacy-debug-sym = BT_AUDIO_DEBUG_BROADCAST_SINK
module-str = "Bluetooth Audio Broadcast Sink"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
config BT_DEBUG_BAP_SCAN_DELEGATOR config BT_DEBUG_BAP_SCAN_DELEGATOR
bool "Broadcast Audio Scan Service debug" bool "Broadcast Audio Scan Service debug"
select DEPRECATED
depends on BT_BAP_SCAN_DELEGATOR depends on BT_BAP_SCAN_DELEGATOR
help help
Use this option to enable Broadcast Audio Scan Service debug logs for Use this option to enable Broadcast Audio Scan Service debug logs for
the Bluetooth Audio functionality. the Bluetooth Audio functionality.
module = BT_BAP_SCAN_DELEGATOR
legacy-debug-sym = BT_DEBUG_BAP_SCAN_DELEGATOR
module-str = "Broadcast Audio Scan Service"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
config BT_DEBUG_BAP_BROADCAST_ASSISTANT config BT_DEBUG_BAP_BROADCAST_ASSISTANT
bool "Broadcast Audio Scan Service client debug" bool "Broadcast Audio Scan Service client debug"
select DEPRECATED
depends on BT_BAP_BROADCAST_ASSISTANT depends on BT_BAP_BROADCAST_ASSISTANT
help help
Use this option to enable Broadcast Audio Scan Service client Use this option to enable Broadcast Audio Scan Service client
debug logs for the Bluetooth Audio functionality. debug logs for the Bluetooth Audio functionality.
module = BT_BAP_BROADCAST_ASSISTANT
legacy-debug-sym = BT_DEBUG_BAP_BROADCAST_ASSISTANT
module-str = "Broadcast Audio Scan Service client debug"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
config BT_AUDIO_STREAM config BT_AUDIO_STREAM
# Virtual/hidden option # Virtual/hidden option
bool bool

View file

@ -28,11 +28,17 @@ config BT_CAP_ACCEPTOR_SET_MEMBER
config BT_DEBUG_CAP_ACCEPTOR config BT_DEBUG_CAP_ACCEPTOR
bool "Common Audio Profile debug" bool "Common Audio Profile debug"
select DEPRECATED
depends on BT_CAP_ACCEPTOR depends on BT_CAP_ACCEPTOR
help help
Use this option to enable CAP debug logs for the Use this option to enable CAP debug logs for the
Bluetooth Audio functionality. Bluetooth Audio functionality.
module = BT_CAP_ACCEPTOR
legacy-debug-sym = BT_DEBUG_CAP_ACCEPTOR
module-str = "Common Audio Profile"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
config BT_CAP_INITIATOR config BT_CAP_INITIATOR
bool "Common Audio Profile Initiator Role Support [EXPERIMENTAL]" bool "Common Audio Profile Initiator Role Support [EXPERIMENTAL]"
depends on (BT_AUDIO_UNICAST_CLIENT && BT_CSIP_SET_COORDINATOR) || BT_AUDIO_BROADCAST_SOURCE depends on (BT_AUDIO_UNICAST_CLIENT && BT_CSIP_SET_COORDINATOR) || BT_AUDIO_BROADCAST_SOURCE

View file

@ -51,10 +51,16 @@ config BT_CSIP_SET_MEMBER_MAX_INSTANCE_COUNT
config BT_DEBUG_CSIP_SET_MEMBER config BT_DEBUG_CSIP_SET_MEMBER
bool "Coordinated Set Identification Service debug" bool "Coordinated Set Identification Service debug"
select DEPRECATED
help help
Use this option to enable Coordinated Set Identification Service debug Use this option to enable Coordinated Set Identification Service debug
logs for the Bluetooth Audio functionality. logs for the Bluetooth Audio functionality.
module = BT_CSIP_SET_MEMBER
legacy-debug-sym = BT_DEBUG_CSIP_SET_MEMBER
module-str = "Coordinated Set Identification Service"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_CSIP_SET_MEMBER endif # BT_CSIP_SET_MEMBER
#################### Coordinated Set Identification Client #################### #################### Coordinated Set Identification Client ####################
@ -99,15 +105,27 @@ config BT_CSIP_SET_COORDINATOR_ENC_SIRK_SUPPORT
config BT_DEBUG_CSIP_SET_COORDINATOR config BT_DEBUG_CSIP_SET_COORDINATOR
bool "Coordinated Set Identification Profile Set Coordinator debug" bool "Coordinated Set Identification Profile Set Coordinator debug"
select DEPRECATED
help help
Use this option to enable Coordinated Set Identification Profile Use this option to enable Coordinated Set Identification Profile
Set Coordinator debug logs for the Bluetooth Audio functionality. Set Coordinator debug logs for the Bluetooth Audio functionality.
module = BT_CSIP_SET_COORDINATOR
legacy-debug-sym = BT_DEBUG_CSIP_SET_COORDINATOR
module-str = "Coordinated Set Identification Profile Set Coordinator"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_CSIP_SET_COORDINATOR endif # BT_CSIP_SET_COORDINATOR
config BT_DEBUG_CSIP_SET_MEMBER_CRYPTO config BT_DEBUG_CSIP_SET_MEMBER_CRYPTO
bool "Coordinated Set Identification Profile crypto functions debug" bool "Coordinated Set Identification Profile crypto functions debug"
select DEPRECATED
depends on BT_CSIP_SET_COORDINATOR || BT_CSIP_SET_MEMBER depends on BT_CSIP_SET_COORDINATOR || BT_CSIP_SET_MEMBER
help help
Use this option to enable Coordinated Set Identification Profile Use this option to enable Coordinated Set Identification Profile
crypto functions debug logs for the Bluetooth Audio functionality. crypto functions debug logs for the Bluetooth Audio functionality.
module = BT_CSIP_SET_MEMBER_CRYPTO
legacy-debug-sym = BT_DEBUG_CSIP_SET_MEMBER_CRYPTO
module-str = "Coordinated Set Identification Profile crypto functions"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"

View file

@ -97,9 +97,15 @@ endif # BT_HAS_PRESET_SUPPORT
config BT_DEBUG_HAS config BT_DEBUG_HAS
bool "Hearing Access Service debug" bool "Hearing Access Service debug"
select DEPRECATED
help help
This option enables enables Hearing Access Service debug logs. This option enables enables Hearing Access Service debug logs.
module = BT_HAS
legacy-debug-sym = BT_DEBUG_HAS
module-str = "Hearing Access Service"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_HAS endif # BT_HAS
config BT_HAS_CLIENT config BT_HAS_CLIENT
@ -114,6 +120,12 @@ config BT_HAS_CLIENT
config BT_DEBUG_HAS_CLIENT config BT_DEBUG_HAS_CLIENT
bool "Hearing Access Service Client debug" bool "Hearing Access Service Client debug"
select DEPRECATED
depends on BT_HAS_CLIENT depends on BT_HAS_CLIENT
help help
This option enables enables Hearing Access Service Client debug logs. This option enables enables Hearing Access Service Client debug logs.
module = BT_HAS_CLIENT
legacy-debug-sym = BT_DEBUG_HAS_CLIENT
module-str = "Hearing Access Service Client"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"

View file

@ -21,10 +21,16 @@ if BT_MCS
config BT_DEBUG_MCS config BT_DEBUG_MCS
bool "Media Control Service debug" bool "Media Control Service debug"
select DEPRECATED
help help
Use this option to enable Media Control Service debug logs for the Use this option to enable Media Control Service debug logs for the
Bluetooth Audio functionality. Bluetooth Audio functionality.
module = BT_MCS
legacy-debug-sym = BT_DEBUG_MCS
module-str = "Media Control Service"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_MCS endif # BT_MCS
#### Media Control Client ################################ #### Media Control Client ################################
@ -134,8 +140,14 @@ config BT_MCC_SHELL
config BT_DEBUG_MCC config BT_DEBUG_MCC
bool "Media Control Client debug" bool "Media Control Client debug"
select DEPRECATED
help help
Use this option to enable Media Control Client debug logs for the Use this option to enable Media Control Client debug logs for the
Bluetooth Audio functionality. Bluetooth Audio functionality.
module = BT_MCC
legacy-debug-sym = BT_DEBUG_MCC
module-str = "Media Control Client"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_MCC endif # BT_MCC

View file

@ -59,7 +59,13 @@ config MCTL_REMOTE_PLAYER_CONTROL_OBJECTS
config MCTL_DEBUG config MCTL_DEBUG
bool "Media control debug" bool "Media control debug"
select DEPRECATED
help help
Use this option to enable Media control debug logs Use this option to enable Media control debug logs
module = MCTL
legacy-debug-sym = MCTL_DEBUG
module-str = "Media control"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # MCTL endif # MCTL

View file

@ -37,10 +37,16 @@ config BT_MICP_MIC_DEV_AICS
config BT_DEBUG_MICP_MIC_DEV config BT_DEBUG_MICP_MIC_DEV
bool "Microphone Input Control Profile Microphone Device debug" bool "Microphone Input Control Profile Microphone Device debug"
select DEPRECATED
help help
Use this option to enable Microphone Input Control Profile Use this option to enable Microphone Input Control Profile
Microphone Device debug logs for the Bluetooth Audio functionality. Microphone Device debug logs for the Bluetooth Audio functionality.
module = BT_MICP_MIC_DEV
legacy-debug-sym = BT_DEBUG_MICP_MIC_DEV
module-str = "Microphone Input Control Profile Microphone Device"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_MICP_MIC_DEV endif # BT_MICP_MIC_DEV
########### Microphone Input Control Profile Microphone Controller ########### ########### Microphone Input Control Profile Microphone Controller ###########
@ -75,8 +81,14 @@ config BT_MICP_MIC_CTLR_AICS
config BT_DEBUG_MICP_MIC_CTLR config BT_DEBUG_MICP_MIC_CTLR
bool "Microphone Input Control Profile Microphone Controller debug" bool "Microphone Input Control Profile Microphone Controller debug"
select DEPRECATED
help help
Use this option to enable Microphone Input Control Profile Microphone Use this option to enable Microphone Input Control Profile Microphone
Controller debug logs for the Bluetooth Audio functionality. Controller debug logs for the Bluetooth Audio functionality.
module = BT_MICP_MIC_CTLR
legacy-debug-sym = BT_DEBUG_MICP_MIC_CTLR
module-str = "Microphone Input Control Profile Microphone Controller"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_MICP_MIC_CTLR endif # BT_MICP_MIC_CTLR

View file

@ -109,7 +109,13 @@ endif # BT_MPL_OBJECTS
config BT_DEBUG_MPL config BT_DEBUG_MPL
bool "Media player debug" bool "Media player debug"
select DEPRECATED
help help
Enables debug logs for the media player Enables debug logs for the media player
module = BT_MPL
legacy-debug-sym = BT_DEBUG_MPL
module-str = "Media player"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_MPL endif # BT_MPL

View file

@ -90,9 +90,15 @@ config BT_PACS
config BT_DEBUG_PACS config BT_DEBUG_PACS
bool "Published Audio Capabilities Service debug" bool "Published Audio Capabilities Service debug"
select DEPRECATED
depends on BT_PACS depends on BT_PACS
help help
Use this option to enable Published Audio Capabilities Service debug Use this option to enable Published Audio Capabilities Service debug
logs for the Bluetooth Audio functionality. logs for the Bluetooth Audio functionality.
module = BT_PACS
legacy-debug-sym = BT_DEBUG_PACS
module-str = "Published Audio Capabilities Service"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endmenu endmenu

View file

@ -131,10 +131,16 @@ config BT_TBS_AUTHORIZATION
config BT_DEBUG_TBS config BT_DEBUG_TBS
bool "Telephone Bearer Service debug" bool "Telephone Bearer Service debug"
select DEPRECATED
help help
Use this option to enable Telephone Bearer Service debug logs for the Use this option to enable Telephone Bearer Service debug logs for the
Bluetooth Audio functionality. Bluetooth Audio functionality.
module = BT_TBS
legacy-debug-sym = BT_DEBUG_TBS
module-str = "Telephone Bearer Service"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_TBS endif # BT_TBS
@ -320,10 +326,16 @@ config BT_TBS_CLIENT_CALL_FRIENDLY_NAME
config BT_DEBUG_TBS_CLIENT config BT_DEBUG_TBS_CLIENT
bool "Telephone Bearer Service client debug" bool "Telephone Bearer Service client debug"
select DEPRECATED
help help
Use this option to enable Telephone Bearer Service client debug logs Use this option to enable Telephone Bearer Service client debug logs
for the Bluetooth Audio functionality. for the Bluetooth Audio functionality.
module = BT_TBS_CLIENT
legacy-debug-sym = BT_DEBUG_TBS_CLIENT
module-str = "Telephone Bearer Service client"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_TBS_CLIENT endif # BT_TBS_CLIENT
if BT_TBS || BT_TBS_CLIENT if BT_TBS || BT_TBS_CLIENT

View file

@ -49,10 +49,16 @@ config BT_VCS_AICS
config BT_DEBUG_VCS config BT_DEBUG_VCS
bool "Volume Control Service debug" bool "Volume Control Service debug"
select DEPRECATED
help help
Use this option to enable Volume Control Service debug logs for the Use this option to enable Volume Control Service debug logs for the
Bluetooth Audio functionality. Bluetooth Audio functionality.
module = BT_VCS
legacy-debug-sym = BT_DEBUG_VCS
module-str = "Volume Control Service"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_VCS endif # BT_VCS
##################### Volume Control Profile Client ##################### ##################### Volume Control Profile Client #####################
@ -101,8 +107,14 @@ config BT_VCS_CLIENT_AICS
config BT_DEBUG_VCS_CLIENT config BT_DEBUG_VCS_CLIENT
bool "Volume Control Profile debug" bool "Volume Control Profile debug"
select DEPRECATED
help help
Use this option to enable Volume Control Profile debug logs for the Use this option to enable Volume Control Profile debug logs for the
Bluetooth Audio functionality. Bluetooth Audio functionality.
module = BT_VCS_CLIENT
legacy-debug-sym = BT_DEBUG_VCS_CLIENT
module-str = "Volume Control Profile"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_VCS_CLIENT endif # BT_VCS_CLIENT

View file

@ -35,10 +35,16 @@ config BT_VOCS_MAX_OUTPUT_DESCRIPTION_SIZE
config BT_DEBUG_VOCS config BT_DEBUG_VOCS
bool "Volume Offset Control Service debug" bool "Volume Offset Control Service debug"
select DEPRECATED
help help
Use this option to enable Volume Offset Control Service debug logs for Use this option to enable Volume Offset Control Service debug logs for
the Bluetooth Audio functionality. the Bluetooth Audio functionality.
module = BT_VOCS
legacy-debug-sym = BT_DEBUG_VOCS
module-str = "Volume Offset Control Service"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_VOCS endif # BT_VOCS
##################### Volume Offset Control Service Client ##################### ##################### Volume Offset Control Service Client #####################
@ -58,15 +64,20 @@ config BT_VOCS_CLIENT
help help
This hidden option enables support for Volume Offset Control Service. This hidden option enables support for Volume Offset Control Service.
if BT_VOCS_CLIENT if BT_VOCS_CLIENT
############# DEBUG ############# ############# DEBUG #############
config BT_DEBUG_VOCS_CLIENT config BT_DEBUG_VOCS_CLIENT
bool "Volume Offset Control Service client debug" bool "Volume Offset Control Service client debug"
select DEPRECATED
help help
Use this option to enable Volume Offset Control Service client debug Use this option to enable Volume Offset Control Service client debug
logs for the Bluetooth Audio functionality. logs for the Bluetooth Audio functionality.
module = BT_VOCS_CLIENT
legacy-debug-sym = BT_DEBUG_VOCS_CLIENT
module-str = "Volume Offset Control Service client"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_VOCS_CLIENT endif # BT_VOCS_CLIENT

View file

@ -20,9 +20,9 @@
#include "aics_internal.h" #include "aics_internal.h"
#include "audio_internal.h" #include "audio_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_AICS) #define LOG_LEVEL CONFIG_BT_AICS_LOG_LEVEL
#define LOG_MODULE_NAME bt_aics #include <zephyr/logging/log.h>
#include "common/log.h" LOG_MODULE_REGISTER(bt_aics);
#define VALID_AICS_OPCODE(opcode) \ #define VALID_AICS_OPCODE(opcode) \
((opcode) >= BT_AICS_OPCODE_SET_GAIN && (opcode) <= BT_AICS_OPCODE_SET_AUTO) ((opcode) >= BT_AICS_OPCODE_SET_GAIN && (opcode) <= BT_AICS_OPCODE_SET_AUTO)
@ -105,7 +105,7 @@ BT_GATT_SERVICE_INSTANCE_DEFINE(aics_service_list, aics_insts,
static void aics_state_cfg_changed(const struct bt_gatt_attr *attr, static void aics_state_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_aics_state(struct bt_conn *conn, static ssize_t read_aics_state(struct bt_conn *conn,
@ -114,9 +114,8 @@ static ssize_t read_aics_state(struct bt_conn *conn,
{ {
struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("gain %d, mute %u, gain_mode %u, counter %u", LOG_DBG("gain %d, mute %u, gain_mode %u, counter %u", inst->srv.state.gain,
inst->srv.state.gain, inst->srv.state.mute, inst->srv.state.mute, inst->srv.state.gain_mode, inst->srv.state.change_counter);
inst->srv.state.gain_mode, inst->srv.state.change_counter);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.state, return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.state,
sizeof(inst->srv.state)); sizeof(inst->srv.state));
@ -128,9 +127,8 @@ static ssize_t read_aics_gain_settings(struct bt_conn *conn,
{ {
struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("units %u, min %d, max %d", LOG_DBG("units %u, min %d, max %d", inst->srv.gain_settings.units,
inst->srv.gain_settings.units, inst->srv.gain_settings.minimum, inst->srv.gain_settings.minimum, inst->srv.gain_settings.maximum);
inst->srv.gain_settings.maximum);
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
&inst->srv.gain_settings, &inst->srv.gain_settings,
@ -142,7 +140,7 @@ static ssize_t read_type(struct bt_conn *conn, const struct bt_gatt_attr *attr,
{ {
struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("%u", inst->srv.type); LOG_DBG("%u", inst->srv.type);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.type, return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.type,
sizeof(inst->srv.type)); sizeof(inst->srv.type));
@ -151,7 +149,7 @@ static ssize_t read_type(struct bt_conn *conn, const struct bt_gatt_attr *attr,
static void aics_input_status_cfg_changed(const struct bt_gatt_attr *attr, static void aics_input_status_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_input_status(struct bt_conn *conn, static ssize_t read_input_status(struct bt_conn *conn,
@ -160,7 +158,7 @@ static ssize_t read_input_status(struct bt_conn *conn,
{ {
struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("%u", inst->srv.status); LOG_DBG("%u", inst->srv.status);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.status, return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.status,
sizeof(inst->srv.status)); sizeof(inst->srv.status));
@ -187,7 +185,7 @@ static ssize_t write_aics_control(struct bt_conn *conn,
/* Check opcode before length */ /* Check opcode before length */
if (!VALID_AICS_OPCODE(cp->cp.opcode)) { if (!VALID_AICS_OPCODE(cp->cp.opcode)) {
BT_DBG("Invalid opcode %u", cp->cp.opcode); LOG_DBG("Invalid opcode %u", cp->cp.opcode);
return BT_GATT_ERR(BT_AICS_ERR_OP_NOT_SUPPORTED); return BT_GATT_ERR(BT_AICS_ERR_OP_NOT_SUPPORTED);
} }
@ -197,14 +195,14 @@ static ssize_t write_aics_control(struct bt_conn *conn,
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
BT_DBG("Opcode %u, counter %u", cp->cp.opcode, cp->cp.counter); LOG_DBG("Opcode %u, counter %u", cp->cp.opcode, cp->cp.counter);
if (cp->cp.counter != inst->srv.state.change_counter) { if (cp->cp.counter != inst->srv.state.change_counter) {
return BT_GATT_ERR(BT_AICS_ERR_INVALID_COUNTER); return BT_GATT_ERR(BT_AICS_ERR_INVALID_COUNTER);
} }
switch (cp->cp.opcode) { switch (cp->cp.opcode) {
case BT_AICS_OPCODE_SET_GAIN: case BT_AICS_OPCODE_SET_GAIN:
BT_DBG("Set gain %d", cp->gain_setting); LOG_DBG("Set gain %d", cp->gain_setting);
if (cp->gain_setting < inst->srv.gain_settings.minimum || if (cp->gain_setting < inst->srv.gain_settings.minimum ||
cp->gain_setting > inst->srv.gain_settings.maximum) { cp->gain_setting > inst->srv.gain_settings.maximum) {
return BT_GATT_ERR(BT_AICS_ERR_OUT_OF_RANGE); return BT_GATT_ERR(BT_AICS_ERR_OUT_OF_RANGE);
@ -216,7 +214,7 @@ static ssize_t write_aics_control(struct bt_conn *conn,
} }
break; break;
case BT_AICS_OPCODE_UNMUTE: case BT_AICS_OPCODE_UNMUTE:
BT_DBG("Unmute"); LOG_DBG("Unmute");
if (inst->srv.state.mute == BT_AICS_STATE_MUTE_DISABLED) { if (inst->srv.state.mute == BT_AICS_STATE_MUTE_DISABLED) {
return BT_GATT_ERR(BT_AICS_ERR_MUTE_DISABLED); return BT_GATT_ERR(BT_AICS_ERR_MUTE_DISABLED);
} }
@ -226,7 +224,7 @@ static ssize_t write_aics_control(struct bt_conn *conn,
} }
break; break;
case BT_AICS_OPCODE_MUTE: case BT_AICS_OPCODE_MUTE:
BT_DBG("Mute"); LOG_DBG("Mute");
if (inst->srv.state.mute == BT_AICS_STATE_MUTE_DISABLED) { if (inst->srv.state.mute == BT_AICS_STATE_MUTE_DISABLED) {
return BT_GATT_ERR(BT_AICS_ERR_MUTE_DISABLED); return BT_GATT_ERR(BT_AICS_ERR_MUTE_DISABLED);
} }
@ -236,7 +234,7 @@ static ssize_t write_aics_control(struct bt_conn *conn,
} }
break; break;
case BT_AICS_OPCODE_SET_MANUAL: case BT_AICS_OPCODE_SET_MANUAL:
BT_DBG("Set manual mode"); LOG_DBG("Set manual mode");
if (BT_AICS_INPUT_MODE_IMMUTABLE(inst->srv.state.gain_mode)) { if (BT_AICS_INPUT_MODE_IMMUTABLE(inst->srv.state.gain_mode)) {
return BT_GATT_ERR(BT_AICS_ERR_GAIN_MODE_NOT_ALLOWED); return BT_GATT_ERR(BT_AICS_ERR_GAIN_MODE_NOT_ALLOWED);
} }
@ -246,7 +244,7 @@ static ssize_t write_aics_control(struct bt_conn *conn,
} }
break; break;
case BT_AICS_OPCODE_SET_AUTO: case BT_AICS_OPCODE_SET_AUTO:
BT_DBG("Set automatic mode"); LOG_DBG("Set automatic mode");
if (BT_AICS_INPUT_MODE_IMMUTABLE(inst->srv.state.gain_mode)) { if (BT_AICS_INPUT_MODE_IMMUTABLE(inst->srv.state.gain_mode)) {
return BT_GATT_ERR(BT_AICS_ERR_GAIN_MODE_NOT_ALLOWED); return BT_GATT_ERR(BT_AICS_ERR_GAIN_MODE_NOT_ALLOWED);
} }
@ -262,9 +260,9 @@ static ssize_t write_aics_control(struct bt_conn *conn,
if (notify) { if (notify) {
inst->srv.state.change_counter++; inst->srv.state.change_counter++;
BT_DBG("New state: gain %d, mute %u, gain_mode %u, counter %u", LOG_DBG("New state: gain %d, mute %u, gain_mode %u, counter %u",
inst->srv.state.gain, inst->srv.state.mute, inst->srv.state.gain, inst->srv.state.mute, inst->srv.state.gain_mode,
inst->srv.state.gain_mode, inst->srv.state.change_counter); inst->srv.state.change_counter);
bt_gatt_notify_uuid(NULL, BT_UUID_AICS_STATE, bt_gatt_notify_uuid(NULL, BT_UUID_AICS_STATE,
inst->srv.service_p->attrs, &inst->srv.state, inst->srv.service_p->attrs, &inst->srv.state,
@ -275,7 +273,7 @@ static ssize_t write_aics_control(struct bt_conn *conn,
inst->srv.state.mute, inst->srv.state.mute,
inst->srv.state.gain_mode); inst->srv.state.gain_mode);
} else { } else {
BT_DBG("Callback not registered for instance %p", inst); LOG_DBG("Callback not registered for instance %p", inst);
} }
} }
@ -286,7 +284,7 @@ static ssize_t write_aics_control(struct bt_conn *conn,
static void aics_description_cfg_changed(const struct bt_gatt_attr *attr, static void aics_description_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
#endif /* CONFIG_BT_AICS */ #endif /* CONFIG_BT_AICS */
@ -298,8 +296,8 @@ static ssize_t write_description(struct bt_conn *conn,
struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr);
if (len >= sizeof(inst->srv.description)) { if (len >= sizeof(inst->srv.description)) {
BT_DBG("Output desc was clipped from length %u to %zu", LOG_DBG("Output desc was clipped from length %u to %zu", len,
len, sizeof(inst->srv.description) - 1); sizeof(inst->srv.description) - 1);
/* We just clip the string value if it's too long */ /* We just clip the string value if it's too long */
len = (uint16_t)sizeof(inst->srv.description) - 1; len = (uint16_t)sizeof(inst->srv.description) - 1;
} }
@ -316,11 +314,11 @@ static ssize_t write_description(struct bt_conn *conn,
inst->srv.cb->description(inst, 0, inst->srv.cb->description(inst, 0,
inst->srv.description); inst->srv.description);
} else { } else {
BT_DBG("Callback not registered for instance %p", inst); LOG_DBG("Callback not registered for instance %p", inst);
} }
} }
BT_DBG("%s", inst->srv.description); LOG_DBG("%s", inst->srv.description);
return len; return len;
} }
@ -355,7 +353,7 @@ static ssize_t read_description(struct bt_conn *conn,
{ {
struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_aics *inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("%s", inst->srv.description); LOG_DBG("%s", inst->srv.description);
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
&inst->srv.description, strlen(inst->srv.description)); &inst->srv.description, strlen(inst->srv.description));
@ -365,7 +363,7 @@ static ssize_t read_description(struct bt_conn *conn,
void *bt_aics_svc_decl_get(struct bt_aics *aics) void *bt_aics_svc_decl_get(struct bt_aics *aics)
{ {
CHECKIF(!aics) { CHECKIF(!aics) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return NULL; return NULL;
} }
@ -385,12 +383,12 @@ int bt_aics_register(struct bt_aics *aics, struct bt_aics_register_param *param)
static bool instance_prepared; static bool instance_prepared;
CHECKIF(!aics) { CHECKIF(!aics) {
BT_DBG("NULL aics pointer"); LOG_DBG("NULL aics pointer");
return -ENOTCONN; return -ENOTCONN;
} }
CHECKIF(!param) { CHECKIF(!param) {
BT_DBG("NULL param"); LOG_DBG("NULL param");
return -EINVAL; return -EINVAL;
} }
@ -404,33 +402,33 @@ int bt_aics_register(struct bt_aics *aics, struct bt_aics_register_param *param)
} }
CHECKIF(param->mute > BT_AICS_STATE_MUTE_DISABLED) { CHECKIF(param->mute > BT_AICS_STATE_MUTE_DISABLED) {
BT_DBG("Invalid AICS mute value: %u", param->mute); LOG_DBG("Invalid AICS mute value: %u", param->mute);
return -EINVAL; return -EINVAL;
} }
CHECKIF(param->gain_mode > BT_AICS_MODE_AUTO) { CHECKIF(param->gain_mode > BT_AICS_MODE_AUTO) {
BT_DBG("Invalid AICS mode value: %u", param->gain_mode); LOG_DBG("Invalid AICS mode value: %u", param->gain_mode);
return -EINVAL; return -EINVAL;
} }
CHECKIF(param->type > BT_AICS_INPUT_TYPE_STREAMING) { CHECKIF(param->type > BT_AICS_INPUT_TYPE_STREAMING) {
BT_DBG("Invalid AICS input type value: %u", param->type); LOG_DBG("Invalid AICS input type value: %u", param->type);
return -EINVAL; return -EINVAL;
} }
CHECKIF(param->units == 0) { CHECKIF(param->units == 0) {
BT_DBG("AICS units value shall not be 0"); LOG_DBG("AICS units value shall not be 0");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!(param->min_gain <= param->max_gain)) { CHECKIF(!(param->min_gain <= param->max_gain)) {
BT_DBG("AICS min gain (%d) shall be lower than or equal to max gain (%d)", LOG_DBG("AICS min gain (%d) shall be lower than or equal to max gain (%d)",
param->min_gain, param->max_gain); param->min_gain, param->max_gain);
return -EINVAL; return -EINVAL;
} }
CHECKIF(param->gain < param->min_gain || param->gain > param->max_gain) { CHECKIF(param->gain < param->min_gain || param->gain > param->max_gain) {
BT_DBG("AICS gain (%d) shall be not lower than min gain (%d) " LOG_DBG("AICS gain (%d) shall be not lower than min gain (%d) "
"or higher than max gain (%d)", "or higher than max gain (%d)",
param->gain, param->min_gain, param->max_gain); param->gain, param->min_gain, param->max_gain);
return -EINVAL; return -EINVAL;
@ -451,10 +449,9 @@ int bt_aics_register(struct bt_aics *aics, struct bt_aics_register_param *param)
sizeof(aics->srv.description) - 1); sizeof(aics->srv.description) - 1);
/* strncpy may not always null-terminate */ /* strncpy may not always null-terminate */
aics->srv.description[sizeof(aics->srv.description) - 1] = '\0'; aics->srv.description[sizeof(aics->srv.description) - 1] = '\0';
if (IS_ENABLED(CONFIG_BT_DEBUG_AICS) && if (IS_ENABLED(CONFIG_BT_AICS_LOG_LEVEL_DBG) &&
strcmp(aics->srv.description, param->description)) { strcmp(aics->srv.description, param->description)) {
BT_DBG("Input desc clipped to %s", LOG_DBG("Input desc clipped to %s", aics->srv.description);
aics->srv.description);
} }
} }
@ -486,7 +483,7 @@ int bt_aics_register(struct bt_aics *aics, struct bt_aics_register_param *param)
err = bt_gatt_service_register(aics->srv.service_p); err = bt_gatt_service_register(aics->srv.service_p);
if (err) { if (err) {
BT_DBG("Could not register AICS service"); LOG_DBG("Could not register AICS service");
return err; return err;
} }
@ -508,13 +505,13 @@ struct bt_aics *bt_aics_free_instance_get(void)
int bt_aics_deactivate(struct bt_aics *inst) int bt_aics_deactivate(struct bt_aics *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
if (inst->srv.status == BT_AICS_STATUS_ACTIVE) { if (inst->srv.status == BT_AICS_STATUS_ACTIVE) {
inst->srv.status = BT_AICS_STATUS_INACTIVE; inst->srv.status = BT_AICS_STATUS_INACTIVE;
BT_DBG("Instance %p: Status was set to inactive", inst); LOG_DBG("Instance %p: Status was set to inactive", inst);
bt_gatt_notify_uuid(NULL, BT_UUID_AICS_INPUT_STATUS, bt_gatt_notify_uuid(NULL, BT_UUID_AICS_INPUT_STATUS,
inst->srv.service_p->attrs, inst->srv.service_p->attrs,
@ -524,7 +521,7 @@ int bt_aics_deactivate(struct bt_aics *inst)
if (inst->srv.cb && inst->srv.cb->status) { if (inst->srv.cb && inst->srv.cb->status) {
inst->srv.cb->status(inst, 0, inst->srv.status); inst->srv.cb->status(inst, 0, inst->srv.status);
} else { } else {
BT_DBG("Callback not registered for instance %p", inst); LOG_DBG("Callback not registered for instance %p", inst);
} }
} }
@ -534,13 +531,13 @@ int bt_aics_deactivate(struct bt_aics *inst)
int bt_aics_activate(struct bt_aics *inst) int bt_aics_activate(struct bt_aics *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
if (inst->srv.status == BT_AICS_STATUS_INACTIVE) { if (inst->srv.status == BT_AICS_STATUS_INACTIVE) {
inst->srv.status = BT_AICS_STATUS_ACTIVE; inst->srv.status = BT_AICS_STATUS_ACTIVE;
BT_DBG("Instance %p: Status was set to active", inst); LOG_DBG("Instance %p: Status was set to active", inst);
bt_gatt_notify_uuid(NULL, BT_UUID_AICS_INPUT_STATUS, bt_gatt_notify_uuid(NULL, BT_UUID_AICS_INPUT_STATUS,
inst->srv.service_p->attrs, inst->srv.service_p->attrs,
@ -550,7 +547,7 @@ int bt_aics_activate(struct bt_aics *inst)
if (inst->srv.cb && inst->srv.cb->status) { if (inst->srv.cb && inst->srv.cb->status) {
inst->srv.cb->status(inst, 0, inst->srv.status); inst->srv.cb->status(inst, 0, inst->srv.status);
} else { } else {
BT_DBG("Callback not registered for instance %p", inst); LOG_DBG("Callback not registered for instance %p", inst);
} }
} }
@ -562,7 +559,7 @@ int bt_aics_activate(struct bt_aics *inst)
int bt_aics_state_get(struct bt_aics *inst) int bt_aics_state_get(struct bt_aics *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
@ -574,7 +571,7 @@ int bt_aics_state_get(struct bt_aics *inst)
inst->srv.state.mute, inst->srv.state.mute,
inst->srv.state.gain_mode); inst->srv.state.gain_mode);
} else { } else {
BT_DBG("Callback not registered for instance %p", inst); LOG_DBG("Callback not registered for instance %p", inst);
} }
return 0; return 0;
} }
@ -585,7 +582,7 @@ int bt_aics_state_get(struct bt_aics *inst)
int bt_aics_gain_setting_get(struct bt_aics *inst) int bt_aics_gain_setting_get(struct bt_aics *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
@ -598,7 +595,7 @@ int bt_aics_gain_setting_get(struct bt_aics *inst)
inst->srv.gain_settings.minimum, inst->srv.gain_settings.minimum,
inst->srv.gain_settings.maximum); inst->srv.gain_settings.maximum);
} else { } else {
BT_DBG("Callback not registered for instance %p", inst); LOG_DBG("Callback not registered for instance %p", inst);
} }
return 0; return 0;
} }
@ -609,7 +606,7 @@ int bt_aics_gain_setting_get(struct bt_aics *inst)
int bt_aics_type_get(struct bt_aics *inst) int bt_aics_type_get(struct bt_aics *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
@ -619,7 +616,7 @@ int bt_aics_type_get(struct bt_aics *inst)
if (inst->srv.cb && inst->srv.cb->type) { if (inst->srv.cb && inst->srv.cb->type) {
inst->srv.cb->type(inst, 0, inst->srv.type); inst->srv.cb->type(inst, 0, inst->srv.type);
} else { } else {
BT_DBG("Callback not registered for instance %p", inst); LOG_DBG("Callback not registered for instance %p", inst);
} }
return 0; return 0;
} }
@ -630,7 +627,7 @@ int bt_aics_type_get(struct bt_aics *inst)
int bt_aics_status_get(struct bt_aics *inst) int bt_aics_status_get(struct bt_aics *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
@ -640,7 +637,7 @@ int bt_aics_status_get(struct bt_aics *inst)
if (inst->srv.cb && inst->srv.cb->status) { if (inst->srv.cb && inst->srv.cb->status) {
inst->srv.cb->status(inst, 0, inst->srv.status); inst->srv.cb->status(inst, 0, inst->srv.status);
} else { } else {
BT_DBG("Callback not registered for instance %p", inst); LOG_DBG("Callback not registered for instance %p", inst);
} }
return 0; return 0;
} }
@ -651,7 +648,7 @@ int bt_aics_status_get(struct bt_aics *inst)
int bt_aics_unmute(struct bt_aics *inst) int bt_aics_unmute(struct bt_aics *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
@ -672,7 +669,7 @@ int bt_aics_unmute(struct bt_aics *inst)
int bt_aics_mute(struct bt_aics *inst) int bt_aics_mute(struct bt_aics *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
@ -693,7 +690,7 @@ int bt_aics_mute(struct bt_aics *inst)
int bt_aics_manual_gain_set(struct bt_aics *inst) int bt_aics_manual_gain_set(struct bt_aics *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
@ -714,7 +711,7 @@ int bt_aics_manual_gain_set(struct bt_aics *inst)
int bt_aics_automatic_gain_set(struct bt_aics *inst) int bt_aics_automatic_gain_set(struct bt_aics *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
@ -735,7 +732,7 @@ int bt_aics_automatic_gain_set(struct bt_aics *inst)
int bt_aics_gain_set(struct bt_aics *inst, int8_t gain) int bt_aics_gain_set(struct bt_aics *inst, int8_t gain)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
@ -757,7 +754,7 @@ int bt_aics_gain_set(struct bt_aics *inst, int8_t gain)
int bt_aics_description_get(struct bt_aics *inst) int bt_aics_description_get(struct bt_aics *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
@ -768,7 +765,7 @@ int bt_aics_description_get(struct bt_aics *inst)
inst->srv.cb->description(inst, 0, inst->srv.cb->description(inst, 0,
inst->srv.description); inst->srv.description);
} else { } else {
BT_DBG("Callback not registered for instance %p", inst); LOG_DBG("Callback not registered for instance %p", inst);
} }
return 0; return 0;
} }
@ -779,12 +776,12 @@ int bt_aics_description_get(struct bt_aics *inst)
int bt_aics_description_set(struct bt_aics *inst, const char *description) int bt_aics_description_set(struct bt_aics *inst, const char *description)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!description) { CHECKIF(!description) {
BT_DBG("NULL description"); LOG_DBG("NULL description");
return -EINVAL; return -EINVAL;
} }

View file

@ -23,9 +23,9 @@
#include "aics_internal.h" #include "aics_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_AICS_CLIENT) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_aics_client
#include "common/log.h" LOG_MODULE_REGISTER(bt_aics_client, CONFIG_BT_AICS_CLIENT_LOG_LEVEL);
static struct bt_aics aics_insts[CONFIG_BT_MAX_CONN * CONFIG_BT_AICS_CLIENT_MAX_INSTANCE_COUNT]; static struct bt_aics aics_insts[CONFIG_BT_MAX_CONN * CONFIG_BT_AICS_CLIENT_MAX_INSTANCE_COUNT];
@ -42,7 +42,7 @@ static struct bt_aics *lookup_aics_by_handle(struct bt_conn *conn, uint16_t hand
} }
} }
BT_DBG("Could not find AICS instance with handle 0x%04x", handle); LOG_DBG("Could not find AICS instance with handle 0x%04x", handle);
return NULL; return NULL;
} }
@ -62,7 +62,7 @@ uint8_t aics_client_notify_handler(struct bt_conn *conn, struct bt_gatt_subscrib
inst = lookup_aics_by_handle(conn, handle); inst = lookup_aics_by_handle(conn, handle);
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
@ -73,9 +73,8 @@ uint8_t aics_client_notify_handler(struct bt_conn *conn, struct bt_gatt_subscrib
if (handle == inst->cli.state_handle) { if (handle == inst->cli.state_handle) {
if (length == sizeof(*state)) { if (length == sizeof(*state)) {
state = (struct bt_aics_state *)data; state = (struct bt_aics_state *)data;
BT_DBG("Inst %p: Gain %d, mute %u, gain_mode %u, counter %u", LOG_DBG("Inst %p: Gain %d, mute %u, gain_mode %u, counter %u", inst,
inst, state->gain, state->mute, state->gain_mode, state->gain, state->mute, state->gain_mode, state->change_counter);
state->change_counter);
inst->cli.change_counter = state->change_counter; inst->cli.change_counter = state->change_counter;
@ -88,7 +87,7 @@ uint8_t aics_client_notify_handler(struct bt_conn *conn, struct bt_gatt_subscrib
} else if (handle == inst->cli.status_handle) { } else if (handle == inst->cli.status_handle) {
if (length == sizeof(*status)) { if (length == sizeof(*status)) {
status = (uint8_t *)data; status = (uint8_t *)data;
BT_DBG("Inst %p: Status %u", inst, *status); LOG_DBG("Inst %p: Status %u", inst, *status);
if (inst->cli.cb && inst->cli.cb->status) { if (inst->cli.cb && inst->cli.cb->status) {
inst->cli.cb->status(inst, 0, *status); inst->cli.cb->status(inst, 0, *status);
} }
@ -98,14 +97,14 @@ uint8_t aics_client_notify_handler(struct bt_conn *conn, struct bt_gatt_subscrib
/* Truncate if too large */ /* Truncate if too large */
if (length > sizeof(desc) - 1) { if (length > sizeof(desc) - 1) {
BT_DBG("Description truncated from %u to %zu octets", LOG_DBG("Description truncated from %u to %zu octets", length,
length, sizeof(desc) - 1); sizeof(desc) - 1);
} }
length = MIN(sizeof(desc) - 1, length); length = MIN(sizeof(desc) - 1, length);
memcpy(desc, data, length); memcpy(desc, data, length);
desc[length] = '\0'; desc[length] = '\0';
BT_DBG("Inst %p: Input description: %s", inst, desc); LOG_DBG("Inst %p: Input description: %s", inst, desc);
if (inst->cli.cb && inst->cli.cb->description) { if (inst->cli.cb && inst->cli.cb->description) {
inst->cli.cb->description(inst, 0, desc); inst->cli.cb->description(inst, 0, desc);
} }
@ -125,15 +124,15 @@ static uint8_t aics_client_read_state_cb(struct bt_conn *conn, uint8_t err,
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("Inst %p: err: 0x%02X", inst, err); LOG_DBG("Inst %p: err: 0x%02X", inst, err);
inst->cli.busy = false; inst->cli.busy = false;
if (cb_err) { if (cb_err) {
BT_DBG("State read failed: %d", err); LOG_DBG("State read failed: %d", err);
if (inst->cli.cb && inst->cli.cb->state) { if (inst->cli.cb && inst->cli.cb->state) {
inst->cli.cb->state(inst, cb_err, 0, 0, 0); inst->cli.cb->state(inst, cb_err, 0, 0, 0);
} }
@ -142,18 +141,16 @@ static uint8_t aics_client_read_state_cb(struct bt_conn *conn, uint8_t err,
if (data) { if (data) {
if (length == sizeof(*state)) { if (length == sizeof(*state)) {
BT_DBG("Gain %d, mute %u, gain_mode %u, counter %u", LOG_DBG("Gain %d, mute %u, gain_mode %u, counter %u", state->gain,
state->gain, state->mute, state->gain_mode, state->mute, state->gain_mode, state->change_counter);
state->change_counter);
inst->cli.change_counter = state->change_counter; inst->cli.change_counter = state->change_counter;
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", LOG_DBG("Invalid length %u (expected %zu)", length, sizeof(*state));
length, sizeof(*state));
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} else { } else {
BT_DBG("Invalid state"); LOG_DBG("Invalid state");
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
@ -176,15 +173,15 @@ static uint8_t aics_client_read_gain_settings_cb(struct bt_conn *conn, uint8_t e
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("Inst %p: err: 0x%02X", inst, err); LOG_DBG("Inst %p: err: 0x%02X", inst, err);
inst->cli.busy = false; inst->cli.busy = false;
if (cb_err) { if (cb_err) {
BT_DBG("Gain settings read failed: %d", err); LOG_DBG("Gain settings read failed: %d", err);
if (inst->cli.cb && inst->cli.cb->gain_setting) { if (inst->cli.cb && inst->cli.cb->gain_setting) {
inst->cli.cb->gain_setting(inst, cb_err, 0, 0, 0); inst->cli.cb->gain_setting(inst, cb_err, 0, 0, 0);
} }
@ -193,14 +190,14 @@ static uint8_t aics_client_read_gain_settings_cb(struct bt_conn *conn, uint8_t e
if (data) { if (data) {
if (length == sizeof(*gain_settings)) { if (length == sizeof(*gain_settings)) {
BT_DBG("Units %u, Max %d, Min %d", gain_settings->units, LOG_DBG("Units %u, Max %d, Min %d", gain_settings->units,
gain_settings->maximum, gain_settings->minimum); gain_settings->maximum, gain_settings->minimum);
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", length, sizeof(*gain_settings)); LOG_DBG("Invalid length %u (expected %zu)", length, sizeof(*gain_settings));
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} else { } else {
BT_DBG("Invalid gain settings"); LOG_DBG("Invalid gain settings");
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
@ -224,15 +221,15 @@ static uint8_t aics_client_read_type_cb(struct bt_conn *conn, uint8_t err,
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("Inst %p: err: 0x%02X", inst, err); LOG_DBG("Inst %p: err: 0x%02X", inst, err);
inst->cli.busy = false; inst->cli.busy = false;
if (cb_err) { if (cb_err) {
BT_DBG("Type read failed: %d", err); LOG_DBG("Type read failed: %d", err);
if (inst->cli.cb && inst->cli.cb->type) { if (inst->cli.cb && inst->cli.cb->type) {
inst->cli.cb->type(inst, cb_err, 0); inst->cli.cb->type(inst, cb_err, 0);
} }
@ -241,13 +238,13 @@ static uint8_t aics_client_read_type_cb(struct bt_conn *conn, uint8_t err,
if (data) { if (data) {
if (length == sizeof(*type)) { if (length == sizeof(*type)) {
BT_DBG("Type %u", *type); LOG_DBG("Type %u", *type);
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", length, sizeof(*type)); LOG_DBG("Invalid length %u (expected %zu)", length, sizeof(*type));
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} else { } else {
BT_DBG("Invalid type"); LOG_DBG("Invalid type");
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
@ -269,15 +266,15 @@ static uint8_t aics_client_read_status_cb(struct bt_conn *conn, uint8_t err,
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("Inst %p: err: 0x%02X", inst, err); LOG_DBG("Inst %p: err: 0x%02X", inst, err);
inst->cli.busy = false; inst->cli.busy = false;
if (cb_err) { if (cb_err) {
BT_DBG("Status read failed: %d", err); LOG_DBG("Status read failed: %d", err);
if (inst->cli.cb && inst->cli.cb->status) { if (inst->cli.cb && inst->cli.cb->status) {
inst->cli.cb->status(inst, cb_err, 0); inst->cli.cb->status(inst, cb_err, 0);
} }
@ -286,13 +283,13 @@ static uint8_t aics_client_read_status_cb(struct bt_conn *conn, uint8_t err,
if (data) { if (data) {
if (length == sizeof(*status)) { if (length == sizeof(*status)) {
BT_DBG("Status %u", *status); LOG_DBG("Status %u", *status);
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", length, sizeof(*status)); LOG_DBG("Invalid length %u (expected %zu)", length, sizeof(*status));
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} else { } else {
BT_DBG("Invalid status"); LOG_DBG("Invalid status");
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
@ -336,7 +333,7 @@ static void aics_cp_notify_app(struct bt_aics *inst, uint8_t err)
} }
break; break;
default: default:
BT_DBG("Unknown opcode 0x%02x", inst->cli.cp_val.cp.opcode); LOG_DBG("Unknown opcode 0x%02x", inst->cli.cp_val.cp.opcode);
break; break;
} }
} }
@ -352,19 +349,18 @@ static uint8_t internal_read_state_cb(struct bt_conn *conn, uint8_t err,
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_ERR("Instance not found"); LOG_ERR("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
if (err) { if (err) {
BT_WARN("State read failed: %d", err); LOG_WRN("State read failed: %d", err);
} else if (data) { } else if (data) {
if (length == sizeof(*state)) { if (length == sizeof(*state)) {
int write_err; int write_err;
BT_DBG("Gain %d, mute %u, gain_mode %u, counter %u", LOG_DBG("Gain %d, mute %u, gain_mode %u, counter %u", state->gain,
state->gain, state->mute, state->mute, state->gain_mode, state->change_counter);
state->gain_mode, state->change_counter);
inst->cli.change_counter = state->change_counter; inst->cli.change_counter = state->change_counter;
/* clear busy flag to reuse function */ /* clear busy flag to reuse function */
@ -382,7 +378,7 @@ static uint8_t internal_read_state_cb(struct bt_conn *conn, uint8_t err,
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", length, sizeof(*state)); LOG_DBG("Invalid length %u (expected %zu)", length, sizeof(*state));
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
} }
@ -405,11 +401,11 @@ static void aics_client_write_aics_cp_cb(struct bt_conn *conn, uint8_t err,
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return; return;
} }
BT_DBG("Inst %p: err: %d", inst, cb_err); LOG_DBG("Inst %p: err: %d", inst, cb_err);
/* If the change counter is out of data when a write was attempted from /* If the change counter is out of data when a write was attempted from
* the application, we automatically initiate a read to get the newest * the application, we automatically initiate a read to get the newest
@ -428,7 +424,7 @@ static void aics_client_write_aics_cp_cb(struct bt_conn *conn, uint8_t err,
cb_err = bt_gatt_read(conn, &inst->cli.read_params); cb_err = bt_gatt_read(conn, &inst->cli.read_params);
if (cb_err) { if (cb_err) {
BT_WARN("Could not read state: %d", cb_err); LOG_WRN("Could not read state: %d", cb_err);
} else { } else {
inst->cli.cp_retried = true; inst->cli.cp_retried = true;
/* Wait for read callback */ /* Wait for read callback */
@ -447,22 +443,22 @@ static int aics_client_common_control(uint8_t opcode, struct bt_aics *inst)
int err; int err;
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!inst->client_instance) { CHECKIF(!inst->client_instance) {
BT_DBG("Not a client instance instance"); LOG_DBG("Not a client instance instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.control_handle) { if (!inst->cli.control_handle) {
BT_DBG("Handle not set for opcode %u", opcode); LOG_DBG("Handle not set for opcode %u", opcode);
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
@ -497,14 +493,14 @@ static uint8_t aics_client_read_desc_cb(struct bt_conn *conn, uint8_t err,
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
inst->cli.busy = false; inst->cli.busy = false;
if (cb_err) { if (cb_err) {
BT_DBG("Description read failed: %d", err); LOG_DBG("Description read failed: %d", err);
if (inst->cli.cb && inst->cli.cb->description) { if (inst->cli.cb && inst->cli.cb->description) {
inst->cli.cb->description(inst, cb_err, NULL); inst->cli.cb->description(inst, cb_err, NULL);
} }
@ -516,8 +512,8 @@ static uint8_t aics_client_read_desc_cb(struct bt_conn *conn, uint8_t err,
/* Truncate if too large */ /* Truncate if too large */
if (length > sizeof(desc) - 1) { if (length > sizeof(desc) - 1) {
BT_DBG("Description truncated from %u to %zu octets", LOG_DBG("Description truncated from %u to %zu octets", length,
length, sizeof(desc) - 1); sizeof(desc) - 1);
} }
length = MIN(sizeof(desc) - 1, length); length = MIN(sizeof(desc) - 1, length);
@ -527,7 +523,7 @@ static uint8_t aics_client_read_desc_cb(struct bt_conn *conn, uint8_t err,
} }
desc[length] = '\0'; desc[length] = '\0';
BT_DBG("Input description: %s", desc); LOG_DBG("Input description: %s", desc);
if (inst->cli.cb && inst->cli.cb->description) { if (inst->cli.cb && inst->cli.cb->description) {
inst->cli.cb->description(inst, cb_err, desc); inst->cli.cb->description(inst, cb_err, desc);
@ -555,7 +551,7 @@ static uint8_t aics_discover_func(struct bt_conn *conn, const struct bt_gatt_att
struct bt_aics *inst = CONTAINER_OF(client_inst, struct bt_aics, cli); struct bt_aics *inst = CONTAINER_OF(client_inst, struct bt_aics, cli);
if (!attr) { if (!attr) {
BT_DBG("Discovery complete for AICS %p", inst); LOG_DBG("Discovery complete for AICS %p", inst);
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
@ -570,7 +566,7 @@ static uint8_t aics_discover_func(struct bt_conn *conn, const struct bt_gatt_att
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) {
struct bt_gatt_subscribe_params *sub_params = NULL; struct bt_gatt_subscribe_params *sub_params = NULL;
@ -583,24 +579,24 @@ static uint8_t aics_discover_func(struct bt_conn *conn, const struct bt_gatt_att
inst->cli.end_handle = chrc->value_handle; inst->cli.end_handle = chrc->value_handle;
if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_STATE)) { if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_STATE)) {
BT_DBG("Audio Input state"); LOG_DBG("Audio Input state");
inst->cli.state_handle = chrc->value_handle; inst->cli.state_handle = chrc->value_handle;
sub_params = &inst->cli.state_sub_params; sub_params = &inst->cli.state_sub_params;
} else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_GAIN_SETTINGS)) { } else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_GAIN_SETTINGS)) {
BT_DBG("Gain settings"); LOG_DBG("Gain settings");
inst->cli.gain_handle = chrc->value_handle; inst->cli.gain_handle = chrc->value_handle;
} else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_INPUT_TYPE)) { } else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_INPUT_TYPE)) {
BT_DBG("Input type"); LOG_DBG("Input type");
inst->cli.type_handle = chrc->value_handle; inst->cli.type_handle = chrc->value_handle;
} else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_INPUT_STATUS)) { } else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_INPUT_STATUS)) {
BT_DBG("Input status"); LOG_DBG("Input status");
inst->cli.status_handle = chrc->value_handle; inst->cli.status_handle = chrc->value_handle;
sub_params = &inst->cli.status_sub_params; sub_params = &inst->cli.status_sub_params;
} else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_CONTROL)) { } else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_CONTROL)) {
BT_DBG("Control point"); LOG_DBG("Control point");
inst->cli.control_handle = chrc->value_handle; inst->cli.control_handle = chrc->value_handle;
} else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_DESCRIPTION)) { } else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_AICS_DESCRIPTION)) {
BT_DBG("Description"); LOG_DBG("Description");
inst->cli.desc_handle = chrc->value_handle; inst->cli.desc_handle = chrc->value_handle;
if (chrc->properties & BT_GATT_CHRC_NOTIFY) { if (chrc->properties & BT_GATT_CHRC_NOTIFY) {
sub_params = &inst->cli.desc_sub_params; sub_params = &inst->cli.desc_sub_params;
@ -678,24 +674,25 @@ int bt_aics_discover(struct bt_conn *conn, struct bt_aics *inst,
int err = 0; int err = 0;
CHECKIF(!inst || !conn || !param) { CHECKIF(!inst || !conn || !param) {
BT_DBG("%s cannot be NULL", LOG_DBG("%s cannot be NULL", inst == NULL ? "inst"
inst == NULL ? "inst" : conn == NULL ? "conn" : "param"); : conn == NULL ? "conn"
: "param");
return -EINVAL; return -EINVAL;
} }
CHECKIF(param->end_handle <= param->start_handle) { CHECKIF(param->end_handle <= param->start_handle) {
BT_DBG("start_handle (%u) shall be less than end_handle (%u)", LOG_DBG("start_handle (%u) shall be less than end_handle (%u)", param->start_handle,
param->start_handle, param->end_handle); param->end_handle);
return -EINVAL; return -EINVAL;
} }
CHECKIF(!inst->cli.active) { CHECKIF(!inst->cli.active) {
BT_DBG("Inactive instance"); LOG_DBG("Inactive instance");
return -EINVAL; return -EINVAL;
} }
if (inst->cli.busy) { if (inst->cli.busy) {
BT_DBG("Instance is busy"); LOG_DBG("Instance is busy");
return -EBUSY; return -EBUSY;
} }
@ -711,7 +708,7 @@ int bt_aics_discover(struct bt_conn *conn, struct bt_aics *inst,
err = bt_gatt_discover(conn, &inst->cli.discover_params); err = bt_gatt_discover(conn, &inst->cli.discover_params);
if (err) { if (err) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
} else { } else {
inst->cli.busy = true; inst->cli.busy = true;
} }
@ -735,17 +732,17 @@ struct bt_aics *bt_aics_client_free_instance_get(void)
int bt_aics_client_conn_get(const struct bt_aics *aics, struct bt_conn **conn) int bt_aics_client_conn_get(const struct bt_aics *aics, struct bt_conn **conn)
{ {
CHECKIF(aics == NULL) { CHECKIF(aics == NULL) {
BT_DBG("NULL aics pointer"); LOG_DBG("NULL aics pointer");
return -EINVAL; return -EINVAL;
} }
if (!aics->client_instance) { if (!aics->client_instance) {
BT_DBG("aics pointer shall be client instance"); LOG_DBG("aics pointer shall be client instance");
return -EINVAL; return -EINVAL;
} }
if (aics->cli.conn == NULL) { if (aics->cli.conn == NULL) {
BT_DBG("aics pointer not associated with a connection. " LOG_DBG("aics pointer not associated with a connection. "
"Do discovery first"); "Do discovery first");
return -ENOTCONN; return -ENOTCONN;
} }
@ -759,22 +756,22 @@ int bt_aics_client_state_get(struct bt_aics *inst)
int err; int err;
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!inst->client_instance) { CHECKIF(!inst->client_instance) {
BT_DBG("Not a client instance instance"); LOG_DBG("Not a client instance instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.state_handle) { if (!inst->cli.state_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
@ -797,22 +794,22 @@ int bt_aics_client_gain_setting_get(struct bt_aics *inst)
int err; int err;
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!inst->client_instance) { CHECKIF(!inst->client_instance) {
BT_DBG("Not a client instance instance"); LOG_DBG("Not a client instance instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.gain_handle) { if (!inst->cli.gain_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
@ -835,22 +832,22 @@ int bt_aics_client_type_get(struct bt_aics *inst)
int err; int err;
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!inst->client_instance) { CHECKIF(!inst->client_instance) {
BT_DBG("Not a client instance instance"); LOG_DBG("Not a client instance instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.type_handle) { if (!inst->cli.type_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
@ -873,22 +870,22 @@ int bt_aics_client_status_get(struct bt_aics *inst)
int err; int err;
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!inst->client_instance) { CHECKIF(!inst->client_instance) {
BT_DBG("Not a client instance instance"); LOG_DBG("Not a client instance instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.status_handle) { if (!inst->cli.status_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
@ -931,22 +928,22 @@ int bt_aics_client_gain_set(struct bt_aics *inst, int8_t gain)
int err; int err;
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!inst->client_instance) { CHECKIF(!inst->client_instance) {
BT_DBG("Not a client instance instance"); LOG_DBG("Not a client instance instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.control_handle) { if (!inst->cli.control_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
@ -974,22 +971,22 @@ int bt_aics_client_description_get(struct bt_aics *inst)
int err; int err;
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!inst->client_instance) { CHECKIF(!inst->client_instance) {
BT_DBG("Not a client instance instance"); LOG_DBG("Not a client instance instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.desc_handle) { if (!inst->cli.desc_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
@ -1011,27 +1008,27 @@ int bt_aics_client_description_set(struct bt_aics *inst,
const char *description) const char *description)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!inst->client_instance) { CHECKIF(!inst->client_instance) {
BT_DBG("Not a client instance instance"); LOG_DBG("Not a client instance instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.desc_handle) { if (!inst->cli.desc_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
} else if (!inst->cli.desc_writable) { } else if (!inst->cli.desc_writable) {
BT_DBG("Description is not writable on peer service instance"); LOG_DBG("Description is not writable on peer service instance");
return -EPERM; return -EPERM;
} }
@ -1043,7 +1040,7 @@ int bt_aics_client_description_set(struct bt_aics *inst,
void bt_aics_client_cb_register(struct bt_aics *inst, struct bt_aics_cb *cb) void bt_aics_client_cb_register(struct bt_aics *inst, struct bt_aics_cb *cb)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("inst cannot be NULL"); LOG_DBG("inst cannot be NULL");
return; return;
} }

View file

@ -22,9 +22,10 @@
#include <zephyr/bluetooth/audio/audio.h> #include <zephyr/bluetooth/audio/audio.h>
#include <zephyr/bluetooth/audio/pacs.h> #include <zephyr/bluetooth/audio/pacs.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_ASCS) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_ascs
#include "common/log.h" LOG_MODULE_REGISTER(bt_ascs, CONFIG_BT_ASCS_LOG_LEVEL);
#include "common/bt_str.h" #include "common/bt_str.h"
#include "common/assert.h" #include "common/assert.h"
@ -83,9 +84,8 @@ void ascs_ep_set_state(struct bt_audio_ep *ep, uint8_t state)
ep->status.state = state; ep->status.state = state;
state_changed = old_state != state; state_changed = old_state != state;
BT_DBG("ep %p id 0x%02x %s -> %s", ep, ep->status.id, LOG_DBG("ep %p id 0x%02x %s -> %s", ep, ep->status.id, bt_audio_ep_state_str(old_state),
bt_audio_ep_state_str(old_state), bt_audio_ep_state_str(state));
bt_audio_ep_state_str(state));
/* Notify clients*/ /* Notify clients*/
ase_status_changed(ep, old_state, state); ase_status_changed(ep, old_state, state);
@ -256,7 +256,7 @@ void ascs_ep_set_state(struct bt_audio_ep *ep, uint8_t state)
break; /* no-op*/ break; /* no-op*/
default: default:
BT_ERR("Invalid state: %u", state); LOG_ERR("Invalid state: %u", state);
break; break;
} }
} }
@ -271,8 +271,7 @@ static void ascs_codec_data_add(struct net_buf_simple *buf, const char *prefix,
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
struct bt_data *d = &data[i].data; struct bt_data *d = &data[i].data;
BT_DBG("#%u: %s type 0x%02x len %u", i, prefix, d->type, LOG_DBG("#%u: %s type 0x%02x len %u", i, prefix, d->type, d->data_len);
d->data_len);
LOG_HEXDUMP_DBG(d->data, d->data_len, prefix); LOG_HEXDUMP_DBG(d->data, d->data_len, prefix);
cc = net_buf_simple_add(buf, sizeof(*cc)); cc = net_buf_simple_add(buf, sizeof(*cc));
@ -302,7 +301,7 @@ static void ascs_ep_get_status_config(struct bt_audio_ep *ep,
cfg->codec.cid = sys_cpu_to_le16(ep->codec.cid); cfg->codec.cid = sys_cpu_to_le16(ep->codec.cid);
cfg->codec.vid = sys_cpu_to_le16(ep->codec.vid); cfg->codec.vid = sys_cpu_to_le16(ep->codec.vid);
BT_DBG("dir 0x%02x unframed_supported 0x%02x phy 0x%02x rtn %u " LOG_DBG("dir 0x%02x unframed_supported 0x%02x phy 0x%02x rtn %u "
"latency %u pd_min %u pd_max %u codec 0x%02x", "latency %u pd_min %u pd_max %u codec 0x%02x",
ep->dir, pref->unframed_supported, pref->phy, ep->dir, pref->unframed_supported, pref->phy,
pref->rtn, pref->latency, pref->pd_min, pref->pd_max, pref->rtn, pref->latency, pref->pd_min, pref->pd_max,
@ -329,7 +328,7 @@ static void ascs_ep_get_status_qos(struct bt_audio_ep *ep,
qos->latency = sys_cpu_to_le16(ep->stream->qos->latency); qos->latency = sys_cpu_to_le16(ep->stream->qos->latency);
sys_put_le24(ep->stream->qos->pd, qos->pd); sys_put_le24(ep->stream->qos->pd, qos->pd);
BT_DBG("dir 0x%02x codec 0x%02x interval %u framing 0x%02x phy 0x%02x " LOG_DBG("dir 0x%02x codec 0x%02x interval %u framing 0x%02x phy 0x%02x "
"rtn %u latency %u pd %u", "rtn %u latency %u pd %u",
ep->dir, ep->stream->codec->id, ep->dir, ep->stream->codec->id,
ep->stream->qos->interval, ep->stream->qos->framing, ep->stream->qos->interval, ep->stream->qos->framing,
@ -350,8 +349,7 @@ static void ascs_ep_get_status_enable(struct bt_audio_ep *ep,
ascs_codec_data_add(buf, "meta", ep->codec.meta_count, ep->codec.meta); ascs_codec_data_add(buf, "meta", ep->codec.meta_count, ep->codec.meta);
enable->metadata_len = buf->len - enable->metadata_len; enable->metadata_len = buf->len - enable->metadata_len;
BT_DBG("dir 0x%02x cig 0x%02x cis 0x%02x", LOG_DBG("dir 0x%02x cig 0x%02x cis 0x%02x", ep->dir, ep->cig_id, ep->cis_id);
ep->dir, ep->cig_id, ep->cis_id);
} }
static int ascs_ep_get_status(struct bt_audio_ep *ep, static int ascs_ep_get_status(struct bt_audio_ep *ep,
@ -363,7 +361,7 @@ static int ascs_ep_get_status(struct bt_audio_ep *ep,
return -EINVAL; return -EINVAL;
} }
BT_DBG("ep %p id 0x%02x state %s", ep, ep->status.id, LOG_DBG("ep %p id 0x%02x state %s", ep, ep->status.id,
bt_audio_ep_state_str(ep->status.state)); bt_audio_ep_state_str(ep->status.state));
/* Reset if buffer before using */ /* Reset if buffer before using */
@ -391,7 +389,7 @@ static int ascs_ep_get_status(struct bt_audio_ep *ep,
ascs_ep_get_status_enable(ep, buf); ascs_ep_get_status_enable(ep, buf);
break; break;
default: default:
BT_ERR("Invalid Endpoint state"); LOG_ERR("Invalid Endpoint state");
break; break;
} }
@ -409,33 +407,32 @@ static void ascs_iso_recv(struct bt_iso_chan *chan,
ep = iso->rx.ep; ep = iso->rx.ep;
if (ep == NULL) { if (ep == NULL) {
BT_ERR("iso %p not bound with ep", chan); LOG_ERR("iso %p not bound with ep", chan);
return; return;
} }
if (ep->status.state != BT_AUDIO_EP_STATE_STREAMING) { if (ep->status.state != BT_AUDIO_EP_STATE_STREAMING) {
BT_DBG("ep %p is not in the streaming state: %s", LOG_DBG("ep %p is not in the streaming state: %s",
ep, bt_audio_ep_state_str(ep->status.state)); ep, bt_audio_ep_state_str(ep->status.state));
return; return;
} }
stream = ep->stream; stream = ep->stream;
if (stream == NULL) { if (stream == NULL) {
BT_ERR("No stream for ep %p", ep); LOG_ERR("No stream for ep %p", ep);
return; return;
} }
ops = stream->ops; ops = stream->ops;
if (IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_STREAM_DATA)) { if (IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_STREAM_DATA)) {
BT_DBG("stream %p ep %p len %zu", LOG_DBG("stream %p ep %p len %zu", stream, stream->ep, net_buf_frags_len(buf));
stream, ep, net_buf_frags_len(buf));
} }
if (ops != NULL && ops->recv != NULL) { if (ops != NULL && ops->recv != NULL) {
ops->recv(stream, info, buf); ops->recv(stream, info, buf);
} else { } else {
BT_WARN("No callback for recv set"); LOG_WRN("No callback for recv set");
} }
} }
@ -448,20 +445,20 @@ static void ascs_iso_sent(struct bt_iso_chan *chan)
ep = iso->tx.ep; ep = iso->tx.ep;
if (ep == NULL) { if (ep == NULL) {
BT_ERR("iso %p not bound with ep", chan); LOG_ERR("iso %p not bound with ep", chan);
return; return;
} }
stream = ep->stream; stream = ep->stream;
if (stream == NULL) { if (stream == NULL) {
BT_ERR("No stream for ep %p", ep); LOG_ERR("No stream for ep %p", ep);
return; return;
} }
ops = stream->ops; ops = stream->ops;
if (IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_STREAM_DATA)) { if (IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_STREAM_DATA)) {
BT_DBG("stream %p ep %p", stream, ep); LOG_DBG("stream %p ep %p", stream, stream->ep);
} }
if (ops != NULL && ops->sent != NULL) { if (ops != NULL && ops->sent != NULL) {
@ -490,7 +487,7 @@ static void ascs_ep_iso_connected(struct bt_audio_ep *ep)
int err; int err;
if (ep->status.state != BT_AUDIO_EP_STATE_ENABLING) { if (ep->status.state != BT_AUDIO_EP_STATE_ENABLING) {
BT_DBG("ep %p not in enabling state: %s", LOG_DBG("ep %p not in enabling state: %s",
ep, bt_audio_ep_state_str(ep->status.state)); ep, bt_audio_ep_state_str(ep->status.state));
return; return;
} }
@ -501,13 +498,13 @@ static void ascs_ep_iso_connected(struct bt_audio_ep *ep)
stream = ep->stream; stream = ep->stream;
if (stream == NULL) { if (stream == NULL) {
BT_ERR("No stream for ep %p", ep); LOG_ERR("No stream for ep %p", ep);
return; return;
} }
err = ase_stream_start(stream); err = ase_stream_start(stream);
if (err) { if (err) {
BT_ERR("Could not start stream %d", err); LOG_ERR("Could not start stream %d", err);
} }
} }
@ -516,7 +513,7 @@ static void ascs_iso_connected(struct bt_iso_chan *chan)
struct bt_audio_iso *iso = CONTAINER_OF(chan, struct bt_audio_iso, chan); struct bt_audio_iso *iso = CONTAINER_OF(chan, struct bt_audio_iso, chan);
if (iso->rx.ep == NULL && iso->tx.ep == NULL) { if (iso->rx.ep == NULL && iso->tx.ep == NULL) {
BT_ERR("iso %p not bound with ep", chan); LOG_ERR("iso %p not bound with ep", chan);
return; return;
} }
@ -536,18 +533,18 @@ static void ascs_ep_iso_disconnected(struct bt_audio_ep *ep, uint8_t reason)
stream = ep->stream; stream = ep->stream;
if (stream == NULL) { if (stream == NULL) {
BT_ERR("No stream for ep %p", ep); LOG_ERR("No stream for ep %p", ep);
return; return;
} }
ops = stream->ops; ops = stream->ops;
BT_DBG("stream %p ep %p reason 0x%02x", stream, ep, reason); LOG_DBG("stream %p ep %p reason 0x%02x", stream, stream->ep, reason);
if (ops != NULL && ops->stopped != NULL) { if (ops != NULL && ops->stopped != NULL) {
ops->stopped(stream); ops->stopped(stream);
} else { } else {
BT_WARN("No callback for stopped set"); LOG_WRN("No callback for stopped set");
} }
if (ep->status.state == BT_AUDIO_EP_STATE_RELEASING) { if (ep->status.state == BT_AUDIO_EP_STATE_RELEASING) {
@ -569,7 +566,7 @@ static void ascs_ep_iso_disconnected(struct bt_audio_ep *ep, uint8_t reason)
err = bt_audio_stream_iso_listen(stream); err = bt_audio_stream_iso_listen(stream);
if (err != 0) { if (err != 0) {
BT_ERR("Could not make stream listen: %d", err); LOG_ERR("Could not make stream listen: %d", err);
} }
} }
} }
@ -579,7 +576,7 @@ static void ascs_iso_disconnected(struct bt_iso_chan *chan, uint8_t reason)
struct bt_audio_iso *iso = CONTAINER_OF(chan, struct bt_audio_iso, chan); struct bt_audio_iso *iso = CONTAINER_OF(chan, struct bt_audio_iso, chan);
if (iso->rx.ep == NULL && iso->tx.ep == NULL) { if (iso->rx.ep == NULL && iso->tx.ep == NULL) {
BT_ERR("iso %p not bound with ep", chan); LOG_ERR("iso %p not bound with ep", chan);
return; return;
} }
@ -602,7 +599,7 @@ static struct bt_iso_chan_ops ascs_iso_ops = {
static void ascs_ase_cfg_changed(const struct bt_gatt_attr *attr, static void ascs_ase_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("attr %p value 0x%04x", attr, value); LOG_DBG("attr %p value 0x%04x", attr, value);
} }
NET_BUF_SIMPLE_DEFINE_STATIC(rsp_buf, CONFIG_BT_L2CAP_TX_MTU); NET_BUF_SIMPLE_DEFINE_STATIC(rsp_buf, CONFIG_BT_L2CAP_TX_MTU);
@ -623,9 +620,9 @@ static void ascs_cp_rsp_add(uint8_t id, uint8_t op, uint8_t code,
struct bt_ascs_cp_rsp *rsp = (void *)rsp_buf.__buf; struct bt_ascs_cp_rsp *rsp = (void *)rsp_buf.__buf;
struct bt_ascs_cp_ase_rsp *ase_rsp; struct bt_ascs_cp_ase_rsp *ase_rsp;
BT_DBG("id 0x%02x op %s (0x%02x) code %s (0x%02x) reason %s (0x%02x)", LOG_DBG("id 0x%02x op %s (0x%02x) code %s (0x%02x) reason %s (0x%02x)", id,
id, bt_ascs_op_str(op), op, bt_ascs_rsp_str(code), code, bt_ascs_op_str(op), op, bt_ascs_rsp_str(code), code, bt_ascs_reason_str(reason),
bt_ascs_reason_str(reason), reason); reason);
/* Allocate response if buffer is empty */ /* Allocate response if buffer is empty */
if (!rsp_buf.len) { if (!rsp_buf.len) {
@ -658,7 +655,7 @@ static void ascs_cp_rsp_add(uint8_t id, uint8_t op, uint8_t code,
static void ascs_cp_rsp_add_errno(uint8_t id, uint8_t op, int err, static void ascs_cp_rsp_add_errno(uint8_t id, uint8_t op, int err,
uint8_t reason) uint8_t reason)
{ {
BT_DBG("id %u op %u err %d reason %u", id, op, err, reason); LOG_DBG("id %u op %u err %d reason %u", id, op, err, reason);
switch (err) { switch (err) {
case -ENOBUFS: case -ENOBUFS:
@ -730,8 +727,7 @@ static void ase_release(struct bt_ascs_ase *ase)
{ {
int err; int err;
BT_DBG("ase %p state %s", LOG_DBG("ase %p state %s", ase, bt_audio_ep_state_str(ase->ep.status.state));
ase, bt_audio_ep_state_str(ase->ep.status.state));
if (ase->ep.status.state == BT_AUDIO_EP_STATE_RELEASING) { if (ase->ep.status.state == BT_AUDIO_EP_STATE_RELEASING) {
/* already releasing */ /* already releasing */
@ -761,7 +757,7 @@ static void ase_disable(struct bt_ascs_ase *ase)
struct bt_audio_ep *ep; struct bt_audio_ep *ep;
int err; int err;
BT_DBG("ase %p", ase); LOG_DBG("ase %p", ase);
ep = &ase->ep; ep = &ase->ep;
@ -772,7 +768,7 @@ static void ase_disable(struct bt_ascs_ase *ase)
case BT_AUDIO_EP_STATE_STREAMING: case BT_AUDIO_EP_STATE_STREAMING:
break; break;
default: default:
BT_WARN("Invalid operation in state: %s", bt_audio_ep_state_str(ep->status.state)); LOG_WRN("Invalid operation in state: %s", bt_audio_ep_state_str(ep->status.state));
ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_DISABLE_OP, ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_DISABLE_OP,
-EBADMSG, BT_ASCS_REASON_NONE); -EBADMSG, BT_ASCS_REASON_NONE);
return; return;
@ -787,7 +783,7 @@ static void ase_disable(struct bt_ascs_ase *ase)
} }
if (err) { if (err) {
BT_ERR("Disable failed: %d", err); LOG_ERR("Disable failed: %d", err);
ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_DISABLE_OP, ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_DISABLE_OP,
err, BT_ASCS_REASON_NONE); err, BT_ASCS_REASON_NONE);
return; return;
@ -889,7 +885,7 @@ static struct bt_audio_iso *audio_iso_get_or_new(struct bt_ascs *ascs,
static void ase_stream_add(struct bt_ascs *ascs, struct bt_ascs_ase *ase, static void ase_stream_add(struct bt_ascs *ascs, struct bt_ascs_ase *ase,
struct bt_audio_stream *stream) struct bt_audio_stream *stream)
{ {
BT_DBG("ase %p stream %p", ase, stream); LOG_DBG("ase %p stream %p", ase, stream);
ase->ep.stream = stream; ase->ep.stream = stream;
stream->conn = ascs->conn; stream->conn = ascs->conn;
stream->ep = &ase->ep; stream->ep = &ase->ep;
@ -916,7 +912,7 @@ static void ase_process(struct k_work *work)
const uint8_t ep_state = ep->status.state; const uint8_t ep_state = ep->status.state;
struct bt_conn *conn = ase->ascs->conn; struct bt_conn *conn = ase->ascs->conn;
BT_DBG("ase %p, ep %p, ep.stream %p", ase, ep, stream); LOG_DBG("ase %p, ep %p, ep.stream %p", ase, ep, stream);
if (conn != NULL && conn->state == BT_CONN_CONNECTED) { if (conn != NULL && conn->state == BT_CONN_CONNECTED) {
ascs_ep_get_status(ep, &ase_buf); ascs_ep_get_status(ep, &ase_buf);
@ -945,8 +941,7 @@ static void ase_process(struct k_work *work)
const int err = bt_audio_stream_disconnect(stream); const int err = bt_audio_stream_disconnect(stream);
if (err != 0) { if (err != 0) {
BT_ERR("Failed to disconnect stream %p: %d", LOG_ERR("Failed to disconnect stream %p: %d", stream, err);
stream, err);
} }
} }
} else if (ep_state == BT_AUDIO_EP_STATE_ENABLING) { } else if (ep_state == BT_AUDIO_EP_STATE_ENABLING) {
@ -977,7 +972,7 @@ static uint8_t ase_attr_cb(const struct bt_gatt_attr *attr, uint16_t handle,
void ascs_ep_init(struct bt_audio_ep *ep, uint8_t id) void ascs_ep_init(struct bt_audio_ep *ep, uint8_t id)
{ {
BT_DBG("ep %p id 0x%02x", ep, id); LOG_DBG("ep %p id 0x%02x", ep, id);
(void)memset(ep, 0, sizeof(*ep)); (void)memset(ep, 0, sizeof(*ep));
ep->status.id = id; ep->status.id = id;
@ -1064,12 +1059,11 @@ static ssize_t ascs_ase_read(struct bt_conn *conn,
struct bt_ascs *ascs = ascs_get(conn); struct bt_ascs *ascs = ascs_get(conn);
struct bt_ascs_ase *ase; struct bt_ascs_ase *ase;
BT_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
offset);
ase = ase_get(ascs, POINTER_TO_UINT(BT_AUDIO_CHRC_USER_DATA(attr))); ase = ase_get(ascs, POINTER_TO_UINT(BT_AUDIO_CHRC_USER_DATA(attr)));
if (!ase) { if (!ase) {
BT_ERR("Unable to get ASE"); LOG_ERR("Unable to get ASE");
return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
} }
@ -1081,7 +1075,7 @@ static ssize_t ascs_ase_read(struct bt_conn *conn,
static void ascs_cp_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void ascs_cp_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("attr %p value 0x%04x", attr, value); LOG_DBG("attr %p value 0x%04x", attr, value);
} }
static bool ascs_codec_config_store(struct bt_data *data, void *user_data) static bool ascs_codec_config_store(struct bt_data *data, void *user_data)
@ -1090,20 +1084,19 @@ static bool ascs_codec_config_store(struct bt_data *data, void *user_data)
struct bt_codec_data *cdata; struct bt_codec_data *cdata;
if (codec->data_count >= ARRAY_SIZE(codec->data)) { if (codec->data_count >= ARRAY_SIZE(codec->data)) {
BT_ERR("No slot available for Codec Config"); LOG_ERR("No slot available for Codec Config");
return false; return false;
} }
cdata = &codec->data[codec->data_count]; cdata = &codec->data[codec->data_count];
if (data->data_len > sizeof(cdata->value)) { if (data->data_len > sizeof(cdata->value)) {
BT_ERR("Not enough space for Codec Config: %u > %zu", LOG_ERR("Not enough space for Codec Config: %u > %zu", data->data_len,
data->data_len, sizeof(cdata->value)); sizeof(cdata->value));
return false; return false;
} }
BT_DBG("#%u type 0x%02x len %u", codec->data_count, data->type, LOG_DBG("#%u type 0x%02x len %u", codec->data_count, data->type, data->data_len);
data->data_len);
cdata->data.type = data->type; cdata->data.type = data->type;
cdata->data.data_len = data->data_len; cdata->data.data_len = data->data_len;
@ -1150,13 +1143,13 @@ static int ascs_ep_set_codec(struct bt_audio_ep *ep, uint8_t id, uint16_t cid,
return -EINVAL; return -EINVAL;
} }
BT_DBG("ep %p dir %u codec id 0x%02x cid 0x%04x vid 0x%04x len %u", LOG_DBG("ep %p dir %u codec id 0x%02x cid 0x%04x vid 0x%04x len %u", ep, ep->dir, id, cid,
ep, ep->dir, id, cid, vid, len); vid, len);
bt_pacs_cap_foreach(ep->dir, codec_lookup_id, &lookup_data); bt_pacs_cap_foreach(ep->dir, codec_lookup_id, &lookup_data);
if (lookup_data.codec == NULL) { if (lookup_data.codec == NULL) {
BT_DBG("Codec with id %u for dir %u is not supported by our capabilities", LOG_DBG("Codec with id %u for dir %u is not supported by our capabilities",
id, ep->dir); id, ep->dir);
return -ENOENT; return -ENOENT;
@ -1184,7 +1177,7 @@ static int ascs_ep_set_codec(struct bt_audio_ep *ep, uint8_t id, uint16_t cid,
/* Check if all entries could be parsed */ /* Check if all entries could be parsed */
if (ad.len) { if (ad.len) {
BT_ERR("Unable to parse Codec Config: len %u", ad.len); LOG_ERR("Unable to parse Codec Config: len %u", ad.len);
(void)memset(codec, 0, sizeof(*codec)); (void)memset(codec, 0, sizeof(*codec));
return -EINVAL; return -EINVAL;
@ -1201,14 +1194,14 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase,
struct bt_codec codec; struct bt_codec codec;
int err; int err;
BT_DBG("ase %p latency 0x%02x phy 0x%02x codec 0x%02x " LOG_DBG("ase %p latency 0x%02x phy 0x%02x codec 0x%02x "
"cid 0x%04x vid 0x%04x codec config len 0x%02x", ase, "cid 0x%04x vid 0x%04x codec config len 0x%02x", ase,
cfg->latency, cfg->phy, cfg->codec.id, cfg->codec.cid, cfg->latency, cfg->phy, cfg->codec.id, cfg->codec.cid,
cfg->codec.vid, cfg->cc_len); cfg->codec.vid, cfg->cc_len);
if (cfg->latency < BT_ASCS_CONFIG_LATENCY_LOW || if (cfg->latency < BT_ASCS_CONFIG_LATENCY_LOW ||
cfg->latency > BT_ASCS_CONFIG_LATENCY_HIGH) { cfg->latency > BT_ASCS_CONFIG_LATENCY_HIGH) {
BT_WARN("Invalid latency: 0x%02x", cfg->latency); LOG_WRN("Invalid latency: 0x%02x", cfg->latency);
ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP,
BT_ASCS_RSP_CONF_INVALID, BT_ASCS_RSP_CONF_INVALID,
BT_ASCS_REASON_LATENCY); BT_ASCS_REASON_LATENCY);
@ -1217,7 +1210,7 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase,
if (cfg->phy < BT_ASCS_CONFIG_PHY_LE_1M || if (cfg->phy < BT_ASCS_CONFIG_PHY_LE_1M ||
cfg->phy > BT_ASCS_CONFIG_PHY_LE_CODED) { cfg->phy > BT_ASCS_CONFIG_PHY_LE_CODED) {
BT_WARN("Invalid PHY: 0x%02x", cfg->phy); LOG_WRN("Invalid PHY: 0x%02x", cfg->phy);
ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP,
BT_ASCS_RSP_CONF_INVALID, BT_ASCS_REASON_PHY); BT_ASCS_RSP_CONF_INVALID, BT_ASCS_REASON_PHY);
return 0; return 0;
@ -1232,7 +1225,7 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase,
case BT_AUDIO_EP_STATE_QOS_CONFIGURED: case BT_AUDIO_EP_STATE_QOS_CONFIGURED:
break; break;
default: default:
BT_WARN("Invalid operation in state: %s", LOG_WRN("Invalid operation in state: %s",
bt_audio_ep_state_str(ase->ep.status.state)); bt_audio_ep_state_str(ase->ep.status.state));
ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP,
BT_ASCS_RSP_INVALID_ASE_STATE, 0x00); BT_ASCS_RSP_INVALID_ASE_STATE, 0x00);
@ -1269,7 +1262,7 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase,
if (err != 0) { if (err != 0) {
uint8_t reason = BT_ASCS_REASON_CODEC_DATA; uint8_t reason = BT_ASCS_REASON_CODEC_DATA;
BT_ERR("Reconfig failed: %d", err); LOG_ERR("Reconfig failed: %d", err);
(void)memcpy(&ase->ep.codec, &codec, sizeof(codec)); (void)memcpy(&ase->ep.codec, &codec, sizeof(codec));
ascs_cp_rsp_add_errno(ASE_ID(ase), ascs_cp_rsp_add_errno(ASE_ID(ase),
@ -1292,8 +1285,7 @@ static int ase_config(struct bt_ascs *ascs, struct bt_ascs_ase *ase,
} }
if (err != 0 || stream == NULL) { if (err != 0 || stream == NULL) {
BT_ERR("Config failed, err: %d, stream %p", LOG_ERR("Config failed, err: %d, stream %p", err, stream);
err, stream);
(void)memcpy(&ase->ep.codec, &codec, sizeof(codec)); (void)memcpy(&ase->ep.codec, &codec, sizeof(codec));
ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP, ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_CONFIG_OP,
@ -1326,19 +1318,19 @@ static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf)
int i; int i;
if (buf->len < sizeof(*req)) { if (buf->len < sizeof(*req)) {
BT_WARN("Malformed ASE Config"); LOG_WRN("Malformed ASE Config");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
req = net_buf_simple_pull_mem(buf, sizeof(*req)); req = net_buf_simple_pull_mem(buf, sizeof(*req));
BT_DBG("num_ases %u", req->num_ases); LOG_DBG("num_ases %u", req->num_ases);
if (req->num_ases < 1) { if (req->num_ases < 1) {
BT_WARN("Number_of_ASEs parameter value is less than 1"); LOG_WRN("Number_of_ASEs parameter value is less than 1");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} else if (buf->len < req->num_ases * sizeof(*cfg)) { } else if (buf->len < req->num_ases * sizeof(*cfg)) {
BT_WARN("Malformed ASE Config: len %u < %zu", buf->len, LOG_WRN("Malformed ASE Config: len %u < %zu", buf->len,
req->num_ases * sizeof(*cfg)); req->num_ases * sizeof(*cfg));
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -1348,18 +1340,18 @@ static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf)
int err; int err;
if (buf->len < sizeof(*cfg)) { if (buf->len < sizeof(*cfg)) {
BT_WARN("Malformed ASE Config: len %u < %zu", buf->len, sizeof(*cfg)); LOG_WRN("Malformed ASE Config: len %u < %zu", buf->len, sizeof(*cfg));
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
cfg = net_buf_simple_pull_mem(buf, sizeof(*cfg)); cfg = net_buf_simple_pull_mem(buf, sizeof(*cfg));
if (buf->len < cfg->cc_len) { if (buf->len < cfg->cc_len) {
BT_WARN("Malformed ASE Codec Config len %u != %u", buf->len, cfg->cc_len); LOG_WRN("Malformed ASE Codec Config len %u != %u", buf->len, cfg->cc_len);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
BT_DBG("ase 0x%02x cc_len %u", cfg->ase, cfg->cc_len); LOG_DBG("ase 0x%02x cc_len %u", cfg->ase, cfg->cc_len);
if (cfg->ase) { if (cfg->ase) {
ase = ase_get(ascs, cfg->ase); ase = ase_get(ascs, cfg->ase);
@ -1370,13 +1362,13 @@ static ssize_t ascs_config(struct bt_ascs *ascs, struct net_buf_simple *buf)
if (!ase) { if (!ase) {
ascs_cp_rsp_add(cfg->ase, BT_ASCS_CONFIG_OP, ascs_cp_rsp_add(cfg->ase, BT_ASCS_CONFIG_OP,
BT_ASCS_RSP_INVALID_ASE, 0x00); BT_ASCS_RSP_INVALID_ASE, 0x00);
BT_WARN("Unknown ase 0x%02x", cfg->ase); LOG_WRN("Unknown ase 0x%02x", cfg->ase);
continue; continue;
} }
err = ase_config(ascs, ase, cfg, buf); err = ase_config(ascs, ase, cfg, buf);
if (err != 0) { if (err != 0) {
BT_WARN("Malformed ASE Config"); LOG_WRN("Malformed ASE Config");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
} }
@ -1392,10 +1384,10 @@ static int ase_stream_qos(struct bt_audio_stream *stream,
{ {
struct bt_audio_ep *ep; struct bt_audio_ep *ep;
BT_DBG("stream %p ep %p qos %p", stream, stream->ep, qos); LOG_DBG("stream %p ep %p qos %p", stream, stream->ep, qos);
if (stream == NULL || stream->ep == NULL || qos == NULL) { if (stream == NULL || stream->ep == NULL || qos == NULL) {
BT_DBG("Invalid input stream, ep or qos pointers"); LOG_DBG("Invalid input stream, ep or qos pointers");
return -EINVAL; return -EINVAL;
} }
@ -1408,7 +1400,7 @@ static int ase_stream_qos(struct bt_audio_stream *stream,
case BT_AUDIO_EP_STATE_QOS_CONFIGURED: case BT_AUDIO_EP_STATE_QOS_CONFIGURED:
break; break;
default: default:
BT_WARN("Invalid operation in state: %s", bt_audio_ep_state_str(ep->status.state)); LOG_WRN("Invalid operation in state: %s", bt_audio_ep_state_str(ep->status.state));
return -EBADMSG; return -EBADMSG;
} }
@ -1425,7 +1417,7 @@ static int ase_stream_qos(struct bt_audio_stream *stream,
err = unicast_server_cb->qos(stream, qos); err = unicast_server_cb->qos(stream, qos);
if (err != 0) { if (err != 0) {
BT_DBG("Application returned error: %d", err); LOG_DBG("Application returned error: %d", err);
return err; return err;
} }
} }
@ -1440,12 +1432,12 @@ static int ase_stream_qos(struct bt_audio_stream *stream,
iso = audio_iso_get_or_new(ascs, cig_id, cis_id); iso = audio_iso_get_or_new(ascs, cig_id, cis_id);
if (iso == NULL) { if (iso == NULL) {
BT_ERR("Could not allocate audio_iso"); LOG_ERR("Could not allocate audio_iso");
return -ENOMEM; return -ENOMEM;
} }
if (bt_audio_iso_get_ep(iso, ep->dir) != NULL) { if (bt_audio_iso_get_ep(iso, ep->dir) != NULL) {
BT_ERR("iso %p already in use in dir %u", LOG_ERR("iso %p already in use in dir %u",
&iso->chan, ep->dir); &iso->chan, ep->dir);
bt_audio_iso_unref(iso); bt_audio_iso_unref(iso);
return -EALREADY; return -EALREADY;
@ -1481,7 +1473,7 @@ static void ase_qos(struct bt_ascs_ase *ase, const struct bt_ascs_qos *qos)
cqos->latency = sys_le16_to_cpu(qos->latency); cqos->latency = sys_le16_to_cpu(qos->latency);
cqos->pd = sys_get_le24(qos->pd); cqos->pd = sys_get_le24(qos->pd);
BT_DBG("ase %p cig 0x%02x cis 0x%02x interval %u framing 0x%02x " LOG_DBG("ase %p cig 0x%02x cis 0x%02x interval %u framing 0x%02x "
"phy 0x%02x sdu %u rtn %u latency %u pd %u", ase, qos->cig, "phy 0x%02x sdu %u rtn %u latency %u pd %u", ase, qos->cig,
qos->cis, cqos->interval, cqos->framing, cqos->phy, cqos->sdu, qos->cis, cqos->interval, cqos->framing, cqos->phy, cqos->sdu,
cqos->rtn, cqos->latency, cqos->pd); cqos->rtn, cqos->latency, cqos->pd);
@ -1490,7 +1482,7 @@ static void ase_qos(struct bt_ascs_ase *ase, const struct bt_ascs_qos *qos)
if (err) { if (err) {
uint8_t reason = BT_ASCS_REASON_NONE; uint8_t reason = BT_ASCS_REASON_NONE;
BT_ERR("QoS failed: err %d", err); LOG_ERR("QoS failed: err %d", err);
if (err == -ENOTSUP) { if (err == -ENOTSUP) {
if (cqos->interval == 0) { if (cqos->interval == 0) {
@ -1551,13 +1543,13 @@ static ssize_t ascs_qos(struct bt_ascs *ascs, struct net_buf_simple *buf)
req = net_buf_simple_pull_mem(buf, sizeof(*req)); req = net_buf_simple_pull_mem(buf, sizeof(*req));
BT_DBG("num_ases %u", req->num_ases); LOG_DBG("num_ases %u", req->num_ases);
if (req->num_ases < 1) { if (req->num_ases < 1) {
BT_WARN("Number_of_ASEs parameter value is less than 1"); LOG_WRN("Number_of_ASEs parameter value is less than 1");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} else if (buf->len < req->num_ases * sizeof(*qos)) { } else if (buf->len < req->num_ases * sizeof(*qos)) {
BT_WARN("Malformed ASE QoS: len %u < %zu", buf->len, req->num_ases * sizeof(*qos)); LOG_WRN("Malformed ASE QoS: len %u < %zu", buf->len, req->num_ases * sizeof(*qos));
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -1566,13 +1558,13 @@ static ssize_t ascs_qos(struct bt_ascs *ascs, struct net_buf_simple *buf)
qos = net_buf_simple_pull_mem(buf, sizeof(*qos)); qos = net_buf_simple_pull_mem(buf, sizeof(*qos));
BT_DBG("ase 0x%02x", qos->ase); LOG_DBG("ase 0x%02x", qos->ase);
ase = ase_find(ascs, qos->ase); ase = ase_find(ascs, qos->ase);
if (!ase) { if (!ase) {
ascs_cp_rsp_add(qos->ase, BT_ASCS_QOS_OP, ascs_cp_rsp_add(qos->ase, BT_ASCS_QOS_OP,
BT_ASCS_RSP_INVALID_ASE, 0x00); BT_ASCS_RSP_INVALID_ASE, 0x00);
BT_WARN("Unknown ase 0x%02x", qos->ase); LOG_WRN("Unknown ase 0x%02x", qos->ase);
continue; continue;
} }
@ -1595,9 +1587,7 @@ static bool ascs_codec_store_metadata(struct bt_data *data, void *user_data)
meta->data.data = meta->value; meta->data.data = meta->value;
(void)memcpy(meta->value, data->data, data->data_len); (void)memcpy(meta->value, data->data, data->data_len);
BT_DBG("#%zu: data: %s", LOG_DBG("#%zu: data: %s", codec->meta_count, bt_hex(meta->value, data->data_len));
codec->meta_count,
bt_hex(meta->value, data->data_len));
codec->meta_count++; codec->meta_count++;
@ -1620,19 +1610,19 @@ static bool ascs_parse_metadata(struct bt_data *data, void *user_data)
result->count++; result->count++;
BT_DBG("#%u type 0x%02x len %u", result->count, data_type, data_len); LOG_DBG("#%u type 0x%02x len %u", result->count, data_type, data_len);
if (result->count > CONFIG_BT_CODEC_MAX_METADATA_COUNT) { if (result->count > CONFIG_BT_CODEC_MAX_METADATA_COUNT) {
BT_ERR("Not enough buffers for Codec Config Metadata: %zu > %zu", LOG_ERR("Not enough buffers for Codec Config Metadata: %zu > %zu", result->count,
result->count, CONFIG_BT_CODEC_MAX_METADATA_LEN); CONFIG_BT_CODEC_MAX_METADATA_LEN);
result->err = -ENOMEM; result->err = -ENOMEM;
return false; return false;
} }
if (data_len > CONFIG_BT_CODEC_MAX_METADATA_LEN) { if (data_len > CONFIG_BT_CODEC_MAX_METADATA_LEN) {
BT_ERR("Not enough space for Codec Config Metadata: %u > %zu", LOG_ERR("Not enough space for Codec Config Metadata: %u > %zu", data->data_len,
data->data_len, CONFIG_BT_CODEC_MAX_METADATA_LEN); CONFIG_BT_CODEC_MAX_METADATA_LEN);
result->err = -ENOMEM; result->err = -ENOMEM;
return false; return false;
@ -1646,7 +1636,7 @@ static bool ascs_parse_metadata(struct bt_data *data, void *user_data)
const uint16_t context = sys_get_le16(data_value); const uint16_t context = sys_get_le16(data_value);
if (!bt_pacs_context_available(ep->dir, context)) { if (!bt_pacs_context_available(ep->dir, context)) {
BT_WARN("Context 0x%04x is unavailable", context); LOG_WRN("Context 0x%04x is unavailable", context);
result->err = -EACCES; result->err = -EACCES;
@ -1661,7 +1651,7 @@ static bool ascs_parse_metadata(struct bt_data *data, void *user_data)
if (!bt_cap_acceptor_ccid_exist(ep->stream->conn, if (!bt_cap_acceptor_ccid_exist(ep->stream->conn,
ccid)) { ccid)) {
BT_WARN("CCID %u is unknown", ccid); LOG_WRN("CCID %u is unknown", ccid);
/* TBD: /* TBD:
* Should we reject the Metadata? * Should we reject the Metadata?
@ -1698,7 +1688,7 @@ static int ascs_verify_metadata(const struct net_buf_simple *buf,
/* Check if all entries could be parsed */ /* Check if all entries could be parsed */
if (meta_ltv.len != 0) { if (meta_ltv.len != 0) {
BT_ERR("Unable to parse Metadata: len %u", meta_ltv.len); LOG_ERR("Unable to parse Metadata: len %u", meta_ltv.len);
if (meta_ltv.len > 2) { if (meta_ltv.len > 2) {
/* Value of the Metadata Type field in error */ /* Value of the Metadata Type field in error */
@ -1721,7 +1711,7 @@ static int ascs_ep_set_metadata(struct bt_audio_ep *ep, struct net_buf_simple *b
return -EINVAL; return -EINVAL;
} }
BT_DBG("ep %p len %u codec %p", ep, len, codec); LOG_DBG("ep %p len %u codec %p", ep, len, codec);
if (len == 0) { if (len == 0) {
(void)memset(codec->meta, 0, sizeof(codec->meta)); (void)memset(codec->meta, 0, sizeof(codec->meta));
@ -1761,7 +1751,7 @@ static int ase_metadata(struct bt_ascs_ase *ase, uint8_t op,
uint8_t state; uint8_t state;
int err; int err;
BT_DBG("ase %p meta->len %u", ase, meta->len); LOG_DBG("ase %p meta->len %u", ase, meta->len);
ep = &ase->ep; ep = &ase->ep;
state = ep->status.state; state = ep->status.state;
@ -1773,7 +1763,7 @@ static int ase_metadata(struct bt_ascs_ase *ase, uint8_t op,
case BT_AUDIO_EP_STATE_STREAMING: case BT_AUDIO_EP_STATE_STREAMING:
break; break;
default: default:
BT_WARN("Invalid operation in state: %s", bt_audio_ep_state_str(state)); LOG_WRN("Invalid operation in state: %s", bt_audio_ep_state_str(state));
err = -EBADMSG; err = -EBADMSG;
ascs_cp_rsp_add_errno(ASE_ID(ase), op, err, ascs_cp_rsp_add_errno(ASE_ID(ase), op, err,
buf->len ? *buf->data : 0x00); buf->len ? *buf->data : 0x00);
@ -1810,7 +1800,7 @@ static int ase_metadata(struct bt_ascs_ase *ase, uint8_t op,
(void)memcpy(ep->codec.meta, metadata_backup, (void)memcpy(ep->codec.meta, metadata_backup,
sizeof(metadata_backup)); sizeof(metadata_backup));
BT_ERR("Metadata failed: %d", err); LOG_ERR("Metadata failed: %d", err);
ascs_cp_rsp_add_errno(ASE_ID(ase), op, err, ascs_cp_rsp_add_errno(ASE_ID(ase), op, err,
buf->len ? *buf->data : 0x00); buf->len ? *buf->data : 0x00);
return err; return err;
@ -1831,14 +1821,14 @@ static int ase_enable(struct bt_ascs_ase *ase, struct bt_ascs_metadata *meta,
struct bt_audio_ep *ep; struct bt_audio_ep *ep;
int err; int err;
BT_DBG("ase %p buf->len %u", ase, buf->len); LOG_DBG("ase %p buf->len %u", ase, buf->len);
ep = &ase->ep; ep = &ase->ep;
/* Valid for an ASE only if ASE_State field = 0x02 (QoS Configured) */ /* Valid for an ASE only if ASE_State field = 0x02 (QoS Configured) */
if (ep->status.state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) { if (ep->status.state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) {
err = -EBADMSG; err = -EBADMSG;
BT_WARN("Invalid operation in state: %s", bt_audio_ep_state_str(ep->status.state)); LOG_WRN("Invalid operation in state: %s", bt_audio_ep_state_str(ep->status.state));
ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_ENABLE_OP, err, ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_ENABLE_OP, err,
BT_ASCS_REASON_NONE); BT_ASCS_REASON_NONE);
return err; return err;
@ -1865,7 +1855,7 @@ static int ase_enable(struct bt_ascs_ase *ase, struct bt_ascs_metadata *meta,
} }
if (err) { if (err) {
BT_ERR("Enable rejected: %d", err); LOG_ERR("Enable rejected: %d", err);
ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_ENABLE_OP, err, ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_ENABLE_OP, err,
BT_ASCS_REASON_NONE); BT_ASCS_REASON_NONE);
return -EFAULT; return -EFAULT;
@ -1890,13 +1880,13 @@ static ssize_t ascs_enable(struct bt_ascs *ascs, struct net_buf_simple *buf)
req = net_buf_simple_pull_mem(buf, sizeof(*req)); req = net_buf_simple_pull_mem(buf, sizeof(*req));
BT_DBG("num_ases %u", req->num_ases); LOG_DBG("num_ases %u", req->num_ases);
if (req->num_ases < 1) { if (req->num_ases < 1) {
BT_WARN("Number_of_ASEs parameter value is less than 1"); LOG_WRN("Number_of_ASEs parameter value is less than 1");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} else if (buf->len < req->num_ases * sizeof(*meta)) { } else if (buf->len < req->num_ases * sizeof(*meta)) {
BT_WARN("Malformed ASE Metadata: len %u < %zu", buf->len, LOG_WRN("Malformed ASE Metadata: len %u < %zu", buf->len,
req->num_ases * sizeof(*meta)); req->num_ases * sizeof(*meta));
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -1906,10 +1896,10 @@ static ssize_t ascs_enable(struct bt_ascs *ascs, struct net_buf_simple *buf)
meta = net_buf_simple_pull_mem(buf, sizeof(*meta)); meta = net_buf_simple_pull_mem(buf, sizeof(*meta));
BT_DBG("ase 0x%02x meta->len %u", meta->ase, meta->len); LOG_DBG("ase 0x%02x meta->len %u", meta->ase, meta->len);
if (buf->len < meta->len) { if (buf->len < meta->len) {
BT_WARN("Malformed ASE Enable Metadata len %u != %u", buf->len, meta->len); LOG_WRN("Malformed ASE Enable Metadata len %u != %u", buf->len, meta->len);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -1917,7 +1907,7 @@ static ssize_t ascs_enable(struct bt_ascs *ascs, struct net_buf_simple *buf)
if (!ase) { if (!ase) {
ascs_cp_rsp_add(meta->ase, BT_ASCS_ENABLE_OP, ascs_cp_rsp_add(meta->ase, BT_ASCS_ENABLE_OP,
BT_ASCS_RSP_INVALID_ASE, 0x00); BT_ASCS_RSP_INVALID_ASE, 0x00);
BT_WARN("Unknown ase 0x%02x", meta->ase); LOG_WRN("Unknown ase 0x%02x", meta->ase);
continue; continue;
} }
@ -1931,13 +1921,13 @@ static void ase_start(struct bt_ascs_ase *ase)
{ {
struct bt_audio_ep *ep; struct bt_audio_ep *ep;
BT_DBG("ase %p", ase); LOG_DBG("ase %p", ase);
ep = &ase->ep; ep = &ase->ep;
/* Valid for an ASE only if ASE_State field = 0x02 (QoS Configured) */ /* Valid for an ASE only if ASE_State field = 0x02 (QoS Configured) */
if (ep->status.state != BT_AUDIO_EP_STATE_ENABLING) { if (ep->status.state != BT_AUDIO_EP_STATE_ENABLING) {
BT_WARN("Invalid operation in state: %s", bt_audio_ep_state_str(ep->status.state)); LOG_WRN("Invalid operation in state: %s", bt_audio_ep_state_str(ep->status.state));
ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_START_OP, -EBADMSG, ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_START_OP, -EBADMSG,
BT_ASCS_REASON_NONE); BT_ASCS_REASON_NONE);
return; return;
@ -1950,7 +1940,7 @@ static void ase_start(struct bt_ascs_ase *ase)
* Response_Code value for that ASE to 0x05 (Invalid ASE direction). * Response_Code value for that ASE to 0x05 (Invalid ASE direction).
*/ */
if (ep->dir == BT_AUDIO_DIR_SINK) { if (ep->dir == BT_AUDIO_DIR_SINK) {
BT_WARN("Start failed: invalid operation for Sink"); LOG_WRN("Start failed: invalid operation for Sink");
ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP,
BT_ASCS_RSP_INVALID_DIR, BT_ASCS_REASON_NONE); BT_ASCS_RSP_INVALID_DIR, BT_ASCS_REASON_NONE);
return; return;
@ -1963,7 +1953,7 @@ static void ase_start(struct bt_ascs_ase *ase)
err = ase_stream_start(ep->stream); err = ase_stream_start(ep->stream);
if (err) { if (err) {
BT_ERR("Start failed: %d", err); LOG_ERR("Start failed: %d", err);
ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, err, ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_START_OP, err,
BT_ASCS_REASON_NONE); BT_ASCS_REASON_NONE);
return; return;
@ -1984,13 +1974,13 @@ static ssize_t ascs_start(struct bt_ascs *ascs, struct net_buf_simple *buf)
req = net_buf_simple_pull_mem(buf, sizeof(*req)); req = net_buf_simple_pull_mem(buf, sizeof(*req));
BT_DBG("num_ases %u", req->num_ases); LOG_DBG("num_ases %u", req->num_ases);
if (req->num_ases < 1) { if (req->num_ases < 1) {
BT_WARN("Number_of_ASEs parameter value is less than 1"); LOG_WRN("Number_of_ASEs parameter value is less than 1");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} else if (buf->len < req->num_ases) { } else if (buf->len < req->num_ases) {
BT_WARN("Malformed ASE Start: len %u < %u", buf->len, req->num_ases); LOG_WRN("Malformed ASE Start: len %u < %u", buf->len, req->num_ases);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -2000,13 +1990,13 @@ static ssize_t ascs_start(struct bt_ascs *ascs, struct net_buf_simple *buf)
id = net_buf_simple_pull_u8(buf); id = net_buf_simple_pull_u8(buf);
BT_DBG("ase 0x%02x", id); LOG_DBG("ase 0x%02x", id);
ase = ase_find(ascs, id); ase = ase_find(ascs, id);
if (!ase) { if (!ase) {
ascs_cp_rsp_add(id, BT_ASCS_START_OP, ascs_cp_rsp_add(id, BT_ASCS_START_OP,
BT_ASCS_RSP_INVALID_ASE, 0x00); BT_ASCS_RSP_INVALID_ASE, 0x00);
BT_WARN("Unknown ase 0x%02x", id); LOG_WRN("Unknown ase 0x%02x", id);
continue; continue;
} }
@ -2027,13 +2017,13 @@ static ssize_t ascs_disable(struct bt_ascs *ascs, struct net_buf_simple *buf)
req = net_buf_simple_pull_mem(buf, sizeof(*req)); req = net_buf_simple_pull_mem(buf, sizeof(*req));
BT_DBG("num_ases %u", req->num_ases); LOG_DBG("num_ases %u", req->num_ases);
if (req->num_ases < 1) { if (req->num_ases < 1) {
BT_WARN("Number_of_ASEs parameter value is less than 1"); LOG_WRN("Number_of_ASEs parameter value is less than 1");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} else if (buf->len < req->num_ases) { } else if (buf->len < req->num_ases) {
BT_WARN("Malformed ASE Disable: len %u < %u", buf->len, req->num_ases); LOG_WRN("Malformed ASE Disable: len %u < %u", buf->len, req->num_ases);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -2043,13 +2033,13 @@ static ssize_t ascs_disable(struct bt_ascs *ascs, struct net_buf_simple *buf)
id = net_buf_simple_pull_u8(buf); id = net_buf_simple_pull_u8(buf);
BT_DBG("ase 0x%02x", id); LOG_DBG("ase 0x%02x", id);
ase = ase_find(ascs, id); ase = ase_find(ascs, id);
if (!ase) { if (!ase) {
ascs_cp_rsp_add(id, BT_ASCS_DISABLE_OP, ascs_cp_rsp_add(id, BT_ASCS_DISABLE_OP,
BT_ASCS_RSP_INVALID_ASE, 0x00); BT_ASCS_RSP_INVALID_ASE, 0x00);
BT_WARN("Unknown ase 0x%02x", id); LOG_WRN("Unknown ase 0x%02x", id);
continue; continue;
} }
@ -2065,7 +2055,7 @@ static void ase_stop(struct bt_ascs_ase *ase)
struct bt_audio_ep *ep; struct bt_audio_ep *ep;
int err; int err;
BT_DBG("ase %p", ase); LOG_DBG("ase %p", ase);
ep = &ase->ep; ep = &ase->ep;
@ -2076,14 +2066,14 @@ static void ase_stop(struct bt_ascs_ase *ase)
* Response_Code value for that ASE to 0x05 (Invalid ASE direction). * Response_Code value for that ASE to 0x05 (Invalid ASE direction).
*/ */
if (ase->ep.dir == BT_AUDIO_DIR_SINK) { if (ase->ep.dir == BT_AUDIO_DIR_SINK) {
BT_WARN("Stop failed: invalid operation for Sink"); LOG_WRN("Stop failed: invalid operation for Sink");
ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_STOP_OP, ascs_cp_rsp_add(ASE_ID(ase), BT_ASCS_STOP_OP,
BT_ASCS_RSP_INVALID_DIR, BT_ASCS_REASON_NONE); BT_ASCS_RSP_INVALID_DIR, BT_ASCS_REASON_NONE);
return; return;
} }
if (ep->status.state != BT_AUDIO_EP_STATE_DISABLING) { if (ep->status.state != BT_AUDIO_EP_STATE_DISABLING) {
BT_WARN("Invalid operation in state: %s", bt_audio_ep_state_str(ep->status.state)); LOG_WRN("Invalid operation in state: %s", bt_audio_ep_state_str(ep->status.state));
ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_STOP_OP, -EBADMSG, ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_STOP_OP, -EBADMSG,
BT_ASCS_REASON_NONE); BT_ASCS_REASON_NONE);
return; return;
@ -2097,7 +2087,7 @@ static void ase_stop(struct bt_ascs_ase *ase)
} }
if (err) { if (err) {
BT_ERR("Stop failed: %d", err); LOG_ERR("Stop failed: %d", err);
ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_STOP_OP, err, ascs_cp_rsp_add_errno(ASE_ID(ase), BT_ASCS_STOP_OP, err,
BT_ASCS_REASON_NONE); BT_ASCS_REASON_NONE);
return; return;
@ -2110,14 +2100,14 @@ static void ase_stop(struct bt_ascs_ase *ase)
*/ */
err = bt_audio_stream_disconnect(stream); err = bt_audio_stream_disconnect(stream);
if (err != -ENOTCONN && err != 0) { if (err != -ENOTCONN && err != 0) {
BT_ERR("Could not disconnect the CIS: %d", err); LOG_ERR("Could not disconnect the CIS: %d", err);
return; return;
} }
ascs_ep_set_state(ep, BT_AUDIO_EP_STATE_QOS_CONFIGURED); ascs_ep_set_state(ep, BT_AUDIO_EP_STATE_QOS_CONFIGURED);
err = bt_audio_stream_iso_listen(stream); err = bt_audio_stream_iso_listen(stream);
if (err != 0) { if (err != 0) {
BT_ERR("Could not make stream listen: %d", err); LOG_ERR("Could not make stream listen: %d", err);
return; return;
} }
@ -2135,13 +2125,13 @@ static ssize_t ascs_stop(struct bt_ascs *ascs, struct net_buf_simple *buf)
req = net_buf_simple_pull_mem(buf, sizeof(*req)); req = net_buf_simple_pull_mem(buf, sizeof(*req));
BT_DBG("num_ases %u", req->num_ases); LOG_DBG("num_ases %u", req->num_ases);
if (req->num_ases < 1) { if (req->num_ases < 1) {
BT_WARN("Number_of_ASEs parameter value is less than 1"); LOG_WRN("Number_of_ASEs parameter value is less than 1");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} else if (buf->len < req->num_ases) { } else if (buf->len < req->num_ases) {
BT_WARN("Malformed ASE Start: len %u < %u", buf->len, req->num_ases); LOG_WRN("Malformed ASE Start: len %u < %u", buf->len, req->num_ases);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -2151,13 +2141,13 @@ static ssize_t ascs_stop(struct bt_ascs *ascs, struct net_buf_simple *buf)
id = net_buf_simple_pull_u8(buf); id = net_buf_simple_pull_u8(buf);
BT_DBG("ase 0x%02x", id); LOG_DBG("ase 0x%02x", id);
ase = ase_find(ascs, id); ase = ase_find(ascs, id);
if (!ase) { if (!ase) {
ascs_cp_rsp_add(id, BT_ASCS_STOP_OP, ascs_cp_rsp_add(id, BT_ASCS_STOP_OP,
BT_ASCS_RSP_INVALID_ASE, 0x00); BT_ASCS_RSP_INVALID_ASE, 0x00);
BT_WARN("Unknown ase 0x%02x", id); LOG_WRN("Unknown ase 0x%02x", id);
continue; continue;
} }
@ -2179,13 +2169,13 @@ static ssize_t ascs_metadata(struct bt_ascs *ascs, struct net_buf_simple *buf)
req = net_buf_simple_pull_mem(buf, sizeof(*req)); req = net_buf_simple_pull_mem(buf, sizeof(*req));
BT_DBG("num_ases %u", req->num_ases); LOG_DBG("num_ases %u", req->num_ases);
if (req->num_ases < 1) { if (req->num_ases < 1) {
BT_WARN("Number_of_ASEs parameter value is less than 1"); LOG_WRN("Number_of_ASEs parameter value is less than 1");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} else if (buf->len < req->num_ases * sizeof(*meta)) { } else if (buf->len < req->num_ases * sizeof(*meta)) {
BT_WARN("Malformed ASE Metadata: len %u < %zu", buf->len, LOG_WRN("Malformed ASE Metadata: len %u < %zu", buf->len,
req->num_ases * sizeof(*meta)); req->num_ases * sizeof(*meta));
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -2196,17 +2186,17 @@ static ssize_t ascs_metadata(struct bt_ascs *ascs, struct net_buf_simple *buf)
meta = net_buf_simple_pull_mem(buf, sizeof(*meta)); meta = net_buf_simple_pull_mem(buf, sizeof(*meta));
if (buf->len < meta->len) { if (buf->len < meta->len) {
BT_WARN("Malformed ASE Metadata: len %u < %u", buf->len, meta->len); LOG_WRN("Malformed ASE Metadata: len %u < %u", buf->len, meta->len);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
BT_DBG("ase 0x%02x meta->len %u", meta->ase, meta->len); LOG_DBG("ase 0x%02x meta->len %u", meta->ase, meta->len);
ase = ase_find(ascs, meta->ase); ase = ase_find(ascs, meta->ase);
if (!ase) { if (!ase) {
ascs_cp_rsp_add(meta->ase, BT_ASCS_METADATA_OP, ascs_cp_rsp_add(meta->ase, BT_ASCS_METADATA_OP,
BT_ASCS_RSP_INVALID_ASE, 0x00); BT_ASCS_RSP_INVALID_ASE, 0x00);
BT_WARN("Unknown ase 0x%02x", meta->ase); LOG_WRN("Unknown ase 0x%02x", meta->ase);
continue; continue;
} }
@ -2227,13 +2217,13 @@ static ssize_t ascs_release(struct bt_ascs *ascs, struct net_buf_simple *buf)
req = net_buf_simple_pull_mem(buf, sizeof(*req)); req = net_buf_simple_pull_mem(buf, sizeof(*req));
BT_DBG("num_ases %u", req->num_ases); LOG_DBG("num_ases %u", req->num_ases);
if (req->num_ases < 1) { if (req->num_ases < 1) {
BT_WARN("Number_of_ASEs parameter value is less than 1"); LOG_WRN("Number_of_ASEs parameter value is less than 1");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} else if (buf->len < req->num_ases) { } else if (buf->len < req->num_ases) {
BT_WARN("Malformed ASE Release: len %u < %u", buf->len, req->num_ases); LOG_WRN("Malformed ASE Release: len %u < %u", buf->len, req->num_ases);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -2243,19 +2233,19 @@ static ssize_t ascs_release(struct bt_ascs *ascs, struct net_buf_simple *buf)
id = net_buf_simple_pull_u8(buf); id = net_buf_simple_pull_u8(buf);
BT_DBG("ase 0x%02x", id); LOG_DBG("ase 0x%02x", id);
ase = ase_find(ascs, id); ase = ase_find(ascs, id);
if (!ase) { if (!ase) {
ascs_cp_rsp_add(id, BT_ASCS_RELEASE_OP, ascs_cp_rsp_add(id, BT_ASCS_RELEASE_OP,
BT_ASCS_RSP_INVALID_ASE, 0); BT_ASCS_RSP_INVALID_ASE, 0);
BT_WARN("Unknown ase 0x%02x", id); LOG_WRN("Unknown ase 0x%02x", id);
continue; continue;
} }
if (ase->ep.status.state == BT_AUDIO_EP_STATE_IDLE || if (ase->ep.status.state == BT_AUDIO_EP_STATE_IDLE ||
ase->ep.status.state == BT_AUDIO_EP_STATE_RELEASING) { ase->ep.status.state == BT_AUDIO_EP_STATE_RELEASING) {
BT_WARN("Invalid operation in state: %s", LOG_WRN("Invalid operation in state: %s",
bt_audio_ep_state_str(ase->ep.status.state)); bt_audio_ep_state_str(ase->ep.status.state));
ascs_cp_rsp_add(id, BT_ASCS_RELEASE_OP, ascs_cp_rsp_add(id, BT_ASCS_RELEASE_OP,
BT_ASCS_RSP_INVALID_ASE_STATE, BT_ASCS_REASON_NONE); BT_ASCS_RSP_INVALID_ASE_STATE, BT_ASCS_REASON_NONE);
@ -2289,8 +2279,8 @@ static ssize_t ascs_cp_write(struct bt_conn *conn,
req = net_buf_simple_pull_mem(&buf, sizeof(*req)); req = net_buf_simple_pull_mem(&buf, sizeof(*req));
BT_DBG("conn %p attr %p buf %p len %u op %s (0x%02x)", conn, LOG_DBG("conn %p attr %p buf %p len %u op %s (0x%02x)", conn, attr, data, len,
attr, data, len, bt_ascs_op_str(req->op), req->op); bt_ascs_op_str(req->op), req->op);
/* Reset/empty response buffer before using it again */ /* Reset/empty response buffer before using it again */
net_buf_simple_reset(&rsp_buf); net_buf_simple_reset(&rsp_buf);
@ -2322,7 +2312,7 @@ static ssize_t ascs_cp_write(struct bt_conn *conn,
break; break;
default: default:
ascs_cp_rsp_add(0x00, req->op, BT_ASCS_RSP_NOT_SUPPORTED, 0); ascs_cp_rsp_add(0x00, req->op, BT_ASCS_RSP_NOT_SUPPORTED, 0);
BT_DBG("Unknown opcode"); LOG_DBG("Unknown opcode");
goto respond; goto respond;
} }

View file

@ -20,9 +20,10 @@
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
#include <zephyr/sys/check.h> #include <zephyr/sys/check.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_BAP_BROADCAST_ASSISTANT) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_bap_broadcast_assistant
#include "common/log.h" LOG_MODULE_REGISTER(bt_bap_broadcast_assistant, CONFIG_BT_BAP_BROADCAST_ASSISTANT_LOG_LEVEL);
#include "common/bt_str.h" #include "common/bt_str.h"
#include "bap_internal.h" #include "bap_internal.h"
@ -71,7 +72,7 @@ static int16_t lookup_index_by_handle(uint16_t handle)
} }
} }
BT_ERR("Unknown handle 0x%04x", handle); LOG_ERR("Unknown handle 0x%04x", handle);
return -1; return -1;
} }
@ -85,12 +86,12 @@ static int parse_recv_state(const void *data, uint16_t length,
__ASSERT(recv_state, "NULL receive state"); __ASSERT(recv_state, "NULL receive state");
if (data == NULL || length == 0) { if (data == NULL || length == 0) {
BT_DBG("NULL data"); LOG_DBG("NULL data");
return -EINVAL; return -EINVAL;
} }
if (length < MINIMUM_RECV_STATE_LEN) { if (length < MINIMUM_RECV_STATE_LEN) {
BT_DBG("Invalid receive state length %u, expected at least %u", LOG_DBG("Invalid receive state length %u, expected at least %u",
length, MINIMUM_RECV_STATE_LEN); length, MINIMUM_RECV_STATE_LEN);
return -EINVAL; return -EINVAL;
} }
@ -113,7 +114,7 @@ static int parse_recv_state(const void *data, uint16_t length,
sizeof(recv_state->num_subgroups); sizeof(recv_state->num_subgroups);
if (buf.len < minimum_size) { if (buf.len < minimum_size) {
BT_DBG("Invalid receive state length %u, expected at least %zu", LOG_DBG("Invalid receive state length %u, expected at least %zu",
buf.len, minimum_size); buf.len, minimum_size);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -130,7 +131,7 @@ static int parse_recv_state(const void *data, uint16_t length,
uint8_t *metadata; uint8_t *metadata;
if (buf.len < sizeof(subgroup->bis_sync)) { if (buf.len < sizeof(subgroup->bis_sync)) {
BT_DBG("Invalid receive state length %u, expected at least %zu", LOG_DBG("Invalid receive state length %u, expected at least %zu",
buf.len, buf.len + sizeof(subgroup->bis_sync)); buf.len, buf.len + sizeof(subgroup->bis_sync));
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -138,20 +139,20 @@ static int parse_recv_state(const void *data, uint16_t length,
subgroup->bis_sync = net_buf_simple_pull_le32(&buf); subgroup->bis_sync = net_buf_simple_pull_le32(&buf);
if (buf.len < sizeof(subgroup->metadata_len)) { if (buf.len < sizeof(subgroup->metadata_len)) {
BT_DBG("Invalid receive state length %u, expected at least %zu", LOG_DBG("Invalid receive state length %u, expected at least %zu",
buf.len, buf.len + sizeof(subgroup->metadata_len)); buf.len, buf.len + sizeof(subgroup->metadata_len));
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
subgroup->metadata_len = net_buf_simple_pull_u8(&buf); subgroup->metadata_len = net_buf_simple_pull_u8(&buf);
if (buf.len < subgroup->metadata_len) { if (buf.len < subgroup->metadata_len) {
BT_DBG("Invalid receive state length %u, expected at least %u", LOG_DBG("Invalid receive state length %u, expected at least %u",
buf.len, buf.len + subgroup->metadata_len); buf.len, buf.len + subgroup->metadata_len);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
if (subgroup->metadata_len > sizeof(subgroup->metadata)) { if (subgroup->metadata_len > sizeof(subgroup->metadata)) {
BT_DBG("Metadata too long: %u/%zu", LOG_DBG("Metadata too long: %u/%zu",
subgroup->metadata_len, subgroup->metadata_len,
sizeof(subgroup->metadata)); sizeof(subgroup->metadata));
} }
@ -163,7 +164,7 @@ static int parse_recv_state(const void *data, uint16_t length,
} }
if (buf.len != 0) { if (buf.len != 0) {
BT_DBG("Invalid receive state length %u, but only %u was parsed", LOG_DBG("Invalid receive state length %u, but only %u was parsed",
length, length - buf.len); length, length - buf.len);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -182,7 +183,7 @@ static uint8_t notify_handler(struct bt_conn *conn,
int16_t index; int16_t index;
if (data == NULL) { if (data == NULL) {
BT_DBG("[UNSUBSCRIBED] %u", handle); LOG_DBG("[UNSUBSCRIBED] %u", handle);
params->value_handle = 0U; params->value_handle = 0U;
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
@ -192,7 +193,7 @@ static uint8_t notify_handler(struct bt_conn *conn,
index = lookup_index_by_handle(handle); index = lookup_index_by_handle(handle);
if (index < 0) { if (index < 0) {
BT_DBG("Invalid index"); LOG_DBG("Invalid index");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
@ -203,7 +204,7 @@ static uint8_t notify_handler(struct bt_conn *conn,
/* TODO: Likely due to the length. /* TODO: Likely due to the length.
* Start a read autonomously * Start a read autonomously
*/ */
BT_WARN("Invalid receive state received"); LOG_WRN("Invalid receive state received");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
@ -249,7 +250,7 @@ static uint8_t read_recv_state_cb(struct bt_conn *conn, uint8_t err,
cb_err = parse_recv_state(data, length, &recv_state); cb_err = parse_recv_state(data, length, &recv_state);
if (cb_err != 0) { if (cb_err != 0) {
BT_DBG("Invalid receive state"); LOG_DBG("Invalid receive state");
} else { } else {
broadcast_assistant.src_ids[index] = recv_state.src_id; broadcast_assistant.src_ids[index] = recv_state.src_id;
} }
@ -257,7 +258,7 @@ static uint8_t read_recv_state_cb(struct bt_conn *conn, uint8_t err,
} }
if (cb_err != 0) { if (cb_err != 0) {
BT_DBG("err: %d", cb_err); LOG_DBG("err: %d", cb_err);
if (broadcast_assistant.discovering) { if (broadcast_assistant.discovering) {
broadcast_assistant.discovering = false; broadcast_assistant.discovering = false;
if (broadcast_assistant_cbs != NULL && if (broadcast_assistant_cbs != NULL &&
@ -315,7 +316,7 @@ static uint8_t char_discover_func(struct bt_conn *conn,
int err; int err;
if (attr == NULL) { if (attr == NULL) {
BT_DBG("Found %u BASS receive states", LOG_DBG("Found %u BASS receive states",
broadcast_assistant.recv_state_cnt); broadcast_assistant.recv_state_cnt);
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
@ -331,22 +332,21 @@ static uint8_t char_discover_func(struct bt_conn *conn,
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) {
struct bt_gatt_chrc *chrc = struct bt_gatt_chrc *chrc =
(struct bt_gatt_chrc *)attr->user_data; (struct bt_gatt_chrc *)attr->user_data;
if (bt_uuid_cmp(chrc->uuid, BT_UUID_BASS_CONTROL_POINT) == 0) { if (bt_uuid_cmp(chrc->uuid, BT_UUID_BASS_CONTROL_POINT) == 0) {
BT_DBG("Control Point"); LOG_DBG("Control Point");
broadcast_assistant.cp_handle = attr->handle + 1; broadcast_assistant.cp_handle = attr->handle + 1;
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_BASS_RECV_STATE) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_BASS_RECV_STATE) == 0) {
if (broadcast_assistant.recv_state_cnt < if (broadcast_assistant.recv_state_cnt <
CONFIG_BT_BAP_BROADCAST_ASSISTANT_RECV_STATE_COUNT) { CONFIG_BT_BAP_BROADCAST_ASSISTANT_RECV_STATE_COUNT) {
uint8_t idx = broadcast_assistant.recv_state_cnt++; uint8_t idx = broadcast_assistant.recv_state_cnt++;
BT_DBG("Receive State %u", LOG_DBG("Receive State %u", broadcast_assistant.recv_state_cnt);
broadcast_assistant.recv_state_cnt);
broadcast_assistant.recv_state_handles[idx] = broadcast_assistant.recv_state_handles[idx] =
attr->handle + 1; attr->handle + 1;
sub_params = &broadcast_assistant.recv_state_sub_params[idx]; sub_params = &broadcast_assistant.recv_state_sub_params[idx];
@ -365,8 +365,8 @@ static uint8_t char_discover_func(struct bt_conn *conn,
err = bt_gatt_subscribe(conn, sub_params); err = bt_gatt_subscribe(conn, sub_params);
if (err != 0) { if (err != 0) {
BT_DBG("Could not subscribe to handle 0x%04x", LOG_DBG("Could not subscribe to handle 0x%04x",
sub_params->value_handle); sub_params->value_handle);
broadcast_assistant.discovering = false; broadcast_assistant.discovering = false;
if (broadcast_assistant_cbs != NULL && if (broadcast_assistant_cbs != NULL &&
@ -392,7 +392,7 @@ static uint8_t service_discover_func(struct bt_conn *conn,
struct bt_gatt_service_val *prim_service; struct bt_gatt_service_val *prim_service;
if (attr == NULL) { if (attr == NULL) {
BT_DBG("Could not discover BASS"); LOG_DBG("Could not discover BASS");
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
broadcast_assistant.discovering = false; broadcast_assistant.discovering = false;
@ -406,7 +406,7 @@ static uint8_t service_discover_func(struct bt_conn *conn,
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_PRIMARY) { if (params->type == BT_GATT_DISCOVER_PRIMARY) {
prim_service = (struct bt_gatt_service_val *)attr->user_data; prim_service = (struct bt_gatt_service_val *)attr->user_data;
@ -421,7 +421,7 @@ static uint8_t service_discover_func(struct bt_conn *conn,
err = bt_gatt_discover(conn, &broadcast_assistant.disc_params); err = bt_gatt_discover(conn, &broadcast_assistant.disc_params);
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
broadcast_assistant.discovering = false; broadcast_assistant.discovering = false;
if (broadcast_assistant_cbs != NULL && if (broadcast_assistant_cbs != NULL &&
@ -477,7 +477,7 @@ static void bap_broadcast_assistant_write_cp_cb(struct bt_conn *conn, uint8_t er
} }
break; break;
default: default:
BT_DBG("Unknown opcode 0x%02x", opcode); LOG_DBG("Unknown opcode 0x%02x", opcode);
break; break;
} }
} }
@ -490,7 +490,7 @@ static int bt_bap_broadcast_assistant_common_cp(struct bt_conn *conn,
if (conn == NULL) { if (conn == NULL) {
return -EINVAL; return -EINVAL;
} else if (broadcast_assistant.cp_handle == 0) { } else if (broadcast_assistant.cp_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -533,8 +533,7 @@ static bool broadcast_source_found(struct bt_data *data, void *user_data)
broadcast_id = sys_get_le24(data->data + BT_UUID_SIZE_16); broadcast_id = sys_get_le24(data->data + BT_UUID_SIZE_16);
BT_DBG("Found BIS advertiser with address %s", LOG_DBG("Found BIS advertiser with address %s", bt_addr_le_str(info->addr));
bt_addr_le_str(info->addr));
if (broadcast_assistant_cbs != NULL && if (broadcast_assistant_cbs != NULL &&
broadcast_assistant_cbs->scan != NULL) { broadcast_assistant_cbs->scan != NULL) {
@ -617,7 +616,7 @@ int bt_bap_broadcast_assistant_scan_start(struct bt_conn *conn, bool start_scan)
err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL);
if (err != 0) { if (err != 0) {
BT_DBG("Could not start scan (%d)", err); LOG_DBG("Could not start scan (%d)", err);
return err; return err;
} }
@ -650,7 +649,7 @@ int bt_bap_broadcast_assistant_scan_stop(struct bt_conn *conn)
if (broadcast_assistant.scanning) { if (broadcast_assistant.scanning) {
err = bt_le_scan_stop(); err = bt_le_scan_stop();
if (err != 0) { if (err != 0) {
BT_DBG("Could not stop scan (%d)", err); LOG_DBG("Could not stop scan (%d)", err);
return err; return err;
} }
@ -714,8 +713,7 @@ int bt_bap_broadcast_assistant_add_src(struct bt_conn *conn,
param->subgroups[i].metadata_len; param->subgroups[i].metadata_len;
if (cp_buf.len + subgroup_size > cp_buf.size) { if (cp_buf.len + subgroup_size > cp_buf.size) {
BT_DBG("MTU is too small to send %zu octets", LOG_DBG("MTU is too small to send %zu octets", cp_buf.len + subgroup_size);
cp_buf.len + subgroup_size);
return -EINVAL; return -EINVAL;
} }
@ -725,7 +723,7 @@ int bt_bap_broadcast_assistant_add_src(struct bt_conn *conn,
subgroup->bis_sync = param->subgroups[i].bis_sync; subgroup->bis_sync = param->subgroups[i].bis_sync;
CHECKIF(param->pa_sync == 0 && subgroup->bis_sync != 0) { CHECKIF(param->pa_sync == 0 && subgroup->bis_sync != 0) {
BT_DBG("Only syncing to BIS is not allowed"); LOG_DBG("Only syncing to BIS is not allowed");
return -EINVAL; return -EINVAL;
} }
@ -783,8 +781,7 @@ int bt_bap_broadcast_assistant_mod_src(struct bt_conn *conn,
param->subgroups[i].metadata_len; param->subgroups[i].metadata_len;
if (cp_buf.len + subgroup_size > cp_buf.size) { if (cp_buf.len + subgroup_size > cp_buf.size) {
BT_DBG("MTU is too small to send %zu octets", LOG_DBG("MTU is too small to send %zu octets", cp_buf.len + subgroup_size);
cp_buf.len + subgroup_size);
return -EINVAL; return -EINVAL;
} }
subgroup = net_buf_simple_add(&cp_buf, subgroup_size); subgroup = net_buf_simple_add(&cp_buf, subgroup_size);
@ -792,7 +789,7 @@ int bt_bap_broadcast_assistant_mod_src(struct bt_conn *conn,
subgroup->bis_sync = param->subgroups[i].bis_sync; subgroup->bis_sync = param->subgroups[i].bis_sync;
CHECKIF(param->pa_sync == 0 && subgroup->bis_sync != 0) { CHECKIF(param->pa_sync == 0 && subgroup->bis_sync != 0) {
BT_DBG("Only syncing to BIS is not allowed"); LOG_DBG("Only syncing to BIS is not allowed");
return -EINVAL; return -EINVAL;
} }
@ -868,7 +865,7 @@ int bt_bap_broadcast_assistant_read_recv_state(struct bt_conn *conn,
} }
if (broadcast_assistant.recv_state_handles[idx] == 0) { if (broadcast_assistant.recv_state_handles[idx] == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }

View file

@ -20,9 +20,10 @@
#include <zephyr/bluetooth/gatt.h> #include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/buf.h> #include <zephyr/bluetooth/buf.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_BAP_SCAN_DELEGATOR) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_bap_scan_delegator
#include "common/log.h" LOG_MODULE_REGISTER(bt_bap_scan_delegator, CONFIG_BT_BAP_SCAN_DELEGATOR_LOG_LEVEL);
#include "common/bt_str.h" #include "common/bt_str.h"
#include "audio_internal.h" #include "audio_internal.h"
@ -156,23 +157,21 @@ static void bt_debug_dump_recv_state(const struct bass_recv_state_internal *recv
const bool is_bad_code = state->encrypt_state == const bool is_bad_code = state->encrypt_state ==
BT_BAP_BIG_ENC_STATE_BAD_CODE; BT_BAP_BIG_ENC_STATE_BAD_CODE;
BT_DBG("Receive State[%d]: src ID %u, addr %s, adv_sid %u, " LOG_DBG("Receive State[%d]: src ID %u, addr %s, adv_sid %u, "
"broadcast_id %u, pa_sync_state %u, " "broadcast_id %u, pa_sync_state %u, "
"encrypt state %u%s%s, num_subgroups %u", "encrypt state %u%s%s, num_subgroups %u",
recv_state->index, state->src_id, bt_addr_le_str(&state->addr), recv_state->index, state->src_id, bt_addr_le_str(&state->addr), state->adv_sid,
state->adv_sid, state->broadcast_id, state->pa_sync_state, state->broadcast_id, state->pa_sync_state, state->encrypt_state,
state->encrypt_state, is_bad_code ? ", bad code" : "",
is_bad_code ? ", bad code" : "", is_bad_code ? bt_hex(state->bad_code, sizeof(state->bad_code)) : "",
is_bad_code ? bt_hex(state->bad_code, sizeof(state->bad_code)) : "", state->num_subgroups);
state->num_subgroups);
for (int i = 0; i < state->num_subgroups; i++) { for (int i = 0; i < state->num_subgroups; i++) {
const struct bt_bap_scan_delegator_subgroup *subgroup = &state->subgroups[i]; const struct bt_bap_scan_delegator_subgroup *subgroup = &state->subgroups[i];
BT_DBG("\tSubgroup[%d]: BIS sync %u (requested %u), metadata_len %u, metadata: %s", LOG_DBG("\tSubgroup[%d]: BIS sync %u (requested %u), metadata_len %u, metadata: %s",
i, subgroup->bis_sync, subgroup->requested_bis_sync, i, subgroup->bis_sync, subgroup->requested_bis_sync, subgroup->metadata_len,
subgroup->metadata_len, bt_hex(subgroup->metadata, subgroup->metadata_len));
bt_hex(subgroup->metadata, subgroup->metadata_len));
} }
} }
@ -182,7 +181,7 @@ static void bass_notify_receive_state(const struct bass_recv_state_internal *sta
state->attr, read_buf.data, read_buf.len); state->attr, read_buf.data, read_buf.len);
if (err != 0) { if (err != 0) {
BT_DBG("Could not notify receive state: %d", err); LOG_DBG("Could not notify receive state: %d", err);
} }
} }
@ -230,7 +229,7 @@ static void scan_delegator_disconnected(struct bt_conn *conn, uint8_t reason)
} }
if (assistant != NULL) { if (assistant != NULL) {
BT_DBG("Instance %u with addr %s disconnected", LOG_DBG("Instance %u with addr %s disconnected",
i, bt_addr_le_str(bt_conn_get_dst(conn))); i, bt_addr_le_str(bt_conn_get_dst(conn)));
(void)memset(assistant, 0, sizeof(*assistant)); (void)memset(assistant, 0, sizeof(*assistant));
} }
@ -263,7 +262,7 @@ static void scan_delegator_security_changed(struct bt_conn *conn,
state->attr, read_buf.data, state->attr, read_buf.data,
read_buf.len); read_buf.len);
if (err != 0) { if (err != 0) {
BT_WARN("Could not notify receive state[%d] to reconnecting assistant: %d", LOG_WRN("Could not notify receive state[%d] to reconnecting assistant: %d",
i, err); i, err);
} }
} }
@ -379,7 +378,7 @@ static void pa_synced(struct bt_le_per_adv_sync *sync,
{ {
struct bass_recv_state_internal *state; struct bass_recv_state_internal *state;
BT_DBG("Synced%s", info->conn ? " via PAST" : ""); LOG_DBG("Synced%s", info->conn ? " via PAST" : "");
if (info->conn != NULL) { if (info->conn != NULL) {
state = bass_lookup_addr(info->addr); state = bass_lookup_addr(info->addr);
@ -388,7 +387,7 @@ static void pa_synced(struct bt_le_per_adv_sync *sync,
} }
if (state == NULL) { if (state == NULL) {
BT_DBG("BASS receive state not found"); LOG_DBG("BASS receive state not found");
return; return;
} }
@ -413,7 +412,7 @@ static void pa_terminated(struct bt_le_per_adv_sync *sync,
{ {
struct bass_recv_state_internal *state = bass_lookup_pa_sync(sync); struct bass_recv_state_internal *state = bass_lookup_pa_sync(sync);
BT_DBG("Terminated"); LOG_DBG("Terminated");
if (state != NULL) { if (state != NULL) {
state->state.pa_sync_state = BT_BAP_PA_STATE_NOT_SYNCED; state->state.pa_sync_state = BT_BAP_PA_STATE_NOT_SYNCED;
@ -476,7 +475,7 @@ static void biginfo_recv(struct bt_le_per_adv_sync *sync,
int err = bis_sync(state); int err = bis_sync(state);
if (err != 0) { if (err != 0) {
BT_DBG("BIS sync failed %d", err); LOG_DBG("BIS sync failed %d", err);
} }
} }
@ -498,7 +497,7 @@ static void pa_timer_handler(struct k_work *work)
struct bass_recv_state_internal *recv_state = CONTAINER_OF( struct bass_recv_state_internal *recv_state = CONTAINER_OF(
dwork, struct bass_recv_state_internal, pa_timer); dwork, struct bass_recv_state_internal, pa_timer);
BT_DBG("PA timeout"); LOG_DBG("PA timeout");
__ASSERT(recv_state, "NULL receive state"); __ASSERT(recv_state, "NULL receive state");
@ -508,7 +507,7 @@ static void pa_timer_handler(struct k_work *work)
int err = bt_le_per_adv_sync_delete(recv_state->pa_sync); int err = bt_le_per_adv_sync_delete(recv_state->pa_sync);
if (err != 0) { if (err != 0) {
BT_ERR("Could not delete BASS pa_sync"); LOG_ERR("Could not delete BASS pa_sync");
} }
recv_state->state.pa_sync_state = BT_BAP_PA_STATE_FAILED; recv_state->state.pa_sync_state = BT_BAP_PA_STATE_FAILED;
@ -539,7 +538,7 @@ static int bis_sync(struct bass_recv_state_internal *state)
param.mse = 0; param.mse = 0;
param.sync_timeout = interval_to_sync_timeout(state->iso_interval); param.sync_timeout = interval_to_sync_timeout(state->iso_interval);
BT_DBG("Bitfield %x", param.bis_bitfield); LOG_DBG("Bitfield %x", param.bis_bitfield);
if (param.bis_bitfield == 0) { if (param.bis_bitfield == 0) {
/* Don't attempt to sync anything */ /* Don't attempt to sync anything */
@ -630,7 +629,7 @@ static void scan_delegator_pa_sync_no_past(struct bass_recv_state_internal *stat
struct bt_le_per_adv_sync_param param = { 0 }; struct bt_le_per_adv_sync_param param = { 0 };
if (state->pa_sync_pending) { if (state->pa_sync_pending) {
BT_DBG("PA sync pending"); LOG_DBG("PA sync pending");
return; return;
} }
@ -644,11 +643,10 @@ static void scan_delegator_pa_sync_no_past(struct bass_recv_state_internal *stat
*/ */
err = bt_le_per_adv_sync_create(&param, &state->pa_sync); err = bt_le_per_adv_sync_create(&param, &state->pa_sync);
if (err != 0) { if (err != 0) {
BT_WARN("Could not sync per adv: %d", err); LOG_WRN("Could not sync per adv: %d", err);
recv_state->pa_sync_state = BT_BAP_PA_STATE_FAILED; recv_state->pa_sync_state = BT_BAP_PA_STATE_FAILED;
} else { } else {
BT_DBG("PA sync pending for addr %s", LOG_DBG("PA sync pending for addr %s", bt_addr_le_str(&recv_state->addr));
bt_addr_le_str(&recv_state->addr));
state->pa_sync_pending = true; state->pa_sync_pending = true;
(void)k_work_reschedule(&state->pa_timer, (void)k_work_reschedule(&state->pa_timer,
K_MSEC(param.timeout * 10)); K_MSEC(param.timeout * 10));
@ -668,7 +666,7 @@ static void scan_delegator_pa_sync_cancel(struct bass_recv_state_internal *state
err = bt_le_per_adv_sync_delete(state->pa_sync); err = bt_le_per_adv_sync_delete(state->pa_sync);
if (err != 0) { if (err != 0) {
BT_WARN("Could not delete per adv sync: %d", err); LOG_WRN("Could not delete per adv sync: %d", err);
} else { } else {
state->pa_sync_pending = false; state->pa_sync_pending = false;
state->pa_sync = NULL; state->pa_sync = NULL;
@ -682,7 +680,7 @@ static void scan_delegator_pa_sync(struct bt_conn *conn,
{ {
struct bt_bap_scan_delegator_recv_state *recv_state = &state->state; struct bt_bap_scan_delegator_recv_state *recv_state = &state->state;
BT_DBG("pa_past %u, pa_interval 0x%04x", pa_past, state->pa_interval); LOG_DBG("pa_past %u, pa_interval 0x%04x", pa_past, state->pa_interval);
if (recv_state->pa_sync_state == BT_BAP_PA_STATE_SYNCED || if (recv_state->pa_sync_state == BT_BAP_PA_STATE_SYNCED ||
recv_state->pa_sync_state == BT_BAP_PA_STATE_INFO_REQ) { recv_state->pa_sync_state == BT_BAP_PA_STATE_INFO_REQ) {
@ -710,7 +708,7 @@ static int scan_delegator_add_source(struct bt_conn *conn,
/* subtract 1 as the opcode has already been pulled */ /* subtract 1 as the opcode has already been pulled */
if (buf->len < sizeof(struct bt_bap_bass_cp_add_src) - 1) { if (buf->len < sizeof(struct bt_bap_bass_cp_add_src) - 1) {
BT_DBG("Invalid length %u", buf->size); LOG_DBG("Invalid length %u", buf->size);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -724,7 +722,7 @@ static int scan_delegator_add_source(struct bt_conn *conn,
} }
if (internal_state == NULL) { if (internal_state == NULL) {
BT_DBG("Could not add src"); LOG_DBG("Could not add src");
return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES); return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES);
} }
@ -733,7 +731,7 @@ static int scan_delegator_add_source(struct bt_conn *conn,
state->src_id = next_src_id(); state->src_id = next_src_id();
state->addr.type = net_buf_simple_pull_u8(buf); state->addr.type = net_buf_simple_pull_u8(buf);
if (state->addr.type > BT_ADDR_LE_RANDOM) { if (state->addr.type > BT_ADDR_LE_RANDOM) {
BT_DBG("Invalid address type %u", state->addr.type); LOG_DBG("Invalid address type %u", state->addr.type);
return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED); return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED);
} }
@ -742,7 +740,7 @@ static int scan_delegator_add_source(struct bt_conn *conn,
state->adv_sid = net_buf_simple_pull_u8(buf); state->adv_sid = net_buf_simple_pull_u8(buf);
if (state->adv_sid > BT_GAP_SID_MAX) { if (state->adv_sid > BT_GAP_SID_MAX) {
BT_DBG("Invalid adv SID %u", state->adv_sid); LOG_DBG("Invalid adv SID %u", state->adv_sid);
return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED); return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED);
} }
@ -750,7 +748,7 @@ static int scan_delegator_add_source(struct bt_conn *conn,
pa_sync = net_buf_simple_pull_u8(buf); pa_sync = net_buf_simple_pull_u8(buf);
if (pa_sync > BT_BAP_BASS_PA_REQ_SYNC) { if (pa_sync > BT_BAP_BASS_PA_REQ_SYNC) {
BT_DBG("Invalid PA sync value %u", pa_sync); LOG_DBG("Invalid PA sync value %u", pa_sync);
return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED); return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED);
} }
@ -758,8 +756,8 @@ static int scan_delegator_add_source(struct bt_conn *conn,
state->num_subgroups = net_buf_simple_pull_u8(buf); state->num_subgroups = net_buf_simple_pull_u8(buf);
if (state->num_subgroups > CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS) { if (state->num_subgroups > CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS) {
BT_WARN("Too many subgroups %u/%u", LOG_WRN("Too many subgroups %u/%u", state->num_subgroups,
state->num_subgroups, CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS); CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS);
return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES); return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES);
} }
@ -768,7 +766,7 @@ static int scan_delegator_add_source(struct bt_conn *conn,
uint8_t *metadata; uint8_t *metadata;
if (buf->len < (sizeof(subgroup->bis_sync) + sizeof(subgroup->metadata_len))) { if (buf->len < (sizeof(subgroup->bis_sync) + sizeof(subgroup->metadata_len))) {
BT_DBG("Invalid length %u", buf->size); LOG_DBG("Invalid length %u", buf->size);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -776,16 +774,15 @@ static int scan_delegator_add_source(struct bt_conn *conn,
if (subgroup->requested_bis_sync && if (subgroup->requested_bis_sync &&
pa_sync == BT_BAP_BASS_PA_REQ_NO_SYNC) { pa_sync == BT_BAP_BASS_PA_REQ_NO_SYNC) {
BT_DBG("Cannot sync to BIS without PA"); LOG_DBG("Cannot sync to BIS without PA");
return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED); return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED);
} }
/* Verify that the request BIS sync indexes are unique or no preference */ /* Verify that the request BIS sync indexes are unique or no preference */
if (bis_syncs_unique_or_no_pref(subgroup->requested_bis_sync, if (bis_syncs_unique_or_no_pref(subgroup->requested_bis_sync,
aggregated_bis_syncs)) { aggregated_bis_syncs)) {
BT_DBG("Duplicate BIS index [%d]%x (aggregated %x)", LOG_DBG("Duplicate BIS index [%d]%x (aggregated %x)", i,
i, subgroup->requested_bis_sync, subgroup->requested_bis_sync, aggregated_bis_syncs);
aggregated_bis_syncs);
return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED); return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED);
} }
@ -798,15 +795,14 @@ static int scan_delegator_add_source(struct bt_conn *conn,
subgroup->metadata_len = net_buf_simple_pull_u8(buf); subgroup->metadata_len = net_buf_simple_pull_u8(buf);
if (buf->len < subgroup->metadata_len) { if (buf->len < subgroup->metadata_len) {
BT_DBG("Invalid length %u", buf->size); LOG_DBG("Invalid length %u", buf->size);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
if (subgroup->metadata_len > CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_METADATA_LEN) { if (subgroup->metadata_len > CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_METADATA_LEN) {
BT_WARN("Metadata too long %u/%u", LOG_WRN("Metadata too long %u/%u", subgroup->metadata_len,
subgroup->metadata_len,
CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_METADATA_LEN); CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_METADATA_LEN);
return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES); return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES);
@ -818,7 +814,7 @@ static int scan_delegator_add_source(struct bt_conn *conn,
} }
if (buf->len != 0) { if (buf->len != 0) {
BT_DBG("Invalid length %u", buf->size); LOG_DBG("Invalid length %u", buf->size);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -831,8 +827,7 @@ static int scan_delegator_add_source(struct bt_conn *conn,
(pa_sync == BT_BAP_BASS_PA_REQ_SYNC_PAST)); (pa_sync == BT_BAP_BASS_PA_REQ_SYNC_PAST));
} }
BT_DBG("Index %u: New source added: ID 0x%02x", LOG_DBG("Index %u: New source added: ID 0x%02x", internal_state->index, state->src_id);
internal_state->index, state->src_id);
bt_debug_dump_recv_state(internal_state); bt_debug_dump_recv_state(internal_state);
net_buf_put_recv_state(internal_state); net_buf_put_recv_state(internal_state);
@ -860,7 +855,7 @@ static int scan_delegator_mod_src(struct bt_conn *conn,
/* subtract 1 as the opcode has already been pulled */ /* subtract 1 as the opcode has already been pulled */
if (buf->len < sizeof(struct bt_bap_bass_cp_mod_src) - 1) { if (buf->len < sizeof(struct bt_bap_bass_cp_mod_src) - 1) {
BT_DBG("Invalid length %u", buf->size); LOG_DBG("Invalid length %u", buf->size);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -869,14 +864,14 @@ static int scan_delegator_mod_src(struct bt_conn *conn,
internal_state = bass_lookup_src_id(src_id); internal_state = bass_lookup_src_id(src_id);
if (internal_state == NULL) { if (internal_state == NULL) {
BT_DBG("Could not find state by src id %u", src_id); LOG_DBG("Could not find state by src id %u", src_id);
return BT_GATT_ERR(BT_BAP_BASS_ERR_INVALID_SRC_ID); return BT_GATT_ERR(BT_BAP_BASS_ERR_INVALID_SRC_ID);
} }
pa_sync = net_buf_simple_pull_u8(buf); pa_sync = net_buf_simple_pull_u8(buf);
if (pa_sync > BT_BAP_BASS_PA_REQ_SYNC) { if (pa_sync > BT_BAP_BASS_PA_REQ_SYNC) {
BT_DBG("Invalid PA sync value %u", pa_sync); LOG_DBG("Invalid PA sync value %u", pa_sync);
return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED); return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED);
} }
@ -885,8 +880,7 @@ static int scan_delegator_mod_src(struct bt_conn *conn,
num_subgroups = net_buf_simple_pull_u8(buf); num_subgroups = net_buf_simple_pull_u8(buf);
if (num_subgroups > CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS) { if (num_subgroups > CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS) {
BT_WARN("Too many subgroups %u/%u", LOG_WRN("Too many subgroups %u/%u", num_subgroups,
num_subgroups,
CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS); CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS);
return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES); return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES);
@ -897,23 +891,22 @@ static int scan_delegator_mod_src(struct bt_conn *conn,
uint8_t *metadata; uint8_t *metadata;
if (buf->len < (sizeof(subgroup->bis_sync) + sizeof(subgroup->metadata_len))) { if (buf->len < (sizeof(subgroup->bis_sync) + sizeof(subgroup->metadata_len))) {
BT_DBG("Invalid length %u", buf->len); LOG_DBG("Invalid length %u", buf->len);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
subgroup->requested_bis_sync = net_buf_simple_pull_le32(buf); subgroup->requested_bis_sync = net_buf_simple_pull_le32(buf);
if (subgroup->requested_bis_sync && if (subgroup->requested_bis_sync &&
pa_sync == BT_BAP_BASS_PA_REQ_NO_SYNC) { pa_sync == BT_BAP_BASS_PA_REQ_NO_SYNC) {
BT_DBG("Cannot sync to BIS without PA"); LOG_DBG("Cannot sync to BIS without PA");
return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED); return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED);
} }
/* Verify that the request BIS sync indexes are unique or no preference */ /* Verify that the request BIS sync indexes are unique or no preference */
if (bis_syncs_unique_or_no_pref(subgroup->requested_bis_sync, if (bis_syncs_unique_or_no_pref(subgroup->requested_bis_sync,
aggregated_bis_syncs)) { aggregated_bis_syncs)) {
BT_DBG("Duplicate BIS index [%d]%x (aggregated %x)", LOG_DBG("Duplicate BIS index [%d]%x (aggregated %x)", i,
i, subgroup->requested_bis_sync, subgroup->requested_bis_sync, aggregated_bis_syncs);
aggregated_bis_syncs);
return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED); return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED);
} }
@ -925,13 +918,12 @@ static int scan_delegator_mod_src(struct bt_conn *conn,
subgroup->metadata_len = net_buf_simple_pull_u8(buf); subgroup->metadata_len = net_buf_simple_pull_u8(buf);
if (buf->len < subgroup->metadata_len) { if (buf->len < subgroup->metadata_len) {
BT_DBG("Invalid length %u", buf->len); LOG_DBG("Invalid length %u", buf->len);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
if (subgroup->metadata_len > CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_METADATA_LEN) { if (subgroup->metadata_len > CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_METADATA_LEN) {
BT_WARN("Metadata too long %u/%u", LOG_WRN("Metadata too long %u/%u", subgroup->metadata_len,
subgroup->metadata_len,
CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_METADATA_LEN); CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_METADATA_LEN);
return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES); return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES);
} }
@ -943,7 +935,7 @@ static int scan_delegator_mod_src(struct bt_conn *conn,
} }
if (buf->len != 0) { if (buf->len != 0) {
BT_DBG("Invalid length %u", buf->size); LOG_DBG("Invalid length %u", buf->size);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -999,7 +991,7 @@ static int scan_delegator_mod_src(struct bt_conn *conn,
/* Terminated BIG first if existed */ /* Terminated BIG first if existed */
err = bis_sync_cancel(internal_state); err = bis_sync_cancel(internal_state);
if (err != 0) { if (err != 0) {
BT_WARN("Could not terminate existing BIG %d", err); LOG_WRN("Could not terminate existing BIG %d", err);
return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
} }
@ -1015,8 +1007,7 @@ static int scan_delegator_mod_src(struct bt_conn *conn,
state_changed |= old_pa_sync_state != state->pa_sync_state; state_changed |= old_pa_sync_state != state->pa_sync_state;
BT_DBG("Index %u: Source modified: ID 0x%02x", LOG_DBG("Index %u: Source modified: ID 0x%02x", internal_state->index, state->src_id);
internal_state->index, state->src_id);
bt_debug_dump_recv_state(internal_state); bt_debug_dump_recv_state(internal_state);
/* Notify if changed */ /* Notify if changed */
@ -1037,7 +1028,7 @@ static int scan_delegator_broadcast_code(struct net_buf_simple *buf)
/* subtract 1 as the opcode has already been pulled */ /* subtract 1 as the opcode has already been pulled */
if (buf->len != sizeof(struct bt_bap_bass_cp_broadcase_code) - 1) { if (buf->len != sizeof(struct bt_bap_bass_cp_broadcase_code) - 1) {
BT_DBG("Invalid length %u", buf->size); LOG_DBG("Invalid length %u", buf->size);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -1045,7 +1036,7 @@ static int scan_delegator_broadcast_code(struct net_buf_simple *buf)
internal_state = bass_lookup_src_id(src_id); internal_state = bass_lookup_src_id(src_id);
if (internal_state == NULL) { if (internal_state == NULL) {
BT_DBG("Could not find state by src id %u", src_id); LOG_DBG("Could not find state by src id %u", src_id);
return BT_GATT_ERR(BT_BAP_BASS_ERR_INVALID_SRC_ID); return BT_GATT_ERR(BT_BAP_BASS_ERR_INVALID_SRC_ID);
} }
@ -1054,9 +1045,8 @@ static int scan_delegator_broadcast_code(struct net_buf_simple *buf)
(void)memcpy(internal_state->broadcast_code, broadcast_code, (void)memcpy(internal_state->broadcast_code, broadcast_code,
sizeof(internal_state->broadcast_code)); sizeof(internal_state->broadcast_code));
BT_DBG("Index %u: broadcast code added: %s", internal_state->index, LOG_DBG("Index %u: broadcast code added: %s", internal_state->index,
bt_hex(internal_state->broadcast_code, bt_hex(internal_state->broadcast_code, sizeof(internal_state->broadcast_code)));
sizeof(internal_state->broadcast_code)));
internal_state->broadcast_code_received = true; internal_state->broadcast_code_received = true;
@ -1064,11 +1054,11 @@ static int scan_delegator_broadcast_code(struct net_buf_simple *buf)
return 0; return 0;
} }
BT_DBG("Syncing to BIS"); LOG_DBG("Syncing to BIS");
err = bis_sync(internal_state); err = bis_sync(internal_state);
if (err != 0) { if (err != 0) {
BT_DBG("BIS sync failed %d", err); LOG_DBG("BIS sync failed %d", err);
return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
} }
@ -1083,7 +1073,7 @@ static int scan_delegator_rem_src(struct net_buf_simple *buf)
/* subtract 1 as the opcode has already been pulled */ /* subtract 1 as the opcode has already been pulled */
if (buf->len != sizeof(struct bt_bap_bass_cp_rem_src) - 1) { if (buf->len != sizeof(struct bt_bap_bass_cp_rem_src) - 1) {
BT_DBG("Invalid length %u", buf->size); LOG_DBG("Invalid length %u", buf->size);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
@ -1091,7 +1081,7 @@ static int scan_delegator_rem_src(struct net_buf_simple *buf)
internal_state = bass_lookup_src_id(src_id); internal_state = bass_lookup_src_id(src_id);
if (internal_state == NULL) { if (internal_state == NULL) {
BT_DBG("Could not find state by src id %u", src_id); LOG_DBG("Could not find state by src id %u", src_id);
return BT_GATT_ERR(BT_BAP_BASS_ERR_INVALID_SRC_ID); return BT_GATT_ERR(BT_BAP_BASS_ERR_INVALID_SRC_ID);
} }
@ -1100,18 +1090,17 @@ static int scan_delegator_rem_src(struct net_buf_simple *buf)
/* Check if successful */ /* Check if successful */
if (internal_state->pa_sync) { if (internal_state->pa_sync) {
BT_WARN("Could not terminate PA sync"); LOG_WRN("Could not terminate PA sync");
return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
} }
err = bis_sync_cancel(internal_state); err = bis_sync_cancel(internal_state);
if (err != 0) { if (err != 0) {
BT_WARN("Could not terminate BIG %d", err); LOG_WRN("Could not terminate BIG %d", err);
return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
} }
BT_DBG("Index %u: Removed source with ID 0x%02x", LOG_DBG("Index %u: Removed source with ID 0x%02x", internal_state->index, src_id);
internal_state->index, src_id);
internal_state->active = false; internal_state->active = false;
(void)memset(&internal_state->state, 0, sizeof(internal_state->state)); (void)memset(&internal_state->state, 0, sizeof(internal_state->state));
@ -1162,60 +1151,60 @@ static ssize_t write_control_point(struct bt_conn *conn,
switch (opcode) { switch (opcode) {
case BT_BAP_BASS_OP_SCAN_STOP: case BT_BAP_BASS_OP_SCAN_STOP:
BT_DBG("Assistant stopping scanning"); LOG_DBG("Assistant stopping scanning");
if (buf.len != 0) { if (buf.len != 0) {
BT_DBG("Invalid length %u", buf.size); LOG_DBG("Invalid length %u", buf.size);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
bap_broadcast_assistant->scanning = false; bap_broadcast_assistant->scanning = false;
break; break;
case BT_BAP_BASS_OP_SCAN_START: case BT_BAP_BASS_OP_SCAN_START:
BT_DBG("Assistant starting scanning"); LOG_DBG("Assistant starting scanning");
if (buf.len != 0) { if (buf.len != 0) {
BT_DBG("Invalid length %u", buf.size); LOG_DBG("Invalid length %u", buf.size);
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
bap_broadcast_assistant->scanning = true; bap_broadcast_assistant->scanning = true;
break; break;
case BT_BAP_BASS_OP_ADD_SRC: case BT_BAP_BASS_OP_ADD_SRC:
BT_DBG("Assistant adding source"); LOG_DBG("Assistant adding source");
err = scan_delegator_add_source(conn, &buf); err = scan_delegator_add_source(conn, &buf);
if (err != 0) { if (err != 0) {
BT_DBG("Could not add source %d", err); LOG_DBG("Could not add source %d", err);
return err; return err;
} }
break; break;
case BT_BAP_BASS_OP_MOD_SRC: case BT_BAP_BASS_OP_MOD_SRC:
BT_DBG("Assistant modifying source"); LOG_DBG("Assistant modifying source");
err = scan_delegator_mod_src(conn, &buf); err = scan_delegator_mod_src(conn, &buf);
if (err != 0) { if (err != 0) {
BT_DBG("Could not modify source %d", err); LOG_DBG("Could not modify source %d", err);
return err; return err;
} }
break; break;
case BT_BAP_BASS_OP_BROADCAST_CODE: case BT_BAP_BASS_OP_BROADCAST_CODE:
BT_DBG("Assistant setting broadcast code"); LOG_DBG("Assistant setting broadcast code");
err = scan_delegator_broadcast_code(&buf); err = scan_delegator_broadcast_code(&buf);
if (err != 0) { if (err != 0) {
BT_DBG("Could not set broadcast code"); LOG_DBG("Could not set broadcast code");
return err; return err;
} }
break; break;
case BT_BAP_BASS_OP_REM_SRC: case BT_BAP_BASS_OP_REM_SRC:
BT_DBG("Assistant removing source"); LOG_DBG("Assistant removing source");
err = scan_delegator_rem_src(&buf); err = scan_delegator_rem_src(&buf);
if (err != 0) { if (err != 0) {
BT_DBG("Could not remove source %d", err); LOG_DBG("Could not remove source %d", err);
return err; return err;
} }
@ -1230,7 +1219,7 @@ static ssize_t write_control_point(struct bt_conn *conn,
static void recv_state_cfg_changed(const struct bt_gatt_attr *attr, static void recv_state_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_recv_state(struct bt_conn *conn, static ssize_t read_recv_state(struct bt_conn *conn,
@ -1242,7 +1231,7 @@ static ssize_t read_recv_state(struct bt_conn *conn,
struct bt_bap_scan_delegator_recv_state *state = &recv_state->state; struct bt_bap_scan_delegator_recv_state *state = &recv_state->state;
if (recv_state->active) { if (recv_state->active) {
BT_DBG("Index %u: Source ID 0x%02x", idx, state->src_id); LOG_DBG("Index %u: Source ID 0x%02x", idx, state->src_id);
bt_debug_dump_recv_state(recv_state); bt_debug_dump_recv_state(recv_state);
@ -1251,7 +1240,7 @@ static ssize_t read_recv_state(struct bt_conn *conn,
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
read_buf.data, read_buf.len); read_buf.data, read_buf.len);
} else { } else {
BT_DBG("Index %u: Not active", idx); LOG_DBG("Index %u: Not active", idx);
return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0); return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0);
} }
@ -1334,15 +1323,15 @@ int bt_bap_scan_delegator_set_sync_state(
if (bis_synced[i] != 0 && if (bis_synced[i] != 0 &&
pa_sync_state == BT_BAP_PA_STATE_NOT_SYNCED) { pa_sync_state == BT_BAP_PA_STATE_NOT_SYNCED) {
BT_DBG("Cannot set BIS sync when PA sync is not synced"); LOG_DBG("Cannot set BIS sync when PA sync is not synced");
return -EINVAL; return -EINVAL;
} }
if (bits_subset_of(bis_synced[i], if (bits_subset_of(bis_synced[i],
subgroup->requested_bis_sync)) { subgroup->requested_bis_sync)) {
BT_DBG("Subgroup[%d] invalid bis_sync value %x for %x", LOG_DBG("Subgroup[%d] invalid bis_sync value %x for %x", i, bis_synced[i],
i, bis_synced[i], subgroup->requested_bis_sync); subgroup->requested_bis_sync);
return -EINVAL; return -EINVAL;
} }
@ -1353,7 +1342,7 @@ int bt_bap_scan_delegator_set_sync_state(
} }
} }
BT_DBG("Index %u: Source ID 0x%02x synced", recv_state->index, src_id); LOG_DBG("Index %u: Source ID 0x%02x synced", recv_state->index, src_id);
if (recv_state->state.pa_sync_state != pa_sync_state || if (recv_state->state.pa_sync_state != pa_sync_state ||
recv_state->state.encrypt_state != encrypt_state) { recv_state->state.encrypt_state != encrypt_state) {

View file

@ -22,9 +22,10 @@
#include "audio_iso.h" #include "audio_iso.h"
#include "endpoint.h" #include "endpoint.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_BROADCAST_SINK) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_audio_broadcast_sink
#include "common/log.h" LOG_MODULE_REGISTER(bt_audio_broadcast_sink, CONFIG_BT_AUDIO_BROADCAST_SINK_LOG_LEVEL);
#include "common/bt_str.h" #include "common/bt_str.h"
#define PA_SYNC_SKIP 5 #define PA_SYNC_SKIP 5
@ -77,34 +78,33 @@ static void broadcast_sink_set_ep_state(struct bt_audio_ep *ep, uint8_t state)
old_state = ep->status.state; old_state = ep->status.state;
BT_DBG("ep %p id 0x%02x %s -> %s", ep, ep->status.id, LOG_DBG("ep %p id 0x%02x %s -> %s", ep, ep->status.id, bt_audio_ep_state_str(old_state),
bt_audio_ep_state_str(old_state), bt_audio_ep_state_str(state));
bt_audio_ep_state_str(state));
switch (old_state) { switch (old_state) {
case BT_AUDIO_EP_STATE_IDLE: case BT_AUDIO_EP_STATE_IDLE:
if (state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) { if (state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) {
BT_DBG("Invalid broadcast sync endpoint state transition"); LOG_DBG("Invalid broadcast sync endpoint state transition");
return; return;
} }
break; break;
case BT_AUDIO_EP_STATE_QOS_CONFIGURED: case BT_AUDIO_EP_STATE_QOS_CONFIGURED:
if (state != BT_AUDIO_EP_STATE_IDLE && if (state != BT_AUDIO_EP_STATE_IDLE &&
state != BT_AUDIO_EP_STATE_STREAMING) { state != BT_AUDIO_EP_STATE_STREAMING) {
BT_DBG("Invalid broadcast sync endpoint state transition"); LOG_DBG("Invalid broadcast sync endpoint state transition");
return; return;
} }
break; break;
case BT_AUDIO_EP_STATE_STREAMING: case BT_AUDIO_EP_STATE_STREAMING:
if (state != BT_AUDIO_EP_STATE_IDLE) { if (state != BT_AUDIO_EP_STATE_IDLE) {
BT_DBG("Invalid broadcast sync endpoint state transition"); LOG_DBG("Invalid broadcast sync endpoint state transition");
return; return;
} }
break; break;
default: default:
BT_ERR("Invalid broadcast sync endpoint state: %s", LOG_ERR("Invalid broadcast sync endpoint state: %s",
bt_audio_ep_state_str(old_state)); bt_audio_ep_state_str(old_state));
return; return;
} }
@ -132,27 +132,26 @@ static void broadcast_sink_iso_recv(struct bt_iso_chan *chan,
struct bt_audio_ep *ep = iso->rx.ep; struct bt_audio_ep *ep = iso->rx.ep;
if (ep == NULL) { if (ep == NULL) {
BT_ERR("iso %p not bound with ep", chan); LOG_ERR("iso %p not bound with ep", chan);
return; return;
} }
stream = ep->stream; stream = ep->stream;
if (stream == NULL) { if (stream == NULL) {
BT_ERR("No stream for ep %p", ep); LOG_ERR("No stream for ep %p", ep);
return; return;
} }
ops = stream->ops; ops = stream->ops;
if (IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_STREAM_DATA)) { if (IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_STREAM_DATA)) {
BT_DBG("stream %p ep %p len %zu", LOG_DBG("stream %p ep %p len %zu", stream, stream->ep, net_buf_frags_len(buf));
stream, ep, net_buf_frags_len(buf));
} }
if (ops != NULL && ops->recv != NULL) { if (ops != NULL && ops->recv != NULL) {
ops->recv(stream, info, buf); ops->recv(stream, info, buf);
} else { } else {
BT_WARN("No callback for recv set"); LOG_WRN("No callback for recv set");
} }
} }
@ -164,26 +163,26 @@ static void broadcast_sink_iso_connected(struct bt_iso_chan *chan)
struct bt_audio_ep *ep = iso->rx.ep; struct bt_audio_ep *ep = iso->rx.ep;
if (ep == NULL) { if (ep == NULL) {
BT_ERR("iso %p not bound with ep", chan); LOG_ERR("iso %p not bound with ep", chan);
return; return;
} }
stream = ep->stream; stream = ep->stream;
if (stream == NULL) { if (stream == NULL) {
BT_ERR("No stream for ep %p", ep); LOG_ERR("No stream for ep %p", ep);
return; return;
} }
ops = stream->ops; ops = stream->ops;
BT_DBG("stream %p", stream); LOG_DBG("stream %p", stream);
broadcast_sink_set_ep_state(ep, BT_AUDIO_EP_STATE_STREAMING); broadcast_sink_set_ep_state(ep, BT_AUDIO_EP_STATE_STREAMING);
if (ops != NULL && ops->started != NULL) { if (ops != NULL && ops->started != NULL) {
ops->started(stream); ops->started(stream);
} else { } else {
BT_WARN("No callback for connected set"); LOG_WRN("No callback for connected set");
} }
} }
@ -197,31 +196,31 @@ static void broadcast_sink_iso_disconnected(struct bt_iso_chan *chan,
struct bt_audio_broadcast_sink *sink; struct bt_audio_broadcast_sink *sink;
if (ep == NULL) { if (ep == NULL) {
BT_ERR("iso %p not bound with ep", chan); LOG_ERR("iso %p not bound with ep", chan);
return; return;
} }
stream = ep->stream; stream = ep->stream;
if (stream == NULL) { if (stream == NULL) {
BT_ERR("No stream for ep %p", ep); LOG_ERR("No stream for ep %p", ep);
return; return;
} }
ops = stream->ops; ops = stream->ops;
BT_DBG("stream %p ep %p reason 0x%02x", stream, ep, reason); LOG_DBG("stream %p ep %p reason 0x%02x", stream, ep, reason);
broadcast_sink_set_ep_state(ep, BT_AUDIO_EP_STATE_IDLE); broadcast_sink_set_ep_state(ep, BT_AUDIO_EP_STATE_IDLE);
if (ops != NULL && ops->stopped != NULL) { if (ops != NULL && ops->stopped != NULL) {
ops->stopped(stream); ops->stopped(stream);
} else { } else {
BT_WARN("No callback for stopped set"); LOG_WRN("No callback for stopped set");
} }
sink = broadcast_sink_lookup_iso_chan(chan); sink = broadcast_sink_lookup_iso_chan(chan);
if (sink == NULL) { if (sink == NULL) {
BT_ERR("Could not lookup sink by iso %p", chan); LOG_ERR("Could not lookup sink by iso %p", chan);
return; return;
} }
@ -287,7 +286,7 @@ static void pa_synced(struct bt_le_per_adv_sync *sync,
return; return;
} }
BT_DBG("Synced to broadcast source with ID 0x%06X", sink->broadcast_id); LOG_DBG("Synced to broadcast source with ID 0x%06X", sink->broadcast_id);
sink->syncing = false; sink->syncing = false;
@ -316,8 +315,7 @@ static void pa_term(struct bt_le_per_adv_sync *sync,
return; return;
} }
BT_DBG("PA sync with broadcast source with ID 0x%06X lost", LOG_DBG("PA sync with broadcast source with ID 0x%06X lost", sink->broadcast_id);
sink->broadcast_id);
broadcast_sink_cleanup(sink); broadcast_sink_cleanup(sink);
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) { SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
if (listener->pa_sync_lost != NULL) { if (listener->pa_sync_lost != NULL) {
@ -332,13 +330,13 @@ static bool net_buf_decode_codec_ltv(struct net_buf_simple *buf,
void *value; void *value;
if (buf->len < sizeof(codec_data->data.data_len)) { if (buf->len < sizeof(codec_data->data.data_len)) {
BT_DBG("Not enough data for LTV length field: %u", buf->len); LOG_DBG("Not enough data for LTV length field: %u", buf->len);
return false; return false;
} }
codec_data->data.data_len = net_buf_simple_pull_u8(buf); codec_data->data.data_len = net_buf_simple_pull_u8(buf);
if (buf->len < sizeof(codec_data->data.type)) { if (buf->len < sizeof(codec_data->data.type)) {
BT_DBG("Not enough data for LTV type field: %u", buf->len); LOG_DBG("Not enough data for LTV type field: %u", buf->len);
return false; return false;
} }
@ -351,8 +349,8 @@ static bool net_buf_decode_codec_ltv(struct net_buf_simple *buf,
codec_data->data.data = codec_data->value; codec_data->data.data = codec_data->value;
if (buf->len < codec_data->data.data_len) { if (buf->len < codec_data->data.data_len) {
BT_DBG("Not enough data for LTV value field: %u/%zu", LOG_DBG("Not enough data for LTV value field: %u/%zu", buf->len,
buf->len, codec_data->data.data_len); codec_data->data.data_len);
return false; return false;
} }
value = net_buf_simple_pull_mem(buf, codec_data->data.data_len); value = net_buf_simple_pull_mem(buf, codec_data->data.data_len);
@ -367,20 +365,20 @@ static bool net_buf_decode_bis_data(struct net_buf_simple *buf,
uint8_t len; uint8_t len;
if (buf->len < BASE_BIS_DATA_MIN_SIZE) { if (buf->len < BASE_BIS_DATA_MIN_SIZE) {
BT_DBG("Not enough bytes (%u) to decode BIS data", buf->len); LOG_DBG("Not enough bytes (%u) to decode BIS data", buf->len);
return false; return false;
} }
bis->index = net_buf_simple_pull_u8(buf); bis->index = net_buf_simple_pull_u8(buf);
if (!IN_RANGE(bis->index, BT_ISO_BIS_INDEX_MIN, BT_ISO_BIS_INDEX_MAX)) { if (!IN_RANGE(bis->index, BT_ISO_BIS_INDEX_MIN, BT_ISO_BIS_INDEX_MAX)) {
BT_DBG("Invalid BIS index %u", bis->index); LOG_DBG("Invalid BIS index %u", bis->index);
return false; return false;
} }
/* codec config data length */ /* codec config data length */
len = net_buf_simple_pull_u8(buf); len = net_buf_simple_pull_u8(buf);
if (len > buf->len) { if (len > buf->len) {
BT_DBG("Invalid BIS specific codec config data length: " LOG_DBG("Invalid BIS specific codec config data length: "
"%u (buf is %u)", len, buf->len); "%u (buf is %u)", len, buf->len);
return false; return false;
} }
@ -402,8 +400,8 @@ static bool net_buf_decode_bis_data(struct net_buf_simple *buf,
if (!net_buf_decode_codec_ltv(&ltv_buf, if (!net_buf_decode_codec_ltv(&ltv_buf,
bis_codec_data)) { bis_codec_data)) {
BT_DBG("Failed to decode BIS config data for entry %u", LOG_DBG("Failed to decode BIS config data for entry %u",
bis->data_count); bis->data_count);
return false; return false;
} }
bis->data_count++; bis->data_count++;
@ -425,9 +423,8 @@ static bool net_buf_decode_subgroup(struct net_buf_simple *buf,
subgroup->bis_count = net_buf_simple_pull_u8(buf); subgroup->bis_count = net_buf_simple_pull_u8(buf);
if (subgroup->bis_count > ARRAY_SIZE(subgroup->bis_data)) { if (subgroup->bis_count > ARRAY_SIZE(subgroup->bis_data)) {
BT_DBG("BASE has more BIS %u than we support %u", LOG_DBG("BASE has more BIS %u than we support %u", subgroup->bis_count,
subgroup->bis_count, (uint8_t)ARRAY_SIZE(subgroup->bis_data));
(uint8_t)ARRAY_SIZE(subgroup->bis_data));
return false; return false;
} }
codec->id = net_buf_simple_pull_u8(buf); codec->id = net_buf_simple_pull_u8(buf);
@ -437,8 +434,7 @@ static bool net_buf_decode_subgroup(struct net_buf_simple *buf,
/* codec configuration data length */ /* codec configuration data length */
len = net_buf_simple_pull_u8(buf); len = net_buf_simple_pull_u8(buf);
if (len > buf->len) { if (len > buf->len) {
BT_DBG("Invalid codec config data length: %u (buf is %u)", LOG_DBG("Invalid codec config data length: %u (buf is %u)", len, buf->len);
len, buf->len);
return false; return false;
} }
@ -457,8 +453,8 @@ static bool net_buf_decode_subgroup(struct net_buf_simple *buf,
struct bt_codec_data *codec_data = &codec->data[codec->data_count++]; struct bt_codec_data *codec_data = &codec->data[codec->data_count++];
if (!net_buf_decode_codec_ltv(&ltv_buf, codec_data)) { if (!net_buf_decode_codec_ltv(&ltv_buf, codec_data)) {
BT_DBG("Failed to decode codec config data for entry %u", LOG_DBG("Failed to decode codec config data for entry %u",
codec->data_count - 1); codec->data_count - 1);
return false; return false;
} }
} }
@ -470,8 +466,7 @@ static bool net_buf_decode_subgroup(struct net_buf_simple *buf,
/* codec metadata length */ /* codec metadata length */
len = net_buf_simple_pull_u8(buf); len = net_buf_simple_pull_u8(buf);
if (len > buf->len) { if (len > buf->len) {
BT_DBG("Invalid codec config data length: %u (buf is %u)", LOG_DBG("Invalid codec config data length: %u (buf is %u)", len, buf->len);
len, buf->len);
return false; return false;
} }
@ -491,15 +486,15 @@ static bool net_buf_decode_subgroup(struct net_buf_simple *buf,
struct bt_codec_data *metadata = &codec->meta[codec->meta_count++]; struct bt_codec_data *metadata = &codec->meta[codec->meta_count++];
if (!net_buf_decode_codec_ltv(&ltv_buf, metadata)) { if (!net_buf_decode_codec_ltv(&ltv_buf, metadata)) {
BT_DBG("Failed to decode codec metadata for entry %u", LOG_DBG("Failed to decode codec metadata for entry %u",
codec->meta_count - 1); codec->meta_count - 1);
return false; return false;
} }
} }
for (int i = 0; i < subgroup->bis_count; i++) { for (int i = 0; i < subgroup->bis_count; i++) {
if (!net_buf_decode_bis_data(buf, &subgroup->bis_data[i])) { if (!net_buf_decode_bis_data(buf, &subgroup->bis_data[i])) {
BT_DBG("Failed to decode BIS data for bis %d", i); LOG_DBG("Failed to decode BIS data for bis %d", i);
return false; return false;
} }
} }
@ -536,7 +531,7 @@ static bool pa_decode_base(struct bt_data *data, void *user_data)
uuid = net_buf_simple_pull_mem(&net_buf, BT_UUID_SIZE_16); uuid = net_buf_simple_pull_mem(&net_buf, BT_UUID_SIZE_16);
if (!bt_uuid_create(&broadcast_uuid.uuid, uuid, BT_UUID_SIZE_16)) { if (!bt_uuid_create(&broadcast_uuid.uuid, uuid, BT_UUID_SIZE_16)) {
BT_ERR("bt_uuid_create failed"); LOG_ERR("bt_uuid_create failed");
return false; return false;
} }
@ -549,15 +544,15 @@ static bool pa_decode_base(struct bt_data *data, void *user_data)
base.subgroup_count = net_buf_simple_pull_u8(&net_buf); base.subgroup_count = net_buf_simple_pull_u8(&net_buf);
if (base.subgroup_count > ARRAY_SIZE(base.subgroups)) { if (base.subgroup_count > ARRAY_SIZE(base.subgroups)) {
BT_DBG("Cannot decode BASE with %u subgroups (max supported is %zu)", LOG_DBG("Cannot decode BASE with %u subgroups (max supported is %zu)",
base.subgroup_count, ARRAY_SIZE(base.subgroups)); base.subgroup_count, ARRAY_SIZE(base.subgroups));
return false; return false;
} }
for (int i = 0; i < base.subgroup_count; i++) { for (int i = 0; i < base.subgroup_count; i++) {
if (!net_buf_decode_subgroup(&net_buf, &base.subgroups[i])) { if (!net_buf_decode_subgroup(&net_buf, &base.subgroups[i])) {
BT_DBG("Failed to decode subgroup %d", i); LOG_DBG("Failed to decode subgroup %d", i);
return false; return false;
} }
} }
@ -570,7 +565,7 @@ static bool pa_decode_base(struct bt_data *data, void *user_data)
} }
if (num_bis > sink->biginfo_num_bis) { if (num_bis > sink->biginfo_num_bis) {
BT_WARN("BASE contains more BIS than reported by BIGInfo"); LOG_WRN("BASE contains more BIS than reported by BIGInfo");
return false; return false;
} }
} }
@ -684,10 +679,10 @@ static void sync_broadcast_pa(const struct bt_le_scan_recv_info *info,
param.timeout = interval_to_sync_timeout(info->interval); param.timeout = interval_to_sync_timeout(info->interval);
err = bt_le_per_adv_sync_create(&param, &sink->pa_sync); err = bt_le_per_adv_sync_create(&param, &sink->pa_sync);
if (err != 0) { if (err != 0) {
BT_ERR("Could not sync to PA: %d", err); LOG_ERR("Could not sync to PA: %d", err);
err = bt_le_scan_stop(); err = bt_le_scan_stop();
if (err != 0 && err != -EALREADY) { if (err != 0 && err != -EALREADY) {
BT_ERR("Could not stop scan: %d", err); LOG_ERR("Could not stop scan: %d", err);
} }
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) { SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
@ -764,8 +759,8 @@ static void broadcast_scan_recv(const struct bt_le_scan_recv_info *info,
* If it was then that means that we found a broadcast source * If it was then that means that we found a broadcast source
*/ */
if (broadcast_id != INVALID_BROADCAST_ID) { if (broadcast_id != INVALID_BROADCAST_ID) {
BT_DBG("Found broadcast source with address %s and id 0x%6X", LOG_DBG("Found broadcast source with address %s and id 0x%6X",
bt_addr_le_str(info->addr), broadcast_id); bt_addr_le_str(info->addr), broadcast_id);
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) { SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
if (listener->scan_recv != NULL) { if (listener->scan_recv != NULL) {
@ -814,7 +809,7 @@ int bt_audio_broadcast_sink_scan_start(const struct bt_le_scan_param *param)
int err; int err;
CHECKIF(param == NULL) { CHECKIF(param == NULL) {
BT_DBG("param is NULL"); LOG_DBG("param is NULL");
return -EINVAL; return -EINVAL;
} }
@ -822,17 +817,17 @@ int bt_audio_broadcast_sink_scan_start(const struct bt_le_scan_param *param)
/* This is to avoid having to re-implement the scan timeout /* This is to avoid having to re-implement the scan timeout
* callback as well, and can be modified later if requested * callback as well, and can be modified later if requested
*/ */
BT_DBG("Scan param shall not have a timeout"); LOG_DBG("Scan param shall not have a timeout");
return -EINVAL; return -EINVAL;
} }
if (sys_slist_is_empty(&sink_cbs)) { if (sys_slist_is_empty(&sink_cbs)) {
BT_WARN("No broadcast sink callbacks registered"); LOG_WRN("No broadcast sink callbacks registered");
return -EINVAL; return -EINVAL;
} }
if (broadcast_sink_free_get() == NULL) { if (broadcast_sink_free_get() == NULL) {
BT_DBG("No more free broadcast sinks"); LOG_DBG("No more free broadcast sinks");
return -ENOMEM; return -ENOMEM;
} }
@ -857,7 +852,7 @@ int bt_audio_broadcast_sink_scan_stop(void)
if (sink != NULL) { if (sink != NULL) {
err = bt_le_per_adv_sync_delete(sink->pa_sync); err = bt_le_per_adv_sync_delete(sink->pa_sync);
if (err != 0) { if (err != 0) {
BT_DBG("Could not delete PA sync: %d", err); LOG_DBG("Could not delete PA sync: %d", err);
return err; return err;
} }
sink->pa_sync = NULL; sink->pa_sync = NULL;
@ -891,7 +886,7 @@ bool bt_audio_ep_is_broadcast_snk(const struct bt_audio_ep *ep)
static void broadcast_sink_ep_init(struct bt_audio_ep *ep) static void broadcast_sink_ep_init(struct bt_audio_ep *ep)
{ {
BT_DBG("ep %p", ep); LOG_DBG("ep %p", ep);
(void)memset(ep, 0, sizeof(*ep)); (void)memset(ep, 0, sizeof(*ep));
ep->dir = BT_AUDIO_DIR_SINK; ep->dir = BT_AUDIO_DIR_SINK;
@ -922,19 +917,19 @@ static int bt_audio_broadcast_sink_setup_stream(uint8_t index,
struct bt_audio_ep *ep; struct bt_audio_ep *ep;
if (stream->group != NULL) { if (stream->group != NULL) {
BT_DBG("Stream %p already in group %p", stream, stream->group); LOG_DBG("Stream %p already in group %p", stream, stream->group);
return -EALREADY; return -EALREADY;
} }
ep = broadcast_sink_new_ep(index); ep = broadcast_sink_new_ep(index);
if (ep == NULL) { if (ep == NULL) {
BT_DBG("Could not allocate new broadcast endpoint"); LOG_DBG("Could not allocate new broadcast endpoint");
return -ENOMEM; return -ENOMEM;
} }
iso = bt_audio_iso_new(); iso = bt_audio_iso_new();
if (iso == NULL) { if (iso == NULL) {
BT_DBG("Could not allocate iso"); LOG_DBG("Could not allocate iso");
return -ENOMEM; return -ENOMEM;
} }
@ -1019,27 +1014,27 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
int err; int err;
CHECKIF(sink == NULL) { CHECKIF(sink == NULL) {
BT_DBG("sink is NULL"); LOG_DBG("sink is NULL");
return -EINVAL; return -EINVAL;
} }
CHECKIF(indexes_bitfield == 0) { CHECKIF(indexes_bitfield == 0) {
BT_DBG("indexes_bitfield is 0"); LOG_DBG("indexes_bitfield is 0");
return -EINVAL; return -EINVAL;
} }
CHECKIF(indexes_bitfield & BIT(0)) { CHECKIF(indexes_bitfield & BIT(0)) {
BT_DBG("BIT(0) is not a valid BIS index"); LOG_DBG("BIT(0) is not a valid BIS index");
return -EINVAL; return -EINVAL;
} }
CHECKIF(streams == NULL) { CHECKIF(streams == NULL) {
BT_DBG("streams is NULL"); LOG_DBG("streams is NULL");
return -EINVAL; return -EINVAL;
} }
if (sink->pa_sync == NULL) { if (sink->pa_sync == NULL) {
BT_DBG("Sink is not PA synced"); LOG_DBG("Sink is not PA synced");
return -EINVAL; return -EINVAL;
} }
@ -1048,12 +1043,12 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
* once the BIGInfo has been received, and then do the sync * once the BIGInfo has been received, and then do the sync
* then. This would be similar how LE Create Connection works. * then. This would be similar how LE Create Connection works.
*/ */
BT_DBG("BIGInfo not received, cannot sync yet"); LOG_DBG("BIGInfo not received, cannot sync yet");
return -EAGAIN; return -EAGAIN;
} }
CHECKIF(sink->big_encrypted && broadcast_code == NULL) { CHECKIF(sink->big_encrypted && broadcast_code == NULL) {
BT_DBG("Broadcast code required"); LOG_DBG("Broadcast code required");
return -EINVAL; return -EINVAL;
} }
@ -1065,7 +1060,7 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
struct codec_lookup_id_data lookup_data = { }; struct codec_lookup_id_data lookup_data = { };
if (codec == NULL) { if (codec == NULL) {
BT_DBG("Index %d not found in BASE", i); LOG_DBG("Index %d not found in BASE", i);
return -EINVAL; return -EINVAL;
} }
@ -1075,7 +1070,7 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
bt_pacs_cap_foreach(BT_AUDIO_DIR_SINK, codec_lookup_id, bt_pacs_cap_foreach(BT_AUDIO_DIR_SINK, codec_lookup_id,
&lookup_data); &lookup_data);
if (lookup_data.codec == NULL) { if (lookup_data.codec == NULL) {
BT_DBG("Codec with id %u is not supported by our capabilities", LOG_DBG("Codec with id %u is not supported by our capabilities",
codec->id); codec->id);
return -ENOENT; return -ENOENT;
@ -1086,8 +1081,8 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
codecs[stream_count++] = codec; codecs[stream_count++] = codec;
if (stream_count > BROADCAST_SNK_STREAM_CNT) { if (stream_count > BROADCAST_SNK_STREAM_CNT) {
BT_DBG("Cannot sync to more than %d streams", LOG_DBG("Cannot sync to more than %d streams",
BROADCAST_SNK_STREAM_CNT); BROADCAST_SNK_STREAM_CNT);
return -EINVAL; return -EINVAL;
} }
} }
@ -1095,7 +1090,7 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
for (size_t i = 0; i < stream_count; i++) { for (size_t i = 0; i < stream_count; i++) {
CHECKIF(streams[i] == NULL) { CHECKIF(streams[i] == NULL) {
BT_DBG("streams[%zu] is NULL", i); LOG_DBG("streams[%zu] is NULL", i);
return -EINVAL; return -EINVAL;
} }
} }
@ -1111,7 +1106,7 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
err = bt_audio_broadcast_sink_setup_stream(sink->index, stream, err = bt_audio_broadcast_sink_setup_stream(sink->index, stream,
codec); codec);
if (err != 0) { if (err != 0) {
BT_DBG("Failed to setup streams[%zu]: %d", i, err); LOG_DBG("Failed to setup streams[%zu]: %d", i, err);
broadcast_sink_cleanup_streams(sink); broadcast_sink_cleanup_streams(sink);
return err; return err;
} }
@ -1157,12 +1152,12 @@ int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink)
int err; int err;
CHECKIF(sink == NULL) { CHECKIF(sink == NULL) {
BT_DBG("sink is NULL"); LOG_DBG("sink is NULL");
return -EINVAL; return -EINVAL;
} }
if (sys_slist_is_empty(&sink->streams)) { if (sys_slist_is_empty(&sink->streams)) {
BT_DBG("Source does not have any streams"); LOG_DBG("Source does not have any streams");
return -EINVAL; return -EINVAL;
} }
@ -1173,20 +1168,20 @@ int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink)
* so we can just check the first stream * so we can just check the first stream
*/ */
if (stream->ep == NULL) { if (stream->ep == NULL) {
BT_DBG("stream->ep is NULL"); LOG_DBG("stream->ep is NULL");
return -EINVAL; return -EINVAL;
} }
if (stream->ep->status.state != BT_AUDIO_EP_STATE_STREAMING && if (stream->ep->status.state != BT_AUDIO_EP_STATE_STREAMING &&
stream->ep->status.state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) { stream->ep->status.state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) {
BT_DBG("Broadcast sink stream %p invalid state: %u", LOG_DBG("Broadcast sink stream %p invalid state: %u", stream,
stream, stream->ep->status.state); stream->ep->status.state);
return -EBADMSG; return -EBADMSG;
} }
err = bt_iso_big_terminate(sink->big); err = bt_iso_big_terminate(sink->big);
if (err) { if (err) {
BT_DBG("Failed to terminate BIG (err %d)", err); LOG_DBG("Failed to terminate BIG (err %d)", err);
return err; return err;
} }
@ -1201,7 +1196,7 @@ int bt_audio_broadcast_sink_delete(struct bt_audio_broadcast_sink *sink)
int err; int err;
CHECKIF(sink == NULL) { CHECKIF(sink == NULL) {
BT_DBG("sink is NULL"); LOG_DBG("sink is NULL");
return -EINVAL; return -EINVAL;
} }
@ -1216,20 +1211,19 @@ int bt_audio_broadcast_sink_delete(struct bt_audio_broadcast_sink *sink)
* so we can just check the first stream * so we can just check the first stream
*/ */
if (stream->ep != NULL) { if (stream->ep != NULL) {
BT_DBG("Sink is not stopped"); LOG_DBG("Sink is not stopped");
return -EBADMSG; return -EBADMSG;
} }
} }
if (sink->pa_sync == NULL) { if (sink->pa_sync == NULL) {
BT_DBG("Broadcast sink is already deleted"); LOG_DBG("Broadcast sink is already deleted");
return -EALREADY; return -EALREADY;
} }
err = bt_le_per_adv_sync_delete(sink->pa_sync); err = bt_le_per_adv_sync_delete(sink->pa_sync);
if (err != 0) { if (err != 0) {
BT_DBG("Failed to delete periodic advertising sync (err %d)", LOG_DBG("Failed to delete periodic advertising sync (err %d)", err);
err);
return err; return err;
} }

View file

@ -15,9 +15,8 @@
#include <zephyr/bluetooth/gatt.h> #include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/audio/audio.h> #include <zephyr/bluetooth/audio/audio.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_BROADCAST_SOURCE) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_audio_broadcast_source LOG_MODULE_REGISTER(bt_audio_broadcast_source, CONFIG_BT_AUDIO_BROADCAST_SOURCE_LOG_LEVEL);
#include "common/log.h"
#include "audio_iso.h" #include "audio_iso.h"
#include "endpoint.h" #include "endpoint.h"
@ -68,39 +67,37 @@ static void broadcast_source_set_ep_state(struct bt_audio_ep *ep, uint8_t state)
old_state = ep->status.state; old_state = ep->status.state;
BT_DBG("ep %p id 0x%02x %s -> %s", ep, ep->status.id, LOG_DBG("ep %p id 0x%02x %s -> %s", ep, ep->status.id, bt_audio_ep_state_str(old_state),
bt_audio_ep_state_str(old_state), bt_audio_ep_state_str(state));
bt_audio_ep_state_str(state));
switch (old_state) { switch (old_state) {
case BT_AUDIO_EP_STATE_IDLE: case BT_AUDIO_EP_STATE_IDLE:
if (state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) { if (state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) {
BT_DBG("Invalid broadcast sync endpoint state transition"); LOG_DBG("Invalid broadcast sync endpoint state transition");
return; return;
} }
break; break;
case BT_AUDIO_EP_STATE_QOS_CONFIGURED: case BT_AUDIO_EP_STATE_QOS_CONFIGURED:
if (state != BT_AUDIO_EP_STATE_IDLE && if (state != BT_AUDIO_EP_STATE_IDLE &&
state != BT_AUDIO_EP_STATE_ENABLING) { state != BT_AUDIO_EP_STATE_ENABLING) {
BT_DBG("Invalid broadcast sync endpoint state transition"); LOG_DBG("Invalid broadcast sync endpoint state transition");
return; return;
} }
break; break;
case BT_AUDIO_EP_STATE_ENABLING: case BT_AUDIO_EP_STATE_ENABLING:
if (state != BT_AUDIO_EP_STATE_STREAMING) { if (state != BT_AUDIO_EP_STATE_STREAMING) {
BT_DBG("Invalid broadcast sync endpoint state transition"); LOG_DBG("Invalid broadcast sync endpoint state transition");
return; return;
} }
break; break;
case BT_AUDIO_EP_STATE_STREAMING: case BT_AUDIO_EP_STATE_STREAMING:
if (state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) { if (state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) {
BT_DBG("Invalid broadcast sync endpoint state transition"); LOG_DBG("Invalid broadcast sync endpoint state transition");
return; return;
} }
break; break;
default: default:
BT_ERR("Invalid broadcast sync endpoint state: %s", LOG_ERR("Invalid broadcast sync endpoint state: %s",
bt_audio_ep_state_str(old_state)); bt_audio_ep_state_str(old_state));
return; return;
} }
@ -126,20 +123,20 @@ static void broadcast_source_iso_sent(struct bt_iso_chan *chan)
struct bt_audio_ep *ep = iso->tx.ep; struct bt_audio_ep *ep = iso->tx.ep;
if (ep == NULL) { if (ep == NULL) {
BT_ERR("iso %p not bound with ep", chan); LOG_ERR("iso %p not bound with ep", chan);
return; return;
} }
stream = ep->stream; stream = ep->stream;
if (stream == NULL) { if (stream == NULL) {
BT_ERR("No stream for ep %p", ep); LOG_ERR("No stream for ep %p", ep);
return; return;
} }
ops = stream->ops; ops = stream->ops;
if (IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_STREAM_DATA)) { if (IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_STREAM_DATA)) {
BT_DBG("stream %p ep %p", stream, stream->ep); LOG_DBG("stream %p ep %p", stream, stream->ep);
} }
if (ops != NULL && ops->sent != NULL) { if (ops != NULL && ops->sent != NULL) {
@ -155,26 +152,26 @@ static void broadcast_source_iso_connected(struct bt_iso_chan *chan)
struct bt_audio_ep *ep = iso->tx.ep; struct bt_audio_ep *ep = iso->tx.ep;
if (ep == NULL) { if (ep == NULL) {
BT_ERR("iso %p not bound with ep", chan); LOG_ERR("iso %p not bound with ep", chan);
return; return;
} }
stream = ep->stream; stream = ep->stream;
if (stream == NULL) { if (stream == NULL) {
BT_ERR("No stream for ep %p", ep); LOG_ERR("No stream for ep %p", ep);
return; return;
} }
ops = stream->ops; ops = stream->ops;
BT_DBG("stream %p ep %p", stream, ep); LOG_DBG("stream %p ep %p", stream, ep);
broadcast_source_set_ep_state(ep, BT_AUDIO_EP_STATE_STREAMING); broadcast_source_set_ep_state(ep, BT_AUDIO_EP_STATE_STREAMING);
if (ops != NULL && ops->started != NULL) { if (ops != NULL && ops->started != NULL) {
ops->started(stream); ops->started(stream);
} else { } else {
BT_WARN("No callback for connected set"); LOG_WRN("No callback for connected set");
} }
} }
@ -186,26 +183,26 @@ static void broadcast_source_iso_disconnected(struct bt_iso_chan *chan, uint8_t
struct bt_audio_ep *ep = iso->tx.ep; struct bt_audio_ep *ep = iso->tx.ep;
if (ep == NULL) { if (ep == NULL) {
BT_ERR("iso %p not bound with ep", chan); LOG_ERR("iso %p not bound with ep", chan);
return; return;
} }
stream = ep->stream; stream = ep->stream;
if (stream == NULL) { if (stream == NULL) {
BT_ERR("No stream for ep %p", ep); LOG_ERR("No stream for ep %p", ep);
return; return;
} }
ops = stream->ops; ops = stream->ops;
BT_DBG("stream %p ep %p reason 0x%02x", stream, stream->ep, reason); LOG_DBG("stream %p ep %p reason 0x%02x", stream, stream->ep, reason);
broadcast_source_set_ep_state(ep, BT_AUDIO_EP_STATE_QOS_CONFIGURED); broadcast_source_set_ep_state(ep, BT_AUDIO_EP_STATE_QOS_CONFIGURED);
if (ops != NULL && ops->stopped != NULL) { if (ops != NULL && ops->stopped != NULL) {
ops->stopped(stream); ops->stopped(stream);
} else { } else {
BT_WARN("No callback for stopped set"); LOG_WRN("No callback for stopped set");
} }
} }
@ -228,7 +225,7 @@ bool bt_audio_ep_is_broadcast_src(const struct bt_audio_ep *ep)
static void broadcast_source_ep_init(struct bt_audio_ep *ep) static void broadcast_source_ep_init(struct bt_audio_ep *ep)
{ {
BT_DBG("ep %p", ep); LOG_DBG("ep %p", ep);
(void)memset(ep, 0, sizeof(*ep)); (void)memset(ep, 0, sizeof(*ep));
ep->dir = BT_AUDIO_DIR_SOURCE; ep->dir = BT_AUDIO_DIR_SOURCE;
@ -275,13 +272,13 @@ static int broadcast_source_setup_stream(uint8_t index,
ep = broadcast_source_new_ep(index); ep = broadcast_source_new_ep(index);
if (ep == NULL) { if (ep == NULL) {
BT_DBG("Could not allocate new broadcast endpoint"); LOG_DBG("Could not allocate new broadcast endpoint");
return -ENOMEM; return -ENOMEM;
} }
iso = bt_audio_iso_new(); iso = bt_audio_iso_new();
if (iso == NULL) { if (iso == NULL) {
BT_DBG("Could not allocate iso"); LOG_DBG("Could not allocate iso");
return -ENOMEM; return -ENOMEM;
} }
@ -334,8 +331,7 @@ static bool encode_base_subgroup(struct bt_audio_broadcast_subgroup *subgroup,
if ((buf->size - buf->len) < (sizeof(codec_data->data_len) + if ((buf->size - buf->len) < (sizeof(codec_data->data_len) +
sizeof(codec_data->type) + sizeof(codec_data->type) +
codec_data->data_len)) { codec_data->data_len)) {
BT_DBG("No room for codec[%d] with len %u", LOG_DBG("No room for codec[%d] with len %u", i, codec_data->data_len);
i, codec_data->data_len);
return false; return false;
} }
@ -351,7 +347,7 @@ static bool encode_base_subgroup(struct bt_audio_broadcast_subgroup *subgroup,
*start = len; *start = len;
if ((buf->size - buf->len) < sizeof(len)) { if ((buf->size - buf->len) < sizeof(len)) {
BT_DBG("No room for metadata length"); LOG_DBG("No room for metadata length");
return false; return false;
} }
@ -364,8 +360,7 @@ static bool encode_base_subgroup(struct bt_audio_broadcast_subgroup *subgroup,
if ((buf->size - buf->len) < (sizeof(metadata->data_len) + if ((buf->size - buf->len) < (sizeof(metadata->data_len) +
sizeof(metadata->type) + sizeof(metadata->type) +
metadata->data_len)) { metadata->data_len)) {
BT_DBG("No room for metadata[%d] with len %u", LOG_DBG("No room for metadata[%d] with len %u", i, metadata->data_len);
i, metadata->data_len);
return false; return false;
} }
@ -384,7 +379,7 @@ static bool encode_base_subgroup(struct bt_audio_broadcast_subgroup *subgroup,
for (int i = 0; i < stream_count; i++) { for (int i = 0; i < stream_count; i++) {
bis_index++; bis_index++;
if ((buf->size - buf->len) < (sizeof(bis_index) + sizeof(uint8_t))) { if ((buf->size - buf->len) < (sizeof(bis_index) + sizeof(uint8_t))) {
BT_DBG("No room for BIS[%d] index", i); LOG_DBG("No room for BIS[%d] index", i);
return false; return false;
} }
@ -392,7 +387,7 @@ static bool encode_base_subgroup(struct bt_audio_broadcast_subgroup *subgroup,
net_buf_simple_add_u8(buf, bis_index); net_buf_simple_add_u8(buf, bis_index);
if ((buf->size - buf->len) < sizeof(len)) { if ((buf->size - buf->len) < sizeof(len)) {
BT_DBG("No room for bis codec config length"); LOG_DBG("No room for bis codec config length");
return false; return false;
} }
@ -407,8 +402,8 @@ static bool encode_base_subgroup(struct bt_audio_broadcast_subgroup *subgroup,
if ((buf->size - buf->len) < (sizeof(codec_data->data_len) + if ((buf->size - buf->len) < (sizeof(codec_data->data_len) +
sizeof(codec_data->type) + sizeof(codec_data->type) +
codec_data->data_len)) { codec_data->data_len)) {
BT_DBG("No room for BIS [%u] codec[%zu] with len %u", LOG_DBG("No room for BIS [%u] codec[%zu] with len %u", bis_index, j,
bis_index, j, codec_data->data_len); codec_data->data_len);
return false; return false;
} }
@ -528,23 +523,23 @@ static bool valid_create_param(const struct bt_audio_broadcast_source_create_par
const struct bt_codec_qos *qos; const struct bt_codec_qos *qos;
CHECKIF(param == NULL) { CHECKIF(param == NULL) {
BT_DBG("param is NULL"); LOG_DBG("param is NULL");
return false; return false;
} }
CHECKIF(param->params_count == 0U) { CHECKIF(param->params_count == 0U) {
BT_DBG("param->params_count is 0"); LOG_DBG("param->params_count is 0");
return false; return false;
} }
qos = param->qos; qos = param->qos;
CHECKIF(qos == NULL) { CHECKIF(qos == NULL) {
BT_DBG("param->qos is NULL"); LOG_DBG("param->qos is NULL");
return false; return false;
} }
CHECKIF(!bt_audio_valid_qos(qos)) { CHECKIF(!bt_audio_valid_qos(qos)) {
BT_DBG("param->qos is invalid"); LOG_DBG("param->qos is invalid");
return false; return false;
} }
@ -554,12 +549,12 @@ static bool valid_create_param(const struct bt_audio_broadcast_source_create_par
subgroup_param = &param->params[i]; subgroup_param = &param->params[i];
CHECKIF(subgroup_param->params_count == 0U) { CHECKIF(subgroup_param->params_count == 0U) {
BT_DBG("subgroup_params[%zu].count is 0", i); LOG_DBG("subgroup_params[%zu].count is 0", i);
return false; return false;
} }
CHECKIF(subgroup_param->codec == NULL) { CHECKIF(subgroup_param->codec == NULL) {
BT_DBG("subgroup_params[%zu].codec is NULL", i); LOG_DBG("subgroup_params[%zu].codec is NULL", i);
return false; return false;
} }
@ -569,15 +564,15 @@ static bool valid_create_param(const struct bt_audio_broadcast_source_create_par
stream_param = &subgroup_param->params[j]; stream_param = &subgroup_param->params[j];
CHECKIF(stream_param->stream == NULL) { CHECKIF(stream_param->stream == NULL) {
BT_DBG("subgroup_params[%zu].stream_params[%zu]->stream is NULL", LOG_DBG("subgroup_params[%zu].stream_params[%zu]->stream is NULL",
i, j); i, j);
return false; return false;
} }
CHECKIF(stream_param->stream->group != NULL) { CHECKIF(stream_param->stream->group != NULL) {
BT_DBG("subgroup_params[%zu].stream_params[%zu]->stream is " LOG_DBG("subgroup_params[%zu].stream_params[%zu]->stream is "
"already part of group %p", "already part of group %p",
i, j, stream_param->stream->group); i, j, stream_param->stream->group);
return false; return false;
} }
} }
@ -593,12 +588,12 @@ static enum bt_audio_state broadcast_source_get_state(struct bt_audio_broadcast_
sys_snode_t *head_node; sys_snode_t *head_node;
if (source == NULL) { if (source == NULL) {
BT_DBG("source is NULL"); LOG_DBG("source is NULL");
return BT_AUDIO_EP_STATE_IDLE; return BT_AUDIO_EP_STATE_IDLE;
} }
if (sys_slist_is_empty(&source->subgroups)) { if (sys_slist_is_empty(&source->subgroups)) {
BT_DBG("Source does not have any streams"); LOG_DBG("Source does not have any streams");
return BT_AUDIO_EP_STATE_IDLE; return BT_AUDIO_EP_STATE_IDLE;
} }
@ -613,7 +608,7 @@ static enum bt_audio_state broadcast_source_get_state(struct bt_audio_broadcast_
* so we can just check the first stream * so we can just check the first stream
*/ */
if (stream->ep == NULL) { if (stream->ep == NULL) {
BT_DBG("stream->ep is NULL"); LOG_DBG("stream->ep is NULL");
return BT_AUDIO_EP_STATE_IDLE; return BT_AUDIO_EP_STATE_IDLE;
} }
@ -631,14 +626,14 @@ int bt_audio_broadcast_source_create(struct bt_audio_broadcast_source_create_par
int err; int err;
CHECKIF(out_source == NULL) { CHECKIF(out_source == NULL) {
BT_DBG("out_source is NULL"); LOG_DBG("out_source is NULL");
return -EINVAL; return -EINVAL;
} }
/* Set out_source to NULL until the source has actually been created */ /* Set out_source to NULL until the source has actually been created */
*out_source = NULL; *out_source = NULL;
if (!valid_create_param(param)) { if (!valid_create_param(param)) {
BT_DBG("Invalid parameters"); LOG_DBG("Invalid parameters");
return -EINVAL; return -EINVAL;
} }
@ -651,7 +646,7 @@ int bt_audio_broadcast_source_create(struct bt_audio_broadcast_source_create_par
} }
if (source == NULL) { if (source == NULL) {
BT_DBG("Could not allocate any more broadcast sources"); LOG_DBG("Could not allocate any more broadcast sources");
return -ENOMEM; return -ENOMEM;
} }
@ -668,7 +663,7 @@ int bt_audio_broadcast_source_create(struct bt_audio_broadcast_source_create_par
subgroup = broadcast_source_new_subgroup(index); subgroup = broadcast_source_new_subgroup(index);
if (subgroup == NULL) { if (subgroup == NULL) {
BT_DBG("Could not allocate new broadcast subgroup"); LOG_DBG("Could not allocate new broadcast subgroup");
broadcast_source_cleanup(source); broadcast_source_cleanup(source);
return -ENOMEM; return -ENOMEM;
} }
@ -678,8 +673,7 @@ int bt_audio_broadcast_source_create(struct bt_audio_broadcast_source_create_par
/* Check that we are not above the maximum BIS count */ /* Check that we are not above the maximum BIS count */
if (subgroup_param->params_count + stream_count > BROADCAST_STREAM_CNT) { if (subgroup_param->params_count + stream_count > BROADCAST_STREAM_CNT) {
BT_DBG("Cannot create broadcaster with %zu streams", LOG_DBG("Cannot create broadcaster with %zu streams", stream_count);
stream_count);
broadcast_source_cleanup(source); broadcast_source_cleanup(source);
return -ENOMEM; return -ENOMEM;
@ -696,7 +690,7 @@ int bt_audio_broadcast_source_create(struct bt_audio_broadcast_source_create_par
subgroup_param->codec, subgroup_param->codec,
qos, source); qos, source);
if (err != 0) { if (err != 0) {
BT_DBG("Failed to setup streams[%zu]: %d", i, err); LOG_DBG("Failed to setup streams[%zu]: %d", i, err);
broadcast_source_cleanup(source); broadcast_source_cleanup(source);
return err; return err;
} }
@ -719,7 +713,7 @@ int bt_audio_broadcast_source_create(struct bt_audio_broadcast_source_create_par
err = generate_broadcast_id(source); err = generate_broadcast_id(source);
if (err != 0) { if (err != 0) {
BT_DBG("Could not generate broadcast id: %d", err); LOG_DBG("Could not generate broadcast id: %d", err);
return err; return err;
} }
@ -734,7 +728,7 @@ int bt_audio_broadcast_source_create(struct bt_audio_broadcast_source_create_par
} }
source->qos = qos; source->qos = qos;
BT_DBG("Broadcasting with ID 0x%6X", source->broadcast_id); LOG_DBG("Broadcasting with ID 0x%6X", source->broadcast_id);
*out_source = source; *out_source = source;
@ -750,14 +744,13 @@ int bt_audio_broadcast_source_reconfig(struct bt_audio_broadcast_source *source,
struct bt_audio_stream *stream; struct bt_audio_stream *stream;
CHECKIF(source == NULL) { CHECKIF(source == NULL) {
BT_DBG("source is NULL"); LOG_DBG("source is NULL");
return -EINVAL; return -EINVAL;
} }
broadcast_state = broadcast_source_get_state(source); broadcast_state = broadcast_source_get_state(source);
if (broadcast_source_get_state(source) != BT_AUDIO_EP_STATE_QOS_CONFIGURED) { if (broadcast_source_get_state(source) != BT_AUDIO_EP_STATE_QOS_CONFIGURED) {
BT_DBG("Broadcast source invalid state: %u", LOG_DBG("Broadcast source invalid state: %u", broadcast_state);
broadcast_state);
return -EBADMSG; return -EBADMSG;
} }
@ -784,13 +777,13 @@ int bt_audio_broadcast_source_start(struct bt_audio_broadcast_source *source,
int err; int err;
CHECKIF(source == NULL) { CHECKIF(source == NULL) {
BT_DBG("source is NULL"); LOG_DBG("source is NULL");
return -EINVAL; return -EINVAL;
} }
broadcast_state = broadcast_source_get_state(source); broadcast_state = broadcast_source_get_state(source);
if (broadcast_source_get_state(source) != BT_AUDIO_EP_STATE_QOS_CONFIGURED) { if (broadcast_source_get_state(source) != BT_AUDIO_EP_STATE_QOS_CONFIGURED) {
BT_DBG("Broadcast source invalid state: %u", broadcast_state); LOG_DBG("Broadcast source invalid state: %u", broadcast_state);
return -EBADMSG; return -EBADMSG;
} }
@ -811,7 +804,7 @@ int bt_audio_broadcast_source_start(struct bt_audio_broadcast_source *source,
err = bt_iso_big_create(adv, &param, &source->big); err = bt_iso_big_create(adv, &param, &source->big);
if (err != 0) { if (err != 0) {
BT_DBG("Failed to create BIG: %d", err); LOG_DBG("Failed to create BIG: %d", err);
return err; return err;
} }
@ -832,25 +825,25 @@ int bt_audio_broadcast_source_stop(struct bt_audio_broadcast_source *source)
int err; int err;
CHECKIF(source == NULL) { CHECKIF(source == NULL) {
BT_DBG("source is NULL"); LOG_DBG("source is NULL");
return -EINVAL; return -EINVAL;
} }
broadcast_state = broadcast_source_get_state(source); broadcast_state = broadcast_source_get_state(source);
if (broadcast_state != BT_AUDIO_EP_STATE_STREAMING && if (broadcast_state != BT_AUDIO_EP_STATE_STREAMING &&
broadcast_state != BT_AUDIO_EP_STATE_ENABLING) { broadcast_state != BT_AUDIO_EP_STATE_ENABLING) {
BT_DBG("Broadcast source invalid state: %u", broadcast_state); LOG_DBG("Broadcast source invalid state: %u", broadcast_state);
return -EBADMSG; return -EBADMSG;
} }
if (source->big == NULL) { if (source->big == NULL) {
BT_DBG("Source is not started"); LOG_DBG("Source is not started");
return -EALREADY; return -EALREADY;
} }
err = bt_iso_big_terminate(source->big); err = bt_iso_big_terminate(source->big);
if (err) { if (err) {
BT_DBG("Failed to terminate BIG (err %d)", err); LOG_DBG("Failed to terminate BIG (err %d)", err);
return err; return err;
} }
@ -864,13 +857,13 @@ int bt_audio_broadcast_source_delete(struct bt_audio_broadcast_source *source)
enum bt_audio_state broadcast_state; enum bt_audio_state broadcast_state;
CHECKIF(source == NULL) { CHECKIF(source == NULL) {
BT_DBG("source is NULL"); LOG_DBG("source is NULL");
return -EINVAL; return -EINVAL;
} }
broadcast_state = broadcast_source_get_state(source); broadcast_state = broadcast_source_get_state(source);
if (broadcast_state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) { if (broadcast_state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) {
BT_DBG("Broadcast source invalid state: %u", broadcast_state); LOG_DBG("Broadcast source invalid state: %u", broadcast_state);
return -EBADMSG; return -EBADMSG;
} }
@ -884,12 +877,12 @@ int bt_audio_broadcast_source_get_id(const struct bt_audio_broadcast_source *sou
uint32_t *const broadcast_id) uint32_t *const broadcast_id)
{ {
CHECKIF(source == NULL) { CHECKIF(source == NULL) {
BT_DBG("source is NULL"); LOG_DBG("source is NULL");
return -EINVAL; return -EINVAL;
} }
CHECKIF(broadcast_id == NULL) { CHECKIF(broadcast_id == NULL) {
BT_DBG("broadcast_id is NULL"); LOG_DBG("broadcast_id is NULL");
return -EINVAL; return -EINVAL;
} }
@ -902,8 +895,7 @@ int bt_audio_broadcast_source_get_base(struct bt_audio_broadcast_source *source,
struct net_buf_simple *base_buf) struct net_buf_simple *base_buf)
{ {
if (!encode_base(source, base_buf)) { if (!encode_base(source, base_buf)) {
BT_DBG("base_buf %p with size %u not large enough", LOG_DBG("base_buf %p with size %u not large enough", base_buf, base_buf->size);
base_buf, base_buf->size);
return -EMSGSIZE; return -EMSGSIZE;
} }

View file

@ -10,9 +10,9 @@
#include <zephyr/bluetooth/audio/csip.h> #include <zephyr/bluetooth/audio/csip.h>
#include "cap_internal.h" #include "cap_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_CAP_ACCEPTOR) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_cap_acceptor
#include "common/log.h" LOG_MODULE_REGISTER(bt_cap_acceptor, LOG_LEVEL_DBG);
#if defined(CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER) #if defined(CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER)
@ -29,7 +29,7 @@ int bt_cap_acceptor_register(const struct bt_csip_set_member_register_param *par
err = bt_csip_set_member_register(param, svc_inst); err = bt_csip_set_member_register(param, svc_inst);
if (err != 0) { if (err != 0) {
BT_DBG("Failed to register CSIP"); LOG_DBG("Failed to register CSIP");
return err; return err;
} }
@ -40,7 +40,7 @@ int bt_cap_acceptor_register(const struct bt_csip_set_member_register_param *par
err = bt_gatt_service_register(&cas); err = bt_gatt_service_register(&cas);
if (err) { if (err) {
BT_DBG("Failed to register CAS"); LOG_DBG("Failed to register CAS");
return err; return err;
} }

View file

@ -11,21 +11,21 @@
#include "cap_internal.h" #include "cap_internal.h"
#include "csip_internal.h" #include "csip_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_CAP_INITIATOR) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_cap_initiator
#include "common/log.h" LOG_MODULE_REGISTER(bt_cap_initiator, LOG_LEVEL_DBG);
static const struct bt_cap_initiator_cb *cap_cb; static const struct bt_cap_initiator_cb *cap_cb;
int bt_cap_initiator_register_cb(const struct bt_cap_initiator_cb *cb) int bt_cap_initiator_register_cb(const struct bt_cap_initiator_cb *cb)
{ {
CHECKIF(cb == NULL) { CHECKIF(cb == NULL) {
BT_DBG("cb is NULL"); LOG_DBG("cb is NULL");
return -EINVAL; return -EINVAL;
} }
CHECKIF(cap_cb != NULL) { CHECKIF(cap_cb != NULL) {
BT_DBG("callbacks already registered"); LOG_DBG("callbacks already registered");
return -EALREADY; return -EALREADY;
} }
@ -74,7 +74,7 @@ static void csis_client_discover_cb(struct bt_conn *conn,
struct cap_unicast_client *client; struct cap_unicast_client *client;
if (err != 0) { if (err != 0) {
BT_DBG("CSIS client discover failed: %d", err); LOG_DBG("CSIS client discover failed: %d", err);
if (cap_cb && cap_cb->unicast_discovery_complete) { if (cap_cb && cap_cb->unicast_discovery_complete) {
cap_cb->unicast_discovery_complete(conn, err, NULL); cap_cb->unicast_discovery_complete(conn, err, NULL);
@ -88,14 +88,14 @@ static void csis_client_discover_cb(struct bt_conn *conn,
conn, client->csis_start_handle); conn, client->csis_start_handle);
if (member == NULL || set_count == 0 || client->csis_inst == NULL) { if (member == NULL || set_count == 0 || client->csis_inst == NULL) {
BT_ERR("Unable to find CSIS for CAS"); LOG_ERR("Unable to find CSIS for CAS");
if (cap_cb && cap_cb->unicast_discovery_complete) { if (cap_cb && cap_cb->unicast_discovery_complete) {
cap_cb->unicast_discovery_complete(conn, -ENODATA, cap_cb->unicast_discovery_complete(conn, -ENODATA,
NULL); NULL);
} }
} else { } else {
BT_DBG("Found CAS with CSIS"); LOG_DBG("Found CAS with CSIS");
if (cap_cb && cap_cb->unicast_discovery_complete) { if (cap_cb && cap_cb->unicast_discovery_complete) {
cap_cb->unicast_discovery_complete(conn, 0, cap_cb->unicast_discovery_complete(conn, 0,
client->csis_inst); client->csis_inst);
@ -110,7 +110,7 @@ static uint8_t cap_unicast_discover_included_cb(struct bt_conn *conn,
params->func = NULL; params->func = NULL;
if (attr == NULL) { if (attr == NULL) {
BT_DBG("CAS CSIS include not found"); LOG_DBG("CAS CSIS include not found");
if (cap_cb && cap_cb->unicast_discovery_complete) { if (cap_cb && cap_cb->unicast_discovery_complete) {
cap_cb->unicast_discovery_complete(conn, 0, NULL); cap_cb->unicast_discovery_complete(conn, 0, NULL);
@ -137,7 +137,7 @@ static uint8_t cap_unicast_discover_included_cb(struct bt_conn *conn,
static bool csis_cbs_registered; static bool csis_cbs_registered;
int err; int err;
BT_DBG("CAS CSIS not known, discovering"); LOG_DBG("CAS CSIS not known, discovering");
if (!csis_cbs_registered) { if (!csis_cbs_registered) {
bt_csip_set_coordinator_register_cb(&csis_client_cb); bt_csip_set_coordinator_register_cb(&csis_client_cb);
@ -146,7 +146,7 @@ static uint8_t cap_unicast_discover_included_cb(struct bt_conn *conn,
err = bt_csip_set_coordinator_discover(conn); err = bt_csip_set_coordinator_discover(conn);
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
if (cap_cb && cap_cb->unicast_discovery_complete) { if (cap_cb && cap_cb->unicast_discovery_complete) {
cap_cb->unicast_discovery_complete(conn, cap_cb->unicast_discovery_complete(conn,
err, err,
@ -154,7 +154,7 @@ static uint8_t cap_unicast_discover_included_cb(struct bt_conn *conn,
} }
} }
} else if (cap_cb && cap_cb->unicast_discovery_complete) { } else if (cap_cb && cap_cb->unicast_discovery_complete) {
BT_DBG("Found CAS with CSIS"); LOG_DBG("Found CAS with CSIS");
cap_cb->unicast_discovery_complete(conn, 0, cap_cb->unicast_discovery_complete(conn, 0,
client->csis_inst); client->csis_inst);
} }
@ -179,13 +179,13 @@ static uint8_t cap_unicast_discover_cas_cb(struct bt_conn *conn,
int err; int err;
if (attr->handle == prim_service->end_handle) { if (attr->handle == prim_service->end_handle) {
BT_DBG("Found CAS without CSIS"); LOG_DBG("Found CAS without CSIS");
cap_cb->unicast_discovery_complete(conn, 0, NULL); cap_cb->unicast_discovery_complete(conn, 0, NULL);
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("Found CAS, discovering included CSIS"); LOG_DBG("Found CAS, discovering included CSIS");
params->uuid = NULL; params->uuid = NULL;
params->start_handle = attr->handle + 1; params->start_handle = attr->handle + 1;
@ -195,7 +195,7 @@ static uint8_t cap_unicast_discover_cas_cb(struct bt_conn *conn,
err = bt_gatt_discover(conn, params); err = bt_gatt_discover(conn, params);
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
params->func = NULL; params->func = NULL;
if (cap_cb && cap_cb->unicast_discovery_complete) { if (cap_cb && cap_cb->unicast_discovery_complete) {
@ -214,7 +214,7 @@ int bt_cap_initiator_unicast_discover(struct bt_conn *conn)
int err; int err;
CHECKIF(conn == NULL) { CHECKIF(conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }

View file

@ -14,16 +14,16 @@
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
#include <zephyr/sys/check.h> #include <zephyr/sys/check.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_AUDIO) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_audio
#include "common/log.h" LOG_MODULE_REGISTER(bt_audio, LOG_LEVEL_DBG);
bool bt_codec_get_val(const struct bt_codec *codec, bool bt_codec_get_val(const struct bt_codec *codec,
uint8_t type, uint8_t type,
const struct bt_codec_data **data) const struct bt_codec_data **data)
{ {
CHECKIF(codec == NULL) { CHECKIF(codec == NULL) {
BT_DBG("codec is NULL"); LOG_DBG("codec is NULL");
return false; return false;
} }
@ -43,7 +43,7 @@ int bt_codec_cfg_get_freq(const struct bt_codec *codec)
const struct bt_codec_data *element; const struct bt_codec_data *element;
CHECKIF(codec == NULL) { CHECKIF(codec == NULL) {
BT_DBG("codec is NULL"); LOG_DBG("codec is NULL");
return BT_AUDIO_CODEC_PARSE_ERR_INVALID_PARAM; return BT_AUDIO_CODEC_PARSE_ERR_INVALID_PARAM;
} }
@ -89,7 +89,7 @@ int bt_codec_cfg_get_frame_duration_us(const struct bt_codec *codec)
const struct bt_codec_data *element; const struct bt_codec_data *element;
CHECKIF(codec == NULL) { CHECKIF(codec == NULL) {
BT_DBG("codec is NULL"); LOG_DBG("codec is NULL");
return BT_AUDIO_CODEC_PARSE_ERR_INVALID_PARAM; return BT_AUDIO_CODEC_PARSE_ERR_INVALID_PARAM;
} }
@ -113,7 +113,7 @@ int bt_codec_cfg_get_chan_allocation_val(const struct bt_codec *codec,
const struct bt_codec_data *element; const struct bt_codec_data *element;
CHECKIF(codec == NULL) { CHECKIF(codec == NULL) {
BT_DBG("codec is NULL"); LOG_DBG("codec is NULL");
return BT_AUDIO_CODEC_PARSE_ERR_INVALID_PARAM; return BT_AUDIO_CODEC_PARSE_ERR_INVALID_PARAM;
} }
@ -137,7 +137,7 @@ int bt_codec_cfg_get_octets_per_frame(const struct bt_codec *codec)
const struct bt_codec_data *element; const struct bt_codec_data *element;
CHECKIF(codec == NULL) { CHECKIF(codec == NULL) {
BT_DBG("codec is NULL"); LOG_DBG("codec is NULL");
return BT_AUDIO_CODEC_PARSE_ERR_INVALID_PARAM; return BT_AUDIO_CODEC_PARSE_ERR_INVALID_PARAM;
} }
@ -154,7 +154,7 @@ int bt_codec_cfg_get_frame_blocks_per_sdu(const struct bt_codec *codec, bool fal
const struct bt_codec_data *element; const struct bt_codec_data *element;
CHECKIF(codec == NULL) { CHECKIF(codec == NULL) {
BT_DBG("codec is NULL"); LOG_DBG("codec is NULL");
return BT_AUDIO_CODEC_PARSE_ERR_INVALID_PARAM; return BT_AUDIO_CODEC_PARSE_ERR_INVALID_PARAM;
} }

View file

@ -18,11 +18,12 @@
#include <tinycrypt/ccm_mode.h> #include <tinycrypt/ccm_mode.h>
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_CSIP_SET_MEMBER_CRYPTO)
#define LOG_MODULE_NAME bt_csip_crypto
#include "common/log.h"
#include "common/bt_str.h" #include "common/bt_str.h"
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_csip_crypto, CONFIG_BT_CSIP_SET_MEMBER_CRYPTO_LOG_LEVEL);
#define BT_CSIP_CRYPTO_PADDING_SIZE 13 #define BT_CSIP_CRYPTO_PADDING_SIZE 13
#define BT_CSIP_R_SIZE 3 /* r is 24 bit / 3 octet */ #define BT_CSIP_R_SIZE 3 /* r is 24 bit / 3 octet */
#define BT_CSIP_R_MASK BIT_MASK(24) /* r is 24 bit / 3 octet */ #define BT_CSIP_R_MASK BIT_MASK(24) /* r is 24 bit / 3 octet */
@ -68,17 +69,17 @@ int bt_csip_sih(const uint8_t sirk[BT_CSIP_SET_SIRK_SIZE], uint32_t r,
uint8_t sirk_tmp[BT_CSIP_SET_SIRK_SIZE]; uint8_t sirk_tmp[BT_CSIP_SET_SIRK_SIZE];
if ((r & BIT(23)) || ((r & BIT(22)) == 0)) { if ((r & BIT(23)) || ((r & BIT(22)) == 0)) {
BT_DBG("Invalid r %0x06x", (uint32_t)(r & BT_CSIP_R_MASK)); LOG_DBG("Invalid r %0x06x", (uint32_t)(r & BT_CSIP_R_MASK));
} }
BT_DBG("SIRK %s", bt_hex(sirk, BT_CSIP_SET_SIRK_SIZE)); LOG_DBG("SIRK %s", bt_hex(sirk, BT_CSIP_SET_SIRK_SIZE));
BT_DBG("r 0x%06x", r); LOG_DBG("r 0x%06x", r);
/* r' = padding || r */ /* r' = padding || r */
(void)memset(res, 0, BT_CSIP_CRYPTO_PADDING_SIZE); (void)memset(res, 0, BT_CSIP_CRYPTO_PADDING_SIZE);
sys_put_be24(r, res + BT_CSIP_CRYPTO_PADDING_SIZE); sys_put_be24(r, res + BT_CSIP_CRYPTO_PADDING_SIZE);
BT_DBG("BE: r' %s", bt_hex(res, sizeof(res))); LOG_DBG("BE: r' %s", bt_hex(res, sizeof(res)));
if (IS_ENABLED(CONFIG_LITTLE_ENDIAN)) { if (IS_ENABLED(CONFIG_LITTLE_ENDIAN)) {
/* Swap to Big Endian (BE) */ /* Swap to Big Endian (BE) */
@ -100,12 +101,12 @@ int bt_csip_sih(const uint8_t sirk[BT_CSIP_SET_SIRK_SIZE], uint32_t r,
* result of sih. * result of sih.
*/ */
BT_DBG("BE: res %s", bt_hex(res, sizeof(res))); LOG_DBG("BE: res %s", bt_hex(res, sizeof(res)));
/* Result is the lowest 3 bytes */ /* Result is the lowest 3 bytes */
*out = sys_get_be24(res + 13); *out = sys_get_be24(res + 13);
BT_DBG("sih 0x%06x", *out); LOG_DBG("sih 0x%06x", *out);
return 0; return 0;
} }
@ -141,13 +142,13 @@ static int k1(const uint8_t *n, size_t n_size,
* k1(N, SALT, P) = AES-CMAC_T(P) * k1(N, SALT, P) = AES-CMAC_T(P)
*/ */
BT_DBG("BE: n %s", bt_hex(n, n_size)); LOG_DBG("BE: n %s", bt_hex(n, n_size));
BT_DBG("BE: salt %s", bt_hex(salt, BT_CSIP_CRYPTO_SALT_SIZE)); LOG_DBG("BE: salt %s", bt_hex(salt, BT_CSIP_CRYPTO_SALT_SIZE));
BT_DBG("BE: p %s", bt_hex(p, p_size)); LOG_DBG("BE: p %s", bt_hex(p, p_size));
err = aes_cmac(salt, n, n_size, t); err = aes_cmac(salt, n, n_size, t);
BT_DBG("BE: t %s", bt_hex(t, sizeof(t))); LOG_DBG("BE: t %s", bt_hex(t, sizeof(t)));
if (err) { if (err) {
return err; return err;
@ -155,7 +156,7 @@ static int k1(const uint8_t *n, size_t n_size,
err = aes_cmac(t, p, p_size, out); err = aes_cmac(t, p, p_size, out);
BT_DBG("BE: out %s", bt_hex(out, 16)); LOG_DBG("BE: out %s", bt_hex(out, 16));
return err; return err;
} }
@ -178,13 +179,13 @@ static int s1(const uint8_t *m, size_t m_size,
* s1(M) = AES-CMAC_zero(M) * s1(M) = AES-CMAC_zero(M)
*/ */
BT_DBG("BE: m %s", bt_hex(m, m_size)); LOG_DBG("BE: m %s", bt_hex(m, m_size));
memset(zero, 0, sizeof(zero)); memset(zero, 0, sizeof(zero));
err = aes_cmac(zero, m, m_size, out); err = aes_cmac(zero, m, m_size, out);
BT_DBG("BE: out %s", bt_hex(out, 16)); LOG_DBG("BE: out %s", bt_hex(out, 16));
return err; return err;
} }
@ -204,7 +205,7 @@ int bt_csip_sef(const uint8_t k[BT_CSIP_CRYPTO_KEY_SIZE],
* sef(K, SIRK) = k1(K, s1("SIRKenc"), "csis") ^ SIRK * sef(K, SIRK) = k1(K, s1("SIRKenc"), "csis") ^ SIRK
*/ */
BT_DBG("SIRK %s", bt_hex(sirk, BT_CSIP_SET_SIRK_SIZE)); LOG_DBG("SIRK %s", bt_hex(sirk, BT_CSIP_SET_SIRK_SIZE));
if (IS_ENABLED(CONFIG_LITTLE_ENDIAN)) { if (IS_ENABLED(CONFIG_LITTLE_ENDIAN)) {
/* Swap because aes_cmac is big endian /* Swap because aes_cmac is big endian
@ -214,21 +215,21 @@ int bt_csip_sef(const uint8_t k[BT_CSIP_CRYPTO_KEY_SIZE],
} else { } else {
(void)memcpy(k1_tmp, k, sizeof(k1_tmp)); (void)memcpy(k1_tmp, k, sizeof(k1_tmp));
} }
BT_DBG("BE: k %s", bt_hex(k1_tmp, sizeof(k1_tmp))); LOG_DBG("BE: k %s", bt_hex(k1_tmp, sizeof(k1_tmp)));
err = s1(m, sizeof(m), s1_out); err = s1(m, sizeof(m), s1_out);
if (err) { if (err) {
return err; return err;
} }
BT_DBG("BE: s1 result %s", bt_hex(s1_out, sizeof(s1_out))); LOG_DBG("BE: s1 result %s", bt_hex(s1_out, sizeof(s1_out)));
err = k1(k1_tmp, sizeof(k1_tmp), s1_out, p, sizeof(p), k1_out); err = k1(k1_tmp, sizeof(k1_tmp), s1_out, p, sizeof(p), k1_out);
if (err) { if (err) {
return err; return err;
} }
BT_DBG("BE: k1 result %s", bt_hex(k1_out, sizeof(k1_out))); LOG_DBG("BE: k1 result %s", bt_hex(k1_out, sizeof(k1_out)));
if (IS_ENABLED(CONFIG_LITTLE_ENDIAN)) { if (IS_ENABLED(CONFIG_LITTLE_ENDIAN)) {
/* Swap result back to little endian */ /* Swap result back to little endian */
@ -236,7 +237,7 @@ int bt_csip_sef(const uint8_t k[BT_CSIP_CRYPTO_KEY_SIZE],
} }
xor_128(k1_out, sirk, out_sirk); xor_128(k1_out, sirk, out_sirk);
BT_DBG("out %s", bt_hex(out_sirk, BT_CSIP_SET_SIRK_SIZE)); LOG_DBG("out %s", bt_hex(out_sirk, BT_CSIP_SET_SIRK_SIZE));
return 0; return 0;
} }
@ -253,6 +254,6 @@ int bt_csip_sdf(const uint8_t k[BT_CSIP_CRYPTO_KEY_SIZE],
* sdf(K, EncSIRK) = k1(K, s1("SIRKenc"), "csis") ^ EncSIRK * sdf(K, EncSIRK) = k1(K, s1("SIRKenc"), "csis") ^ EncSIRK
*/ */
BT_DBG("Running SDF as SEF"); LOG_DBG("Running SDF as SEF");
return bt_csip_sef(k, enc_sirk, out_sirk); return bt_csip_sef(k, enc_sirk, out_sirk);
} }

View file

@ -36,9 +36,10 @@
#include "csip_internal.h" #include "csip_internal.h"
#include "../host/conn_internal.h" #include "../host/conn_internal.h"
#include "../host/keys.h" #include "../host/keys.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_CSIP_SET_COORDINATOR)
#define LOG_MODULE_NAME bt_csip_set_coordinator #include <zephyr/logging/log.h>
#include "common/log.h"
LOG_MODULE_REGISTER(bt_csip_set_coordinator, CONFIG_BT_CSIP_SET_COORDINATOR_LOG_LEVEL);
static uint8_t gatt_write_buf[1]; static uint8_t gatt_write_buf[1];
static struct bt_gatt_write_params write_params; static struct bt_gatt_write_params write_params;
@ -179,7 +180,7 @@ static struct bt_csip_set_coordinator_svc_inst *get_next_active_instance(void)
svc_inst = lookup_instance_by_set_info(member, active.info); svc_inst = lookup_instance_by_set_info(member, active.info);
if (svc_inst == NULL) { if (svc_inst == NULL) {
BT_DBG("Failed to lookup instance by set_info %p", active.info); LOG_DBG("Failed to lookup instance by set_info %p", active.info);
} }
return svc_inst; return svc_inst;
@ -198,12 +199,12 @@ static int member_rank_compare_asc(const void *m1, const void *m2)
svc_inst_2 = lookup_instance_by_set_info(member_2, active.info); svc_inst_2 = lookup_instance_by_set_info(member_2, active.info);
if (svc_inst_1 == NULL) { if (svc_inst_1 == NULL) {
BT_ERR("svc_inst_1 was NULL for member %p", member_1); LOG_ERR("svc_inst_1 was NULL for member %p", member_1);
return 0; return 0;
} }
if (svc_inst_2 == NULL) { if (svc_inst_2 == NULL) {
BT_ERR("svc_inst_2 was NULL for member %p", member_2); LOG_ERR("svc_inst_2 was NULL for member %p", member_2);
return 0; return 0;
} }
@ -269,7 +270,7 @@ static int sirk_decrypt(struct bt_conn *conn,
0x3c, 0xe5, 0xce, 0xd9}; 0x3c, 0xe5, 0xce, 0xd9};
static bool swapped; static bool swapped;
BT_DBG("Decrypting with sample data K"); LOG_DBG("Decrypting with sample data K");
if (!swapped && IS_ENABLED(CONFIG_LITTLE_ENDIAN)) { if (!swapped && IS_ENABLED(CONFIG_LITTLE_ENDIAN)) {
/* Swap test_k to little endian */ /* Swap test_k to little endian */
@ -370,7 +371,7 @@ static uint8_t sirk_notify_func(struct bt_conn *conn,
struct bt_csip_set_coordinator_svc_inst *svc_inst; struct bt_csip_set_coordinator_svc_inst *svc_inst;
if (data == NULL) { if (data == NULL) {
BT_DBG("[UNSUBSCRIBED] %u", params->value_handle); LOG_DBG("[UNSUBSCRIBED] %u", params->value_handle);
params->value_handle = 0U; params->value_handle = 0U;
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
@ -383,7 +384,7 @@ static uint8_t sirk_notify_func(struct bt_conn *conn,
svc_inst = lookup_instance_by_handle(conn, handle); svc_inst = lookup_instance_by_handle(conn, handle);
if (svc_inst != NULL) { if (svc_inst != NULL) {
BT_DBG("Instance %u", svc_inst->idx); LOG_DBG("Instance %u", svc_inst->idx);
if (length == sizeof(struct bt_csip_set_sirk)) { if (length == sizeof(struct bt_csip_set_sirk)) {
struct bt_csip_set_sirk *sirk = struct bt_csip_set_sirk *sirk =
(struct bt_csip_set_sirk *)data; (struct bt_csip_set_sirk *)data;
@ -393,9 +394,8 @@ static uint8_t sirk_notify_func(struct bt_conn *conn,
client = &client_insts[bt_conn_index(conn)]; client = &client_insts[bt_conn_index(conn)];
dst_sirk = client->set_member.insts[svc_inst->idx].info.set_sirk; dst_sirk = client->set_member.insts[svc_inst->idx].info.set_sirk;
BT_DBG("Set SIRK %sencrypted", LOG_DBG("Set SIRK %sencrypted",
sirk->type == BT_CSIP_SIRK_TYPE_PLAIN sirk->type == BT_CSIP_SIRK_TYPE_PLAIN ? "not " : "");
? "not " : "");
/* Assuming not connected to other set devices */ /* Assuming not connected to other set devices */
if (sirk->type == BT_CSIP_SIRK_TYPE_ENCRYPTED) { if (sirk->type == BT_CSIP_SIRK_TYPE_ENCRYPTED) {
@ -407,11 +407,12 @@ static uint8_t sirk_notify_func(struct bt_conn *conn,
err = sirk_decrypt(conn, sirk->value, err = sirk_decrypt(conn, sirk->value,
dst_sirk); dst_sirk);
if (err != 0) { if (err != 0) {
BT_ERR("Could not decrypt " LOG_ERR("Could not decrypt "
"SIRK %d", err); "SIRK %d",
err);
} }
} else { } else {
BT_DBG("Encrypted SIRK not supported"); LOG_DBG("Encrypted SIRK not supported");
return BT_GATT_ITER_CONTINUE; return BT_GATT_ITER_CONTINUE;
} }
} else { } else {
@ -423,10 +424,10 @@ static uint8_t sirk_notify_func(struct bt_conn *conn,
/* TODO: Notify app */ /* TODO: Notify app */
} else { } else {
BT_DBG("Invalid length %u", length); LOG_DBG("Invalid length %u", length);
} }
} else { } else {
BT_DBG("Notification/Indication on unknown service inst"); LOG_DBG("Notification/Indication on unknown service inst");
} }
return BT_GATT_ITER_CONTINUE; return BT_GATT_ITER_CONTINUE;
@ -441,7 +442,7 @@ static uint8_t size_notify_func(struct bt_conn *conn,
struct bt_csip_set_coordinator_svc_inst *svc_inst; struct bt_csip_set_coordinator_svc_inst *svc_inst;
if (data == NULL) { if (data == NULL) {
BT_DBG("[UNSUBSCRIBED] %u", params->value_handle); LOG_DBG("[UNSUBSCRIBED] %u", params->value_handle);
params->value_handle = 0U; params->value_handle = 0U;
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
@ -462,17 +463,16 @@ static uint8_t size_notify_func(struct bt_conn *conn,
set_info = &client->set_member.insts[svc_inst->idx].info; set_info = &client->set_member.insts[svc_inst->idx].info;
(void)memcpy(&set_size, data, length); (void)memcpy(&set_size, data, length);
BT_DBG("Set size updated from %u to %u", LOG_DBG("Set size updated from %u to %u", set_info->set_size, set_size);
set_info->set_size, set_size);
set_info->set_size = set_size; set_info->set_size = set_size;
/* TODO: Notify app */ /* TODO: Notify app */
} else { } else {
BT_DBG("Invalid length %u", length); LOG_DBG("Invalid length %u", length);
} }
} else { } else {
BT_DBG("Notification/Indication on unknown service inst"); LOG_DBG("Notification/Indication on unknown service inst");
} }
LOG_HEXDUMP_DBG(data, length, "Value"); LOG_HEXDUMP_DBG(data, length, "Value");
@ -488,7 +488,7 @@ static uint8_t lock_notify_func(struct bt_conn *conn,
struct bt_csip_set_coordinator_svc_inst *svc_inst; struct bt_csip_set_coordinator_svc_inst *svc_inst;
if (data == NULL) { if (data == NULL) {
BT_DBG("[UNSUBSCRIBED] %u", params->value_handle); LOG_DBG("[UNSUBSCRIBED] %u", params->value_handle);
params->value_handle = 0U; params->value_handle = 0U;
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
@ -509,26 +509,25 @@ static uint8_t lock_notify_func(struct bt_conn *conn,
(void)memcpy(&value, data, length); (void)memcpy(&value, data, length);
if (value != BT_CSIP_RELEASE_VALUE && if (value != BT_CSIP_RELEASE_VALUE &&
value != BT_CSIP_LOCK_VALUE) { value != BT_CSIP_LOCK_VALUE) {
BT_DBG("Invalid value %u", value); LOG_DBG("Invalid value %u", value);
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
(void)memcpy(&svc_inst->set_lock, data, length); (void)memcpy(&svc_inst->set_lock, data, length);
locked = svc_inst->set_lock == BT_CSIP_LOCK_VALUE; locked = svc_inst->set_lock == BT_CSIP_LOCK_VALUE;
BT_DBG("Instance %u lock was %s", LOG_DBG("Instance %u lock was %s", svc_inst->idx,
svc_inst->idx, locked ? "locked" : "released");
locked ? "locked" : "released");
client = &client_insts[bt_conn_index(conn)]; client = &client_insts[bt_conn_index(conn)];
inst = &client->set_member.insts[svc_inst->idx]; inst = &client->set_member.insts[svc_inst->idx];
lock_changed(inst, locked); lock_changed(inst, locked);
} else { } else {
BT_DBG("Invalid length %u", length); LOG_DBG("Invalid length %u", length);
} }
} else { } else {
BT_DBG("Notification/Indication on unknown service inst"); LOG_DBG("Notification/Indication on unknown service inst");
} }
LOG_HEXDUMP_DBG(data, length, "Value"); LOG_HEXDUMP_DBG(data, length, "Value");
@ -540,7 +539,7 @@ static int csip_set_coordinator_write_set_lock(struct bt_csip_set_coordinator_sv
bt_gatt_write_func_t cb) bt_gatt_write_func_t cb)
{ {
if (inst->set_lock_handle == 0) { if (inst->set_lock_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
cur_inst = NULL; cur_inst = NULL;
return -EINVAL; return -EINVAL;
} }
@ -566,7 +565,7 @@ static int read_set_sirk(struct bt_csip_set_coordinator_svc_inst *svc_inst)
} }
if (svc_inst->set_sirk_handle == 0) { if (svc_inst->set_sirk_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -591,13 +590,13 @@ static int csip_set_coordinator_read_set_size(struct bt_conn *conn,
} else { } else {
cur_inst = lookup_instance_by_index(conn, inst_idx); cur_inst = lookup_instance_by_index(conn, inst_idx);
if (cur_inst == NULL) { if (cur_inst == NULL) {
BT_DBG("Inst not found"); LOG_DBG("Inst not found");
return -EINVAL; return -EINVAL;
} }
} }
if (cur_inst->set_size_handle == 0) { if (cur_inst->set_size_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
cur_inst = NULL; cur_inst = NULL;
return -EINVAL; return -EINVAL;
} }
@ -623,13 +622,13 @@ static int csip_set_coordinator_read_rank(struct bt_conn *conn,
} else { } else {
cur_inst = lookup_instance_by_index(conn, inst_idx); cur_inst = lookup_instance_by_index(conn, inst_idx);
if (cur_inst == NULL) { if (cur_inst == NULL) {
BT_DBG("Inst not found"); LOG_DBG("Inst not found");
return -EINVAL; return -EINVAL;
} }
} }
if (cur_inst->rank_handle == 0) { if (cur_inst->rank_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
cur_inst = NULL; cur_inst = NULL;
return -EINVAL; return -EINVAL;
} }
@ -665,8 +664,7 @@ static uint8_t discover_func(struct bt_conn *conn,
void *notify_handler = NULL; void *notify_handler = NULL;
if (attr == NULL) { if (attr == NULL) {
BT_DBG("Setup complete for %u / %u", LOG_DBG("Setup complete for %u / %u", cur_inst->idx + 1, client->inst_count);
cur_inst->idx + 1, client->inst_count);
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
if ((cur_inst->idx + 1) < client->inst_count) { if ((cur_inst->idx + 1) < client->inst_count) {
@ -681,7 +679,7 @@ static uint8_t discover_func(struct bt_conn *conn,
err = bt_gatt_discover(conn, &discover_params); err = bt_gatt_discover(conn, &discover_params);
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
discover_complete(client, err); discover_complete(client, err);
} }
@ -692,38 +690,38 @@ static uint8_t discover_func(struct bt_conn *conn,
busy = false; busy = false;
err = csip_set_coordinator_discover_sets(&client->set_member); err = csip_set_coordinator_discover_sets(&client->set_member);
if (err != 0) { if (err != 0) {
BT_DBG("Discover sets failed (err %d)", err); LOG_DBG("Discover sets failed (err %d)", err);
discover_complete(client, err); discover_complete(client, err);
} }
} }
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC && if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC &&
client->inst_count != 0) { client->inst_count != 0) {
chrc = (struct bt_gatt_chrc *)attr->user_data; chrc = (struct bt_gatt_chrc *)attr->user_data;
if (bt_uuid_cmp(chrc->uuid, BT_UUID_CSIS_SET_SIRK) == 0) { if (bt_uuid_cmp(chrc->uuid, BT_UUID_CSIS_SET_SIRK) == 0) {
BT_DBG("Set SIRK"); LOG_DBG("Set SIRK");
cur_inst->set_sirk_handle = chrc->value_handle; cur_inst->set_sirk_handle = chrc->value_handle;
sub_params = &cur_inst->sirk_sub_params; sub_params = &cur_inst->sirk_sub_params;
sub_params->disc_params = &cur_inst->sirk_sub_disc_params; sub_params->disc_params = &cur_inst->sirk_sub_disc_params;
notify_handler = sirk_notify_func; notify_handler = sirk_notify_func;
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_CSIS_SET_SIZE) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_CSIS_SET_SIZE) == 0) {
BT_DBG("Set size"); LOG_DBG("Set size");
cur_inst->set_size_handle = chrc->value_handle; cur_inst->set_size_handle = chrc->value_handle;
sub_params = &cur_inst->size_sub_params; sub_params = &cur_inst->size_sub_params;
sub_params->disc_params = &cur_inst->size_sub_disc_params; sub_params->disc_params = &cur_inst->size_sub_disc_params;
notify_handler = size_notify_func; notify_handler = size_notify_func;
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_CSIS_SET_LOCK) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_CSIS_SET_LOCK) == 0) {
BT_DBG("Set lock"); LOG_DBG("Set lock");
cur_inst->set_lock_handle = chrc->value_handle; cur_inst->set_lock_handle = chrc->value_handle;
sub_params = &cur_inst->lock_sub_params; sub_params = &cur_inst->lock_sub_params;
sub_params->disc_params = &cur_inst->lock_sub_disc_params; sub_params->disc_params = &cur_inst->lock_sub_disc_params;
notify_handler = lock_notify_func; notify_handler = lock_notify_func;
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_CSIS_RANK) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_CSIS_RANK) == 0) {
BT_DBG("Set rank"); LOG_DBG("Set rank");
cur_inst->rank_handle = chrc->value_handle; cur_inst->rank_handle = chrc->value_handle;
} }
@ -758,8 +756,7 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
if (attr == NULL || if (attr == NULL ||
client->inst_count == CONFIG_BT_CSIP_SET_COORDINATOR_MAX_CSIS_INSTANCES) { client->inst_count == CONFIG_BT_CSIP_SET_COORDINATOR_MAX_CSIS_INSTANCES) {
BT_DBG("Discover complete, found %u instances", LOG_DBG("Discover complete, found %u instances", client->inst_count);
client->inst_count);
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
if (client->inst_count != 0) { if (client->inst_count != 0) {
@ -774,7 +771,7 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
err = bt_gatt_discover(conn, &discover_params); err = bt_gatt_discover(conn, &discover_params);
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
discover_complete(client, err); discover_complete(client, err);
} }
} else { } else {
@ -784,7 +781,7 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_PRIMARY) { if (params->type == BT_GATT_DISCOVER_PRIMARY) {
prim_service = (struct bt_gatt_service_val *)attr->user_data; prim_service = (struct bt_gatt_service_val *)attr->user_data;
@ -812,7 +809,7 @@ bool bt_csip_set_coordinator_is_set_member(const uint8_t set_sirk[BT_CSIP_SET_SI
uint32_t prand = sys_get_le24(data->data + 3); uint32_t prand = sys_get_le24(data->data + 3);
uint32_t calculated_hash; uint32_t calculated_hash;
BT_DBG("hash: 0x%06x, prand 0x%06x", hash, prand); LOG_DBG("hash: 0x%06x, prand 0x%06x", hash, prand);
err = bt_csip_sih(set_sirk, prand, &calculated_hash); err = bt_csip_sih(set_sirk, prand, &calculated_hash);
if (err != 0) { if (err != 0) {
return false; return false;
@ -820,8 +817,7 @@ bool bt_csip_set_coordinator_is_set_member(const uint8_t set_sirk[BT_CSIP_SET_SI
calculated_hash &= 0xffffff; calculated_hash &= 0xffffff;
BT_DBG("calculated_hash: 0x%06x, hash 0x%06x", LOG_DBG("calculated_hash: 0x%06x, hash 0x%06x", calculated_hash, hash);
calculated_hash, hash);
return calculated_hash == hash; return calculated_hash == hash;
} }
@ -842,7 +838,7 @@ static uint8_t csip_set_coordinator_discover_insts_read_rank_cb(struct bt_conn *
busy = false; busy = false;
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
discover_complete(client, err); discover_complete(client, err);
} else if (data != NULL) { } else if (data != NULL) {
@ -851,10 +847,9 @@ static uint8_t csip_set_coordinator_discover_insts_read_rank_cb(struct bt_conn *
if (length == 1) { if (length == 1) {
(void)memcpy(&client->svc_insts[cur_inst->idx].rank, (void)memcpy(&client->svc_insts[cur_inst->idx].rank,
data, length); data, length);
BT_DBG("%u", LOG_DBG("%u", client->svc_insts[cur_inst->idx].rank);
client->svc_insts[cur_inst->idx].rank);
} else { } else {
BT_DBG("Invalid length, continuing to next member"); LOG_DBG("Invalid length, continuing to next member");
} }
discover_insts_resume(conn, 0, 0, 0); discover_insts_resume(conn, 0, 0, 0);
@ -874,7 +869,7 @@ static uint8_t csip_set_coordinator_discover_insts_read_set_size_cb(
busy = false; busy = false;
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
discover_complete(client, err); discover_complete(client, err);
} else if (data != NULL) { } else if (data != NULL) {
@ -886,9 +881,9 @@ static uint8_t csip_set_coordinator_discover_insts_read_set_size_cb(
if (length == sizeof(set_info->set_size)) { if (length == sizeof(set_info->set_size)) {
(void)memcpy(&set_info->set_size, data, length); (void)memcpy(&set_info->set_size, data, length);
BT_DBG("%u", set_info->set_size); LOG_DBG("%u", set_info->set_size);
} else { } else {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
} }
discover_insts_resume(conn, 0, 0, cur_inst->rank_handle); discover_insts_resume(conn, 0, 0, cur_inst->rank_handle);
@ -908,8 +903,8 @@ static int parse_sirk(struct bt_csip_set_coordinator_inst *client,
struct bt_csip_set_sirk *sirk = struct bt_csip_set_sirk *sirk =
(struct bt_csip_set_sirk *)data; (struct bt_csip_set_sirk *)data;
BT_DBG("Set SIRK %sencrypted", LOG_DBG("Set SIRK %sencrypted",
sirk->type == BT_CSIP_SIRK_TYPE_PLAIN ? "not " : ""); sirk->type == BT_CSIP_SIRK_TYPE_PLAIN ? "not " : "");
/* Assuming not connected to other set devices */ /* Assuming not connected to other set devices */
if (sirk->type == BT_CSIP_SIRK_TYPE_ENCRYPTED) { if (sirk->type == BT_CSIP_SIRK_TYPE_ENCRYPTED) {
if (IS_ENABLED(CONFIG_BT_CSIP_SET_COORDINATOR_ENC_SIRK_SUPPORT)) { if (IS_ENABLED(CONFIG_BT_CSIP_SET_COORDINATOR_ENC_SIRK_SUPPORT)) {
@ -920,12 +915,13 @@ static int parse_sirk(struct bt_csip_set_coordinator_inst *client,
err = sirk_decrypt(client->conn, sirk->value, err = sirk_decrypt(client->conn, sirk->value,
set_sirk); set_sirk);
if (err != 0) { if (err != 0) {
BT_ERR("Could not decrypt " LOG_ERR("Could not decrypt "
"SIRK %d", err); "SIRK %d",
err);
return err; return err;
} }
} else { } else {
BT_WARN("Encrypted SIRK not supported"); LOG_WRN("Encrypted SIRK not supported");
set_sirk = NULL; set_sirk = NULL;
return BT_ATT_ERR_INSUFFICIENT_ENCRYPTION; return BT_ATT_ERR_INSUFFICIENT_ENCRYPTION;
} }
@ -938,7 +934,7 @@ static int parse_sirk(struct bt_csip_set_coordinator_inst *client,
"Set SIRK"); "Set SIRK");
} }
} else { } else {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
return BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; return BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
@ -956,7 +952,7 @@ static uint8_t csip_set_coordinator_discover_insts_read_set_sirk_cb(
busy = false; busy = false;
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
discover_complete(client, err); discover_complete(client, err);
} else if (data != NULL) { } else if (data != NULL) {
@ -965,7 +961,7 @@ static uint8_t csip_set_coordinator_discover_insts_read_set_sirk_cb(
cb_err = parse_sirk(client, data, length); cb_err = parse_sirk(client, data, length);
if (cb_err != 0) { if (cb_err != 0) {
BT_DBG("Could not parse SIRK: %d", cb_err); LOG_DBG("Could not parse SIRK: %d", cb_err);
} else { } else {
discover_insts_resume(conn, 0, discover_insts_resume(conn, 0,
cur_inst->set_size_handle, cur_inst->set_size_handle,
@ -997,14 +993,14 @@ static void discover_insts_resume(struct bt_conn *conn, uint16_t sirk_handle,
conn, cur_inst->idx, conn, cur_inst->idx,
csip_set_coordinator_discover_insts_read_set_size_cb); csip_set_coordinator_discover_insts_read_set_size_cb);
if (cb_err != 0) { if (cb_err != 0) {
BT_DBG("Could not read set size: %d", cb_err); LOG_DBG("Could not read set size: %d", cb_err);
} }
} else if (rank_handle != 0) { } else if (rank_handle != 0) {
cb_err = csip_set_coordinator_read_rank( cb_err = csip_set_coordinator_read_rank(
conn, cur_inst->idx, conn, cur_inst->idx,
csip_set_coordinator_discover_insts_read_rank_cb); csip_set_coordinator_discover_insts_read_rank_cb);
if (cb_err != 0) { if (cb_err != 0) {
BT_DBG("Could not read set rank: %d", cb_err); LOG_DBG("Could not read set rank: %d", cb_err);
} }
} else { } else {
uint8_t next_idx = cur_inst->idx + 1; uint8_t next_idx = cur_inst->idx + 1;
@ -1036,15 +1032,14 @@ static void csip_set_coordinator_write_restore_cb(struct bt_conn *conn,
busy = false; busy = false;
if (err != 0) { if (err != 0) {
BT_WARN("Could not restore (%d)", err); LOG_WRN("Could not restore (%d)", err);
release_set_complete(err); release_set_complete(err);
return; return;
} }
active.members_restored++; active.members_restored++;
BT_DBG("Restored %u/%u members", LOG_DBG("Restored %u/%u members", active.members_restored, active.members_handled);
active.members_restored, active.members_handled);
if (active.members_restored < active.members_handled && if (active.members_restored < active.members_handled &&
CONFIG_BT_MAX_CONN > 1) { CONFIG_BT_MAX_CONN > 1) {
@ -1065,9 +1060,8 @@ static void csip_set_coordinator_write_restore_cb(struct bt_conn *conn,
if (csip_err == 0) { if (csip_err == 0) {
busy = true; busy = true;
} else { } else {
BT_DBG("Failed to release next member[%u]: %d", LOG_DBG("Failed to release next member[%u]: %d", active.members_handled,
active.members_handled, csip_err);
csip_err);
release_set_complete(csip_err); release_set_complete(csip_err);
} }
@ -1083,7 +1077,7 @@ static void csip_set_coordinator_write_lock_cb(struct bt_conn *conn,
busy = false; busy = false;
if (err != 0) { if (err != 0) {
BT_DBG("Could not lock (0x%X)", err); LOG_DBG("Could not lock (0x%X)", err);
if (active.members_handled > 0 && CONFIG_BT_MAX_CONN > 1) { if (active.members_handled > 0 && CONFIG_BT_MAX_CONN > 1) {
struct bt_csip_set_coordinator_set_member *member; struct bt_csip_set_coordinator_set_member *member;
int csip_err; int csip_err;
@ -1094,8 +1088,7 @@ static void csip_set_coordinator_write_lock_cb(struct bt_conn *conn,
cur_inst = lookup_instance_by_set_info(member, cur_inst = lookup_instance_by_set_info(member,
active.info); active.info);
if (cur_inst == NULL) { if (cur_inst == NULL) {
BT_DBG("Failed to lookup instance by set_info %p", LOG_DBG("Failed to lookup instance by set_info %p", active.info);
active.info);
lock_set_complete(-ENOENT); lock_set_complete(-ENOENT);
} }
@ -1106,7 +1099,7 @@ static void csip_set_coordinator_write_lock_cb(struct bt_conn *conn,
if (csip_err == 0) { if (csip_err == 0) {
busy = true; busy = true;
} else { } else {
BT_WARN("Could not release lock of previous locked member: %d", LOG_WRN("Could not release lock of previous locked member: %d",
csip_err); csip_err);
active_members_reset(); active_members_reset();
return; return;
@ -1119,8 +1112,7 @@ static void csip_set_coordinator_write_lock_cb(struct bt_conn *conn,
} }
active.members_handled++; active.members_handled++;
BT_DBG("Locked %u/%u members", LOG_DBG("Locked %u/%u members", active.members_handled, active.members_count);
active.members_handled, active.members_count);
if (active.members_handled < active.members_count) { if (active.members_handled < active.members_count) {
struct bt_csip_set_coordinator_svc_inst *prev_inst = cur_inst; struct bt_csip_set_coordinator_svc_inst *prev_inst = cur_inst;
@ -1139,8 +1131,8 @@ static void csip_set_coordinator_write_lock_cb(struct bt_conn *conn,
if (csip_err == 0) { if (csip_err == 0) {
busy = true; busy = true;
} else { } else {
BT_DBG("Failed to lock next member[%u]: %d", LOG_DBG("Failed to lock next member[%u]: %d", active.members_handled,
active.members_handled, csip_err); csip_err);
active.members_restored = 0; active.members_restored = 0;
@ -1150,7 +1142,7 @@ static void csip_set_coordinator_write_lock_cb(struct bt_conn *conn,
if (csip_err == 0) { if (csip_err == 0) {
busy = true; busy = true;
} else { } else {
BT_WARN("Could not release lock of previous locked member: %d", LOG_WRN("Could not release lock of previous locked member: %d",
csip_err); csip_err);
active_members_reset(); active_members_reset();
return; return;
@ -1167,15 +1159,14 @@ static void csip_set_coordinator_write_release_cb(struct bt_conn *conn, uint8_t
busy = false; busy = false;
if (err != 0) { if (err != 0) {
BT_DBG("Could not release lock (%d)", err); LOG_DBG("Could not release lock (%d)", err);
release_set_complete(err); release_set_complete(err);
return; return;
} }
active.members_handled++; active.members_handled++;
BT_DBG("Released %u/%u members", LOG_DBG("Released %u/%u members", active.members_handled, active.members_count);
active.members_handled, active.members_count);
if (active.members_handled < active.members_count) { if (active.members_handled < active.members_count) {
int csip_err; int csip_err;
@ -1193,8 +1184,8 @@ static void csip_set_coordinator_write_release_cb(struct bt_conn *conn, uint8_t
if (csip_err == 0) { if (csip_err == 0) {
busy = true; busy = true;
} else { } else {
BT_DBG("Failed to release next member[%u]: %d", LOG_DBG("Failed to release next member[%u]: %d", active.members_handled,
active.members_handled, csip_err); csip_err);
release_set_complete(csip_err); release_set_complete(csip_err);
} }
@ -1228,7 +1219,7 @@ static uint8_t csip_set_coordinator_read_lock_cb(struct bt_conn *conn,
busy = false; busy = false;
if (err != 0) { if (err != 0) {
BT_DBG("Could not read lock value (0x%X)", err); LOG_DBG("Could not read lock value (0x%X)", err);
csip_set_coordinator_lock_state_read_cb(err, false); csip_set_coordinator_lock_state_read_cb(err, false);
@ -1236,11 +1227,10 @@ static uint8_t csip_set_coordinator_read_lock_cb(struct bt_conn *conn,
} }
active.members_handled++; active.members_handled++;
BT_DBG("Read lock state on %u/%u members", LOG_DBG("Read lock state on %u/%u members", active.members_handled, active.members_count);
active.members_handled, active.members_count);
if (data == NULL || length != sizeof(cur_inst->set_lock)) { if (data == NULL || length != sizeof(cur_inst->set_lock)) {
BT_DBG("Invalid data %p or length %u", data, length); LOG_DBG("Invalid data %p or length %u", data, length);
csip_set_coordinator_lock_state_read_cb(err, false); csip_set_coordinator_lock_state_read_cb(err, false);
@ -1249,7 +1239,7 @@ static uint8_t csip_set_coordinator_read_lock_cb(struct bt_conn *conn,
value = ((uint8_t *)data)[0]; value = ((uint8_t *)data)[0];
if (value != BT_CSIP_RELEASE_VALUE && value != BT_CSIP_LOCK_VALUE) { if (value != BT_CSIP_RELEASE_VALUE && value != BT_CSIP_LOCK_VALUE) {
BT_DBG("Invalid value %u read", value); LOG_DBG("Invalid value %u read", value);
err = BT_ATT_ERR_UNLIKELY; err = BT_ATT_ERR_UNLIKELY;
csip_set_coordinator_lock_state_read_cb(err, false); csip_set_coordinator_lock_state_read_cb(err, false);
@ -1260,7 +1250,7 @@ static uint8_t csip_set_coordinator_read_lock_cb(struct bt_conn *conn,
cur_inst->set_lock = value; cur_inst->set_lock = value;
if (value != BT_CSIP_RELEASE_VALUE) { if (value != BT_CSIP_RELEASE_VALUE) {
BT_DBG("Set member not unlocked"); LOG_DBG("Set member not unlocked");
csip_set_coordinator_lock_state_read_cb(0, true); csip_set_coordinator_lock_state_read_cb(0, true);
@ -1281,8 +1271,8 @@ static uint8_t csip_set_coordinator_read_lock_cb(struct bt_conn *conn,
if (csip_err == 0) { if (csip_err == 0) {
busy = true; busy = true;
} else { } else {
BT_DBG("Failed to read next member[%u]: %d", LOG_DBG("Failed to read next member[%u]: %d", active.members_handled,
active.members_handled, csip_err); csip_err);
csip_set_coordinator_lock_state_read_cb(err, false); csip_set_coordinator_lock_state_read_cb(err, false);
} }
@ -1296,7 +1286,7 @@ static uint8_t csip_set_coordinator_read_lock_cb(struct bt_conn *conn,
static int csip_set_coordinator_read_set_lock(struct bt_csip_set_coordinator_svc_inst *inst) static int csip_set_coordinator_read_set_lock(struct bt_csip_set_coordinator_svc_inst *inst)
{ {
if (inst->set_lock_handle == 0) { if (inst->set_lock_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
cur_inst = NULL; cur_inst = NULL;
return -EINVAL; return -EINVAL;
} }
@ -1386,7 +1376,7 @@ struct bt_csip_set_coordinator_csis_inst *bt_csip_set_coordinator_csis_inst_by_h
int bt_csip_set_coordinator_register_cb(struct bt_csip_set_coordinator_cb *cb) int bt_csip_set_coordinator_register_cb(struct bt_csip_set_coordinator_cb *cb)
{ {
CHECKIF(cb == NULL) { CHECKIF(cb == NULL) {
BT_DBG("cb is NULL"); LOG_DBG("cb is NULL");
return -EINVAL; return -EINVAL;
} }
@ -1402,7 +1392,7 @@ int bt_csip_set_coordinator_discover(struct bt_conn *conn)
struct bt_csip_set_coordinator_inst *client; struct bt_csip_set_coordinator_inst *client;
CHECKIF(conn == NULL) { CHECKIF(conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
@ -1443,8 +1433,8 @@ static int verify_members(const struct bt_csip_set_coordinator_set_member **memb
uint8_t ranks[CONFIG_BT_MAX_CONN]; uint8_t ranks[CONFIG_BT_MAX_CONN];
if (count > CONFIG_BT_MAX_CONN) { if (count > CONFIG_BT_MAX_CONN) {
BT_DBG("count (%u) larger than maximum support servers (%d)", LOG_DBG("count (%u) larger than maximum support servers (%d)", count,
count, CONFIG_BT_MAX_CONN); CONFIG_BT_MAX_CONN);
return -EINVAL; return -EINVAL;
} }
@ -1457,26 +1447,25 @@ static int verify_members(const struct bt_csip_set_coordinator_set_member **memb
struct bt_conn *conn; struct bt_conn *conn;
CHECKIF(member == NULL) { CHECKIF(member == NULL) {
BT_DBG("Invalid member[%d] was NULL", i); LOG_DBG("Invalid member[%d] was NULL", i);
return -EINVAL; return -EINVAL;
} }
conn = client_inst->conn; conn = client_inst->conn;
CHECKIF(conn == NULL) { CHECKIF(conn == NULL) {
BT_DBG("Member[%d] conn was NULL", i); LOG_DBG("Member[%d] conn was NULL", i);
return -EINVAL; return -EINVAL;
} }
if (conn->state != BT_CONN_CONNECTED) { if (conn->state != BT_CONN_CONNECTED) {
BT_DBG("Member[%d] was not connected", i); LOG_DBG("Member[%d] was not connected", i);
return -ENOTCONN; return -ENOTCONN;
} }
svc_inst = lookup_instance_by_set_info(member, set_info); svc_inst = lookup_instance_by_set_info(member, set_info);
if (svc_inst == NULL) { if (svc_inst == NULL) {
BT_DBG("Member[%d] could not find matching instance for the set_info", LOG_DBG("Member[%d] could not find matching instance for the set_info", i);
i);
return -EINVAL; return -EINVAL;
} }
@ -1485,7 +1474,7 @@ static int verify_members(const struct bt_csip_set_coordinator_set_member **memb
zero_rank = true; zero_rank = true;
} else if (ranks[i] != 0 && zero_rank) { } else if (ranks[i] != 0 && zero_rank) {
/* all members in a set shall either use rank, or not use rank */ /* all members in a set shall either use rank, or not use rank */
BT_DBG("Found mix of 0 and non-0 ranks"); LOG_DBG("Found mix of 0 and non-0 ranks");
return -EINVAL; return -EINVAL;
} }
@ -1493,9 +1482,9 @@ static int verify_members(const struct bt_csip_set_coordinator_set_member **memb
for (size_t j = 0U; j < i; j++) { for (size_t j = 0U; j < i; j++) {
if (ranks[j] == ranks[i]) { if (ranks[j] == ranks[i]) {
/* duplicate rank */ /* duplicate rank */
BT_DBG("Duplicate rank (%u) for members[%zu] " LOG_DBG("Duplicate rank (%u) for members[%zu] "
"and members[%zu]", "and members[%zu]",
ranks[i], i, j); ranks[i], i, j);
return -EINVAL; return -EINVAL;
} }
} }
@ -1513,13 +1502,13 @@ static int bt_csip_set_coordinator_get_lock_state(
int err; int err;
if (busy) { if (busy) {
BT_DBG("csip_set_coordinator busy"); LOG_DBG("csip_set_coordinator busy");
return -EBUSY; return -EBUSY;
} }
err = verify_members(members, count, set_info); err = verify_members(members, count, set_info);
if (err != 0) { if (err != 0) {
BT_DBG("Could not verify members: %d", err); LOG_DBG("Could not verify members: %d", err);
return err; return err;
} }
@ -1527,7 +1516,7 @@ static int bt_csip_set_coordinator_get_lock_state(
cur_inst = lookup_instance_by_set_info(active.members[0], active.info); cur_inst = lookup_instance_by_set_info(active.members[0], active.info);
if (cur_inst == NULL) { if (cur_inst == NULL) {
BT_DBG("Failed to lookup instance by set_info %p", active.info); LOG_DBG("Failed to lookup instance by set_info %p", active.info);
active_members_reset(); active_members_reset();
return -ENOENT; return -ENOENT;
@ -1570,13 +1559,13 @@ int bt_csip_set_coordinator_lock(
int err; int err;
CHECKIF(busy) { CHECKIF(busy) {
BT_DBG("csip_set_coordinator busy"); LOG_DBG("csip_set_coordinator busy");
return -EBUSY; return -EBUSY;
} }
err = verify_members(members, count, set_info); err = verify_members(members, count, set_info);
if (err != 0) { if (err != 0) {
BT_DBG("Could not verify members: %d", err); LOG_DBG("Could not verify members: %d", err);
return err; return err;
} }
@ -1584,7 +1573,7 @@ int bt_csip_set_coordinator_lock(
cur_inst = lookup_instance_by_set_info(active.members[0], active.info); cur_inst = lookup_instance_by_set_info(active.members[0], active.info);
if (cur_inst == NULL) { if (cur_inst == NULL) {
BT_DBG("Failed to lookup instance by set_info %p", active.info); LOG_DBG("Failed to lookup instance by set_info %p", active.info);
active_members_reset(); active_members_reset();
return -ENOENT; return -ENOENT;
@ -1606,13 +1595,13 @@ int bt_csip_set_coordinator_release(const struct bt_csip_set_coordinator_set_mem
int err; int err;
CHECKIF(busy) { CHECKIF(busy) {
BT_DBG("csip_set_coordinator busy"); LOG_DBG("csip_set_coordinator busy");
return -EBUSY; return -EBUSY;
} }
err = verify_members(members, count, set_info); err = verify_members(members, count, set_info);
if (err != 0) { if (err != 0) {
BT_DBG("Could not verify members: %d", err); LOG_DBG("Could not verify members: %d", err);
return err; return err;
} }
@ -1620,7 +1609,7 @@ int bt_csip_set_coordinator_release(const struct bt_csip_set_coordinator_set_mem
cur_inst = lookup_instance_by_set_info(active.members[0], active.info); cur_inst = lookup_instance_by_set_info(active.members[0], active.info);
if (cur_inst == NULL) { if (cur_inst == NULL) {
BT_DBG("Failed to lookup instance by set_info %p", active.info); LOG_DBG("Failed to lookup instance by set_info %p", active.info);
active_members_reset(); active_members_reset();
return -ENOENT; return -ENOENT;

View file

@ -32,11 +32,12 @@
#define BT_CSIP_SIH_HASH_SIZE 3 #define BT_CSIP_SIH_HASH_SIZE 3
#define CSIP_SET_LOCK_TIMER_VALUE K_SECONDS(60) #define CSIP_SET_LOCK_TIMER_VALUE K_SECONDS(60)
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_CSIP_SET_MEMBER)
#define LOG_MODULE_NAME bt_csip_set_member
#include "common/log.h"
#include "common/bt_str.h" #include "common/bt_str.h"
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_csip_set_member, CONFIG_BT_CSIP_SET_MEMBER_LOG_LEVEL);
struct bt_csip_set_member_svc_inst { struct bt_csip_set_member_svc_inst {
struct bt_csip_set_sirk set_sirk; struct bt_csip_set_sirk set_sirk;
uint8_t set_size; uint8_t set_size;
@ -155,7 +156,7 @@ static int sirk_encrypt(struct bt_conn *conn,
sys_mem_swap(test_k, 16); sys_mem_swap(test_k, 16);
swapped = true; swapped = true;
} }
BT_DBG("Encrypting test SIRK"); LOG_DBG("Encrypting test SIRK");
k = test_k; k = test_k;
} else { } else {
k = conn->le.keys->ltk.val; k = conn->le.keys->ltk.val;
@ -211,14 +212,14 @@ int bt_csip_set_member_generate_rsi(const struct bt_csip_set_member_svc_inst *sv
res = generate_prand(&prand); res = generate_prand(&prand);
if (res != 0) { if (res != 0) {
BT_WARN("Could not generate new prand"); LOG_WRN("Could not generate new prand");
return res; return res;
} }
} }
res = bt_csip_sih(svc_inst->set_sirk.value, prand, &hash); res = bt_csip_sih(svc_inst->set_sirk.value, prand, &hash);
if (res != 0) { if (res != 0) {
BT_WARN("Could not generate new RSI"); LOG_WRN("Could not generate new RSI");
return res; return res;
} }
@ -252,7 +253,7 @@ static ssize_t read_set_sirk(struct bt_conn *conn,
err = sirk_encrypt(conn, &svc_inst->set_sirk, err = sirk_encrypt(conn, &svc_inst->set_sirk,
&enc_sirk); &enc_sirk);
if (err != 0) { if (err != 0) {
BT_ERR("Could not encrypt SIRK: %d", LOG_ERR("Could not encrypt SIRK: %d",
err); err);
gatt_err = BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); gatt_err = BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
} else { } else {
@ -266,7 +267,7 @@ static ssize_t read_set_sirk(struct bt_conn *conn,
} else if (cb_rsp == BT_CSIP_READ_SIRK_REQ_RSP_OOB_ONLY) { } else if (cb_rsp == BT_CSIP_READ_SIRK_REQ_RSP_OOB_ONLY) {
gatt_err = BT_GATT_ERR(BT_CSIP_ERROR_SIRK_OOB_ONLY); gatt_err = BT_GATT_ERR(BT_CSIP_ERROR_SIRK_OOB_ONLY);
} else { } else {
BT_ERR("Invalid callback response: %u", cb_rsp); LOG_ERR("Invalid callback response: %u", cb_rsp);
gatt_err = BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); gatt_err = BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
} }
@ -278,7 +279,7 @@ static ssize_t read_set_sirk(struct bt_conn *conn,
} }
BT_DBG("Set sirk %sencrypted", LOG_DBG("Set sirk %sencrypted",
sirk->type == BT_CSIP_SIRK_TYPE_PLAIN ? "not " : ""); sirk->type == BT_CSIP_SIRK_TYPE_PLAIN ? "not " : "");
LOG_HEXDUMP_DBG(svc_inst->set_sirk.value, LOG_HEXDUMP_DBG(svc_inst->set_sirk.value,
sizeof(svc_inst->set_sirk.value), "Set SIRK"); sizeof(svc_inst->set_sirk.value), "Set SIRK");
@ -289,7 +290,7 @@ static ssize_t read_set_sirk(struct bt_conn *conn,
static void set_sirk_cfg_changed(const struct bt_gatt_attr *attr, static void set_sirk_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_set_size(struct bt_conn *conn, static ssize_t read_set_size(struct bt_conn *conn,
@ -298,7 +299,7 @@ static ssize_t read_set_size(struct bt_conn *conn,
{ {
struct bt_csip_set_member_svc_inst *svc_inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_csip_set_member_svc_inst *svc_inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("%u", svc_inst->set_size); LOG_DBG("%u", svc_inst->set_size);
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
&svc_inst->set_size, &svc_inst->set_size,
@ -308,7 +309,7 @@ static ssize_t read_set_size(struct bt_conn *conn,
static void set_size_cfg_changed(const struct bt_gatt_attr *attr, static void set_size_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_set_lock(struct bt_conn *conn, static ssize_t read_set_lock(struct bt_conn *conn,
@ -317,7 +318,7 @@ static ssize_t read_set_lock(struct bt_conn *conn,
{ {
struct bt_csip_set_member_svc_inst *svc_inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_csip_set_member_svc_inst *svc_inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("%u", svc_inst->set_lock); LOG_DBG("%u", svc_inst->set_lock);
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
&svc_inst->set_lock, &svc_inst->set_lock,
@ -372,7 +373,7 @@ static uint8_t set_lock(struct bt_conn *conn,
(void)k_work_cancel_delayable(&svc_inst->set_lock_timer); (void)k_work_cancel_delayable(&svc_inst->set_lock_timer);
} }
BT_DBG("%u", svc_inst->set_lock); LOG_DBG("%u", svc_inst->set_lock);
if (notify) { if (notify) {
/* /*
@ -420,7 +421,7 @@ static ssize_t write_set_lock(struct bt_conn *conn,
static void set_lock_cfg_changed(const struct bt_gatt_attr *attr, static void set_lock_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_rank(struct bt_conn *conn, const struct bt_gatt_attr *attr, static ssize_t read_rank(struct bt_conn *conn, const struct bt_gatt_attr *attr,
@ -428,7 +429,7 @@ static ssize_t read_rank(struct bt_conn *conn, const struct bt_gatt_attr *attr,
{ {
struct bt_csip_set_member_svc_inst *svc_inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_csip_set_member_svc_inst *svc_inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("%u", svc_inst->rank); LOG_DBG("%u", svc_inst->rank);
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
&svc_inst->rank, &svc_inst->rank,
@ -445,7 +446,7 @@ static void set_lock_timer_handler(struct k_work *work)
svc_inst = CONTAINER_OF(delayable, struct bt_csip_set_member_svc_inst, svc_inst = CONTAINER_OF(delayable, struct bt_csip_set_member_svc_inst,
set_lock_timer); set_lock_timer);
BT_DBG("Lock timeout, releasing"); LOG_DBG("Lock timeout, releasing");
svc_inst->set_lock = BT_CSIP_RELEASE_VALUE; svc_inst->set_lock = BT_CSIP_RELEASE_VALUE;
notify_clients(svc_inst, NULL); notify_clients(svc_inst, NULL);
@ -488,7 +489,7 @@ static void csip_security_changed(struct bt_conn *conn, bt_security_t level,
static void handle_csip_disconnect(struct bt_csip_set_member_svc_inst *svc_inst, static void handle_csip_disconnect(struct bt_csip_set_member_svc_inst *svc_inst,
struct bt_conn *conn) struct bt_conn *conn)
{ {
BT_DBG("Non-bonded device"); LOG_DBG("Non-bonded device");
if (is_last_client_to_write(svc_inst, conn)) { if (is_last_client_to_write(svc_inst, conn)) {
(void)memset(&svc_inst->lock_client_addr, 0, (void)memset(&svc_inst->lock_client_addr, 0,
sizeof(svc_inst->lock_client_addr)); sizeof(svc_inst->lock_client_addr));
@ -519,8 +520,7 @@ static void handle_csip_disconnect(struct bt_csip_set_member_svc_inst *svc_inst,
static void csip_disconnected(struct bt_conn *conn, uint8_t reason) static void csip_disconnected(struct bt_conn *conn, uint8_t reason)
{ {
BT_DBG("Disconnected: %s (reason %u)", LOG_DBG("Disconnected: %s (reason %u)", bt_addr_le_str(bt_conn_get_dst(conn)), reason);
bt_addr_le_str(bt_conn_get_dst(conn)), reason);
for (int i = 0; i < ARRAY_SIZE(svc_insts); i++) { for (int i = 0; i < ARRAY_SIZE(svc_insts); i++) {
handle_csip_disconnect(&svc_insts[i], conn); handle_csip_disconnect(&svc_insts[i], conn);
@ -581,7 +581,7 @@ static void handle_csip_auth_complete(struct bt_csip_set_member_svc_inst *svc_in
oldest->active = true; oldest->active = true;
oldest->age = svc_inst->age_counter++; oldest->age = svc_inst->age_counter++;
#else #else
BT_WARN("Could not add device to pending notification list"); LOG_WRN("Could not add device to pending notification list");
#endif /* CONFIG_BT_KEYS_OVERWRITE_OLDEST */ #endif /* CONFIG_BT_KEYS_OVERWRITE_OLDEST */
} }
@ -599,8 +599,8 @@ static void auth_pairing_complete(struct bt_conn *conn, bool bonded)
* the oldest entry, following the behavior of the key storage. * the oldest entry, following the behavior of the key storage.
*/ */
BT_DBG("%s paired (%sbonded)", LOG_DBG("%s paired (%sbonded)", bt_addr_le_str(bt_conn_get_dst(conn)),
bt_addr_le_str(bt_conn_get_dst(conn)), bonded ? "" : "not "); bonded ? "" : "not ");
if (!bonded) { if (!bonded) {
return; return;
@ -677,19 +677,19 @@ void *bt_csip_set_member_svc_decl_get(const struct bt_csip_set_member_svc_inst *
static bool valid_register_param(const struct bt_csip_set_member_register_param *param) static bool valid_register_param(const struct bt_csip_set_member_register_param *param)
{ {
if (param->lockable && param->rank == 0) { if (param->lockable && param->rank == 0) {
BT_DBG("Rank cannot be 0 if service is lockable"); LOG_DBG("Rank cannot be 0 if service is lockable");
return false; return false;
} }
if (param->rank > 0 && param->rank > param->set_size) { if (param->rank > 0 && param->rank > param->set_size) {
BT_DBG("Invalid rank: %u (shall be less than set_size: %u)", LOG_DBG("Invalid rank: %u (shall be less than set_size: %u)", param->set_size,
param->set_size, param->set_size); param->set_size);
return false; return false;
} }
#if CONFIG_BT_CSIP_SET_MEMBER_MAX_INSTANCE_COUNT > 1 #if CONFIG_BT_CSIP_SET_MEMBER_MAX_INSTANCE_COUNT > 1
if (param->parent == NULL) { if (param->parent == NULL) {
BT_DBG("Parent service not provided"); LOG_DBG("Parent service not provided");
return false; return false;
} }
#endif /* CONFIG_BT_CSIP_SET_MEMBER_MAX_INSTANCE_COUNT > 1 */ #endif /* CONFIG_BT_CSIP_SET_MEMBER_MAX_INSTANCE_COUNT > 1 */
@ -709,12 +709,12 @@ int bt_csip_set_member_register(const struct bt_csip_set_member_register_param *
} }
CHECKIF(param == NULL) { CHECKIF(param == NULL) {
BT_DBG("NULL param"); LOG_DBG("NULL param");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!valid_register_param(param)) { CHECKIF(!valid_register_param(param)) {
BT_DBG("Invalid parameters"); LOG_DBG("Invalid parameters");
return -EINVAL; return -EINVAL;
} }
@ -727,7 +727,7 @@ int bt_csip_set_member_register(const struct bt_csip_set_member_register_param *
err = bt_gatt_service_register(inst->service_p); err = bt_gatt_service_register(inst->service_p);
if (err != 0) { if (err != 0) {
BT_DBG("CSIS service register failed: %d", err); LOG_DBG("CSIS service register failed: %d", err);
return err; return err;
} }
@ -747,7 +747,7 @@ int bt_csip_set_member_register(const struct bt_csip_set_member_register_param *
(void)memcpy(inst->set_sirk.value, test_sirk, (void)memcpy(inst->set_sirk.value, test_sirk,
sizeof(test_sirk)); sizeof(test_sirk));
BT_DBG("CSIP SIRK was overwritten by sample data SIRK"); LOG_DBG("CSIP SIRK was overwritten by sample data SIRK");
} else { } else {
(void)memcpy(inst->set_sirk.value, param->set_sirk, (void)memcpy(inst->set_sirk.value, param->set_sirk,
sizeof(inst->set_sirk.value)); sizeof(inst->set_sirk.value));

View file

@ -21,9 +21,9 @@
#include "audio_internal.h" #include "audio_internal.h"
#include "has_internal.h" #include "has_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HAS) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_has
#include "common/log.h" LOG_MODULE_REGISTER(bt_has, CONFIG_BT_HAS_LOG_LEVEL);
/* The service allows operations with paired devices only. /* The service allows operations with paired devices only.
* For now, the context is kept for connected devices only, thus the number of contexts is * For now, the context is kept for connected devices only, thus the number of contexts is
@ -40,7 +40,7 @@ static ssize_t write_control_point(struct bt_conn *conn, const struct bt_gatt_at
static ssize_t read_active_preset_index(struct bt_conn *conn, const struct bt_gatt_attr *attr, static ssize_t read_active_preset_index(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset) void *buf, uint16_t len, uint16_t offset)
{ {
BT_DBG("conn %p attr %p offset %d", (void *)conn, attr, offset); LOG_DBG("conn %p attr %p offset %d", (void *)conn, attr, offset);
if (offset > sizeof(has.active_index)) { if (offset > sizeof(has.active_index)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
@ -52,14 +52,14 @@ static ssize_t read_active_preset_index(struct bt_conn *conn, const struct bt_ga
static void ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("attr %p value 0x%04x", attr, value); LOG_DBG("attr %p value 0x%04x", attr, value);
} }
#endif /* CONFIG_BT_HAS_PRESET_SUPPORT */ #endif /* CONFIG_BT_HAS_PRESET_SUPPORT */
static ssize_t read_features(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, static ssize_t read_features(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset) uint16_t len, uint16_t offset)
{ {
BT_DBG("conn %p attr %p offset %d", (void *)conn, attr, offset); LOG_DBG("conn %p attr %p offset %d", (void *)conn, attr, offset);
if (offset > sizeof(has.features)) { if (offset > sizeof(has.features)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
@ -198,7 +198,7 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_
{ {
struct has_client *client; struct has_client *client;
BT_DBG("conn %p level %d err %d", (void *)conn, level, err); LOG_DBG("conn %p level %d err %d", (void *)conn, level, err);
if (err != BT_SECURITY_ERR_SUCCESS) { if (err != BT_SECURITY_ERR_SUCCESS) {
return; return;
@ -206,7 +206,7 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_
client = client_get_or_new(conn); client = client_get_or_new(conn);
if (unlikely(!client)) { if (unlikely(!client)) {
BT_ERR("Failed to allocate client"); LOG_ERR("Failed to allocate client");
return; return;
} }
@ -224,7 +224,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
{ {
struct has_client *client; struct has_client *client;
BT_DBG("conn %p err %d", conn, err); LOG_DBG("conn %p err %d", conn, err);
if (err != 0 || !bt_addr_le_is_bonded(conn->id, &conn->le.dst)) { if (err != 0 || !bt_addr_le_is_bonded(conn->id, &conn->le.dst)) {
return; return;
@ -232,7 +232,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
client = client_get_or_new(conn); client = client_get_or_new(conn);
if (unlikely(!client)) { if (unlikely(!client)) {
BT_ERR("Failed to allocate client"); LOG_ERR("Failed to allocate client");
return; return;
} }
@ -245,7 +245,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
{ {
struct has_client *client; struct has_client *client;
BT_DBG("conn %p reason %d", (void *)conn, reason); LOG_DBG("conn %p reason %d", (void *)conn, reason);
client = client_get(conn); client = client_get(conn);
if (client) { if (client) {
@ -347,7 +347,7 @@ static void control_point_ntf_complete(struct bt_conn *conn, void *user_data)
{ {
struct has_client *client = client_get(conn); struct has_client *client = client_get(conn);
BT_DBG("conn %p\n", (void *)conn); LOG_DBG("conn %p\n", (void *)conn);
/* Resubmit if needed */ /* Resubmit if needed */
if (client != NULL && if (client != NULL &&
@ -362,7 +362,7 @@ static void control_point_ind_complete(struct bt_conn *conn,
{ {
if (err) { if (err) {
/* TODO: Handle error somehow */ /* TODO: Handle error somehow */
BT_ERR("conn %p err 0x%02x\n", (void *)conn, err); LOG_ERR("conn %p err 0x%02x\n", (void *)conn, err);
} }
control_point_ntf_complete(conn, NULL); control_point_ntf_complete(conn, NULL);
@ -430,7 +430,7 @@ static int bt_has_cp_read_preset_rsp(struct has_client *client, const struct has
NET_BUF_SIMPLE_DEFINE(buf, sizeof(*hdr) + sizeof(*rsp) + BT_HAS_PRESET_NAME_MAX); NET_BUF_SIMPLE_DEFINE(buf, sizeof(*hdr) + sizeof(*rsp) + BT_HAS_PRESET_NAME_MAX);
BT_DBG("conn %p preset %p is_last 0x%02x", (void *)client->conn, preset, is_last); LOG_DBG("conn %p preset %p is_last 0x%02x", (void *)client->conn, preset, is_last);
hdr = net_buf_simple_add(&buf, sizeof(*hdr)); hdr = net_buf_simple_add(&buf, sizeof(*hdr));
hdr->opcode = BT_HAS_OP_READ_PRESET_RSP; hdr->opcode = BT_HAS_OP_READ_PRESET_RSP;
@ -530,7 +530,7 @@ static void process_control_point_work(struct k_work *work)
err = bt_has_cp_read_preset_rsp(client, preset, is_last); err = bt_has_cp_read_preset_rsp(client, preset, is_last);
if (err) { if (err) {
BT_ERR("bt_has_cp_read_preset_rsp failed (err %d)", err); LOG_ERR("bt_has_cp_read_preset_rsp failed (err %d)", err);
} }
if (err || is_last) { if (err || is_last) {
@ -558,7 +558,7 @@ static void process_control_point_work(struct k_work *work)
err = bt_has_cp_generic_update(client, preset, is_last); err = bt_has_cp_generic_update(client, preset, is_last);
if (err) { if (err) {
BT_ERR("bt_has_cp_read_preset_rsp failed (err %d)", err); LOG_ERR("bt_has_cp_read_preset_rsp failed (err %d)", err);
} }
if (err || is_last) { if (err || is_last) {
@ -594,7 +594,7 @@ static uint8_t handle_read_preset_req(struct bt_conn *conn, struct net_buf_simpl
req = net_buf_simple_pull_mem(buf, sizeof(*req)); req = net_buf_simple_pull_mem(buf, sizeof(*req));
BT_DBG("start_index %d num_presets %d", req->start_index, req->num_presets); LOG_DBG("start_index %d num_presets %d", req->start_index, req->num_presets);
/* Abort if there is no preset in requested index range */ /* Abort if there is no preset in requested index range */
preset_foreach(req->start_index, BT_HAS_PRESET_INDEX_LAST, preset_found, &preset); preset_foreach(req->start_index, BT_HAS_PRESET_INDEX_LAST, preset_found, &preset);
@ -621,7 +621,7 @@ static int set_preset_name(uint8_t index, const char *name, size_t len)
{ {
struct has_preset *preset = NULL; struct has_preset *preset = NULL;
BT_DBG("index %d name_len %zu", index, len); LOG_DBG("index %d name_len %zu", index, len);
if (len < BT_HAS_PRESET_NAME_MIN || len > BT_HAS_PRESET_NAME_MAX) { if (len < BT_HAS_PRESET_NAME_MIN || len > BT_HAS_PRESET_NAME_MAX) {
return -EINVAL; return -EINVAL;
@ -846,8 +846,8 @@ static uint8_t handle_control_point_op(struct bt_conn *conn, struct net_buf_simp
hdr = net_buf_simple_pull_mem(buf, sizeof(*hdr)); hdr = net_buf_simple_pull_mem(buf, sizeof(*hdr));
BT_DBG("conn %p opcode %s (0x%02x)", (void *)conn, bt_has_op_str(hdr->opcode), LOG_DBG("conn %p opcode %s (0x%02x)", (void *)conn, bt_has_op_str(hdr->opcode),
hdr->opcode); hdr->opcode);
switch (hdr->opcode) { switch (hdr->opcode) {
case BT_HAS_OP_READ_PRESET_REQ: case BT_HAS_OP_READ_PRESET_REQ:
@ -892,8 +892,8 @@ static ssize_t write_control_point(struct bt_conn *conn, const struct bt_gatt_at
struct net_buf_simple buf; struct net_buf_simple buf;
uint8_t err; uint8_t err;
BT_DBG("conn %p attr %p data %p len %d offset %d flags 0x%02x", (void *)conn, attr, data, LOG_DBG("conn %p attr %p data %p len %d offset %d flags 0x%02x", (void *)conn, attr, data,
len, offset, flags); len, offset, flags);
if (offset > 0) { if (offset > 0) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
@ -907,7 +907,7 @@ static ssize_t write_control_point(struct bt_conn *conn, const struct bt_gatt_at
err = handle_control_point_op(conn, &buf); err = handle_control_point_op(conn, &buf);
if (err) { if (err) {
BT_WARN("err 0x%02x", err); LOG_WRN("err 0x%02x", err);
return BT_GATT_ERR(err); return BT_GATT_ERR(err);
} }
@ -920,38 +920,38 @@ int bt_has_preset_register(const struct bt_has_preset_register_param *param)
size_t name_len; size_t name_len;
CHECKIF(param == NULL) { CHECKIF(param == NULL) {
BT_ERR("param is NULL"); LOG_ERR("param is NULL");
return -EINVAL; return -EINVAL;
} }
CHECKIF(param->index == BT_HAS_PRESET_INDEX_NONE) { CHECKIF(param->index == BT_HAS_PRESET_INDEX_NONE) {
BT_ERR("param->index is invalid"); LOG_ERR("param->index is invalid");
return -EINVAL; return -EINVAL;
} }
CHECKIF(param->name == NULL) { CHECKIF(param->name == NULL) {
BT_ERR("param->name is NULL"); LOG_ERR("param->name is NULL");
return -EINVAL; return -EINVAL;
} }
name_len = strlen(param->name); name_len = strlen(param->name);
CHECKIF(name_len < BT_HAS_PRESET_NAME_MIN) { CHECKIF(name_len < BT_HAS_PRESET_NAME_MIN) {
BT_ERR("param->name is too short (%zu < %u)", name_len, BT_HAS_PRESET_NAME_MIN); LOG_ERR("param->name is too short (%zu < %u)", name_len, BT_HAS_PRESET_NAME_MIN);
return -EINVAL; return -EINVAL;
} }
CHECKIF(name_len > BT_HAS_PRESET_NAME_MAX) { CHECKIF(name_len > BT_HAS_PRESET_NAME_MAX) {
BT_WARN("param->name is too long (%zu > %u)", name_len, BT_HAS_PRESET_NAME_MAX); LOG_WRN("param->name is too long (%zu > %u)", name_len, BT_HAS_PRESET_NAME_MAX);
} }
CHECKIF(param->ops == NULL) { CHECKIF(param->ops == NULL) {
BT_ERR("param->ops is NULL"); LOG_ERR("param->ops is NULL");
return -EINVAL; return -EINVAL;
} }
CHECKIF(param->ops->select == NULL) { CHECKIF(param->ops->select == NULL) {
BT_ERR("param->ops->select is NULL"); LOG_ERR("param->ops->select is NULL");
return -EINVAL; return -EINVAL;
} }
@ -976,7 +976,7 @@ int bt_has_preset_unregister(uint8_t index)
sizeof(struct bt_has_cp_preset_changed) + sizeof(uint8_t)); sizeof(struct bt_has_cp_preset_changed) + sizeof(uint8_t));
CHECKIF(index == BT_HAS_PRESET_INDEX_NONE) { CHECKIF(index == BT_HAS_PRESET_INDEX_NONE) {
BT_ERR("index is invalid"); LOG_ERR("index is invalid");
return -EINVAL; return -EINVAL;
} }
@ -998,7 +998,7 @@ int bt_has_preset_available(uint8_t index)
struct has_preset *preset = NULL; struct has_preset *preset = NULL;
CHECKIF(index == BT_HAS_PRESET_INDEX_NONE) { CHECKIF(index == BT_HAS_PRESET_INDEX_NONE) {
BT_ERR("index is invalid"); LOG_ERR("index is invalid");
return -EINVAL; return -EINVAL;
} }
@ -1028,7 +1028,7 @@ int bt_has_preset_unavailable(uint8_t index)
struct has_preset *preset = NULL; struct has_preset *preset = NULL;
CHECKIF(index == BT_HAS_PRESET_INDEX_NONE) { CHECKIF(index == BT_HAS_PRESET_INDEX_NONE) {
BT_ERR("index is invalid"); LOG_ERR("index is invalid");
return -EINVAL; return -EINVAL;
} }

View file

@ -15,9 +15,9 @@
#include "has_internal.h" #include "has_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HAS_CLIENT) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_has_client
#include "../common/log.h" LOG_MODULE_REGISTER(bt_has_client, CONFIG_BT_HAS_CLIENT_LOG_LEVEL);
#define HAS_INST(_has) CONTAINER_OF(_has, struct has_inst, has) #define HAS_INST(_has) CONTAINER_OF(_has, struct has_inst, has)
#define HANDLE_IS_VALID(handle) ((handle) != 0x0000) #define HANDLE_IS_VALID(handle) ((handle) != 0x0000)
@ -95,17 +95,17 @@ static void handle_read_preset_rsp(struct has_inst *inst, struct net_buf_simple
char name[BT_HAS_PRESET_NAME_MAX + 1]; /* + 1 byte for null-terminator */ char name[BT_HAS_PRESET_NAME_MAX + 1]; /* + 1 byte for null-terminator */
size_t name_len; size_t name_len;
BT_DBG("conn %p buf %p", (void *)inst->conn, buf); LOG_DBG("conn %p buf %p", (void *)inst->conn, buf);
if (buf->len < sizeof(*pdu)) { if (buf->len < sizeof(*pdu)) {
BT_ERR("malformed PDU"); LOG_ERR("malformed PDU");
return; return;
} }
pdu = net_buf_simple_pull_mem(buf, sizeof(*pdu)); pdu = net_buf_simple_pull_mem(buf, sizeof(*pdu));
if (pdu->is_last > BT_HAS_IS_LAST) { if (pdu->is_last > BT_HAS_IS_LAST) {
BT_WARN("unexpected is_last value 0x%02x", pdu->is_last); LOG_WRN("unexpected is_last value 0x%02x", pdu->is_last);
} }
record.index = pdu->index; record.index = pdu->index;
@ -114,7 +114,7 @@ static void handle_read_preset_rsp(struct has_inst *inst, struct net_buf_simple
name_len = buf->len + 1; /* + 1 byte for NULL terminator */ name_len = buf->len + 1; /* + 1 byte for NULL terminator */
if (name_len > ARRAY_SIZE(name)) { if (name_len > ARRAY_SIZE(name)) {
BT_WARN("name is too long (%zu > %u)", buf->len, BT_HAS_PRESET_NAME_MAX); LOG_WRN("name is too long (%zu > %u)", buf->len, BT_HAS_PRESET_NAME_MAX);
name_len = ARRAY_SIZE(name); name_len = ARRAY_SIZE(name);
} }
@ -132,7 +132,7 @@ static void handle_generic_update(struct has_inst *inst, struct net_buf_simple *
size_t name_len; size_t name_len;
if (buf->len < sizeof(*pdu)) { if (buf->len < sizeof(*pdu)) {
BT_ERR("malformed PDU"); LOG_ERR("malformed PDU");
return; return;
} }
@ -144,7 +144,7 @@ static void handle_generic_update(struct has_inst *inst, struct net_buf_simple *
name_len = buf->len + 1; /* + 1 byte for NULL terminator */ name_len = buf->len + 1; /* + 1 byte for NULL terminator */
if (name_len > ARRAY_SIZE(name)) { if (name_len > ARRAY_SIZE(name)) {
BT_WARN("name is too long (%zu > %u)", buf->len, BT_HAS_PRESET_NAME_MAX); LOG_WRN("name is too long (%zu > %u)", buf->len, BT_HAS_PRESET_NAME_MAX);
name_len = ARRAY_SIZE(name); name_len = ARRAY_SIZE(name);
} }
@ -157,7 +157,7 @@ static void handle_generic_update(struct has_inst *inst, struct net_buf_simple *
static void handle_preset_deleted(struct has_inst *inst, struct net_buf_simple *buf, bool is_last) static void handle_preset_deleted(struct has_inst *inst, struct net_buf_simple *buf, bool is_last)
{ {
if (buf->len < sizeof(uint8_t)) { if (buf->len < sizeof(uint8_t)) {
BT_ERR("malformed PDU"); LOG_ERR("malformed PDU");
return; return;
} }
@ -168,7 +168,7 @@ static void handle_preset_availability(struct has_inst *inst, struct net_buf_sim
bool available, bool is_last) bool available, bool is_last)
{ {
if (buf->len < sizeof(uint8_t)) { if (buf->len < sizeof(uint8_t)) {
BT_ERR("malformed PDU"); LOG_ERR("malformed PDU");
return; return;
} }
@ -180,17 +180,17 @@ static void handle_preset_changed(struct has_inst *inst, struct net_buf_simple *
{ {
const struct bt_has_cp_preset_changed *pdu; const struct bt_has_cp_preset_changed *pdu;
BT_DBG("conn %p buf %p", (void *)inst->conn, buf); LOG_DBG("conn %p buf %p", (void *)inst->conn, buf);
if (buf->len < sizeof(*pdu)) { if (buf->len < sizeof(*pdu)) {
BT_ERR("malformed PDU"); LOG_ERR("malformed PDU");
return; return;
} }
pdu = net_buf_simple_pull_mem(buf, sizeof(*pdu)); pdu = net_buf_simple_pull_mem(buf, sizeof(*pdu));
if (pdu->is_last > BT_HAS_IS_LAST) { if (pdu->is_last > BT_HAS_IS_LAST) {
BT_WARN("unexpected is_last 0x%02x", pdu->is_last); LOG_WRN("unexpected is_last 0x%02x", pdu->is_last);
} }
switch (pdu->change_id) { switch (pdu->change_id) {
@ -215,7 +215,7 @@ static void handle_preset_changed(struct has_inst *inst, struct net_buf_simple *
} }
return; return;
default: default:
BT_WARN("unknown change_id 0x%02x", pdu->change_id); LOG_WRN("unknown change_id 0x%02x", pdu->change_id);
} }
} }
@ -227,7 +227,7 @@ static uint8_t control_point_notify_cb(struct bt_conn *conn,
struct net_buf_simple buf; struct net_buf_simple buf;
struct has_inst *inst; struct has_inst *inst;
BT_DBG("conn %p params %p data %p len %u", (void *)conn, params, data, len); LOG_DBG("conn %p params %p data %p len %u", (void *)conn, params, data, len);
if (!conn) { /* Unpaired, continue receiving notifications */ if (!conn) { /* Unpaired, continue receiving notifications */
return BT_GATT_ITER_CONTINUE; return BT_GATT_ITER_CONTINUE;
@ -267,7 +267,7 @@ static uint8_t control_point_notify_cb(struct bt_conn *conn,
static void discover_complete(struct has_inst *inst) static void discover_complete(struct has_inst *inst)
{ {
BT_DBG("conn %p", (void *)inst->conn); LOG_DBG("conn %p", (void *)inst->conn);
atomic_clear_bit(inst->flags, HAS_DISCOVER_IN_PROGRESS); atomic_clear_bit(inst->flags, HAS_DISCOVER_IN_PROGRESS);
@ -284,7 +284,7 @@ static void discover_complete(struct has_inst *inst)
static void discover_failed(struct bt_conn *conn, int err) static void discover_failed(struct bt_conn *conn, int err)
{ {
BT_DBG("conn %p", (void *)conn); LOG_DBG("conn %p", (void *)conn);
client_cb->discover(conn, err, NULL, 0, 0); client_cb->discover(conn, err, NULL, 0, 0);
} }
@ -313,7 +313,7 @@ static void read_presets_req_cb(struct bt_conn *conn, uint8_t err,
__ASSERT(inst, "no instance for conn %p", (void *)conn); __ASSERT(inst, "no instance for conn %p", (void *)conn);
BT_DBG("conn %p err 0x%02x param %p", (void *)conn, err, params); LOG_DBG("conn %p err 0x%02x param %p", (void *)conn, err, params);
atomic_clear_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS); atomic_clear_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS);
@ -329,8 +329,8 @@ static int read_presets_req(struct has_inst *inst, uint8_t start_index, uint8_t
NET_BUF_SIMPLE_DEFINE(buf, sizeof(*hdr) + sizeof(*req)); NET_BUF_SIMPLE_DEFINE(buf, sizeof(*hdr) + sizeof(*req));
BT_DBG("conn %p start_index 0x%02x num_presets %d", (void *)inst->conn, start_index, LOG_DBG("conn %p start_index 0x%02x num_presets %d", (void *)inst->conn, start_index,
num_presets); num_presets);
hdr = net_buf_simple_add(&buf, sizeof(*hdr)); hdr = net_buf_simple_add(&buf, sizeof(*hdr));
hdr->opcode = BT_HAS_OP_READ_PRESET_REQ; hdr->opcode = BT_HAS_OP_READ_PRESET_REQ;
@ -348,7 +348,7 @@ static void set_active_preset_cb(struct bt_conn *conn, uint8_t err,
__ASSERT(inst, "no instance for conn %p", (void *)conn); __ASSERT(inst, "no instance for conn %p", (void *)conn);
BT_DBG("conn %p err 0x%02x param %p", (void *)conn, err, params); LOG_DBG("conn %p err 0x%02x param %p", (void *)conn, err, params);
atomic_clear_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS); atomic_clear_bit(inst->flags, HAS_CP_OPERATION_IN_PROGRESS);
@ -364,7 +364,7 @@ static int preset_set(struct has_inst *inst, uint8_t opcode, uint8_t index)
NET_BUF_SIMPLE_DEFINE(buf, sizeof(*hdr) + sizeof(*req)); NET_BUF_SIMPLE_DEFINE(buf, sizeof(*hdr) + sizeof(*req));
BT_DBG("conn %p opcode 0x%02x index 0x%02x", (void *)inst->conn, opcode, index); LOG_DBG("conn %p opcode 0x%02x index 0x%02x", (void *)inst->conn, opcode, index);
hdr = net_buf_simple_add(&buf, sizeof(*hdr)); hdr = net_buf_simple_add(&buf, sizeof(*hdr));
hdr->opcode = opcode; hdr->opcode = opcode;
@ -380,7 +380,7 @@ static int preset_set_next_or_prev(struct has_inst *inst, uint8_t opcode)
NET_BUF_SIMPLE_DEFINE(buf, sizeof(*hdr)); NET_BUF_SIMPLE_DEFINE(buf, sizeof(*hdr));
BT_DBG("conn %p opcode 0x%02x", (void *)inst->conn, opcode); LOG_DBG("conn %p opcode 0x%02x", (void *)inst->conn, opcode);
hdr = net_buf_simple_add(&buf, sizeof(*hdr)); hdr = net_buf_simple_add(&buf, sizeof(*hdr));
hdr->opcode = opcode; hdr->opcode = opcode;
@ -397,7 +397,7 @@ static uint8_t active_index_update(struct has_inst *inst, const void *data, uint
inst->has.active_index = net_buf_simple_pull_u8(&buf); inst->has.active_index = net_buf_simple_pull_u8(&buf);
BT_DBG("conn %p index 0x%02x", (void *)inst->conn, inst->has.active_index); LOG_DBG("conn %p index 0x%02x", (void *)inst->conn, inst->has.active_index);
return prev; return prev;
} }
@ -409,7 +409,7 @@ static uint8_t active_preset_notify_cb(struct bt_conn *conn,
struct has_inst *inst; struct has_inst *inst;
uint8_t prev; uint8_t prev;
BT_DBG("conn %p params %p data %p len %u", (void *)conn, params, data, len); LOG_DBG("conn %p params %p data %p len %u", (void *)conn, params, data, len);
if (!conn) { if (!conn) {
/* Unpaired, stop receiving notifications from device */ /* Unpaired, stop receiving notifications from device */
@ -457,7 +457,7 @@ static void active_index_subscribe_cb(struct bt_conn *conn, uint8_t att_err,
__ASSERT(inst, "no instance for conn %p", (void *)conn); __ASSERT(inst, "no instance for conn %p", (void *)conn);
BT_DBG("conn %p att_err 0x%02x params %p", (void *)inst->conn, att_err, params); LOG_DBG("conn %p att_err 0x%02x params %p", (void *)inst->conn, att_err, params);
if (att_err != BT_ATT_ERR_SUCCESS) { if (att_err != BT_ATT_ERR_SUCCESS) {
/* Cleanup instance so that it can be reused */ /* Cleanup instance so that it can be reused */
@ -471,7 +471,7 @@ static void active_index_subscribe_cb(struct bt_conn *conn, uint8_t att_err,
static int active_index_subscribe(struct has_inst *inst, uint16_t value_handle) static int active_index_subscribe(struct has_inst *inst, uint16_t value_handle)
{ {
BT_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle); LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle);
inst->active_index_subscription.notify = active_preset_notify_cb; inst->active_index_subscription.notify = active_preset_notify_cb;
inst->active_index_subscription.subscribe = active_index_subscribe_cb; inst->active_index_subscription.subscribe = active_index_subscribe_cb;
@ -494,8 +494,8 @@ static uint8_t active_index_read_cb(struct bt_conn *conn, uint8_t att_err,
__ASSERT(inst, "no instance for conn %p", (void *)conn); __ASSERT(inst, "no instance for conn %p", (void *)conn);
BT_DBG("conn %p att_err 0x%02x params %p data %p len %u", (void *)conn, att_err, params, LOG_DBG("conn %p att_err 0x%02x params %p data %p len %u", (void *)conn, att_err, params,
data, len); data, len);
if (att_err != BT_ATT_ERR_SUCCESS || len == 0) { if (att_err != BT_ATT_ERR_SUCCESS || len == 0) {
goto fail; goto fail;
@ -505,7 +505,7 @@ static uint8_t active_index_read_cb(struct bt_conn *conn, uint8_t att_err,
err = active_index_subscribe(inst, params->by_uuid.start_handle); err = active_index_subscribe(inst, params->by_uuid.start_handle);
if (err) { if (err) {
BT_ERR("Subscribe failed (err %d)", err); LOG_ERR("Subscribe failed (err %d)", err);
goto fail; goto fail;
} }
@ -522,7 +522,7 @@ fail:
static int active_index_read(struct has_inst *inst) static int active_index_read(struct has_inst *inst)
{ {
BT_DBG("conn %p", (void *)inst->conn); LOG_DBG("conn %p", (void *)inst->conn);
(void)memset(&inst->params.read, 0, sizeof(inst->params.read)); (void)memset(&inst->params.read, 0, sizeof(inst->params.read));
@ -545,7 +545,7 @@ static void control_point_subscribe_cb(struct bt_conn *conn, uint8_t att_err,
__ASSERT(inst, "no instance for conn %p", (void *)conn); __ASSERT(inst, "no instance for conn %p", (void *)conn);
BT_DBG("conn %p att_err 0x%02x", (void *)inst->conn, att_err); LOG_DBG("conn %p att_err 0x%02x", (void *)inst->conn, att_err);
if (att_err != BT_ATT_ERR_SUCCESS) { if (att_err != BT_ATT_ERR_SUCCESS) {
goto fail; goto fail;
@ -553,7 +553,7 @@ static void control_point_subscribe_cb(struct bt_conn *conn, uint8_t att_err,
err = active_index_read(inst); err = active_index_read(inst);
if (err) { if (err) {
BT_ERR("Active Preset Index read failed (err %d)", err); LOG_ERR("Active Preset Index read failed (err %d)", err);
goto fail; goto fail;
} }
@ -569,7 +569,7 @@ fail:
static int control_point_subscribe(struct has_inst *inst, uint16_t value_handle, static int control_point_subscribe(struct has_inst *inst, uint16_t value_handle,
uint8_t properties) uint8_t properties)
{ {
BT_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle); LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle);
inst->control_point_subscription.notify = control_point_notify_cb; inst->control_point_subscription.notify = control_point_notify_cb;
inst->control_point_subscription.subscribe = control_point_subscribe_cb; inst->control_point_subscription.subscribe = control_point_subscribe_cb;
@ -597,10 +597,10 @@ static uint8_t control_point_discover_cb(struct bt_conn *conn, const struct bt_g
__ASSERT(inst, "no instance for conn %p", (void *)conn); __ASSERT(inst, "no instance for conn %p", (void *)conn);
BT_DBG("conn %p attr %p params %p", (void *)inst->conn, attr, params); LOG_DBG("conn %p attr %p params %p", (void *)inst->conn, attr, params);
if (!attr) { if (!attr) {
BT_INFO("Control Point not found"); LOG_INF("Control Point not found");
discover_complete(inst); discover_complete(inst);
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
@ -609,7 +609,7 @@ static uint8_t control_point_discover_cb(struct bt_conn *conn, const struct bt_g
err = control_point_subscribe(inst, chrc->value_handle, chrc->properties); err = control_point_subscribe(inst, chrc->value_handle, chrc->properties);
if (err) { if (err) {
BT_ERR("Subscribe failed (err %d)", err); LOG_ERR("Subscribe failed (err %d)", err);
/* Cleanup instance so that it can be reused */ /* Cleanup instance so that it can be reused */
inst_cleanup(inst); inst_cleanup(inst);
@ -622,7 +622,7 @@ static uint8_t control_point_discover_cb(struct bt_conn *conn, const struct bt_g
static int control_point_discover(struct has_inst *inst) static int control_point_discover(struct has_inst *inst)
{ {
BT_DBG("conn %p", (void *)inst->conn); LOG_DBG("conn %p", (void *)inst->conn);
(void)memset(&inst->params.discover, 0, sizeof(inst->params.discover)); (void)memset(&inst->params.discover, 0, sizeof(inst->params.discover));
@ -645,7 +645,7 @@ static void features_update(struct has_inst *inst, const void *data, uint16_t le
inst->has.features = net_buf_simple_pull_u8(&buf); inst->has.features = net_buf_simple_pull_u8(&buf);
BT_DBG("conn %p features 0x%02x", (void *)inst->conn, inst->has.features); LOG_DBG("conn %p features 0x%02x", (void *)inst->conn, inst->has.features);
} }
static uint8_t features_read_cb(struct bt_conn *conn, uint8_t att_err, static uint8_t features_read_cb(struct bt_conn *conn, uint8_t att_err,
@ -656,8 +656,8 @@ static uint8_t features_read_cb(struct bt_conn *conn, uint8_t att_err,
__ASSERT(inst, "no instance for conn %p", (void *)conn); __ASSERT(inst, "no instance for conn %p", (void *)conn);
BT_DBG("conn %p att_err 0x%02x params %p data %p len %u", (void *)conn, att_err, params, LOG_DBG("conn %p att_err 0x%02x params %p data %p len %u", (void *)conn, att_err, params,
data, len); data, len);
if (att_err != BT_ATT_ERR_SUCCESS || len == 0) { if (att_err != BT_ATT_ERR_SUCCESS || len == 0) {
goto fail; goto fail;
@ -673,7 +673,7 @@ static uint8_t features_read_cb(struct bt_conn *conn, uint8_t att_err,
err = control_point_discover(inst); err = control_point_discover(inst);
if (err) { if (err) {
BT_ERR("Control Point discover failed (err %d)", err); LOG_ERR("Control Point discover failed (err %d)", err);
goto fail; goto fail;
} }
@ -690,7 +690,7 @@ fail:
static int features_read(struct has_inst *inst, uint16_t value_handle) static int features_read(struct has_inst *inst, uint16_t value_handle)
{ {
BT_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle); LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle);
inst->params.read.func = features_read_cb; inst->params.read.func = features_read_cb;
inst->params.read.handle_count = 1u; inst->params.read.handle_count = 1u;
@ -708,7 +708,7 @@ static void features_subscribe_cb(struct bt_conn *conn, uint8_t att_err,
__ASSERT(inst, "no instance for conn %p", (void *)conn); __ASSERT(inst, "no instance for conn %p", (void *)conn);
BT_DBG("conn %p att_err 0x%02x params %p", (void *)inst->conn, att_err, params); LOG_DBG("conn %p att_err 0x%02x params %p", (void *)inst->conn, att_err, params);
if (att_err != BT_ATT_ERR_SUCCESS) { if (att_err != BT_ATT_ERR_SUCCESS) {
goto fail; goto fail;
@ -716,7 +716,7 @@ static void features_subscribe_cb(struct bt_conn *conn, uint8_t att_err,
err = features_read(inst, inst->features_subscription.value_handle); err = features_read(inst, inst->features_subscription.value_handle);
if (err) { if (err) {
BT_ERR("Read failed (err %d)", err); LOG_ERR("Read failed (err %d)", err);
goto fail; goto fail;
} }
@ -734,7 +734,7 @@ static uint8_t features_notify_cb(struct bt_conn *conn, struct bt_gatt_subscribe
{ {
struct has_inst *inst; struct has_inst *inst;
BT_DBG("conn %p params %p data %p len %u", (void *)conn, params, data, len); LOG_DBG("conn %p params %p data %p len %u", (void *)conn, params, data, len);
if (!conn) { if (!conn) {
/* Unpaired, stop receiving notifications from device */ /* Unpaired, stop receiving notifications from device */
@ -766,7 +766,7 @@ static uint8_t features_notify_cb(struct bt_conn *conn, struct bt_gatt_subscribe
static int features_subscribe(struct has_inst *inst, uint16_t value_handle) static int features_subscribe(struct has_inst *inst, uint16_t value_handle)
{ {
BT_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle); LOG_DBG("conn %p handle 0x%04x", (void *)inst->conn, value_handle);
inst->features_subscription.notify = features_notify_cb; inst->features_subscription.notify = features_notify_cb;
inst->features_subscription.subscribe = features_subscribe_cb; inst->features_subscription.subscribe = features_subscribe_cb;
@ -789,7 +789,7 @@ static uint8_t features_discover_cb(struct bt_conn *conn, const struct bt_gatt_a
__ASSERT(inst, "no instance for conn %p", (void *)conn); __ASSERT(inst, "no instance for conn %p", (void *)conn);
BT_DBG("conn %p attr %p params %p", (void *)conn, attr, params); LOG_DBG("conn %p attr %p params %p", (void *)conn, attr, params);
if (!attr) { if (!attr) {
err = -ENOENT; err = -ENOENT;
@ -802,13 +802,13 @@ static uint8_t features_discover_cb(struct bt_conn *conn, const struct bt_gatt_a
if (chrc->properties & BT_GATT_CHRC_NOTIFY) { if (chrc->properties & BT_GATT_CHRC_NOTIFY) {
err = features_subscribe(inst, chrc->value_handle); err = features_subscribe(inst, chrc->value_handle);
if (err) { if (err) {
BT_ERR("Subscribe failed (err %d)", err); LOG_ERR("Subscribe failed (err %d)", err);
goto fail; goto fail;
} }
} else { } else {
err = features_read(inst, chrc->value_handle); err = features_read(inst, chrc->value_handle);
if (err) { if (err) {
BT_ERR("Read failed (err %d)", err); LOG_ERR("Read failed (err %d)", err);
goto fail; goto fail;
} }
} }
@ -826,7 +826,7 @@ fail:
static int features_discover(struct has_inst *inst) static int features_discover(struct has_inst *inst)
{ {
BT_DBG("conn %p", (void *)inst->conn); LOG_DBG("conn %p", (void *)inst->conn);
(void)memset(&inst->params.discover, 0, sizeof(inst->params.discover)); (void)memset(&inst->params.discover, 0, sizeof(inst->params.discover));
@ -869,7 +869,7 @@ int bt_has_client_discover(struct bt_conn *conn)
struct has_inst *inst; struct has_inst *inst;
int err; int err;
BT_DBG("conn %p", (void *)conn); LOG_DBG("conn %p", (void *)conn);
CHECKIF(!conn || !client_cb || !client_cb->discover) { CHECKIF(!conn || !client_cb || !client_cb->discover) {
return -EINVAL; return -EINVAL;
@ -910,7 +910,7 @@ int bt_has_client_presets_read(struct bt_has *has, uint8_t start_index, uint8_t
struct has_inst *inst = HAS_INST(has); struct has_inst *inst = HAS_INST(has);
int err; int err;
BT_DBG("conn %p start_index 0x%02x count %d", (void *)inst->conn, start_index, count); LOG_DBG("conn %p start_index 0x%02x count %d", (void *)inst->conn, start_index, count);
if (!inst->conn) { if (!inst->conn) {
return -ENOTCONN; return -ENOTCONN;
@ -942,7 +942,7 @@ int bt_has_client_preset_set(struct bt_has *has, uint8_t index, bool sync)
struct has_inst *inst = HAS_INST(has); struct has_inst *inst = HAS_INST(has);
uint8_t opcode; uint8_t opcode;
BT_DBG("conn %p index 0x%02x", (void *)inst->conn, index); LOG_DBG("conn %p index 0x%02x", (void *)inst->conn, index);
if (!inst->conn) { if (!inst->conn) {
return -ENOTCONN; return -ENOTCONN;
@ -971,7 +971,7 @@ int bt_has_client_preset_next(struct bt_has *has, bool sync)
struct has_inst *inst = HAS_INST(has); struct has_inst *inst = HAS_INST(has);
uint8_t opcode; uint8_t opcode;
BT_DBG("conn %p sync %d", (void *)inst->conn, sync); LOG_DBG("conn %p sync %d", (void *)inst->conn, sync);
if (!inst->conn) { if (!inst->conn) {
return -ENOTCONN; return -ENOTCONN;
@ -996,7 +996,7 @@ int bt_has_client_preset_prev(struct bt_has *has, bool sync)
struct has_inst *inst = HAS_INST(has); struct has_inst *inst = HAS_INST(has);
uint8_t opcode; uint8_t opcode;
BT_DBG("conn %p sync %d", (void *)inst->conn, sync); LOG_DBG("conn %p sync %d", (void *)inst->conn, sync);
if (!inst->conn) { if (!inst->conn) {
return -ENOTCONN; return -ENOTCONN;

File diff suppressed because it is too large Load diff

View file

@ -26,9 +26,9 @@
#include "audio_internal.h" #include "audio_internal.h"
#include "media_proxy_internal.h" #include "media_proxy_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_MCS) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_mcs
#include "common/log.h" LOG_MODULE_REGISTER(bt_mcs, CONFIG_BT_MCS_LOG_LEVEL);
/* TODO Media control may send a large number of notifications for a /* TODO Media control may send a large number of notifications for a
* single command, so requires many buffers. * single command, so requires many buffers.
@ -51,7 +51,7 @@ static ssize_t read_player_name(struct bt_conn *conn,
{ {
const char *name = media_proxy_sctrl_get_player_name(); const char *name = media_proxy_sctrl_get_player_name();
BT_DBG("Player name read: %s", name); LOG_DBG("Player name read: %s", name);
return bt_gatt_attr_read(conn, attr, buf, len, offset, name, return bt_gatt_attr_read(conn, attr, buf, len, offset, name,
strlen(name)); strlen(name));
@ -60,7 +60,7 @@ static ssize_t read_player_name(struct bt_conn *conn,
static void player_name_cfg_changed(const struct bt_gatt_attr *attr, static void player_name_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
#ifdef CONFIG_BT_OTS #ifdef CONFIG_BT_OTS
@ -70,7 +70,7 @@ static ssize_t read_icon_id(struct bt_conn *conn,
{ {
uint64_t icon_id = media_proxy_sctrl_get_icon_id(); uint64_t icon_id = media_proxy_sctrl_get_icon_id();
BT_DBG_OBJ_ID("Icon object read: ", icon_id); LOG_DBG_OBJ_ID("Icon object read: ", icon_id);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &icon_id, return bt_gatt_attr_read(conn, attr, buf, len, offset, &icon_id,
BT_OTS_OBJ_ID_SIZE); BT_OTS_OBJ_ID_SIZE);
} }
@ -82,8 +82,7 @@ static ssize_t read_icon_url(struct bt_conn *conn,
{ {
const char *url = media_proxy_sctrl_get_icon_url(); const char *url = media_proxy_sctrl_get_icon_url();
BT_DBG("Icon URL read, offset: %d, len:%d, URL: %s", offset, len, LOG_DBG("Icon URL read, offset: %d, len:%d, URL: %s", offset, len, url);
url);
return bt_gatt_attr_read(conn, attr, buf, len, offset, url, return bt_gatt_attr_read(conn, attr, buf, len, offset, url,
strlen(url)); strlen(url));
@ -91,7 +90,7 @@ static ssize_t read_icon_url(struct bt_conn *conn,
static void track_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void track_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_track_title(struct bt_conn *conn, static ssize_t read_track_title(struct bt_conn *conn,
@ -100,8 +99,7 @@ static ssize_t read_track_title(struct bt_conn *conn,
{ {
const char *title = media_proxy_sctrl_get_track_title(); const char *title = media_proxy_sctrl_get_track_title();
BT_DBG("Track title read, offset: %d, len:%d, title: %s", offset, len, LOG_DBG("Track title read, offset: %d, len:%d, title: %s", offset, len, title);
title);
return bt_gatt_attr_read(conn, attr, buf, len, offset, title, return bt_gatt_attr_read(conn, attr, buf, len, offset, title,
strlen(title)); strlen(title));
@ -110,7 +108,7 @@ static ssize_t read_track_title(struct bt_conn *conn,
static void track_title_cfg_changed(const struct bt_gatt_attr *attr, static void track_title_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_track_duration(struct bt_conn *conn, static ssize_t read_track_duration(struct bt_conn *conn,
@ -119,7 +117,7 @@ static ssize_t read_track_duration(struct bt_conn *conn,
{ {
int32_t duration = media_proxy_sctrl_get_track_duration(); int32_t duration = media_proxy_sctrl_get_track_duration();
BT_DBG("Track duration read: %d (0x%08x)", duration, duration); LOG_DBG("Track duration read: %d (0x%08x)", duration, duration);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &duration, return bt_gatt_attr_read(conn, attr, buf, len, offset, &duration,
sizeof(duration)); sizeof(duration));
@ -128,7 +126,7 @@ static ssize_t read_track_duration(struct bt_conn *conn,
static void track_duration_cfg_changed(const struct bt_gatt_attr *attr, static void track_duration_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_track_position(struct bt_conn *conn, static ssize_t read_track_position(struct bt_conn *conn,
@ -137,7 +135,7 @@ static ssize_t read_track_position(struct bt_conn *conn,
{ {
int32_t position = media_proxy_sctrl_get_track_position(); int32_t position = media_proxy_sctrl_get_track_position();
BT_DBG("Track position read: %d (0x%08x)", position, position); LOG_DBG("Track position read: %d (0x%08x)", position, position);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &position, return bt_gatt_attr_read(conn, attr, buf, len, offset, &position,
sizeof(position)); sizeof(position));
@ -161,7 +159,7 @@ static ssize_t write_track_position(struct bt_conn *conn,
media_proxy_sctrl_set_track_position(position); media_proxy_sctrl_set_track_position(position);
BT_DBG("Track position write: %d", position); LOG_DBG("Track position write: %d", position);
return len; return len;
} }
@ -169,7 +167,7 @@ static ssize_t write_track_position(struct bt_conn *conn,
static void track_position_cfg_changed(const struct bt_gatt_attr *attr, static void track_position_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_playback_speed(struct bt_conn *conn, static ssize_t read_playback_speed(struct bt_conn *conn,
@ -178,7 +176,7 @@ static ssize_t read_playback_speed(struct bt_conn *conn,
{ {
int8_t speed = media_proxy_sctrl_get_playback_speed(); int8_t speed = media_proxy_sctrl_get_playback_speed();
BT_DBG("Playback speed read: %d", speed); LOG_DBG("Playback speed read: %d", speed);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &speed, return bt_gatt_attr_read(conn, attr, buf, len, offset, &speed,
sizeof(speed)); sizeof(speed));
@ -202,7 +200,7 @@ static ssize_t write_playback_speed(struct bt_conn *conn,
media_proxy_sctrl_set_playback_speed(speed); media_proxy_sctrl_set_playback_speed(speed);
BT_DBG("Playback speed write: %d", speed); LOG_DBG("Playback speed write: %d", speed);
return len; return len;
} }
@ -210,7 +208,7 @@ static ssize_t write_playback_speed(struct bt_conn *conn,
static void playback_speed_cfg_changed(const struct bt_gatt_attr *attr, static void playback_speed_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_seeking_speed(struct bt_conn *conn, static ssize_t read_seeking_speed(struct bt_conn *conn,
@ -219,7 +217,7 @@ static ssize_t read_seeking_speed(struct bt_conn *conn,
{ {
int8_t speed = media_proxy_sctrl_get_seeking_speed(); int8_t speed = media_proxy_sctrl_get_seeking_speed();
BT_DBG("Seeking speed read: %d", speed); LOG_DBG("Seeking speed read: %d", speed);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &speed, return bt_gatt_attr_read(conn, attr, buf, len, offset, &speed,
sizeof(speed)); sizeof(speed));
@ -228,7 +226,7 @@ static ssize_t read_seeking_speed(struct bt_conn *conn,
static void seeking_speed_cfg_changed(const struct bt_gatt_attr *attr, static void seeking_speed_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
#ifdef CONFIG_BT_OTS #ifdef CONFIG_BT_OTS
@ -238,7 +236,7 @@ static ssize_t read_track_segments_id(struct bt_conn *conn,
{ {
uint64_t track_segments_id = media_proxy_sctrl_get_track_segments_id(); uint64_t track_segments_id = media_proxy_sctrl_get_track_segments_id();
BT_DBG_OBJ_ID("Track segments ID read: ", track_segments_id); LOG_DBG_OBJ_ID("Track segments ID read: ", track_segments_id);
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
&track_segments_id, BT_OTS_OBJ_ID_SIZE); &track_segments_id, BT_OTS_OBJ_ID_SIZE);
} }
@ -249,7 +247,7 @@ static ssize_t read_current_track_id(struct bt_conn *conn,
{ {
uint64_t track_id = media_proxy_sctrl_get_current_track_id(); uint64_t track_id = media_proxy_sctrl_get_current_track_id();
BT_DBG_OBJ_ID("Current track ID read: ", track_id); LOG_DBG_OBJ_ID("Current track ID read: ", track_id);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &track_id, return bt_gatt_attr_read(conn, attr, buf, len, offset, &track_id,
BT_OTS_OBJ_ID_SIZE); BT_OTS_OBJ_ID_SIZE);
} }
@ -262,22 +260,21 @@ static ssize_t write_current_track_id(struct bt_conn *conn,
uint64_t id; uint64_t id;
if (offset != 0) { if (offset != 0) {
BT_DBG("Invalid offset"); LOG_DBG("Invalid offset");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
} }
if (len != BT_OTS_OBJ_ID_SIZE) { if (len != BT_OTS_OBJ_ID_SIZE) {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
id = sys_get_le48((uint8_t *)buf); id = sys_get_le48((uint8_t *)buf);
if (IS_ENABLED(CONFIG_BT_DEBUG_MCS)) { if (IS_ENABLED(CONFIG_BT_MCS_LOG_LEVEL_DBG)) {
char str[BT_OTS_OBJ_ID_STR_LEN]; char str[BT_OTS_OBJ_ID_STR_LEN];
(void)bt_ots_obj_id_to_str(id, str, sizeof(str)); (void)bt_ots_obj_id_to_str(id, str, sizeof(str));
BT_DBG("Current track write: offset: %d, len: %d, track ID: %s", LOG_DBG("Current track write: offset: %d, len: %d, track ID: %s", offset, len, str);
offset, len, str);
} }
media_proxy_sctrl_set_current_track_id(id); media_proxy_sctrl_set_current_track_id(id);
@ -288,7 +285,7 @@ static ssize_t write_current_track_id(struct bt_conn *conn,
static void current_track_id_cfg_changed(const struct bt_gatt_attr *attr, static void current_track_id_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_next_track_id(struct bt_conn *conn, static ssize_t read_next_track_id(struct bt_conn *conn,
@ -298,13 +295,13 @@ static ssize_t read_next_track_id(struct bt_conn *conn,
uint64_t track_id = media_proxy_sctrl_get_next_track_id(); uint64_t track_id = media_proxy_sctrl_get_next_track_id();
if (track_id == MPL_NO_TRACK_ID) { if (track_id == MPL_NO_TRACK_ID) {
BT_DBG("Next track read, but it is empty"); LOG_DBG("Next track read, but it is empty");
/* "If the media player has no next track, the length of the */ /* "If the media player has no next track, the length of the */
/* characteristic shall be zero." */ /* characteristic shall be zero." */
return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0); return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0);
} }
BT_DBG_OBJ_ID("Next track read: ", track_id); LOG_DBG_OBJ_ID("Next track read: ", track_id);
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
&track_id, BT_OTS_OBJ_ID_SIZE); &track_id, BT_OTS_OBJ_ID_SIZE);
} }
@ -317,22 +314,21 @@ static ssize_t write_next_track_id(struct bt_conn *conn,
uint64_t id; uint64_t id;
if (offset != 0) { if (offset != 0) {
BT_DBG("Invalid offset"); LOG_DBG("Invalid offset");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
} }
if (len != BT_OTS_OBJ_ID_SIZE) { if (len != BT_OTS_OBJ_ID_SIZE) {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
id = sys_get_le48((uint8_t *)buf); id = sys_get_le48((uint8_t *)buf);
if (IS_ENABLED(CONFIG_BT_DEBUG_MCS)) { if (IS_ENABLED(CONFIG_BT_MCS_LOG_LEVEL_DBG)) {
char str[BT_OTS_OBJ_ID_STR_LEN]; char str[BT_OTS_OBJ_ID_STR_LEN];
(void)bt_ots_obj_id_to_str(id, str, sizeof(str)); (void)bt_ots_obj_id_to_str(id, str, sizeof(str));
BT_DBG("Next track write: offset: %d, len: %d, track ID: %s", LOG_DBG("Next track write: offset: %d, len: %d, track ID: %s", offset, len, str);
offset, len, str);
} }
media_proxy_sctrl_set_next_track_id(id); media_proxy_sctrl_set_next_track_id(id);
@ -343,7 +339,7 @@ static ssize_t write_next_track_id(struct bt_conn *conn,
static void next_track_id_cfg_changed(const struct bt_gatt_attr *attr, static void next_track_id_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_parent_group_id(struct bt_conn *conn, static ssize_t read_parent_group_id(struct bt_conn *conn,
@ -352,7 +348,7 @@ static ssize_t read_parent_group_id(struct bt_conn *conn,
{ {
uint64_t group_id = media_proxy_sctrl_get_parent_group_id(); uint64_t group_id = media_proxy_sctrl_get_parent_group_id();
BT_DBG_OBJ_ID("Parent group read: ", group_id); LOG_DBG_OBJ_ID("Parent group read: ", group_id);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &group_id, return bt_gatt_attr_read(conn, attr, buf, len, offset, &group_id,
BT_OTS_OBJ_ID_SIZE); BT_OTS_OBJ_ID_SIZE);
} }
@ -360,7 +356,7 @@ static ssize_t read_parent_group_id(struct bt_conn *conn,
static void parent_group_id_cfg_changed(const struct bt_gatt_attr *attr, static void parent_group_id_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_current_group_id(struct bt_conn *conn, static ssize_t read_current_group_id(struct bt_conn *conn,
@ -369,7 +365,7 @@ static ssize_t read_current_group_id(struct bt_conn *conn,
{ {
uint64_t group_id = media_proxy_sctrl_get_current_group_id(); uint64_t group_id = media_proxy_sctrl_get_current_group_id();
BT_DBG_OBJ_ID("Current group read: ", group_id); LOG_DBG_OBJ_ID("Current group read: ", group_id);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &group_id, return bt_gatt_attr_read(conn, attr, buf, len, offset, &group_id,
BT_OTS_OBJ_ID_SIZE); BT_OTS_OBJ_ID_SIZE);
} }
@ -382,22 +378,22 @@ static ssize_t write_current_group_id(struct bt_conn *conn,
uint64_t id; uint64_t id;
if (offset != 0) { if (offset != 0) {
BT_DBG("Invalid offset"); LOG_DBG("Invalid offset");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
} }
if (len != BT_OTS_OBJ_ID_SIZE) { if (len != BT_OTS_OBJ_ID_SIZE) {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
id = sys_get_le48((uint8_t *)buf); id = sys_get_le48((uint8_t *)buf);
if (IS_ENABLED(CONFIG_BT_DEBUG_MCS)) { if (IS_ENABLED(CONFIG_BT_MCS_LOG_LEVEL_DBG)) {
char str[BT_OTS_OBJ_ID_STR_LEN]; char str[BT_OTS_OBJ_ID_STR_LEN];
(void)bt_ots_obj_id_to_str(id, str, sizeof(str)); (void)bt_ots_obj_id_to_str(id, str, sizeof(str));
BT_DBG("Current group ID write: offset: %d, len: %d, track ID: %s", LOG_DBG("Current group ID write: offset: %d, len: %d, track ID: %s", offset, len,
offset, len, str); str);
} }
media_proxy_sctrl_set_current_group_id(id); media_proxy_sctrl_set_current_group_id(id);
@ -407,7 +403,7 @@ static ssize_t write_current_group_id(struct bt_conn *conn,
static void current_group_id_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void current_group_id_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
#endif /* CONFIG_BT_OTS */ #endif /* CONFIG_BT_OTS */
@ -417,7 +413,7 @@ static ssize_t read_playing_order(struct bt_conn *conn,
{ {
uint8_t order = media_proxy_sctrl_get_playing_order(); uint8_t order = media_proxy_sctrl_get_playing_order();
BT_DBG("Playing order read: %d (0x%02x)", order, order); LOG_DBG("Playing order read: %d (0x%02x)", order, order);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &order, return bt_gatt_attr_read(conn, attr, buf, len, offset, &order,
sizeof(order)); sizeof(order));
@ -428,7 +424,7 @@ static ssize_t write_playing_order(struct bt_conn *conn,
const void *buf, uint16_t len, uint16_t offset, const void *buf, uint16_t len, uint16_t offset,
uint8_t flags) uint8_t flags)
{ {
BT_DBG("Playing order write"); LOG_DBG("Playing order write");
int8_t order; int8_t order;
@ -443,7 +439,7 @@ static ssize_t write_playing_order(struct bt_conn *conn,
media_proxy_sctrl_set_playing_order(order); media_proxy_sctrl_set_playing_order(order);
BT_DBG("Playing order write: %d", order); LOG_DBG("Playing order write: %d", order);
return len; return len;
} }
@ -451,7 +447,7 @@ static ssize_t write_playing_order(struct bt_conn *conn,
static void playing_order_cfg_changed(const struct bt_gatt_attr *attr, static void playing_order_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_playing_orders_supported(struct bt_conn *conn, static ssize_t read_playing_orders_supported(struct bt_conn *conn,
@ -460,7 +456,7 @@ static ssize_t read_playing_orders_supported(struct bt_conn *conn,
{ {
uint16_t orders = media_proxy_sctrl_get_playing_orders_supported(); uint16_t orders = media_proxy_sctrl_get_playing_orders_supported();
BT_DBG("Playing orders read: %d (0x%04x)", orders, orders); LOG_DBG("Playing orders read: %d (0x%04x)", orders, orders);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &orders, return bt_gatt_attr_read(conn, attr, buf, len, offset, &orders,
sizeof(orders)); sizeof(orders));
@ -472,7 +468,7 @@ static ssize_t read_media_state(struct bt_conn *conn,
{ {
uint8_t state = media_proxy_sctrl_get_media_state(); uint8_t state = media_proxy_sctrl_get_media_state();
BT_DBG("Media state read: %d", state); LOG_DBG("Media state read: %d", state);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &state, return bt_gatt_attr_read(conn, attr, buf, len, offset, &state,
sizeof(state)); sizeof(state));
@ -481,7 +477,7 @@ static ssize_t read_media_state(struct bt_conn *conn,
static void media_state_cfg_changed(const struct bt_gatt_attr *attr, static void media_state_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t write_control_point(struct bt_conn *conn, static ssize_t write_control_point(struct bt_conn *conn,
@ -501,7 +497,7 @@ static ssize_t write_control_point(struct bt_conn *conn,
} }
memcpy(&command.opcode, buf, sizeof(command.opcode)); memcpy(&command.opcode, buf, sizeof(command.opcode));
BT_DBG("Opcode: %d", command.opcode); LOG_DBG("Opcode: %d", command.opcode);
command.use_param = false; command.use_param = false;
if (len == sizeof(command.opcode) + sizeof(command.param)) { if (len == sizeof(command.opcode) + sizeof(command.param)) {
@ -509,7 +505,7 @@ static ssize_t write_control_point(struct bt_conn *conn,
(char *)buf + sizeof(command.opcode), (char *)buf + sizeof(command.opcode),
sizeof(command.param)); sizeof(command.param));
command.use_param = true; command.use_param = true;
BT_DBG("Parameter: %d", command.param); LOG_DBG("Parameter: %d", command.param);
} }
media_proxy_sctrl_send_command(&command); media_proxy_sctrl_send_command(&command);
@ -520,7 +516,7 @@ static ssize_t write_control_point(struct bt_conn *conn,
static void control_point_cfg_changed(const struct bt_gatt_attr *attr, static void control_point_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_opcodes_supported(struct bt_conn *conn, static ssize_t read_opcodes_supported(struct bt_conn *conn,
@ -529,7 +525,7 @@ static ssize_t read_opcodes_supported(struct bt_conn *conn,
{ {
uint32_t opcodes = media_proxy_sctrl_get_commands_supported(); uint32_t opcodes = media_proxy_sctrl_get_commands_supported();
BT_DBG("Opcodes_supported read: %d (0x%08x)", opcodes, opcodes); LOG_DBG("Opcodes_supported read: %d (0x%08x)", opcodes, opcodes);
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
&opcodes, BT_MCS_OPCODES_SUPPORTED_LEN); &opcodes, BT_MCS_OPCODES_SUPPORTED_LEN);
@ -538,7 +534,7 @@ static ssize_t read_opcodes_supported(struct bt_conn *conn,
static void opcodes_supported_cfg_changed(const struct bt_gatt_attr *attr, static void opcodes_supported_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
#ifdef CONFIG_BT_OTS #ifdef CONFIG_BT_OTS
@ -559,7 +555,7 @@ static ssize_t write_search_control_point(struct bt_conn *conn,
memcpy(&search.search, (char *)buf, len); memcpy(&search.search, (char *)buf, len);
search.len = len; search.len = len;
BT_DBG("Search length: %d", len); LOG_DBG("Search length: %d", len);
LOG_HEXDUMP_DBG(&search.search, search.len, "Search content"); LOG_HEXDUMP_DBG(&search.search, search.len, "Search content");
media_proxy_sctrl_send_search(&search); media_proxy_sctrl_send_search(&search);
@ -570,7 +566,7 @@ static ssize_t write_search_control_point(struct bt_conn *conn,
static void search_control_point_cfg_changed(const struct bt_gatt_attr *attr, static void search_control_point_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_search_results_id(struct bt_conn *conn, static ssize_t read_search_results_id(struct bt_conn *conn,
@ -579,7 +575,7 @@ static ssize_t read_search_results_id(struct bt_conn *conn,
{ {
uint64_t search_id = media_proxy_sctrl_get_search_results_id(); uint64_t search_id = media_proxy_sctrl_get_search_results_id();
BT_DBG_OBJ_ID("Search results id read: ", search_id); LOG_DBG_OBJ_ID("Search results id read: ", search_id);
/* TODO: The permanent solution here should be that the call to */ /* TODO: The permanent solution here should be that the call to */
/* mpl should fill the UUID in a pointed-to value, and return a */ /* mpl should fill the UUID in a pointed-to value, and return a */
@ -602,7 +598,7 @@ static ssize_t read_search_results_id(struct bt_conn *conn,
static void search_results_id_cfg_changed(const struct bt_gatt_attr *attr, static void search_results_id_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
#endif /* CONFIG_BT_OTS */ #endif /* CONFIG_BT_OTS */
@ -612,7 +608,7 @@ static ssize_t read_content_ctrl_id(struct bt_conn *conn,
{ {
uint8_t id = media_proxy_sctrl_get_content_ctrl_id(); uint8_t id = media_proxy_sctrl_get_content_ctrl_id();
BT_DBG("Content control ID read: %d", id); LOG_DBG("Content control ID read: %d", id);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &id, return bt_gatt_attr_read(conn, attr, buf, len, offset, &id,
sizeof(id)); sizeof(id));
@ -772,9 +768,9 @@ static void notify(const struct bt_uuid *uuid, const void *data, uint16_t len)
if (err) { if (err) {
if (err == -ENOTCONN) { if (err == -ENOTCONN) {
BT_DBG("Notification error: ENOTCONN (%d)", err); LOG_DBG("Notification error: ENOTCONN (%d)", err);
} else { } else {
BT_ERR("Notification error: %d", err); LOG_ERR("Notification error: %d", err);
} }
} }
} }
@ -812,43 +808,43 @@ static void notify_string(const struct bt_uuid *uuid, const char *str)
void media_proxy_sctrl_track_changed_cb(void) void media_proxy_sctrl_track_changed_cb(void)
{ {
BT_DBG("Notifying track change"); LOG_DBG("Notifying track change");
notify(BT_UUID_MCS_TRACK_CHANGED, NULL, 0); notify(BT_UUID_MCS_TRACK_CHANGED, NULL, 0);
} }
void media_proxy_sctrl_track_title_cb(const char *title) void media_proxy_sctrl_track_title_cb(const char *title)
{ {
BT_DBG("Notifying track title: %s", title); LOG_DBG("Notifying track title: %s", title);
notify_string(BT_UUID_MCS_TRACK_TITLE, title); notify_string(BT_UUID_MCS_TRACK_TITLE, title);
} }
void media_proxy_sctrl_track_position_cb(int32_t position) void media_proxy_sctrl_track_position_cb(int32_t position)
{ {
BT_DBG("Notifying track position: %d", position); LOG_DBG("Notifying track position: %d", position);
notify(BT_UUID_MCS_TRACK_POSITION, &position, sizeof(position)); notify(BT_UUID_MCS_TRACK_POSITION, &position, sizeof(position));
} }
void media_proxy_sctrl_track_duration_cb(int32_t duration) void media_proxy_sctrl_track_duration_cb(int32_t duration)
{ {
BT_DBG("Notifying track duration: %d", duration); LOG_DBG("Notifying track duration: %d", duration);
notify(BT_UUID_MCS_TRACK_DURATION, &duration, sizeof(duration)); notify(BT_UUID_MCS_TRACK_DURATION, &duration, sizeof(duration));
} }
void media_proxy_sctrl_playback_speed_cb(int8_t speed) void media_proxy_sctrl_playback_speed_cb(int8_t speed)
{ {
BT_DBG("Notifying playback speed: %d", speed); LOG_DBG("Notifying playback speed: %d", speed);
notify(BT_UUID_MCS_PLAYBACK_SPEED, &speed, sizeof(speed)); notify(BT_UUID_MCS_PLAYBACK_SPEED, &speed, sizeof(speed));
} }
void media_proxy_sctrl_seeking_speed_cb(int8_t speed) void media_proxy_sctrl_seeking_speed_cb(int8_t speed)
{ {
BT_DBG("Notifying seeking speed: %d", speed); LOG_DBG("Notifying seeking speed: %d", speed);
notify(BT_UUID_MCS_SEEKING_SPEED, &speed, sizeof(speed)); notify(BT_UUID_MCS_SEEKING_SPEED, &speed, sizeof(speed));
} }
void media_proxy_sctrl_current_track_id_cb(uint64_t id) void media_proxy_sctrl_current_track_id_cb(uint64_t id)
{ {
BT_DBG_OBJ_ID("Notifying current track ID: ", id); LOG_DBG_OBJ_ID("Notifying current track ID: ", id);
notify(BT_UUID_MCS_CURRENT_TRACK_OBJ_ID, &id, BT_OTS_OBJ_ID_SIZE); notify(BT_UUID_MCS_CURRENT_TRACK_OBJ_ID, &id, BT_OTS_OBJ_ID_SIZE);
} }
@ -857,63 +853,62 @@ void media_proxy_sctrl_next_track_id_cb(uint64_t id)
if (id == MPL_NO_TRACK_ID) { if (id == MPL_NO_TRACK_ID) {
/* "If the media player has no next track, the length of the */ /* "If the media player has no next track, the length of the */
/* characteristic shall be zero." */ /* characteristic shall be zero." */
BT_DBG_OBJ_ID("Notifying EMPTY next track ID: ", id); LOG_DBG_OBJ_ID("Notifying EMPTY next track ID: ", id);
notify(BT_UUID_MCS_NEXT_TRACK_OBJ_ID, NULL, 0); notify(BT_UUID_MCS_NEXT_TRACK_OBJ_ID, NULL, 0);
} else { } else {
BT_DBG_OBJ_ID("Notifying next track ID: ", id); LOG_DBG_OBJ_ID("Notifying next track ID: ", id);
notify(BT_UUID_MCS_NEXT_TRACK_OBJ_ID, &id, BT_OTS_OBJ_ID_SIZE); notify(BT_UUID_MCS_NEXT_TRACK_OBJ_ID, &id, BT_OTS_OBJ_ID_SIZE);
} }
} }
void media_proxy_sctrl_parent_group_id_cb(uint64_t id) void media_proxy_sctrl_parent_group_id_cb(uint64_t id)
{ {
BT_DBG_OBJ_ID("Notifying parent group ID: ", id); LOG_DBG_OBJ_ID("Notifying parent group ID: ", id);
notify(BT_UUID_MCS_PARENT_GROUP_OBJ_ID, &id, BT_OTS_OBJ_ID_SIZE); notify(BT_UUID_MCS_PARENT_GROUP_OBJ_ID, &id, BT_OTS_OBJ_ID_SIZE);
} }
void media_proxy_sctrl_current_group_id_cb(uint64_t id) void media_proxy_sctrl_current_group_id_cb(uint64_t id)
{ {
BT_DBG_OBJ_ID("Notifying current group ID: ", id); LOG_DBG_OBJ_ID("Notifying current group ID: ", id);
notify(BT_UUID_MCS_CURRENT_GROUP_OBJ_ID, &id, BT_OTS_OBJ_ID_SIZE); notify(BT_UUID_MCS_CURRENT_GROUP_OBJ_ID, &id, BT_OTS_OBJ_ID_SIZE);
} }
void media_proxy_sctrl_playing_order_cb(uint8_t order) void media_proxy_sctrl_playing_order_cb(uint8_t order)
{ {
BT_DBG("Notifying playing order: %d", order); LOG_DBG("Notifying playing order: %d", order);
notify(BT_UUID_MCS_PLAYING_ORDER, &order, sizeof(order)); notify(BT_UUID_MCS_PLAYING_ORDER, &order, sizeof(order));
} }
void media_proxy_sctrl_media_state_cb(uint8_t state) void media_proxy_sctrl_media_state_cb(uint8_t state)
{ {
BT_DBG("Notifying media state: %d", state); LOG_DBG("Notifying media state: %d", state);
notify(BT_UUID_MCS_MEDIA_STATE, &state, sizeof(state)); notify(BT_UUID_MCS_MEDIA_STATE, &state, sizeof(state));
} }
void media_proxy_sctrl_command_cb(const struct mpl_cmd_ntf *cmd_ntf) void media_proxy_sctrl_command_cb(const struct mpl_cmd_ntf *cmd_ntf)
{ {
BT_DBG("Notifying control point command - opcode: %d, result: %d", LOG_DBG("Notifying control point command - opcode: %d, result: %d",
cmd_ntf->requested_opcode, cmd_ntf->result_code); cmd_ntf->requested_opcode, cmd_ntf->result_code);
notify(BT_UUID_MCS_MEDIA_CONTROL_POINT, cmd_ntf, sizeof(*cmd_ntf)); notify(BT_UUID_MCS_MEDIA_CONTROL_POINT, cmd_ntf, sizeof(*cmd_ntf));
} }
void media_proxy_sctrl_commands_supported_cb(uint32_t opcodes) void media_proxy_sctrl_commands_supported_cb(uint32_t opcodes)
{ {
BT_DBG("Notifying command opcodes supported: %d (0x%08x)", opcodes, LOG_DBG("Notifying command opcodes supported: %d (0x%08x)", opcodes, opcodes);
opcodes);
notify(BT_UUID_MCS_MEDIA_CONTROL_OPCODES, &opcodes, notify(BT_UUID_MCS_MEDIA_CONTROL_OPCODES, &opcodes,
BT_MCS_OPCODES_SUPPORTED_LEN); BT_MCS_OPCODES_SUPPORTED_LEN);
} }
void media_proxy_sctrl_search_cb(uint8_t result_code) void media_proxy_sctrl_search_cb(uint8_t result_code)
{ {
BT_DBG("Notifying search control point - result: %d", result_code); LOG_DBG("Notifying search control point - result: %d", result_code);
notify(BT_UUID_MCS_SEARCH_CONTROL_POINT, &result_code, notify(BT_UUID_MCS_SEARCH_CONTROL_POINT, &result_code,
sizeof(result_code)); sizeof(result_code));
} }
void media_proxy_sctrl_search_results_id_cb(uint64_t id) void media_proxy_sctrl_search_results_id_cb(uint64_t id)
{ {
BT_DBG_OBJ_ID("Notifying search results ID: ", id); LOG_DBG_OBJ_ID("Notifying search results ID: ", id);
notify(BT_UUID_MCS_SEARCH_RESULTS_OBJ_ID, &id, BT_OTS_OBJ_ID_SIZE); notify(BT_UUID_MCS_SEARCH_RESULTS_OBJ_ID, &id, BT_OTS_OBJ_ID_SIZE);
} }
@ -924,7 +919,7 @@ int bt_mcs_init(struct bt_ots_cb *ots_cbs)
int err; int err;
if (initialized) { if (initialized) {
BT_DBG("Already initialized"); LOG_DBG("Already initialized");
return -EALREADY; return -EALREADY;
} }
@ -936,7 +931,7 @@ int bt_mcs_init(struct bt_ots_cb *ots_cbs)
ots = bt_ots_free_instance_get(); ots = bt_ots_free_instance_get();
if (!ots) { if (!ots) {
BT_ERR("Failed to retrieve OTS instance\n"); LOG_ERR("Failed to retrieve OTS instance\n");
return -ENOMEM; return -ENOMEM;
} }
@ -949,7 +944,7 @@ int bt_mcs_init(struct bt_ots_cb *ots_cbs)
/* Initialize OTS instance. */ /* Initialize OTS instance. */
err = bt_ots_init(ots, &ots_init); err = bt_ots_init(ots, &ots_init);
if (err) { if (err) {
BT_ERR("Failed to init OTS (err:%d)\n", err); LOG_ERR("Failed to init OTS (err:%d)\n", err);
return err; return err;
} }
@ -964,7 +959,7 @@ int bt_mcs_init(struct bt_ots_cb *ots_cbs)
err = bt_gatt_service_register(&mcs); err = bt_gatt_service_register(&mcs);
if (err) { if (err) {
BT_ERR("Could not register the MCS service"); LOG_ERR("Could not register the MCS service");
#ifdef CONFIG_BT_OTS #ifdef CONFIG_BT_OTS
/* TODO: How does one un-register the OTS? */ /* TODO: How does one un-register the OTS? */
#endif /* CONFIG_BT_OTS */ #endif /* CONFIG_BT_OTS */

File diff suppressed because it is too large Load diff

View file

@ -16,12 +16,12 @@
/* Debug output of 48 bit Object ID value */ /* Debug output of 48 bit Object ID value */
/* (Zephyr does not yet support debug output of more than 32 bit values.) */ /* (Zephyr does not yet support debug output of more than 32 bit values.) */
/* Takes a text and a 64-bit integer as input */ /* Takes a text and a 64-bit integer as input */
#define BT_DBG_OBJ_ID(text, id64) \ #define LOG_DBG_OBJ_ID(text, id64) \
do { \ do { \
if (IS_ENABLED(CONFIG_BT_DEBUG_MCS)) { \ if (IS_ENABLED(CONFIG_BT_MCS_LOG_LEVEL_DBG)) { \
char t[BT_OTS_OBJ_ID_STR_LEN]; \ char t[BT_OTS_OBJ_ID_STR_LEN]; \
(void)bt_ots_obj_id_to_str(id64, t, sizeof(t)); \ (void)bt_ots_obj_id_to_str(id64, t, sizeof(t)); \
BT_DBG(text "0x%s", t); \ LOG_DBG(text "0x%s", t); \
} \ } \
} while (0) } while (0)

View file

@ -20,9 +20,10 @@
#include <zephyr/bluetooth/gatt.h> #include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/audio/micp.h> #include <zephyr/bluetooth/audio/micp.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_MICP_MIC_CTLR) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_micp_mic_ctlr
#include "common/log.h" LOG_MODULE_REGISTER(bt_micp_mic_ctlr, CONFIG_BT_MICP_MIC_CTLR_LOG_LEVEL);
#include "common/bt_str.h" #include "common/bt_str.h"
/* Callback functions */ /* Callback functions */
@ -65,15 +66,13 @@ static uint8_t mute_notify_handler(struct bt_conn *conn,
if (data != NULL) { if (data != NULL) {
if (length == sizeof(*mute_val)) { if (length == sizeof(*mute_val)) {
mute_val = (uint8_t *)data; mute_val = (uint8_t *)data;
BT_DBG("Mute %u", *mute_val); LOG_DBG("Mute %u", *mute_val);
if (micp_mic_ctlr_cb != NULL && if (micp_mic_ctlr_cb != NULL &&
micp_mic_ctlr_cb->mute != NULL) { micp_mic_ctlr_cb->mute != NULL) {
micp_mic_ctlr_cb->mute(mic_ctlr, 0, *mute_val); micp_mic_ctlr_cb->mute(mic_ctlr, 0, *mute_val);
} }
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", LOG_DBG("Invalid length %u (expected %zu)", length, sizeof(*mute_val));
length, sizeof(*mute_val));
} }
} }
@ -91,14 +90,13 @@ static uint8_t micp_mic_ctlr_read_mute_cb(struct bt_conn *conn, uint8_t err,
mic_ctlr->busy = false; mic_ctlr->busy = false;
if (err > 0) { if (err > 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
if (length == sizeof(mute_val)) { if (length == sizeof(mute_val)) {
mute_val = ((uint8_t *)data)[0]; mute_val = ((uint8_t *)data)[0];
BT_DBG("Mute %u", mute_val); LOG_DBG("Mute %u", mute_val);
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", LOG_DBG("Invalid length %u (expected %zu)", length, sizeof(mute_val));
length, sizeof(mute_val));
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} }
@ -116,7 +114,7 @@ static void micp_mic_ctlr_write_mics_mute_cb(struct bt_conn *conn, uint8_t err,
struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)]; struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)];
uint8_t mute_val = mic_ctlr->mute_val_buf[0]; uint8_t mute_val = mic_ctlr->mute_val_buf[0];
BT_DBG("Write %s (0x%02X)", err ? "failed" : "successful", err); LOG_DBG("Write %s (0x%02X)", err ? "failed" : "successful", err);
mic_ctlr->busy = false; mic_ctlr->busy = false;
@ -161,7 +159,7 @@ static void aics_discover_cb(struct bt_aics *inst, int err)
} }
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
if (micp_mic_ctlr_cb != NULL && if (micp_mic_ctlr_cb != NULL &&
micp_mic_ctlr_cb->discover != NULL) { micp_mic_ctlr_cb->discover != NULL) {
micp_mic_ctlr_cb->discover(mic_ctlr, err, 0); micp_mic_ctlr_cb->discover(mic_ctlr, err, 0);
@ -177,8 +175,7 @@ static uint8_t micp_discover_include_func(
struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)]; struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)];
if (attr == NULL) { if (attr == NULL) {
BT_DBG("Discover include complete for MICS: %u AICS", LOG_DBG("Discover include complete for MICS: %u AICS", mic_ctlr->aics_inst_cnt);
mic_ctlr->aics_inst_cnt);
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
if (micp_mic_ctlr_cb != NULL && if (micp_mic_ctlr_cb != NULL &&
@ -190,12 +187,12 @@ static uint8_t micp_discover_include_func(
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_INCLUDE) { if (params->type == BT_GATT_DISCOVER_INCLUDE) {
struct bt_gatt_include *include = (struct bt_gatt_include *)attr->user_data; struct bt_gatt_include *include = (struct bt_gatt_include *)attr->user_data;
BT_DBG("Include UUID %s", bt_uuid_str(include->uuid)); LOG_DBG("Include UUID %s", bt_uuid_str(include->uuid));
if (bt_uuid_cmp(include->uuid, BT_UUID_AICS) == 0 && if (bt_uuid_cmp(include->uuid, BT_UUID_AICS) == 0 &&
mic_ctlr->aics_inst_cnt < CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST) { mic_ctlr->aics_inst_cnt < CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST) {
@ -215,7 +212,7 @@ static uint8_t micp_discover_include_func(
err = bt_aics_discover(conn, mic_ctlr->aics[inst_idx], err = bt_aics_discover(conn, mic_ctlr->aics[inst_idx],
&param); &param);
if (err != 0) { if (err != 0) {
BT_DBG("AICS Discover failed (err %d)", err); LOG_DBG("AICS Discover failed (err %d)", err);
if (micp_mic_ctlr_cb != NULL && if (micp_mic_ctlr_cb != NULL &&
micp_mic_ctlr_cb->discover != NULL) { micp_mic_ctlr_cb->discover != NULL) {
micp_mic_ctlr_cb->discover(mic_ctlr, err, micp_mic_ctlr_cb->discover(mic_ctlr, err,
@ -243,7 +240,7 @@ static uint8_t micp_discover_func(struct bt_conn *conn,
if (attr == NULL) { if (attr == NULL) {
int err = 0; int err = 0;
BT_DBG("Discovery complete"); LOG_DBG("Discovery complete");
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
if (CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST > 0) { if (CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST > 0) {
/* Discover included services */ /* Discover included services */
@ -255,7 +252,7 @@ static uint8_t micp_discover_func(struct bt_conn *conn,
err = bt_gatt_discover(conn, err = bt_gatt_discover(conn,
&mic_ctlr->discover_params); &mic_ctlr->discover_params);
if (err != 0) { if (err != 0) {
BT_DBG("Discover AICS failed (err %d)", err); LOG_DBG("Discover AICS failed (err %d)", err);
if (micp_mic_ctlr_cb != NULL && if (micp_mic_ctlr_cb != NULL &&
micp_mic_ctlr_cb->discover != NULL) { micp_mic_ctlr_cb->discover != NULL) {
micp_mic_ctlr_cb->discover(mic_ctlr, err, 0); micp_mic_ctlr_cb->discover(mic_ctlr, err, 0);
@ -270,14 +267,14 @@ static uint8_t micp_discover_func(struct bt_conn *conn,
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) {
struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data;
struct bt_gatt_subscribe_params *sub_params = NULL; struct bt_gatt_subscribe_params *sub_params = NULL;
if (bt_uuid_cmp(chrc->uuid, BT_UUID_MICS_MUTE) == 0) { if (bt_uuid_cmp(chrc->uuid, BT_UUID_MICS_MUTE) == 0) {
BT_DBG("Mute"); LOG_DBG("Mute");
mic_ctlr->mute_handle = chrc->value_handle; mic_ctlr->mute_handle = chrc->value_handle;
sub_params = &mic_ctlr->mute_sub_params; sub_params = &mic_ctlr->mute_sub_params;
sub_params->disc_params = &mic_ctlr->mute_sub_disc_params; sub_params->disc_params = &mic_ctlr->mute_sub_disc_params;
@ -295,11 +292,10 @@ static uint8_t micp_discover_func(struct bt_conn *conn,
err = bt_gatt_subscribe(conn, sub_params); err = bt_gatt_subscribe(conn, sub_params);
if (err == 0) { if (err == 0) {
BT_DBG("Subscribed to handle 0x%04X", LOG_DBG("Subscribed to handle 0x%04X", attr->handle);
attr->handle);
} else { } else {
BT_DBG("Could not subscribe to handle 0x%04X: %d", LOG_DBG("Could not subscribe to handle 0x%04X: %d", attr->handle,
attr->handle, err); err);
} }
} }
} }
@ -314,7 +310,7 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)]; struct bt_micp_mic_ctlr *mic_ctlr = &mic_ctlrs[bt_conn_index(conn)];
if (attr == NULL) { if (attr == NULL) {
BT_DBG("Could not find a MICS instance on the server"); LOG_DBG("Could not find a MICS instance on the server");
if (micp_mic_ctlr_cb != NULL && if (micp_mic_ctlr_cb != NULL &&
micp_mic_ctlr_cb->discover != NULL) { micp_mic_ctlr_cb->discover != NULL) {
micp_mic_ctlr_cb->discover(mic_ctlr, -ENODATA, 0); micp_mic_ctlr_cb->discover(mic_ctlr, -ENODATA, 0);
@ -322,14 +318,14 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_PRIMARY) { if (params->type == BT_GATT_DISCOVER_PRIMARY) {
struct bt_gatt_service_val *prim_service = struct bt_gatt_service_val *prim_service =
(struct bt_gatt_service_val *)attr->user_data; (struct bt_gatt_service_val *)attr->user_data;
int err; int err;
BT_DBG("Primary discover complete"); LOG_DBG("Primary discover complete");
mic_ctlr->start_handle = attr->handle + 1; mic_ctlr->start_handle = attr->handle + 1;
mic_ctlr->end_handle = prim_service->end_handle; mic_ctlr->end_handle = prim_service->end_handle;
@ -342,7 +338,7 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
err = bt_gatt_discover(conn, &mic_ctlr->discover_params); err = bt_gatt_discover(conn, &mic_ctlr->discover_params);
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
if (micp_mic_ctlr_cb != NULL && if (micp_mic_ctlr_cb != NULL &&
micp_mic_ctlr_cb->discover != NULL) { micp_mic_ctlr_cb->discover != NULL) {
micp_mic_ctlr_cb->discover(mic_ctlr, err, 0); micp_mic_ctlr_cb->discover(mic_ctlr, err, 0);
@ -407,7 +403,7 @@ int bt_micp_mic_ctlr_discover(struct bt_conn *conn, struct bt_micp_mic_ctlr **mi
*/ */
CHECKIF(conn == NULL) { CHECKIF(conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
@ -460,7 +456,7 @@ int bt_micp_mic_ctlr_cb_register(struct bt_micp_mic_ctlr_cb *cb)
/* Ensure that the cb->aics_cb.discover is the aics_discover_cb */ /* Ensure that the cb->aics_cb.discover is the aics_discover_cb */
CHECKIF(cb->aics_cb.discover != NULL && CHECKIF(cb->aics_cb.discover != NULL &&
cb->aics_cb.discover != aics_discover_cb) { cb->aics_cb.discover != aics_discover_cb) {
BT_ERR("AICS discover callback shall not be set"); LOG_ERR("AICS discover callback shall not be set");
return -EINVAL; return -EINVAL;
} }
cb->aics_cb.discover = aics_discover_cb; cb->aics_cb.discover = aics_discover_cb;
@ -488,7 +484,7 @@ int bt_micp_mic_ctlr_included_get(struct bt_micp_mic_ctlr *mic_ctlr,
struct bt_micp_included *included) struct bt_micp_included *included)
{ {
CHECKIF(mic_ctlr == NULL) { CHECKIF(mic_ctlr == NULL) {
BT_DBG("NULL mic_ctlr"); LOG_DBG("NULL mic_ctlr");
return -EINVAL; return -EINVAL;
} }
@ -505,12 +501,12 @@ int bt_micp_mic_ctlr_included_get(struct bt_micp_mic_ctlr *mic_ctlr,
int bt_micp_mic_ctlr_conn_get(const struct bt_micp_mic_ctlr *mic_ctlr, struct bt_conn **conn) int bt_micp_mic_ctlr_conn_get(const struct bt_micp_mic_ctlr *mic_ctlr, struct bt_conn **conn)
{ {
CHECKIF(mic_ctlr == NULL) { CHECKIF(mic_ctlr == NULL) {
BT_DBG("NULL mic_ctlr pointer"); LOG_DBG("NULL mic_ctlr pointer");
return -EINVAL; return -EINVAL;
} }
if (mic_ctlr->conn == NULL) { if (mic_ctlr->conn == NULL) {
BT_DBG("mic_ctlr pointer not associated with a connection. " LOG_DBG("mic_ctlr pointer not associated with a connection. "
"Do discovery first"); "Do discovery first");
return -ENOTCONN; return -ENOTCONN;
} }
@ -524,12 +520,12 @@ int bt_micp_mic_ctlr_mute_get(struct bt_micp_mic_ctlr *mic_ctlr)
int err; int err;
CHECKIF(mic_ctlr == NULL) { CHECKIF(mic_ctlr == NULL) {
BT_DBG("NULL mic_ctlr"); LOG_DBG("NULL mic_ctlr");
return -EINVAL; return -EINVAL;
} }
if (mic_ctlr->mute_handle == 0) { if (mic_ctlr->mute_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (mic_ctlr->busy) { } else if (mic_ctlr->busy) {
return -EBUSY; return -EBUSY;
@ -553,12 +549,12 @@ int bt_micp_mic_ctlr_write_mute(struct bt_micp_mic_ctlr *mic_ctlr, bool mute)
int err; int err;
CHECKIF(mic_ctlr == NULL) { CHECKIF(mic_ctlr == NULL) {
BT_DBG("NULL mic_ctlr"); LOG_DBG("NULL mic_ctlr");
return -EINVAL; return -EINVAL;
} }
if (mic_ctlr->mute_handle == 0) { if (mic_ctlr->mute_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (mic_ctlr->busy) { } else if (mic_ctlr->busy) {
return -EBUSY; return -EBUSY;

View file

@ -21,9 +21,9 @@
#include "audio_internal.h" #include "audio_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_MICP_MIC_DEV) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_micp
#include "common/log.h" LOG_MODULE_REGISTER(bt_micp, CONFIG_BT_MICP_MIC_DEV_LOG_LEVEL);
struct bt_micp_server { struct bt_micp_server {
uint8_t mute; uint8_t mute;
@ -36,14 +36,14 @@ static struct bt_micp_server micp_inst;
static void mute_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void mute_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_mute(struct bt_conn *conn, static ssize_t read_mute(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf, const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset) uint16_t len, uint16_t offset)
{ {
BT_DBG("Mute %u", micp_inst.mute); LOG_DBG("Mute %u", micp_inst.mute);
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
&micp_inst.mute, sizeof(micp_inst.mute)); &micp_inst.mute, sizeof(micp_inst.mute));
@ -72,7 +72,7 @@ static ssize_t write_mute(struct bt_conn *conn, const struct bt_gatt_attr *attr,
return BT_GATT_ERR(BT_MICP_ERR_MUTE_DISABLED); return BT_GATT_ERR(BT_MICP_ERR_MUTE_DISABLED);
} }
BT_DBG("%u", *val); LOG_DBG("%u", *val);
if (*val != micp_inst.mute) { if (*val != micp_inst.mute) {
micp_inst.mute = *val; micp_inst.mute = *val;
@ -120,14 +120,14 @@ static int prepare_aics_inst(struct bt_micp_mic_dev_register_param *param)
if (bt_uuid_cmp(mics_attrs[i].uuid, BT_UUID_GATT_INCLUDE) == 0) { if (bt_uuid_cmp(mics_attrs[i].uuid, BT_UUID_GATT_INCLUDE) == 0) {
micp_inst.aics_insts[j] = bt_aics_free_instance_get(); micp_inst.aics_insts[j] = bt_aics_free_instance_get();
if (micp_inst.aics_insts[j] == NULL) { if (micp_inst.aics_insts[j] == NULL) {
BT_DBG("Could not get free AICS instances[%u]", j); LOG_DBG("Could not get free AICS instances[%u]", j);
return -ENOMEM; return -ENOMEM;
} }
err = bt_aics_register(micp_inst.aics_insts[j], err = bt_aics_register(micp_inst.aics_insts[j],
&param->aics_param[j]); &param->aics_param[j]);
if (err != 0) { if (err != 0) {
BT_DBG("Could not register AICS instance[%u]: %d", j, err); LOG_DBG("Could not register AICS instance[%u]: %d", j, err);
return err; return err;
} }
@ -162,7 +162,7 @@ int bt_micp_mic_dev_register(struct bt_micp_mic_dev_register_param *param)
#if defined(CONFIG_BT_MICP_MIC_DEV_AICS) #if defined(CONFIG_BT_MICP_MIC_DEV_AICS)
err = prepare_aics_inst(param); err = prepare_aics_inst(param);
if (err != 0) { if (err != 0) {
BT_DBG("Failed to prepare AICS instances: %d", err); LOG_DBG("Failed to prepare AICS instances: %d", err);
return err; return err;
} }
@ -173,7 +173,7 @@ int bt_micp_mic_dev_register(struct bt_micp_mic_dev_register_param *param)
err = bt_gatt_service_register(&mics_svc); err = bt_gatt_service_register(&mics_svc);
if (err != 0) { if (err != 0) {
BT_ERR("MICS service register failed: %d", err); LOG_ERR("MICS service register failed: %d", err);
} }
micp_inst.cb = param->cb; micp_inst.cb = param->cb;
@ -196,7 +196,7 @@ int bt_micp_mic_dev_mute_disable(void)
int bt_micp_mic_dev_included_get(struct bt_micp_included *included) int bt_micp_mic_dev_included_get(struct bt_micp_included *included)
{ {
CHECKIF(included == NULL) { CHECKIF(included == NULL) {
BT_DBG("NULL service pointer"); LOG_DBG("NULL service pointer");
return -EINVAL; return -EINVAL;
} }

View file

@ -14,9 +14,10 @@
#include "media_proxy_internal.h" #include "media_proxy_internal.h"
#include "mpl_internal.h" #include "mpl_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_MPL) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_mpl
#include "common/log.h" LOG_MODULE_REGISTER(bt_mpl, CONFIG_BT_MPL_LOG_LEVEL);
#include "ccid_internal.h" #include "ccid_internal.h"
#include "mcs_internal.h" #include "mcs_internal.h"
@ -331,7 +332,7 @@ static uint32_t setup_segments_object(struct mpl_track *track)
seg_size += seg->name_len; seg_size += seg->name_len;
seg_size += sizeof(seg->pos); seg_size += sizeof(seg->pos);
if (tot_size + seg_size > obj.content->size) { if (tot_size + seg_size > obj.content->size) {
BT_DBG("Segments object out of space"); LOG_DBG("Segments object out of space");
break; break;
} }
net_buf_simple_add_u8(obj.content, seg->name_len); net_buf_simple_add_u8(obj.content, seg->name_len);
@ -344,9 +345,9 @@ static uint32_t setup_segments_object(struct mpl_track *track)
} }
LOG_HEXDUMP_DBG(obj.content->data, obj.content->len, "Segments Object"); LOG_HEXDUMP_DBG(obj.content->data, obj.content->len, "Segments Object");
BT_DBG("Segments object length: %d", obj.content->len); LOG_DBG("Segments object length: %d", obj.content->len);
} else { } else {
BT_ERR("No seg!"); LOG_ERR("No seg!");
} }
return obj.content->len; return obj.content->len;
@ -403,10 +404,10 @@ static uint32_t setup_parent_group_object(struct mpl_group *group)
next_size += record_size; next_size += record_size;
} }
if (next_size > obj.content->size) { if (next_size > obj.content->size) {
BT_WARN("Not room for full group in object"); LOG_WRN("Not room for full group in object");
} }
LOG_HEXDUMP_DBG(obj.content->data, obj.content->len, "Parent Group Object"); LOG_HEXDUMP_DBG(obj.content->data, obj.content->len, "Parent Group Object");
BT_DBG("Group object length: %d", obj.content->len); LOG_DBG("Group object length: %d", obj.content->len);
} }
return obj.content->len; return obj.content->len;
} }
@ -435,10 +436,10 @@ static uint32_t setup_group_object(struct mpl_group *group)
next_size += record_size; next_size += record_size;
} }
if (next_size > obj.content->size) { if (next_size > obj.content->size) {
BT_WARN("Not room for full group in object"); LOG_WRN("Not room for full group in object");
} }
LOG_HEXDUMP_DBG(obj.content->data, obj.content->len, "Group Object"); LOG_HEXDUMP_DBG(obj.content->data, obj.content->len, "Group Object");
BT_DBG("Group object length: %d", obj.content->len); LOG_DBG("Group object length: %d", obj.content->len);
} }
return obj.content->len; return obj.content->len;
} }
@ -455,7 +456,7 @@ static int add_icon_object(struct mpl_mediaplayer *pl)
if (obj.busy) { if (obj.busy) {
/* TODO: Can there be a collision between select and internal */ /* TODO: Can there be a collision between select and internal */
/* activities, like adding new objects? */ /* activities, like adding new objects? */
BT_ERR("Object busy"); LOG_ERR("Object busy");
return 0; return 0;
} }
obj.busy = true; obj.busy = true;
@ -472,7 +473,7 @@ static int add_icon_object(struct mpl_mediaplayer *pl)
ret = bt_ots_obj_add(bt_mcs_get_ots(), &add_param); ret = bt_ots_obj_add(bt_mcs_get_ots(), &add_param);
if (ret < 0) { if (ret < 0) {
BT_WARN("Unable to add icon object, error %d", ret); LOG_WRN("Unable to add icon object, error %d", ret);
obj.busy = false; obj.busy = false;
return ret; return ret;
@ -490,7 +491,7 @@ static int add_current_track_segments_object(struct mpl_mediaplayer *pl)
struct bt_uuid *segs_type = BT_UUID_OTS_TYPE_TRACK_SEGMENT; struct bt_uuid *segs_type = BT_UUID_OTS_TYPE_TRACK_SEGMENT;
if (obj.busy) { if (obj.busy) {
BT_ERR("Object busy"); LOG_ERR("Object busy");
return 0; return 0;
} }
obj.busy = true; obj.busy = true;
@ -507,7 +508,7 @@ static int add_current_track_segments_object(struct mpl_mediaplayer *pl)
ret = bt_ots_obj_add(bt_mcs_get_ots(), &add_param); ret = bt_ots_obj_add(bt_mcs_get_ots(), &add_param);
if (ret < 0) { if (ret < 0) {
BT_WARN("Unable to add track segments object: %d", ret); LOG_WRN("Unable to add track segments object: %d", ret);
obj.busy = false; obj.busy = false;
return ret; return ret;
@ -525,11 +526,11 @@ static int add_track_object(struct mpl_track *track)
int ret; int ret;
if (obj.busy) { if (obj.busy) {
BT_ERR("Object busy"); LOG_ERR("Object busy");
return 0; return 0;
} }
if (!track) { if (!track) {
BT_ERR("No track"); LOG_ERR("No track");
return -EINVAL; return -EINVAL;
} }
@ -549,7 +550,7 @@ static int add_track_object(struct mpl_track *track)
ret = bt_ots_obj_add(bt_mcs_get_ots(), &add_param); ret = bt_ots_obj_add(bt_mcs_get_ots(), &add_param);
if (ret < 0) { if (ret < 0) {
BT_WARN("Unable to add track object: %d", ret); LOG_WRN("Unable to add track object: %d", ret);
obj.busy = false; obj.busy = false;
return ret; return ret;
@ -567,7 +568,7 @@ static int add_parent_group_object(struct mpl_mediaplayer *pl)
struct bt_uuid *group_type = BT_UUID_OTS_TYPE_GROUP; struct bt_uuid *group_type = BT_UUID_OTS_TYPE_GROUP;
if (obj.busy) { if (obj.busy) {
BT_ERR("Object busy"); LOG_ERR("Object busy");
return 0; return 0;
} }
obj.busy = true; obj.busy = true;
@ -584,7 +585,7 @@ static int add_parent_group_object(struct mpl_mediaplayer *pl)
ret = bt_ots_obj_add(bt_mcs_get_ots(), &add_param); ret = bt_ots_obj_add(bt_mcs_get_ots(), &add_param);
if (ret < 0) { if (ret < 0) {
BT_WARN("Unable to add parent group object"); LOG_WRN("Unable to add parent group object");
obj.busy = false; obj.busy = false;
return ret; return ret;
@ -602,12 +603,12 @@ static int add_group_object(struct mpl_group *group)
int ret; int ret;
if (obj.busy) { if (obj.busy) {
BT_ERR("Object busy"); LOG_ERR("Object busy");
return 0; return 0;
} }
if (!group) { if (!group) {
BT_ERR("No group"); LOG_ERR("No group");
return -EINVAL; return -EINVAL;
} }
@ -627,7 +628,7 @@ static int add_group_object(struct mpl_group *group)
ret = bt_ots_obj_add(bt_mcs_get_ots(), &add_param); ret = bt_ots_obj_add(bt_mcs_get_ots(), &add_param);
if (ret < 0) { if (ret < 0) {
BT_WARN("Unable to add group object: %d", ret); LOG_WRN("Unable to add group object: %d", ret);
obj.busy = false; obj.busy = false;
return ret; return ret;
@ -698,7 +699,7 @@ static int add_group_and_track_objects(struct mpl_mediaplayer *pl)
static int on_obj_deleted(struct bt_ots *ots, struct bt_conn *conn, static int on_obj_deleted(struct bt_ots *ots, struct bt_conn *conn,
uint64_t id) uint64_t id)
{ {
BT_DBG_OBJ_ID("Object Id deleted: ", id); LOG_DBG_OBJ_ID("Object Id deleted: ", id);
return 0; return 0;
} }
@ -709,38 +710,38 @@ static void on_obj_selected(struct bt_ots *ots, struct bt_conn *conn,
if (obj.busy) { if (obj.busy) {
/* TODO: Can there be a collision between select and internal */ /* TODO: Can there be a collision between select and internal */
/* activities, like adding new objects? */ /* activities, like adding new objects? */
BT_ERR("Object busy - select not performed"); LOG_ERR("Object busy - select not performed");
return; return;
} }
obj.busy = true; obj.busy = true;
BT_DBG_OBJ_ID("Object Id selected: ", id); LOG_DBG_OBJ_ID("Object Id selected: ", id);
if (id == pl.icon_id) { if (id == pl.icon_id) {
BT_DBG("Icon Object ID"); LOG_DBG("Icon Object ID");
(void)setup_icon_object(); (void)setup_icon_object();
} else if (id == pl.group->track->segments_id) { } else if (id == pl.group->track->segments_id) {
BT_DBG("Current Track Segments Object ID"); LOG_DBG("Current Track Segments Object ID");
(void)setup_segments_object(pl.group->track); (void)setup_segments_object(pl.group->track);
} else if (id == pl.group->track->id) { } else if (id == pl.group->track->id) {
BT_DBG("Current Track Object ID"); LOG_DBG("Current Track Object ID");
(void)setup_track_object(pl.group->track); (void)setup_track_object(pl.group->track);
} else if (pl.next_track_set && id == pl.next.track->id) { } else if (pl.next_track_set && id == pl.next.track->id) {
/* Next track, if the next track has been explicitly set */ /* Next track, if the next track has been explicitly set */
BT_DBG("Next Track Object ID"); LOG_DBG("Next Track Object ID");
(void)setup_track_object(pl.next.track); (void)setup_track_object(pl.next.track);
} else if (id == pl.group->track->next->id) { } else if (id == pl.group->track->next->id) {
/* Next track, if next track has not been explicitly set */ /* Next track, if next track has not been explicitly set */
BT_DBG("Next Track Object ID"); LOG_DBG("Next Track Object ID");
(void)setup_track_object(pl.group->track->next); (void)setup_track_object(pl.group->track->next);
} else if (id == pl.group->parent->id) { } else if (id == pl.group->parent->id) {
BT_DBG("Parent Group Object ID"); LOG_DBG("Parent Group Object ID");
(void)setup_parent_group_object(pl.group); (void)setup_parent_group_object(pl.group);
} else if (id == pl.group->id) { } else if (id == pl.group->id) {
BT_DBG("Current Group Object ID"); LOG_DBG("Current Group Object ID");
(void)setup_group_object(pl.group); (void)setup_group_object(pl.group);
} else { } else {
BT_ERR("Unknown Object ID"); LOG_ERR("Unknown Object ID");
obj.busy = false; obj.busy = false;
return; return;
} }
@ -753,58 +754,58 @@ static int on_obj_created(struct bt_ots *ots, struct bt_conn *conn, uint64_t id,
const struct bt_ots_obj_add_param *add_param, const struct bt_ots_obj_add_param *add_param,
struct bt_ots_obj_created_desc *created_desc) struct bt_ots_obj_created_desc *created_desc)
{ {
BT_DBG_OBJ_ID("Object Id created: ", id); LOG_DBG_OBJ_ID("Object Id created: ", id);
*created_desc = *obj.desc; *created_desc = *obj.desc;
if (!bt_uuid_cmp(&add_param->type.uuid, BT_UUID_OTS_TYPE_MPL_ICON)) { if (!bt_uuid_cmp(&add_param->type.uuid, BT_UUID_OTS_TYPE_MPL_ICON)) {
BT_DBG("Icon Obj Type"); LOG_DBG("Icon Obj Type");
if (obj.add_type == MPL_OBJ_ICON) { if (obj.add_type == MPL_OBJ_ICON) {
obj.add_type = MPL_OBJ_NONE; obj.add_type = MPL_OBJ_NONE;
pl.icon_id = id; pl.icon_id = id;
} else { } else {
BT_DBG("Unexpected object creation"); LOG_DBG("Unexpected object creation");
} }
} else if (!bt_uuid_cmp(&add_param->type.uuid, } else if (!bt_uuid_cmp(&add_param->type.uuid,
BT_UUID_OTS_TYPE_TRACK_SEGMENT)) { BT_UUID_OTS_TYPE_TRACK_SEGMENT)) {
BT_DBG("Track Segments Obj Type"); LOG_DBG("Track Segments Obj Type");
if (obj.add_type == MPL_OBJ_TRACK_SEGMENTS) { if (obj.add_type == MPL_OBJ_TRACK_SEGMENTS) {
obj.add_type = MPL_OBJ_NONE; obj.add_type = MPL_OBJ_NONE;
pl.group->track->segments_id = id; pl.group->track->segments_id = id;
} else { } else {
BT_DBG("Unexpected object creation"); LOG_DBG("Unexpected object creation");
} }
} else if (!bt_uuid_cmp(&add_param->type.uuid, } else if (!bt_uuid_cmp(&add_param->type.uuid,
BT_UUID_OTS_TYPE_TRACK)) { BT_UUID_OTS_TYPE_TRACK)) {
BT_DBG("Track Obj Type"); LOG_DBG("Track Obj Type");
if (obj.add_type == MPL_OBJ_TRACK) { if (obj.add_type == MPL_OBJ_TRACK) {
obj.add_type = MPL_OBJ_NONE; obj.add_type = MPL_OBJ_NONE;
obj.add_track->id = id; obj.add_track->id = id;
obj.add_track = NULL; obj.add_track = NULL;
} else { } else {
BT_DBG("Unexpected object creation"); LOG_DBG("Unexpected object creation");
} }
} else if (!bt_uuid_cmp(&add_param->type.uuid, } else if (!bt_uuid_cmp(&add_param->type.uuid,
BT_UUID_OTS_TYPE_GROUP)) { BT_UUID_OTS_TYPE_GROUP)) {
BT_DBG("Group Obj Type"); LOG_DBG("Group Obj Type");
if (obj.add_type == MPL_OBJ_PARENT_GROUP) { if (obj.add_type == MPL_OBJ_PARENT_GROUP) {
BT_DBG("Parent group"); LOG_DBG("Parent group");
obj.add_type = MPL_OBJ_NONE; obj.add_type = MPL_OBJ_NONE;
pl.group->parent->id = id; pl.group->parent->id = id;
} else if (obj.add_type == MPL_OBJ_GROUP) { } else if (obj.add_type == MPL_OBJ_GROUP) {
BT_DBG("Other group"); LOG_DBG("Other group");
obj.add_type = MPL_OBJ_NONE; obj.add_type = MPL_OBJ_NONE;
obj.add_group->id = id; obj.add_group->id = id;
obj.add_group = NULL; obj.add_group = NULL;
} else { } else {
BT_DBG("Unexpected object creation"); LOG_DBG("Unexpected object creation");
} }
} else { } else {
BT_DBG("Unknown Object ID"); LOG_DBG("Unknown Object ID");
} }
if (obj.add_type == MPL_OBJ_NONE) { if (obj.add_type == MPL_OBJ_NONE) {
@ -821,39 +822,38 @@ static ssize_t on_object_send(struct bt_ots *ots, struct bt_conn *conn,
if (obj.busy) { if (obj.busy) {
/* TODO: Can there be a collision between select and internal */ /* TODO: Can there be a collision between select and internal */
/* activities, like adding new objects? */ /* activities, like adding new objects? */
BT_ERR("Object busy"); LOG_ERR("Object busy");
return 0; return 0;
} }
obj.busy = true; obj.busy = true;
if (IS_ENABLED(CONFIG_BT_DEBUG_MPL)) { if (IS_ENABLED(CONFIG_BT_MPL_LOG_LEVEL_DBG)) {
char t[BT_OTS_OBJ_ID_STR_LEN]; char t[BT_OTS_OBJ_ID_STR_LEN];
(void)bt_ots_obj_id_to_str(id, t, sizeof(t)); (void)bt_ots_obj_id_to_str(id, t, sizeof(t));
BT_DBG("Object Id %s, offset %lu, length %zu", t, LOG_DBG("Object Id %s, offset %lu, length %zu", t, (long)offset, len);
(long)offset, len);
} }
if (id != obj.selected_id) { if (id != obj.selected_id) {
BT_ERR("Read from unselected object"); LOG_ERR("Read from unselected object");
obj.busy = false; obj.busy = false;
return 0; return 0;
} }
if (!data) { if (!data) {
BT_DBG("Read complete"); LOG_DBG("Read complete");
obj.busy = false; obj.busy = false;
return 0; return 0;
} }
if (offset >= obj.content->len) { if (offset >= obj.content->len) {
BT_DBG("Offset too large"); LOG_DBG("Offset too large");
obj.busy = false; obj.busy = false;
return 0; return 0;
} }
if (IS_ENABLED(CONFIG_BT_DEBUG_MPL)) { if (IS_ENABLED(CONFIG_BT_MPL_LOG_LEVEL_DBG)) {
if (len > obj.content->len - offset) { if (len > obj.content->len - offset) {
BT_DBG("Requested len too large"); LOG_DBG("Requested len too large");
} }
} }
@ -878,62 +878,53 @@ static struct bt_ots_cb ots_cbs = {
void do_prev_segment(struct mpl_mediaplayer *pl) void do_prev_segment(struct mpl_mediaplayer *pl)
{ {
BT_DBG("Segment name before: %s", LOG_DBG("Segment name before: %s", pl->group->track->segment->name);
pl->group->track->segment->name);
if (pl->group->track->segment->prev != NULL) { if (pl->group->track->segment->prev != NULL) {
pl->group->track->segment = pl->group->track->segment->prev; pl->group->track->segment = pl->group->track->segment->prev;
} }
BT_DBG("Segment name after: %s", LOG_DBG("Segment name after: %s", pl->group->track->segment->name);
pl->group->track->segment->name);
} }
void do_next_segment(struct mpl_mediaplayer *pl) void do_next_segment(struct mpl_mediaplayer *pl)
{ {
BT_DBG("Segment name before: %s", LOG_DBG("Segment name before: %s", pl->group->track->segment->name);
pl->group->track->segment->name);
if (pl->group->track->segment->next != NULL) { if (pl->group->track->segment->next != NULL) {
pl->group->track->segment = pl->group->track->segment->next; pl->group->track->segment = pl->group->track->segment->next;
} }
BT_DBG("Segment name after: %s", LOG_DBG("Segment name after: %s", pl->group->track->segment->name);
pl->group->track->segment->name);
} }
void do_first_segment(struct mpl_mediaplayer *pl) void do_first_segment(struct mpl_mediaplayer *pl)
{ {
BT_DBG("Segment name before: %s", LOG_DBG("Segment name before: %s", pl->group->track->segment->name);
pl->group->track->segment->name);
while (pl->group->track->segment->prev != NULL) { while (pl->group->track->segment->prev != NULL) {
pl->group->track->segment = pl->group->track->segment->prev; pl->group->track->segment = pl->group->track->segment->prev;
} }
BT_DBG("Segment name after: %s", LOG_DBG("Segment name after: %s", pl->group->track->segment->name);
pl->group->track->segment->name);
} }
void do_last_segment(struct mpl_mediaplayer *pl) void do_last_segment(struct mpl_mediaplayer *pl)
{ {
BT_DBG("Segment name before: %s", LOG_DBG("Segment name before: %s", pl->group->track->segment->name);
pl->group->track->segment->name);
while (pl->group->track->segment->next != NULL) { while (pl->group->track->segment->next != NULL) {
pl->group->track->segment = pl->group->track->segment->next; pl->group->track->segment = pl->group->track->segment->next;
} }
BT_DBG("Segment name after: %s", LOG_DBG("Segment name after: %s", pl->group->track->segment->name);
pl->group->track->segment->name);
} }
void do_goto_segment(struct mpl_mediaplayer *pl, int32_t segnum) void do_goto_segment(struct mpl_mediaplayer *pl, int32_t segnum)
{ {
int32_t k; int32_t k;
BT_DBG("Segment name before: %s", LOG_DBG("Segment name before: %s", pl->group->track->segment->name);
pl->group->track->segment->name);
if (segnum > 0) { if (segnum > 0) {
/* Goto first segment */ /* Goto first segment */
@ -965,8 +956,7 @@ void do_goto_segment(struct mpl_mediaplayer *pl, int32_t segnum)
} }
} }
BT_DBG("Segment name after: %s", LOG_DBG("Segment name after: %s", pl->group->track->segment->name);
pl->group->track->segment->name);
} }
static bool do_prev_track(struct mpl_mediaplayer *pl) static bool do_prev_track(struct mpl_mediaplayer *pl)
@ -974,7 +964,7 @@ static bool do_prev_track(struct mpl_mediaplayer *pl)
bool track_changed = false; bool track_changed = false;
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Track ID before: ", pl->group->track->id); LOG_DBG_OBJ_ID("Track ID before: ", pl->group->track->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
if (pl->group->track->prev != NULL) { if (pl->group->track->prev != NULL) {
@ -983,7 +973,7 @@ static bool do_prev_track(struct mpl_mediaplayer *pl)
} }
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Track ID after: ", pl->group->track->id); LOG_DBG_OBJ_ID("Track ID after: ", pl->group->track->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
return track_changed; return track_changed;
@ -995,7 +985,7 @@ static bool do_next_track_normal_order(struct mpl_mediaplayer *pl)
bool track_changed = false; bool track_changed = false;
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Track ID before: ", pl->group->track->id); LOG_DBG_OBJ_ID("Track ID before: ", pl->group->track->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
if (pl->group->track->next != NULL) { if (pl->group->track->next != NULL) {
@ -1004,7 +994,7 @@ static bool do_next_track_normal_order(struct mpl_mediaplayer *pl)
} }
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Track ID after: ", pl->group->track->id); LOG_DBG_OBJ_ID("Track ID after: ", pl->group->track->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
return track_changed; return track_changed;
@ -1040,7 +1030,7 @@ static bool do_first_track(struct mpl_mediaplayer *pl)
bool track_changed = false; bool track_changed = false;
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Track ID before: ", pl->group->track->id); LOG_DBG_OBJ_ID("Track ID before: ", pl->group->track->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
if (pl->group->track->prev != NULL) { if (pl->group->track->prev != NULL) {
@ -1052,7 +1042,7 @@ static bool do_first_track(struct mpl_mediaplayer *pl)
} }
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Track ID after: ", pl->group->track->id); LOG_DBG_OBJ_ID("Track ID after: ", pl->group->track->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
return track_changed; return track_changed;
@ -1063,7 +1053,7 @@ static bool do_last_track(struct mpl_mediaplayer *pl)
bool track_changed = false; bool track_changed = false;
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Track ID before: ", pl->group->track->id); LOG_DBG_OBJ_ID("Track ID before: ", pl->group->track->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
if (pl->group->track->next != NULL) { if (pl->group->track->next != NULL) {
@ -1075,7 +1065,7 @@ static bool do_last_track(struct mpl_mediaplayer *pl)
} }
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Track ID after: ", pl->group->track->id); LOG_DBG_OBJ_ID("Track ID after: ", pl->group->track->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
return track_changed; return track_changed;
@ -1087,7 +1077,7 @@ static bool do_goto_track(struct mpl_mediaplayer *pl, int32_t tracknum)
int32_t k; int32_t k;
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Track ID before: ", pl->group->track->id); LOG_DBG_OBJ_ID("Track ID before: ", pl->group->track->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
if (tracknum > 0) { if (tracknum > 0) {
@ -1121,7 +1111,7 @@ static bool do_goto_track(struct mpl_mediaplayer *pl, int32_t tracknum)
} }
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Track ID after: ", pl->group->track->id); LOG_DBG_OBJ_ID("Track ID after: ", pl->group->track->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
/* The track has changed if we have moved more in one direction */ /* The track has changed if we have moved more in one direction */
@ -1135,7 +1125,7 @@ static bool do_prev_group(struct mpl_mediaplayer *pl)
bool group_changed = false; bool group_changed = false;
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Group ID before: ", pl->group->id); LOG_DBG_OBJ_ID("Group ID before: ", pl->group->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
if (pl->group->prev != NULL) { if (pl->group->prev != NULL) {
@ -1144,7 +1134,7 @@ static bool do_prev_group(struct mpl_mediaplayer *pl)
} }
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Group ID after: ", pl->group->id); LOG_DBG_OBJ_ID("Group ID after: ", pl->group->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
return group_changed; return group_changed;
@ -1155,7 +1145,7 @@ static bool do_next_group(struct mpl_mediaplayer *pl)
bool group_changed = false; bool group_changed = false;
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Group ID before: ", pl->group->id); LOG_DBG_OBJ_ID("Group ID before: ", pl->group->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
if (pl->group->next != NULL) { if (pl->group->next != NULL) {
@ -1164,7 +1154,7 @@ static bool do_next_group(struct mpl_mediaplayer *pl)
} }
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Group ID after: ", pl->group->id); LOG_DBG_OBJ_ID("Group ID after: ", pl->group->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
return group_changed; return group_changed;
@ -1175,7 +1165,7 @@ static bool do_first_group(struct mpl_mediaplayer *pl)
bool group_changed = false; bool group_changed = false;
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Group ID before: ", pl->group->id); LOG_DBG_OBJ_ID("Group ID before: ", pl->group->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
if (pl->group->prev != NULL) { if (pl->group->prev != NULL) {
@ -1187,7 +1177,7 @@ static bool do_first_group(struct mpl_mediaplayer *pl)
} }
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Group ID after: ", pl->group->id); LOG_DBG_OBJ_ID("Group ID after: ", pl->group->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
return group_changed; return group_changed;
@ -1198,7 +1188,7 @@ static bool do_last_group(struct mpl_mediaplayer *pl)
bool group_changed = false; bool group_changed = false;
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Group ID before: ", pl->group->id); LOG_DBG_OBJ_ID("Group ID before: ", pl->group->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
if (pl->group->next != NULL) { if (pl->group->next != NULL) {
@ -1210,7 +1200,7 @@ static bool do_last_group(struct mpl_mediaplayer *pl)
} }
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Group ID after: ", pl->group->id); LOG_DBG_OBJ_ID("Group ID after: ", pl->group->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
return group_changed; return group_changed;
@ -1222,7 +1212,7 @@ static bool do_goto_group(struct mpl_mediaplayer *pl, int32_t groupnum)
int32_t k; int32_t k;
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Group ID before: ", pl->group->id); LOG_DBG_OBJ_ID("Group ID before: ", pl->group->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
if (groupnum > 0) { if (groupnum > 0) {
@ -1256,7 +1246,7 @@ static bool do_goto_group(struct mpl_mediaplayer *pl, int32_t groupnum)
} }
#ifdef CONFIG_BT_MPL_OBJECTS #ifdef CONFIG_BT_MPL_OBJECTS
BT_DBG_OBJ_ID("Group ID after: ", pl->group->id); LOG_DBG_OBJ_ID("Group ID after: ", pl->group->id);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
/* The group has changed if we have moved more in one direction */ /* The group has changed if we have moved more in one direction */
@ -1407,10 +1397,10 @@ void do_full_goto_group(struct mpl_mediaplayer *pl, int32_t groupnum)
void inactive_state_command_handler(const struct mpl_cmd *command, void inactive_state_command_handler(const struct mpl_cmd *command,
struct mpl_cmd_ntf *ntf) struct mpl_cmd_ntf *ntf)
{ {
BT_DBG("Command opcode: %d", command->opcode); LOG_DBG("Command opcode: %d", command->opcode);
if (IS_ENABLED(CONFIG_BT_DEBUG_MPL)) { if (IS_ENABLED(CONFIG_BT_MPL_LOG_LEVEL_DBG)) {
if (command->use_param) { if (command->use_param) {
BT_DBG("Command parameter: %d", command->param); LOG_DBG("Command parameter: %d", command->param);
} }
} }
switch (command->opcode) { switch (command->opcode) {
@ -1450,7 +1440,7 @@ void inactive_state_command_handler(const struct mpl_cmd *command,
* with the "next" order hardcoded into the group and track structure * with the "next" order hardcoded into the group and track structure
*/ */
if (pl.next_track_set) { if (pl.next_track_set) {
BT_DBG("Next track set"); LOG_DBG("Next track set");
if (do_next_track_next_track_set(&pl)) { if (do_next_track_next_track_set(&pl)) {
do_group_change_notifications(&pl); do_group_change_notifications(&pl);
} }
@ -1557,7 +1547,7 @@ void inactive_state_command_handler(const struct mpl_cmd *command,
media_proxy_pl_command_cb(ntf); media_proxy_pl_command_cb(ntf);
break; break;
default: default:
BT_DBG("Invalid command: %d", command->opcode); LOG_DBG("Invalid command: %d", command->opcode);
ntf->result_code = MEDIA_PROXY_CMD_NOT_SUPPORTED; ntf->result_code = MEDIA_PROXY_CMD_NOT_SUPPORTED;
media_proxy_pl_command_cb(ntf); media_proxy_pl_command_cb(ntf);
break; break;
@ -1567,10 +1557,10 @@ void inactive_state_command_handler(const struct mpl_cmd *command,
void playing_state_command_handler(const struct mpl_cmd *command, void playing_state_command_handler(const struct mpl_cmd *command,
struct mpl_cmd_ntf *ntf) struct mpl_cmd_ntf *ntf)
{ {
BT_DBG("Command opcode: %d", command->opcode); LOG_DBG("Command opcode: %d", command->opcode);
if (IS_ENABLED(CONFIG_BT_DEBUG_MPL)) { if (IS_ENABLED(CONFIG_BT_MPL_LOG_LEVEL_DBG)) {
if (command->use_param) { if (command->use_param) {
BT_DBG("Command parameter: %d", command->param); LOG_DBG("Command parameter: %d", command->param);
} }
} }
switch (command->opcode) { switch (command->opcode) {
@ -1694,7 +1684,7 @@ void playing_state_command_handler(const struct mpl_cmd *command,
break; break;
case MEDIA_PROXY_OP_NEXT_TRACK: case MEDIA_PROXY_OP_NEXT_TRACK:
if (pl.next_track_set) { if (pl.next_track_set) {
BT_DBG("Next track set"); LOG_DBG("Next track set");
if (do_next_track_next_track_set(&pl)) { if (do_next_track_next_track_set(&pl)) {
do_group_change_notifications(&pl); do_group_change_notifications(&pl);
} }
@ -1783,7 +1773,7 @@ void playing_state_command_handler(const struct mpl_cmd *command,
media_proxy_pl_command_cb(ntf); media_proxy_pl_command_cb(ntf);
break; break;
default: default:
BT_DBG("Invalid command: %d", command->opcode); LOG_DBG("Invalid command: %d", command->opcode);
ntf->result_code = MEDIA_PROXY_CMD_NOT_SUPPORTED; ntf->result_code = MEDIA_PROXY_CMD_NOT_SUPPORTED;
media_proxy_pl_command_cb(ntf); media_proxy_pl_command_cb(ntf);
break; break;
@ -1793,10 +1783,10 @@ void playing_state_command_handler(const struct mpl_cmd *command,
void paused_state_command_handler(const struct mpl_cmd *command, void paused_state_command_handler(const struct mpl_cmd *command,
struct mpl_cmd_ntf *ntf) struct mpl_cmd_ntf *ntf)
{ {
BT_DBG("Command opcode: %d", command->opcode); LOG_DBG("Command opcode: %d", command->opcode);
if (IS_ENABLED(CONFIG_BT_DEBUG_MPL)) { if (IS_ENABLED(CONFIG_BT_MPL_LOG_LEVEL_DBG)) {
if (command->use_param) { if (command->use_param) {
BT_DBG("Command parameter: %d", command->param); LOG_DBG("Command parameter: %d", command->param);
} }
} }
switch (command->opcode) { switch (command->opcode) {
@ -1920,7 +1910,7 @@ void paused_state_command_handler(const struct mpl_cmd *command,
break; break;
case MEDIA_PROXY_OP_NEXT_TRACK: case MEDIA_PROXY_OP_NEXT_TRACK:
if (pl.next_track_set) { if (pl.next_track_set) {
BT_DBG("Next track set"); LOG_DBG("Next track set");
if (do_next_track_next_track_set(&pl)) { if (do_next_track_next_track_set(&pl)) {
do_group_change_notifications(&pl); do_group_change_notifications(&pl);
} }
@ -2009,7 +1999,7 @@ void paused_state_command_handler(const struct mpl_cmd *command,
media_proxy_pl_command_cb(ntf); media_proxy_pl_command_cb(ntf);
break; break;
default: default:
BT_DBG("Invalid command: %d", command->opcode); LOG_DBG("Invalid command: %d", command->opcode);
ntf->result_code = MEDIA_PROXY_CMD_NOT_SUPPORTED; ntf->result_code = MEDIA_PROXY_CMD_NOT_SUPPORTED;
media_proxy_pl_command_cb(ntf); media_proxy_pl_command_cb(ntf);
break; break;
@ -2019,10 +2009,10 @@ void paused_state_command_handler(const struct mpl_cmd *command,
void seeking_state_command_handler(const struct mpl_cmd *command, void seeking_state_command_handler(const struct mpl_cmd *command,
struct mpl_cmd_ntf *ntf) struct mpl_cmd_ntf *ntf)
{ {
BT_DBG("Command opcode: %d", command->opcode); LOG_DBG("Command opcode: %d", command->opcode);
if (IS_ENABLED(CONFIG_BT_DEBUG_MPL)) { if (IS_ENABLED(CONFIG_BT_MPL_LOG_LEVEL_DBG)) {
if (command->use_param) { if (command->use_param) {
BT_DBG("Command parameter: %d", command->param); LOG_DBG("Command parameter: %d", command->param);
} }
} }
switch (command->opcode) { switch (command->opcode) {
@ -2164,7 +2154,7 @@ void seeking_state_command_handler(const struct mpl_cmd *command,
break; break;
case MEDIA_PROXY_OP_NEXT_TRACK: case MEDIA_PROXY_OP_NEXT_TRACK:
if (pl.next_track_set) { if (pl.next_track_set) {
BT_DBG("Next track set"); LOG_DBG("Next track set");
if (do_next_track_next_track_set(&pl)) { if (do_next_track_next_track_set(&pl)) {
do_group_change_notifications(&pl); do_group_change_notifications(&pl);
} }
@ -2275,7 +2265,7 @@ void seeking_state_command_handler(const struct mpl_cmd *command,
media_proxy_pl_command_cb(ntf); media_proxy_pl_command_cb(ntf);
break; break;
default: default:
BT_DBG("Invalid command: %d", command->opcode); LOG_DBG("Invalid command: %d", command->opcode);
ntf->result_code = MEDIA_PROXY_CMD_NOT_SUPPORTED; ntf->result_code = MEDIA_PROXY_CMD_NOT_SUPPORTED;
media_proxy_pl_command_cb(ntf); media_proxy_pl_command_cb(ntf);
break; break;
@ -2421,8 +2411,8 @@ void set_track_position(int32_t position)
} }
} }
BT_DBG("Pos. given: %d, resulting pos.: %d (duration is %d)", LOG_DBG("Pos. given: %d, resulting pos.: %d (duration is %d)", position, new_pos,
position, new_pos, pl.group->track->duration); pl.group->track->duration);
if (new_pos != old_pos) { if (new_pos != old_pos) {
/* Set new position and notify it */ /* Set new position and notify it */
@ -2466,7 +2456,7 @@ void set_current_track_id(uint64_t id)
struct mpl_group *group; struct mpl_group *group;
struct mpl_track *track; struct mpl_track *track;
BT_DBG_OBJ_ID("Track ID to set: ", id); LOG_DBG_OBJ_ID("Track ID to set: ", id);
if (find_track_by_id(&pl, id, &group, &track)) { if (find_track_by_id(&pl, id, &group, &track)) {
@ -2485,7 +2475,7 @@ void set_current_track_id(uint64_t id)
return; return;
} }
BT_DBG("Track not found"); LOG_DBG("Track not found");
/* TODO: Should an error be returned here? /* TODO: Should an error be returned here?
* That would require a rewrite of the MPL api to add return values to the functions. * That would require a rewrite of the MPL api to add return values to the functions.
@ -2513,7 +2503,7 @@ void set_next_track_id(uint64_t id)
struct mpl_group *group; struct mpl_group *group;
struct mpl_track *track; struct mpl_track *track;
BT_DBG_OBJ_ID("Next Track ID to set: ", id); LOG_DBG_OBJ_ID("Next Track ID to set: ", id);
if (find_track_by_id(&pl, id, &group, &track)) { if (find_track_by_id(&pl, id, &group, &track)) {
@ -2524,7 +2514,7 @@ void set_next_track_id(uint64_t id)
return; return;
} }
BT_DBG("Track not found"); LOG_DBG("Track not found");
} }
uint64_t get_parent_group_id(void) uint64_t get_parent_group_id(void)
@ -2542,7 +2532,7 @@ void set_current_group_id(uint64_t id)
struct mpl_group *group; struct mpl_group *group;
bool track_change; bool track_change;
BT_DBG_OBJ_ID("Group ID to set: ", id); LOG_DBG_OBJ_ID("Group ID to set: ", id);
if (find_group_by_id(&pl, id, &group)) { if (find_group_by_id(&pl, id, &group)) {
@ -2560,7 +2550,7 @@ void set_current_group_id(uint64_t id)
return; return;
} }
BT_DBG("Group not found"); LOG_DBG("Group not found");
} }
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
@ -2594,16 +2584,16 @@ void send_command(const struct mpl_cmd *command)
struct mpl_cmd_ntf ntf; struct mpl_cmd_ntf ntf;
if (command->use_param) { if (command->use_param) {
BT_DBG("opcode: %d, param: %d", command->opcode, command->param); LOG_DBG("opcode: %d, param: %d", command->opcode, command->param);
} else { } else {
BT_DBG("opcode: %d", command->opcode); LOG_DBG("opcode: %d", command->opcode);
} }
if (pl.state < MEDIA_PROXY_STATE_LAST) { if (pl.state < MEDIA_PROXY_STATE_LAST) {
ntf.requested_opcode = command->opcode; ntf.requested_opcode = command->opcode;
command_handlers[pl.state](command, &ntf); command_handlers[pl.state](command, &ntf);
} else { } else {
BT_DBG("INVALID STATE"); LOG_DBG("INVALID STATE");
} }
} }
@ -2621,20 +2611,20 @@ static void parse_search(const struct mpl_search *search)
bool search_failed = false; bool search_failed = false;
if (search->len > SEARCH_LEN_MAX) { if (search->len > SEARCH_LEN_MAX) {
BT_WARN("Search too long (%d) - aborting", search->len); LOG_WRN("Search too long (%d) - aborting", search->len);
search_failed = true; search_failed = true;
} else { } else {
BT_DBG("Parsing %d octets search", search->len); LOG_DBG("Parsing %d octets search", search->len);
while (search->len - index > 0) { while (search->len - index > 0) {
sci.len = (uint8_t)search->search[index++]; sci.len = (uint8_t)search->search[index++];
if (sci.len < SEARCH_SCI_LEN_MIN) { if (sci.len < SEARCH_SCI_LEN_MIN) {
BT_WARN("Invalid length field - too small"); LOG_WRN("Invalid length field - too small");
search_failed = true; search_failed = true;
break; break;
} }
if (sci.len > (search->len - index)) { if (sci.len > (search->len - index)) {
BT_WARN("Incomplete search control item"); LOG_WRN("Incomplete search control item");
search_failed = true; search_failed = true;
break; break;
} }
@ -2647,7 +2637,7 @@ static void parse_search(const struct mpl_search *search)
(void)memcpy(&sci.param, &search->search[index], sci.len - 1); (void)memcpy(&sci.param, &search->search[index], sci.len - 1);
index += sci.len - 1; index += sci.len - 1;
BT_DBG("SCI # %d: type: %d", sci_num, sci.type); LOG_DBG("SCI # %d: type: %d", sci_num, sci.type);
LOG_HEXDUMP_DBG(sci.param, sci.len - 1, "param:"); LOG_HEXDUMP_DBG(sci.param, sci.len - 1, "param:");
sci_num++; sci_num++;
} }
@ -2671,7 +2661,7 @@ static void parse_search(const struct mpl_search *search)
void send_search(const struct mpl_search *search) void send_search(const struct mpl_search *search)
{ {
if (search->len > SEARCH_LEN_MAX) { if (search->len > SEARCH_LEN_MAX) {
BT_WARN("Search too long: %d", search->len); LOG_WRN("Search too long: %d", search->len);
} }
LOG_HEXDUMP_DBG(search->search, search->len, "Search"); LOG_HEXDUMP_DBG(search->search, search->len, "Search");
@ -2696,7 +2686,7 @@ int media_proxy_pl_init(void)
int ret; int ret;
if (initialized) { if (initialized) {
BT_DBG("Already initialized"); LOG_DBG("Already initialized");
return -EALREADY; return -EALREADY;
} }
@ -2712,11 +2702,11 @@ int media_proxy_pl_init(void)
ret = bt_mcs_init(NULL); ret = bt_mcs_init(NULL);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
if (ret < 0) { if (ret < 0) {
BT_ERR("Could not init MCS: %d", ret); LOG_ERR("Could not init MCS: %d", ret);
return ret; return ret;
} }
#else #else
BT_WARN("MCS not configured"); LOG_WRN("MCS not configured");
#endif /* CONFIG_BT_MCS */ #endif /* CONFIG_BT_MCS */
/* Get a Content Control ID */ /* Get a Content Control ID */
@ -2729,14 +2719,14 @@ int media_proxy_pl_init(void)
/* Icon Object */ /* Icon Object */
ret = add_icon_object(&pl); ret = add_icon_object(&pl);
if (ret < 0) { if (ret < 0) {
BT_ERR("Unable to add icon object, error %d", ret); LOG_ERR("Unable to add icon object, error %d", ret);
return ret; return ret;
} }
/* Add all tracks and groups to OTS */ /* Add all tracks and groups to OTS */
ret = add_group_and_track_objects(&pl); ret = add_group_and_track_objects(&pl);
if (ret < 0) { if (ret < 0) {
BT_ERR("Error adding tracks and groups to OTS, error %d", ret); LOG_ERR("Error adding tracks and groups to OTS, error %d", ret);
return ret; return ret;
} }
@ -2745,7 +2735,7 @@ int media_proxy_pl_init(void)
/* but for no only one of the tracks has segments .*/ /* but for no only one of the tracks has segments .*/
ret = add_current_track_segments_object(&pl); ret = add_current_track_segments_object(&pl);
if (ret < 0) { if (ret < 0) {
BT_ERR("Error adding Track Segments Object to OTS, error %d", ret); LOG_ERR("Error adding Track Segments Object to OTS, error %d", ret);
return ret; return ret;
} }
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
@ -2787,7 +2777,7 @@ int media_proxy_pl_init(void)
ret = media_proxy_pl_register(&pl.calls); ret = media_proxy_pl_register(&pl.calls);
if (ret < 0) { if (ret < 0) {
BT_ERR("Unable to register player"); LOG_ERR("Unable to register player");
return ret; return ret;
} }
@ -2795,7 +2785,7 @@ int media_proxy_pl_init(void)
return 0; return 0;
} }
#if CONFIG_BT_DEBUG_MPL /* Special commands for debugging */ #if CONFIG_BT_MPL_LOG_LEVEL_DBG /* Special commands for debugging */
void mpl_debug_dump_state(void) void mpl_debug_dump_state(void)
{ {
@ -2805,52 +2795,52 @@ void mpl_debug_dump_state(void)
struct mpl_track *track; struct mpl_track *track;
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
BT_DBG("Mediaplayer name: %s", pl.name); LOG_DBG("Mediaplayer name: %s", pl.name);
#if CONFIG_BT_MPL_OBJECTS #if CONFIG_BT_MPL_OBJECTS
(void)bt_ots_obj_id_to_str(pl.icon_id, t, sizeof(t)); (void)bt_ots_obj_id_to_str(pl.icon_id, t, sizeof(t));
BT_DBG("Icon ID: %s", t); LOG_DBG("Icon ID: %s", t);
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
BT_DBG("Icon URL: %s", pl.icon_url); LOG_DBG("Icon URL: %s", pl.icon_url);
BT_DBG("Track position: %d", pl.track_pos); LOG_DBG("Track position: %d", pl.track_pos);
BT_DBG("Media state: %d", pl.state); LOG_DBG("Media state: %d", pl.state);
BT_DBG("Playback speed parameter: %d", pl.playback_speed_param); LOG_DBG("Playback speed parameter: %d", pl.playback_speed_param);
BT_DBG("Seeking speed factor: %d", pl.seeking_speed_factor); LOG_DBG("Seeking speed factor: %d", pl.seeking_speed_factor);
BT_DBG("Playing order: %d", pl.playing_order); LOG_DBG("Playing order: %d", pl.playing_order);
BT_DBG("Playing orders supported: 0x%x", pl.playing_orders_supported); LOG_DBG("Playing orders supported: 0x%x", pl.playing_orders_supported);
BT_DBG("Opcodes supported: %d", pl.opcodes_supported); LOG_DBG("Opcodes supported: %d", pl.opcodes_supported);
BT_DBG("Content control ID: %d", pl.content_ctrl_id); LOG_DBG("Content control ID: %d", pl.content_ctrl_id);
#if CONFIG_BT_MPL_OBJECTS #if CONFIG_BT_MPL_OBJECTS
(void)bt_ots_obj_id_to_str(pl.group->parent->id, t, sizeof(t)); (void)bt_ots_obj_id_to_str(pl.group->parent->id, t, sizeof(t));
BT_DBG("Current group's parent: %s", t); LOG_DBG("Current group's parent: %s", t);
(void)bt_ots_obj_id_to_str(pl.group->id, t, sizeof(t)); (void)bt_ots_obj_id_to_str(pl.group->id, t, sizeof(t));
BT_DBG("Current group: %s", t); LOG_DBG("Current group: %s", t);
(void)bt_ots_obj_id_to_str(pl.group->track->id, t, sizeof(t)); (void)bt_ots_obj_id_to_str(pl.group->track->id, t, sizeof(t));
BT_DBG("Current track: %s", t); LOG_DBG("Current track: %s", t);
if (pl.next_track_set) { if (pl.next_track_set) {
(void)bt_ots_obj_id_to_str(pl.next.track->id, t, sizeof(t)); (void)bt_ots_obj_id_to_str(pl.next.track->id, t, sizeof(t));
BT_DBG("Next track: %s", t); LOG_DBG("Next track: %s", t);
} else if (pl.group->track->next) { } else if (pl.group->track->next) {
(void)bt_ots_obj_id_to_str(pl.group->track->next->id, t, (void)bt_ots_obj_id_to_str(pl.group->track->next->id, t,
sizeof(t)); sizeof(t));
BT_DBG("Next track: %s", t); LOG_DBG("Next track: %s", t);
} else { } else {
BT_DBG("No next track"); LOG_DBG("No next track");
} }
if (pl.search_results_id) { if (pl.search_results_id) {
(void)bt_ots_obj_id_to_str(pl.search_results_id, t, sizeof(t)); (void)bt_ots_obj_id_to_str(pl.search_results_id, t, sizeof(t));
BT_DBG("Search results: %s", t); LOG_DBG("Search results: %s", t);
} else { } else {
BT_DBG("No search results"); LOG_DBG("No search results");
} }
BT_DBG("Groups and tracks:"); LOG_DBG("Groups and tracks:");
group = pl.group; group = pl.group;
while (group->prev != NULL) { while (group->prev != NULL) {
@ -2859,12 +2849,10 @@ void mpl_debug_dump_state(void)
while (group) { while (group) {
(void)bt_ots_obj_id_to_str(group->id, t, sizeof(t)); (void)bt_ots_obj_id_to_str(group->id, t, sizeof(t));
BT_DBG("Group: %s, %s", t, LOG_DBG("Group: %s, %s", t, group->title);
group->title);
(void)bt_ots_obj_id_to_str(group->parent->id, t, sizeof(t)); (void)bt_ots_obj_id_to_str(group->parent->id, t, sizeof(t));
BT_DBG("\tParent: %s, %s", t, LOG_DBG("\tParent: %s, %s", t, group->parent->title);
group->parent->title);
track = group->track; track = group->track;
while (track->prev != NULL) { while (track->prev != NULL) {
@ -2873,8 +2861,7 @@ void mpl_debug_dump_state(void)
while (track) { while (track) {
(void)bt_ots_obj_id_to_str(track->id, t, sizeof(t)); (void)bt_ots_obj_id_to_str(track->id, t, sizeof(t));
BT_DBG("\tTrack: %s, %s, duration: %d", t, LOG_DBG("\tTrack: %s, %s, duration: %d", t, track->title, track->duration);
track->title, track->duration);
track = track->next; track = track->next;
} }
@ -2882,15 +2869,15 @@ void mpl_debug_dump_state(void)
} }
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
} }
#endif /* CONFIG_BT_DEBUG_MPL */ #endif /* CONFIG_BT_MPL_LOG_LEVEL_DBG */
#if defined(CONFIG_BT_MPL_LOG_LEVEL_DBG) && \
#if defined(CONFIG_BT_DEBUG_MPL) && defined(CONFIG_BT_TESTING) /* Special commands for testing */ defined(CONFIG_BT_TESTING) /* Special commands for testing */
#if CONFIG_BT_MPL_OBJECTS #if CONFIG_BT_MPL_OBJECTS
void mpl_test_unset_parent_group(void) void mpl_test_unset_parent_group(void)
{ {
BT_DBG("Setting current group to be it's own parent"); LOG_DBG("Setting current group to be it's own parent");
pl.group->parent = pl.group; pl.group->parent = pl.group;
} }
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
@ -2975,4 +2962,4 @@ void mpl_test_search_results_changed_cb(void)
} }
#endif /* CONFIG_BT_MPL_OBJECTS */ #endif /* CONFIG_BT_MPL_OBJECTS */
#endif /* CONFIG_BT_DEBUG_MPL && CONFIG_BT_TESTING */ #endif /* CONFIG_BT_MPL_LOG_LEVEL_DBG && CONFIG_BT_TESTING */

View file

@ -23,9 +23,10 @@
#include <zephyr/bluetooth/audio/pacs.h> #include <zephyr/bluetooth/audio/pacs.h>
#include "../host/conn_internal.h" #include "../host/conn_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_PACS) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_pacs
#include "common/log.h" LOG_MODULE_REGISTER(bt_pacs, CONFIG_BT_PACS_LOG_LEVEL);
#include "common/bt_str.h" #include "common/bt_str.h"
#include "audio_internal.h" #include "audio_internal.h"
@ -190,7 +191,7 @@ static void get_pac_records(struct bt_conn *conn, sys_slist_t *list,
static void available_context_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void available_context_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("attr %p value 0x%04x", attr, value); LOG_DBG("attr %p value 0x%04x", attr, value);
} }
static ssize_t available_contexts_read(struct bt_conn *conn, static ssize_t available_contexts_read(struct bt_conn *conn,
@ -202,8 +203,7 @@ static ssize_t available_contexts_read(struct bt_conn *conn,
.src = sys_cpu_to_le16(src_available_contexts), .src = sys_cpu_to_le16(src_available_contexts),
}; };
BT_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
offset);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &context, return bt_gatt_attr_read(conn, attr, buf, len, offset, &context,
sizeof(context)); sizeof(context));
@ -212,7 +212,7 @@ static ssize_t available_contexts_read(struct bt_conn *conn,
static void supported_context_cfg_changed(const struct bt_gatt_attr *attr, static void supported_context_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("attr %p value 0x%04x", attr, value); LOG_DBG("attr %p value 0x%04x", attr, value);
} }
static ssize_t supported_context_read(struct bt_conn *conn, static ssize_t supported_context_read(struct bt_conn *conn,
@ -224,8 +224,7 @@ static ssize_t supported_context_read(struct bt_conn *conn,
.src = sys_cpu_to_le16(src_supported_contexts), .src = sys_cpu_to_le16(src_supported_contexts),
}; };
BT_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
offset);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &context, return bt_gatt_attr_read(conn, attr, buf, len, offset, &context,
sizeof(context)); sizeof(context));
@ -264,8 +263,7 @@ static PACS(snk_pacs, pac_notify_snk);
static ssize_t snk_read(struct bt_conn *conn, const struct bt_gatt_attr *attr, static ssize_t snk_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset) void *buf, uint16_t len, uint16_t offset)
{ {
BT_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
offset);
get_pac_records(conn, &snk_pacs.list, &read_buf); get_pac_records(conn, &snk_pacs.list, &read_buf);
@ -275,7 +273,7 @@ static ssize_t snk_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
static void snk_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void snk_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("attr %p value 0x%04x", attr, value); LOG_DBG("attr %p value 0x%04x", attr, value);
} }
static inline int set_snk_available_contexts(uint16_t contexts) static inline int set_snk_available_contexts(uint16_t contexts)
@ -300,8 +298,7 @@ static ssize_t snk_loc_read(struct bt_conn *conn,
{ {
uint32_t location = sys_cpu_to_le32(snk_location.location); uint32_t location = sys_cpu_to_le32(snk_location.location);
BT_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
offset);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &location, return bt_gatt_attr_read(conn, attr, buf, len, offset, &location,
sizeof(location)); sizeof(location));
@ -309,7 +306,7 @@ static ssize_t snk_loc_read(struct bt_conn *conn,
static void snk_loc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void snk_loc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("attr %p value 0x%04x", attr, value); LOG_DBG("attr %p value 0x%04x", attr, value);
} }
static int set_snk_location(enum bt_audio_location audio_location) static int set_snk_location(enum bt_audio_location audio_location)
@ -349,13 +346,13 @@ static ssize_t snk_loc_write(struct bt_conn *conn,
location = (enum bt_audio_location)sys_get_le32(data); location = (enum bt_audio_location)sys_get_le32(data);
if (location > BT_AUDIO_LOCATION_MASK || location == 0) { if (location > BT_AUDIO_LOCATION_MASK || location == 0) {
BT_DBG("Invalid location value: 0x%08X", location); LOG_DBG("Invalid location value: 0x%08X", location);
return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED); return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED);
} }
err = set_snk_location(location); err = set_snk_location(location);
if (err != 0) { if (err != 0) {
BT_DBG("write_location returned %d", err); LOG_DBG("write_location returned %d", err);
return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED); return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED);
} }
@ -370,8 +367,7 @@ static PACS(src_pacs, pac_notify_src);
static ssize_t src_read(struct bt_conn *conn, const struct bt_gatt_attr *attr, static ssize_t src_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset) void *buf, uint16_t len, uint16_t offset)
{ {
BT_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
offset);
get_pac_records(conn, &src_pacs.list, &read_buf); get_pac_records(conn, &src_pacs.list, &read_buf);
@ -381,7 +377,7 @@ static ssize_t src_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
static void src_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void src_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("attr %p value 0x%04x", attr, value); LOG_DBG("attr %p value 0x%04x", attr, value);
} }
static inline int set_src_available_contexts(uint16_t contexts) static inline int set_src_available_contexts(uint16_t contexts)
@ -406,8 +402,7 @@ static ssize_t src_loc_read(struct bt_conn *conn,
{ {
uint32_t location = sys_cpu_to_le32(src_location.location); uint32_t location = sys_cpu_to_le32(src_location.location);
BT_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, LOG_DBG("conn %p attr %p buf %p len %u offset %u", conn, attr, buf, len, offset);
offset);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &location, return bt_gatt_attr_read(conn, attr, buf, len, offset, &location,
sizeof(location)); sizeof(location));
@ -415,7 +410,7 @@ static ssize_t src_loc_read(struct bt_conn *conn,
static void src_loc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void src_loc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("attr %p value 0x%04x", attr, value); LOG_DBG("attr %p value 0x%04x", attr, value);
} }
static int set_src_location(enum bt_audio_location audio_location) static int set_src_location(enum bt_audio_location audio_location)
@ -455,13 +450,13 @@ static ssize_t src_loc_write(struct bt_conn *conn,
location = (enum bt_audio_location)sys_get_le32(data); location = (enum bt_audio_location)sys_get_le32(data);
if (location > BT_AUDIO_LOCATION_MASK || location == 0) { if (location > BT_AUDIO_LOCATION_MASK || location == 0) {
BT_DBG("Invalid location value: 0x%08X", location); LOG_DBG("Invalid location value: 0x%08X", location);
return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED); return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED);
} }
err = set_src_location(location); err = set_src_location(location);
if (err != 0) { if (err != 0) {
BT_DBG("write_location returned %d", err); LOG_DBG("write_location returned %d", err);
return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED); return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED);
} }
@ -535,7 +530,7 @@ static void pac_notify_snk_loc(struct k_work *work)
err = bt_gatt_notify_uuid(NULL, BT_UUID_PACS_SNK_LOC, pacs_svc.attrs, &location_le, err = bt_gatt_notify_uuid(NULL, BT_UUID_PACS_SNK_LOC, pacs_svc.attrs, &location_le,
sizeof(location_le)); sizeof(location_le));
if (err != 0 && err != -ENOTCONN) { if (err != 0 && err != -ENOTCONN) {
BT_WARN("PACS notify_loc failed: %d", err); LOG_WRN("PACS notify_loc failed: %d", err);
} }
} }
#endif /* CONFIG_BT_PAC_SNK_LOC */ #endif /* CONFIG_BT_PAC_SNK_LOC */
@ -550,7 +545,7 @@ static void pac_notify_src_loc(struct k_work *work)
err = bt_gatt_notify_uuid(NULL, BT_UUID_PACS_SRC_LOC, pacs_svc.attrs, &location_le, err = bt_gatt_notify_uuid(NULL, BT_UUID_PACS_SRC_LOC, pacs_svc.attrs, &location_le,
sizeof(location_le)); sizeof(location_le));
if (err != 0 && err != -ENOTCONN) { if (err != 0 && err != -ENOTCONN) {
BT_WARN("PACS notify_loc failed: %d", err); LOG_WRN("PACS notify_loc failed: %d", err);
} }
} }
#endif /* CONFIG_BT_PAC_SRC_LOC */ #endif /* CONFIG_BT_PAC_SRC_LOC */
@ -566,7 +561,7 @@ static void pac_notify_snk(struct k_work *work)
err = bt_gatt_notify_uuid(NULL, BT_UUID_PACS_SNK, pacs_svc.attrs, err = bt_gatt_notify_uuid(NULL, BT_UUID_PACS_SNK, pacs_svc.attrs,
read_buf.data, read_buf.len); read_buf.data, read_buf.len);
if (err != 0 && err != -ENOTCONN) { if (err != 0 && err != -ENOTCONN) {
BT_WARN("PACS notify failed: %d", err); LOG_WRN("PACS notify failed: %d", err);
} }
} }
#endif /* CONFIG_BT_PAC_SNK */ #endif /* CONFIG_BT_PAC_SNK */
@ -582,7 +577,7 @@ static void pac_notify_src(struct k_work *work)
err = bt_gatt_notify_uuid(NULL, BT_UUID_PACS_SRC, pacs_svc.attrs, err = bt_gatt_notify_uuid(NULL, BT_UUID_PACS_SRC, pacs_svc.attrs,
read_buf.data, read_buf.len); read_buf.data, read_buf.len);
if (err != 0 && err != -ENOTCONN) { if (err != 0 && err != -ENOTCONN) {
BT_WARN("PACS notify failed: %d", err); LOG_WRN("PACS notify failed: %d", err);
} }
} }
#endif /* CONFIG_BT_PAC_SRC */ #endif /* CONFIG_BT_PAC_SRC */
@ -603,7 +598,7 @@ static void available_contexts_notify(struct k_work *work)
err = bt_gatt_notify_uuid(NULL, BT_UUID_PACS_AVAILABLE_CONTEXT, pacs_svc.attrs, err = bt_gatt_notify_uuid(NULL, BT_UUID_PACS_AVAILABLE_CONTEXT, pacs_svc.attrs,
&context, sizeof(context)); &context, sizeof(context));
if (err != 0 && err != -ENOTCONN) { if (err != 0 && err != -ENOTCONN) {
BT_WARN("Available Audio Contexts notify failed: %d", err); LOG_WRN("Available Audio Contexts notify failed: %d", err);
} }
} }
@ -641,7 +636,7 @@ void bt_pacs_cap_foreach(enum bt_audio_dir dir, bt_pacs_cap_foreach_func_t func,
struct pacs *pac; struct pacs *pac;
CHECKIF(func == NULL) { CHECKIF(func == NULL) {
BT_ERR("func is NULL"); LOG_ERR("func is NULL");
return; return;
} }
@ -667,7 +662,7 @@ int bt_pacs_cap_register(enum bt_audio_dir dir, struct bt_pacs_cap *cap)
return -EINVAL; return -EINVAL;
} }
BT_DBG("cap %p dir 0x%02x codec 0x%02x codec cid 0x%04x " LOG_DBG("cap %p dir 0x%02x codec 0x%02x codec cid 0x%04x "
"codec vid 0x%04x", cap, dir, cap->codec->id, "codec vid 0x%04x", cap, dir, cap->codec->id,
cap->codec->cid, cap->codec->vid); cap->codec->cid, cap->codec->vid);
@ -692,7 +687,7 @@ int bt_pacs_cap_unregister(enum bt_audio_dir dir, struct bt_pacs_cap *cap)
return -EINVAL; return -EINVAL;
} }
BT_DBG("cap %p dir 0x%02x", cap, dir); LOG_DBG("cap %p dir 0x%02x", cap, dir);
if (!sys_slist_find_and_remove(&pac->list, &cap->_node)) { if (!sys_slist_find_and_remove(&pac->list, &cap->_node)) {
return -ENOENT; return -ENOENT;

View file

@ -14,6 +14,7 @@
#include <zephyr/bluetooth/bluetooth.h> #include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h> #include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h> #include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/iso.h> #include <zephyr/bluetooth/iso.h>
#include <zephyr/bluetooth/audio/audio.h> #include <zephyr/bluetooth/audio/audio.h>
@ -25,9 +26,9 @@
#include "unicast_client_internal.h" #include "unicast_client_internal.h"
#include "unicast_server.h" #include "unicast_server.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_STREAM) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_audio_stream
#include "common/log.h" LOG_MODULE_REGISTER(bt_audio_stream, CONFIG_BT_AUDIO_STREAM_LOG_LEVEL);
static uint8_t pack_bt_codec_cc(const struct bt_codec *codec, uint8_t cc[]) static uint8_t pack_bt_codec_cc(const struct bt_codec *codec, uint8_t cc[])
{ {
@ -74,7 +75,7 @@ void bt_audio_stream_attach(struct bt_conn *conn,
struct bt_audio_ep *ep, struct bt_audio_ep *ep,
struct bt_codec *codec) struct bt_codec *codec)
{ {
BT_DBG("conn %p stream %p ep %p codec %p", conn, stream, ep, codec); LOG_DBG("conn %p stream %p ep %p codec %p", conn, stream, ep, codec);
if (conn != NULL) { if (conn != NULL) {
__ASSERT(stream->conn == NULL || stream->conn == conn, __ASSERT(stream->conn == NULL || stream->conn == conn,
@ -106,31 +107,31 @@ bool bt_audio_valid_qos(const struct bt_codec_qos *qos)
{ {
if (qos->interval < BT_ISO_SDU_INTERVAL_MIN || if (qos->interval < BT_ISO_SDU_INTERVAL_MIN ||
qos->interval > BT_ISO_SDU_INTERVAL_MAX) { qos->interval > BT_ISO_SDU_INTERVAL_MAX) {
BT_DBG("Interval not within allowed range: %u (%u-%u)", LOG_DBG("Interval not within allowed range: %u (%u-%u)", qos->interval,
qos->interval, BT_ISO_SDU_INTERVAL_MIN, BT_ISO_SDU_INTERVAL_MAX); BT_ISO_SDU_INTERVAL_MIN, BT_ISO_SDU_INTERVAL_MAX);
return false; return false;
} }
if (qos->framing > BT_CODEC_QOS_FRAMED) { if (qos->framing > BT_CODEC_QOS_FRAMED) {
BT_DBG("Invalid Framing 0x%02x", qos->framing); LOG_DBG("Invalid Framing 0x%02x", qos->framing);
return false; return false;
} }
if (qos->phy != BT_CODEC_QOS_1M && if (qos->phy != BT_CODEC_QOS_1M &&
qos->phy != BT_CODEC_QOS_2M && qos->phy != BT_CODEC_QOS_2M &&
qos->phy != BT_CODEC_QOS_CODED) { qos->phy != BT_CODEC_QOS_CODED) {
BT_DBG("Invalid PHY 0x%02x", qos->phy); LOG_DBG("Invalid PHY 0x%02x", qos->phy);
return false; return false;
} }
if (qos->sdu > BT_ISO_MAX_SDU) { if (qos->sdu > BT_ISO_MAX_SDU) {
BT_DBG("Invalid SDU %u", qos->sdu); LOG_DBG("Invalid SDU %u", qos->sdu);
return false; return false;
} }
if (qos->latency < BT_ISO_LATENCY_MIN || if (qos->latency < BT_ISO_LATENCY_MIN ||
qos->latency > BT_ISO_LATENCY_MAX) { qos->latency > BT_ISO_LATENCY_MAX) {
BT_DBG("Invalid Latency %u", qos->latency); LOG_DBG("Invalid Latency %u", qos->latency);
return false; return false;
} }
@ -149,8 +150,8 @@ int bt_audio_stream_send(struct bt_audio_stream *stream, struct net_buf *buf,
ep = stream->ep; ep = stream->ep;
if (ep->status.state != BT_AUDIO_EP_STATE_STREAMING) { if (ep->status.state != BT_AUDIO_EP_STATE_STREAMING) {
BT_DBG("Channel %p not ready for streaming (state: %s)", LOG_DBG("Channel %p not ready for streaming (state: %s)", stream,
stream, bt_audio_ep_state_str(ep->status.state)); bt_audio_ep_state_str(ep->status.state));
return -EBADMSG; return -EBADMSG;
} }
@ -174,7 +175,7 @@ static int bt_audio_stream_iso_accept(const struct bt_iso_accept_info *info,
{ {
int i; int i;
BT_DBG("acl %p", info->acl); LOG_DBG("acl %p", info->acl);
for (i = 0; i < ARRAY_SIZE(enabling); i++) { for (i = 0; i < ARRAY_SIZE(enabling); i++) {
struct bt_audio_stream *c = enabling[i]; struct bt_audio_stream *c = enabling[i];
@ -184,13 +185,13 @@ static int bt_audio_stream_iso_accept(const struct bt_iso_accept_info *info,
*iso_chan = &enabling[i]->ep->iso->chan; *iso_chan = &enabling[i]->ep->iso->chan;
enabling[i] = NULL; enabling[i] = NULL;
BT_DBG("iso_chan %p", *iso_chan); LOG_DBG("iso_chan %p", *iso_chan);
return 0; return 0;
} }
} }
BT_ERR("No channel listening"); LOG_ERR("No channel listening");
return -EPERM; return -EPERM;
} }
@ -206,7 +207,7 @@ int bt_audio_stream_iso_listen(struct bt_audio_stream *stream)
int err, i; int err, i;
struct bt_audio_stream **free_stream = NULL; struct bt_audio_stream **free_stream = NULL;
BT_DBG("stream %p conn %p", stream, stream->conn); LOG_DBG("stream %p conn %p", stream, stream->conn);
if (server) { if (server) {
goto done; goto done;
@ -214,7 +215,7 @@ int bt_audio_stream_iso_listen(struct bt_audio_stream *stream)
err = bt_iso_server_register(&iso_server); err = bt_iso_server_register(&iso_server);
if (err) { if (err) {
BT_ERR("bt_iso_server_register: %d", err); LOG_ERR("bt_iso_server_register: %d", err);
return err; return err;
} }
@ -236,7 +237,7 @@ done:
return 0; return 0;
} }
BT_ERR("Unable to listen: no slot left"); LOG_ERR("Unable to listen: no slot left");
return -ENOSPC; return -ENOSPC;
} }
@ -257,12 +258,11 @@ bool bt_audio_valid_stream_qos(const struct bt_audio_stream *stream,
if (qos_pref->latency < qos->latency) { if (qos_pref->latency < qos->latency) {
/* Latency is a preferred value. Print debug info but do not fail. */ /* Latency is a preferred value. Print debug info but do not fail. */
BT_DBG("Latency %u higher than preferred max %u", LOG_DBG("Latency %u higher than preferred max %u", qos->latency, qos_pref->latency);
qos->latency, qos_pref->latency);
} }
if (!IN_RANGE(qos->pd, qos_pref->pd_min, qos_pref->pd_max)) { if (!IN_RANGE(qos->pd, qos_pref->pd_min, qos_pref->pd_max)) {
BT_DBG("Presentation Delay not within range: min %u max %u pd %u", LOG_DBG("Presentation Delay not within range: min %u max %u pd %u",
qos_pref->pd_min, qos_pref->pd_max, qos->pd); qos_pref->pd_min, qos_pref->pd_max, qos->pd);
return false; return false;
} }
@ -274,7 +274,7 @@ void bt_audio_stream_detach(struct bt_audio_stream *stream)
{ {
const bool is_broadcast = bt_audio_stream_is_broadcast(stream); const bool is_broadcast = bt_audio_stream_is_broadcast(stream);
BT_DBG("stream %p", stream); LOG_DBG("stream %p", stream);
if (stream->conn != NULL) { if (stream->conn != NULL) {
bt_conn_unref(stream->conn); bt_conn_unref(stream->conn);
@ -293,7 +293,7 @@ int bt_audio_stream_disconnect(struct bt_audio_stream *stream)
{ {
struct bt_iso_chan *iso_chan = bt_audio_stream_iso_chan_get(stream); struct bt_iso_chan *iso_chan = bt_audio_stream_iso_chan_get(stream);
BT_DBG("stream %p iso %p", stream, iso_chan); LOG_DBG("stream %p iso %p", stream, iso_chan);
if (stream == NULL) { if (stream == NULL) {
return -EINVAL; return -EINVAL;
@ -318,7 +318,7 @@ int bt_audio_stream_disconnect(struct bt_audio_stream *stream)
void bt_audio_stream_reset(struct bt_audio_stream *stream) void bt_audio_stream_reset(struct bt_audio_stream *stream)
{ {
BT_DBG("stream %p", stream); LOG_DBG("stream %p", stream);
if (stream == NULL) { if (stream == NULL) {
return; return;
@ -337,24 +337,24 @@ int bt_audio_stream_config(struct bt_conn *conn,
uint8_t role; uint8_t role;
int err; int err;
BT_DBG("conn %p stream %p, ep %p codec %p codec id 0x%02x " LOG_DBG("conn %p stream %p, ep %p codec %p codec id 0x%02x "
"codec cid 0x%04x codec vid 0x%04x", conn, stream, ep, "codec cid 0x%04x codec vid 0x%04x", conn, stream, ep,
codec, codec ? codec->id : 0, codec ? codec->cid : 0, codec, codec ? codec->id : 0, codec ? codec->cid : 0,
codec ? codec->vid : 0); codec ? codec->vid : 0);
CHECKIF(conn == NULL || stream == NULL || codec == NULL) { CHECKIF(conn == NULL || stream == NULL || codec == NULL) {
BT_DBG("NULL value(s) supplied)"); LOG_DBG("NULL value(s) supplied)");
return -EINVAL; return -EINVAL;
} }
if (stream->conn != NULL) { if (stream->conn != NULL) {
BT_DBG("Stream already configured for conn %p", stream->conn); LOG_DBG("Stream already configured for conn %p", stream->conn);
return -EALREADY; return -EALREADY;
} }
role = conn->role; role = conn->role;
if (role != BT_HCI_ROLE_CENTRAL) { if (role != BT_HCI_ROLE_CENTRAL) {
BT_DBG("Invalid conn role: %u, shall be central", role); LOG_DBG("Invalid conn role: %u, shall be central", role);
return -EINVAL; return -EINVAL;
} }
@ -367,8 +367,7 @@ int bt_audio_stream_config(struct bt_conn *conn,
case BT_AUDIO_EP_STATE_QOS_CONFIGURED: case BT_AUDIO_EP_STATE_QOS_CONFIGURED:
break; break;
default: default:
BT_ERR("Invalid state: %s", LOG_ERR("Invalid state: %s", bt_audio_ep_state_str(ep->status.state));
bt_audio_ep_state_str(ep->status.state));
return -EBADMSG; return -EBADMSG;
} }
@ -376,7 +375,7 @@ int bt_audio_stream_config(struct bt_conn *conn,
err = bt_unicast_client_config(stream, codec); err = bt_unicast_client_config(stream, codec);
if (err != 0) { if (err != 0) {
BT_DBG("Failed to configure stream: %d", err); LOG_DBG("Failed to configure stream: %d", err);
return err; return err;
} }
@ -400,7 +399,7 @@ static int bt_audio_cig_create(struct bt_audio_unicast_group *group,
uint8_t cis_count; uint8_t cis_count;
int err; int err;
BT_DBG("group %p qos %p", group, qos); LOG_DBG("group %p qos %p", group, qos);
cis_count = 0; cis_count = 0;
for (size_t i = 0; i < ARRAY_SIZE(group->cis); i++) { for (size_t i = 0; i < ARRAY_SIZE(group->cis); i++) {
@ -415,7 +414,7 @@ static int bt_audio_cig_create(struct bt_audio_unicast_group *group,
err = bt_iso_cig_create(&param, &group->cig); err = bt_iso_cig_create(&param, &group->cig);
if (err != 0) { if (err != 0) {
BT_ERR("bt_iso_cig_create failed: %d", err); LOG_ERR("bt_iso_cig_create failed: %d", err);
return err; return err;
} }
@ -431,7 +430,7 @@ static int bt_audio_cig_reconfigure(struct bt_audio_unicast_group *group,
uint8_t cis_count; uint8_t cis_count;
int err; int err;
BT_DBG("group %p qos %p", group, qos); LOG_DBG("group %p qos %p", group, qos);
cis_count = 0U; cis_count = 0U;
for (size_t i = 0; i < ARRAY_SIZE(group->cis); i++) { for (size_t i = 0; i < ARRAY_SIZE(group->cis); i++) {
@ -446,7 +445,7 @@ static int bt_audio_cig_reconfigure(struct bt_audio_unicast_group *group,
err = bt_iso_cig_reconfigure(group->cig, &param); err = bt_iso_cig_reconfigure(group->cig, &param);
if (err != 0) { if (err != 0) {
BT_ERR("bt_iso_cig_create failed: %d", err); LOG_ERR("bt_iso_cig_create failed: %d", err);
return err; return err;
} }
@ -482,26 +481,26 @@ int bt_audio_stream_qos(struct bt_conn *conn,
uint8_t role; uint8_t role;
int err; int err;
BT_DBG("conn %p group %p", conn, group); LOG_DBG("conn %p group %p", conn, group);
CHECKIF(conn == NULL) { CHECKIF(conn == NULL) {
BT_DBG("conn is NULL"); LOG_DBG("conn is NULL");
return -EINVAL; return -EINVAL;
} }
CHECKIF(group == NULL) { CHECKIF(group == NULL) {
BT_DBG("group is NULL"); LOG_DBG("group is NULL");
return -EINVAL; return -EINVAL;
} }
if (sys_slist_is_empty(&group->streams)) { if (sys_slist_is_empty(&group->streams)) {
BT_DBG("group stream list is empty"); LOG_DBG("group stream list is empty");
return -ENOEXEC; return -ENOEXEC;
} }
role = conn->role; role = conn->role;
if (role != BT_HCI_ROLE_CENTRAL) { if (role != BT_HCI_ROLE_CENTRAL) {
BT_DBG("Invalid conn role: %u, shall be central", role); LOG_DBG("Invalid conn role: %u, shall be central", role);
return -EINVAL; return -EINVAL;
} }
@ -525,7 +524,7 @@ int bt_audio_stream_qos(struct bt_conn *conn,
ep = stream->ep; ep = stream->ep;
if (ep == NULL) { if (ep == NULL) {
BT_DBG("stream->ep is NULL"); LOG_DBG("stream->ep is NULL");
return -EINVAL; return -EINVAL;
} }
@ -537,8 +536,8 @@ int bt_audio_stream_qos(struct bt_conn *conn,
case BT_AUDIO_EP_STATE_QOS_CONFIGURED: case BT_AUDIO_EP_STATE_QOS_CONFIGURED:
break; break;
default: default:
BT_DBG("Invalid state: %s", LOG_DBG("Invalid state: %s",
bt_audio_ep_state_str(stream->ep->status.state)); bt_audio_ep_state_str(stream->ep->status.state));
return -EINVAL; return -EINVAL;
} }
@ -560,13 +559,13 @@ int bt_audio_stream_qos(struct bt_conn *conn,
/* This can only happen if the stream was somehow added /* This can only happen if the stream was somehow added
* to a group without the audio_iso being bound to it * to a group without the audio_iso being bound to it
*/ */
BT_ERR("Could not find audio_iso for stream %p", stream); LOG_ERR("Could not find audio_iso for stream %p", stream);
return -EINVAL; return -EINVAL;
} }
} }
if (!conn_stream_found) { if (!conn_stream_found) {
BT_DBG("No streams in the group %p for conn %p", group, conn); LOG_DBG("No streams in the group %p for conn %p", group, conn);
return -EINVAL; return -EINVAL;
} }
@ -598,7 +597,7 @@ int bt_audio_stream_qos(struct bt_conn *conn,
err = bt_unicast_client_ep_send(conn, ep, buf); err = bt_unicast_client_ep_send(conn, ep, buf);
if (err != 0) { if (err != 0) {
BT_DBG("Could not send config QoS: %d", err); LOG_DBG("Could not send config QoS: %d", err);
audio_stream_qos_cleanup(conn, group); audio_stream_qos_cleanup(conn, group);
return err; return err;
} }
@ -613,29 +612,28 @@ int bt_audio_stream_enable(struct bt_audio_stream *stream,
uint8_t role; uint8_t role;
int err; int err;
BT_DBG("stream %p", stream); LOG_DBG("stream %p", stream);
if (stream == NULL || stream->ep == NULL || stream->conn == NULL) { if (stream == NULL || stream->ep == NULL || stream->conn == NULL) {
BT_DBG("Invalid stream"); LOG_DBG("Invalid stream");
return -EINVAL; return -EINVAL;
} }
role = stream->conn->role; role = stream->conn->role;
if (role != BT_HCI_ROLE_CENTRAL) { if (role != BT_HCI_ROLE_CENTRAL) {
BT_DBG("Invalid conn role: %u, shall be central", role); LOG_DBG("Invalid conn role: %u, shall be central", role);
return -EINVAL; return -EINVAL;
} }
/* Valid for an ASE only if ASE_State field = 0x02 (QoS Configured) */ /* Valid for an ASE only if ASE_State field = 0x02 (QoS Configured) */
if (stream->ep->status.state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) { if (stream->ep->status.state != BT_AUDIO_EP_STATE_QOS_CONFIGURED) {
BT_ERR("Invalid state: %s", LOG_ERR("Invalid state: %s", bt_audio_ep_state_str(stream->ep->status.state));
bt_audio_ep_state_str(stream->ep->status.state));
return -EBADMSG; return -EBADMSG;
} }
err = bt_unicast_client_enable(stream, meta, meta_count); err = bt_unicast_client_enable(stream, meta, meta_count);
if (err != 0) { if (err != 0) {
BT_DBG("Failed to enable stream: %d", err); LOG_DBG("Failed to enable stream: %d", err);
return err; return err;
} }
@ -649,13 +647,13 @@ int bt_audio_stream_stop(struct bt_audio_stream *stream)
int err; int err;
if (stream == NULL || stream->ep == NULL || stream->conn == NULL) { if (stream == NULL || stream->ep == NULL || stream->conn == NULL) {
BT_DBG("Invalid stream"); LOG_DBG("Invalid stream");
return -EINVAL; return -EINVAL;
} }
role = stream->conn->role; role = stream->conn->role;
if (role != BT_HCI_ROLE_CENTRAL) { if (role != BT_HCI_ROLE_CENTRAL) {
BT_DBG("Invalid conn role: %u, shall be central", role); LOG_DBG("Invalid conn role: %u, shall be central", role);
return -EINVAL; return -EINVAL;
} }
@ -666,14 +664,13 @@ int bt_audio_stream_stop(struct bt_audio_stream *stream)
case BT_AUDIO_EP_STATE_DISABLING: case BT_AUDIO_EP_STATE_DISABLING:
break; break;
default: default:
BT_ERR("Invalid state: %s", LOG_ERR("Invalid state: %s", bt_audio_ep_state_str(ep->status.state));
bt_audio_ep_state_str(ep->status.state));
return -EBADMSG; return -EBADMSG;
} }
err = bt_unicast_client_stop(stream); err = bt_unicast_client_stop(stream);
if (err != 0) { if (err != 0) {
BT_DBG("Stopping stream failed: %d", err); LOG_DBG("Stopping stream failed: %d", err);
return err; return err;
} }
@ -682,7 +679,7 @@ int bt_audio_stream_stop(struct bt_audio_stream *stream)
int bt_audio_cig_terminate(struct bt_audio_unicast_group *group) int bt_audio_cig_terminate(struct bt_audio_unicast_group *group)
{ {
BT_DBG("group %p", group); LOG_DBG("group %p", group);
return bt_iso_cig_terminate(group->cig); return bt_iso_cig_terminate(group->cig);
} }
@ -694,7 +691,7 @@ int bt_audio_stream_connect(struct bt_audio_stream *stream)
iso_chan = bt_audio_stream_iso_chan_get(stream); iso_chan = bt_audio_stream_iso_chan_get(stream);
BT_DBG("stream %p iso %p", stream, iso_chan); LOG_DBG("stream %p iso %p", stream, iso_chan);
if (stream == NULL || iso_chan == NULL) { if (stream == NULL || iso_chan == NULL) {
return -EINVAL; return -EINVAL;
@ -846,7 +843,7 @@ static int unicast_group_add_stream(struct bt_audio_unicast_group *group,
stream->unicast_group = group; stream->unicast_group = group;
sys_slist_append(&group->streams, &stream->_node); sys_slist_append(&group->streams, &stream->_node);
BT_DBG("Added stream %p to group %p", stream, group); LOG_DBG("Added stream %p to group %p", stream, group);
return 0; return 0;
} }
@ -909,20 +906,19 @@ int bt_audio_unicast_group_create(struct bt_audio_unicast_group_param params[],
int err; int err;
CHECKIF(out_unicast_group == NULL) { CHECKIF(out_unicast_group == NULL) {
BT_DBG("out_unicast_group is NULL"); LOG_DBG("out_unicast_group is NULL");
return -EINVAL; return -EINVAL;
} }
/* Set out_unicast_group to NULL until the source has actually been created */ /* Set out_unicast_group to NULL until the source has actually been created */
*out_unicast_group = NULL; *out_unicast_group = NULL;
CHECKIF(params == NULL) { CHECKIF(params == NULL) {
BT_DBG("streams is NULL"); LOG_DBG("streams is NULL");
return -EINVAL; return -EINVAL;
} }
CHECKIF(num_param > UNICAST_GROUP_STREAM_CNT) { CHECKIF(num_param > UNICAST_GROUP_STREAM_CNT) {
BT_DBG("Too many streams provided: %u/%u", LOG_DBG("Too many streams provided: %u/%u", num_param, UNICAST_GROUP_STREAM_CNT);
num_param, UNICAST_GROUP_STREAM_CNT);
return -EINVAL; return -EINVAL;
} }
@ -931,32 +927,32 @@ int bt_audio_unicast_group_create(struct bt_audio_unicast_group_param params[],
params[i].qos == NULL || params[i].qos == NULL ||
(params[i].dir != BT_AUDIO_DIR_SINK && (params[i].dir != BT_AUDIO_DIR_SINK &&
params[i].dir != BT_AUDIO_DIR_SOURCE)) { params[i].dir != BT_AUDIO_DIR_SOURCE)) {
BT_DBG("Invalid params[%zu] values", i); LOG_DBG("Invalid params[%zu] values", i);
return -EINVAL; return -EINVAL;
} }
if (params[i].stream->group != NULL) { if (params[i].stream->group != NULL) {
BT_DBG("params[%zu] stream (%p) already part of group %p", LOG_DBG("params[%zu] stream (%p) already part of group %p", i,
i, params[i].stream, params[i].stream->group); params[i].stream, params[i].stream->group);
return -EALREADY; return -EALREADY;
} }
if (group_qos == NULL) { if (group_qos == NULL) {
group_qos = params[i].qos; group_qos = params[i].qos;
} else if (!unicast_group_valid_qos(group_qos, params[i].qos)) { } else if (!unicast_group_valid_qos(group_qos, params[i].qos)) {
BT_DBG("Stream[%zu] QoS incompatible with group QoS", i); LOG_DBG("Stream[%zu] QoS incompatible with group QoS", i);
return -EINVAL; return -EINVAL;
} }
CHECKIF(!bt_audio_valid_qos(params[i].qos)) { CHECKIF(!bt_audio_valid_qos(params[i].qos)) {
BT_DBG("Invalid QoS"); LOG_DBG("Invalid QoS");
return -EINVAL; return -EINVAL;
} }
} }
unicast_group = unicast_group_alloc(); unicast_group = unicast_group_alloc();
if (unicast_group == NULL) { if (unicast_group == NULL) {
BT_DBG("Could not allocate any more unicast groups"); LOG_DBG("Could not allocate any more unicast groups");
return -ENOMEM; return -ENOMEM;
} }
@ -964,7 +960,7 @@ int bt_audio_unicast_group_create(struct bt_audio_unicast_group_param params[],
err = unicast_group_add_stream(unicast_group, params[i].stream, err = unicast_group_add_stream(unicast_group, params[i].stream,
params[i].qos, params[i].dir); params[i].qos, params[i].dir);
if (err < 0) { if (err < 0) {
BT_DBG("unicast_group_add_stream failed: %d", err); LOG_DBG("unicast_group_add_stream failed: %d", err);
unicast_group_free(unicast_group); unicast_group_free(unicast_group);
return err; return err;
@ -973,7 +969,7 @@ int bt_audio_unicast_group_create(struct bt_audio_unicast_group_param params[],
err = bt_audio_cig_create(unicast_group, group_qos); err = bt_audio_cig_create(unicast_group, group_qos);
if (err != 0) { if (err != 0) {
BT_DBG("bt_audio_cig_create failed: %d", err); LOG_DBG("bt_audio_cig_create failed: %d", err);
unicast_group_free(unicast_group); unicast_group_free(unicast_group);
return err; return err;
@ -996,17 +992,17 @@ int bt_audio_unicast_group_add_streams(struct bt_audio_unicast_group *unicast_gr
int err; int err;
CHECKIF(unicast_group == NULL) { CHECKIF(unicast_group == NULL) {
BT_DBG("unicast_group is NULL"); LOG_DBG("unicast_group is NULL");
return -EINVAL; return -EINVAL;
} }
CHECKIF(params == NULL) { CHECKIF(params == NULL) {
BT_DBG("params is NULL"); LOG_DBG("params is NULL");
return -EINVAL; return -EINVAL;
} }
CHECKIF(num_param == 0) { CHECKIF(num_param == 0) {
BT_DBG("num_param is 0"); LOG_DBG("num_param is 0");
return -EINVAL; return -EINVAL;
} }
@ -1015,20 +1011,20 @@ int bt_audio_unicast_group_add_streams(struct bt_audio_unicast_group *unicast_gr
params[i].qos == NULL || params[i].qos == NULL ||
(params[i].dir != BT_AUDIO_DIR_SINK && (params[i].dir != BT_AUDIO_DIR_SINK &&
params[i].dir != BT_AUDIO_DIR_SOURCE)) { params[i].dir != BT_AUDIO_DIR_SOURCE)) {
BT_DBG("Invalid params[%zu] values", i); LOG_DBG("Invalid params[%zu] values", i);
return -EINVAL; return -EINVAL;
} }
if (params[i].stream->group != NULL) { if (params[i].stream->group != NULL) {
BT_DBG("params[%zu] stream (%p) already part of group %p", LOG_DBG("params[%zu] stream (%p) already part of group %p", i,
i, params[i].stream, params[i].stream->group); params[i].stream, params[i].stream->group);
return -EALREADY; return -EALREADY;
} }
if (group_qos == NULL) { if (group_qos == NULL) {
group_qos = params[i].qos; group_qos = params[i].qos;
} else if (!unicast_group_valid_qos(group_qos, params[i].qos)) { } else if (!unicast_group_valid_qos(group_qos, params[i].qos)) {
BT_DBG("Stream[%zu] QoS incompatible with group QoS", i); LOG_DBG("Stream[%zu] QoS incompatible with group QoS", i);
return -EINVAL; return -EINVAL;
} }
} }
@ -1039,8 +1035,8 @@ int bt_audio_unicast_group_add_streams(struct bt_audio_unicast_group *unicast_gr
} }
if (total_stream_cnt > UNICAST_GROUP_STREAM_CNT) { if (total_stream_cnt > UNICAST_GROUP_STREAM_CNT) {
BT_DBG("Too many streams provided: %u/%u", LOG_DBG("Too many streams provided: %u/%u", total_stream_cnt,
total_stream_cnt, UNICAST_GROUP_STREAM_CNT); UNICAST_GROUP_STREAM_CNT);
return -EINVAL; return -EINVAL;
} }
@ -1050,7 +1046,7 @@ int bt_audio_unicast_group_add_streams(struct bt_audio_unicast_group *unicast_gr
*/ */
cig = unicast_group->cig; cig = unicast_group->cig;
if (cig != NULL && cig->state != BT_ISO_CIG_STATE_CONFIGURED) { if (cig != NULL && cig->state != BT_ISO_CIG_STATE_CONFIGURED) {
BT_DBG("At least one unicast group stream is started"); LOG_DBG("At least one unicast group stream is started");
return -EBADMSG; return -EBADMSG;
} }
@ -1060,14 +1056,14 @@ int bt_audio_unicast_group_add_streams(struct bt_audio_unicast_group *unicast_gr
params[num_added].qos, params[num_added].qos,
params[num_added].dir); params[num_added].dir);
if (err < 0) { if (err < 0) {
BT_DBG("unicast_group_add_stream failed: %d", err); LOG_DBG("unicast_group_add_stream failed: %d", err);
goto fail; goto fail;
} }
} }
err = bt_audio_cig_reconfigure(unicast_group, group_qos); err = bt_audio_cig_reconfigure(unicast_group, group_qos);
if (err != 0) { if (err != 0) {
BT_DBG("bt_audio_cig_reconfigure failed: %d", err); LOG_DBG("bt_audio_cig_reconfigure failed: %d", err);
goto fail; goto fail;
} }
@ -1085,7 +1081,7 @@ fail:
int bt_audio_unicast_group_delete(struct bt_audio_unicast_group *unicast_group) int bt_audio_unicast_group_delete(struct bt_audio_unicast_group *unicast_group)
{ {
CHECKIF(unicast_group == NULL) { CHECKIF(unicast_group == NULL) {
BT_DBG("unicast_group is NULL"); LOG_DBG("unicast_group is NULL");
return -EINVAL; return -EINVAL;
} }
@ -1093,8 +1089,7 @@ int bt_audio_unicast_group_delete(struct bt_audio_unicast_group *unicast_group)
const int err = bt_audio_cig_terminate(unicast_group); const int err = bt_audio_cig_terminate(unicast_group);
if (err != 0) { if (err != 0) {
BT_DBG("bt_audio_cig_terminate failed with err %d", LOG_DBG("bt_audio_cig_terminate failed with err %d", err);
err);
return err; return err;
} }
@ -1114,15 +1109,15 @@ int bt_audio_stream_reconfig(struct bt_audio_stream *stream,
uint8_t role; uint8_t role;
int err; int err;
BT_DBG("stream %p codec %p", stream, codec); LOG_DBG("stream %p codec %p", stream, codec);
CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) { CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) {
BT_DBG("Invalid stream"); LOG_DBG("Invalid stream");
return -EINVAL; return -EINVAL;
} }
CHECKIF(codec == NULL) { CHECKIF(codec == NULL) {
BT_DBG("codec is NULL"); LOG_DBG("codec is NULL");
return -EINVAL; return -EINVAL;
} }
@ -1136,7 +1131,7 @@ int bt_audio_stream_reconfig(struct bt_audio_stream *stream,
case BT_AUDIO_EP_STATE_QOS_CONFIGURED: case BT_AUDIO_EP_STATE_QOS_CONFIGURED:
break; break;
default: default:
BT_ERR("Invalid state: %s", bt_audio_ep_state_str(state)); LOG_ERR("Invalid state: %s", bt_audio_ep_state_str(state));
return -EBADMSG; return -EBADMSG;
} }
@ -1152,7 +1147,7 @@ int bt_audio_stream_reconfig(struct bt_audio_stream *stream,
} }
if (err != 0) { if (err != 0) {
BT_DBG("reconfiguring stream failed: %d", err); LOG_DBG("reconfiguring stream failed: %d", err);
} else { } else {
stream->codec = codec; stream->codec = codec;
} }
@ -1166,10 +1161,10 @@ int bt_audio_stream_start(struct bt_audio_stream *stream)
uint8_t role; uint8_t role;
int err; int err;
BT_DBG("stream %p ep %p", stream, stream == NULL ? NULL : stream->ep); LOG_DBG("stream %p ep %p", stream, stream == NULL ? NULL : stream->ep);
CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) { CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) {
BT_DBG("Invalid stream"); LOG_DBG("Invalid stream");
return -EINVAL; return -EINVAL;
} }
@ -1179,7 +1174,7 @@ int bt_audio_stream_start(struct bt_audio_stream *stream)
case BT_AUDIO_EP_STATE_ENABLING: case BT_AUDIO_EP_STATE_ENABLING:
break; break;
default: default:
BT_ERR("Invalid state: %s", bt_audio_ep_state_str(state)); LOG_ERR("Invalid state: %s", bt_audio_ep_state_str(state));
return -EBADMSG; return -EBADMSG;
} }
@ -1195,7 +1190,7 @@ int bt_audio_stream_start(struct bt_audio_stream *stream)
} }
if (err != 0) { if (err != 0) {
BT_DBG("Starting stream failed: %d", err); LOG_DBG("Starting stream failed: %d", err);
return err; return err;
} }
@ -1210,16 +1205,16 @@ int bt_audio_stream_metadata(struct bt_audio_stream *stream,
uint8_t role; uint8_t role;
int err; int err;
BT_DBG("stream %p metadata count %u", stream, meta_count); LOG_DBG("stream %p metadata count %u", stream, meta_count);
CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) { CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) {
BT_DBG("Invalid stream"); LOG_DBG("Invalid stream");
return -EINVAL; return -EINVAL;
} }
CHECKIF((meta == NULL && meta_count != 0U) || CHECKIF((meta == NULL && meta_count != 0U) ||
(meta != NULL && meta_count == 0U)) { (meta != NULL && meta_count == 0U)) {
BT_DBG("Invalid meta (%p) or count (%zu)", meta, meta_count); LOG_DBG("Invalid meta (%p) or count (%zu)", meta, meta_count);
return -EINVAL; return -EINVAL;
} }
@ -1231,7 +1226,7 @@ int bt_audio_stream_metadata(struct bt_audio_stream *stream,
case BT_AUDIO_EP_STATE_STREAMING: case BT_AUDIO_EP_STATE_STREAMING:
break; break;
default: default:
BT_ERR("Invalid state: %s", bt_audio_ep_state_str(state)); LOG_ERR("Invalid state: %s", bt_audio_ep_state_str(state));
return -EBADMSG; return -EBADMSG;
} }
@ -1247,7 +1242,7 @@ int bt_audio_stream_metadata(struct bt_audio_stream *stream,
} }
if (err != 0) { if (err != 0) {
BT_DBG("Updating metadata failed: %d", err); LOG_DBG("Updating metadata failed: %d", err);
return err; return err;
} }
@ -1260,10 +1255,10 @@ int bt_audio_stream_disable(struct bt_audio_stream *stream)
uint8_t role; uint8_t role;
int err; int err;
BT_DBG("stream %p", stream); LOG_DBG("stream %p", stream);
CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) { CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) {
BT_DBG("Invalid stream"); LOG_DBG("Invalid stream");
return -EINVAL; return -EINVAL;
} }
@ -1275,7 +1270,7 @@ int bt_audio_stream_disable(struct bt_audio_stream *stream)
case BT_AUDIO_EP_STATE_STREAMING: case BT_AUDIO_EP_STATE_STREAMING:
break; break;
default: default:
BT_ERR("Invalid state: %s", bt_audio_ep_state_str(state)); LOG_ERR("Invalid state: %s", bt_audio_ep_state_str(state));
return -EBADMSG; return -EBADMSG;
} }
@ -1291,7 +1286,7 @@ int bt_audio_stream_disable(struct bt_audio_stream *stream)
} }
if (err != 0) { if (err != 0) {
BT_DBG("Disabling stream failed: %d", err); LOG_DBG("Disabling stream failed: %d", err);
return err; return err;
} }
@ -1304,10 +1299,10 @@ int bt_audio_stream_release(struct bt_audio_stream *stream)
uint8_t role; uint8_t role;
int err; int err;
BT_DBG("stream %p", stream); LOG_DBG("stream %p", stream);
CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) { CHECKIF(stream == NULL || stream->ep == NULL || stream->conn == NULL) {
BT_DBG("Invalid stream"); LOG_DBG("Invalid stream");
return -EINVAL; return -EINVAL;
} }
@ -1325,7 +1320,7 @@ int bt_audio_stream_release(struct bt_audio_stream *stream)
case BT_AUDIO_EP_STATE_DISABLING: case BT_AUDIO_EP_STATE_DISABLING:
break; break;
default: default:
BT_ERR("Invalid state: %s", bt_audio_ep_state_str(state)); LOG_ERR("Invalid state: %s", bt_audio_ep_state_str(state));
return -EBADMSG; return -EBADMSG;
} }
@ -1341,7 +1336,7 @@ int bt_audio_stream_release(struct bt_audio_stream *stream)
} }
if (err != 0) { if (err != 0) {
BT_DBG("Releasing stream failed: %d", err); LOG_DBG("Releasing stream failed: %d", err);
return err; return err;
} }

View file

@ -21,9 +21,9 @@
#include "tbs_internal.h" #include "tbs_internal.h"
#include "ccid_internal.h" #include "ccid_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_TBS) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_tbs
#include "common/log.h" LOG_MODULE_REGISTER(bt_tbs, CONFIG_BT_TBS_LOG_LEVEL);
#define BT_TBS_VALID_STATUS_FLAGS(val) ((val) <= (BIT(0) | BIT(1))) #define BT_TBS_VALID_STATUS_FLAGS(val) ((val) <= (BIT(0) | BIT(1)))
#define IS_GTBS_CHRC(_attr) \ #define IS_GTBS_CHRC(_attr) \
@ -281,8 +281,8 @@ static void tbs_set_terminate_reason(struct tbs_service_inst *inst,
{ {
inst->terminate_reason.call_index = call_index; inst->terminate_reason.call_index = call_index;
inst->terminate_reason.reason = reason; inst->terminate_reason.reason = reason;
BT_DBG("Index %u: call index 0x%02x, reason %s", LOG_DBG("Index %u: call index 0x%02x, reason %s", inst->index, call_index,
inst->index, call_index, bt_tbs_term_reason_str(reason)); bt_tbs_term_reason_str(reason));
bt_gatt_notify_uuid(NULL, BT_UUID_TBS_TERMINATE_REASON, bt_gatt_notify_uuid(NULL, BT_UUID_TBS_TERMINATE_REASON,
inst->service_p->attrs, inst->service_p->attrs,
@ -322,7 +322,7 @@ static uint8_t next_free_call_index(void)
} }
} }
BT_DBG("No more free call spots"); LOG_DBG("No more free call spots");
return BT_TBS_FREE_CALL_INDEX; return BT_TBS_FREE_CALL_INDEX;
} }
@ -504,13 +504,12 @@ static ssize_t read_provider_name(struct bt_conn *conn,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
provider_name = gtbs_inst.provider_name; provider_name = gtbs_inst.provider_name;
BT_DBG("GTBS: Provider name %s", provider_name); LOG_DBG("GTBS: Provider name %s", provider_name);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
provider_name = inst->provider_name; provider_name = inst->provider_name;
BT_DBG("Index %u, Provider name %s", LOG_DBG("Index %u, Provider name %s", inst->index, provider_name);
inst->index, provider_name);
} }
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
@ -524,9 +523,9 @@ static void provider_name_cfg_changed(const struct bt_gatt_attr *attr,
const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
} }
} }
@ -537,12 +536,12 @@ static ssize_t read_uci(struct bt_conn *conn, const struct bt_gatt_attr *attr,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
uci = gtbs_inst.uci; uci = gtbs_inst.uci;
BT_DBG("GTBS: UCI %s", uci); LOG_DBG("GTBS: UCI %s", uci);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
uci = inst->uci; uci = inst->uci;
BT_DBG("Index %u: UCI %s", inst->index, uci); LOG_DBG("Index %u: UCI %s", inst->index, uci);
} }
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
@ -557,12 +556,12 @@ static ssize_t read_technology(struct bt_conn *conn,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
technology = gtbs_inst.technology; technology = gtbs_inst.technology;
BT_DBG("GTBS: Technology 0x%02X", technology); LOG_DBG("GTBS: Technology 0x%02X", technology);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
technology = inst->technology; technology = inst->technology;
BT_DBG("Index %u: Technology 0x%02X", inst->index, technology); LOG_DBG("Index %u: Technology 0x%02X", inst->index, technology);
} }
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
@ -575,9 +574,9 @@ static void technology_cfg_changed(const struct bt_gatt_attr *attr,
const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
} }
} }
@ -593,7 +592,7 @@ static ssize_t read_uri_scheme_list(struct bt_conn *conn,
size_t uri_len = strlen(svc_insts[i].uri_scheme_list); size_t uri_len = strlen(svc_insts[i].uri_scheme_list);
if (read_buf.len + uri_len >= read_buf.size) { if (read_buf.len + uri_len >= read_buf.size) {
BT_WARN("Cannot fit all TBS instances in GTBS " LOG_WRN("Cannot fit all TBS instances in GTBS "
"URI scheme list"); "URI scheme list");
break; break;
} }
@ -604,7 +603,7 @@ static ssize_t read_uri_scheme_list(struct bt_conn *conn,
} }
/* Add null terminator for printing */ /* Add null terminator for printing */
read_buf.data[read_buf.len] = '\0'; read_buf.data[read_buf.len] = '\0';
BT_DBG("GTBS: URI scheme %s", read_buf.data); LOG_DBG("GTBS: URI scheme %s", read_buf.data);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
@ -612,8 +611,7 @@ static ssize_t read_uri_scheme_list(struct bt_conn *conn,
strlen(inst->uri_scheme_list)); strlen(inst->uri_scheme_list));
/* Add null terminator for printing */ /* Add null terminator for printing */
read_buf.data[read_buf.len] = '\0'; read_buf.data[read_buf.len] = '\0';
BT_DBG("Index %u: URI scheme %s", inst->index, LOG_DBG("Index %u: URI scheme %s", inst->index, read_buf.data);
read_buf.data);
} }
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
@ -626,9 +624,9 @@ static void uri_scheme_list_cfg_changed(const struct bt_gatt_attr *attr,
const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
} }
} }
@ -640,13 +638,12 @@ static ssize_t read_signal_strength(struct bt_conn *conn,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
signal_strength = gtbs_inst.signal_strength; signal_strength = gtbs_inst.signal_strength;
BT_DBG("GTBS: Signal strength 0x%02x", signal_strength); LOG_DBG("GTBS: Signal strength 0x%02x", signal_strength);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
signal_strength = inst->signal_strength; signal_strength = inst->signal_strength;
BT_DBG("Index %u: Signal strength 0x%02x", LOG_DBG("Index %u: Signal strength 0x%02x", inst->index, signal_strength);
inst->index, signal_strength);
} }
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
@ -659,9 +656,9 @@ static void signal_strength_cfg_changed(const struct bt_gatt_attr *attr,
const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
} }
} }
@ -678,14 +675,13 @@ static ssize_t read_signal_strength_interval(struct bt_conn *conn,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
signal_strength_interval = gtbs_inst.signal_strength_interval; signal_strength_interval = gtbs_inst.signal_strength_interval;
BT_DBG("GTBS: Signal strength interval 0x%02x", LOG_DBG("GTBS: Signal strength interval 0x%02x", signal_strength_interval);
signal_strength_interval);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
signal_strength_interval = inst->signal_strength_interval; signal_strength_interval = inst->signal_strength_interval;
BT_DBG("Index %u: Signal strength interval 0x%02x", LOG_DBG("Index %u: Signal strength interval 0x%02x", inst->index,
inst->index, signal_strength_interval); signal_strength_interval);
} }
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
@ -718,13 +714,12 @@ static ssize_t write_signal_strength_interval(struct bt_conn *conn,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
gtbs_inst.signal_strength_interval = signal_strength_interval; gtbs_inst.signal_strength_interval = signal_strength_interval;
BT_DBG("GTBS: 0x%02x", signal_strength_interval); LOG_DBG("GTBS: 0x%02x", signal_strength_interval);
} else { } else {
struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
inst->signal_strength_interval = signal_strength_interval; inst->signal_strength_interval = signal_strength_interval;
BT_DBG("Index %u: 0x%02x", LOG_DBG("Index %u: 0x%02x", inst->index, signal_strength_interval);
inst->index, signal_strength_interval);
} }
return len; return len;
@ -736,10 +731,10 @@ static void current_calls_cfg_changed(const struct bt_gatt_attr *attr,
struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
inst->notify_current_calls = (value == BT_GATT_CCC_NOTIFY); inst->notify_current_calls = (value == BT_GATT_CCC_NOTIFY);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
gtbs_inst.notify_current_calls = (value == BT_GATT_CCC_NOTIFY); gtbs_inst.notify_current_calls = (value == BT_GATT_CCC_NOTIFY);
} }
} }
@ -751,11 +746,11 @@ static ssize_t read_current_calls(struct bt_conn *conn,
net_buf_put_current_calls(BT_AUDIO_CHRC_USER_DATA(attr)); net_buf_put_current_calls(BT_AUDIO_CHRC_USER_DATA(attr));
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
BT_DBG("GTBS"); LOG_DBG("GTBS");
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("Index %u", inst->index); LOG_DBG("Index %u", inst->index);
} }
if (offset == 0) { if (offset == 0) {
@ -774,12 +769,12 @@ static ssize_t read_ccid(struct bt_conn *conn,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
ccid = gtbs_inst.ccid; ccid = gtbs_inst.ccid;
BT_DBG("GTBS: CCID 0x%02X", ccid); LOG_DBG("GTBS: CCID 0x%02X", ccid);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
ccid = inst->ccid; ccid = inst->ccid;
BT_DBG("Index %u: CCID 0x%02X", inst->index, ccid); LOG_DBG("Index %u: CCID 0x%02X", inst->index, ccid);
} }
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
@ -794,13 +789,12 @@ static ssize_t read_status_flags(struct bt_conn *conn,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
status_flags = gtbs_inst.status_flags; status_flags = gtbs_inst.status_flags;
BT_DBG("GTBS: status_flags 0x%04X", status_flags); LOG_DBG("GTBS: status_flags 0x%04X", status_flags);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
status_flags = inst->status_flags; status_flags = inst->status_flags;
BT_DBG("Index %u: status_flags 0x%04X", LOG_DBG("Index %u: status_flags 0x%04X", inst->index, status_flags);
inst->index, status_flags);
} }
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
@ -813,9 +807,9 @@ static void status_flags_cfg_changed(const struct bt_gatt_attr *attr,
const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
} }
} }
@ -829,20 +823,18 @@ static ssize_t read_incoming_uri(struct bt_conn *conn,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
inc_call_target = &gtbs_inst.incoming_uri; inc_call_target = &gtbs_inst.incoming_uri;
BT_DBG("GTBS: call index 0x%02X, URI %s", LOG_DBG("GTBS: call index 0x%02X, URI %s", inc_call_target->call_index,
inc_call_target->call_index, inc_call_target->uri);
inc_call_target->uri);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
inc_call_target = &inst->incoming_uri; inc_call_target = &inst->incoming_uri;
BT_DBG("Index %u: call index 0x%02X, URI %s", LOG_DBG("Index %u: call index 0x%02X, URI %s", inst->index,
inst->index, inc_call_target->call_index, inc_call_target->call_index, inc_call_target->uri);
inc_call_target->uri);
} }
if (!inc_call_target->call_index) { if (!inc_call_target->call_index) {
BT_DBG("URI not set"); LOG_DBG("URI not set");
return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0); return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0);
} }
@ -860,9 +852,9 @@ static void incoming_uri_cfg_changed(const struct bt_gatt_attr *attr,
const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
} }
} }
@ -873,11 +865,11 @@ static ssize_t read_call_state(struct bt_conn *conn,
net_buf_put_call_state(BT_AUDIO_CHRC_USER_DATA(attr)); net_buf_put_call_state(BT_AUDIO_CHRC_USER_DATA(attr));
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
BT_DBG("GTBS"); LOG_DBG("GTBS");
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("Index %u", inst->index); LOG_DBG("Index %u", inst->index);
} }
if (offset == 0) { if (offset == 0) {
@ -894,10 +886,10 @@ static void call_state_cfg_changed(const struct bt_gatt_attr *attr,
struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
inst->notify_call_states = (value == BT_GATT_CCC_NOTIFY); inst->notify_call_states = (value == BT_GATT_CCC_NOTIFY);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
gtbs_inst.notify_call_states = (value == BT_GATT_CCC_NOTIFY); gtbs_inst.notify_call_states = (value == BT_GATT_CCC_NOTIFY);
} }
} }
@ -911,8 +903,8 @@ static int notify_ccp(struct bt_conn *conn, const struct bt_gatt_attr *attr,
.status = status .status = status
}; };
BT_DBG("Notifying CCP: Call index %u, %s opcode and status %s", LOG_DBG("Notifying CCP: Call index %u, %s opcode and status %s", call_index,
call_index, bt_tbs_opcode_str(opcode), bt_tbs_status_str(status)); bt_tbs_opcode_str(opcode), bt_tbs_status_str(status));
return bt_gatt_notify(conn, attr, &ccp_not, sizeof(ccp_not)); return bt_gatt_notify(conn, attr, &ccp_not, sizeof(ccp_not));
} }
@ -1077,7 +1069,7 @@ static int originate_call(struct tbs_service_inst *inst,
(void)memcpy(call->remote_uri, ccp->uri, uri_len); (void)memcpy(call->remote_uri, ccp->uri, uri_len);
call->remote_uri[uri_len] = '\0'; call->remote_uri[uri_len] = '\0';
if (!bt_tbs_valid_uri(call->remote_uri)) { if (!bt_tbs_valid_uri(call->remote_uri)) {
BT_DBG("Invalid URI: %s", call->remote_uri); LOG_DBG("Invalid URI: %s", call->remote_uri);
call->index = BT_TBS_FREE_CALL_INDEX; call->index = BT_TBS_FREE_CALL_INDEX;
return BT_TBS_RESULT_CODE_INVALID_URI; return BT_TBS_RESULT_CODE_INVALID_URI;
@ -1095,7 +1087,7 @@ static int originate_call(struct tbs_service_inst *inst,
hold_other_calls(inst, 1, &call->index); hold_other_calls(inst, 1, &call->index);
notify_calls(inst); notify_calls(inst);
BT_DBG("New call with call index %u", call->index); LOG_DBG("New call with call index %u", call->index);
return BT_TBS_RESULT_CODE_SUCCESS; return BT_TBS_RESULT_CODE_SUCCESS;
} }
@ -1211,16 +1203,14 @@ static void notify_app(struct bt_conn *conn, uint16_t len,
inst = lookup_inst_by_call_index(call_index); inst = lookup_inst_by_call_index(call_index);
if (inst == NULL) { if (inst == NULL) {
BT_DBG("Could not find instance by call index 0x%02X", LOG_DBG("Could not find instance by call index 0x%02X", call_index);
call_index);
break; break;
} }
call = lookup_call_in_inst(inst, call_index); call = lookup_call_in_inst(inst, call_index);
if (call == NULL) { if (call == NULL) {
BT_DBG("Could not find call by call index 0x%02X", LOG_DBG("Could not find call by call index 0x%02X", call_index);
call_index);
break; break;
} }
@ -1295,13 +1285,12 @@ static ssize_t write_call_cp(struct bt_conn *conn,
} }
if (is_gtbs) { if (is_gtbs) {
BT_DBG("GTBS: Processing the %s opcode", LOG_DBG("GTBS: Processing the %s opcode", bt_tbs_opcode_str(ccp->opcode));
bt_tbs_opcode_str(ccp->opcode));
} else { } else {
inst = BT_AUDIO_CHRC_USER_DATA(attr); inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("Index %u: Processing the %s opcode", LOG_DBG("Index %u: Processing the %s opcode", inst->index,
inst->index, bt_tbs_opcode_str(ccp->opcode)); bt_tbs_opcode_str(ccp->opcode));
} }
switch (ccp->opcode) { switch (ccp->opcode) {
@ -1428,13 +1417,13 @@ static ssize_t write_call_cp(struct bt_conn *conn,
if (inst != NULL) { if (inst != NULL) {
if (is_gtbs) { if (is_gtbs) {
BT_DBG("GTBS: Processed the %s opcode with status %s " LOG_DBG("GTBS: Processed the %s opcode with status %s "
"for call index %u", "for call index %u",
bt_tbs_opcode_str(ccp->opcode), bt_tbs_opcode_str(ccp->opcode),
bt_tbs_status_str(status), bt_tbs_status_str(status),
call_index); call_index);
} else { } else {
BT_DBG("Index %u: Processed the %s opcode with status " LOG_DBG("Index %u: Processed the %s opcode with status "
"%s for call index %u", "%s for call index %u",
inst->index, inst->index,
bt_tbs_opcode_str(ccp->opcode), bt_tbs_opcode_str(ccp->opcode),
@ -1446,10 +1435,10 @@ static ssize_t write_call_cp(struct bt_conn *conn,
const struct bt_tbs_call *call = lookup_call(call_index); const struct bt_tbs_call *call = lookup_call(call_index);
if (call != NULL) { if (call != NULL) {
BT_DBG("Call is now in the %s state", LOG_DBG("Call is now in the %s state",
bt_tbs_state_str(call->state)); bt_tbs_state_str(call->state));
} else { } else {
BT_DBG("Call is now terminated"); LOG_DBG("Call is now terminated");
} }
} }
} }
@ -1475,9 +1464,9 @@ static void call_cp_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
} }
} }
@ -1489,13 +1478,12 @@ static ssize_t read_optional_opcodes(struct bt_conn *conn,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
optional_opcodes = gtbs_inst.optional_opcodes; optional_opcodes = gtbs_inst.optional_opcodes;
BT_DBG("GTBS: Supported opcodes 0x%02x", optional_opcodes); LOG_DBG("GTBS: Supported opcodes 0x%02x", optional_opcodes);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
optional_opcodes = inst->optional_opcodes; optional_opcodes = inst->optional_opcodes;
BT_DBG("Index %u: Supported opcodes 0x%02x", LOG_DBG("Index %u: Supported opcodes 0x%02x", inst->index, optional_opcodes);
inst->index, optional_opcodes);
} }
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
@ -1508,9 +1496,9 @@ static void terminate_reason_cfg_changed(const struct bt_gatt_attr *attr,
const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
} }
} }
@ -1523,20 +1511,18 @@ static ssize_t read_friendly_name(struct bt_conn *conn,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
friendly_name = &gtbs_inst.friendly_name; friendly_name = &gtbs_inst.friendly_name;
BT_DBG("GTBS: call index 0x%02X, URI %s", LOG_DBG("GTBS: call index 0x%02X, URI %s", friendly_name->call_index,
friendly_name->call_index, friendly_name->uri);
friendly_name->uri);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
friendly_name = &inst->friendly_name; friendly_name = &inst->friendly_name;
BT_DBG("Index %u: call index 0x%02X, URI %s", LOG_DBG("Index %u: call index 0x%02X, URI %s", inst->index,
inst->index, friendly_name->call_index, friendly_name->call_index, friendly_name->uri);
friendly_name->uri);
} }
if (friendly_name->call_index == BT_TBS_FREE_CALL_INDEX) { if (friendly_name->call_index == BT_TBS_FREE_CALL_INDEX) {
BT_DBG("URI not set"); LOG_DBG("URI not set");
return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0); return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0);
} }
@ -1553,9 +1539,9 @@ static void friendly_name_cfg_changed(const struct bt_gatt_attr *attr,
const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
} }
} }
@ -1568,19 +1554,17 @@ static ssize_t read_incoming_call(struct bt_conn *conn,
if (IS_GTBS_CHRC(attr)) { if (IS_GTBS_CHRC(attr)) {
remote_uri = &gtbs_inst.in_call; remote_uri = &gtbs_inst.in_call;
BT_DBG("GTBS: call index 0x%02X, URI %s", LOG_DBG("GTBS: call index 0x%02X, URI %s", remote_uri->call_index, remote_uri->uri);
remote_uri->call_index, remote_uri->uri);
} else { } else {
const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct tbs_service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr);
remote_uri = &inst->in_call; remote_uri = &inst->in_call;
BT_DBG("Index %u: call index 0x%02X, URI %s", LOG_DBG("Index %u: call index 0x%02X, URI %s", inst->index, remote_uri->call_index,
inst->index, remote_uri->call_index, remote_uri->uri);
remote_uri->uri);
} }
if (remote_uri->call_index == BT_TBS_FREE_CALL_INDEX) { if (remote_uri->call_index == BT_TBS_FREE_CALL_INDEX) {
BT_DBG("URI not set"); LOG_DBG("URI not set");
return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0); return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0);
} }
@ -1597,9 +1581,9 @@ static void in_call_cfg_changed(const struct bt_gatt_attr *attr,
const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr); const struct tbs_service_inst *inst = lookup_inst_by_ccc(attr);
if (inst != NULL) { if (inst != NULL) {
BT_DBG("Index %u: value 0x%04x", inst->index, value); LOG_DBG("Index %u: value 0x%04x", inst->index, value);
} else if (IS_ENABLED(CONFIG_BT_GTBS)) { } else if (IS_ENABLED(CONFIG_BT_GTBS)) {
BT_DBG("GTBS: value 0x%04x", value); LOG_DBG("GTBS: value 0x%04x", value);
} }
} }
@ -1808,7 +1792,7 @@ static int bt_tbs_init(const struct device *unused)
err = bt_gatt_service_register(svc_insts[i].service_p); err = bt_gatt_service_register(svc_insts[i].service_p);
if (err != 0) { if (err != 0) {
BT_ERR("Could not register TBS[%d]: %d", i, err); LOG_ERR("Could not register TBS[%d]: %d", i, err);
} }
} }
@ -1930,7 +1914,7 @@ int bt_tbs_originate(uint8_t bearer_index, char *remote_uri,
if (bearer_index >= CONFIG_BT_TBS_BEARER_COUNT) { if (bearer_index >= CONFIG_BT_TBS_BEARER_COUNT) {
return -EINVAL; return -EINVAL;
} else if (!bt_tbs_valid_uri(remote_uri)) { } else if (!bt_tbs_valid_uri(remote_uri)) {
BT_DBG("Invalid URI %s", remote_uri); LOG_DBG("Invalid URI %s", remote_uri);
return -EINVAL; return -EINVAL;
} }
@ -2088,10 +2072,10 @@ int bt_tbs_remote_incoming(uint8_t bearer_index, const char *to,
if (bearer_index >= CONFIG_BT_TBS_BEARER_COUNT) { if (bearer_index >= CONFIG_BT_TBS_BEARER_COUNT) {
return -EINVAL; return -EINVAL;
} else if (!bt_tbs_valid_uri(to)) { } else if (!bt_tbs_valid_uri(to)) {
BT_DBG("Invalid \"to\" URI: %s", to); LOG_DBG("Invalid \"to\" URI: %s", to);
return -EINVAL; return -EINVAL;
} else if (!bt_tbs_valid_uri(from)) { } else if (!bt_tbs_valid_uri(from)) {
BT_DBG("Invalid \"from\" URI: %s", from); LOG_DBG("Invalid \"from\" URI: %s", from);
return -EINVAL; return -EINVAL;
} }
@ -2186,7 +2170,7 @@ int bt_tbs_remote_incoming(uint8_t bearer_index, const char *to,
notify_calls(inst); notify_calls(inst);
BT_DBG("New call with call index %u", call->index); LOG_DBG("New call with call index %u", call->index);
return call->index; return call->index;
} }
@ -2317,13 +2301,12 @@ int bt_tbs_set_signal_strength(uint8_t bearer_index,
} }
} else { } else {
if (bearer_index == BT_TBS_GTBS_INDEX) { if (bearer_index == BT_TBS_GTBS_INDEX) {
BT_DBG("GTBS: Reporting signal strength in %d ms", LOG_DBG("GTBS: Reporting signal strength in %d ms", timer_status);
timer_status);
gtbs_inst.pending_signal_strength_notification = true; gtbs_inst.pending_signal_strength_notification = true;
} else { } else {
BT_DBG("Index %u: Reporting signal strength in %d ms", LOG_DBG("Index %u: Reporting signal strength in %d ms", bearer_index,
bearer_index, timer_status); timer_status);
inst->pending_signal_strength_notification = true; inst->pending_signal_strength_notification = true;
} }
} }
@ -2406,8 +2389,7 @@ int bt_tbs_set_uri_scheme_list(uint8_t bearer_index, const char **uri_list,
/* Store final result */ /* Store final result */
(void)strcpy(inst->uri_scheme_list, uri_scheme_list); (void)strcpy(inst->uri_scheme_list, uri_scheme_list);
BT_DBG("TBS instance %u uri prefix list is now %s", LOG_DBG("TBS instance %u uri prefix list is now %s", bearer_index, inst->uri_scheme_list);
bearer_index, inst->uri_scheme_list);
bt_gatt_notify_uuid(NULL, BT_UUID_TBS_URI_LIST, bt_gatt_notify_uuid(NULL, BT_UUID_TBS_URI_LIST,
inst->service_p->attrs, &inst->uri_scheme_list, inst->service_p->attrs, &inst->uri_scheme_list,
@ -2421,7 +2403,7 @@ int bt_tbs_set_uri_scheme_list(uint8_t bearer_index, const char **uri_list,
const size_t uri_len = strlen(svc_insts[i].uri_scheme_list); const size_t uri_len = strlen(svc_insts[i].uri_scheme_list);
if (uri_scheme_buf.len + uri_len >= uri_scheme_buf.size) { if (uri_scheme_buf.len + uri_len >= uri_scheme_buf.size) {
BT_WARN("Cannot fit all TBS instances in GTBS " LOG_WRN("Cannot fit all TBS instances in GTBS "
"URI scheme list"); "URI scheme list");
break; break;
} }
@ -2433,7 +2415,7 @@ int bt_tbs_set_uri_scheme_list(uint8_t bearer_index, const char **uri_list,
/* Add null terminator for printing */ /* Add null terminator for printing */
uri_scheme_buf.data[uri_scheme_buf.len] = '\0'; uri_scheme_buf.data[uri_scheme_buf.len] = '\0';
BT_DBG("GTBS: URI scheme %s", uri_scheme_buf.data); LOG_DBG("GTBS: URI scheme %s", uri_scheme_buf.data);
bt_gatt_notify_uuid(NULL, BT_UUID_TBS_URI_LIST, bt_gatt_notify_uuid(NULL, BT_UUID_TBS_URI_LIST,
gtbs_inst.service_p->attrs, gtbs_inst.service_p->attrs,
@ -2448,11 +2430,11 @@ void bt_tbs_register_cb(struct bt_tbs_cb *cbs)
tbs_cbs = cbs; tbs_cbs = cbs;
} }
#if defined(CONFIG_BT_DEBUG_TBS) #if defined(CONFIG_BT_TBS_LOG_LEVEL_DBG)
void bt_tbs_dbg_print_calls(void) void bt_tbs_dbg_print_calls(void)
{ {
for (int i = 0; i < CONFIG_BT_TBS_BEARER_COUNT; i++) { for (int i = 0; i < CONFIG_BT_TBS_BEARER_COUNT; i++) {
BT_DBG("Bearer #%u", i); LOG_DBG("Bearer #%u", i);
for (int j = 0; j < ARRAY_SIZE(svc_insts[i].calls); j++) { for (int j = 0; j < ARRAY_SIZE(svc_insts[i].calls); j++) {
struct bt_tbs_call *call = &svc_insts[i].calls[j]; struct bt_tbs_call *call = &svc_insts[i].calls[j];
@ -2460,11 +2442,11 @@ void bt_tbs_dbg_print_calls(void)
continue; continue;
} }
BT_DBG(" Call #%u", call->index); LOG_DBG(" Call #%u", call->index);
BT_DBG(" State: %s", bt_tbs_state_str(call->state)); LOG_DBG(" State: %s", bt_tbs_state_str(call->state));
BT_DBG(" Flags: 0x%02X", call->flags); LOG_DBG(" Flags: 0x%02X", call->flags);
BT_DBG(" URI : %s", call->remote_uri); LOG_DBG(" URI : %s", call->remote_uri);
} }
} }
} }
#endif /* defined(CONFIG_BT_DEBUG_TBS) */ #endif /* defined(CONFIG_BT_TBS_LOG_LEVEL_DBG) */

View file

@ -21,9 +21,10 @@
#include "tbs_internal.h" #include "tbs_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_TBS_CLIENT) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_tbs_client
#include "common/log.h" LOG_MODULE_REGISTER(bt_tbs_client, CONFIG_BT_TBS_CLIENT_LOG_LEVEL);
#include "common/bt_str.h" #include "common/bt_str.h"
#define MAX_URI_SCHEME_LIST_SIZE 64 #define MAX_URI_SCHEME_LIST_SIZE 64
@ -126,7 +127,7 @@ static struct bt_tbs_instance *lookup_inst_by_handle(struct bt_conn *conn,
return &srv_inst->tbs_insts[i]; return &srv_inst->tbs_insts[i];
} }
} }
BT_DBG("Could not find instance with handle 0x%04x", handle); LOG_DBG("Could not find instance with handle 0x%04x", handle);
return NULL; return NULL;
} }
@ -135,7 +136,7 @@ static uint8_t net_buf_pull_call_state(struct net_buf_simple *buf,
struct bt_tbs_client_call_state *call_state) struct bt_tbs_client_call_state *call_state)
{ {
if (buf->len < sizeof(*call_state)) { if (buf->len < sizeof(*call_state)) {
BT_DBG("Invalid buffer length %u", buf->len); LOG_DBG("Invalid buffer length %u", buf->len);
return BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; return BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
@ -160,7 +161,7 @@ static uint8_t net_buf_pull_call(struct net_buf_simple *buf,
__ASSERT(call, "NULL call"); __ASSERT(call, "NULL call");
if (buf->len < sizeof(item_len) + min_item_len) { if (buf->len < sizeof(item_len) + min_item_len) {
BT_DBG("Invalid buffer length %u", buf->len); LOG_DBG("Invalid buffer length %u", buf->len);
return BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; return BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
@ -168,7 +169,7 @@ static uint8_t net_buf_pull_call(struct net_buf_simple *buf,
uri_len = item_len - sizeof(call->call_info); uri_len = item_len - sizeof(call->call_info);
if (item_len > buf->len || item_len < min_item_len) { if (item_len > buf->len || item_len < min_item_len) {
BT_DBG("Invalid current call item length %u", item_len); LOG_DBG("Invalid current call item length %u", item_len);
return BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; return BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
@ -179,7 +180,7 @@ static uint8_t net_buf_pull_call(struct net_buf_simple *buf,
uri = net_buf_simple_pull_mem(buf, uri_len); uri = net_buf_simple_pull_mem(buf, uri_len);
if (uri_len > CONFIG_BT_TBS_MAX_URI_LENGTH) { if (uri_len > CONFIG_BT_TBS_MAX_URI_LENGTH) {
BT_WARN("Current call (index %u) uri length larger than supported %u/%zu", LOG_WRN("Current call (index %u) uri length larger than supported %u/%zu",
call->call_info.index, uri_len, CONFIG_BT_TBS_MAX_URI_LENGTH); call->call_info.index, uri_len, CONFIG_BT_TBS_MAX_URI_LENGTH);
return BT_ATT_ERR_INSUFFICIENT_RESOURCES; return BT_ATT_ERR_INSUFFICIENT_RESOURCES;
} }
@ -205,16 +206,16 @@ static void bearer_list_current_calls(struct bt_conn *conn, const struct bt_tbs_
err = net_buf_pull_call(buf, call); err = net_buf_pull_call(buf, call);
if (err == BT_ATT_ERR_INSUFFICIENT_RESOURCES) { if (err == BT_ATT_ERR_INSUFFICIENT_RESOURCES) {
BT_WARN("Call with skipped due to too long URI"); LOG_WRN("Call with skipped due to too long URI");
continue; continue;
} else if (err != 0) { } else if (err != 0) {
BT_DBG("Invalid current call notification: %d", err); LOG_DBG("Invalid current call notification: %d", err);
return; return;
} }
cnt++; cnt++;
if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) { if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) {
BT_WARN("Could not parse all calls due to memory restrictions"); LOG_WRN("Could not parse all calls due to memory restrictions");
break; break;
} }
} }
@ -232,8 +233,8 @@ static void call_cp_callback_handler(struct bt_conn *conn, int err,
{ {
bt_tbs_client_cp_cb cp_cb = NULL; bt_tbs_client_cp_cb cp_cb = NULL;
BT_DBG("Status: %s for the %s opcode for call 0x%02x", LOG_DBG("Status: %s for the %s opcode for call 0x%02x", bt_tbs_status_str(err),
bt_tbs_status_str(err), bt_tbs_opcode_str(opcode), call_index); bt_tbs_opcode_str(opcode), call_index);
if (tbs_client_cbs == NULL) { if (tbs_client_cbs == NULL) {
return; return;
@ -303,7 +304,7 @@ static void provider_name_notify_handler(struct bt_conn *conn,
const char *name = parse_string_value(data, length, const char *name = parse_string_value(data, length,
CONFIG_BT_TBS_MAX_PROVIDER_NAME_LENGTH); CONFIG_BT_TBS_MAX_PROVIDER_NAME_LENGTH);
BT_DBG("%s", name); LOG_DBG("%s", name);
if (tbs_client_cbs != NULL && tbs_client_cbs->bearer_provider_name != NULL) { if (tbs_client_cbs != NULL && tbs_client_cbs->bearer_provider_name != NULL) {
tbs_client_cbs->bearer_provider_name(conn, 0, tbs_index(conn, tbs_inst), name); tbs_client_cbs->bearer_provider_name(conn, 0, tbs_index(conn, tbs_inst), name);
@ -318,11 +319,11 @@ static void technology_notify_handler(struct bt_conn *conn,
{ {
uint8_t technology; uint8_t technology;
BT_DBG(""); LOG_DBG("");
if (length == sizeof(technology)) { if (length == sizeof(technology)) {
(void)memcpy(&technology, data, length); (void)memcpy(&technology, data, length);
BT_DBG("%s (0x%02x)", bt_tbs_technology_str(technology), technology); LOG_DBG("%s (0x%02x)", bt_tbs_technology_str(technology), technology);
if (tbs_client_cbs != NULL && tbs_client_cbs->technology != NULL) { if (tbs_client_cbs != NULL && tbs_client_cbs->technology != NULL) {
tbs_client_cbs->technology(conn, 0, tbs_index(conn, tbs_inst), technology); tbs_client_cbs->technology(conn, 0, tbs_index(conn, tbs_inst), technology);
@ -338,11 +339,11 @@ static void signal_strength_notify_handler(struct bt_conn *conn,
{ {
uint8_t signal_strength; uint8_t signal_strength;
BT_DBG(""); LOG_DBG("");
if (length == sizeof(signal_strength)) { if (length == sizeof(signal_strength)) {
(void)memcpy(&signal_strength, data, length); (void)memcpy(&signal_strength, data, length);
BT_DBG("0x%02x", signal_strength); LOG_DBG("0x%02x", signal_strength);
if (tbs_client_cbs != NULL && tbs_client_cbs->signal_strength != NULL) { if (tbs_client_cbs != NULL && tbs_client_cbs->signal_strength != NULL) {
tbs_client_cbs->signal_strength(conn, 0, tbs_index(conn, tbs_inst), tbs_client_cbs->signal_strength(conn, 0, tbs_index(conn, tbs_inst),
@ -359,7 +360,7 @@ static void current_calls_notify_handler(struct bt_conn *conn,
{ {
struct net_buf_simple buf; struct net_buf_simple buf;
BT_DBG(""); LOG_DBG("");
net_buf_simple_init_with_data(&buf, (void *)data, length); net_buf_simple_init_with_data(&buf, (void *)data, length);
@ -376,11 +377,11 @@ static void status_flags_notify_handler(struct bt_conn *conn,
{ {
uint16_t status_flags; uint16_t status_flags;
BT_DBG(""); LOG_DBG("");
if (length == sizeof(status_flags)) { if (length == sizeof(status_flags)) {
(void)memcpy(&status_flags, data, length); (void)memcpy(&status_flags, data, length);
BT_DBG("0x%04x", status_flags); LOG_DBG("0x%04x", status_flags);
if (tbs_client_cbs != NULL && tbs_client_cbs->status_flags != NULL) { if (tbs_client_cbs != NULL && tbs_client_cbs->status_flags != NULL) {
tbs_client_cbs->status_flags(conn, 0, tbs_index(conn, tbs_inst), tbs_client_cbs->status_flags(conn, 0, tbs_index(conn, tbs_inst),
status_flags); status_flags);
@ -397,7 +398,7 @@ static void incoming_uri_notify_handler(struct bt_conn *conn,
const char *uri = parse_string_value(data, length, const char *uri = parse_string_value(data, length,
CONFIG_BT_TBS_MAX_URI_LENGTH); CONFIG_BT_TBS_MAX_URI_LENGTH);
BT_DBG("%s", uri); LOG_DBG("%s", uri);
if (tbs_client_cbs != NULL && tbs_client_cbs->call_uri != NULL) { if (tbs_client_cbs != NULL && tbs_client_cbs->call_uri != NULL) {
tbs_client_cbs->call_uri(conn, 0, tbs_index(conn, tbs_inst), uri); tbs_client_cbs->call_uri(conn, 0, tbs_index(conn, tbs_inst), uri);
@ -413,7 +414,7 @@ static void call_state_notify_handler(struct bt_conn *conn,
uint8_t cnt = 0; uint8_t cnt = 0;
struct net_buf_simple buf; struct net_buf_simple buf;
BT_DBG(""); LOG_DBG("");
net_buf_simple_init_with_data(&buf, (void *)data, length); net_buf_simple_init_with_data(&buf, (void *)data, length);
@ -425,13 +426,13 @@ static void call_state_notify_handler(struct bt_conn *conn,
err = net_buf_pull_call_state(&buf, call_state); err = net_buf_pull_call_state(&buf, call_state);
if (err != 0) { if (err != 0) {
BT_DBG("Invalid current call notification: %d", err); LOG_DBG("Invalid current call notification: %d", err);
return; return;
} }
cnt++; cnt++;
if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) { if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) {
BT_WARN("Could not parse all calls due to memory restrictions"); LOG_WRN("Could not parse all calls due to memory restrictions");
break; break;
} }
} }
@ -448,14 +449,13 @@ static void call_cp_notify_handler(struct bt_conn *conn,
{ {
struct bt_tbs_call_cp_notify *ind_val; struct bt_tbs_call_cp_notify *ind_val;
BT_DBG(""); LOG_DBG("");
if (length == sizeof(*ind_val)) { if (length == sizeof(*ind_val)) {
ind_val = (struct bt_tbs_call_cp_notify *)data; ind_val = (struct bt_tbs_call_cp_notify *)data;
BT_DBG("Status: %s for the %s opcode for call 0x%02X", LOG_DBG("Status: %s for the %s opcode for call 0x%02X",
bt_tbs_status_str(ind_val->status), bt_tbs_status_str(ind_val->status), bt_tbs_opcode_str(ind_val->opcode),
bt_tbs_opcode_str(ind_val->opcode), ind_val->call_index);
ind_val->call_index);
call_cp_callback_handler(conn, ind_val->status, tbs_index(conn, tbs_inst), call_cp_callback_handler(conn, ind_val->status, tbs_index(conn, tbs_inst),
ind_val->opcode, ind_val->call_index); ind_val->opcode, ind_val->call_index);
@ -469,13 +469,12 @@ static void termination_reason_notify_handler(struct bt_conn *conn,
{ {
struct bt_tbs_terminate_reason reason; struct bt_tbs_terminate_reason reason;
BT_DBG(""); LOG_DBG("");
if (length == sizeof(reason)) { if (length == sizeof(reason)) {
(void)memcpy(&reason, data, length); (void)memcpy(&reason, data, length);
BT_DBG("ID 0x%02X, reason %s", LOG_DBG("ID 0x%02X, reason %s", reason.call_index,
reason.call_index, bt_tbs_term_reason_str(reason.reason));
bt_tbs_term_reason_str(reason.reason));
if (tbs_client_cbs != NULL && tbs_client_cbs->termination_reason != NULL) { if (tbs_client_cbs != NULL && tbs_client_cbs->termination_reason != NULL) {
tbs_client_cbs->termination_reason(conn, 0, tbs_index(conn, tbs_inst), tbs_client_cbs->termination_reason(conn, 0, tbs_index(conn, tbs_inst),
@ -492,7 +491,7 @@ static void in_call_notify_handler(struct bt_conn *conn,
const char *uri = parse_string_value(data, length, const char *uri = parse_string_value(data, length,
CONFIG_BT_TBS_MAX_URI_LENGTH); CONFIG_BT_TBS_MAX_URI_LENGTH);
BT_DBG("%s", uri); LOG_DBG("%s", uri);
if (tbs_client_cbs != NULL && tbs_client_cbs->remote_uri != NULL) { if (tbs_client_cbs != NULL && tbs_client_cbs->remote_uri != NULL) {
tbs_client_cbs->remote_uri(conn, 0, tbs_index(conn, tbs_inst), uri); tbs_client_cbs->remote_uri(conn, 0, tbs_index(conn, tbs_inst), uri);
@ -508,7 +507,7 @@ static void friendly_name_notify_handler(struct bt_conn *conn,
const char *name = parse_string_value(data, length, const char *name = parse_string_value(data, length,
CONFIG_BT_TBS_MAX_URI_LENGTH); CONFIG_BT_TBS_MAX_URI_LENGTH);
BT_DBG("%s", name); LOG_DBG("%s", name);
if (tbs_client_cbs != NULL && tbs_client_cbs->friendly_name != NULL) { if (tbs_client_cbs != NULL && tbs_client_cbs->friendly_name != NULL) {
tbs_client_cbs->friendly_name(conn, 0, tbs_index(conn, tbs_inst), name); tbs_client_cbs->friendly_name(conn, 0, tbs_index(conn, tbs_inst), name);
@ -525,7 +524,7 @@ static uint8_t notify_handler(struct bt_conn *conn,
struct bt_tbs_instance *tbs_inst = lookup_inst_by_handle(conn, handle); struct bt_tbs_instance *tbs_inst = lookup_inst_by_handle(conn, handle);
if (data == NULL) { if (data == NULL) {
BT_DBG("[UNSUBSCRIBED] 0x%04X", params->value_handle); LOG_DBG("[UNSUBSCRIBED] 0x%04X", params->value_handle);
params->value_handle = 0U; params->value_handle = 0U;
if (tbs_inst != NULL) { if (tbs_inst != NULL) {
tbs_inst->subscribe_cnt--; tbs_inst->subscribe_cnt--;
@ -537,7 +536,7 @@ static uint8_t notify_handler(struct bt_conn *conn,
if (tbs_inst != NULL) { if (tbs_inst != NULL) {
uint8_t inst_index = tbs_index(conn, tbs_inst); uint8_t inst_index = tbs_index(conn, tbs_inst);
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
LOG_HEXDUMP_DBG(data, length, "notify handler value"); LOG_HEXDUMP_DBG(data, length, "notify handler value");
@ -590,7 +589,7 @@ static uint8_t notify_handler(struct bt_conn *conn,
#endif /* defined(CONFIG_BT_TBS_CLIENT_CALL_FRIENDLY_NAME) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_CALL_FRIENDLY_NAME) */
} }
} else { } else {
BT_DBG("Notification/Indication on unknown TBS inst"); LOG_DBG("Notification/Indication on unknown TBS inst");
} }
return BT_GATT_ITER_CONTINUE; return BT_GATT_ITER_CONTINUE;
@ -611,7 +610,7 @@ static int tbs_client_common_call_control(struct bt_conn *conn,
} }
if (inst->call_cp_sub_params.value_handle == 0) { if (inst->call_cp_sub_params.value_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -634,14 +633,14 @@ static uint8_t read_bearer_provider_name_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
provider_name = parse_string_value(data, length, provider_name = parse_string_value(data, length,
CONFIG_BT_TBS_MAX_PROVIDER_NAME_LENGTH); CONFIG_BT_TBS_MAX_PROVIDER_NAME_LENGTH);
BT_DBG("%s", provider_name); LOG_DBG("%s", provider_name);
} }
inst->busy = false; inst->busy = false;
@ -665,13 +664,13 @@ static uint8_t read_bearer_uci_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
bearer_uci = parse_string_value(data, length, BT_TBS_MAX_UCI_SIZE); bearer_uci = parse_string_value(data, length, BT_TBS_MAX_UCI_SIZE);
BT_DBG("%s", bearer_uci); LOG_DBG("%s", bearer_uci);
} }
inst->busy = false; inst->busy = false;
@ -696,17 +695,17 @@ static uint8_t read_technology_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
LOG_HEXDUMP_DBG(data, length, "Data read"); LOG_HEXDUMP_DBG(data, length, "Data read");
if (length == sizeof(technology)) { if (length == sizeof(technology)) {
(void)memcpy(&technology, data, length); (void)memcpy(&technology, data, length);
BT_DBG("%s (0x%02x)", bt_tbs_technology_str(technology), technology); LOG_DBG("%s (0x%02x)", bt_tbs_technology_str(technology), technology);
} else { } else {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} }
@ -732,14 +731,14 @@ static uint8_t read_uri_list_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
uri_scheme_list = parse_string_value(data, length, uri_scheme_list = parse_string_value(data, length,
MAX_URI_SCHEME_LIST_SIZE); MAX_URI_SCHEME_LIST_SIZE);
BT_DBG("%s", uri_scheme_list); LOG_DBG("%s", uri_scheme_list);
} }
inst->busy = false; inst->busy = false;
@ -764,17 +763,17 @@ static uint8_t read_signal_strength_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
LOG_HEXDUMP_DBG(data, length, "Data read"); LOG_HEXDUMP_DBG(data, length, "Data read");
if (length == sizeof(signal_strength)) { if (length == sizeof(signal_strength)) {
(void)memcpy(&signal_strength, data, length); (void)memcpy(&signal_strength, data, length);
BT_DBG("0x%02x", signal_strength); LOG_DBG("0x%02x", signal_strength);
} else { } else {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} }
@ -801,17 +800,17 @@ static uint8_t read_signal_interval_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
LOG_HEXDUMP_DBG(data, length, "Data read"); LOG_HEXDUMP_DBG(data, length, "Data read");
if (length == sizeof(signal_interval)) { if (length == sizeof(signal_interval)) {
(void)memcpy(&signal_interval, data, length); (void)memcpy(&signal_interval, data, length);
BT_DBG("0x%02x", signal_interval); LOG_DBG("0x%02x", signal_interval);
} else { } else {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} }
@ -835,10 +834,10 @@ static uint8_t read_current_calls_cb(struct bt_conn *conn, uint8_t err,
uint8_t inst_index = tbs_index(conn, inst); uint8_t inst_index = tbs_index(conn, inst);
int tbs_err = err; int tbs_err = err;
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (tbs_err != 0) { if (tbs_err != 0) {
BT_DBG("err: %d", tbs_err); LOG_DBG("err: %d", tbs_err);
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
if (tbs_client_cbs != NULL && if (tbs_client_cbs != NULL &&
tbs_client_cbs->current_calls != NULL) { tbs_client_cbs->current_calls != NULL) {
@ -849,11 +848,11 @@ static uint8_t read_current_calls_cb(struct bt_conn *conn, uint8_t err,
} }
if (data != NULL) { if (data != NULL) {
BT_DBG("Current calls read (offset %u): %s", LOG_DBG("Current calls read (offset %u): %s", params->single.offset,
params->single.offset, bt_hex(data, length)); bt_hex(data, length));
if (inst->net_buf.size < inst->net_buf.len + length) { if (inst->net_buf.size < inst->net_buf.len + length) {
BT_DBG("Could not read all data, aborting"); LOG_DBG("Could not read all data, aborting");
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
if (tbs_client_cbs != NULL && if (tbs_client_cbs != NULL &&
@ -901,17 +900,17 @@ static uint8_t read_ccid_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
LOG_HEXDUMP_DBG(data, length, "Data read"); LOG_HEXDUMP_DBG(data, length, "Data read");
if (length == sizeof(ccid)) { if (length == sizeof(ccid)) {
(void)memcpy(&ccid, data, length); (void)memcpy(&ccid, data, length);
BT_DBG("0x%02x", ccid); LOG_DBG("0x%02x", ccid);
} else { } else {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} }
@ -938,17 +937,17 @@ static uint8_t read_status_flags_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
LOG_HEXDUMP_DBG(data, length, "Data read"); LOG_HEXDUMP_DBG(data, length, "Data read");
if (length == sizeof(status_flags)) { if (length == sizeof(status_flags)) {
(void)memcpy(&status_flags, data, length); (void)memcpy(&status_flags, data, length);
BT_DBG("0x%04x", status_flags); LOG_DBG("0x%04x", status_flags);
} else { } else {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} }
@ -975,13 +974,13 @@ static uint8_t read_call_uri_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
in_target_uri = parse_string_value(data, length, CONFIG_BT_TBS_MAX_URI_LENGTH); in_target_uri = parse_string_value(data, length, CONFIG_BT_TBS_MAX_URI_LENGTH);
BT_DBG("%s", in_target_uri); LOG_DBG("%s", in_target_uri);
} }
inst->busy = false; inst->busy = false;
@ -1004,10 +1003,10 @@ static uint8_t read_call_state_cb(struct bt_conn *conn, uint8_t err,
struct bt_tbs_client_call_state call_states[CONFIG_BT_TBS_CLIENT_MAX_CALLS]; struct bt_tbs_client_call_state call_states[CONFIG_BT_TBS_CLIENT_MAX_CALLS];
int tbs_err = err; int tbs_err = err;
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (tbs_err != 0) { if (tbs_err != 0) {
BT_DBG("err: %d", tbs_err); LOG_DBG("err: %d", tbs_err);
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
if (tbs_client_cbs != NULL && if (tbs_client_cbs != NULL &&
tbs_client_cbs->call_state != NULL) { tbs_client_cbs->call_state != NULL) {
@ -1018,11 +1017,11 @@ static uint8_t read_call_state_cb(struct bt_conn *conn, uint8_t err,
} }
if (data != NULL) { if (data != NULL) {
BT_DBG("Call states read (offset %u): %s", LOG_DBG("Call states read (offset %u): %s", params->single.offset,
params->single.offset, bt_hex(data, length)); bt_hex(data, length));
if (inst->net_buf.size < inst->net_buf.len + length) { if (inst->net_buf.size < inst->net_buf.len + length) {
BT_DBG("Could not read all data, aborting"); LOG_DBG("Could not read all data, aborting");
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
if (tbs_client_cbs != NULL && if (tbs_client_cbs != NULL &&
@ -1056,13 +1055,13 @@ static uint8_t read_call_state_cb(struct bt_conn *conn, uint8_t err,
tbs_err = net_buf_pull_call_state(&inst->net_buf, call_state); tbs_err = net_buf_pull_call_state(&inst->net_buf, call_state);
if (tbs_err != 0) { if (tbs_err != 0) {
BT_DBG("Invalid current call notification: %d", err); LOG_DBG("Invalid current call notification: %d", err);
break; break;
} }
cnt++; cnt++;
if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) { if (cnt == CONFIG_BT_TBS_CLIENT_MAX_CALLS) {
BT_WARN("Could not parse all calls due to memory restrictions"); LOG_WRN("Could not parse all calls due to memory restrictions");
break; break;
} }
} }
@ -1088,17 +1087,17 @@ static uint8_t read_optional_opcodes_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
LOG_HEXDUMP_DBG(data, length, "Data read"); LOG_HEXDUMP_DBG(data, length, "Data read");
if (length == sizeof(optional_opcodes)) { if (length == sizeof(optional_opcodes)) {
(void)memcpy(&optional_opcodes, data, length); (void)memcpy(&optional_opcodes, data, length);
BT_DBG("0x%04x", optional_opcodes); LOG_DBG("0x%04x", optional_opcodes);
} else { } else {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} }
@ -1125,13 +1124,13 @@ static uint8_t read_remote_uri_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
remote_uri = parse_string_value(data, length, CONFIG_BT_TBS_MAX_URI_LENGTH); remote_uri = parse_string_value(data, length, CONFIG_BT_TBS_MAX_URI_LENGTH);
BT_DBG("%s", remote_uri); LOG_DBG("%s", remote_uri);
} }
inst->busy = false; inst->busy = false;
@ -1156,13 +1155,13 @@ static uint8_t read_friendly_name_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (err != 0) { if (err != 0) {
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
} else if (data != NULL) { } else if (data != NULL) {
friendly_name = parse_string_value(data, length, CONFIG_BT_TBS_MAX_URI_LENGTH); friendly_name = parse_string_value(data, length, CONFIG_BT_TBS_MAX_URI_LENGTH);
BT_DBG("%s", friendly_name); LOG_DBG("%s", friendly_name);
} }
inst->busy = false; inst->busy = false;
@ -1187,16 +1186,16 @@ static uint8_t disc_read_ccid_cb(struct bt_conn *conn, uint8_t err,
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
BT_DBG("Index %u", inst_index); LOG_DBG("Index %u", inst_index);
if (cb_err != 0) { if (cb_err != 0) {
BT_DBG("err: 0x%02X", cb_err); LOG_DBG("err: 0x%02X", cb_err);
} else if (data != NULL) { } else if (data != NULL) {
if (length == sizeof(inst->ccid)) { if (length == sizeof(inst->ccid)) {
inst->ccid = ((uint8_t *)data)[0]; inst->ccid = ((uint8_t *)data)[0];
BT_DBG("0x%02x", inst->ccid); LOG_DBG("0x%02x", inst->ccid);
} else { } else {
BT_DBG("Invalid length"); LOG_DBG("Invalid length");
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} }
@ -1207,13 +1206,13 @@ static uint8_t disc_read_ccid_cb(struct bt_conn *conn, uint8_t err,
tbs_client_cbs->discover(conn, cb_err, 0U, false); tbs_client_cbs->discover(conn, cb_err, 0U, false);
} else { } else {
if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS) && inst == srv_inst->gtbs) { if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS) && inst == srv_inst->gtbs) {
BT_DBG("Setup complete GTBS"); LOG_DBG("Setup complete GTBS");
inst_index = 0; inst_index = 0;
} else { } else {
inst_index++; inst_index++;
BT_DBG("Setup complete for %u / %u TBS", inst_index, srv_inst->inst_cnt); LOG_DBG("Setup complete for %u / %u TBS", inst_index, srv_inst->inst_cnt);
} }
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
@ -1281,7 +1280,7 @@ static uint8_t discover_func(struct bt_conn *conn,
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) {
const struct bt_gatt_chrc *chrc; const struct bt_gatt_chrc *chrc;
@ -1290,37 +1289,37 @@ static uint8_t discover_func(struct bt_conn *conn,
chrc = (struct bt_gatt_chrc *)attr->user_data; chrc = (struct bt_gatt_chrc *)attr->user_data;
if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_CALL_STATE) == 0) { if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_CALL_STATE) == 0) {
BT_DBG("Call state"); LOG_DBG("Call state");
sub_params = &current_inst->call_state_sub_params; sub_params = &current_inst->call_state_sub_params;
sub_params->value_handle = chrc->value_handle; sub_params->value_handle = chrc->value_handle;
sub_params->disc_params = &current_inst->call_state_sub_disc_params; sub_params->disc_params = &current_inst->call_state_sub_disc_params;
#if defined(CONFIG_BT_TBS_CLIENT_BEARER_PROVIDER_NAME) #if defined(CONFIG_BT_TBS_CLIENT_BEARER_PROVIDER_NAME)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_PROVIDER_NAME) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_PROVIDER_NAME) == 0) {
BT_DBG("Provider name"); LOG_DBG("Provider name");
sub_params = &current_inst->name_sub_params; sub_params = &current_inst->name_sub_params;
sub_params->value_handle = chrc->value_handle; sub_params->value_handle = chrc->value_handle;
sub_params->disc_params = &current_inst->name_sub_disc_params; sub_params->disc_params = &current_inst->name_sub_disc_params;
#endif /* defined(CONFIG_BT_TBS_CLIENT_BEARER_PROVIDER_NAME) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_BEARER_PROVIDER_NAME) */
#if defined(CONFIG_BT_TBS_CLIENT_BEARER_UCI) #if defined(CONFIG_BT_TBS_CLIENT_BEARER_UCI)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_UCI) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_UCI) == 0) {
BT_DBG("Bearer UCI"); LOG_DBG("Bearer UCI");
current_inst->bearer_uci_handle = chrc->value_handle; current_inst->bearer_uci_handle = chrc->value_handle;
#endif /* defined(CONFIG_BT_TBS_CLIENT_BEARER_UCI) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_BEARER_UCI) */
#if defined(CONFIG_BT_TBS_CLIENT_BEARER_TECHNOLOGY) #if defined(CONFIG_BT_TBS_CLIENT_BEARER_TECHNOLOGY)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_TECHNOLOGY) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_TECHNOLOGY) == 0) {
BT_DBG("Technology"); LOG_DBG("Technology");
sub_params = &current_inst->technology_sub_params; sub_params = &current_inst->technology_sub_params;
sub_params->value_handle = chrc->value_handle; sub_params->value_handle = chrc->value_handle;
sub_params->disc_params = &current_inst->technology_sub_disc_params; sub_params->disc_params = &current_inst->technology_sub_disc_params;
#endif /* defined(CONFIG_BT_TBS_CLIENT_BEARER_TECHNOLOGY) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_BEARER_TECHNOLOGY) */
#if defined(CONFIG_BT_TBS_CLIENT_BEARER_URI_SCHEMES_SUPPORTED_LIST) #if defined(CONFIG_BT_TBS_CLIENT_BEARER_URI_SCHEMES_SUPPORTED_LIST)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_URI_LIST) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_URI_LIST) == 0) {
BT_DBG("URI Scheme List"); LOG_DBG("URI Scheme List");
current_inst->uri_list_handle = chrc->value_handle; current_inst->uri_list_handle = chrc->value_handle;
#endif /* defined(CONFIG_BT_TBS_CLIENT_BEARER_URI_SCHEMES_SUPPORTED_LIST) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_BEARER_URI_SCHEMES_SUPPORTED_LIST) */
#if defined(CONFIG_BT_TBS_CLIENT_BEARER_SIGNAL_STRENGTH) #if defined(CONFIG_BT_TBS_CLIENT_BEARER_SIGNAL_STRENGTH)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_SIGNAL_STRENGTH) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_SIGNAL_STRENGTH) == 0) {
BT_DBG("Signal strength"); LOG_DBG("Signal strength");
sub_params = &current_inst->signal_strength_sub_params; sub_params = &current_inst->signal_strength_sub_params;
sub_params->value_handle = chrc->value_handle; sub_params->value_handle = chrc->value_handle;
sub_params->disc_params = &current_inst->signal_strength_sub_disc_params; sub_params->disc_params = &current_inst->signal_strength_sub_disc_params;
@ -1328,64 +1327,64 @@ static uint8_t discover_func(struct bt_conn *conn,
#if defined(CONFIG_BT_TBS_CLIENT_READ_BEARER_SIGNAL_INTERVAL) \ #if defined(CONFIG_BT_TBS_CLIENT_READ_BEARER_SIGNAL_INTERVAL) \
|| defined(CONFIG_BT_TBS_CLIENT_SET_BEARER_SIGNAL_INTERVAL) || defined(CONFIG_BT_TBS_CLIENT_SET_BEARER_SIGNAL_INTERVAL)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_SIGNAL_INTERVAL) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_SIGNAL_INTERVAL) == 0) {
BT_DBG("Signal strength reporting interval"); LOG_DBG("Signal strength reporting interval");
current_inst->signal_interval_handle = chrc->value_handle; current_inst->signal_interval_handle = chrc->value_handle;
#endif /* defined(CONFIG_BT_TBS_CLIENT_READ_BEARER_SIGNAL_INTERVAL) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_READ_BEARER_SIGNAL_INTERVAL) */
/* || defined(CONFIG_BT_TBS_CLIENT_SET_BEARER_SIGNAL_INTERVAL) */ /* || defined(CONFIG_BT_TBS_CLIENT_SET_BEARER_SIGNAL_INTERVAL) */
#if defined(CONFIG_BT_TBS_CLIENT_BEARER_LIST_CURRENT_CALLS) #if defined(CONFIG_BT_TBS_CLIENT_BEARER_LIST_CURRENT_CALLS)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_LIST_CURRENT_CALLS) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_LIST_CURRENT_CALLS) == 0) {
BT_DBG("Current calls"); LOG_DBG("Current calls");
sub_params = &current_inst->current_calls_sub_params; sub_params = &current_inst->current_calls_sub_params;
sub_params->value_handle = chrc->value_handle; sub_params->value_handle = chrc->value_handle;
sub_params->disc_params = &current_inst->current_calls_sub_disc_params; sub_params->disc_params = &current_inst->current_calls_sub_disc_params;
#endif /* defined(CONFIG_BT_TBS_CLIENT_BEARER_LIST_CURRENT_CALLS) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_BEARER_LIST_CURRENT_CALLS) */
#if defined(CONFIG_BT_TBS_CLIENT_CCID) #if defined(CONFIG_BT_TBS_CLIENT_CCID)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_CCID) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_CCID) == 0) {
BT_DBG("CCID"); LOG_DBG("CCID");
current_inst->ccid_handle = chrc->value_handle; current_inst->ccid_handle = chrc->value_handle;
#endif /* defined(CONFIG_BT_TBS_CLIENT_CCID) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_CCID) */
#if defined(CONFIG_BT_TBS_CLIENT_INCOMING_URI) #if defined(CONFIG_BT_TBS_CLIENT_INCOMING_URI)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_INCOMING_URI) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_INCOMING_URI) == 0) {
BT_DBG("Incoming target URI"); LOG_DBG("Incoming target URI");
sub_params = &current_inst->in_target_uri_sub_params; sub_params = &current_inst->in_target_uri_sub_params;
sub_params->value_handle = chrc->value_handle; sub_params->value_handle = chrc->value_handle;
sub_params->disc_params = &current_inst->in_target_uri_sub_disc_params; sub_params->disc_params = &current_inst->in_target_uri_sub_disc_params;
#endif /* defined(CONFIG_BT_TBS_CLIENT_INCOMING_URI) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_INCOMING_URI) */
#if defined(CONFIG_BT_TBS_CLIENT_STATUS_FLAGS) #if defined(CONFIG_BT_TBS_CLIENT_STATUS_FLAGS)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_STATUS_FLAGS) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_STATUS_FLAGS) == 0) {
BT_DBG("Status flags"); LOG_DBG("Status flags");
sub_params = &current_inst->status_flags_sub_params; sub_params = &current_inst->status_flags_sub_params;
sub_params->value_handle = chrc->value_handle; sub_params->value_handle = chrc->value_handle;
sub_params->disc_params = &current_inst->status_sub_disc_params; sub_params->disc_params = &current_inst->status_sub_disc_params;
#endif /* defined(CONFIG_BT_TBS_CLIENT_STATUS_FLAGS) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_STATUS_FLAGS) */
#if defined(CONFIG_BT_TBS_CLIENT_CP_PROCEDURES) #if defined(CONFIG_BT_TBS_CLIENT_CP_PROCEDURES)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_CALL_CONTROL_POINT) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_CALL_CONTROL_POINT) == 0) {
BT_DBG("Call control point"); LOG_DBG("Call control point");
sub_params = &current_inst->call_cp_sub_params; sub_params = &current_inst->call_cp_sub_params;
sub_params->value_handle = chrc->value_handle; sub_params->value_handle = chrc->value_handle;
sub_params->disc_params = &current_inst->call_cp_sub_disc_params; sub_params->disc_params = &current_inst->call_cp_sub_disc_params;
#endif /* defined(CONFIG_BT_TBS_CLIENT_CP_PROCEDURES) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_CP_PROCEDURES) */
#if defined(CONFIG_BT_TBS_CLIENT_OPTIONAL_OPCODES) #if defined(CONFIG_BT_TBS_CLIENT_OPTIONAL_OPCODES)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_OPTIONAL_OPCODES) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_OPTIONAL_OPCODES) == 0) {
BT_DBG("Supported opcodes"); LOG_DBG("Supported opcodes");
current_inst->optional_opcodes_handle = chrc->value_handle; current_inst->optional_opcodes_handle = chrc->value_handle;
#endif /* defined(CONFIG_BT_TBS_CLIENT_OPTIONAL_OPCODES) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_OPTIONAL_OPCODES) */
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_TERMINATE_REASON) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_TERMINATE_REASON) == 0) {
BT_DBG("Termination reason"); LOG_DBG("Termination reason");
current_inst->termination_reason_handle = chrc->value_handle; current_inst->termination_reason_handle = chrc->value_handle;
sub_params = &current_inst->termination_sub_params; sub_params = &current_inst->termination_sub_params;
sub_params->value_handle = chrc->value_handle; sub_params->value_handle = chrc->value_handle;
sub_params->disc_params = &current_inst->termination_sub_disc_params; sub_params->disc_params = &current_inst->termination_sub_disc_params;
#if defined(CONFIG_BT_TBS_CLIENT_CALL_FRIENDLY_NAME) #if defined(CONFIG_BT_TBS_CLIENT_CALL_FRIENDLY_NAME)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_FRIENDLY_NAME) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_FRIENDLY_NAME) == 0) {
BT_DBG("Incoming friendly name"); LOG_DBG("Incoming friendly name");
sub_params = &current_inst->friendly_name_sub_params; sub_params = &current_inst->friendly_name_sub_params;
sub_params->value_handle = chrc->value_handle; sub_params->value_handle = chrc->value_handle;
sub_params->disc_params = &current_inst->friendly_name_sub_disc_params; sub_params->disc_params = &current_inst->friendly_name_sub_disc_params;
#endif /* defined(CONFIG_BT_TBS_CLIENT_CALL_FRIENDLY_NAME) */ #endif /* defined(CONFIG_BT_TBS_CLIENT_CALL_FRIENDLY_NAME) */
#if defined(CONFIG_BT_TBS_CLIENT_INCOMING_CALL) #if defined(CONFIG_BT_TBS_CLIENT_INCOMING_CALL)
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_INCOMING_CALL) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_TBS_INCOMING_CALL) == 0) {
BT_DBG("Incoming call"); LOG_DBG("Incoming call");
sub_params = &current_inst->incoming_call_sub_params; sub_params = &current_inst->incoming_call_sub_params;
sub_params->value_handle = chrc->value_handle; sub_params->value_handle = chrc->value_handle;
sub_params->disc_params = &current_inst->incoming_call_sub_disc_params; sub_params->disc_params = &current_inst->incoming_call_sub_disc_params;
@ -1409,12 +1408,12 @@ static uint8_t discover_func(struct bt_conn *conn,
sub_params->notify = notify_handler; sub_params->notify = notify_handler;
err = bt_gatt_subscribe(conn, sub_params); err = bt_gatt_subscribe(conn, sub_params);
if (err != 0) { if (err != 0) {
BT_DBG("Could not subscribe to " LOG_DBG("Could not subscribe to "
"characterstic at handle 0x%04X" "characterstic at handle 0x%04X"
"(%d)", "(%d)",
sub_params->value_handle, err); sub_params->value_handle, err);
} else { } else {
BT_DBG("Subscribed to characterstic at " LOG_DBG("Subscribed to characterstic at "
"handle 0x%04X", "handle 0x%04X",
sub_params->value_handle); sub_params->value_handle);
} }
@ -1442,7 +1441,7 @@ static void discover_next_instance(struct bt_conn *conn, uint8_t index)
err = bt_gatt_discover(conn, &srv_inst->discover_params); err = bt_gatt_discover(conn, &srv_inst->discover_params);
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
srv_inst->current_inst = NULL; srv_inst->current_inst = NULL;
if (tbs_client_cbs != NULL && if (tbs_client_cbs != NULL &&
tbs_client_cbs->discover != NULL) { tbs_client_cbs->discover != NULL) {
@ -1455,10 +1454,10 @@ static void discover_next_instance(struct bt_conn *conn, uint8_t index)
static void primary_discover_complete(struct bt_tbs_server_inst *server, struct bt_conn *conn) static void primary_discover_complete(struct bt_tbs_server_inst *server, struct bt_conn *conn)
{ {
if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS)) { if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS)) {
BT_DBG("Discover complete, found %u instances (GTBS%s found)", LOG_DBG("Discover complete, found %u instances (GTBS%s found)", server->inst_cnt,
server->inst_cnt, server->gtbs != NULL ? "" : " not"); server->gtbs != NULL ? "" : " not");
} else { } else {
BT_DBG("Discover complete, found %u instances", server->inst_cnt); LOG_DBG("Discover complete, found %u instances", server->inst_cnt);
} }
if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS) && server->gtbs != NULL) { if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS) && server->gtbs != NULL) {
@ -1487,7 +1486,7 @@ static uint8_t primary_discover_tbs(struct bt_conn *conn, const struct bt_gatt_a
if (attr != NULL) { if (attr != NULL) {
const struct bt_gatt_service_val *prim_service; const struct bt_gatt_service_val *prim_service;
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
prim_service = (struct bt_gatt_service_val *)attr->user_data; prim_service = (struct bt_gatt_service_val *)attr->user_data;
@ -1514,7 +1513,7 @@ static uint8_t primary_discover_gtbs(struct bt_conn *conn, const struct bt_gatt_
if (attr != NULL) { if (attr != NULL) {
const struct bt_gatt_service_val *prim_service; const struct bt_gatt_service_val *prim_service;
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
prim_service = (struct bt_gatt_service_val *)attr->user_data; prim_service = (struct bt_gatt_service_val *)attr->user_data;
@ -1538,7 +1537,7 @@ static uint8_t primary_discover_gtbs(struct bt_conn *conn, const struct bt_gatt_
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
} }
primary_discover_complete(srv_inst, conn); primary_discover_complete(srv_inst, conn);
@ -1597,7 +1596,7 @@ int bt_tbs_client_originate_call(struct bt_conn *conn, uint8_t inst_index,
if (conn == NULL) { if (conn == NULL) {
return -ENOTCONN; return -ENOTCONN;
} else if (!bt_tbs_valid_uri(uri)) { } else if (!bt_tbs_valid_uri(uri)) {
BT_DBG("Invalid URI: %s", uri); LOG_DBG("Invalid URI: %s", uri);
return -EINVAL; return -EINVAL;
} }
@ -1608,15 +1607,14 @@ int bt_tbs_client_originate_call(struct bt_conn *conn, uint8_t inst_index,
/* Check if there are free spots */ /* Check if there are free spots */
if (!free_call_spot(inst)) { if (!free_call_spot(inst)) {
BT_DBG("Cannot originate more calls"); LOG_DBG("Cannot originate more calls");
return -ENOMEM; return -ENOMEM;
} }
uri_len = strlen(uri); uri_len = strlen(uri);
if (uri_len > max_uri_len) { if (uri_len > max_uri_len) {
BT_DBG("URI len (%zu) longer than maximum writable %zu", LOG_DBG("URI len (%zu) longer than maximum writable %zu", uri_len, max_uri_len);
uri_len, max_uri_len);
return -ENOMEM; return -ENOMEM;
} }
@ -1653,13 +1651,13 @@ int bt_tbs_client_join_calls(struct bt_conn *conn, uint8_t inst_index,
} }
if (inst->call_cp_sub_params.value_handle == 0) { if (inst->call_cp_sub_params.value_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
if (count > max_call_cnt) { if (count > max_call_cnt) {
BT_DBG("Call count (%u) larger than maximum writable %zu", LOG_DBG("Call count (%u) larger than maximum writable %zu", count,
count, max_call_cnt); max_call_cnt);
return -ENOMEM; return -ENOMEM;
} }
@ -1697,7 +1695,7 @@ int bt_tbs_client_set_signal_strength_interval(struct bt_conn *conn,
/* Populate Outgoing Remote URI */ /* Populate Outgoing Remote URI */
if (inst->signal_interval_handle == 0) { if (inst->signal_interval_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -1725,7 +1723,7 @@ int bt_tbs_client_read_bearer_provider_name(struct bt_conn *conn,
} }
if (inst->name_sub_params.value_handle == 0) { if (inst->name_sub_params.value_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -1759,7 +1757,7 @@ int bt_tbs_client_read_bearer_uci(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->bearer_uci_handle == 0) { if (inst->bearer_uci_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -1793,7 +1791,7 @@ int bt_tbs_client_read_technology(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->technology_sub_params.value_handle == 0) { if (inst->technology_sub_params.value_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -1827,7 +1825,7 @@ int bt_tbs_client_read_uri_list(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->uri_list_handle == 0) { if (inst->uri_list_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -1861,7 +1859,7 @@ int bt_tbs_client_read_signal_strength(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->signal_strength_sub_params.value_handle == 0) { if (inst->signal_strength_sub_params.value_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -1895,7 +1893,7 @@ int bt_tbs_client_read_signal_interval(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->signal_interval_handle == 0) { if (inst->signal_interval_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -1929,7 +1927,7 @@ int bt_tbs_client_read_current_calls(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->current_calls_sub_params.value_handle == 0) { if (inst->current_calls_sub_params.value_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -1963,7 +1961,7 @@ int bt_tbs_client_read_ccid(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->ccid_handle == 0) { if (inst->ccid_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -1997,7 +1995,7 @@ int bt_tbs_client_read_call_uri(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->in_target_uri_sub_params.value_handle == 0) { if (inst->in_target_uri_sub_params.value_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -2031,7 +2029,7 @@ int bt_tbs_client_read_status_flags(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->status_flags_sub_params.value_handle == 0) { if (inst->status_flags_sub_params.value_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -2064,7 +2062,7 @@ int bt_tbs_client_read_call_state(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->call_state_sub_params.value_handle == 0) { if (inst->call_state_sub_params.value_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -2098,7 +2096,7 @@ int bt_tbs_client_read_optional_opcodes(struct bt_conn *conn,
} }
if (inst->optional_opcodes_handle == 0) { if (inst->optional_opcodes_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -2132,7 +2130,7 @@ int bt_tbs_client_read_remote_uri(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->incoming_call_sub_params.value_handle == 0) { if (inst->incoming_call_sub_params.value_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -2166,7 +2164,7 @@ int bt_tbs_client_read_friendly_name(struct bt_conn *conn, uint8_t inst_index)
} }
if (inst->friendly_name_sub_params.value_handle == 0) { if (inst->friendly_name_sub_params.value_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
@ -2207,7 +2205,7 @@ int bt_tbs_client_discover(struct bt_conn *conn, bool subscribe)
srv_inst->subscribe_all = subscribe; srv_inst->subscribe_all = subscribe;
(void)memset(&srv_inst->discover_params, 0, sizeof(srv_inst->discover_params)); (void)memset(&srv_inst->discover_params, 0, sizeof(srv_inst->discover_params));
if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS)) { if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS)) {
BT_DBG("Discovering GTBS"); LOG_DBG("Discovering GTBS");
srv_inst->discover_params.uuid = gtbs_uuid; srv_inst->discover_params.uuid = gtbs_uuid;
srv_inst->discover_params.func = primary_discover_gtbs; srv_inst->discover_params.func = primary_discover_gtbs;
} else { } else {
@ -2233,7 +2231,7 @@ struct bt_tbs_instance *bt_tbs_client_get_by_ccid(const struct bt_conn *conn,
struct bt_tbs_server_inst *server; struct bt_tbs_server_inst *server;
CHECKIF(conn == NULL) { CHECKIF(conn == NULL) {
BT_DBG("conn was NULL"); LOG_DBG("conn was NULL");
return NULL; return NULL;
} }

File diff suppressed because it is too large Load diff

View file

@ -13,21 +13,21 @@
#include "pacs_internal.h" #include "pacs_internal.h"
#include "endpoint.h" #include "endpoint.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_UNICAST_SERVER) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_unicast_server
#include "common/log.h" LOG_MODULE_REGISTER(bt_unicast_server, CONFIG_BT_AUDIO_UNICAST_SERVER_LOG_LEVEL);
const struct bt_audio_unicast_server_cb *unicast_server_cb; const struct bt_audio_unicast_server_cb *unicast_server_cb;
int bt_audio_unicast_server_register_cb(const struct bt_audio_unicast_server_cb *cb) int bt_audio_unicast_server_register_cb(const struct bt_audio_unicast_server_cb *cb)
{ {
CHECKIF(cb == NULL) { CHECKIF(cb == NULL) {
BT_DBG("cb is NULL"); LOG_DBG("cb is NULL");
return -EINVAL; return -EINVAL;
} }
if (unicast_server_cb != NULL) { if (unicast_server_cb != NULL) {
BT_DBG("callback structure already registered"); LOG_DBG("callback structure already registered");
return -EALREADY; return -EALREADY;
} }
@ -39,12 +39,12 @@ int bt_audio_unicast_server_register_cb(const struct bt_audio_unicast_server_cb
int bt_audio_unicast_server_unregister_cb(const struct bt_audio_unicast_server_cb *cb) int bt_audio_unicast_server_unregister_cb(const struct bt_audio_unicast_server_cb *cb)
{ {
CHECKIF(cb == NULL) { CHECKIF(cb == NULL) {
BT_DBG("cb is NULL"); LOG_DBG("cb is NULL");
return -EINVAL; return -EINVAL;
} }
if (unicast_server_cb != cb) { if (unicast_server_cb != cb) {
BT_DBG("callback structure not registered"); LOG_DBG("callback structure not registered");
return -EINVAL; return -EINVAL;
} }

View file

@ -8,6 +8,8 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <string.h>
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
#include <zephyr/sys/check.h> #include <zephyr/sys/check.h>
@ -23,9 +25,9 @@
#include "audio_internal.h" #include "audio_internal.h"
#include "vcs_internal.h" #include "vcs_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_VCS) #define LOG_LEVEL CONFIG_BT_VCS_LOG_LEVEL
#define LOG_MODULE_NAME bt_vcs #include <zephyr/logging/log.h>
#include "common/log.h" LOG_MODULE_REGISTER(bt_vcs);
static bool valid_vocs_inst(struct bt_vcs *vcs, struct bt_vocs *vocs) static bool valid_vocs_inst(struct bt_vcs *vcs, struct bt_vocs *vocs)
{ {
@ -75,16 +77,15 @@ static struct bt_vcs vcs_inst;
static void volume_state_cfg_changed(const struct bt_gatt_attr *attr, static void volume_state_cfg_changed(const struct bt_gatt_attr *attr,
uint16_t value) uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_vol_state(struct bt_conn *conn, static ssize_t read_vol_state(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf, const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset) uint16_t len, uint16_t offset)
{ {
BT_DBG("Volume %u, mute %u, counter %u", LOG_DBG("Volume %u, mute %u, counter %u", vcs_inst.srv.state.volume,
vcs_inst.srv.state.volume, vcs_inst.srv.state.mute, vcs_inst.srv.state.mute, vcs_inst.srv.state.change_counter);
vcs_inst.srv.state.change_counter);
return bt_gatt_attr_read(conn, attr, buf, len, offset, return bt_gatt_attr_read(conn, attr, buf, len, offset,
&vcs_inst.srv.state, sizeof(vcs_inst.srv.state)); &vcs_inst.srv.state, sizeof(vcs_inst.srv.state));
@ -110,7 +111,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
/* Check opcode before length */ /* Check opcode before length */
if (!VALID_VCS_OPCODE(cp_val->cp.opcode)) { if (!VALID_VCS_OPCODE(cp_val->cp.opcode)) {
BT_DBG("Invalid opcode %u", cp_val->cp.opcode); LOG_DBG("Invalid opcode %u", cp_val->cp.opcode);
return BT_GATT_ERR(BT_VCS_ERR_OP_NOT_SUPPORTED); return BT_GATT_ERR(BT_VCS_ERR_OP_NOT_SUPPORTED);
} }
@ -123,7 +124,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
opcode = cp_val->cp.opcode; opcode = cp_val->cp.opcode;
BT_DBG("Opcode %u, counter %u", opcode, cp_val->cp.counter); LOG_DBG("Opcode %u, counter %u", opcode, cp_val->cp.counter);
if (cp_val->cp.counter != vcs_inst.srv.state.change_counter) { if (cp_val->cp.counter != vcs_inst.srv.state.change_counter) {
return BT_GATT_ERR(BT_VCS_ERR_INVALID_COUNTER); return BT_GATT_ERR(BT_VCS_ERR_INVALID_COUNTER);
@ -131,7 +132,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
switch (opcode) { switch (opcode) {
case BT_VCS_OPCODE_REL_VOL_DOWN: case BT_VCS_OPCODE_REL_VOL_DOWN:
BT_DBG("Relative Volume Down (0x%x)", opcode); LOG_DBG("Relative Volume Down (0x%x)", opcode);
if (vcs_inst.srv.state.volume > 0) { if (vcs_inst.srv.state.volume > 0) {
vcs_inst.srv.state.volume = VOLUME_DOWN(vcs_inst.srv.state.volume); vcs_inst.srv.state.volume = VOLUME_DOWN(vcs_inst.srv.state.volume);
notify = true; notify = true;
@ -139,7 +140,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
volume_change = true; volume_change = true;
break; break;
case BT_VCS_OPCODE_REL_VOL_UP: case BT_VCS_OPCODE_REL_VOL_UP:
BT_DBG("Relative Volume Up (0x%x)", opcode); LOG_DBG("Relative Volume Up (0x%x)", opcode);
if (vcs_inst.srv.state.volume != UINT8_MAX) { if (vcs_inst.srv.state.volume != UINT8_MAX) {
vcs_inst.srv.state.volume = VOLUME_UP(vcs_inst.srv.state.volume); vcs_inst.srv.state.volume = VOLUME_UP(vcs_inst.srv.state.volume);
notify = true; notify = true;
@ -147,7 +148,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
volume_change = true; volume_change = true;
break; break;
case BT_VCS_OPCODE_UNMUTE_REL_VOL_DOWN: case BT_VCS_OPCODE_UNMUTE_REL_VOL_DOWN:
BT_DBG("(Unmute) relative Volume Down (0x%x)", opcode); LOG_DBG("(Unmute) relative Volume Down (0x%x)", opcode);
if (vcs_inst.srv.state.volume > 0) { if (vcs_inst.srv.state.volume > 0) {
vcs_inst.srv.state.volume = VOLUME_DOWN(vcs_inst.srv.state.volume); vcs_inst.srv.state.volume = VOLUME_DOWN(vcs_inst.srv.state.volume);
notify = true; notify = true;
@ -159,7 +160,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
volume_change = true; volume_change = true;
break; break;
case BT_VCS_OPCODE_UNMUTE_REL_VOL_UP: case BT_VCS_OPCODE_UNMUTE_REL_VOL_UP:
BT_DBG("(Unmute) relative Volume Up (0x%x)", opcode); LOG_DBG("(Unmute) relative Volume Up (0x%x)", opcode);
if (vcs_inst.srv.state.volume != UINT8_MAX) { if (vcs_inst.srv.state.volume != UINT8_MAX) {
vcs_inst.srv.state.volume = VOLUME_UP(vcs_inst.srv.state.volume); vcs_inst.srv.state.volume = VOLUME_UP(vcs_inst.srv.state.volume);
notify = true; notify = true;
@ -171,7 +172,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
volume_change = true; volume_change = true;
break; break;
case BT_VCS_OPCODE_SET_ABS_VOL: case BT_VCS_OPCODE_SET_ABS_VOL:
BT_DBG("Set Absolute Volume (0x%x): Current volume %u", LOG_DBG("Set Absolute Volume (0x%x): Current volume %u",
opcode, vcs_inst.srv.state.volume); opcode, vcs_inst.srv.state.volume);
if (vcs_inst.srv.state.volume != cp_val->volume) { if (vcs_inst.srv.state.volume != cp_val->volume) {
vcs_inst.srv.state.volume = cp_val->volume; vcs_inst.srv.state.volume = cp_val->volume;
@ -180,29 +181,28 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
volume_change = true; volume_change = true;
break; break;
case BT_VCS_OPCODE_UNMUTE: case BT_VCS_OPCODE_UNMUTE:
BT_DBG("Unmute (0x%x)", opcode); LOG_DBG("Unmute (0x%x)", opcode);
if (vcs_inst.srv.state.mute) { if (vcs_inst.srv.state.mute) {
vcs_inst.srv.state.mute = BT_VCS_STATE_UNMUTED; vcs_inst.srv.state.mute = BT_VCS_STATE_UNMUTED;
notify = true; notify = true;
} }
break; break;
case BT_VCS_OPCODE_MUTE: case BT_VCS_OPCODE_MUTE:
BT_DBG("Mute (0x%x)", opcode); LOG_DBG("Mute (0x%x)", opcode);
if (vcs_inst.srv.state.mute == BT_VCS_STATE_UNMUTED) { if (vcs_inst.srv.state.mute == BT_VCS_STATE_UNMUTED) {
vcs_inst.srv.state.mute = BT_VCS_STATE_MUTED; vcs_inst.srv.state.mute = BT_VCS_STATE_MUTED;
notify = true; notify = true;
} }
break; break;
default: default:
BT_DBG("Unknown opcode (0x%x)", opcode); LOG_DBG("Unknown opcode (0x%x)", opcode);
return BT_GATT_ERR(BT_VCS_ERR_OP_NOT_SUPPORTED); return BT_GATT_ERR(BT_VCS_ERR_OP_NOT_SUPPORTED);
} }
if (notify) { if (notify) {
vcs_inst.srv.state.change_counter++; vcs_inst.srv.state.change_counter++;
BT_DBG("New state: volume %u, mute %u, counter %u", LOG_DBG("New state: volume %u, mute %u, counter %u", vcs_inst.srv.state.volume,
vcs_inst.srv.state.volume, vcs_inst.srv.state.mute, vcs_inst.srv.state.mute, vcs_inst.srv.state.change_counter);
vcs_inst.srv.state.change_counter);
bt_gatt_notify_uuid(NULL, BT_UUID_VCS_STATE, bt_gatt_notify_uuid(NULL, BT_UUID_VCS_STATE,
vcs_inst.srv.service_p->attrs, vcs_inst.srv.service_p->attrs,
@ -231,13 +231,13 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
static void flags_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void flags_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_flags(struct bt_conn *conn, const struct bt_gatt_attr *attr, static ssize_t read_flags(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset) void *buf, uint16_t len, uint16_t offset)
{ {
BT_DBG("0x%02x", vcs_inst.srv.flags); LOG_DBG("0x%02x", vcs_inst.srv.flags);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &vcs_inst.srv.flags, return bt_gatt_attr_read(conn, attr, buf, len, offset, &vcs_inst.srv.flags,
sizeof(vcs_inst.srv.flags)); sizeof(vcs_inst.srv.flags));
} }
@ -283,16 +283,14 @@ static int prepare_vocs_inst(struct bt_vcs_register_param *param)
vcs_inst.srv.vocs_insts[j] = bt_vocs_free_instance_get(); vcs_inst.srv.vocs_insts[j] = bt_vocs_free_instance_get();
if (vcs_inst.srv.vocs_insts[j] == NULL) { if (vcs_inst.srv.vocs_insts[j] == NULL) {
BT_ERR("Could not get free VOCS instances[%d]", LOG_ERR("Could not get free VOCS instances[%d]", j);
j);
return -ENOMEM; return -ENOMEM;
} }
err = bt_vocs_register(vcs_inst.srv.vocs_insts[j], err = bt_vocs_register(vcs_inst.srv.vocs_insts[j],
&param->vocs_param[j]); &param->vocs_param[j]);
if (err != 0) { if (err != 0) {
BT_DBG("Could not register VOCS instance[%d]: %d", LOG_DBG("Could not register VOCS instance[%d]: %d", j, err);
j, err);
return err; return err;
} }
@ -325,23 +323,21 @@ static int prepare_aics_inst(struct bt_vcs_register_param *param)
vcs_inst.srv.aics_insts[j] = bt_aics_free_instance_get(); vcs_inst.srv.aics_insts[j] = bt_aics_free_instance_get();
if (vcs_inst.srv.aics_insts[j] == NULL) { if (vcs_inst.srv.aics_insts[j] == NULL) {
BT_ERR("Could not get free AICS instances[%d]", LOG_ERR("Could not get free AICS instances[%d]", j);
j);
return -ENOMEM; return -ENOMEM;
} }
err = bt_aics_register(vcs_inst.srv.aics_insts[j], err = bt_aics_register(vcs_inst.srv.aics_insts[j],
&param->aics_param[j]); &param->aics_param[j]);
if (err != 0) { if (err != 0) {
BT_DBG("Could not register AICS instance[%d]: %d", LOG_DBG("Could not register AICS instance[%d]: %d", j, err);
j, err);
return err; return err;
} }
vcs_attrs[i].user_data = bt_aics_svc_decl_get(vcs_inst.srv.aics_insts[j]); vcs_attrs[i].user_data = bt_aics_svc_decl_get(vcs_inst.srv.aics_insts[j]);
j++; j++;
BT_DBG("AICS P %p", vcs_attrs[i].user_data); LOG_DBG("AICS P %p", vcs_attrs[i].user_data);
if (j == CONFIG_BT_VCS_AICS_INSTANCE_COUNT) { if (j == CONFIG_BT_VCS_AICS_INSTANCE_COUNT) {
break; break;
@ -362,17 +358,17 @@ int bt_vcs_register(struct bt_vcs_register_param *param, struct bt_vcs **vcs)
int err; int err;
CHECKIF(param == NULL) { CHECKIF(param == NULL) {
BT_DBG("param is NULL"); LOG_DBG("param is NULL");
return -EINVAL; return -EINVAL;
} }
CHECKIF(param->mute > BT_VCS_STATE_MUTED) { CHECKIF(param->mute > BT_VCS_STATE_MUTED) {
BT_DBG("Invalid mute value: %u", param->mute); LOG_DBG("Invalid mute value: %u", param->mute);
return -EINVAL; return -EINVAL;
} }
CHECKIF(param->step == 0) { CHECKIF(param->step == 0) {
BT_DBG("Invalid step value: %u", param->step); LOG_DBG("Invalid step value: %u", param->step);
return -EINVAL; return -EINVAL;
} }
@ -407,7 +403,7 @@ int bt_vcs_register(struct bt_vcs_register_param *param, struct bt_vcs **vcs)
err = bt_gatt_service_register(&vcs_svc); err = bt_gatt_service_register(&vcs_svc);
if (err != 0) { if (err != 0) {
BT_DBG("VCS service register failed: %d", err); LOG_DBG("VCS service register failed: %d", err);
} }
vcs_inst.srv.cb = param->cb; vcs_inst.srv.cb = param->cb;
@ -421,12 +417,12 @@ int bt_vcs_register(struct bt_vcs_register_param *param, struct bt_vcs **vcs)
int bt_vcs_aics_deactivate(struct bt_vcs *vcs, struct bt_aics *inst) int bt_vcs_aics_deactivate(struct bt_vcs *vcs, struct bt_aics *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst == NULL) { CHECKIF(inst == NULL) {
BT_DBG("NULL aics instance"); LOG_DBG("NULL aics instance");
return -EINVAL; return -EINVAL;
} }
@ -440,12 +436,12 @@ int bt_vcs_aics_deactivate(struct bt_vcs *vcs, struct bt_aics *inst)
int bt_vcs_aics_activate(struct bt_vcs *vcs, struct bt_aics *inst) int bt_vcs_aics_activate(struct bt_vcs *vcs, struct bt_aics *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst == NULL) { CHECKIF(inst == NULL) {
BT_DBG("NULL aics instance"); LOG_DBG("NULL aics instance");
return -EINVAL; return -EINVAL;
} }
@ -461,7 +457,7 @@ int bt_vcs_aics_activate(struct bt_vcs *vcs, struct bt_aics *inst)
int bt_vcs_included_get(struct bt_vcs *vcs, struct bt_vcs_included *included) int bt_vcs_included_get(struct bt_vcs *vcs, struct bt_vcs_included *included)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -504,7 +500,7 @@ int bt_vcs_vol_step_set(uint8_t volume_step)
int bt_vcs_vol_get(struct bt_vcs *vcs) int bt_vcs_vol_get(struct bt_vcs *vcs)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -527,7 +523,7 @@ int bt_vcs_vol_get(struct bt_vcs *vcs)
int bt_vcs_flags_get(struct bt_vcs *vcs) int bt_vcs_flags_get(struct bt_vcs *vcs)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -549,7 +545,7 @@ int bt_vcs_flags_get(struct bt_vcs *vcs)
int bt_vcs_vol_down(struct bt_vcs *vcs) int bt_vcs_vol_down(struct bt_vcs *vcs)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -573,7 +569,7 @@ int bt_vcs_vol_down(struct bt_vcs *vcs)
int bt_vcs_vol_up(struct bt_vcs *vcs) int bt_vcs_vol_up(struct bt_vcs *vcs)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -597,7 +593,7 @@ int bt_vcs_vol_up(struct bt_vcs *vcs)
int bt_vcs_unmute_vol_down(struct bt_vcs *vcs) int bt_vcs_unmute_vol_down(struct bt_vcs *vcs)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -621,7 +617,7 @@ int bt_vcs_unmute_vol_down(struct bt_vcs *vcs)
int bt_vcs_unmute_vol_up(struct bt_vcs *vcs) int bt_vcs_unmute_vol_up(struct bt_vcs *vcs)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -645,7 +641,7 @@ int bt_vcs_unmute_vol_up(struct bt_vcs *vcs)
int bt_vcs_vol_set(struct bt_vcs *vcs, uint8_t volume) int bt_vcs_vol_set(struct bt_vcs *vcs, uint8_t volume)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -672,7 +668,7 @@ int bt_vcs_vol_set(struct bt_vcs *vcs, uint8_t volume)
int bt_vcs_unmute(struct bt_vcs *vcs) int bt_vcs_unmute(struct bt_vcs *vcs)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -696,7 +692,7 @@ int bt_vcs_unmute(struct bt_vcs *vcs)
int bt_vcs_mute(struct bt_vcs *vcs) int bt_vcs_mute(struct bt_vcs *vcs)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -720,7 +716,7 @@ int bt_vcs_mute(struct bt_vcs *vcs)
int bt_vcs_vocs_state_get(struct bt_vcs *vcs, struct bt_vocs *inst) int bt_vcs_vocs_state_get(struct bt_vcs *vcs, struct bt_vocs *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -739,7 +735,7 @@ int bt_vcs_vocs_state_get(struct bt_vcs *vcs, struct bt_vocs *inst)
int bt_vcs_vocs_location_get(struct bt_vcs *vcs, struct bt_vocs *inst) int bt_vcs_vocs_location_get(struct bt_vcs *vcs, struct bt_vocs *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -759,7 +755,7 @@ int bt_vcs_vocs_location_set(struct bt_vcs *vcs, struct bt_vocs *inst,
uint8_t location) uint8_t location)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -779,7 +775,7 @@ int bt_vcs_vocs_state_set(struct bt_vcs *vcs, struct bt_vocs *inst,
int16_t offset) int16_t offset)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -798,7 +794,7 @@ int bt_vcs_vocs_state_set(struct bt_vcs *vcs, struct bt_vocs *inst,
int bt_vcs_vocs_description_get(struct bt_vcs *vcs, struct bt_vocs *inst) int bt_vcs_vocs_description_get(struct bt_vcs *vcs, struct bt_vocs *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -818,7 +814,7 @@ int bt_vcs_vocs_description_set(struct bt_vcs *vcs, struct bt_vocs *inst,
const char *description) const char *description)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -837,7 +833,7 @@ int bt_vcs_vocs_description_set(struct bt_vcs *vcs, struct bt_vocs *inst,
int bt_vcs_aics_state_get(struct bt_vcs *vcs, struct bt_aics *inst) int bt_vcs_aics_state_get(struct bt_vcs *vcs, struct bt_aics *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -856,7 +852,7 @@ int bt_vcs_aics_state_get(struct bt_vcs *vcs, struct bt_aics *inst)
int bt_vcs_aics_gain_setting_get(struct bt_vcs *vcs, struct bt_aics *inst) int bt_vcs_aics_gain_setting_get(struct bt_vcs *vcs, struct bt_aics *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -875,7 +871,7 @@ int bt_vcs_aics_gain_setting_get(struct bt_vcs *vcs, struct bt_aics *inst)
int bt_vcs_aics_type_get(struct bt_vcs *vcs, struct bt_aics *inst) int bt_vcs_aics_type_get(struct bt_vcs *vcs, struct bt_aics *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -894,7 +890,7 @@ int bt_vcs_aics_type_get(struct bt_vcs *vcs, struct bt_aics *inst)
int bt_vcs_aics_status_get(struct bt_vcs *vcs, struct bt_aics *inst) int bt_vcs_aics_status_get(struct bt_vcs *vcs, struct bt_aics *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -913,7 +909,7 @@ int bt_vcs_aics_status_get(struct bt_vcs *vcs, struct bt_aics *inst)
int bt_vcs_aics_unmute(struct bt_vcs *vcs, struct bt_aics *inst) int bt_vcs_aics_unmute(struct bt_vcs *vcs, struct bt_aics *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -932,7 +928,7 @@ int bt_vcs_aics_unmute(struct bt_vcs *vcs, struct bt_aics *inst)
int bt_vcs_aics_mute(struct bt_vcs *vcs, struct bt_aics *inst) int bt_vcs_aics_mute(struct bt_vcs *vcs, struct bt_aics *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -951,7 +947,7 @@ int bt_vcs_aics_mute(struct bt_vcs *vcs, struct bt_aics *inst)
int bt_vcs_aics_manual_gain_set(struct bt_vcs *vcs, struct bt_aics *inst) int bt_vcs_aics_manual_gain_set(struct bt_vcs *vcs, struct bt_aics *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -970,7 +966,7 @@ int bt_vcs_aics_manual_gain_set(struct bt_vcs *vcs, struct bt_aics *inst)
int bt_vcs_aics_automatic_gain_set(struct bt_vcs *vcs, struct bt_aics *inst) int bt_vcs_aics_automatic_gain_set(struct bt_vcs *vcs, struct bt_aics *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -990,7 +986,7 @@ int bt_vcs_aics_gain_set(struct bt_vcs *vcs, struct bt_aics *inst,
int8_t gain) int8_t gain)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -1009,7 +1005,7 @@ int bt_vcs_aics_gain_set(struct bt_vcs *vcs, struct bt_aics *inst,
int bt_vcs_aics_description_get(struct bt_vcs *vcs, struct bt_aics *inst) int bt_vcs_aics_description_get(struct bt_vcs *vcs, struct bt_aics *inst)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }
@ -1029,7 +1025,7 @@ int bt_vcs_aics_description_set(struct bt_vcs *vcs, struct bt_aics *inst,
const char *description) const char *description)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance"); LOG_DBG("NULL vcs instance");
return -EINVAL; return -EINVAL;
} }

View file

@ -22,9 +22,10 @@
#include "vcs_internal.h" #include "vcs_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_VCS_CLIENT) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_vcs_client
#include "common/log.h" LOG_MODULE_REGISTER(bt_vcs_client, CONFIG_BT_VCS_CLIENT_LOG_LEVEL);
#include "common/bt_str.h" #include "common/bt_str.h"
/* Callback functions */ /* Callback functions */
@ -103,9 +104,8 @@ static uint8_t vcs_client_notify_handler(struct bt_conn *conn,
if (handle == vcs_inst->cli.state_handle && if (handle == vcs_inst->cli.state_handle &&
length == sizeof(vcs_inst->cli.state)) { length == sizeof(vcs_inst->cli.state)) {
memcpy(&vcs_inst->cli.state, data, length); memcpy(&vcs_inst->cli.state, data, length);
BT_DBG("Volume %u, mute %u, counter %u", LOG_DBG("Volume %u, mute %u, counter %u", vcs_inst->cli.state.volume,
vcs_inst->cli.state.volume, vcs_inst->cli.state.mute, vcs_inst->cli.state.mute, vcs_inst->cli.state.change_counter);
vcs_inst->cli.state.change_counter);
if (vcs_client_cb && vcs_client_cb->state) { if (vcs_client_cb && vcs_client_cb->state) {
vcs_client_cb->state(vcs_inst, 0, vcs_inst->cli.state.volume, vcs_client_cb->state(vcs_inst, 0, vcs_inst->cli.state.volume,
vcs_inst->cli.state.mute); vcs_inst->cli.state.mute);
@ -113,7 +113,7 @@ static uint8_t vcs_client_notify_handler(struct bt_conn *conn,
} else if (handle == vcs_inst->cli.flag_handle && } else if (handle == vcs_inst->cli.flag_handle &&
length == sizeof(vcs_inst->cli.flags)) { length == sizeof(vcs_inst->cli.flags)) {
memcpy(&vcs_inst->cli.flags, data, length); memcpy(&vcs_inst->cli.flags, data, length);
BT_DBG("Flags %u", vcs_inst->cli.flags); LOG_DBG("Flags %u", vcs_inst->cli.flags);
if (vcs_client_cb && vcs_client_cb->flags) { if (vcs_client_cb && vcs_client_cb->flags) {
vcs_client_cb->flags(vcs_inst, 0, vcs_inst->cli.flags); vcs_client_cb->flags(vcs_inst, 0, vcs_inst->cli.flags);
} }
@ -132,17 +132,15 @@ static uint8_t vcs_client_read_vol_state_cb(struct bt_conn *conn, uint8_t err,
vcs_inst->cli.busy = false; vcs_inst->cli.busy = false;
if (cb_err) { if (cb_err) {
BT_DBG("err: %d", cb_err); LOG_DBG("err: %d", cb_err);
} else if (data != NULL) { } else if (data != NULL) {
if (length == sizeof(vcs_inst->cli.state)) { if (length == sizeof(vcs_inst->cli.state)) {
memcpy(&vcs_inst->cli.state, data, length); memcpy(&vcs_inst->cli.state, data, length);
BT_DBG("Volume %u, mute %u, counter %u", LOG_DBG("Volume %u, mute %u, counter %u", vcs_inst->cli.state.volume,
vcs_inst->cli.state.volume, vcs_inst->cli.state.mute, vcs_inst->cli.state.change_counter);
vcs_inst->cli.state.mute,
vcs_inst->cli.state.change_counter);
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", LOG_DBG("Invalid length %u (expected %zu)", length,
length, sizeof(vcs_inst->cli.state)); sizeof(vcs_inst->cli.state));
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} }
@ -170,14 +168,14 @@ static uint8_t vcs_client_read_flag_cb(struct bt_conn *conn, uint8_t err,
vcs_inst->cli.busy = false; vcs_inst->cli.busy = false;
if (cb_err) { if (cb_err) {
BT_DBG("err: %d", cb_err); LOG_DBG("err: %d", cb_err);
} else if (data != NULL) { } else if (data != NULL) {
if (length == sizeof(vcs_inst->cli.flags)) { if (length == sizeof(vcs_inst->cli.flags)) {
memcpy(&vcs_inst->cli.flags, data, length); memcpy(&vcs_inst->cli.flags, data, length);
BT_DBG("Flags %u", vcs_inst->cli.flags); LOG_DBG("Flags %u", vcs_inst->cli.flags);
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", LOG_DBG("Invalid length %u (expected %zu)", length,
length, sizeof(vcs_inst->cli.flags)); sizeof(vcs_inst->cli.flags));
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} }
@ -236,7 +234,7 @@ static void vcs_cp_notify_app(struct bt_vcs *vcs, uint8_t opcode, int err)
} }
break; break;
default: default:
BT_DBG("Unknown opcode 0x%02x", opcode); LOG_DBG("Unknown opcode 0x%02x", opcode);
break; break;
} }
} }
@ -253,17 +251,15 @@ static uint8_t internal_read_vol_state_cb(struct bt_conn *conn, uint8_t err,
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (err > 0) { if (err > 0) {
BT_WARN("Volume state read failed: %d", err); LOG_WRN("Volume state read failed: %d", err);
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} else if (data != NULL) { } else if (data != NULL) {
if (length == sizeof(vcs_inst->cli.state)) { if (length == sizeof(vcs_inst->cli.state)) {
int write_err; int write_err;
memcpy(&vcs_inst->cli.state, data, length); memcpy(&vcs_inst->cli.state, data, length);
BT_DBG("Volume %u, mute %u, counter %u", LOG_DBG("Volume %u, mute %u, counter %u", vcs_inst->cli.state.volume,
vcs_inst->cli.state.volume, vcs_inst->cli.state.mute, vcs_inst->cli.state.change_counter);
vcs_inst->cli.state.mute,
vcs_inst->cli.state.change_counter);
/* clear busy flag to reuse function */ /* clear busy flag to reuse function */
vcs_inst->cli.busy = false; vcs_inst->cli.busy = false;
@ -278,8 +274,8 @@ static uint8_t internal_read_vol_state_cb(struct bt_conn *conn, uint8_t err,
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", LOG_DBG("Invalid length %u (expected %zu)", length,
length, sizeof(vcs_inst->cli.state)); sizeof(vcs_inst->cli.state));
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
} }
@ -299,7 +295,7 @@ static void vcs_client_write_vcs_cp_cb(struct bt_conn *conn, uint8_t err,
uint8_t opcode = vcs_inst->cli.cp_val.cp.opcode; uint8_t opcode = vcs_inst->cli.cp_val.cp.opcode;
int cb_err = err; int cb_err = err;
BT_DBG("err: 0x%02X", err); LOG_DBG("err: 0x%02X", err);
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
/* If the change counter is out of data when a write was attempted from /* If the change counter is out of data when a write was attempted from
@ -319,7 +315,7 @@ static void vcs_client_write_vcs_cp_cb(struct bt_conn *conn, uint8_t err,
cb_err = bt_gatt_read(conn, &vcs_inst->cli.read_params); cb_err = bt_gatt_read(conn, &vcs_inst->cli.read_params);
if (cb_err) { if (cb_err) {
BT_WARN("Could not read Volume state: %d", cb_err); LOG_WRN("Could not read Volume state: %d", cb_err);
} else { } else {
vcs_inst->cli.cp_retried = true; vcs_inst->cli.cp_retried = true;
/* Wait for read callback */ /* Wait for read callback */
@ -344,8 +340,8 @@ static uint8_t vcs_discover_include_func(struct bt_conn *conn,
struct bt_vcs *vcs_inst = &vcs_insts[bt_conn_index(conn)]; struct bt_vcs *vcs_inst = &vcs_insts[bt_conn_index(conn)];
if (attr == NULL) { if (attr == NULL) {
BT_DBG("Discover include complete for VCS: %u AICS and %u VOCS", LOG_DBG("Discover include complete for VCS: %u AICS and %u VOCS",
vcs_inst->cli.aics_inst_cnt, vcs_inst->cli.vocs_inst_cnt); vcs_inst->cli.aics_inst_cnt, vcs_inst->cli.vocs_inst_cnt);
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
if (vcs_client_cb && vcs_client_cb->discover) { if (vcs_client_cb && vcs_client_cb->discover) {
@ -360,13 +356,13 @@ static uint8_t vcs_discover_include_func(struct bt_conn *conn,
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_INCLUDE) { if (params->type == BT_GATT_DISCOVER_INCLUDE) {
uint8_t conn_index = bt_conn_index(conn); uint8_t conn_index = bt_conn_index(conn);
include = (struct bt_gatt_include *)attr->user_data; include = (struct bt_gatt_include *)attr->user_data;
BT_DBG("Include UUID %s", bt_uuid_str(include->uuid)); LOG_DBG("Include UUID %s", bt_uuid_str(include->uuid));
#if CONFIG_BT_VCS_CLIENT_MAX_AICS_INST > 0 #if CONFIG_BT_VCS_CLIENT_MAX_AICS_INST > 0
if (bt_uuid_cmp(include->uuid, BT_UUID_AICS) == 0 && if (bt_uuid_cmp(include->uuid, BT_UUID_AICS) == 0 &&
@ -386,7 +382,7 @@ static uint8_t vcs_discover_include_func(struct bt_conn *conn,
vcs_insts[conn_index].cli.aics[inst_idx], vcs_insts[conn_index].cli.aics[inst_idx],
&param); &param);
if (err != 0) { if (err != 0) {
BT_DBG("AICS Discover failed (err %d)", err); LOG_DBG("AICS Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) { if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(vcs_inst, err, vcs_client_cb->discover(vcs_inst, err,
0, 0); 0, 0);
@ -414,7 +410,7 @@ static uint8_t vcs_discover_include_func(struct bt_conn *conn,
vcs_insts[conn_index].cli.vocs[inst_idx], vcs_insts[conn_index].cli.vocs[inst_idx],
&param); &param);
if (err != 0) { if (err != 0) {
BT_DBG("VOCS Discover failed (err %d)", err); LOG_DBG("VOCS Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) { if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(vcs_inst, err, vcs_client_cb->discover(vcs_inst, err,
0, 0); 0, 0);
@ -445,7 +441,7 @@ static uint8_t vcs_discover_func(struct bt_conn *conn,
struct bt_vcs *vcs_inst = &vcs_insts[bt_conn_index(conn)]; struct bt_vcs *vcs_inst = &vcs_insts[bt_conn_index(conn)];
if (attr == NULL) { if (attr == NULL) {
BT_DBG("Setup complete for VCS"); LOG_DBG("Setup complete for VCS");
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
#if (CONFIG_BT_VCS_CLIENT_MAX_AICS_INST > 0 || CONFIG_BT_VCS_CLIENT_MAX_VOCS_INST > 0) #if (CONFIG_BT_VCS_CLIENT_MAX_AICS_INST > 0 || CONFIG_BT_VCS_CLIENT_MAX_VOCS_INST > 0)
/* Discover included services */ /* Discover included services */
@ -456,7 +452,7 @@ static uint8_t vcs_discover_func(struct bt_conn *conn,
err = bt_gatt_discover(conn, &vcs_inst->cli.discover_params); err = bt_gatt_discover(conn, &vcs_inst->cli.discover_params);
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) { if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(vcs_inst, err, 0, 0); vcs_client_cb->discover(vcs_inst, err, 0, 0);
} }
@ -470,21 +466,21 @@ static uint8_t vcs_discover_func(struct bt_conn *conn,
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) {
chrc = (struct bt_gatt_chrc *)attr->user_data; chrc = (struct bt_gatt_chrc *)attr->user_data;
if (bt_uuid_cmp(chrc->uuid, BT_UUID_VCS_STATE) == 0) { if (bt_uuid_cmp(chrc->uuid, BT_UUID_VCS_STATE) == 0) {
BT_DBG("Volume state"); LOG_DBG("Volume state");
vcs_inst->cli.state_handle = chrc->value_handle; vcs_inst->cli.state_handle = chrc->value_handle;
sub_params = &vcs_inst->cli.state_sub_params; sub_params = &vcs_inst->cli.state_sub_params;
sub_params->disc_params = &vcs_inst->cli.state_sub_disc_params; sub_params->disc_params = &vcs_inst->cli.state_sub_disc_params;
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_VCS_CONTROL) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_VCS_CONTROL) == 0) {
BT_DBG("Control Point"); LOG_DBG("Control Point");
vcs_inst->cli.control_handle = chrc->value_handle; vcs_inst->cli.control_handle = chrc->value_handle;
} else if (bt_uuid_cmp(chrc->uuid, BT_UUID_VCS_FLAGS) == 0) { } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_VCS_FLAGS) == 0) {
BT_DBG("Flags"); LOG_DBG("Flags");
vcs_inst->cli.flag_handle = chrc->value_handle; vcs_inst->cli.flag_handle = chrc->value_handle;
sub_params = &vcs_inst->cli.flag_sub_params; sub_params = &vcs_inst->cli.flag_sub_params;
sub_params->disc_params = &vcs_inst->cli.flag_sub_disc_params; sub_params->disc_params = &vcs_inst->cli.flag_sub_disc_params;
@ -500,11 +496,9 @@ static uint8_t vcs_discover_func(struct bt_conn *conn,
sub_params->notify = vcs_client_notify_handler; sub_params->notify = vcs_client_notify_handler;
err = bt_gatt_subscribe(conn, sub_params); err = bt_gatt_subscribe(conn, sub_params);
if (err == 0) { if (err == 0) {
BT_DBG("Subscribed to handle 0x%04X", LOG_DBG("Subscribed to handle 0x%04X", attr->handle);
attr->handle);
} else { } else {
BT_DBG("Could not subscribe to handle 0x%04X", LOG_DBG("Could not subscribe to handle 0x%04X", attr->handle);
attr->handle);
} }
} }
} }
@ -525,19 +519,19 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
struct bt_vcs *vcs_inst = &vcs_insts[bt_conn_index(conn)]; struct bt_vcs *vcs_inst = &vcs_insts[bt_conn_index(conn)];
if (attr == NULL) { if (attr == NULL) {
BT_DBG("Could not find a VCS instance on the server"); LOG_DBG("Could not find a VCS instance on the server");
if (vcs_client_cb && vcs_client_cb->discover) { if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(vcs_inst, -ENODATA, 0, 0); vcs_client_cb->discover(vcs_inst, -ENODATA, 0, 0);
} }
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_PRIMARY) { if (params->type == BT_GATT_DISCOVER_PRIMARY) {
int err; int err;
BT_DBG("Primary discover complete"); LOG_DBG("Primary discover complete");
prim_service = (struct bt_gatt_service_val *)attr->user_data; prim_service = (struct bt_gatt_service_val *)attr->user_data;
vcs_inst->cli.start_handle = attr->handle + 1; vcs_inst->cli.start_handle = attr->handle + 1;
@ -552,7 +546,7 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
err = bt_gatt_discover(conn, &vcs_inst->cli.discover_params); err = bt_gatt_discover(conn, &vcs_inst->cli.discover_params);
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) { if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(vcs_inst, err, 0, 0); vcs_client_cb->discover(vcs_inst, err, 0, 0);
} }
@ -569,12 +563,12 @@ static int vcs_client_common_vcs_cp(struct bt_vcs *vcs, uint8_t opcode)
int err; int err;
CHECKIF(vcs->cli.conn == NULL) { CHECKIF(vcs->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (vcs->cli.control_handle == 0) { if (vcs->cli.control_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (vcs->cli.busy) { } else if (vcs->cli.busy) {
return -EBUSY; return -EBUSY;
@ -623,7 +617,7 @@ static void aics_discover_cb(struct bt_aics *inst, int err)
} }
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) { if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(vcs_inst, err, 0, 0); vcs_client_cb->discover(vcs_inst, err, 0, 0);
} }
@ -652,7 +646,7 @@ static void vocs_discover_cb(struct bt_vocs *inst, int err)
struct bt_vcs *vcs_inst = lookup_vcs_by_vocs(inst); struct bt_vcs *vcs_inst = lookup_vcs_by_vocs(inst);
if (vcs_inst == NULL) { if (vcs_inst == NULL) {
BT_ERR("Could not lookup vcs_inst from vocs"); LOG_ERR("Could not lookup vcs_inst from vocs");
if (vcs_client_cb && vcs_client_cb->discover) { if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(vcs_inst, vcs_client_cb->discover(vcs_inst,
@ -670,7 +664,7 @@ static void vocs_discover_cb(struct bt_vocs *inst, int err)
} }
if (err != 0) { if (err != 0) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) { if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(vcs_inst, err, 0, 0); vcs_client_cb->discover(vcs_inst, err, 0, 0);
} }
@ -774,7 +768,7 @@ int bt_vcs_discover(struct bt_conn *conn, struct bt_vcs **vcs)
*/ */
CHECKIF(conn == NULL) { CHECKIF(conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
@ -817,7 +811,7 @@ int bt_vcs_client_cb_register(struct bt_vcs_cb *cb)
/* Ensure that the cb->vocs_cb.discover is the vocs_discover_cb */ /* Ensure that the cb->vocs_cb.discover is the vocs_discover_cb */
CHECKIF(cb->vocs_cb.discover != NULL && CHECKIF(cb->vocs_cb.discover != NULL &&
cb->vocs_cb.discover != vocs_discover_cb) { cb->vocs_cb.discover != vocs_discover_cb) {
BT_ERR("VOCS discover callback shall not be set"); LOG_ERR("VOCS discover callback shall not be set");
return -EINVAL; return -EINVAL;
} }
cb->vocs_cb.discover = vocs_discover_cb; cb->vocs_cb.discover = vocs_discover_cb;
@ -843,7 +837,7 @@ int bt_vcs_client_cb_register(struct bt_vcs_cb *cb)
/* Ensure that the cb->aics_cb.discover is the aics_discover_cb */ /* Ensure that the cb->aics_cb.discover is the aics_discover_cb */
CHECKIF(cb->aics_cb.discover != NULL && CHECKIF(cb->aics_cb.discover != NULL &&
cb->aics_cb.discover != aics_discover_cb) { cb->aics_cb.discover != aics_discover_cb) {
BT_ERR("AICS discover callback shall not be set"); LOG_ERR("AICS discover callback shall not be set");
return -EINVAL; return -EINVAL;
} }
cb->aics_cb.discover = aics_discover_cb; cb->aics_cb.discover = aics_discover_cb;
@ -886,17 +880,17 @@ int bt_vcs_client_included_get(struct bt_vcs *vcs,
int bt_vcs_client_conn_get(const struct bt_vcs *vcs, struct bt_conn **conn) int bt_vcs_client_conn_get(const struct bt_vcs *vcs, struct bt_conn **conn)
{ {
CHECKIF(vcs == NULL) { CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs pointer"); LOG_DBG("NULL vcs pointer");
return -EINVAL; return -EINVAL;
} }
if (!vcs->client_instance) { if (!vcs->client_instance) {
BT_DBG("vcs pointer shall be client instance"); LOG_DBG("vcs pointer shall be client instance");
return -EINVAL; return -EINVAL;
} }
if (vcs->cli.conn == NULL) { if (vcs->cli.conn == NULL) {
BT_DBG("vcs pointer not associated with a connection. " LOG_DBG("vcs pointer not associated with a connection. "
"Do discovery first"); "Do discovery first");
return -ENOTCONN; return -ENOTCONN;
} }
@ -910,12 +904,12 @@ int bt_vcs_client_read_vol_state(struct bt_vcs *vcs)
int err; int err;
CHECKIF(vcs->cli.conn == NULL) { CHECKIF(vcs->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (vcs->cli.state_handle == 0) { if (vcs->cli.state_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (vcs->cli.busy) { } else if (vcs->cli.busy) {
return -EBUSY; return -EBUSY;
@ -939,12 +933,12 @@ int bt_vcs_client_read_flags(struct bt_vcs *vcs)
int err; int err;
CHECKIF(vcs->cli.conn == NULL) { CHECKIF(vcs->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (vcs->cli.flag_handle == 0) { if (vcs->cli.flag_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (vcs->cli.busy) { } else if (vcs->cli.busy) {
return -EBUSY; return -EBUSY;
@ -988,12 +982,12 @@ int bt_vcs_client_set_volume(struct bt_vcs *vcs, uint8_t volume)
int err; int err;
CHECKIF(vcs->cli.conn == NULL) { CHECKIF(vcs->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (vcs->cli.control_handle == 0) { if (vcs->cli.control_handle == 0) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (vcs->cli.busy) { } else if (vcs->cli.busy) {
return -EBUSY; return -EBUSY;

View file

@ -20,16 +20,16 @@
#include "audio_internal.h" #include "audio_internal.h"
#include "vocs_internal.h" #include "vocs_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_VOCS) #define LOG_LEVEL CONFIG_BT_VOCS_LOG_LEVEL
#define LOG_MODULE_NAME bt_vocs #include <zephyr/logging/log.h>
#include "common/log.h" LOG_MODULE_REGISTER(bt_vocs);
#define VALID_VOCS_OPCODE(opcode) ((opcode) == BT_VOCS_OPCODE_SET_OFFSET) #define VALID_VOCS_OPCODE(opcode) ((opcode) == BT_VOCS_OPCODE_SET_OFFSET)
#if defined(CONFIG_BT_VOCS) #if defined(CONFIG_BT_VOCS)
static void offset_state_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void offset_state_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
static ssize_t read_offset_state(struct bt_conn *conn, const struct bt_gatt_attr *attr, static ssize_t read_offset_state(struct bt_conn *conn, const struct bt_gatt_attr *attr,
@ -37,14 +37,14 @@ static ssize_t read_offset_state(struct bt_conn *conn, const struct bt_gatt_attr
{ {
struct bt_vocs *inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_vocs *inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("offset %d, counter %u", inst->srv.state.offset, inst->srv.state.change_counter); LOG_DBG("offset %d, counter %u", inst->srv.state.offset, inst->srv.state.change_counter);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.state, return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.state,
sizeof(inst->srv.state)); sizeof(inst->srv.state));
} }
static void location_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void location_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
#endif /* CONFIG_BT_VOCS */ #endif /* CONFIG_BT_VOCS */
@ -64,7 +64,7 @@ static ssize_t write_location(struct bt_conn *conn, const struct bt_gatt_attr *a
} }
memcpy(&inst->srv.location, buf, len); memcpy(&inst->srv.location, buf, len);
BT_DBG("%02x", inst->srv.location); LOG_DBG("%02x", inst->srv.location);
if (old_location != inst->srv.location) { if (old_location != inst->srv.location) {
(void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_LOCATION, (void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_LOCATION,
@ -86,7 +86,7 @@ static ssize_t read_location(struct bt_conn *conn, const struct bt_gatt_attr *at
{ {
struct bt_vocs *inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_vocs *inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("0x%08x", inst->srv.location); LOG_DBG("0x%08x", inst->srv.location);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.location, return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.location,
sizeof(inst->srv.location)); sizeof(inst->srv.location));
} }
@ -109,7 +109,7 @@ static ssize_t write_vocs_control(struct bt_conn *conn, const struct bt_gatt_att
/* Check opcode before length */ /* Check opcode before length */
if (!VALID_VOCS_OPCODE(cp->opcode)) { if (!VALID_VOCS_OPCODE(cp->opcode)) {
BT_DBG("Invalid opcode %u", cp->opcode); LOG_DBG("Invalid opcode %u", cp->opcode);
return BT_GATT_ERR(BT_VOCS_ERR_OP_NOT_SUPPORTED); return BT_GATT_ERR(BT_VOCS_ERR_OP_NOT_SUPPORTED);
} }
@ -117,7 +117,7 @@ static ssize_t write_vocs_control(struct bt_conn *conn, const struct bt_gatt_att
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
BT_DBG("Opcode %u, counter %u", cp->opcode, cp->counter); LOG_DBG("Opcode %u, counter %u", cp->opcode, cp->counter);
if (cp->counter != inst->srv.state.change_counter) { if (cp->counter != inst->srv.state.change_counter) {
@ -126,7 +126,7 @@ static ssize_t write_vocs_control(struct bt_conn *conn, const struct bt_gatt_att
switch (cp->opcode) { switch (cp->opcode) {
case BT_VOCS_OPCODE_SET_OFFSET: case BT_VOCS_OPCODE_SET_OFFSET:
BT_DBG("Set offset %d", cp->offset); LOG_DBG("Set offset %d", cp->offset);
if (cp->offset > BT_VOCS_MAX_OFFSET || cp->offset < BT_VOCS_MIN_OFFSET) { if (cp->offset > BT_VOCS_MAX_OFFSET || cp->offset < BT_VOCS_MIN_OFFSET) {
return BT_GATT_ERR(BT_VOCS_ERR_OUT_OF_RANGE); return BT_GATT_ERR(BT_VOCS_ERR_OUT_OF_RANGE);
} }
@ -142,8 +142,8 @@ static ssize_t write_vocs_control(struct bt_conn *conn, const struct bt_gatt_att
if (notify) { if (notify) {
inst->srv.state.change_counter++; inst->srv.state.change_counter++;
BT_DBG("New state: offset %d, counter %u", LOG_DBG("New state: offset %d, counter %u", inst->srv.state.offset,
inst->srv.state.offset, inst->srv.state.change_counter); inst->srv.state.change_counter);
(void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_STATE, (void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_STATE,
inst->srv.service_p->attrs, inst->srv.service_p->attrs,
&inst->srv.state, sizeof(inst->srv.state)); &inst->srv.state, sizeof(inst->srv.state));
@ -160,7 +160,7 @@ static ssize_t write_vocs_control(struct bt_conn *conn, const struct bt_gatt_att
#if defined(CONFIG_BT_VOCS) #if defined(CONFIG_BT_VOCS)
static void output_desc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) static void output_desc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{ {
BT_DBG("value 0x%04x", value); LOG_DBG("value 0x%04x", value);
} }
#endif /* CONFIG_BT_VOCS */ #endif /* CONFIG_BT_VOCS */
@ -174,8 +174,8 @@ static ssize_t write_output_desc(struct bt_conn *conn, const struct bt_gatt_attr
} }
if (len >= sizeof(inst->srv.output_desc)) { if (len >= sizeof(inst->srv.output_desc)) {
BT_DBG("Output desc was clipped from length %u to %zu", LOG_DBG("Output desc was clipped from length %u to %zu", len,
len, sizeof(inst->srv.output_desc) - 1); sizeof(inst->srv.output_desc) - 1);
/* We just clip the string value if it's too long */ /* We just clip the string value if it's too long */
len = (uint16_t)sizeof(inst->srv.output_desc) - 1; len = (uint16_t)sizeof(inst->srv.output_desc) - 1;
} }
@ -194,7 +194,7 @@ static ssize_t write_output_desc(struct bt_conn *conn, const struct bt_gatt_attr
} }
} }
BT_DBG("%s", inst->srv.output_desc); LOG_DBG("%s", inst->srv.output_desc);
return len; return len;
} }
@ -228,7 +228,7 @@ static ssize_t read_output_desc(struct bt_conn *conn, const struct bt_gatt_attr
{ {
struct bt_vocs *inst = BT_AUDIO_CHRC_USER_DATA(attr); struct bt_vocs *inst = BT_AUDIO_CHRC_USER_DATA(attr);
BT_DBG("%s", inst->srv.output_desc); LOG_DBG("%s", inst->srv.output_desc);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.output_desc, return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.output_desc,
strlen(inst->srv.output_desc)); strlen(inst->srv.output_desc));
} }
@ -274,7 +274,7 @@ struct bt_vocs *bt_vocs_free_instance_get(void)
void *bt_vocs_svc_decl_get(struct bt_vocs *vocs) void *bt_vocs_svc_decl_get(struct bt_vocs *vocs)
{ {
CHECKIF(!vocs) { CHECKIF(!vocs) {
BT_DBG("Null VOCS pointer"); LOG_DBG("Null VOCS pointer");
return NULL; return NULL;
} }
@ -297,12 +297,12 @@ int bt_vocs_register(struct bt_vocs *vocs,
static bool instances_prepared; static bool instances_prepared;
CHECKIF(!vocs) { CHECKIF(!vocs) {
BT_DBG("Null VOCS pointer"); LOG_DBG("Null VOCS pointer");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!param) { CHECKIF(!param) {
BT_DBG("NULL params pointer"); LOG_DBG("NULL params pointer");
return -EINVAL; return -EINVAL;
} }
@ -312,12 +312,12 @@ int bt_vocs_register(struct bt_vocs *vocs,
} }
CHECKIF(vocs->srv.initialized) { CHECKIF(vocs->srv.initialized) {
BT_DBG("Already initialized VOCS instance"); LOG_DBG("Already initialized VOCS instance");
return -EALREADY; return -EALREADY;
} }
CHECKIF(param->offset > BT_VOCS_MAX_OFFSET || param->offset < BT_VOCS_MIN_OFFSET) { CHECKIF(param->offset > BT_VOCS_MAX_OFFSET || param->offset < BT_VOCS_MIN_OFFSET) {
BT_DBG("Invalid offset %d", param->offset); LOG_DBG("Invalid offset %d", param->offset);
return -EINVAL; return -EINVAL;
} }
@ -330,9 +330,9 @@ int bt_vocs_register(struct bt_vocs *vocs,
sizeof(vocs->srv.output_desc) - 1); sizeof(vocs->srv.output_desc) - 1);
/* strncpy may not always null-terminate */ /* strncpy may not always null-terminate */
vocs->srv.output_desc[sizeof(vocs->srv.output_desc) - 1] = '\0'; vocs->srv.output_desc[sizeof(vocs->srv.output_desc) - 1] = '\0';
if (IS_ENABLED(CONFIG_BT_DEBUG_VOCS) && if (IS_ENABLED(CONFIG_BT_VOCS_LOG_LEVEL_DBG) &&
strcmp(vocs->srv.output_desc, param->output_desc)) { strcmp(vocs->srv.output_desc, param->output_desc)) {
BT_DBG("Output desc clipped to %s", vocs->srv.output_desc); LOG_DBG("Output desc clipped to %s", vocs->srv.output_desc);
} }
} }
@ -361,7 +361,7 @@ int bt_vocs_register(struct bt_vocs *vocs,
err = bt_gatt_service_register(vocs->srv.service_p); err = bt_gatt_service_register(vocs->srv.service_p);
if (err) { if (err) {
BT_DBG("Could not register VOCS service"); LOG_DBG("Could not register VOCS service");
return err; return err;
} }
@ -373,7 +373,7 @@ int bt_vocs_register(struct bt_vocs *vocs,
int bt_vocs_state_get(struct bt_vocs *inst) int bt_vocs_state_get(struct bt_vocs *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("Null VOCS pointer"); LOG_DBG("Null VOCS pointer");
return -EINVAL; return -EINVAL;
} }
@ -392,7 +392,7 @@ int bt_vocs_state_get(struct bt_vocs *inst)
int bt_vocs_location_get(struct bt_vocs *inst) int bt_vocs_location_get(struct bt_vocs *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("Null VOCS pointer"); LOG_DBG("Null VOCS pointer");
return -EINVAL; return -EINVAL;
} }
@ -411,7 +411,7 @@ int bt_vocs_location_get(struct bt_vocs *inst)
int bt_vocs_location_set(struct bt_vocs *inst, uint32_t location) int bt_vocs_location_set(struct bt_vocs *inst, uint32_t location)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("Null VOCS pointer"); LOG_DBG("Null VOCS pointer");
return -EINVAL; return -EINVAL;
} }
@ -427,7 +427,7 @@ int bt_vocs_location_set(struct bt_vocs *inst, uint32_t location)
int bt_vocs_state_set(struct bt_vocs *inst, int16_t offset) int bt_vocs_state_set(struct bt_vocs *inst, int16_t offset)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("Null VOCS pointer"); LOG_DBG("Null VOCS pointer");
return -EINVAL; return -EINVAL;
} }
@ -449,7 +449,7 @@ int bt_vocs_state_set(struct bt_vocs *inst, int16_t offset)
int bt_vocs_description_get(struct bt_vocs *inst) int bt_vocs_description_get(struct bt_vocs *inst)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("Null VOCS pointer"); LOG_DBG("Null VOCS pointer");
return -EINVAL; return -EINVAL;
} }
@ -468,12 +468,12 @@ int bt_vocs_description_get(struct bt_vocs *inst)
int bt_vocs_description_set(struct bt_vocs *inst, const char *description) int bt_vocs_description_set(struct bt_vocs *inst, const char *description)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("Null VOCS pointer"); LOG_DBG("Null VOCS pointer");
return -EINVAL; return -EINVAL;
} }
CHECKIF(!description) { CHECKIF(!description) {
BT_DBG("Null description pointer"); LOG_DBG("Null description pointer");
return -EINVAL; return -EINVAL;
} }

View file

@ -21,9 +21,9 @@
#include "vocs_internal.h" #include "vocs_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_VOCS_CLIENT) #include <zephyr/logging/log.h>
#define LOG_MODULE_NAME bt_vocs_client
#include "common/log.h" LOG_MODULE_REGISTER(bt_vocs_client, CONFIG_BT_VOCS_CLIENT_LOG_LEVEL);
static struct bt_vocs vocs_insts[CONFIG_BT_MAX_CONN * CONFIG_BT_VOCS_CLIENT_MAX_INSTANCE_COUNT]; static struct bt_vocs vocs_insts[CONFIG_BT_MAX_CONN * CONFIG_BT_VOCS_CLIENT_MAX_INSTANCE_COUNT];
@ -41,7 +41,7 @@ static struct bt_vocs *lookup_vocs_by_handle(struct bt_conn *conn, uint16_t hand
} }
} }
BT_DBG("Could not find VOCS instance with handle 0x%04x", handle); LOG_DBG("Could not find VOCS instance with handle 0x%04x", handle);
return NULL; return NULL;
} }
@ -58,7 +58,7 @@ uint8_t vocs_client_notify_handler(struct bt_conn *conn, struct bt_gatt_subscrib
inst = lookup_vocs_by_handle(conn, handle); inst = lookup_vocs_by_handle(conn, handle);
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
@ -69,13 +69,13 @@ uint8_t vocs_client_notify_handler(struct bt_conn *conn, struct bt_gatt_subscrib
if (handle == inst->cli.state_handle) { if (handle == inst->cli.state_handle) {
if (length == sizeof(inst->cli.state)) { if (length == sizeof(inst->cli.state)) {
memcpy(&inst->cli.state, data, length); memcpy(&inst->cli.state, data, length);
BT_DBG("Inst %p: Offset %d, counter %u", inst, inst->cli.state.offset, LOG_DBG("Inst %p: Offset %d, counter %u", inst, inst->cli.state.offset,
inst->cli.state.change_counter); inst->cli.state.change_counter);
if (inst->cli.cb && inst->cli.cb->state) { if (inst->cli.cb && inst->cli.cb->state) {
inst->cli.cb->state(inst, 0, inst->cli.state.offset); inst->cli.cb->state(inst, 0, inst->cli.state.offset);
} }
} else { } else {
BT_DBG("Invalid state length %u", length); LOG_DBG("Invalid state length %u", length);
} }
} else if (handle == inst->cli.desc_handle) { } else if (handle == inst->cli.desc_handle) {
char desc[MIN(BT_L2CAP_RX_MTU, BT_ATT_MAX_ATTRIBUTE_LEN) + 1]; char desc[MIN(BT_L2CAP_RX_MTU, BT_ATT_MAX_ATTRIBUTE_LEN) + 1];
@ -83,26 +83,26 @@ uint8_t vocs_client_notify_handler(struct bt_conn *conn, struct bt_gatt_subscrib
/* Truncate if too large */ /* Truncate if too large */
if (length > sizeof(desc) - 1) { if (length > sizeof(desc) - 1) {
BT_DBG("Description truncated from %u to %zu octets", LOG_DBG("Description truncated from %u to %zu octets", length,
length, sizeof(desc) - 1); sizeof(desc) - 1);
} }
length = MIN(sizeof(desc) - 1, length); length = MIN(sizeof(desc) - 1, length);
memcpy(desc, data, length); memcpy(desc, data, length);
desc[length] = '\0'; desc[length] = '\0';
BT_DBG("Inst %p: Output description: %s", inst, desc); LOG_DBG("Inst %p: Output description: %s", inst, desc);
if (inst->cli.cb && inst->cli.cb->description) { if (inst->cli.cb && inst->cli.cb->description) {
inst->cli.cb->description(inst, 0, desc); inst->cli.cb->description(inst, 0, desc);
} }
} else if (handle == inst->cli.location_handle) { } else if (handle == inst->cli.location_handle) {
if (length == sizeof(inst->cli.location)) { if (length == sizeof(inst->cli.location)) {
memcpy(&inst->cli.location, data, length); memcpy(&inst->cli.location, data, length);
BT_DBG("Inst %p: Location %u", inst, inst->cli.location); LOG_DBG("Inst %p: Location %u", inst, inst->cli.location);
if (inst->cli.cb && inst->cli.cb->location) { if (inst->cli.cb && inst->cli.cb->location) {
inst->cli.cb->location(inst, 0, inst->cli.location); inst->cli.cb->location(inst, 0, inst->cli.location);
} }
} else { } else {
BT_DBG("Invalid location length %u", length); LOG_DBG("Invalid location length %u", length);
} }
} }
@ -119,26 +119,27 @@ static uint8_t vocs_client_read_offset_state_cb(struct bt_conn *conn, uint8_t er
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("Inst %p: err: 0x%02X", inst, err); LOG_DBG("Inst %p: err: 0x%02X", inst, err);
inst->cli.busy = false; inst->cli.busy = false;
if (cb_err) { if (cb_err) {
BT_DBG("Offset state read failed: %d", err); LOG_DBG("Offset state read failed: %d", err);
} else if (data) { } else if (data) {
if (length == sizeof(inst->cli.state)) { if (length == sizeof(inst->cli.state)) {
memcpy(&inst->cli.state, data, length); memcpy(&inst->cli.state, data, length);
BT_DBG("Offset %d, counter %u", LOG_DBG("Offset %d, counter %u", inst->cli.state.offset,
inst->cli.state.offset, inst->cli.state.change_counter); inst->cli.state.change_counter);
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", length, sizeof(inst->cli.state)); LOG_DBG("Invalid length %u (expected %zu)", length,
sizeof(inst->cli.state));
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} else { } else {
BT_DBG("Invalid state"); LOG_DBG("Invalid state");
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
@ -160,26 +161,26 @@ static uint8_t vocs_client_read_location_cb(struct bt_conn *conn, uint8_t err,
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("Inst %p: err: 0x%02X", inst, err); LOG_DBG("Inst %p: err: 0x%02X", inst, err);
inst->cli.busy = false; inst->cli.busy = false;
if (cb_err) { if (cb_err) {
BT_DBG("Offset state read failed: %d", err); LOG_DBG("Offset state read failed: %d", err);
} else if (data) { } else if (data) {
if (length == sizeof(inst->cli.location)) { if (length == sizeof(inst->cli.location)) {
memcpy(&inst->cli.location, data, length); memcpy(&inst->cli.location, data, length);
BT_DBG("Location %u", inst->cli.location); LOG_DBG("Location %u", inst->cli.location);
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", LOG_DBG("Invalid length %u (expected %zu)", length,
length, sizeof(inst->cli.location)); sizeof(inst->cli.location));
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN; cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
} }
} else { } else {
BT_DBG("Invalid location"); LOG_DBG("Invalid location");
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
@ -201,21 +202,20 @@ static uint8_t internal_read_volume_offset_state_cb(struct bt_conn *conn, uint8_
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_ERR("Instance not found"); LOG_ERR("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
if (err) { if (err) {
BT_WARN("Volume offset state read failed: %d", err); LOG_WRN("Volume offset state read failed: %d", err);
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} else if (data) { } else if (data) {
if (length == sizeof(inst->cli.state)) { if (length == sizeof(inst->cli.state)) {
int write_err; int write_err;
memcpy(&inst->cli.state, data, length); memcpy(&inst->cli.state, data, length);
BT_DBG("Offset %d, counter %u", LOG_DBG("Offset %d, counter %u", inst->cli.state.offset,
inst->cli.state.offset, inst->cli.state.change_counter);
inst->cli.state.change_counter);
/* clear busy flag to reuse function */ /* clear busy flag to reuse function */
inst->cli.busy = false; inst->cli.busy = false;
@ -224,11 +224,12 @@ static uint8_t internal_read_volume_offset_state_cb(struct bt_conn *conn, uint8_
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
} else { } else {
BT_DBG("Invalid length %u (expected %zu)", length, sizeof(inst->cli.state)); LOG_DBG("Invalid length %u (expected %zu)", length,
sizeof(inst->cli.state));
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
} else { } else {
BT_DBG("Invalid (empty) offset state read"); LOG_DBG("Invalid (empty) offset state read");
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} }
@ -252,11 +253,11 @@ static void vcs_client_write_vocs_cp_cb(struct bt_conn *conn, uint8_t err,
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return; return;
} }
BT_DBG("Inst %p: err: 0x%02X", inst, err); LOG_DBG("Inst %p: err: 0x%02X", inst, err);
/* If the change counter is out of data when a write was attempted from the application, /* If the change counter is out of data when a write was attempted from the application,
* we automatically initiate a read to get the newest state and try again. Once the * we automatically initiate a read to get the newest state and try again. Once the
@ -266,7 +267,7 @@ static void vcs_client_write_vocs_cp_cb(struct bt_conn *conn, uint8_t err,
if (cb_err == BT_VOCS_ERR_INVALID_COUNTER && inst->cli.cp_retried) { if (cb_err == BT_VOCS_ERR_INVALID_COUNTER && inst->cli.cp_retried) {
cb_err = BT_ATT_ERR_UNLIKELY; cb_err = BT_ATT_ERR_UNLIKELY;
} else if (cb_err == BT_VOCS_ERR_INVALID_COUNTER && inst->cli.state_handle) { } else if (cb_err == BT_VOCS_ERR_INVALID_COUNTER && inst->cli.state_handle) {
BT_DBG("Invalid change counter. Reading volume offset state from server."); LOG_DBG("Invalid change counter. Reading volume offset state from server.");
inst->cli.read_params.func = internal_read_volume_offset_state_cb; inst->cli.read_params.func = internal_read_volume_offset_state_cb;
inst->cli.read_params.handle_count = 1; inst->cli.read_params.handle_count = 1;
@ -274,7 +275,7 @@ static void vcs_client_write_vocs_cp_cb(struct bt_conn *conn, uint8_t err,
cb_err = bt_gatt_read(conn, &inst->cli.read_params); cb_err = bt_gatt_read(conn, &inst->cli.read_params);
if (cb_err) { if (cb_err) {
BT_WARN("Could not read Volume offset state: %d", cb_err); LOG_WRN("Could not read Volume offset state: %d", cb_err);
} else { } else {
inst->cli.cp_retried = true; inst->cli.cp_retried = true;
/* Wait for read callback */ /* Wait for read callback */
@ -301,22 +302,22 @@ static uint8_t vcs_client_read_output_desc_cb(struct bt_conn *conn, uint8_t err,
memset(params, 0, sizeof(*params)); memset(params, 0, sizeof(*params));
if (!inst) { if (!inst) {
BT_DBG("Instance not found"); LOG_DBG("Instance not found");
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("Inst %p: err: 0x%02X", inst, err); LOG_DBG("Inst %p: err: 0x%02X", inst, err);
inst->cli.busy = false; inst->cli.busy = false;
if (cb_err) { if (cb_err) {
BT_DBG("Description read failed: %d", err); LOG_DBG("Description read failed: %d", err);
} else { } else {
if (data) { if (data) {
LOG_HEXDUMP_DBG(data, length, "Output description read"); LOG_HEXDUMP_DBG(data, length, "Output description read");
if (length > sizeof(desc) - 1) { if (length > sizeof(desc) - 1) {
BT_DBG("Description truncated from %u to %zu octets", LOG_DBG("Description truncated from %u to %zu octets", length,
length, sizeof(desc) - 1); sizeof(desc) - 1);
} }
length = MIN(sizeof(desc) - 1, length); length = MIN(sizeof(desc) - 1, length);
@ -324,7 +325,7 @@ static uint8_t vcs_client_read_output_desc_cb(struct bt_conn *conn, uint8_t err,
memcpy(desc, data, length); memcpy(desc, data, length);
} }
desc[length] = '\0'; desc[length] = '\0';
BT_DBG("Output description: %s", desc); LOG_DBG("Output description: %s", desc);
} }
if (inst->cli.cb && inst->cli.cb->description) { if (inst->cli.cb && inst->cli.cb->description) {
@ -351,7 +352,7 @@ static uint8_t vocs_discover_func(struct bt_conn *conn, const struct bt_gatt_att
struct bt_vocs *inst = CONTAINER_OF(client_inst, struct bt_vocs, cli); struct bt_vocs *inst = CONTAINER_OF(client_inst, struct bt_vocs, cli);
if (!attr) { if (!attr) {
BT_DBG("Discovery complete for VOCS %p", inst); LOG_DBG("Discovery complete for VOCS %p", inst);
inst->cli.busy = false; inst->cli.busy = false;
(void)memset(params, 0, sizeof(*params)); (void)memset(params, 0, sizeof(*params));
@ -364,7 +365,7 @@ static uint8_t vocs_discover_func(struct bt_conn *conn, const struct bt_gatt_att
return BT_GATT_ITER_STOP; return BT_GATT_ITER_STOP;
} }
BT_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle); LOG_DBG("[ATTRIBUTE] handle 0x%04X", attr->handle);
if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) {
struct bt_gatt_subscribe_params *sub_params = NULL; struct bt_gatt_subscribe_params *sub_params = NULL;
@ -377,11 +378,11 @@ static uint8_t vocs_discover_func(struct bt_conn *conn, const struct bt_gatt_att
inst->cli.end_handle = chrc->value_handle; inst->cli.end_handle = chrc->value_handle;
if (!bt_uuid_cmp(chrc->uuid, BT_UUID_VOCS_STATE)) { if (!bt_uuid_cmp(chrc->uuid, BT_UUID_VOCS_STATE)) {
BT_DBG("Volume offset state"); LOG_DBG("Volume offset state");
inst->cli.state_handle = chrc->value_handle; inst->cli.state_handle = chrc->value_handle;
sub_params = &inst->cli.state_sub_params; sub_params = &inst->cli.state_sub_params;
} else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_VOCS_LOCATION)) { } else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_VOCS_LOCATION)) {
BT_DBG("Location"); LOG_DBG("Location");
inst->cli.location_handle = chrc->value_handle; inst->cli.location_handle = chrc->value_handle;
if (chrc->properties & BT_GATT_CHRC_NOTIFY) { if (chrc->properties & BT_GATT_CHRC_NOTIFY) {
sub_params = &inst->cli.location_sub_params; sub_params = &inst->cli.location_sub_params;
@ -390,10 +391,10 @@ static uint8_t vocs_discover_func(struct bt_conn *conn, const struct bt_gatt_att
inst->cli.location_writable = true; inst->cli.location_writable = true;
} }
} else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_VOCS_CONTROL)) { } else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_VOCS_CONTROL)) {
BT_DBG("Control point"); LOG_DBG("Control point");
inst->cli.control_handle = chrc->value_handle; inst->cli.control_handle = chrc->value_handle;
} else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_VOCS_DESCRIPTION)) { } else if (!bt_uuid_cmp(chrc->uuid, BT_UUID_VOCS_DESCRIPTION)) {
BT_DBG("Description"); LOG_DBG("Description");
inst->cli.desc_handle = chrc->value_handle; inst->cli.desc_handle = chrc->value_handle;
if (chrc->properties & BT_GATT_CHRC_NOTIFY) { if (chrc->properties & BT_GATT_CHRC_NOTIFY) {
sub_params = &inst->cli.desc_sub_params; sub_params = &inst->cli.desc_sub_params;
@ -416,8 +417,7 @@ static uint8_t vocs_discover_func(struct bt_conn *conn, const struct bt_gatt_att
sub_params->notify = vocs_client_notify_handler; sub_params->notify = vocs_client_notify_handler;
err = bt_gatt_subscribe(conn, sub_params); err = bt_gatt_subscribe(conn, sub_params);
if (err) { if (err) {
BT_WARN("Could not subscribe to handle %u", LOG_WRN("Could not subscribe to handle %u", sub_params->ccc_handle);
sub_params->ccc_handle);
} }
} }
} }
@ -430,22 +430,22 @@ int bt_vocs_client_state_get(struct bt_vocs *inst)
int err; int err;
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.state_handle) { if (!inst->cli.state_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} }
if (inst->cli.busy) { if (inst->cli.busy) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EBUSY; return -EBUSY;
} }
@ -466,22 +466,22 @@ int bt_vocs_client_location_set(struct bt_vocs *inst, uint32_t location)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.location_handle) { if (!inst->cli.location_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
} else if (!inst->cli.location_writable) { } else if (!inst->cli.location_writable) {
BT_DBG("Location is not writable on peer service instance"); LOG_DBG("Location is not writable on peer service instance");
return -EPERM; return -EPERM;
} }
@ -496,17 +496,17 @@ int bt_vocs_client_location_get(struct bt_vocs *inst)
int err; int err;
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.location_handle) { if (!inst->cli.location_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
@ -530,17 +530,17 @@ int bt_vocs_client_state_set(struct bt_vocs *inst, int16_t offset)
int err; int err;
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.control_handle) { if (!inst->cli.control_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
@ -569,17 +569,17 @@ int bt_vocs_client_description_get(struct bt_vocs *inst)
int err; int err;
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.desc_handle) { if (!inst->cli.desc_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
@ -602,22 +602,22 @@ int bt_vocs_client_description_set(struct bt_vocs *inst,
const char *description) const char *description)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("NULL instance"); LOG_DBG("NULL instance");
return -EINVAL; return -EINVAL;
} }
CHECKIF(inst->cli.conn == NULL) { CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn"); LOG_DBG("NULL conn");
return -EINVAL; return -EINVAL;
} }
if (!inst->cli.desc_handle) { if (!inst->cli.desc_handle) {
BT_DBG("Handle not set"); LOG_DBG("Handle not set");
return -EINVAL; return -EINVAL;
} else if (inst->cli.busy) { } else if (inst->cli.busy) {
return -EBUSY; return -EBUSY;
} else if (!inst->cli.desc_writable) { } else if (!inst->cli.desc_writable) {
BT_DBG("Description is not writable on peer service instance"); LOG_DBG("Description is not writable on peer service instance");
return -EPERM; return -EPERM;
} }
@ -643,17 +643,17 @@ struct bt_vocs *bt_vocs_client_free_instance_get(void)
int bt_vocs_client_conn_get(const struct bt_vocs *vocs, struct bt_conn **conn) int bt_vocs_client_conn_get(const struct bt_vocs *vocs, struct bt_conn **conn)
{ {
CHECKIF(vocs == NULL) { CHECKIF(vocs == NULL) {
BT_DBG("NULL vocs pointer"); LOG_DBG("NULL vocs pointer");
return -EINVAL; return -EINVAL;
} }
if (!vocs->client_instance) { if (!vocs->client_instance) {
BT_DBG("vocs pointer shall be client instance"); LOG_DBG("vocs pointer shall be client instance");
return -EINVAL; return -EINVAL;
} }
if (vocs->cli.conn == NULL) { if (vocs->cli.conn == NULL) {
BT_DBG("vocs pointer not associated with a connection. " LOG_DBG("vocs pointer not associated with a connection. "
"Do discovery first"); "Do discovery first");
return -ENOTCONN; return -ENOTCONN;
} }
@ -699,24 +699,25 @@ int bt_vocs_discover(struct bt_conn *conn, struct bt_vocs *inst,
int err = 0; int err = 0;
CHECKIF(!inst || !conn || !param) { CHECKIF(!inst || !conn || !param) {
BT_DBG("%s cannot be NULL", LOG_DBG("%s cannot be NULL", inst == NULL ? "inst"
inst == NULL ? "inst" : conn == NULL ? "conn" : "param"); : conn == NULL ? "conn"
: "param");
return -EINVAL; return -EINVAL;
} }
CHECKIF(param->end_handle < param->start_handle) { CHECKIF(param->end_handle < param->start_handle) {
BT_DBG("start_handle (%u) shall be less than end_handle (%u)", LOG_DBG("start_handle (%u) shall be less than end_handle (%u)", param->start_handle,
param->start_handle, param->end_handle); param->end_handle);
return -EINVAL; return -EINVAL;
} }
CHECKIF(!inst->cli.active) { CHECKIF(!inst->cli.active) {
BT_DBG("Inactive instance"); LOG_DBG("Inactive instance");
return -EINVAL; return -EINVAL;
} }
if (inst->cli.busy) { if (inst->cli.busy) {
BT_DBG("Instance is busy"); LOG_DBG("Instance is busy");
return -EBUSY; return -EBUSY;
} }
@ -730,7 +731,7 @@ int bt_vocs_discover(struct bt_conn *conn, struct bt_vocs *inst,
err = bt_gatt_discover(conn, &inst->cli.discover_params); err = bt_gatt_discover(conn, &inst->cli.discover_params);
if (err) { if (err) {
BT_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
} else { } else {
inst->cli.busy = true; inst->cli.busy = true;
} }
@ -741,7 +742,7 @@ int bt_vocs_discover(struct bt_conn *conn, struct bt_vocs *inst,
void bt_vocs_client_cb_register(struct bt_vocs *inst, struct bt_vocs_cb *cb) void bt_vocs_client_cb_register(struct bt_vocs *inst, struct bt_vocs_cb *cb)
{ {
CHECKIF(!inst) { CHECKIF(!inst) {
BT_DBG("inst cannot be NULL"); LOG_DBG("inst cannot be NULL");
return; return;
} }

View file

@ -4,7 +4,6 @@ zephyr_library()
zephyr_library_sources(addr.c) zephyr_library_sources(addr.c)
zephyr_library_sources(dummy.c) zephyr_library_sources(dummy.c)
zephyr_library_sources(log.c)
zephyr_library_sources(bt_str.c) zephyr_library_sources(bt_str.c)
zephyr_library_sources_ifdef(CONFIG_BT_RPA rpa.c) zephyr_library_sources_ifdef(CONFIG_BT_RPA rpa.c)

View file

@ -373,16 +373,28 @@ if BT_DEBUG
config BT_DEBUG_HCI_DRIVER config BT_DEBUG_HCI_DRIVER
bool "Bluetooth HCI driver debug" bool "Bluetooth HCI driver debug"
select DEPRECATED
help help
This option enables debug support for the active This option enables debug support for the active
Bluetooth HCI driver, including the Controller-side HCI layer Bluetooth HCI driver, including the Controller-side HCI layer
when included in the build. when included in the build.
module = BT_HCI_DRIVER
legacy-debug-sym = BT_DEBUG_HCI_DRIVER
module-str = "Bluetooth HCI driver"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
config BT_DEBUG_RPA config BT_DEBUG_RPA
bool "Bluetooth Resolvable Private Address (RPA) debug" bool "Bluetooth Resolvable Private Address (RPA) debug"
select DEPRECATED
depends on BT_RPA depends on BT_RPA
help help
This option enables debug support for the Bluetooth This option enables debug support for the Bluetooth
Resolvable Private Address (RPA) generation and resolution. Resolvable Private Address (RPA) generation and resolution.
module = BT_RPA
legacy-debug-sym = BT_DEBUG_RPA
module-str = "Bluetooth Resolvable Private Address (RPA)"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
endif # BT_DEBUG endif # BT_DEBUG

View file

@ -0,0 +1,17 @@
# Copyright (c) 2022 Nordic Semicoductor ASA
# SPDX-License-Identifier: Apache-2.0
parent-module = BT
choice "$(module)_LOG_LEVEL_CHOICE"
default $(module)_LOG_LEVEL_INHERIT if y
config $(module)_LOG_LEVEL_INHERIT
bool "Inherit $(parent-module)_LOG_LEVEL"
endchoice
config $(module)_LOG_LEVEL
default 4 if $(legacy-debug-sym)
default $(parent-module)_LOG_LEVEL if $(module)_LOG_LEVEL_INHERIT
source "subsys/logging/Kconfig.template.log_config"

View file

@ -1,8 +0,0 @@
/* log.c - logging helpers */
/*
* Copyright (c) 2017 Nordic Semiconductor ASA
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

View file

@ -1,46 +0,0 @@
/** @file
* @brief Bluetooth subsystem logging helpers.
*/
/*
* Copyright (c) 2017 Nordic Semiconductor ASA
* Copyright (c) 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __BT_LOG_H
#define __BT_LOG_H
#include <zephyr/linker/sections.h>
#include <offsets.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/bluetooth/hci.h>
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(BT_DBG_ENABLED)
#define BT_DBG_ENABLED 1
#endif
#if BT_DBG_ENABLED
#define LOG_LEVEL LOG_LEVEL_DBG
#else
#define LOG_LEVEL CONFIG_BT_LOG_LEVEL
#endif
LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL);
#define BT_DBG(fmt, ...) LOG_DBG(fmt, ##__VA_ARGS__)
#define BT_ERR(fmt, ...) LOG_ERR(fmt, ##__VA_ARGS__)
#define BT_WARN(fmt, ...) LOG_WRN(fmt, ##__VA_ARGS__)
#define BT_INFO(fmt, ...) LOG_INF(fmt, ##__VA_ARGS__)
#ifdef __cplusplus
}
#endif
#endif /* __BT_LOG_H */

View file

@ -15,13 +15,14 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_RPA)
#define LOG_MODULE_NAME bt_rpa
#include "common/log.h"
#include "common/bt_str.h" #include "common/bt_str.h"
#include <zephyr/bluetooth/crypto.h> #include <zephyr/bluetooth/crypto.h>
#define LOG_LEVEL CONFIG_BT_RPA_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_rpa);
#if defined(CONFIG_BT_CTLR) && defined(CONFIG_BT_HOST_CRYPTO) #if defined(CONFIG_BT_CTLR) && defined(CONFIG_BT_HOST_CRYPTO)
#include "../controller/util/util.h" #include "../controller/util/util.h"
#include "../controller/hal/ecb.h" #include "../controller/hal/ecb.h"
@ -57,8 +58,8 @@ static int ah(const uint8_t irk[16], const uint8_t r[3], uint8_t out[3])
uint8_t res[16]; uint8_t res[16];
int err; int err;
BT_DBG("irk %s", bt_hex(irk, 16)); LOG_DBG("irk %s", bt_hex(irk, 16));
BT_DBG("r %s", bt_hex(r, 3)); LOG_DBG("r %s", bt_hex(r, 3));
/* r' = padding || r */ /* r' = padding || r */
memcpy(res, r, 3); memcpy(res, r, 3);
@ -86,7 +87,7 @@ bool bt_rpa_irk_matches(const uint8_t irk[16], const bt_addr_t *addr)
uint8_t hash[3]; uint8_t hash[3];
int err; int err;
BT_DBG("IRK %s bdaddr %s", bt_hex(irk, 16), bt_addr_str(addr)); LOG_DBG("IRK %s bdaddr %s", bt_hex(irk, 16), bt_addr_str(addr));
err = ah(irk, addr->val + 3, hash); err = ah(irk, addr->val + 3, hash);
if (err) { if (err) {
@ -114,7 +115,7 @@ int bt_rpa_create(const uint8_t irk[16], bt_addr_t *rpa)
return err; return err;
} }
BT_DBG("Created RPA %s", bt_addr_str((bt_addr_t *)rpa->val)); LOG_DBG("Created RPA %s", bt_addr_str((bt_addr_t *)rpa->val));
return 0; return 0;
} }

View file

@ -4,9 +4,6 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_crypto
#include "common/log.h"
#include "common/bt_str.h" #include "common/bt_str.h"
#include "util/memq.h" #include "util/memq.h"
@ -14,6 +11,10 @@
#include "hal/ecb.h" #include "hal/ecb.h"
#include "lll.h" #include "lll.h"
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_ctlr_crypto);
int bt_rand(void *buf, size_t len) int bt_rand(void *buf, size_t len)
{ {
return lll_csrand_get(buf, len); return lll_csrand_get(buf, len);
@ -22,12 +23,12 @@ int bt_rand(void *buf, size_t len)
int bt_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16], int bt_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16],
uint8_t enc_data[16]) uint8_t enc_data[16])
{ {
BT_DBG("key %s", bt_hex(key, 16)); LOG_DBG("key %s", bt_hex(key, 16));
BT_DBG("plaintext %s", bt_hex(plaintext, 16)); LOG_DBG("plaintext %s", bt_hex(plaintext, 16));
ecb_encrypt(key, plaintext, enc_data, NULL); ecb_encrypt(key, plaintext, enc_data, NULL);
BT_DBG("enc_data %s", bt_hex(enc_data, 16)); LOG_DBG("enc_data %s", bt_hex(enc_data, 16));
return 0; return 0;
} }
@ -35,12 +36,12 @@ int bt_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16],
int bt_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16], int bt_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16],
uint8_t enc_data[16]) uint8_t enc_data[16])
{ {
BT_DBG("key %s", bt_hex(key, 16)); LOG_DBG("key %s", bt_hex(key, 16));
BT_DBG("plaintext %s", bt_hex(plaintext, 16)); LOG_DBG("plaintext %s", bt_hex(plaintext, 16));
ecb_encrypt_be(key, plaintext, enc_data); ecb_encrypt_be(key, plaintext, enc_data);
BT_DBG("enc_data %s", bt_hex(enc_data, 16)); LOG_DBG("enc_data %s", bt_hex(enc_data, 16));
return 0; return 0;
} }

View file

@ -89,12 +89,13 @@
#include "hci_user_ext.h" #include "hci_user_ext.h"
#endif /* CONFIG_BT_CTLR_USER_EXT */ #endif /* CONFIG_BT_CTLR_USER_EXT */
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_hci
#include "common/log.h"
#include "common/bt_str.h" #include "common/bt_str.h"
#include "hal/debug.h" #include "hal/debug.h"
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_ctlr_hci);
#define STR_NULL_TERMINATOR 0x00 #define STR_NULL_TERMINATOR 0x00
/* opcode of the HCI command currently being processed. The opcode is stored /* opcode of the HCI command currently being processed. The opcode is stored
@ -542,7 +543,7 @@ static void host_buffer_size(struct net_buf *buf, struct net_buf **evt)
return; return;
} }
BT_DBG("FC: host buf size: %d", acl_pkts); LOG_DBG("FC: host buf size: %d", acl_pkts);
hci_hbuf_total = -acl_pkts; hci_hbuf_total = -acl_pkts;
} }
@ -580,7 +581,7 @@ static void host_num_completed_packets(struct net_buf *buf,
count += c; count += c;
} }
BT_DBG("FC: acked: %d", count); LOG_DBG("FC: acked: %d", count);
hci_hbuf_acked += count; hci_hbuf_acked += count;
k_poll_signal_raise(hbuf_signal, 0x0); k_poll_signal_raise(hbuf_signal, 0x0);
} }
@ -1576,8 +1577,7 @@ static void le_read_supp_states(struct net_buf *buf, struct net_buf **evt)
* Initiating State + Active Scanning * Initiating State + Active Scanning
*/ */
states &= ~(BIT64(22) | BIT64(23)); states &= ~(BIT64(22) | BIT64(23));
BT_DBG("states: 0x%08x%08x", (uint32_t)(states >> 32), LOG_DBG("states: 0x%08x%08x", (uint32_t)(states >> 32), (uint32_t)(states & 0xffffffff));
(uint32_t)(states & 0xffffffff));
sys_put_le64(states, rp->le_states); sys_put_le64(states, rp->le_states);
} }
@ -5029,7 +5029,7 @@ struct net_buf *hci_vs_err_stack_frame(unsigned int reason, const z_arch_esf_t *
vs_err_fatal_cpu_data_fill( vs_err_fatal_cpu_data_fill(
(bt_hci_vs_fatal_error_cpu_data *)sf->cpu_data, esf); (bt_hci_vs_fatal_error_cpu_data *)sf->cpu_data, esf);
} else { } else {
BT_ERR("Can't create HCI Fatal Error event"); LOG_ERR("Can't create HCI Fatal Error event");
} }
return buf; return buf;
@ -5091,7 +5091,7 @@ static struct net_buf *hci_vs_err_trace_create(uint8_t data_type,
net_buf_add_u8(buf, STR_NULL_TERMINATOR); net_buf_add_u8(buf, STR_NULL_TERMINATOR);
net_buf_add_le32(buf, line); net_buf_add_le32(buf, line);
} else { } else {
BT_ERR("Can't create HCI Fatal Error event"); LOG_ERR("Can't create HCI Fatal Error event");
} }
} }
} }
@ -5408,7 +5408,7 @@ static int mesh_cmd_handle(struct net_buf *cmd, struct net_buf **evt)
uint8_t mesh_op; uint8_t mesh_op;
if (cmd->len < sizeof(*cp_mesh)) { if (cmd->len < sizeof(*cp_mesh)) {
BT_ERR("No HCI VSD Command header"); LOG_ERR("No HCI VSD Command header");
return -EINVAL; return -EINVAL;
} }
@ -5522,13 +5522,13 @@ struct net_buf *hci_cmd_handle(struct net_buf *cmd, void **node_rx)
int err; int err;
if (cmd->len < sizeof(*chdr)) { if (cmd->len < sizeof(*chdr)) {
BT_ERR("No HCI Command header"); LOG_ERR("No HCI Command header");
return NULL; return NULL;
} }
chdr = net_buf_pull_mem(cmd, sizeof(*chdr)); chdr = net_buf_pull_mem(cmd, sizeof(*chdr));
if (cmd->len < chdr->param_len) { if (cmd->len < chdr->param_len) {
BT_ERR("Invalid HCI CMD packet length"); LOG_ERR("Invalid HCI CMD packet length");
return NULL; return NULL;
} }
@ -5603,7 +5603,7 @@ int hci_acl_handle(struct net_buf *buf, struct net_buf **evt)
*evt = NULL; *evt = NULL;
if (buf->len < sizeof(*acl)) { if (buf->len < sizeof(*acl)) {
BT_ERR("No HCI ACL header"); LOG_ERR("No HCI ACL header");
return -EINVAL; return -EINVAL;
} }
@ -5612,12 +5612,12 @@ int hci_acl_handle(struct net_buf *buf, struct net_buf **evt)
handle = sys_le16_to_cpu(acl->handle); handle = sys_le16_to_cpu(acl->handle);
if (buf->len < len) { if (buf->len < len) {
BT_ERR("Invalid HCI ACL packet length"); LOG_ERR("Invalid HCI ACL packet length");
return -EINVAL; return -EINVAL;
} }
if (len > LL_LENGTH_OCTETS_TX_MAX) { if (len > LL_LENGTH_OCTETS_TX_MAX) {
BT_ERR("Invalid HCI ACL Data length"); LOG_ERR("Invalid HCI ACL Data length");
return -EINVAL; return -EINVAL;
} }
@ -5627,7 +5627,7 @@ int hci_acl_handle(struct net_buf *buf, struct net_buf **evt)
node_tx = ll_tx_mem_acquire(); node_tx = ll_tx_mem_acquire();
if (!node_tx) { if (!node_tx) {
BT_ERR("Tx Buffer Overflow"); LOG_ERR("Tx Buffer Overflow");
data_buf_overflow(evt, BT_OVERFLOW_LINK_ACL); data_buf_overflow(evt, BT_OVERFLOW_LINK_ACL);
return -ENOBUFS; return -ENOBUFS;
} }
@ -5656,7 +5656,7 @@ int hci_acl_handle(struct net_buf *buf, struct net_buf **evt)
memcpy(&pdu_data->lldata[0], buf->data, len); memcpy(&pdu_data->lldata[0], buf->data, len);
if (ll_tx_mem_enqueue(handle, node_tx)) { if (ll_tx_mem_enqueue(handle, node_tx)) {
BT_ERR("Invalid Tx Enqueue"); LOG_ERR("Invalid Tx Enqueue");
ll_tx_mem_release(node_tx); ll_tx_mem_release(node_tx);
return -EINVAL; return -EINVAL;
} }
@ -5686,7 +5686,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
dp_in = NULL; dp_in = NULL;
if (buf->len < sizeof(*iso_hdr)) { if (buf->len < sizeof(*iso_hdr)) {
BT_ERR("No HCI ISO header"); LOG_ERR("No HCI ISO header");
return -EINVAL; return -EINVAL;
} }
@ -5695,7 +5695,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
len = sys_le16_to_cpu(iso_hdr->len); len = sys_le16_to_cpu(iso_hdr->len);
if (buf->len < len) { if (buf->len < len) {
BT_ERR("Invalid HCI ISO packet length"); LOG_ERR("Invalid HCI ISO packet length");
return -EINVAL; return -EINVAL;
} }
@ -5786,7 +5786,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
/* Get controller's input data path for CIS */ /* Get controller's input data path for CIS */
dp_in = hdr->datapath_in; dp_in = hdr->datapath_in;
if (!dp_in || dp_in->path_id != BT_HCI_DATAPATH_ID_HCI) { if (!dp_in || dp_in->path_id != BT_HCI_DATAPATH_ID_HCI) {
BT_ERR("Input data path not set for HCI"); LOG_ERR("Input data path not set for HCI");
return -EINVAL; return -EINVAL;
} }
@ -5815,7 +5815,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
/* Check invalid BIS PDU length */ /* Check invalid BIS PDU length */
if (slen > LL_BIS_OCTETS_TX_MAX) { if (slen > LL_BIS_OCTETS_TX_MAX) {
BT_ERR("Invalid HCI ISO Data length"); LOG_ERR("Invalid HCI ISO Data length");
return -EINVAL; return -EINVAL;
} }
@ -5830,7 +5830,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
stream = ull_adv_iso_stream_get(stream_handle); stream = ull_adv_iso_stream_get(stream_handle);
if (!stream) { if (!stream) {
BT_ERR("Invalid BIS stream"); LOG_ERR("Invalid BIS stream");
return -EINVAL; return -EINVAL;
} }
@ -5838,14 +5838,14 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
adv_iso = ull_adv_iso_by_stream_get(stream_handle); adv_iso = ull_adv_iso_by_stream_get(stream_handle);
if (!adv_iso) { if (!adv_iso) {
BT_ERR("No BIG associated with stream handle"); LOG_ERR("No BIG associated with stream handle");
return -EINVAL; return -EINVAL;
} }
/* Get free node tx */ /* Get free node tx */
tx = ll_iso_tx_mem_acquire(); tx = ll_iso_tx_mem_acquire();
if (!tx) { if (!tx) {
BT_ERR("ISO Tx Buffer Overflow"); LOG_ERR("ISO Tx Buffer Overflow");
data_buf_overflow(evt, BT_OVERFLOW_LINK_ISO); data_buf_overflow(evt, BT_OVERFLOW_LINK_ISO);
return -ENOBUFS; return -ENOBUFS;
} }
@ -5884,7 +5884,7 @@ int hci_iso_handle(struct net_buf *buf, struct net_buf **evt)
stream->pkt_seq_num++; stream->pkt_seq_num++;
if (ll_iso_tx_mem_enqueue(handle, tx, NULL)) { if (ll_iso_tx_mem_enqueue(handle, tx, NULL)) {
BT_ERR("Invalid ISO Tx Enqueue"); LOG_ERR("Invalid ISO Tx Enqueue");
ll_iso_tx_mem_release(tx); ll_iso_tx_mem_release(tx);
return -EINVAL; return -EINVAL;
} }
@ -6824,7 +6824,7 @@ static void le_ext_adv_report(struct pdu_data *pdu_data,
/* The Link Layer currently returns RSSI as an absolute value */ /* The Link Layer currently returns RSSI as an absolute value */
rssi = -(node_rx_curr->hdr.rx_ftr.rssi); rssi = -(node_rx_curr->hdr.rx_ftr.rssi);
BT_DBG("phy= 0x%x, type= 0x%x, len= %u, tat= %u, rat= %u," LOG_DBG("phy= 0x%x, type= 0x%x, len= %u, tat= %u, rat= %u,"
" rssi=%d dB", phy, adv->type, adv->len, adv->tx_addr, " rssi=%d dB", phy, adv->type, adv->len, adv->tx_addr,
adv->rx_addr, rssi); adv->rx_addr, rssi);
@ -6832,8 +6832,7 @@ static void le_ext_adv_report(struct pdu_data *pdu_data,
h = (void *)p->ext_hdr_adv_data; h = (void *)p->ext_hdr_adv_data;
ptr = (void *)h; ptr = (void *)h;
BT_DBG(" Ext. adv mode= 0x%x, hdr len= %u", p->adv_mode, LOG_DBG(" Ext. adv mode= 0x%x, hdr len= %u", p->adv_mode, p->ext_hdr_len);
p->ext_hdr_len);
evt_type_curr = p->adv_mode; evt_type_curr = p->adv_mode;
@ -6855,7 +6854,7 @@ static void le_ext_adv_report(struct pdu_data *pdu_data,
(void)memcpy(addr.a.val, ptr, sizeof(bt_addr_t)); (void)memcpy(addr.a.val, ptr, sizeof(bt_addr_t));
ptr += BDADDR_SIZE; ptr += BDADDR_SIZE;
BT_DBG(" AdvA: %s", bt_addr_le_str(&addr)); LOG_DBG(" AdvA: %s", bt_addr_le_str(&addr));
} }
if (h->tgt_addr) { if (h->tgt_addr) {
@ -6885,7 +6884,7 @@ static void le_ext_adv_report(struct pdu_data *pdu_data,
(void)memcpy(addr.a.val, direct_addr_curr, (void)memcpy(addr.a.val, direct_addr_curr,
sizeof(bt_addr_t)); sizeof(bt_addr_t));
BT_DBG(" TgtA: %s", bt_addr_le_str(&addr)); LOG_DBG(" TgtA: %s", bt_addr_le_str(&addr));
} }
if (h->adi) { if (h->adi) {
@ -6893,8 +6892,8 @@ static void le_ext_adv_report(struct pdu_data *pdu_data,
ptr += sizeof(*adi); ptr += sizeof(*adi);
BT_DBG(" AdvDataInfo DID = 0x%x, SID = 0x%x", LOG_DBG(" AdvDataInfo DID = 0x%x, SID = 0x%x", adi_curr->did,
adi_curr->did, adi_curr->sid); adi_curr->sid);
} }
if (h->aux_ptr) { if (h->aux_ptr) {
@ -6916,7 +6915,7 @@ static void le_ext_adv_report(struct pdu_data *pdu_data,
aux_phy = BIT(PDU_ADV_AUX_PTR_PHY_GET(aux_ptr)); aux_phy = BIT(PDU_ADV_AUX_PTR_PHY_GET(aux_ptr));
BT_DBG(" AuxPtr chan_idx = %u, ca = %u, offs_units " LOG_DBG(" AuxPtr chan_idx = %u, ca = %u, offs_units "
"= %u offs = 0x%x, phy = 0x%x", "= %u offs = 0x%x, phy = 0x%x",
aux_ptr->chan_idx, aux_ptr->ca, aux_ptr->chan_idx, aux_ptr->ca,
aux_ptr->offs_units, PDU_ADV_AUX_PTR_OFFSET_GET(aux_ptr), aux_phy); aux_ptr->offs_units, PDU_ADV_AUX_PTR_OFFSET_GET(aux_ptr), aux_phy);
@ -6930,7 +6929,7 @@ static void le_ext_adv_report(struct pdu_data *pdu_data,
interval_le16 = si->interval; interval_le16 = si->interval;
BT_DBG(" SyncInfo offs = %u, offs_unit = 0x%x, " LOG_DBG(" SyncInfo offs = %u, offs_unit = 0x%x, "
"interval = 0x%x, sca = 0x%x, " "interval = 0x%x, sca = 0x%x, "
"chan map = 0x%x 0x%x 0x%x 0x%x 0x%x, " "chan map = 0x%x 0x%x 0x%x 0x%x 0x%x, "
"AA = 0x%x, CRC = 0x%x 0x%x 0x%x, " "AA = 0x%x, CRC = 0x%x 0x%x 0x%x, "
@ -6954,14 +6953,13 @@ static void le_ext_adv_report(struct pdu_data *pdu_data,
tx_pwr_curr = *(int8_t *)ptr; tx_pwr_curr = *(int8_t *)ptr;
ptr++; ptr++;
BT_DBG(" Tx pwr= %d dB", tx_pwr_curr); LOG_DBG(" Tx pwr= %d dB", tx_pwr_curr);
} }
hdr_len = ptr - (uint8_t *)p; hdr_len = ptr - (uint8_t *)p;
hdr_buf_len = PDU_AC_EXT_HEADER_SIZE_MIN + p->ext_hdr_len; hdr_buf_len = PDU_AC_EXT_HEADER_SIZE_MIN + p->ext_hdr_len;
if (hdr_len > hdr_buf_len) { if (hdr_len > hdr_buf_len) {
BT_WARN(" Header length %u/%u, INVALID.", hdr_len, LOG_WRN(" Header length %u/%u, INVALID.", hdr_len, p->ext_hdr_len);
p->ext_hdr_len);
} else { } else {
uint8_t acad_len = hdr_buf_len - hdr_len; uint8_t acad_len = hdr_buf_len - hdr_len;
@ -6976,7 +6974,7 @@ no_ext_hdr:
data_len_curr = adv->len - hdr_len; data_len_curr = adv->len - hdr_len;
data_curr = ptr; data_curr = ptr;
BT_DBG(" AD Data (%u): <todo>", data_len); LOG_DBG(" AD Data (%u): <todo>", data_len);
} }
if (node_rx_curr == node_rx) { if (node_rx_curr == node_rx) {
@ -7378,14 +7376,13 @@ static void le_per_adv_sync_report(struct pdu_data *pdu_data,
/* The Link Layer currently returns RSSI as an absolute value */ /* The Link Layer currently returns RSSI as an absolute value */
rssi = -(node_rx->hdr.rx_ftr.rssi); rssi = -(node_rx->hdr.rx_ftr.rssi);
BT_DBG("len = %u, rssi = %d", adv->len, rssi); LOG_DBG("len = %u, rssi = %d", adv->len, rssi);
p = (void *)&adv->adv_ext_ind; p = (void *)&adv->adv_ext_ind;
h = (void *)p->ext_hdr_adv_data; h = (void *)p->ext_hdr_adv_data;
ptr = (void *)h; ptr = (void *)h;
BT_DBG(" Per. adv mode= 0x%x, hdr len= %u", p->adv_mode, LOG_DBG(" Per. adv mode= 0x%x, hdr len= %u", p->adv_mode, p->ext_hdr_len);
p->ext_hdr_len);
if (!p->ext_hdr_len) { if (!p->ext_hdr_len) {
hdr_len = PDU_AC_EXT_HEADER_SIZE_MIN; hdr_len = PDU_AC_EXT_HEADER_SIZE_MIN;
@ -7410,7 +7407,7 @@ static void le_per_adv_sync_report(struct pdu_data *pdu_data,
cte_type = cte_info->type; cte_type = cte_info->type;
ptr++; ptr++;
BT_DBG(" CTE type= %d", cte_type); LOG_DBG(" CTE type= %d", cte_type);
} }
if (h->adi) { if (h->adi) {
@ -7432,7 +7429,7 @@ static void le_per_adv_sync_report(struct pdu_data *pdu_data,
aux_phy = BIT(PDU_ADV_AUX_PTR_PHY_GET(aux_ptr)); aux_phy = BIT(PDU_ADV_AUX_PTR_PHY_GET(aux_ptr));
BT_DBG(" AuxPtr chan_idx = %u, ca = %u, offs_units " LOG_DBG(" AuxPtr chan_idx = %u, ca = %u, offs_units "
"= %u offs = 0x%x, phy = 0x%x", "= %u offs = 0x%x, phy = 0x%x",
aux_ptr->chan_idx, aux_ptr->ca, aux_ptr->chan_idx, aux_ptr->ca,
aux_ptr->offs_units, PDU_ADV_AUX_PTR_OFFSET_GET(aux_ptr), aux_phy); aux_ptr->offs_units, PDU_ADV_AUX_PTR_OFFSET_GET(aux_ptr), aux_phy);
@ -7448,14 +7445,13 @@ static void le_per_adv_sync_report(struct pdu_data *pdu_data,
tx_pwr = *(int8_t *)ptr; tx_pwr = *(int8_t *)ptr;
ptr++; ptr++;
BT_DBG(" Tx pwr= %d dB", tx_pwr); LOG_DBG(" Tx pwr= %d dB", tx_pwr);
} }
hdr_len = ptr - (uint8_t *)p; hdr_len = ptr - (uint8_t *)p;
hdr_buf_len = PDU_AC_EXT_HEADER_SIZE_MIN + p->ext_hdr_len; hdr_buf_len = PDU_AC_EXT_HEADER_SIZE_MIN + p->ext_hdr_len;
if (hdr_len > hdr_buf_len) { if (hdr_len > hdr_buf_len) {
BT_WARN(" Header length %u/%u, INVALID.", hdr_len, LOG_WRN(" Header length %u/%u, INVALID.", hdr_len, p->ext_hdr_len);
p->ext_hdr_len);
} else { } else {
acad_len = hdr_buf_len - hdr_len; acad_len = hdr_buf_len - hdr_len;
if (acad_len) { if (acad_len) {
@ -7471,7 +7467,7 @@ no_ext_hdr:
data_len = adv->len - hdr_len; data_len = adv->len - hdr_len;
data = ptr; data = ptr;
BT_DBG(" AD Data (%u): <todo>", data_len); LOG_DBG(" AD Data (%u): <todo>", data_len);
} }
if (0) { if (0) {
@ -7846,8 +7842,7 @@ static void le_scan_req_received(struct pdu_data *pdu_data,
/* The Link Layer currently returns RSSI as an absolute value */ /* The Link Layer currently returns RSSI as an absolute value */
rssi = -(node_rx->hdr.rx_ftr.rssi); rssi = -(node_rx->hdr.rx_ftr.rssi);
BT_DBG("handle: %d, addr: %s, rssi: %d dB.", LOG_DBG("handle: %d, addr: %s, rssi: %d dB.", handle, bt_addr_le_str(&addr), rssi);
handle, bt_addr_le_str(&addr), rssi);
return; return;
} }
@ -8080,7 +8075,7 @@ static void le_chan_sel_algo(struct pdu_data *pdu_data, uint16_t handle,
if (!(event_mask & BT_EVT_MASK_LE_META_EVENT) || if (!(event_mask & BT_EVT_MASK_LE_META_EVENT) ||
!(le_event_mask & BT_EVT_MASK_LE_CHAN_SEL_ALGO)) { !(le_event_mask & BT_EVT_MASK_LE_CHAN_SEL_ALGO)) {
BT_DBG("handle: 0x%04x, CSA: %x.", handle, cs->csa); LOG_DBG("handle: 0x%04x, CSA: %x.", handle, cs->csa);
return; return;
} }
@ -8102,10 +8097,8 @@ static void le_phy_upd_complete(struct pdu_data *pdu_data, uint16_t handle,
if (!(event_mask & BT_EVT_MASK_LE_META_EVENT) || if (!(event_mask & BT_EVT_MASK_LE_META_EVENT) ||
!(le_event_mask & BT_EVT_MASK_LE_PHY_UPDATE_COMPLETE)) { !(le_event_mask & BT_EVT_MASK_LE_PHY_UPDATE_COMPLETE)) {
BT_WARN("handle: 0x%04x, status: %x, tx: %x, rx: %x.", handle, LOG_WRN("handle: 0x%04x, status: %x, tx: %x, rx: %x.", handle, pu->status,
pu->status, find_lsb_set(pu->tx), find_lsb_set(pu->rx));
find_lsb_set(pu->tx),
find_lsb_set(pu->rx));
return; return;
} }
@ -8129,7 +8122,7 @@ static void le_req_peer_sca_complete(struct pdu_data *pdu, uint16_t handle,
if (!(event_mask & BT_EVT_MASK_LE_META_EVENT) || if (!(event_mask & BT_EVT_MASK_LE_META_EVENT) ||
!(le_event_mask & BT_EVT_MASK_LE_REQ_PEER_SCA_COMPLETE)) { !(le_event_mask & BT_EVT_MASK_LE_REQ_PEER_SCA_COMPLETE)) {
BT_WARN("handle: 0x%04x, status: %x, sca: %x.", handle, LOG_WRN("handle: 0x%04x, status: %x, sca: %x.", handle,
scau->status, scau->status,
scau->sca); scau->sca);
return; return;
@ -8292,8 +8285,7 @@ static void encode_control(struct node_rx_pdu *node_rx,
#if defined(CONFIG_BT_CTLR_CONN_RSSI_EVENT) #if defined(CONFIG_BT_CTLR_CONN_RSSI_EVENT)
case NODE_RX_TYPE_RSSI: case NODE_RX_TYPE_RSSI:
BT_INFO("handle: 0x%04x, rssi: -%d dB.", handle, LOG_INF("handle: 0x%04x, rssi: -%d dB.", handle, pdu_data->rssi);
pdu_data->rssi);
return; return;
#endif /* CONFIG_BT_CTLR_CONN_RSSI_EVENT */ #endif /* CONFIG_BT_CTLR_CONN_RSSI_EVENT */
@ -8328,28 +8320,22 @@ static void encode_control(struct node_rx_pdu *node_rx,
#if defined(CONFIG_BT_CTLR_ADV_INDICATION) #if defined(CONFIG_BT_CTLR_ADV_INDICATION)
case NODE_RX_TYPE_ADV_INDICATION: case NODE_RX_TYPE_ADV_INDICATION:
BT_INFO("Advertised."); LOG_INF("Advertised.");
return; return;
#endif /* CONFIG_BT_CTLR_ADV_INDICATION */ #endif /* CONFIG_BT_CTLR_ADV_INDICATION */
#if defined(CONFIG_BT_CTLR_SCAN_INDICATION) #if defined(CONFIG_BT_CTLR_SCAN_INDICATION)
case NODE_RX_TYPE_SCAN_INDICATION: case NODE_RX_TYPE_SCAN_INDICATION:
BT_INFO("Scanned."); LOG_INF("Scanned.");
return; return;
#endif /* CONFIG_BT_CTLR_SCAN_INDICATION */ #endif /* CONFIG_BT_CTLR_SCAN_INDICATION */
#if defined(CONFIG_BT_CTLR_PROFILE_ISR) #if defined(CONFIG_BT_CTLR_PROFILE_ISR)
case NODE_RX_TYPE_PROFILE: case NODE_RX_TYPE_PROFILE:
BT_INFO("l: %u, %u, %u; t: %u, %u, %u; cpu: %u, %u, %u, %u.", LOG_INF("l: %u, %u, %u; t: %u, %u, %u; cpu: %u, %u, %u, %u.",
pdu_data->profile.lcur, pdu_data->profile.lcur, pdu_data->profile.lmin, pdu_data->profile.lmax,
pdu_data->profile.lmin, pdu_data->profile.cur, pdu_data->profile.min, pdu_data->profile.max,
pdu_data->profile.lmax, pdu_data->profile.radio, pdu_data->profile.lll, pdu_data->profile.ull_high,
pdu_data->profile.cur,
pdu_data->profile.min,
pdu_data->profile.max,
pdu_data->profile.radio,
pdu_data->profile.lll,
pdu_data->profile.ull_high,
pdu_data->profile.ull_low); pdu_data->profile.ull_low);
return; return;
#endif /* CONFIG_BT_CTLR_PROFILE_ISR */ #endif /* CONFIG_BT_CTLR_PROFILE_ISR */
@ -8456,7 +8442,7 @@ static void le_unknown_rsp(struct pdu_data *pdu_data, uint16_t handle,
break; break;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */ #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */
default: default:
BT_WARN("type: 0x%02x", pdu_data->llctrl.unknown_rsp.type); LOG_WRN("type: 0x%02x", pdu_data->llctrl.unknown_rsp.type);
break; break;
} }
} }
@ -8470,7 +8456,7 @@ static void le_reject_ext_ind(struct pdu_data *pdu, uint16_t handle, struct net_
break; break;
#endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */ #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_REQ */
default: default:
BT_WARN("reject opcode: 0x%02x", pdu->llctrl.reject_ext_ind.reject_opcode); LOG_WRN("reject opcode: 0x%02x", pdu->llctrl.reject_ext_ind.reject_opcode);
break; break;
} }
} }

View file

@ -28,9 +28,6 @@
#include <zephyr/drivers/clock_control/nrf_clock_control.h> #include <zephyr/drivers/clock_control/nrf_clock_control.h>
#endif #endif
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_hci_driver
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
#include "util/util.h" #include "util/util.h"
@ -63,6 +60,10 @@
#include "hci_internal.h" #include "hci_internal.h"
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_ctlr_hci_driver);
static struct k_sem sem_prio_recv; static struct k_sem sem_prio_recv;
static struct k_fifo recv_fifo; static struct k_fifo recv_fifo;
@ -281,7 +282,7 @@ static void prio_recv_thread(void *p1, void *p2, void *p3)
/* Send the rx node up to Host thread, /* Send the rx node up to Host thread,
* recv_thread() * recv_thread()
*/ */
BT_DBG("ISO RX node enqueue"); LOG_DBG("ISO RX node enqueue");
k_fifo_put(&recv_fifo, node_rx); k_fifo_put(&recv_fifo, node_rx);
iso_received = true; iso_received = true;
@ -296,7 +297,7 @@ static void prio_recv_thread(void *p1, void *p2, void *p3)
buf = bt_buf_get_evt(BT_HCI_EVT_NUM_COMPLETED_PACKETS, buf = bt_buf_get_evt(BT_HCI_EVT_NUM_COMPLETED_PACKETS,
false, K_FOREVER); false, K_FOREVER);
hci_num_cmplt_encode(buf, handle, num_cmplt); hci_num_cmplt_encode(buf, handle, num_cmplt);
BT_DBG("Num Complete: 0x%04x:%u", handle, num_cmplt); LOG_DBG("Num Complete: 0x%04x:%u", handle, num_cmplt);
bt_recv_prio(buf); bt_recv_prio(buf);
k_yield(); k_yield();
#endif /* CONFIG_BT_CONN || CONFIG_BT_CTLR_ADV_ISO || CONFIG_BT_CTLR_CONN_ISO */ #endif /* CONFIG_BT_CONN || CONFIG_BT_CTLR_ADV_ISO || CONFIG_BT_CTLR_CONN_ISO */
@ -315,7 +316,7 @@ static void prio_recv_thread(void *p1, void *p2, void *p3)
buf = process_prio_evt(node_rx, &evt_flags); buf = process_prio_evt(node_rx, &evt_flags);
if (buf) { if (buf) {
BT_DBG("Priority event"); LOG_DBG("Priority event");
if (!(evt_flags & BT_HCI_EVT_FLAG_RECV)) { if (!(evt_flags & BT_HCI_EVT_FLAG_RECV)) {
node_rx->hdr.next = NULL; node_rx->hdr.next = NULL;
ll_rx_mem_release((void **)&node_rx); ll_rx_mem_release((void **)&node_rx);
@ -334,7 +335,7 @@ static void prio_recv_thread(void *p1, void *p2, void *p3)
/* Send the rx node up to Host thread, /* Send the rx node up to Host thread,
* recv_thread() * recv_thread()
*/ */
BT_DBG("RX node enqueue"); LOG_DBG("RX node enqueue");
k_fifo_put(&recv_fifo, node_rx); k_fifo_put(&recv_fifo, node_rx);
} }
} }
@ -347,14 +348,14 @@ static void prio_recv_thread(void *p1, void *p2, void *p3)
continue; continue;
} }
BT_DBG("sem take..."); LOG_DBG("sem take...");
/* Wait until ULL mayfly has something to give us. /* Wait until ULL mayfly has something to give us.
* Blocking-take of the semaphore; we take it once ULL mayfly * Blocking-take of the semaphore; we take it once ULL mayfly
* has let it go in ll_rx_sched(). * has let it go in ll_rx_sched().
*/ */
k_sem_take(&sem_prio_recv, K_FOREVER); k_sem_take(&sem_prio_recv, K_FOREVER);
/* Now, ULL mayfly has something to give to us */ /* Now, ULL mayfly has something to give to us */
BT_DBG("sem taken"); LOG_DBG("sem taken");
} }
} }
@ -476,7 +477,7 @@ static inline struct net_buf *process_node(struct node_rx_pdu *node_rx)
case HCI_CLASS_ACL_DATA: case HCI_CLASS_ACL_DATA:
if (pend || !hbuf_count) { if (pend || !hbuf_count) {
sys_slist_append(&hbuf_pend, (void *)node_rx); sys_slist_append(&hbuf_pend, (void *)node_rx);
BT_DBG("FC: Queuing item: %d", class); LOG_DBG("FC: Queuing item: %d", class);
return NULL; return NULL;
} }
break; break;
@ -530,7 +531,7 @@ static inline struct net_buf *process_hbuf(struct node_rx_pdu *n)
class == HCI_CLASS_EVT_LLCP || class == HCI_CLASS_EVT_LLCP ||
(class == HCI_CLASS_ACL_DATA && hbuf_count)) { (class == HCI_CLASS_ACL_DATA && hbuf_count)) {
/* node to process later, schedule an iteration */ /* node to process later, schedule an iteration */
BT_DBG("FC: signalling"); LOG_DBG("FC: signalling");
k_poll_signal_raise(&hbuf_signal, 0x0); k_poll_signal_raise(&hbuf_signal, 0x0);
} }
return NULL; return NULL;
@ -539,12 +540,12 @@ static inline struct net_buf *process_hbuf(struct node_rx_pdu *n)
switch (class) { switch (class) {
case HCI_CLASS_EVT_CONNECTION: case HCI_CLASS_EVT_CONNECTION:
case HCI_CLASS_EVT_LLCP: case HCI_CLASS_EVT_LLCP:
BT_DBG("FC: dequeueing event"); LOG_DBG("FC: dequeueing event");
(void) sys_slist_get(&hbuf_pend); (void) sys_slist_get(&hbuf_pend);
break; break;
case HCI_CLASS_ACL_DATA: case HCI_CLASS_ACL_DATA:
if (hbuf_count) { if (hbuf_count) {
BT_DBG("FC: dequeueing ACL data"); LOG_DBG("FC: dequeueing ACL data");
(void) sys_slist_get(&hbuf_pend); (void) sys_slist_get(&hbuf_pend);
} else { } else {
/* no buffers, HCI will signal */ /* no buffers, HCI will signal */
@ -573,7 +574,7 @@ static inline struct net_buf *process_hbuf(struct node_rx_pdu *n)
/* more to process, schedule an /* more to process, schedule an
* iteration * iteration
*/ */
BT_DBG("FC: signalling"); LOG_DBG("FC: signalling");
k_poll_signal_raise(&hbuf_signal, 0x0); k_poll_signal_raise(&hbuf_signal, 0x0);
} }
} }
@ -605,7 +606,7 @@ static void recv_thread(void *p1, void *p2, void *p3)
struct node_rx_pdu *node_rx = NULL; struct node_rx_pdu *node_rx = NULL;
struct net_buf *buf = NULL; struct net_buf *buf = NULL;
BT_DBG("blocking"); LOG_DBG("blocking");
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) #if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
int err; int err;
@ -627,7 +628,7 @@ static void recv_thread(void *p1, void *p2, void *p3)
#else #else
node_rx = k_fifo_get(&recv_fifo, K_FOREVER); node_rx = k_fifo_get(&recv_fifo, K_FOREVER);
#endif #endif
BT_DBG("unblocked"); LOG_DBG("unblocked");
if (node_rx && !buf) { if (node_rx && !buf) {
/* process regular node from radio */ /* process regular node from radio */
@ -644,8 +645,7 @@ static void recv_thread(void *p1, void *p2, void *p3)
buf = net_buf_frag_del(NULL, buf); buf = net_buf_frag_del(NULL, buf);
if (frag->len) { if (frag->len) {
BT_DBG("Packet in: type:%u len:%u", LOG_DBG("Packet in: type:%u len:%u", bt_buf_get_type(frag),
bt_buf_get_type(frag),
frag->len); frag->len);
bt_recv(frag); bt_recv(frag);
@ -665,11 +665,11 @@ static int cmd_handle(struct net_buf *buf)
evt = hci_cmd_handle(buf, (void **) &node_rx); evt = hci_cmd_handle(buf, (void **) &node_rx);
if (evt) { if (evt) {
BT_DBG("Replying with event of %u bytes", evt->len); LOG_DBG("Replying with event of %u bytes", evt->len);
bt_recv_prio(evt); bt_recv_prio(evt);
if (node_rx) { if (node_rx) {
BT_DBG("RX node enqueue"); LOG_DBG("RX node enqueue");
node_rx->hdr.user_meta = hci_get_class(node_rx); node_rx->hdr.user_meta = hci_get_class(node_rx);
k_fifo_put(&recv_fifo, node_rx); k_fifo_put(&recv_fifo, node_rx);
} }
@ -686,7 +686,7 @@ static int acl_handle(struct net_buf *buf)
err = hci_acl_handle(buf, &evt); err = hci_acl_handle(buf, &evt);
if (evt) { if (evt) {
BT_DBG("Replying with event of %u bytes", evt->len); LOG_DBG("Replying with event of %u bytes", evt->len);
bt_recv_prio(evt); bt_recv_prio(evt);
} }
@ -702,7 +702,7 @@ static int iso_handle(struct net_buf *buf)
err = hci_iso_handle(buf, &evt); err = hci_iso_handle(buf, &evt);
if (evt) { if (evt) {
BT_DBG("Replying with event of %u bytes", evt->len); LOG_DBG("Replying with event of %u bytes", evt->len);
bt_recv_prio(evt); bt_recv_prio(evt);
} }
@ -715,10 +715,10 @@ static int hci_driver_send(struct net_buf *buf)
uint8_t type; uint8_t type;
int err; int err;
BT_DBG("enter"); LOG_DBG("enter");
if (!buf->len) { if (!buf->len) {
BT_ERR("Empty HCI packet"); LOG_ERR("Empty HCI packet");
return -EINVAL; return -EINVAL;
} }
@ -738,7 +738,7 @@ static int hci_driver_send(struct net_buf *buf)
break; break;
#endif /* CONFIG_BT_CTLR_ADV_ISO || CONFIG_BT_CTLR_CONN_ISO */ #endif /* CONFIG_BT_CTLR_ADV_ISO || CONFIG_BT_CTLR_CONN_ISO */
default: default:
BT_ERR("Unknown HCI type %u", type); LOG_ERR("Unknown HCI type %u", type);
return -EINVAL; return -EINVAL;
} }
@ -746,7 +746,7 @@ static int hci_driver_send(struct net_buf *buf)
net_buf_unref(buf); net_buf_unref(buf);
} }
BT_DBG("exit: %d", err); LOG_DBG("exit: %d", err);
return err; return err;
} }
@ -762,7 +762,7 @@ static int hci_driver_open(void)
err = ll_init(&sem_prio_recv); err = ll_init(&sem_prio_recv);
if (err) { if (err) {
BT_ERR("LL initialization failed: %d", err); LOG_ERR("LL initialization failed: %d", err);
return err; return err;
} }
@ -785,7 +785,7 @@ static int hci_driver_open(void)
K_PRIO_COOP(CONFIG_BT_RX_PRIO), 0, K_NO_WAIT); K_PRIO_COOP(CONFIG_BT_RX_PRIO), 0, K_NO_WAIT);
k_thread_name_set(&recv_thread_data, "BT RX"); k_thread_name_set(&recv_thread_data, "BT RX");
BT_DBG("Success."); LOG_DBG("Success.");
return 0; return 0;
} }

View file

@ -14,6 +14,7 @@
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
#include <zephyr/bluetooth/bluetooth.h> #include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>
#include "util/memq.h" #include "util/memq.h"
@ -29,8 +30,10 @@
#include "isoal.h" #include "isoal.h"
#include "ull_iso_types.h" #include "ull_iso_types.h"
#define LOG_MODULE_NAME bt_ctlr_isoal #include <zephyr/logging/log.h>
#include "common/log.h"
LOG_MODULE_REGISTER(bt_ctlr_isoal, LOG_LEVEL_DBG);
#include "hal/debug.h" #include "hal/debug.h"
#if defined(CONFIG_BT_CTLR_ADV_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO) #if defined(CONFIG_BT_CTLR_ADV_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO)
@ -751,7 +754,7 @@ static isoal_status_t isoal_rx_unframed_consume(struct isoal_sink *sink,
} else { } else {
/* Unsupported case */ /* Unsupported case */
err = ISOAL_STATUS_ERR_UNSPECIFIED; err = ISOAL_STATUS_ERR_UNSPECIFIED;
BT_ERR("Invalid unframed LLID (%d)", llid); LOG_ERR("Invalid unframed LLID (%d)", llid);
LL_ASSERT(0); LL_ASSERT(0);
} }
break; break;
@ -1223,7 +1226,7 @@ static isoal_status_t isoal_check_source_hdl_valid(isoal_source_handle_t hdl)
return ISOAL_STATUS_OK; return ISOAL_STATUS_OK;
} }
BT_ERR("Invalid source handle (0x%02x)", hdl); LOG_ERR("Invalid source handle (0x%02x)", hdl);
return ISOAL_STATUS_ERR_UNSPECIFIED; return ISOAL_STATUS_ERR_UNSPECIFIED;
} }
@ -1404,7 +1407,7 @@ static isoal_status_t isoal_tx_pdu_emit(const struct isoal_source *source_ctx,
/* If it fails, the node will be released and no further attempt /* If it fails, the node will be released and no further attempt
* will be possible * will be possible
*/ */
BT_ERR("Failed to enqueue node (%p)", node_tx); LOG_ERR("Failed to enqueue node (%p)", node_tx);
source_ctx->session.pdu_release(node_tx, handle, status); source_ctx->session.pdu_release(node_tx, handle, status);
} }

View file

@ -24,9 +24,8 @@
#include "ll_feat.h" #include "ll_feat.h"
#include "ll_settings.h" #include "ll_settings.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) #include <zephyr/bluetooth/hci.h>
#define LOG_MODULE_NAME bt_ctlr_ll_feat
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
#if defined(CONFIG_BT_CTLR_SET_HOST_FEATURE) #if defined(CONFIG_BT_CTLR_SET_HOST_FEATURE)

View file

@ -12,8 +12,10 @@
#include "ll_settings.h" #include "ll_settings.h"
#define LOG_MODULE_NAME bt_ctlr_ll_settings #include <zephyr/logging/log.h>
#include "common/log.h"
LOG_MODULE_REGISTER(bt_ctlr_ll_settings, LOG_LEVEL_DBG);
#include "hal/debug.h" #include "hal/debug.h"
#if defined(CONFIG_BT_CTLR_VERSION_SETTINGS) #if defined(CONFIG_BT_CTLR_VERSION_SETTINGS)
@ -56,20 +58,20 @@ static int ctlr_set(const char *name, size_t len_rd,
if (!strncmp(name, "company", nlen)) { if (!strncmp(name, "company", nlen)) {
len = read_cb(store, &company_id, sizeof(company_id)); len = read_cb(store, &company_id, sizeof(company_id));
if (len < 0) { if (len < 0) {
BT_ERR("Failed to read Company Id from storage" LOG_ERR("Failed to read Company Id from storage"
" (err %zd)", len); " (err %zd)", len);
} else { } else {
BT_DBG("Company Id set to %04x", company_id); LOG_DBG("Company Id set to %04x", company_id);
} }
return 0; return 0;
} }
if (!strncmp(name, "subver", nlen)) { if (!strncmp(name, "subver", nlen)) {
len = read_cb(store, &subversion, sizeof(subversion)); len = read_cb(store, &subversion, sizeof(subversion));
if (len < 0) { if (len < 0) {
BT_ERR("Failed to read Subversion from storage" LOG_ERR("Failed to read Subversion from storage"
" (err %zd)", len); " (err %zd)", len);
} else { } else {
BT_DBG("Subversion set to %04x", subversion); LOG_DBG("Subversion set to %04x", subversion);
} }
return 0; return 0;
} }
@ -79,10 +81,10 @@ static int ctlr_set(const char *name, size_t len_rd,
if (!strncmp(name, "smi_tx", nlen)) { if (!strncmp(name, "smi_tx", nlen)) {
len = read_cb(store, &smi_tx, sizeof(smi_tx)); len = read_cb(store, &smi_tx, sizeof(smi_tx));
if (len < 0) { if (len < 0) {
BT_ERR("Failed to read SMI TX flag from storage" LOG_ERR("Failed to read SMI TX flag from storage"
" (err %zd)", len); " (err %zd)", len);
} else { } else {
BT_DBG("SMI TX flag set to %04x", smi_tx); LOG_DBG("SMI TX flag set to %04x", smi_tx);
} }
return 0; return 0;
} }

View file

@ -9,9 +9,6 @@
#include "hal/ccm.h" #include "hal/ccm.h"
#include "hal/radio.h" #include "hal/radio.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_chan
#include "common/log.h"
#include <soc.h> #include <soc.h>
#include "hal/debug.h" #include "hal/debug.h"

View file

@ -13,9 +13,6 @@
#include "lll.h" #include "lll.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_common
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
/** /**

View file

@ -11,9 +11,6 @@
#include "hal/cntr.h" #include "hal/cntr.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_hal_cntr
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
#ifndef NRF_RTC #ifndef NRF_RTC

View file

@ -14,9 +14,6 @@
#include "util/mem.h" #include "util/mem.h"
#include "hal/ecb.h" #include "hal/ecb.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_hal_ecb
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
struct ecb_param { struct ecb_param {

View file

@ -14,9 +14,6 @@
#include "ll_sw/lll.h" #include "ll_sw/lll.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_hal_mayfly
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
#define MAYFLY_CALL_ID_LLL TICKER_USER_ID_LLL #define MAYFLY_CALL_ID_LLL TICKER_USER_ID_LLL

View file

@ -18,9 +18,6 @@
#include "ll_sw/lll.h" #include "ll_sw/lll.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_hal_ticker
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
#define TICKER_MAYFLY_CALL_ID_ISR TICKER_USER_ID_LLL #define TICKER_MAYFLY_CALL_ID_ISR TICKER_USER_ID_LLL

View file

@ -33,9 +33,6 @@
#include "lll_internal.h" #include "lll_internal.h"
#include "lll_prof_internal.h" #include "lll_prof_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
#if defined(CONFIG_BT_CTLR_ZLI) #if defined(CONFIG_BT_CTLR_ZLI)

View file

@ -47,9 +47,6 @@
#include "lll_prof_internal.h" #include "lll_prof_internal.h"
#include "lll_df_internal.h" #include "lll_df_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_adv
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
#define PDU_FREE_TIMEOUT K_SECONDS(5) #define PDU_FREE_TIMEOUT K_SECONDS(5)

View file

@ -40,9 +40,6 @@
#include "lll_adv_internal.h" #include "lll_adv_internal.h"
#include "lll_prof_internal.h" #include "lll_prof_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_adv_aux
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
static int init_reset(void); static int init_reset(void);

View file

@ -5,6 +5,7 @@
*/ */
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include <soc.h> #include <soc.h>
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
@ -35,9 +36,6 @@
#include "ll_feat.h" #include "ll_feat.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_adv_iso
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
#define TEST_WITH_DUMMY_PDU 0 #define TEST_WITH_DUMMY_PDU 0

View file

@ -39,9 +39,6 @@
#include "lll_prof_internal.h" #include "lll_prof_internal.h"
#include "lll_df_internal.h" #include "lll_df_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_adv_sync
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
static int init_reset(void); static int init_reset(void);

View file

@ -35,9 +35,6 @@
#include "lll_df_internal.h" #include "lll_df_internal.h"
#include "lll_tim_internal.h" #include "lll_tim_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_central
#include "common/log.h"
#include <soc.h> #include <soc.h>
#include "hal/debug.h" #include "hal/debug.h"

View file

@ -21,8 +21,6 @@
#include "lll_conn_iso.h" #include "lll_conn_iso.h"
#include "lll_peripheral_iso.h" #include "lll_peripheral_iso.h"
#define LOG_MODULE_NAME bt_ctlr_lll_peripheral_iso
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
int lll_central_iso_init(void) int lll_central_iso_init(void)

View file

@ -10,9 +10,6 @@
#include <zephyr/drivers/clock_control.h> #include <zephyr/drivers/clock_control.h>
#include <zephyr/drivers/clock_control/nrf_clock_control.h> #include <zephyr/drivers/clock_control/nrf_clock_control.h>
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_clock
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
/* Clock setup timeouts are unlikely, below values are experimental */ /* Clock setup timeouts are unlikely, below values are experimental */

View file

@ -37,9 +37,8 @@
#include "lll_tim_internal.h" #include "lll_tim_internal.h"
#include "lll_prof_internal.h" #include "lll_prof_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) #include <zephyr/bluetooth/hci.h>
#define LOG_MODULE_NAME bt_ctlr_lll_conn
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
static int init_reset(void); static int init_reset(void);

View file

@ -17,8 +17,6 @@
#include "lll.h" #include "lll.h"
#include "lll_conn_iso.h" #include "lll_conn_iso.h"
#define LOG_MODULE_NAME bt_ctlr_lll_conn_iso
#include "common/log.h"
#include <soc.h> #include <soc.h>
#include "hal/debug.h" #include "hal/debug.h"

View file

@ -28,9 +28,6 @@
#include "lll_df.h" #include "lll_df.h"
#include "lll_df_internal.h" #include "lll_df_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_CTLR_DF_DEBUG_ENABLE)
#define LOG_MODULE_NAME bt_ctlr_lll_df
#include "common/log.h"
#include <soc.h> #include <soc.h>
#include "hal/debug.h" #include "hal/debug.h"

View file

@ -34,9 +34,6 @@
#include "lll_df_internal.h" #include "lll_df_internal.h"
#include "lll_tim_internal.h" #include "lll_tim_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_periph
#include "common/log.h"
#include <soc.h> #include <soc.h>
#include "hal/debug.h" #include "hal/debug.h"

View file

@ -18,8 +18,6 @@
#include "lll_conn_iso.h" #include "lll_conn_iso.h"
#include "lll_peripheral_iso.h" #include "lll_peripheral_iso.h"
#define LOG_MODULE_NAME bt_ctlr_lll_peripheral_iso
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
int lll_peripheral_iso_init(void) int lll_peripheral_iso_init(void)

View file

@ -43,9 +43,6 @@
#include "lll_prof_internal.h" #include "lll_prof_internal.h"
#include "lll_scan_internal.h" #include "lll_scan_internal.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_scan
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
/* Maximum primary Advertising Radio Channels to scan */ /* Maximum primary Advertising Radio Channels to scan */

View file

@ -44,9 +44,6 @@
#include "ll_feat.h" #include "ll_feat.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_scan_aux
#include "common/log.h"
#include <soc.h> #include <soc.h>
#include <ull_scan_types.h> #include <ull_scan_types.h>
#include "hal/debug.h" #include "hal/debug.h"

View file

@ -38,9 +38,8 @@
#include "ll_feat.h" #include "ll_feat.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) #include <zephyr/bluetooth/hci.h>
#define LOG_MODULE_NAME bt_ctlr_lll_sync
#include "common/log.h"
#include <soc.h> #include <soc.h>
#include "hal/debug.h" #include "hal/debug.h"

View file

@ -5,6 +5,7 @@
*/ */
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include <soc.h> #include <soc.h>
#include <zephyr/sys/byteorder.h> #include <zephyr/sys/byteorder.h>
@ -30,9 +31,6 @@
#include "ll_feat.h" #include "ll_feat.h"
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_ctlr_lll_sync_iso
#include "common/log.h"
#include "hal/debug.h" #include "hal/debug.h"
static int init_reset(void); static int init_reset(void);

Some files were not shown because too many files have changed in this diff Show more