Skip to content

Commit 46601c1

Browse files
net: openthread: rpc: Add vendor data APIs serialization
Add serialization of APIs for setting and getting vendor name, model and sw version. Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
1 parent 5372540 commit 46601c1

File tree

12 files changed

+628
-0
lines changed

12 files changed

+628
-0
lines changed

doc/nrf/libraries/networking/ot_rpc.rst

+6
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,15 @@ OpenThread RPC currently supports the serialization of the following OpenThread
163163
* :c:func:`otThreadGetMleCounters`
164164
* :c:func:`otThreadGetNetworkName`
165165
* :c:func:`otThreadGetPartitionId`
166+
* :c:func:`otThreadGetVendorName`
167+
* :c:func:`otThreadGetVendorModel`
168+
* :c:func:`otThreadGetVendorSwVersion`
166169
* :c:func:`otThreadGetVersion`
167170
* :c:func:`otThreadSetEnabled`
168171
* :c:func:`otThreadSetLinkMode`
172+
* :c:func:`otThreadSetVendorName`
173+
* :c:func:`otThreadSetVendorModel`
174+
* :c:func:`otThreadSetVendorSwVersion`
169175
* :c:func:`otUdpBind`
170176
* :c:func:`otUdpClose`
171177
* :c:func:`otUdpConnect`

samples/nrf_rpc/protocols_serialization/client/src/ot_shell.c

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <openthread/thread.h>
1717
#include <openthread/udp.h>
1818
#include <openthread/netdata.h>
19+
#include <openthread/netdiag.h>
1920
#include <openthread/message.h>
2021
#include <openthread/srp_client.h>
2122
#include <openthread/dns_client.h>
@@ -1028,6 +1029,19 @@ static int cmd_test_srp_client_ttl(const struct shell *sh, size_t argc, char *ar
10281029
return 0;
10291030
}
10301031

1032+
static int cmd_test_vendor_data(const struct shell *sh, size_t argc, char *argv[])
1033+
{
1034+
otThreadSetVendorName(NULL, argv[1]);
1035+
otThreadSetVendorModel(NULL, argv[2]);
1036+
otThreadSetVendorSwVersion(NULL, argv[3]);
1037+
1038+
shell_print(sh, "Vendor name set to: %s", otThreadGetVendorName(NULL));
1039+
shell_print(sh, "Vendor model set to: %s", otThreadGetVendorModel(NULL));
1040+
shell_print(sh, "Vendor SW version set to: %s", otThreadGetVendorSwVersion(NULL));
1041+
1042+
return 0;
1043+
}
1044+
10311045
static void print_txt_entry(const struct shell *sh, const otDnsTxtEntry *entry)
10321046
{
10331047
char buffer[128];
@@ -1575,6 +1589,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
15751589
cmd_dns_client_service, 4, 0),
15761590
SHELL_CMD_ARG(test_dns_client_browse, NULL, "Service browsing, args <service> <server>",
15771591
cmd_dns_client_browse, 3, 0),
1592+
SHELL_CMD_ARG(test_vendor_data, NULL, "Vendor data, args: <vendor-name> <vendor-model>"
1593+
" <vendor-sw-version>",
1594+
cmd_test_vendor_data, 4, 0),
15781595
SHELL_SUBCMD_SET_END);
15791596

