home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / MODEMS / MODEM / 4KXMODEM.DOC < prev    next >
Text File  |  2000-06-30  |  18KB  |  397 lines

  1.  
  2. Date: 4 Jul 88 13:16:38 GMT
  3. From: pnet01!pro-sol!mdavis@nosc.mil (Morgan Davis)
  4. Subject: 4K XMODEM EXTENSION REFERENCE
  5.  
  6.                        THE 4K XMODEM EXTENSION REFERENCE
  7.                        =================================
  8.  
  9.                 A significant but simple upgrade for 1K XMODEM
  10.  
  11.                                  Developed by
  12.  
  13.                                  Morgan Davis
  14.  
  15.  
  16.                             Document Revision 1.00
  17.                                  July 4, 1988
  18.  
  19.                        Distribute as widely as possible.
  20.  
  21.  
  22.  
  23.  
  24.                                    CONTENTS
  25.                                    ========
  26.  
  27.  
  28.  
  29.              I. INTRODUCTION
  30.                 General Description and Background........ 1.1
  31.                 Features.................................. 1.2
  32.                 Why 4K?................................... 1.3
  33.  
  34.             II. PROTOCOL SPECIFICATIONS
  35.                 Symbol Definitions........................ 2.1
  36.                 Initial Handshaking -- Receiver........... 2.2
  37.                 Initial Handshaking -- Sender............. 2.3
  38.                 The Transfer.............................. 2.4
  39.                 Handling Errors........................... 2.5
  40.                 Buffer Considerations..................... 2.6
  41.                 Longer Timeout Option..................... 2.7
  42.  
  43.            III. APPLE-SPECIFICS
  44.                 ASCII Express "Pro" Extension............. 3.1
  45.                 AE Pro Mode Compatibility................. 3.2
  46.  
  47.                 ACKnowledgments
  48.                 Feedback and Line Noise
  49.  
  50.  
  51.  
  52.  
  53.                             PART ONE: INTRODUCTION
  54.                             ======================
  55.  
  56.  
  57.  
  58. 1.1:  General Description and Background
  59.  
  60. This document describes the 4K (kilobyte) extension to 1K XMODEM protocol.
  61. 1K XMODEM is a widely used and accepted standard in transferring information
  62. between terminals and communications equipment.  This document does not,
  63. however, delve into the details of XMODEM protocol.  Plenty of documentation
  64. has been written about XMODEM and its number of head-spinning variations.
  65.  
  66. Perhaps the most complete, yet concise reference describing this protocol is
  67. by Chuck Forsberg who improved upon XMODEM by developing YMODEM, a 1K
  68. variation of the standard 128-byte packet used in XMODEM.  Forsberg's
  69. _XMODEM/YMODEM_PROTOCOL_REFERENCE_ is widely distributed and available on
  70. most information services and local bulletin board systems.  If you can't
  71. locate a copy for yourself, write to:
  72.  
  73.         Omen Technology, Inc.
  74.         17505-V Sauvie Island Road
  75.         Portland, Oregon  97231
  76.         503/621-3406
  77.  
  78. or contact Chuck Forsberg at one of these addresses:
  79.  
  80.         Compuserve: 70715,131
  81.         UUCP: tektronix!reed!omen!caf
  82.         Telegodzilla BBS: 503/621-3746
  83.  
  84.  
  85. 1.2:  Features
  86.  
  87. Transferring a file with large data packets means it takes less time to
  88. send than if small packets were used.  This is because after each packet
  89. is sent, the sender must wait for an acknowledgement from the receiver.  This
  90. acknowledgement tells the sender "everything is fine" and to continue sending
  91. the next packet.
  92.  
  93. An ideal delay between packets (with no disk-access) is usually less than 200
  94. milliseconds, about 1/5th second.  But the delay can vary depending on
  95. environmental factors.  Most significant is the type of connection between
  96. the sender and receiver.  If a packet-switched network is utilized, such as
  97. Telenet or Tymnet, this delay can be quite lengthy -- from a half second on
  98. up to five seconds, perhaps longer.  Even if two modems are connected
  99. directly through the phone system delays can also occur, especially with
  100. error-correcting modems like the USRobotics Courier HST 9600.  Buffered
  101. multi-user systems are also a source of unwanted delays.  You can't
  102. arbitrarily speed up your modem to get around this problem, but you can make
  103. use of a larger data block size through software.
  104.  
  105. For example, if a 32K file is being sent using 4K data blocks, only eight of
  106. these inter-packet delays takes place during the course of the transfer.  But
  107. if a smaller packet is used, say the standard 128-byte size employed in
  108. regular XMODEM, 256 acknowledgements would transpire.  If it takes one second
  109. between each packet for this brief chat, you save about 4.25 minutes using a
  110. 4K data block as opposed to a 128-byte block, at the SAME baud rate.
  111.  
  112. As the size of the file increases, so does the improvement factor when larger
  113. data blocks are used.  In addition, the faster the transfer rate (2400 bps
  114. and higher), the better the performance with a larger block.
  115.  
  116.  
  117. 1.3:  Why 4K?
  118.  
  119. Using larger packets in XMODEM is nothing new.  This was realized as soon as
  120. 1200 bps modems became popular.  The step up from 128-byte packets to 1K
  121. packets became even more significant as 2400 bps modems became affordable.
  122. But now, with error-correcting 9600 bps modems and a wider use of
  123. packet-switched networks like Telenet's PC Pursuit, the 1K data block is no
  124. longer an optimal method.
  125.  
  126.              If a larger data block is better, why not use
  127.              something really big, like a 16K packet?
  128.  
  129. Three reasons:
  130.  
  131. One.  To be widely accepted and compatible with most microcomputers, a
  132. dedicated 16K packet buffer would bestow a major burden on most terminal
  133. programs, especially on 64K-RAM machines.  The 4K packet proves to be a
  134. significant improvement over smaller sizes while being reasonable in its
  135. demands on most machines.
  136.  
  137. Two.  Having to resend just one 16K packet due to an error at 2400 bps or
  138. lower (very popular speeds at the time of this writing) would nullify any
  139. improvement in using a large packet.  Even 8K would be unreasonable.
  140.  
  141. Three (and this is a technical problem).  Many computers just aren't fast
  142. enough to handle a constant 16K stream of data at speeds faster than 2400
  143. bps.  As each character is received, the computer might have to service more
  144. than one interrupt, manage buffering, handle events from the user, as well as
  145. perform CRCs and other calculations.  A lot of computers just couldn't keep
  146. up since there is no software flow control during an 8-bit, asynchronous
  147. transfer.
  148.  
  149. Data communications involves transactions between many different types of
  150. computers.  So when 19,200 bps speeds and one megabyte RAM machines become
  151. standard issue, we will have definitely outgrown the 4K packet size and can
  152. consider something more robust.  But until that time . . .
  153.  
  154.  
  155.  
  156.  
  157.                         PART TWO: PROTOCOL SPECIFICATION
  158.                         ================================
  159.  
  160.  
  161.  
  162. 2.1:  Symbol Definitions
  163.  
  164. <SOH>  = 01h = Start of header (128-byte block)
  165. <STX>  = 02h = Start of header (1K block)
  166. <EOT>  = 04h = End of transfer
  167. <ACK>  = 06h = Acknowledge (good block)
  168. <NAK>  = 15h = Negative ACK (bad block)
  169. <CAN>  = 18h = Cancel transfer
  170.  <C>   = 43h = CRC request character
  171.  <K>   = 4Bh = 1K data block request character
  172.  <L>   = 4Ch = 4K data block request character ("L" for "Large").
  173. <SSTX> = 82h = Special Start of header (4K block)
  174.  
  175.  
  176. 2.2:  Initial Handshaking -- Receiver
  177.  
  178. To transfer a file with 1K or 4K data blocks, the receiver must request the
  179. CRC-16 option, as a cyclic redundancy check is required to use 1K and 4K
  180. packets.  This is done by sending <C> every three seconds instead of <NAK>.
  181. The sender will look for a <NAK> or <C> from the receiver as a cue to begin
  182. the transfer.
  183.  
  184. Though not required but as a consideration to the sender, the receiver
  185. should send <C><K><L> rather than just <C>.  This tells a 4K-compatible
  186. sender that 1K and 4K blocks can be handled by the receiver.  (The sending of
  187. <C><K> is an accepted standard for requesting 1K blocks).
  188.  
  189. The order of the letters <K> and <L> shouldn't be significant to the sender,
  190. but they should be sent as <K><L> as a matter of convention.  This will avoid
  191. any problems if 4K blocks are requested from a sender that only understands
  192. 128-byte and 1K data blocks, as it will see <C><K> and ignore the following
  193. <L>.
  194.  
  195. The receiver should send these request characters every three seconds and
  196. wait for either <SOH>, <STX>, or <SSTX> to come in from the sender.  These
  197. characters denote the start of a 128-byte, 1K, or 4K packet being delivered,
  198. and CRC-16 is assumed.
  199.  
  200. If the receiver has sent the request characters three or four times and
  201. nothing has come back from the sender, it reverts to standard XMODEM and
  202. begins sending <NAK> once every ten seconds for at least a minute.  At this
  203. point, the receiver will only recognize 128-byte, checksum packets.  It
  204. ignores any start of header character other than <SOH>, as anything else
  205. could be garbage from line noise.
  206.  
  207. Should the receiver get two <CAN>s in a row while waiting for the start of a
  208. packet, it can abort the receive attempt.
  209.  
  210.  
  211. 2.3:  Initial Handshaking -- Sender
  212.  
  213. If the sender gets a <NAK> while waiting to begin the transfer, it knows that
  214. a standard, 128-byte, checksum XMODEM is requested and can begin sending
  215. right away.
  216.  
  217. If the sender gets a <C>, it prepares to use the CRC-16 option.  At this
  218. point, it should set up a one-second timeout and wait for either a <K> or
  219. <L>.  If a <K> is detected, it should wait one more second for the
  220. possibility of an <L> to come in.  To effect this in an elegant manner, a
  221. loop can be created which simply waits one second per character until a
  222. timeout occurs.  When a character comes in it is examined to see if it is a
  223. <K> or <L> (the other shouldn't matter) and, if so, the appropriate flags are
  224. set.  It then loops back for more characters.  When a timeout occurs, the
  225. loop terminates and the transfer begins immediately.
  226.  
  227. With some implementations, the receiver will only send a <C> and the block
  228. size is already assumed to be 1K or 4K.  Therefore, the sender should begin
  229. sending blocks using a size specified by the operator of the sending program.
  230.  
  231. Should the sender detect two <CAN>s in a row, it can elect to abort the
  232. transfer.
  233.  
  234.  
  235. 2.3:  The Transfer
  236.  
  237. After each side has introduced itself, the transfer begins.  At this point,
  238. all the rules that apply to standard 128-byte and 1K XMODEM are applicable to
  239. 4K mode as well.  The only difference is that a 4K packet begins with <SSTX>,
  240. which simply is <STX> with bit 7 set to 1.  This alerts the receiver that
  241. 4096 bytes of data are contained in the data block of the packet being sent.
  242. The transfer continues as you would expect.
  243.  
  244. When the sender nears the end of the file, it ought to begin tapering down
  245. the data block sizes using the "best fit" logic.  For example, if there is
  246. less than 4K left to send, it should fall back to 1K or 128-byte blocks,
  247. whichever is most efficient.  This will insure that the resulting file will
  248. not contain any more than 127 padding characters (usually nulls, 00h).
  249. Imagine the great injustice to the receiver if nearly 4K of unnecessary
  250. padding was delivered.
  251.  
  252.  
  253. 2.4:  Error Handling
  254.  
  255. Bad block retries due to errors can really degrade performance, especially
  256. with 1K and 4K blocks.  So it is recommended that the implementation of the
  257. sender include "fall-back" and "step-up" block size logic.
  258.  
  259. A fall-back occurs after too many consecutive errors.  This causes subsequent
  260. data blocks to be sent out using the next smallest size block (i.e. from 4K
  261. down to 1K, and from 1K down to 128-bytes).  If the current block size is 4K,
  262. only two consecutive errors should be allowed before the sender falls back to
  263. 1K.  At 1K, three consecutive retries are allowed, and then 128-byte blocks
  264. are used.
  265.  
  266. A step-up occurs after a run of successful packets are sent, usually eight or
  267. more.  In a software implementation, this could be known by incrementing a
  268. counter each time a packet is successfully sent.  Should the receiver ever
  269. NAK a packet, the sender must reset this counter.
  270.  
  271. The sender must also maintain a variable that defines the largest block size
  272. allowed so that it cannot step-up to a size that the receiver is not prepared
  273. to handle.  In addition, consideration must be given to the exact moment when
  274. stepping up is done.  (This is described in the next section).
  275.  
  276. If a transfer is cancelled by too many consecutive errors, or by operator
  277. intervention, several <CAN> characters, five are adequate, should be sent to
  278. the other side, followed by an equal number of backspaces (08h) to clean up
  279. the display.
  280.  
  281.  
  282. 2.5:  Buffer Considerations
  283.  
  284. To handle a 4K packet, a receiver must allocate at least 4K of contiguous
  285. memory in which to store the data portion of the largest sized packet.
  286. However, since a mixture of 128-byte, 1K and 4K packets can be sent during
  287. the transfer, it is possible to overrun the end of the buffer.  Imagine that
  288. a 4K buffer is already 75% full and a 4K block is sent.  Since there is no
  289. way to know how large the next block will be until it starts coming in, it
  290. could easily wipe out information beyond the end of the buffer.
  291.  
  292. This situation can occur when a sender employs block size "step-up" logic.
  293. As a consideration to the receiver, the sender should never transmit a 4K
  294. block unless the amount sent so far is a multiple of 4096 (1000h), or zero.
  295. A simple way for the sender to handle this is by performing the step-up
  296. checking during its own 4K file buffer refresh sequence.  This will ensure
  297. that the receiver will be able to handle a step up to 4K without overrunning
  298. its packet buffer.
  299.  
  300. If the receiver detects a 4K packet coming in at an inconvenient time, the
  301. best way to handle it is to write the previously buffered blocks to disk, NAK
  302. the sender's 4K packet and prepare to receive it again into the empty buffer.
  303. This can severely degrade the performance of the transfer, but it should
  304. never occur if the sender's implementation is done properly.
  305.  
  306.  
  307. 2.6:  Longer Timeout Option
  308.  
  309. Timeout errors can occur frequently when transferring files with a
  310. packet-switched network.  A timeout happens when a certain amount of time
  311. passes and no activity has taken place.
  312.  
  313. Since standard XMODEM implements a one-second timeout during the reception of
  314. characters in the data block portion of a packet, the larger data block size
  315. could cause some delays with hosts that buffer outgoing data.  A host's
  316. buffering-related delay could cause the receiver to time out in mid-packet.
  317.  
  318. The programmer should allow the user to specify increased timeout durations.
  319. This should be employed during both sending and receiving so that
  320. transferring files over a network, such as Telenet or Tymnet, will result in
  321. fewer timeout errors.
  322.  
  323.  
  324.  
  325.  
  326.                          PART THREE: APPLE-SPECIFICS
  327.                          ===========================
  328.  
  329.  
  330.  
  331. 3.1:  ASCII Express "Pro" Extension
  332.  
  333. An adopted standard for transmitting files in the Apple world involves the
  334. exchange of a special packet of file information.  This resource information
  335. is external to the data included in the file and is stored in the file's
  336. directory entry.  Since standard XMODEM makes no provision for sending this
  337. extra but important information, the ASCII Express "Pro" (AE Pro) technique
  338. was developed by United Software Industries, Inc.  Documentation for this
  339. special extension to XMODEM is available from most information services or
  340. bulletin boards.
  341.  
  342.  
  343. 3.2  AE Pro Mode Compatibility
  344.  
  345. To maintain AE Pro compatibility with the extended CRC, 1K and 4K modes, the
  346. following guidelines apply:
  347.  
  348.   o   The initial AE Pro exchange is not made until the normal
  349.       sender/receiver handshaking is done to determine CRC or checksum,
  350.       and requested block sizes.
  351.  
  352.   o   The initial AE Pro packet is sent using these three bytes:
  353.       <SOH>+80h (81h), the Apple DOS 3.3 filetype byte (or 00h if
  354.       using ProDOS), and a complement byte of the filetype value
  355.       when exclusive-OR'd with $FF.
  356.  
  357. The rest of the transfer ensues as described in the AE Pro Extension
  358. reference.  When the AE Pro file information packet is sent at the end of a
  359. ProDOS-based transfer, it uses a 128-byte data block, and CRC-16 or checksum
  360. depending on how the transfer had been established.
  361.  
  362.  
  363.  
  364.  
  365.                                ACKnowledgments
  366.                                ===============
  367.  
  368. Special thanks to Don Elton for providing the proving grounds with his own
  369. terminal program for this new specification as it was being conceptualized.
  370. Thanks also to United Software Industries, Inc., for letting me develop this
  371. on their time (while getting paid, no less).
  372.  
  373.  
  374.                            Feedback and Line Noise
  375.                            =======================
  376.  
  377. Questions and comments about the 4K extension can be sent to:
  378.  
  379.     BIX:       mdavis
  380.     MCI Mail:  mdavis
  381.     AppleLink: mdavis
  382.     ProLine:   mdavis@pro-sol
  383.     UUCP:      crash!pnet01!pro-sol!mdavis
  384.     ARPANet:   crash!pnet01!mdavis@pro-sol.nosc.mil
  385.     InterNet:  mdavis@pro-sol.cts.com
  386.     US Mail:   Morgan Davis, PO Box 4313, La Mesa, California 92044
  387.     Modem BBS: pro-sol: 619/281-7222; Speeds: 9600, 2400, 1200, 300
  388.  
  389. Morgan developed the ModemWorks telecommunications language software and has
  390. used it to create ProLine, a world-wide, networked message and conferencing
  391. system.  He has also written several books on how to program Apple computers,
  392. his most recent being "Mastering the Apple IIGS Toolbox", and "Advanced
  393. Programming Techniques for the Apple IIGS Toolbox".  Currently, he is manager
  394. of product development at United Software Industries, an author of the
  395. MouseTalk terminal program, and a founder of Living Legends Software.  Morgan
  396. is also moderator of the Apple conference on the BYTE Information Exchange.
  397.