/****************************************************************************
*	Author		:	G Todd													*
*	Language 	:	Turbo C 2.0												*
*	Logfile		:	zmnp.h													*
*	Project		:	Comms library.											*
*	Date 		:	17 Jan 90												*
*	Revision 	:	1.1		GT	Originate.									*
*****************************************************************************
*	Purpose		:	Public definitions for comms library.					*
*				:	Copyright 1990 Giles Todd.								*
****************************************************************************/

#ifndef ZMNP_H
#define	ZMNP_H

/****************************************************************************
*	Structure definitions.													*
****************************************************************************/

/* MNP link status block */

struct link_stat_blk
	{
	unsigned int p_status;					/* physical connection status	*/
	unsigned int l_status;					/* MNP link status				*/
	unsigned int s_count;					/* Tx buf bytes free			*/
	unsigned int r_count;					/* Rx buf bytes ready			*/
	unsigned int all_sent;					/* all sent flag				*/
	};


/****************************************************************************
*	Basic async comms functions.											*
****************************************************************************/

/****************************************************************************
*	connect																	*
*	Initialise 8250 and interrupt vectors.									*
****************************************************************************/

int connect (int rate, int data, int parity, int stop, int port, int handshake);

/****************************************************************************
*	hang_up																	*
*	Drops DTR for half a second.											*
****************************************************************************/

void hangup (void);

/****************************************************************************
*	disconnect																*
*	Hang up, restore 8250 settings and remove isr.							*
****************************************************************************/

void disconnect (void);

/****************************************************************************
*	send																	*
*	Insert up to <buflen> bytes from <sndbuf> into the Tx buffer.  Return	*
*	number of bytes inserted.												*
****************************************************************************/

int send (unsigned char *sndbuf, unsigned int buflen);

/****************************************************************************
*	receive																	*
*	Copy up to <buflen> bytes from <rxbuf> into <rcvbuf>.  Return number of	*
*	bytes copied.															*
****************************************************************************/

int receive (unsigned char *rcvbuf, unsigned int buflen);

/****************************************************************************
*	bufstat																	*
*	Returns number of bytes free in Tx buffer and number of bytes ready in	*
*	Rx buffer.																*
****************************************************************************/

void bufstat (unsigned short *s_free, unsigned short *r_ready);

/****************************************************************************
*	linestat																*
*	Returns the latest copy of the 8250 line status register.				*
****************************************************************************/

unsigned char linestat (void);

/****************************************************************************
*	modemstat																*
*	Returns the latest copy of the 8250 modem status register.				*
****************************************************************************/

unsigned char modemstat (void);


/****************************************************************************
*	MNP 2 function prototypes.												*
****************************************************************************/

/****************************************************************************
*	mnpconnect - establish an MNP link-connection.							*
*	synopsis:	retcode = mnpconnect (mode);								*
*	input:	unsigned int mode;		0 = originator/1 = answerer				*
*	output:	int retcode;			establishment result					*
****************************************************************************/

int mnpconnect (unsigned int mode);
	
/****************************************************************************
*	mnpdisconnect - terminate an MNP link-connection.						*
*	synopsis:	mnpdisconnect ();											*
*	input:	none															*
*	output:	none															*
****************************************************************************/

void mnpdisconnect (void);

/****************************************************************************
*	mnpreceive - receive data on an MNP link-connection.					*
*	synopsis:	retcode = mnpreceive (&buffer, buflen);						*
*	input:	unsigned char *buffer;	pointer to user buffer					*
*			int buflen;				length of user buffer					*
*	output:	int retcode;	if positive, the number of data bytes			*
*							copied into the user data buffer;				*
*							if negative, link error code					*
****************************************************************************/

int mnpreceive (unsigned char *bufptr, unsigned int buflen);
	
/****************************************************************************
*	mnpsend - send data on an MNP link-connection.							*
*	synopsis:	retcode = mnpsend (&buffer, buflen);						*
*	input:	unsigned char *buffer; 	pointer to user data buffer				*
*			int buflen;				length of user data buffer				*
*	output: int retcode - if positive, the number of data bytes				*
*						  copied from the user data buffer; 				*
*						  if negative, link error code						*
****************************************************************************/
	
int mnpsend (unsigned char *bufptr, unsigned int buflen);
	
/****************************************************************************
*	mnpstatus - get link-connection status information.						*
*	synopsis:	mnpstatus (&lstat_blk);										*
*	input:	struct link_stat_blk *lstat_blk;	pointer to status block		*
*	output:	none															*
****************************************************************************/
	
void mnpstatus (struct link_stat_blk *lsb);
	
/****************************************************************************
*	mnpbreak - send a break signal (using MNP attention).					*
*	synopsis:	retcode = mnpbreak ();										*
*	input:	none															*
*	output:	int retcode;	link error code									*
****************************************************************************/
	
int mnpbreak (void);


/****************************************************************************
*	ZMODEM function prototypes.												*
****************************************************************************/

/****************************************************************************
*	sendfile.																*
*	Send file(s).  Returns 0 if successful.									*
****************************************************************************/

int sendfile (char protocol, char *options, char *filenames[],
			  void (*reporter) (int type, void *data));

/****************************************************************************
*	getfile																	*
*	Receives file(s).  Returns 0 if successful.								*
****************************************************************************/

int getfile (char protocol, char *options, char *filename,
			 void (*reporter) (int type, void *data));

#endif
