/* TNC-2 emulator for use by RLI or MBL bbs */

#define TNCPARAMS	79		/* number of TNC parameter bytes */
#define TNCTEXTS	4		/* number of TNC parameter texts */
#define TNCTIMERS	3		/* number of TNC every/after timers */

/* input/output fifo */
struct tncfifo {
	char *begin;			/* first byte of buffer */
	char *end;			/* last byte of buffer + 1 */
	char *in;			/* where bytes are added */
	char *out;			/* where bytes are removed */
	int  num;			/* number of bytes in buffer */
};

/* controlblock for each BBS TNC supported */
struct tnc {
	/* static info about this TNC */
	struct tnc *next;		/* next in list */
	int dev;			/* TNC I/O device (COM number) */
	struct interface *interface;	/* associated interface */
	struct ax25_call *axcall;	/* associated AX.25 port */
	/* state information, updated by connections and mode changes */
	struct ax25_cb *axp;		/* AX.25 connection, if any */
	int linepos;			/* current line buffer pos */
	int passc;			/* PASS-character flag */
	int mode;			/* operation mode */
#define TM_CMD		0		/* command mode */
#define TM_CONV		1		/* converse mode */
#define TM_TRANS	2		/* transparent mode */
#define TM_KISS		3		/* KISS mode */
	/* parameters of the TNC set by the various customization commands */
	int conmode;			/* connect mode */
	char param[TNCPARAMS];		/* TNC parameter info */
	char *text[TNCTEXTS];		/* TNC parameter texts */
	struct timer timer[TNCTIMERS];	/* TNC timers */
	char every[TNCTIMERS];		/* EVERY/AFTER flag for timers */
	struct ax25 unproto;		/* UI address plus digis */
	/* input/output buffer areas */
	int status;			/* various I/O status flags */
#define TS_TXBUF	0x01		/* transmit buffer enabled */
#define TS_RXOVR	0x02		/* receive overrun */
#define TS_TXOVR	0x04		/* transmit overrun */
#define TS_RXSTOP	0x08		/* receive flow control */
#define TS_TXSTOP	0x10		/* transmit flow control */
#define TS_TXHOLD	0x20		/* transmit hold by "drop RTS" */
#define TS_BREAK	0x40		/* BREAK received */
#define TS_DCD		0x80		/* TNC is CONNECTED (give DCD) */
	struct tncfifo input;		/* input (from client to TNC) FIFO */
	struct tncfifo output;		/* output (from TNC to client) FIFO */
	struct slip slip;		/* SLIP struct for KISS emulation */
#ifdef ATARI_ST
	void (*save_vec[4])();		/* saved I/O vectors */
#endif
	char linebuf[260];		/* input line buffer */
};
#define NULLTNC		((struct tnc *) 0)

extern struct tnc *tnc2s;		/* one for every emulated TNC2 */

/* command table entry for the emulated TNC */
struct tnccommand {
	char name[9];			/* command name +\0, max 8 chars */
	char type;			/* selects type of command using: */
#define TC_EXEC		0		/* executed using function spec'd */
#define TC_ON_OFF	1		/* on/off switch */
#define TC_DECVAL	2		/* decimal value */
#define TC_HEXVAL	3		/* hexadecimal value */
#define TC_TEXT		4		/* text value */
#define TC_TIMER	5		/* timer every/after */
#define TC_MISC		6		/* miscellaneous setting */
	int paramnum;			/* parameter number (if any) */
	void (*func)();			/* executing function (if any) */
};

/* return values from tnc2_line() */

#define TL_INCOMPLETE	0		/* incomplete line, wait for next ch */
#define TL_CANCEL	1		/* line cancelled by CANLINE */
#define TL_COMPLETE	2		/* complete line entered */
#define TL_PACKET	3		/* complete packet entered */
#define TL_COMMAND	4		/* escape to commandmode */

/* magic character return values */

#define TCH_NOCHAR	-1		/* no character available */
#define TCH_BREAK	256		/* received a BREAK */
