Commit e458f5aa authored by Théo Battrel's avatar Théo Battrel Committed by Carles Cufi
Browse files

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: default avatarThéo Battrel <theo.battrel@nordicsemi.no>
parent 808266a4
Loading
Loading
Loading
Loading
+5 −0
Changes for doc/releases/release-notes-3.3.rst: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -40,6 +40,11 @@ Changes in this release
* Starting from this release ``zephyr-`` prefixed tags won't be created
  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
============================

+36 −38
Changes for drivers/bluetooth/hci/h4.c: 36 added lines, 38 removed lines.
Original line number Diff line number Diff line
@@ -22,9 +22,10 @@
#include <zephyr/bluetooth/hci.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"
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_driver);

#include "common/bt_str.h"

#include "../util.h"
@@ -76,7 +77,7 @@ static inline void h4_get_type(void)
{
	/* Get packet type */
	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;
		return;
	}
@@ -98,7 +99,7 @@ static inline void h4_get_type(void)
		}
		__fallthrough;
	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;
	}
}
@@ -110,7 +111,7 @@ static void h4_read_hdr(void)

	ret = uart_fifo_read(h4_dev, rx.hdr + bytes_read, rx.remaining);
	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 {
		rx.remaining -= ret;
	}
@@ -124,7 +125,7 @@ static inline void get_acl_hdr(void)
		struct bt_hci_acl_hdr *hdr = &rx.acl;

		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;
	}
}
@@ -137,7 +138,7 @@ static inline void get_iso_hdr(void)
		struct bt_hci_iso_hdr *hdr = &rx.iso;

		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;
	}
}
@@ -166,12 +167,12 @@ static inline void get_evt_hdr(void)
	if (!rx.remaining) {
		if (rx.evt.evt == BT_HCI_EVT_LE_META_EVENT &&
		    (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.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;
	}
}
@@ -193,7 +194,7 @@ static void reset_rx(void)

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) {
	case H4_EVT:
@@ -217,10 +218,10 @@ static void rx_thread(void *p1, void *p2, void *p3)
	ARG_UNUSED(p2);
	ARG_UNUSED(p3);

	BT_DBG("started");
	LOG_DBG("started");

	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
		 * 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) {
			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)) {
				BT_ERR("Not enough space in buffer");
				LOG_ERR("Not enough space in buffer");
				rx.discard = rx.remaining;
				reset_rx();
			} else {
@@ -245,7 +246,7 @@ static void rx_thread(void *p1, void *p2, void *p3)
		do {
			uart_irq_rx_enable(h4_dev);

			BT_DBG("Calling bt_recv(%p)", buf);
			LOG_DBG("Calling bt_recv(%p)", buf);
			bt_recv(buf);

			/* 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)));
	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;
	}

@@ -286,23 +287,22 @@ static inline void read_payload(void)
		rx.buf = get_rx(K_NO_WAIT);
		if (!rx.buf) {
			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;
				reset_rx();
				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);
			return;
		}

		BT_DBG("Allocated rx.buf %p", rx.buf);
		LOG_DBG("Allocated rx.buf %p", rx.buf);

		buf_tailroom = net_buf_tailroom(rx.buf);
		if (buf_tailroom < rx.remaining) {
			BT_ERR("Not enough space in buffer %u/%zu",
			       rx.remaining, buf_tailroom);
			LOG_ERR("Not enough space in buffer %u/%zu", rx.remaining, buf_tailroom);
			rx.discard = rx.remaining;
			reset_rx();
			return;
@@ -313,16 +313,15 @@ static inline void read_payload(void)

	read = uart_fifo_read(h4_dev, net_buf_tail(rx.buf), rx.remaining);
	if (unlikely(read < 0)) {
		BT_ERR("Failed to read UART (err %d)", read);
		LOG_ERR("Failed to read UART (err %d)", read);
		return;
	}

	net_buf_add(rx.buf, read);
	rx.remaining -= read;

	BT_DBG("got %d bytes, remaining %u", read, rx.remaining);
	BT_DBG("Payload (len %u): %s", rx.buf->len,
	       bt_hex(rx.buf->data, rx.buf->len));
	LOG_DBG("got %d bytes, remaining %u", read, rx.remaining);
	LOG_DBG("Payload (len %u): %s", rx.buf->len, bt_hex(rx.buf->data, rx.buf->len));

	if (rx.remaining) {
		return;
@@ -343,12 +342,12 @@ static inline void read_payload(void)

	if (IS_ENABLED(CONFIG_BT_RECV_BLOCKING) &&
	    (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);
	}

	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);
	}
}
@@ -378,7 +377,7 @@ static inline void read_header(void)

	if (rx.have_hdr && 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;
			reset_rx();
		} else {
@@ -394,7 +393,7 @@ static inline void process_tx(void)
	if (!tx.buf) {
		tx.buf = net_buf_get(&tx.fifo, K_NO_WAIT);
		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);
			return;
		}
@@ -415,13 +414,13 @@ static inline void process_tx(void)
			}
			__fallthrough;
		default:
			BT_ERR("Unknown buffer type");
			LOG_ERR("Unknown buffer type");
			goto done;
		}

		bytes = uart_fifo_fill(h4_dev, &tx.type, 1);
		if (bytes != 1) {
			BT_WARN("Unable to send H:4 type");
			LOG_WRN("Unable to send H:4 type");
			tx.type = H4_NONE;
			return;
		}
@@ -429,7 +428,7 @@ static inline void process_tx(void)

	bytes = uart_fifo_fill(h4_dev, tx.buf->data, tx.buf->len);
	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 {
		net_buf_pull(tx.buf, bytes);
	}
@@ -449,9 +448,8 @@ done:

static inline void process_rx(void)
{
	BT_DBG("remaining %u discard %u have_hdr %u rx.buf %p len %u",
	       rx.remaining, rx.discard, rx.have_hdr, rx.buf,
	       rx.buf ? rx.buf->len : 0);
	LOG_DBG("remaining %u discard %u have_hdr %u rx.buf %p len %u", rx.remaining, rx.discard,
		rx.have_hdr, rx.buf, rx.buf ? rx.buf->len : 0);

	if (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)
{
	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);
	uart_irq_tx_enable(h4_dev);
@@ -508,7 +506,7 @@ static int h4_open(void)
	int ret;
	k_tid_t tid;

	BT_DBG("");
	LOG_DBG("");

	uart_irq_rx_disable(h4_dev);
	uart_irq_tx_disable(h4_dev);
+42 −49
Changes for drivers/bluetooth/hci/h5.c: 42 added lines, 49 removed lines.
Original line number Diff line number Diff line
@@ -23,12 +23,12 @@
#include <zephyr/bluetooth/hci.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"

#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(rx_stack, 256);

@@ -159,7 +159,7 @@ static int h5_unslip_byte(uint8_t *byte)
		*byte = SLIP_ESC;
		break;
	default:
		BT_ERR("Invalid escape byte %x\n", *byte);
		LOG_ERR("Invalid escape byte %x\n", *byte);
		return -EIO;
	}

@@ -175,8 +175,8 @@ static void process_unack(void)
		return;
	}

	BT_DBG("rx_ack %u tx_ack %u tx_seq %u unack_queue_len %u",
	       h5.rx_ack, h5.tx_ack, h5.tx_seq, unack_queue_len);
	LOG_DBG("rx_ack %u tx_ack %u tx_seq %u unack_queue_len %u", h5.rx_ack, h5.tx_ack, h5.tx_seq,
		unack_queue_len);

	while (unack_queue_len > 0) {
		if (next_seq == h5.rx_ack) {
@@ -192,22 +192,22 @@ static void process_unack(void)
	}

	if (next_seq != h5.rx_ack) {
		BT_ERR("Wrong sequence: rx_ack %u tx_seq %u next_seq %u",
		       h5.rx_ack, h5.tx_seq, next_seq);
		LOG_ERR("Wrong sequence: rx_ack %u tx_seq %u next_seq %u", h5.rx_ack, h5.tx_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) {
		struct net_buf *buf = net_buf_get(&h5.unack_queue, K_NO_WAIT);

		if (!buf) {
			BT_ERR("Unack queue is empty");
			LOG_ERR("Unack queue is empty");
			break;
		}

		/* 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);
		unack_queue_len--;
@@ -218,18 +218,15 @@ static void process_unack(void)
static void h5_print_header(const uint8_t *hdr, const char *str)
{
	if (H5_HDR_RELIABLE(hdr)) {
		BT_DBG("%s REL: seq %u ack %u crc %u type %u len %u",
		       str, H5_HDR_SEQ(hdr), H5_HDR_ACK(hdr),
		       H5_HDR_CRC(hdr), H5_HDR_PKT_TYPE(hdr),
		       H5_HDR_LEN(hdr));
		LOG_DBG("%s REL: seq %u ack %u crc %u type %u len %u", str, H5_HDR_SEQ(hdr),
			H5_HDR_ACK(hdr), H5_HDR_CRC(hdr), H5_HDR_PKT_TYPE(hdr), H5_HDR_LEN(hdr));
	} else {
		BT_DBG("%s UNREL: ack %u crc %u type %u len %u",
		       str, H5_HDR_ACK(hdr), H5_HDR_CRC(hdr),
		       H5_HDR_PKT_TYPE(hdr), H5_HDR_LEN(hdr));
		LOG_DBG("%s UNREL: ack %u crc %u type %u len %u", str, H5_HDR_ACK(hdr),
			H5_HDR_CRC(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)
{
	int n = 0;
@@ -327,7 +324,7 @@ static void retx_timeout(struct k_work *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) {
		struct k_fifo tmp_queue;
@@ -360,7 +357,7 @@ static void ack_timeout(struct k_work *work)
{
	ARG_UNUSED(work);

	BT_DBG("");
	LOG_DBG("");

	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;

	BT_DBG("");
	LOG_DBG("");

	/* rx_ack should be in every packet */
	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_tx_ready(h5_dev)) {
				BT_DBG("transmit ready");
				LOG_DBG("transmit ready");
			} else {
				BT_DBG("spurious interrupt");
				LOG_DBG("spurious interrupt");
			}
			/* Only the UART RX path is interrupt-enabled */
			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,
							  K_NO_WAIT);
				if (!h5.rx_buf) {
					BT_WARN("No available data buffers");
					LOG_WRN("No available data buffers");
					h5_reset_rx();
					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,
							  K_NO_WAIT);
				if (!h5.rx_buf) {
					BT_WARN("No available data buffers");
					LOG_WRN("No available data buffers");
					h5_reset_rx();
					continue;
				}
