Skip to content

Commit a040c16

Browse files
alxelaxrlubos
authored andcommitted
net: openthread: rpc: use nrf rpc api to existing implementation
Part of BT rpc became NRF rpc public API. Commit adapts some OpenThread rpc implementation to this API. Signed-off-by: Aleksandr Khromykh <[email protected]>
1 parent 914924f commit a040c16

File tree

9 files changed

+84
-66
lines changed

9 files changed

+84
-66
lines changed

subsys/net/openthread/rpc/client/ot_rpc_cli_client.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,17 @@
55
*/
66

77
#include <ot_rpc_ids.h>
8+
#include <ot_rpc_common.h>
89

910
#include <nrf_rpc_cbor.h>
1011

1112
#include <openthread/cli.h>
1213

1314
#include <string.h>
1415

15-
NRF_RPC_GROUP_DECLARE(ot_group);
16-
1716
otCliOutputCallback cli_output_callback;
1817
void *cli_output_context;
1918

20-
static void decode_void(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
21-
void *handler_data)
22-
{
23-
ARG_UNUSED(group);
24-
ARG_UNUSED(ctx);
25-
ARG_UNUSED(handler_data);
26-
}
27-
2819
void otCliInit(otInstance *aInstance, otCliOutputCallback aCallback, void *aContext)
2920
{
3021
const size_t cbor_buffer_size = 0;
@@ -36,7 +27,7 @@ void otCliInit(otInstance *aInstance, otCliOutputCallback aCallback, void *aCont
3627

3728
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
3829

39-
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_CLI_INIT, &ctx, decode_void, NULL);
30+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_CLI_INIT, &ctx, ot_rpc_decode_void, NULL);
4031
}
4132

4233
void otCliInputLine(char *aBuf)
@@ -48,7 +39,8 @@ void otCliInputLine(char *aBuf)
4839
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
4940
zcbor_tstr_encode_ptr(ctx.zs, aBuf, buffer_len);
5041

51-
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_CLI_INPUT_LINE, &ctx, decode_void, NULL);
42+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_CLI_INPUT_LINE, &ctx, ot_rpc_decode_void,
43+
NULL);
5244
}
5345

5446
static void invoke_cli_output_callback(const char *format, ...)

subsys/net/openthread/rpc/client/ot_rpc_ctrl_client.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <ot_rpc_ids.h>
88
#include <ot_rpc_types.h>
9+
#include <ot_rpc_common.h>
910

1011
#include <nrf_rpc_cbor.h>
1112

@@ -17,19 +18,9 @@
1718

1819
#include <string.h>
1920

20-
NRF_RPC_GROUP_DECLARE(ot_group);
21-
2221
#define OT_RPC_MAX_NUM_UNICAST_ADDRESSES 8
2322
#define OT_RPC_MAX_NUM_MULTICAST_ADDRESSES 8
2423

25-
static void decode_void(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
26-
void *handler_data)
27-
{
28-
ARG_UNUSED(group);
29-
ARG_UNUSED(ctx);
30-
ARG_UNUSED(handler_data);
31-
}
32-
3324
static otError decode_ot_error(struct nrf_rpc_cbor_ctx *ctx)
3425
{
3526
otError error;
@@ -181,7 +172,7 @@ void otRemoveStateChangeCallback(otInstance *aInstance, otStateChangedCallback a
181172
zcbor_uint32_put(ctx.zs, (uint32_t)aContext);
182173

183174
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_REMOVE_STATE_CHANGED_CALLBACK, &ctx,
184-
decode_void, NULL);
175+
ot_rpc_decode_void, NULL);
185176
}
186177

