n2dsy@hou2d.UUCP (G.BEATTIE) (04/08/88)
Here is the document file that I promised last week describing the Asynchonous Framing Technique (AFT). This is only a framing protocol. It contains NO state machine, transparency and error control. Four files will follow this message(but only in comp.protocols.tcp-ip): 1. AFT.C - a machine independent implementation of the AFT software. 2. ASYNC.ASM - an MS-DOS device driver to use with AFT. 3. TEST1.C - a test and demo programme for the AFT software. 4. Test2.C - another test and demo programme for the AFT software. The file contained in this message is AFT.DOC. If you like what you see here in the document file, go to the newsgroup "comp.protocols.tcp-ip" and pull the other four files. Machine Independent Asynchronous Framing Technique (AFT) Version 1.0, by John Howell (N2FVN), August 7, 1987 This software is in the public domain. It is provided on an 'as is' basis without warranty. This is a portable implementation of the Asynchronous Framing Technique for X.25 (X.25/AFT) Revision 2 coded in the C language. AFT is a protocol which allows X.25 style framing to be done over an asynchronous communication channel. It allows for detection of the start and end of frames, detection of corrupted transmission, and sending of frames containing eight bit characters over communication links which cannot accept all possible characters. AFT is intended to be used as a replacement for the X.25 level two framing technique in cases where synchronous communication is not practical. For more information on X.25/AFT contact: Research Department Hayes Microcomputer Products, Inc. 705 Westech Drive Norcross, Georgia 30092 This implementation of AFT supports all features of revision two of the protocol. A method is provided to select which of the possible options are to be used. The implementation has three components: 1) Option Selection 2) Frame Transmission 3) Frame Reception The interface to the user of AFT was chosen to allow use of the software in many different environments. As provided this software requires additional machine dependant software to provide a full AFT implementation. The transmit and receive routines have been implemented in such a way that they may be called either within interrupt service routines as characters are sent and received or they may be called from non-interrupt routines which fill or empty queues used by the software doing the hardware dependant portion of the I/O. This implementation provides no actual routines to do I/O since this is highly machine dependant. In this program the terms bytes and characters are used as synonyms for eight bit groups of data which are known as octets in X.25. This program assumes that the implementation of type 'char' is an eight bit value. Also the type 'int' is assumed to be at least 16 bits in size. An attempt has been made to only use those features of C which are common to nearly all implementations. This code was actually tested using Microsoft C version 4.0. Some abbreviations used in this program are: FCS Frame Check Sequence LEN Length OPT Option RX Receive SUB Substituted TX Transmit Interface to External Routines The following routines make up the interface to the AFT implementation. It is assumed that the user is familiar with the C language. aft_options(ebdt, transparency_level, suffix_len, suffix, max_rx_len) This routine selects the options to be used for AFT communication. It must be called at least once before any other AFT routines are used. It may be called again later to change the previously selected options. This should only be done at a time when no frames are being sent or received. 'ebdt' is a flag (0=false, non-zero=true) which determines whether the eight-bit data transparency option is to be used on transmit and receive. The EBDT option should only be used in cases where the communication path does not transfer the high order bit of characters transparently. This option must be selected identically on both the sending and receiving sides of the link. Use of this feature adds an extra 14% overhead to the communications. 'transparency_level' takes on one of three values. Zero indicates that basic transparency is to be used. This should be selected when the communication path allows transparent transmission of all 256 possible characters. One indicates that flow control transparency is to be used. This should be selected when the transmission of X-on and X- off characters would cause the receiver to perform flow control which would prevent them from appearing within frames. Two indicates that control-character transparency is to be used. This should be selected when the transmission path does not allow transparent transmission of some control characters. Each higher numbered option adds more overhead to transmitted frames. 'suffix_len' is the length of a string which will be appended to each frame when it is sent. This feature is used to provide any extra characters which the receiving system may require to recognize the end of an input. Zero should be used when no frame suffix is to be added which is the most common case. The maximum suffix allowed is three characters. 'suffix' is a pointer to the actual character string in which the suffix is stored. This is only examined if the suffix length is non-zero. This string may contain up to three characters which may each be any value. 'max_rx_len' is the size of the buffer which will be used for receiving frames. This length is used by the receive frame routines to prevent storing data past the end of the buffer. Received frames which are too long will be discarded. The receive buffer provided must be at least two characters larger than the maximum expected frame size. This is required since buffer is used for temporary storage of the two character frame check sequence. int aft_tx_start(length, buffer) This is the routine used to do the setup for transmitting a frame. This routine returns a value of zero if a new frame cannot be started because a frame is already being sent, or a value of one if the request is accepted. In either case this routine returns immediately. The actual sending of the frame is done by aft_tx_char. 'length' is the length of the frame to be sent. The minimum valid frame length is two characters. The maximum is limited only by the restrictions of the C compiler used. 'buffer' is a pointer to the buffer holding the frame to be sent. This buffer should contain only the address, control, and information fields for the frame. The AFT routines will generate starting and closing flags, frame check sequence, and other characters required for transparency when the frame is sent. AFT will not modify the contents of the buffer. The buffer contents should not be modified by any other routines until transmission of the frame is completed or an incorrect frame may be sent. int aft_tx_char() This routine is used to obtain the next character to be sent in order to transmit a frame. It returns characters to be sent as a value from zero to 255 in the low order byte of the returned integer and zero in the high order byte of the integer. Once the final character of the frame has been sent the return value will be one in the high order byte and a flag character in the low order byte. This routine is designed to be either used as a non- interrupt routine to which is called in a loop to fill an outgoing buffer which will be sent by other software or called within an interrupt routine when a transmitter buffer empty condition occurs to provide the next character to be sent. When used in an interrupt routine the caller may ignore the upper byte of the return value. If this is done then the result will be to send continuous flags between frames. aft_tx_abort() This routine may be called to cause aft_send_char to abort the frame it is currently sending. A lead-in character is sent followed by a flag to indicate that the receiver should ignore the frame. It a frame is not being sent then no action is taken. int aft_tx_complete() This routine is intended to be used in cases where aft_tx_char is being called during interrupt service. It provides a way for non-interrupt routines to poll for frame sending completion. It returns zero if a frame is currently being sent or one if no frame is being sent. A frame is considered to be sent once aft_tx_char is about to return the frame complete code (0x017E) to its caller. Instead of using this routine aft_tx_char may be easily modified to take any desired action when sending of a frame is completed. int aft_rx_start(buffer) This routine provides a buffer for the AFT software to use to receive a frame into. This routine returns a value of zero if the buffer is not accepted because a receive operation is already in progress or a value of one if the buffer is accepted. In either case this routine returns immediately to its caller. 'buffer' is a pointer to the buffer into which the frame will be received. This buffer will be filled one character at a time by aft_rx_char as characters for the frame are received. Once the receive operation is completed this buffer will hold the received frame address, control, and information fields. All flags, FCS, and extra transparency characters will have been removed. int aft_rx_char(c) This routine accepts a received character and adds it to the frame being received. If aft_rx_start has not been called to provide a buffer for receive then the first few characters of the frame will be saved in a temporary buffer. This will prevent loss of data in cases where aft_rx_char is being called directly by the receive interrupt service routine. This routine can also be called by a non-interrupt routine which obtains the characters from a received character queue. A value of zero is returned if this character does not complete a frame. A non-zero return value indicates that the character provided completed the received frame. In this case the value returned is the length of the frame which is contained in the receive buffer. If an invalid FCS is received at the end of the frame then the frame will be discarded. A frame of less than two bytes will also be discarded. 'c' is the next character received from the communication port. aft_rx_error() This routine is called to indicate the occurrence of an error condition on the communication line. Possible conditions may be framing error, break received, parity error (if in EBDT mode), time out (which is not required for AFT), or overrun. When this routine is called AFT discards the frame currently being received and begins searching for the start of the next frame. int aft_rx_complete() This routine is used in cases where aft_rx_char is being called during interrupt service. It provides a way for non- interrupt routines to poll for completion of a receive operation. It returns zero if the receive operation has not completed and the received frame length if it has. After this routine returns that a frame has completed then aft_rx_start should be called as quickly as possible to provide a new receive buffer. If this is not done in time then the next incoming frame may be lost. Instead of using this routine aft_rx_char may be easily modified to take any desired action when sending of a frame is completed.