void app_tftp(char *arg) { struct command_t *commands; struct note_t *note; struct pico_tftp_session *session; int is_server_enabled = 0; int filesize; family = IPV6_MODE ? PICO_PROTO_IPV6 : PICO_PROTO_IPV4; commands = parse_arguments(arg); while (commands) { if (toupper(commands->operation) != 'S') note = transfer_prepare(&session, commands->operation, commands->filename, &commands->server_address, family); switch (commands->operation) { case 'S': case 's': if (!is_server_enabled) { pico_tftp_listen(PICO_PROTO_IPV4, (commands->operation == 'S') ? tftp_listen_cb_opt : tftp_listen_cb); is_server_enabled = 1; } break; case 'T': filesize = get_filesize(commands->filename); if (filesize < 0) { fprintf(stderr, "TFTP: unable to read size of file %s\n", commands->filename); exit(3); } pico_tftp_set_option(session, PICO_TFTP_OPTION_FILE, filesize); start_tx(session, commands->filename, short_be(PICO_TFTP_PORT), cb_tftp_tx_opt, note); break; case 't': start_tx(session, commands->filename, short_be(PICO_TFTP_PORT), cb_tftp_tx, note); break; case 'R': pico_tftp_set_option(session, PICO_TFTP_OPTION_FILE, 0); start_rx(session, commands->filename, short_be(PICO_TFTP_PORT), cb_tftp_rx_opt, note); break; case 'r': start_rx(session, commands->filename, short_be(PICO_TFTP_PORT), cb_tftp_rx, note); } commands = commands->next; } }
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"); } }