/* * Copyright (c) 2023 joshua stein * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef __NOMODEM_H__ #define __NOMODEM_H__ #include "session.h" #include "util.h" /* handshake sequence */ #define NOMODEM_START0 0x01 #define NOMODEM_START1 0x00 #define NOMODEM_START2 0x01 #define NOMODEM_START3 0x00 /* then a version */ #define NOMODEM_VERSION 0x01 /* then a command */ #define NOMODEM_CMD_SEND 0x01 /* we are sending you a file */ #define NOMODEM_CMD_RECEIVE 0x02 /* please upload a file to us */ #define NOMODEM_ACK 0x01 #define NOMODEM_CANCEL 0x03 /* ^C */ #define NOMODEM_TIMEOUT 20 enum { NOMODEM_MODE_SENDING, NOMODEM_MODE_RECEIVING }; struct nomodem_session { struct session *session; short mode; FILE *file; unsigned long file_size; char file_name[64]; char *file_path; bool need_header; bool need_header_ack; unsigned long last_input; unsigned char *buf; size_t buf_size; }; struct nomodem_session * nomodem_send(struct session *s, FILE *fp, char *filename); struct nomodem_session * nomodem_receive(struct session *s, char *path); bool nomodem_timed_out(struct nomodem_session *ns); bool nomodem_continue(struct nomodem_session *ns); void nomodem_finish(struct nomodem_session **nsp); unsigned short nomodem_get_char(struct nomodem_session *ns); #endif