@@ -501,7 +498,7 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
			case HCI_3WIRE_ACK_PKT:
				h5.rx_buf = net_buf_alloc(&h5_pool, K_NO_WAIT);
				if (!h5.rx_buf) {
					BT_WARN("No available signal buffers");
					LOG_WRN("No available signal buffers");
					h5_reset_rx();
					continue;
				}
@@ -509,8 +506,7 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
				h5.rx_state = PAYLOAD;
				break;
			default:
				BT_ERR("Wrong packet type %u",
				       H5_HDR_PKT_TYPE(hdr));
				LOG_ERR("Wrong packet type %u", H5_HDR_PKT_TYPE(hdr));
				h5.rx_state = END;
				break;
			}
@@ -530,7 +526,7 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
			if (!h5.rx_buf) {
				h5.rx_buf = get_evt_buf(byte);
				if (!h5.rx_buf) {
					BT_WARN("No available event buffers");
					LOG_WRN("No available event buffers");
					h5_reset_rx();
					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);
			if (buf_tailroom < sizeof(byte)) {
				BT_ERR("Not enough space in buffer %zu/%zu",
				       sizeof(byte), buf_tailroom);
				LOG_ERR("Not enough space in buffer %zu/%zu", sizeof(byte),
					buf_tailroom);
				h5_reset_rx();
				break;
			}
@@ -552,13 +548,12 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
			break;
		case END:
			if (byte != SLIP_DELIMITER) {
				BT_ERR("Missing ending SLIP_DELIMITER");
				LOG_ERR("Missing ending SLIP_DELIMITER");
				h5_reset_rx();
				break;
			}

			BT_DBG("Received full packet: type %u",
			       H5_HDR_PKT_TYPE(hdr));
			LOG_DBG("Received full packet: type %u", H5_HDR_PKT_TYPE(hdr));

			/* Check when full packet is received, it can be done
			 * 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) &&
			    H5_HDR_SEQ(hdr) != h5.tx_ack) {
				BT_ERR("Seq expected %u got %u. Drop packet",
				       h5.tx_ack, H5_HDR_SEQ(hdr));
				LOG_ERR("Seq expected %u got %u. Drop packet", h5.tx_ack,
					H5_HDR_SEQ(hdr));
				h5_reset_rx();
				break;
			}
@@ -588,7 +583,7 @@ static int h5_queue(struct net_buf *buf)
{
	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)) {
	case BT_BUF_CMD:
@@ -601,7 +596,7 @@ static int h5_queue(struct net_buf *buf)
		type = HCI_ISODATA_PKT;
		break;
	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;
	}

@@ -614,7 +609,7 @@ static int h5_queue(struct net_buf *buf)

static void tx_thread(void)
{
	BT_DBG("");
	LOG_DBG("");

	/* FIXME: make periodic sending */
	h5_send(sync_req, HCI_3WIRE_LINK_PKT, sizeof(sync_req));
@@ -623,7 +618,7 @@ static void tx_thread(void)
		struct net_buf *buf;
		uint8_t type;

		BT_DBG("link_state %u", h5.link_state);
		LOG_DBG("link_state %u", h5.link_state);

		switch (h5.link_state) {
		case UNINIT:
@@ -660,7 +655,7 @@ static void h5_set_txwin(uint8_t *conf)

static void rx_thread(void)
{
	BT_DBG("");
	LOG_DBG("");

	while (true) {
		struct net_buf *buf;
@@ -700,11 +695,9 @@ static void rx_thread(void)
				h5.tx_win = (buf->data[2] & 0x07);
			}

			BT_DBG("Finished H5 configuration, tx_win %u",
			       h5.tx_win);
			LOG_DBG("Finished H5 configuration, tx_win %u", h5.tx_win);
		} else {
			BT_ERR("Not handled yet %x %x",
			       buf->data[0], buf->data[1]);
			LOG_ERR("Not handled yet %x %x", buf->data[0], buf->data[1]);
		}

		net_buf_unref(buf);
@@ -718,7 +711,7 @@ static void rx_thread(void)

static void h5_init(void)
{
	BT_DBG("");
	LOG_DBG("");

	h5.link_state = UNINIT;
	h5.rx_state = START;
@@ -751,7 +744,7 @@ static void h5_init(void)

static int h5_open(void)
{
	BT_DBG("");
	LOG_DBG("");

	uart_irq_rx_disable(h5_dev);
	uart_irq_tx_disable(h5_dev);
+23 −23
Changes for drivers/bluetooth/hci/hci_b91.c: 23 added lines, 23 removed lines.
Original line number Diff line number Diff line
@@ -4,15 +4,17 @@
 * SPDX-License-Identifier: Apache-2.0
 */

#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_hci_driver_b91
#include "common/log.h"
#include <zephyr/bluetooth/hci.h>

#include <zephyr/sys/byteorder.h>
#include <zephyr/drivers/bluetooth/hci_driver.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_ACL                 0x02
#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;

	if (len < sizeof(hdr)) {
		BT_ERR("Not enough data for event header");
		LOG_ERR("Not enough data for event header");
		return NULL;
	}

@@ -65,17 +67,17 @@ static struct net_buf *bt_b91_evt_recv(uint8_t *data, size_t len)
	len -= sizeof(hdr);

	if (len != hdr.len) {
		BT_ERR("Event payload length is not correct");
		LOG_ERR("Event payload length is not correct");
		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);
	if (!buf) {
		if (discardable) {
			BT_DBG("Discardable buffer pool full, ignoring event");
			LOG_DBG("Discardable buffer pool full, ignoring event");
		} else {
			BT_ERR("No available event buffers!");
			LOG_ERR("No available event buffers!");
		}
		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);
	if (buf_tailroom < len) {
		BT_ERR("Not enough space in buffer %zu/%zu",
		       len, buf_tailroom);
		LOG_ERR("Not enough space in buffer %zu/%zu", len, buf_tailroom);
		net_buf_unref(buf);
		return NULL;
	}
@@ -102,7 +103,7 @@ static struct net_buf *bt_b91_acl_recv(uint8_t *data, size_t len)
	size_t buf_tailroom;

	if (len < sizeof(hdr)) {
		BT_ERR("Not enough data for ACL header");
		LOG_ERR("Not enough data for ACL header");
		return NULL;
	}

@@ -112,12 +113,12 @@ static struct net_buf *bt_b91_acl_recv(uint8_t *data, size_t len)
		data += sizeof(hdr);
		len -= sizeof(hdr);
	} else {
		BT_ERR("No available ACL buffers!");
		LOG_ERR("No available ACL buffers!");
		return NULL;
	}

	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);
		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));
	buf_tailroom = net_buf_tailroom(buf);
	if (buf_tailroom < len) {
		BT_ERR("Not enough space in buffer %zu/%zu",
		       len, buf_tailroom);
		LOG_ERR("Not enough space in buffer %zu/%zu", len, buf_tailroom);
		net_buf_unref(buf);
		return NULL;
	}

	BT_DBG("len %u", len);
	LOG_DBG("len %u", len);
	net_buf_add_mem(buf, data, len);

	return buf;
