|
4 | 4 | * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
5 | 5 | */ |
6 | 6 |
|
| 7 | +#include "zcbor_common.h" |
| 8 | +#include "zcbor_decode.h" |
| 9 | +#include "zcbor_encode.h" |
7 | 10 | #include <ot_rpc_ids.h> |
8 | 11 | #include <ot_rpc_types.h> |
9 | 12 | #include <ot_rpc_common.h> |
10 | 13 |
|
11 | 14 | #include <nrf_rpc_cbor.h> |
12 | 15 |
|
| 16 | +#include <openthread/netdata.h> |
13 | 17 | #include <openthread/ip6.h> |
14 | 18 | #include <openthread/link.h> |
15 | 19 | #include <openthread/thread.h> |
@@ -481,3 +485,164 @@ void otLinkGetFactoryAssignedIeeeEui64(otInstance *aInstance, otExtAddress *aEui |
481 | 485 | nrf_rpc_cbor_cmd_no_err(&ot_group, OT_RPC_CMD_LINK_GET_FACTORY_ASSIGNED_EUI64, &ctx, |
482 | 486 | ot_rpc_decode_eui64, aEui64->m8); |
483 | 487 | } |
| 488 | + |
| 489 | +otError otNetDataGet(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength) |
| 490 | +{ |
| 491 | + struct zcbor_string zstr; |
| 492 | + struct nrf_rpc_cbor_ctx ctx; |
| 493 | + otError error = OT_ERROR_NONE; |
| 494 | + bool decoded_ok = true; |
| 495 | + |
| 496 | + NRF_RPC_CBOR_ALLOC(&ot_group, ctx, 5); |
| 497 | + |
| 498 | + if (!zcbor_bool_put(ctx.zs, aStable)) { |
| 499 | + NRF_RPC_CBOR_DISCARD(&ot_group, ctx); |
| 500 | + error = OT_ERROR_INVALID_ARGS; |
| 501 | + goto exit; |
| 502 | + } |
| 503 | + |
| 504 | + if (!zcbor_uint_encode(ctx.zs, aDataLength, sizeof(*aDataLength))) { |
| 505 | + NRF_RPC_CBOR_DISCARD(&ot_group, ctx); |
| 506 | + error = OT_ERROR_INVALID_ARGS; |
| 507 | + goto exit; |
| 508 | + } |
| 509 | + |
| 510 | + nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, OT_RPC_CMD_NETDATA_GET, &ctx); |
| 511 | + |
| 512 | + decoded_ok = zcbor_nil_expect(ctx.zs, NULL); |
| 513 | + |
| 514 | + if (decoded_ok) { |
| 515 | + *aDataLength = 0; |
| 516 | + goto decode_error; |
| 517 | + } |
| 518 | + |
| 519 | + if (ctx.zs->constant_state->error != ZCBOR_ERR_WRONG_TYPE) { |
| 520 | + decoded_ok = false; |
| 521 | + error = OT_ERROR_FAILED; |
| 522 | + goto exit; |
| 523 | + } |
| 524 | + |
| 525 | + zcbor_pop_error(ctx.zs); |
| 526 | + |
| 527 | + decoded_ok = zcbor_bstr_decode(ctx.zs, &zstr); |
| 528 | + |
| 529 | + if (!decoded_ok) { |
| 530 | + error = OT_ERROR_FAILED; |
| 531 | + goto exit; |
| 532 | + } |
| 533 | + |
| 534 | + memcpy(aData, zstr.value, (zstr.len < *aDataLength ? zstr.len : *aDataLength)); |
| 535 | + |
| 536 | +decode_error: |
| 537 | + if (!zcbor_uint_decode(ctx.zs, &error, sizeof(error))) { |
| 538 | + error = OT_ERROR_FAILED; |
| 539 | + } |
| 540 | + |
| 541 | + nrf_rpc_cbor_decoding_done(&ot_group, &ctx); |
| 542 | + |
| 543 | +exit: |
| 544 | + if (!decoded_ok) { |
| 545 | + nrf_rpc_cbor_decoding_done(&ot_group, &ctx); |
| 546 | + ot_rpc_report_decoding_error(OT_RPC_CMD_NETDATA_GET); |
| 547 | + } |
| 548 | + |
| 549 | + return error; |
| 550 | +} |
| 551 | + |
| 552 | +otError otNetDataGetNextService(otInstance *aInstance, otNetworkDataIterator *aIterator, |
| 553 | + otServiceConfig *aConfig) |
| 554 | +{ |
| 555 | + struct nrf_rpc_cbor_ctx ctx; |
| 556 | + otError error; |
| 557 | + bool decoded_ok = true; |
| 558 | + |
| 559 | + NRF_RPC_CBOR_ALLOC(&ot_group, ctx, sizeof(*aIterator) + 1); |
| 560 | + |
| 561 | + if (!zcbor_uint_encode(ctx.zs, aIterator, sizeof(*aIterator))) { |
| 562 | + NRF_RPC_CBOR_DISCARD(&ot_group, ctx); |
| 563 | + error = OT_ERROR_INVALID_ARGS; |
| 564 | + goto exit; |
| 565 | + } |
| 566 | + |
| 567 | + nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, OT_RPC_CMD_NETDATA_GET_NEXT_SERVICE, &ctx); |
| 568 | + |
| 569 | + decoded_ok = zcbor_uint_decode(ctx.zs, aIterator, sizeof(*aIterator)); |
| 570 | + |
| 571 | + if (!decoded_ok) { |
| 572 | + error = OT_ERROR_FAILED; |
| 573 | + goto exit; |
| 574 | + } |
| 575 | + |
| 576 | + decoded_ok = ot_rpc_decode_service_config(&ctx, aConfig); |
| 577 | + |
| 578 | + if (!decoded_ok) { |
| 579 | + error = OT_ERROR_FAILED; |
| 580 | + goto exit; |
| 581 | + } |
| 582 | + |
| 583 | + decoded_ok = zcbor_uint_decode(ctx.zs, &error, sizeof(error)); |
| 584 | + |
| 585 | + if (!decoded_ok) { |
| 586 | + error = OT_ERROR_FAILED; |
| 587 | + goto exit; |
| 588 | + } |
| 589 | + |
| 590 | + nrf_rpc_cbor_decoding_done(&ot_group, &ctx); |
| 591 | + |
| 592 | +exit: |
| 593 | + if (!decoded_ok) { |
| 594 | + nrf_rpc_cbor_decoding_done(&ot_group, &ctx); |
| 595 | + ot_rpc_report_decoding_error(OT_RPC_CMD_NETDATA_GET_NEXT_SERVICE); |
| 596 | + } |
| 597 | + |
| 598 | + return error; |
| 599 | +} |
| 600 | + |
| 601 | +otError otNetDataGetNextOnMeshPrefix(otInstance *aInstance, otNetworkDataIterator *aIterator, |
| 602 | + otBorderRouterConfig *aConfig) |
| 603 | +{ |
| 604 | + struct nrf_rpc_cbor_ctx ctx; |
| 605 | + otError error = OT_ERROR_NONE; |
| 606 | + bool decoded_ok = true; |
| 607 | + |
| 608 | + NRF_RPC_CBOR_ALLOC(&ot_group, ctx, sizeof(*aIterator) + 1); |
| 609 | + |
| 610 | + if (!zcbor_uint_encode(ctx.zs, aIterator, sizeof(*aIterator))) { |
| 611 | + NRF_RPC_CBOR_DISCARD(&ot_group, ctx); |
| 612 | + error = OT_ERROR_INVALID_ARGS; |
| 613 | + goto exit; |
| 614 | + } |
| 615 | + |
| 616 | + nrf_rpc_cbor_cmd_rsp_no_err(&ot_group, OT_RPC_CMD_NETDATA_GET_NEXT_ON_MESH_PREFIX, &ctx); |
| 617 | + |
| 618 | + decoded_ok = zcbor_uint_decode(ctx.zs, aIterator, sizeof(*aIterator)); |
| 619 | + |
| 620 | + if (!decoded_ok) { |
| 621 | + error = OT_ERROR_FAILED; |
| 622 | + goto exit; |
| 623 | + } |
| 624 | + |
| 625 | + decoded_ok = ot_rpc_decode_border_router_config(&ctx, aConfig); |
| 626 | + |
| 627 | + if (!decoded_ok) { |
| 628 | + error = OT_ERROR_FAILED; |
| 629 | + goto exit; |
| 630 | + } |
| 631 | + |
| 632 | + decoded_ok = zcbor_uint_decode(ctx.zs, &error, sizeof(error)); |
| 633 | + |
| 634 | + if (!decoded_ok) { |
| 635 | + error = OT_ERROR_FAILED; |
| 636 | + goto exit; |
| 637 | + } |
| 638 | + |
| 639 | + nrf_rpc_cbor_decoding_done(&ot_group, &ctx); |
| 640 | + |
| 641 | +exit: |
| 642 | + if (!decoded_ok) { |
| 643 | + ot_rpc_report_decoding_error(OT_RPC_CMD_NETDATA_GET_NEXT_ON_MESH_PREFIX); |
| 644 | + nrf_rpc_cbor_decoding_done(&ot_group, &ctx); |
| 645 | + } |
| 646 | + |
| 647 | + return error; |
| 648 | +} |
0 commit comments