Metropoli BBS
VIEWER: cctz.h MODE: TEXT (ASCII)
/*
Copyright (C) Magna Carta Software, Inc. 1991.  All Rights Reserved.
C COMMUNICATIONS TOOLKIT
CCTZ.H -- Manifest constants for ZMODEM file transfer protocol;
*/

#if !defined(CCTZ_H_INCLUDED)
    #define CCTZ_H_INCLUDED

#if !defined(CCTTYPE_H_INCLUDED)
    #include <ccttype.h>
#endif

#if !defined(XFER_H_INCLUDED)
    #include <xfer.h>
#endif

#define ZSIDLE      24          /* idle state at beginning of a send */
#define ZTIMEOUT    (-2)        /* timeout error */

#define ZPAD        '*'         /* 052 Padding character begins frames */
#define ZDLE        0X18        /* Ctrl-X Zmodem escape - CAN */
#define ZDLEE       (ZDLE^0X40) /* Escaped ZDLE as transmitted */
#define ZBIN        'A'         /* Binary frame indicator */
#define ZHEX        'B'         /* HEX frame indicator */
#define ZBIN32      'C'         /* Binary frame with 32 bit FCS */

/* FRAME TYPES */
#define Z_FRTYPES   20          /* Number of types of ZMODEM frames */
#define Z_FTOFFSET  3

#define ZRQINIT     0           /* Request receive init */
#define ZRINIT      1           /* Receive init */
#define ZSINIT      2           /* Send init sequence (optional) */
#define ZACK        3           /* ACK to above */
#define ZFILE       4           /* File name from sender */
#define ZSKIP       5           /* To sender: skip this file */
#define ZNAK        6           /* Last packet was garbled */
#define ZABORT      7           /* Abort batch transfers */
#define ZFIN        8           /* Finish session */
#define ZRPOS       9           /* Resume data trans at this position */
#define ZDATA       10          /* Data packet(s) follow */
#define ZEOF        11          /* End of file */
#define ZFERR       12          /* Fatal Read or Write error Detected */
#define ZCRC        13          /* Request for file CRC and response */
#define ZCHALLENGE  14          /* Receiver's Challenge */
#define ZCOMPL      15          /* Request is complete */
#define ZCAN        16          /* Other end canned session with CAN*5 */
#define ZFREECNT    17          /* Request for free bytes on filesystem */
#define ZCOMMAND    18          /* Command from sending program */
#define ZSTDERR     19          /* Output to standard error, data follows */


/* ZDLE sequences */
#define ZCRCE       'h'         /* CRC next, frame ends, header packet follows */
#define ZCRCG       'i'         /* CRC next, frame continues nonstop */
#define ZCRCQ       'j'         /* CRC next, frame continues, ZACK expected */
#define ZCRCW       'k'         /* CRC next, ZACK expected, end of frame */
#define ZRUB0       'l'         /* Translate to rubout 0X7F */
#define ZRUB1       'm'         /* Translate to rubout (?) 0XFF */


/* ZDLREAD RETURN VALUES (INTERNAL) */
/* -1 IS GENERAL ERROR, -2 IS TIMEOUT */
#define GOTOR       0X100
#define GOTCRCE     (ZCRCE|GOTOR)   /* ZDLE-ZCRCE received */
#define GOTCRCG     (ZCRCG|GOTOR)   /* ZDLE-ZCRCG received */
#define GOTCRCQ     (ZCRCQ|GOTOR)   /* ZDLE-ZCRCQ received */
#define GOTCRCW     (ZCRCW|GOTOR)   /* ZDLE-ZCRCW received */
#define GOTCAN      (GOTOR|030)     /* CAN*5 seen */


/* BYTE POSITIONS WITHIN HEADER ARRAY */
#define ZF0         3           /* First flags byte */
#define ZF1         2
#define ZF2         1
#define ZF3         0
#define ZP0         0           /* Low order 8 bits of position */
#define ZP1         1
#define ZP2         2
#define ZP3         3           /* High order 8 bits of file position */