@@ -158,11 +158,11 @@ static void hci_b91_host_rcv_pkt(uint8_t *data, uint16_t len)

	default:
		buf = NULL;
		BT_ERR("Unknown HCI type %u", pkt_indicator);
		LOG_ERR("Unknown HCI type %u", pkt_indicator);
	}

	if (buf) {
		BT_DBG("Calling bt_recv(%p)", buf);
		LOG_DBG("Calling bt_recv(%p)", buf);
		bt_recv(buf);
	}
}
@@ -182,7 +182,7 @@ static int bt_b91_send(struct net_buf *buf)
	int err = 0;
	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)) {
	case BT_BUF_ACL_OUT:
@@ -194,7 +194,7 @@ static int bt_b91_send(struct net_buf *buf)
		break;

	default:
		BT_ERR("Unknown type %u", bt_buf_get_type(buf));
		LOG_ERR("Unknown type %u", bt_buf_get_type(buf));
		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) {
		b91_bt_host_send_packet(type, buf->data, buf->len);
	} else {
		BT_ERR("Send packet timeout error");
		LOG_ERR("Send packet timeout error");
		err = -ETIMEDOUT;
	}

@@ -220,13 +220,13 @@ static int hci_b91_open(void)

	status = b91_bt_controller_init();
	if (status) {
		BT_ERR("Bluetooth controller init failed %d", status);
		LOG_ERR("Bluetooth controller init failed %d", status);
		return status;
	}

	b91_bt_host_callback_register(&vhci_host_cb);

	BT_DBG("B91 BT started");
	LOG_DBG("B91 BT started");

	return 0;
}
+30 −31
Changes for drivers/bluetooth/hci/hci_esp32.c: 30 added lines, 31 removed lines.
Original line number Diff line number Diff line
@@ -4,9 +4,7 @@
 * SPDX-License-Identifier: Apache-2.0
 */

