Bluetooth: Move out string related function of common/log.h

Functions related to string manipulation that were defined in
`common/log.h` has been moved to the `common/bt_str.h` file and their
implementation in `common/bt_str.c`.

Files that were using those functions has been updated consequently.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
This commit is contained in:
Théo Battrel 2022-10-25 08:48:54 +02:00 committed by Carles Cufí
commit c9d68a5a4f
59 changed files with 140 additions and 77 deletions

View file

@ -25,6 +25,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
#define LOG_MODULE_NAME bt_driver
#include "common/log.h"
#include "common/bt_str.h"
#include "../util.h"

View file

@ -40,6 +40,7 @@ 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"
#define HCI_CMD 0x01
#define HCI_ACL 0x02

View file

@ -25,6 +25,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_ASCS)
#define LOG_MODULE_NAME bt_ascs
#include "common/log.h"
#include "common/bt_str.h"
#include "common/assert.h"
#include "../host/hci_core.h"

View file

@ -23,6 +23,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_BASS)
#define LOG_MODULE_NAME bt_bass
#include "common/log.h"
#include "common/bt_str.h"
#include "audio_internal.h"
#include "bass_internal.h"

View file

@ -22,6 +22,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_BASS_CLIENT)
#define LOG_MODULE_NAME bt_bass_client
#include "common/log.h"
#include "common/bt_str.h"
#include "bass_internal.h"
#include "../host/conn_internal.h"

View file

@ -23,6 +23,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_AUDIO_DEBUG_BROADCAST_SINK)
#define LOG_MODULE_NAME bt_audio_broadcast_sink
#include "common/log.h"
#include "common/bt_str.h"
#define PA_SYNC_SKIP 5
#define SYNC_RETRY_COUNT 6 /* similar to retries for connections */

View file

@ -35,6 +35,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_CSIS)
#define LOG_MODULE_NAME bt_csis
#include "common/log.h"
#include "common/bt_str.h"
static struct bt_csis csis_insts[CONFIG_BT_CSIS_MAX_INSTANCE_COUNT];
static bt_addr_le_t server_dummy_addr; /* 0'ed address */

View file

@ -21,6 +21,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_CSIS_CRYPTO)
#define LOG_MODULE_NAME bt_csis_crypto
#include "common/log.h"
#include "common/bt_str.h"
#define BT_CSIS_CRYPTO_PADDING_SIZE 13
#define BT_CSIS_R_SIZE 3 /* r is 24 bit / 3 octet */

View file

@ -40,6 +40,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_MCC)
#define LOG_MODULE_NAME bt_mcc
#include "common/log.h"
#include "common/bt_str.h"
struct mcs_instance_t {
uint16_t start_handle;

View file

@ -23,6 +23,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_MICP_MIC_CTLR)
#define LOG_MODULE_NAME bt_micp_mic_ctlr
#include "common/log.h"
#include "common/bt_str.h"
/* Callback functions */
static struct bt_micp_mic_ctlr_cb *micp_mic_ctlr_cb;

View file

@ -26,6 +26,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_PACS)
#define LOG_MODULE_NAME bt_pacs
#include "common/log.h"
#include "common/bt_str.h"
#include "audio_internal.h"
#include "pacs_internal.h"

View file

@ -24,6 +24,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_TBS_CLIENT)
#define LOG_MODULE_NAME bt_tbs_client
#include "common/log.h"
#include "common/bt_str.h"
#define MAX_URI_SCHEME_LIST_SIZE 64
#if IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS)

View file

@ -25,6 +25,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_VCS_CLIENT)
#define LOG_MODULE_NAME bt_vcs_client
#include "common/log.h"
#include "common/bt_str.h"
/* Callback functions */
static struct bt_vcs_cb *vcs_client_cb;

View file

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

View file

