Bluetooth: Samples: Use string printing functions for error codes

When developing Bluetooth applications, you typically run into some errors.
If you are an experienced Bluetooth developer, you would typically know
how to translate the error codes into string representations.
Others might not.

This commit to adds string printing of error codes for all
samples to make them more user-friendly.

Several formatting alternatives were considered. The chosen alternative
balances code readability and FLASH size (with and without string
printing).

Example output from the peripheral_hids sample when the
peer rejects pairing:

```
Bluetooth initialized
Bluetooth authentication callbacks registered.
Advertising successfully started
Connected 5E:67:02:D3:1C:DB (random)
Security failed: 5E:67:02:D3:1C:DB (random) \
level 1 err 6 BT_SECURITY_ERR_PAIR_NOT_ALLOWED
Disconnected from 5E:67:02:D3:1C:DB (random), \
reason 0x13 BT_HCI_ERR_REMOTE_USER_TERM_CONN
```

Other alternatives that were considered:

- Use of parantheses:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err BT_SECURITY_ERR_PAIR_NOT_ALLOWED(6)
Disconnected from 5E:67:02:D3:1C:DB (random), reason \
BT_HCI_ERR_REMOTE_USER_TERM_CONN(0x13)
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err (6)
Disconnected from 5E:67:02:D3:1C:DB (random), reason (0x13)
```

- Spaces and parantheses:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err BT_SECURITY_ERR_PAIR_NOT_ALLOWED (6)
Disconnected from 5E:67:02:D3:1C:DB (random), \
reason BT_HCI_ERR_REMOTE_USER_TERM_CONN (0x13)
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err  (6)
Disconnected from 5E:67:02:D3:1C:DB (random), reason  (0x13)
```

- Parantheses around everything:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err (BT_SECURITY_ERR_PAIR_NOT_ALLOWED(6))
Disconnected from 5E:67:02:D3:1C:DB (random), \
reason (BT_HCI_ERR_REMOTE_USER_TERM_CONN(0x13))
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err ((6))
Disconnected from 5E:67:02:D3:1C:DB (random), reason ((0x13))
```

- Error code first, then string representation:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err 6 (BT_SECURITY_ERR_PAIR_NOT_ALLOWED)
Disconnected from 5E:67:02:D3:1C:DB (random), reason \
0x13 (BT_HCI_ERR_REMOTE_USER_TERM_CONN)
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err 6 ()
Disconnected from 5E:67:02:D3:1C:DB (random), reason 0x13 ()
```

- Apostrophes around error printing:
```
// strings enabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 \
err "BT_SECURITY_ERR_PAIR_NOT_ALLOWED (6)"
Disconnected from 5E:67:02:D3:1C:DB (random), reason \
"BT_HCI_ERR_REMOTE_USER_TERM_CONN (0x13)"
// strings disabled
Security failed: 5E:67:02:D3:1C:DB (random) level 1 err " (6)"
Disconnected from 5E:67:02:D3:1C:DB (random), reason " (0x13)"
```

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
This commit is contained in:
Rubin Gerritsen 2024-07-04 13:18:05 +02:00 committed by Carles Cufí
parent de664204a7
commit a4e43d013c
57 changed files with 146 additions and 110 deletions

View file