#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_hci_driver_esp32
#include "common/log.h"
#include <zephyr/bluetooth/hci.h>

#include <zephyr/init.h>
#include <zephyr/sys/byteorder.h>
@@ -15,6 +13,10 @@

#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_ACL                 0x02
#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;

	if (remaining < sizeof(hdr)) {
		BT_ERR("Not enough data for event header");
		LOG_ERR("Not enough data for event header");
		return NULL;
	}

@@ -69,17 +71,17 @@ static struct net_buf *bt_esp_evt_recv(uint8_t *data, size_t remaining)
	remaining -= sizeof(hdr);

	if (remaining != hdr.len) {
		BT_ERR("Event payload length is not correct");
		LOG_ERR("Event payload length is not correct");
		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);
	if (!buf) {
		if (discardable) {
			BT_DBG("Discardable buffer pool full, ignoring event");
			LOG_DBG("Discardable buffer pool full, ignoring event");
		} else {
			BT_ERR("No available event buffers!");
			LOG_ERR("No available event buffers!");
		}
		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);
	if (buf_tailroom < remaining) {
		BT_ERR("Not enough space in buffer %zu/%zu",
		       remaining, buf_tailroom);
		LOG_ERR("Not enough space in buffer %zu/%zu", remaining, buf_tailroom);
		net_buf_unref(buf);
		return NULL;
	}