187178
static void ot_rpc_cmd_state_changed(const struct nrf_rpc_group *group,

subsys/net/openthread/rpc/client/ot_rpc_if_client.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <ot_rpc_ids.h>
8+
#include <ot_rpc_common.h>
89

910
#include <nrf_rpc_cbor.h>
1011

@@ -15,17 +16,8 @@
1516
#include <zephyr/net/net_pkt.h>
1617
#include <zephyr/net/net_core.h>
1718

18-
NRF_RPC_GROUP_DECLARE(ot_group);
1919
LOG_MODULE_DECLARE(ot_rpc, LOG_LEVEL_DBG);
2020

21-
static void decode_void(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
22-
void *handler_data)
23-
{
24-
ARG_UNUSED(group);
25-
ARG_UNUSED(ctx);
26-
ARG_UNUSED(handler_data);
27-
}
28-
2921
struct ot_rpc_l2_data {
3022
};
3123

@@ -65,7 +57,7 @@ static int ot_rpc_l2_send(struct net_if *iface, struct net_pkt *pkt)
6557
NET_DBG("Sending Ip6 packet to RPC server");
6658

6759
encoded_ok = true;
68-
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_IF_SEND, &ctx, decode_void, NULL);
60+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_IF_SEND, &ctx, ot_rpc_decode_void, NULL);
6961

7062
out:
7163
if (!encoded_ok) {
@@ -191,7 +183,7 @@ static int ot_rpc_l2_enable(struct net_if *iface, bool state)
191183

192184
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
193185
zcbor_bool_put(ctx.zs, state);
194-
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_IF_ENABLE, &ctx, decode_void, NULL);
186+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_IF_ENABLE, &ctx, ot_rpc_decode_void, NULL);
195187