@ -322,7 +322,8 @@ static void connected(struct bt_conn *conn, uint8_t err)
ot_plat_ble_connection = bt_conn_ref(conn);
if (err) {
LOG_WRN("Connection failed (err %u)", err);
LOG_WRN("Connection failed err %u %s",
err, bt_hci_err_to_str(err));
return;
} else if (bt_conn_get_info(conn, &info)) {
LOG_WRN("Could not parse connection info");
@ -342,7 +343,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
{
otError error = OT_ERROR_NONE;
LOG_INF("Disconnected (reason %" PRIu8 ")", reason);
LOG_INF("Disconnected, reason 0x%02x %s", reason, bt_hci_err_to_str(reason));
if (ot_plat_ble_connection) {
bt_conn_unref(ot_plat_ble_connection);

View file

@ -439,7 +439,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
(void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err != 0) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
bt_conn_unref(broadcast_sink_conn);
broadcast_sink_conn = NULL;
@ -466,7 +466,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
(void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(broadcast_sink_conn);
broadcast_sink_conn = NULL;
@ -481,7 +481,7 @@ static void security_changed_cb(struct bt_conn *conn, bt_security_t level,
printk("Security level changed: %u\n", level);
k_sem_give(&sem_security_updated);
} else {
printk("Failed to set security level: %u\n", err);
printk("Failed to set security level: %s(%u)\n", bt_security_err_to_str(err), err);
}
}

View file

@ -1063,7 +1063,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err != 0U) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
broadcast_assistant_conn = NULL;
return;
@ -1085,7 +1085,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(broadcast_assistant_conn);
broadcast_assistant_conn = NULL;

View file

@ -395,7 +395,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
(void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err != 0) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
bt_conn_unref(default_conn);
default_conn = NULL;
@ -422,7 +422,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
(void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;
@ -436,7 +436,7 @@ static void security_changed_cb(struct bt_conn *conn, bt_security_t level,
if (err == 0) {
k_sem_give(&sem_security_updated);
} else {
printk("Failed to set security level: %u", err);
printk("Failed to set security level: %s(%u)", bt_security_err_to_str(err), err);
}
}

View file

@ -583,7 +583,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err != 0) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
default_conn = NULL;
return;
@ -603,7 +603,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;

View file

@ -82,7 +82,7 @@ static void disconnected_cb(struct bt_conn *conn, uint8_t reason)
}
(void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
LOG_INF("Disconnected: %s (reason 0x%02x)", addr, reason);
LOG_INF("Disconnected: %s, reason 0x%02x %s", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(peer.conn);
peer.conn = NULL;

View file

@ -522,7 +522,7 @@ static void disconnected_cb(struct bt_conn *conn, uint8_t reason)
(void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
LOG_INF("Disconnected: %s (reason 0x%02x)", addr, reason);
LOG_INF("Disconnected: %s, reason 0x%02x %s", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(peer.conn);
peer.conn = NULL;
@ -537,7 +537,8 @@ static void security_changed_cb(struct bt_conn *conn, bt_security_t level,
LOG_INF("Security changed: %u", level);
k_sem_give(&sem_security_changed);
} else {
LOG_ERR("Failed to set security level: %d", sec_err);
LOG_ERR("Failed to set security level: %s(%d)",
bt_security_err_to_str(sec_err), sec_err);
if (sec_err == BT_SECURITY_ERR_PIN_OR_KEY_MISSING) {
int err;

View file

@ -80,7 +80,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
bt_conn_unref(default_conn);
default_conn = NULL;
@ -108,7 +108,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;

View file

@ -10,6 +10,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>
extern int mtu_exchange(struct bt_conn *conn);
extern int write_cmd(struct bt_conn *conn);

View file

@ -10,6 +10,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>
static struct bt_gatt_exchange_params mtu_exchange_params;
static uint32_t write_count;
@ -134,8 +135,8 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
return;
}
printk("%s: %s role %u (reason %u)\n", __func__, addr, conn_info.role,
reason);
printk("%s: %s role %u, reason %u %s\n", __func__, addr, conn_info.role,
reason, bt_hci_err_to_str(reason));
conn_connected = NULL;
@ -166,7 +167,7 @@ static void le_param_updated(struct bt_conn *conn, uint16_t interval,
static void security_changed(struct bt_conn *conn, bt_security_t level,
enum bt_security_err err)
{
printk("%s: to level %u (err %u)\n", __func__, level, err);
printk("%s: to level %u, err %s(%u)\n", __func__, level, bt_security_err_to_str(err), err);
}
#endif

View file

@ -252,7 +252,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
if (default_conn != conn) {
return;

View file

@ -243,7 +243,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
if (default_conn != conn) {
return;

View file

@ -179,7 +179,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
bt_conn_unref(default_conn);
default_conn = NULL;
@ -215,7 +215,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;

View file

@ -182,7 +182,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(conn);
@ -228,8 +228,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
if (!err) {
printk("Security changed: %s level %u\n", addr, level);
} else {
printk("Security failed: %s level %u err %d\n", addr, level,
err);
printk("Security failed: %s level %u err %d %s\n", addr, level,
err, bt_security_err_to_str(err));
}
}
#endif

View file

@ -502,7 +502,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
first_selected = false;
if (err != 0) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
bt_conn_unref(default_conn);
default_conn = NULL;
@ -542,7 +542,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;

View file

@ -9,6 +9,7 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/hci.h>
#define NAME_LEN 30
@ -128,7 +129,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err != 0) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
bt_conn_unref(default_conn);
default_conn = NULL;
@ -163,7 +164,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;

View file

@ -82,7 +82,7 @@ static const struct bt_data ad[] = {
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
printk("Connected\n");
}
@ -90,7 +90,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
}
BT_CONN_CB_DEFINE(conn_callbacks) = {

View file

@ -232,7 +232,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
if (default_conn != conn) {
return;

View file

@ -76,7 +76,7 @@ static void enable_cte_response(struct bt_conn *conn)
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
printk("Connected\n");
}
@ -86,7 +86,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
}
BT_CONN_CB_DEFINE(conn_callbacks) = {

View file

@ -661,7 +661,7 @@ static void idle_timeout(struct k_work *work)
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
printk("Connected\n");
k_work_cancel_delayable(&idle_work);
@ -672,7 +672,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
{
struct eds_slot *slot = &eds_slots[eds_active_slot];
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
if (!slot->connectable) {
k_work_reschedule(&idle_work, K_NO_WAIT);

View file

@ -19,6 +19,7 @@
#include <zephyr/bluetooth/addr.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/bluetooth.h>
#include "common/bt_str.h"
@ -329,7 +330,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
LOG_DBG("Disconnected: %s (reason 0x%02x)", addr, reason);
LOG_DBG("Disconnected: %s, reason 0x%02x %s", addr, reason, bt_hci_err_to_str(reason));
if (default_conn != conn) {
return;
@ -348,7 +349,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_
if (!err) {
LOG_DBG("Security changed: %s level %u", addr, level);
} else {
LOG_DBG("Security failed: %s level %u err %d", addr, level, err);
LOG_DBG("Security failed: %s level %u err %d %s", addr, level,
err, bt_security_err_to_str(err));
}
}

View file

@ -17,6 +17,7 @@
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/logging/log.h>
@ -198,7 +199,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err) {
LOG_ERR("Failed to connect to %s (%u)", addr, err);
LOG_ERR("Failed to connect to %s %u %s", addr, err, bt_hci_err_to_str(err));
return;
}
@ -213,7 +214,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
LOG_DBG("Disconnected from %s (reason 0x%02x)", addr, reason);
LOG_DBG("Disconnected from %s, reason 0x%02x %s", addr, reason, bt_hci_err_to_str(reason));
k_poll_signal_raise(&disconn_signal, 0);
}
@ -227,7 +228,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_
if (!err) {
LOG_DBG("Security changed: %s level %u", addr, level);
} else {
LOG_DBG("Security failed: %s level %u err %d", addr, level, err);
LOG_DBG("Security failed: %s level %u err %s(%d)", addr, level,
bt_security_err_to_str(err), err);
}
}

View file

@ -7,6 +7,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gap.h>
#include <zephyr/bluetooth/hci.h>
static struct bt_conn *default_conn;
@ -51,7 +52,7 @@ static void connected_cb(struct bt_conn *conn, uint8_t err)
static void disconnected_cb(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02X)\n", reason);
printk("Disconnected, reason 0x%02X %s\n", reason, bt_hci_err_to_str(reason));
__ASSERT(conn == default_conn, "Unexpected disconnected callback");

View file

@ -7,6 +7,7 @@
#include <zephyr/kernel.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/hci.h>
#define NAME_LEN 30
@ -60,7 +61,7 @@ static void disconnected_cb(struct bt_conn *conn, uint8_t reason)
bt_conn_unref(default_conn);
default_conn = NULL;
printk("Disconnected (reason 0x%02X)\n", reason);
printk("Disconnected, reason 0x%02X %s\n", reason, bt_hci_err_to_str(reason));
}
static void recycled_cb(void)

View file

@ -17,6 +17,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/l2cap.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/classic/rfcomm.h>
#include <zephyr/bluetooth/classic/sdp.h>
#include <zephyr/bluetooth/classic/hfp_ag.h>
@ -148,7 +149,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
if (default_conn != NULL) {
default_conn = NULL;
}
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
if (default_conn == conn) {
struct bt_conn_info info;
@ -175,7 +176,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
if (default_conn != conn) {
return;
@ -197,7 +198,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_
bt_addr_to_str(info.br.dst, addr, sizeof(addr));
printk("Security changed: %s level %u (err %d)\n", addr, level, err);
printk("Security changed: %s level %u, err %s(%d)\n", addr, level,
bt_security_err_to_str(err), err);
}
static struct bt_conn_cb conn_callbacks = {

View file

@ -13,6 +13,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/audio/audio.h>
#include <zephyr/bluetooth/audio/bap.h>
#include <zephyr/bluetooth/audio/pacs.h>
@ -344,7 +345,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err != 0) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
default_conn = NULL;
return;
@ -365,7 +366,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;

View file

@ -12,6 +12,7 @@
#include <zephyr/sys/util.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/audio/tbs.h>
enum {
@ -61,7 +62,7 @@ static int process_profile_connection(struct bt_conn *conn)
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err %d)\n", err);
printk("Connection failed, err %d %s\n", err, bt_hci_err_to_str(err));
return;
}

View file

@ -146,7 +146,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
int ret;
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
default_conn = bt_conn_ref(conn);
ret = bt_hci_get_conn_handle(default_conn,
@ -177,7 +177,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
if (default_conn) {
bt_conn_unref(default_conn);

View file

@ -14,6 +14,7 @@
#include <zephyr/console/console.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/iso.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/logging/log.h>
@ -475,7 +476,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err != 0 && role == ROLE_CENTRAL) {
LOG_INF("Failed to connect to %s: %u", addr, err);
LOG_INF("Failed to connect to %s: %u %s", addr, err, bt_hci_err_to_str(err));
bt_conn_unref(default_conn);
default_conn = NULL;
@ -495,7 +496,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
LOG_INF("Disconnected: %s (reason 0x%02x)", addr, reason);
LOG_INF("Disconnected: %s, reason 0x%02x %s", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;

View file

@ -194,7 +194,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
bt_conn_unref(default_conn);
default_conn = NULL;
@ -233,7 +233,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;

View file

@ -7,6 +7,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gap.h>
#include <zephyr/bluetooth/hci.h>
#define NUM_RSP_SLOTS 5
#define NUM_SUBEVENTS 5
@ -133,7 +134,7 @@ static void connected_cb(struct bt_conn *conn, uint8_t err)
static void disconnected_cb(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02X)\n", reason);
printk("Disconnected, reason 0x%02X %s\n", reason, bt_hci_err_to_str(reason));
__ASSERT(conn == default_conn, "Unexpected disconnected callback");

View file

@ -8,6 +8,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>
#define NUM_RSP_SLOTS 5
#define NUM_SUBEVENTS 5
@ -116,7 +117,7 @@ void connected_cb(struct bt_conn *conn, uint8_t err)
void disconnected_cb(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02X)\n", reason);
printk("Disconnected, reason 0x%02X %s\n", reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;

View file

@ -7,6 +7,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gap.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/sys/util.h>
#define NAME_LEN 30
@ -127,7 +128,7 @@ static void disconnected_cb(struct bt_conn *conn, uint8_t reason)
bt_conn_unref(default_conn);
default_conn = NULL;
printk("Disconnected (reason 0x%02X)\n", reason);
printk("Disconnected, reason 0x%02X %s\n", reason, bt_hci_err_to_str(reason));
k_sem_give(&sem_disconnected);
}

View file

@ -8,6 +8,7 @@
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/sys/util.h>
#define NAME_LEN 30
@ -175,7 +176,7 @@ BT_GATT_SERVICE_DEFINE(pawr_svc, BT_GATT_PRIMARY_SERVICE(&pawr_svc_uuid.uuid),
void connected(struct bt_conn *conn, uint8_t err)
{
printk("Connected (err 0x%02X)\n", err);
printk("Connected, err 0x%02X %s\n", err, bt_hci_err_to_str(err));
if (err) {
default_conn = NULL;
@ -191,7 +192,7 @@ void disconnected(struct bt_conn *conn, uint8_t reason)
bt_conn_unref(default_conn);
default_conn = NULL;
printk("Disconnected (reason 0x%02X)\n", reason);
printk("Disconnected, reason 0x%02X %s\n", reason, bt_hci_err_to_str(reason));
}
BT_CONN_CB_DEFINE(conn_cb) = {

View file

@ -242,7 +242,7 @@ static struct bt_gatt_cb gatt_callbacks = {
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
printk("Connected\n");
}
@ -250,7 +250,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
}
static void alert_stop(void)

View file

@ -14,6 +14,7 @@
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>
/* Custom Service Variables */
#define BT_UUID_CUSTOM_SERVICE_VAL \
@ -81,7 +82,7 @@ static const struct bt_data sd[] = {
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
printk("Connected\n");
}
@ -89,7 +90,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
}
BT_CONN_CB_DEFINE(conn_callbacks) = {

View file

@ -21,6 +21,7 @@
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/services/bas.h>
#define CSC_SUPPORTED_LOCATIONS { CSC_LOC_OTHER, \
@ -345,7 +346,7 @@ static void csc_simulation(void)
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
printk("Connected\n");
}
@ -353,7 +354,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
}
BT_CONN_CB_DEFINE(conn_callbacks) = {

View file

@ -33,7 +33,7 @@ static const struct bt_data sd[] = {
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
printk("Connected\n");
}
@ -41,7 +41,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
}
BT_CONN_CB_DEFINE(conn_callbacks) = {

View file

@ -399,7 +399,7 @@ static const struct bt_data sd[] = {
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
printk("Connected\n");
}
@ -407,7 +407,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
}
BT_CONN_CB_DEFINE(conn_callbacks) = {

View file

@ -10,6 +10,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>
extern int mtu_exchange(struct bt_conn *conn);
extern int write_cmd(struct bt_conn *conn);

View file

@ -42,7 +42,8 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s, err 0x%02x %s\n", addr,
err, bt_hci_err_to_str(err));
return;
}
@ -59,7 +60,8 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected from %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected from %s, reason 0x%02x %s\n", addr,
reason, bt_hci_err_to_str(reason));
}
static void security_changed(struct bt_conn *conn, bt_security_t level,
@ -72,8 +74,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
if (!err) {
printk("Security changed: %s level %u\n", addr, level);
} else {
printk("Security failed: %s level %u err %d\n", addr, level,
err);
printk("Security failed: %s level %u err %s(%d)\n", addr, level,
bt_security_err_to_str(err), err);
}
}

View file

@ -46,7 +46,7 @@ static ATOMIC_DEFINE(state, 2U);
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
printk("Connected\n");
@ -56,7 +56,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
(void)atomic_set_bit(state, STATE_DISCONNECTED);
}

View file

@ -38,7 +38,7 @@ static const struct bt_data sd[] = {
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err));
} else {
printk("Connected\n");
}
@ -46,7 +46,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
}
BT_CONN_CB_DEFINE(conn_callbacks) = {

View file

@ -12,6 +12,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/hci.h>
static struct k_work work_adv_start;
static uint8_t volatile conn_count;
@ -79,7 +80,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
char addr[BT_ADDR_LE_STR_LEN];
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err));
return;
}
@ -99,7 +100,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected %s, reason %s(0x%02x)\n", addr, bt_hci_err_to_str(reason), reason);
if ((conn_count == 1U) && is_disconnecting) {
is_disconnecting = false;
@ -170,8 +171,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
if (!err) {
printk("Security changed: %s level %u\n", addr, level);
} else {
printk("Security failed: %s level %u err %d\n", addr, level,
err);
printk("Security failed: %s level %u err %s(%d)\n", addr, level,
bt_security_err_to_str(err), err);
}
}

