| 1 |
/* |
| 2 |
* Copyright (c) 2023 joshua stein <jcs@jcs.org> |
| 3 |
* |
| 4 |
* Permission to use, copy, modify, and distribute this software for any |
| 5 |
* purpose with or without fee is hereby granted, provided that the above |
| 6 |
* copyright notice and this permission notice appear in all copies. |
| 7 |
* |
| 8 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 |
*/ |
| 16 |
|
| 17 |
#ifndef __NOMODEM_H__ |
| 18 |
#define __NOMODEM_H__ |
| 19 |
|
| 20 |
#include "session.h" |
| 21 |
#include "util.h" |
| 22 |
|
| 23 |
/* handshake sequence */ |
| 24 |
#define NOMODEM_START0 0x01 |
| 25 |
#define NOMODEM_START1 0x00 |
| 26 |
#define NOMODEM_START2 0x01 |
| 27 |
#define NOMODEM_START3 0x00 |
| 28 |
|
| 29 |
/* then a version */ |
| 30 |
#define NOMODEM_VERSION 0x01 |
| 31 |
|
| 32 |
/* then a command */ |
| 33 |
#define NOMODEM_CMD_SEND 0x01 /* we are sending you a file */ |
| 34 |
#define NOMODEM_CMD_RECEIVE 0x02 /* please upload a file to us */ |
| 35 |
|
| 36 |
#define NOMODEM_ACK 0x01 |
| 37 |
#define NOMODEM_CANCEL 0x03 /* ^C */ |
| 38 |
|
| 39 |
#define NOMODEM_TIMEOUT 20 |
| 40 |
|
| 41 |
enum { |
| 42 |
NOMODEM_MODE_SENDING, |
| 43 |
NOMODEM_MODE_RECEIVING |
| 44 |
}; |
| 45 |
|
| 46 |
struct nomodem_session { |
| 47 |
struct session *session; |
| 48 |
|
| 49 |
short mode; |
| 50 |
FILE *file; |
| 51 |
unsigned long file_size; |
| 52 |
char file_name[64]; |
| 53 |
char *file_path; |
| 54 |
bool need_header; |
| 55 |
bool need_header_ack; |
| 56 |
unsigned long last_input; |
| 57 |
|
| 58 |
unsigned char *buf; |
| 59 |
size_t buf_size; |
| 60 |
}; |
| 61 |
|
| 62 |
struct nomodem_session * nomodem_send(struct session *s, FILE *fp, |
| 63 |
char *filename); |
| 64 |
struct nomodem_session * nomodem_receive(struct session *s, char *path); |
| 65 |
bool nomodem_timed_out(struct nomodem_session *ns); |
| 66 |
bool nomodem_continue(struct nomodem_session *ns); |
| 67 |
void nomodem_finish(struct nomodem_session **nsp); |
| 68 |
unsigned short nomodem_get_char(struct nomodem_session *ns); |
| 69 |
|
| 70 |
#endif |