diff --git a/components/bt/esp_ble_mesh/Kconfig.in b/components/bt/esp_ble_mesh/Kconfig.in index beb72faa0b..0a5492094e 100644 --- a/components/bt/esp_ble_mesh/Kconfig.in +++ b/components/bt/esp_ble_mesh/Kconfig.in @@ -1132,6 +1132,19 @@ if BLE_MESH This option adds extra self-tests which are run every time BLE Mesh networking is initialized. + config BLE_MESH_BQB_TEST + bool + default n + help + This option is used to enable some internal functions for auto-pts test. + + config BLE_MESH_BQB_TEST_LOG + bool + depends on BLE_MESH_BQB_TEST + default y + help + This option is used to enable the log of auto-pts test. + if BLE_MESH_SELF_TEST config BLE_MESH_TEST_AUTO_ENTER_NETWORK diff --git a/components/bt/esp_ble_mesh/mesh_common/include/mesh_trace.h b/components/bt/esp_ble_mesh/mesh_common/include/mesh_trace.h index 72ad111ac3..c0f5874a55 100644 --- a/components/bt/esp_ble_mesh/mesh_common/include/mesh_trace.h +++ b/components/bt/esp_ble_mesh/mesh_common/include/mesh_trace.h @@ -120,6 +120,52 @@ extern "C" { #define NET_BUF_SIMPLE_ASSERT(cond) #endif +#if CONFIG_BLE_MESH_BQB_TEST_LOG +/** + * For example, the test case "MESH/NODE/TNPT/BV-01-C" + * could use BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_TNPT, "msg %s", msg) + * to print some message. + */ +enum BLE_MESH_BQB_TEST_LOG_LEVEL { + BLE_MESH_BQB_TEST_LOG_LEVEL_OUTPUT_ALL = 0, /* Output all BQB related test log */ + BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE = BIT(0), + BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_PVNR = BIT(1), + BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_CFGCL = BIT(2), + BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_SR = BIT(3), + BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_CL = BIT(4), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_PBADV = BIT(5), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_MPS = BIT(6), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_PROV = BIT(7), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_BCN = BIT(8), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_NET = BIT(9), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_RLY = BIT(10), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_TNPT = BIT(11), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_IVU = BIT(12), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_KR = BIT(13), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_FRND_FN = BIT(14), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_FRND_LPN = BIT(15), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_PROX = BIT(16), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_MPXS = BIT(17), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_CFG = BIT(18), + BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_HM = BIT(19), +}; + +#define BLE_MESH_BQB_TEST_LOG_LEVEL_OUTPUT_NONE 0x000FFFFF + +#endif /* CONFIG_BLE_MESH_BQB_TEST_LOG */ + +#if (CONFIG_BLE_MESH_BQB_TEST_LOG && !CONFIG_BLE_MESH_NO_LOG) +extern bool bt_mesh_bqb_test_flag_check(uint32_t module_mask); +extern int bt_mesh_bqb_test_flag_set(uint32_t value); +#define BT_BQB(module_mask, fmt, args...) \ + do { \ + if (bt_mesh_bqb_test_flag_check(module_mask)) \ + BLE_MESH_PRINT_I("BLE_MESH_BQB", fmt, ## args); \ + } while (0) +#else +#define BT_BQB(module_mask, fmt, args...) +#endif + #ifdef __cplusplus } #endif diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_util.c b/components/bt/esp_ble_mesh/mesh_common/mesh_util.c index 79cfd3fc07..34ca9766c7 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_util.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_util.c @@ -7,9 +7,11 @@ */ #include +#include #include "mesh_types.h" #include "mesh_util.h" +#include "mesh_trace.h" const char *bt_hex(const void *buf, size_t len) { @@ -42,3 +44,53 @@ void mem_rcopy(uint8_t *dst, uint8_t const *src, uint16_t len) *dst++ = *--src; } } + +#ifdef CONFIG_BLE_MESH_BQB_TEST_LOG + +enum BLE_MESH_BQB_TEST_FLAG_OP { + BLE_MESH_BQB_TEST_FLAG_OP_GET = 0, + BLE_MESH_BQB_TEST_FLAG_OP_SET, +}; + +static uint32_t bt_mesh_bqb_test_flag(uint8_t op, uint32_t value) +{ + static uint32_t bqb_log_flag = 0; + + switch (operation) { + case BLE_MESH_BQB_TEST_FLAG_OP_GET: + break; + case BLE_MESH_BQB_TEST_FLAG_OP_SET: + bqb_log_flag = value; + break; + default: + BT_ERR("Unknown BQB test flag opcode 0x%02x", op); + break; + } + + return bqb_log_flag; +} + +uint32_t bt_mesh_bqb_test_flag_get(void) +{ + return bt_mesh_bqb_test_flag(BLE_MESH_BQB_TEST_FLAG_OP_GET, 0); +} + +int bt_mesh_bqb_test_flag_set(uint32_t module_mask) +{ + if (module_mask > BLE_MESH_BQB_TEST_LOG_LEVEL_OUTPUT_NONE) { + BT_ERR("BT_BQB module mask error : overflow"); + return -EINVAL; + } + return (bt_mesh_bqb_test_flag(BLE_MESH_BQB_TEST_FLAG_OP_SET, module_mask) == module_mask) ? 0 : -EINVAL; +} + +bool bt_mesh_bqb_test_flag_check(uint32_t module_mask) +{ + if (module_mask > BLE_MESH_BQB_TEST_LOG_LEVEL_OUTPUT_NONE) { + BT_ERR("BT_BQB module mask error : overflow"); + return false; + } + + return ((bt_mesh_bqb_test_flag_get() & module_mask) == module_mask); +} +#endif /* CONFIG_BLE_MESH_BQB_TEST_LOG */