home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / comm / hydrakit.zip / HYDRA001.ARJ / HYDRA.DOC < prev   
Text File  |  1992-12-01  |  111KB  |  1,898 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.     ─────────────────────────────────────────────────────────────────────
  12.  
  13.     Filename......: HYDRA.DOC; The HYDRA file transfer protocol
  14.                     (also published as EMSC-002).
  15.     Rev...........: 001
  16.     Date..........: Dec 1, 1992
  17.     Subject.......: HYDRA file transfer protocol definitions
  18.     Authors.......: Joaquim H. Homrighausen and Arjen G. Lentz
  19.  
  20.     ─────────────────────────────────────────────────────────────────────
  21.      Copyright 1991-1993 Joaquim H. Homrighausen. All rights reserved.
  22.      Copyright 1991-1993 Lentz Software Development. All rights reserved.
  23.     ─────────────────────────────────────────────────────────────────────
  24.  
  25.  
  26.     Restrictions
  27.     ═════════════════════════════════════════════════════════════════════
  28.     You are granted a license to implement the HYDRA file transfer
  29.     protocol, HYDRA hereafter, in your own programs and/or use the sample
  30.     source code and adapt these to your particular situation and needs;
  31.     subject to the following conditions:
  32.  
  33.     o You must refer to it as the HYDRA file transfer protocol, and you
  34.       must give credit to the authors of HYDRA in any information screens
  35.       or literature pertaining to your programs that contains other such
  36.       information (credits, your own copyrights, etc.).
  37.  
  38.     o HYDRA will always remain backwards compatible with previous
  39.       revisions. HYDRA allows for expansion of its features without
  40.       interfering with previous revisions. It is, however, important that
  41.       different people do not expand the protocol in different directions.
  42.       We therefore ask you to contact us if you have any needs/ideas
  43.       regarding HYDRA, so development can be synchronized and beneficial
  44.       to all.
  45.  
  46.     o If your implementation cannot converse with past or future revisions
  47.       as supplied by us, then you must refer to it as "HYDRA derived", or
  48.       as "a variation of HYDRA", or words to that effect.
  49.  
  50.     Permission is hereby granted to the FTSC (FidoNet Technical Standards
  51.     Committee) and other technical organisations to republish this
  52.     document in its entirety. Librarians may change the title page and
  53.     page headers to match their library format as long as all copyrights
  54.     and body text remain unaltered. The original document name and source
  55.     must be mentioned in any republished versions of this document.
  56.  
  57.     No organization, company, person, or other being may impose any fees
  58.     for any reason for providing this document. This document may not be
  59.     sold or otherwise transferred for personal or company gain under any
  60.     circumstances.
  61.  
  62.  
  63.     Disclaimer
  64.     ═════════════════════════════════════════════════════════════════════
  65.     This information is provided "as is" and comes with no warranties of
  66.     any kind, either expressed or implied. There is no support available
  67.     for this package. It's intended to be used by programmers and
  68.     developers.
  69.  
  70.     In no event shall the authors be liable to you or anyone else for any
  71.     damages, including any lost profits, lost savings or other incidental
  72.     or consequential damages arising out of the use or inability to use
  73.     this information.
  74.  
  75.  
  76.     Revision timestamps
  77.     ═════════════════════════════════════════════════════════════════════
  78.     001                           0x2b1aab00                 Dec 01, 1992
  79.  
  80.  
  81.     Introduction
  82.     ═════════════════════════════════════════════════════════════════════
  83.     This document will not attempt to convince the reader that HYDRA is
  84.     of value to him/her or that it is better than other file transfer
  85.     protocols, it will simply describe the protocol. Just to get it out
  86.     of the way, HYDRA is not the ultimate file transfer protocol.
  87.  
  88.     The authors do, however, feel that it offers an significant
  89.     improvement over those file transfer protocols available today. HYDRA
  90.     is a bi-directional protocol with the ability to receive and send
  91.     files simultaneously. There are other bi-directional file transfer
  92.     protocols, but to the authors' knowledge no public specifications
  93.     exist.
  94.  
  95.     HYDRA owes much to Zmodem and its designer, Chuck Forsberg as well as
  96.     to Janus, designed by Rick Huebner. We would like to think of HYDRA
  97.     as a combination of both with a few extra options installed.
  98.  
  99.     The basic concept of a bi-directional file transfer protocol is
  100.     simple. Both data channels are utilized to transmit and receive files
  101.     simultaneously. I.e. two 100 kb files can be exchanged between two
  102.     parties in the time it takes a fully streaming uni-directional file
  103.     transfer protocol to transmit one of the files.
  104.  
  105.  
  106.     Protocol design
  107.     ═════════════════════════════════════════════════════════════════════
  108.     The ultimate goal when designing HYDRA was to design a protocol that
  109.     is as simple and robust as possible; complexity increase the problem
  110.     of faulty implementations.
  111.  
  112.     The obvious function of a file transfer protocol is to transport a
  113.     collection of data from its source to its destination as efficient
  114.     possible and without jeopardizing the integrity of the data.
  115.  
  116.     The lack of data compression and lost packet management (as used in
  117.     Kermit and Super Kermit) is intentional. The authors feel that this
  118.     unnecessarily increases the complexity of the protocol.
  119.  
  120.     While HYDRA performs to its best on full duplex links, it should be
  121.     possible to use it on links using proprietary protocols such as the
  122.     US Robotics HST protocol which features one 14.4 kbps data channel
  123.     and one 450 bps back channel.
  124.  
  125.     The protocol design should be flexible enough for future enhancements
  126.     while maintaining backward compatibility.
  127.  
  128.  
  129.     Protocol requirements and restrictions
  130.     ═════════════════════════════════════════════════════════════════════
  131.     HYDRA require that the link can handle ASCII character 24 (DLE) as
  132.     well as all ASCII characters in the range 32 through 126. All other
  133.     characters can be escaped or encoded by the protocol as required by
  134.     the link.
  135.  
  136.     Capability of the computer to perform simultaneous serial I/O as well
  137.     as simultaneous serial I/O combined with disk access is preferred,
  138.     but can be circumvented by opting for windowed transmission instead
  139.     of full streaming.
  140.  
  141.     HYDRA calls for the ability to check whether there is anything in the
  142.     serial input buffer (i.e. "peek-ahead"), but it doesn't mind if it
  143.     has to wait for a second if there is no data available (using for
  144.     instance the UNIX alarm() mechanism).
  145.  
  146.     The protocol is extremely tolerant with timeouts (i.e. satellite or
  147.     network delays) while still maintaining maximum reliability,
  148.     robustness, and throughput.
  149.  
  150.  
  151.     Terms and definitions
  152.     ═════════════════════════════════════════════════════════════════════
  153.     A BYTE                   An 8-bit unsigned character.
  154.     A WORD                   A 16-bit unsigned integer.
  155.     A DWORD                  A 32-bit unsigned integer.
  156.     A LONG                   A 32-bit SIGNED integer.
  157.     FILE OFFSETS (position)  A long.
  158.     NUL                      The ASCII character 0.
  159.     BS                       The ASCII character 8.
  160.     CR                       The ASCII character 13.
  161.     XOFF                     The ASCII character 17.
  162.     XON                      The ASCII character 19.
  163.     H_DLE                    The HYDRA link escape character, ASCII 24
  164.                              (^X).
  165.     SP or SPACE              The ASCII character 32.
  166.     UNIX timestamp           A specific time and date expressed as the
  167.                              number of seconds since midnight, January
  168.                              1st, 1970. All UNIX timestamps used in HYDRA
  169.                              are expressed in local time.
  170.  
  171.     Multi-byte items are transmitted in "low-byte first" order, so big-
  172.     endian CPUs (like 680xx) need to do some byteswapping, depending on
  173.     the implementation.
  174.  
  175.     Values preceded by '0x' are in hexadecimal notation (base 16, 0..9
  176.     a..f). All values transmitted in hexadecimal notation must be
  177.     converted to lowercase characters and left-padded to their full
  178.     size with '0' prior to transmission. E.g. a WORD with the value 255
  179.     (decimal) is expressed as 00ff. A LONG with the value 255 (decmial)
  180.     is expressed as 000000ff.
  181.  
  182.     In formulas, "AND" means bitwise AND, "XOR" means bitwise Exclusive
  183.     OR, "NOT" is ones complement (i.e. all zeros become ones, all ones
  184.     become zeros). The ">>" is a shift operation to the right, "R >> 3"
  185.     means shift R three bits to the right.
  186.  
  187.  
  188.     General packet format
  189.     ═════════════════════════════════════════════════════════════════════
  190.     All data exchange is done with framed packets protected by 16 or 32
  191.     bit CRC values appended to the packet data and packet type (low-
  192.     byte first). The only exception to this is the cancel sequence of 5
  193.     consecutive H_DLE characters.
  194.  
  195.     All packets except those with the type DATA are followed by a CR
  196.     (ASCII 13) to help get through some buffered environments and aid
  197.     possible debugging and/or tracing. If requested by the other side in
  198.     its INIT packet, packets can also be prefixed by a specific data
  199.     string which can include NULs, delays or break signals. Refer to the
  200.     section on the INIT packet for more information.
  201.  
  202.  
  203.                           Format of unframed packet
  204.  
  205.                 ┌──────────────────────────────────────────┐
  206.                 ~ Zero or more bytes packet dependent data ~
  207.                 ├──────────────────────────────────────────┤
  208.                 │ Packet type byte                         │
  209.                 ├──────────────────────────────────────────┤
  210.                 │ CRC-16/32 of packet data and packet type │
  211.                 └──────────────────────────────────────────┘
  212.  
  213.  
  214.                             Table of packet types
  215.  
  216.          ┌────────┬─────────┬─────┬────────────────────────────────┐
  217.          │Name    │Character│ASCII│Description                     │
  218.          ├────────┼─────────┼─────┼────────────────────────────────┤
  219.          │START   │   'A'   │  65 │Startup sequence                │
  220.          │INIT    │   'B'   │  66 │Session initialisation          │
  221.          │INITACK │   'C'   │  67 │Response to INIT packet         │
  222.          │FINFO   │   'D'   │  68 │File information                │
  223.          │FINFOACK│   'E'   │  69 │Response to FINFO packet        │
  224.          │DATA    │   'F'   │  70 │File data packet                │
  225.          │DATAACK │   'G'   │  71 │File data position ACK packet   │
  226.          │RPOS    │   'H'   │  72 │Reposition request packet       │
  227.          │EOF     │   'I'   │  73 │End of file packet              │
  228.          │EOFACK  │   'J'   │  74 │Response to EOF packet          │
  229.          │END     │   'K'   │  75 │End of session                  │
  230.          │IDLE    │   'L'   │  76 │Idle (just saying I'm alive)    │
  231.          │DEVDATA │   'M'   │  77 │Data to specified device     (1)│
  232.          │DEVDACK │   'N'   │  78 │Response to DEVDATA packet   (1)│
  233.          └────────┴─────────┴─────┴────────────────────────────────┘
  234.  
  235.     (1) Support for DEVDATA and DEVDACK types is optional and indicated
  236.         in INIT state of a HYDRA session.
  237.  
  238.  
  239.                            Format of framed packet
  240.  
  241.                ┌──────────────────────┬────────────────────┐
  242.                │        H_DLE         │Packet format byte  │
  243.                ├──────────────────────┴────────────────────┤
  244.                ~               Encoded packet              ~
  245.                ├──────────────────────┬────────────────────┤
  246.                │        H_DLE         │End of framed packet│
  247.                └──────────────────────┴────────────────────┘
  248.  
  249.  
  250.                             Table of packet formats
  251.  
  252.            ┌────┬─────────┬─────┬────────────────────────────────┐
  253.            │Name│Character│ASCII│Description                     │
  254.            ├────┼─────────┼─────┼────────────────────────────────┤
  255.            │END │   'a'   │  97 │End of framed packet            │
  256.            │BIN │   'b'   │  98 │Binary packet                   │
  257.            │HEX │   'c'   │  99 │Hex encoded packet              │
  258.            │ASC │   'd'   │ 100 │Shifted 7-bit encoded packet (1)│
  259.            │UUE │   'e'   │ 101 │UUencoded packet             (1)│
  260.            └────┴─────────┴─────┴────────────────────────────────┘
  261.  
  262.     (1) Support for ASC and/or UUE formats is optional and indicated in
  263.         the INIT state of a HYDRA session.
  264.  
  265.  
  266.     Packet sender and receiver state charts
  267.     ─────────────────────────────────────────────────────────────────────
  268.  
  269. TXPKT (Sender)
  270. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  271. │State   │Predicate(s)                  │Action(s)                 │Next state│
  272. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  273. │Begin   │1│pkttype == START or         │format = HEXPKT           │Format    │
  274. │        │ │pkttype == INIT or          │                          │          │
  275. │        │ │pkttype == INITACK or       │                          │          │
  276. │        │ │pkttype == END or           │                          │          │
  277. │        │ │pkttype == IDLE             │                          │          │
  278. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  279. │        │2│Escape 8th bit (7 bit link) │                          │Coding    │
  280. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  281. │        │3│else (no spc.pkt, 8bit link)│format = BINPKT           │Format    │
  282. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  283. │Coding  │1│escape all control chars &  │format = UUEPKT           │Format    │
  284. │        │ │UUENCODED packets allowed   │                          │          │
  285. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  286. │        │2│ASCII packets allowed       │format = ASCPKT           │Format    │
  287. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  288. │        │3│7 bit link &                │format = HEXPKT           │Format    │
  289. │        │ │escape all control chars &  │                          │          │
  290. │        │ │UUE/ASC pkts not allowed    │                          │          │
  291. ├────────┼─┴────────────────────────────┼──────────────────────────┼──────────┤
  292. │Format  │                              │Append format byte to data│CRC       │
  293. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  294. │CRC     │1│format != HEXPKT &          │Calc CRC-32 (data,pkttype)│Encode    │
  295. │        │ │CRC-32 allowed              │Append one's complement of│          │
  296. │        │ │                            │CRC to data, lowbyte first│          │
  297. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  298. │        │2│else (HEXPKT or no CRC-32)  │Calc CRC-16 (data,pkttype)│Encode    │
  299. │        │ │                            │Append one's complement of│          │
  300. │        │ │                            │CRC to data, lowbyte first│          │
  301. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  302. │Encode  │1│format == BINPKT            │BIN escape databuf        │Prefix    │
  303. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  304. │        │2│format == HEXPKT            │HEX encode databuf        │Prefix    │
  305. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  306. │        │3│format == ASCPKT            │ASC encode/escape databuf │Prefix    │
  307. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  308. │        │4│format == UUEPKT            │UUE encode databuf        │Prefix    │
  309. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  310. │Prefix  │1│No more prefix characters   │                          │Transmit  │
  311. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  312. │        │2│Prefix character ASCII 221  │Send 1 second break signal│          │
  313. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  314. │        │3│Prefix character ASCII 222  │1 second delay            │          │
  315. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  316. │        │4│Prefix character ASCII 223  │Transmit NUL (ASCII 0)    │          │
  317. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  318. │        │5│else (any other character)  │Transmit character        │          │
  319. ├────────┼─┴────────────────────────────┼──────────────────────────┼──────────┤
  320. │Transmit│                              │Transmit H_DLE,format byte│Suffix    │
  321. │        │                              │Transmit encoded buffer   │          │
  322. │        │                              │Transmit H_DLE,pktend byte│          │
  323. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  324. │Suffix  │1│pkttype != DATA &           │Transmit CR,LF (ASC 13,10)│Done      │
  325. │        │ │pktformat != BINPKT         │                          │          │
  326. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  327. │        │2│else (pkttype == DATA or    │                          │Done      │
  328. │        │ │      pktformat == BINPKT)  │                          │          │
  329. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  330.  
  331.  
  332. RXPKT (Receiver)
  333. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  334. │State   │Predicate(s)                  │Action(s)                 │Next state│
  335. ├────────┼──────────────────────────────┼──────────────────────────┼──────────┤
  336. │Reset   │                              │rxdle = 0                 │NextByte  │
  337. │        │                              │format = 0                │          │
  338. │        │                              │pktlen = 0                │          │
  339. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  340. │NextByte│1│User wishes to abort session│Report reason for abort   │Abort     │
  341. │        │ │or carrier lost             │                          │          │
  342. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  343. │        │2│Byte available in inputbuf  │                          │StripIn   │
  344. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  345. │        │3│braintimer expired          │Report braindead situation│Abort     │
  346. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  347. │        │4│Any other timer expired     │Tell responsible party    │          │
  348. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  349. │StripIn │1│Escape 8th bit (7 bit link) │c = c AND 0x7f (strip 8th)│StripC    │
  350. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  351. │        │2│else (8 bit link)           │                          │StripC    │
  352. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  353. │StripC  │1│Escape ctlchars with 8th set│n = c AND 0x7f (strip 8th)│Process   │
  354. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  355. │        │2│else (let 8 bit ctl through)│n = c                     │Process   │
  356. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  357. │Process │1│c == H_DLE                  │increment rxdle           │DLE       │
  358. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  359. │        │2│Escape XON/XOFF &           │Eat these                 │NextByte  │
  360. │        │ │n == XON or n == XOFF       │                          │          │
  361. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  362. │        │3│Escape all control chars &  │Eat these                 │NextByte  │
  363. │        │ │n < 32 or n == 127          │                          │          │
  364. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  365. │        │4│rxdle > 0                   │                          │Escape    │
  366. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  367. │        │5│else (no eating or escaping)│                          │Store     │
  368. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  369. │DLE     │1│rxdle == 5                  │Report remote wants abort │Abort     │
  370. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  371. │        │2│else (rxdle < 5)            │                          │NextByte  │
  372. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  373. │Escape  │1│c == PKTEND                 │                          │PktEnd    │
  374. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  375. │        │2│c == BINPKT                 │format = BINPKT           │PktStart  │
  376. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  377. │        │3│c == HEXPKT                 │format = HEXPKT           │PktStart  │
  378. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  379. │        │4│c == ASCPKT                 │format = ASCPKT           │PktStart  │
  380. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  381. │        │5│c == UUEPKT                 │format = UUEPKT           │PktStart  │
  382. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  383. │        │6│else (normal escaped char)  │c = c XOR 0x40            │Store     │
  384. │        │ │                            │rxdle = 0                 │Store     │
  385. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  386. │Store   │1│format == 0                 │Garbage                   │NextByte  │
  387. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  388. │        │2│pktlen >= maximum           │Pkt too long / lost PKTEND│Reset     │
  389. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  390. │        │3│else (fmt > 0 & len < max)  │Append c to databuffer    │NextByte  │
  391. │        │ │                            │increment pktlen          │          │
  392. ├────────┼─┴────────────────────────────┼──────────────────────────┼──────────┤
  393. │PktStart│                              │rxdle = 0                 │NextByte  │
  394. │        │                              │pktlen = 0                │          │
  395. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  396. │PktEnd  │1│format == 0                 │End without start, garbage│Reset     │
  397. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  398. │        │2│format == BINPKT            │(No more decoding needed) │CalcCRC   │
  399. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  400. │        │3│format == HEXPKT            │ok = Decode HEXPKT        │CheckDec  │
  401. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  402. │        │4│format == ASCPKT            │ok = Decode ASCPKT        │CheckDec  │
  403. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  404. │        │5│format == UUEPKT            │ok = Decode UUEPKT        │CheckDec  │
  405. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  406. │CheckDec│1│ok (no errors during decode)│                          │CalcCRC   │
  407. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  408. │        │2│else (errors in decoding)   │Bad encoding, ignore pkt  │Reset     │
  409. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  410. │CalcCRC │1│format != HEXPKT &          │Calc CRC-32 over databuf  │CheckCRC  │
  411. │        │ │CRC-32 allowed              │ok = (crc == 0xdebb20e3)  │          │
  412. │        │ │                            │pktlen = pktlen - 4       │          │
  413. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  414. │        │2│else (HEXPKT or no CRC-32)  │Calc CRC-16 over databuf  │CheckCRC  │
  415. │        │ │                            │ok = (crc == 0xf0b8)      │          │
  416. │        │ │                            │pktlen = pktlen - 2       │          │
  417. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  418. │CheckCRC│1│ok (CRC matched magic)      │pkttype = last byte of buf│Reset     │
  419. │        │ │                            │pktlen = pktlen - 1       │          │
  420. │        │ │                            │Hand pkt to higher level  │          │
  421. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  422. │        │2│else (CRC check failed)     │Bad CRC, ignore packet    │Reset     │
  423. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  424.  
  425.  
  426.  
  427.     BIN packet format
  428.     ─────────────────────────────────────────────────────────────────────
  429.     The binary packet format require an 8-bit data channel. If requested
  430.     by either side, one or more sets of control characters are escaped.
  431.     In this case, when one of these characters appears in an unframed
  432.     packet, a H_DLE is sent followed by the character XOR 0x40. The H_DLE
  433.     character itself is always transmitted in this fashion. On the
  434.     receiver side, if the character after a H_DLE is not one of the
  435.     packet format bytes, this character is decoded using XOR 0x40 again.
  436.  
  437.  
  438. BINPKT Escaping
  439. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  440. │State   │Predicate(s)                  │Action(s)                 │Next state│
  441. ├────────┼──────────────────────────────┼──────────────────────────┼──────────┤
  442. │Begin   │                              │txlastc = 0               │NextByte  │
  443. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  444. │NextByte│1│No more bytes to process    │                          │Done      │
  445. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  446. │        │2│Escape ctlchars with 8th set│n = c AND 0x7f (strip 8th)│Escape    │
  447. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  448. │        │3│else (let 8 bit ctl through)│n = c                     │Escape    │
  449. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  450. │Escape  │1│n == H_DLE                  │Output H_DLE              │Output    │
  451. │        │ │                            │c = c XOR 0x40            │          │
  452. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  453. │        │2│Escape XON/XOFF &           │Output H_DLE              │Output    │
  454. │        │ │n == XON or n == XOFF       │c = c XOR 0x40            │          │
  455. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  456. │        │3│Escape Telenet &            │Output H_DLE              │Output    │
  457. │        │ │n == CR &                   │c = c XOR 0x40            │          │
  458. │        │ │txlasc == '@'               │                          │          │
  459. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  460. │        │4│Escape all control chars &  │Output H_DLE              │Output    │
  461. │        │ │n < 32 or n == 127          │c = c XOR 0x40            │          │
  462. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  463. │        │5│else (any other character)  │                          │Output    │
  464. ├────────┼─┴────────────────────────────┼──────────────────────────┼──────────┤
  465. │Output  │                              │Store c                   │NextByte  │
  466. │        │                              │txlastc = c               │          │
  467. └────────┴──────────────────────────────┴──────────────────────────┴──────────┘
  468.  
  469.  
  470.  
  471.     HEX packet format
  472.     ─────────────────────────────────────────────────────────────────────
  473.     Supported by all implementations, this packet format is used in
  474.     worst-case situations and upon startup of a session when it is not
  475.     yet known what restrictions the line and the other side will place on
  476.     the link.
  477.  
  478.     Packet types always transmitted in HEX format are: START, INIT,
  479.     INITACK, IDLE, END.
  480.  
  481.     HEX format packets always use a 16-bit CRC.
  482.  
  483.     HEX packets assume a 7-bit link, escaping all control characters and
  484.     filtering all control characters upon receipt.
  485.  
  486.     ASCII characters in the range 128-255 (high bit set) are encoded by
  487.     first transmitting a backslash ('\') character (ASCII 92), followed
  488.     by the character in two lowercase hex-digits (bits 4-7 in first
  489.     digit, bits 0-3 in second).
  490.  
  491.     Uppercase hex-digits are not permitted.
  492.  
  493.     The backslash character itself is transmitted as two backslashes.
  494.  
  495.     ASCII characters in the range 0-31 and 127 (all control characters)
  496.     are escaped with H_DLE in the same fashion as in binary (BIN)
  497.     packets.
  498.  
  499.     Decoded  byte 1
  500.             ┌──────┐
  501.             76543210
  502.             └──┘└──┘
  503.     Encoded  h1  h2
  504.  
  505.  
  506. HEXPKT Encoding/Escaping
  507. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  508. │State   │Predicate(s)                  │Action(s)                 │Next state│
  509. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  510. │NextByte│1│No more bytes to process    │                          │Done      │
  511. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  512. │        │2│High bit of c set           │Output \ (backslash)      │          │
  513. │        │ │                            │Output hexdigit(c bit 4-7)│          │
  514. │        │ │                            │Output hexdigit(c bit 0-3)│          │
  515. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  516. │        │3│c < 32 or c == 127          │Output H_DLE              │          │
  517. │        │ │                            │Output (c XOR 0x40)       │          │
  518. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  519. │        │4│c == \ (backslash)          │Output \ (backslash)      │          │
  520. │        │ │                            │Output \ (backslash)      │          │
  521. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  522. │        │5│else (any other character)  │Output c                  │          │
  523. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  524.  
  525.  
  526. HEXPKT Decoding
  527. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  528. │State   │Predicate(s)                  │Action(s)                 │Next state│
  529. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  530. │NextByte│1│No more bytes to process    │                          │Done OK   │
  531. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  532. │        │2│c == \ (backslash)          │                          │Escape    │
  533. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  534. │        │3│else (any other character)  │Output c                  │Escape    │
  535. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  536. │Escape  │1│No more bytes to process    │Premature end of data     │Error     │
  537. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  538. │        │2│c == \ (backslash)          │Output \ (backslash)      │          │
  539. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  540. │        │3│c == lowercase hexdigit     │Save c, move ptr to next  │NextHex   │
  541. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  542. │        │4│else (all other characters) │Invalid character         │Error     │
  543. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  544. │NextHex │1│No more bytes to process    │Premature end of data     │Error     │
  545. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  546. │        │2│c == lowercase hexdigit     │Output (1st << 4 OR 2nd)  │NextByte  │
  547. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  548. │        │3│else (all other characters) │Invalid character         │Error     │
  549. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  550.  
  551.  
  552.     ASC packet format
  553.     ─────────────────────────────────────────────────────────────────────
  554.     Support of this packet format is optional and signalled in the INIT
  555.     packet with the ASC flag in the "Supported options" field. 8-bit data
  556.     is transformed into 7-bit data by a simple shift operation. Each byte
  557.     is inserted at the top of a shift register, the lower seven bits are
  558.     moved out. So seven 8-bit bytes are encoded into eight 7-bit
  559.     characters.
  560.  
  561.     The end of the packet is padded by a maximum of six bits of 0 to make
  562.     the number of bits a multiple of seven and thereby creating
  563.     complete characters (so the receiver stops decoding when there are
  564.     less than seven bits left). The output can contain control
  565.     characters, so if escaping of these characters is required, this is
  566.     done as in BIN packets using the H_DLE method.
  567.  
  568.  
  569.     Decoded  byte 7  byte 6  byte 5  byte 4  byte 3  byte 2  byte 1
  570.             ┌──────┐┌──────┐┌──────┐┌──────┐┌──────┐┌──────┐┌──────┐
  571.             76543210765432107654321076543210765432107654321076543210
  572.             └─────┘└─────┘└─────┘└─────┘└─────┘└─────┘└─────┘└─────┘
  573.     Encoded   c8     c7      c6    c5     c4     c3     c2     c1
  574.  
  575.  
  576. ASCPKT Encoding/Escaping
  577. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  578. │State   │Predicate(s)                  │Action(s)                 │Next state│
  579. ├────────┼──────────────────────────────┼──────────────────────────┼──────────┤
  580. │Reset   │                              │n = 0 (16 bit wide!)      │NextByte  │
  581. │        │                              │bitshift = 0              │          │
  582. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  583. │NextByte│1│No more bytes to process    │                          │Flush     │
  584. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  585. │        │2│else (more bytes to process)│n = n OR (c << bitshift)  │Shift     │
  586. │        │ │                            │BINPKT escape (n & 0x7f)  │          │
  587. │        │ │                            │n = n >> 7                │          │
  588. │        │ │                            │increment bitshift        │          │
  589. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  590. │Shift   │1│bitshift == 7               │BINPKT escape (n & 0x7f)  │Reset     │
  591. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  592. │        │2│else (bitshift < 7)         │                          │NextByte  │
  593. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  594. │Flush   │1│bitshift > 0                │BINPKT escape (n & 0x7f)  │Done      │
  595. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  596. │        │2│else (bitshift == 0)        │                          │Done      │
  597. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  598.  
  599. ASCPKT Decoding
  600. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  601. │State   │Predicate(s)                  │Action(s)                 │Next state│
  602. ├────────┼──────────────────────────────┼──────────────────────────┼──────────┤
  603. │Begin   │                              │n = 0 (16 bit wide!)      │NextByte  │
  604. │        │                              │bitshift = 0              │          │
  605. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  606. │NextByte│1│No more bytes to process    │                          │Done OK   │
  607. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  608. │        │2│else (more bytes to process)│c = c AND 0x7f            │Shift     │
  609. │        │ │                            │n = n OR (c << bitshift)  │          │
  610. │        │ │                            │bitshift = bitshift + 7   │          │
  611. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  612. │Shift   │1│bitshift >= 8               │Output (n AND 0xff)       │NextByte  │
  613. │        │ │                            │n = n >> 8                │          │
  614. │        │ │                            │bitshift = bitshift - 8   │          │
  615. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  616. │        │2│else (bitshift < 8)         │                          │NextByte  │
  617. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  618.  
  619.  
  620.  
  621.     UUE packet format
  622.     ─────────────────────────────────────────────────────────────────────
  623.     Support of this packet format is optional and signalled in the INIT
  624.     packet with the UUE flag in the "Supported options" field. The 8-bit
  625.     data is transformed into printable ASCII using the UUENCODE
  626.     algorithm. Three 8-bit bytes are encoded into four printable ASCII
  627.     characters. This done by taking the bottom six bits left and adding
  628.     '!' (ASCII 33) to move this character value into printable ASCII
  629.     range.
  630.  
  631.     The end of the packet is padded by a maximum of five bits of 0 to
  632.     make the number of bits a multiple of six and thereby creating 
  633.     complete characters (so the receiver stops decoding when there are
  634.     less than six bits left). The output of this coding scheme does not
  635.     need any further escaping before transmission.
  636.  
  637.     Decoded  byte 3  byte 2  byte 1
  638.             ┌──────┐┌──────┐┌──────┐
  639.             765432107654321076543210
  640.             └────┘└────┘└────┘└────┘
  641.     Encoded   c4    c3    c2    c1
  642.  
  643.  
  644. UUEPKT Encoding
  645. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  646. │State   │Predicate(s)                  │Action(s)                 │Next state│
  647. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  648. │NextByte│1│Less than three bytes left  │                          │Flush     │
  649. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  650. │        │2│else (three or more left)   │UUE(in[0]>>2)             │          │
  651. │        │ │                            │UUE(in[0]<<4 OR in[1]>>4) │          │
  652. │        │ │                            │UUE(in[1]<<2 OR in[2]>>6) │          │
  653. │        │ │                            │UUE(in[2])                │          │
  654. │        │ │                            │(UUE: (c AND 0x3f) + '!') │          │
  655. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  656. │Flush   │1│No more bytes left          │                          │Done      │
  657. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  658. │        │2│One byte left               │UUE(in[0]>>2)             │Done      │
  659. │        │ │                            │UUE(in[0]<<4)             │          │
  660. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  661. │        │3│Two bytes left              │UUE(in[0]>>2)             │Done      │
  662. │        │ │                            │UUE(in[0]<<4 OR in[1]>>4) │          │
  663. │        │ │                            │UUE(in[1]<<2)             │          │
  664. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  665.  
  666. UUEPKT Decoding
  667. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  668. │State   │Predicate(s)                  │Action(s)                 │Next state│
  669. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  670. │NextByte│1│Less than four bytes left   │                          │Flush     │
  671. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  672. │        │2│else (four or more left) &  │UD(i[0])<<2 OR UD(i[1])>>4│          │
  673. │        │ │(c AND 0x7f) is in UUE range│UD(i[1])<<4 OR UD(i[2])>>2│          │
  674. │        │ │                            │UD(i[2])<<6 OR UD(i[3])   │          │
  675. │        │ │                            │(UD: (c - '!') AND 0x3f)  │          │
  676. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  677. │        │3│else (all other characters) │Invalid character(s)      │Error     │
  678. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  679. │Flush   │1│No bytes left or            │                          │Done OK   │
  680. │        │ │Less than two bytes left    │                          │          │
  681. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  682. │        │2│Two bytes left &            │UD(i[0])<<2 OR UD(i[1])>>4│Done OK   │
  683. │        │ │(c AND 0x7f) is in UUE range│                          │          │
  684. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  685. │        │3│Three bytes left &          │UD(i[0])<<2 OR UD(i[1])>>4│Done OK   │
  686. │        │ │(c AND 0x7f) is in UUE range│UD(i[1])<<4 OR UD(i[2])>>2│          │
  687. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  688. │        │4│else (all other characters) │Invalid character(s)      │Error     │
  689. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  690.  
  691.  
  692.  
  693.     START packet                                             (HEX format)
  694.     ─────────────────────────────────────────────────────────────────────
  695.     This packet is sent to tell the remote to initiate a HYDRA session.
  696.  
  697.     The complete framed packet as transmitted looks like:
  698.  
  699.         ASCII values   24    99  65  92 102  53  92  97  51    24    97
  700.                     ┌───────┬───┬───┬───┬───┬───┬───┬───┬───┬───────┬───┐
  701.         Characters  │ H_DLE │ c │ A │ \ │ f │ 5 │ \ │ a │ 3 │ H_DLE │ a │
  702.                     └───────┴───┴───┴───┴───┴───┴───┴───┴───┴───────┴───┘
  703.  
  704.     Applications may scan for this sequence to automatically start HYDRA
  705.     when the remote transmits this packet (AutoStart). Prior to the START
  706.     packet, a special string is transmitted to enable remote starting
  707.     from a command prompt, hydra<CR> (the word hydra in lowercase):
  708.  
  709.         ASCII values 104 121 100 114  97  13
  710.                     ┌───┬───┬───┬───┬───┬────┐
  711.         Characters  │ h │ y │ d │ r │ a │ CR │
  712.                     └───┴───┴───┴───┴───┴────┘
  713.  
  714.     The special string combined with the START packet is transmitted at
  715.     five second intervals until either a START or INIT packet is received
  716.     from the remote, or the maximum number of retries is reached. Any
  717.     other packet types received in this stage must be ignored as they
  718.     could be remains of a previous session.
  719.  
  720.  
  721.     INIT packet                                              (HEX format)
  722.     ─────────────────────────────────────────────────────────────────────
  723.     The INIT packet contains file transfer session options. The remote
  724.     acknowledges this packet by returning an INITACK packet.
  725.  
  726.  
  727.                               INIT packet data
  728.  
  729.                  ┌───────────────────────────────────────┐
  730.                  ~ Application ID string, NUL terminated ~
  731.                  ├───────────────────────────────────────┤
  732.                  ~ Supported options, NUL terminated     ~
  733.                  ├───────────────────────────────────────┤
  734.                  ~ Desired options, NUL terminated       ~
  735.                  ├───────────────────────────────────────┤
  736.                  │ Desired transmitter window size or 0  │
  737.                  ├───────────────────────────────────────┤
  738.                  │ Desired receiver window size or 0     │
  739.                  ├───────────────────────────────────────┤
  740.                  ~ Other general options, NUL terminated ~
  741.                  ├───────────────────────────────────────┤
  742.                  ~ Packet prefix string, NUL terminated  ~
  743.                  └───────────────────────────────────────┘
  744.  
  745.     The application ID string contains a printable ASCII string with the
  746.     document revision date, product name, product revision number, and
  747.     optionally the product serial number. The format of the string is:
  748.  
  749.         <RevDate><ProductName><,><ProductRevision>[<,><ProductSerial#>]
  750.  
  751.     RevDate is the UNIX timestamp (the hour, minute, and second portion
  752.     is assumed to be zero), in hexadecimal notation, of the HYDRA
  753.     document that the application is supposed to support. None of the
  754.     following three fields should exceed thirty characters in length and
  755.     must not contain any control characters (ASCII 0-31) or the comma
  756.     character (ASCII 44). The field separator is a comma (ASCII 44)
  757.     character.
  758.  
  759.     Capability flags
  760.  
  761.         XON        Escape <XON> and <XOFF> characters.
  762.         TLN        Escape the <CR>@<CR> sequence (Telenet escape).
  763.         CTL        Escape ASCII characters 0-31 and 127.
  764.         HIC        Escape above three with high bit set.
  765.         HI8        Escape ASCII characters 128-255 and strip the high bit.
  766.         BRK        Can transmit a break signal.
  767.         ASC        Can handle ASC packets.
  768.         UUE        Can handle UUE packets.
  769.         C32        Can receive packets with 32-bit CRC error detection.
  770.         DEV        Can receive device packets.
  771.         FPT        Can receive filenames with paths.
  772.  
  773.     Capability flags are always three characters long, in uppercase, and
  774.     seperated by a comma character (ASCII 44). Please note that the first
  775.     five flags must be supported by all applications that implement the
  776.     HYDRA specifications.
  777.  
  778.     The "Supported options" string contain the capability flags of the
  779.     options that the application support. The "Desired options" string
  780.     contain the capability flags of the options that the application
  781.     would like to use/enable for the session. Some flags do not have to
  782.     be specified in both strings. E.g. if the C32 flag is present in the
  783.     "Supported options" string and the remote system indicates support
  784.     for the same flag, 32-bit CRC error detection will be used. An
  785.     application may not ask for an option it does not support.
  786.  
  787.     Escaping certain characters or bits also means filtering any
  788.     occurrence of them in the incoming data stream. At the start of a
  789.     session, it is assumed that the first five capability flags are in
  790.     effect, i.e. the high bit is stripped off every received character
  791.     and all control characters are filtered out.
  792.  
  793.     The "Desired transmitter/receiver window size" fields are long
  794.     integers expressed in hexadecimal notation. With these options each
  795.     side tells the other to use window management of the requested size
  796.     when transmitting file data, instead of using full streaming (0).
  797.     The window setting is completely seperate for both directions.
  798.     If one side requests a smaller window size than the other, that
  799.     smaller size will be used for that direction; also, a window of any
  800.     size takes precedence over no window (0).
  801.     Please note that the terms 'transmitter' and 'receiver' used for the
  802.     fields in the INIT packet are from the view of the side transmitting
  803.     that packet, so the other side should merge the 'transmitter' window
  804.     field from the received INIT packet with its own 'receiver' window
  805.     field.
  806.  
  807.     The "General options" string currently has no other fields than
  808.     "Desired tx/rx window size"; the string is NUL terminated.
  809.  
  810.     The packet prefix string is normally empty, but may be provided by
  811.     the remote if required. The maximum length of a packet prefix string
  812.     is 30 characters. All characters should be transmitted as specified,
  813.     with the following exceptions:
  814.  
  815.     
  816.                 Table of special packet prefix string chars
  817.  
  818.                ┌─────┬──────────────────────────────────────┐
  819.                │ASCII│Description                           │
  820.                ├─────┼──────────────────────────────────────┤
  821.                │ 221 │Transmit a break signal for one second│
  822.                │ 222 │Delay one second before next character│
  823.                │ 223 │Transmit a NUL (ASCII 0) character    │
  824.                └─────┴──────────────────────────────────────┘
  825.  
  826.  
  827.     INITACK packet                                           (HEX format)
  828.     ─────────────────────────────────────────────────────────────────────
  829.     The INITACK packet is used to acknowledge the receipt of the remote's
  830.     INIT packet.
  831.  
  832.     Duplicate INIT packets should be acknowledged too, as the remote may
  833.     have missed previous INITACK packets; the reception of such a
  834.     duplicate packet should not however reset the braindead timer, as it
  835.     does not mean a change of state and is not actual file data.
  836.  
  837.  
  838.     FINFO packet
  839.     ─────────────────────────────────────────────────────────────────────
  840.     File information packet, sent to notify the remote that another file
  841.     is to be transmitted, or to signal end of batch. After the FINFO
  842.     packet has been transmitted, the timer is set to the normal timeout
  843.     value. The sender then waits for an FINFOACK packet from the remote
  844.     or for the timer to expire. In the event of a timeout, the transmit/
  845.     wait sequence is repeated with half the normal timeout value until
  846.     the maximum number of retries has been reached.
  847.  
  848.  
  849.                               FINFO packet data
  850.                    ┌─────────────────────────────────────┐
  851.                    ~ File information, NUL terminated    ~
  852.                    └─────────────────────────────────────┘
  853.  
  854.  
  855.                    File information        End of batch
  856.                   ┌─────────────────┐   ┌─────────────────┐
  857.                   │ Timestamp or 0  │   │       NUL       │ 
  858.                   ├─────────────────┤   └─────────────────┘ 
  859.                   │ Filesize or 0   │
  860.                   ├─────────────────┤
  861.                   │ Reserved (0)    │
  862.                   ├─────────────────┤
  863.                   │ Transaction #   │
  864.                   ├─────────────────┤
  865.                   │ File count or 0 │
  866.                   ├─────────────────┤
  867.                   ~ Short filename  ~
  868.                   ├─────────────────┤
  869.                   ~ Real filename   ~
  870.                   ├─────────────────┤
  871.                   │     NUL         │
  872.                   └─────────────────┘
  873.                      
  874.     End of batch is signalled by an empty string (only the terminating
  875.     NUL).
  876.  
  877.     The first five fields are long integers expressed in hexadecimal
  878.     notation.
  879.  
  880.     Timestamp is a UNIX timestamp representing the creation time of the
  881.     file. If the creation time is not known, this is zero.
  882.  
  883.     Filesize is the size of the file in bytes. If the size of the file is
  884.     not known, this is zero. This field should not be used as an exact
  885.     measure of the size of the file. It is safe to assume that you should
  886.     not receive less data than specified in this field, but the file may
  887.     grow while it is being transferred (e.g. the result of a background
  888.     process).
  889.  
  890.     Transaction # is a unique number for each set of files being sent
  891.     during the session. This is primarily used to allow the receiving
  892.     application to group several files together and store them in
  893.     specific directories as a result of automated file requests. If the
  894.     file being sent is not a result of an automated file request, this
  895.     field must be set to zero.
  896.  
  897.     File count is the session file counter. For the first file in a
  898.     session, this field contains the total number of files to be sent
  899.     during the session; for subsequent files, it contains the file number
  900.     in the session, starting with two (2). If the total number of files
  901.     is not known, this field contains zero for all files.
  902.  
  903.     The first filename field must be specified in lowercase characters.
  904.     It must conform to MS-DOS filename conventions and not exceed 12
  905.     characters in length (excluding the terminating NUL character). The
  906.     second field, real filename, is the actual filename on the sending
  907.     system. If this field is not present, the short filename field is
  908.     used.
  909.  
  910.     No directory paths may be specified in the short filename. Directory
  911.     paths may be specified in the real filename field if the "Desired
  912.     options" of the receiver contains FPT. If the real filename field
  913.     contains a path, it may include any ASCII character in the range 32
  914.     (0x20) through 255 (0xff) with \ characters translated to /. A drive
  915.     specifier may be present in the <Drive>: (e.g. c:) format. If both
  916.     the short and real filename fields are present, they are separated
  917.     by a NUL character. There is never more than one NUL character
  918.     terminating the packet.
  919.     
  920.  
  921.     FINFOACK packet
  922.     ─────────────────────────────────────────────────────────────────────
  923.     Sent in response to an FINFO packet. If the FINFO packet contained
  924.     file information, the FINFOACK packet is also used to instruct the
  925.     remote how to proceed with the transfer.
  926.  
  927.  
  928.                             FINFOACK packet data
  929.                  ┌───────────────────────────────────────┐
  930.                  │ Long file offset, special code, or 0  │
  931.                  └───────────────────────────────────────┘
  932.  
  933.     The only data in this packet is a long integer. In response to an
  934.     an end of batch FINFO packet, the file offset is set to zero (0). In
  935.     all other cases, file offset is one of the following:
  936.  
  937.  
  938.                        File offsets and special values
  939.            ┌──────┬──────────────────────────────────────────────┐
  940.            │Offset│Description                                   │
  941.            ├──────┼──────────────────────────────────────────────┤
  942.            │ >=0  │Seek to specified offset and start sending (1)│
  943.            │  -1  │Already have file                          (2)│
  944.            │  -2  │Send file during another batch (not now)      │
  945.            └──────┴──────────────────────────────────────────────┘
  946.  
  947.     (1) This can only be something other than zero if the FINFO packet
  948.         specified a filesize other than zero (i.e. the size of the file
  949.         is known to the receiver).
  950.  
  951.     (2) The sending application should consider the file as having been
  952.         sent successfully. This is primarily used to prevent duplicate
  953.         files from being transmitted.
  954.  
  955.  
  956.     DATA packet
  957.     ─────────────────────────────────────────────────────────────────────
  958.     Packet containing actual file data.
  959.  
  960.  
  961.                                   DATA packet
  962.                   ┌─────────────────────────────────────────┐
  963.                   │ Long file offset of file data block     │
  964.                   ├─────────────────────────────────────────┤
  965.                   ~ Variable length data block 0-2048 bytes ~
  966.                   └─────────────────────────────────────────┘
  967.  
  968.     If the file offset corresponds with what is expected by the receiver,
  969.     the data block is saved and the file position increased accordingly.
  970.     If the file offset is not correct, DATA packets may have been lost or
  971.     failed the CRC check. Bad packets are ignored because it is not
  972.     certain that the bad packet was an actual DATA packet and not some
  973.     other type of packet. The file offset comparison is therefore the
  974.     only way to find out about lost or bad data.
  975.  
  976.     When a bad data packet is detected, an RPOS packet is transmitted by
  977.     the receiver to force the sender to seek to the desired file offset
  978.     and resume transmission from it. After transmitting the RPOS packet,
  979.     the receiver initializes a timer and continues to monitor received
  980.     DATA packets while comparing their file offset with its desired
  981.     offset.
  982.  
  983.     If the offset of a newly received DATA packet is greater than the
  984.     offset received in the last DATA packet prior to transmitting the
  985.     RPOS packet, the sender has not yet seen the RPOS packet, or the
  986.     DATA packet was already in the data stream when the RPOS packet was
  987.     transmitted.
  988.  
  989.     If the received offset matches the requested offset, the transfer is
  990.     resumed, otherwise, a new RPOS packet is transmitted by the receiver
  991.     and the timer restarted.
  992.  
  993.     If the timer expires, another RPOS packet is transmitted by the
  994.     receiver. This is repeated until the maximum number of retries has
  995.     been reached.
  996.  
  997.     If the receiver encounters more missing or invalid DATA packets at
  998.     the same offset than it finds acceptable and it is not the originator
  999.     of the session, it may decide to revert to a one-way transfer and
  1000.     wait with sending the remainder of its own files until the remote has
  1001.     transmitted its end of batch signal. It is possible that some hard-
  1002.     ware is not capable or well suited for a bi-directional file transfer
  1003.     involving large volumes of data (see description of the IDLE packet).
  1004.  
  1005.  
  1006.     DATAACK packet
  1007.     ─────────────────────────────────────────────────────────────────────
  1008.     Transmitted by the receiver with its current file offset after
  1009.     receiving a valid DATA packet.
  1010.  
  1011.  
  1012.                               DATAACK packet data
  1013.                           ┌────────────────────────┐
  1014.                           │    Long file offset    │
  1015.                           └────────────────────────┘
  1016.  
  1017.     This packet is only transmitted if there is a window in operation
  1018.     for that direction (selected in the INIT stage of the session), in
  1019.     which case the sender uses the DATAACK file offsets to manage its
  1020.     transmit window. If the sender's file offset is greater than or equal
  1021.     to the last DATAACK offset received plus the window size, no more
  1022.     data is transmitted by the sender until a DATAACK packet is received
  1023.     which allows the sender to proceed without exceeding the window size.
  1024.  
  1025.     While waiting for the DATAACK packet, the sender checks its timer
  1026.     and retry counter. If the timer expires before a valid DATAACK packet
  1027.     is received, the next DATA packet is transmitted, the retry counter
  1028.     incremented, and the timer restarted with half the normal timeout.
  1029.     This system ensures that the two sides do not end up waiting for
  1030.     each other in case packets are lost; the receiver will respond with
  1031.     either a DATAACK or RPOS packet. Receipt of a DATAACK packet does not
  1032.     reset the braindead timer.
  1033.  
  1034.     There are two windowing systems the receiver can use: sliding window
  1035.     or segmented streaming.
  1036.  
  1037.     If the receiver is capable of simultaneous serial and disk I/O, it
  1038.     will transmit a DATAACK packet for every received DATA packet, or
  1039.     every few DATA packets if it wants to be more economical with line
  1040.     capacity.
  1041.     Sliding window transmission is just a method of keeping the runahaid
  1042.     of the transmitter within reasonable limits (for sattelite or network
  1043.     links with long delays), thereby allowing for faster error recovery.
  1044.     Because of Hydra's tolerancy to delays and method of error recovery,
  1045.     sliding windows transmission is not normally required and full
  1046.     streaming can be used.
  1047.  
  1048.     If however the receiver is not capable of simultaneous serial and
  1049.     disk I/O, it will will process received DATA packets until the window
  1050.     size is reached (or slightly exceeded), write the received packets to
  1051.     disk, and then transmit one DATAACK packet to signal that it can
  1052.     receive the next segment of data.
  1053.  
  1054.     If the sender cannot handle simultaneous serial and disk I/O, it can
  1055.     apply the segmented streaming technique for reading data segments of
  1056.     the negotiated window size from disk.
  1057.  
  1058.  
  1059.     RPOS packet
  1060.     ─────────────────────────────────────────────────────────────────────
  1061.     Transmitted by the receiver to force the sender to seek to a specific
  1062.     position in the file and resume the transfer (as described above).
  1063.  
  1064.     The RPOS packet is also used by the receiver to skip a file once the
  1065.     transfer has been initiated. This is done by transmitting a RPOS
  1066.     packet with -2 as the desired offset and then waiting for a EOF
  1067.     packet with the same offset (-2). Once the EOF packet is received,
  1068.     the receiver responds to it by transmitting a EOFACK packet and then
  1069.     proceeds to wait for the next FINFO packet.
  1070.  
  1071.  
  1072.                           RPOS packet dependent data
  1073.                   ┌────────────────────────────────────────┐
  1074.                   │ Long file offset                       │
  1075.                   ├────────────────────────────────────────┤
  1076.                   │ Desired datablock size (word, 64-2048) │
  1077.                   ├────────────────────────────────────────┤
  1078.                   │ Long RPOS packet ID                    │
  1079.                   └────────────────────────────────────────┘
  1080.  
  1081.  
  1082.                                  File offsets 
  1083.              ┌──────┬───────────────────────────────────────────┐
  1084.              │Offset│Description                                │
  1085.              ├──────┼───────────────────────────────────────────┤
  1086.              │ >=0  │Seek to specified offset and resume sending│
  1087.              │  -2  │Send file during another batch (not now)   │
  1088.              └──────┴───────────────────────────────────────────┘
  1089.  
  1090.     The desired data blocksize field tells the sender what blocksize
  1091.     to use when it resumes transmitting from the specified file offset.
  1092.  
  1093.     Each new RPOS packet should be given a different packet ID. This
  1094.     allows the sender to identify and ignore duplicate RPOS packets.
  1095.     The ID need not be sequential, but it must not have the same value as
  1096.     any other RPOS packet sent during the transmission of the same file.
  1097.     A RPOS ID value of zero (0) is not permitted. The same ID value is
  1098.     only used when sending multiple RPOS packets due to an expired RPOS
  1099.     packet timer as described above (DATA packet).
  1100.  
  1101.  
  1102.     EOF packet
  1103.     ─────────────────────────────────────────────────────────────────────
  1104.     Indicates that the end of the file has been reached by the sender.
  1105.     The packet is transmitted after the last DATA packet with file data.
  1106.     The EOF packet only contains one field which holds the current file
  1107.     offset of the sender (i.e. the actual size of the file).
  1108.  
  1109.     After the EOF packet has been transmitted, the timer is set to the
  1110.     normal timeout value. The sender then waits for an EOFACK packet
  1111.     from the remote or for the timer to expire. In the event of a
  1112.     timeout, the transmit/wait sequence is repeated with half the normal
  1113.     timeout value until the maximum number of retries has been reached.
  1114.  
  1115.     In the event that the receiver requests to skip the file by
  1116.     transmitting a RPOS(-2) packet (see RPOS packet), the EOF packet
  1117.     contains the same value (-2). If the sender wants to skip the file
  1118.     currently being transmitted, it issues an EOF packet with -2 as the
  1119.     offset value.
  1120.  
  1121.     EOF packets with an incorrect offset should be treated by the
  1122.     receiver as if it was an incorrect DATA packet (i.e. transmitting an
  1123.     RPOS packet). Accepted EOF packets are acknowledged by transmitting
  1124.     an EOFACK packet.
  1125.  
  1126.  
  1127.                                 EOF packet data
  1128.                      ┌──────────────────────────────────┐
  1129.                      │ Long file offset or special code │
  1130.                      └──────────────────────────────────┘
  1131.  
  1132.  
  1133.                          File offsets and special value
  1134.                ┌──────┬────────────────────────────────────────┐
  1135.                │Offset│Description                             │
  1136.                ├──────┼────────────────────────────────────────┤
  1137.                │ >=0  │Final offset in file (size of file)     │
  1138.                │  -2  │Send file during another batch (not now)│
  1139.                └──────┴────────────────────────────────────────┘
  1140.  
  1141.  
  1142.     EOFACK packet
  1143.     ─────────────────────────────────────────────────────────────────────
  1144.     Transmitted in response to an accepted EOF packet. After transmitting
  1145.     this packet, the receiver waits for the FINFO packet of the next file
  1146.     or end of batch.
  1147.  
  1148.  
  1149.     END packet                                               (HEX format)
  1150.     ─────────────────────────────────────────────────────────────────────
  1151.     Once all files have been transmitted by both sides and no device
  1152.     packets remain to be transmitted, the end of session sequence is
  1153.     initiated. END packets are always sent in HEX format.
  1154.  
  1155.     Two END packets are transmitted and the transmit timer set to half
  1156.     the normal timeout. The application then waits for an END packet from
  1157.     the remote or for the transmit timer to expire. In the event of a
  1158.     timeout, the transmit/wait sequence is repeated until the maximum
  1159.     number of retries has been reached. At this point, the HYDRA session
  1160.     may be considered to be successful as both batches were completed.
  1161.  
  1162.     If an END packet is received before timeout, another three (3) END
  1163.     packets are transmitted and the protocol exits. Both sides need to
  1164.     transmit END packets and receive at least one from the remote.
  1165.  
  1166.  
  1167.     IDLE packet                                              (HEX format)
  1168.     ─────────────────────────────────────────────────────────────────────
  1169.     The IDLE packet is used to let the remote know that the application
  1170.     is still alive. This is only applicable in uni-directional transfer
  1171.     mode to let the remote know that your application is still alive when
  1172.     it is receiving files, and after having transmitted an end of batch
  1173.     signal to the remote and not having any more files to send for the
  1174.     remainder of the session.
  1175.  
  1176.     When applicable, the IDLE packet is transmitted every 20 seconds. The
  1177.     remote resets its braindead timer upon receipt of an IDLE packet. If
  1178.     an application receives an IDLE packet while it is in a state where
  1179.     it is transmitting IDLE packets to the remote, something is wrong.
  1180.     This could occur if both sides have accidentally switched to one-way
  1181.     mode waiting for the remote to finish its batch. In this situation,
  1182.     one-way should be disabled to prevent a complete deadlock. Note that
  1183.     if both sides have finished their batch, the end of session sequence
  1184.     (see END packet) should be initiated.
  1185.  
  1186.  
  1187.     DEVDATA packet
  1188.     ─────────────────────────────────────────────────────────────────────
  1189.     Support for the DEVDATA and DEVDACK packets is optional and indicated
  1190.     in the INIT packet with the DEV flag in the "Supported options"
  1191.     field. The ID value is a long, different for each new device data
  1192.     packet sent. A value of zero (0) is not permitted.
  1193.  
  1194.     Only one DEVDATA packet may be transmitted at a time; the side
  1195.     issuing it then waits either for a timeout of the device transmit
  1196.     timer, or for a DEVDACK packet with the correct ID value to be
  1197.     received from the remote. If the timer expires before a correct
  1198.     DEVDACK packet is received, the DEVDATA packet is again transmitted,
  1199.     and the nnumber of device transmit retries incremented. If the
  1200.     maximum number of retries is reached, the HYDRA session is aborted;
  1201.     apparently the other is not functioning properly, or data is not
  1202.     getting through. In either case, the normal operation of the
  1203.     protocol (transferring files) will also fail.
  1204.  
  1205.     The name of the device to which the data is addressed is transmitted
  1206.     as an uppercase fixed-length three character NUL terminated string.
  1207.     There are two pre-defined device names as described below. If an
  1208.     unknown device name is specified, or a duplicate DEVDATA packet is
  1209.     received (one with the same ID value as a previously received and
  1210.     acknowledged DEVDATA packet), the packet is simply discarded after
  1211.     transmitting a DEVDACK packet with the corresponding ID value.
  1212.  
  1213.     DEVDATA and DEVDACK packets do not reset the braindead timer. They
  1214.     operate independently from the normal protocol. Device packets may
  1215.     only be transmitted after the initialization sequence, and before
  1216.     both sides have completed their batch. If a DEVDATA packet has not
  1217.     yet been acknowledged, the end of session sequence is delayed until
  1218.     a DEVDACK packet has been sent in response.
  1219.  
  1220.  
  1221.                        DEVDATA packet dependent data
  1222.            ┌──────────────────────────────────────────────────┐
  1223.            │ Long DEVDATA packet ID value                     │
  1224.            ├──────────────────────────────────────────────────┤
  1225.            │ 3 character uppercase device name, NUL terminated│
  1226.            ├──────────────────────────────────────────────────┤
  1227.            ~ Variable length device data block (0-2048)       ~
  1228.            └──────────────────────────────────────────────────┘
  1229.  
  1230.  
  1231.                            Predefined device names
  1232.                 ┌───┬─────────────────────────────────────┐
  1233.                 │Dev│Description                          │
  1234.                 ├───┼─────────────────────────────────────┤
  1235.                 │MSG│Print data in protocol message window│
  1236.                 │CON│Print data to user console           │
  1237.                 └───┴─────────────────────────────────────┘
  1238.  
  1239.     The MSG device may be used to notify the remote of protocol-specific
  1240.     issues, i.e. "One-way transfer mode". Such messages may be logged,
  1241.     but should not be considered to be machine-readable.
  1242.  
  1243.     The CON device may be used to implement a "chat" or conversation
  1244.     feature. This is a special case in which a session *can* be prolonged
  1245.     after end of batch, but not against the remote's will.
  1246.     While chat is enabled, there is no transition from the REND to the
  1247.     END transmitter state. When a CON device packet is transmitted in
  1248.     chat mode and the txstate is REND, the own braindead timer is reset.
  1249.     If the other side does initiate the end sequence by sending an END
  1250.     packet, the chat mode is immediately terminated and the session ended
  1251.     in a clean manner. If one side does not want to (continue) chat, and
  1252.     the other side does not comply, the one side will abort after a
  1253.     braindead timeout, so this chat system does not mean a security flaw.
  1254.     Each side is responsible for keeping the session going on his end
  1255.     until its own user has finished chatting. It is suggested that the
  1256.     software apply a timeout of say 1 minute to keyboard input, ending
  1257.     the chat automatically if the user stops typing but does not exit
  1258.     chat mode. Also, the chat mode should be initiated with a special key
  1259.     so that it can not erronously be started or prolonged.
  1260.  
  1261.  
  1262.     DEVDACK packet
  1263.     ─────────────────────────────────────────────────────────────────────
  1264.     Transmitted in response to a DEVDATA packet. The device data ID value
  1265.     must correspond to the ID of the previously received DEVDATA packet.
  1266.  
  1267.  
  1268.                               DEVDACK packet data
  1269.                          ┌───────────────────────────┐
  1270.                          │ Long device data ID value │
  1271.                          └───────────────────────────┘
  1272.  
  1273.  
  1274.  
  1275. DEVICE sender (devtxstate HTD_...)
  1276. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  1277. │State   │Predicate(s)                  │Action(s)                 │Next state│
  1278. ├────────┼──────────────────────────────┼──────────────────────────┼──────────┤
  1279. │Begin   │                              │devtxid = 0               │DONE      │
  1280. │        │                              │reset devtxtimer          │          │
  1281. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  1282. │DONE    │1│wish to send device data &  │increase devtxid          │DATA      │
  1283. │        │ │other side allows DEV pkts  │devtxretries = 0          │          │
  1284. │        │ │                            │reset devtxtimer          │          │
  1285. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1286. │        │2│wish to send device data &  │Tell calling function     │          │
  1287. │        │ │other doesn't allow DEV pkts│it's not on...            │          │
  1288. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1289. │DATA    │1│devtxretries == 10          │Report too many errors    │Abort     │
  1290. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1291. │        │2│else (devtxretries < 10)    │txpkt DEVDATA(id,dev,data)│DACK      │
  1292. │        │ │                            │devtxtimer = timeout      │          │
  1293. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1294. │DACK    │1│rxpkt DACK &                │reset devtxtimer          │DONE      │
  1295. │        │ │DACK(id) == devtxid         │                          │          │
  1296. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1297. │        │2│devtxtimer expired          │Report devtx timeout      │DATA      │
  1298. │        │ │                            │increase devtxretries     │          │
  1299. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  1300.  
  1301. DEVICE RECEIVER
  1302. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  1303. │State   │Predicate(s)                  │Action(s)                 │Next state│
  1304. ├────────┼──────────────────────────────┼──────────────────────────┼──────────┤
  1305. │Begin   │                              │devrxid = 0               │DONE      │
  1306. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  1307. │DONE    │1│rxpkt DEVDATA               │txpkt DEVDACK(id)         │CheckID   │
  1308. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1309. │CheckID │1│DEVDATA(id) != devrxid      │devrxid = DEVDATA(id)     │Process   │
  1310. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1311. │        │2│else (apparent duplicate)   │                          │DONE      │
  1312. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1313. │Process │1│DEVDATA(dev) == MSG         │Print protocol message    │DONE      │
  1314. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1315. │        │2│DEVDATA(dev) == CON         │Output to user console    │DONE      │
  1316. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1317. │        │3│DEVDATA(dev) == known&ok    │Call processing routine   │DONE      │
  1318. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1319. │        │4│else (unknown/not-ok device)│One-way into bitbucket    │DONE      │
  1320. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  1321.  
  1322.  
  1323.     Packet length and data block size
  1324.     ─────────────────────────────────────────────────────────────────────
  1325.     The maximum length of a source data block (i.e. raw, non processed
  1326.     input file or device data) is 2048 bytes. The maximum allowed length
  1327.     of the packet data is 2048 + 8 = 2056 bytes. The eight bytes are to
  1328.     provide sufficient room for the additional fields in the DATA and
  1329.     DEVDATA packets. Packetizing adds an additional three to five bytes.
  1330.     The maximum length of a framed packet being transmitted can be three
  1331.     times the size of its source data depending on what type of encoding
  1332.     scheme is used (ASC, HEX, UUE, BIN). The minimum length of a data
  1333.     block is 64 bytes.
  1334.  
  1335.     The block size of DATA packets is based on the physical (DCE) link
  1336.     speed and is established as follows:
  1337.  
  1338.             ┌─────────┬──────────────────┬───────────────────┐
  1339.             │DCE speed│Maximum block size│Starting block size│
  1340.             ├─────────┼──────────────────┼───────────────────┤
  1341.             │  300 bps│     256 bytes    │     256 bytes     │
  1342.             │ 1200 bps│     512 bytes    │     256 bytes     │
  1343.             │ 2400 bps│    1024 bytes    │     512 bytes     │
  1344.             │>2400 bps│    2048 bytes    │     512 bytes     │
  1345.             └─────────┴──────────────────┴───────────────────┘
  1346.  
  1347.     The blocksize is initialized to the starting blocksize when a session
  1348.     is first started. After each kilobyte of file data transmitted, the
  1349.     blocksize is doubled until it reaches the maximum allowed blocksize.
  1350.  
  1351.     When the maximum allowed blocksize has been reached, the variable
  1352.     keeping track of how many bytes are needed to increase the blocksize
  1353.     is reset to zero.
  1354.  
  1355.     If a request for retransmission (RPOS packet) is received from the
  1356.     receiver, the blocksize is immediately set to that specified in the
  1357.     retransmission request. Every time this occurs, the number of bytes
  1358.     needed to double the blocksize is increased by 1024 with a maximum of
  1359.     of 8192 bytes. The end result is that more data has to be
  1360.     successfully transmitted before the blocksize is increased for each
  1361.     error that occurs.
  1362.  
  1363.     The length of a data block is dynamic and always in the range 0-2048
  1364.     bytes. A data block is never padded. If there is insufficient data
  1365.     to fill a block of the current blocksize, the blocksize is adjusted
  1366.     to the amount of remaining data.
  1367.  
  1368.     The blocksize logic is not reset between files in a session.
  1369.  
  1370.  
  1371.     Timers and retry counters
  1372.     ═════════════════════════════════════════════════════════════════════
  1373.     Each process in the protocol (transmit, receive and device transmit)
  1374.     has its own timer and retry counter, and there is one overall
  1375.     braindead timer. Allowed are 10 tries, the braindead timeout is 120
  1376.     seconds, and the other timeouts are based on the speed of the line
  1377.     and the state of the protocol. It can be calculated as (40960/DCE
  1378.     rate), with a minimum of 10 seconds and a maximum of 60 seconds.
  1379.  
  1380.                      ┌─────────┬──────────┬──────────┐
  1381.                      │DCE speed│Timeout   │Half      │
  1382.                      ├─────────┼──────────┼──────────┤
  1383.                      │  300 bps│60 seconds│30 seconds│
  1384.                      │ 1200 bps│34 seconds│17 seconds│
  1385.                      │ 2400 bps│17 seconds│ 8 seconds│
  1386.                      │>2400 bps│10 seconds│ 5 seconds│
  1387.                      └─────────┴──────────┴──────────┘
  1388.  
  1389.     If the output buffer is empty, the timeout value is halved. In
  1390.     general, this is the case if the number of tries is greater than zero
  1391.     and during the init and end sequences. These timeouts are not fatal
  1392.     situations, they just give the remote a reasonable amount of time to
  1393.     receive and respond to a packet before a retry occurs. Duplicate
  1394.     packets are always identified and ignored. A retry counter is reset
  1395.     if there is a change of state, or a reposition different from the
  1396.     previous file offset occurs.
  1397.  
  1398.     The braindead timer monitors useful data from the other side: a first
  1399.     response to a transmitted supervisiory packet, or a received packet
  1400.     with file data at the correct offset. Device packets and packets that
  1401.     do not signify any progress of the protocol do not affect the
  1402.     braindead timer.
  1403.  
  1404.     No other timers (such as one between characters in a packet) are
  1405.     necessary.
  1406.  
  1407.  
  1408.     Aborting a session
  1409.     ═════════════════════════════════════════════════════════════════════
  1410.     A session is aborted with five consequetive CAN (^X or ASCII 24)
  1411.     characters. Whenever a state table mentions "Abort", the following
  1412.     procedure is to be followed:
  1413.  
  1414.     Clear the output buffer and transmit eight CAN characters followed by
  1415.     ten BS (^H or ASCII 8) characters; wait a few seconds for the data to
  1416.     be transmitted to the remote, purge the input buffer and exit the
  1417.     protocol code.
  1418.  
  1419.  
  1420. GENERAL sender (txstate HTX_...)
  1421. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  1422. │State   │Predicate(s)                  │Action(s)                 │Next state│
  1423. ├────────┼──────────────────────────────┼──────────────────────────┼──────────┤
  1424. │Begin   │                              │txretries = 0             │START     │
  1425. │        │                              │reset txtimer             │          │
  1426. │        │                              │blksize = startblksize    │          │
  1427. │        │                              │goodbytes = 0             │          │
  1428. │        │                              │goodneeded = 1024         │          │
  1429. │        │                              │braintimer = 120          │          │
  1430. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  1431. │START   │1│txretries == 10             │Report too many errors    │Abort     │
  1432. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1433. │        │2│else (txretries < 10)       │txstr AutoStart           │SWAIT     │
  1434. │        │ │                            │txpkt START               │          │
  1435. │        │ │                            │txtimer = 5               │          │
  1436. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1437. │SWAIT   │1│rxpkt START or              │txretries = 0             │INIT      │
  1438. │        │ │rxpkt INIT                  │reset txtimer             │          │
  1439. │        │ │                            │braintimer = 120          │          │
  1440. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1441. │        │2│txtimer expired             │Report tx timeout         │START     │
  1442. │        │ │                            │increment txretries       │          │
  1443. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1444. │INIT    │1│txretries == 10             │Report too many errors    │Abort     │
  1445. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1446. │        │2│else (txretries < 10)       │txpkt INIT(linkinfo)      │INITACK   │
  1447. │        │ │                            │txtimer = timeout/2       │          │
  1448. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1449. │INITACK │1│rxpkt INITACK               │txretries = 0             │RINIT     │
  1450. │        │ │                            │reset txtimer             │          │
  1451. │        │ │                            │braintimer = 120          │          │
  1452. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1453. │        │2│txtimer expired             │Report tx timeout         │INIT      │
  1454. │        │ │                            │increment txretries       │          │
  1455. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1456. │RINIT   │1│rxstate != INIT             │                          │NextFile  │
  1457. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1458. │NextFile│1│No files left?              │Report end of batch       │ToFName   │
  1459. │        │ │                            │Set NULL fileinfo         │          │
  1460. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1461. │        │2│Can access next file?       │Set up fileinfo           │ToFName   │
  1462. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1463. │        │3│Can't access file?          │Report access failure     │NextFile  │
  1464. ├────────┼─┴────────────────────────────┼──────────────────────────┼──────────┤
  1465. │ToFName │                              │txsyncid = 0              │FINFO     │
  1466. │        │                              │txretries = 0             │          │
  1467. │        │                              │reset txtimer             │          │
  1468. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  1469. │FINFO   │1│txretries == 10             │Report too many errors    │Abort     │
  1470. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1471. │        │2│txretries > 0               │txpkt FINFO(fileinfo)     │FINFOACK  │
  1472. │        │ │                            │txtimer = timeout/2       │          │
  1473. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1474. │        │3│else (txretries == 0)       │txpkt FINFO(fileinfo)     │FINFOACK  │
  1475. │        │ │                            │txtimer = timeout         │          │
  1476. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1477. │FINFOACK│1│NULL fname (end of batch) & │txtimer = idletimeout     │REND      │
  1478. │        │ │rxpkt FINFOACK              │braintimer = 120          │          │
  1479. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1480. │        │2│rxpkt FINFOACK &            │txpos = FINFOACK(pos)     │DATA      │
  1481. │        │ │FINFOACK(pos) >= 0          │txretries = 0             │          │
  1482. │        │ │                            │txlastack = 0             │          │
  1483. │        │ │                            │braintimer = 120          │          │
  1484. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1485. │        │3│rxpkt FINFOACK &            │They already have file    │NextFile  │
  1486. │        │ │FINFOACK(pos) == -1)        │braintimer = 120          │          │
  1487. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1488. │        │4│rxpkt FINFOACK &            │Skip this file for now    │NextFile  │
  1489. │        │ │FINFOACK(pos) == -2)        │braintimer = 120          │          │
  1490. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1491. │        │5│txtimer expired             │Report tx timeout         │FINFO     │
  1492. │        │ │                            │inrease txretries         │          │
  1493. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1494. │DATA    │1│rxstate != Done &           │txtimer = idletimeout     │XWAIT     │
  1495. │        │ │hdxlink == True             │                          │          │
  1496. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1497. │        │2│rxpkt DATAACK &             │txlastack = DATAACK(pos)  │          │
  1498. │        │ │DATAACK(pos) > txlastack    │                          │          │
  1499. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1500. │        │3│rxpkt RPOS &                │Skip this file for now    │SkipFile  │
  1501. │        │ │RPOS(pos) < 0               │braintimer = 120          │          │
  1502. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1503. │        │4│rxpkt RPOS &                │Report too many errors    │Abort     │
  1504. │        │ │RPOS(id) == txsyncid &      │                          │          │
  1505. │        │ │inc txretries == 10         │                          │          │
  1506. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1507. │        │5│rxpkt RPOS &                │txpos = RPOS(pos)         │          │
  1508. │        │ │RPOS(id) != txsyncid &      │txsyncid = RPOS(id)       │          │
  1509. │        │ │RPOS(pos) >= 0              │txretries = 1             │          │
  1510. │        │ │                            │blksize = RPOS(blksize)   │          │
  1511. │        │ │                            │goodbytes = 0             │          │
  1512. │        │ │                            │inc goodneeded + 1024     │          │
  1513. │        │ │                            │if (goodneeded > 8192)    │          │
  1514. │        │ │                            │   goodneeded = 8192      │          │
  1515. │        │ │                            │braintimer = 120          │          │
  1516. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1517. │        │6│File seek/read error or     │Skip this file for now    │SkipFile  │
  1518. │        │ │user wishes to skip file    │                          │          │
  1519. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1520. │        │7│txwindow &                  │if (txretries > 0)        │DATAACK   │
  1521. │        │ │txpos >= txlastack+txwindow │   txtimer = timeout/2    │          │
  1522. │        │ │                            │else                      │          │
  1523. │        │ │                            │   txtimer = timeout      │          │
  1524. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1525. │        │8│Enough room in output &     │txpkt DATA(pos,data)      │          │
  1526. │        │ │more filedata(blksize) to go│txpos += datalen          │          │
  1527. │        │ │                            │inc goodbytes + datalen   │          │
  1528. │        │ │                            │if goodbytes > goodneeded │          │
  1529. │        │ │                            │   Store txpos,blksize    │          │
  1530. │        │ │                            │   blksize * 2 (max.2048) │          │
  1531. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1532. │        │9│End of filedata reached     │                          │EOF       │
  1533. ├────────┼─┴────────────────────────────┼──────────────────────────┼──────────┤
  1534. │SkipFile│                              │txpos = -1                │EOF       │
  1535. │        │                              │txretries = 0             │          │
  1536. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  1537. │DATAACK │1│txretries == 10             │Report too many errors    │Abort     │
  1538. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1539. │        │2│rxpkt DATAACK &             │txlastack = DATAACK(pos)  │DATA      │
  1540. │        │ │DATAACK(pos) > txlastack &  │txretries = 0             │          │
  1541. │        │ │txpos < DATAACK(pos) + txwin│reset txtimer             │          │
  1542. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1543. │        │3│rxpkt RPOS                  │Handle RPOS in state DATA │          │
  1544. │        │ │                            │but stay in this state    │          │
  1545. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1546. │        │4│txtimer expired             │Report tx timeout         │DATA      │
  1547. │        │ │                            │increment txretries       │          │
  1548. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1549. │XWAIT   │1│rxstate == Done             │reset txtimer             │DATA      │
  1550. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1551. │        │2│rxpkt DATAACK &             │txlastack = DATAACK(pos)  │          │
  1552. │        │ │DATAACK(pos) > txlastack    │                          │          │
  1553. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1554. │        │3│rxpkt RPOS                  │Handle RPOS in state DATA │          │
  1555. │        │ │                            │but stay in this state    │          │
  1556. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1557. │        │4│rxpkt IDLE                  │hdxlink = False           │DATA      │
  1558. │        │ │                            │reset txtimer             │          │
  1559. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1560. │        │5│txtimer expired             │txpkt IDLE                │          │
  1561. │        │ │                            │txtimer = idletimeout     │          │
  1562. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1563. │EOF     │1│txretries == 10             │Report too many errors    │Abort     │
  1564. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1565. │        │2│txretries > 0               │txpkt EOF(txpos)          │EOFACK    │
  1566. │        │ │                            │txtimer = timeout/2       │          │
  1567. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1568. │        │3│else (txretries == 0)       │txpkt EOF(txpos)          │EOFACK    │
  1569. │        │ │                            │txtimer = timeout         │          │
  1570. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1571. │EOFACK  │1│rxpkt EOFACK                │braintimer = 120          │NextFile  │
  1572. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1573. │        │2│rxpkt DATAACK &             │txlastack = DATAACK(pos)  │          │
  1574. │        │ │DATAACK(pos) > txlastack    │                          │          │
  1575. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1576. │        │3│rxpkt RPOS &                │rxpos == -2               │EOF       │
  1577. │        │ │RPOS(pos) == -2 &           │                          │          │
  1578. │        │ │rxpos != -2                 │                          │          │
  1579. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1580. │        │4│rxpkt RPOS &                │Handle as in state DATA   │DATA      │
  1581. │        │ │RPOS(pos) >= 0              │                          │          │
  1582. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1583. │        │5│txtimer expired             │Report tx timeout         │EOF       │
  1584. │        │ │                            │increment txretries       │          │
  1585. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1586. │REND    │1│rxstate == DONE &           │txretries = 0             │END       │
  1587. │        │ │devtxstate == DONE          │                          │          │
  1588. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1589. │        │2│txtimer expired             │txpkt IDLE                │          │
  1590. │        │ │                            │txtimer = idletimeout     │          │
  1591. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1592. │END     │1│txretries == 10             │                          │Abort     │
  1593. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1594. │        │2│else (txretries < 10)       │txpkt END (twice)         │ENDACK    │
  1595. │        │ │                            │txtimer = timeout/2       │          │
  1596. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1597. │ENDACK  │1│rxpkt END                   │txpkt END (thrice)        │Done      │
  1598. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1599. │        │2│txtimer expired             │Report tx timeout         │END       │
  1600. │        │ │                            │increment txretries       │          │
  1601. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  1602.  
  1603.  
  1604.  
  1605. GENERAL RECEIVER (rxstate HRX_...)
  1606. ┌────────┬──────────────────────────────┬──────────────────────────┬──────────┐
  1607. │State   │Predicate(s)                  │Action(s)                 │Next state│
  1608. ├────────┼──────────────────────────────┼──────────────────────────┼──────────┤
  1609. │Begin   │                              │reset rxtimer             │START     │
  1610. │        │                              │lastrxdlen = startblksize │          │
  1611. │        │                              │(tx handles braintimer)   │          │
  1612. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  1613. │INIT    │1│rxpkt INIT &                │txpkt INITACK             │FINFO     │
  1614. │        │ │INIT(options) are compatible│Set options               │          │
  1615. │        │ │                            │braintimer = 120          │          │
  1616. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1617. │        │2│INIT(options) not compatible│Report link failure       │Abort     │
  1618. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1619. │FINFO   │1│rxpkt INIT (apparent dup)   │txpkt INITACK             │          │
  1620. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1621. │        │2│rxpkt FINFO &               │Report end of batch       │          │
  1622. │        │ │FINFO(fileinfo) == Empty    │txpkt FINFOACK            │DONE      │
  1623. │        │ │                            │braintimer = 120          │          │
  1624. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1625. │        │3│rxpkt FINFO &               │do not want this file     │          │
  1626. │        │ │we already have file        │txpkt FINFOACK(-1)        │          │
  1627. │        │ │                            │braintimer = 120          │          │
  1628. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1629. │        │4│rxpkt FINFO &               │Skip this file for now    │          │
  1630. │        │ │open/diskspace error        │txpkt FINFOACK(-2)        │          │
  1631. │        │ │                            │braintimer = 120          │          │
  1632. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1633. │        │5│rxpkt FINFO &               │rxpos = resume offset     │ToData    │
  1634. │        │ │file we want to resume      │                          │          │
  1635. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1636. │        │6│rxpkt FINFO &               │rxpos = 0                 │ToData    │
  1637. │        │ │new file for us             │                          │          │
  1638. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1639. │        │7│rxpkt EOF (apparent dup)    │txpkt EOFACK              │          │
  1640. ├────────┼─┴────────────────────────────┼──────────────────────────┼──────────┤
  1641. │ToData  │                              │txpkt FINFOACK(rxpos)     │DATA      │
  1642. │        │                              │rxsyncid = 0              │          │
  1643. │        │                              │rxlastsync = 0;           │          │
  1644. │        │                              │rxretries = 0             │          │
  1645. │        │                              │reset rxtimer             │          │
  1646. │        │                              │braintimer = 120          │          │
  1647. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  1648. │DATA    │1│rxpkt FINFO (apparent dup)  │txpkt FINFOACK(rxpos)     │          │
  1649. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1650. │        │2│rxpkt DATA &                │Store data                │          │
  1651. │        │ │DATA(pos) == rxpos          │rxpos += datalen          │          │
  1652. │        │ │                            │rxretries = 0             │          │
  1653. │        │ │                            │rxlastsync = rxpos        │          │
  1654. │        │ │                            │reset rxtimer             │          │
  1655. │        │ │                            │braintimer = 120          │          │
  1656. │        │ │                            │if (rxwindow)             │          │
  1657. │        │ │                            │   txpkt DATAACK(rxpos)   │          │
  1658. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1659. │        │3│rxpkt DATA &                │Report bad rxpos          │BadPos    │
  1660. │        │ │DATA(pos) != rxpos          │                          │          │
  1661. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1662. │        │4│rxpkt EOF &                 │Close file, received ok   │OkEOF     │
  1663. │        │ │EOF(pos) == rxpos           │                          │          │
  1664. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1665. │        │5│rxpkt EOF &                 │Close, save for resume    │OkEOF     │
  1666. │        │ │EOF(pos) == -2              │                          │          │
  1667. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1668. │        │6│rxpkt EOF &                 │Report bad EOF            │BadPos    │
  1669. │        │ │EOF(pos) != rxpos           │                          │          │
  1670. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1671. │        │7│File write error or         │Close, save for resume    │          │
  1672. │        │ │user wishes to skip file    │rxpos = -2                │          │
  1673. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1674. │        │8│rxpkt IDLE &                │braintimer = 120          │          │
  1675. │        │ │hdxlink == False            │                          │          │
  1676. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1677. │BadPos  │1│DATA/EOF(pos) <= rxlastsync │rxretries = 0             │Timer     │
  1678. │        │ │                            │reset rxtimer             │          │
  1679. │        │ │                            │rxlastsync = pos          │          │
  1680. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1681. │        │2│DATA/EOF(pos) > rxlastsync  │rxlastsync = pos          │Timer     │
  1682. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1683. │Timer   │1│rxtimer expired             │                          │HdxLink   │
  1684. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1685. │        │2│else (rxtimer not expired)  │                          │DATA      │
  1686. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1687. │HdxLink │1│rxretries > 4 &             │hdxlink = True            │Retries   │
  1688. │        │ │txstate < REND &            │rxretries = 0             │          │
  1689. │        │ │originator == False &       │                          │          │
  1690. │        │ │hdxlink == False            │                          │          │
  1691. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1692. │        │2│else (above not the case)   │                          │Retries   │
  1693. ├────────┼─┼────────────────────────────┼──────────────────────────┼──────────┤
  1694. │Retries │1│inc rxretries == 10         │Report too many errors    │Abort     │
  1695. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1696. │        │2│rxretries == 1              │increase rxsyncid         │RPos      │
  1697. │        ├─┼────────────────────────────┼──────────────────────────┼──────────┤
  1698. │        │3│else (rxretries > 1)        │                          │RPos      │
  1699. ├────────┼─┴────────────────────────────┼──────────────────────────┼──────────┤
  1700. │RPos    │                              │lastrxdatalen/=2 (min.64) │DATA      │
  1701. │        │                              │txpkt RPOS (rxpos,        │          │
  1702. │        │                              │   lastrxdatalen,rxsyncid)│          │
  1703. │        │                              │rxtimer = timeout         │          │
  1704. ├────────┼──────────────────────────────┼──────────────────────────┼──────────┤
  1705. │OkEOF   │                              │txpkt EOFACK              │FINFO     │
  1706. │        │                              │reset rxtimer             │          │
  1707. │        │                              │braintimer = 120          │          │
  1708. ├────────┼─┬────────────────────────────┼──────────────────────────┼──────────┤
  1709. │DONE    │1│rxpkt FINFO (apparent dup)  │txpkt FINFOACK(-2)        │          │
  1710. └────────┴─┴────────────────────────────┴──────────────────────────┴──────────┘
  1711.  
  1712.  
  1713.     HYDRA in FidoNet technology mailers
  1714.     ═════════════════════════════════════════════════════════════════════
  1715.     HYDRA is suitable for use in FidoNet mailers. It can be implemented
  1716.     for EMSI and FTS-6 mail sessions. The FTS-6 (YooHoo) capability bit
  1717.     for HYDRA is 0x0020 (DOES_HYDRA). The EMSI and IEMSI protocol
  1718.     capability flag is HYD.
  1719.  
  1720.     When utilizing HYDRA in a mail session, two complete batches are
  1721.     always performed. Little else differs from a normal FTS-6 ZedZap mail
  1722.     session. The first batch is used to transmit all mail, files, and
  1723.     file requests by both sides. The second batch is always performed,
  1724.     sending nothing if there are no file requests to honor. The data
  1725.     buffers are not purged between the two batches since HYDRA ignores
  1726.     any leftovers from the previous batch (END packets, etc.).
  1727.  
  1728.     To integrate HYDRA into an existing mailer, the same code used for
  1729.     the ZedZap session flow can be used, but instead of one transmit and
  1730.     one receive session, two transmit sessions (or batches) are used.
  1731.     When the HYDRA end of batch is initiated it will not be terminated
  1732.     until an end of batch has been received from the remote and the end
  1733.     of session sequence has been finished.
  1734.  
  1735.     Fido and FidoNet are registered marks of Tom Jennings and Fido
  1736.     Software.
  1737.  
  1738.  
  1739.     Error detection using CRCs
  1740.     ═════════════════════════════════════════════════════════════════════
  1741.     CRC (Cyclic Redundancy Check) values only provide their promised
  1742.     maximum error detection capability when properly applied, which
  1743.     involves calculating and transmitting low-bit first, presetting the
  1744.     CRC with all ones, and transmitting the ones' complement of the
  1745.     result. The receiver also initializes to all ones, processes all of
  1746.     the data AND the following CRC, and the result should match a "magic
  1747.     value" which is 0xf0b8 for the 16-bit CRC and 0xdebb20e3 for the
  1748.     32-bit CRC.
  1749.  
  1750.     The easiest and fastest way to perform CRC calculations is by using a
  1751.     table that does the algorithm's shift-operations in 8-bits at a time.
  1752.  
  1753.  
  1754.     CRC-16 error detection
  1755.     ─────────────────────────────────────────────────────────────────────
  1756.     16-bit CRC using the CCITT CRC-16 polynomial. This is the default at
  1757.     startup, and always used for HEX packets even if both sides are
  1758.     capable of handling 32-bit CRCs.
  1759.  
  1760.     This CRC-16 is not identical to the one used by the Xmodem and Zmodem
  1761.     file transfer protocols. The polynomial is the same
  1762.     (X^16+X^12+X^5+X^0 or 0x8408) but the bit-ordering is the opposite,
  1763.     and preconditioning and postconditioning is used as in 32-bit CRCs.
  1764.     This method is also used by the European version of X.25.
  1765.  
  1766.     The 16-bit CRC table is created as follows (pseudocode, the variable
  1767.     CRC16 and the table of 256 entries are 16-bit unsigned integers):
  1768.  
  1769.         FOR (i=0 TO 255)
  1770.             {
  1771.             CRC16=i
  1772.             FOR (N=1 TO 8)
  1773.                 {
  1774.                 IF (CRC16 AND 1)
  1775.                     CRC16=(CRC16 >> 1) XOR 0x8408
  1776.                 ELSE
  1777.                     CRC16=CRC16 >> 1
  1778.                 }
  1779.             CRC16TAB[i]=CRC16;
  1780.             }
  1781.  
  1782.     When processing data, each byte is run through the CRC calculation
  1783.     routine as follows (variable CRC stores the 16-bit CRC value/result,
  1784.     C is the next 8-bit char):
  1785.  
  1786.         CRC=CRC16TAB[(CRC XOR C) AND 0xff] XOR ((CRC>>8) AND 0x00ff)
  1787.  
  1788.  
  1789.     CRC-32 error detection
  1790.     ─────────────────────────────────────────────────────────────────────
  1791.     32-bit CRC using the CCITT CRC-32 polynomial. Support of CRC-32 is
  1792.     optional and signalled in the INIT packet.
  1793.  
  1794.     If both sides indicate they can handle CRC-32, all packets except
  1795.     those transmitted in HEX format use this algorithm instead of CRC-16
  1796.     to improve error detection.
  1797.  
  1798.     This CRC-32 is identical to the one used by the Zmodem protocol.
  1799.     The polynomial is (0xedb88320):
  1800.  
  1801.     X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
  1802.  
  1803.     The principal method of calculation, transmission, and checking is
  1804.     identical to CRC-16 as described above, but the "magic value" for
  1805.     32-bit CRC is 0xdebb20e3.
  1806.  
  1807.     The CRC-32 table is created as follows (pseudocode, the variable
  1808.     CRC32 and the table of 256 entries are 32-bit unsigned integers):
  1809.  
  1810.     FOR (i=0 TO 255)
  1811.         {
  1812.         CRC32=i
  1813.         FOR (N=1 TO 8)
  1814.             {
  1815.             IF (CRC32 AND 1)
  1816.                 CRC32 = (CRC32 >> 1) XOR 0xedb88320
  1817.             ELSE
  1818.                 CRC32 = CRC32 >> 1
  1819.             }
  1820.         CRC32TAB[i] = CRC32;
  1821.         }
  1822.  
  1823.     When processing data, each byte is run through the CRC calculation
  1824.     routine as follows (variable CRC stores the 32-bit CRC value/result,
  1825.     C is the next 8-bit character):
  1826.  
  1827.         CRC=CRC32TAB[(CRC XOR C) AND 0xFF] XOR ((CRC>>8) AND 0x00ffffff)
  1828.  
  1829.  
  1830.     The authors
  1831.     ═════════════════════════════════════════════════════════════════════
  1832.     The authors can be reached at the following addresses:
  1833.  
  1834.     Joaquim H. Homrighausen                    Arjen G. Lentz
  1835.     389, route d'Arlon                         Lentz Software Development
  1836.     L-8011 Strassen                            Langegracht 7B
  1837.     Luxembourg                                 3811 BT Amersfoort
  1838.                                                The Netherlands
  1839.     joho@ae.lu
  1840.     FidoNet 2:270/17                           aglentz@fido.lu
  1841.                                                FidoNet 2:283/512
  1842.  
  1843.  
  1844.     The name HYDRA
  1845.     ═════════════════════════════════════════════════════════════════════
  1846.     Hydra is a greek mythological creature (the watersnake). Like the
  1847.     Nemeic lion, Hydra is the daughter of the giant Typhon and the snake
  1848.     Echidna.
  1849.  
  1850.     She grew up in the marshes of Lerna near/in Argolis (Argos). There
  1851.     she ate entire herds of cattle and destroyed large cropfields. Later,
  1852.     she lived in caves on a hill near the spring of Amymone.
  1853.  
  1854.     Hydra is a monstrous large snake with nine heads: eight mortal ones,
  1855.     and one (the middle one) immortal. She was defeated and killed by
  1856.     Heracles (Hercules) - son of Zeus and Alcemene, grandson of Perseus -
  1857.     as the second of his twelve tasks, with the help of his cousin
  1858.     Iolaos. Every time he cut of one of the heads with his sword, two new
  1859.     heads grew in its place. So Iolaos scorched the wound of each cut off
  1860.     head with burning branches so the head couldn't grow on again.
  1861.  
  1862.     Heracles buried the last and immortal head under a stone nearby. He
  1863.     also dipped his arrows in Hydra's poisonous blood, thereafter the
  1864.     wounds caused by those arrows were incurable.
  1865.  
  1866.  
  1867.     Also star constellation (sign of the watersnake) in the equatorial
  1868.     zone.
  1869.  
  1870.  
  1871.     Also a type of sweetwater polip (the Hydroidea Thin, tubeshaped body
  1872.     can be full contracted, just like the six (or more) tentacles. There
  1873.     is no generation change, the gender-products grow directly on the
  1874.     body.
  1875.  
  1876.     The animals catch their prey with nettlecells, and are very verocious.
  1877.     They can be found in various stilstanding and flowing water and were
  1878.     first described by Anthonie van Leeuwenhoek in the year 1704.
  1879.  
  1880.  
  1881.     Also small island (spelled Idhra in modern Greek) of the Sargonic
  1882.     group in the Aegean Sea, just of the eastern tip of the Argolis
  1883.     peninsula of the Peloponesus (Attika). Its length (NE/SW) is 21 km,
  1884.     with a total area of 49,6 square km. Its highest point is 597 meters
  1885.     above sea level. Population of 2794 (latest census: 1981). Only one
  1886.     real city with the same name as the island. Once quite wooded and
  1887.     well watered, now denuded and dry, with almost no arable land
  1888.     (infertile limestone). Certain times of the year the people have to
  1889.     ship in water from the main land. Its Turkish name is Camliza which
  1890.     means "Place of Pines".
  1891.  
  1892.     References:
  1893.          Dutch:  Oosthoeks Encyclopedie
  1894.                  Grote Winklerprins Encyclopedie
  1895.        English:  Encyclopaedia Brittannica
  1896.  
  1897.     --- end of "hydra.doc" ---
  1898.