Skip to content

Commit 77509e8

Browse files
maje-embrlubos
authored andcommitted
bluetooth: rpc: Added functions for internal use
Added serialization of functions required by bluetooth tester application. Ref: NCSDK-13233 Signed-off-by: Marcin Jeliński <[email protected]>
1 parent 505c251 commit 77509e8

File tree

7 files changed

+110
-1
lines changed

7 files changed

+110
-1
lines changed

subsys/bluetooth/rpc/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ config BT_RPC_GATT_BUFFER_SIZE
108108

109109
endif # BT_RPC_HOST
110110

111+
config BT_RPC_INTERNAL_FUNCTIONS
112+
bool "Internal functions"
113+
default n
114+
help
115+
Enable functionality required for internal purposes e.g. testing.
116+
111117
endif # BT_RPC
112118

113119
choice BT_STACK_SELECTION

subsys/bluetooth/rpc/client/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ zephyr_library_sources_ifdef(
2222
zephyr_library_sources(
2323
${ZEPHYR_BASE}/subsys/bluetooth/host/uuid.c
2424
)
25+
26+
zephyr_library_sources_ifdef(
27+
CONFIG_BT_RPC_INTERNAL_FUNCTIONS
28+
bt_rpc_internal_client.c
29+
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* Copyright (c) 2022 Nordic Semiconductor ASA
2+
*
3+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
4+
*/
5+
6+
#include <zephyr.h>
7+
8+
#include <nrf_rpc_cbor.h>
9+
10+
#include "bt_rpc_common.h"
11+
#include "serialize.h"
12+
#include "cbkproxy.h"
13+
14+
#include <logging/log.h>
15+
16+
LOG_MODULE_DECLARE(BT_RPC, CONFIG_BT_RPC_LOG_LEVEL);
17+
18+
bool bt_addr_le_is_bonded(uint8_t id, const bt_addr_le_t *addr)
19+
{
20+
struct nrf_rpc_cbor_ctx ctx;
21+
bool result;
22+
size_t buffer_size_max = 5;
23+
24+
buffer_size_max += addr ? sizeof(bt_addr_le_t) : 0;
25+
26+
NRF_RPC_CBOR_ALLOC(ctx, buffer_size_max);
27+
28+
ser_encode_uint(&ctx.encoder, id);
29+
ser_encode_buffer(&ctx.encoder, addr, sizeof(bt_addr_le_t));
30+
nrf_rpc_cbor_cmd_no_err(&bt_rpc_grp, BT_ADDR_LE_IS_BONDED_CMD,
31+
&ctx, ser_rsp_decode_bool, &result);
32+
33+
return result;
34+
}

subsys/bluetooth/rpc/common/bt_rpc_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static const CHECK_LIST_ENTRY_TYPE check_table[] = {
224224
CHECK_FLAGS(
225225
CONFIG_BT_SETTINGS,
226226
CONFIG_BT_GATT_CLIENT,
227-
0,
227+
CONFIG_BT_INTERNAL_FUNCTIONS,
228228
0,
229229
0,
230230
0,

subsys/bluetooth/rpc/common/bt_rpc_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ enum bt_rpc_cmd_from_cli_to_host {
132132
BT_ENCRYPT_BE_RPC_CMD,
133133
BT_CCM_DECRYPT_RPC_CMD,
134134
BT_CCM_ENCRYPT_RPC_CMD,
135+
/* internal.h API */
136+
BT_ADDR_LE_IS_BONDED_CMD,
135137
};
136138

137139
/** @brief Host commands IDs used in bluetooth API serialization.

subsys/bluetooth/rpc/host/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ zephyr_library_sources_ifdef(
1717
bt_rpc_conn_host.c
1818
bt_rpc_gatt_host.c
1919
)
20+
21+
zephyr_library_sources_ifdef(
22+
CONFIG_BT_RPC_INTERNAL_FUNCTIONS
23+
bt_rpc_internal_host.c
24+
)
25+
26+
zephyr_library_include_directories_ifdef(
27+
CONFIG_BT_RPC_INTERNAL_FUNCTIONS
28+
${ZEPHYR_BASE}/subsys/bluetooth/host
29+
)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2022 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr.h>
8+
9+
#include <bluetooth/conn.h>
10+
#include <hci_core.h>
11+
12+
#include <nrf_rpc_cbor.h>
13+
14+
#include "bt_rpc_common.h"
15+
#include "serialize.h"
16+
#include "cbkproxy.h"
17+
18+
#include <logging/log.h>
19+
20+
LOG_MODULE_DECLARE(BT_RPC, CONFIG_BT_RPC_LOG_LEVEL);
21+
22+
static void report_decoding_error(uint8_t cmd_evt_id, void *data)
23+
{
24+
nrf_rpc_err(-EBADMSG, NRF_RPC_ERR_SRC_RECV, &bt_rpc_grp, cmd_evt_id,
25+
NRF_RPC_PACKET_TYPE_CMD);
26+
}
27+
28+
static void bt_addr_le_is_bonded_rpc_handler(CborValue *value, void *handler_data)
29+
{
30+
bt_addr_le_t addr_data;
31+
const bt_addr_le_t *addr;
32+
uint8_t id;
33+
bool result;
34+
35+
id = ser_decode_uint(value);
36+
addr = ser_decode_buffer(value, &addr_data, sizeof(bt_addr_le_t));
37+
38+
if (!ser_decoding_done_and_check(value)) {
39+
goto decoding_error;
40+
}
41+
42+
result = bt_addr_le_is_bonded(id, addr);
43+
ser_rsp_send_bool(result);
44+
45+
return;
46+
47+
decoding_error:
48+
report_decoding_error(BT_ADDR_LE_IS_BONDED_CMD, handler_data);
49+
}
50+
51+
NRF_RPC_CBOR_CMD_DECODER(bt_rpc_grp, bt_addr_le_is_bonded, BT_ADDR_LE_IS_BONDED_CMD,
52+
bt_addr_le_is_bonded_rpc_handler, NULL);

0 commit comments

Comments
 (0)