@@ -106,7 +107,7 @@ static struct net_buf *bt_esp_acl_recv(uint8_t *data, size_t remaining)
	size_t buf_tailroom;

	if (remaining < sizeof(hdr)) {
		BT_ERR("Not enough data for ACL header");
		LOG_ERR("Not enough data for ACL header");
		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));
	} else {
		BT_ERR("No available ACL buffers!");
		LOG_ERR("No available ACL buffers!");
		return NULL;
	}

	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);
		return NULL;
	}

	buf_tailroom = net_buf_tailroom(buf);
	if (buf_tailroom < remaining) {
		BT_ERR("Not enough space in buffer %zu/%zu",
		       remaining, buf_tailroom);
		LOG_ERR("Not enough space in buffer %zu/%zu", remaining, buf_tailroom);
		net_buf_unref(buf);
		return NULL;
	}

	BT_DBG("len %u", remaining);
	LOG_DBG("len %u", remaining);
	net_buf_add_mem(buf, data, remaining);

	return buf;
@@ -149,7 +149,7 @@ static struct net_buf *bt_esp_iso_recv(uint8_t *data, size_t remaining)
	size_t buf_tailroom;

	if (remaining < sizeof(hdr)) {
		BT_ERR("Not enough data for ISO header");
		LOG_ERR("Not enough data for ISO header");
		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));
	} else {
		BT_ERR("No available ISO buffers!");
		LOG_ERR("No available ISO buffers!");
		return NULL;
	}

	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);
		return NULL;
	}

	buf_tailroom = net_buf_tailroom(buf);
	if (buf_tailroom < remaining) {
		BT_ERR("Not enough space in buffer %zu/%zu",
		       remaining, buf_tailroom);
		LOG_ERR("Not enough space in buffer %zu/%zu", remaining, buf_tailroom);
		net_buf_unref(buf);
		return NULL;
	}

	BT_DBG("len %zu", remaining);
	LOG_DBG("len %zu", remaining);
	net_buf_add_mem(buf, data, remaining);

	return buf;