View file

@ -33,7 +33,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
return;
}
@ -46,7 +46,8 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected from %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected from %s, reason 0x%02x %s\n", addr,
reason, bt_hci_err_to_str(reason));
}
BT_CONN_CB_DEFINE(conn_callbacks) = {

View file

@ -13,6 +13,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/services/ots.h>
@ -50,7 +51,7 @@ static struct object_creation_data *object_being_created;
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err %u)\n", err);
printk("Connection failed, err %u %s\n", err, bt_hci_err_to_str(err));
return;
}
@ -59,7 +60,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason %u)\n", reason);
printk("Disconnected, reason %u %s\n", reason, bt_hci_err_to_str(reason));
}
BT_CONN_CB_DEFINE(conn_callbacks) = {

View file

@ -9,6 +9,7 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/hci.h>
static struct bt_conn *default_conn;
@ -99,7 +100,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;

View file

@ -35,7 +35,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
return;
}
@ -52,7 +52,8 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected from %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected from %s, reason 0x%02x %s\n", addr,
reason, bt_hci_err_to_str(reason));
}
static void identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa,
@ -77,8 +78,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
if (!err) {
printk("Security changed: %s level %u\n", addr, level);
} else {
printk("Security failed: %s level %u err %d\n", addr, level,
err);
printk("Security failed: %s level %u err %s(%d)\n", addr, level,
bt_security_err_to_str(err), err);
}
}

