int cb_tftp_tx(struct pico_tftp_session *session, uint16_t event, uint8_t *block, int32_t len, void *arg) { struct note_t *note = (struct note_t *) arg; if (event != PICO_TFTP_EV_OK) { fprintf(stderr, "TFTP: Error %" PRIu16 ": %s\n", event, block); exit(1); } len = read(note->fd, tftp_txbuf, PICO_TFTP_PAYLOAD_SIZE); if (len >= 0) { note->filesize += len; pico_tftp_send(session, tftp_txbuf, len); if (len < PICO_TFTP_PAYLOAD_SIZE) { printf("TFTP: file %s (%" PRId32 " bytes) TX transfer complete!\n", note->filename, note->filesize); close(note->fd); del_note(note); } } else { perror("read"); fprintf(stderr, "Filesystem error reading file %s, cancelling current transfer\n", note->filename); pico_tftp_abort(session, TFTP_ERR_EACC, "Error on read"); del_note(note); } if (!clipboard) pico_timer_add(3000, deferred_exit, NULL); return len; }
int cb_tftp_tx(uint16_t err, uint8_t *block, uint32_t len) { static int fd = -1; static int count = 1; (void)block; if (fd == -1) { fd = open("/dev/urandom", O_RDONLY); if (fd < 0) { perror("open"); exit(1); } } if (err != PICO_TFTP_ERR_OK) { printf("TFTP: Error %d: %s\n", err, block); exit(1); } if (count++ == TFTP_TX_COUNT) { len = 0; close(fd); pico_timer_add(2000, deferred_exit, NULL); } else { len = read(fd, tftp_txbuf, PICO_TFTP_SIZE); } if (len >= 0) { pico_tftp_send(tftp_txbuf, len); } return len; }