2019-01-07 02:16:47 -05:00
|
|
|
/*
|
2021-10-26 04:24:54 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nordic Semiconductor ASA
|
|
|
|
* SPDX-FileCopyrightText: 2016 Vinayak Kariappa Chettimada
|
|
|
|
* SPDX-FileCopyrightText: 2015-2016 Intel Corporation
|
2019-01-07 02:16:47 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2023-02-28 03:35:24 -05:00
|
|
|
#include <errno.h>
|
2020-01-19 05:57:13 -05:00
|
|
|
|
|
|
|
#include "mesh_types.h"
|
2019-01-07 02:16:47 -05:00
|
|
|
#include "mesh_util.h"
|
2023-02-28 03:35:24 -05:00
|
|
|
#include "mesh_trace.h"
|
2019-01-07 02:16:47 -05:00
|
|
|
|
|
|
|
const char *bt_hex(const void *buf, size_t len)
|
|
|
|
{
|
|
|
|
static const char hex[] = "0123456789abcdef";
|
2020-06-09 22:47:30 -04:00
|
|
|
static char hexbufs[2][129];
|
2020-12-07 04:03:11 -05:00
|
|
|
static uint8_t curbuf;
|
|
|
|
const uint8_t *b = buf;
|
2020-06-09 22:47:30 -04:00
|
|
|
char *str = NULL;
|
2019-01-07 02:16:47 -05:00
|
|
|
int i;
|
|
|
|
|
2020-06-09 22:47:30 -04:00
|
|
|
str = hexbufs[curbuf++];
|
|
|
|
curbuf %= ARRAY_SIZE(hexbufs);
|
|
|
|
|
|
|
|
len = MIN(len, (sizeof(hexbufs[0]) - 1) / 2);
|
2019-01-07 02:16:47 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-12-07 04:03:11 -05:00
|
|
|
void mem_rcopy(uint8_t *dst, uint8_t const *src, uint16_t len)
|
2019-01-07 02:16:47 -05:00
|
|
|
{
|
|
|
|
src += len;
|
|
|
|
while (len--) {
|
|
|
|
*dst++ = *--src;
|
|
|
|
}
|
|
|
|
}
|
2023-02-28 03:35:24 -05:00
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2023-03-21 23:28:29 -04:00
|
|
|
switch (op) {
|
2023-02-28 03:35:24 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-03-16 02:23:22 -04:00
|
|
|
int bt_mesh_bqb_test_flag_set(uint32_t flag_mask)
|
2023-02-28 03:35:24 -05:00
|
|
|
{
|
2023-03-21 23:28:29 -04:00
|
|
|
if (flag_mask > BLE_MESH_BQB_TEST_LOG_LEVEL_OUTPUT_NONE) {
|
2023-03-16 02:23:22 -04:00
|
|
|
BT_ERR("Invalid BQB test flag mask 0x%08x", flag_mask);
|
2023-02-28 03:35:24 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2023-03-16 02:23:22 -04:00
|
|
|
|
|
|
|
return (bt_mesh_bqb_test_flag(BLE_MESH_BQB_TEST_FLAG_OP_SET, flag_mask) == flag_mask) ? 0 : -EINVAL;
|
2023-02-28 03:35:24 -05:00
|
|
|
}
|
|
|
|
|
2023-03-16 02:23:22 -04:00
|
|
|
bool bt_mesh_bqb_test_flag_check(uint32_t flag_mask)
|
2023-02-28 03:35:24 -05:00
|
|
|
{
|
2023-03-21 23:28:29 -04:00
|
|
|
if (flag_mask > BLE_MESH_BQB_TEST_LOG_LEVEL_OUTPUT_NONE) {
|
2023-03-16 02:23:22 -04:00
|
|
|
BT_ERR("Invalid BQB test flag mask 0x%08x", flag_mask);
|
2023-02-28 03:35:24 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-16 02:23:22 -04:00
|
|
|
return ((bt_mesh_bqb_test_flag_get() & flag_mask) == flag_mask);
|
2023-02-28 03:35:24 -05:00
|
|
|
}
|
2023-03-16 02:23:22 -04:00
|
|
|
|
2023-02-28 03:35:24 -05:00
|
|
|
#endif /* CONFIG_BLE_MESH_BQB_TEST_LOG */
|