home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / main / PROG / zmodem.doc < prev   
Encoding:
Text File  |  2005-01-19  |  37.6 KB  |  994 lines

  1. zmodem.doc !copyrighted by MCS 1994 use it anyway you like but don't complain
  2. this file should be accompanied by a readme which contains some background
  3. information on implementing zmodem.
  4.  
  5. GENERAL
  6. -------
  7.  
  8.     Documentation about the zmodem protocol internals; should be sufficient
  9.     to implement a completely functional zmodem protocol suite.
  10.     
  11.     Zmodem is a file transfer protocol that attempts to maximize bandwidth
  12.     and minimize transfer times. it is a unidirectional protocol; i.e. the
  13.     return channel only transfers control information; no data. either side
  14.     may initiate the transfer; but the downloading site may respond to 
  15.     an initialization frame by auto starting the download software.
  16.     
  17.     Schematically a zmodem file transfer in progress looks like this:
  18.  
  19.              |----------<< back channel <<-------------|
  20.        ------+-------                          --------+------
  21.        |   Sender   |                          |   Receiver  |
  22.        |  (upload)  |                          |  (download) |
  23.        --------------                          --------+------
  24.              |---------->> data channel >>-------------|
  25.  
  26.     Multiple files may be transferred in one session.
  27.  
  28. SAMPLE
  29. ------
  30.  
  31.     all zmodem transactions are done using frames. a frame consists
  32.     of a header followed by one or more data subpackets.
  33.     a typical (simple) zmodem file transfer looks like this :
  34.  
  35.         sender                      receiver
  36.  
  37.         ZRQINIT(0)
  38.                                     ZRINIT
  39.         ZFILE
  40.                                     ZRPOS
  41.         ZDATA data ...
  42.         ZEOF
  43.                                     ZRINIT
  44.         ZFIN
  45.                                     ZFIN
  46.         OO
  47.  
  48.     zmodem continuously    transmits data unless the receiver interrupts
  49.     the sender to request retransmission of garbled data.
  50.     zmodem in effect uses the entire file as a window.
  51.  
  52. REQUIREMENTS
  53. ------------
  54.  
  55.     zmodem requires an 8 bit transfer medium; but allows encoded packets
  56.     for less transparent media.
  57.     zmodem escapes network control characters to allow operation with
  58.     packet switched networks.
  59.  
  60.     To support full streaming, the transmission path should either assert
  61.     flow control or pass full speed transmission without loss of data.
  62.     Otherwise the zmodem sender must manage the window size.
  63.  
  64.     zmodem places no constraints on the content files.
  65.  
  66. LINK ESCAPE ENCODING
  67. --------------------
  68.  
  69.     zmodem achieves data transparency by extending the 8 bit character set
  70.     (256 codes) with escape sequences based on the zmodem data link escape
  71.     character ZDLE
  72.  
  73.     Link Escape coding permits variable length data subpackets without the
  74.     overhead of a separate byte count.  It allows the beginning of frames to
  75.     be detected without special timing techniques, facilitating rapid error
  76.     recovery.
  77.  
  78.     Link Escape coding does add some overhead.  The worst case, a file
  79.     consisting entirely of escaped characters, would incur a 50% overhead.
  80.  
  81.     The ZDLE character is special. ZDLE represents a control
  82.     sequence of some sort. If a ZDLE character appears in binary data,
  83.     it is prefixed with ZDLE, then sent as ZDLEE
  84.  
  85.     5 consecutive CAN characters abort a zmodem session
  86.  
  87.     Since CAN is not used in normal terminal operations, interactive
  88.     applications and communications programs can monitor the data flow for
  89.     ZDLE.  The following characters can be scanned to detect the ZRQINIT
  90.     header, the invitation to automatically download commands or files.
  91.  
  92.     Receipt of five successive CAN characters will abort a zmodem session.
  93.     Eight CAN characters are sent (just to be on the safe side)
  94.  
  95.     The receiving program decodes any sequence of ZDLE followed by a byte with
  96.     bit 6 set and bit 5 reset (upper case letter, either parity) to the
  97.     equivalent control character by inverting bit 6.  This allows the
  98.     transmitter to escape any control character that cannot be sent by the
  99.     communications medium. In addition, the receiver recognizes escapes for
  100.     0x7f and 0xff should these characters need to be escaped.
  101.  
  102.     zmodem software escapes ZDLE (0x18), 0x10, 0x90, 0x11, 0x91, 0x13,
  103.     and 0x93. 
  104.     If preceded by 0x40 or 0xc0 (@), 0x0d and 0x8d are also escaped to
  105.     protect the Telenet command escape CR-@-CR. The receiver ignores
  106.     0x11, 0x91, 0x13, and 0x93 characters in the data stream.
  107.  
  108. HEADERS
  109. -------
  110.  
  111.     All zmodem frames begin with a header which may be sent in binary or HEX
  112.     form. Either form of the header contains the same raw information:
  113.  
  114.     - A type byte
  115.  
  116.     - Four bytes of data indicating flags and/or numeric quantities depending
  117.       on the frame type
  118.  
  119.     the maximum header information length is 16 bytes
  120.     the data subpackets following the header are maximum 1024 bytes long.
  121.  
  122.              M         L
  123.       FTYPE  F3 F2 F1 F0   (flags frame)
  124.  
  125.              L         M
  126.       FTYPE  P0 P1 P2 P3   (numeric frame)
  127.  
  128.     Beware of the catch; flags and numbers are indexed the other way around !
  129.  
  130.     16 BIT CRC BINARY HEADER
  131.     ------------------------
  132.     
  133.         A binary header is sent by the sending program to the receiving
  134.         program. All bytes in a binary header are ZDLE encoded.
  135.     
  136.         A binary header begins with the sequence ZPAD, ZDLE, ZBIN.
  137.     
  138.         0 or more binary data subpackets with 16 bit CRC will follow depending
  139.         on the frame type.
  140.     
  141.         * ZDLE A TYPE F3/P0 F2/P1 F1/P2 F0/P3 CRC-1 CRC-2
  142.     
  143.     
  144.     32 BIT CRC BINARY HEADER
  145.     ------------------------
  146.     
  147.         A "32 bit CRC" Binary header is similar to a Binary Header, except the
  148.         ZBIN (A) character is replaced by a ZBIN32 (C) character, and four
  149.         characters of CRC are sent.
  150.     
  151.         0 or more binary data subpackets with 32 bit CRC will follow depending
  152.         on the frame type.
  153.     
  154.         * ZDLE C TYPE F3/P0 F2/P1 F1/P2 F0/P3 CRC-1 CRC-2 CRC-3 CRC-4
  155.     
  156.     HEX HEADER
  157.     ----------
  158.     
  159.         The receiver sends responses in hex headers.  The sender also uses hex
  160.         headers when they are not followed by binary data subpackets.
  161.     
  162.         Hex encoding protects the reverse channel from random control 
  163.         characters. The hex header receiving routine ignores parity.
  164.     
  165.         use of hex headers by the receiving program allows control characters
  166.         to be used to interrupt the sender when errors are detected.
  167.         A HEX header may be used in place of a binary header
  168.         wherever convenient.
  169.         If a data packet follows a HEX header, it is protected with CRC-16.
  170.     
  171.         A hex header begins with the sequence ZPAD, ZPAD, ZDLE, ZHEX.  
  172.         The extra ZPAD character allows the sending program to detect
  173.         an asynchronous header (indicating an error condition) and then
  174.         get the rest of the header with a non-error specific routine.
  175.     
  176.         The type byte, the four position/flag bytes, and the 16 bit CRC
  177.         thereof are sent in hex using the character set 01234567890abcdef.
  178.         Upper case hex digits are not allowed.
  179.         Since this form of hex encoding detects many patterns of errors,
  180.         especially missing characters, a hex header with 32 bit CRC has not
  181.         been defined.
  182.     
  183.         A carriage return and line feed are sent with HEX headers.  The
  184.         receive routine expects to see at least one of these characters, two
  185.         if the first is CR.
  186.     
  187.         An XON character is appended to all HEX packets except ZACK and ZFIN.
  188.         The XON releases the sender from spurious XOFF flow control characters
  189.         generated by line noise. XON is not sent after ZACK headers to protect
  190.         flow control in streaming situations. XON is not sent after a ZFIN
  191.         header to allow proper session cleanup.
  192.     
  193.         0 or more data subpackets will follow depending on the frame type.
  194.     
  195.         * * ZDLE B TYPE F3/P0 F2/P1 F1/P2 F0/P3 CRC-1 CRC-2 CR LF XON
  196.     
  197.         (TYPE, F3...F0, CRC-1, and CRC-2 are each sent as two hex digits.)
  198.     
  199.     BINARY DATA SUBPACKETS
  200.     ----------------------
  201.     
  202.         Binary data subpackets immediately follow the associated binary header
  203.         packet.  A binary data packet contains 0 to 1024 bytes of data.
  204.         Recommended length values are 256 bytes below 2400 bps, 512 at 
  205.         2400 bps, and 1024 above 4800 bps or when the data link is known to
  206.         be relatively error free.
  207.     
  208.         No padding is used with binary data subpackets.  The data bytes are
  209.         ZDLE encoded and transmitted.  A ZDLE and frameend are then sent,
  210.         followed by two or four ZDLE encoded CRC bytes.  The CRC accumulates
  211.         the data bytes and frameend.
  212.     
  213. PROTOCOL TRANSACTION OVERVIEW
  214. -----------------------------    
  215.  
  216.     zmodem timing is receiver driven.  The
  217.     transmitter should not time out at all, except to abort the program if no
  218.     headers are received for an extended period of time, say one minute.
  219.     
  220.     SESSION STARTUP
  221.     ---------------
  222.  
  223.         To start a zmodem file transfer session, the sending program is called
  224.         with the names of the desired file(s) and option(s).
  225.     
  226.         Then the sender may send a ZRQINIT header. The ZRQINIT header causes a
  227.         previously started receive program to send its ZRINIT header without
  228.         delay.
  229.     
  230.         In an interactive or conversational mode, the receiving application
  231.         may monitor the data stream for ZDLE.  The following characters may be 
  232.         scanned for B00 indicating a ZRQINIT header, a command to download
  233.         data.
  234.     
  235.         The sending program awaits a command from the receiving program to
  236.         start file transfers. 
  237.     
  238.         In case of garbled data, the sending program can repeat the invitation
  239.         to receive a number of times until a session starts.
  240.     
  241.         When the zmodem receive program starts, it immediately sends a ZRINIT
  242.         header to initiate zmodem file transfers, or a ZCHALLENGE header to
  243.         verify the sending program.  The receive program resends its header at
  244.         response time (default 10 second) intervals for a suitable period of
  245.         time (40 seconds total) before exitting.
  246.     
  247.         If the receiving program receives a ZRQINIT header, it resends the
  248.         ZRINIT header.  If the sending program receives the ZCHALLENGE header,
  249.         it places the data in ZP0...ZP3 in an answering ZACK header.
  250.     
  251.         If the receiving program receives a ZRINIT header, it is an echo
  252.         indicating that the sending program is not operational.
  253.     
  254.         Eventually the sending program correctly receives the ZRINIT header.
  255.     
  256.         The sender may then send an optional ZSINIT frame to define the
  257.         receiving program's Attn sequence, or to specify complete control
  258.         character escaping. if the receiver specifies the same or higher
  259.         level of escaping the ZSINIT frame need not be sent unless an Attn
  260.         sequence is needed.
  261.     
  262.         If the ZSINIT header specifies ESCCTL or ESC8, a HEX header is used,
  263.         and the receiver activates the specified ESC modes before reading the
  264.         following data subpacket.
  265.     
  266.         The receiver sends a ZACK header in response, containing 0.
  267.     
  268.     FILE TRANSMISSION
  269.     -----------------
  270.  
  271.         The sender then sends a ZFILE header with zmodem Conversion,
  272.         Management, and Transport options (see ZFILE header type) followed
  273.         by a ZCRCW data subpacket containing the file name, file length and
  274.         modification date.
  275.  
  276.         The receiver examines the file name, length, and date information
  277.         provided by the sender in the context of the specified transfer
  278.         options, the current state of its file system(s), and local security
  279.         requirements.  The receiving program should insure the pathname and
  280.         options are compatible with its operating environment and local
  281.         security requirements.
  282.  
  283.         The receiver may respond with a ZSKIP header, which makes the sender
  284.         proceed to the next file (if any) in the batch.
  285.  
  286.             The receiver has a file with the same name and length, may
  287.             respond with a ZCRC header with a byte count, which
  288.             requires the sender to perform a 32 bit CRC on the
  289.             specified number of bytes in the file and transmit the
  290.             complement of the CRC in an answering ZCRC header.the crc is
  291.             initialised to 0xfffffff; a byte count of 0 implies the entire
  292.             file the receiver uses this information to determine whether to
  293.             accept the file or skip it.  This sequence may be triggered
  294.             by the ZMCRC Management Option.
  295.  
  296.         A ZRPOS header from the receiver initiates transmission of the file
  297.         data starting at the offset in the file specified in the ZRPOS header.
  298.         Normally the receiver specifies the data transfer to begin begin at
  299.         offset 0 in the file.
  300.  
  301.             The receiver may start the transfer further down in the
  302.             file.  This allows a file transfer interrupted by a loss
  303.             of carrier or system crash to be completed on the next
  304.             connection without requiring the entire file to be
  305.             retransmitted. If downloading a file from a timesharing
  306.             system that becomes sluggish, the transfer can be
  307.             interrupted and resumed later with no loss of data.
  308.  
  309.         The sender sends a ZDATA binary header (with file position) followed
  310.         by one or more data subpackets.
  311.     
  312.         The receiver compares the file position in the ZDATA header with the
  313.         number of characters successfully received to the file. If they do not
  314.         agree, a ZRPOS error response is generated to force the sender to the
  315.         right position within the file. (if the ZMSPARS option is used the
  316.         receiver instead seeks to the position given in the ZDATA header)
  317.  
  318.         A data subpacket terminated by ZCRCG and CRC does not elicit a
  319.         response unless an error is detected; more data subpacket(s) follow
  320.         immediately.
  321.  
  322.         ZCRCQ data subpackets expect a ZACK response with the
  323.         receiver's file offset if no error, otherwise a ZRPOS
  324.         response with the last good file offset.  Another data
  325.         subpacket continues immediately.  ZCRCQ subpackets are
  326.         not used if the receiver does not indicate full duplex ability
  327.         with the CANFDX bit.
  328.  
  329.         ZCRCW data subpackets expect a response before the next frame is sent.
  330.         If the receiver does not indicate overlapped I/O capability with the
  331.         CANOVIO bit, or sets a buffer size, the sender uses the ZCRCW to allow
  332.         the receiver to write its buffer before sending more data.
  333.  
  334.             A zero length data frame may be used as an idle
  335.             subpacket to prevent the receiver from timing out in
  336.             case data is not immediately available to the sender.
  337.  
  338.         In the absence of fatal error, the sender eventually encounters end of
  339.         file.  If the end of file is encountered within a frame, the frame is
  340.         closed with a ZCRCE data subpacket which does not elicit a response
  341.         except in case of error.
  342.  
  343.         The sender sends a ZEOF header with the file ending offset equal to
  344.         the number of characters in the file.  The receiver compares this
  345.         number with the number of characters received. If the receiver has
  346.         received all of the file, it closes the file.  If the file close was
  347.         satisfactory, the receiver responds with ZRINIT.  If the receiver has
  348.         not received all the bytes of the file, the receiver ignores the ZEOF
  349.         because a new ZDATA is coming. If the receiver cannot properly close
  350.         the file, a ZFERR header is sent.
  351.  
  352.         After all files are processed, any further protocol
  353.         errors should not prevent the sending program from
  354.         returning with a success status.
  355.  
  356.     SESSION CLEANUP
  357.     ---------------
  358.  
  359.         The sender closes the session with a ZFIN header.  The receiver
  360.         acknowledges this with its own ZFIN header.
  361.  
  362.         When the sender receives the acknowledging header, it sends two
  363.         characters, "OO" (Over and Out) and exits.
  364.         The receiver waits briefly for the "O" characters, then exits
  365.         whether they were received or not.
  366.  
  367.     SESSION ABORT SEQUENCE
  368.     ----------------------
  369.  
  370.         If the receiver is receiving data in streaming mode, the Attn
  371.         sequence is executed to interrupt data transmission before the Cancel
  372.         sequence is sent.  The Cancel sequence consists of eight CAN
  373.         characters and ten backspace characters.  zmodem only requires five
  374.         Cancel characters, the other three are "insurance".
  375.  
  376.         The trailing backspace characters attempt to erase the effects of the
  377.         CAN characters if they are received by a command interpreter.
  378.  
  379.            char ses_abort_seq[] = {
  380.                 24,24,24,24,24,24,24,24,8,8,8,8,8,8,8,8,8,8,0
  381.            };
  382.  
  383.     ATTENTION SEQUENCE
  384.     ------------------
  385.  
  386.         The receiving program sends the Attn sequence whenever it detects an
  387.         error and needs to interrupt the sending program.
  388.  
  389.         The default Attn string value is empty (no Attn sequence).  The
  390.         receiving program resets Attn to the empty default before each
  391.         transfer session.
  392.  
  393.         The sender specifies the Attn sequence in its optional ZSINIT frame.
  394.         The Attn string is terminated with a null.
  395.  
  396. FRAME TYPES
  397. -----------
  398.  
  399.     The numeric values are listed at the end of this file.
  400.     Unused bits and unused bytes in the header (ZP0...ZP3) are set to 0.
  401.  
  402.     ZRQINIT
  403.     -------
  404.  
  405.         Sent by the sending program, to trigger the receiving program to send
  406.         its ZRINIT header.  
  407.         The sending program may
  408.         repeat the receive invitation (including ZRQINIT) if a response is
  409.         not obtained at first.
  410.  
  411.         ZF0 contains ZCOMMAND if the program is attempting to send a command,
  412.         0 otherwise.
  413.  
  414.     ZRINIT
  415.     ------
  416.  
  417.         Sent by the receiving program. ZF0 and ZF1 contain the  bitwise or
  418.         of the receiver capability flags:
  419.  
  420.             CANCRY        receiver can decrypt
  421.             CANFDX        receiver can send and receive true full duplex
  422.             CANOVIO        receiver can receive data during disk I/O
  423.             CANBRK        receiver can send a break signal
  424.             CANCRY        receiver can decrypt
  425.             CANLZW        receiver can uncompress
  426.             CANFC32        receiver can use 32 bit Frame Check
  427.             ESCCTL        receiver expects ctl chars to be escaped
  428.             ESC8        receiver expects 8th bit to be escaped
  429.  
  430.         ZP0 and ZP1 contain the size of the receiver's buffer in bytes, or 0
  431.         if nonstop I/O is allowed.
  432.  
  433.         while all these capabilities are nice in theory most zmodem implem-
  434.         tations balk at anything other than 0,0. i.e. telix starts sending
  435.         35 byte packets when CANFC32 is on.
  436.  
  437.     ZSINIT
  438.     ------
  439.  
  440.         The Sender sends flags followed by a binary data subpacket terminated
  441.         with ZCRCW.
  442.  
  443.             TESCCTL        Transmitter expects ctl chars to be escaped
  444.             TESC8        Transmitter expects 8th bit to be escaped
  445.  
  446.         The data subpacket contains the null terminated Attn sequence,
  447.         maximum length 32 bytes including the terminating null.
  448.  
  449.     ZACK
  450.     ----
  451.  
  452.         Acknowledgment to a ZSINIT frame, ZCHALLENGE header, ZCRCQ or ZCRCW
  453.         data subpacket.  ZP0 to ZP3 contain file offset.  The response to
  454.         ZCHALLENGE contains the same 32 bit number received in the ZCHALLENGE
  455.         header.
  456.  
  457.     ZFILE
  458.     -----
  459.         This frame denotes the beginning of a file transmission attempt.
  460.         ZF0, ZF1, and ZF2 may contain options. A value of 0 in each of these
  461.         bytes implies no special treatment.  Options specified to the
  462.         receiver override options specified to the sender with the exception
  463.         of ZCBIN.  A ZCBIN from the sender overrides any other Conversion
  464.         Option given to the receiver except ZCRESUM.  A ZCBIN from the
  465.         receiver overrides any other Conversion Option sent by the sender.
  466.  
  467.  
  468.         ZF0: CONVERSION OPTION
  469.         ----------------------
  470.  
  471.             If the receiver does not recognize the Conversion Option, an
  472.             application dependent default conversion may apply.
  473.  
  474.             ZCBIN "Binary" transfer - inhibit conversion unconditionally
  475.  
  476.             ZCNL Convert received end of line to local end of line
  477.                  convention.  The supported end of line conventions are
  478.                  CR/LF (most ASCII based operating systems except Unix
  479.                  and Macintosh), and NL (Unix).  Either of these two end
  480.                  of line conventions meet the permissible ASCII
  481.                  definitions for Carriage Return and Line Feed/New Line.
  482.                  Neither the ASCII code nor zmodem ZCNL encompass lines
  483.                  separated only by carriage returns.  Other processing
  484.                  appropriate to ASCII text files and the local operating
  485.                  system may also be applied by the receiver. (filtering
  486.                  RUBOUT NULL Ctrl-Z etc)
  487.  
  488.             ZCRECOV Recover/Resume interrupted file transfer.  ZCREVOV is
  489.                  also useful for updating a remote copy of a file that
  490.                  grows without resending of old data.  If the destination
  491.                  file exists and is no longer than the source, append to
  492.                  the destination file and start transfer at the offset
  493.                  corresponding to the receiver's end of file.  This
  494.                  option does not apply if the source file is shorter.
  495.                  Files that have been converted (e.g., ZCNL) or subject
  496.                  to a single ended Transport Option cannot have their
  497.                  transfers recovered.
  498.  
  499.         ZF1: Management Option
  500.         ----------------------
  501.  
  502.             If the receiver does not recognize the Management Option, the
  503.             file should be transferred normally.
  504.  
  505.             The ZMSKNOLOC bit instructs the receiver to bypass the
  506.             current file if the receiver does not have a file with the
  507.             same name.
  508.  
  509.             Five bits (defined by ZMMASK) define the following set of
  510.             mutually exclusive management options.
  511.  
  512.                 ZMNEWL Transfer file if destination file absent.  Otherwise,
  513.                 transfer file overwriting destination if the source file
  514.                 is newer or longer.
  515.  
  516.                 ZMCRC Compare the source and destination files.  Transfer if
  517.                 file lengths or file polynomials differ.
  518.  
  519.                 ZMAPND Append source file contents to the end of the existing
  520.                 destination file (if any).
  521.  
  522.                 ZMCLOB Replace existing destination file (if any).
  523.  
  524.                 ZMDIFF Transfer file if destination file absent.  Otherwise,
  525.                 transfer file overwriting destination if files have
  526.                 different lengths or dates.
  527.  
  528.                 ZMPROT Protect destination file by transferring file only if
  529.                 the destination file is absent.
  530.  
  531.                 ZMNEW Transfer file if destination file absent.  Otherwise,
  532.                 transfer file overwriting destination if the source file
  533.                 is newer.
  534.  
  535.         ZF2: TRANSPORT OPTION
  536.         ---------------------
  537.  
  538.             If the receiver does not implement the particular transport
  539.             option, the file is copied without conversion for later
  540.             processing. better not to use these; see readme
  541.  
  542.             ZTLZW Lempel-Ziv compression.  Transmitted data will be
  543.             identical to that produced by compress 4.0 operating on
  544.             a computer with VAX byte ordering, using 12 bit
  545.             encoding.
  546.  
  547.             ZTCRYPT Encryption.  An initial null terminated string
  548.             identifies the key.  Details to be determined.
  549.  
  550.             ZTRLE Run Length encoding, Details to be determined.
  551.  
  552.             A ZCRCW data subpacket follows with file name, file length,
  553.             modification date, and other information described in a later
  554.             chapter.
  555.  
  556.         ZF3: EXTENDED OPTIONS
  557.         ---------------------
  558.  
  559.             The Extended Options are bit encoded.
  560.  
  561.             ZTSPARS Special processing for sparse files, or sender managed
  562.             selective retransmission. Each file segment is transmitted as
  563.             a separate frame, where the frames are not necessarily
  564.             contiguous.  The sender should end each segment with a ZCRCW
  565.             data subpacket and process the expected ZACK to insure no data
  566.             is lost.  ZTSPARS cannot be used with ZCNL.
  567.  
  568.     ZSKIP
  569.     -----
  570.  
  571.         Sent by the receiver in response to ZFILE, makes the sender skip to
  572.         the next file.
  573.  
  574.     ZNAK
  575.     ----
  576.  
  577.         Indicates last header was garbled.  (See also ZRPOS).
  578.  
  579.     ZABORT
  580.     ------
  581.  
  582.         Sent by receiver to terminate batch file transfers when requested by
  583.         the user.  Sender responds with a ZFIN sequence. (or ZCOMPL in case of
  584.         server mode).
  585.  
  586.     ZFIN
  587.     ----
  588.  
  589.         Sent by sending program to terminate a zmodem session. Receiver
  590.         responds with its own ZFIN.
  591.  
  592.     ZRPOS
  593.     -----
  594.  
  595.         Sent by receiver to force file transfer to resume at file offset
  596.         given in ZP0...ZP3.
  597.  
  598.     ZDATA
  599.     -----
  600.  
  601.         ZP0...ZP3 contain file offset. One or more data subpackets follow.
  602.  
  603.     ZEOF
  604.     ----
  605.  
  606.         Sender reports End of File.  ZP0...ZP3 contain the ending file
  607.         offset.
  608.  
  609.     ZFERR
  610.     -----
  611.  
  612.         Error in reading or writing file, protocol equivalent to ZABORT.
  613.  
  614.     ZCRC
  615.     ----
  616.  
  617.         Request (receiver) and response (sender) for file polynomial.
  618.         ZP0...ZP3 contain file polynomial.
  619.  
  620.     ZCHALLENGE
  621.     ----------
  622.  
  623.         Request sender to echo a random number in ZP0...ZP3 in a ZACK frame.
  624.         Sent by the receiving program to the sending program to verify that
  625.         it is connected to an operating program, and was not activated by
  626.         spurious data or a Trojan Horse message. this is the most simply 
  627.         defeated security system ever invented. don't rely on it and better
  628.         still don't use or implement it. build your security measures around
  629.         starting the download at all and disallow explicit path names.
  630.  
  631.     ZCOMPL
  632.     ------
  633.  
  634.         Request now completed.
  635.  
  636.     ZCAN
  637.     ----
  638.  
  639.         This is a pseudo frame type in response to a
  640.         Session Abort sequence.
  641.  
  642.     ZFREECNT
  643.     --------
  644.  
  645.         Sending program requests a ZACK frame with ZP0...ZP3 containing the
  646.         number of free bytes on the current file system.  A value of 0
  647.         represents an indefinite amount of free space.
  648.  
  649.     ZCOMMAND
  650.     --------
  651.  
  652.         ZCOMMAND is sent in a binary frame.  ZF0 contains 0 or ZCACK1 (see
  653.         below).
  654.  
  655.         A ZCRCW data subpacket follows, with the ASCII text command string
  656.         terminated with a NULL character.  If the command is intended to be
  657.         executed by the operating system hosting the receiving program
  658.         (e.g., "shell escape"), it must have "!" as the first character.
  659.         Otherwise the command is meant to be executed by the application
  660.         program which receives the command.
  661.  
  662.         If the receiver detects an illegal or badly formed command, the
  663.         receiver immediately responds with a ZCOMPL header with an error
  664.         code in ZP0...ZP3.
  665.  
  666.         If ZF0 contained ZCACK1, the receiver immediately responds with a
  667.         ZCOMPL header with 0 status.
  668.  
  669.         Otherwise, the receiver responds with a ZCOMPL header when the
  670.         operation is completed.  The exit status of the completed command is
  671.         stored in ZP0...ZP3.  A 0 exit status implies nominal completion of
  672.         the command.
  673.  
  674.         If the command causes a file to be transmitted, the command sender
  675.         will see a ZRQINIT frame from the other computer attempting to send
  676.         data.
  677.  
  678.         The sender examines ZF0 of the received ZRQINIT header to verify it
  679.         is not an echo of its own ZRQINIT header.  It is illegal for the
  680.         sending program to command the receiving program to send a command.
  681.  
  682.         If the receiver program does not implement command downloading, it
  683.         may display the command to the standard error output, then return a
  684.         ZCOMPL header.
  685.  
  686.     ZFILE FRAME FILE INFORMATION SUBPACKET
  687.     --------------------------------------
  688.  
  689.         zmodem sends the same file information with the ZFILE frame data
  690.  
  691.         The pathname (file name) field is mandatory. each field after 
  692.         pathname is optional and separated from the previous one by 
  693.         a space. fields may not be skipped. the use of the optional
  694.         fields is (by definition) optional to the receiver.
  695.  
  696.         PATHNAME
  697.         --------
  698.  
  699.             The pathname (conventionally, the file name) is sent as a
  700.             null terminated ASCII string. 
  701.             No spaces are included in the pathname. 
  702.  
  703.             Filename Considerations
  704.  
  705.                 - File names should be translated to lower case unless the
  706.                   sending system supports upper/lower case file names. This
  707.                   is a convenience for users of systems (such as Unix) which
  708.                   store filenames in upper and lower case.
  709.  
  710.                 - The receiver should accommodate file names in lower and
  711.                   upper case.
  712.     
  713.                 - When transmitting files between different operating
  714.                   systems, file names must be acceptable to both the sender
  715.                   and receiving operating systems.  If not, transformations
  716.                   should be applied to make the file names acceptable. If
  717.                   the transformations are unsuccessful, a new file name may
  718.                   be invented be the receiving program.
  719.     
  720.                 - If directories are included, they are delimited by /; i.e.,
  721.                   "subdir/foo" is acceptable, "subdir\foo" is not.
  722.     
  723.         LENGTH
  724.         ------
  725.  
  726.             The length field is stored as a decimal string
  727.             counting the number of data bytes in the file.
  728.  
  729.             The zmodem receiver uses the file length as an estimate only.
  730.             It may be used to display an estimate of the transmission time,
  731.             and may be compared with the amount of free disk space.  The
  732.             actual length of the received file is determined by the data
  733.             transfer. A file may grow after transmission commences, and
  734.             all the data will be sent.
  735.  
  736.         MODIFICATION DATE
  737.         -----------------
  738.  
  739.             The mod date is sent as an octal number giving the time the
  740.             contents of the file were last changed measured in seconds from
  741.             Jan 1 1970 Universal Coordinated Time (GMT).  A date of 0
  742.             implies the modification date is unknown and should be left as
  743.             the date the file is received.
  744.  
  745.             This standard format was chosen to eliminate ambiguities
  746.             arising from transfers between different time zones.
  747.  
  748.         FILE MODE
  749.         ---------
  750.  
  751.             The file mode is stored as an octal string.
  752.             Unless the file originated from a Unix system, the file mode is
  753.             set to 0. 
  754.  
  755.         SERIAL NUMBER
  756.         -------------
  757.  
  758.             set this field to 0.
  759.  
  760.         NUMBER OF FILES REMAINING
  761.         -------------------------
  762.  
  763.             This field is coded as a decimal number, and includes the
  764.             current file.  This field is an estimate, and incorrect values
  765.             must not be allowed to cause loss of data.
  766.  
  767.         NUMBER OF BYTES REMAINING 
  768.         -------------------------
  769.  
  770.             This field is coded as a decimal number, and includes the
  771.             current file.  This field is an estimate, and incorrect values
  772.             must not be allowed to cause loss of data. 
  773.  
  774.         FILE TYPE
  775.         ---------
  776.  
  777.             set this field to 0.
  778.  
  779.         The file information is terminated by a null.  If only the pathname
  780.         is sent, the pathname is terminated with two nulls.  The length of
  781.         the file information subpacket, including the trailing null, must
  782.         not exceed 1024 bytes; a typical length is less than 64 bytes.
  783.  
  784. STREAMING TECHNIQUES / ERROR RECOVERY
  785. -------------------------------------
  786.  
  787.     zmodem provides several data streaming methods
  788.     selected according to the limitations of the sending environment,
  789.     receiving environment, and transmission channel(s).
  790.     
  791.     WINDOW MANAGEMENT
  792.     -----------------
  793.  
  794.         When sending data through a network, some nodes of the network store
  795.         data while it is transferred to the receiver.  7000 bytes and more of
  796.         transient storage have been observed.  Such a large amount of storage
  797.         causes the transmitter to "get ahead" of the receiver. 
  798.         This condition is not fatal but it does slow error recovery.
  799.         
  800.         To manage the window size, the sending program uses ZCRCQ data
  801.         subpackets to trigger ZACK headers from the receiver.  The returning
  802.         ZACK headers inform the sender of the receiver's progress.  When the
  803.         window size (current transmitter file offset - last reported receiver
  804.         file offset) exceeds a specified value, the sender waits for a
  805.         ZACK packet with a receiver file offset that reduces the window
  806.         size. ZRPOS and other error packets are handled normally.
  807.  
  808.     FULL STREAMING WITH SAMPLING
  809.     ----------------------------    
  810.  
  811.         If the receiver can overlap serial I/O with disk I/O, and if the
  812.         sender can sample the reverse channel for the presence of data
  813.         without having to wait, full streaming can be used with no Attn
  814.         sequence required.  The sender begins data transmission with a ZDATA
  815.         header and continuous ZCRCG data subpackets.  When the receiver
  816.         detects an error, it executes the Attn sequence and then sends a
  817.         ZRPOS header with the correct position within the file.
  818.         
  819.         At the end of each transmitted data subpacket, the sender checks for
  820.         the presence of an error header from the receiver.  To do this, the
  821.         sender samples the reverse data stream for the presence of either a
  822.         ZPAD or CAN character (using rdchk() or a similar mechanism)
  823.         . Flow control characters (if present) are acted upon.
  824.         
  825.         Other characters (indicating line noise) increment a counter which is
  826.         reset whenever the sender waits for a header from the receiver.  If
  827.         the counter overflows, the sender sends the next data subpacket as
  828.         ZCRCW, and waits for a response.
  829.         
  830.         ZPAD indicates some sort of error header from the receiver.  A CAN
  831.         suggests the user is attempting to "stop the bubble machine" by
  832.         keyboarding CAN characters.  If one of these characters is seen, an
  833.         empty ZCRCE data subpacket is sent.  Normally, the receiver will have
  834.         sent an ZRPOS or other error header, which will force the sender to
  835.         resume transmission at a different address, or take other action.  In
  836.         the unlikely event the ZPAD or CAN character was spurious, the
  837.         receiver will time out and send a ZRPOS header.
  838.         The obvious choice of ZCRCW packet, which would trigger an ZACK from
  839.         the receiver, is not used because multiple in transit frames could
  840.         result if the channel has a long propagation delay.
  841.         
  842.         Then the receiver's response header is read and acted upon; starting
  843.         with a resinchronize.
  844.         
  845.         A ZRPOS header resets the sender's file offset to the correct
  846.         position.  If possible, the sender should purge its output buffers
  847.         and/or networks of all unprocessed output data, to minimize the
  848.         amount of unwanted data the receiver must discard before receiving
  849.         data starting at the correct file offset.  The next transmitted data
  850.         frame should be a ZCRCW frame followed by a wait to guarantee
  851.         complete flushing of the network's memory.
  852.     
  853.         If the receiver gets a ZACK header with an address that disagrees
  854.         with the sender address, it is ignored, and the sender waits for
  855.         another header.  A ZFIN, ZABORT, or TIMEOUT terminates the session; a
  856.         ZSKIP terminates the processing of this file.
  857.         
  858.         The reverse channel is then sampled for the presence of another
  859.         header from the receiver (if sampling is possible). if one is detected
  860.         another error header is read. Otherwise,
  861.         transmission resumes at the (possibly reset) file offset with a ZDATA
  862.         header followed by data subpackets.
  863.     
  864.     FULL STREAMING WITH REVERSE INTERRUPT
  865.     -------------------------------------    
  866.  
  867.         The above method cannot be used if the reverse data stream cannot be
  868.         sampled without entering an I/O wait.  An alternate method is to
  869.         instruct the receiver to interrupt the sending program when an error
  870.         is detected.
  871.     
  872.         The receiver can interrupt the sender with a control character, break
  873.         signal, or combination thereof, as specified in the Attn sequence.
  874.         After executing the Attn sequence, the receiver sends a hex ZRPOS
  875.         header to force the sender to resend the lost data.
  876.         
  877.         When the sending program responds to this interrupt, it reads a HEX
  878.         header (normally ZRPOS) from the receiver and takes the action
  879.         described in the previous section. 
  880.     
  881.     FULL STREAMING WITH SLIDING WINDOW
  882.     ----------------------------------    
  883.  
  884.         If none of the above methods is applicable, hope is not yet lost.  If
  885.         the sender can buffer responses from the receiver, the sender can use
  886.         ZCRCQ data subpackets to get ACKs from the receiver without
  887.         interrupting the transmission of data. After a sufficient number of
  888.         ZCRCQ data subpackets have been sent, the sender can read one of the
  889.         headers that should have arrived in its receive interrupt buffer.
  890.     
  891.         A problem with this method is the possibility of wasting an excessive
  892.         amount of time responding to the receiver's error header.  It may be
  893.         possible to program the receiver's Attn sequence to flush the
  894.         sender's interrupt buffer before sending the ZRPOS header.
  895.  
  896.     SEGMENTED STREAMING
  897.     -------------------
  898.  
  899.         If the receiver cannot overlap serial and disk I/O, it uses the
  900.         ZRINIT frame to specify a buffer length which the sender will not
  901.         overflow.  The sending program sends a ZCRCW data subpacket and waits
  902.         for a ZACK header before sending the next segment of the file.
  903.  
  904.         A sufficiently large receiving buffer allows throughput to closely
  905.         approach that of full streaming.  For example, 16kb segmented
  906.         streaming adds about 3 per cent to full streaming zmodem file
  907.         transfer times when the round trip delay is five seconds.
  908.  
  909. CONSTANTS
  910. ---------
  911.  
  912.     ASCII
  913.     -----
  914.  
  915.         SOH            0x01
  916.         STX            0x02
  917.         EOT            0x04
  918.         ENQ            0x05
  919.         ACK            0x06
  920.         LF            0x0a
  921.         CR            0x0d
  922.         XON            0x11
  923.         XOFF        0x13
  924.         NAK            0x15
  925.         CAN            0x18
  926.  
  927.     ZMODEM    
  928.     ------
  929.  
  930.         ZPAD        0x2a    /* pad character; begins frames */
  931.         ZDLE        0x18    /* ctrl-x zmodem escape */
  932.         ZDLEE        0x58    /* escaped ZDLE */    
  933.  
  934.         ZBIN        0x41    /* binary frame indicator (CRC16) */
  935.         ZHEX        0x42    /* hex frame indicator */
  936.         ZBIN32        0x43    /* binary frame indicator (CRC32) */
  937.         ZBINR32        0x44    /* run length encoded binary frame (CRC32) */
  938.  
  939.         ZVBIN        0x61    /* binary frame indicator (CRC16) */
  940.         ZVHEX        0x62    /* hex frame indicator */
  941.         ZVBIN32        0x63    /* binary frame indicator (CRC32) */
  942.         ZVBINR32    0x64    /* run length encoded binary frame (CRC32) */
  943.  
  944.         ZRESC        0x7e    /* run length encoding flag / escape character */
  945.  
  946.     FRAME TYPES
  947.     -----------
  948.  
  949.         ZRQINIT        0x00    /* request receive init (s->r) */
  950.         ZRINIT        0x01    /* receive init (r->s) */
  951.         ZSINIT        0x02    /* send init sequence (optional) (s->r) */
  952.         ZACK        0x03    /* ack to ZRQINIT ZRINIT or ZSINIT (s<->r) */
  953.         ZFILE        0x04    /* file name (s->r) */
  954.         ZSKIP        0x05    /* skip this file (r->s) */
  955.         ZNAK        0x06    /* last packet was corrupted (?) */
  956.         ZABORT        0x07    /* abort batch transfers (?) */
  957.         ZFIN        0x08    /* finish session (s<->r) */
  958.         ZRPOS        0x09    /* resume data transmission here (r->s) */
  959.         ZDATA        0x0a    /* data packet(s) follow (s->r) */
  960.         ZEOF        0x0b    /* end of file reached (s->r) */
  961.         ZFERR        0x0c    /* fatal read or write error detected (?) */
  962.         ZCRC        0x0d    /* request for file CRC and response (?) */
  963.         ZCHALLENGE    0x0e    /* security challenge (r->s) */
  964.         ZCOMPL        0x0f    /* request is complete (?) */    
  965.         ZCAN        0x10    /* pseudo frame; 
  966.                                other end cancelled session with 5* CAN */
  967.         ZFREECNT    0x11    /* request free bytes on file system (s->r) */
  968.         ZCOMMAND    0x12    /* issue command (s->r) */
  969.         ZSTDERR        0x13    /* output data to stderr (??) */
  970.  
  971.     ZDLE SEQUENCES
  972.     --------------
  973.  
  974.         ZCRCE        0x68    /* CRC next, frame ends, header packet follows */
  975.         ZCRCG        0x69    /* CRC next, frame continues nonstop */
  976.         ZCRCQ        0x6a    /* CRC next, frame continuous, ZACK expected */
  977.         ZCRCW        0x6b    /* CRC next, ZACK expected, end of frame */
  978.         ZRUB0        0x6c    /* translate to rubout 0x7f */
  979.         ZRUB1        0x6d    /* translate to rubout 0xff */
  980.  
  981.     RECEIVER CAPABILITY FLAGS
  982.     -------------------------
  983.  
  984.         CANFDX        0x01    /* Rx can send and receive true full duplex */
  985.         CANOVIO        0x02    /* Rx can receive data during disk I/O */
  986.         CANBRK        0x04    /* Rx can send a break signal */
  987.         CANCRY        0x08    /* Receiver can decrypt */
  988.         CANLZW        0x10    /* Receiver can uncompress */
  989.         CANFC32        0x20    /* Receiver can use 32 bit Frame Check */
  990.         ESCCTL        0x40    /* Receiver expects ctl chars to be escaped
  991.         ESC8        0x80    /* Receiver expects 8th bit to be escaped */
  992.  
  993.  
  994.