81 lines
2.2 KiB
C
81 lines
2.2 KiB
C
/* ************************************************************************** */
|
|
/* _____ _ */
|
|
/* protocol/sendexe.c |_ _|__ _ _| |__ ___ _ _ */
|
|
/* | Project: libp7 | |/ _ \| | | | '_ \ / _ \ | | | */
|
|
/* | | (_) | |_| | | | | __/ |_| | */
|
|
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
|
/* Last updated: 2016/10/13 07:33:17 |___/ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
#include <libp7/internals.h>
|
|
|
|
/**
|
|
* p7_sendexe_stream:
|
|
* Send executable stream.
|
|
*
|
|
* @arg handle the libp7 handle
|
|
* @arg exe the update.exe to send
|
|
* @arg size the update.exe size
|
|
* @arg loadaddr the load address
|
|
* @arg straddr the start address
|
|
* @return 0 if it worked, error code otherwise
|
|
*/
|
|
|
|
int p7_sendexe_stream(p7_handle_t *handle,
|
|
FILE *exe, p7uint_t size, p7uint_t loadaddr, p7uint_t straddr)
|
|
{
|
|
int err;
|
|
|
|
/* make checks */
|
|
chk_isread(exe);
|
|
chk_handle(handle);
|
|
chk_active(handle);
|
|
chk_filesize(size);
|
|
|
|
/* send command */
|
|
log_info("sending up and run command");
|
|
if ((err = p7_send_cmdosu_upandrun(handle, size, loadaddr, straddr)))
|
|
return (err);
|
|
else if (response.type != p7_pt_ack) {
|
|
log_fatal("response wasn't ack");
|
|
return (p7_error_unknown);
|
|
}
|
|
|
|
/* upload executable */
|
|
if ((err = p7_send_filestream(handle, exe, size, 0, NULL)))
|
|
return (err);
|
|
|
|
/* we're good */
|
|
return (0);
|
|
}
|
|
|
|
/**
|
|
* p7_sendexe:
|
|
* Send executable.
|
|
*
|
|
* @arg handle the libp7 handle
|
|
* @arg exe the update.exe to send
|
|
* @arg loadaddr the load address
|
|
* @arg straddr the start address
|
|
* @return if it worked
|
|
*/
|
|
|
|
int p7_sendexe(p7_handle_t *handle,
|
|
FILE *exe, p7uint_t loadaddr, p7uint_t straddr)
|
|
{
|
|
/* make checks */
|
|
chk_isread(exe);
|
|
|
|
/* calculate exe size */
|
|
p7uint_t size;
|
|
if (fseek(exe, 0, SEEK_END)) {
|
|
log_fatal("seek failed!");
|
|
return (p7_error_noseek);
|
|
}
|
|
size = (p7uint_t)ftell(exe);
|
|
rewind(exe);
|
|
|
|
/* real func */
|
|
return (p7_sendexe_stream(handle, exe, size, loadaddr, straddr));
|
|
}
|