Skip to content

Commit 5a72d78

Browse files
Damian-Nordicnordicjm
authored andcommitted
net: openthread: rpc: add pending dataset APIs
Add serialization of APIs for getting and setting Thread pending operational dataset. Signed-off-by: Damian Krolik <[email protected]>
1 parent fdd05c6 commit 5a72d78

File tree

8 files changed

+431
-134
lines changed

8 files changed

+431
-134
lines changed

doc/nrf/libraries/networking/ot_rpc.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,13 @@ OpenThread RPC currently supports the serialization of the following OpenThread
8383
* :c:func:`otCoapStop`
8484
* :c:func:`otDatasetGetActive`
8585
* :c:func:`otDatasetGetActiveTlvs`
86+
* :c:func:`otDatasetGetPending`
87+
* :c:func:`otDatasetGetPendingTlvs`
8688
* :c:func:`otDatasetIsCommissioned`
8789
* :c:func:`otDatasetSetActive`
8890
* :c:func:`otDatasetSetActiveTlvs`
91+
* :c:func:`otDatasetSetPending`
92+
* :c:func:`otDatasetSetPendingTlvs`
8993
* :c:func:`otDnsAddressResponseGetAddress`
9094
* :c:func:`otDnsAddressResponseGetHostName`
9195
* :c:func:`otDnsBrowseResponseGetHostAddress`

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

Lines changed: 70 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,86 +25,114 @@ bool otDatasetIsCommissioned(otInstance *aInstance)
2525
return result;
2626
}
2727

28-
otError otDatasetSetActiveTlvs(otInstance *aInstance, const otOperationalDatasetTlvs *aDataset)
28+
static otError ot_rpc_dataset_set_tlvs(uint8_t cmd, const otOperationalDatasetTlvs *dataset)
2929
{
3030
struct nrf_rpc_cbor_ctx ctx;
31-
size_t cbor_buffer_size;
3231
otError error;
3332

34-
ARG_UNUSED(aInstance);
33+
__ASSERT_NO_MSG(dataset);
3534

36-
if (aDataset == NULL || aDataset->mLength > OT_OPERATIONAL_DATASET_MAX_LENGTH) {
35+
if (dataset->mLength > OT_OPERATIONAL_DATASET_MAX_LENGTH) {
3736
return OT_ERROR_INVALID_ARGS;
3837
}
3938

40-
cbor_buffer_size = aDataset->mLength + 2;
41-
42-
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
43-
44-
nrf_rpc_encode_buffer(&ctx, aDataset->mTlvs, aDataset->mLength);
45-
46-
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_DATASET_SET_ACTIVE_TLVS, &ctx,
47-
ot_rpc_decode_error, &error);
39+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 2 + dataset->mLength);
40+
nrf_rpc_encode_buffer(&ctx, dataset->mTlvs, dataset->mLength);
41+
nrf_rpc_cbor_cmd_no_err(&ot_group, cmd, &ctx, ot_rpc_decode_error, &error);
4842

4943
return error;
5044
}
5145

52-
otError otDatasetGetActiveTlvs(otInstance *aInstance, otOperationalDatasetTlvs *aDataset)
46+
static otError ot_rpc_dataset_get_tlvs(uint8_t cmd, otOperationalDatasetTlvs *dataset)
5347
{
5448
struct nrf_rpc_cbor_ctx ctx;
55-
otOperationalDatasetTlvs *dataset = aDataset;
5649

57-
ARG_UNUSED(aInstance);
58-
59-
if (aDataset == NULL) {
60-
return OT_ERROR_NOT_FOUND;
61-
}
50+
__ASSERT_NO_MSG(dataset);
6251

6352
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
64-
65-
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_DATASET_GET_ACTIVE_TLVS, &ctx,
66-
ot_rpc_decode_dataset_tlvs, &dataset);
53+
nrf_rpc_cbor_cmd_no_err(&ot_group, cmd, &ctx, ot_rpc_decode_dataset_tlvs, &dataset);
6754

6855
return dataset ? OT_ERROR_NONE : OT_ERROR_NOT_FOUND;
6956
}
7057