@@ -210,12 +209,12 @@ static int hci_esp_host_rcv_pkt(uint8_t *data, uint16_t len)
		break;

	default:
		BT_ERR("Unknown HCI type %u", pkt_indicator);
		LOG_ERR("Unknown HCI type %u", pkt_indicator);
		return -1;
	}

	if (buf) {
		BT_DBG("Calling bt_recv(%p)", buf);
		LOG_DBG("Calling bt_recv(%p)", buf);

		bt_recv(buf);
	}
@@ -238,7 +237,7 @@ static int bt_esp32_send(struct net_buf *buf)
	int err = 0;
	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)) {
	case BT_BUF_ACL_OUT:
@@ -251,7 +250,7 @@ static int bt_esp32_send(struct net_buf *buf)
		pkt_indicator = HCI_ISO;
		break;
	default:
		BT_ERR("Unknown type %u", bt_buf_get_type(buf));
		LOG_ERR("Unknown type %u", bt_buf_get_type(buf));
		goto done;
	}
	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:");

	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) {
		esp_vhci_host_send_packet(buf->data, buf->len);
	} else {
		BT_ERR("Send packet timeout error");
		LOG_ERR("Send packet timeout error");
		err = -ETIMEDOUT;
	}

@@ -289,13 +288,13 @@ static int bt_esp32_ble_init(void)

	ret = esp_bt_controller_init(&bt_cfg);
	if (ret) {
		BT_ERR("Bluetooth controller init failed %d", ret);
		LOG_ERR("Bluetooth controller init failed %d", ret);
		return ret;
	}

	ret = esp_bt_controller_enable(mode);
	if (ret) {
		BT_ERR("Bluetooth controller enable failed: %d", ret);
		LOG_ERR("Bluetooth controller enable failed: %d", ret);
		return ret;
	}

@@ -313,7 +312,7 @@ static int bt_esp32_open(void)
		return err;
	}

	BT_DBG("ESP32 BT started");
	LOG_DBG("ESP32 BT started");

	return 0;
}
Loading