void start_tx(struct pico_tftp_session *session, const char *filename, uint16_t port, int (*tx_callback)(struct pico_tftp_session *session, uint16_t err, uint8_t *block, int32_t len, void *arg), struct note_t *note) { if (pico_tftp_start_tx(session, port, filename, tx_callback, note)) { fprintf(stderr, "TFTP: Error in initialization\n"); exit(1); } }
int tftp_listen_cb(union pico_address *addr, uint16_t port, uint16_t opcode, char *filename) { printf("TFTP listen callback.\n"); if (opcode == PICO_TFTP_RRQ) { printf("Received TFTP get request for %s\n", filename); if(pico_tftp_start_tx(addr, port, PICO_PROTO_IPV4, filename, cb_tftp_tx) < 0) { fprintf(stderr, "TFTP: Error in initialization\n"); exit(1); } } else if (opcode == PICO_TFTP_WRQ) { printf("Received TFTP put request for %s\n", filename); if(pico_tftp_start_rx(addr, port, PICO_PROTO_IPV4, filename, cb_tftp) < 0) { fprintf(stderr, "TFTP: Error in initialization\n"); exit(1); } } else { printf ("Received invalid TFTP request %d\n", opcode); return -1; } return 0; }
void app_tftp(char *arg) { char *nxt; char *mode, *addr, *file; int tftp_mode; struct pico_ip4 server; nxt = cpy_arg(&mode, arg); if ((*mode == 's') || (*mode == 'c') || (*mode == 'p')) { /* TEST BENCH SEND MODE */ if (*mode == 's') { tftp_mode = TFTP_MODE_SRV; printf("tftp> Server\n"); } else { if (*mode == 'c') tftp_mode = TFTP_MODE_CLI; if (*mode == 'p') tftp_mode = TFTP_MODE_PSH; printf("tftp> Client\n"); if (!nxt) { printf("Usage: tftp:client:host:file:\n"); exit(1); } nxt = cpy_arg(&addr, nxt); if (pico_string_to_ipv4(addr, &server.addr) < 0) { printf("invalid host %s\n", addr); exit(1); } if (!nxt) { printf("Usage: tftp:client:host:file:\n"); exit(1); } nxt = cpy_arg(&file, nxt); } } else { printf("Usage: tftp:tx|rx|p:...\n"); } if (tftp_mode == TFTP_MODE_SRV) { pico_tftp_listen(PICO_PROTO_IPV4, tftp_listen_cb); } else if (tftp_mode == TFTP_MODE_CLI) { if(pico_tftp_start_rx((union pico_address *)&server, short_be(PICO_TFTP_PORT), PICO_PROTO_IPV4, file, cb_tftp) < 0) { fprintf(stderr, "TFTP: Error in initialization\n"); exit(1); } } else if (tftp_mode == TFTP_MODE_PSH) { if(pico_tftp_start_tx((union pico_address *)&server, short_be(PICO_TFTP_PORT), PICO_PROTO_IPV4, file, cb_tftp_tx) < 0) { fprintf(stderr, "TFTP: Error in initialization\n"); exit(1); } } else { printf("Usage: tftp:tx|rx|p:...\n"); } }