@ -0,0 +1,63 @@
/* Copyright (c) 2022 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
/* Helper for printk parameters to convert from binary to hex.
* We declare multiple buffers so the helper can be used multiple times
* in a single printk call.
*/
#include <stddef.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/util.h>
#include <zephyr/types.h>
const char *bt_hex_real(const void *buf, size_t len)
{
static const char hex[] = "0123456789abcdef";
static char str[129];
const uint8_t *b = buf;
size_t i;
len = MIN(len, (sizeof(str) - 1) / 2);
for (i = 0; i < len; i++) {
str[i * 2] = hex[b[i] >> 4];
str[i * 2 + 1] = hex[b[i] & 0xf];
}
str[i * 2] = '\0';
return str;
}
const char *bt_addr_str_real(const bt_addr_t *addr)
{
static char str[BT_ADDR_STR_LEN];
bt_addr_to_str(addr, str, sizeof(str));
return str;
}
const char *bt_addr_le_str_real(const bt_addr_le_t *addr)
{
static char str[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(addr, str, sizeof(str));
return str;
}
const char *bt_uuid_str_real(const struct bt_uuid *uuid)
{
static char str[BT_UUID_STR_LEN];
bt_uuid_to_str(uuid, str, sizeof(str));
return str;
}

View file

@ -0,0 +1,22 @@
/* Copyright (c) 2022 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/uuid.h>
/* NOTE: These helper functions always encodes into the same buffer storage.
* It is the responsibility of the user of this function to copy the information
* in this string if needed.
*
* NOTE: These functions are not thread-safe!
*/
const char *bt_hex_real(const void *buf, size_t len);
const char *bt_addr_str_real(const bt_addr_t *addr);
const char *bt_addr_le_str_real(const bt_addr_le_t *addr);
const char *bt_uuid_str_real(const struct bt_uuid *uuid);
#define bt_hex(buf, len) bt_hex_real(buf, len)
#define bt_addr_str(addr) bt_addr_str_real(addr)
#define bt_addr_le_str(addr) bt_addr_le_str_real(addr)
#define bt_uuid_str(uuid) bt_uuid_str_real(uuid)

View file

@ -6,62 +6,3 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
/* Helper for printk parameters to convert from binary to hex.
* We declare multiple buffers so the helper can be used multiple times
* in a single printk call.
*/
#include <stddef.h>
#include <zephyr/types.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/util.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/hci.h>
const char *bt_hex_real(const void *buf, size_t len)
{
static const char hex[] = "0123456789abcdef";
static char str[129];
const uint8_t *b = buf;
size_t i;
len = MIN(len, (sizeof(str) - 1) / 2);
for (i = 0; i < len; i++) {
str[i * 2] = hex[b[i] >> 4];
str[i * 2 + 1] = hex[b[i] & 0xf];
}
str[i * 2] = '\0';
return str;
}
const char *bt_addr_str_real(const bt_addr_t *addr)
{
static char str[BT_ADDR_STR_LEN];
bt_addr_to_str(addr, str, sizeof(str));
return str;
}
const char *bt_addr_le_str_real(const bt_addr_le_t *addr)
{
static char str[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(addr, str, sizeof(str));
return str;
}
const char *bt_uuid_str_real(const struct bt_uuid *uuid)
{
static char str[BT_UUID_STR_LEN];
bt_uuid_to_str(uuid, str, sizeof(str));
return str;
}

View file

@ -16,8 +16,6 @@
#include <zephyr/logging/log.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/hci.h>
#ifdef __cplusplus
@ -41,22 +39,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL);
#define BT_WARN(fmt, ...) LOG_WRN(fmt, ##__VA_ARGS__)
#define BT_INFO(fmt, ...) LOG_INF(fmt, ##__VA_ARGS__)
/* NOTE: These helper functions always encodes into the same buffer storage.
* It is the responsibility of the user of this function to copy the information
* in this string if needed.
*
* NOTE: These functions are not thread-safe!
*/
const char *bt_hex_real(const void *buf, size_t len);
const char *bt_addr_str_real(const bt_addr_t *addr);
const char *bt_addr_le_str_real(const bt_addr_le_t *addr);
const char *bt_uuid_str_real(const struct bt_uuid *uuid);
#define bt_hex(buf, len) bt_hex_real(buf, len)
#define bt_addr_str(addr) bt_addr_str_real(addr)
#define bt_addr_le_str(addr) bt_addr_le_str_real(addr)
#define bt_uuid_str(uuid) bt_uuid_str_real(uuid)
#ifdef __cplusplus
}
#endif

View file

@ -18,6 +18,7 @@
#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 <zephyr/bluetooth/crypto.h>

View file

@ -7,6 +7,7 @@
#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 "util/memq.h"

View file

@ -92,6 +92,7 @@
#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 "hal/debug.h"
#define STR_NULL_TERMINATOR 0x00

