Skip to content

Commit

Permalink
Fix multiple file download for FSIM fdo.download:done module
Browse files Browse the repository at this point in the history
Implement a queue to store fdo.download:done messages for multiple file downloads

Signed-off-by: Shrikant Temburwar <[email protected]>
  • Loading branch information
shrikant1407 committed Mar 4, 2024
1 parent 3395708 commit ff59117
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions device_modules/fdo_sim/fdo_sim_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ int fdo_sim_set_osi_args(int exec_array_index, size_t *exec_instructions_sz)
int fdo_sim_set_osi_exec(uint8_t **exec_instr)
{
int result = FDO_SI_INTERNAL_ERROR;
exit_code = -1;

if (fdor_is_value_null(fdor)) {
LOG(LOG_ERROR, "Module fdo.command - Failed to read "
Expand Down
18 changes: 15 additions & 3 deletions device_modules/fdo_sim/fdo_sim_download.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ static fdoSimModMsg write_type = FDO_SIM_MOD_MSG_NONE;

static fdo_hash_t *expectedCheckSum = NULL;
static size_t expected_len = -1;
static int return_code = -1;
static size_t bytes_received = 0;
static int fdo_sim_download_queue[MOD_MAX_BUFF_SIZE];
static int front = -1;
static int rear = -1;

int fdo_sim_download(fdo_sdk_si_type type, char *module_message,
uint8_t *module_val, size_t *module_val_sz,
Expand All @@ -47,6 +49,7 @@ int fdo_sim_download(fdo_sdk_si_type type, char *module_message,
uint8_t *bin_data = NULL;
size_t bin_len = 0;
size_t temp_module_val_sz = 0;
int return_code = -1;

switch (type) {
case FDO_SI_START:
Expand All @@ -66,10 +69,14 @@ int fdo_sim_download(fdo_sdk_si_type type, char *module_message,
result = fdo_sim_get_dsi_count(num_module_messages);
goto end;
case FDO_SI_GET_DSI:
return_code = (front == -1 || front > rear)
? -1
: fdo_sim_download_queue[front++];
result = fdo_sim_get_dsi(&fdow, mtu, module_message, module_val,
module_val_sz, return_code, bin_data,
temp_module_val_sz, &hasmore,
&write_type, filename);
hasmore = (front > rear) ? false : true;
goto end;
case FDO_SI_SET_OSI:
result = fdo_sim_set_osi_download(
Expand Down Expand Up @@ -298,6 +305,7 @@ int fdo_sim_set_osi_write(size_t bin_len, uint8_t *bin_data)

if (bytes_received == expected_len || !bin_len) {
// Entire file has been sent
bytes_received = 0;
result = FDO_SI_SUCCESS;
goto end;
}
Expand Down Expand Up @@ -365,15 +373,19 @@ int fdo_sim_set_osi_write(size_t bin_len, uint8_t *bin_data)
goto end;
}

if (front == -1) {
front = 0;
}

if (fdo_compare_hashes(hash, expectedCheckSum)) {
LOG(LOG_DEBUG,
"Module fdo.download - Hash matched \n");
return_code = file_len;
fdo_sim_download_queue[++rear] = file_len;
} else {
LOG(LOG_ERROR,
"Module fdo.download: Failed to verify "
" hash\n");
return_code = -1;
fdo_sim_download_queue[++rear] = -1;
}
}
hasmore = true;
Expand Down

0 comments on commit ff59117

Please sign in to comment.