View file

@ -170,7 +170,7 @@ static void disconnected(struct bt_conn *disconn, uint8_t reason)
ble_conn = NULL;
}
LOG_INF("Disconnected (reason %u)", reason);
LOG_INF("Disconnected, reason %u %s", reason, bt_hci_err_to_str(reason));
}
BT_CONN_CB_DEFINE(conn_callbacks) = {

View file

@ -18,6 +18,7 @@
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>
#include <zephyr/bluetooth/audio/tmap.h>
#include <zephyr/bluetooth/audio/cap.h>
#include <zephyr/bluetooth/hci.h>
#include "tmap_central.h"
@ -82,7 +83,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
(void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err != 0) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
bt_conn_unref(default_conn);
default_conn = NULL;
@ -109,7 +110,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
(void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;
@ -124,7 +125,7 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
printk("Security changed: %u\n", err);
k_sem_give(&sem_security_updated);
} else {
printk("Failed to set security level: %u\n", err);
printk("Failed to set security level: %s(%u)\n", bt_security_err_to_str(err), err);
}
}

View file

@ -7,6 +7,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/audio/audio.h>
#include <zephyr/bluetooth/audio/vcp.h>
#include <zephyr/bluetooth/hci.h>
static struct bt_vcp_vol_ctlr *vcp_vol_ctlr;
@ -78,7 +79,7 @@ static int process_profile_connection(struct bt_conn *conn)
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
printk("Connection failed (err %d)\n", err);
printk("Connection failed, err %d %s\n", err, bt_hci_err_to_str(err));
return;
}

