#ifndef __KERMIT_H__ #define __KERMIT_H__ #define VERSION "EKSW-0.94" /* Kermit module version number */ /* kermit.h -- Symbol and struct definitions for embedded Kermit. */ /* Author: Frank da Cruz and John Dunlap. Copyright (C) 1995, 2011, Trustees of Columbia University in the City of New York. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Columbia University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef COMMENT /* COMMENT must not be defined */ #undef COMMENT /* (e.g. in a platform header file) */ #endif /* COMMENT */ /* Never use NULL as a pointer. Always use 0 cast to the appropriate type, for example: (UCHAR *)0. Reason: system might define NULL to be an integer 0, and when passed to a function that wants a pointer, might wind up with junk in the left half (if pointers wider than ints). */ #ifdef NULL #undef NULL #endif /* NULL */ /* Feature Selection */ # define P_WSLOTS 3 # define P_PKTLEN 1000 # undef NO_CTRLC // allow 3 ctrl-c chars to terminate # define NO_SCAN // we have no file system # define FN_MAX 64 // filename buf size # define IBUFLEN 512 // readfile buf size # define OBUFLEN 512 // writefile buf size #ifndef NO_CTRLC #define F_CTRLC /* 3 consecutive Ctrl-C's to quit */ #endif /* NO_CTRLC */ #ifndef NO_SCAN #define F_SCAN /* Scan files for text/binary */ #endif /* NO_SCAN */ #ifdef COMMENT /* None of the following ... */ /* + = It works if selected - = Partially implemented but doesn't work 0 = Not implemented */ #define F_LS /* 0 Locking shifts */ #define F_RS /* 0 Recovery */ #endif /* COMMENT */ /* Control character symbols */ #define NUL '\0' /* Null */ #define SOH 001 /* Start of header */ #define LF 012 /* Linefeed */ #define CR 015 /* Carriage Return */ #define SO 016 /* Shift Out */ #define SI 017 /* Shift In */ #define DLE 020 /* Datalink Escape */ #define ESC 033 /* Escape */ #define XON 021 /* XON */ #define XOFF 023 /* XOFF */ #define SP 040 /* Space */ #define DEL 0177 /* Delete (Rubout) */ #ifndef HAVE_VERSION /* k_data struct has version member */ #define HAVE_VERSION /* as of version 1.1 */ #endif /* HAVE_VERSION */ /* Main program return codes */ #define SUCCESS 0 #define FAILURE 1 /* Buffer lengths (can be overridden in platform.h) */ #ifndef RECVONLY #ifndef IBUFLEN #define IBUFLEN 1024 /* File input buffer size */ #endif /* IBUFLEN */ #endif /* RECVONLY */ #ifndef OBUFLEN #define OBUFLEN 1024 /* File output buffer size */ #endif /* OBUFLEN */ #ifndef IDATALEN /* S/I packet data max length */ #define IDATALEN 32 #endif /* IDATALEN */ #ifndef FN_MAX #define FN_MAX 1024 /* Maximum filename length */ #endif /* FN_MAX */ #define DATE_MAX 20 /* Max length for file date */ /* Generic On/Off values */ #define OFF 0 #define ON 1 /* File Transfer Modes */ #define BINARY 1 #define TEXT 0 /* Parity values */ #define PAR_NONE 0 #define PAR_SPACE 1 #define PAR_EVEN 2 #define PAR_ODD 3 #define PAR_MARK 4 /* Protocol parameters */ # define P_BUFLEN (P_PKTLEN+8) #define P_S_TIMO 5 /* Timeout to tell other Kermit */ #define P_R_TIMO 5 /* Default timeout for me to use */ #define P_RETRY 20 /* Per-packet resend limit */ #define P_PARITY PAR_NONE /* Default parity */ #define P_R_SOH SOH /* Incoming packet start */ #define P_S_SOH SOH /* Outbound packet start */ #define P_R_EOM CR /* Incoming packet end */ #define P_S_EOM CR /* Outbound packet end */ /* Capability bits */ #define CAP_LP 2 /* Long packet capability */ #define CAP_SW 4 /* Sliding windows capability */ #define CAP_AT 8 /* Attribute packet capability */ #define CAP_RS 16 /* Resend capability */ #define CAP_LS 32 /* Locking shift capability */ /* Actions */ #define A_SEND 1 /* Send file(s) */ #define A_RECV 2 /* Receive file(s) */ #define A_GET 3 /* Get file(s) */ /* Receive protocol states */ #define R_ERROR -1 /* Fatal protocol error */ #define R_NONE 0 /* Protocol not running */ #define R_WAIT 1 /* Waiting for S packet */ #define R_FILE 2 /* Waiting for F or B packet */ #define R_ATTR 3 /* Waiting for A or D packet */ #define R_DATA 4 /* Waiting for D or Z packet */ /* Send protocol states */ #define S_ERROR -1 /* Fatal protocol error */ #define S_NONE 10 /* Protocol not running */ #define S_INIT 11 /* Sent S packet */ #define S_FILE 12 /* Sent F packet */ #define S_ATTR 13 /* Sent A packet */ #define S_DATA 14 /* Sent D packet */ #define S_EOF 15 /* Sent Z packet */ #define S_EOT 16 /* Sent B packet -- end of bunch */ #define S_GET 17 /* Sent R packet to init "get" */ /* What I'm Doing */ #define W_NOTHING 0 #define W_SEND 1 #define W_RECV 2 #define W_GET 3 /* Kermit module function codes */ #define K_INIT 0 /* Initialize */ #define K_RUN 1 /* Run */ #define K_STATUS 2 /* Request status */ #define K_CONTINUE 3 /* Keep going */ #define K_QUIT 4 /* Quit immediately */ #define K_ERROR 5 /* Quit with error packet, msg given */ #define K_SEND 6 /* Begin Send sequence */ #define K_GET 7 /* Begin Get sequence */ #define K_SYNC 8 /* to reset server */ /* Kermit module return codes */ #define X_ERROR -1 /* Fatal error */ #define X_OK 0 /* OK, no action needed */ #define X_FILE 1 /* Filename received */ #define X_DATA 2 /* File data received */ #define X_DONE 3 /* Done */ #define X_STATUS 4 /* Status report */ /* Interruption codes */ #define I_FILE 1 /* Cancel file */ #define I_GROUP 2 /* Cancel group */ struct packet { int len; /* Length */ short seq; /* Sequence number */ char typ; /* Type */ short rtr; /* Retry count */ UCHAR *dat; /* Pointer to data */ USHORT crc; short flg; /* Flags */ UCHAR *buf; }; struct k_data { /* The Kermit data structure */ UCHAR *version; /* Version number of Kermit module */ short remote; /* 0 = local, 1 = remote */ short xfermode; /* 0 = automatic, 1 = manual */ short binary; /* 0 = text, 1 = binary */ short state; /* Kermit protocol state */ short what; /* Action (send or receive) */ short s_first; /* Encode at beginning of file */ short s_next; /* Encode lookahead byte */ short s_seq; /* Sequence number sent */ long s_cnt; // count packets sent short r_seq; /* Sequence number received */ short s_type; /* Packet type sent */ short r_type; /* Packet type received */ short s_soh; /* Packet start sent */ short r_soh; /* Packet start received */ short s_eom; /* Packet end sent */ short r_eom; /* Packet end received */ int size; /* Current size of output pkt data */ int osize; /* Previous output packet data size */ int r_timo; /* Receive and send timers */ int s_timo; /* ... */ int r_maxlen; /* maximum packet length to receive */ int s_maxlen; /* maximum packet length to send */ int p_maxlen; short wslots_max; // max window slots to negotiate short wslots; /* current window slots */ long send_pause_us; short parity; /* 0 = none, nonzero = some */ short retry; /* retry limit */ short cancel; /* Cancellation */ short ikeep; /* Keep incompletely received files */ char s_ctlq; /* control-prefix out */ char r_ctlq; /* control-prefix in */ char ebq; /* 8-bit prefix */ char ebqflg; /* 8-bit prefixing negotiated */ char rptq; /* Repeat-count prefix */ int s_rpt; /* Current repeat count */ short rptflg; /* flag for repeat counts negotiated */ short bct; /* Block-check type 1..3 */ short bcta3; /* force block check type always 3 */ unsigned short capas; /* Capability bits */ USHORT crcta[16]; /* CRC generation table A */ USHORT crctb[16]; /* CRC generation table B */ UCHAR s_remain[6]; /* Send data leftovers */ UCHAR ipktbuf[P_BUFLEN]; UCHAR ipktbufs[P_BUFLEN * P_WSLOTS]; /* Buffers for incoming packets */ struct packet ipktinfo[P_WSLOTS]; /* Incoming packet info */ UCHAR opktbuf[P_BUFLEN * P_WSLOTS]; /* Outbound packet buffer */ int opktlen; /* Outbound packet length */ UCHAR xdatabuf[P_PKTLEN + 2]; /* Buffer for building data field */ struct packet opktinfo[P_WSLOTS]; /* Outbound packet info */ UCHAR *xdata; /* Pointer to data field of outpkt */ short r_pw[64]; /* Packet Seq.No. to window-slot map */ short s_pw[64]; /* Packet Seq.No. to window-slot map */ UCHAR ack_s[IDATALEN]; /* Our own init parameter string */ UCHAR *obuf; int rx_avail; /* Comms bytes available for reading */ int obuflen; /* Length of output file buffer */ int obufpos; /* Output file buffer position */ UCHAR **filelist; /* List of files to send */ UCHAR *dir; /* Directory */ UCHAR *filename; /* Name of current file */ UCHAR *istring; /* Pointer to string to encode from */ UCHAR *ostring; /* Pointer to string to decode to */ int (*rxd) (struct k_data *, UCHAR *, int); /* Comms read function */ int (*txd) (struct k_data *, UCHAR *, int); /* and comms write function */ int (*ixd) (struct k_data *); /* and comms info function */ int (*openf) (struct k_data *, UCHAR *, int); /* open-file function */ ULONG (*finfo) (struct k_data *, UCHAR *, UCHAR *, int, short *, short); int (*readf) (struct k_data *); /* read-file function */ int (*writef) (struct k_data *, UCHAR *, int); /* write-file function */ int (*closef) (struct k_data *, UCHAR, int); /* close-file function */ int (*dbf) (int, UCHAR *, UCHAR *, long); /* debug function */ UCHAR *zinbuf; /* Input file buffer itself */ int zincnt; /* Input buffer position */ int zinlen; /* Length of input file buffer */ UCHAR *zinptr; /* Pointer to input file buffer */ int sw_full; int do_rxd; long baud; int cgetpkt; short anseq; int nresend; int nspkt; int nsnak; int nsack; int nepkt; int nbchk; int nshort; int ndiscard1; int ndiscard2; int ndiscard3; int nnaa; int rtt; int Bps; int dummy; }; struct k_response { /* Report from Kermit */ short rstatus; /* Current status */ UCHAR filename[FN_MAX]; /* Name of current file */ UCHAR filedate[DATE_MAX]; /* Date of file */ long filesize; /* Size of file */ long sofar; /* Bytes transferred so far */ long sofar_rumor; /* rumored Bytes transferred so far */ }; /* Macro definitions */ #define tochar(ch) (UCHAR)((UCHAR)((UCHAR)(ch) + SP )) #define xunchar(ch) (UCHAR)((UCHAR)((UCHAR)(ch) - SP )) #define ctl(ch) (UCHAR)((UCHAR)((UCHAR)(ch) ^ 64 )) #ifdef COMMENT #define tochar(ch) (((ch) + SP ) & 0xFF ) /* Digit to character */ #define xunchar(ch) (((ch) - SP ) & 0xFF ) /* Character to number */ #define ctl(ch) (((ch) ^ 64 ) & 0xFF ) /* Controllify/uncontrollify */ #endif /* COMMENT */ /* Prototypes for kermit() functions */ int kermit (short fc, struct k_data *, int len, char *msg, struct k_response *); UCHAR *get_rslot (struct k_data *, short *rslot); UCHAR *get_sslot (struct k_data *, short *sslot); void free_rslot (struct k_data *, short rslot); void free_sslot (struct k_data *, short sslot); int ok2rxd (struct k_data *); #endif /* __KERMIT_H__ */