Skip to content

Commit

Permalink
zero: csp-handler: Fix missing error telemetry
Browse files Browse the repository at this point in the history
Fixes an issue where reply telemetry was not returned for
file-related commands with invalid sizes or command IDs.

Signed-off-by: Takuya Sasaki <takuya.sasaki@spacecubics.com>
  • Loading branch information
sasataku committed Nov 22, 2024
1 parent d847422 commit 9571284
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 16 additions & 2 deletions zero/meta-csp/recipes-cspd/csp-handler/files/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
static GQueue file_work_queue;
static pthread_t file_work;

void send_err_reply(csp_packet_t *packet, uint8_t command_id, int err_code)
{
struct file_err_reply_telemetry tlm;

tlm.telemetry_id = command_id;
tlm.error_code = htole32(err_code);

memcpy(packet->data, &tlm, sizeof(tlm));
packet->length = sizeof(tlm);

csp_sendto_reply(packet, packet, CSP_O_SAME);
}

static void csp_file_work(csp_packet_t *packet)
{
int ret = 0;
Expand All @@ -44,7 +57,7 @@ static void csp_file_work(csp_packet_t *packet)
sd_journal_print(LOG_ERR, "Invalide command size: %d", packet->length);
ret = -EINVAL;
command_id = CSP_UNKNOWN_COMMAND_ID;
goto free;
goto reply;
}

command_id = packet->data[CSP_COMMAND_ID_OFFSET];
Expand All @@ -66,8 +79,9 @@ static void csp_file_work(csp_packet_t *packet)
break;
}

free:
reply:
if (ret < 0) {
send_err_reply(packet, command_id, ret);
}

end:
Expand Down
5 changes: 5 additions & 0 deletions zero/meta-csp/recipes-cspd/csp-handler/files/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@

#include <csp/csp.h>

struct file_err_reply_telemetry {
uint8_t telemetry_id;
uint32_t error_code;
} __attribute__((__packed__));

void file_handler_init(void);
void file_handler(csp_packet_t *packet);

0 comments on commit 9571284

Please sign in to comment.