From 700328ac55015607169cd67dfda15d4420086956 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 6 Dec 2017 14:59:09 +0100 Subject: [PATCH] Bluetooth: Introduce Bluetooth Testing API This introduces Bluetooth internal API intended to be used for qualification purposes. Application may register callbacks to get data that is not exposed by public API. Signed-off-by: Mariusz Skamra --- subsys/bluetooth/host/CMakeLists.txt | 1 + subsys/bluetooth/host/Kconfig | 6 +++++ subsys/bluetooth/host/mesh/transport.c | 6 +++++ subsys/bluetooth/host/testing.c | 35 ++++++++++++++++++++++++++ subsys/bluetooth/host/testing.h | 23 +++++++++++++++++ 5 files changed, 71 insertions(+) create mode 100644 subsys/bluetooth/host/testing.c create mode 100644 subsys/bluetooth/host/testing.h diff --git a/subsys/bluetooth/host/CMakeLists.txt b/subsys/bluetooth/host/CMakeLists.txt index 8172067f51c..856cb1585f5 100644 --- a/subsys/bluetooth/host/CMakeLists.txt +++ b/subsys/bluetooth/host/CMakeLists.txt @@ -12,6 +12,7 @@ zephyr_library_sources_ifdef(CONFIG_BT_TINYCRYPT_ECC hci_ecc.c) zephyr_library_sources_ifdef(CONFIG_BT_A2DP a2dp.c) zephyr_library_sources_ifdef(CONFIG_BT_AVDTP avdtp.c) zephyr_library_sources_ifdef(CONFIG_BT_RFCOMM rfcomm.c) +zephyr_library_sources_ifdef(CONFIG_BT_TESTING testing.c) zephyr_library_sources_ifdef( CONFIG_BT_BREDR diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 923959a2bf3..927c43b3f79 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -444,6 +444,12 @@ config BT_DEBUG_SDP This option enables debug support for the Bluetooth Service Discovery Protocol (SDP). +config BT_TESTING + bool "Bluetooth Testing" + help + This option enables custom Bluetooth testing interface. + Shall only be used for testing purposes. + endif # BT_DEBUG config BT_BREDR diff --git a/subsys/bluetooth/host/mesh/transport.c b/subsys/bluetooth/host/mesh/transport.c index 1aed995aea5..592c6448652 100644 --- a/subsys/bluetooth/host/mesh/transport.c +++ b/subsys/bluetooth/host/mesh/transport.c @@ -30,6 +30,7 @@ #include "access.h" #include "foundation.h" #include "transport.h" +#include "../testing.h" #define AID_MASK ((u8_t)(BIT_MASK(6))) @@ -1276,6 +1277,11 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx) BT_DBG("Payload %s", bt_hex(buf->data, buf->len)); + if (IS_ENABLED(CONFIG_BT_TESTING)) { + bt_test_mesh_net_recv(rx->ctx.recv_ttl, rx->ctl, rx->ctx.addr, + rx->dst, buf->data, buf->len); + } + /* If LPN mode is enabled messages are only accepted when we've * requested the Friend to send them. The messages must also * be encrypted using the Friend Credentials. diff --git a/subsys/bluetooth/host/testing.c b/subsys/bluetooth/host/testing.c new file mode 100644 index 00000000000..97761a83af9 --- /dev/null +++ b/subsys/bluetooth/host/testing.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include "testing.h" + +static sys_slist_t cb_slist; + +void bt_test_cb_register(struct bt_test_cb *cb) +{ + sys_slist_append(&cb_slist, &cb->node); +} + +void bt_test_cb_unregister(struct bt_test_cb *cb) +{ + sys_slist_find_and_remove(&cb_slist, &cb->node); +} + +void bt_test_mesh_net_recv(u8_t ttl, u8_t ctl, u16_t src, u16_t dst, + const void *payload, size_t payload_len) +{ + struct bt_test_cb *cb; + + SYS_SLIST_FOR_EACH_CONTAINER(&cb_slist, cb, node) { + if (cb->mesh_net_recv) { + cb->mesh_net_recv(ttl, ctl, src, dst, payload, + payload_len); + } + } +} diff --git a/subsys/bluetooth/host/testing.h b/subsys/bluetooth/host/testing.h new file mode 100644 index 00000000000..49d5f8c6ec5 --- /dev/null +++ b/subsys/bluetooth/host/testing.h @@ -0,0 +1,23 @@ +/** + * @file testing.h + * @brief Internal API for Bluetooth testing. + */ + +/* + * Copyright (c) 2017 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +struct bt_test_cb { + void (*mesh_net_recv)(u8_t ttl, u8_t ctl, u16_t src, u16_t dst, + const void *payload, size_t payload_len); + + sys_snode_t node; +}; + +void bt_test_cb_register(struct bt_test_cb *cb); +void bt_test_cb_unregister(struct bt_test_cb *cb); + +void bt_test_mesh_net_recv(u8_t ttl, u8_t ctl, u16_t src, u16_t dst, + const void *payload, size_t payload_len);