Skip to content

Commit

Permalink
mgmt: ec_host_cmd: verify a command before passing it to handler
Browse files Browse the repository at this point in the history
Verify validity of a received command before passing it to the general
handler.

It allows performing some actions, right after receiving the command.
The context switch is not needed. Such feature may be needed for
overloaded system, where instant reboot is required.

Signed-off-by: Dawid Niedzwiecki <[email protected]>
  • Loading branch information
niedzwiecki-dawid committed Jul 3, 2023
1 parent bdd1808 commit d69d00c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/zephyr/mgmt/ec_host_cmd/ec_host_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct ec_host_cmd {
* when data in rx_ctx are ready. The handler takes rx_ready to read data in rx_ctx.
*/
struct k_sem rx_ready;
/** Status of the rx data checked in the ec_host_cmd_send_received function. */
enum ec_host_cmd_status rx_status;
#ifdef CONFIG_EC_HOST_CMD_DEDICATED_THREAD
struct k_thread thread;
#endif /* CONFIG_EC_HOST_CMD_DEDICATED_THREAD */
Expand Down
12 changes: 9 additions & 3 deletions subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ int ec_host_cmd_send_response(enum ec_host_cmd_status status,
void ec_host_cmd_rx_notify(void)
{
struct ec_host_cmd *hc = &ec_host_cmd;
struct ec_host_cmd_rx_ctx *rx = &hc->rx_ctx;

hc->rx_status = verify_rx(rx);

k_sem_give(&hc->rx_ready);
}
Expand Down Expand Up @@ -304,9 +307,12 @@ FUNC_NORETURN static void ec_host_cmd_thread(void *hc_handle, void *arg2, void *
k_sem_take(&hc->rx_ready, K_FOREVER);

ec_host_cmd_log_request(rx->buf);
status = verify_rx(rx);
if (status != EC_HOST_CMD_SUCCESS) {
ec_host_cmd_send_response(status, &args);

/* Check status of the rx data, that has been verified in
* ec_host_cmd_send_received.
*/
if (hc->rx_status != EC_HOST_CMD_SUCCESS) {
ec_host_cmd_send_response(hc->rx_status, &args);
continue;
}

Expand Down

0 comments on commit d69d00c

Please sign in to comment.