View file

@ -14,6 +14,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/byteorder.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/audio/audio.h>
#include <zephyr/bluetooth/audio/bap.h>
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>
@ -98,7 +99,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
if (err != 0) {
printk("Failed to connect to %s (%u)\n", addr, err);
printk("Failed to connect to %s %u %s\n", addr, err, bt_hci_err_to_str(err));
default_conn = NULL;
return;
@ -119,7 +120,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Disconnected: %s (reason 0x%02x)\n", addr, reason);
printk("Disconnected: %s, reason 0x%02x %s\n", addr, reason, bt_hci_err_to_str(reason));
bt_conn_unref(default_conn);
default_conn = NULL;
@ -134,7 +135,7 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
printk("Security changed: %u\n", err);
k_sem_give(&sem_security_updated);
} else {
printk("Failed to set security level: %u", err);
printk("Failed to set security level: %s(%u)", bt_security_err_to_str(err), err);
}
}

View file

@ -235,7 +235,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
struct bt_conn_info info;
if (err) {
printk("Connection failed (err 0x%02x)\n", err);
printk("Connection failed, err 0x%02x %s\n", err, bt_hci_err_to_str(err));
return;
}
@ -260,7 +260,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
if (default_conn) {
bt_conn_unref(default_conn);

View file

@ -14,6 +14,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/bluetooth/hci.h>
#include "mesh.h"
#include "board.h"
@ -137,7 +138,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
if (strcmp(CONFIG_BT_DEVICE_NAME, bt_get_name()) &&
!mesh_is_initialized()) {

View file

@ -6,6 +6,7 @@
#include <zephyr/kernel.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/logging/log.h>
#include <zephyr/logging/log_backend_ble.h>
@ -37,7 +38,7 @@ static void start_adv(void)
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
LOG_ERR("Connection failed (err 0x%02x)", err);
LOG_ERR("Connection failed, err 0x%02x %s", err, bt_hci_err_to_str(err));
} else {
LOG_INF("Connected");
}
@ -45,7 +46,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
LOG_INF("Disconnected (reason 0x%02x)", reason);
LOG_INF("Disconnected, reason 0x%02x %s", reason, bt_hci_err_to_str(reason));
start_adv();
}

View file

@ -8,6 +8,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/mgmt/mcumgr/transport/smp_bt.h>
#define LOG_LEVEL LOG_LEVEL_DBG
@ -43,7 +44,7 @@ static void advertise(struct k_work *work)
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
LOG_ERR("Connection failed (err 0x%02x)", err);
LOG_ERR("Connection failed, err 0x%02x %s", err, bt_hci_err_to_str(err));
} else {
LOG_INF("Connected");
}
@ -53,7 +54,7 @@ static void connected(struct bt_conn *conn, uint8_t err)
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
LOG_INF("Disconnected (reason 0x%02x)", reason);
LOG_INF("Disconnected, reason 0x%02x %s", reason, bt_hci_err_to_str(reason));
}
static void on_conn_recycled(void)

View file

@ -741,8 +741,8 @@ static void connected(struct bt_conn *conn, uint8_t err)
conn_addr_str(conn, addr, sizeof(addr));
if (err) {
shell_error(ctx_shell, "Failed to connect to %s (0x%02x)", addr,
err);
shell_error(ctx_shell, "Failed to connect to %s 0x%02x %s", addr,
err, bt_hci_err_to_str(err));
goto done;
}