|
| 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