/* BIT MASKS FOR ZRINIT FLAGS BYTE ZF0 */
#define CANFDX      1           /* Rx can send and receive true FDX */
#define CANOVIO     2           /* Rx can receive data during disk I/O */
#define CANBRK      4           /* Rx can send a break signal */
#define CANCRY      8           /* Receiver can decrypt */
#define CANLZW      0X10        /* Receiver can uncompress */
#define CANFC32     0X20        /* Receiver can use 32 bit Frame Check */
#define ESCCTL      0X40        /* Receiver expects ctl chars to be escaped */
#define ESC8        0X80        /* Receiver expects 8th bit to be escaped */


/* PARAMETERS FOR ZSINIT FRAME */
#define ZATTNLEN    32          /* Max length of attention string */

/* BIT MASKS FOR ZSINIT FLAGS BYTE ZF0 */
#define TESCCTL     0X40        /* Transmitter expects ctl chars to be escaped */
#define TESC8       0X80        /* Transmitter expects 8th bit to be escaped */

/* PARAMETERS FOR ZFILE FRAME */
/* CONVERSION OPTIONS ONE OF THESE IN ZF0 */
#define ZCBIN       1           /* Binary transfer - inhibit conversion */
#define ZCNL        2           /* Convert NL to local end of line convention */
#define ZCRESUM     3           /* Resume interrupted file transfer */

/* MANAGEMENT INCLUDE OPTIONS, ONE OF THESE ORED IN ZF1 */
#define ZMSKNOLOC   0X80        /* Skip file if not present at rx */

/* MANAGEMENT OPTIONS, ONE OF THESE ORED IN ZF1 */
#define ZMMASK      0X1F        /* Mask for the choices below */
#define ZMNEWL      1           /* Transfer if source newer or longer */
#define ZMCRC       2           /* Transfer if different file CRC or length */
#define ZMAPND      3           /* Append contents to existing file (if any) */
#define ZMCLOB      4           /* Replace existing file */
#define ZMNEW       5           /* Transfer if source newer */
#define ZMDIFF      6           /* Transfer if dates or lengths different */
#define ZMPROT      7           /* Protect destination file */

/* TRANSPORT OPTIONS, ONE OF THESE IN ZF2 */
#define ZTLZW       1           /* Lempel-Ziv compression */
#define ZTCRYPT     2           /* Encryption */
#define ZTRLE       3           /* Run Length encoding */

/* EXTENDED OPTIONS FOR ZF3, BIT ENCODED */
#define ZXSPARS     64          /* Encoding for sparse file operations */

/* Parameters for ZCOMMAND frame ZF0 (otherwise 0) */
#define ZCACK1      1           /* Acknowledge, then do command */

/* CRC CALCULATION MACROS */
#define updcrc_(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
#define UPDC32(b, c) (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFFL))