15801597
SHELL_CMD_ARG_REGISTER(ot, &ot_cmds,

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

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
zephyr_library()
88

99
zephyr_library_sources(
10+
ot_rpc_client_common.c
1011
ot_rpc_cli.c
1112
ot_rpc_coap.c
1213
ot_rpc_diag.c
@@ -16,6 +17,7 @@ zephyr_library_sources(
1617
ot_rpc_link.c
1718
ot_rpc_message.c
1819
ot_rpc_netdata.c
20+
ot_rpc_netdiag.c
1921
ot_rpc_srp_client.c
2022
ot_rpc_thread.c
2123
ot_rpc_udp.c
@@ -25,6 +27,7 @@ zephyr_library_sources(
2527
zephyr_library_sources_ifdef(CONFIG_OPENTHREAD_RPC_NET_IF ot_rpc_if.c)
2628

2729
zephyr_library_include_directories(
30+
${CMAKE_CURRENT_SOURCE_DIR}
2831
${CMAKE_CURRENT_SOURCE_DIR}/../common
2932
)
3033

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <ot_rpc_client_common.h>
8+
#include <nrf_rpc/nrf_rpc_serialize.h>
9+
10+
#include <nrf_rpc_cbor.h>
11+
12+
size_t ot_rpc_get_string(enum ot_rpc_cmd_server cmd, char *buffer, size_t buffer_size)
13+
{
14+
struct nrf_rpc_cbor_ctx ctx;
15+
16+
if (!buffer || !buffer_size) {
17+
ot_rpc_report_rsp_decoding_error(cmd);
18+
return 0;
19+
}
20+
21+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
22+
nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, cmd, &ctx);
23+
24+
nrf_rpc_decode_str(&ctx, buffer, buffer_size);
25+
26+
if (!nrf_rpc_decoding_done_and_check(&ot_group, &ctx)) {
27+
ot_rpc_report_rsp_decoding_error(cmd);
28+
29+
/* In case of error, set buffer to an empty string */
30+
*buffer = '\0';
31+
}
32+
33+
return strlen(buffer);
34+
}
35+
36+
otError ot_rpc_set_string(enum ot_rpc_cmd_server cmd, const char *data)
37+
{
38+
struct nrf_rpc_cbor_ctx ctx;
39+
otError error;
40+
41+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, strlen(data) + 2);
42+
nrf_rpc_encode_str(&ctx, data, strlen(data));
43+
44+
nrf_rpc_cbor_cmd_no_err(&ot_group, cmd, &ctx, ot_rpc_decode_error, &error);
45+
46+
return error;
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <ot_rpc_common.h>
8+
#include <ot_rpc_ids.h>
9+
10+
#include <openthread/thread.h>
11+
12+
size_t ot_rpc_get_string(enum ot_rpc_cmd_server cmd, char *buffer, size_t buffer_size);
13+
otError ot_rpc_set_string(enum ot_rpc_cmd_server cmd, const char *data);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <ot_rpc_client_common.h>
8+
#include <ot_rpc_ids.h>
9+
10+
#include <openthread/netdiag.h>
11+
12+
static char vendor_name[OT_NETWORK_DIAGNOSTIC_MAX_VENDOR_NAME_TLV_LENGTH + 1];
13+
static char vendor_model[OT_NETWORK_DIAGNOSTIC_MAX_VENDOR_MODEL_TLV_LENGTH + 1];
14+
static char vendor_sw_version[OT_NETWORK_DIAGNOSTIC_MAX_VENDOR_SW_VERSION_TLV_LENGTH + 1];
15+
16+
otError otThreadSetVendorName(otInstance *aInstance, const char *aVendorName)
17+
{
18+
ARG_UNUSED(aInstance);
19+
20+
return ot_rpc_set_string(OT_RPC_CMD_THREAD_SET_VENDOR_NAME, aVendorName);
21+
}
22+
23+
otError otThreadSetVendorModel(otInstance *aInstance, const char *aVendorModel)
24+
{
25+
ARG_UNUSED(aInstance);
26+
27+
return ot_rpc_set_string(OT_RPC_CMD_THREAD_SET_VENDOR_MODEL, aVendorModel);
28+
}
29+
30+
otError otThreadSetVendorSwVersion(otInstance *aInstance, const char *aVendorSwVersion)
31+
{
32+
ARG_UNUSED(aInstance);
33+
34+
return ot_rpc_set_string(OT_RPC_CMD_THREAD_SET_VENDOR_SW_VERSION, aVendorSwVersion);
35+
}
36+
37+
const char *otThreadGetVendorName(otInstance *aInstance)
38+
{
39+
ARG_UNUSED(aInstance);
40+
41+
ot_rpc_get_string(OT_RPC_CMD_THREAD_GET_VENDOR_NAME, vendor_name, sizeof(vendor_name));
42+
return vendor_name;
43+
}
44+
45+
const char *otThreadGetVendorModel(otInstance *aInstance)
46+
{
47+
ARG_UNUSED(aInstance);
48+
49+
ot_rpc_get_string(OT_RPC_CMD_THREAD_GET_VENDOR_MODEL, vendor_model, sizeof(vendor_model));
50+
return vendor_model;
51+
}
52+
53+
const char *otThreadGetVendorSwVersion(otInstance *aInstance)
54+
{
55+
ARG_UNUSED(aInstance);
56+
57+
ot_rpc_get_string(OT_RPC_CMD_THREAD_GET_VENDOR_SW_VERSION, vendor_sw_version,
58+
sizeof(vendor_sw_version));
59+
return vendor_sw_version;
60+
}

subsys/net/openthread/rpc/common/ot_rpc_ids.h

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ enum ot_rpc_cmd_server {
8383
OT_RPC_CMD_THREAD_GET_PARENT_INFO,
8484
OT_RPC_CMD_THREAD_GET_PARTITION_ID,
8585
OT_RPC_CMD_THREAD_GET_VERSION,
86+
OT_RPC_CMD_THREAD_SET_VENDOR_NAME,
87+
OT_RPC_CMD_THREAD_SET_VENDOR_MODEL,
88+
OT_RPC_CMD_THREAD_SET_VENDOR_SW_VERSION,
89+
OT_RPC_CMD_THREAD_GET_VENDOR_NAME,
90+
OT_RPC_CMD_THREAD_GET_VENDOR_MODEL,
91+
OT_RPC_CMD_THREAD_GET_VENDOR_SW_VERSION,
8692
OT_RPC_CMD_UDP_NEW_MESSAGE,
8793
OT_RPC_CMD_MESSAGE_FREE,
8894
OT_RPC_CMD_MESSAGE_APPEND,

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

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ zephyr_library_sources(
1717
ot_rpc_link.c
1818
ot_rpc_message.c
1919
ot_rpc_netdata.c
20+
ot_rpc_netdiag.c
2021
ot_rpc_srp_client.c
2122
ot_rpc_thread.c
2223
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <nrf_rpc/nrf_rpc_serialize.h>
8+
#include <ot_rpc_ids.h>
9+
#include <ot_rpc_types.h>
10+
#include <ot_rpc_common.h>
11+
12+
#include <nrf_rpc_cbor.h>
13+
14+
#include <zephyr/net/openthread.h>
15+
16+
#include <openthread/netdiag.h>
17+
18+
static void ot_rpc_cmd_set_vendor_name(const struct nrf_rpc_group *group,
19+
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
20+
{
21+
otError error;
22+
char buffer[256];
23+
24+
nrf_rpc_decode_str(ctx, buffer, sizeof(buffer));
25+
26+
if (!nrf_rpc_decoding_done_and_check(group, ctx)) {
27+
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_THREAD_SET_VENDOR_NAME);
28+
return;
29+
}
30+
31+
openthread_api_mutex_lock(openthread_get_default_context());
32+
error = otThreadSetVendorName(openthread_get_default_instance(), buffer);
33+
openthread_api_mutex_unlock(openthread_get_default_context());
34+
35+
nrf_rpc_rsp_send_uint(group, error);
36+
}
37+
38+
static void ot_rpc_cmd_set_vendor_model(const struct nrf_rpc_group *group,
39+
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
40+
{
41+
otError error;
42+
char buffer[256];
43+
44+
nrf_rpc_decode_str(ctx, buffer, sizeof(buffer));
45+
46+
if (!nrf_rpc_decoding_done_and_check(group, ctx)) {
47+
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_THREAD_SET_VENDOR_MODEL);
48+
return;
49+
}
50+
51+
openthread_api_mutex_lock(openthread_get_default_context());
52+
error = otThreadSetVendorModel(openthread_get_default_instance(), buffer);
53+
openthread_api_mutex_unlock(openthread_get_default_context());
54+
55+
nrf_rpc_rsp_send_uint(group, error);
56+
}
57+
58+
static void ot_rpc_cmd_set_vendor_sw_version(const struct nrf_rpc_group *group,
59+
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
60+
{
61+
otError error;
62+
char buffer[256];
63+
64+
nrf_rpc_decode_str(ctx, buffer, sizeof(buffer));
65+
66+
if (!nrf_rpc_decoding_done_and_check(group, ctx)) {
67+
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_THREAD_SET_VENDOR_SW_VERSION);
68+
return;
69+
}
70+
71+
openthread_api_mutex_lock(openthread_get_default_context());
72+
error = otThreadSetVendorSwVersion(openthread_get_default_instance(), buffer);
73+
openthread_api_mutex_unlock(openthread_get_default_context());
74+
75+
nrf_rpc_rsp_send_uint(group, error);
76+
}
77+
78+
static void ot_rpc_cmd_get_vendor_name(const struct nrf_rpc_group *group,
79+
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
80+
{
81+
const char *data;
82+
struct nrf_rpc_cbor_ctx rsp_ctx;
83+
84+
nrf_rpc_cbor_decoding_done(group, ctx);
85+
86+
openthread_api_mutex_lock(openthread_get_default_context());
87+
data = otThreadGetVendorName(openthread_get_default_instance());
88+
89+
NRF_RPC_CBOR_ALLOC(group, rsp_ctx, 2 + strlen(data));
90+
nrf_rpc_encode_str(&rsp_ctx, data, strlen(data));
91+
openthread_api_mutex_unlock(openthread_get_default_context());
92+
93+
nrf_rpc_cbor_rsp_no_err(group, &rsp_ctx);
94+
}
95+
96+
static void ot_rpc_cmd_get_vendor_model(const struct nrf_rpc_group *group,
97+
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
98+
{
99+
const char *data;
100+
struct nrf_rpc_cbor_ctx rsp_ctx;
101+
102+
nrf_rpc_cbor_decoding_done(group, ctx);
103+
104+
openthread_api_mutex_lock(openthread_get_default_context());
105+
data = otThreadGetVendorModel(openthread_get_default_instance());
106+
107+
NRF_RPC_CBOR_ALLOC(group, rsp_ctx, 2 + strlen(data));
108+
nrf_rpc_encode_str(&rsp_ctx, data, strlen(data));
109+
openthread_api_mutex_unlock(openthread_get_default_context());
110+
111+
nrf_rpc_cbor_rsp_no_err(group, &rsp_ctx);
112+
}
113+
114+
static void ot_rpc_cmd_get_vendor_sw_version(const struct nrf_rpc_group *group,
115+
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
116+
{
117+
const char *data;
118+
struct nrf_rpc_cbor_ctx rsp_ctx;
119+
120+
nrf_rpc_cbor_decoding_done(group, ctx);
121+
122+
openthread_api_mutex_lock(openthread_get_default_context());
123+
data = otThreadGetVendorSwVersion(openthread_get_default_instance());
124+
125+
NRF_RPC_CBOR_ALLOC(group, rsp_ctx, 2 + strlen(data));
126+
nrf_rpc_encode_str(&rsp_ctx, data, strlen(data));
127+
openthread_api_mutex_unlock(openthread_get_default_context());
128+
129+
nrf_rpc_cbor_rsp_no_err(group, &rsp_ctx);
130+
}
131+
132+
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_cmd_set_vendor_name, OT_RPC_CMD_THREAD_SET_VENDOR_NAME,
133+
ot_rpc_cmd_set_vendor_name, NULL);
134+
135+
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_cmd_set_vendor_model, OT_RPC_CMD_THREAD_SET_VENDOR_MODEL,
136+
ot_rpc_cmd_set_vendor_model, NULL);
137+
138+
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_cmd_set_vendor_sw_version,
139+
OT_RPC_CMD_THREAD_SET_VENDOR_SW_VERSION,
140+
ot_rpc_cmd_set_vendor_sw_version, NULL);
141+
142+
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_cmd_get_vendor_name, OT_RPC_CMD_THREAD_GET_VENDOR_NAME,
143+
ot_rpc_cmd_get_vendor_name, NULL);
144+
145+
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_cmd_get_vendor_model, OT_RPC_CMD_THREAD_GET_VENDOR_MODEL,
146+
ot_rpc_cmd_get_vendor_model, NULL);
147+
148+
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_cmd_get_vendor_sw_version,
149+
OT_RPC_CMD_THREAD_GET_VENDOR_SW_VERSION,
150+
ot_rpc_cmd_get_vendor_sw_version, NULL);

0 commit comments

Comments
 (0)