71-
otError otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset)
58+
static otError ot_rpc_dataset_set(uint8_t cmd, const otOperationalDataset *dataset)
7259
{
7360
struct nrf_rpc_cbor_ctx ctx;
74-
size_t cbor_buffer_size;
7561
otError error;
7662

63+
__ASSERT_NO_MSG(dataset);
64+
65+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, OPERATIONAL_DATASET_LENGTH(dataset));
66+
ot_rpc_encode_dataset(&ctx, dataset);
67+
nrf_rpc_cbor_cmd_no_err(&ot_group, cmd, &ctx, ot_rpc_decode_error, &error);
68+
69+
return error;
70+
}
71+
72+
static otError ot_rpc_dataset_get(uint8_t cmd, otOperationalDataset *dataset)
73+
{
74+
struct nrf_rpc_cbor_ctx ctx;
75+
76+
__ASSERT_NO_MSG(dataset);
77+
78+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
79+
nrf_rpc_cbor_cmd_no_err(&ot_group, cmd, &ctx, ot_rpc_decode_dataset, &dataset);
80+
81+
return dataset ? OT_ERROR_NONE : OT_ERROR_NOT_FOUND;
82+
}
83+
84+
otError otDatasetSetActiveTlvs(otInstance *aInstance, const otOperationalDatasetTlvs *aDataset)
85+
{
7786
ARG_UNUSED(aInstance);
7887

79-
if (aDataset == NULL) {
80-
return OT_ERROR_INVALID_ARGS;
81-
}
88+
return ot_rpc_dataset_set_tlvs(OT_RPC_CMD_DATASET_SET_ACTIVE_TLVS, aDataset);
89+
}
8290

83-
cbor_buffer_size = OPERATIONAL_DATASET_LENGTH(aDataset);
91+
otError otDatasetGetActiveTlvs(otInstance *aInstance, otOperationalDatasetTlvs *aDataset)
92+
{
93+
ARG_UNUSED(aInstance);
8494

85-
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, cbor_buffer_size);
86-
ot_rpc_encode_dataset(&ctx, aDataset);
87-
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_DATASET_SET_ACTIVE, &ctx, ot_rpc_decode_error,
88-
&error);
95+
return ot_rpc_dataset_get_tlvs(OT_RPC_CMD_DATASET_GET_ACTIVE_TLVS, aDataset);
96+
}
8997

90-
return error;
98+
otError otDatasetSetActive(otInstance *aInstance, const otOperationalDataset *aDataset)
99+
{
100+
ARG_UNUSED(aInstance);
101+
102+
return ot_rpc_dataset_set(OT_RPC_CMD_DATASET_SET_ACTIVE, aDataset);
91103
}
92104

93105
otError otDatasetGetActive(otInstance *aInstance, otOperationalDataset *aDataset)
94106
{
95-
struct nrf_rpc_cbor_ctx ctx;
96-
otOperationalDataset *dataset = aDataset;
107+
ARG_UNUSED(aInstance);
97108

109+
return ot_rpc_dataset_get(OT_RPC_CMD_DATASET_GET_ACTIVE, aDataset);
110+
}
111+
112+
otError otDatasetSetPendingTlvs(otInstance *aInstance, const otOperationalDatasetTlvs *aDataset)
113+
{
98114
ARG_UNUSED(aInstance);
99115

100-
if (aDataset == NULL) {
101-
return OT_ERROR_NOT_FOUND;
102-
}
116+
return ot_rpc_dataset_set_tlvs(OT_RPC_CMD_DATASET_SET_PENDING_TLVS, aDataset);
117+
}
103118

104-
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 0);
119+
otError otDatasetGetPendingTlvs(otInstance *aInstance, otOperationalDatasetTlvs *aDataset)
120+
{
121+
ARG_UNUSED(aInstance);
105122

106-
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_DATASET_GET_ACTIVE, &ctx,
107-
ot_rpc_decode_dataset, &dataset);
123+
return ot_rpc_dataset_get_tlvs(OT_RPC_CMD_DATASET_GET_PENDING_TLVS, aDataset);
124+
}
108125

109-
return dataset ? OT_ERROR_NONE : OT_ERROR_NOT_FOUND;
126+
otError otDatasetSetPending(otInstance *aInstance, const otOperationalDataset *aDataset)
127+
{
128+
ARG_UNUSED(aInstance);
129+
130+
return ot_rpc_dataset_set(OT_RPC_CMD_DATASET_SET_PENDING, aDataset);
131+
}
132+
133+
otError otDatasetGetPending(otInstance *aInstance, otOperationalDataset *aDataset)
134+
{
135+
ARG_UNUSED(aInstance);
136+
137+
return ot_rpc_dataset_get(OT_RPC_CMD_DATASET_GET_PENDING, aDataset);
110138
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ enum ot_rpc_cmd_server {
5858
OT_RPC_CMD_DATASET_GET_ACTIVE_TLVS,
5959
OT_RPC_CMD_DATASET_SET_ACTIVE,
6060
OT_RPC_CMD_DATASET_GET_ACTIVE,
61+
OT_RPC_CMD_DATASET_SET_PENDING_TLVS,
62+
OT_RPC_CMD_DATASET_GET_PENDING_TLVS,
63+
OT_RPC_CMD_DATASET_SET_PENDING,
64+
OT_RPC_CMD_DATASET_GET_PENDING,
6165
OT_RPC_CMD_GET_VERSION_STRING,
6266
OT_RPC_CMD_LINK_GET_CHANNEL,
6367
OT_RPC_CMD_LINK_GET_COUNTERS,

0 commit comments

Comments
 (0)