View file

@ -20,6 +20,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE)
#define LOG_MODULE_NAME bt_adv
#include "common/log.h"
#include "common/bt_str.h"
enum adv_name_type {
ADV_NAME_TYPE_NONE,

View file

@ -14,6 +14,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE)
#define LOG_MODULE_NAME bt_aes_ccm
#include "common/log.h"
#include "common/bt_str.h"
static inline void xor16(uint8_t *dst, const uint8_t *a, const uint8_t *b)
{

View file

@ -24,6 +24,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_ATT)
#define LOG_MODULE_NAME bt_att
#include "common/log.h"
#include "common/bt_str.h"
#include "hci_core.h"
#include "conn_internal.h"

View file

@ -15,6 +15,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE)
#define LOG_MODULE_NAME bt_br
#include "common/log.h"
#include "common/bt_str.h"
#include "hci_core.h"
#include "conn_internal.h"

View file

@ -25,6 +25,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE)
#define LOG_MODULE_NAME bt_crypto
#include "common/log.h"
#include "common/bt_str.h"
#include "hci_core.h"

View file

@ -36,6 +36,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_GATT)
#define LOG_MODULE_NAME bt_gatt
#include "common/log.h"
#include "common/bt_str.h"
#include "hci_core.h"
#include "conn_internal.h"

View file

@ -31,6 +31,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE)
#define LOG_MODULE_NAME bt_hci_core
#include "common/log.h"
#include "common/bt_str.h"
#include "common/assert.h"
#include "common/rpa.h"

View file

@ -26,6 +26,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE)
#define LOG_MODULE_NAME bt_hci_ecc
#include "common/log.h"
#include "common/bt_str.h"
#include "hci_ecc.h"
#include "ecc.h"

View file

@ -32,6 +32,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE)
#define LOG_MODULE_NAME bt_id
#include "common/log.h"
#include "common/bt_str.h"
struct bt_adv_id_check_data {
uint8_t id;

View file

@ -23,6 +23,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_KEYS)
#define LOG_MODULE_NAME bt_keys
#include "common/log.h"
#include "common/bt_str.h"
#include "common/rpa.h"
#include "conn_internal.h"

View file

@ -19,6 +19,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_KEYS)
#define LOG_MODULE_NAME bt_keys_br
#include "common/log.h"
#include "common/bt_str.h"
#include "hci_core.h"
#include "settings.h"

View file

@ -25,6 +25,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE)
#define LOG_MODULE_NAME bt_scan
#include "common/log.h"
#include "common/bt_str.h"
static bt_le_scan_cb_t *scan_dev_found_cb;
static sys_slist_t scan_cbs = SYS_SLIST_STATIC_INIT(&scan_cbs);

View file

@ -19,6 +19,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_SDP)
#define LOG_MODULE_NAME bt_sdp
#include "common/log.h"
#include "common/bt_str.h"
#include "common/assert.h"
#include "hci_core.h"

View file

@ -15,6 +15,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_SETTINGS)
#define LOG_MODULE_NAME bt_settings
#include "common/log.h"
#include "common/bt_str.h"
#include "hci_core.h"
#include "settings.h"

View file

@ -34,6 +34,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_SMP)
#define LOG_MODULE_NAME bt_smp
#include "common/log.h"
#include "common/bt_str.h"
#include "hci_core.h"
#include "ecc.h"

View file

@ -16,6 +16,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE)
#define LOG_MODULE_NAME bt_ssp
#include "common/log.h"
#include "common/bt_str.h"
#include "keys.h"

View file

@ -17,6 +17,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_ACCESS)
#define LOG_MODULE_NAME bt_mesh_access
#include "common/log.h"
#include "common/bt_str.h"
#include "mesh.h"
#include "adv.h"

View file

@ -18,6 +18,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_ADV)
#define LOG_MODULE_NAME bt_mesh_adv
#include "common/log.h"
#include "common/bt_str.h"
#include "adv.h"
#include "net.h"

View file

@ -16,6 +16,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_ADV)
#define LOG_MODULE_NAME bt_mesh_adv_ext
#include "common/log.h"
#include "common/bt_str.h"
#include "host/hci_core.h"

View file

