forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathot_rpc_netdiag.c
340 lines (295 loc) · 13 KB
/
ot_rpc_netdiag.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <ot_rpc_client_common.h>
#include <ot_rpc_ids.h>
#include <ot_rpc_types.h>
#include <nrf_rpc/nrf_rpc_serialize.h>
#include <openthread/netdiag.h>
static char vendor_name[OT_NETWORK_DIAGNOSTIC_MAX_VENDOR_NAME_TLV_LENGTH + 1];
static char vendor_model[OT_NETWORK_DIAGNOSTIC_MAX_VENDOR_MODEL_TLV_LENGTH + 1];
static char vendor_sw_version[OT_NETWORK_DIAGNOSTIC_MAX_VENDOR_SW_VERSION_TLV_LENGTH + 1];
static otReceiveDiagnosticGetCallback receive_diag_get_cb;
static void *receive_diag_get_cb_context;
void ot_rpc_decode_network_diag_tlv(struct nrf_rpc_cbor_ctx *ctx, otNetworkDiagTlv *aNetworkDiagTlv)
{
aNetworkDiagTlv->mType = nrf_rpc_decode_uint(ctx);
switch (aNetworkDiagTlv->mType) {
case OT_NETWORK_DIAGNOSTIC_TLV_EXT_ADDRESS:
nrf_rpc_decode_buffer(ctx, aNetworkDiagTlv->mData.mExtAddress.m8,
OT_EXT_ADDRESS_SIZE);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_EUI64:
nrf_rpc_decode_buffer(ctx, aNetworkDiagTlv->mData.mEui64.m8, OT_EXT_ADDRESS_SIZE);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_MODE:
uint8_t mode = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMode.mRxOnWhenIdle = (bool)(mode & BIT(0));
aNetworkDiagTlv->mData.mMode.mDeviceType = (bool)(mode & BIT(1));
aNetworkDiagTlv->mData.mMode.mNetworkData = (bool)(mode & BIT(2));
break;
case OT_NETWORK_DIAGNOSTIC_TLV_CONNECTIVITY:
aNetworkDiagTlv->mData.mConnectivity.mParentPriority = nrf_rpc_decode_int(ctx);
aNetworkDiagTlv->mData.mConnectivity.mLinkQuality3 = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mConnectivity.mLinkQuality2 = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mConnectivity.mLinkQuality1 = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mConnectivity.mLeaderCost = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mConnectivity.mIdSequence = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mConnectivity.mActiveRouters = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mConnectivity.mSedBufferSize = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mConnectivity.mSedDatagramCount = nrf_rpc_decode_uint(ctx);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_ROUTE:
aNetworkDiagTlv->mData.mRoute.mIdSequence = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mRoute.mRouteCount = nrf_rpc_decode_uint(ctx);
zcbor_list_start_decode(ctx->zs);
for (int i = 0; i < aNetworkDiagTlv->mData.mRoute.mRouteCount; i++) {
aNetworkDiagTlv->mData.mRoute.mRouteData[i].mRouterId =
nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mRoute.mRouteData[i].mLinkQualityIn =
nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mRoute.mRouteData[i].mLinkQualityOut =
nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mRoute.mRouteData[i].mRouteCost =
nrf_rpc_decode_uint(ctx);
}
zcbor_list_end_decode(ctx->zs);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_LEADER_DATA:
aNetworkDiagTlv->mData.mLeaderData.mPartitionId = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mLeaderData.mWeighting = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mLeaderData.mDataVersion = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mLeaderData.mStableDataVersion = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mLeaderData.mLeaderRouterId = nrf_rpc_decode_uint(ctx);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_MAC_COUNTERS:
aNetworkDiagTlv->mData.mMacCounters.mIfInUnknownProtos = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMacCounters.mIfInErrors = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMacCounters.mIfOutErrors = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMacCounters.mIfInUcastPkts = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMacCounters.mIfInBroadcastPkts = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMacCounters.mIfInDiscards = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMacCounters.mIfOutUcastPkts = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMacCounters.mIfOutBroadcastPkts = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMacCounters.mIfOutDiscards = nrf_rpc_decode_uint(ctx);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_MLE_COUNTERS:
aNetworkDiagTlv->mData.mMleCounters.mDisabledRole = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMleCounters.mDetachedRole = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMleCounters.mChildRole = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMleCounters.mRouterRole = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMleCounters.mLeaderRole = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMleCounters.mAttachAttempts = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMleCounters.mPartitionIdChanges = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMleCounters.mBetterPartitionAttachAttempts =
nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMleCounters.mParentChanges = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mMleCounters.mTrackedTime = nrf_rpc_decode_uint64(ctx);
aNetworkDiagTlv->mData.mMleCounters.mDisabledTime = nrf_rpc_decode_uint64(ctx);
aNetworkDiagTlv->mData.mMleCounters.mDetachedTime = nrf_rpc_decode_uint64(ctx);
aNetworkDiagTlv->mData.mMleCounters.mChildTime = nrf_rpc_decode_uint64(ctx);
aNetworkDiagTlv->mData.mMleCounters.mRouterTime = nrf_rpc_decode_uint64(ctx);
aNetworkDiagTlv->mData.mMleCounters.mLeaderTime = nrf_rpc_decode_uint64(ctx);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_BATTERY_LEVEL:
aNetworkDiagTlv->mData.mBatteryLevel = nrf_rpc_decode_uint(ctx);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_TIMEOUT:
aNetworkDiagTlv->mData.mTimeout = nrf_rpc_decode_uint(ctx);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_MAX_CHILD_TIMEOUT:
aNetworkDiagTlv->mData.mMaxChildTimeout = nrf_rpc_decode_uint(ctx);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_SHORT_ADDRESS:
aNetworkDiagTlv->mData.mAddr16 = nrf_rpc_decode_uint(ctx);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_SUPPLY_VOLTAGE:
aNetworkDiagTlv->mData.mSupplyVoltage = nrf_rpc_decode_uint(ctx);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_VERSION:
aNetworkDiagTlv->mData.mVersion = nrf_rpc_decode_uint(ctx);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_VENDOR_NAME:
nrf_rpc_decode_str(ctx, aNetworkDiagTlv->mData.mVendorName,
sizeof(aNetworkDiagTlv->mData.mVendorName));
break;
case OT_NETWORK_DIAGNOSTIC_TLV_VENDOR_MODEL:
nrf_rpc_decode_str(ctx, aNetworkDiagTlv->mData.mVendorModel,
sizeof(aNetworkDiagTlv->mData.mVendorModel));
break;
case OT_NETWORK_DIAGNOSTIC_TLV_VENDOR_SW_VERSION:
nrf_rpc_decode_str(ctx, aNetworkDiagTlv->mData.mVendorSwVersion,
sizeof(aNetworkDiagTlv->mData.mVendorSwVersion));
break;
case OT_NETWORK_DIAGNOSTIC_TLV_THREAD_STACK_VERSION:
nrf_rpc_decode_str(ctx, aNetworkDiagTlv->mData.mThreadStackVersion,
sizeof(aNetworkDiagTlv->mData.mThreadStackVersion));
break;
case OT_NETWORK_DIAGNOSTIC_TLV_VENDOR_APP_URL:
nrf_rpc_decode_str(ctx, aNetworkDiagTlv->mData.mVendorAppUrl,
sizeof(aNetworkDiagTlv->mData.mVendorAppUrl));
break;
case OT_NETWORK_DIAGNOSTIC_TLV_NETWORK_DATA:
aNetworkDiagTlv->mData.mNetworkData.mCount = nrf_rpc_decode_uint(ctx);
nrf_rpc_decode_buffer(ctx, aNetworkDiagTlv->mData.mNetworkData.m8,
sizeof(aNetworkDiagTlv->mData.mNetworkData.m8));
break;
case OT_NETWORK_DIAGNOSTIC_TLV_CHANNEL_PAGES:
aNetworkDiagTlv->mData.mChannelPages.mCount = nrf_rpc_decode_uint(ctx);
nrf_rpc_decode_buffer(ctx, aNetworkDiagTlv->mData.mChannelPages.m8,
sizeof(aNetworkDiagTlv->mData.mChannelPages.m8));
break;
case OT_NETWORK_DIAGNOSTIC_TLV_IP6_ADDR_LIST:
aNetworkDiagTlv->mData.mIp6AddrList.mCount = nrf_rpc_decode_uint(ctx);
zcbor_list_start_decode(ctx->zs);
for (int i = 0; i < aNetworkDiagTlv->mData.mIp6AddrList.mCount; i++) {
nrf_rpc_decode_buffer(ctx,
aNetworkDiagTlv->mData.mIp6AddrList.mList[i].mFields.m8,
OT_IP6_ADDRESS_SIZE);
}
zcbor_list_end_decode(ctx->zs);
break;
case OT_NETWORK_DIAGNOSTIC_TLV_CHILD_TABLE:
aNetworkDiagTlv->mData.mChildTable.mCount = nrf_rpc_decode_uint(ctx);
zcbor_list_start_decode(ctx->zs);
for (int i = 0; i < aNetworkDiagTlv->mData.mChildTable.mCount; i++) {
uint8_t mode;
aNetworkDiagTlv->mData.mChildTable.mTable[i].mTimeout =
nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mChildTable.mTable[i].mLinkQuality =
nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mChildTable.mTable[i].mChildId =
nrf_rpc_decode_uint(ctx);
mode = nrf_rpc_decode_uint(ctx);
aNetworkDiagTlv->mData.mChildTable.mTable[i].mMode.mRxOnWhenIdle =
(bool)(mode & BIT(0));
aNetworkDiagTlv->mData.mChildTable.mTable[i].mMode.mDeviceType =
(bool)(mode & BIT(1));
aNetworkDiagTlv->mData.mChildTable.mTable[i].mMode.mNetworkData =
(bool)(mode & BIT(2));
}
zcbor_list_end_decode(ctx->zs);
break;
default:
break;
}
}
otError otThreadGetNextDiagnosticTlv(const otMessage *aMessage, otNetworkDiagIterator *aIterator,
otNetworkDiagTlv *aNetworkDiagTlv)
{
struct nrf_rpc_cbor_ctx ctx;
otError error;
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, sizeof(ot_rpc_res_tab_key) + 2 +
sizeof(otNetworkDiagIterator));
nrf_rpc_encode_uint(&ctx, (ot_rpc_res_tab_key)aMessage);
nrf_rpc_encode_uint(&ctx, *aIterator);
nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, OT_RPC_CMD_THREAD_GET_NEXT_DIAGNOSTIC_TLV, &ctx);
error = nrf_rpc_decode_uint(&ctx);
if (error != OT_ERROR_NONE) {
goto exit;
}
*aIterator = nrf_rpc_decode_uint(&ctx);
ot_rpc_decode_network_diag_tlv(&ctx, aNetworkDiagTlv);
exit:
if (!nrf_rpc_decoding_done_and_check(&ot_group, &ctx)) {
ot_rpc_report_rsp_decoding_error(OT_RPC_CMD_THREAD_GET_NEXT_DIAGNOSTIC_TLV);
}
return error;
}
static void ot_rpc_cmd_thread_send_diagnostic_get_cb(const struct nrf_rpc_group *group,
struct nrf_rpc_cbor_ctx *ctx,
void *handler_data)
{
otError error;
otMessage *message;
otMessageInfo message_info;
error = nrf_rpc_decode_uint(ctx);
message = (otMessage *)nrf_rpc_decode_uint(ctx);
ot_rpc_decode_message_info(ctx, &message_info);
if (!nrf_rpc_decoding_done_and_check(group, ctx)) {
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_THREAD_SEND_DIAGNOSTIC_GET_CB);
return;
}
if (receive_diag_get_cb != NULL) {
receive_diag_get_cb(error, message, &message_info, receive_diag_get_cb_context);
}
nrf_rpc_rsp_send_void(group);
}
otError otThreadSendDiagnosticGet(otInstance *aInstance, const otIp6Address *aDestination,
const uint8_t *aTlvTypes, uint8_t aCount,
otReceiveDiagnosticGetCallback aCallback, void *aCallbackContext)
{
struct nrf_rpc_cbor_ctx ctx;
otError error;
ARG_UNUSED(aInstance);
receive_diag_get_cb = aCallback;
receive_diag_get_cb_context = aCallbackContext;
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + OT_IP6_ADDRESS_SIZE + 4 + aCount * 2);
nrf_rpc_encode_buffer(&ctx, aDestination->mFields.m8, OT_IP6_ADDRESS_SIZE);
nrf_rpc_encode_uint(&ctx, aCount);
zcbor_list_start_encode(ctx.zs, aCount);
for (int i = 0; i < aCount; i++) {
nrf_rpc_encode_uint(&ctx, aTlvTypes[i]);
}
zcbor_list_end_encode(ctx.zs, aCount);
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_THREAD_SEND_DIAGNOSTIC_GET,
&ctx, ot_rpc_decode_error, &error);
return error;
}
otError otThreadSendDiagnosticReset(otInstance *aInstance, const otIp6Address *aDestination,
const uint8_t aTlvTypes[], uint8_t aCount)
{
struct nrf_rpc_cbor_ctx ctx;
otError error;
ARG_UNUSED(aInstance);
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + OT_IP6_ADDRESS_SIZE + 4 + aCount * 2);
nrf_rpc_encode_buffer(&ctx, aDestination->mFields.m8, OT_IP6_ADDRESS_SIZE);
nrf_rpc_encode_uint(&ctx, aCount);
zcbor_list_start_encode(ctx.zs, aCount);
for (int i = 0; i < aCount; i++) {
nrf_rpc_encode_uint(&ctx, aTlvTypes[i]);
}
zcbor_list_end_encode(ctx.zs, aCount);
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_THREAD_SEND_DIAGNOSTIC_RESET,
&ctx, ot_rpc_decode_error, &error);
return error;
}
otError otThreadSetVendorName(otInstance *aInstance, const char *aVendorName)
{
ARG_UNUSED(aInstance);
return ot_rpc_set_string(OT_RPC_CMD_THREAD_SET_VENDOR_NAME, aVendorName);
}
otError otThreadSetVendorModel(otInstance *aInstance, const char *aVendorModel)
{
ARG_UNUSED(aInstance);
return ot_rpc_set_string(OT_RPC_CMD_THREAD_SET_VENDOR_MODEL, aVendorModel);
}
otError otThreadSetVendorSwVersion(otInstance *aInstance, const char *aVendorSwVersion)
{
ARG_UNUSED(aInstance);
return ot_rpc_set_string(OT_RPC_CMD_THREAD_SET_VENDOR_SW_VERSION, aVendorSwVersion);
}
const char *otThreadGetVendorName(otInstance *aInstance)
{
ARG_UNUSED(aInstance);
ot_rpc_get_string(OT_RPC_CMD_THREAD_GET_VENDOR_NAME, vendor_name, sizeof(vendor_name));
return vendor_name;
}
const char *otThreadGetVendorModel(otInstance *aInstance)
{
ARG_UNUSED(aInstance);
ot_rpc_get_string(OT_RPC_CMD_THREAD_GET_VENDOR_MODEL, vendor_model, sizeof(vendor_model));
return vendor_model;
}
const char *otThreadGetVendorSwVersion(otInstance *aInstance)
{
ARG_UNUSED(aInstance);
ot_rpc_get_string(OT_RPC_CMD_THREAD_GET_VENDOR_SW_VERSION, vendor_sw_version,
sizeof(vendor_sw_version));
return vendor_sw_version;
}
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_cmd_thread_send_diagnostic_get_cb,
OT_RPC_CMD_THREAD_SEND_DIAGNOSTIC_GET_CB,
ot_rpc_cmd_thread_send_diagnostic_get_cb, NULL);