home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / XFER.ZIP / XYMODEM.DOC < prev   
Text File  |  1991-07-28  |  9KB  |  224 lines

  1.        *** XMODEM Protocol ***
  2.  
  3.        XMODEM  refers  to  the  file transfer protocol introduced by Ward
  4.        Christensen in 1977.  XMODEM  is  widely  supported  on  most  all
  5.        bulletin board systems.
  6.  
  7.        The following ASCII character definitions are used in XMODEM.
  8.  
  9.        <SOH> = 01H  Is always the first byte in each block.
  10.        <EOT> = 04H  Sent instead of SOH to mark the end of transmission.
  11.        <ACK> = 06H  Positive acknowledgment.
  12.        <NAK> = 15H  Negative acknowledgment.
  13.        <CAN> = 18H  Cancel transfer.
  14.  
  15.        XMODEM  is  a  receiver driven, asynchronous, 8 data bit protocol.
  16.        Each packet looks like the following:
  17.  
  18.        <SOH> <packet #> <compliment #> <data> <checksum>
  19.  
  20.        where:
  21.  
  22.        <SOH>         = 01H
  23.        <packet #>    = Packet number, starting at 01, incrementing by 1,
  24.                        and wraps from 0FFH to 00H (not to 01H).
  25.        <compliment #>= 255 minus the packet number.
  26.        <data>        = 128 bytes of binary data.
  27.        <checksum>    = The sum of the data bytes. Starting with a zero
  28.                        add each data byte to the checksum. Use only the
  29.                        rightmost 8 bits.
  30.  
  31.        When the receiver is ready, it sends a NAK every 10 seconds  (  up
  32.        to one minute ) until the NAK is ackowledged by the transmitter by
  33.        sending  the  first  packet.  The transmitter continues by sending
  34.        each  packet  in  turn,  always  waiting  for  the  packet  to  be
  35.        ackowleged  before sending the next. Finally, when the transmitter
  36.        has no more data, it sends an EOT instead of a SOH to complete the
  37.        transfer.
  38.  
  39.        Each packet is sent by the transmitter as follows:
  40.  
  41.        (1) Each packet always starts with a SOH.
  42.  
  43.        (2) The  packet  number  is  sent  next,  starting  with 01H, and
  44.            incrementing by 1. The packet number wraps from 0FFH to 00H.
  45.  
  46.        (3) The packet number compliment  is  sent  next.  It  is  always
  47.            calculated a 255 minus the packet number.
  48.  
  49.        (4) Exactly 128 bytes of data is sent.  If the transmitter doesn't
  50.            have  128  bytes  of  data to send, then control-Z's (1AH) are
  51.            padded to the data block.
  52.  
  53.        (5) The checksum is calculated by  added  together  all  128  data
  54.            bytes and sending the least significant 8 bits.
  55.  
  56.        (6) The transmitter waits ( up to 10 seconds ) for a response. If
  57.            the response is an ACK, then the transmitter goes on  to  the
  58.            next  packet.  If the response is a NAK, then the transmitter
  59.            re-sends the entire packet. If the response is  a  CAN,  then
  60.            all further transmission is cancelled.
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.        Each packet is handled by the receiver as follows:
  69.  
  70.        (1) If the first character is an EOT  then  the  transfer  is  now
  71.            complete, and the receiver should ACK the EOT before exitting.
  72.            If the  first  character is a CAN,  then  all  further  action
  73.            is cancelled. If the first character is  a  SOH,  then this is
  74.            the  first character of the next packet.
  75.  
  76.        (2) If the packet number is not correct ( the first packet is 1 ),
  77.            then  this  is  a  fatal error, and the receiver should send a
  78.            CAN to the transmitter in order to cancel further transmission.
  79.  
  80.        (3) If the packet number compliment is not correct, this is also a
  81.            fatal error and the receiver sends a CAN to the transmitter.
  82.  
  83.        (4) Exactly 128 bytes of data are received.
  84.  
  85.        (5) The  checksum  is  received.  It  is  compared with the value
  86.            obtained by computing the  checksum  from  the  just  received
  87.            data.  If the  checksum values are the same, an ACK to sent to
  88.            the transmitter. Otherwise, a NAK is sent.
  89.  
  90.        Here is a XMODEM example of the data flow.  It  includes  the  two
  91.        most  common  line  hits:  a  garbaged  block,  and an <ACK> reply
  92.        getting  garbaged.  <data>  represent  128  bytes  of  data.  <CS>
  93.        represents the checksum byte.
  94.  
  95.         SENDER                                  RECEIVER
  96.         ======                                  ========
  97.  
  98.                                      <---              <NAK>
  99.        <SOH> 01 FE <data> <CS>       --->
  100.                                      <---              <ACK>
  101.        <SOH> 02 FD <data> <CS>       --->       (data gets line hit)
  102.                                      <---              <NAK>
  103.        <SOH> 02 FD <data> <CS>       --->
  104.                                      <---              <ACK>
  105.        <SOH> 03 FC <data> <CS>       --->
  106.        (ACK gets garbaged)           <---              <ACK>
  107.        <SOH> 03 FC <data> <CS>       --->              <ACK>
  108.        <EOT>                         --->
  109.                                      <---       <anything except ACK>
  110.        <EOT>                         --->
  111.                                      <---              <ACK>
  112.  
  113.  
  114.        *** XMODEM/CRC Protocol ***
  115.  
  116.        The XMODEM/CRC protocol is similar to the XMODEM protocol,  except
  117.        that  the  receiver specifies CRC-16 by sending C (Hex 43) instead
  118.        of NAK when requesting the FIRST block.  A two byte CRC is sent in
  119.        place of the one byte arithmetic checksum.
  120.  
  121.        *** XMODEM/1K Protocol ***
  122.  
  123.        The XMODEM/1K protocol is identical  to  XMODEM/CRC,  except  that
  124.        1024  byte  data blocks in addition to 128 byte data blocks can be
  125.        sent.  An STX (02H) replaces the SOH (01H) at the beginning of the
  126.        transmitted block to notify  the  receiver  of  the  longer  block
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.        length.   The  transmitted block contains 1024 bytes of data.  The
  134.        receiver should be able to accept any mixture of 128 and 1024 byte
  135.        blocks.  The block number (in the second and third  bytes  of  the
  136.        block)  is  incremented  by  one  for each block regardless of the
  137.        block length.
  138.  
  139.        The  sender  must  not  change  between  128  and  1024 byte block
  140.        lengths if it has not received a valid ACK for the current  block.
  141.  
  142.        Here is an example of XMODEM/1K with 1024 blocks:
  143.  
  144.               SENDER                                  RECEIVER
  145.               ======                                  ========
  146.                                                       C
  147.               STX 01 FE Data[1024] CRC CRC
  148.                                                       ACK
  149.               STX 02 FD Data[1024] CRC CRC
  150.                                                       ACK
  151.               STX 03 FC Data[1000] ^Z[24] CRC CRC
  152.                                                       ACK
  153.               EOT
  154.                                                       ACK
  155.  
  156.        Mixed 1024 and 128 byte Blocks
  157.  
  158.               SENDER                                  RECEIVER
  159.               ======                                  ========
  160.                                                       C
  161.               STX 01 FE Data[1024] CRC CRC
  162.                                                       ACK
  163.               STX 02 FD Data[1024] CRC CRC
  164.                                                       ACK
  165.               SOH 03 FC Data[128] CRC CRC
  166.                                                       ACK
  167.               SOH 04 FB Data[100] ^Z[28] CRC CRC
  168.                                                       ACK
  169.               EOT
  170.                                                       ACK
  171.  
  172.  
  173.        *** YMODEM Protocol ***
  174.  
  175.  
  176.        The  YMODEM  Batch  protocol  is  an  extension  to  the XMODEM/1K
  177.        protocol that allows 0 or more files to be transmitted in a single
  178.        session. YMODEM always sends an information packet (  number  0  )
  179.        with each file containing the filename and the file length.
  180.  
  181.        The filename is sent as a null terminated ASCII string.   This  is
  182.        the    filename    format   used  by  the  handle  oriented  MSDOS
  183.        functions.
  184.  
  185.        The  length  field  is sent as a decimal ascii string counting the
  186.        number of data bytes in  the  file.   The  file  length  does  not
  187.        include any ^Z or other characters used to pad the last block. All
  188.        unused bytes in packet 0 must be set to 0.
  189.  
  190.        After  the  file  has  been transmitted, the receiver asks for the
  191.        next file by sending a 'C'.
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.        Transmission of a null pathname terminates the YMODEM protocol.
  200.  
  201.  
  202.        Here is an example of YMODEM:
  203.  
  204.             SENDER                                  RECEIVER
  205.             ======                                  ========
  206.                                                     ACK
  207.                                                     C
  208.             STX 02 FD Data[1024] CRC CRC
  209.                                                     ACK
  210.             SOH 03 FC Data[128] CRC CRC
  211.                                                     ACK
  212.             SOH 04 FB Data[100] ^Z[28] CRC CRC
  213.                                                     ACK
  214.             EOT
  215.                                                     NAK
  216.             EOT
  217.                                                     ACK
  218.                                                     C
  219.             SOH 00 FF NUL[128] CRC CRC
  220.  
  221.  
  222.  
  223.                                                     ACK
  224.