xref: /netbsd-src/external/bsd/ekermit/dist/kermit.h (revision 755f450934b71be60310099f12a64671ac92d28f)
1 #ifndef __KERMIT_H__
2 #define __KERMIT_H__
3 
4 #define VERSION "1.7"			/* Kermit module version number */
5 
6 /*
7   kermit.h -- Symbol and struct definitions for embedded Kermit.
8 
9   As of version 1.6 of 30 March 2011, E-Kermit is Open Source software under
10   the Revised 3-Clause BSD license which follows.  E-Kermit 1.6 is identical
11   to version 1.51 except for the new license.
12 
13   Author: Frank da Cruz.
14 
15   Copyright (C) 1995, 2011,
16   Trustees of Columbia University in the City of New York.
17   All rights reserved.
18 
19   Redistribution and use in source and binary forms, with or without
20   modification, are permitted provided that the following conditions are met:
21 
22   * Redistributions of source code must retain the above copyright notice,
23     this list of conditions and the following disclaimer.
24 
25   * Redistributions in binary form must reproduce the above copyright notice,
26     this list of conditions and the following disclaimer in the documentation
27     and/or other materials provided with the distribution.
28 
29   * Neither the name of Columbia University nor the names of its contributors
30     may be used to endorse or promote products derived from this software
31     without specific prior written permission.
32 
33   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
37   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43   POSSIBILITY OF SUCH DAMAGE.
44 */
45 
46 #ifdef COMMENT                          /* COMMENT must not be defined */
47 #undef COMMENT				/* (e.g. in a platform header file) */
48 #endif /* COMMENT */
49 
50 /*
51   Never use NULL as a pointer.  Always use 0 cast to the appropriate type,
52   for example: (UCHAR *)0.  Reason: compiler might define NULL to be an
53   integer 0, and when passed to a function that wants a pointer, might wind
54   up with junk in the left half (if pointers wider than ints).
55 */
56 #ifdef NULL
57 #undef NULL
58 #endif /* NULL */
59 
60 /* Feature Selection */
61 
62 /* XAC compiler for Philips XAG30 microprocessor */
63 /* See http://www.columbia.edu/kermit/em-apex.html */
64 
65 #ifdef XAC				/* XAC has tiny command line */
66 #define NO_LP				/* Long packets too big for APF9 */
67 #define NO_SSW
68 #define NO_SCAN				/* No file system */
69 #define FN_MAX  16
70 #define IBUFLEN 128
71 #define OBUFLEN 512
72 
73 #else  /* XAC */
74 
75 #ifdef MINSIZE
76 #define NO_LP
77 #define NO_AT
78 #define NO_CTRLC
79 #define NO_SSW
80 #define NO_CRC
81 #define NO_SCAN
82 #endif	/* MINSIZE */
83 
84 #endif	/* XAC */
85 
86 #ifndef NO_LP
87 #define F_LP                            /* Long packets */
88 #endif	/* NO_LP */
89 
90 #ifndef NO_AT
91 #define F_AT                            /* Attribute packets */
92 #endif	/* NO_AT */
93 
94 #ifndef NO_CTRLC
95 #define F_CTRLC                         /* 3 consecutive Ctrl-C's to quit */
96 #endif	/* NO_CTRLC */
97 
98 #ifndef NO_SSW
99 #define F_SSW				/* Simulated sliding windows */
100 #endif	/* NO_SSW */
101 
102 #ifndef NO_SCAN
103 #define F_SCAN				/* Scan files for text/binary */
104 #endif	/* NO_SCAN */
105 
106 #ifndef NO_CRC				/* Type 2 and 3 block checks */
107 #define F_CRC
108 #endif /* NO_CRC */
109 
110 /*
111   F_SSW means we say (in negotiations) that we support sliding windows, but we
112   really don't.  This allows the sender to send to us in a steady stream, and
113   works just fine except that error recovery is via go-back-to-n rather than
114   selective repeat.
115 */
116 
117 #ifdef COMMENT                          /* None of the following ... */
118 /*
119   + = It works if selected
120   - = Partially implemented but doesn't work
121   0 = Not implemented
122 */
123   #define F_TSW                         /* - True sliding windows */
124   #define F_LS                          /* 0 Locking shifts */
125   #define F_RS                          /* 0 Recovery */
126 
127 #endif /* COMMENT */
128 
129 #ifdef F_TSW				/* F_SW is defined if either */
130 #ifndef F_SW				/* F_SSW or F_TSW is defined... */
131 #define F_SW
132 #endif /* F_SW */
133 #endif /* F_TSW */
134 
135 #ifdef F_SSW
136 #ifndef F_SW
137 #define F_SW
138 #endif /* F_SW */
139 #endif /* F_SSW */
140 
141 /* Control character symbols */
142 
143 #define NUL  '\0'                       /* Null */
144 #define SOH  001                        /* Start of header */
145 #define LF   012                        /* Linefeed */
146 #define CR   015                        /* Carriage Return */
147 #define SO   016                        /* Shift Out */
148 #define SI   017                        /* Shift In */
149 #define DLE  020                        /* Datalink Escape */
150 #define ESC  033                        /* Escape */
151 #define XON  021                        /* XON */
152 #define XOFF 023                        /* XOFF */
153 #define SP   040                        /* Space */
154 #define DEL  0177                       /* Delete (Rubout) */
155 
156 #ifndef HAVE_VERSION			/* k_data struct has version member */
157 #define HAVE_VERSION			/* as of version 1.1 */
158 #endif /* HAVE_VERSION */
159 
160 /* Main program return codes */
161 
162 #define SUCCESS     0
163 #define FAILURE     1
164 
165 /* Buffer lengths (can be overridden in platform.h) */
166 
167 #ifndef RECVONLY
168 #ifndef IBUFLEN
169 #define IBUFLEN  1024			/* File input buffer size */
170 #endif /* IBUFLEN */
171 #endif	/* RECVONLY */
172 
173 #ifndef OBUFLEN
174 #define OBUFLEN  1024                   /* File output buffer size */
175 #endif /* OBUFLEN */
176 
177 #ifndef IDATALEN			/* S/I packet data max length */
178 #define IDATALEN 32
179 #endif /* IDATALEN */
180 
181 #ifndef FN_MAX
182 #define FN_MAX   1024                   /* Maximum filename length */
183 #endif /* FN_MAX */
184 
185 #define DATE_MAX   20                   /* Max length for file date */
186 
187 /* Protocol parameters */
188 
189 #ifndef P_WSLOTS
190 #ifdef F_SW                             /* Window slots */
191 #ifdef F_TSW				/* True window slots */
192 #define P_WSLOTS    4			/* Max is 4 */
193 #else
194 #define P_WSLOTS   31			/* Simulated max is 31 */
195 #endif /* F_TSW */
196 #else
197 #define P_WSLOTS    1
198 #endif /* F_SW */
199 #endif /* P_WSLOTS */
200 
201 #ifndef P_PKTLEN			/* Kermit max packet length */
202 #ifdef F_LP
203 #define P_PKTLEN 4096
204 #else
205 #define P_PKTLEN   94
206 #endif /* F_LP */
207 #endif /* P_PKTLEN */
208 
209 /* Generic On/Off values */
210 
211 #define OFF         0
212 #define ON          1
213 
214 /* File Transfer Modes */
215 
216 #define BINARY      0
217 #define TEXT        1
218 
219 /* Parity values */
220 
221 #define PAR_NONE    0
222 #define PAR_SPACE   1
223 #define PAR_EVEN    2
224 #define PAR_ODD     3
225 #define PAR_MARK    4
226 
227 /* Protocol parameters */
228 
229 #define P_S_TIMO   40                   /* Timeout to tell other Kermit  */
230 #define P_R_TIMO    5                   /* Default timeout for me to use */
231 #define P_RETRY    10                   /* Per-packet retramsit limit    */
232 #define P_PARITY  PAR_NONE              /* Default parity        */
233 #define P_R_SOH   SOH                   /* Incoming packet start */
234 #define P_S_SOH   SOH                   /* Outbound packet start */
235 #define P_R_EOM    CR                   /* Incoming packet end   */
236 #define P_S_EOM    CR                   /* Outbound packet end   */
237 
238 /* Capability bits */
239 
240 #define CAP_LP      2                   /* Long packet capability */
241 #define CAP_SW      4                   /* Sliding windows capability */
242 #define CAP_AT      8                   /* Attribute packet capability */
243 #define CAP_RS     16                   /* Resend capability */
244 #define CAP_LS     32                   /* Locking shift capability */
245 
246 /* Actions */
247 
248 #define A_SEND      1			/* Send file(s) */
249 #define A_RECV      2			/* Receive file(s) */
250 
251 /* Receive protocol states */
252 
253 #define R_ERROR    -1                   /* Fatal protocol error */
254 #define R_NONE      0                   /* Protocol not running */
255 #define R_WAIT      1                   /* Waiting for S packet */
256 #define R_FILE      2                   /* Waiting for F or B packet */
257 #define R_ATTR      3                   /* Waiting for A or D packet */
258 #define R_DATA      4                   /* Waiting for D or Z packet */
259 
260 /* Send protocol states */
261 
262 #define S_ERROR    -1                   /* Fatal protocol error */
263 #define S_NONE     10                   /* Protocol not running */
264 #define S_INIT     11                   /* Sent S packet */
265 #define S_FILE     12                   /* Sent F packet */
266 #define S_ATTR     13                   /* Sent A packet */
267 #define S_DATA     14                   /* Sent D packet */
268 #define S_EOF      15                   /* Sent Z packet */
269 #define S_EOT      16                   /* Sent B packet */
270 
271 /* What I'm Doing */
272 
273 #define W_NOTHING   0
274 #define W_SEND      1
275 #define W_RECV      2
276 
277 /* Kermit module function codes */
278 
279 #define K_INIT      0                   /* Initialize */
280 #define K_RUN       1                   /* Run */
281 #define K_STATUS    2                   /* Request status */
282 #define K_CONTINUE  3                   /* Keep going */
283 #define K_QUIT      4                   /* Quit immediately */
284 #define K_ERROR     5                   /* Quit with error packet, msg given */
285 #define K_SEND      6			/* Begin Send sequence */
286 
287 /* Kermit module return codes */
288 
289 #define X_ERROR    -1                   /* Fatal error */
290 #define X_OK        0                   /* OK, no action needed */
291 #define X_FILE      1                   /* Filename received */
292 #define X_DATA      2                   /* File data received */
293 #define X_DONE      3                   /* Done */
294 #define X_STATUS    4                   /* Status report */
295 
296 /* Interruption codes */
297 
298 #define I_FILE      1			/* Cancel file */
299 #define I_GROUP     2			/* Cancel group */
300 
301 struct packet {
302     int len;                            /* Length */
303     short seq;                          /* Sequence number */
304     char typ;                           /* Type */
305     short rtr;                          /* Retry count */
306     UCHAR * dat;                        /* Pointer to data */
307     short flg;				/* Flags */
308 };
309 
310 struct k_data {                         /* The Kermit data structure */
311     UCHAR * version;			/* Version number of Kermit module */
312     short remote;			/* 0 = local, 1 = remote */
313     short xfermode;			/* 0 = automatic, 1 = manual */
314     short binary;                       /* 0 = text, 1 = binary */
315     short state;                        /* Kermit protocol state */
316     short what;				/* Action (send or receive) */
317     short s_first;			/* Enocode at beginning of file */
318     short s_next;			/* Encode lookahead byte */
319     short s_seq;                        /* Sequence number sent */
320     short r_seq;                        /* Sequence number received */
321     short s_type;                       /* Packet type sent */
322     short r_type;                       /* Packet type received */
323     short s_soh;                        /* Packet start sent */
324     short r_soh;                        /* Packet start received */
325     short s_eom;                        /* Packet end sent */
326     short r_eom;                        /* Packet end received */
327     int size;				/* Current size of output pkt data */
328     int osize;				/* Previous output packet data size */
329     int r_timo;                         /* Receive and send timers */
330     int s_timo;                         /* ... */
331     int r_maxlen;                       /* maximum packet length to receive */
332     int s_maxlen;                       /* maximum packet length to send */
333     short window;                       /* maximum window slots */
334     short wslots;                       /* current window slots */
335     short parity;                       /* 0 = none, nonzero = some */
336     short retry;                        /* retry limit */
337     short cancel;			/* Cancellation */
338     short ikeep;			/* Keep incompletely received files */
339     char s_ctlq;                        /* control-prefix out */
340     char r_ctlq;                        /* control-prefix in */
341     char ebq;				/* 8-bit prefix */
342     char ebqflg;			/* 8-bit prefixing negotiated */
343     char rptq;				/* Repeat-count prefix */
344     int s_rpt;				/* Current repeat count */
345     short rptflg;                       /* flag for repeat counts negotiated */
346     short bct;                          /* Block-check type 1..3 */
347     unsigned short capas;               /* Capability bits */
348 #ifdef F_CRC
349     USHORT crcta[16];			/* CRC generation table A */
350     USHORT crctb[16];			/* CRC generation table B */
351 #endif /* F_CRC */
352     UCHAR s_remain[6];			 /* Send data leftovers */
353     UCHAR ipktbuf[P_PKTLEN+8][P_WSLOTS]; /* Buffers for incoming packets */
354     struct packet ipktinfo[P_WSLOTS];    /* Incoming packet info */
355 #ifdef COMMENT
356     UCHAR opktbuf[P_PKTLEN+8][P_WSLOTS]; /* Buffers for outbound packets */
357 #else
358     UCHAR opktbuf[P_PKTLEN+8];		/* Outbound packet buffer */
359     int opktlen;			/* Outbound packet length */
360     UCHAR xdatabuf[P_PKTLEN+2];		/* Buffer for building data field */
361 #endif /* COMMENT */
362     struct packet opktinfo[P_WSLOTS];	/* Outbound packet info */
363     UCHAR * xdata;			/* Pointer to data field of outpkt */
364 #ifdef F_TSW
365     short r_pw[64];			/* Packet Seq.No. to window-slot map */
366     short s_pw[64];			/* Packet Seq.No. to window-slot map */
367 #endif /* F_TSW */
368     UCHAR ack_s[IDATALEN];		/* Our own init parameter string */
369     UCHAR * obuf;
370     int rx_avail;			/* Comms bytes available for reading */
371     int obuflen;                        /* Length of output file buffer */
372     int obufpos;                        /* Output file buffer position */
373     UCHAR ** filelist;			/* List of files to send */
374     UCHAR * dir;			/* Directory */
375     UCHAR * filename;			/* Name of current file */
376     UCHAR * istring;			/* Pointer to string to encode from */
377     UCHAR * ostring;			/* Pointer to string to decode to */
378     int (*rxd)(struct k_data *, UCHAR *, int);   /* Comms read function */
379     int (*txd)(struct k_data *, UCHAR *, int);   /* and comms write function */
380     int (*ixd)(struct k_data *);	         /* and comms info function */
381     int (*openf)(struct k_data *,UCHAR *,int);   /* open-file function  */
382     ULONG (*finfo)(struct k_data *,UCHAR *,UCHAR *,int,short *,short);
383     int (*readf)(struct k_data *);	         /* read-file function  */
384     int (*writef)(struct k_data *,UCHAR *, int); /* write-file function */
385     int (*closef)(struct k_data *,UCHAR,int);    /* close-file function */
386     void (*dbf)(int,UCHAR *,UCHAR *,long);  /* debug function */
387     UCHAR * zinbuf;			/* Input file buffer itself */
388     int zincnt;				/* Input buffer position */
389     int zinlen;				/* Length of input file buffer */
390     UCHAR * zinptr;			/* Pointer to input file buffer */
391     int bctf;				/* Flag to force type 3 block check */
392     int dummy;
393 };
394 
395 struct k_response {			/* Report from Kermit */
396     short status;                       /* Current status */
397     UCHAR filename[FN_MAX];             /* Name of current file */
398     UCHAR filedate[DATE_MAX];           /* Date of file */
399     long filesize;                      /* Size of file */
400     long sofar;				/* Bytes transferred so far */
401 };
402 
403 /* Macro definitions */
404 
405 #define tochar(ch)  (UCHAR)((UCHAR)((UCHAR)(ch) + SP ))
406 #define xunchar(ch) (UCHAR)((UCHAR)((UCHAR)(ch) - SP ))
407 #define ctl(ch)     (UCHAR)((UCHAR)((UCHAR)(ch) ^ 64 ))
408 
409 #ifdef COMMENT
410 #define tochar(ch)  (((ch) + SP ) & 0xFF ) /* Digit to character */
411 #define xunchar(ch) (((ch) - SP ) & 0xFF ) /* Character to number */
412 #define ctl(ch)     (((ch) ^ 64 ) & 0xFF ) /* Controllify/uncontrollify */
413 #endif /* COMMENT */
414 
415 /* Prototypes for kermit() functions */
416 
417 int kermit(short, struct k_data *, short, int, char *, struct k_response *);
418 UCHAR * getrslot(struct k_data *, short *);
419 UCHAR * getsslot(struct k_data *, short *);
420 void freerslot(struct k_data *, short);
421 void freesslot(struct k_data *, short);
422 
423 #endif /* __KERMIT_H__ */
424