196188
if (state) {
197189
update_netif_addrs(iface);

subsys/net/openthread/rpc/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ zephyr_library()
88

99
zephyr_library_sources(
1010
ot_rpc_group.c
11+
ot_rpc_common.c
1112
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include "ot_rpc_common.h"
8+
9+
#include <nrf_rpc/nrf_rpc_serialize.h>
10+
11+
#include <openthread/dataset.h>
12+
13+
void ot_rpc_decode_error(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
14+
void *handler_data)
15+
{
16+
nrf_rpc_rsp_decode_i32(group, ctx, handler_data);
17+
}
18+
19+
void ot_rpc_decode_void(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
20+
void *handler_data)
21+
{
22+
nrf_rpc_rsp_decode_void(group, ctx, handler_data);
23+
}
24+
25+
void ot_rpc_decode_dataset_tlvs(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
26+
void *handler_data)
27+
{
28+
otOperationalDatasetTlvs *dataset = *(otOperationalDatasetTlvs **)handler_data;
29+
const void *data;
30+
size_t length;
31+
32+
data = nrf_rpc_decode_buffer_ptr_and_size(ctx, &length);
33+
34+
if (data == NULL) {
35+
handler_data = NULL;
36+
} else {
37+
dataset->mLength = length;
38+
memcpy(dataset->mTlvs, data, dataset->mLength);
39+
}
40+
}
41+
42+
void ot_rpc_report_decoding_error(uint8_t cmd_evt_id, void *data)
43+
{
44+
nrf_rpc_err(-EBADMSG, NRF_RPC_ERR_SRC_RECV, &ot_group, cmd_evt_id, NRF_RPC_PACKET_TYPE_CMD);
45+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef OT_RPC_COMMON_H_
8+
#define OT_RPC_COMMON_H_
9+
10+
#include <nrf_rpc_cbor.h>
11+
12+
NRF_RPC_GROUP_DECLARE(ot_group);
13+
14+
void ot_rpc_decode_error(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
15+
void *handler_data);
16+
void ot_rpc_decode_void(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
17+
void *handler_data);
18+
void ot_rpc_decode_dataset_tlvs(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
19+
void *handler_data);
20+
void ot_rpc_report_decoding_error(uint8_t cmd_evt_id, void *data);
21+
22+
#endif /* OT_RPC_COMMON_H_ */

subsys/net/openthread/rpc/server/ot_rpc_cli_server.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <ot_rpc_ids.h>
8+
#include <ot_rpc_common.h>
89

910
#include <nrf_rpc_cbor.h>
1011

@@ -14,16 +15,6 @@
1415

1516
#include <stdio.h>
1617

17-
NRF_RPC_GROUP_DECLARE(ot_group);
18-
19-
static void decode_void(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
20-
void *handler_data)
21-
{
22-
ARG_UNUSED(group);
23-
ARG_UNUSED(ctx);
24-
ARG_UNUSED(handler_data);
25-
}
26-
2718
static int ot_cli_output_callback(void *aContext, const char *aFormat, va_list aArguments)
2819
{
2920
size_t cbor_buffer_size = 6;
@@ -44,7 +35,7 @@ static int ot_cli_output_callback(void *aContext, const char *aFormat, va_list a
4435
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
4536
zcbor_tstr_encode_ptr(ctx.zs, output_line_buffer, num_written);
4637

47-
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_CLI_OUTPUT, &ctx, decode_void, NULL);
38+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_CLI_OUTPUT, &ctx, ot_rpc_decode_void, NULL);
4839

4940
return num_written;
5041
}

subsys/net/openthread/rpc/server/ot_rpc_ctrl_server.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <ot_rpc_ids.h>
88
#include <ot_rpc_types.h>
9+
#include <ot_rpc_common.h>
910

1011
#include <nrf_rpc_cbor.h>
1112

@@ -16,8 +17,6 @@
1617

1718
#include <zephyr/net/openthread.h>
1819

19-
NRF_RPC_GROUP_DECLARE(ot_group);
20-
2120
/* TODO: move to common */
2221
typedef struct ot_rpc_callback {
2322
uint32_t callback;
@@ -66,14 +65,6 @@ static ot_rpc_callback_t *ot_rpc_callback_del(uint32_t callback, uint32_t contex
6665
return NULL;
6766
}
6867

69-
static void decode_void(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
70-
void *handler_data)
71-
{
72-
ARG_UNUSED(group);
73-
ARG_UNUSED(ctx);
74-
ARG_UNUSED(handler_data);
75-
}
76-
7768
static void ot_rpc_cmd_ip6_get_unicast_addrs(const struct nrf_rpc_group *group,
7869
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
7970
{
@@ -157,7 +148,8 @@ static void ot_state_changed_callback(otChangedFlags aFlags, void *aContext)
157148
zcbor_uint32_put(ctx.zs, aFlags);
158149

159150
openthread_api_mutex_unlock(openthread_get_default_context());
160-
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_STATE_CHANGED, &ctx, decode_void, NULL);
151+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_STATE_CHANGED, &ctx, ot_rpc_decode_void,
152+
NULL);
161153
openthread_api_mutex_lock(openthread_get_default_context());
162154
}
163155

subsys/net/openthread/rpc/server/ot_rpc_if_server.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <ot_rpc_ids.h>
8+
#include <ot_rpc_common.h>
89

910
#include <nrf_rpc_cbor.h>
1011

@@ -20,19 +21,10 @@
2021

2122
#include <stdio.h>
2223

23-
NRF_RPC_GROUP_DECLARE(ot_group);
2424
LOG_MODULE_DECLARE(ot_rpc, LOG_LEVEL_DBG);
2525

2626
struct net_context *recv_net_context;
2727

28-
static void decode_void(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
29-
void *handler_data)
30-
{
31-
ARG_UNUSED(group);
32-
ARG_UNUSED(ctx);
33-
ARG_UNUSED(handler_data);
34-
}
35-
3628
static void ot_rpc_if_recv_cb(struct net_context *context, struct net_pkt *pkt,
3729
union net_ip_header *ip_hdr, union net_proto_header *proto_hdr,
3830
int status, void *user_data)
@@ -69,7 +61,7 @@ static void ot_rpc_if_recv_cb(struct net_context *context, struct net_pkt *pkt,
6961
NET_DBG("Passing Ip6 packet to RPC client");
7062

7163
encoded_ok = true;
72-
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_IF_RECEIVE, &ctx, decode_void, NULL);
64+
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_IF_RECEIVE, &ctx, ot_rpc_decode_void, NULL);
7365

7466
out:
7567
if (!encoded_ok) {

0 commit comments

Comments
 (0)