home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / docum / xyz.doc / ymodem.doc next >
Encoding:
Text File  |  1992-03-28  |  67.2 KB  |  1,722 lines

  1.  
  2.                                       - 1 -
  3.  
  4.  
  5.  
  6.                          XMODEM/YMODEM PROTOCOL REFERENCE
  7.                      A compendium of documents describing the
  8.  
  9.                                 XMODEM and YMODEM
  10.  
  11.                              File Transfer Protocols
  12.  
  13.  
  14.  
  15.  
  16.                       This document was formatted 10-14-88.
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.                              Edited by Chuck Forsberg
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.                 This file may be redistributed without restriction
  35.                         provided the text is not altered.
  36.  
  37.                      Please distribute as widely as possible.
  38.  
  39.                            Questions to Chuck Forsberg
  40.  
  41.  
  42.  
  43.  
  44.  
  45.                                Omen Technology Inc
  46.                           The High Reliability Software
  47.                             17505-V Sauvie Island Road
  48.                               Portland Oregon 97231
  49.                             VOICE: 503-621-3406 :VOICE
  50.       TeleGodzilla BBS: 503-621-3746 Speed 19200(Telebit PEP),2400,1200,300
  51.                               CompuServe: 70007,2304
  52.                                     GEnie: CAF
  53.                         UUCP: ...!tektronix!reed!omen!caf
  54.  
  55.  
  56.  
  57.                                       - 2 -
  58.  
  59.     1.  TOWER OF BABEL
  60.  
  61.     A "YMODEM Tower of Babel" has descended on the microcomputing community
  62.     bringing with it confusion, frustration, bloated phone bills, and wasted
  63.     man hours.  Sadly, I (Chuck Forsberg) am partly to blame for this mess.
  64.  
  65.     As author of the early 1980s batch and 1k XMODEM extensions, I assumed
  66.     readers of earlier versions of this document would implement as much of
  67.     the YMODEM protocol as their programming skills and computing environments
  68.     would permit.  This proved a rather naive assumption as programmers
  69.     motivated by competitive pressure implemented as little of YMODEM as
  70.     possible.  Some have taken whatever parts of YMODEM that appealed to them,
  71.     applied them to MODEM7 Batch, Telink, XMODEM or whatever, and called the
  72.     result YMODEM.
  73.  
  74.     Jeff Garbers (Crosstalk package development director) said it all: "With
  75.     protocols in the public domain, anyone who wants to dink around with them
  76.     can go ahead." [1]
  77.  
  78.     Documents containing altered examples derived from YMODEM.DOC have added
  79.     to the confusion.  In one instance, some self styled rewriter of history
  80.     altered the heading in YMODEM.DOC's Figure 1 from "1024 byte Packets" to
  81.     "YMODEM/CRC File Transfer Protocol".  None of the XMODEM and YMODEM
  82.     examples shown in that document were correct.
  83.  
  84.     To put an end to this confusion, we must make "perfectly clear" what
  85.     YMODEM stands for, as Ward Christensen defined it in his 1985 coining of
  86.     the term.
  87.  
  88.     To the majority of you who read, understood, and respected Ward's
  89.     definition of YMODEM, I apologize for the inconvenience.
  90.  
  91.     1.1  Definitions
  92.  
  93.     ARC     ARC is a program that compresses one or more files into an archive
  94.             and extracts files from such archives.
  95.  
  96.     XMODEM  refers to the file transfer etiquette introduced by Ward
  97.             Christensen's 1977 MODEM.ASM program.  The name XMODEM comes from
  98.             Keith Petersen's XMODEM.ASM program, an adaptation of MODEM.ASM
  99.             for Remote CP/M (RCPM) systems.  It's also called the MODEM or
  100.             MODEM2 protocol.  Some who are unaware of MODEM7's unusual batch
  101.             file mode call it MODEM7.  Other aliases include "CP/M Users'
  102.             Group" and "TERM II FTP 3".  The name XMODEM caught on partly
  103.             because it is distinctive and partly because of media interest in
  104.  
  105.  
  106.     __________
  107.  
  108.      1. Page C/12, PC-WEEK July 12, 1987
  109.  
  110.     Chapter 1
  111.  
  112.     X/YMODEM Protocol Reference    June 18 1988                              3
  113.  
  114.             bulletin board and RCPM systems where it was accessed with an
  115.             "XMODEM" command.  This protocol is supported by every serious
  116.             communications program because of its universality, simplicity,
  117.             and reasonable performance.
  118.  
  119.     XMODEM/CRC replaces XMODEM's 1 byte checksum with a two byte Cyclical
  120.             Redundancy Check (CRC-16), giving modern error detection
  121.             protection.
  122.  
  123.     XMODEM-1k Refers to the XMODEM/CRC protocol with 1024 byte data blocks.
  124.  
  125.     YMODEM  Refers to the XMODEM/CRC (optional 1k blocks) protocol with batch
  126.             transmission as described below.  In a nutshell, YMODEM means
  127.             BATCH.
  128.  
  129.     YMODEM-g Refers to the streaming YMODEM variation described below.
  130.  
  131.     True YMODEM(TM) In an attempt to sort out the YMODEM Tower of Babel, Omen
  132.             Technology has trademarked the term True YMODEM(TM) to represent
  133.             the complete YMODEM protocol described in this document, including
  134.             pathname, length, and modification date transmitted in block 0.
  135.             Please contact Omen Technology about certifying programs for True
  136.             YMODEM(TM) compliance.
  137.  
  138.     ZMODEM  uses familiar XMODEM/CRC and YMODEM technology in a new protocol
  139.             that provides reliability, throughput, file management, and user
  140.             amenities appropriate to contemporary data communications.
  141.  
  142.     ZOO     Like ARC, ZOO is a program that compresses one or more files into
  143.             a "zoo archive".  ZOO supports many different operating systems
  144.             including Unix and VMS.
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.     Chapter 1
  156.  
  157.     X/YMODEM Protocol Reference    June 18 1988                              4
  158.  
  159.     2.  YMODEM MINIMUM REQUIREMENTS
  160.  
  161.     All programs claiming to support YMODEM must meet the following minimum
  162.     requirements:
  163.  
  164.        + The sending program shall send the pathname (file name) in block 0.
  165.  
  166.        + The pathname shall be a null terminated ASCII string as described
  167.          below.
  168.  
  169.          For those who are too lazy to read the entire document:
  170.  
  171.             + Unless specifically requested, only the file name portion is
  172.               sent.
  173.  
  174.             + No drive letter is sent.
  175.  
  176.             + Systems that do not distinguish between upper and lower case
  177.               letters in filenames shall send the pathname in lower case only.
  178.  
  179.  
  180.        + The receiving program shall use this pathname for the received file
  181.          name, unless explicitly overridden.
  182.  
  183.        + When the receiving program receives this block and successfully
  184.          opened the output file, it shall acknowledge this block with an ACK
  185.          character and then proceed with a normal XMODEM file transfer
  186.          beginning with a "C" or NAK tranmsitted by the receiver.
  187.  
  188.        + The sending program shall use CRC-16 in response to a "C" pathname
  189.          nak, otherwise use 8 bit checksum.
  190.  
  191.        + The receiving program must accept any mixture of 128 and 1024 byte
  192.          blocks within each file it receives.  Sending programs may
  193.          arbitrarily switch between 1024 and 128 byte blocks.
  194.  
  195.        + The sending program must not change the length of an unacknowledged
  196.          block.
  197.  
  198.        + At the end of each file, the sending program shall send EOT up to ten
  199.          times until it receives an ACK character.  (This is part of the
  200.          XMODEM spec.)
  201.  
  202.        + The end of a transfer session shall be signified by a null (empty)
  203.          pathname, this pathname block shall be acknowledged the same as other
  204.          pathname blocks.
  205.  
  206.     Programs not meeting all of these requirements are not YMODEM compatible,
  207.     and shall not be described as supporting YMODEM.
  208.  
  209.     Meeting these MINIMUM requirements does not guarantee reliable file
  210.  
  211.     Chapter 2
  212.  
  213.     X/YMODEM Protocol Reference    June 18 1988                              5
  214.  
  215.     transfers under stress.  Particular attention is called to XMODEM's single
  216.     character supervisory messages that are easily corrupted by transmission
  217.     errors.
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.     Chapter 2
  267.  
  268.     X/YMODEM Protocol Reference    June 18 1988                              6
  269.  
  270.     3.  WHY YMODEM?
  271.  
  272.     Since its development half a decade ago, the Ward Christensen modem
  273.     protocol has enabled a wide variety of computer systems to interchange
  274.     data.  There is hardly a communications program that doesn't at least
  275.     claim to support this protocol.
  276.  
  277.     Advances in computing, modems and networking have revealed a number of
  278.     weaknesses in the original protocol:
  279.  
  280.        + The short block length caused throughput to suffer when used with
  281.          timesharing systems, packet switched networks, satellite circuits,
  282.          and buffered (error correcting) modems.
  283.  
  284.        + The 8 bit arithmetic checksum and other aspects allowed line
  285.          impairments to interfere with dependable, accurate transfers.
  286.  
  287.        + Only one file could be sent per command.  The file name had to be
  288.          given twice, first to the sending program and then again to the
  289.          receiving program.
  290.  
  291.        + The transmitted file could accumulate as many as 127 extraneous
  292.          bytes.
  293.  
  294.        + The modification date of the file was lost.
  295.  
  296.     A number of other protocols have been developed over the years, but none
  297.     have displaced XMODEM to date:
  298.  
  299.        + Lack of public domain documentation and example programs have kept
  300.          proprietary protocols such as Blast, Relay, and others tightly bound
  301.          to the fortunes of their suppliers.
  302.  
  303.        + Complexity discourages the widespread application of BISYNC, SDLC,
  304.          HDLC, X.25, and X.PC protocols.
  305.  
  306.        + Performance compromises and complexity have limited the popularity of
  307.          the Kermit protocol, which was developed to allow file transfers in
  308.          environments hostile to XMODEM.
  309.  
  310.     The XMODEM protocol extensions and YMODEM Batch address some of these
  311.     weaknesses while maintaining most of XMODEM's simplicity.
  312.  
  313.     YMODEM is supported by the public domain programs YAM (CP/M),
  314.     YAM(CP/M-86), YAM(CCPM-86), IMP (CP/M), KMD (CP/M), rz/sz (Unix, Xenix,
  315.     VMS, Berkeley Unix, Venix, Xenix, Coherent, IDRIS, Regulus).  Commercial
  316.     implementations include MIRROR, and Professional-YAM.[1] Communications
  317.  
  318.  
  319.  
  320.     Chapter 3
  321.  
  322.     X/YMODEM Protocol Reference    June 18 1988                              7
  323.  
  324.     programs supporting these extensions have been in use since 1981.
  325.  
  326.     The 1k block length (XMODEM-1k) described below may be used in conjunction
  327.     with YMODEM Batch Protocol, or with single file transfers identical to the
  328.     XMODEM/CRC protocol except for minimal changes to support 1k blocks.
  329.  
  330.     Another extension is the YMODEM-g protocol.  YMODEM-g provides batch
  331.     transfers with maximum throughput when used with end to end error
  332.     correcting media, such as X.PC and error correcting modems, including 9600
  333.     bps units by TeleBit, U.S.Robotics, Hayes, Electronic Vaults, Data Race,
  334.     and others.
  335.  
  336.     To complete this tome, edited versions of Ward Christensen's original
  337.     protocol document and John Byrns's CRC-16 document are included for
  338.     reference.
  339.  
  340.     References to the MODEM or MODEM7 protocol have been changed to XMODEM to
  341.     accommodate the vernacular.  In Australia, it is properly called the
  342.     Christensen Protocol.
  343.  
  344.  
  345.     3.1  Some Messages from the Pioneer
  346.  
  347.     #: 130940 S0/Communications 25-Apr-85  18:38:47
  348.     Sb: my protocol
  349.     Fm: Ward Christensen 76703,302 [2]
  350.     To: all
  351.  
  352.     Be aware the article[3] DID quote me correctly in terms of the phrases
  353.     like "not robust", etc.
  354.  
  355.     It was a quick hack I threw together, very unplanned (like everything I
  356.     do), to satisfy a personal need to communicate with "some other" people.
  357.  
  358.     ONLY the fact that it was done in 8/77, and that I put it in the public
  359.     domain immediately, made it become the standard that it is.
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.     __________________________________________________________________________
  368.  
  369.      1. Available for IBM PC,XT,AT, Unix and Xenix
  370.  
  371.      2. Edited for typesetting appearance
  372.  
  373.      3. Infoworld April 29 p. 16
  374.  
  375.     Chapter 3
  376.  
  377.     X/YMODEM Protocol Reference    June 18 1988                              8
  378.  
  379.     I think its time for me to
  380.  
  381.     (1) document it; (people call me and say "my product is going to include
  382.     it - what can I 'reference'", or "I'm writing a paper on it, what do I put
  383.     in the bibliography") and
  384.  
  385.     (2) propose an "incremental extension" to it, which might take "exactly"
  386.     the form of Chuck Forsberg's YAM protocol.  He wrote YAM in C for CP/M and
  387.     put it in the public domain, and wrote a batch protocol for Unix[4] called
  388.     rb and sb (receive batch, send batch), which was basically XMODEM with
  389.        (a) a record 0 containing filename date time and size
  390.        (b) a 1K block size option
  391.        (c) CRC-16.
  392.  
  393.     He did some clever programming to detect false ACK or EOT, but basically
  394.     left them the same.
  395.  
  396.     People who suggest I make SIGNIFICANT changes to the protocol, such as
  397.     "full duplex", "multiple outstanding blocks", "multiple destinations", etc
  398.     etc don't understand that the incredible simplicity of the protocol is one
  399.     of the reasons it survived to this day in as many machines and programs as
  400.     it may be found in!
  401.  
  402.     Consider the PC-NET group back in '77 or so - documenting to beat the band
  403.     - THEY had a protocol, but it was "extremely complex", because it tried to
  404.     be "all things to all people" - i.e. send binary files on a 7-bit system,
  405.     etc.  I was not that "benevolent". I (emphasize > I < ) had an 8-bit UART,
  406.     so "my protocol was an 8-bit protocol", and I would just say "sorry" to
  407.     people who were held back by 7-bit limitations.  ...
  408.  
  409.     Block size: Chuck Forsberg created an extension of my protocol, called
  410.     YAM, which is also supported via his public domain programs for UNIX
  411.     called rb and sb - receive batch and send batch.  They cleverly send a
  412.     "block 0" which contains the filename, date, time, and size.
  413.     Unfortunately, its UNIX style, and is a bit weird[5] - octal numbers, etc.
  414.     BUT, it is a nice way to overcome the kludgy "echo the chars of the name"
  415.     introduced with MODEM7.  Further, chuck uses CRC-16 and optional 1K
  416.     blocks.  Thus the record 0, 1K, and CRC, make it a "pretty slick new
  417.     protocol" which is not significantly different from my own.
  418.  
  419.     Also, there is a catchy name - YMODEM.  That means to some that it is the
  420.     "next thing after XMODEM", and to others that it is the Y(am)MODEM
  421.  
  422.  
  423.     __________
  424.  
  425.      4. VAX/VMS versions of these programs are also available.
  426.  
  427.      5. The file length, time, and file mode are optional.  The pathname and
  428.         file length may be sent alone if desired.
  429.  
  430.     Chapter 3
  431.  
  432.     X/YMODEM Protocol Reference    June 18 1988                              9
  433.  
  434.     protocol.  I don't want to emphasize that too much - out of fear that
  435.     other mfgrs might think it is a "competitive" protocol, rather than an
  436.     "unaffiliated" protocol.  Chuck is currently selling a much-enhanced
  437.     version of his CP/M-80 C program YAM, calling it Professional Yam, and its
  438.     for the PC - I'm using it right now.  VERY slick!  32K capture buffer,
  439.     script, scrolling, previously captured text search, plus built-in commands
  440.     for just about everything - directory (sorted every which way), XMODEM,
  441.     YMODEM, KERMIT, and ASCII file upload/download, etc.  You can program it
  442.     to "behave" with most any system - for example when trying a number for
  443.     CIS it detects the "busy" string back from the modem and substitutes a
  444.     diff phone # into the dialing string and branches back to try it.
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.     Chapter 3
  485.  
  486.     X/YMODEM Protocol Reference    June 18 1988                             10
  487.  
  488.     4.  XMODEM PROTOCOL ENHANCEMENTS
  489.  
  490.     This chapter discusses the protocol extensions to Ward Christensen's 1982
  491.     XMODEM protocol description document.
  492.  
  493.     The original document recommends the user be asked whether to continue
  494.     trying or abort after 10 retries.  Most programs no longer ask the
  495.     operator whether he wishes to keep retrying.  Virtually all correctable
  496.     errors are corrected within the first few retransmissions.  If the line is
  497.     so bad that ten attempts are insufficient, there is a significant danger
  498.     of undetected errors.  If the connection is that bad, it's better to
  499.     redial for a better connection, or mail a floppy disk.
  500.  
  501.  
  502.     4.1  Graceful Abort
  503.  
  504.     The YAM and Professional-YAM X/YMODEM routines recognize a sequence of two
  505.     consecutive CAN (Hex 18) characters without modem errors (overrun,
  506.     framing, etc.) as a transfer abort command.  This sequence is recognized
  507.     when is waiting for the beginning of a block or for an acknowledgement to
  508.     a block that has been sent.  The check for two consecutive CAN characters
  509.     reduces the number of transfers aborted by line hits.  YAM sends eight CAN
  510.     characters when it aborts an XMODEM, YMODEM, or ZMODEM protocol file
  511.     transfer.  Pro-YAM then sends eight backspaces to delete the CAN
  512.     characters from the remote's keyboard input buffer, in case the remote had
  513.     already aborted the transfer and was awaiting a keyboarded command.
  514.  
  515.  
  516.     4.2  CRC-16 Option
  517.  
  518.     The XMODEM protocol uses an optional two character CRC-16 instead of the
  519.     one character arithmetic checksum used by the original protocol and by
  520.     most commercial implementations.  CRC-16 guarantees detection of all
  521.     single and double bit errors,  all errors with an odd number of error
  522.     bits, all burst errors of length 16 or less, 99.9969% of all 17-bit error
  523.     bursts, and 99.9984 per cent of all possible longer error bursts.  By
  524.     contrast, a double bit error, or a burst error of 9 bits or more can sneak
  525.     past the XMODEM protocol arithmetic checksum.
  526.  
  527.     The XMODEM/CRC protocol is similar to the XMODEM protocol, except that the
  528.     receiver specifies CRC-16 by sending C (Hex 43) instead of NAK when
  529.     requesting the FIRST block.  A two byte CRC is sent in place of the one
  530.     byte arithmetic checksum.
  531.  
  532.     YAM's c option to the r command enables CRC-16 in single file reception,
  533.     corresponding to the original implementation in the MODEM7 series
  534.     programs.  This remains the default because many commercial communications
  535.     programs and bulletin board systems still do not support CRC-16,
  536.     especially those written in Basic or Pascal.
  537.  
  538.     XMODEM protocol with CRC is accurate provided both sender and receiver
  539.  
  540.     Chapter 4                                     XMODEM Protocol Enhancements
  541.  
  542.     X/YMODEM Protocol Reference    June 18 1988                             11
  543.  
  544.     both report a successful transmission.  The protocol is robust in the
  545.     presence of characters lost by buffer overloading on timesharing systems.
  546.  
  547.     The single character ACK/NAK responses generated by the receiving program
  548.     adapt well to split speed modems, where the reverse channel is limited to
  549.     ten per cent or less of the main channel's speed.
  550.  
  551.     XMODEM and YMODEM are half duplex protocols which do not attempt to
  552.     transmit information and control signals in both directions at the same
  553.     time.  This avoids buffer overrun problems that have been reported by
  554.     users attempting to exploit full duplex asynchronous file transfer
  555.     protocols such as Blast.
  556.  
  557.     Professional-YAM adds several proprietary logic enhancements to XMODEM's
  558.     error detection and recovery.  These compatible enhancements eliminate
  559.     most of the bad file transfers other programs make when using the XMODEM
  560.     protocol under less than ideal conditions.
  561.  
  562.  
  563.     4.3  XMODEM-1k 1024 Byte Block
  564.  
  565.     Disappointing throughput downloading from Unix with YMODEM[1] lead to the
  566.     development of 1024 byte blocks in 1982.  1024 byte blocks reduce the
  567.     effect of delays from timesharing systems, modems, and packet switched
  568.     networks on throughput by 87.5 per cent in addition to decreasing XMODEM's
  569.     3 per cent overhead (block number, CRC, etc.).
  570.  
  571.     Some environments cannot accept 1024 byte bursts, including some networks
  572.     and minicomputer ports.  The longer block length should be an option.
  573.  
  574.     The choice to use 1024 byte blocks is expressed to the sending program on
  575.     its command line or selection menu.[2] 1024 byte blocks improve throughput
  576.     in many applications.
  577.  
  578.     An STX (02) replaces the SOH (01) at the beginning of the transmitted
  579.     block to notify the receiver of the longer block length.  The transmitted
  580.     block contains 1024 bytes of data.  The receiver should be able to accept
  581.     any mixture of 128 and 1024 byte blocks.  The block number (in the second
  582.     and third bytes of the block) is incremented by one for each block
  583.     regardless of the block length.
  584.  
  585.     The sender must not change between 128 and 1024 byte block lengths if it
  586.     has not received a valid ACK for the current block.  Failure to observe
  587.  
  588.  
  589.     __________
  590.  
  591.      1. The name hadn't been coined yet, but the protocol was the same.
  592.  
  593.      2. See "KMD/IMP Exceptions to YMODEM" below.
  594.  
  595.     Chapter 4                                     XMODEM Protocol Enhancements
  596.   
  597.     X/YMODEM Protocol Reference    June 18 1988                             12
  598.  
  599.     this restriction allows transmission errors to pass undetected.
  600.  
  601.     If 1024 byte blocks are being used, it is possible for a file to "grow" up
  602.     to the next multiple of 1024 bytes.  This does not waste disk space if the
  603.     allocation granularity is 1k or greater.  With YMODEM batch transmission,
  604.     the optional file length transmitted in the file name block allows the
  605.     receiver to discard the padding, preserving the exact file length and
  606.     contents.
  607.  
  608.     1024 byte blocks may be used with batch file transmission or with single
  609.     file transmission.  CRC-16 should be used with the k option to preserve
  610.     data integrity over phone lines.  If a program wishes to enforce this
  611.     recommendation, it should cancel the transfer, then issue an informative
  612.     diagnostic message if the receiver requests checksum instead of CRC-16.
  613.  
  614.     Under no circumstances may a sending program use CRC-16 unless the
  615.     receiver commands CRC-16.
  616.  
  617.              Figure 1.  XMODEM-1k Blocks
  618.  
  619.              SENDER                                  RECEIVER
  620.                                                      "sx -k foo.bar"
  621.              "foo.bar open x.x minutes"
  622.                                                      C
  623.              STX 01 FE Data[1024] CRC CRC
  624.                                                      ACK
  625.              STX 02 FD Data[1024] CRC CRC
  626.                                                      ACK
  627.              STX 03 FC Data[1000] CPMEOF[24] CRC CRC
  628.                                                      ACK
  629.              EOT
  630.                                                      ACK
  631.  
  632.              Figure 2.  Mixed 1024 and 128 byte Blocks
  633.  
  634.              SENDER                                  RECEIVER
  635.                                                      "sx -k foo.bar"
  636.              "foo.bar open x.x minutes"
  637.                                                      C
  638.              STX 01 FE Data[1024] CRC CRC
  639.                                                      ACK
  640.              STX 02 FD Data[1024] CRC CRC
  641.                                                      ACK
  642.              SOH 03 FC Data[128] CRC CRC
  643.                                                      ACK
  644.              SOH 04 FB Data[100] CPMEOF[28] CRC CRC
  645.                                                      ACK
  646.              EOT
  647.                                                      ACK
  648.     Chapter 4                                     XMODEM Protocol Enhancements
  649.   
  650.     X/YMODEM Protocol Reference    June 18 1988                             13
  651.  
  652.     5.  YMODEM Batch File Transmission
  653.  
  654.     The YMODEM Batch protocol is an extension to the XMODEM/CRC protocol that
  655.     allows 0 or more files to be transmitted with a single command.  (Zero
  656.     files may be sent if none of the requested files is accessible.) The
  657.     design approach of the YMODEM Batch protocol is to use the normal routines
  658.     for sending and receiving XMODEM blocks in a layered fashion similar to
  659.     packet switching methods.
  660.  
  661.     Why was it necessary to design a new batch protocol when one already
  662.     existed in MODEM7?[1] The batch file mode used by MODEM7 is unsuitable
  663.     because it does not permit full pathnames, file length, file date, or
  664.     other attribute information to be transmitted.  Such a restrictive design,
  665.     hastily implemented with only CP/M in mind, would not have permitted
  666.     extensions to current areas of personal computing such as Unix, DOS, and
  667.     object oriented systems.  In addition, the MODEM7 batch file mode is
  668.     somewhat susceptible to transmission impairments.
  669.  
  670.     As in the case of single a file transfer, the receiver initiates batch
  671.     file transmission by sending a "C" character (for CRC-16).
  672.  
  673.     The sender opens the first file and sends block number 0 with the
  674.     following information.[2]
  675.  
  676.     Only the pathname (file name) part is required for batch transfers.
  677.  
  678.     To maintain upwards compatibility, all unused bytes in block 0 must be set
  679.     to null.
  680.  
  681.     Pathname The pathname (conventionally, the file name) is sent as a null
  682.          terminated ASCII string.  This is the filename format used by the
  683.          handle oriented MSDOS(TM) functions and C library fopen functions.
  684.          An assembly language example follows:
  685.                                   DB      'foo.bar',0
  686.          No spaces are included in the pathname.  Normally only the file name
  687.          stem (no directory prefix) is transmitted unless the sender has
  688.          selected YAM's f option to send the full pathname.  The source drive
  689.          (A:, B:, etc.) is not sent.
  690.  
  691.          Filename Considerations:
  692.  
  693.  
  694.  
  695.     __________
  696.  
  697.      1. The MODEM7 batch protocol transmitted CP/M FCB bytes f1...f8 and
  698.         t1...t3 one character at a time.  The receiver echoed these bytes as
  699.         received, one at a time.
  700.  
  701.      2. Only the data part of the block is described here.
  702.  
  703.     Chapter 5                                     XMODEM Protocol Enhancements
  704.   
  705.     X/YMODEM Protocol Reference    June 18 1988                             14
  706.  
  707.             + File names are forced to lower case unless the sending system
  708.               supports upper/lower case file names.  This is a convenience for
  709.               users of systems (such as Unix) which store filenames in upper
  710.               and lower case.
  711.  
  712.             + The receiver should accommodate file names in lower and upper
  713.               case.
  714.  
  715.             + When transmitting files between different operating systems,
  716.               file names must be acceptable to both the sender and receiving
  717.               operating systems.
  718.  
  719.          If directories are included, they are delimited by /; i.e.,
  720.          "subdir/foo" is acceptable, "subdir\foo" is not.
  721.  
  722.     Length The file length and each of the succeeding fields are optional.[3]
  723.          The length field is stored in the block as a decimal string counting
  724.          the number of data bytes in the file.  The file length does not
  725.          include any CPMEOF (^Z) or other garbage characters used to pad the
  726.          last block.
  727.  
  728.          If the file being transmitted is growing during transmission, the
  729.          length field should be set to at least the final expected file
  730.          length, or not sent.
  731.  
  732.          The receiver stores the specified number of characters, discarding
  733.          any padding added by the sender to fill up the last block.
  734.  
  735.     Modification Date The mod date is optional, and the filename and length
  736.          may be sent without requiring the mod date to be sent.
  737.  
  738.          Iff the modification date is sent, a single space separates the
  739.          modification date from the file length.
  740.  
  741.          The mod date is sent as an octal number giving the time the contents
  742.          of the file were last changed, measured in seconds from Jan 1 1970
  743.          Universal Coordinated Time (GMT).  A date of 0 implies the
  744.          modification date is unknown and should be left as the date the file
  745.          is received.
  746.  
  747.          This standard format was chosen to eliminate ambiguities arising from
  748.          transfers between different time zones.
  749.  
  750.  
  751.  
  752.  
  753.  
  754.     __________
  755.  
  756.      3. Fields may not be skipped.
  757.  
  758.   Chapter 5                    XMODEM Protocol Enhancements
  759.  
  760.     X/YMODEM Protocol Reference    June 18 1988                             15
  761.  
  762.     Mode Iff the file mode is sent, a single space separates the file mode
  763.          from the modification date.  The file mode is stored as an octal
  764.          string.  Unless the file originated from a Unix system, the file mode
  765.          is set to 0.  rb(1) checks the file mode for the 0x8000 bit which
  766.          indicates a Unix type regular file.  Files with the 0x8000 bit set
  767.          are assumed to have been sent from another Unix (or similar) system
  768.          which uses the same file conventions.  Such files are not translated
  769.          in any way.
  770.  
  771.  
  772.     Serial Number Iff the serial number is sent, a single space separates the
  773.          serial number from the file mode.  The serial number of the
  774.          transmitting program is stored as an octal string.  Programs which do
  775.          not have a serial number should omit this field, or set it to 0.  The
  776.          receiver's use of this field is optional.
  777.  
  778.  
  779.     Other Fields YMODEM was designed to allow additional header fields to be
  780.          added as above without creating compatibility problems with older
  781.          YMODEM programs.  Please contact Omen Technology if other fields are
  782.          needed for special application requirements.
  783.  
  784.     The rest of the block is set to nulls.  This is essential to preserve
  785.     upward compatibility.[4]
  786.  
  787.     If the filename block is received with a CRC or other error, a
  788.     retransmission is requested.  After the filename block has been received,
  789.     it is ACK'ed if the write open is successful.  If the file cannot be
  790.     opened for writing, the receiver cancels the transfer with CAN characters
  791.     as described above.
  792.  
  793.     The receiver then initiates transfer of the file contents with a "C"
  794.     character, according to the standard XMODEM/CRC protocol.
  795.  
  796.     After the file contents and XMODEM EOT have been transmitted and
  797.     acknowledged, the receiver again asks for the next pathname.
  798.  
  799.     Transmission of a null pathname terminates batch file transmission.
  800.  
  801.     Note that transmission of no files is not necessarily an error.  This is
  802.     possible if none of the files requested of the sender could be opened for
  803.     reading.
  804.  
  805.  
  806.  
  807.     __________
  808.  
  809.      4. If, perchance, this information extends beyond 128 bytes (possible
  810.         with Unix 4.2 BSD extended file names), the block should be sent as a
  811.         1k block as described above.
  812.  
  813.     Chapter 5                                     XMODEM Protocol Enhancements
  814.  
  815.     X/YMODEM Protocol Reference    June 18 1988                             16
  816.  
  817.     Most YMODEM receivers request CRC-16 by default.
  818.  
  819.     The Unix programs sz(1) and rz(1) included in the source code file
  820.     RZSZ.ZOO should answer other questions about YMODEM batch protocol.
  821.  
  822.               Figure 3.  YMODEM Batch Transmission Session (1 file)
  823.  
  824.               SENDER                                  RECEIVER
  825.                                                       "sb foo.*<CR>"
  826.               "sending in batch mode etc."
  827.                                                       C (command:rb)
  828.               SOH 00 FF foo.c NUL[123] CRC CRC
  829.                                                       ACK
  830.                                                       C
  831.               SOH 01 FE Data[128] CRC CRC
  832.                                                       ACK
  833.               SOH 02 FC Data[128] CRC CRC
  834.                                                       ACK
  835.               SOH 03 FB Data[100] CPMEOF[28] CRC CRC
  836.                                                       ACK
  837.               EOT
  838.                                                       NAK
  839.               EOT
  840.                                                       ACK
  841.                                                       C
  842.               SOH 00 FF NUL[128] CRC CRC
  843.                                                       ACK
  844.  
  845.                 Figure 7.  YMODEM Header Information and Features
  846.  
  847.     _____________________________________________________________
  848.     | Program   | Length | Date | Mode | S/N | 1k-Blk | YMODEM-g |
  849.     |___________|________|______|______|_____|________|__________|
  850.     |Unix rz/sz | yes    | yes  | yes  | no  | yes    | sb only  |
  851.     |___________|________|______|______|_____|________|__________|
  852.     |VMS rb/sb  | yes    | no   | no   | no  | yes    | no       |
  853.     |___________|________|______|______|_____|________|__________|
  854.     |Pro-YAM    | yes    | yes  | no   | yes | yes    | yes      |
  855.     |___________|________|______|______|_____|________|__________|
  856.     |CP/M YAM   | no     | no   | no   | no  | yes    | no       |
  857.     |___________|________|______|______|_____|________|__________|
  858.     |KMD/IMP    | ?      | no   | no   | no  | yes    | no       |
  859.     |___________|________|______|______|_____|________|__________|
  860.  
  861.     5.1  KMD/IMP Exceptions to YMODEM
  862.  
  863.     KMD and IMP use a "CK" character sequence emitted by the receiver to
  864.     trigger the use of 1024 byte blocks as an alternative to specifying this
  865.     option to the sending program.  This two character sequence generally
  866.     works well on single process micros in direct communication, provided the
  867.     programs rigorously adhere to all the XMODEM recommendations included
  868.  
  869.     Chapter 5                                     XMODEM Protocol Enhancements
  870.  
  871.     X/YMODEM Protocol Reference    June 18 1988                             17
  872.  
  873.        Figure 4.  YMODEM Batch Transmission Session (2 files)
  874.  
  875.            SENDER                                  RECEIVER
  876.                                                    "sb foo.c baz.c<CR>"
  877.            "sending in batch mode etc."
  878.                                                    C (command:rb)
  879.            SOH 00 FF foo.c NUL[123] CRC CRC
  880.                                                    ACK
  881.                                                    C
  882.            SOH 01 FE Data[128] CRC CRC
  883.                                                    ACK
  884.            SOH 02 FC Data[128] CRC CRC
  885.                                                    ACK
  886.            SOH 03 FB Data[100] CPMEOF[28] CRC CRC
  887.                                                    ACK
  888.            EOT
  889.                                                    NAK
  890.            EOT
  891.                                                    ACK
  892.                                                    C
  893.            SOH 00 FF baz.c NUL[123] CRC CRC
  894.                                                    ACK
  895.                                                    C
  896.            SOH 01 FB Data[100] CPMEOF[28] CRC CRC
  897.                                                    ACK
  898.            EOT
  899.                                                    NAK
  900.            EOT
  901.                                                    ACK
  902.                                                    C
  903.            SOH 00 FF NUL[128] CRC CRC
  904.                                                    ACK
  905.  
  906.             Figure 5.  YMODEM Batch Transmission Session-1k Blocks
  907.  
  908.             SENDER                                  RECEIVER
  909.                                                     "sb -k foo.*<CR>"
  910.             "sending in batch mode etc."
  911.                                                     C (command:rb)
  912.             SOH 00 FF foo.c NUL[123] CRC CRC
  913.                                                     ACK
  914.                                                     C
  915.             STX 01 FD Data[1024] CRC CRC
  916.                                                     ACK
  917.             SOH 02 FC Data[128] CRC CRC
  918.                                                     ACK
  919.             SOH 03 FB Data[100] CPMEOF[28] CRC CRC
  920.                                                     ACK
  921.             EOT
  922.                                                     NAK
  923.             EOT
  924.  
  925.     Chapter 5                                     XMODEM Protocol Enhancements
  926.  
  927.     X/YMODEM Protocol Reference    June 18 1988                             18
  928.  
  929.                                                     ACK
  930.                                                     C
  931.             SOH 00 FF NUL[128] CRC CRC
  932.                                                     ACK
  933.  
  934.            Figure 6.  YMODEM Filename block transmitted by sz
  935.  
  936.            -rw-r--r--  6347 Jun 17 1984 20:34 bbcsched.txt
  937.  
  938.            00 0100FF62 62637363 6865642E 74787400   |...bbcsched.txt.|
  939.            10 36333437 20333331 34373432 35313320   |6347 3314742513 |
  940.            20 31303036 34340000 00000000 00000000   |100644..........|
  941.            30 00000000 00000000 00000000 00000000
  942.            40 00000000 00000000 00000000 00000000
  943.            50 00000000 00000000 00000000 00000000
  944.            60 00000000 00000000 00000000 00000000
  945.            70 00000000 00000000 00000000 00000000
  946.            80 000000CA 56
  947.  
  948.     herein.  Programs with marginal XMODEM implementations do not fare so
  949.     well.  Timesharing systems and packet switched networks can separate the
  950.     successive characters, rendering this method unreliable.
  951.  
  952.     Sending programs may detect the CK sequence if the operating enviornment
  953.     does not preclude reliable implementation.
  954.  
  955.     Instead of the standard YMODEM file length in decimal, KMD and IMP
  956.     transmit the CP/M record count in the last two bytes of the header block.
  957.  
  958.  
  959.     6.  YMODEM-g File Transmission
  960.  
  961.     Developing technology is providing phone line data transmission at ever
  962.     higher speeds using very specialized techniques.  These high speed modems,
  963.     as well as session protocols such as X.PC, provide high speed, nearly
  964.     error free communications at the expense of considerably increased delay
  965.     time.
  966.  
  967.     This delay time is moderate compared to human interactions, but it
  968.     cripples the throughput of most error correcting protocols.
  969.  
  970.     The g option to YMODEM has proven effective under these circumstances.
  971.     The g option is driven by the receiver, which initiates the batch transfer
  972.     by transmitting a G instead of C.  When the sender recognizes the G, it
  973.     bypasses the usual wait for an ACK to each transmitted block, sending
  974.     succeeding blocks at full speed, subject to XOFF/XON or other flow control
  975.     exerted by the medium.
  976.  
  977.     The sender expects an inital G to initiate the transmission of a
  978.     particular file, and also expects an ACK on the EOT sent at the end of
  979.     each file.  This synchronization allows the receiver time to open and
  980.  
  981.     Chapter 6                                     XMODEM Protocol Enhancements
  982.  
  983.     X/YMODEM Protocol Reference    June 18 1988                             19
  984.  
  985.     close files as necessary.
  986.  
  987.     If an error is detected in a YMODEM-g transfer, the receiver aborts the
  988.     transfer with the multiple CAN abort sequence.  The ZMODEM protocol should
  989.     be used in applications that require both streaming throughput and error
  990.     recovery.
  991.  
  992.             Figure 8.  YMODEM-g Transmission Session
  993.  
  994.             SENDER                                  RECEIVER
  995.                                                     "sb foo.*<CR>"
  996.             "sending in batch mode etc..."
  997.                                                     G (command:rb -g)
  998.             SOH 00 FF foo.c NUL[123] CRC CRC
  999.                                                     G
  1000.             SOH 01 FE Data[128] CRC CRC
  1001.             STX 02 FD Data[1024] CRC CRC
  1002.             SOH 03 FC Data[128] CRC CRC
  1003.             SOH 04 FB Data[100] CPMEOF[28] CRC CRC
  1004.             EOT
  1005.                                                     ACK
  1006.                                                     G
  1007.             SOH 00 FF NUL[128] CRC CRC
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.     Chapter 6                                     XMODEM Protocol Enhancements
  1035.  
  1036.     X/YMODEM Protocol Reference    June 18 1988                             20
  1037.  
  1038.     7.  XMODEM PROTOCOL OVERVIEW
  1039.  
  1040.     8/9/82 by Ward Christensen.
  1041.  
  1042.     I will maintain a master copy of this.  Please pass on changes or
  1043.     suggestions via CBBS/Chicago at (312) 545-8086, CBBS/CPMUG (312) 849-1132
  1044.     or by voice at (312) 849-6279.
  1045.  
  1046.     7.1  Definitions
  1047.  
  1048.       <soh> 01H
  1049.       <eot> 04H
  1050.       <ack> 06H
  1051.       <nak> 15H
  1052.       <can> 18H
  1053.       <C>   43H
  1054.  
  1055.  
  1056.     7.2  Transmission Medium Level Protocol
  1057.  
  1058.     Asynchronous, 8 data bits, no parity, one stop bit.
  1059.  
  1060.     The protocol imposes no restrictions on the contents of the data being
  1061.     transmitted.  No control characters are looked for in the 128-byte data
  1062.     messages.  Absolutely any kind of data may be sent - binary, ASCII, etc.
  1063.     The protocol has not formally been adopted to a 7-bit environment for the
  1064.     transmission of ASCII-only (or unpacked-hex) data , although it could be
  1065.     simply by having both ends agree to AND the protocol-dependent data with
  1066.     7F hex before validating it.  I specifically am referring to the checksum,
  1067.     and the block numbers and their ones- complement.
  1068.  
  1069.     Those wishing to maintain compatibility of the CP/M file structure, i.e.
  1070.     to allow modemming ASCII files to or from CP/M systems should follow this
  1071.     data format:
  1072.  
  1073.        + ASCII tabs used (09H); tabs set every 8.
  1074.  
  1075.        + Lines terminated by CR/LF (0DH 0AH)
  1076.  
  1077.        + End-of-file indicated by ^Z, 1AH.  (one or more)
  1078.  
  1079.        + Data is variable length, i.e. should be considered a continuous
  1080.          stream of data bytes, broken into 128-byte chunks purely for the
  1081.          purpose of transmission.
  1082.  
  1083.        + A CP/M "peculiarity": If the data ends exactly on a 128-byte
  1084.          boundary, i.e. CR in 127, and LF in 128, a subsequent sector
  1085.          containing the ^Z EOF character(s) is optional, but is preferred.
  1086.          Some utilities or user programs still do not handle EOF without ^Zs.
  1087.  
  1088.     Chapter 7                                         Xmodem Protocol Overview
  1089.  
  1090.     X/YMODEM Protocol Reference    June 18 1988                             21
  1091.  
  1092.        + The last block sent is no different from others, i.e.  there is no
  1093.          "short block".
  1094.                   Figure 9.  XMODEM Message Block Level Protocol
  1095.  
  1096.     Each block of the transfer looks like:
  1097.           <SOH><blk #><255-blk #><--128 data bytes--><cksum>
  1098.     in which:
  1099.     <SOH>         = 01 hex
  1100.     <blk #>       = binary number, starts at 01 increments by 1, and
  1101.                     wraps 0FFH to 00H (not to 01)
  1102.     <255-blk #>   = blk # after going thru 8080 "CMA" instr, i.e.
  1103.                     each bit complemented in the 8-bit block number.
  1104.                     Formally, this is the "ones complement".
  1105.     <cksum>       = the sum of the data bytes only.  Toss any carry.
  1106.  
  1107.     7.3  File Level Protocol
  1108.  
  1109.     7.3.1  Common_to_Both_Sender_and_Receiver
  1110.     All errors are retried 10 times.  For versions running with an operator
  1111.     (i.e. NOT with XMODEM), a message is typed after 10 errors asking the
  1112.     operator whether to "retry or quit".
  1113.  
  1114.     Some versions of the protocol use <can>, ASCII ^X, to cancel transmission.
  1115.     This was never adopted as a standard, as having a single "abort" character
  1116.     makes the transmission susceptible to false termination due to an <ack>
  1117.     <nak> or <soh> being corrupted into a <can> and aborting transmission.
  1118.  
  1119.     The protocol may be considered "receiver driven", that is, the sender need
  1120.     not automatically re-transmit, although it does in the current
  1121.     implementations.
  1122.  
  1123.  
  1124.     7.3.2  Receive_Program_Considerations
  1125.     The receiver has a 10-second timeout.  It sends a <nak> every time it
  1126.     times out.  The receiver's first timeout, which sends a <nak>, signals the
  1127.     transmitter to start.  Optionally, the receiver could send a <nak>
  1128.     immediately, in case the sender was ready.  This would save the initial 10
  1129.     second timeout.  However, the receiver MUST continue to timeout every 10
  1130.     seconds in case the sender wasn't ready.
  1131.  
  1132.     Once into a receiving a block, the receiver goes into a one-second timeout
  1133.     for each character and the checksum.  If the receiver wishes to <nak> a
  1134.     block for any reason (invalid header, timeout receiving data), it must
  1135.     wait for the line to clear.  See "programming tips" for ideas
  1136.  
  1137.     Synchronizing:  If a valid block number is received, it will be: 1) the
  1138.     expected one, in which case everything is fine; or 2) a repeat of the
  1139.     previously received block.  This should be considered OK, and only
  1140.     indicates that the receivers <ack> got glitched, and the sender re-
  1141.     transmitted; 3) any other block number indicates a fatal loss of
  1142.     synchronization, such as the rare case of the sender getting a line-glitch
  1143.  
  1144.     Chapter 7                                         Xmodem Protocol Overview
  1145.  
  1146.     X/YMODEM Protocol Reference    June 18 1988                             22
  1147.  
  1148.     that looked like an <ack>.  Abort the transmission, sending a <can>
  1149.  
  1150.  
  1151.     7.3.3  Sending_program_considerations
  1152.     While waiting for transmission to begin, the sender has only a single very
  1153.     long timeout, say one minute.  In the current protocol, the sender has a
  1154.     10 second timeout before retrying.  I suggest NOT doing this, and letting
  1155.     the protocol be completely receiver-driven.  This will be compatible with
  1156.     existing programs.
  1157.  
  1158.     When the sender has no more data, it sends an <eot>, and awaits an <ack>,
  1159.     resending the <eot> if it doesn't get one.  Again, the protocol could be
  1160.     receiver-driven, with the sender only having the high-level 1-minute
  1161.     timeout to abort.
  1162.  
  1163.  
  1164.     Here is a sample of the data flow, sending a 3-block message.  It includes
  1165.     the two most common line hits - a garbaged block, and an <ack> reply
  1166.     getting garbaged.  <xx> represents the checksum byte.
  1167.  
  1168.                   Figure 10.  Data flow including Error Recovery
  1169.  
  1170.     SENDER                                  RECEIVER
  1171.                                   times out after 10 seconds,
  1172.                                   <---              <nak>
  1173.     <soh> 01 FE -data- <xx>       --->
  1174.                                   <---              <ack>
  1175.     <soh> 02 FD -data- xx         --->       (data gets line hit)
  1176.                                   <---              <nak>
  1177.     <soh> 02 FD -data- xx         --->
  1178.                                   <---              <ack>
  1179.     <soh> 03 FC -data- xx         --->
  1180.     (ack gets garbaged)           <---              <ack>
  1181.     <soh> 03 FC -data- xx         --->              <ack>
  1182.     <eot>                         --->
  1183.                                   <---       <anything except ack>
  1184.     <eot>                         --->
  1185.                                   <---              <ack>
  1186.     (finished)
  1187.  
  1188.     7.4  Programming Tips
  1189.  
  1190.        + The character-receive subroutine should be called with a parameter
  1191.          specifying the number of seconds to wait.  The receiver should first
  1192.          call it with a time of 10, then <nak> and try again, 10 times.
  1193.  
  1194.          After receiving the <soh>, the receiver should call the character
  1195.          receive subroutine with a 1-second timeout, for the remainder of the
  1196.          message and the <cksum>.  Since they are sent as a continuous stream,
  1197.          timing out of this implies a serious like glitch that caused, say,
  1198.          127 characters to be seen instead of 128.
  1199.  
  1200.     Chapter 7                                         Xmodem Protocol Overview
  1201.  
  1202.     X/YMODEM Protocol Reference    June 18 1988                             23
  1203.  
  1204.        + When the receiver wishes to <nak>, it should call a "PURGE"
  1205.          subroutine, to wait for the line to clear.  Recall the sender tosses
  1206.          any characters in its UART buffer immediately upon completing sending
  1207.          a block, to ensure no glitches were mis- interpreted.
  1208.  
  1209.          The most common technique is for "PURGE" to call the character
  1210.          receive subroutine, specifying a 1-second timeout,[1] and looping
  1211.          back to PURGE until a timeout occurs.  The <nak> is then sent,
  1212.          ensuring the other end will see it.
  1213.  
  1214.        + You may wish to add code recommended by John Mahr to your character
  1215.          receive routine - to set an error flag if the UART shows framing
  1216.          error, or overrun.  This will help catch a few more glitches - the
  1217.          most common of which is a hit in the high bits of the byte in two
  1218.          consecutive bytes.  The <cksum> comes out OK since counting in 1-byte
  1219.          produces the same result of adding 80H + 80H as with adding 00H +
  1220.          00H.
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.     __________
  1247.  
  1248.      1. These times should be adjusted for use with timesharing systems.
  1249.  
  1250.     Chapter 7                                         Xmodem Protocol Overview
  1251.  
  1252.     X/YMODEM Protocol Reference    June 18 1988                             24
  1253.  
  1254.     8.  XMODEM/CRC Overview
  1255.  
  1256.     Original 1/13/85 by John Byrns -- CRC option.
  1257.  
  1258.     Please pass on any reports of errors in this document or suggestions for
  1259.     improvement to me via Ward's/CBBS at (312) 849-1132, or by voice at (312)
  1260.     885-1105.
  1261.  
  1262.     The CRC used in the Modem Protocol is an alternate form of block check
  1263.     which provides more robust error detection than the original checksum.
  1264.     Andrew S. Tanenbaum says in his book, Computer Networks, that the CRC-
  1265.     CCITT used by the Modem Protocol will detect all single and double bit
  1266.     errors, all errors with an odd number of bits, all burst errors of length
  1267.     16 or less, 99.997% of 17-bit error bursts, and 99.998% of 18-bit and
  1268.     longer bursts.[1]
  1269.  
  1270.     The changes to the Modem Protocol to replace the checksum with the CRC are
  1271.     straight forward. If that were all that we did we would not be able to
  1272.     communicate between a program using the old checksum protocol and one
  1273.     using the new CRC protocol. An initial handshake was added to solve this
  1274.     problem. The handshake allows a receiving program with CRC capability to
  1275.     determine whether the sending program supports the CRC option, and to
  1276.     switch it to CRC mode if it does. This handshake is designed so that it
  1277.     will work properly with programs which implement only the original
  1278.     protocol. A description of this handshake is presented in section 10.
  1279.  
  1280.                 Figure 11.  Message Block Level Protocol, CRC mode
  1281.  
  1282.     Each block of the transfer in CRC mode looks like:
  1283.          <SOH><blk #><255-blk #><--128 data bytes--><CRC hi><CRC lo>
  1284.     in which:
  1285.     <SOH>        = 01 hex
  1286.     <blk #>      = binary number, starts at 01 increments by 1, and
  1287.                    wraps 0FFH to 00H (not to 01)
  1288.     <255-blk #>  = ones complement of blk #.
  1289.     <CRC hi>     = byte containing the 8 hi order coefficients of the CRC.
  1290.     <CRC lo>     = byte containing the 8 lo order coefficients of the CRC.
  1291.  
  1292.     8.1  CRC Calculation
  1293.  
  1294.     8.1.1  Formal_Definition
  1295.     To calculate the 16 bit CRC the message bits are considered to be the
  1296.     coefficients of a polynomial. This message polynomial is first multiplied
  1297.     by X^16 and then divided by the generator polynomial (X^16 + X^12 + X^5 +
  1298.  
  1299.  
  1300.     __________
  1301.  
  1302.      1. This reliability figure is misleading because XMODEM's critical
  1303.         supervisory functions are not protected by this CRC.
  1304.  
  1305.     Chapter 8                                         Xmodem Protocol Overview
  1306.  
  1307.     X/YMODEM Protocol Reference    June 18 1988                             25
  1308.  
  1309.     1) using modulo two arithmetic. The remainder left after the division is
  1310.     the desired CRC. Since a message block in the Modem Protocol is 128 bytes
  1311.     or 1024 bits, the message polynomial will be of order X^1023. The hi order
  1312.     bit of the first byte of the message block is the coefficient of X^1023 in
  1313.     the message polynomial.  The lo order bit of the last byte of the message
  1314.     block is the coefficient of X^0 in the message polynomial.
  1315.  
  1316.                Figure 12.  Example of CRC Calculation written in C
  1317.  
  1318.     The following XMODEM crc routine is taken from "rbsb.c".  Please refer to
  1319.     the source code for these programs (contained in RZSZ.ZOO) for usage.  A
  1320.     fast table driven version is also included in this file.
  1321.  
  1322.     /* update CRC */
  1323.     unsigned short
  1324.     updcrc(c, crc)
  1325.     register c;
  1326.     register unsigned crc;
  1327.     {
  1328.             register count;
  1329.  
  1330.             for (count=8; --count>=0;) {
  1331.                     if (crc & 0x8000) {
  1332.                             crc <<= 1;
  1333.                             crc += (((c<<=1) & 0400)  !=  0);
  1334.                             crc ^= 0x1021;
  1335.                     }
  1336.                     else {
  1337.                             crc <<= 1;
  1338.                             crc += (((c<<=1) & 0400)  !=  0);
  1339.                     }
  1340.             }
  1341.             return crc;
  1342.     }
  1343.  
  1344.     8.2  CRC File Level Protocol Changes
  1345.  
  1346.     8.2.1  Common_to_Both_Sender_and_Receiver
  1347.     The only change to the File Level Protocol for the CRC option is the
  1348.     initial handshake which is used to determine if both the sending and the
  1349.     receiving programs support the CRC mode. All Modem Programs should support
  1350.     the checksum mode for compatibility with older versions.  A receiving
  1351.     program that wishes to receive in CRC mode implements the mode setting
  1352.     handshake by sending a <C> in place of the initial <nak>.  If the sending
  1353.     program supports CRC mode it will recognize the <C> and will set itself
  1354.     into CRC mode, and respond by sending the first block as if a <nak> had
  1355.     been received. If the sending program does not support CRC mode it will
  1356.     not respond to the <C> at all. After the receiver has sent the <C> it will
  1357.     wait up to 3 seconds for the <soh> that starts the first block. If it
  1358.     receives a <soh> within 3 seconds it will assume the sender supports CRC
  1359.     mode and will proceed with the file exchange in CRC mode. If no <soh> is
  1360.  
  1361.     Chapter 8                                         Xmodem Protocol Overview
  1362.  
  1363.     X/YMODEM Protocol Reference    June 18 1988                             26
  1364.  
  1365.     received within 3 seconds the receiver will switch to checksum mode, send
  1366.     a <nak>, and proceed in checksum mode. If the receiver wishes to use
  1367.     checksum mode it should send an initial <nak> and the sending program
  1368.     should respond to the <nak> as defined in the original Modem Protocol.
  1369.     After the mode has been set by the initial <C> or <nak> the protocol
  1370.     follows the original Modem Protocol and is identical whether the checksum
  1371.     or CRC is being used.
  1372.  
  1373.  
  1374.     8.2.2  Receive_Program_Considerations
  1375.     There are at least 4 things that can go wrong with the mode setting
  1376.     handshake.
  1377.  
  1378.       1.  the initial <C> can be garbled or lost.
  1379.  
  1380.       2.  the initial <soh> can be garbled.
  1381.  
  1382.       3.  the initial <C> can be changed to a <nak>.
  1383.  
  1384.       4.  the initial <nak> from a receiver which wants to receive in checksum
  1385.           can be changed to a <C>.
  1386.  
  1387.     The first problem can be solved if the receiver sends a second <C> after
  1388.     it times out the first time. This process can be repeated several times.
  1389.     It must not be repeated too many times before sending a <nak> and
  1390.     switching to checksum mode or a sending program without CRC support may
  1391.     time out and abort. Repeating the <C> will also fix the second problem if
  1392.     the sending program cooperates by responding as if a <nak> were received
  1393.     instead of ignoring the extra <C>.
  1394.  
  1395.     It is possible to fix problems 3 and 4 but probably not worth the trouble
  1396.     since they will occur very infrequently. They could be fixed by switching
  1397.     modes in either the sending or the receiving program after a large number
  1398.     of successive <nak>s. This solution would risk other problems however.
  1399.  
  1400.  
  1401.     8.2.3  Sending_Program_Considerations
  1402.     The sending program should start in the checksum mode. This will insure
  1403.     compatibility with checksum only receiving programs. Anytime a <C> is
  1404.     received before the first <nak> or <ack> the sending program should set
  1405.     itself into CRC mode and respond as if a <nak> were received. The sender
  1406.     should respond to additional <C>s as if they were <nak>s until the first
  1407.     <ack> is received. This will assist the receiving program in determining
  1408.     the correct mode when the <soh> is lost or garbled. After the first <ack>
  1409.     is received the sending program should ignore <C>s.
  1410.  
  1411.  
  1412.  
  1413.  
  1414.     Chapter 8                                         Xmodem Protocol Overview
  1415.  
  1416.     X/YMODEM Protocol Reference    June 18 1988                             27
  1417.  
  1418.     8.3  Data Flow Examples with CRC Option
  1419.  
  1420.     Here is a data flow example for the case where the receiver requests
  1421.     transmission in the CRC mode but the sender does not support the CRC
  1422.     option. This example also includes various transmission errors.  <xx>
  1423.     represents the checksum byte.
  1424.  
  1425.           Figure 13.  Data Flow: Receiver has CRC Option, Sender Doesn't
  1426.  
  1427.     SENDER                                        RECEIVER
  1428.                             <---                <C>
  1429.                                     times out after 3 seconds,
  1430.                             <---                <C>
  1431.                                     times out after 3 seconds,
  1432.                             <---                <C>
  1433.                                     times out after 3 seconds,
  1434.                             <---                <C>
  1435.                                     times out after 3 seconds,
  1436.                             <---                <nak>
  1437.     <soh> 01 FE -data- <xx> --->
  1438.                             <---                <ack>
  1439.     <soh> 02 FD -data- <xx> --->        (data gets line hit)
  1440.                             <---                <nak>
  1441.     <soh> 02 FD -data- <xx> --->
  1442.                             <---                <ack>
  1443.     <soh> 03 FC -data- <xx> --->
  1444.        (ack gets garbaged)  <---                <ack>
  1445.                                     times out after 10 seconds,
  1446.                             <---                <nak>
  1447.     <soh> 03 FC -data- <xx> --->
  1448.                             <---                <ack>
  1449.     <eot>                   --->
  1450.                             <---                <ack>
  1451.  
  1452.     Here is a data flow example for the case where the receiver requests
  1453.     transmission in the CRC mode and the sender supports the CRC option.  This
  1454.     example also includes various transmission errors.  <xxxx> represents the
  1455.     2 CRC bytes.
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  
  1465.  
  1466.  
  1467.     Chapter 8                                         Xmodem Protocol Overview
  1468.  
  1469.     X/YMODEM Protocol Reference    June 18 1988                             28
  1470.  
  1471.                Figure 14.  Receiver and Sender Both have CRC Option
  1472.  
  1473.     SENDER                                       RECEIVER
  1474.                               <---                 <C>
  1475.     <soh> 01 FE -data- <xxxx> --->
  1476.                               <---                 <ack>
  1477.     <soh> 02 FD -data- <xxxx> --->         (data gets line hit)
  1478.                               <---                 <nak>
  1479.     <soh> 02 FD -data- <xxxx> --->
  1480.                               <---                 <ack>
  1481.     <soh> 03 FC -data- <xxxx> --->
  1482.     (ack gets garbaged)       <---                 <ack>
  1483.                                          times out after 10 seconds,
  1484.                               <---                 <nak>
  1485.     <soh> 03 FC -data- <xxxx> --->
  1486.                               <---                 <ack>
  1487.     <eot>                     --->
  1488.                               <---                 <ack>
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.     Chapter 8                                         Xmodem Protocol Overview
  1521.  
  1522.     X/YMODEM Protocol Reference    June 18 1988                             29
  1523.  
  1524.     9.  MORE INFORMATION
  1525.  
  1526.     Please contact Omen Technology for troff source files and typeset copies
  1527.     of this document.
  1528.  
  1529.  
  1530.     9.1  TeleGodzilla Bulletin Board
  1531.  
  1532.     More information may be obtained by calling TeleGodzilla at 503-621-3746.
  1533.     Speed detection is automatic for 1200, 2400 and 19200(Telebit PEP) bps.
  1534.     TrailBlazer modem users may issue the TeleGodzilla trailblazer command to
  1535.     swith to 19200 bps once they have logged in.
  1536.  
  1537.     Interesting files include RZSZ.ZOO (C source code), YZMODEM.ZOO (Official
  1538.     XMODEM, YMODEM, and ZMODEM protocol descriptions), ZCOMMEXE.ARC,
  1539.     ZCOMMDOC.ARC, and ZCOMMHLP.ARC (PC-DOS shareware comm program with XMODEM,
  1540.     True YMODEM(TM), ZMODEM, Kermit Sliding Windows, Telink, MODEM7 Batch,
  1541.     script language, etc.).
  1542.  
  1543.  
  1544.     9.2  Unix UUCP Access
  1545.  
  1546.     UUCP sites can obtain the current version of this file with
  1547.                      uucp omen!/u/caf/public/ymodem.doc /tmp
  1548.     A continually updated list of available files is stored in
  1549.     /usr/spool/uucppublic/FILES.  When retrieving these files with uucp,
  1550.     remember that the destination directory on your system must be writeable
  1551.     by anyone, or the UUCP transfer will fail.
  1552.  
  1553.     The following L.sys line calls TeleGodzilla (Pro-YAM in host operation).
  1554.     TeleGodzilla determines the incoming speed automatically.
  1555.  
  1556.     In response to "Name Please:" uucico gives the Pro-YAM "link" command as a
  1557.     user name.  The password (Giznoid) controls access to the Xenix system
  1558.     connected to the IBM PC's other serial port.  Communications between
  1559.     Pro-YAM and Xenix use 9600 bps; YAM converts this to the caller's speed.
  1560.  
  1561.     Finally, the calling uucico logs in as uucp.
  1562.  
  1563.     omen Any ACU 2400 1-503-621-3746 se:--se: link ord: Giznoid in:--in: uucp
  1564.  
  1565.  
  1566.  
  1567.     10.  REVISIONS
  1568.  
  1569.     6-18-88 Further revised for clarity.  Corrected block numbering in two
  1570.     examples.
  1571.     10-27-87 Optional fields added for number of files remaining to be sent
  1572.     and total number of bytes remaining to be sent.
  1573.     10-18-87 Flow control discussion added to 1024 byte block descritpion,
  1574.     minor revisions for clarity per user comments.
  1575.  
  1576.     Chapter 10                          Xmodem Protocol Overview
  1577.  
  1578.     X/YMODEM Protocol Reference    June 18 1988                             30
  1579.  
  1580.     8-03-87 Revised for clarity.
  1581.     5-31-1987 emphasizes minimum requirements for YMODEM, and updates
  1582.     information on accessing files.
  1583.     9-11-1986 clarifies nomenclature and some minor points.
  1584.     The April 15 1986 edition clarifies some points concerning CRC
  1585.     calculations and spaces in the header.
  1586.  
  1587.  
  1588.     11.  YMODEM Programs
  1589.  
  1590.     ZCOMM, A shareware little brother to Professional-YAM, is available as
  1591.     ZCOMMEXE.ARC on TeleGodzilla and other bulletin board systems.  ZCOMM may
  1592.     be used to test YMODEM amd ZMODEM implementations.
  1593.  
  1594.     Unix programs supporting YMODEM are available on TeleGodzilla in RZSZ.ZOO.
  1595.     This ZOO archive includes a ZCOMM/Pro-YAM/PowerCom script ZUPL.T to upload
  1596.     a bootstrap program MINIRB.C, compile it, and then upload the rest of the
  1597.     files using the compiled MINIRB.  Most Unix like systems are supported,
  1598.     including V7, Xenix, Sys III, 4.2 BSD, SYS V, Idris, Coherent, and
  1599.     Regulus.
  1600.  
  1601.     A version for VAX-VMS is available in VRBSB.SHQ.
  1602.  
  1603.     Irv Hoff has added 1k blocks and basic YMODEM batch transfers to the KMD
  1604.     and IMP series programs, which replace the XMODEM and MODEM7/MDM7xx series
  1605.     respectively.  Overlays are available for a wide variety of CP/M systems.
  1606.  
  1607.     Questions about Professional-YAM communications software may be directed
  1608.     to:
  1609.          Chuck Forsberg
  1610.          Omen Technology Inc
  1611.          17505-V Sauvie Island Road
  1612.          Portland Oregon 97231
  1613.          VOICE: 503-621-3406 :VOICE
  1614.          Modem: 503-621-3746 Speed: 19200(Telebit PEP),2400,1200,300
  1615.          Usenet: ...!tektronix!reed!omen!caf
  1616.          CompuServe: 70007,2304
  1617.          GEnie: CAF
  1618.  
  1619.     Unlike ZMODEM and Kermit, XMODEM and YMODEM place obstacles in the path of
  1620.     a reliable high performance implementation, evidenced by poor reliability
  1621.     under stress of the industry leaders' XMODEM and YMODEM programs.  Omen
  1622.     Technology provides consulting and other services to those wishing to
  1623.     implement XMODEM, YMODEM, and ZMODEM with state of the art features and
  1624.     reliability.
  1625.  
  1626.  
  1627.  
  1628.  
  1629.     Chapter 11                                        Xmodem Protocol Overview
  1630.  
  1631.  
  1632.                                      CONTENTS
  1633.  
  1634.  
  1635.      1.  TOWER OF BABEL...................................................   2
  1636.          1.1  Definitions.................................................   2
  1637.  
  1638.      2.  YMODEM MINIMUM REQUIREMENTS......................................   4
  1639.  
  1640.      3.  WHY YMODEM?......................................................   6
  1641.          3.1  Some Messages from the Pioneer..............................   7
  1642.  
  1643.      4.  XMODEM PROTOCOL ENHANCEMENTS.....................................  10
  1644.          4.1  Graceful Abort..............................................  10
  1645.          4.2  CRC-16 Option...............................................  10
  1646.          4.3  XMODEM-1k 1024 Byte Block...................................  11
  1647.  
  1648.      5.  YMODEM Batch File Transmission...................................  13
  1649.          5.1  KMD/IMP Exceptions to YMODEM................................  16
  1650.  
  1651.      6.  YMODEM-g File Transmission.......................................  18
  1652.  
  1653.      7.  XMODEM PROTOCOL OVERVIEW.........................................  20
  1654.          7.1  Definitions.................................................  20
  1655.          7.2  Transmission Medium Level Protocol..........................  20
  1656.          7.3  File Level Protocol.........................................  21
  1657.          7.4  Programming Tips............................................  22
  1658.  
  1659.      8.  XMODEM/CRC Overview..............................................  24
  1660.          8.1  CRC Calculation.............................................  24
  1661.          8.2  CRC File Level Protocol Changes.............................  25
  1662.          8.3  Data Flow Examples with CRC Option..........................  27
  1663.  
  1664.      9.  MORE INFORMATION.................................................  29
  1665.          9.1  TeleGodzilla Bulletin Board.................................  29
  1666.          9.2  Unix UUCP Access............................................  29
  1667.  
  1668.     10.  REVISIONS........................................................  29
  1669.  
  1670.     11.  YMODEM Programs..................................................  30
  1671.  
  1672.                                       - i -
  1673.  
  1674.  
  1675.                                  LIST OF FIGURES
  1676.  
  1677.  
  1678.      Figure 1.  XMODEM-1k Blocks..........................................  12
  1679.  
  1680.      Figure 2.  Mixed 1024 and 128 byte Blocks............................  12
  1681.  
  1682.      Figure 3.  YMODEM Batch Transmission Session (1 file)................  16
  1683.  
  1684.      Figure 4.  YMODEM Batch Transmission Session (2 files)...............  16
  1685.  
  1686.      Figure 5.  YMODEM Batch Transmission Session-1k Blocks...............  16
  1687.  
  1688.      Figure 6.  YMODEM Filename block transmitted by sz...................  16
  1689.  
  1690.      Figure 7.  YMODEM Header Information and Features....................  16
  1691.  
  1692.      Figure 8.  YMODEM-g Transmission Session.............................  19
  1693.  
  1694.      Figure 9.  XMODEM Message Block Level Protocol.......................  21
  1695.  
  1696.     Figure 10.  Data flow including Error Recovery........................  22
  1697.  
  1698.     Figure 11.  Message Block Level Protocol, CRC mode....................  24
  1699.  
  1700.     Figure 12.  Example of CRC Calculation written in C...................  25
  1701.  
  1702.     Figure 13.  Data Flow: Receiver has CRC Option, Sender Doesn't........  27
  1703.  
  1704.     Figure 14.  Receiver and Sender Both have CRC Option..................  28
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.                                       - ii -
  1721.   
  1722.