home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / OSKBox.lzh / MAILBOX / FILES / WA8DED / host.doc < prev    next >
Text File  |  1990-04-25  |  36KB  |  738 lines

  1.                          WA8DED HOST MODE USER'S GUIDE
  2.  
  3.  
  4.                            Paul T. Williamson, KB5MU
  5.  
  6.                                   23 May 1986
  7.  
  8.   Abstract:  This  document  explains  the use of Host mode with WA8DED's AX.25
  9. Version 2 Multi-channel TNC Firmware, Version 1.1 for the TAPR TNC-1.    It  is
  10. based  on  the  information  provided in the WA8DED document (Version 1.0), the
  11. W6IXU mailbox software (13 May 1986 revision),  and  the  WA8DED  Split  Screen
  12. Terminal  Emulator  (SS,  28 April 1986 version).  It is intended for use by an
  13. application programmer attempting to communicate with the TNC in Host mode, and
  14. assumes that the programmer is already familiar with user-mode operation of the
  15. WA8DED firmware.
  16.  
  17.  
  18.  
  19.                                    Chapter 1
  20.                               What Is Host Mode?
  21.   WA8DED's TNC firmware provides two entirely independent user interfaces.  The
  22. default  user  interface is designed for use by a human operator at a terminal.
  23. Host mode, on the other hand, is  designed  for  use  by  a  specially-designed
  24. computer  program.    It  allows the computer to maintain strict control of the
  25. computer-TNC link, and to obtain control information that  would  otherwise  be
  26. difficult to extract from the normal data stream.
  27.  
  28.   One  of  the most common bugaboos of computer-TNC interfacing has always been
  29. flow control.  The TNC is capable of sending data faster than the computer  can
  30. process  it,  and  likewise the computer is capable of sending data faster than
  31. the TNC can transmit it.  It is theoretically possible to  solve  this  problem
  32. with  either  hardware  flow  control  (RTS/CTS  wires  in  the RS-232 link) or
  33. software flow control (XON/XOFF characters inserted in the data stream).   Both
  34. of  these  methods  are tricky and error-prone, however.  Hardware flow control
  35. may not always be available, and software flow  control,  even  when  it  works
  36. adequately,  leads  to data transparency problems (i.e., what if the data being
  37. transmitted contains XON or XOFF?).  If everything is not exactly  right,  data
  38. will be lost.
  39.  
  40.   WA8DED's Host mode solves this problem by 
  41.  
  42.    1. Speaking only when spoken to, and
  43.  
  44.    2. Limiting all data bursts to 256 bytes.
  45.  
  46. The  first  point  allows  the  computer  program to go off and do other things
  47. (write data out to disk, handle the  console,  make  coffee)  without  worrying
  48. about  data  coming  from  the TNC and dropping on the floor.  The second point
  49. allows computers that have a hard time  handling  fast  serial  data  (e.g.,  a
  50. Commodore  64  with no UART) to concentrate on the receiving task to fill a 256
  51. byte buffer, then go off and process the data without worrying about additional
  52. data  arriving  before  it has time to process that batch.  This scheme is very
  53. forgiving of inefficient serial routines, so that faster computers can get away
  54. with simple byte-level polling (e.g., a program for the IBM PC can use the BIOS
  55. serial port routines).
  56.  
  57.   On the subject of serial routines, notice that the TNC does not handle either
  58. hardware  or  software flow control when in Host mode.  You must make sure that
  59. your serial drivers will not send unwanted XON and XOFF characters to the TNC.
  60.  
  61.   Since the TNC speaks only when spoken to, the computer must  constantly  poll
  62. the  TNC  to  find  out what is happening on the link.  In user mode, connected
  63. data received over the AX.25 link is immediately displayed (if that channel  is
  64. selected).    In  Host  mode,  the  TNC  is  not  allowed  to  send information
  65. unsolicited, so the program must ask the  TNC  for  data  periodically.    This
  66. implies  that  the  computer-TNC  link will be busy most of the time.  Frequent
  67. polling and a relatively high baud rate (say 4800 or 9600 baud)  are  desirable
  68. for  applications that require quick response times.  A user monitoring data in
  69. real time will notice delays if the delay between polls is too great.
  70.  
  71.   The format of these short computer-TNC exchanges is  carefully  specified  to
  72. eliminate  ambiguity  and  minimize overhead.  The computer sends to the TNC in
  73. the following format:
  74.  
  75.     {channel}{info/cmd}{count}{data...}
  76.  
  77.   Channel is the channel number to which the transmission pertains.    Info/cmd
  78. distinguishes  between  information  to be transmitted and commands to be acted
  79. upon by the TNC.  Count specifies the number of bytes to  follow,  and  Data...
  80. are the actual data bytes or command bytes.  The details of this format will be
  81. discussed later.  All computer-to-TNC transmissions must follow this format.
  82.  
  83.   The TNC sends to the computer one of several different formats:  
  84.  
  85.     {channel}{code=0}                      short format
  86.  
  87. or 
  88.  
  89.     {channel}{code=1-5}{data...}{0}        null-terminated format
  90.  
  91. or 
  92.  
  93.     {channel}{code=6-7}{count}{data...}    byte-count format]
  94.  
  95.   Notice that you can always tell what is to follow  from  the  code  received.
  96. The  last  format is very similar to the computer-to-TNC format. The details of
  97. these formats will be described later.  All computer-to-TNC transmissions  will
  98. follow one of these formats.
  99.  
  100.  
  101.  
  102.                                    Chapter 2
  103.                         Entering and Exiting Host Mode
  104.   Host mode is entered by giving a JHOST 1 command to the TNC in the usual way.
  105. This sounds simple enough.  Just send <ESC>JHOST1<CR> to the TNC.  But what  if
  106. something  has  already  been sent to the TNC (say by powerup transients)?  The
  107. <ESC> will be treated as data (echoed as ^[ by the TNC) and the command will be
  108. lost.    We can work around this by sending a ^U or ^X first, to clear the junk
  109. out.  It might also be a good idea to send an XON, in case the junk included an
  110. XOFF.  So  we  send  ^Q^X^[JHOST1^M  (or,  if  you  prefer the ASCII mnemonics,
  111. <DC1><CAN><ESC>JHOST1<CR>):  
  112.  
  113.             11 18 1B 4A 48 4F 53 54 31 0D
  114.             ^Q ^X ^[ J  H  O  S  T  1  CR
  115.  
  116. This will work every time, if the TNC is in user mode.  If the TNC is  in  Host
  117. mode  already, we should detect that fact and recover.  Host mode recovery will
  118. be discussed later in this document.
  119.  
  120.   Exiting Host mode is a simple matter of sending a JHOST0 command to the  TNC.
  121. The  TNC  will  acknowledge  the  JHOST0 command in the usual Host-mode fashion
  122. before  returning  to  user  mode,  so  you  can  use  your  regular  Host-mode
  123. transaction routine.
  124.  
  125.   Note  that  a  QRES  command issued in Host mode will dump you back into user
  126. mode.  It does not acknowledge in Host-mode fashion before doing so.  The  Host
  127. mode  parameter  is not stored in NOVRAM, so it is not possible to "wake up" in
  128. Host mode.  It is, however, possible to PERM other parameters from Host mode.
  129.  
  130.  
  131.  
  132.                                    Chapter 3
  133.                               Commanding the TNC
  134.   OK, now that we're in Host mode, let's look at a simple command exchange.  We
  135. will  gloss  over  some of the details for this first look.  Suppose we want to
  136. turn off Unattended mode.  In normal user  mode,  we  would  type  <ESC>U0<CR>.
  137. That  is,  we would send a U0 command to the TNC.  To send a U0 command in Host
  138. mode, we have  to  assemble  a  transmission  for  the  TNC  according  to  the
  139. computer-to-TNC format.
  140.  
  141.   Recall that the computer-to-TNC format is:  
  142.  
  143.     {channel}{info/cmd}{count}{data...}
  144.  
  145. The  first  byte,  channel,  is  the  channel number.  In user mode, it doesn't
  146. matter what channel you are on when you give a U command.   Likewise,  in  Host
  147. mode,  it  doesn't matter which channel you send this command to.  Let's choose
  148. channel 0.  The second byte is info/cmd; this is a command, so this byte has to
  149. be  1.    The  command data we are going to send is simply "U0", the same ASCII
  150. string we would have used between <ESC> and <CR> to do the same thing  in  user
  151. mode.    This  is  two bytes long, so the count byte should indicate two bytes.
  152. Count is encoded as (length - 1), so the third byte of the  message  should  be
  153. 2 - 1 = 1.
  154.  
  155.   The  following is an illustration of the required transmission.  The top line
  156. lists the bytes to be sent in hex notation.  The first  byte  sent  is  on  the
  157. left.    Below  each byte of the top line is an explanation of that byte.  This
  158. format  will  be  used  throughout  this  document  to  illustrate  Host   mode
  159. transmissions.  
  160.  
  161.             00 01 01 55 30
  162.             |  |  |  U  0
  163.             |  |  |
  164.             |  |  +-- Count = 1    (two bytes)
  165.             |  +----- Info/cmd = 1 (this is a command)
  166.             +-------- Channel = 0
  167.  
  168.   Note  that  no  carriage  return is required or allowed.  As soon as the byte
  169. count is fulfilled (i.e., when the last byte has been received) the TNC accepts
  170. the transmission as complete.
  171.  
  172.   How do we know the TNC got the command OK?  Simple: it responds with a status
  173. message.  A U0 command can't fail, so we can guess that the status message will
  174. be  a success message.  A U0 command doesn't return any information, either, so
  175. no data field will be present.  So, we can guess that the TNC will respond with
  176. a transmission in the short format:  
  177.  
  178.             00 00
  179.             |  |
  180.             |  +--- Code = 0 (Success, no data follows)
  181.             +------ Channel 0
  182.  
  183.   Now  we  can  see  the  general  shape  of  any computer-TNC transaction: the
  184. computer sends a command to the TNC, and the TNC responds with  an  appropriate
  185. message.    In  writing  a program to interface with Host mode, we will have to
  186. take care of building these  outgoing  frames  and  interpreting  the  incoming
  187. frames.    If  we take a hint from WA8DED and W6IXU, we will implement a single
  188. routine that does the dirty work of sending a transmission  and  receiving  the
  189. response.
  190.  
  191.   In  receiving  the  response,  the  routine  will  have  to  decide  how many
  192. characters to read from the serial port by looking at the code  in  the  second
  193. byte of the TNC's message.  This code tells it in which format the transmission
  194. will be: short format with no following data, null-terminated format with  some
  195. data  ending  in  a  null,  or byte-count format with a count and the specified
  196. number of bytes of information.
  197.  
  198.   Notice that the routine that receives the response doesn't have to  have  any
  199. knowledge  of  the  current  state  of the TNC or the application program.  The
  200. meaning and encoding of the TNC's response is completely determined by the data
  201. in  that  response.   This simplifies the routine that receives the response by
  202. isolating it from the complexities of the application program.
  203.  
  204.  
  205.  
  206.                                    Chapter 4
  207.                         Polling the TNC: the G command
  208.   The most essential, basic transaction in Host mode is the  G  command,  which
  209. polls  a  specific channel of the TNC for events and data.  A typical Host-mode
  210. application program will constantly send G commands to the  TNC  and  interpret
  211. the  responses.    Since  the G command is a query to a specific channel of the
  212. TNC, it is necessary to send G commands to all of the channels that may  be  in
  213. use.    Data  received from a station connected on channel 1 (or 2, or 3, or 4)
  214. will be sent to the computer as a response to a G command directed to channel 1
  215. (or 2, or 3, or 4).  Monitored data will be sent to the computer as a G command
  216. directed to channel 0.
  217.  
  218.   The G command has three forms.  A command of  "G"  will  return  any  of  the
  219. possible  responses  that  is  available.    A command of "G0" will return only
  220. information.  A command of "G1" will return only link status responses.    This
  221. is  useful  when  you  are  waiting for a link status change and do not wish to
  222. handle data, or vice versa.
  223.  
  224.   The only other thing that changes in a G command is the channel number.    Be
  225. sure  to send G commands to all channels that may be active.  You need not send
  226. G commands to channel 4 if Y is 3, for instance, but you must send  G  commands
  227. to  channels 0 through 3.  The unrestricted G command has the following format:
  228.  
  229.             0x 01 00 47
  230.             |  |  |  G
  231.             |  |  |
  232.             |  |  +--- Count = 0    (one byte of data)
  233.             |  +------ Info/cmd = 1 (this is a command)
  234.             +--------- Channel = x  (where x is 0, 1, 2, 3, or 4)
  235.  
  236.   There are only a few possible responses to a G command.  If the program polls
  237. the  TNC  constantly  with  G  commands,  most  of the replies will be "nothing
  238. available".  This simply means nothing new has happened on the link  since  the
  239. last  poll.   This response applies to any of the three forms of the G command.
  240. Each of the other possible responses indicates an event on the AX.25 channel: a
  241. change  in Link Status (such as "DISCONNECTED"), which is evoked by G or G1, or
  242. receipt of a frame of monitored or connected data, which is evoked by G or  G0.
  243. The  detailed  formats  of  these  responses  will  be  discussed later in this
  244. document.
  245.  
  246.   Monitored information is handled specially by the G command.  Monitored  data
  247. is  handled  on  channel  0  of  the  TNC.    The monitor header is transmitted
  248. separately from the monitor  information.    The  monitor  header  transmission
  249. indicates  whether  or  not  there is an associated information transmission to
  250. come.  If there is, it will be the next response on channel 0.  This scheme has
  251. two  results:  it  spares  the  programmer  the  task  of  parsing  out monitor
  252. information from the monitor header (if such is  desired),  and  it  keeps  the
  253. maximum  transmission  length  down to the maximum data field size, rather than
  254. the data field size plus the monitor header size (and thus allows the count  to
  255. be a single byte).
  256.  
  257.   This  scheme  for  monitored data might be considered a violation of the rule
  258. that each computer-TNC transmission  is  self-contained  and  self-explanatory.
  259. The   monitored  information  transmission  is  qualified  by  the  immediately
  260. preceding monitor header transmission.  You many want to treat a monitor header
  261. with  information  as  a  special case in the application program, and grab the
  262. corresponding monitor information transmission immediately.
  263.  
  264.  
  265.  
  266.                                    Chapter 5
  267.                        Details of Computer-to-TNC Format
  268.   As we said before, the computer-to-TNC transmissions must always follow  this
  269. format:  
  270.  
  271.     {channel}{info/cmd}{count}{data...}
  272.  
  273.   The  three  header  bytes  (channel,  info/cmd,  and  count) are expressed in
  274. binary.  For instance, to specify 0 for any of these values, send a  NULL  (^@,
  275. '\0' for C fans, CHR$(0) for BASIC fans).  DON'T send the ASCII character '0'.
  276.  
  277.   The data field will contain one of the following:  
  278.  
  279.    1. Data to be transmitted via the AX.25 link.
  280.  
  281.    2. A command string just like you might issue from the normal user mode
  282.       (the part strictly between the <ESC> and the <CR>).
  283.  
  284.    3. "G", the Host-mode poll command.  
  285.  
  286.   If data for the AX.25 link is to be sent, the  info/cmd  byte  must  be  zero
  287. (binary  zero,  remember, not ASCII "0").  The data field may contain any bytes
  288. whatsoever, but not more than 256 of  them.    Count  up  the  data  bytes  and
  289. subtract one to find the value of the count byte.  So if you're connected to me
  290. on channel 2, and you want to say 
  291.  
  292.            Hello
  293.  
  294. to me, send the TNC this transmission:  
  295.  
  296.             02 00 05 48 65 6C 6C 6F 0D
  297.             |  |  |  H  e  l  l  o  CR
  298.             |  |  |                 |
  299.             |  |  |                 +---- (this is a data byte)
  300.             |  |  +- Count = 5    (six bytes of data)
  301.             |  +---- Info/cmd = 0 (this is information to be sent)
  302.             +------- Channel = 2  (since I'm on your channel 2)
  303.  
  304. Note that the CR is sent as data, and will be  transmitted  through  the  AX.25
  305. link.  It is not part of the transmission format.
  306.  
  307.   If  the  information  is  sent  to  channel  0, it will go out unproto to the
  308. address on channel 0 (default CQ).  If information is sent on  channel  1  -  4
  309. while that channel is not connected, it is ignored.
  310.  
  311.   If  a  command string is to be sent, the info/cmd byte must be one.  The data
  312. field should contain the ASCII command string.  It does not  contain  <ESC>  or
  313. <CR>, just the characters that would go between them to form a normal user-mode
  314. command.  For instance, to set TXDELAY to 30, send the TNC this transmission:  
  315.  
  316.  
  317.             00 01 02 54 33 30
  318.             |  |  |  T  3  0
  319.             |  |  |
  320.             |  |  +- Count = 2    (three bytes of data)
  321.             |  +---- Info/cmd = 1 (this is a command)
  322.             +------- Channel = 0  (doesn't matter here)
  323.  
  324.   The channel number is significant for the  C,  D,  F,  G,  L,  N,  O,  and  V
  325. commands.    C,  D, F, N, O, and V commands are channel specific in exactly the
  326. same way as they are in user mode.  The L command is different  in  Host  mode,
  327. and  will  be discussed later in this document.  The G command has already been
  328. discussed.  The channel number is not significant for other commands.  You  may
  329. use  whatever  channel  number  is  convenient.    (WA8DED and W6IXU send these
  330. commands to channel 0).
  331.  
  332.   The byte-count format for the computer-to-TNC transmissions is  used  because
  333. it  provides  "data  transparency".    This means that any bytes whatsoever may
  334. appear in the data field.  The TNC can just accept the next so many bytes  from
  335. the  computer  without  thinking about it.  If a special character were used to
  336. signal the end of the data, that character could not occur in the  data.    The
  337. null-terminated  format  can  use  this  scheme,  since  the  data  in these is
  338. guaranteed not to contain a null.
  339.  
  340.   Unfortunately, the byte-count scheme is not very robust.  If a  character  is
  341. lost  or  a spurious character is inserted, the computer and TNC could stay out
  342. of synch forever.  We must take pains to detect loss of synch  and  to  recover
  343. from  the  fault.   Fortunately, the first byte of a transmission has only five
  344. valid values (0-4) and the second byte has only two valid values (0 and 1),  so
  345. it is possible to detect a loss of synchronization in most cases.  Timeouts can
  346. also be used to detect synch failures.  Once the error is detected, recovery is
  347. possible.  Host mode recovery will be discussed later in this document.
  348.  
  349.  
  350.  
  351.                                    Chapter 6
  352.                        Details of TNC-to-Computer Format
  353.   The  TNC-to-computer  transmission  format is a bit more complicated than the
  354. computer-to-TNC format.  The key to decoding a transmission from the TNC is the
  355. code  byte that follows the channel number byte.  The following table gives the
  356. code values:
  357.  
  358.                              TNC-TO-COMPUTER CODES
  359.  
  360.           Code Meaning                       Format
  361.           ==== =======                       ======
  362.           0    Success, nothing follows      short format
  363.                (Nothing available)
  364.           1    Success, message follows      null-terminated format
  365.           2    Failure, message follows      null-terminated format
  366.           3    Link status                   null-terminated format
  367.           4    Monitor header/no info        null-terminated format
  368.           5    Monitor header/info           null-terminated format
  369.           6    Monitor information           byte-count format
  370.           7    Connected information         byte-count format
  371.  
  372.   These various formats are used for different purposes.  Codes 0, 1, and 2 are
  373. responses  to  an  information or command transmission from the computer.  If a
  374. batch of information was queued for transmission successfully or if  a  command
  375. completes successfully without returning any information, a code 0 transmission
  376. will be the reply:  
  377.  
  378.             02 00
  379.             |  |
  380.             |  +---- Code = 1    (Success, nothing follows)
  381.             +------- Channel = 2 (same as the info or command sent)
  382.  
  383. If the command is successful and returns information (like any command  without
  384. an  argument), a code 1 transmission will be the reply.  The returned data will
  385. follow the code, "null terminated".  This just means that a 0 byte will  appear
  386. after the last information byte.  For example, consider an M command without an
  387. argument.  In user mode, the user would type  <ESC>M<CR>,  and  the  TNC  would
  388. display something like 
  389.  
  390.     * IUSCRT *
  391.  
  392. In Host mode, the command would be 
  393.  
  394.             00 01 00 4D
  395.             |  |  |  M
  396.             |  |  |
  397.             |  |  +---- Count = 0    (one data byte)
  398.             |  +------- Info/cmd = 1 (this is a command)
  399.             +---------- Channel = 0  (Doesn't matter here)
  400.  
  401. and the response might be 
  402.  
  403.             00 01 49 55 53 43 52 54 00
  404.             |  |  I  U  S  C  R  T  |
  405.             |  |                    +---- Null termination
  406.             |  |
  407.             |  +---- Code = 1    (Success with info)
  408.             +------- Channel = 0 (same as in the query)
  409.  
  410. If  the command failed, or the information cannot be queued for transmission, a
  411. code 2 transmission with one of these error messages will be the reply:  
  412.  
  413.                                FAILURE MESSAGES
  414.  
  415.                                 INVALID COMMAND
  416.                             TNC BUSY - LINE IGNORED
  417.                            CHANNEL ALREADY CONNECTED
  418.                            STATION ALREADY CONNECTED
  419.  
  420.   For example if you send a data line:  
  421.  
  422.             03 00 0C 48 65 6C 6C 6F 20 74 68 65 72 65 2E 0D
  423.             |  |  |  H  e  l  l  o     t  h  e  r  e  .  CR
  424.             |  |  |                                      |
  425.             |  |  |            (this is a data byte) ----+
  426.             |  |  +---- Count = 12   (thirteen data bytes)
  427.             |  +------- Info/cmd = 0 (this is information)
  428.             +---------- Channel = 3  (for instance)
  429.  
  430. when the TNC has no RAM available to buffer the data line, it will respond with
  431. a code 2 failure message to inform you of the condition:  
  432.  
  433.             03 02 544C432042555359202D204C494C452049474C4F524544 00
  434.             |  |  T N C   B U S Y   -   L I N E   I G N O R E D  |
  435.             |  |                                                 |
  436.             |  +---- Code = 2 (Failure)      Null terminator ----+
  437.             +------ Channel = 3 (same as the info sent)
  438.  
  439. If you send a bad command:  
  440.  
  441.             00 01 03 4A 55 4C 4B
  442.             |  |  |  J  U  N  K
  443.             |  |  |
  444.             |  |  +---- Count = 3    (four data bytes)
  445.             |  +------- Info/cmd = 1 (this is a command)
  446.             +---------- Channel = 0  (Doesn't matter here.)
  447.  
  448. It will complain about it with a code 2 failure message:  
  449.  
  450.             00 02 49 4E 56 41 4C 49 44 20 43 4F 4D 4D 41 4E 44 00
  451.             |  |  I  N  V  A  L  I  D     C  O  M  M  A  N  D  |
  452.             |  |                                               |
  453.             |  +---- Code = 2 (Failure)     Null termination --+
  454.             +------- Channel = 0 (same as the command sent)
  455.  
  456.   The  remaining  codes,  3 through 7, are used only as responses to a "G" poll
  457. command.  A 0 code can also be a response to a G poll.  A  0  code  means  that
  458. nothing is available for that channel: that is, no events worthy of notice have
  459. taken place on the channel polled.  This is the most common  response  to  a  G
  460. command.  
  461.  
  462.             0x 00
  463.             |  |
  464.             |  +---- Code = 0    (Nothing available)
  465.             +------- Channel = x (same as the G command)
  466.  
  467.   A code of 3 signifies a Link Status message.  These messages are:  
  468.  
  469.                              LINK STATUS MESSAGES
  470.  
  471.                ({n}) BUSY fm {call} via {digipeaters}
  472.                ({n}) CONNECTED to {call} via {digipeaters}
  473.                ({n}) LINK RESET fm {call} via {digipeaters}
  474.                ({n}) LINK RESET to {call} via {digipeaters}
  475.                ({n}) DISCONNECTED fm {call} via {digipeaters}
  476.                ({n}) LINK FAILURE with {call} via {digipeaters}
  477.                CONNECT REQUEST fm {call} via {digipeaters}
  478.                ({n}) FRAME REJECT (x y z) fm {call} via {digipeaters}
  479.                ({n}) FRAME REJECT (x y z) to {call} via {digipeaters}
  480.  
  481.   These messages should look familiar, since they are identical to the messages
  482. displayed by the TNC in user mode.  {n} is the channel number.  Notice that the
  483. channel number in the message is redundant information.  The channel number may
  484. be omitted from this message in a future release.
  485.  
  486.   For instance, if I connect to you direct on channel 2, a poll  of  channel  2
  487. (not  necessarily the next one, depending on what else is going on) will return
  488. the event:  
  489.  
  490.          02 03 28322920434F4E4E454354454420746F204B42354D55 00
  491.          |  |  ( 2 )   C O N N E C T E D   t o   K B 5 M U  |
  492.          |  |                                               |
  493.          |  +---- Code = 3 (Link Status) Null termination --+
  494.          +------- Channel = 2
  495.  
  496.   Codes of 4 and 5 both signify a monitor header.  This  is  a  null-terminated
  497. format message containing the 
  498.  
  499.     fm {call} to {call} via {digipeaters} ctl {name} pid {hex}
  500.  
  501. string  that  forms  a monitor header.  The monitor header is also identical to
  502. the monitor header displayed in user mode.  If the code was  4,  the  monitored
  503. frame contained no information field, so the monitor header is all you get.  If
  504. you monitor KB6C responding to a connect request from me and then poll  channel
  505. 0, you'll get:  
  506.  
  507.     0004666D204B42364320746F204B42354D552063746C2055612070494420463000
  508.     | | f m   K B 6 C   t o   K B 5 M U   c t l   U A   p i d   F 0 |
  509.     | |                                                             |
  510.     | +---- Code = 4 (Monitor, no info)        Null termination ----+
  511.     +------- Channel = 0 (Monitor info is always on channel 0)
  512.  
  513.   If  the code was 5, the monitored frame did contain an information field.  In
  514. this case, another G command to channel 0 will return the monitored information
  515. with  a code of 6.  Since data transmissions must be transparent, the monitored
  516. information is passed as a byte-count format transmission.    That  is,  it  is
  517. preceded  by a count byte (one less than the number of bytes in the field).  No
  518. null terminator is used in this case.  Since codes  4,  5,  and  6  pertain  to
  519. monitored  information,  they will be seen only on channel 0.  If you hear KB6C
  520. say "Hi" to NK6K, and then poll channel 0, you'll get:  
  521.  
  522.     0005666D204B42364320746F204E4B364B2063746C204930302070494420463000
  523.     | | f m   K B 6 C   t o   N K 6 K   c t l   I 0 0   p i d   F 0 |
  524.     | |                                           | |               |
  525.     | |                           or whatever ----+-+               |
  526.     | |                                                             |
  527.     | +---- Code = 5 (Monitor, info follows)   Null termination ----+
  528.     +------ Channel = 0 (Monitor info is always on channel 0)
  529.  
  530. and then the very next poll to channel 0 will get:  
  531.  
  532.          00 06 02 48 69 0D
  533.          |  |  |  H  i  CR
  534.          |  |  |        |
  535.          |  |  |        +----    (this is a data byte)
  536.          |  |  +---- Count = 2   (three bytes of data)
  537.          |  +------- Code = 6    (monitored information)
  538.          +---------- Channel = 0 (Monitor info is always on channel 0)
  539.  
  540.   A code of 7 signifies connected information, so it will only  be  seen  on  a
  541. connected  channel  1  through  4.  It is a byte-count format transmission, for
  542. data transparency.  If you're connected to me on channel 4 and I  say  "Hi",  a
  543. poll of channel 4 will return:  
  544.  
  545.             04 07 02 48 69 0D
  546.             |  |  |  H  i  CR
  547.             |  |  |        |
  548.             |  |  |        +----    (this is a data byte)
  549.             |  |  +---- Count = 2   (three bytes of data)
  550.             |  +------- Code = 7    (connected information)
  551.             +---------- Channel = 4 (info was received on channel 4)
  552.  
  553.  
  554.  
  555.                                    Chapter 7
  556.                     Querying Channel Status: the L command
  557.   One  of the most powerful features of the Host mode is the ability to ask the
  558. TNC for a status report on a given channel.  This  report  is  similar  to  the
  559. report  given by the L command in user mode, but more extensive.  To obtain the
  560. Channel Status report, send an L command to the channel of interest.   The  TNC
  561. will  (barring  error)  respond with a code 1 packet.  The information field of
  562. this packet will contain six decimal number in ASCII delimited by spaces.
  563.  
  564.   A typical Channel Status query:  
  565.  
  566.             01 01 00 4C
  567.             |  |  |  L
  568.             |  |  |
  569.             |  |  +---- Count = 0    (one data byte)
  570.             |  +------- Info/cmd = 1 (this is a command)
  571.             +---------- Channel = 1  (give me a report on channel 1)
  572.  
  573. A typical Channel Status report:  
  574.  
  575.             01 01 30 20 30 20 30 20 30 20 30 20 30 00
  576.             |  |  0     0     0     0     0     0  |
  577.             |  |                                   |
  578.             |  |              null termination ----+
  579.             |  +------- Code = 1    (Success with info)
  580.             +---------- Channel = 1 (this is a report on channel 1)
  581.  
  582.   Channel 0 does not have as much state information as  a  regular  connectable
  583. channel, so a Channel Status query to channel 0:  
  584.  
  585.             00 01 00 4C
  586.             |  |  |  L
  587.             |  |  |
  588.             |  |  +---- Count = 0    (one data byte)
  589.             |  +------- Info/cmd = 1 (this is a command)
  590.             +---------- Channel = 0  (give me a report on channel 0)
  591.  
  592. Will return a Channel Status report similar to this one.  
  593.  
  594.             00 01 30 20 33 00
  595.             |  |  0     3  |
  596.             |  |           |
  597.             |  |           +---- null termination
  598.             |  +------- Code = 1    (Success with info)
  599.             +---------- Channel = 0 (this is a report on channel 0)
  600.  
  601.   The interpretation of the returned information is as follows:  
  602.  
  603.  
  604.                              CHANNEL STATUS FORMAT
  605.  
  606.           a b c d e f
  607.           a = Number of link status messages not yet displayed
  608.           b = Number of receive frames not yet displayed
  609.           c = Number of send frames not yet transmitted
  610.           d = Number of transmitted frames not yet acknowledged
  611.           e = Number of tries on current operation
  612.           f = Link state
  613.  
  614.               Possible link states are:
  615.                0 = Disconnected
  616.                1 = Link Setup
  617.                2 = Frame Reject
  618.                3 = Disconnect Request
  619.                4 = Information Transfer
  620.                5 = Reject Frame Sent
  621.                6 = Waiting Acknowledgement
  622.                7 = Device Busy
  623.                8 = Remote Device Busy
  624.                9 = Both Devices Busy
  625.               10 = Waiting Acknowledgement and Device Busy
  626.               11 = Waiting Acknowledgement and Remote Busy
  627.               12 = Waiting Acknowledgement and Both Devices Busy
  628.               13 = Reject Frame Sent and Device Busy
  629.               14 = Reject Frame Sent and Remote Busy
  630.               15 = Reject Frame Sent and Both Devices Busy
  631.  
  632.           NOTE 1:  Only items a and b are displayed for channel 0.
  633.           NOTE 2:  Only states 0 - 4 are possible if version 1 is in use.
  634.  
  635.  
  636.   How  you  will use the Channel Status report will depend on your application.
  637. An interactive terminal program  might  simply  display  some  or  all  of  the
  638. information and leave it at that.  A mailbox program might want to wait for all
  639. packets  to  be  acknowledged  before  starting  a  timeout  timer  or   before
  640. disconnecting.    A  mail  forwarder  would  want  to  make  sure  all data was
  641. acknowledged before considering its task done.  Any program might want to  give
  642. up  if  throughput is too low.  These functions are easy to implement with Host
  643. mode.
  644.  
  645.  
  646.  
  647.                                    Chapter 8
  648.                            Host Mode Error Recovery
  649.   What happens if something goes wrong on the computer-TNC link?   Maybe  there
  650. is  a  loose  wire,  or  maybe  RF  got into the RS-232 lines.  Maybe it's just
  651. Murphy.  For whatever reason, the data on the line got corrupted.  RS-232 links
  652. are  very  reliable, so you may never see an error, but the application program
  653. should be ready to cope with one.
  654.  
  655.   The error recovery program must assume  that  the  TNC  is  in  a  completely
  656. unknown state.  It might be expecting more bytes to fill a byte count (if bytes
  657. coming from the computer were  lost).    It  might  be  simply  waiting  for  a
  658. transmission,  but  the computer thought there was an error since data was lost
  659. or corrupted on its way from the TNC.  What we want to do is hit the TNC with a
  660. stream  of  data that will eventually bring it into a known state.  Preferably,
  661. this process should generate little or no spurious data on the AX.25 link.
  662.  
  663.   The first thing to do is dump any further data that may be  coming  from  the
  664. TNC.  We don't know what it is, and so we can't use it.  The possibility exists
  665. that this is connected information we're dropping on the floor.  This  is  just
  666. too bad.  There is nothing we can do.
  667.  
  668.   Next,  we just send ^A's one at a time until the TNC responds.  The first few
  669. ^A's may go to fulfill a byte count that the TNC  is  waiting  for.    If  this
  670. happens  to  be a connected information transmission, these ^A's will go out on
  671. the AX.25 link. Tough.  When any outstanding byte count is fulfilled  (no  more
  672. than 256 should be required), the following five ^A's will be seen as a command
  673. on channel 1.  This is why ^A is chosen: to make the TNC  interpret  the  extra
  674. transmission as a command.  
  675.  
  676.             01 01 01 01 01
  677.             |  |  |  ^A ^A
  678.             |  |  |
  679.             |  |  +-- Count of two bytes.
  680.             |  +----- This is a command.
  681.             +-------- Channel #1.
  682.  
  683. A  command  of  "^A^A"  doesn't mean anything, so the TNC should respond with a
  684. failure message:  
  685.  
  686.             01 02 49 4E 56 41 4C 49 44 20 43 4F 4D 4D 41 4E 44 00
  687.             |  |  I  N  V  A  L  I  D     C  O  M  M  A  N  D  |
  688.             |  |                                               |
  689.             |  +---- Failure message.       Null termination --+
  690.             +------- Same channel as the command specified
  691.  
  692. We don't really care what the response is, though.  It may not be exactly  what
  693. we  expect.    For  instance,  the  first  ^A might fulfill the byte count of a
  694. garbled command.  This would usually generate an error message  of  some  other
  695. type.   All we need is to get the first response.  Then we know that the TNC is
  696. waiting for a command.
  697.  
  698.   This implies that we have to wait between ^A's long enough to see if there is
  699. a  response yet.  This can make the recovery process a slow one.  For instance,
  700. if the TNC spuriously receives 00 00 FF, it  expects  to  see  256  data  bytes
  701. following,  so  we  will  have to send 256 ^A's before we get a response (which
  702. will probably be a success message, since this is just a data  transmission  to
  703. the TNC).  Fortunately, this error recovery process is not required very often.
  704.  
  705.  
  706.  
  707.                                    Chapter 9
  708.                          Acknowledgements and Comments
  709.   Thanks are of course due to Ronald E. Raikes, WA8DED, for creating the WA8DED
  710. AX.25 Version 2 Multi-channel TNC Firmware, for writing SS,  the  split  screen
  711. terminal  emulator that takes advantage of Host mode, and for proofreading this
  712. document for accuracy.  Thanks are also due to Mike Busch, W6IXU,  for  writing
  713. the mailbox software which was my first exposure to Host mode.
  714.  
  715.   Comments  on  this document would be appreciated.  You can send them to me by
  716. packet (KB5MU  KA6IQA on WestNet),  by  CompuServe  (75265,367),  by  telephone
  717. (619-458-1238) or by mail:  
  718.  
  719.         Paul T. Williamson, KB5MU
  720.         6583 Edmonton Ave.
  721.         San Diego, CA  92122
  722.  
  723. Heck, you could even send an NTS radiogram.
  724.  
  725.   SS,  the split screen terminal emulator, is an excellent example of Host-mode
  726. software.  It is available for non-commercial, non-profit use.  It runs  on  an
  727. IBM   PC   or  moderately  compatible,  and  provides  connect  status  display
  728. continuously for all five TNC channels, a typing  buffer,  a  transmitted  data
  729. buffer,  a  receive buffer, and a Link Status line at the bottom of the screen.
  730. It is written in C for the Microsoft C Compiler version 3.0, with  a  trace  of
  731. assembly  language for interface to console services.  I would be happy to send
  732. a copy of it to anyone who is interested and sends me a  diskette  with  return
  733. postage at the above address.
  734.  
  735.   The  W6IXU  Mailbox  software is not available for distribution at this time.
  736. It will become available for distribution by some means when it stabilizes  and
  737. a suitable means of distribution is found.
  738.