home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / protocol / kproto.mss < prev    next >
Text File  |  2020-01-01  |  201KB  |  4,421 lines

  1. @Comment(-*-SCRIBE-*-)
  2. @Comment(SCRIBE Text Formatter Input for the Kermit Protocol Manual)
  3.  
  4. @Make<Manual>
  5. @Comment(Use /draft:F on command line to produce .LPT file w/cc in column 1)
  6.  
  7. @Style<Justification On, Hyphenation On, WidestBlank 1.4, Spacing 1,
  8.         Spread 1, Indent 0, HyphenBreak Off>
  9. @PageHeading<Center "">
  10. @Modify<IndexEnv, Columns 2, ColumnMargin 0.5inch, LineWidth 3inch, Boxed>
  11.  
  12. @Comment(Set desired spacing around various environments)
  13.  
  14. @Modify<Quotation,Indentation 0, Above 1, Below 1, Spacing 1>
  15. @Modify<Example, Above 1, Below 1, Blanklines Hinge>
  16. @Modify<Verbatim, Leftmargin 0>
  17. @Modify<Itemize, Above 1, Below 1, Spacing 1, Spread 1>
  18. @Modify<Enumerate, Above 1, Below 1, Spacing 1, Spread 1>
  19. @Modify<Description, Above 1, Below 1, Spacing 1>
  20.  
  21. @Comment(Printing Device Dependencies)
  22.  
  23. @Define<Q,FaceCode R>
  24. @Define<UU,use UX,need 6>
  25. @define<xx,use b>
  26. @define<yy,use i>
  27. @Case<Device,
  28.  LPT="@use(Auxfile='PROTLP.AUX')
  29.     @Case[Draft,F=`@Style(CarriageControl=FORTRAN)']
  30.     @Style(linewidth 79)",
  31.  Printronix="@use(AuxFile='PROTPX.AUX')
  32.     @Case[Draft,F=`@Style(CarriageControl=FORTRAN)']
  33.     @Style(LineWidth 74, PaperLength 11 inches,BottomMargin 5 spacings)",
  34.  PagedFile="@use(AuxFile='PROTPF.AUX')
  35.     @Style(LineWidth 79, PaperLength 10.8 inches)
  36.     @Style(TopMargin 3 spacings,BottomMargin 6 Spacings)
  37.     @Modify(Example,Leftmargin +2)",
  38.  Diablo="@Use(Auxfile='KPRDIA.AUX')
  39.     @TypeWheel(Titan 10)",
  40.  Postscript="@Use(Auxfile='KPRPS.AUX')
  41. @comment(    [at]Style<Doublesided> )
  42.     @Style<Fontscale 10>
  43.     @Define<xx,use b,Size 12>
  44.     @Define<yy,use i,Size 10>
  45.     @Define<Q,FaceCode T>
  46.     @Define(QQ,FaceCode T,AfterEntry=[@r<``>],BeforeExit=[@r<''>])
  47.     @Define<SubH,Use Display,FaceCode B,Above 1.6,Below 1>
  48.     @Modify<Quotation,Size +0>
  49.     @Modify<Itemize,Spread 0.8>",
  50.  Imprint10="@Use(AuxFile='KPRIMP.AUX')
  51.     @Define<Q,FaceCode U>
  52.     @Modify<Insert,Spacing 1>
  53.     @Modify<Verbatim,FaceCode U>
  54.     @Modify<Example,FaceCode U,spacing 1.2>
  55.     @Modify<Itemize,Spread 0.8>
  56.     @Style<FontFamily SmallRoman12,Spacing 1.6,SingleSided>",
  57.  Imagen300="@Use(AuxFile='KPRIMP.AUX')
  58.     @Define<Q,FaceCode U>
  59.     @Modify<Insert,Spacing 1>
  60.     @Modify<Verbatim,FaceCode U>
  61.     @Modify<Example,FaceCode U,spacing 1.2>
  62.     @Modify<Itemize,Spread 0.8>
  63.     @Style<FontFamily SmallRoman12,Spacing 1.6,SingleSided>",
  64.  X9700="@Use<AuxFile='KPRTX9.AUX'>
  65.     @Style<FontFamily Univers10, DoubleSided, Spacing 1.2>
  66.     @Define<Q,FaceCode U>
  67.     @Modify<Description,Spacing 0.8,Spread 0.75> 
  68.     @Modify<Quotation,Spacing 0.8,Spread 0.75> 
  69.     @Modify<Enumerate,Spacing 0.8,Spread 0.75> 
  70.     @Modify(Verbatim,Spacing 0.8,Spread 0.75,FaceCode U)
  71.     @Modify<Example,FaceCode U, Spacing 1.1>
  72.     @Modify[Itemize, Numbered < @,- >, Spacing 0.8, Spread 0.5]"
  73.  >
  74. @Comment(Set spacing and paging requirements for chapter & section headings)
  75.  
  76. @Modify(Hdx,Above 2,Below 1,Need 8)
  77. @Modify(Hd0,Above 2,Below 1,Need 8)
  78. @Modify(Hd2,Above 2,Below 1,Need 8)
  79. @Modify(Hd3,Above 2,Below 1,Need 8)
  80. @Modify(Hd4,Above 2,Below 1,Need 8)
  81. @Modify<Heading, Above 2, Need 8>
  82. @Modify<Subheading, Above 1.5, Need 6>
  83.  
  84. @Comment(Start the document off with a titlepage)
  85.  
  86. @Begin(TitlePage,Initialize "@BlankSpace(2.5inches)",sink 0)
  87. @MajorHeading(KERMIT PROTOCOL MANUAL)
  88.  
  89. @i<Sixth Edition>
  90.  
  91.  
  92.  
  93. Frank da Cruz
  94.  
  95. Columbia University Center for Computing Activities
  96. New York, New York  10027
  97.  
  98.  
  99. June 1986
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. Copyright (C) 1981,1986
  107. Trustees of Columbia University in the City of New York
  108.  
  109. @i<Permission is granted to any individual or institution to copy or
  110. use this document, except for explicitly commercial purposes.>
  111. @case[device, x9700 "@blankpage(1)"]
  112. @end<titlepage>
  113. @PageHeading(
  114.    Right="@yy<Page @ref(page)>",
  115.    Left="@xx<Kermit Protocol Manual>",
  116.    Line="@bar()@blankspace(2)")
  117. @set(page=1)
  118.  
  119. @Heading<Preface to the Sixth Edition>
  120.  
  121. The sixth edition (June 1986) of the @i<Kermit Protocol Manual> is being issued
  122. for two major reasons: to correct minor errors in the fifth edition, and to
  123. include new sections on two major protocol extensions: long packets and sliding
  124. windows.  No attempt has been made to reorganize, rewrite, or otherwise improve
  125. the protocol manual.  The Kermit protocol has been presented in an entirely
  126. different -- hopefully more thorough, organized, coherent, and useful (if not
  127. more formal) -- manner in the book,
  128. @case[device,file={"Kermit, A File Transfer Protocol," },
  129.     pagedfile={"Kermit, A File Transfer Protocol," },
  130.     else={@i<Kermit, A File Transfer Protocol>, }]
  131. by Frank @w<da Cruz>, Digital Press, Bedford MA (1987), ISBN
  132. @w<0-932376-88-6>, DEC order number @w<EY-6705E-DP>.  If you have the book, you
  133. won't need this protocol manual.  On the other hand, if you don't have the
  134. book, this manual should still contain all the necessary information.  The
  135. @i<Kermit Protocol Manual> will continue to be freely distributed in
  136. perpetuity.
  137.  
  138. The bare-bones C-language Kermit program that appeared as an appendix in
  139. previous editions has been removed.  It was not a particularly good example of
  140. how to write a Kermit program, and made the manual unnecessarily thick.  For
  141. sample Kermit programs, see the source code for any of the hundreds of Kermit
  142. implementations, or follow the program fragments in the book.
  143.  
  144. @Heading<Preface to the Fifth Edition>
  145.  
  146. The fifth edition (March 1984) attempts to clarify some fine points that had
  147. been left ambiguous in the 4th edition, particularly with respect to when and
  148. how prefix encoding is done, and when it is not, and about switching between
  149. block check types.  A mechanism is suggested (in the Attributes section) for
  150. file archiving, and several attributes have been rearranged and some others
  151. added (this should do no harm, since no one to date has attempted to implement
  152. the attributes packet).  A more complete protocol state table is provided, a
  153. few minor additions are made to the collection of packet types.
  154.  
  155. @Heading<Preface to the Fourth Edition>
  156.  
  157. The fourth edition (November 1983) of the Kermit Protocol Manual incorporates
  158. some new ideas that grew from our experience in attempting to implement some of
  159. the features described in earlier editions, particularly user/@|server
  160. functions.  These include a mechanism to allow batch transfers to be
  161. interrupted gracefully for either the current file or the entire batch of
  162. files; a "capability mask"; a protocol extension for passing file attributes.
  163. In addition, numbers are now written in decimal notation rather than octal,
  164. which was confusing to many readers.  Also, several incompatible changes were
  165. made in minor areas where no attempts at an implementation had yet been made;
  166. these include:
  167. @Begin(Itemize,spread 0.5)
  168. The format and interpretation of the operands to the server commands.
  169.  
  170. Usurpation of the reserved fields 10-11 of the Send-Init packet, and addition
  171. of new reserved fields.
  172. @End(Itemize)
  173. Most of the remaining material has been rewritten and reorganized, and much new
  174. material added, including a section on the recommended vocabulary for
  175. documentation and commands.
  176.  
  177. The previous edition of the Protocol Manual attempted to define "protocol
  178. version 3"; this edition abandons that concept.  Since Kermit development is
  179. an unorganized, disorderly, distributed enterprise, no requirement can be
  180. imposed on Kermit implementors to include a certain set of capabilities in
  181. their implementations.  Rather, in this edition we attempt to define the basic
  182. functionality of Kermit, and then describe various optional functions.
  183.  
  184. The key principle is that any implementation of Kermit should work with any
  185. other, no matter how advanced the one or how primitive the other.  The
  186. capability mask and other Send-Init fields attempt to promote this principle.
  187.  
  188.  
  189. @Heading<Acknowledgements> 
  190.  
  191. Bill Catchings and I designed the basic Kermit protocol at Columbia University
  192. in 1981.  For ideas, we looked at some of the ANSI models (X3.57, X3.66), the
  193. ISO OSI model, some real-@|world "asynchronous protocols" (including the
  194. Stanford Dialnet and TTYFTP projects, the University of Utah Small FTP
  195. project), as well as at file transfer on full-@|blown networks like DECnet and
  196. ARPAnet.
  197.  
  198. Bill wrote the first two programs to implement the protocol, one for the
  199. DEC-20, one for a CP/M-80 microcomputer, and in the process worked out most of
  200. the details and heuristics required for basic file transfer.  Meanwhile, Daphne
  201. Tzoar and Vace Kundakci, also of Columbia, worked out the additional details
  202. necessary for IBM mainframe communication, while writing IBM VM/CMS and PC-DOS
  203. versions.
  204.  
  205. Much credit should also go to Bernie Eiben of Digital Equipment Corporation for
  206. promoting widespread use of Kermit and for adding many insights into how it
  207. should operate, to Nick Bush and Bob McQueen of Stevens Institute of
  208. Technology, for many contributions to the "advanced" parts of the protocol, and
  209. for several major Kermit implementations, and to Leslie Spira and her group
  210. at The Source Telecomputing for adding full-duplex sliding window capability
  211. to the Kermit protocol.
  212.  
  213. Thanks to the many people all over the world who have contributed new
  214. Kermit implementations, who have helped with Kermit distribution through
  215. various user groups, and who have contributed to the quality of the protocol
  216. and its many implementations by reporting or fixing problems, criticizing the
  217. design, or suggesting new features.   In particular, thanks to Ted Toal of
  218. Nevada City, CA, for a detailed list of corrections to the fifth edition of
  219. this manual.
  220.  
  221. And above all, thanks to Christine Gianone for taking charge of Kermit at
  222. Columbia; for keeping it alive, healthy, and strong; for promoting its
  223. development and use all over the world; for setting its tone and direction; for
  224. fostering its spirit.  Without her guidance and perserverance, Kermit might
  225. have faded from the scene years ago.
  226.  
  227. The Kermit protocol was named after Kermit the Frog, star of the television
  228. series THE MUPPET SHOW.  The name is used by permission of Henson Associates,
  229. Inc., New York City.
  230.  
  231. @Heading<Disclaimer>
  232.  
  233. @i<No warranty of the software nor of the accuracy of the documentation
  234. surrounding it is expressed or implied, and neither the authors nor Columbia
  235. University acknowledge any liability resulting from program or documentation
  236. errors.>
  237.  
  238. @Chapter<Introduction>
  239.  
  240. This manual describes the @Index[Kermit] Kermit @Index[Protocol]
  241. protocol.  It is assumed that you understand the purpose and operation of the
  242. Kermit file transfer facility, described in the @i<Kermit Users Guide>, and
  243. basic terminology of data communications and computer programming.
  244.  
  245. @Section<Background>
  246.  
  247. The Kermit file transfer protocol is intended for use in an environment where
  248. there may be a diverse mixture of computers -- micros, personal computers,
  249. workstations, laboratory computers, timesharing systems -- from a variety of
  250. manufacturers.  All these systems need have in common is the ability to
  251. communicate in ASCII over ordinary serial telecommunication lines.
  252.  
  253. Kermit was originally designed at Columbia University to meet the need for file
  254. transfer between our DECSYSTEM-20 and IBM 370-@|series mainframes and various
  255. microcomputers.  It turned out that the diverse characteristics of these three
  256. kinds of systems resulted in a design that was general enough to fit almost any
  257. system.  The IBM mainframe, in particular, strains most common assumptions
  258. about how computers communicate.
  259.  
  260. @Section<Overview>
  261.  
  262. The Kermit protocol is specifically designed for character-@|oriented
  263. transmission over serial telecommunication lines.  The design allows for the
  264. restrictions and peculiarities of the medium and the requirements of diverse
  265. operating environments -- buffering, duplex, parity, character set, file
  266. organization, etc.  The protocol is carried out by Kermit programs on each end
  267. of the serial connection sending "packets" back and forth; the sender sends
  268. file names, file contents, and control information; the receiver acknowledges
  269. (positively or negatively) each packet.
  270.  
  271. The packets have a layered design, more or less in keeping with the ANSI and
  272. ISO philosophies, with the outermost fields used by the data link layer to
  273. verify data integrity, the next by the session layer to verify continuity, and
  274. the data itself at the application level.
  275.  
  276. Connections between systems are established by the ordinary user.  In a typical
  277. case, the user runs Kermit on a microcomputer, enters terminal emulation,
  278. connects to a remote host computer (perhaps by dialing up), logs in, runs
  279. Kermit on the remote host, and then issues commands to that Kermit to start
  280. a file transfer, "escapes" back to the micro, and issues commands to that
  281. Kermit to start its side of the file transfer.  Files may be transferred singly
  282. or in groups.
  283.  
  284. Basic Kermit provides only file transfer, and that is provided for
  285. @i<sequential files only>@index(Sequential Files), though the protocol attempts
  286. to allow for various types of sequential files.  Microcomputer implementations
  287. of Kermit are also expected to provide terminal emulation, to facilitate the
  288. initial connection.
  289.  
  290. More advanced implementations simplify the "user interface" somewhat by
  291. allowing the Kermit on the remote host to run as a "server", which can transfer
  292. files in either direction upon command from the local "user" Kermit.  The
  293. server can also provide additional functionality, such as file management,
  294. messages, mail, and so forth.  Other optional features also exist, including a
  295. variety of block check types, a mechanism for passing 8-bit data through a
  296. 7-bit communication link, a way to compressing a repeated sequence of
  297. characters, and so forth.
  298.  
  299. As local area networks become more popular, inexpensive, and standardized, the
  300. demand for Kermit and similar protocols may dwindle, but will never wither away
  301. entirely.  Unlike hardwired networks, Kermit gives the ordinary user the power
  302. to establish reliable error-@|free connections between @i<any two> computers;
  303. this may always be necessary for one-@|shot or long-@|haul connections.
  304.  
  305. @Section<General Terminology>
  306.  
  307. @Index<TTY>
  308. @u<TTY>: This is the term commonly used for a device which is connected to a
  309. computer over an EIA RS-232 serial telecommunication line.  This device is most
  310. commonly an ASCII terminal, but it may be a microcomputer or even a large
  311. multi-@|user computer emulating an ASCII terminal.  Most computers provide
  312. hardware (RS-232 connectors and UARTs) and software (device drivers) to support
  313. TTY connections; this is what makes TTY-@|oriented file transfer protocols
  314. like Kermit possible on almost any system at little or no cost.
  315.  
  316. @Index[Local]
  317. @u<LOCAL>: When two machines are connected, the LOCAL machine is the one which
  318. you interact with directly, and which is in control of the terminal.  The
  319. "local Kermit" is the one that runs on the local machine.  A local Kermit
  320. always communicates over an external device (the micro's communication port, an
  321. assigned TTY line, etc).
  322.  
  323. @index<Remote>
  324. @u<REMOTE>: The REMOTE machine is the one on the far side of the connection,
  325. which you must interact with "through" the local machine.  The "remote Kermit"
  326. runs on the remote machine.  A remote Kermit usually communicates over its own
  327. "console", "controlling terminal", or "standard i/o" device.
  328.  
  329. @index<Host>
  330. @u<HOST>: Another word for "computer", usually meaning a computer that can
  331. provide a home for multiple users or applications.  This term should be avoided
  332. in Kermit lore, unless preceded immediately by LOCAL or REMOTE, to denote which
  333. host is meant.
  334.  
  335. @index<Server>
  336. @u<SERVER>: An implementation of remote Kermit that can accept commands in
  337. packet form from a local Kermit program, instead of directly from the user.
  338.  
  339. @index<User>
  340. @u<USER>: In addition to its usual use to denote the person using a system or
  341. program, "user" will also be used refer to the local Kermit program, when the
  342. remote Kermit is a server.
  343.  
  344. @Section<Numbers>
  345.  
  346. All @u<numbers> in the following text are expressed in decimal
  347. (base 10) notation unless otherwise specified.   
  348.  
  349. @Index<Bit Positions>
  350. Numbers are also referred to in terms of their bit positions in a computer
  351. word.  Since Kermit may be implemented on computers with various word sizes, we
  352. start numbering the bits from the "right" -- bit 0 is the least significant.
  353. Bits 0-5 are the 6 least significant bits; if they were all set to one, the
  354. value would be 63.
  355.  
  356. @Index<8th Bit>
  357. A special quirk in terminology, however, refers to the high order bit of a
  358. character as it is transmitted on the communication line, as the "8th bit".
  359. More properly, it is bit 7, since we start counting from 0.  References to the
  360. "8th bit" generally are with regard to that bit which ASCII transmission sets
  361. aside for use as a parity bit.  Kermit concerns itself with whether this bit
  362. can be usurped for the transmission of data, and if not, it may resort to
  363. "8th-bit prefixing".
  364.  
  365. @Section<Character Set>
  366.  
  367. All @u<characters> are in ASCII @index<ASCII> (American national Standard Code
  368. for Information Interchange) representation, ANSI standard X3.4-1968.  All
  369. implementations of Kermit transmit and receive characters only in ASCII.  The
  370. ASCII character set is listed in Appendix @ref<-ascii>.
  371.  
  372. @ux<ASCII character mnemonics:>
  373.  @Begin<Description,Spread 0,leftmargin +8,indent -8>
  374. NUL@\Null, idle, ASCII character 0.
  375.  
  376. SOH@\Start-of-header, ASCII character 1 (Control-A).
  377.  
  378. SP@\Space, blank, ASCII 32.
  379.  
  380. CR@\Carriage return, ASCII 13 (Control-M).
  381.  
  382. LF@\Linefeed, ASCII 10 (Control-J).
  383.  
  384. CRLF@\A carriage-@|return linefeed sequence.
  385.  
  386. DEL@\Delete, rubout, ASCII 127.
  387. @end<description>
  388.  
  389. @Index<Control Character>
  390. A @ux<control character> is considered to be any byte whose low order 7 bits
  391. are in the range 0 through 31, or equal to 127.  In this document,
  392. control characters are written in several ways:
  393. @Begin(Description,leftmargin +8,indent -8)
  394. Control-A@\This denotes ASCII character 1, commonly referred to as "Control-A".
  395. Control-B is ASCII character 2, and so forth.
  396.  
  397. CTRL-A@\This is a common abbreviation for "Control-A".  A control character is
  398. generally typed at a computer terminal by holding down the key marked CTRL and
  399. pressing the corresponding alphabetic character, in this case "A".
  400.  
  401. @q<^A>@\"Uparrow" notation for CTRL-A.  Many computer systems "echo" control
  402. characters in this fashion.
  403. @End(Description) 
  404.  
  405. A @ux<printable ASCII character> is considered to be any character in the
  406. range 32 (SP) through 126 (tilde).
  407.  
  408. @Section<Conversion Functions>
  409.  
  410. Several conversion functions are useful in the description of the protocol
  411. and in the program example.  The machine that Kermit runs on need operate only
  412. on integer data; these are functions that operate upon the numeric value of
  413. single ASCII characters.
  414.  @begin<description,leftmargin +4,indent -4>
  415. @Index[tochar(x)]
  416. @q<tochar(x) = x+32>@\Transforms the integer @i<x>, which is assumed to lie in
  417. the range 0 to 94, into a printable ASCII character; 0 becomes SP, 1 becomes
  418. "@q<!>", 3 becomes "@q<#>", etc.
  419.  
  420. @Index[unchar(x)]
  421. @q<unchar(x) = x-32>@\Transforms the character @i<x>, which is assumed to be in
  422. the printable range (SP through tilde), into an integer in the range 0 to 94.
  423.  
  424. @Index[ctl(x)]
  425.  @q<ctl(x) = x XOR 64>@\Maps between control characters and their printable
  426. representations, preserving the high-@|order bit.  If @i<x> is a control
  427. character, then
  428.  @example<x = ctl(ctl(x))>
  429.  that is, the same function is used to controllify and uncontrollify.  The
  430. argument is assumed to be a true control character (0 to 31, or 127), or the
  431. result of applying @c<ctl> to a true control character (i.e. 63 to 95).  The
  432. transformation is a mnemonic one -- @q(^A) becomes A and vice versa.
  433. @end<description>
  434.  
  435. @Section<Protocol Jargon>
  436.  
  437. @Index[Packet]
  438. A @u<Packet> is a clearly delimited string of characters, comprised of "control
  439. fields" nested around data; the control fields allow a Kermit program to
  440. determine whether the data has been transmitted correctly and completely.
  441. A packet is the unit of transmission in the Kermit protocol.
  442.  
  443. @Index[ACK]
  444. @u<ACK> stands for "Acknowledge".  An ACK is a packet that is sent to
  445. acknowledge receipt of another packet.  Not to be confused with the ASCII
  446. character ACK.
  447.  
  448. @Index[NAK]
  449. @u<NAK> stands for "Negative Acknowledge".  A NAK is a packet sent to say that
  450. a corrupted or incomplete packet was received, the wrong packet was received,
  451. or an expected packet was not received.  Not to be confused with the ASCII
  452. character NAK.
  453.  
  454. @Index<Timeout>
  455. A @u<timeout> is an event that can occur if expected data does not arrive
  456. within a specified amount of time.  The program generating the input request
  457. can set a "timer interrupt" to break it out of a nonresponsive read, so that
  458. recovery procedures may be activated.
  459.  
  460. @Chapter<Environment>
  461.  
  462. @section<System Requirements>
  463.  
  464. The Kermit protocol requires that@q<:>
  465. @begin<itemize>
  466. The host can send and receive characters using 7- or 8-bit ASCII encoding over
  467. an EIA RS-232 physical connection, either hardwired or dialup.
  468.  
  469. All printable ASCII characters are acceptable as input to the host and will not
  470. be transformed in any way@foot<If they are translated to another character set,
  471. like EBCDIC@index(EBCDIC), the Kermit program must be able to reconstruct the
  472. packet as it appeared on the communication line, before transformation.>.
  473. Similarly, any intervening network or communications equipment ("smart modems",
  474. TELENET, terminal concentrators, port selectors, etc) must not transform or
  475. swallow any printable ASCII characters.
  476.  
  477. @index<SOH>
  478. A single ASCII @i<control character> can pass from one system to the other
  479. without transformation.  This character is used for packet synchronization.
  480. The character is normally Control-A (SOH, ASCII 1), but can be redefined.
  481.  
  482. @IndexEntry[Key="Line Terminator (see End-Of-Line)",
  483.   Text="Line Terminator (see End-Of-Line)"]
  484. @Index[End-Of-Line (EOL)]
  485. If a host requires a line terminator for terminal input, that terminator
  486. must be a single ASCII control character, such as CR or LF, distinct from the
  487. packet synchronization character.
  488.  
  489. @Index[Remote]@Index[Binary Mode]@Index[Raw Mode]
  490.  When using a job's controlling terminal for file transfer, the system must
  491. allow the Kermit program to set the terminal to no echo, infinite width (no
  492. "wraparound" or CRLF insertion by the operating system), and no "formatting" of
  493. incoming or outgoing characters (for instance, raising lowercase letters to
  494. uppercase, transforming control characters to printable sequences, etc).  In
  495. short, the terminal must be put in "binary" or "raw" mode, and, hopefully,
  496. restored afterwards to normal operation.
  497.  
  498. The host's terminal input processor should be capable of receiving a single
  499. burst of 40 to 100 characters at normal transmission speeds.  This is the
  500. typical size of packet.
  501. @end<itemize>
  502. Note that most of these requirements rule out the use of Kermit through
  503. IBM 3270 / ASCII protocol converters, except those (like the Series/1
  504. or 7171 running the Yale ASCII package) that can be put in "transparant mode."
  505.  
  506. Kermit does @i<not> require:
  507. @begin<itemize>
  508. @Index<Baud>
  509. That the connection run at any particular baud rate.
  510.  
  511. @index<Flow Control>
  512. That the system can do @Index[XON/XOFF] XON/XOFF or any other kind of flow
  513. control.  System- or hardware-@|level flow control can help, but it's not
  514. necessary.  See section @ref<-flow>.
  515.  
  516. @Index[Duplex]@Index[Full Duplex]@Index[Half Duplex]
  517. That the system is capable of full duplex operation.  Any mixture of half and
  518. full duplex systems is supported.
  519.  
  520. @Index<Binary Files>
  521. That the system can transmit or receive 8-bit bytes.  Kermit will take
  522. advantage of 8-bit connections to send binary files; if an 8-bit connection is
  523. not possible, then binary files may be sent using an optional prefix encoding.
  524.  @end<itemize>
  525.  
  526. @section<Printable Text versus Binary Data>
  527.  
  528. @Index[Records]@Index[Logical Records] @Index[Printable Files]
  529. @Index[Binary Files] @Index[Text Files]
  530. For transmission between unlike systems, files must be assigned to
  531. either of two catagories: @i<printable text> or @i<binary>.
  532.  
  533. A printable text file is one that can make sense on an unlike system -- a
  534. document, program source, textual data, etc.  A binary file is one that will
  535. not (and probably can not) make sense on an unlike system -- an executable
  536. program, numbers stored in internal format, etc.  On systems with 8-bit bytes,
  537. printable ASCII files will have the high order bit of each byte set to
  538. zero@foot<There are some exceptions, such as systems that store text files in
  539. so-@|called "negative ASCII", or text files produced by word processors that
  540. use the high order bit to indicate underline or boldface attributes.>
  541. (since ASCII is a 7-bit code) whereas binary files will use the high order bit
  542. of each byte for data, in which case its value can vary from byte to byte.
  543.  
  544. Many computers have no way to distinguish a printable file from a binary file
  545. -- especially one originating from an unlike system -- so the user may have to
  546. give an explicit command to Kermit to tell it whether to perform these
  547. conversions.
  548.  
  549. @subSection<Printable Text Files>
  550.  
  551. @index<Text Files>@index<EBCDIC>@index<ASCII>@index<Logical Record>
  552. A primary goal of Kermit is for printable text files to be useful on the target
  553. system after transfer.  This requires a standard representation for text during
  554. transmission.  Kermit's standard is simple: 7-bit ASCII characters, with
  555. "logical records" (lines) delimited by CRLFs.  It is the responsibility of
  556. systems that do not store printable files in this fashion to perform the
  557. necessary conversions upon input and output.  For instance, IBM mainframes
  558. might strip trailing blanks on output and add them back on input; UNIX would
  559. prepend a CR to its normal record terminator, LF, upon output and discard it
  560. upon input.  In addition, IBM mainframes must do EBCDIC/@|ASCII translation for
  561. text files.
  562.  
  563. @index<Tab Expansion>
  564. No other conversions (e.g. tab expansion) are performed upon text files.  This
  565. representation is chosen because it corresponds to the way text files are
  566. stored on most microcomputers and on many other systems.  In many common cases,
  567. no transformations are necessary at all.
  568.  
  569. @subSection<Binary Files>
  570.  
  571. @index<Binary Files>
  572. Binary files are transmitted as though they were a sequence of characters.  The
  573. difference from printable files is that the status of the "8th bit" must be
  574. preserved.  When binary files are transmitted to an unlike system, the main
  575. objective is that they can be brought back to the original system (or one like
  576. it) intact; no special conversions should be done during transmission, except
  577. to make the data fit the transmission medium.
  578.  
  579. For binary files, eight bit character transmission is permissible as long as
  580. the two Kermit programs involved can control the value of the parity bit, and
  581. no intervening communications equipment will change its value.  In that case,
  582. the 8th bit of a transmitted character will match that of the original data
  583. byte, after any control-@|prefixing has been done.  When one or both sides
  584. cannot control the parity bit, a special prefix character may be inserted, as
  585. described below.
  586.  
  587. Systems that do not store binary data in 8-bit bytes, or whose word size is not
  588. a multiple of 8, may make special provisions for "image mode" transfer of
  589. binary files.  This may be done within the basic protocol by having the two
  590. sides implicitly agree upon a scheme for packing the data into 7-
  591. or 8-bit ASCII characters, or else the more flexible (but optional) file
  592. attributes feature may be used.  The former method is used on PDP-10 36-bit
  593. word machines, in which text is stored five 7-bit bytes per word; the value of
  594. the "odd bit" is sent as the parity bit of every 5th word.
  595.  
  596. @Chapter<File Transfer>
  597.  
  598. @Index<Transaction>
  599. The file transfer protocol takes place over a @i<transaction>.  A
  600. transaction@index<Transaction> is an exchange of packets beginning with a
  601. Send-Init (S) packet, and ending with a Break Transmission (B) or Error (E)
  602. packet@foot<A transaction should also be considered terminated when one side or
  603. the other has stopped without sending an Error packet.>, and may include the
  604. transfer of one or more files, all in the same direction.  In order to minimize
  605. the unforseen, Kermit packets do not contain any control characters except one
  606. specially designated to mark the beginning of a packet.  Except for the packet
  607. marker, only printable characters are transmitted.
  608. The following
  609. sequence characterizes basic Kermit operation; the @i<sender> is the machine
  610. that is sending files; the @i<receiver> is the machine receiving the files.
  611. @Begin(Enumerate)
  612. The sender transmits a Send-@|Initiate (S) packet to specify
  613. its parameters (packet length, timeout, etc; these are explained below).
  614.  
  615. The receiver sends an ACK (Y) packet, with its own parameters in the data
  616. field.
  617.  
  618. The sender transmits a File-Header (F) packet, which contains the file's name
  619. in the data field.  The receiver ACKs the F packet, with no data in the data
  620. field of the ACK (optionally, it may contain the name under which the receiver
  621. will store the file).
  622. @tag(-fpacket)
  623.  
  624. The sender sends the contents of the file, in Data (D) packets.  Any data not
  625. in the printable range is prefixed and replaced by a printable equivalent.
  626. Each D packet is acknowledged before the next one is sent.
  627.  
  628. When all the file data has been sent, the sender sends an End-@|Of-@|File (Z)
  629. packet.  The receiver ACKs it.
  630.  
  631. If there is another file to send, the process is repeated beginning at step
  632. @ref<-fpacket>.
  633.  
  634. When no more files remain to be sent, the sender transmits an
  635. End-@|Of-@|Transmission (B) packet.  The receiver ACKs it.  This ends the
  636. transaction, and closes the logical connection (the physical connection remains
  637. open).
  638. @end<enumerate>
  639. @index<Sequence Number>
  640. Each packet has a @i<sequence number>, starting with 0 for the Send Init.  The
  641. acknowledgment (ACK or NAK) for a packet has the same packet number as the
  642. packet being acknowledged.  Once an acknowledgment is successfully received
  643. the packet number is increased by one, modulo 64.
  644.  
  645. If the sender is remote, it waits for a certain amount of time (somewhere in
  646. the 5-30 second range) before transmitting the Send-Init, to give the user time
  647. to escape back to the local Kermit and tell it to receive files.
  648.  
  649. Each transaction starts fresh, as if no previous transaction had taken place.
  650. For example, the sequence number is set back to zero, and parameters are
  651. reset to their default or user-selected values.
  652.  
  653. @section<Conditioning the Terminal>
  654.  
  655. Kermit is most commonly run with the user sitting at a microcomputer, connected
  656. through a communications port to a remote timesharing system.  The remote
  657. Kermit is using its job's own "controlling terminal" for file transfer.  While
  658. the microcomputer's port is an ordinary device, a timesharing job's controlling
  659. terminal is a special one, and often performs many services that would
  660. interfere with normal operation of Kermit.  Such services include echoing (on
  661. full duplex systems), wrapping lines by inserting carriage return linefeed
  662. sequences at the terminal width, pausing at the end of a screen or page full of
  663. text, displaying system messages, alphabetic case conversion, control character
  664. intepretation, and so forth.  Mainframe Kermit programs should be prepared to
  665. disable as many of these services as possible before packet communication
  666. begins, and to restore them to their original condition at the end of a
  667. transaction.  Disabling these services is usually known as "putting the
  668. terminal in binary mode."
  669.  
  670. Kermit's use of printable control character equivalents, variable packet
  671. lengths, redefinable markers and prefixes, and allowance for any characters at
  672. all to appear between packets with no adverse effects provide a great deal of
  673. adaptability for those systems that do not allow certain (or any) of these
  674. features to be disabled.
  675.  
  676. @Section<Timeouts, NAKs, and Retries>
  677.  
  678. If a Kermit program is capable of setting a timer interrupt, or setting a time
  679. limit on an input request, it should do so whenever attempting to read a packet
  680. from the communication line, whether sending or receiving files.
  681. Having read a packet, it should turn off the timer.
  682.  
  683. If the sender times out waiting for an acknowledgement, it should send the same
  684. packet again, repeating the process a certain number of times up to a retry
  685. limit, or until an acknowledgement is received.  If the receiver times out
  686. waiting for a packet, it can send either a NAK packet for the expected packet
  687. or another ACK for the last packet it got.  The latter is preferred.
  688.  
  689. If a packet from the sender is garbled or lost in transmission (the latter is
  690. detected by a timeout, the former by a bad checksum), the receiver sends a NAK
  691. for the garbled or missing packet.  If an ACK or a NAK from the receiver is
  692. garbled or lost, the sender ignores it; in that case, one side or the other
  693. will time out and retransmit.
  694.  
  695. A retry count is maintained, and there is a retry threshold, normally set
  696. around 5.  Whenever a packet is resent -- because of a timeout, or because it
  697. was NAK'd -- the counter is incremented.  When it reaches the threshold, the
  698. transaction is terminated and the counter reset.
  699.  
  700. If neither side is capable of timing out, a facility for manual intervention
  701. must be available on the local Kermit.  Typically, this will work by sampling
  702. the keyboard (console) periodically; if input, such as a CR, appears, then the
  703. same action is taken as if a timeout had occurred.  The local Kermit keeps a
  704. running display of the packet number or byte count on the screen to allow the
  705. user to detect when traffic has stopped.  At this point, manual intervention
  706. should break the deadlock.
  707.  
  708. Shared systems which can become sluggish when heavily used should adjust their
  709. own timeout intervals on a per-@|packet basis, based on the system load, so
  710. that file transfers won't fail simply because the system was too slow.
  711.  
  712. Normally, only one side should be doing timeouts, preferably the side with the
  713. greatest knowledge of the "environment" -- system load, baud rate, and so
  714. forth, so as to optimally adjust the timeout interval for each packet.  If both
  715. sides are timing out, their intervals should differ sufficiently to minimize
  716. collisions.
  717.  
  718. @section<Errors>
  719.  
  720. @Index<Errors>@Index<Fatal Errors>
  721. During file transfer, the sender may encounter an i/o error on the disk, or the
  722. receiver may attempt to write to a full or write-@|protected device.  Any
  723. condition that will prevent successful transmission of the file is called a
  724. "fatal error".  Fatal errors should be detected, and the transfer shut down
  725. gracefully, with the pertinent information provided to the user.  Error packets
  726. provide a mechanism to do this.
  727.  
  728. If a fatal error takes place on either the sending or receiving side, the side
  729. which encountered the error should send an Error (E) packet.  The E packet
  730. contains a brief textual error message in the data field.  Both the sender and
  731. receiver should be prepared to receive an Error packet at any time during the
  732. transaction.  Both the sender and receiver of the Error packet should halt, or
  733. go back into into user command mode (a server should return to server command
  734. wait).  The side that is local should print the error message on the screen.
  735.  
  736. There is no provision for sending nonfatal error messages, warnings, or
  737. information messages during a transaction.  It would be possible to add such a
  738. feature, but this would require both sides agree to use it through setting of a
  739. bit in the capability mask, since older Kermits that did not know about such a
  740. feature would encounter an unexpected packet type and would enter the fatal
  741. error state.  In any case, the utility of such a feature is questionable, since
  742. there is no guarantee that the user will be present to see such messages at the
  743. time they are sent; even if they are saved up for later perusal in a "message
  744. box", their significance may be long past by the time the user reads them.
  745. See the section on Robustness, below.
  746.  
  747. @section<Heuristics>
  748.  
  749. During any transaction, several heuristics are useful:
  750. @begin<enumerate>
  751. A NAK for the current packet is equivalent to an ACK for the previous packet
  752. (modulo 64).  This handles the common situation in which a packet is
  753. successfully received, and then ACK'd, but the ACK is lost.  The ACKing side
  754. then times out waiting for the next packet and NAKs it.  The side that receives
  755. a NAK for packet @i<n+1> while waiting for an ACK for packet @i<n> simply sends
  756. packet @i<n+1>.
  757.  
  758. If packet @i<n> arrives more than once, simply ACK it and discard it.  This
  759. can happen when the first ACK was lost.  Resending the ACK is necessary @i<and>
  760. sufficient -- don't write the packet out to the file again!
  761.  
  762. When opening a connection, discard the contents of the line's input buffer
  763. before reading or sending the first packet.  This is especially important if
  764. the other side is in receive mode  (or acting as a server), in which case
  765. it may have been sending out periodic NAKs for your expected SEND-@|INIT or
  766. command packet.  If you don't do this, you may find that there are sufficient
  767. NAKs to prevent the transfer -- you send a Send-Init, read the response, which
  768. is an old NAK, so you send another Send-Init, read the next old NAK, and so
  769. forth, up to the retransmission limit, and give up before getting to the ACKs
  770. that are waiting in line behind all the old NAKs.  If the number of NAKs is
  771. below the cutoff, then each packet may be transmitted multiply.
  772.  
  773. Similarly, before sending a packet, you should clear the input buffer (after
  774. looking for any required handshake character).  Failure to clear the buffer
  775. could result in propogation of the repetition of a packet caused by stacked-up
  776. NAKs.
  777.  
  778. If an ACK arrives for a packet that has already been ACK'd, simply ignore
  779. the redundant ACK and wait for the next ACK, which should be on its way.
  780. @end<enumerate>
  781.  
  782. @Section<File Names>
  783. @Index<File Names>
  784. The syntax for file names can vary widely from system to system.  To avoid
  785. problems, it is suggested that filenames be represented in the File Header (F)
  786. packet in a "normal form", by default (that is, there should be an option to
  787. override such conversions). 
  788.  
  789. @Begin(Enumerate)
  790. @Index<Normal Form for File Names>
  791. Delete all pathnames and attributes from the file specification.  The file
  792. header packet should not contain directory or device names; if it does, it may
  793. cause the recipient to try to store the file in an inaccessible or nonexistent
  794. area, or it may result in a very strange filename.
  795.  
  796. After stripping any pathname, convert the remainder of the file specification
  797. to the form "@i<name>@q<.>@i<type>", with no restriction on length (except that
  798. it fit in the data field of the F packet), and: @Begin(Enumerate, spread 0)
  799. Include no more than one dot.
  800.  
  801. Not begin or end with a dot.
  802.  
  803. The  @i"name" and @i"type" fields contain digits and uppercase letters.
  804. @End(Enumerate)
  805. @End(Enumerate)
  806. Special characters like @q<"$">, @q<"_">, @q<"-">, @q<"&">, and so
  807. forth should be disallowed, since they're sure to cause problems on
  808. one system or another.
  809.  
  810. The recipient, of course, cannot depend upon the sender to follow this
  811. convention, and should still take precautions.  However, since most file
  812. systems embody the notion of a file name and a file type, this convention will
  813. allow these items to be expressed in a way that an unlike system can
  814. understand.  The particular notation is chosen simply because it is the most
  815. common.
  816.  
  817. The recipient must worry about the length of the name and type fields of the
  818. file name.  If either is too long, they must be truncated.  If the result
  819. (whether truncated or not) is the same as the name of a file that already
  820. exists in the same area, the recipient should have the ability to take some
  821. special action to avoid writing over the original file.
  822.  
  823. Kermit implementations that convert file specifications to normal form by
  824. default should have an option to override this feature.  This would be most
  825. useful when transferring files between like systems, perhaps used in
  826. conjunction with "image mode" file transfer.  This could allow, for instance,
  827. one UNIX system to send an entire directory tree to another UNIX system.
  828.  
  829. @Section<Robustness>
  830.  
  831. A major feature of the Kermit protocol is the ability to transfer multiple
  832. files.  Whether a particular Kermit program can actually send multiple files
  833. depends on the capabilities of the program and the host operating system
  834. (any Kermit program can receive multiple files).
  835.  
  836. If a Kermit program can send multiple files, it should make every attempt to
  837. send the entire group specified.  If it fails to send a particular file, it
  838. should not terminate the entire batch, but should go on the the next one, and
  839. proceed until an attempt has been made to send each file in the group.
  840.  
  841. Operating in this robust manner, however, gives rise to a problem: the user
  842. must be notified of a failure to send any particular file.  Unfortunately, it
  843. is not sufficient to print a message to the screen since the user may not be
  844. physically present.  A better solution would be to have the sender optionally
  845. keep a log of the @Index<Transaction Log>
  846. transaction, giving the name of each file for which an attempt was made, and
  847. stating whether the attempt was successful, and if not, the reason.  Additional
  848. aids to robustness are described in the Optional Features section, below.
  849.  
  850. @Section<Flow Control>
  851.  
  852. @label<-flow>
  853. @Index<XON/XOFF>@Index<Flow Control> On full duplex connections, XON/XOFF flow
  854. control can generally be used in conjunction with
  855. Kermit file transfer with no ill effects.  This is because XOFFs are sent in
  856. the opposite direction of packet flow, so they will not interfere with the
  857. packets themselves.  XON/XOFF, therefore, need not be implemented by the Kermit
  858. program, but can done by the host system.  If the host system provides this
  859. capability, it should be used -- if both sides can respond XON/XOFF signals,
  860. then buffer overruns and the resulting costly packet retransmissions can be
  861. avoided.
  862.  
  863. Beware, however, of the following situation: remote Kermit is sending periodic
  864. NAKs, local system is buffering them on the operating system level (because the
  865. user has not started the local end of the file transfer yet); local line buffer
  866. becomes full, local systems sends XOFF, remote starts buffering them up on its
  867. end, user finally starts file transfer on local end, clears buffer, local
  868. operating system sends XON, and then all the remotely buffered NAKs show up,
  869. causing the packet echoing problem described above, despite the buffer
  870. clearing.
  871.  
  872. Flow control via modem signals can also be used when available.
  873.  
  874. Note that flow control should not be confused with "handshake" or "line
  875. turnaround" techniques that are used on simplex or half-@|duplex communication
  876. lines.  In fact, the two techniques are mutually exclusive.
  877.  
  878. @Section<Basic Kermit Protocol State Table>
  879.  
  880. The Kermit protocol can be described as a set of states and transitions, and
  881. rules for what to do when changing from one state to another.  State changes
  882. occur based on the type of packets that are sent or received, or
  883. errors that may occur.  Packets always go back and forth; the sender of a file
  884. always sends data packets of some kind (init, header, data) and the receiver
  885. always returns ACK or NAK packets.
  886.  
  887. Upon entering a given state, a certain kind of packet is either being sent or
  888. is expected to arrive -- this is shown on top of the description of that state.
  889. As a result of the action, various responses may occur; these are shown in the
  890. EVENT column.  For each event, an appropriate ACTION is taken, and the protocol
  891. enters a NEW STATE.
  892.  
  893. The following table specifies basic Kermit operation.  Timeouts and error
  894. conditions have been omitted from the following table for simplicity, but the
  895. action is as described above.  Server operation and some of the advanced
  896. features are also omitted.  A full-@|blown state table is given subsequently.
  897.  
  898. @newpage()
  899. @begin<example>
  900.  
  901. @u<STATE   EVENT           ACTION                      >@ux<NEW STATE>
  902.  
  903. @i(@ @ @ @ @ -- SEND STATES --)
  904.  
  905. @i(Send Send-Init Packet:)
  906. S       Get NAK,bad ACK (None)                          S
  907.         Get good ACK    Set remote's params, open file  SF
  908.         (Other)         (None)                          A
  909.         
  910. @i(Send File-Header Packet)
  911. SF      Get NAK,bad ACK (None)                          SF
  912.         Get good ACK    Get bufferful of file data      SD
  913.         (Other)         (None)                          A
  914.  
  915. @i(Send File-Data Packet)
  916. SD      Get NAK,bad ACK (None)                          SD
  917.         Get good ACK    Get bufferful of file data      SD
  918.         (End of file)   (None)                          SZ
  919.         (Other)         (None)                          A
  920.  
  921. @i(Send EOF Packet)
  922. SZ      Get NAK,bad ACK (None)                          SZ
  923.         Get good ACK    Get next file to send           SF
  924.         (No more files) (None)                          SB
  925.         (Other)         (None)                          A
  926.  
  927. @i<Send Break (EOT) Packet>
  928. SB      Get NAK,bad ACK (None)                          SB
  929.         Get good ACK    (None)                          C
  930.         (Other)         (None)                          A
  931.  
  932.  
  933. @i<@ @ @ @ @ -- RECEIVE STATES -->
  934.  
  935. @i(Wait for Send-Init Packet)
  936. R       Get Send-Init   ACK w/local params              RF
  937.         (Other)         (None)                          A
  938.  
  939. @i(Wait for File-Header Packet)
  940. RF      Get Send-Init   ACK w/local params
  941.                          (previous ACK was lost)        RF
  942.         Get Send-EOF    ACK (prev ACK lost)             RF
  943.         Get Break       ACK                             C
  944.         Get File-Header Open file, ACK                  RD
  945.         (Other)         (None)                          A
  946.  
  947. @i(Wait for File-Data Packet)
  948. RD      Get previous    
  949.          packet(D,F)    ACK it again                    RD
  950.         Get EOF         ACK it, close the file          RF
  951.         Get good data   Write to file, ACK              RD
  952.         (Other)         (None)                          A
  953.  
  954.  
  955. @i<@ @ @ @ @ -- STATES COMMON TO SENDING AND RECEIVING -->
  956.  
  957. C       (Send Complete)                                 start
  958. A       ("Abort")                                       start
  959. @end<example>
  960.  
  961. @Chapter<Packet Format>
  962.  
  963. @section<Fields>
  964.  
  965. @Index[Packet]
  966. The Kermit protocol is built around exchange of packets of the
  967. following format:
  968. @begin<example>
  969. +------+-------------+-------------+------+------------+-------+
  970. | MARK | tochar(LEN) | tochar(SEQ) | TYPE |    DATA    | CHECK |
  971. +------+-------------+-------------+------+------------+-------+
  972. @end<example>
  973. where all fields consist of ASCII characters.  The fields are:
  974.  @begin<description,leftmargin +8,indent -8>
  975. @u<MARK>@\The synchronization character that marks the beginning of the
  976. packet.  This should normally be CTRL-A, but may be redefined.
  977.  
  978. @u<LEN>@\The number of ASCII characters within the packet that follow this
  979. field, in other words the packet length minus two.  Since this number is
  980. transformed to a single character via the @q<tochar()> function, packet character
  981. counts of 0 to 94 (decimal) are permitted, and 96 (decimal) is the maximum
  982. total packet length.  The length does not include end-@|of-@|line or padding
  983. characters, which are outside the packet and are strictly for the benefit of
  984. the operating system or communications equipment, but it does include the block
  985. check characters.
  986.  
  987. @u<SEQ>@\The packet sequence number, modulo 64, ranging from 0 to 63.
  988. Sequence numbers "wrap around" to 0 after each group of 64 packets.
  989.  
  990. @u<TYPE>@\The packet type, a single ASCII character.  The following packet
  991. types are required:
  992.  @begin<description,spread 0, leftmargin +4, indent -4>
  993. D@\Data packet
  994.  
  995. Y@\Acknowledge (ACK)
  996.  
  997. N@\Negative acknowledge (NAK)
  998.  
  999. S@\Send initiate (exchange parameters)
  1000.  
  1001. B@\Break transmission (EOT)
  1002.  
  1003. F@\File header
  1004.  
  1005. Z@\End of file (EOF)
  1006.  
  1007. E@\Error
  1008.  
  1009. Q@\@i<Reserved for internal use>
  1010.  
  1011. T@\@i<Reserved for internal use>
  1012. @end<description>
  1013. The NAK packet is used only to indicate that the expected packet was not
  1014. received correctly, never to supply other kinds of information, such as refusal
  1015. to perform a requested service.  The NAK packet @i<always> has an empty data
  1016. field.  The T "packet" is used internally by many Kermit programs to indicate
  1017. that a timeout occurred.
  1018.  
  1019. @Index[Control Characters]
  1020. @u<DATA>@\The "contents" of the packet, if any contents are required in the
  1021. given type of packet, interpreted according to the packet type.  Control
  1022. characters (bytes whose low order 7 bits are in the ASCII control range 0-31,
  1023. or 127) are preceded by a special prefix character, normally "@q<#>", and
  1024. "uncontrollified" via @q<ctl()>.  A prefixed sequence may not be broken across
  1025. packets.  Logical records in printable files are delimited with CRLFs, suitably
  1026. prefixed (e.g. "@q<#M#J>").  Logical records need not correspond to packets.
  1027. Any prefix characters are included in the count.  Optional encoding for 8-bit
  1028. data and repeated characters is described later.  The data fields of all
  1029. packets are subject to prefix encoding, @i<except> the S, I, and A packets
  1030. and their acknowledgements, which must @i<not> be encoded.
  1031.  
  1032. @begin[multiple]
  1033. @u<CHECK>@\@Index[Checksum]@Index<Block Check>A block check on the characters
  1034. in the packet between, but not including, the mark and the block check itself.
  1035. The check for each packet is computed by both hosts, and must agree if a packet
  1036. is to be accepted.  A single-@|character arithmetic checksum is the normal and
  1037. required block check.  Only six bits of the arithmetic sum are included.  In
  1038. order that all the bits of each data character contribute to this quantity,
  1039. bits 6 and 7 of the final value are added to the quantity formed by bits 0-5.
  1040. Thus if @i<s> is the arithmetic sum of the ASCII characters, then
  1041. @example[@i<check> = tochar((@i<s> + ((@i<s> AND 192)/64)) AND 63)]
  1042. This is the default block check, and all Kermits must be capable of performing
  1043. it.  Other optional block check types are described later.
  1044.  
  1045. The block check is based on the ASCII values of all the characters in the
  1046. packet, including control fields and prefix characters.  Non-@|ASCII systems
  1047. must translate to ASCII before performing the block check calculation.
  1048. @end[multiple]
  1049. @end<description>
  1050.  
  1051. @section<Terminator>
  1052.  
  1053. @Index[End-Of-Line (EOL)] @index<Line Terminator>
  1054. Any line terminator that is required by the system may be appended to the
  1055. packet; this is carriage return (ASCII 15) by default.  Line terminators are
  1056. not considered part of the packet, and are not included in the count or
  1057. checksum.  Terminators are not necessary to the protocol, and are invisible to
  1058. it, as are any characters that may appear between packets.  If a host cannot do
  1059. single character input from a TTY line, then a terminator will be required when
  1060. sending to that host.  The terminator can be specified in the initial
  1061. connection exchange.
  1062.  
  1063. Some Kermit implementations also use the terminator for another reason --
  1064. speed.  Some systems are not fast enough to take in a packet and decode it
  1065. character by character at high baud rates; by blindly reading and storing all
  1066. characters between the MARK and the EOL, they are able to absorb the incoming
  1067. characters at full speed and then process them at their own rate.
  1068.  
  1069. @section<Other Interpacket Data>
  1070.  
  1071. The space between packets may be used for any desired purpose.  Handshaking
  1072. characters may be necessary on certain connections, others may require screen
  1073. control or other sequences to keep the packets flowing.
  1074.  
  1075. @section<Encoding, Prefixing, Block Check>
  1076.  
  1077. @index<Control Fields>
  1078. MARK, LEN, SEQ, TYPE, and CHECK are @i<control fields>.  Control fields are
  1079. always literal single-@|character fields, except that the CHECK field may be
  1080. extended by one or two additional check characters.  Each control field is
  1081. encoded by @q<tochar()> or taken literally, but never prefixed.  The control
  1082. fields never contain 8-bit data.
  1083.  
  1084. @index<Data Encoding>
  1085. The DATA field contains a string of data characters in which any control
  1086. characters are encoded printably and preceded with the control prefix.  The
  1087. decision to prefix a character in this way depends upon whether its low order 7
  1088. bits are in the ASCII control range, i.e. 0-31 or 127.  Prefix
  1089. characters that appear in the data must themselves be prefixed by the control
  1090. prefix, but unlike control characters, these retain their literal value in the
  1091. packet.  The character to be prefixed is considered a prefix character if its
  1092. low-order 7 bits corresponds to an active prefix character, such as @q<#>
  1093. (ASCII 35), @i<regardless of the setting of its high-order bit>.
  1094.  
  1095. During decoding, any character that follows the control prefix, but is not
  1096. in the control range, is taken literally.  Thus, it does no harm to prefix
  1097. a printable character, even if that character does not happen to be an
  1098. active prefix.
  1099.  
  1100. The treatment of the high order ("8th") bit of a data byte is as follows:
  1101. @begin<itemize>
  1102. @index<Block Check>
  1103. If the communication channel allows 8 data bits per character, then the
  1104. original value of the 8th bit is retained in the prefixed character.  For
  1105. instance, a data byte corresponding to a Control-A with the 8th bit set would
  1106. be send as a control prefix, normally "@q<#>", without the 8th bit set,
  1107. followed by @q<ctl(^A)> @i<with> the 8th bit set.  In binary notation, this
  1108. would be 
  1109. @example<00100011 11000001>
  1110. In this case, the 8th bit is figured into all block check calculations.
  1111.  
  1112. @Index<Parity>
  1113. If the communication channel or one of the hosts requires parity on each
  1114. character, and both sides are capable of 8th-@|bit prefixing, then 
  1115. the 8th bit will be used for parity, and must @i<not> be included in the block
  1116. check.  8th bit prefixing is an option feature described in greater detail in
  1117. Section @ref<-optional>, below.
  1118.  
  1119. If parity is being used but 8th-@|bit prefixing is @i<not> being done, then the
  1120. value of the 8th bit of each data byte will be lost and binary files will not
  1121. be transmitted correctly.  Again, the 8th bit does not figure into the block
  1122. check.
  1123. @end<itemize>
  1124.  
  1125. The data fields of all packets are subject to prefix encoding, @i<except>
  1126. S, I, and A packets, and the ACKs to those packets (see below).
  1127.  
  1128. @Chapter<Initial Connection>
  1129.  
  1130. @Index[Initial Connection]@Index<Send-Init>
  1131. Initial connection occurs when the user has started up a Kermit program on both
  1132. ends of the physical connection.  One Kermit has been directed (in one way or
  1133. another) to send a file, and the other to receive it.  
  1134.  
  1135. The receiving Kermit waits for a "Send-Init" packet from the
  1136. sending Kermit.  It doesn't matter whether the sending Kermit is started before
  1137. or after the receiving Kermit (if before, the Send-Init packet should be
  1138. retransmitted periodically until the receiving Kermit acknowledges it).  The
  1139. data field of the Send-Init packet is optional; trailing fields can be
  1140. omitted (or left blank, i.e. contain a space) to accept or specify default
  1141. values.
  1142.  
  1143. The Send-Init packet contains a string of configuration information in its data
  1144. field.  The receiver sends an ACK for the Send-Init, whose data field contains
  1145. its own configuration parameters.  The data field of the Send-Init and the ACK
  1146. to the Send-Init are @i<literal>, that is, there is no prefix encoding.  This
  1147. is because the two parties will not know @i<how> to do prefix encoding until
  1148. @i<after> the configuration data is exchanged.
  1149.  
  1150. It is important to note that newly invented fields are added at the right, so
  1151. that old Kermit programs that do not have code to handle the new fields will
  1152. act as if they were not there.  For this reason, the default value for any
  1153. field, indicated by blank, should result in the behavior that occurred before
  1154. the new field was defined or added.
  1155. @begin<example,leftmargin +2>
  1156.  1      2      3      4      5      6      7      8      9      10...
  1157. +------+------+------+------+------+------+------+------+------+-------
  1158. | MAXL | TIME | NPAD | PADC | EOL  | QCTL | QBIN | CHKT | REPT | CAPAS
  1159. +------+------+------+------+------+------+------+------+------+-------
  1160. @end<example>
  1161. The fields are as follows (the first and second person "I" and "you" are
  1162. used to distinguish the two sides).  Fields are encoded printably using the
  1163. @q<tochar()> function unless indicated otherwise.
  1164. @begin<description,leftmargin +10,indent -10>
  1165. 1. @u<MAXL>@\The maximum length packet I want to receive, a number up to 94
  1166. (decimal).  (This really means the biggest value I want to see in a LEN field.)
  1167. You respond with the maximum you want me to send.  This allows systems to
  1168. adjust to each other's buffer sizes, or to the condition of the transmission
  1169. medium.
  1170.  
  1171. 2. @u<TIME>@\The number of seconds after which I want you to time me out while
  1172. waiting for a packet from me.  You respond with the
  1173. amount of time I should wait for packets from you.  This allows the two sides
  1174. to accommodate to different line speeds or other factors that could cause
  1175. timing problems.  Only one side needs to time out.  If both sides time out,
  1176. then the timeout intervals should not be close together. 
  1177.  
  1178. 3. @u<NPAD>@\The number of padding characters I want to precede each incoming
  1179. packet; you respond in kind.  Padding may be necessary when sending to
  1180. a half duplex system that requires some time to change the direction of
  1181. transmission, although in practice this situation is more commonly handled by a
  1182. "handshake" mechanism.
  1183.  
  1184. 4. @u<PADC>@\The control character I need for padding, if any, transformed by
  1185. @q<ctl()> (@i<not> @q<tochar()>) to make it printable.  You respond in kind.
  1186. Normally NUL (ASCII 0), some systems use DEL (ASCII 127).  This field is to be
  1187. ignored if the value NPAD is zero.
  1188.  
  1189. 5. @u<EOL>@\The character I need to terminate an incoming packet, if any.  You
  1190. respond in kind.  Most systems that require a line terminator for terminal
  1191. input accept carriage return for this purpose (note, because there is no way to
  1192. specify that no EOL should be sent, it would have been better to use @q<ctl()>
  1193. for this field rather than @q<tochar()>, but it's too late now).
  1194.  
  1195. 6. @u<QCTL>@\(verbatim) The printable ASCII character I will use to quote
  1196. control characters, normally and by default "@q<#>".  You respond with the one
  1197. you will use.
  1198. @end<description>
  1199.  
  1200. @i<The following fields relate to the use of OPTIONAL features of the Kermit
  1201. protocol, described in section @ref(-optional).>
  1202.  
  1203. @begin<description,leftmargin +10,indent -10>
  1204. 7. @u<QBIN>@\(verbatim) The printable ASCII character I want to use to quote
  1205. characters which have the 8th bit set, for transmitting binary files when the
  1206. parity bit cannot be used for data.  Since this kind of quoting increases both
  1207. processor and transmission overhead, it is normally to be avoided.  If used,
  1208. the quote character must be in the range ASCII 33-62 ("@q<!>" through "@q(>)")
  1209. or 96-126 ("@q<`>" through "@q<~>"), but different from
  1210. the control-@|quoting character.  This field is interpreted as follows:
  1211. @begin<description,leftmargin +4,indent -4,spread 0>
  1212. @q<Y>@\I agree to 8-bit quoting if you request it (I don't need it).
  1213.  
  1214. @q<N>@\I will not do 8-bit quoting (I don't know how).
  1215.  
  1216. @q<&>@\(or any other character in the range 33-62 or 96-126)
  1217. I need to do 8-bit quoting using this character (it will be done if the other
  1218. Kermit puts a @q<Y> in this field, or responds with the same prefix character,
  1219. such as @q<&>).  The recommended 8th-bit quoting prefix character is "@q<&>".
  1220.  
  1221. @i<Anything Else >: 8-bit quoting will not be done.
  1222. @end<description>
  1223. Note that this scheme allows either side to initiate the request, and the order
  1224. does not matter.  For instance, a micro capable of 8-bit communication will
  1225. normally put a "@q<Y>" in this field whereas a mainframe that uses parity
  1226. will always put an "@q<&>".  No matter who sends first, this combination will
  1227. result in election of 8th-bit quoting.
  1228.  
  1229. 8. @u<CHKT>@\(Verbatim) Check Type, the method for detecting errors.  "1" for
  1230. single-@|character checksum (the normal and required method), "2" for
  1231. two-@|character checksum (optional), "3" for three-@|character CRC-@|CCITT
  1232. (optional).  If your response agrees, the designated method will be used;
  1233. otherwise the single-@|character checksum will be used.
  1234.  
  1235. 9. @u<REPT>@\The prefix character I will use to indicate a repeated character.
  1236. This can be any printable character in the range ASCII 33-62 or 96-126, but
  1237. different from the control and 8th-bit prefixes.  SP (32) denotes no repeat
  1238. count processing is to be done.  Tilde ("@q<~>") is the recommended and normal
  1239. repeat prefix.  If you don't respond identically, repeat counts will not be
  1240. done.  Groups of at least 3 or 4 identical characters may be transmitted more
  1241. efficiently using a repeat count, though an individual implementation may wish
  1242. to set a different threshhold.
  1243.  
  1244. 10-?. @Index[CAPAS]@Index[Capabilies]@u[CAPAS]@\A bit mask, in which each bit
  1245. position corresponds to a capability of Kermit, and is set to 1 if that
  1246. capability is 
  1247. present, or 0 if it is not.  Each character contains a 6-bit field (transformed
  1248. by @q<tochar()>), whose low order bit is set to 1 if another capability byte
  1249. follows, and to 0 in the last capability byte.  The capabilities defined so far
  1250. are:
  1251. @Begin(Description,leftmargin +6,indent -4,spread 0)
  1252. @q<#1>@\@i<Reserved>
  1253.  
  1254. @q<#2>@\@i<Reserved>
  1255.  
  1256. @q<#3>@\Ability to accept "A" packets (file attributes)
  1257.  
  1258. @q<#4>@\Ability to do full duplex sliding window protocol
  1259.  
  1260. @q<#5>@\Ability to transmit and receive extended-length packets
  1261. @End(Description) 
  1262. The capability byte as defined so far would then look like:
  1263. @begin<example,leftmargin +0>
  1264.  bit5 bit4 bit3 bit2 bit1 bit0
  1265. +----+----+----+----+----+----+
  1266. | #1 | #2 | #3 | #4 | #5 |  0 |
  1267. +----+----+----+----+----+----+
  1268. @end<example>
  1269. If all these capabilities were "on", the value of the byte would be 76
  1270. (octal).  When capability 6 is added, the capability mask will look
  1271. like this:
  1272. @begin<example,leftmargin +0>
  1273.  bit5 bit4 bit3 bit2 bit1 bit0    bit5 bit4 bit3 bit2 bit1 bit0
  1274. +----+----+----+----+----+----+   +----+----+----+----+----+----+
  1275. | #1 | #2 | #3 | #4 | #5 |  1 |   | #6 | -- | -- | -- | -- |  0 |
  1276. +----+----+----+----+----+----+   +----+----+----+----+----+----+
  1277. @end<example>
  1278.  
  1279. CAPAS+1. @u<WINDO>@\Window size (see section @ref<-window>).
  1280.  
  1281. CAPAS+2. @u<MAXLX1>@\Extended packet length (see section @ref<-longp>).
  1282.  
  1283. CAPAS+3. @u<MAXLX2>@\Extended packet length (see section @ref<-longp>).
  1284.  @end<description>
  1285.  
  1286. The receiving Kermit responds with an ACK ("Y") packet in the same format to
  1287. indicate its own preferences, options, and parameters.  The ACK need not
  1288. contain the same number of fields as the the Send-Init.  From that point, the
  1289. two Kermit programs are "configured" to communicate with each other for the
  1290. remainder of the transaction.  In the case of 8th-bit quoting, one side must
  1291. specify the character to be used, and the other must agree with a "Y" in the
  1292. same field, but the order in which this occurs does not matter.  Similarly for
  1293. checksums -- if one side requests 2 character checksums and the other side
  1294. responds with a "1" or with nothing at all, then single-@|character checksums
  1295. will be done, since not all implementations can be expected to do 2-@|character
  1296. checksums or CRCs.  And for repeat counts; if the repeat field of the send-init
  1297. and the ACK do not agree, repeat processing will not be done.
  1298.  
  1299. All Send-Init fields are optional.  The data field may be left totally empty.
  1300. Similarly, intervening fields may be defaulted by setting them to blank.
  1301. Kermit implementations should know what to do in these cases, namely apply
  1302. appropriate defaults.  The defaults should be:
  1303. @begin<description,leftmargin +12, indent -8, spread 0>
  1304. @label<-defaults>
  1305. MAXL:@\80
  1306.  
  1307. TIME:@\5 seconds
  1308.  
  1309. NPAD:@\0, no padding
  1310.  
  1311. PADC:@\0 (NUL)
  1312.  
  1313. EOL:@\CR (carriage return)
  1314.  
  1315. QCTL:@\the character "#"
  1316.  
  1317. QBIN:@\space, can't do 8-bit quoting
  1318.  
  1319. CHKT:@\"1", single-character checksum
  1320.  
  1321. REPT:@\No repeat count processing
  1322.  
  1323. CAPAS:@\All zeros (no special capabilities)
  1324.  
  1325. WINDO:@\Blank (zero) - no sliding windows
  1326.  
  1327. MAXLX1:@\Blank (zero) - no extended length packets
  1328.  
  1329. MAXLX2:@\Blank (zero) - no extended length packets
  1330. @end<description>
  1331.  
  1332. There are no prolonged negotiations in the initial connection
  1333. sequence -- there is one Send-Init and one ACK in reply.  Everything must
  1334. be settled in this exchange.
  1335.  
  1336. @index<Parity>
  1337. The very first Send-Init may not get through if the sending Kermit makes wrong
  1338. assumptions about the receiving host.  For instance, the receiving host may
  1339. require certain parity, some padding, handshaking, or a special end of line
  1340. character in order to read the Send-Init packet.  For this reason, there should
  1341. be a way for the user the user to specify whatever may be necessary to get the
  1342. first packet through.
  1343.  
  1344. A parity field is not provided in the Send-Init packet because it could not be
  1345. of use.  If the sender requires a certain kind of parity, it will also be
  1346. sending it.  If the receiver does not know this in advance, i.e. @i<before>
  1347. getting the Send-Init, it will not be able to read the Send-Init packet.
  1348.  
  1349.  
  1350. @Chapter<Optional Features>
  1351. @label<-optional>
  1352.  
  1353. The foregoing sections have discussed basic, required operations for any Kermit
  1354. implementation.  The following sections discuss optional and advanced features.
  1355.  
  1356. @Section<8th-Bit and Repeat Count Prefixing>
  1357.  
  1358. @index<Encoding>@index<Prefix>@index<8th Bit>
  1359. Prefix quoting of control characters is mandatory.  In addition, prefixing may
  1360. also be used for 8-bit quantities or repeat counts, when both Kermit programs
  1361. agree to do so.  8th-bit prefixing can allow 8-bit binary data pass through
  1362. 7-bit physical links.  Repeat count prefixing can improve the throughput of
  1363. certain kinds of files dramatically; binary files (particularly executable
  1364. programs) and structured text (highly indented or columnar text) tend to be the
  1365. major beneficiaries.
  1366.  
  1367. When more than one type of prefixing is in effect, a single data character can
  1368. be preceded by more than one prefix character.
  1369. Repeat count processing can only be requested by the sender, and will only be
  1370. used by the sender if the receiver agrees.  8th-bit prefixing is a special case
  1371. because its use is normally not desirable, since it increases both
  1372. processing and transmission overhead.  However, since it is the only
  1373. straightforward mechanism for binary file transfer available to those systems
  1374. that usurp the parity bit, a receiver must be able to request the sender to do
  1375. 8th-bit quoting, since most senders will not normally do it by default.
  1376.  
  1377. @Index<Repeat Prefix>
  1378. The repeat prefix is followed immediately by a single-@|character repeat count,
  1379. encoded printably via @q<tochar()>, followed by the character itself (perhaps
  1380. prefixed by control or 8th bit prefixes, as explained below).  The repeat count
  1381. may express values from 0 to 94.  If a character appears more than 94
  1382. times in a row, it must be "cut off" at 94, emitted with all appropriate
  1383. prefixes, and "restarted".
  1384. The following table should clarify Kermit's prefixing mechanism (the final line
  1385. shows how a sequence of 120 consecutive NULs would be encoded):
  1386. @begin<example>
  1387.              Prefixed           With
  1388. @u<Character    Representation>     @ux<Repeat Count for 8>
  1389.    A            A                ~(A   ["(" is ASCII 40 - 32 = 8]
  1390.    ^A           #A               ~(#A
  1391.    'A           &A               ~(&A
  1392.    '^A          &#A              ~(&#A
  1393.    #            ##               ~(##
  1394.    '#           &##              ~(&##
  1395.    &            #&               ~(#&
  1396.    '&           &#&              ~(&#&
  1397.    ~            #~               ~(#~
  1398.    '~           &#~              ~(&#~
  1399.    NUL          #@@               ~~#@@~:#@@ [120 NULs]
  1400. @end<example>
  1401. @q<A> represents any printable character, @q<^A> represents any control
  1402. character, @q<'x> represents any character with the 8th bit set.  The @q<#>
  1403. character is used for control-@|character prefixing, and the @q<&> character
  1404. for 8-bit prefixing.  The repeat count must always precede any other prefix
  1405. character.  The repeat count is taken literally (after transformation by
  1406. @q<unchar()>; for instance "@q<#>" and "@q<&>" immediately following a "@q<~>"
  1407. denote repeat counts, not control characters or 8-bit characters.  The control
  1408. prefix character "@q<#>" is most closely bound to the data character, then the
  1409. 8-bit prefix, then the repeat count; in other words, the order is: repeat
  1410. prefix and count, 8-bit prefix, control prefix, and the data character itself.
  1411. To illustrate, note that @q<&#A> is @i<not> equivalent to @q<#&A>.
  1412.  
  1413. When the parity bit is available for data, then 8th-bit prefixing should not be
  1414. done, and the 8th bit of the prefixed character will have the same value as the
  1415. 8th bit of the original data byte.  In that case, the table looks like this:
  1416. @begin<example>
  1417.              Prefixed           With
  1418. @u<Character    Representation>     @ux<Repeat Count for 8>
  1419.    'A           'A               ~('A
  1420.    '^A          #'A              ~(#'A
  1421.    '#           #'#              ~(#'#
  1422.    '&           '&               ~('&
  1423.    '~           #'~              ~(#'~
  1424. @end<example>
  1425. Note that since 8th bit prefixing is not being done, "@q<&>" is not being used
  1426. as an 8th bit prefix character, so it does not need to be prefixed with
  1427. "@q<#>".  Also, note that the 8th bit is set on the final argument of the
  1428. repeat sequence, no matter how long, and not on any of the prefix characters.
  1429.  
  1430. Finally, remember the following rules:
  1431. @Begin(Itemize,spread 0.5)
  1432. @i<Prefixed sequences must not be broken across packets.>
  1433.  
  1434. @i<Control, 8th-bit, and repeat count prefixes must be distinct.>
  1435.  
  1436. @i<Data fields of all packets must pass through the prefix encoding mechanism,
  1437. except for S, I, and A packets, and ACKs to those packets, whose data fields
  1438. must not be encoded.>
  1439. @End(Itemize)
  1440. In the first rule above, note that a prefixed sequence means a single character
  1441. @index<Prefixed Sequence>
  1442. and all its prefixes, like @q<~%&#X>, @i<not> a sequence like @q<#M#J>, which
  1443. is @i<two> prefixed sequences.
  1444.  
  1445. @Section<Server Operation>
  1446.  
  1447. @index<Server Operation>
  1448. A Kermit server is a Kermit program running remotely with no "user interface".
  1449. All commands to the server arrive in packets from the local Kermit.  SERVER
  1450. operation is much more convenient than basic operation, since the user need
  1451. never again interact directly with the remote Kermit program after once
  1452. starting it up in server mode, and therefore need not issue complementary SEND
  1453. and RECEIVE commands on the two sides to get a file transfer started; rather, a
  1454. single command (such as SEND or GET) to the local Kermit suffices.  Kermit
  1455. servers can also provide services beyond file transfer.
  1456.  
  1457. Between transactions, a Kermit server waits for packets containing server
  1458. commands.  The packet sequence number is always set back to 0 after a
  1459. transaction.  A Kermit server in command wait should be looking for packet 0,
  1460. and command packets sent to servers should also be packet 0.
  1461. Certain server commands will result in the exchange of multiple packets.  Those
  1462. operations proceed exactly like file transfer.
  1463.  
  1464. @index<Server Command Wait>
  1465. A Kermit server program waiting for a command packet is said to be in "server
  1466. command wait".  Once put into server command wait, the server should never
  1467. leave it until it gets a command packet telling it to do so.  This means that
  1468. after any transaction is terminated, either normally or by any kind of error,
  1469. the server must go back into command wait.  While in command wait, a server may
  1470. elect to send out periodic NAKs for packet 0, the expected command packet.
  1471. Since the user may be disconnected from the server for long periods of time
  1472. (hours), the interval between these NAKs should be significantly longer than
  1473. the normal timeout interval (say, 30-60 seconds, rather than 5-10).  The
  1474. periodic NAKs are useful for breaking the deadlock that would occur if a local
  1475. program was unable to time out, and sent a command that was lost.  On the other
  1476. hand, they can cause problems for local Kermit programs that cannot clear their
  1477. input buffers, or for systems that do XON/XOFF blindly, causing the NAKs to
  1478. buffered in the server's host system output buffer, to be suddenly released
  1479. en masse when an XON appears.  For this reason, servers should have an option
  1480. to set the command-@|wait wakeup interval, or to disable it altogher.
  1481.  
  1482. Server operation must be implemented in two places: in the server itself, and
  1483. in any Kermit program that will be communicating with a server.  The server
  1484. must have code to read the server commands from packets and respond to them.
  1485. The user Kermit must have code to parse the user's server-@|related commands,
  1486. to form the server command packets, and to handle the responses to those server
  1487. commands.
  1488.  
  1489. @subsection<Server Commands>
  1490.  
  1491. Server commands are listed below.  Not all of them have been implemented, and
  1492. some may never be, but their use should be reserved.  Although server-@|mode
  1493. operation is optional, certain commands should be implemented in every server.
  1494. These include Send-Init (S), Receive-Init (R), and the Generic Logout (GL)
  1495. and/or Finish (GF) commands.  If the server receives a command it does not
  1496. understand, or cannot execute, it should respond with an Error (E) packet
  1497. containing a message like "Unimplemented Server Command" and both sides should
  1498. set the packet sequence number back to 0, and the server should remain in
  1499. server command wait.  Only a GL or GF command should terminate server
  1500. operation.
  1501.  
  1502. Server commands are as follows:
  1503.  @begin<description,spread 0, leftmargin +4, indent -4>
  1504. S@\Send Initiate (exchange parameters, server waits for a file).
  1505.  
  1506. R@\Receive Initiate (ask the server to send the specified files).
  1507.  
  1508. I@\Initialize (exchange parameters).
  1509.  
  1510. X@\Text header.  Allows transfer of text to the user's screen in
  1511. response to a generic or host command.  This works just like file transfer
  1512. except that the destination "device" is the screen rather than a file.
  1513. Data field may contain a filename, title, or other heading.
  1514.  
  1515. C@\Host Command.  The data field contains a string to be executed as a command
  1516. by the host system command processor.
  1517.  
  1518. K@\Kermit Command.  The data field contains a string in the interactive command
  1519. language of the Kermit server (normally a SET command) to be executed as if it
  1520. were typed in at command level.
  1521.  
  1522. G@\Generic Kermit Command.  Single character in data field (possibly followed
  1523. by operands, shown in {braces}, optional fields in [brackets]) specifies the
  1524. command:
  1525.  @begin<description,spread 0, leftmargin +4, indent -4>
  1526. I@\Login [{*user[*password[*account]]}]
  1527.  
  1528. C@\CWD, Change Working Directory [{*directory[*password]}]
  1529.  
  1530. L@\Logout, Bye
  1531.  
  1532. F@\Finish (Shut down the server, but don't logout).
  1533.  
  1534. D@\Directory [{*filespec}]
  1535.  
  1536. U@\Disk Usage Query [{*area}]
  1537.  
  1538. E@\Erase (delete) {*filespec}
  1539.  
  1540. T@\Type {*filespec}
  1541.  
  1542. R@\Rename {*oldname*newname}
  1543.  
  1544. K@\Copy {*source*destination}
  1545.  
  1546. W@\Who's logged in? (Finger) [{*user ID or network host[*options]}]
  1547.  
  1548. M@\Send a short Message {*destination*text}
  1549.  
  1550. H@\Help [{*topic}]
  1551.  
  1552. Q@\Server Status Query
  1553.  
  1554. P@\Program {*[program-filespec][*program-commands]}
  1555.  
  1556. J@\Journal {*command[*argument]}
  1557.  
  1558. V@\Variable {*command[*argument[*argument]]}
  1559. @end<description>
  1560. Asterisk as used above ("@q<*>") represents a single-@|character length field,
  1561. encoded using @q<tochar()>, for the operand that follows it; thus lengths from
  1562. 0 to 94 may be specified.  This allows multiple operands to be clearly
  1563. delimited regardless of their contents.
  1564. @end<description>
  1565. Note that field length encoding is used within the data field of all Generic
  1566. command packets, but not within the data fields of the other packets, such as
  1567. S, I, R, X, K, and C.
  1568.  
  1569. @index<Encoding>@index<Prefix> All server commands that send arguments in their
  1570. data fields should pass through the prefix encoding mechanism.  Thus if a data
  1571. character or length field happens to correspond to an active prefix character,
  1572. it must itself be prefixed.  The field length denotes the length of the field
  1573. @i<before> prefix encoding and (hopefully) @i<after> prefix decoding.  For
  1574. example, to send a generic command with two fields, "ABC" and "ZZZZZZZZ", first
  1575. each field would be prefixed by @q<tochar()> of its length, in this case
  1576. @q<tochar(3)> and @q<tochar(8)>, giving "@q<#ABC(ZZZZZZZZ>".  But "@q<#>" is the
  1577. normal control prefix character so it must be prefixed itself, and the eight
  1578. Z's can be condensed to 3 characters using a repeat prefix (if repeat counts
  1579. are in effect), so the result after encoding would be "@q<##ABC(~(Z>" (assuming
  1580. the repeat prefix is tilde ("@q<~>").  The recipient would decode this back
  1581. into the original "@q<#ABC(ZZZZZZZZ>" before attempting to extract the two
  1582. fields.
  1583.  
  1584. Since a generic command must fit into a single packet, the program sending the
  1585. command should ensure that the command actually fits, and should not include
  1586. length fields that point beyond the end of the packet.  Servers, however,
  1587. should be defensive and not attempt to process any characters beyond the end of
  1588. the data field, even if the argument length field would lead them to do so.
  1589.  
  1590. @subsection<Timing>
  1591.  
  1592. Kermit does not provide a mechanism for suspending and continuing a
  1593. transaction.  This means that text sent to the user's screen should not be
  1594. frozen for long periods (i.e.@ not longer than the timeout period times the
  1595. retry threshold).
  1596.  
  1597. Between transactions, when the server has no tasks pending, it may send out
  1598. periodic NAKs (always with type 1 checksums) to prevent a deadlock in case a
  1599. command was sent to it but was lost.  These NAKs can pile up in the local
  1600. "user" Kermit's input buffer (if it has one), so the user Kermit should be
  1601. prepared to clear its input buffer before sending a command to a server.
  1602. Meanwhile, servers should recognize that some systems provide no function
  1603. to do this (or even when they do, the process can be foiled by system flow
  1604. control firmware) and should therefore provide a way turn off or slow down the
  1605. command-@|wait NAKs.
  1606.  
  1607. @SubSection<The R Command>
  1608.  
  1609. @index<GET Command>
  1610. The R packet, generally sent by a local Kermit program whose user typed a GET
  1611. command, tells the server to send the files specified by the name in the data
  1612. field of the R packet.  Since we can't assume that the two Kermits are running
  1613. on like systems, the local (user) Kermit must parse the file specification as a
  1614. character string, send it as-is (but encoded) to the server, and let the server
  1615. take care of validating its syntax and looking up the file.  If the server can
  1616. open and read the specified file, it sends a Send-Init (S) packet -- @i<not an
  1617. acknowledgement!> -- to the user, and then completes the file-@|sending
  1618. transaction, as described above.
  1619.  
  1620. If the server cannot send the file, it should respond with an error (E) packet
  1621. containing a reason, like "File not found" or "Read access required".
  1622.  
  1623. Thus, the only two valid responses to a successfully received R packet are an S
  1624. packet or an E packet.  The R packet is not ACK'd.
  1625.  
  1626. @SubSection<The K Command>
  1627.  
  1628. The K packet can contain a character string which the server interprets as a
  1629. command in its own interactive command language.  This facility is useful for
  1630. achieving the same effect as a direct command without having to shut down the
  1631. server, connect back to the remote system, continue it (or start a new one),
  1632. and issue the desired commands.  The server responds with an ACK if the command
  1633. was executed successfully, or an error packet otherwise.  The most likely use
  1634. for the K packet might be for transmitting SET commands, e.g. for switching
  1635. between text and binary file modes.
  1636.  
  1637. @SubSection<Short and Long Replies>
  1638.  
  1639. @index<Long Reply>@index<Short Reply>
  1640.  Any request made of a server may be answered in either of two ways, and any
  1641. User Kermit that makes such a request should be prepared for either kind of
  1642. reply:
  1643. @Begin(itemize)
  1644. @i<A short reply>.  This consists of a single ACK packet, which may contain
  1645. text in its data field.  For instance, the user might send a disk space query
  1646. to the server, and the server might ACK the request with a short character
  1647. string in the data field, such as "12K bytes free".  The user Kermit should
  1648. display this text on the screen.
  1649.  
  1650. @i<A long reply>.  This proceeds exactly like a file transfer (and in some
  1651. cases it may be a file transfer).  It begins with one of the following:
  1652. @begin<itemize,spread 0.5>
  1653. A File-Header (F)
  1654. packet (optionally followed by one or more Attributes packets; these are
  1655. discussed later);
  1656.  
  1657. A Text-Header (X) packet.
  1658.  
  1659. A Send-Init (S) Packet, followed by an X or F packet.
  1660. @end<itemize>
  1661. After the X or F packet comes an arbitrary number of Data (D) packets,
  1662. then an End-Of-File (Z) packet, and finally a Break-Transmission (B) packet,
  1663. as for ordinary file transfer.
  1664. @End(itemize)
  1665. A long reply should begin with an S packet unless an I-packet exchange has
  1666. already taken place, @i<and> the type 1 (single-@|character) block check is
  1667. being used. 
  1668.  
  1669. @SubSection<Additional Server Commands>
  1670.  
  1671. @index<Server Commands>
  1672. The following server commands request the server to perform tasks other than
  1673. sending or receiving files.  Almost any of these can have either short or long
  1674. replies.  For instance, the Generic Erase (GE) command may elicit a simple ACK,
  1675. or a stream of packets containing the names of all the files it erased (or
  1676. didn't erase).  These commands are now described in more detail; arguments are
  1677. as provided in commands typed to the user Kermit (subject to prefix encoding);
  1678. no transformations to any kind of normal or canonic form are done -- filenames
  1679. and other operands are in the syntax of the server's host system.
  1680.  
  1681. @begin<description, leftmargin +4, indent -4>
  1682. I@\Login.  For use when a Kermit server is kept perpetually running on a
  1683. dedicated line.  This lets a new user obtain an identity on the server's host
  1684. system.  If the data field is empty, this removes the user's identity, so that
  1685. the next user does not get access to it.
  1686.  
  1687. L@\Logout, Bye.  This shuts down the server entirely, causing the server itself
  1688. to log out its own job.  This is for use when the server has been started up
  1689. manually by the user, who then wishes to shut it down remotely.  For a
  1690. perpetual, dedicated server, this command simply removes the server's access
  1691. rights to the current user's files, and leaves the server waiting for a new
  1692. login command.
  1693.  
  1694. F@\Finish.  This is to allow the user to shut down the server, putting its
  1695. terminal back into normal (as opposed to binary or raw) mode, and putting the
  1696. server's job back at system command level, still logged in, so that the user
  1697. can connect back to the job.  For a perpetual, dedicated server, this command
  1698. behaves as the L (BYE) command.
  1699.  
  1700. C@\CWD.  Change Working Directory.  This sets the default directory or area for
  1701. file transfer on the server's host.  With no operands, this command sets the
  1702. default area to be the user's own default area.
  1703.  
  1704. D@\Directory.  Send a directory listing to the user.  The user program can
  1705. display it on the terminal or store it in a file, as it chooses.  The directory
  1706. listing should contain file sizes and creation dates as well as file names, if
  1707. possible.  A wildcard or other file-@|group designator may be specified to ask
  1708. the server list only those files that match.  If no operand is given, all files
  1709. in the current area should be shown.
  1710.  
  1711. U@\Disk Usage Query.  The server responds with the amount of space used and the
  1712. amount left free to use, in K bytes (or other units, which should be
  1713. specified).
  1714.  
  1715. E@\Erase (delete).  Delete the specified file or file group.
  1716.  
  1717. T@\Type.  Send the specified file or file group, indicating (by starting with
  1718. an X packet rather than an F packet, or else by using the Type attribute) that
  1719. the file is to be displayed on the screen, rather than stored.
  1720.  
  1721. R@\Rename.  Change the name of the file or files as indicated.  The string
  1722. indicating the new name may contain other attributes, such as protection code,
  1723. permitted in file specifications by the host.
  1724.  
  1725. K@\Copy.  Produce a new copy of the file or file group, as indicated, leaving
  1726. the source file(s) unmodified.
  1727.  
  1728. W@\Who's logged in? (Finger).  With no arguments, list all the users who are
  1729. logged in on the server's host system.  If an argument is specified, provide
  1730. more detailed information on the specified user or network host.
  1731.  
  1732. M@\Short Message.  Send the given short (single-packet) message to the
  1733. indicated user's screen.
  1734.  
  1735. P@\Program.  This command has two arguments, program name (filespec), and
  1736. command(s) for the program.  The first field is required, but may be left null
  1737. (i.e. zero length).  If it is null, the currently loaded program is "fed" the
  1738. specified command.  If not null, the specified program is loaded and started;
  1739. if a program command is given it is fed to the program as an initial command
  1740. (for instance, as a command line argument on systems that support that
  1741. concept).  In any case, the output of the program is sent back in packets as
  1742. either a long or short reply, as described above.
  1743.  
  1744. J@\Journal.  This command controls server transaction logging.  The data field
  1745. contains one of the following:
  1746. @begin<description, leftmargin +4, indent -4>
  1747. @q<+>@\Begin/resume logging transactions.  If a filename is given, close any
  1748. currently open transaction and then open the specified file as the new
  1749. transaction log.  If no name given, but a log file was already open, resume
  1750. logging to that file.  If no filename  was given and no log was open, the
  1751. server should open a log with a default name, like @q<TRANSACTION.LOG>.
  1752.  
  1753. @q<->@\Stop logging transactions, but don't close the current transaction log
  1754. file.
  1755.  
  1756. @q<C>@\Stop logging and close the current log.
  1757.  
  1758. @q<S>@\Send the transaction log as a file.  If it was open, close it first.
  1759. @end<description>
  1760. Transaction logging is the recording of the progress of file transfers.  It
  1761. should contain entries showing the name of each file transferred, when the
  1762. transfer began and ended, whether it completed successfully, and if not, why.
  1763.  
  1764. @q<V>@\Set or Query a variable.  The @i<command> can be S or Q.  The first
  1765. argument is the variable name.  The second argument, if any, is the value.
  1766. @begin<description, leftmargin +4, indent -4>
  1767. S@\Set the specified variable to the specified value.  If the value is null,
  1768. then undefine the variable.  If the variable is null then do nothing.  If the
  1769. variable did not exist before, create it.  The server should respond with an
  1770. ACK if successful, and Error packet otherwise.
  1771.  
  1772. Q@\Query the value of the named variable.  If no variable is supplied, display
  1773. the value of all active variables.  The server responds with either a short or
  1774. long reply, as described above.  If a queried variable does not exist, a null
  1775. value is returned.
  1776. @end<description>
  1777. Variables are named by character strings, and have character string values,
  1778. which may be static or dynamic.  For instance, a server might have built-@|in
  1779. variables like "system name" which never changes, or others like "mail status"
  1780. which, when queried, cause the server to check to see if the user has any new
  1781. mail.
  1782. @end<description>
  1783.  
  1784. @SubSection<Host Commands>
  1785.  
  1786. Host commands are conceptually simple, but may be hard to implement on some
  1787. systems.  The C packet contains a text string in its data field which is simply
  1788. fed to the server's host system command processor; any output from the
  1789. processor is sent back to the user in Kermit packets, as either a short or long
  1790. reply.
  1791.  
  1792. Implementation of this facility under UNIX, with its forking process structure
  1793. and i/o redirection via pipes, is quite natural.  On other systems, it could be
  1794. virtually impossible.
  1795.  
  1796. @SubSection<Exchanging Parameters Before Server Commands>
  1797.  
  1798. In basic Kermit, the Send-Init exchange is always sufficient to configure the
  1799. two sides to each other.  During server operation, on the other hand, some
  1800. transactions may not begin with a Send-Init packet.  For instance, when the
  1801. user sends an R packet to ask the server to send a file, the server chooses
  1802. what block check option to use.  Or if the user requests a directory listing,
  1803. the server does not know what packet length to use.
  1804.  
  1805. The solution to this problem is the "I" (Init-Info) packet.  It is exactly like
  1806. a Send-Init packet, and the ACK works the same way too.  However, receipt of an
  1807. I packet does not cause transition to file-send state.  The I-packet exchange
  1808. simply allows the two sides to set their parameters, in preparation for the
  1809. next transaction.
  1810.  
  1811. Servers should be able to receive and ACK "I" packets when in server command
  1812. wait.  User Kermits need not send "I" packets, however; in that case, the
  1813. server will assume all the defaults for the user listed on
  1814. page @pageref<-defaults>, or whatever parameters have been set by other means
  1815. (e.g. SET commands typed to the server before it was put in server mode).
  1816.  
  1817. User Kermits which send I packets should be prepared to receive and ignore an
  1818. Error packet in response.  This could happen if the server has not implemented
  1819. I packets.
  1820.  
  1821. The I packet, together with its ACK, constitute a complete transaction, 
  1822. separate from the S-packet or other exchange that follows it.  The packet
  1823. number remains at zero after the I-packet exchange.
  1824.  
  1825. @section<Alternate Block Check Types>
  1826.  
  1827. There are two optional kinds of block checks:
  1828. @begin<description,leftmargin +4,indent -4>
  1829. @ux<Type 2>@\
  1830. A two-@|character checksum based on the low order 12 bits of the arithmetic sum
  1831. of the characters in the packet (from the LEN field through the last data
  1832. character, inclusive) as follows:
  1833. @begin<example>
  1834.          1              2
  1835. --------+----------------+---------------+
  1836. ...data | tochar(b6-b11) | tochar(b0-b5) |
  1837. --------+----------------+---------------+
  1838. @End(Example)
  1839. For instance, if the 16-bit result is 154321 (octal), then the 2 character
  1840. block check would be "@q<C1>".
  1841.  
  1842. @ux<Type 3>@\ 
  1843. Three-@|character 16-bit CRC-CCITT. The CRC calculation treats the
  1844. data it operates upon as a string of bits with the low order bit of the first
  1845. character first and the high order bit of the last character last.  The initial
  1846. value of the CRC is taken as 0; the 16-bit CRC is the remainder after dividing
  1847. the data bit string by the polynomial @i<X>@+(16)+@i<X>@+(12)+@i<X>@+(5)+1
  1848. (this calculation can actually be done a character at a time, using a simple
  1849. table lookup algorithm).  The result is represented as three printable
  1850. characters at the end of the packet, as follows:
  1851. @begin<example>
  1852.          1               2              3
  1853. --------+-----------------+----------------+---------------+
  1854. ...data | tochar(b12-b15) | tochar(b6-b11) | tochar(b0-b5) |
  1855. --------+-----------------+----------------+---------------+
  1856. @End(Example)
  1857. For instance, if the 16-bit result is 154321 (octal), then the 3 character
  1858. block check would be "@q<-C1>".  The CRC technique chosen here agrees with many
  1859. hardware implementations (e.g. the VAX CRC instruction).
  1860. @End(Description) 
  1861. Here is an algorithm for Kermit's CRC-CCITT calculation:
  1862. @begin<example,leftmargin +2>
  1863.     crc = 0                                   @i<Start CRC off at 0>
  1864.     i = <position of LEN field>               @i<First byte to include>
  1865.  
  1866. A:  c = <byte at position i>                  @i<Get current byte>
  1867.     if (parity not NONE) then c = c AND 127;  @i<Mask off any parity bit>
  1868.     q = (crc XOR c) AND 15;                   @i<Do low-order 4 bits>
  1869.     crc = (crc / 16) XOR (q * 4225);
  1870.     q = (crc XOR (c / 16)) AND 015;           @i<And high 4 bits>
  1871.     crc = (crc / 16) XOR (q * 4225);
  1872.     i = i + 1                                 @i<Position of next byte>
  1873.     LEN = LEN - 1                             @i<Decrement packet length>
  1874.     if (LEN > 0) goto A                       @i<Loop till done>
  1875.  
  1876. @i<At this point, the @q(crc) variable contains the desired quantity.>
  1877. @end<example>
  1878. Thanks to Andy Lowry of Columbia's CS department for this "tableless" CRC
  1879. algorithm (actually, it uses a table with one entry -- 4225).  @q<AND> is the
  1880. bitwise AND operation, @q<XOR> the bitwise exclusive OR, "@q<*>" is
  1881. multiplication, and "@q</>" signifies integer division (@w["@q<crc / 16>"] is
  1882. equivalent to shifting the @q<crc> quantity 4 bits to the right).
  1883.  
  1884. The single-character checksum has proven quite adequate in practice.  The other
  1885. options can be used only if both sides agree to do so via Init packet (S or I)
  1886. exchange.  The 2 and 3 character block checks should only be used
  1887. under conditions of severe line noise and packet corruption.
  1888.  
  1889. Since type 2 and 3 block checks are optional, not all Kermits can be expected
  1890. to understand them.  Therefore, during initial connection, communication must
  1891. begin using the type 1 block check.  If type 2 or 3 block checks are agreed to
  1892. during the "I" or "S" packet exchange, the switch will occur @i<only after> the
  1893. Send-Init has been sent and ACK'd with a type 1 block check.  This means that
  1894. the first packet with a type 2 or 3 block check must always be an "F" or "X"
  1895. packet.  Upon completion of a transaction, both sides must switch back to type
  1896. 1 (to allow for the fact that neither side has any way of knowing when
  1897. the other side has been stopped and restarted).  The transaction is over
  1898. @i<after> a "B" or "E" packet has been sent and ACK'd, or after any error that
  1899. terminates the transaction prematurely or abnormally.
  1900.  
  1901. A consequence of the foregoing rule is that if a type 2 or 3 block check is
  1902. to be used, a long reply sent by the server @i<must> begin with a Send-Init
  1903. (S) packet, even if an I packet exchange had already occurred.  If type 1 block
  1904. checks are being used, the S packet can be skipped and the transfer can start
  1905. with an X or F packet.
  1906.  
  1907. A server that has completed a transaction and is awaiting a new command may
  1908. send out periodic NAKs for that command (packet 0).  Those NAKs must have type
  1909. 1 block checks.
  1910.  
  1911. The use of alternate block check types can cause certain complications.  For
  1912. instance, if the server gets a horrible error (so bad that it doesn't even send
  1913. an error packet) and reverts to command wait, sending NAKs for packet 0 using a
  1914. type 1 block check, while a transfer using type 2 or 3 block checks was in
  1915. progress, neither side will be able to read the other's packets.  Communication
  1916. can also grind to a halt if A sends a Send-Init requesting, say, type 3 block
  1917. checks, B ACKs the request, switches to type 3 and waits for the X or F packet
  1918. with a type 3 block check, but the ACK was lost, so A resends the S packet with
  1919. a type 1 block check.  Situations like this will ultimately resolve themselves
  1920. after the two sides retransmit up to their retry threshhold, but can be
  1921. rectified earlier by the use of two heuristics:
  1922. @begin<itemize, spread 0.5>
  1923. The packet reader can assume that if the packet type is "S", the block check
  1924. type is 1.
  1925.  
  1926. @index<NAK>A NAK packet never has anything in its data field.  Therefore, the
  1927. block check type can always be deduced by the packet reader from the length
  1928. field of a NAK.  In fact, it is the value of the length field minus 2.  A NAK
  1929. can therefore be thought of as a kind of "universal synchronizer".
  1930. @end<itemize>
  1931. These heuristics tend to violate the layered nature of the protocol, since the
  1932. packet reader should normally be totally unconcerned with the packet type
  1933. (which is of interest to the application level which invokes the packet
  1934. reader).  A better design would have had each packet include an indicator of
  1935. the type of its own block check; this would have allowed the block check type
  1936. to be changed dynamically during a transaction to adapt to changing conditions.
  1937. But it's too late for that now...
  1938.  
  1939. @section<Interrupting a File Transfer>
  1940.  
  1941. @index<Interrupting a File Transfer>
  1942. This section describes an optional feature of the Kermit protocol to allow
  1943. graceful interruption of file transfer.  This feature is unrelated to server
  1944. operation.
  1945.  
  1946. To interrupt sending a file, send an EOF ("Z") packet in place of the next data
  1947. packet, including a "D" (for Discard) in the data field.  The recipient ACKs
  1948. the Z packet normally, but does not retain the file.  This does not interfere
  1949. with older Kermits on the receiving end; they will not inspect the data field
  1950. and will close the file normally.  The mechanism can be triggered by typing an
  1951. interrupt character at the console of the sending Kermit program.  If a
  1952. (wildcard) file group is being sent, it is possible to skip to the next file or
  1953. to terminate the entire batch; the protocol is the same in either case, but the
  1954. desired action could be selected by different interrupt characters, e.g. CTRL-X
  1955. to skip the current file, CTRL-Z to skip the rest of the batch.
  1956.  
  1957. To interrupt receiving a file, put an "X" in the data field of an ACK for a
  1958. Data packet.  To interrupt receiving an entire file group, use a "Z".  The user
  1959. could trigger this mechanism by typing an interrupt character, say,
  1960. CTRL-X and CTRL-Z, respectively, at the receiving Kermit's console.  A sender
  1961. that was aware of the new feature, upon finding one of these codes, would act
  1962. as described above, i.e. send a "Z" packet with a "D" code; a sender that did
  1963. not implement this feature would simply ignore the codes and continue sending.
  1964. In this case, and if the user wanted the whole batch to be cancelled (or only
  1965. one file was being sent), the receiving Kermit program, after determining that
  1966. the sender had ignored the "X" or "Z" code, could send an Error (E) packet to
  1967. stop the transfer.
  1968.  
  1969. The sender may also choose to send a Z packet containing the D code when it
  1970. detects that the file it is sending cannot be sent correctly and completely --
  1971. for instance, after sending some packets correctly, it gets an i/o error
  1972. reading the file.  Or, it notices that the "8th bit" of a file byte is set when
  1973. the file is being sent as a text file and no provision has been made for
  1974. transmitting the 8th bit.
  1975.  
  1976. @Section<Transmitting File Attributes>
  1977. @label<-attributes>
  1978.  
  1979. The optional Attributes (A) packet provides a mechanism for the sender of a
  1980. file to provide additional information about it.  This packet can be sent if
  1981. the receiver has indicated its ability to process it by setting the Attributes
  1982. bit in the capability mask.  If both sides set this bit in the Kermit
  1983. capability mask, then the sender, after sending the filename in the "F" packet
  1984. and receiving an acknowledgement, may (but does not have to) send an "A" packet
  1985. to provide file attribute information.
  1986.  
  1987. Setting the Attributes bit in the capability mask does @i<not> indicate support
  1988. for any particular attributes, only that the receiver is prepared to accept the
  1989. "A" packet.
  1990.  
  1991. The attributes are given in the data field of the "A" packet.  The data
  1992. field consists of 0 or more subfields, which may occur in any order.  Each
  1993. subfield is of the following form:
  1994. @Begin(Example) 
  1995. +-----------+----------------+------+
  1996. | ATTRIBUTE | tochar(LENGTH) | DATA |
  1997. +-----------+----------------+------+
  1998. @End(Example)
  1999. where
  2000. @Begin(Description, leftmargin +10, indent -10) 
  2001. ATTRIBUTE@\is a single printable character other than space,
  2002.  
  2003. LENGTH@\is the length of the data characters (0 to 94), with 32
  2004. added to produce a single printable character, and
  2005.  
  2006. DATA@\is @i<length> characters worth of data, all printable characters.
  2007. @End(Description) 
  2008. No quoting or prefixing is done on any of this data.
  2009.  
  2010. More than one attribute packet may be sent.  The only requirement is that all
  2011. the A packets for a file must immediately follow its File header (or X) packet,
  2012. and precede the first Data packet.
  2013.  
  2014. There may be 93 different attributes, one for each of the 93 printable ASCII
  2015. characters other than space.  These are assigned in ASCII order.
  2016. @Begin(Description, leftmargin +10, indent -10) 
  2017. @q<!> (ASCII 33)@\Length.  The data field gives the length in K (1024) bytes,
  2018. as a printable decimal number, e.g. "!#109".  This will allow
  2019. the receiver to determine in advance whether there is sufficient
  2020. room for the file, and/or how long the transfer will take.
  2021.  
  2022. @q<"> (ASCII 34)@\Type.  The data field can contain some indicator of the
  2023. nature of the file.  Operands are enclosed in {braces}, optional items in
  2024. [brackets].  The braces and brackets do not actually appear in the packet.
  2025. @Begin(Description,leftmargin +8, indent -8)
  2026. A[{xx}]@\ASCII text, containing no 8-bit quantities, logical records (lines)
  2027. delimited by the (quoted) control character sequence {xx},
  2028. represented here by its printable counterpart (MJ = CRLF,
  2029. J = LF, etc).  For instance AMJ means that the appearance
  2030. of @q<#M#J> (the normal prefixed CRLF sequence) in a file data
  2031. packet indicates the end of a record, assuming the current control prefix is
  2032. "@q<#>".  If {xx} is omitted, MJ will be assumed.
  2033.  
  2034. B[{xx}]@\Binary.  {xx} indicates in what manner the file is binary:
  2035. @Begin(Description,leftmargin +4, indent -4)
  2036. 8@\(default) The file is a sequence of 8-bit bytes, which must be
  2037. saved as is.  The 8th bit may be sent "bare", or prefixed
  2038. according to the Send-Init negotiation about 8th-bit
  2039. prefixing.
  2040.  
  2041. 36@\The file is a PDP-10 format binary file, in which five
  2042. 7-bit bytes are fit into one 36-bit word, with the final
  2043. bit of each word being represented as the "parity bit" of
  2044. every 5th character (perhaps prefixed).
  2045. @End(Description) 
  2046.  
  2047. D{x}@\@i<Moved from here to FORMAT attribute>
  2048.  
  2049. F{x}@\@i<Moved from here to FORMAT attribute>
  2050.  
  2051. I[{x}]@\Image.  The file is being sent exactly as it is represented on the
  2052. system of origin.  For use between like systems.  There are {x} usable bits per
  2053. character, before prefixing.  For instance, to send binary data from a system
  2054. with 9-bit bytes, it might be convenient to send three 6-bit characters for
  2055. every two 9-bit bytes.  Default {x} is 8.
  2056. @End(Description) 
  2057.  
  2058. @q<#> (ASCII 35)@\Creation Date, expressed as "@q<[yy]yymmdd[ hh:mm[:ss]]>"
  2059. (ISO standard date format), e.g. @q<831009@ 23:59>.  The time is optional; if
  2060. given, it should be in 24-hour format, and the seconds may be omitted, and a
  2061. single space should separate the time from the date.
  2062.  
  2063. @q<$> (ASCII 36)@\Creator's ID, expressed as a character string of the given
  2064. length. 
  2065.  
  2066. @q<%> (ASCII 37)@\Account to charge the file to, character string.
  2067.  
  2068. @q<&> (ASCII 38)@\Area in which to store the file, character string.
  2069.  
  2070. @q<'> (ASCII 39)@\Password for above, character string.
  2071.  
  2072. @q<(> (ASCII 40)@\Block Size.  The file has, or is to be stored with, the given
  2073. block size.
  2074.  
  2075. @q<)> (ASCII 41)@\Access:
  2076. @Begin(Description,leftmargin +4, indent -4,spread 0)
  2077. N@\New, the normal case -- create a new file of the given name.
  2078.  
  2079. S@\Supersede (overwrite) any file of the same name.
  2080.  
  2081. A@\Append to file of the given name.
  2082. @End(Description)
  2083.  
  2084. @q<*> (ASCII 42)@\Encoding:
  2085. @Begin(Description,leftmargin +4, indent -4,spread 0)
  2086. A@\ASCII, normal ASCII encoding with any necessary prefixing, etc.
  2087.   
  2088. H@\Hexadecimal "nibble" encoding.
  2089.  
  2090. E@\EBCDIC (sent as if it were a binary file).
  2091.  
  2092. X@\Encrypted.
  2093.  
  2094. Q{x}@\Huffman Encoded for compression.  First @i<x> bytes of the file are the
  2095. key.
  2096. @End(Description) 
  2097.  
  2098. @q<+> (ASCII 43)@\Disposition (operands are specified in the syntax of the
  2099. receiver's host system):
  2100. @Begin(Description) 
  2101. M{user(s)}@\Send the file as Mail to the specified user(s).
  2102.  
  2103. O{destination}@\Send the file as a lOng terminal message to the specified
  2104. destination (terminal, job, or user).
  2105.  
  2106. S[{options}]@\Submit the file as a batch job, with any specified options.
  2107.  
  2108. P[{options}]@\Print the file on a system printer, with any specified options,
  2109. which may specify a particular printer, forms, etc.
  2110.  
  2111. T@\Type the file on the screen.
  2112.  
  2113. L[{aaa}]@\Load the file into memory at the given address, if any.
  2114.  
  2115. X[{aaa}]@\Load the file into memory at the given address and eXecute it.
  2116.  
  2117. A@\Archive the file; save the file together with the attribute packets that
  2118. preceded it, so that it can be sent back to the system of origin with all its
  2119. attributes intact.  A file stored in this way should be specially marked so
  2120. that the Kermit that sends it back will recognize the attribute information as
  2121. distinct from the file data.
  2122. @End(Description) 
  2123.  
  2124. , (ASCII 44)@\Protection.  Protection code for the file, in the syntax of the
  2125. receiver's host file system.  With no operand, store according to the system's
  2126. default protection for the destination area.
  2127.  
  2128. - (ASCII 45)@\Protection.  Protection code for the file with respect to the
  2129. "public" or "world", expressed generically in a 6-bit quantity (made
  2130. printable by @q<tochar()>), in which the bits have the following meaning:
  2131. @Begin(Description,leftmargin +4,indent -4,spread 0)
  2132. b0:@\Read Access
  2133.  
  2134. b1:@\Write Access
  2135.  
  2136. b2:@\Execute Access
  2137.  
  2138. b3:@\Append Access
  2139.  
  2140. b4:@\Delete Access
  2141.  
  2142. b5:@\Directory Listing
  2143. @End(Description)
  2144. A one in the bit position means allow the corresponding type of access, a zero
  2145. means prohibit it.  For example, the letter "E" in this field would allow read,
  2146. execute, and directory listing access (@q<unchar("E") = 69-32 = 37 = 100101>
  2147. binary).
  2148.  
  2149. . (ASCII 46)@\Machine and operating system of origin.  This is useful in
  2150. conjunction with the archive disposition attribute.  It allows a file, once
  2151. archived, to be transferred among different types of systems, retaining its
  2152. archive status, until it finds its way to a machine with the right
  2153. characteristics to de-archive it.  The systems are denoted by codes; the first
  2154. character is the major system designator, the second designates the specific
  2155. model or operating system.  A third character may be added to make further
  2156. distinctions, for instance operating system version.  The systems below do not
  2157. form a complete collection; many more can and probably will be added.
  2158. @begin<description,leftmargin +4,indent -4,spread 0.5>
  2159. A@\Apple microcomputers
  2160. @begin<description,leftmargin +4,indent -4,spread 0>
  2161. 1@\Apple II, DOS 
  2162.  
  2163. 2@\Apple III
  2164.  
  2165. 3@\Macintosh
  2166.  
  2167. 4@\Lisa
  2168. @end<description>
  2169.  
  2170. B@\Sperry (Univac) mainframes
  2171. @begin<description,leftmargin +4,indent -4,spread 0>
  2172. 1@\1100 series, EXEC
  2173.  
  2174. 2@\9080, VS9
  2175. @end<description>
  2176.  
  2177. C@\CDC mainframes
  2178. @begin<description,leftmargin +4,indent -4,spread 0>
  2179. 1@\Cyber series, NOS
  2180.  
  2181. 2@\Cyber series, NOS-BE
  2182.  
  2183. 3@\Cyber series, NOS-VE
  2184.  
  2185. 4@\Cyber series, SCOPE
  2186. @end<description>
  2187.  
  2188. D@\DEC Systems
  2189. @begin<description,leftmargin +4,indent -4,spread 0>
  2190. 1@\DECsystem-10/20, TOPS-10
  2191.  
  2192. 2@\DECsystem-10/20, TOPS-20
  2193.  
  2194. 3@\DECsystem-10/20, TENEX
  2195.  
  2196. 4@\DECsystem-10/20, ITS
  2197.  
  2198. 5@\DECsystem-10/20, WAITS
  2199.  
  2200. 6@\DECsystem-10/20, MAXC
  2201.  
  2202. 7@\VAX-11, VMS
  2203.  
  2204. 8@\PDP-11, RSX-11
  2205.  
  2206. 9@\PDP-11, IAS
  2207.  
  2208. A@\PDP-11, RSTS/E
  2209.  
  2210. B@\PDP-11, RT-11
  2211.  
  2212. C@\Professional-300, P/OS
  2213.  
  2214. D@\Word Processor (WPS or DECmate), WPS
  2215. @end<description>
  2216.  
  2217. E@\Honeywell mainframes
  2218. @begin<description,leftmargin +4,indent -4,spread 0>
  2219. 1@\MULTICS systems
  2220.  
  2221. 2@\DPS series, running CP-6
  2222.  
  2223. 3@\DPS series, GCOS
  2224.  
  2225. 4@\DTSS
  2226. @end<description>
  2227.  
  2228. F@\Data General machines
  2229. @begin<description,leftmargin +4,indent -4,spread 0>
  2230. 1@\RDOS
  2231.  
  2232. 2@\AOS
  2233.  
  2234. 3@\AOS/VS
  2235. @end<description>
  2236.  
  2237. G@\PR1ME machines, PRIMOS
  2238.  
  2239. H@\Hewlett-Packard machines
  2240. @begin<description,leftmargin +4,indent -4,spread 0>
  2241. 1@\HP-1000, RTE
  2242.  
  2243. 2@\HP-3000, MPE
  2244. @end<description>
  2245.  
  2246. I@\IBM 370-series and compatible mainframes
  2247. @begin<description,leftmargin +4,indent -4,spread 0>
  2248. 1@\VM/CMS
  2249.  
  2250. 2@\MVS/TSO
  2251.  
  2252. 3@\DOS
  2253.  
  2254. 4@\MUSIC
  2255.  
  2256. 5@\GUTS
  2257.  
  2258. 6@\MTS
  2259. @end<description>
  2260.  
  2261. J@\Tandy microcomputers, TRSDOS
  2262.  
  2263. K@\Atari computers
  2264. @begin<description,leftmargin +4,indent -4,spread 0>
  2265. 1@\Home computers, DOS
  2266.  
  2267. 2@\ST series
  2268. @end<description>
  2269.  
  2270. L@\Commodore micros
  2271. @begin<description,leftmargin +4,indent -4,spread 0>
  2272. 1@\Pet
  2273.  
  2274. 2@\64
  2275.  
  2276. 3@\Amiga
  2277. @end<description>
  2278.  
  2279. M@\Miscellaneous mainframes and minis with proprietary operation systems:
  2280. @begin<description,leftmargin +4,indent -4,spread 0>
  2281. 1@\Gould/SEL minis, MPX
  2282.  
  2283. 2@\Harris, VOS
  2284.  
  2285. 3@\Perkin-Elmer minis, OS/32
  2286.  
  2287. 4@\Prime, Primos
  2288.  
  2289. 5@\Tandem, Nonstop
  2290.  
  2291. 6@\Cray, CTSS
  2292.  
  2293. 7@\Burroughs (subtypes may be necessary here)
  2294.  
  2295. 8@\GEC 4000, OS4000
  2296.  
  2297. 9@\ICL machines
  2298.  
  2299. A@\Norsk Data, Sintran III
  2300.  
  2301. B@\Nixdorf machines
  2302. @end<description>
  2303.  
  2304. N@\Miscellaneous micros and workstations:
  2305. @begin<description,leftmargin +4,indent -4,spread 0>
  2306. 1@\Acorn BBC Micro
  2307.  
  2308. 2@\Alpha Micro
  2309.  
  2310. 3@\Apollo Aegis
  2311.  
  2312. 4@\Convergent, Burroughs, and similar systems with CTOS, BTOS
  2313.  
  2314. 5@\Corvus, CCOS
  2315.  
  2316. 6@\Cromemco, CDOS
  2317.  
  2318. 7@\Intel x86/3x0, iRMX-x86
  2319.  
  2320. 8@\Intel MDS, ISIS
  2321.  
  2322. 9@\Luxor ABC-800, ABCDOS
  2323.  
  2324. A@\Perq
  2325.  
  2326. B@\Motorola, Versados
  2327. @end<description>
  2328.  
  2329. O-T@\@i(Reserved)
  2330.  
  2331. U@\Portable Operating or File Systems
  2332. @begin<description,leftmargin +4,indent -4,spread 0>
  2333. 1@\UNIX
  2334.  
  2335. 2@\Software Tools
  2336.  
  2337. 3@\CP/M-80
  2338.  
  2339. 4@\CP/M-86
  2340.  
  2341. 5@\CP/M-68K
  2342.  
  2343. 6@\MP/M
  2344.  
  2345. 7@\Concurrent CP/M
  2346.  
  2347. 8@\MS-DOS
  2348.  
  2349. 9@\UCSD p-System
  2350.  
  2351. A@\MUMPS
  2352.  
  2353. B@\LISP
  2354.  
  2355. C@\FORTH
  2356.  
  2357. D@\OS-9
  2358. @end<description>
  2359. @end<description>
  2360.  
  2361. / (ASCII 47)@\Format of the data within the packets.
  2362. @begin<description>
  2363. A{xx}@\Variable length delimited records, terminated by the character sequence
  2364. {xx}, where xx is a string of one or more control characters, represented here
  2365. by their unprefixed printable equivalents, e.g. @q<MJ> for @q<^M^J> (CRLF).
  2366.  
  2367. D{x}@\Variable length undelimited records.  Each logical record begins with an
  2368. {x}-character ASCII decimal length field (similar to ANSI tape format "D").
  2369. For example, "@q<D$>" would indicate 4-digit length fields, like "0132".
  2370.  
  2371. F{xxxx}@\Fixed-length undelimited records.  Each logical record is
  2372. {xxxx} bytes long.
  2373.  
  2374. R{x}@\For record-@|oriented transfers, to be used in combination with one of
  2375. the formats given above.  Each record begins (in the case of D format, after
  2376. the length field) with an x-character long position field indicating the byte
  2377. position within the file at which this record is to be stored.
  2378.  
  2379. M{x}@\For record-@|oriented transfers, to be used in combination with one of
  2380. the formats given above.  Maximum record length for a variable-@|length record.
  2381.  
  2382. @end<description>
  2383.  
  2384. 0 (ASCII 48)@\Special system-dependent parameters for storing the file on the
  2385. system of origin, for specification of exotic attributes not covered explicitly
  2386. by any of the Kermit attribute descriptors.  These are given as a character
  2387. string in the system's own language, for example a list of DCB parameters in
  2388. IBM Job Control Language.
  2389.  
  2390. 1-@@ (ASCII 49)@\Exact byte count of the file as it is stored on the sender's
  2391. system, before any conversions (e.g. to canonic form).  Of limited usefulness
  2392. when transferring text files between systems that represent text boundaries
  2393. differently.
  2394.  
  2395. 2-@@ (ASCII 50-64)@\@i<Reserved>
  2396. @End(Description)
  2397. Other attributes can be imagined, and can be added later if needed.  However,
  2398. two important points should be noted:
  2399. @Begin(Itemize)
  2400. The receiver may have absolutely no way of honoring, or even recording, a given
  2401. attribute.  For instance, CP/M-80 has no slot for creation date or creator's ID
  2402. in its FCB; the DEC-20 has no concept of block size, etc.
  2403.  
  2404. The sender may have no way of determining the correct values of any of the
  2405. attributes.  This is particularly true when sending files of foreign origin.
  2406. @End(Itemize)
  2407.  
  2408. The "A" packet mechanism only provides a way to send certain information about
  2409. a file to the receiver, with no provision or guarantee about what the receiver
  2410. may do with it.  That information may be obtained directly from the file's
  2411. directory entry (FCB, FDB, @q<...>), or specified via user command.
  2412.  
  2413. The ACK to the "A" packet may in turn have information in its data field.
  2414. However, no complicated negotiations about file attributes may take place, so
  2415. the net result is that the receiver may either refuse the file or accept it.
  2416. The receiver may reply to the "A" packet with any of the following codes in the
  2417. data field of the ACK packet:
  2418. @Begin(Description,leftmargin +8, indent -8)
  2419. <null>@\(empty data field) I accept the file, go ahead and send it.
  2420.  
  2421. N[{xxx}]@\I refuse the file as specified, don't send it; {xxx} is a string of
  2422. zero or more of the attribute characters listed above, to specify what
  2423. attributes I object to (e.g. "@q<!>" means it's too long, "@q<&>" means I don't
  2424. have write access to the specified area, etc).
  2425.  
  2426. Y[{xxx}]@\I agree to receive the file, but I cannot honor attributes {xxx}, so
  2427. I will store the file according to my own defaults.
  2428.  
  2429. Y@\(degenerate case of Y{xxx}, equivalent to <null>, above)
  2430. @End(Description)
  2431.  
  2432. How the receiver actually replies is an implementation decision.  A NAK in
  2433. response to the "A" packet means, of course, that the receiver did not receive
  2434. the "A" correctly, not that it refuses to receive the file.
  2435.  
  2436. @Section<Advanced Kermit Protocol State Table>
  2437.  
  2438. The simple table presented previously is sufficient for a basic Kermit
  2439. implementation.  The following is a state table for the full Kermit protocol,
  2440. including both server mode and sending commands to a server Kermit.  It does
  2441. not include handling of the file attributes packet (A).  Note that states whose
  2442. names start with "Send" always send a packet each time they are entered (even
  2443. when the previous state was the same).  States whose name starts with "Rec",
  2444. always wait for a packet to be received (up to the timeout value), and process
  2445. the received packet.  States whose names do not include either send or receive
  2446. do not process packets directly.  These are states which perform some local
  2447. operation and then change to another state.
  2448.  
  2449. The initial state is determined by the user's command.  A "server" command
  2450. enters at @q<Rec_Server_Idle>.  A "send" command enters at @q<Send_Init>.  A
  2451. "receive" command (the old non-@|server version, not a "get" command) enters at
  2452. @q<Rec_Init>.  Any generic command, the "get" command, and the "host" command
  2453. enter at either @q<Send_Server_Init> or @q<Send_Gen_Cmd>, depending upon the
  2454. expected response.
  2455.  
  2456. Under "Rec'd Msg", the packet type of the incoming message is shown, followed
  2457. by the packet number in parentheses; (n) means the current packet number, (n-1)
  2458. and (n+1) mean the previous and next packet numbers (modulo 64), (0) means
  2459. packet number zero. Following the packet number may be slash and a letter,
  2460. indicating some special signal in the data field.  For instance @t<Z(n)/D>
  2461. indicates a Z (EOF) packet, sequence number @i<n>, with a "D" in the data
  2462. field.
  2463.  
  2464. Under "Action", "@t<r+>" means that the retry count is incremented and compared
  2465. with a threshhold; if the threshhold is exceeded, an Error packet is sent and
  2466. the state changes to "Abort".  "@t<n+>" means that the packet number is
  2467. incremented, modulo 64, and the retry count, @i<r>, is set back to zero.  
  2468.  
  2469. @begin<example, group, blanklines hinge, leftmargin 0>
  2470. @u<State>   @ux<Rec'd Msg>       @u<Action>                  @ux<Next state>
  2471.  
  2472. Rec_Server_Idle -- @i<Server idle, waiting for a message>
  2473.  
  2474.     Set n and r to 0
  2475.  
  2476.         I(0)            Send ACK                Rec_Server_Idle
  2477.         S(0)            Process params,
  2478.                          ACK with params, n+    Rec_File
  2479.         R(0)            Save file name          Send_Init
  2480.  
  2481.         K, C or G(0)    Short reply:
  2482.                          ACK(0)/reply           Rec_Server_Idle
  2483.                         Long reply: 
  2484.                          init needed            Send_Init
  2485.                          init not needed, n+    Open_File 
  2486.  
  2487.         Timeout         Send NAK(0)             Rec_Server_Idle
  2488.         Other           Send E                  Rec_Server_Idle
  2489. @hinge
  2490.  
  2491. Rec_Init -- @i<Entry point for non-server RECEIVE command>
  2492.  
  2493.     Set n and r to 0
  2494.  
  2495.         S(0)            Process params, send
  2496.                          ACK with params, n+    Rec_File
  2497.         Timeout         Send NAK(0), r+         Rec_Init
  2498.         Other           Send E                  Abort
  2499. @hinge
  2500.  
  2501. Rec_File -- @i<Look for a file header or EOT message>
  2502.  
  2503.         F(n)            Open file, ACK, n+      Rec_Data
  2504.         X(n)            Prepare to type on
  2505.                          screen, ACK, n+        Rec_Data
  2506.         B(n)            ACK                     Complete
  2507.         S(n-1)          ACK with params, r+     Rec_File
  2508.         Z(n-1)          ACK, r+                 Rec_File
  2509.         Timeout         Resend ACK(n), r+       Rec_File
  2510.         Other           Send E                  Abort
  2511. @hinge
  2512.  
  2513. Rec_Data -- @i<Receive data up to end of file>
  2514.  
  2515.         D(n)            Store data, ACK, n+;
  2516.                          If interruption wanted
  2517.                          include X or Z in ACK  Rec_Data
  2518.         D(n-1)          Send ACK, r+            Rec-Data
  2519.         Z(n)            Close file, ACK, n+     Rec_File
  2520.         Z(n)/D          Discard file, ACK, n+   Rec_File
  2521.         F(n-1)          Send ACK, r+            Rec_Data
  2522.         X(n-1)          Send ACK, r+            Rec_Data
  2523.         Timeout         Send ACK(n-1), r+       Rec_Data
  2524.         Other           Send E                  Abort
  2525. @hinge
  2526.  
  2527.  
  2528. Send_Init -- @i<Also entry for SEND command>
  2529.  
  2530.     Set n and r to 0, send S(0) with parameters
  2531.  
  2532.         Y(0)            Process params, n+      Open_File
  2533.         N, Timeout      r+                      Send_Init
  2534.         Other           r+                      Send_Init
  2535. @hinge
  2536.  
  2537. Open_File -- @i<Open file or set up text to send>
  2538.  
  2539.                                                 Send_File
  2540. @hinge
  2541.  
  2542. Send_File -- @i<Send file or text header>
  2543.  
  2544.     Send F or X(n)
  2545.  
  2546.         Y(n), N(n+1)    Get first buffer of     Send_Data or Send_Eof if
  2547.                          data, n+                empty file or text
  2548.         N, Timeout      r+                      Send_File
  2549.         Other                                   Abort
  2550. @hinge
  2551.  
  2552. Send_Data -- @i<Send contents of file or textual information>
  2553.  
  2554.     Send D(n) with current buffer
  2555.  
  2556.         Y(n), N(n+1)    n+, Get next buffer     Send_Data or Send_Eof if
  2557.                                                  at end of file or text
  2558.         Y(n)/X or Z     n+                      Send_Eof    
  2559.         N, Timeout      r+                      Send_Data
  2560.         Other                                   Abort
  2561. @hinge
  2562.  
  2563. Send_Eof -- @i<Send end of file indicator>
  2564.  
  2565.     Send Z(n); if interrupting send Z(n)/D
  2566.  
  2567.         Y(n), N(n+1)    Open next file, n+      Send_File if more, or
  2568.                                                 Send_Break if no more
  2569.                                                  or if interrupt "Z".
  2570.         N, Timeout      r+                      Send_Eof
  2571.         Other                                   Abort
  2572. @hinge
  2573.  
  2574. Send_Break -- @i<End of Transaction>
  2575.  
  2576.     Send B(n)
  2577.  
  2578.         Y(n), N(0)                              Complete
  2579.         N(n), Timeout                           Send_Break
  2580.         Other                                   Abort
  2581. @hinge
  2582.  
  2583. Send_Server_Init - @i<Entry for Server commands which expect large response.>
  2584.  
  2585.     Send I(0) with parameters
  2586.  
  2587.         Y(0)            Process params          Send_Gen_Cmd
  2588.         N, Timeout      r+                      Send_Server_Init
  2589.         E               Use default params      Send_Gen_Cmd
  2590.         Other                                   Abort
  2591. @hinge
  2592.  
  2593. Send_Gen_Cmd - @i<Entry for Server commands which expect short response (ACK)>
  2594.  
  2595.     Send G, R or C(0)
  2596.  
  2597.         S(0)            Process params,      
  2598.                          ACK with params, n+    Rec_File
  2599.         X(1)            Setup to type on
  2600.                          terminal, n+           Rec_Data
  2601.         Y(0)            Type data on TTY        Complete
  2602.         N, Timeout      r+                      Send_Gen_Cmd
  2603.         Other                                   Abort
  2604. @hinge
  2605.  
  2606. Complete -- @i<Successful Completion of Transaction>
  2607.  
  2608.         Set n and r to 0;
  2609.         If server, reset params, enter Rec_Server_Idle
  2610.         otherwise exit
  2611. @hinge
  2612.  
  2613. Abort -- @i<Premature Termination of Transaction>
  2614.  
  2615.     Reset any open file, set n and r to 0
  2616.  
  2617.         If server, reset params, enter Rec_Server_Idle
  2618.         otherwise exit
  2619. @hinge
  2620.  
  2621. Exit, Logout states
  2622.         Exit or Logout
  2623. @hinge
  2624. @end<example>
  2625.  
  2626. Note that the generic commands determine the next state as follows:
  2627. @begin<enumerate>
  2628. If the command is not supported, an error packet is sent and  the  next
  2629. state is "Abort".
  2630.  
  2631. If the command generates a response which can  be  fit  into  the  data
  2632. portion  of  an ACK, an ACK is sent with the text (quoted as necessary)
  2633. in the data portion.
  2634.  
  2635. If the command generates a large response or must send a file,  nothing
  2636. is  sent  from  the @q<Rec_Server_Idle> state, and the next state is either
  2637. @q<Send_Init> (if either no I message was received or  if  alternate  block
  2638. check types are to be used), or @q<Open_File> (if an I message was received
  2639. and the single character block check is to be used).
  2640.  
  2641. If the command is Logout, an ACK is sent and the new state is Logout.
  2642.  
  2643. If the command is Exit, an ACK is sent and the new state is Exit.
  2644. @end<enumerate>
  2645.  
  2646. @chapter<Performance Extensions>
  2647.  
  2648. The material in this chapter was added in 1985-86 to address the inherent
  2649. performance problems of a stop-and-wait protocol like Kermit.
  2650.  
  2651. @section<Long Packets>
  2652. @label<-longp>
  2653.  
  2654. @index<Long Packet Extension>
  2655. A method is provided to allow the formation of long Kermit packets.
  2656. Questions as to the desirability or appropriateness of this extension to the
  2657. Kermit protocol are not addressed.  All numbers are in decimal (base 10)
  2658. notation, all arithmetic is integer arithmetic.
  2659.  
  2660. In order for long packets to be exchanged, the sender must set the bit for
  2661. Capability #5 (the LONGP bit) in the CAPAS field of the Send-Init (S or I)
  2662. packet,
  2663. @begin<example,group>
  2664.  bit5 bit4 bit3 bit2 bit1 bit0
  2665. +----+----+----+----+----+----+
  2666. | #1 | #2 | #3 | #4 | #5 |  0 |
  2667. +----+----+----+----+----+----+
  2668.                        ^
  2669.                        |
  2670.                      LONGP
  2671. @end<example>
  2672. and also furnish the MAXLX1 and MAXLX2 (extended length 1 and 2) fields, as
  2673. follows:
  2674. @begin<example,leftmargin 0,group>
  2675.         10              CAPAS+1  CAPAS+2  CAPAS+3
  2676.     ---+-------+-     -+--------+--------+--------+
  2677.        | CAPAS |  ...  | WINDO  | MAXLX1 | MAXLX2 |
  2678.     ---+-------+-     -+--------+--------+--------+
  2679.                         ^
  2680.                         |
  2681.                       @r<(currently field 11, because CAPAS is still 1 byte)>
  2682. @end<example>
  2683. where WINDO is the window size (a separate Kermit protocol extension),
  2684. and MAXLX1 and MAXLX2 are each a printable ASCII character in the range SP
  2685. (space, ASCII 32) to ~ (tilde, ASCII 126), formed as follows:
  2686. @begin<example,group>
  2687. @r<MAXLX1> = tochar(@r<m> / @r<95>)
  2688. @r<MAXLX2> = tochar(@r<m> MOD @r<95>)
  2689. @end<example>
  2690. (where m is the intended maximum length, @q</> signifies integer division, and
  2691. @q<MOD> is the modulus operator), to indicate the longest extended-length
  2692. packet it will accept as input.  The receiver responds with an ACK packet
  2693. having the same bit also set in the CAPAS field, and with the MAXLX1 and MAXLX2
  2694. fields set to indicate the maximum length packet it will accept.
  2695.  
  2696. The maximum length expressible by this construct is 95 x 94 + 94, or 9024.
  2697.  
  2698. Since the sender can not know in advance whether the receiver is capable of
  2699. extended headers, the Send-Init MAXL field must also be set in the normal
  2700. manner for compatibility.
  2701.  
  2702. If the receiver responds favorably to an extended-length packet bid (that is,
  2703. if its ACK has the LONGP bit set in the CAPAS field), then the combined value
  2704. of its MAXLX1,MAXLX2 fields is used.  If the LONGP bit is set but the
  2705. MAXLX1,MAXLX2 pair is missing, then the value 500 will be used by default.
  2706.  
  2707. If the response is unfavorable (the LONGP bit is not set in the receiver's
  2708. CAPAS field), then extended headers will not be used and the MAXL field will
  2709. supply the maximum packet length.
  2710.  
  2711. After the Send-Init has been sent and acknowledged with agreement to allow
  2712. extended headers, all packets up to and including the B or E packet which
  2713. terminates the transaction (and its acknowledgement) are allowed -- but not
  2714. required -- to have extended headers; extended and normal packets may be freely
  2715. mixed by both Kermits.
  2716.  
  2717. The normal Kermit packet length field (LEN) specifies the number of bytes
  2718. to follow, up to and including the block check.  Since at least 3 bytes must
  2719. follow (SEQ, TYPE, and CHECK), a value of 0, 1, or 2 is never encountered
  2720. in the LEN field of a valid unextended Kermit packet.  When extended packets
  2721. have been negotiated, the LEN field is treated as follows for the duration of
  2722. the transaction:
  2723. @begin<itemize,spread 0>
  2724. If @q[unchar(LEN) >] 2 then the packet is a normal, unextended packet.
  2725.  
  2726. If @q[unchar(LEN) =] 0 then the packet has a "Type 0" extended header.
  2727.  
  2728. If @q[unchar(LEN) =] 1 or 2, the packet is invalid and should cause an Error. 
  2729. @end<itemize>
  2730. "Lengths" of 1 and 2 are reserved for future use in Type 1 and 2 extended
  2731. headers, yet to be specified.
  2732.  
  2733. A Type 0 extended packet has the following layout:
  2734. @begin<example,leftmargin 0,longlines keep,group>
  2735. +------+-----+-----+------+-------+-------+--------+----       ----+-------+
  2736. | MARK |     | SEQ | TYPE | LENX1 | LENX2 | HCHECK |  DATA ....    | CHECK |
  2737. +------+-----+-----+------+-------+-------+--------+----       ----+-------+
  2738.                           | Extended Header        |
  2739. @end<example>
  2740. The blank length field (SP = @q<tochar(0)>) indicates that the first 3 bytes of
  2741. what is normally the data field is now an extended header of Type 0, in which
  2742. the number of bytes remaining in the packet, up to and including the block
  2743. check, is
  2744. @begin<example,leftmargin 0>
  2745.     @i<extended-length> = (95 x unchar(LENX1)) + unchar(LENX2)
  2746. @end<example>
  2747. and HCHECK is a header checksum, formed exactly like a Type-1 Kermit block
  2748. check, but from the sum of the ASCII values of the SEQ, TYPE, LENX1, and
  2749. LENX2 fields:
  2750. @begin<example,leftmargin 0,group>
  2751.      @i<s> = LEN + SEQ + TYPE + LENX1 + LENX2
  2752.  
  2753.      HCHECK = tochar((@i<s> + ((@i<s> & 192)/64)) & 63)
  2754. @end<example>
  2755. where @q<&> is the bitwise AND operator.
  2756.  
  2757. Since the value of the extended length field must be known accurately in
  2758. order to locate the end of the packet and the packet block check, it is
  2759. vital that this information not be corrupted before it is used.  The header
  2760. checksum prevents this.
  2761.  
  2762. The extended header, like the normal header itself, is @i<not> prefix-encoded.
  2763. This is because it is used at datalink level, before decoding takes place.
  2764. Therefore the entity responsible for building packets must leave 3 spaces at
  2765. the beginning of the data field, and the datalink function (spack) fills in
  2766. LENX1, LENX2, and HCHECK based upon the data actually entered into the packet,
  2767. after encoding.  The packet receiving datalink function (rpack) behaves
  2768. accordingly.
  2769.  
  2770. The packet block check is formed in the usual manner, based on all packet bytes
  2771. beginning with LEN and ending with the last character in the data field.  The
  2772. block check may be Type 1, 2, or 3, depending upon what was negotiated, but
  2773. longer packets are more likely to be corrupted than shorter ones and should
  2774. therefore have higher-order block checks if possible.  This proposal does not
  2775. change the way block check type is negotiated, and does not require that Type
  2776. 2 or 3 block check be implemented.
  2777.  
  2778. With long packets, the possibility exists that the arithmetic sum of the
  2779. characters in a packet will exceed
  2780. @case[device,file="2^15",
  2781.     pagedfile="2^15",
  2782.     else="2@+<15>"], and will overflow a 16-bit word, or
  2783. become negative.  The checksum function would have to be modified to guard
  2784. against this, for instance by always setting the high four bits of the sum to
  2785. zero before adding in the next byte.
  2786.  
  2787. Implementation can be a bit tricky.  The Kermit program should be set up to
  2788. use normal, untextended packets by default -- that is, to mimic the behavior
  2789. of original, "classic" Kermit.  Even when the program believes itself to be
  2790. capable of sending and receiving long packets, it has no knowledge of what
  2791. devices may lie along the communication path, whose buffers might not be long
  2792. enough to accommodate bursts of data of the desired length.  Long packets
  2793. should be elected when the user has explicitly elected them with a SET command.
  2794. The current SET SEND PACKET-LENGTH <n> command will do; if the number is larger
  2795. than 94, then the program will -- transparently to the user -- try to negotiate
  2796. long packets.  A finer degree of control can be accomplished by included SET
  2797. commands to explicitly enable or disable the use of long packets.
  2798.  
  2799. Once long packets are successfully negotiated, the program should be prepared
  2800. to back off when errors occur, since the very size of the packets may be the
  2801. cause of the errors.  Upon timeout or receipt of a NAK (or extra copies of the
  2802. previous packet), the sender should be prepared to reconstruct the current
  2803. packet at, say, half its size, down to some reasonable minimum, before
  2804. retransmission.  Even when the size itself is not the problem, this makes
  2805. retransmission less painful under noisy conditions.
  2806.  
  2807. Long packets and sliding windows may be used at the same time, though the
  2808. benefits from doing so may not be worth the trouble of coding the dynamic
  2809. buffer allocation required (for n buffers of size m, negotiated at Send-Init
  2810. time).  It's also worth noting that the benefit/cost ratio of long packets
  2811. declines after a length of about 1000, at which point the benefit of additional
  2812. length is less than 1%, and the cost of retransmission is very high.
  2813.  
  2814. @section<Sliding Windows>
  2815. @label<-window>
  2816. @index<Window>@index<Sliding Window>
  2817. The sliding window extension to Kermit was proposed and developed by a group at
  2818. The Source Telecomputing in McLean, Virginia, led by Leslie Spira and including
  2819. Hugh Matlock and John Mulligan, who wrote the following material.  Like other
  2820. extensions, this one is designed for "upward compatibility" with Kermits that
  2821. do not support this extension.
  2822.  
  2823. The windowing protocol as defined for the Kermit file transfer protocol is
  2824. based on the main premise of continuously sending data packets up to the number
  2825. defined by a set window size.  These data packets are continuously acknowledged
  2826. by the receive side and the ideal transfer occurs as long as they are
  2827. transmitted with good checksums, they are transmitted in sequential order and
  2828. there are no lost data packets or acknowledgements.  The various error
  2829. conditions define the details of the windowing protocol and are best examined
  2830. on a case basis.
  2831.  
  2832. There are five stages that describe the overall sequence of events in the
  2833. Kermit protocol.  Three of these stages deviate from the original protocol in
  2834. order to add the windowing feature.  Stages 1 through 5 are briefly described
  2835. on the following page.  The three stages (1, 3 and 4) which deviate from the
  2836. original protocol are then described in greater detail in the pages that
  2837. follow.
  2838.  
  2839. @subsection<Overall Sequence of Events>
  2840.  
  2841. @begin<description,leftmargin +4,indent -4>
  2842. @uu<STAGE 1 - Propose and Accept Windowing>@\
  2843. The send side requests windowing in the transmission of the Send-Initiate (S)
  2844. packet.  The receive side accepts windowing by sending an acknowledgement (ACK
  2845. packet) for the Send-Initiate packet.
  2846.  
  2847. @uu<STAGE 2 - Send and Accept File-Header Packet>@\
  2848. The send side transmits the File-Header (F) packet and waits for the receive
  2849. side to acknowledge it prior to transmitting any data.
  2850.  
  2851. @begin<multiple>
  2852. @uu<STAGE 3 - Transfer Data>@\
  2853. The sending routine transmits Data (D) packets one after the other until the
  2854. protocol window is closed.  The receiving side ACKs good data, stores data to
  2855. disk as necessary and NAKs bad data.
  2856.  
  2857. When the sender receives an ACK, the window may be rotated and the next
  2858. packet sent.  If the sender receives a NAK, the data  packet  concerned
  2859. is retransmitted.
  2860. @end<multiple>
  2861.  
  2862. @begin<multiple>
  2863. @uu<STAGE 4 - Send and Accept End_of_File Packet>@\
  2864. As the sender is reading the file for data to send, it will eventually reach
  2865. the end of the file.  It then waits until all outstanding data packets have
  2866. been acknowledged, and then sends an End-of_File (Z) packet.
  2867.  
  2868. When the receive side gets the End-of-File packet it stores the rest of the
  2869. data to disk, closes the file, and ACKs the End-of_File packet.
  2870.  
  2871. The protocol then returns to Stage 2, sending and acknowledging any further
  2872. File-Header (F) packets.
  2873. @end<multiple>
  2874.  
  2875. @uu<STAGE 5 - End of Transmission>@\
  2876. Once the End-of-File packet has been sent and acknowledged and there are no
  2877. more files to send, the sender transmits the End-of-Transmission (B) packet in
  2878. order to end the ongoing transaction.  Once the receiver ACKs this packet, the
  2879. transaction is ended and the logical connection closed.
  2880. @end<description>
  2881.  
  2882. @subheading<Stage 1 - Propose and Accept Windowing>
  2883.  
  2884. The initial connection as currently defined for the Kermit protocol will need
  2885. to change only in terms of the contents of the Send-Initiate packet.  The
  2886. receiving Kermit waits for the sending Kermit to transmit the Send-Initiate (S)
  2887. packet and the sending packet does not proceed with any additional transmission
  2888. until the ACK has been returned by the receiver.
  2889.  
  2890. The contents of the Send-Init packet, however, will be slightly revised.  The
  2891. data field of the Send-Init packet currently contains all of the configuration
  2892. parameters.  The first six fields of the Send-Init packet are fixed as follows:
  2893. @begin<example,leftmargin 0>
  2894.    1        2        3        4        5        6
  2895.   +--------+--------+--------+--------+--------+--------+
  2896.   | MAXL   | TIME   | NPAD   | PADC   | EOL    | QCTL   |
  2897.   +--------+--------+--------+--------+--------+--------+
  2898. @end<example>
  2899. Fields 7  through  10  are  optional  features  of  Kermit and fields 7
  2900. through 9 will also  remain  unchanged  as  defined  for  the  existing
  2901. protocol:
  2902. @begin<example,leftmargin 0>
  2903.    7        8        9        10
  2904.   +--------+--------+--------+--------+
  2905.   | QBIN   | CHKT   | REPT   | CAPAS  |
  2906.   +--------+--------+--------+--------+
  2907. @end<example>
  2908.  
  2909. The windowing capability constitutes a fourth capability and the fourth bit
  2910. of the capability field will be set to 1 if the Kermit implementation can
  2911. handle windowing:
  2912. @begin<example>
  2913.  bit5 bit4 bit3 bit2 bit1 bit0
  2914. +----+----+----+----+----+----+
  2915. | #1 | #2 | #3 | #4 | #5 |  0 |
  2916. +----+----+----+----+----+----+
  2917.                   ^
  2918.                   |
  2919.                  SWC @r<(sliding window capability)>
  2920. @end<example>
  2921.  
  2922. The remaining fields of the Send-Init packet are  either  reserved  for
  2923. future use  by  the standard Kermit protocol or reserved for local site
  2924. implementations.  The four fields following the  capability  field  are
  2925. reserved for the standard Kermit protocol.  The field following the capability
  2926. mask is used to specify the "Window Size":
  2927. @begin<example,leftmargin 0>
  2928.         10              CAPAS+1  CAPAS+2  CAPAS+3
  2929.     ---+-------+-     -+--------+--------+--------+
  2930.        | CAPAS |  ...  | WINDO  | MAXLX1 | MAXLX2 |
  2931.     ---+-------+-     -+--------+--------+--------+
  2932.                         ^
  2933.                         |
  2934.                       @r<(currently field 11, because CAPAS is still 1 byte)>
  2935. @end<example>
  2936. WINDO is the window size to be used, encoded printably using the @q<tochar()>
  2937. function.  The window size may range from 1 to 31 inclusive.
  2938.  
  2939. The sender will specify the window size it wishes to use and the receiver will
  2940. reply (in the ACK packet) with the window size it wishes to use.  The window
  2941. size actually used will be the minimum of the two.  If the receiver replies
  2942. with a window size of 0 then no windowing will be done.
  2943.  
  2944. @subheading<Stage 3 - Transfer Data>
  2945.  
  2946. The sequence  of  events  required for the transmission of data packets
  2947. and confirmation of receipts  constitute  the  main  functions  of  the
  2948. windowing protocol.   There  are  four  main  functions  which  can  be
  2949. identified within this stage.  These are:
  2950. @begin<itemize,spread 0>
  2951. the sender's processing of the data packets,
  2952.  
  2953. the receiver's handling of incoming packets,
  2954.  
  2955. the sender's handling of the confirmations,
  2956.  
  2957. the error handling on both sides.
  2958. @end<itemize>
  2959. The following discussion details the specific actions required for each
  2960. of these functions.  Refer to the  state  table  at  the  end  of  this
  2961. document for  the  specific  action taken on a "received message" basis
  2962. for the full protocol.
  2963.  
  2964. @uu<The Sender's Processing of Data Packets>
  2965.  
  2966. The sender instigates the transmission by  sending  the  first  data
  2967. packet and  then  operating in a cyclical mode of sending data until
  2968. the defined window is closed.
  2969.  
  2970. Data to be sent must be read from the file, encoded into the  Kermit
  2971. Data packet, and saved in a Send-Table.  A Send-Table entry consists
  2972. of the  data  packet itself (which makes convenient the re-send of a
  2973. NAK'd packet), a bit which keeps track of  whether  the  packet  has
  2974. been ACK'd (the ACK'd bit), and a retry counter.  The table is large
  2975. enough to hold all the packets for the protocol window.
  2976.  
  2977. Before each transmission, the input buffer is checked and  input  is
  2978. processed, as  described  below.   Transmission  is  stopped  if the
  2979. protocol window "closes", that is, if the Send-Table is full.
  2980.  
  2981. @uu<The Receiver's Handling of Incoming Packets>
  2982.  
  2983. The receiver keeps its  own  table  as  it  receives  incoming  data
  2984. packets.  This  allows  the  receiver  to receive subsequent packets
  2985. while it is waiting for a re-send of an erroneous  or  lost  packet.
  2986. In other  words,  the incoming packets do not have to be received in
  2987. sequential order and can still be written to disk in order.
  2988.  
  2989. A Receive-Table entry consists of the data packet, a bit which keeps
  2990. track of whether a good version of the packet has been received (the
  2991. ACK'd bit), and a retry counter for the  NAKs  we  send  to  request
  2992. retransmissions of  the  packet.   The table is large enough to hold
  2993. all the packets for the protocol window.
  2994.  
  2995. The different possibilities for a received packet are:
  2996. @begin<enumerate,spread 0>
  2997. A new packet, the next sequential one (the usual case)
  2998.  
  2999. A new packet, not the next sequential one (some were lost)
  3000.  
  3001. An old packet, retransmitted
  3002.  
  3003. An unexpected data packet
  3004.  
  3005. Any packet with a bad checksum
  3006. @end<enumerate>
  3007. These are now discussed separately:
  3008. @begin<enumerate>
  3009. The next new packet has sequence number  <one  past  the  latest
  3010. table entry>.  The packet is ACK'd, and the Receive-Table is checked
  3011. for space.   If  it  is  full (already contains window_size entries)
  3012. then the oldest entry is written to disk.  (This entry  should  have
  3013. the ACK'd  bit set.  If not, the receiver aborts the file transfer.)
  3014. The received packet is then stored in the  Receive-Table,  with  the
  3015. ACK'd bit set.
  3016.  
  3017. If the packet received has sequence number  in  the  range  <two
  3018. past the  latest  table entry> to <window_size past the latest table
  3019. entry> then it is a new packet, but some have been lost.  (The upper
  3020. limit here represents the  highest  packet  the  sender  could  send
  3021. within its  protocol  window.  Note that the requirement to test for
  3022. this case is what limits the maximum  window_size  to  half  of  the
  3023. range of  possible  sequence numbers) We ACK the packet, and NAK all
  3024. packets that were skipped.  (The skipped packets are those from <one
  3025. past the latest table entry> to <one before  the  received  packet>)
  3026. The Receive-Table is then checked.  The table may have to be rotated
  3027. to accomodate the packet, as with case 1.  (This time, several table
  3028. entries may  have  to  be written to disk.  As before, if any do not
  3029. have the ACK'd bit set, they will trigger an abort.)  The packet  is
  3030. then stored in the table, and the ACK'd bit set.
  3031.  
  3032. A retransmitted packet will have sequence number  in  the  range
  3033. <the oldest table entry> to <the latest table entry>.  The packet is
  3034. ACK'd, then placed in the table, setting the ACK'd bit.
  3035.  
  3036. A packet with sequence number outside of  the  range  from  <the
  3037. oldest table  entry> to <window_size past the latest table entry> is
  3038. ignored.
  3039.  
  3040. If the packet received  has  a  bad  checksum,  we  must  decide
  3041. whether to  generate  a  NAK,  and if so, with what sequence number.
  3042. The best action may depend on the configuration  and  channel  error
  3043. rate.  For  now,  we  adopt  the  following heuristic:  If there are
  3044. unACK'd entries in our Receive-Table, we send a NAK for  the  oldest
  3045. one.  Otherwise  we ignore the packet.  (Notice that this will occur
  3046. in a common case:  when things have  been  going  smoothly  and  one
  3047. packet gets  garbled.   In this case, when we later receive the next
  3048. packet we will NAK for this one as described under Case 2 above.)
  3049. @end<enumerate>
  3050.  
  3051. @uu<The Sender's Handling of Confirmations>
  3052.  
  3053. The sender's receipt of confirmations controls the rotation  of  the
  3054. Send-Table and  normally returns the sender to a sending state.  The
  3055. sender's action  depends  on  the  packet  checksum,  the  type   of
  3056. confirmation (ACK  or  NAK),  and whether the confirmation is within
  3057. the high and low boundaries of the Send-Table.
  3058.  
  3059. If the checksum is bad the packet is ignored.
  3060.  
  3061. When the sender receives an ACK, the sequence  number  is  examined.
  3062. If the  sequence  number is outside of the current table boundaries,
  3063. then the ACK is also ignored.  If the sequence number is  inside  of
  3064. the current  table  boundaries then the ACK'd bit for that packet is
  3065. marked.  If the entry  is  at  the  low  boundary,  this  enables  a
  3066. "rotation" of  the  table.   The low boundary is changed to the next
  3067. sequential entry for which the ACK'd bit is  not  set.   This  frees
  3068. space in the table to allow further transmissions.
  3069.  
  3070. When the sender receives a NAK, the table boundaries are checked.  A
  3071. NAK outside  of  the  table boundary is ignored and a NAK inside the
  3072. table boundary indicates that the sender must  re-send  the  packet.
  3073. The sender  first tests the packet's retry counter against the retry
  3074. threshold.  If the threshold has been reached, then the transfer  is
  3075. stopped (by going to the Abort state).  Otherwise, the retry counter
  3076. is incremented and the packet re-sent.
  3077.  
  3078. @uu<Error Handling for Both Sides>
  3079.  
  3080. Three situations  are  discussed  here:   Sender  timeout,  Receiver
  3081. timeout, and invalid packets.
  3082.  
  3083. If certain packets are lost, each side may "hang", waiting  for  the
  3084. other.  To  get  things  moving  when  this  happens each may have a
  3085. "timeout limit", the longest they will wait for something  from  the
  3086. other side.
  3087.  
  3088. If the sender's timeout condition is triggered, then  it  will  send
  3089. the oldest  unACK'd  packet.   This  will  be  the  first one in the
  3090. Send-Table.
  3091.  
  3092. If the receiver's timeout condition is triggered, then it will  send
  3093. a NAK  for the "most desired packet".  This is defined as either the
  3094. oldest unACK'd packet, or if none are unACK'd, then the next  packet
  3095. to be received (sequence number <latest table entry plus one>).  The
  3096. packet retry  count  is  not  incremented  by  this NAK;  instead we
  3097. depend on the timeout retry count, discussed next.
  3098.  
  3099. For either the sender  or  receiver,  the  timeout  retry  count  is
  3100. incremented each  time a timeout occurs.  If the timeout retry limit
  3101. is exceeded then the side  aborts  the  file  transfer.   Each  side
  3102. resets the retry count to zero whenever they receive a packet.
  3103.  
  3104. In addition, as with the existing Kermit, any invalid  packet  types
  3105. received by either side will cause an Error packet and stop the file
  3106. transfer.
  3107.  
  3108. @subheading<Stage 4 - Send and Accept End of File Packet>
  3109.  
  3110. There are  several  ways  to  end  the file transfer.  The first is the
  3111. normal way, when the sender encounters an  end-of-file  condition  when
  3112. reading the  file  to  get  a  packet  for transmission.  The second is
  3113. because of a sender side user interrupt.  The third  is  because  of  a
  3114. receiver side user interrupt.  Both of these cause the received file to
  3115. be discarded.   In  addition  either side may stop the transfer with an
  3116. Error packet if an unrecoverable error is encountered.
  3117.  
  3118. @uu<Normal End of File Handling>
  3119.  
  3120. When the sender reaches the end of file, it must wait until all data
  3121. packets have been acknowledged before sending  the  End-of-File  (Z)
  3122. packet.  To  do this it must be able to check the end-of-file status
  3123. when it processes ACKs.  If the ACK  causes  the  Send-Table  to  be
  3124. emptied and  the  end-of-file has been reached, then a transition is
  3125. made to the Send_Eof state which sends the End_of_File packet.
  3126.  
  3127. When the  receiver  gets  the  End_of_File  packet,  it  writes  the
  3128. contents of  the  Receive-Table  to  the file (suitably decoded) and
  3129. closes the file.  (If any entries do not have the ACK'd bit set,  or
  3130. if errors  occur  in  writing the file, the receiver aborts the file
  3131. transfer.)  If the operation is successful, the  receiver  sends  an
  3132. ACK.  It  then  sets  its  sequence number to the End_of_File packet
  3133. sequence number and goes to Rcv_File state.
  3134.  
  3135. @subheading<File Transfer Interruptions>
  3136. @begin<description,leftmargin +4,indent -4>
  3137. @begin<multiple>
  3138. @uu<Sender User Interrupt>@\
  3139. Whenever the sender checks for input from the data communications line, it
  3140. should also check for user input.  If that indicates that the file transfer
  3141. should be stopped, the sender goes directly to the Send_Eof state and sends an
  3142. End_of_File packet with the Discard indication.  It will not have to wait for
  3143. outstanding packets to be ACK'd.
  3144.  
  3145. When the receiver gets the End_of_File packet with the Discard indication it
  3146. discards the file, sets its sequence number to the End_of_File packet sequence
  3147. number, and goes to RcvFile state.
  3148. @end<multiple>
  3149.  
  3150. @begin<multiple>
  3151. @uu<Receiver User Interrupt>@\
  3152. Whenever the receiver checks for input from the data communications line, it
  3153. also should check for user input.  If that indicates that the file transfer
  3154. should be stopped, the receiver sets an "interrupt indication" of X (for "stop
  3155. this file transfer") or of Z (for "stop the batch of file transfers").  When
  3156. the receiver later sends an ACK, it places an X or Z in the data field.
  3157.  
  3158. When the sender gets this ACK, it goes to the Send_Eof state and sends the
  3159. End_of_File packet with the Discard indication, as above.
  3160.  
  3161. When the receiver gets the End_of_File packet with the Discard indication, it
  3162. discards the file, sets its sequence number to the End_of_File packet sequence
  3163. number, and goes to RcvFile state.
  3164. @end<multiple>
  3165. @end<description>
  3166.  
  3167. @subheading<Low Level Protocol Requirements>
  3168.  
  3169. The windowing protocol makes certain assumptions about the underlying
  3170. transmission and reception mechanism.
  3171.  
  3172. First, it must provide a full-duplex channel so that messages may be sent and
  3173. received simultaneously.
  3174.  
  3175. Second, it will prove advantageous to be able to buffer several received
  3176. messages at the low level before processing them at the Kermit level.  This is
  3177. for two reasons.  The first is that the Kermit windowing level of the protocol
  3178. may take a while to process one input, and meanwhile several others may arrive.
  3179. The second reason is to support XON/XOFF flow control.  If Kermit receives an
  3180. XOFF from the data communications line, it must wait for an XON before sending
  3181. its packet.  While it is waiting, the low level receive must be able to accept
  3182. input.  Otherwise a deadlock situation could arise with each side flow
  3183. controlled, waiting for the other.
  3184.  
  3185. @subheading<Kermit Windowing Protocol State Table>
  3186.  
  3187. The following table shows the inputs expected, the actions performed, and the
  3188. succeeding states for the Send_Data_Windowing and Rcv_Data_Windowing states.
  3189.  
  3190. If both sides agree on windowing in the Send Init exchange, then instead of
  3191. entering the old Send_Data or Rcv_Data states from Send_File or Rcv_File, we
  3192. enter the new Send_Data_Windowing or Rcv_Data_Windowing.
  3193. @begin<example,spacing 1,font smallbodyfont,leftmargin 0,rightmargin 0,
  3194.     need 30,group,blanklines hinge>
  3195. SEND_DATA_WINDOWING (SDW)
  3196.  
  3197. @ux<Rec'd Msg>                @u<Action>                          @ux<Next State>
  3198.  
  3199. No input/Window closed  (1) Wait for input                   SDW
  3200. No input/Window open    (2) Read file, encode packet,        SDW
  3201.                             Place in table, mark unACK'd,
  3202.                             Send packet
  3203.  
  3204. ACK/ X or Z             (3) set interrupt indicator (X/Z)  Send_Eof
  3205. ACK/outside table        -ignore-                            SDW
  3206. ACK/inside table        (4) mark pkt ACK'd,         SDW or Send_Eof
  3207.                             if low rotate table,
  3208.                             if file eof & table empty
  3209.                                then goto Send_Eof
  3210.  
  3211. NAK/outside table        -ignore-                            SDW
  3212. NAK/inside table        (5) test retry limit,                SDW
  3213.                             re-send DATA packet
  3214.  
  3215. Bad checksum            -ignore-                             SDW
  3216.  
  3217. Timeout                 (6) re-send oldest unACK'd pkt       SDW
  3218.  
  3219. User interrupt          (7) set interrupt indicator (X/Z)  Send_Eof
  3220.  
  3221. Other                   (8) send Error                      Quit
  3222.  
  3223. RCV_DATA_WINDOWING (RDW)
  3224.  
  3225. @ux<Rec'd Msg>                @u<Action>                          @ux<Next State>
  3226.  
  3227. DATA/new                (1) send ACK                         RDW
  3228.                             if table full: file & rotate
  3229.                             store new pkt in table
  3230. DATA/old                (2) send ACK, store in table         RDW
  3231. DATA/unexpected         -ignore-                             RDW
  3232.  
  3233. Z/discard               (3) discard file                   Rcv_File
  3234. Z/                      (4) write table to file & close    Rcv_File
  3235.                             if OK send ACK, else Error     or Quit
  3236.  
  3237. Bad checksum            (5) send NAK for oldest unACK'd      RDW
  3238.  
  3239. Timeout                 (6) send NAK for most desired pkt    RDW
  3240.  
  3241. User Interrupt          (7) Set interrupt indicator X or Z   RDW
  3242.  
  3243. Other                   (8) send Error pkt                  Quit
  3244. @end<example>
  3245.  
  3246. @subsection<Questions and Answers about Sliding Windows>
  3247.  
  3248. @begin<description,leftmargin +4,indent -4>
  3249. @B<Q.>@\What is the purpose of the "windowing" extension?
  3250.  
  3251. @B<A.>@\The object is to speed up file transfers using Kermit.  The increase
  3252. will be especially noticeable over the data networks (such as Telenet
  3253. and Tymnet) and over connections using satellite links.  This is
  3254. because there are long communications delays over these connections.
  3255.  
  3256. @B<Q.>@\How does it work?
  3257.  
  3258. @B<A.>@\Basically, it allows you to send several packets out in a row before
  3259.     getting the first acknowledgment back.  The number of packets that can
  3260.     be sent out is set by the "window size", hence the name windowing.
  3261.  
  3262. @B<Q.>@\Could you explain in more detail?
  3263.  
  3264. @begin<multiple>
  3265. @B<A.>@\Right now, a system sending a file transmits one packet of data, then
  3266. does nothing more until it gets back an acknowledgment that the packet
  3267. has been received.  Once it gets an acknowledgment, it sends the next
  3268. packet of data.  Over standard direct-dial land-based phone lines, the
  3269. transmission delays are relatively small.  However, the public data
  3270. networks or satellite links can introduce delays of up to several
  3271. seconds round trip.  As a result, the sending system ends up spending
  3272. much more time waiting than actually sending data.
  3273.  
  3274. With the new windowing enhancement, the sending system will be able to
  3275. keep sending data continuously, getting the acknowledgments back
  3276. later.  It only has to stop sending data if it reaches the end of the
  3277. current "window" without getting an acknowledgment for the first
  3278. packet in the current "window".
  3279. @end<multiple>
  3280.  
  3281. @B<Q.>@\What size is the "window"?
  3282.  
  3283. @begin<multiple>
  3284. @B<A.>@\The window size can vary depending on what the two ends of the
  3285. connection agree on.  The suggested standard window size will be 8
  3286. packets.  The maximum is 31 packets.
  3287.  
  3288. The Kermit sequence numbering is modulo 64 (it "wraps" back to the 1st
  3289. sequence number after the 64th sequence number).  It is helpful to
  3290. limit the maximum window size to 31 to avoid problems (ambiguous
  3291. sequence numbers) under certain error conditions.
  3292. @end<multiple>
  3293.  
  3294. @B<Q.>@\Is windowing in effect throughout a Kermit session?
  3295.  
  3296. @B<A.>@\No, it is only in effect during the actual data transfer (data
  3297. packets) portion of a file transfer.  Windowing begins with the first
  3298. data packet (D packet type), and stops when you get an End-of-File
  3299. packet (Z packet type).
  3300.  
  3301. @B<Q.>@\Why does it stop when you get to the End-of-File packet?
  3302.  
  3303. @B<A.>@\This is done primarily to avoid having more than one file open at
  3304. once.
  3305.  
  3306.  
  3307. @B<Q.>@\Why will windowing be especially helpful at higher baud rates over
  3308. communications paths that have delays?
  3309.  
  3310. @begin<multiple>
  3311. @B<A.>@\As you increase the baud rate, the transmission speed of the data
  3312. increases, but you do not change the delay caused by the
  3313. communications path.  As a result, the delay becomes more and more
  3314. significant.
  3315.  
  3316. Assume, for example, that your communications path introduces a delay
  3317. of 1 second each way for packets, for a total delay of 2 seconds round
  3318. trip.  Assume also that your packets have 900 bits in them so it takes
  3319. you 3 seconds to send a packet at 300 baud (this is roughly equivalent
  3320. to a typical Kermit packet).
  3321.  
  3322. WITHOUT windowing, here is what happens:
  3323.  
  3324. If at 300 baud you transmitted data for 3 seconds (sending 900 bits),
  3325. then waited 2 seconds for each acknowledgment, your throughput would
  3326. be roughly 180 baud.  (Total time for each transmission = 5 seconds.
  3327. 900/5 = 180).
  3328.  
  3329. However, if you went to 2400 baud, you would transmit data for 3/8
  3330. second, then wait 2 seconds for an acknowledgment.  (Total time for
  3331. each transmission = 2 and 3/8 seconds).  The throughput would increase
  3332. only to about 378 baud. (900 / 2.375 = 378).
  3333.  
  3334. The delay becomes the limiting factor; in this case, with this packet
  3335. size, the delay sets an outside limit of 450 baud (900 / 2 second
  3336. delay = 450), no matter how fast the modem speed.
  3337.  
  3338. WITH windowing, the throughput should be close to the actual
  3339. transmission speed.  It should be possible to send data nearly
  3340. continuously.  The exact speed will depend on the window size, length
  3341. of transmission delays, and error rate.
  3342. @end<multiple>
  3343.  
  3344. @B<Q.>@\Are there any new packet types introduced by this extension?
  3345.  
  3346. @B<A.>@\No, the only change is to the contents of the Send-Init packet, to
  3347. arrange for windowing if both sides can do it.  If either side cannot,
  3348. Kermit will work as it does now.  Adding an extension such as this was
  3349. provided for in the original Kermit definition.  See section 3 of the
  3350. windowing definition for details.
  3351.  
  3352. @B<Q.>@\On the receive side, in section 4.2, why does the definition say that
  3353. writing to disk is done when the Receive-Table becomes full rather
  3354. than as soon as you get a good packet?
  3355.  
  3356. @begin<multiple>
  3357. @B<A.>@\The definition was phrased this way because it makes the logic of the
  3358. receive side clearer and simpler to implement.
  3359.  
  3360. Actually, you could also write a packet to disk when it is a good
  3361. packet and it is the earliest entry in the receive table.  This
  3362. approach has the disadvantage that you don't know at this point that
  3363. the sender has received your ACK, so you have to be prepared to handle
  3364. the same packet later on if the sender never gets the ACK, times out,
  3365. and sends the same packet again.  Thus you have to be prepared to deal
  3366. with packets previous to the current window; you will have to ACK such
  3367. a packet if it has been received properly before.
  3368.  
  3369. By writing packets to disk only when the receive table becomes full,
  3370. (the oldest packet) you know that the sender has received your ACK
  3371. (otherwise the sender could not have rotated the window to the n+1
  3372. position to send the current packet, where n is the window size).
  3373. This makes it very easy to stay in synch with the sender.  The
  3374. disadvantage of this approach is that when you receive the End-of-File
  3375. packet, you have to take the time to write all the remaining packets
  3376. in the Receive-Table to disk.
  3377. @end<multiple>
  3378.  
  3379. @B<Q.>@\Could you briefly explain what happens if a single packet gets corrupted?
  3380.  
  3381. @begin<multiple>
  3382. @B<A.>@\In essence, the receiver will ignore the bad packet.  When it gets the
  3383. next good packet, it will realize (because packets are numbered) that
  3384. one or more packets were lost, and NAK those packets.  The receiver
  3385. continues to accept good data.
  3386.  
  3387. As long as the sender's window does not become "blocked", the only
  3388. loss of throughput will be the time it takes to transmit the NAK'd
  3389. packets.
  3390. @end<multiple>
  3391.  
  3392. @B<Q.>@\There are currently two proposals for Kermit extensions: the Windowing
  3393. extension and a proposal for extended packet lengths.  What are the
  3394. relative advantages and disadvantages of sliding windows and extended
  3395. packet lengths?
  3396.  
  3397. @begin<multiple>
  3398. @B<A.>@\What is best depends on the exact conditions and systems involved in a
  3399. particular file transfer.  There are some general rules however.
  3400.  
  3401. Windowing helps more and more as the communications path delays get longer.
  3402.  
  3403. Windowing is also more and more helpful as the baud rate goes up.
  3404.  
  3405. Increased packet length is most helpful on circuits with low error
  3406. rates.  If the error rate is high, it is difficult for a long packet
  3407. to get through uncorrupted.  Also, it then takes longer to re-transmit
  3408. the corrupted packet.
  3409.  
  3410. On some machines, the CPU time to process a packet is relatively
  3411. constant no matter what the packet length, so longer packets can
  3412. reduce CPU time.
  3413. @end<multiple>
  3414.  
  3415. @B<Q.>@\Are extended packet lengths and sliding windows mutually exlusive?
  3416.  
  3417. @begin<multiple>
  3418. @B<A.>@\No, there is no real reason that they would have to be.  As a
  3419. practical matter, it is slightly easier to implement windowing if you
  3420. know the maximum packet size ahead of time, since you can then just
  3421. use an array to store your data.  In standard Kermit, you know
  3422. automactically that your maximum packet length is 94, so you can just
  3423. go ahead and dimension an array at 94 by Window-size.
  3424.  
  3425. If you are going to use both extended packet length and windowing, you
  3426. need to select the maximum packet length and window-size so that the
  3427. combination does not exceed the available memory for each side of the
  3428. transfer.
  3429.  
  3430. In addition, it is possible to see the desired relationship between
  3431. packet size and windowing for various baud rates and communications
  3432. delays.  For the common case of an error corrected by one
  3433. retransmission of the corrupted packet, the minimum window size needed
  3434. for continuous throughput (the window never gets "blocked") can be
  3435. calculated by:
  3436. @begin<example,leftmargin 0,group,need 5>
  3437.                     4 x delay x baud rate
  3438.       WS  >   1 +  ------------------------
  3439.                        packet-size x 10          @r<(this is the # of bits)>
  3440. @end<example>
  3441. Windowing always helps (the minimal continuous throughput window size
  3442. is always greater than 1).
  3443.  
  3444. In the above equation, the "4" derives from the fact that a corrupted
  3445. packet has 4 transit times involved:
  3446. @begin<itemize,spread 0>
  3447. Original (bad checksum) packet
  3448.  
  3449. NAK for the packet
  3450.  
  3451. Retransmission of packet
  3452.  
  3453. ACK for retransmission.
  3454. @end<itemize>
  3455. All of this must happen before the window becomes blocked.
  3456.  
  3457. The "delay" is the effective maximum one-way communications path
  3458. delay, which includes any CPU delays.
  3459.  
  3460. Strictly speaking, the "packet-size" should have the length of the ACK
  3461. packets added to it.
  3462.  
  3463. As an example, if you assume a 2-second (one-way) delay, at 1200 baud,
  3464. with a packet size of 94, the minimum window size for continuous
  3465. throughput would be:
  3466. @begin<example,leftmargin 0,group,need 5>
  3467.               4 x 2 x 1200
  3468.        WS  >  ------------    =   10.2
  3469.                 94 x 10
  3470. @end<example>
  3471. Under these circumstances, a window size of at least 11 should be
  3472. chosen, if possible.
  3473. @end<multiple>
  3474. @end<description>
  3475.  
  3476. @subsection<More Q-and-A About Windows>
  3477.  
  3478. While reading the following questions and answers, keep in mind that the
  3479. Kermit windowing definiton was developed to handle a common situation of long
  3480. circuit delays with possible moderate error rates.  Kermit does not need
  3481. this type of extension for clean lines with insignificant delays - Kermit
  3482. could be left alone, or use Extended Packet Lengths, in such environments.
  3483.  
  3484. Long delays with significant error rates will occur under two obvious and
  3485. common conditions:
  3486. @begin<enumerate>
  3487. Local phone line (of uncertain quality) to Public Data Networks
  3488. (such as Telenet).
  3489.  
  3490. Satellite phone links.  These often occur with the lower-priced
  3491. phone services, which often also have noisier lines.  In
  3492. addition, satellite links will increase as more people need to
  3493. transfer data overseas.
  3494. @end<enumerate>
  3495. The above conditions will become more common, as well increased baud
  3496. rates, which make the delays more significant.
  3497.  
  3498. As an aside, note that the benefit of Extended Packet Lengths over the
  3499. Public Data Networks is limited by the number of outstanding bytes the PDN
  3500. allows.  (Internally, the PDNs require end-to-end acknowledgement.  They
  3501. use their own windowing system within the network.)  I don't currently
  3502. know the exact impact of this.
  3503.  
  3504. Now on to the questions...
  3505. @begin<description,leftmargin +4,indent -4>
  3506. @B<Q.>@\Can sliding windows be done on half-duplex channels?  Are any
  3507. modifications to the proposal required?
  3508.  
  3509. @begin<multiple>
  3510. @B<A.>@\An underlying assumption in the development of windowing was that
  3511. there was a full-duplex channel.
  3512.  
  3513. The intent of windowing is to try to keep the sender continuously
  3514. sending data.  Obviously, this is not possible on a half-duplex
  3515. channel.  A better solution for half-duplex channels would be to use
  3516. an extended packet length.
  3517.  
  3518. An attempt to use windowing on half-duplex really is just a way of
  3519. doing extended packet lengths.  The sender would send out a group of
  3520. packets, then wait and get a group of ACKS.  It would be better to
  3521. simply send out a large packet, which would have less overhead.
  3522. @end<multiple>
  3523.  
  3524. @B<Q.>@\Is the cost in complexity for sliding windows worth the increase in
  3525. performance?
  3526.  
  3527. @begin<multiple>
  3528. @B<A.>@\Under the conditions described above (long delays and possibly
  3529. significant error rates) windowing can increase performance by a
  3530. factor of 2, 3, or more, especially at higher baud rates.  This
  3531. increase is necessary to make Kermit viable under some conditions.
  3532. With classic Kermit over the Public Data Networks, I have had
  3533. througput as low as 250 baud over a 1200 baud circuit (with a
  3534. negligible error rate).  Windowing should allow throughput close to
  3535. the maximum baud rate.
  3536.  
  3537. Windowing is most helpful when the delay is significant in relation to
  3538. data sending time.  Any delay becomes more significant as users move
  3539. to higher baud rates (2400 baud and beyond).
  3540.  
  3541. The complexity of implementing windowing has yet to be fully
  3542. evaluated.  The first implementation (for the IBM PC using C-Kermit)
  3543. proved to be fairly manageable.  It appears that the windowing logic
  3544. can be implemented so that Kermit Classic uses the same code, but with
  3545. a window size of 1, which should avoid having to keep separate
  3546. sections of code.
  3547.  
  3548. The windowing definiton was developed with the idea of keeping changes
  3549. to Kermit to a minimum.  No new packet types were developed, ACKs and
  3550. NAKS were kept the same, and windowing is in effect only during actual
  3551. data transfer (D packets).  We tried to define the protocol so that a
  3552. window size of 1 was the same as the current classic Kermit.
  3553.  
  3554. These factors should help reduce the complexity of implementing
  3555. windowing.  We currently have a working implementation of Kermit for
  3556. the IBM PC going through testing.
  3557.  
  3558. It's fun to see the modem "Send" light stay on constantly!
  3559. @end<multiple>
  3560.  
  3561. @B<Q.>@\Why doesn't the Windowing proposal use a "bulk ACK"?
  3562.  
  3563. @begin<multiple>
  3564. @B<A.>@\There are a couple of possibilities for ways to use some sort of
  3565. "bulk" or combined ACK.  We looked at them when developing the
  3566. Windowing definition.  We did not see any advantages that outweighed
  3567. the disadvantages.
  3568.  
  3569. Here are two possible ways of changing how ACKs would work:
  3570. @begin<enumerate>
  3571. An ACK for any packet would also ACK all previous packets.  The concept that an
  3572. ACK would also ACK all previous packets seems attractive at first, since it
  3573. would appear to reduce overhead.  However, it has a major drawback in that you
  3574. then must re-synch when you get errors.  This is because, once you have an
  3575. error, you have to send a NAK, then stop and wait for a re-transmission of the
  3576. NAK'd packet, before you send out any more ACKs.  (If you sent out an ACK for a
  3577. later packet, it would imply that you had received the NAK'd packet.  Not until
  3578. you safely get the re-transmission can you go ahead.)  This would negate one of
  3579. the nicest parts of windowing as it is defined now, which is that the sender
  3580. can transmit continuously, including during error recovery, as long as the
  3581. window does not become blocked.  It does not appear to us that the reduction in
  3582. the number of ACKs sent is worth this penalty.  In addition, this is a
  3583. departure from the way ACKs in Kermit work now.  It seemed best to make as few
  3584. changes to Kermit as possible.  If this facility turns out to be useful, it
  3585. would be better to introduce a new packet type (or other means of
  3586. distinguishing regular ACKs from "Bulk ACKS").
  3587.  
  3588. A new "Bulk ACK" packet type could be developed.  This did not seem to us to be
  3589. a good idea, since it required defining a new packet type.  We were trying to
  3590. fit windowing in with as few changes to Kermit as possible.  A "Bulk ACK", in
  3591. which one packet could contain a whole string of ACKs and NAKs, also seems like
  3592. a good idea at first.  The penalty here is a little more subtle.  First, if you
  3593. lose a "Bulk ACK" packet, you lose more information and it takes longer to get
  3594. things flowing smoothly again.  Second, and probably more importantly,
  3595. efficient windowing depends on the window never becoming "blocked" (i.e., the
  3596. sender can always keep sending).  A "Bulk ACK" interferes with this to some
  3597. extent, because if you have a long delay, the "Bulk ACK" with its multiple
  3598. individual ACKs may not get back to the sender in time to prevent the window
  3599. from becoming blocked.  With the current definition of windowing, returning an
  3600. ACK for each packet gets the ACKs (or NAKs) to the sender as soon as possible.
  3601. This provides the best chance for keeping the window open so that the sender
  3602. can transmit continually.  Once again, remember the conditions under which
  3603. windowing is most useful: long delays with significant error rates.  Under
  3604. these conditions, individual ACKs have advantages.  If these conditions don't
  3605. apply, it may not be necessary to use windowing, or it may be better to use
  3606. extended packet lengths.
  3607. @end<enumerate>
  3608. @end<multiple>
  3609. @end<description>
  3610.  
  3611. @Chapter<Kermit Commands>
  3612.  
  3613. The following list of Kermit commands and terms is suggested.  It is not
  3614. intended to recommend a particular style of command parsing, only to promote a
  3615. consistent vocabulary, both in documentation and in choosing the names for
  3616. commands.
  3617.  
  3618. @Section<Basic Commands>
  3619.  
  3620. @Begin(Description,leftmargin +8,indent -8)
  3621. SEND@\This verb tells a Kermit program to send one or more files from its own
  3622.   file structure.
  3623.  
  3624. RECEIVE@\This verb should tell a Kermit program to expect one or more files to
  3625.   arrive.
  3626.  
  3627. GET@\This verb should tell a user Kermit to send one or more files.  Some
  3628.   Kermit implementations have separate RECEIVE and GET commands; others use
  3629.   RECEIVE for both purposes, which creates confusion.
  3630. @End(Description)
  3631. Since it can be useful, even necessary, to specify different names for source
  3632. and destination files, these commands should take operands as follows (optional
  3633. operands in [brackets]):
  3634. @Begin(Description,leftmargin +8,indent -8)
  3635. SEND local-source-filespec [remote-destination-filespec]@\
  3636. If the destination file specification is included, this will go in the file
  3637. header packet, instead of the file's local name.
  3638.  
  3639. RECEIVE [local-destination-filespec]@\
  3640. If the destination filespec is given, the incoming file will be stored under
  3641. that name, rather than the one in the file header pakcet.
  3642.  
  3643. GET remote-source-filespec [local-destination-filespec]@\
  3644. If the destination filespec is given, the incoming file will be stored under
  3645. that name, rather than the one in the file header packet.
  3646. @End(Description)
  3647. If a file group is being sent or received, alternate names should @i<not> be
  3648. used.  It may be necessary to adopt a multi-line syntax for these commands
  3649. when filespecs may contain characters that are also valid command field
  3650. delimiters.
  3651.  
  3652. @Section<Program Management Commands>
  3653.  
  3654. @Begin(Description,leftmargin +8,indent -8)
  3655. EXIT@\Leave the Kermit program, doing whatever cleaning up must be done --
  3656. deassigning of devices, closing of files, etc.
  3657.  
  3658. QUIT@\Leave the Kermit program without cleaning up, in such a manner as to
  3659. allow further manipulation of the files and devices.
  3660.  
  3661. PUSH@\Preserve the current Kermit environment and enter the system command
  3662. processor.
  3663.  
  3664. TAKE@\Read and execute Kermit program commands from a local file.
  3665.  
  3666. LOG@\Specify a log for file transfer transactions, or for terminal session
  3667. logging.
  3668. @End(Description)
  3669.  
  3670. @Section<Terminal Emulation Commands>
  3671. @label<-emulation>
  3672.  
  3673. @Begin(Description,leftmargin +8,indent -8)
  3674. CONNECT@\This verb, valid only for a local Kermit, means to go into terminal
  3675. emulation mode; present the illusion of being directly connected as a terminal
  3676. to the remote system.  Provide an "escape character" to allow the user to "get
  3677. back" to the local system.  The escape character, when typed, should take a
  3678. single-@|character argument; the following are suggested:
  3679. @Begin(Description,leftmargin +8,indent -4,spread 0)
  3680. 0@\(zero) Transmit a NUL
  3681.  
  3682. B@\Transmit a BREAK
  3683.  
  3684. C@\Close the connection, return to local Kermit command level
  3685.  
  3686. P@\Push to system command processor
  3687.  
  3688. Q@\Quit logging (if logging is being done)
  3689.  
  3690. R@\Resume logging
  3691.  
  3692. S@\Show status of connection
  3693.  
  3694. ?@\Show the available arguments to the escape character
  3695.  
  3696. @i<(a second copy of the escape character)>:@ @ Transmit the escape
  3697. character itself
  3698. @End(Description)
  3699. Lower case equivalents should be accepted.  If any invalid argument is typed,
  3700. issue a beep.
  3701. @End(Description)
  3702. Also see the SET command.
  3703.  
  3704. @Section<Special User-Mode Commands>
  3705.  
  3706. These commands are used only by Users of Servers.
  3707.  
  3708. @Begin(Description,leftmargin +8,indent -8)
  3709. BYE@\This command sends a message to the remote server to log itself out, and
  3710. upon successful completion, terminate the local Kermit program.
  3711.  
  3712. FINISH@\This command causes the remote server to shut itself down gracefully
  3713. without logging out its job, leaving the local Kermit at Kermit command level,
  3714. allowing the user to re-CONNECT to the remote job. 
  3715. @End(Description) 
  3716.  
  3717. @Section<Commands Whose Object Should Be Specified>
  3718.  
  3719. Some Kermit implementations include various local file management services and
  3720. commands to invoke them.  For instance, an implementation might have commands
  3721. to let you get directory listings, delete files, switch disks, and inquire
  3722. about free disk space without having to exit and restart the program.  In
  3723. addition, remote servers may also provide such services.  A user Kermit must
  3724. be able to distinguish between commands aimed at its own system and those
  3725. aimed at the remote one.  When any confusion is possible, such a command may be
  3726. prefixed by one of the following "object prefixes":
  3727.  
  3728. @Begin(Description,leftmargin +8,indent -8)
  3729. REMOTE@\Ask the remote Kermit server to provide this service.
  3730.  
  3731. LOCAL@\Perform the service locally.
  3732. @End(Description) 
  3733.  
  3734. If the "object prefix" is omitted, the command should be executed locally.
  3735. The services include:
  3736.  
  3737. @Begin(Description,leftmargin +8,indent -8)
  3738. LOGIN@\This should be used in its timesharing sense, to create an identity
  3739. ("job", "session", "access", "account") on the system.
  3740.  
  3741. LOGOUT@\To terminate a session that was initiated by LOGIN.
  3742.  
  3743. COPY@\Make a new copy of the specified file with the specified name.
  3744.  
  3745. CWD@\Change Working Directory.  This is ugly, but more natural verbs like
  3746. CONNECT and ATTACH are too imprecise.  CWD is the ARPAnet file transfer
  3747. standard command to invoke this function.
  3748.  
  3749. DIRECTORY@\Provide a list of the names, and possibly other attributes, of the
  3750. files in the current working directory (or the specified directory).
  3751.  
  3752. DELETE@\Delete the specified files.
  3753.  
  3754. ERASE@\This could be a synomym for DELETE, since its meaning is clear.
  3755. @Begin(Quotation)
  3756. (It doesn't seem wise to include UNDELETE or UNERASE in the standard
  3757. list; most systems don't support such a function, and users' expectations
  3758. should not be toyed with...)
  3759. @End(Quotation)
  3760.  
  3761. KERMIT@\Send a command to the remote Kermit server in its own interactive
  3762. command syntax.
  3763.  
  3764. RENAME@\Change the name of the specified file.
  3765.  
  3766. TYPE@\Display the contents of the specified file(s) at the terminal.
  3767.  
  3768. SPACE@\Tell how much space is used and available for storing files in the
  3769. current working directory (or the specified directory).
  3770.  
  3771. SUBMIT@\Submit the specified file(s) for background (batch) processing.
  3772.  
  3773. PRINT@\Print the specified file(s) on a printer.
  3774.  
  3775. MOUNT@\Request a mount of the specified tape, disk, or other removable storage
  3776. medium.
  3777.  
  3778. WHO@\Show who is logged in (e.g. to a timesharing system), or give
  3779. information about a specified user or network host.
  3780.  
  3781. MAIL@\Send electronic mail to the specified user(s).
  3782.  
  3783. MESSAGE@\Send a terminal message (on a network or timesharing system).
  3784.  
  3785. HELP@\Give brief information about how to use Kermit.
  3786.  
  3787. SET@\Set various parameters relating to debugging, transmission, file mode,
  3788. and so forth.
  3789.  
  3790. SHOW@\Display settings of SET parameters, capabilities in force, etc.
  3791.  
  3792. STATISTICS@\Give information about the performance of the most recent file
  3793. transfer -- elapsed time, effective baud rate, various counts, etc.
  3794.  
  3795. HOST@\Pass the given command string to the specified (i.e. remote or local)
  3796. host for execution in its own command language.
  3797.  
  3798. LOGGING@\Open or close a transaction or debugging log.
  3799. @End(Description) 
  3800.  
  3801. @section<The SET Command>
  3802.  
  3803. A SET command should be provided to allow the user to tailor a connection to
  3804. the peculiarities of the communication path, the local or remote file system,
  3805. etc.  Here are some parameters that should be SET-able:
  3806. @Begin(Description,leftmargin +8,indent -8)
  3807. BLOCK-CHECK@\Specify the type of block check to be used: single character
  3808. checksum, two-@|character checksum, 3-@|character CRC.
  3809.  
  3810. DEBUGGING@\Display or log the packet traffic, packet numbers, and/or program
  3811. states.  Useful for debugging new versions of Kermit, novel combinations of
  3812. Kermit programs, etc.
  3813.  
  3814. DELAY@\How many seconds a remote (non-server) Kermit should wait before sending
  3815. the Send-Init packet, to give the user time to escape back to the local Kermit
  3816. and type a RECEIVE command.
  3817.  
  3818. DISPLAY@\Style of file transfer display (NONE, SERIAL, SCREEN, etc).
  3819.  
  3820. DUPLEX@\For terminal emulation, specify FULL or HALF duplex echoing.
  3821.  
  3822. END-OF-LINE@\Specify any line terminator that must be used after a packet.
  3823.  
  3824. ESCAPE@\Specify the escape character for terminal emulation.
  3825.  
  3826. FILE attributes@\
  3827. Almost any of the attributes listed above in the Attributes section
  3828. (@ref<-attributes>).  The most common need is to tell the Kermit program
  3829. whether an incoming or outbound file is text or binary.
  3830.  
  3831. FLOW-CONTROL@\Specify the flow control mechanism for the line, such as
  3832. XON/XOFF, ENQ/ACK, DTR/CTS, etc.  Allow flow control to be turned off (NONE) as
  3833. well as on.  Flow control is done only on full-@|duplex connections.
  3834.  
  3835. HANDSHAKE@\Specify any line-@|access negotiation that must be used or simulated
  3836. during file transfer.  For instance, a half duplex system will often need to
  3837. "turn the line around" after sending a packet, in order to give you permission
  3838. to reply.  A common handshake is XON (@q<^Q>); the current user of the line
  3839. transmits an XON when done transmitting data.
  3840.  
  3841. LINE@\Specify the line or device designator for the connection.  This is for
  3842. use in a Kermit program that can run in either remote or local mode; the
  3843. default line is the controlling terminal (for remote operation).  If an
  3844. external device is used, local operation is presumed.
  3845.  
  3846. LOG@\Specify a local file in which to keep a log of the transaction.  There may
  3847. be logs for debugging purposes (packet traffic, state transitions, etc) and for
  3848. auditing purposes (to record the name and disposition of each file
  3849. transferred).
  3850.  
  3851. MARKER@\Change the start-of-packet marker from the default of SOH (CTRL-A) to
  3852. some other control character, in case one or both systems has problems using
  3853. CTRL-A for this purpose.
  3854.  
  3855. PACKET-LENGTH@\The maximum length for a packet.  This should normally be no
  3856. less than 30 or 40, and can be greater than 94 only if the long-packet protocol
  3857. extension is available, in which case it can be a much larger number, up to the
  3858. maximum size allowed for the particular Kermit program (but never greater than
  3859. 9024).  Short packets can be an advantage on noisy lines; they reduce the
  3860. probabily of a particular packet being corrupted, as well as the retransmission
  3861. overhead when corruption does occur.  Long packets boost performance on clean
  3862. lines.
  3863.  
  3864. PADDING@\The number of padding characters that should be sent before each
  3865. packet, and what the padding character should be.  Rarely necessary.
  3866.  
  3867. PARITY@\Specify the parity (ODD, EVEN, MARK, SPACE, NONE) of the physical
  3868. connection.  If other than none, the "8th bit" cannot be used to transmit data
  3869. and must not be used by either side in block check computation.
  3870.  
  3871. PAUSE@\How many seconds to pause after receiving a packet before sending the
  3872. next packet.  Normally 0, but when a system communication processor or front
  3873. end has trouble keeping up with the traffic, a short pause between packets may
  3874. allow it to recover its wits; hopefully, something under a second will suffice.
  3875.  
  3876. PREFIX@\Change the default prefix for control characters, 8-bit characters, or
  3877. repeated quantities.
  3878.  
  3879. PROMPT@\Change the program's prompt.  This is useful when running Kermit
  3880. between two systems whose prompt is the same, to eliminate confusion about
  3881. which Kermit you are talking to.
  3882.  
  3883. REPEAT-COUNT-PROCESSING@\Change the default for repeat count processing.
  3884. Normally, it will be done if both Kermit programs agree to do it.
  3885.  
  3886. RETRY@\The maximum number of times to attempt to send or receive a packet
  3887. before giving up.  The normal number is about 5, but the user should be able to
  3888. adjust it according to the condition of the line, the load on the systems, etc.
  3889.  
  3890. TIMEOUT@\Specify the length of the timer to set when waiting for a packet to
  3891. arrive.
  3892.  
  3893. WINDOW-SIZE@\Maximum number of unacknowledged packets outstanding, when the
  3894. sliding window option is available, usually between 4 and 31.
  3895. @End(Description)
  3896.  
  3897. @Section<Macros, the DEFINE Command>
  3898.  
  3899. @index<DEFINE>
  3900. In addition to the individual set commands, a "macro" facility is recommended
  3901. to allow users to combine the characteristics of specific systems into a single
  3902. SET option.  For example:
  3903. @begin[example]
  3904. DEFINE IBM = PARITY ODD, DUPLEX HALF, HANDSHAKE XON
  3905. DEFINE UNIX = PARITY NONE, DUPLEX FULL
  3906. DEFINE TELENET = PARITY MARK
  3907. @end[example]
  3908. This could be done by providing a fancy runtime parser for commands like this
  3909. (which could be automatically TAKEn from the user's Kermit initialization file
  3910. upon program startup), or simply hardwired into the SET command table.
  3911.  
  3912. With these definitions in place, the user would simply type "SET IBM", "SET
  3913. UNIX", and so forth, to set up the program to communication to the remote
  3914. system.
  3915.  
  3916. @chapter<Kermit Programs>
  3917.  
  3918. @section<Terminal emulation>
  3919.  
  3920. The local system must be able to act as a terminal so that the user can connect
  3921. to the remote system, log in, and start up the remote Kermit.
  3922.  
  3923. Terminal emulation should be provided by any Kermit program that runs locally,
  3924. so that the user need not exit and restart the local Kermit program in order to
  3925. switch between terminal and protocol operation.  On smaller systems, this is
  3926. particularly important for various reasons -- restarting the program and typing
  3927. in all the necessary SET commands is too inconvenient and time-@|consuming;
  3928. in some micros, switching in and out of terminal emulation may cause carrier to
  3929. drop, etc.
  3930.  
  3931. Only bare-bones terminal emulation need be supplied by Kermit; there is no need
  3932. to emulate any particular kind of "smart" terminal.  Simple "dumb" terminal
  3933. emulation is sufficient to do the job.  Emulation of fancier terminals is nice
  3934. to have, however, to take advantage of the remote system's editing and display
  3935. capabilities.  In some cases, microcomputer firmware will take care of this.
  3936. To build emulation for a particular type of terminal into the program, you must
  3937. interpret and act upon escape sequences as they arrive at the port.
  3938.  
  3939. No error checking is done during terminal emulation.  It is "outside the
  3940. protocol"; characters go back and forth "bare".  In this sense, terminal
  3941. emulation through Kermit is no better than actually using a real terminal.
  3942.  
  3943. Some Kermit implementations may allow logging of the terminal emulation session
  3944. to a local file.  Such a facility allows "capture" of remote typescripts and
  3945. files, again with no error checking or correction.  When this facility is
  3946. provided, it is also desirable to have a convenient way of "toggling" the
  3947. logging on and off.
  3948.  
  3949. If the local system does not provide system- or firmware-@|level flow control,
  3950. like XON/XOFF, the terminal emulation program should attempt to simulate it,
  3951. especially if logging is being done.
  3952.  
  3953. The terminal emulation facility should be able to handle either remote or local
  3954. echoing (full or half duplex), any required handshake, and it should be able to
  3955. transmit any parity required by the remote side or the communication medium.
  3956.  
  3957. A terminal emulator works by continuously sampling both console input from the
  3958. local terminal and input from the communication line.  Simple input and output
  3959. functions will not suffice, however, since if you ask for input from a certain
  3960. device and there is none available, you will generally block until input
  3961. @i<does> become available, during which time you will be missing input from the
  3962. other device.  Thus you must have a way to bounce back and forth regardless of
  3963. whether input is available.  Several mechanisms are commonly used:
  3964. @Begin(Itemize)
  3965. Continuously jump back and forth between the port status register and the
  3966. console status register, checking the status bits for input available.  This
  3967. is only practical on single-@|user, single-@|process systems, where the CPU has
  3968. nothing else to do.
  3969.  
  3970. Issue an ordinary blocking input request for the port, but enable interrupts on
  3971. console input, or vice versa.
  3972.  
  3973. Handle port input in one process and console input in another, parallel
  3974. process.  The UNIX Kermit program listed in this manual uses this method.
  3975. @End(Itemize)
  3976. Any input at the port should be displayed immediately on the
  3977. screen.  Any input from the console should be output immediately to the port.
  3978. In addition, if the connection is half duplex, console input should also be
  3979. sent immediately to the screen.
  3980.  
  3981. The terminal emulation code must examine each console character to
  3982. determine whether it is the "escape character".  If so, it should take the next
  3983. character as a special command, which it executes.  These commands are
  3984. described above, in section @ref<-emulation>.
  3985.  
  3986. @index<BREAK>
  3987. The terminal emulator should be able to send every ASCII character, NUL through
  3988. DEL, and it should also be able to transmit a BREAK signal (BREAK is not a
  3989. character, but an "escape" from ASCII transmission in which a 0 is put on
  3990. the line for about a quarter of a second, regardless of the baud rate, with no
  3991. framing bits).  BREAK is important when communicating with various systems,
  3992. such as IBM mainframes.
  3993.  
  3994. Finally, it is sometimes necessary to perform certain transformations on the CR
  3995. character that is normally typed to end a line of input.  Some systems use
  3996. LF, EOT, or other characters for this function.  To complicate matters,
  3997. intervening communications equipment (particularly the public packet-@|switched
  3998. networks) may have their own independent requirements.  Thus if using Kermit to
  3999. communicate over, say, TRANSPAC with a system that uses LF for
  4000. end-@|of-@|line, it may be necessary to transform CR into LFCR (linefeed first
  4001. -- the CR tells the network to send the packet, which will contain the LF, and
  4002. the host uses the LF for termination).  The user should be provided with
  4003. a mechanism for specifying this transformation, a command like "SET CR
  4004. @i<sequence>".
  4005.  
  4006. @section<Writing a Kermit Program>
  4007.  
  4008. @Index<Program, Kermit>
  4009. Before writing a new implementation of Kermit or modifying an old one, first be
  4010. sure to contact the Kermit Distribution center at Columbia University to make
  4011. sure that you're not duplicating someone else's effort, and that you have all
  4012. the latest material to work from.  If you do write or significantly modify (or
  4013. document) a Kermit program, please send it back to Columbia so that it can be
  4014. included in the standard Kermit distribution and others can benifit from it.
  4015. It is only through this kind of sharing that Kermit has grown from its modest
  4016. beginnings to its present scale. 
  4017.  
  4018. The following sections provide some hints on Kermit programming.
  4019.  
  4020. @subsection<Program Organization>
  4021.  
  4022. A basic Kermit implementation can usually be written as a relatively small
  4023. program, self-contained in a single source file.  However, it is often the case
  4024. that a program written to run on one system will be adapted to run on other
  4025. systems as well.  In that case, it is best to avoid having totally divergent
  4026. sources, because when new features are added to (or bugs fixed in) the
  4027. system-@|independent parts of the program -- i.e. to the protocol itself --
  4028. only one implementation will reap the benefits initially, and the other will
  4029. require painful, error-@|prone "retrofitting" to bring it up to the same level.
  4030.  
  4031. Thus, if there is any chance that a Kermit program will run on more than one
  4032. machine, or under more than one operating system, or support more than one kind
  4033. of port or modem, etc, it is desirable to isolate the system-@|dependent parts
  4034. in a way that makes the common parts usable by the various implementations.
  4035. There are several approaches:
  4036. @Begin(Enumerate)
  4037. Runtime support.  If possible, the program can inspect the hardware or inquire
  4038. of the system about relevant parameters, and configure itself dynamically at
  4039. startup time.  This is hardly ever possible.
  4040.  
  4041. Conditional compilation (or assembly).  If the number of systems or options to
  4042. be supported is small, the system dependent code can be enclosed in conditional
  4043. compilation brackets (like @q<IF IBMPC .... ENDIF>).  However, as the
  4044. number of system dependencies to be supported grows, this method becomes
  4045. unwieldy and error-@|prone -- installing support for system X tends to break
  4046. the pre-existing support for system Y.
  4047.  
  4048. Modular composition.  When there is a potentially large number of options a
  4049. program should support, it should be broken up into separate modules (source
  4050. files), with clearly specified, simple calling conventions.  This allows people
  4051. with new options to provide their own support for them in an easy way, without
  4052. endangering any existing support.  Suggested modules for a Kermit program are:
  4053.  
  4054. @Begin(Itemize)
  4055. System-Indendent protocol handling: state switching, packet formation,
  4056. encoding (prefixing) and decoding, etc.
  4057.  
  4058. User Interface: the command parser.  Putting this in a separate module allows
  4059. plug-in of command parsers to suit the user's taste, to mimic the style of the
  4060. host system command parser or some popular application, etc.
  4061.  
  4062. Screen i/o: This module would contain the screen control codes, cursor
  4063. positioning routines, etc.
  4064.  
  4065. Port i/o: Allows support of various port hardware.  This module can define the
  4066. port status register location, the status bits, and so forth, and can implement
  4067. the functions to read and write characters at the port.
  4068.  
  4069. Modem control: This module would support any kind of "intelligent" modem, which
  4070. is not simply a transparent extension of the communications port.
  4071. Such modems may accept special commands to perform functions like dialing out,
  4072. redialing a recent number, hanging up, etc., and may need special
  4073. initialization (for instance, setting modem signals like DTR).
  4074.  
  4075. Console input: This module would supply the function to get characters from the
  4076. console; it would know about the status register locations and bits, interrupt
  4077. structure, key-to-@|character mappings, etc., and could also implement key
  4078. redefinitions, keystroke macros, programmable function keys, expanded control
  4079. and meta functions, etc.
  4080.  
  4081. Terminal Emulation: This module would interpret escape sequences in the
  4082. incoming character stream (obtained from the port i/o module) for
  4083. the particular type of terminal being emulated and interpret them by making
  4084. appropriate calls the the screen i/o module, and it would send user typein
  4085. (obtained from the console input module) out the serial port (again using the
  4086. port i/o module).  Ideally, this module could be replacable by other modules to
  4087. emulate different kinds of terminals (e.g. ANSI, VT52, ADM3A, etc).
  4088.  
  4089. File i/o: This module contains all the knowledge about the host system's file
  4090. structure; how to open and close files, perform "get next file" operations,
  4091. read and write files, determine and set their attributes, detect the end of a
  4092. file, and so forth, and provides the functions, including buffering, to get a
  4093. character from a file and put a character to a file.  This module may also
  4094. provide file management services for local files -- directory listings,
  4095. deleting, renaming, copying, and so forth.
  4096.  
  4097. Definitions and Data: Separate modules might also be kept for compile-@|time
  4098. parameter definitions and for global runtime data.
  4099. @End(Itemize)
  4100. @End(Enumerate)
  4101.  
  4102. @subsection<Programming Language>
  4103.  
  4104. @Index<Language, Programming>
  4105. The language to be used in writing a Kermit program is more than a matter of
  4106. taste.  The primary consideration is that the language provide the necessary
  4107. functionality and speed.  For instance, a microcomputer implementation of BASIC
  4108. may not allow the kind of low-@|level access to device registers needed to do
  4109. terminal emulation, or to detect console input during file transfer, or even if
  4110. it can do these things, it might not be able to run fast enough do drive the
  4111. communication line at the desired baud rate.
  4112.  
  4113. The second consideration in choosing a language is portability.  This is used
  4114. in two senses: (1) whether the language is in the public domain (or,
  4115. equivalently, provided "free" as part of the basic system), and (2) whether it
  4116. is well standardized and in wide use on a variety of systems.  A language that
  4117. is portable in both senses is to be preferred.
  4118.  
  4119. Whatever programming language is selected, it is important that all lines in
  4120. the program source be kept to 80 characters or less (after expansion of tabs).
  4121. This is because Kermit material must often be shipped over RJE and other
  4122. card-@|format communication links.
  4123.  
  4124. In addition, it is important that the names of all files used in creating and
  4125. supporting a particular Kermit implementation be (possibly a subset) of the
  4126. form @q<NAME.TYPE>, where NAME is limited to six characters, and TYPE is
  4127. limited to three, and where the NAME of each file begin with a common 2 or 3
  4128. character prefix.  This is so that all related files will be grouped together
  4129. in an alphabetic directory listing, and so when all of the hundreds of Kermit
  4130. related files are placed together on a tape, all names will be both legal and
  4131. unique, especially on systems (like PDP-11 operating systems) with restrictive
  4132. file naming conventions.
  4133.  
  4134. @subsection<Documentation>
  4135.  
  4136. A new Kermit program should be thoroughly documented; one of the hallmarks of
  4137. Kermit is its documentation.  The documentation should be at both the user
  4138. level (how to use the program, what the commands are, etc, similar to the
  4139. documentation presently found in the @i<Kermit Users Guide>), and the
  4140. implementation level (describe system dependencies, give pointers for adapting
  4141. to new systems, and so forth).  In addition, programs themselves should contain
  4142. copious commentary.  Like program source, documentation should be kept within
  4143. 80-@|character lines.
  4144.  
  4145. If possible, a section for the implementation should be written for the Kermit
  4146. User Guide using the UNILOGIC Scribe formatting language (subsets of which are
  4147. also to be found in some microcomputer text processing software such as Perfect
  4148. Writer or Final Word), using the same general conventions as the existing
  4149. Scribe-@|format implementation sections.
  4150.  
  4151. @index<Edit Number>
  4152. Kermit programs should also contain a revision history, in which each change is
  4153. briefly explained, assigned an "edit number", and the programmer and site are
  4154. identified.  The lines or sections comprising the edit should be marked with
  4155. the corresponding edit number, and the Kermit program, upon startup, should
  4156. announce its version and edit numbers, so that when users complain of problems
  4157. we will know what version of the program is in question.
  4158.  
  4159. The version number changes when the functionality has been changed sufficiently
  4160. to require major revisions of user documentation.  The edit number should
  4161. increase (monotonically, irrespective of version number) whenever a change is
  4162. made to the program.  The edit numbers are very important for program
  4163. management; after shipping out a version of, say, CP/M Kermit-80, we often
  4164. receive many copies of it, each containing its own set of changes, which we
  4165. must reconcile in some manner.  Edit numbers help a great deal here.
  4166.  
  4167. @subsection<Bootstrapping>
  4168.  
  4169. @Index<Bootstrap>
  4170. Finally, a bootstrap procedure should be provided.  Kermit is generally
  4171. distributed on magnetic tape to large central sites; the users at those sites
  4172. need ways of "downloading" the various implementations to their micros and
  4173. other local systems.  A simple bootstrap procedure would consist of precise
  4174. instructions on how to accomplish an "unguarded" capture of the program.
  4175. Perhaps a simple, short program can be written for each each end that will do
  4176. the job; listings and instructions can be provided for the user to type in and
  4177. run these programs.
  4178.  
  4179. @appendix<Packet Format and Types>
  4180.  
  4181. @b<Basic Kermit Packet Layout>
  4182. @begin<example,group,leftmargin 0>
  4183.  
  4184.        |<------Included in CHECK------>|
  4185.        |                               |
  4186. +------+-----+-----+------+------ - - -+-------+
  4187. | MARK | LEN | SEQ | TYPE | DATA       | CHECK |<terminator>
  4188. +------+-----+-----+------+------ - - -+-------+
  4189.              |                                 |
  4190.              |<--------LEN-32 characters------>|
  4191.  
  4192.  MARK   @r<A real control character, usually CTRL-A.>
  4193.   LEN   @r<One character, length of remainder of packet + 32, max 95>
  4194.   SEQ   @r<One character, packet sequence number + 32, modulo 64>
  4195.  TYPE   @r<One character, an uppercase letter>
  4196. CHECK   @r<One, two, or three characters, as negotiated.>
  4197.  
  4198. <terminator>  @r<Any control character required for reading the packet.>
  4199. @end<Example>
  4200.  
  4201. @b<Kermit Extended Packet Layout>
  4202. @begin<example,group,leftmargin 0>
  4203.        |<-------------------------Included in CHECK------------->|
  4204.        |                                                         |
  4205.        |<-------Included in HCHECK------->|                      |
  4206.        |                                  |                      |
  4207. +------+-----+-----+------+-------+-------+--------+----- - - - -+-------+
  4208. | MARK |     | SEQ | TYPE | LENX1 | LENX2 | HCHECK | DATA        | CHECK |
  4209. +------+-----+-----+------+-------+-------+--------+----- - - - -+-------+
  4210.         blank                                      |                     |
  4211.                                                    |<------------------->|
  4212.                     LX1=LENX1-32, LX2=LX2-32         95 x LX1 + LX2 chars
  4213.  
  4214. HCHECK is a single-character type 1 checksum
  4215. @end<example>
  4216.  
  4217. @b<Initialization String>
  4218. @begin<example,group,leftmargin 0,longlines keep>
  4219.  1       2       3       4       5       6       7       8       9       10
  4220. +-------+-------+-------+-------+-------+-------+-------+-------+-------+- -
  4221. | MAXL  | TIME  | NPAD  | PADC  | EOL   | QCTL  | QBIN  | CHKT  | REPT  |
  4222. +-------+-------+-------+-------+-------+-------+-------+-------+-------+- -
  4223.  
  4224.      10              CAPAS+1  CAPAS+2  CAPAS+3
  4225. - --+-------+-     -+--------+--------+--------+- -
  4226.     | CAPAS    ... 0| WINDO  | MAXLX1 | MAXLX1 |
  4227. - --+-------+-     -+--------+--------+--------+- -
  4228. @end<example>
  4229. @begin<description,spread 0,leftmargin +8,indent -8>
  4230. MAXL@\Maximum length (0-94) +32
  4231.  
  4232. TIME@\Timeout, seconds (0-94) +32
  4233.  
  4234. NPAD@\Number of pad characters (0-94) +32
  4235.  
  4236. EOL@\Packet terminator (0-63) +32
  4237.  
  4238. QCTL@\Control prefix, literal
  4239.  
  4240. QBIN@\8th bit prefix, literal
  4241.  
  4242. CHKT@\Block check type {1,2,3}, literal
  4243.  
  4244. REPT@\Repeat count prefix, literal
  4245.  
  4246. CAPAS@\Extendable capabilities mask, ends when value-32 is even
  4247.  
  4248. WINDO@\Window size (0-31) +32
  4249.  
  4250. MAXLX1@\High part of extended packet maximum length (int(max/95)+32)
  4251.  
  4252. MAXLX2@\Low part of extended packet maximum length  (mod(max,95)+32)
  4253. @end<description>
  4254.  
  4255. @b<Packet Types>
  4256. @begin<description,spread 0, leftmargin +4, indent -4>
  4257. Y@\Acknowledgment (ACK).  Data according to what kind
  4258. of packet is being acknowledged.
  4259.  
  4260. N@\Negative Acknowledgment (NAK).  Data field always empty.
  4261.  
  4262. S@\Send Initiation.  Data field contains unencoded initialization string.
  4263. Tells receiver to expect files.  ACK to this packet also contains unencoded
  4264. initialization string.
  4265.  
  4266. I@\Initialize.  Data field contains unencoded initialization string.
  4267. Sent to server to set parameters prior to a command.  ACK to this packet also
  4268. contains unencoded initialization string.
  4269.  
  4270. F@\File Header.  Indicates file data about to arrive for named file.  Data
  4271. field contains encoded file name.  ACK to this packet may contain encoded name
  4272. receiver will store file under.
  4273.  
  4274. X@\Text Header.  Indicates screen data about to arrive.  Data
  4275. field contains encoded heading for display.
  4276.  
  4277. A@\File Attributes.  Data field contains unencoded attributes.  ACK may contain
  4278. unencoded corresponding agreement or refusal, per attribute.
  4279.  
  4280. D@\Data Packet.  Data field contains encoded file or screen data.  ACK may
  4281. contain X to interrupt sending this file, Z to interrupt entire transaction.
  4282.  
  4283. Z@\End of file.  Data field may contain D for Discard.
  4284.  
  4285. B@\Break transmission.
  4286.  
  4287. E@\Error.  Data field contains encoded error message.
  4288.  
  4289. R@\Receive Initiate.  Data field contains encoded file name.
  4290.  
  4291. C@\Host Command.  Data field contains encoded command for host's command
  4292. processor.
  4293.  
  4294. K@\Kermit Command.  Data field contains encoded command for Kermit
  4295. command processor.
  4296.  
  4297. T@\Timeout psuedopacket, for internal use.
  4298.  
  4299. Q@\Block check error psuedopacket, for internal use.
  4300.  
  4301. G@\Generic Kermit Command.  Data field contains a single character subcommand,
  4302. followed by zero or more length-encoded operands, encoded after formation:
  4303. @begin<description,spread 0, leftmargin +4, indent -4>
  4304. I@\Login [<%user[%password[%account]]>]
  4305.  
  4306. C@\CWD, Change Working Directory [<%directory[%password]>]
  4307.  
  4308. L@\Logout, Bye
  4309.  
  4310. F@\Finish (Shut down the server, but don't logout).
  4311.  
  4312. D@\Directory [<%filespec>]
  4313.  
  4314. U@\Disk Usage Query [<%area>]
  4315.  
  4316. E@\Erase (delete) <%filespec>
  4317.  
  4318. T@\Type <%filespec>
  4319.  
  4320. R@\Rename <%oldname%newname>
  4321.  
  4322. K@\Copy <%source%destination>
  4323.  
  4324. W@\Who's logged in? [<%user ID or network host[%options]>]
  4325.  
  4326. M@\Send a short Message <%destination%text>
  4327.  
  4328. H@\Help [<%topic>]
  4329.  
  4330. Q@\Server Status Query
  4331.  
  4332. P@\Program <%[program-filespec][%program-commands]>
  4333.  
  4334. J@\Journal <%command[%argument]>
  4335.  
  4336. V@\Variable <%command[%argument[%argument]]>
  4337. @end<description>
  4338. @end<description>
  4339.  
  4340. @appendix<List of Features>
  4341.  
  4342. There's no true linear scale along which to rate Kermit implementations.
  4343. A basic, minimal implementation provides file transfer in both directions, and,
  4344. for microcomputers (PC's, workstations, other single user systems), terminal
  4345. emulation.  Even within this framework, there can be variations.  For instance,
  4346. can the program send a @i<file group> in a single command, or must a command be
  4347. issued for each file?  Can it time out?  Here is a list of features that may be
  4348. present; for any Kermit implementation, the documentation should show whether
  4349. these features exist, and how to invoke them.
  4350.  
  4351. @Begin(Itemize) 
  4352. File groups.  Can it send a group of files with a single command, using
  4353. "wildcard", pattern, or list notation?  Can it successfully send or receive a
  4354. group of files of mixed types?  Can it recover from an error on a particular
  4355. file and go on to the next one?  Can it keep a log of the files involved
  4356. showing the disposition of each?
  4357.  
  4358. Filenames.  Can it take action to avoid overwriting a local
  4359. file when a new file of the same name arrives?  Can it convert filenames to and
  4360. from legal or "normal form"?
  4361.  
  4362. File types.  Can binary as well as text files be transmitted?
  4363.  
  4364. 8th-Bit prefixing.  Can it send and receive 8-bit data through a 7-bit channel
  4365. using the prefixing mechanism?
  4366.  
  4367. Repeat-Count processing.  Can it send and receive data with repeated characters
  4368. replaced by a prefix sequence?
  4369.  
  4370. Terminal Emulation.  Does it have a terminal emulation facility?  Does it
  4371. emulate a particular terminal?  To what extent?  Does it provide various
  4372. communication options, such as duplex, parity, and handshake selection?  Can it
  4373. transmit all ASCII characters?  Can it transmit BREAK?  Can it log the remote
  4374. session locally?
  4375.  
  4376. Communications Options.  Can duplex, parity, handshake, and line terminator be
  4377. specified for file transfer?
  4378.  
  4379. Block Check Options.  In addition to the basic single-@|character checksum, can
  4380. the two-@|character checksum and the three-@|character CRC be selected?
  4381.  
  4382. Basic Server.  Can it run in server mode, accepting commands to send or receive
  4383. files, and to shut itself down?
  4384.  
  4385. Advanced Server.  Can it accept server commands to delete files, provide
  4386. directory listings, send messages, and forth?
  4387.  
  4388. Issue Commands to Server.  Can it send commands to a server, and handle all
  4389. possible responses?
  4390.  
  4391. Host Commands.  Can it parse and send remote "host commands"?  If it is a
  4392. server, can it pass these commands to the host system command processor and
  4393. return the results to the local user Kermit?
  4394.  
  4395. Interrupt File Transfers.  Can it interrupt sending or receiving a file?  Can
  4396. it respond to interrupt requests from the other side?
  4397.  
  4398. Local File Management Services.  Are there commands to get local directory
  4399. listings, delete local files, and so forth?
  4400.  
  4401. File Attributes.  Can it send file attribute information about local files, and
  4402. can deal with incoming file attribute information?   Can alternate dispositions
  4403. be specified.  Can files be archived?
  4404.  
  4405. Long Packets.  Is the long packet protocol extension implemented?
  4406.  
  4407. Sliding Windows.  Is the sliding window protocol extension implemented?
  4408.  
  4409. Debugging Capability.  Can packet traffic be logged, examined,
  4410. single-@|stepped? 
  4411.  
  4412. Frills.  Does it have login scripts?  Raw download/upload?  A DIAL command
  4413. and modem control?  Phone directories?
  4414. @end<itemize>
  4415.  
  4416. @Include<ascii.mss>
  4417.  
  4418. @Case(Device,x9700="@Comment<Begin Duplex Kludge>
  4419. @SendEnd(#Index `@begin<Transparent,PageBreak UntilOdd>@end<Transparent>')
  4420. @Comment<End Duplex Kludge>")
  4421.