Skip to content

Commit

Permalink
libosdp: file: Do not disrupt SC when file TX fails
Browse files Browse the repository at this point in the history
Fixes: #99
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Feb 21, 2024
1 parent c08e7c0 commit 68cb607
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/osdp_cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,13 @@ static int cp_build_command(struct osdp_pd *pd, uint8_t *buf, int max_len)
buf[len++] = pd->cmd_id;
break;
case CMD_FILETRANSFER:
buf[len++] = pd->cmd_id;
ret = osdp_file_cmd_tx_build(pd, buf + len, max_len);
ret = osdp_file_cmd_tx_build(pd, buf + len + 1, max_len);
if (ret <= 0) {
return OSDP_CP_ERR_GENERIC;
/* (Only) Abort file transfer on failures */
buf[len++] = CMD_ABORT;
break;
}
buf[len++] = pd->cmd_id;
len += ret;
break;
case CMD_KEYSET:
Expand Down
16 changes: 9 additions & 7 deletions src/osdp_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int osdp_file_cmd_tx_build(struct osdp_pd *pd, uint8_t *buf, int max_len)
if ((size_t)max_len <= sizeof(struct osdp_cmd_file_xfer)) {
LOG_ERR("TX_Build: insufficient space need:%zu have:%d",
sizeof(struct osdp_cmd_file_xfer), max_len);
return -1;
goto reply_abort;
}

/**
Expand All @@ -68,19 +68,21 @@ int osdp_file_cmd_tx_build(struct osdp_pd *pd, uint8_t *buf, int max_len)
if (f->length < 0) {
LOG_ERR("TX_Build: user read failed! rc:%d len:%d off:%d",
f->length, buf_available, p->offset);
f->errors++;
f->length = 0;
return -1;
goto reply_abort;
}
if (f->length == 0) {
LOG_WRN("TX_Build: Read 0 length chunk; Aborting transfer!");
file_state_reset(f);
return -1;
LOG_WRN("TX_Build: Read 0 length chunk");
goto reply_abort;
}

p->length = f->length;

return sizeof(struct osdp_cmd_file_xfer) + f->length;

reply_abort:
LOG_ERR("TX_Build: Aborting file transfer due to unrecoverable error!");
file_state_reset(f);
return -1;
}

int osdp_file_cmd_stat_decode(struct osdp_pd *pd, uint8_t *buf, int len)
Expand Down

0 comments on commit 68cb607

Please sign in to comment.