Skip to content

Commit 7ba47ec

Browse files
Damian-Nordicnordicjm
authored andcommitted
net: openthread: rpc: prevent factory reset from hanging
When "factoryreset" shell command is received over RPC, send a response to the caller before executing the command, because the factory reset automatically reboots the board, which makes the caller wait for the response indefinitely. Signed-off-by: Damian Krolik <[email protected]>
1 parent db23520 commit 7ba47ec

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

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

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,13 @@ static int ot_cli_output_callback(void *aContext, const char *aFormat, va_list a
4343
static void ot_rpc_cmd_cli_init(const struct nrf_rpc_group *group, struct nrf_rpc_cbor_ctx *ctx,
4444
void *handler_data)
4545
{
46-
struct nrf_rpc_cbor_ctx rsp_ctx;
47-
48-
/* Parse the input */
49-
5046
nrf_rpc_cbor_decoding_done(group, ctx);
5147

52-
/* Initialize OT CLI */
53-
5448
openthread_api_mutex_lock(openthread_get_default_context());
5549
otCliInit(openthread_get_default_instance(), ot_cli_output_callback, NULL /* aContext*/);
5650
openthread_api_mutex_unlock(openthread_get_default_context());
5751

58-
/* Encode and send the response */
59-
60-
NRF_RPC_CBOR_ALLOC(group, rsp_ctx, 0);
61-
62-
nrf_rpc_cbor_rsp_no_err(group, &rsp_ctx);
52+
nrf_rpc_rsp_send_void(group);
6353
}
6454

6555
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_cmd_cli_init, OT_RPC_CMD_CLI_INIT, ot_rpc_cmd_cli_init,
@@ -68,10 +58,10 @@ NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_cmd_cli_init, OT_RPC_CMD_CLI_INIT, ot_
6858
static void ot_rpc_cmd_cli_input_line(const struct nrf_rpc_group *group,
6959
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
7060
{
71-
struct nrf_rpc_cbor_ctx rsp_ctx;
72-
char *buffer = NULL;
61+
char *buffer;
7362
const void *ptr;
7463
size_t len;
64+
bool reply_before_exec;
7565

7666
/* Parse the input */
7767
ptr = nrf_rpc_decode_str_ptr_and_len(ctx, &len);
@@ -84,29 +74,33 @@ static void ot_rpc_cmd_cli_input_line(const struct nrf_rpc_group *group,
8474
}
8575
}
8676

87-
if (!nrf_rpc_decoding_done_and_check(group, ctx)) {
88-
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_CLI_INPUT_LINE);
77+
nrf_rpc_cbor_decoding_done(group, ctx);
8978

90-
free(buffer);
79+
if (!ptr) {
80+
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_CLI_INPUT_LINE);
9181
return;
9282
}
9383

94-
if (!ptr || !buffer) {
84+
if (!buffer) {
85+
nrf_rpc_err(-ENOMEM, NRF_RPC_ERR_SRC_RECV, group, OT_RPC_CMD_CLI_INPUT_LINE,
86+
NRF_RPC_PACKET_TYPE_CMD);
9587
return;
9688
}
9789

98-
/* Execute OT CLI command */
90+
reply_before_exec = !strcmp(buffer, "factoryreset");
91+
92+
if (reply_before_exec) {
93+
nrf_rpc_rsp_send_void(group);
94+
}
95+
9996
openthread_api_mutex_lock(openthread_get_default_context());
10097
otCliInputLine(buffer);
10198
openthread_api_mutex_unlock(openthread_get_default_context());
102-
103-
/* Encode and send the response */
104-
105-
NRF_RPC_CBOR_ALLOC(group, rsp_ctx, 0);
106-
107-
nrf_rpc_cbor_rsp_no_err(group, &rsp_ctx);
108-
10999
free(buffer);
100+
101+
if (!reply_before_exec) {
102+
nrf_rpc_rsp_send_void(group);
103+
}
110104
}
111105

112106
NRF_RPC_CBOR_CMD_DECODER(ot_group, ot_rpc_cmd_cli_input_line, OT_RPC_CMD_CLI_INPUT_LINE,

0 commit comments

Comments
 (0)