From 85eadcfddcf43e08da412594666d3e6a2ef05b07 Mon Sep 17 00:00:00 2001 From: Rubin Gerritsen Date: Fri, 5 Jul 2024 09:46:57 +0200 Subject: [PATCH] Bluetooth: Mark bt__err_to_str() APIs experimental It was pointed out in a future PR that they should have a corresponding experimental Kconfig entry. See PR #73795. This updates the APIs added in PR #73826 and PR #74295. Signed-off-by: Rubin Gerritsen --- include/zephyr/bluetooth/att.h | 11 +++++++++++ include/zephyr/bluetooth/conn.h | 11 +++++++++++ include/zephyr/bluetooth/gatt.h | 2 ++ include/zephyr/bluetooth/hci.h | 11 +++++++++++ subsys/bluetooth/common/Kconfig | 8 ++++++++ subsys/bluetooth/common/bt_str.c | 2 ++ subsys/bluetooth/host/Kconfig | 17 +++++++++++++++++ subsys/bluetooth/host/Kconfig.gatt | 8 ++++++++ subsys/bluetooth/host/att.c | 3 ++- subsys/bluetooth/host/smp.c | 5 ++++- subsys/bluetooth/host/smp.h | 9 +++++++++ tests/bluetooth/gatt/prj.conf | 1 + tests/bluetooth/hci/prj.conf | 1 + tests/bluetooth/smp/prj.conf | 2 ++ 14 files changed, 89 insertions(+), 2 deletions(-) diff --git a/include/zephyr/bluetooth/att.h b/include/zephyr/bluetooth/att.h index 0594a674cc6..9550848cb7d 100644 --- a/include/zephyr/bluetooth/att.h +++ b/include/zephyr/bluetooth/att.h @@ -112,8 +112,19 @@ extern "C" { * See also the defined BT_ATT_ERR_* macros. * * @return The string representation of the ATT error code. + * If @kconfig{CONFIG_BT_ATT_ERR_TO_STR} is not enabled, + * this just returns the empty string */ +#if defined(CONFIG_BT_ATT_ERR_TO_STR) const char *bt_att_err_to_str(uint8_t att_err); +#else +static inline const char *bt_att_err_to_str(uint8_t att_err) +{ + ARG_UNUSED(att_err); + + return ""; +} +#endif #if defined(CONFIG_BT_EATT) #if defined(CONFIG_BT_TESTING) diff --git a/include/zephyr/bluetooth/conn.h b/include/zephyr/bluetooth/conn.h index 84d20336323..5a5525df44a 100644 --- a/include/zephyr/bluetooth/conn.h +++ b/include/zephyr/bluetooth/conn.h @@ -1285,8 +1285,19 @@ int bt_conn_cb_unregister(struct bt_conn_cb *cb); /** Converts a security error to string. * * @return The string representation of the security error code. + * If @kconfig{CONFIG_BT_SECURITY_ERR_TO_STR} is not enabled, + * this just returns the empty string */ +#if defined(CONFIG_BT_SECURITY_ERR_TO_STR) const char *bt_security_err_to_str(enum bt_security_err err); +#else +static inline const char *bt_security_err_to_str(enum bt_security_err err) +{ + ARG_UNUSED(err); + + return ""; +} +#endif /** @brief Enable/disable bonding. * diff --git a/include/zephyr/bluetooth/gatt.h b/include/zephyr/bluetooth/gatt.h index 6813f417ded..78a6aab25fa 100644 --- a/include/zephyr/bluetooth/gatt.h +++ b/include/zephyr/bluetooth/gatt.h @@ -413,6 +413,8 @@ struct bt_gatt_cpf { * See also the defined BT_ATT_ERR_* macros. * * @return The string representation of the GATT error code. + * If @kconfig{CONFIG_BT_ATT_ERR_TO_STR} is not enabled, + * this just returns the empty string. */ static inline const char *bt_gatt_err_to_str(int gatt_err) { diff --git a/include/zephyr/bluetooth/hci.h b/include/zephyr/bluetooth/hci.h index 7dfcb227527..21b6925ea33 100644 --- a/include/zephyr/bluetooth/hci.h +++ b/include/zephyr/bluetooth/hci.h @@ -31,8 +31,19 @@ extern "C" { * See also the defined BT_HCI_ERR_* macros. * * @return The string representation of the HCI error code. + * If @kconfig{CONFIG_BT_HCI_ERR_TO_STR} is not enabled, + * this just returns the empty string */ +#if defined(CONFIG_BT_HCI_ERR_TO_STR) const char *bt_hci_err_to_str(uint8_t hci_err); +#else +static inline const char *bt_hci_err_to_str(uint8_t hci_err) +{ + ARG_UNUSED(hci_err); + + return ""; +} +#endif /** Allocate a HCI command buffer. * diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index 5d9a746a8d5..125521f68a3 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -257,6 +257,14 @@ config BT_ASSERT_PANIC endif # BT_ASSERT +config BT_HCI_ERR_TO_STR + bool "Print HCI error codes as strings [EXPERIMENTAL]" + select EXPERIMENTAL + help + This configuration enables printing of HCI error + codes represented as strings. + See bt_hci_err_to_str() for more details. + config BT_MONITOR bool select LOG_OUTPUT diff --git a/subsys/bluetooth/common/bt_str.c b/subsys/bluetooth/common/bt_str.c index 08247931989..7e8e8d9f2e2 100644 --- a/subsys/bluetooth/common/bt_str.c +++ b/subsys/bluetooth/common/bt_str.c @@ -62,6 +62,7 @@ const char *bt_uuid_str(const struct bt_uuid *uuid) return str; } +#if defined(CONFIG_BT_HCI_ERR_TO_STR) const char *bt_hci_err_to_str(uint8_t hci_err) { #define HCI_ERR(err) [err] = #err @@ -146,3 +147,4 @@ const char *bt_hci_err_to_str(uint8_t hci_err) #undef HCI_ERR } +#endif /* CONFIG_BT_HCI_ERR_TO_STR */ diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 3445c9b5517..0236f3f1326 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -363,6 +363,23 @@ config BT_SMP (SMP), making it possible to pair devices over LE. if BT_SMP + +config BT_SECURITY_ERR_TO_STR + bool "Print security error codes as strings [EXPERIMENTAL]" + select EXPERIMENTAL + help + This configuration enables printing of security error + codes represented as strings. + See bt_security_err_to_str() for more details. + +config BT_SMP_ERR_TO_STR + bool "Print SMP error codes as strings [EXPERIMENTAL]" + select EXPERIMENTAL + help + This configuration enables printing of SMP error + codes represented as strings. + See bt_smp_err_to_str() for more details. + config BT_PASSKEY_KEYPRESS bool "Passkey Keypress Notification support [EXPERIMENTAL]" select EXPERIMENTAL diff --git a/subsys/bluetooth/host/Kconfig.gatt b/subsys/bluetooth/host/Kconfig.gatt index 45e3fa8e4fc..3c6702e2928 100644 --- a/subsys/bluetooth/host/Kconfig.gatt +++ b/subsys/bluetooth/host/Kconfig.gatt @@ -5,6 +5,14 @@ menu "ATT and GATT Options" +config BT_ATT_ERR_TO_STR + bool "Print ATT error codes as strings [EXPERIMENTAL]" + select EXPERIMENTAL + help + This configuration enables printing of ATT error + codes represented as strings. + See bt_att_err_to_str() for more details. + config BT_ATT_TX_COUNT int "Number of ATT buffers" default BT_BUF_ACL_TX_COUNT diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index a7ba44f5dbc..1cf5bebe555 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -185,7 +185,7 @@ static struct bt_att_tx_meta_data tx_meta_data_storage[CONFIG_BT_ATT_TX_COUNT]; struct bt_att_tx_meta_data *bt_att_get_tx_meta_data(const struct net_buf *buf); static void att_on_sent_cb(struct bt_att_tx_meta_data *meta); - +#if defined(CONFIG_BT_ATT_ERR_TO_STR) const char *bt_att_err_to_str(uint8_t att_err) { /* To mapping tables are used to avoid a big gap with NULL-entries. */ @@ -239,6 +239,7 @@ const char *bt_att_err_to_str(uint8_t att_err) #undef ATT_ERR #undef ATT_ERR_SECOND } +#endif /* CONFIG_BT_ATT_ERR_TO_STR */ static void att_tx_destroy(struct net_buf *buf) { diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 5138011e0a9..84f5277ecc8 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -475,6 +475,7 @@ static enum bt_security_err security_err_get(uint8_t smp_err) } } +#if defined(CONFIG_BT_SECURITY_ERR_TO_STR) const char *bt_security_err_to_str(enum bt_security_err err) { #define SEC_ERR(err) [err] = #err @@ -500,7 +501,7 @@ const char *bt_security_err_to_str(enum bt_security_err err) #undef SEC_ERR } - +#endif /* CONFIG_BT_SECURITY_ERR_TO_STR */ static uint8_t smp_err_get(enum bt_security_err auth_err) { @@ -527,6 +528,7 @@ static uint8_t smp_err_get(enum bt_security_err auth_err) } } +#if defined(CONFIG_BT_SMP_ERR_TO_STR) const char *bt_smp_err_to_str(uint8_t smp_err) { #define SMP_ERR(err) [err] = #err @@ -558,6 +560,7 @@ const char *bt_smp_err_to_str(uint8_t smp_err) #undef SMP_ERR } +#endif /* CONFIG_BT_SMP_ERR_TO_STR */ static struct net_buf *smp_create_pdu(struct bt_smp *smp, uint8_t op, size_t len) { diff --git a/subsys/bluetooth/host/smp.h b/subsys/bluetooth/host/smp.h index 3ec68d3b670..51969aaadfb 100644 --- a/subsys/bluetooth/host/smp.h +++ b/subsys/bluetooth/host/smp.h @@ -192,4 +192,13 @@ int bt_smp_irk_get(uint8_t *ir, uint8_t *irk); * * @return The string representation of the SMP error code. */ +#if defined(CONFIG_BT_SMP_ERR_TO_STR) const char *bt_smp_err_to_str(uint8_t smp_err); +#else +static inline const char *bt_smp_err_to_str(uint8_t smp_err) +{ + ARG_UNUSED(smp_err); + + return ""; +} +#endif diff --git a/tests/bluetooth/gatt/prj.conf b/tests/bluetooth/gatt/prj.conf index f705142d552..88706f76035 100644 --- a/tests/bluetooth/gatt/prj.conf +++ b/tests/bluetooth/gatt/prj.conf @@ -8,3 +8,4 @@ CONFIG_BT_H4=n CONFIG_LOG=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_GATT_DYNAMIC_DB=y +CONFIG_BT_ATT_ERR_TO_STR=y diff --git a/tests/bluetooth/hci/prj.conf b/tests/bluetooth/hci/prj.conf index 1f86a43c208..dc7e7ba5a4f 100644 --- a/tests/bluetooth/hci/prj.conf +++ b/tests/bluetooth/hci/prj.conf @@ -4,3 +4,4 @@ CONFIG_ZTEST=y CONFIG_BT=y CONFIG_BT_CTLR=n CONFIG_BT_H4=n +CONFIG_BT_HCI_ERR_TO_STR=y diff --git a/tests/bluetooth/smp/prj.conf b/tests/bluetooth/smp/prj.conf index a5d4251d5ff..0b6afd9a57b 100644 --- a/tests/bluetooth/smp/prj.conf +++ b/tests/bluetooth/smp/prj.conf @@ -8,3 +8,5 @@ CONFIG_BT_H4=n CONFIG_LOG=y CONFIG_BT_PERIPHERAL=y +CONFIG_BT_SMP_ERR_TO_STR=y +CONFIG_BT_SECURITY_ERR_TO_STR=y