typedef struct {
    char            txhdr[4];
    char            rxhdr[4];
    char            attn[ZATTNLEN];
    char            txbuf[1024+48];
    char            rxbuf[1024+48];
    XFER            *x;
    DWORD           rxpos;
    DWORD           txpos;
    DWORD           bytcnt;
    DWORD           lastsync;
    DWORD           lrxpos;
    WORD            retries;
    WORD            crc32;
    WORD            nulls;
    WORD            txwcnt;
    WORD            txwspac;
    WORD            f_eof;

    WORD            cmdack1;
    WORD            cmdnum;
    WORD            cmdtries;
    WORD            errors;
    WORD            blkopt;
    WORD            blklen;
    WORD            tframlen;
    WORD            txwindow;
    WORD            rxbuflen;
    WORD            ctlesc;
    WORD            txfcs32;
    WORD            crc32t;
    WORD            rxcount;
    WORD            rxtype;     /* type of received packet */
    WORD            rxframeind; /* receive frame indicator */
    WORD            rxwindow;   /* receive window */
    WORD            rxtimeout;  /* time to wait for receiver */
    WORD            tcount;     /* outstanding windows count */
    WORD            tryhtype;   /* type of header to try */
    long            speed;      /* DTE speed */
    BYTE            l_cap;      /* Our (local) capabilities, bit encoded as:
                                0 -- CANFDX (RX can send and receive full duplex
                                1 -- CANOVIO (RX can overlap serial/disk I/O
                                2 -- CANBRK (RX can send a break signal
                                3 -- CANCRY (RX can decrypt)
                                4 -- CANLZW (RX can uncompress)
                                5 -- CANFC32 (RX can use 32-bit FC
                                6 -- ESCCTL (RX expects ctl chars to be escaped
                                7 -- ESC8   (RX expects 8th bit to be escaped
                                */
    BYTE            r_cap;      /* Remote capabilities, bit encoded as r_cap */
/*  BYTE            cap;  */      /* Actual capabilities, bit encoded as l_cap */
    BYTE            l_conv;     /* Our (local) conversion options bit encoded as:
                                0 -- ZCBIN (no conversion)
                                1 -- ZCNL (convert to local end-of-line convention)
                                2 -- ZCRESUM (use file recovery)
                                */
    BYTE            r_conv;     /* Remote conversion options, bit encoded as l_conv */
/*  BYTE            conv;   */  /* Actual conversion options, bit encoded as l_conv */
    BYTE            l_manag;    /* Our (local) management options, bit encoded as:
                                0 -- ZMNEWL (transfer if source newer or longer)
                                1 -- ZMCRC  (transfer if different file CRC or length)
                                2 -- ZMAPND (append contents to existing file (if any))
                                3 -- ZMCLOB (replace existing file)
                                4 -- ZMNEW  (transfer if source newer)
                                5 -- ZMDIFF (transfer if dates or lengths diff.)
                                6 -- ZMPROT (protect destination file)
                                7 -- ZMSKNOLOC (skip file if not present at rx)
                                */
    BYTE            r_manag;    /* Remote mgt. options, bit encoded as l_manag */
    BYTE            manag;      /* Actual mgt. options, bit encoded as l_manag */
    BYTE            l_trans;    /* Our (local) transport options, bit encoded as:
                                0 -- ZTLZW  (Lempel-Ziv compression)
                                1 -- ZTCRYPT(encryption)
                                2 -- ZTRLE  (run-length encoding)
                                */
    BYTE            r_trans;    /* Remote transport options */
    BYTE            trans;      /* Actual transport options */
} Z_PARMS;



#define isescctl(a)         ((a)->manag & ESCCTL)
#define wantfc32(a)         ((a)->l_cap & CANFC32)


extern          long  cr3tab[];
extern unsigned short crctab[];

short           FCALL_  noxrd7_(COMM_PORT *p);
unsigned long   FCALL_  rclhdr_(char *hdr);
void            FCALL_  stohdr_(Z_PARMS *z, long pos);
short           FCALL_  z_s_abort_(COMM_PORT *p);
short           FCALL_  z_ack_fin_(COMM_PORT *p);
short           FCALL_  z_decodec_(COMM_PORT *p);
short           FCALL_  z_deinit(COMM_PORT *p);
short           FCALL_  z_encodec_(COMM_PORT *p, short c);
unsigned short  FCALL_  z_filbuf_(COMM_PORT *p);
Z_PARMS *       FCALL_  z_init(COMM_PORT *p, WORD zcap, WORD zconv, WORD zmanag);
void            FCALL_  z_m_puts_(COMM_PORT *p, char *s);
short           FCALL_  z_receive_(COMM_PORT *p);
short           FCALL_  z_r_h_(COMM_PORT *p, char *hdr, short eflag);
short           FCALL_  z_send_(COMM_PORT *p);
short           FCALL_  z_sync_(COMM_PORT *p, short flag);
short           FCALL_  z_s_bh_(COMM_PORT *p, short htype, char *hdr);
short           FCALL_  z_s_cmd_(COMM_PORT *p, char *buf, short blen);
short           FCALL_  z_s_data_(COMM_PORT *p, char *buf, short length, short frameend);
short           FCALL_  z_s_hh_(COMM_PORT *p, short htype, const char *hdr);
short           FCALL_  z_s_fin_(COMM_PORT *p);
#endif
[ RETURN TO DIRECTORY ]