Skip to content

Commit 907668f

Browse files
net: openthread: rpc: Add netdiag unit tests.
- Add netdiag unit tests - Fix bugs found during testing - Simplify encoding of tlv types array, using buffer as it is an array of 1-byte uint8 types. Signed-off-by: Maciej Baczmanski <[email protected]>
1 parent 39b3bd8 commit 907668f

File tree

5 files changed

+1665
-41
lines changed

5 files changed

+1665
-41
lines changed

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,9 @@ otError otThreadSendDiagnosticGet(otInstance *aInstance, const otIp6Address *aDe
251251
receive_diag_get_cb = aCallback;
252252
receive_diag_get_cb_context = aCallbackContext;
253253

254-
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + OT_IP6_ADDRESS_SIZE + 4 + aCount * 2);
254+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + OT_IP6_ADDRESS_SIZE + 2 + aCount);
255255
nrf_rpc_encode_buffer(&ctx, aDestination->mFields.m8, OT_IP6_ADDRESS_SIZE);
256-
nrf_rpc_encode_uint(&ctx, aCount);
257-
zcbor_list_start_encode(ctx.zs, aCount);
258-
for (int i = 0; i < aCount; i++) {
259-
nrf_rpc_encode_uint(&ctx, aTlvTypes[i]);
260-
}
261-
zcbor_list_end_encode(ctx.zs, aCount);
256+
nrf_rpc_encode_buffer(&ctx, aTlvTypes, aCount);
262257

263258
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_THREAD_SEND_DIAGNOSTIC_GET,
264259
&ctx, ot_rpc_decode_error, &error);
@@ -274,14 +269,9 @@ otError otThreadSendDiagnosticReset(otInstance *aInstance, const otIp6Address *a
274269

275270
ARG_UNUSED(aInstance);
276271

277-
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + OT_IP6_ADDRESS_SIZE + 4 + aCount * 2);
272+
NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 1 + OT_IP6_ADDRESS_SIZE + 2 + aCount);
278273
nrf_rpc_encode_buffer(&ctx, aDestination->mFields.m8, OT_IP6_ADDRESS_SIZE);
279-
nrf_rpc_encode_uint(&ctx, aCount);
280-
zcbor_list_start_encode(ctx.zs, aCount);
281-
for (int i = 0; i < aCount; i++) {
282-
nrf_rpc_encode_uint(&ctx, aTlvTypes[i]);
283-
}
284-
zcbor_list_end_encode(ctx.zs, aCount);
274+
nrf_rpc_encode_buffer(&ctx, aTlvTypes, aCount);
285275

286276
nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_THREAD_SEND_DIAGNOSTIC_RESET,
287277
&ctx, ot_rpc_decode_error, &error);

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

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ static void ot_rpc_encode_network_diag_tlv(struct nrf_rpc_cbor_ctx *ctx,
151151
nrf_rpc_encode_uint64(ctx, aNetworkDiagTlv->mData.mMleCounters.mDetachedTime);
152152
nrf_rpc_encode_uint64(ctx, aNetworkDiagTlv->mData.mMleCounters.mChildTime);
153153
nrf_rpc_encode_uint64(ctx, aNetworkDiagTlv->mData.mMleCounters.mRouterTime);
154-
nrf_rpc_encode_uint64(ctx, aNetworkDiagTlv->mData.mMleCounters.mParentChanges);
155154
nrf_rpc_encode_uint64(ctx, aNetworkDiagTlv->mData.mMleCounters.mLeaderTime);
156155
break;
157156
case OT_NETWORK_DIAGNOSTIC_TLV_BATTERY_LEVEL:
@@ -310,61 +309,54 @@ static void ot_rpc_cmd_send_diagnostic_get(const struct nrf_rpc_group *group,
310309
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
311310
{
312311
otIp6Address addr;
313-
otError error;
314-
uint8_t count;
315-
uint8_t tlvTypes[35];
312+
otError error = OT_ERROR_INVALID_ARGS;
313+
size_t count;
314+
const uint8_t *tlvTypes;
316315

317316
nrf_rpc_decode_buffer(ctx, addr.mFields.m8, OT_IP6_ADDRESS_SIZE);
318317

319-
count = nrf_rpc_decode_uint(ctx);
318+
tlvTypes = nrf_rpc_decode_buffer_ptr_and_size(ctx, &count);
320319

321-
zcbor_list_start_decode(ctx->zs);
322-
for (int i = 0; i < count; i++) {
323-
tlvTypes[i] = nrf_rpc_decode_uint(ctx);
320+
if (tlvTypes) {
321+
openthread_api_mutex_lock(openthread_get_default_context());
322+
error = otThreadSendDiagnosticGet(openthread_get_default_instance(), &addr,
323+
tlvTypes, count, handle_receive_diagnostic_get,
324+
NULL);
325+
openthread_api_mutex_unlock(openthread_get_default_context());
324326
}
325-
zcbor_list_end_decode(ctx->zs);
326327

327328
if (!nrf_rpc_decoding_done_and_check(group, ctx)) {
328329
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_THREAD_SEND_DIAGNOSTIC_GET);
329330
return;
330331
}
331332

332-
openthread_api_mutex_lock(openthread_get_default_context());
333-
error = otThreadSendDiagnosticGet(openthread_get_default_instance(), &addr, tlvTypes, count,
334-
handle_receive_diagnostic_get, NULL);
335-
openthread_api_mutex_unlock(openthread_get_default_context());
336-
337333
nrf_rpc_rsp_send_uint(group, error);
338334
}
339335

340336
static void ot_rpc_cmd_send_diagnostic_reset(const struct nrf_rpc_group *group,
341337
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
342338
{
343339
otIp6Address addr;
344-
otError error;
345-
uint8_t count;
346-
uint8_t tlvTypes[35];
340+
otError error = OT_ERROR_INVALID_ARGS;
341+
size_t count;
342+
const uint8_t *tlvTypes;
347343

348344
nrf_rpc_decode_buffer(ctx, addr.mFields.m8, OT_IP6_ADDRESS_SIZE);
349345

350-
count = nrf_rpc_decode_uint(ctx);
346+
tlvTypes = nrf_rpc_decode_buffer_ptr_and_size(ctx, &count);
351347

352-
zcbor_list_start_decode(ctx->zs);
353-
for (int i = 0; i < count; i++) {
354-
tlvTypes[i] = nrf_rpc_decode_uint(ctx);
348+
if (tlvTypes) {
349+
openthread_api_mutex_lock(openthread_get_default_context());
350+
error = otThreadSendDiagnosticReset(openthread_get_default_instance(), &addr,
351+
tlvTypes, count);
352+
openthread_api_mutex_unlock(openthread_get_default_context());
355353
}
356-
zcbor_list_end_decode(ctx->zs);
357354

358355
if (!nrf_rpc_decoding_done_and_check(group, ctx)) {
359356
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_THREAD_SEND_DIAGNOSTIC_RESET);
360357
return;
361358
}
362359

363-
openthread_api_mutex_lock(openthread_get_default_context());
364-
error = otThreadSendDiagnosticReset(openthread_get_default_instance(), &addr, tlvTypes,
365-
count);
366-
openthread_api_mutex_lock(openthread_get_default_context());
367-
368360
nrf_rpc_rsp_send_uint(group, error);
369361
}
370362

0 commit comments

Comments
 (0)