@ -18,6 +18,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_ADV)
#define LOG_MODULE_NAME bt_mesh_adv_legacy
#include "common/log.h"
#include "common/bt_str.h"
#include "host/hci_core.h"

View file

@ -24,6 +24,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_KEYS)
#define LOG_MODULE_NAME bt_mesh_app_keys
#include "common/log.h"
#include "common/bt_str.h"
/* Tracking of what storage changes are pending for App Keys. We track this in
* a separate array here instead of within the respective bt_mesh_app_key

View file

@ -16,6 +16,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_BEACON)
#define LOG_MODULE_NAME bt_mesh_beacon
#include "common/log.h"
#include "common/bt_str.h"
#include "adv.h"
#include "mesh.h"

View file

@ -15,6 +15,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_CDB)
#define LOG_MODULE_NAME bt_mesh_cdb
#include "common/log.h"
#include "common/bt_str.h"
#include "cdb.h"
#include "mesh.h"

View file

@ -20,6 +20,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL)
#define LOG_MODULE_NAME bt_mesh_cfg_cli
#include "common/log.h"
#include "common/bt_str.h"
#include "net.h"
#include "foundation.h"

View file

@ -19,6 +19,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL)
#define LOG_MODULE_NAME bt_mesh_cfg_srv
#include "common/log.h"
#include "common/bt_str.h"
#include "host/testing.h"

View file

@ -27,6 +27,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_CRYPTO)
#define LOG_MODULE_NAME bt_mesh_tc_crypto
#include "common/log.h"
#include "common/bt_str.h"
#include "mesh.h"
#include "crypto.h"

View file

@ -18,6 +18,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROXY)
#define LOG_MODULE_NAME bt_mesh_gatt_client
#include "common/log.h"
#include "common/bt_str.h"
#include "mesh.h"
#include "adv.h"

View file

@ -19,6 +19,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL)
#define LOG_MODULE_NAME bt_mesh_health_cli
#include "common/log.h"
#include "common/bt_str.h"
#include "net.h"
#include "foundation.h"

View file

@ -20,6 +20,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_NET)
#define LOG_MODULE_NAME bt_mesh_net
#include "common/log.h"
#include "common/bt_str.h"
#include "crypto.h"
#include "adv.h"

View file

@ -20,6 +20,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROV)
#define LOG_MODULE_NAME bt_mesh_pb_adv
#include "common/log.h"
#include "common/bt_str.h"
#define GPCF(gpc) (gpc & 0x03)
#define GPC_START(last_seg) (((last_seg) << 2) | 0x00)

View file

@ -19,6 +19,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROV)
#define LOG_MODULE_NAME bt_mesh_pb_gatt
#include "common/log.h"
#include "common/bt_str.h"
struct prov_bearer_send_cb {
prov_bearer_send_complete_t cb;

View file

@ -17,6 +17,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROV)
#define LOG_MODULE_NAME bt_mesh_pb_gatt_srv
#include "common/log.h"
#include "common/bt_str.h"
#include "mesh.h"
#include "adv.h"

View file

@ -20,6 +20,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROV_DEVICE)
#define LOG_MODULE_NAME bt_mesh_prov_device
#include "common/log.h"
#include "common/bt_str.h"
#include "host/ecc.h"
#include "host/testing.h"

View file

@ -21,6 +21,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROVISIONER)
#define LOG_MODULE_NAME bt_mesh_provisioner
#include "common/log.h"
#include "common/bt_str.h"
#include "host/ecc.h"
#include "host/testing.h"

View file

@ -19,6 +19,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROXY)
#define LOG_MODULE_NAME bt_mesh_proxy
#include "common/log.h"
#include "common/bt_str.h"
#include "mesh.h"
#include "adv.h"

View file

@ -17,6 +17,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROXY)
#define LOG_MODULE_NAME bt_mesh_gatt
#include "common/log.h"
#include "common/bt_str.h"
#include "mesh.h"
#include "adv.h"

View file

@ -22,6 +22,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_KEYS)
#define LOG_MODULE_NAME bt_mesh_net_keys
#include "common/log.h"
#include "common/bt_str.h"
#include "crypto.h"
#include "adv.h"

View file

@ -20,6 +20,7 @@
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_TRANS)
#define LOG_MODULE_NAME bt_mesh_transport
#include "common/log.h"
#include "common/bt_str.h"
#include "host/testing.h"