Skip to content

Commit

Permalink
nrf_rpc: detect reboot of the remote
Browse files Browse the repository at this point in the history
Raise an error when the remote sends an init packet with
unknown destination group ID after the group has been bound,
which indicates a reboot of the peer.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
  • Loading branch information
Damian-Nordic committed Nov 20, 2024
1 parent 58fe4d4 commit 370afd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions nrf_rpc/include/nrf_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ enum nrf_rpc_err_src {
NRF_RPC_ERR_SRC_RECV, /**< @brief Error during receiving */
NRF_RPC_ERR_SRC_SEND, /**< @brief Error during sending */
NRF_RPC_ERR_SRC_REMOTE, /**< @brief Error reported be the remote */
NRF_RPC_ERR_SRC_REBOOT, /**< @brief Error due to reboot of the remote */
};

/* Helper nRF group structure declaration needed for callback definition. */
Expand Down
7 changes: 7 additions & 0 deletions nrf_rpc/nrf_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ struct internal_task {
const struct nrf_rpc_group *group;
bool send_reply;
bool signal_groups_init_event;
bool signal_reboot;
} group_init;

struct {
Expand Down Expand Up @@ -379,6 +380,11 @@ static void internal_tx_handler(void)
case NRF_RPC_TASK_GROUP_INIT: {
const struct nrf_rpc_group *group = task.group_init.group;

if (task.group_init.signal_reboot) {
nrf_rpc_err(-NRF_ECONNRESET, NRF_RPC_ERR_SRC_REBOOT, group,
NRF_RPC_ID_UNKNOWN, NRF_RPC_PACKET_TYPE_INIT);
}

if (task.group_init.send_reply && group_init_send(group)) {
NRF_RPC_ERR("Failed to send group init packet for group id: %d strid: %s",
group->data->src_group_id, group->strid);
Expand Down Expand Up @@ -710,6 +716,7 @@ static int init_packet_handle(struct header *hdr, const struct nrf_rpc_group **g
internal_task.group_init.group = *group;
internal_task.group_init.send_reply = send_reply;
internal_task.group_init.signal_groups_init_event = signal_groups_init_event;
internal_task.group_init.signal_reboot = send_reply && !first_init;
nrf_rpc_os_thread_pool_send((const uint8_t *)&internal_task, sizeof(internal_task));
nrf_rpc_os_event_wait(&internal_task_consumed, NRF_RPC_OS_WAIT_FOREVER);
}
Expand Down

0 comments on commit 370afd5

Please sign in to comment.