T.30 FAX protocol handling

# What does it do?

The T.30 protocol is the core protocol used for FAX transmission. This module implements most of its key featrues. It does not interface to the outside work. Seperate modules do that for T.38, analogue line, and other forms of FAX communication.

Current features of this module include:

    - FAXing to and from multi-page TIFF/F files, whose images are one of the standard
      FAX sizes.
    - V.27ter, V.29 and V.17 modes (2400bps, to 14,400bps).
    - T.4 1D (MH), T.4 2D,(MR) and T.6 (MMR) compression.
    - Error correction mode (ECM).
    - All standard horizonal resolutions (R8, R16, 300dpi, 600dpi, 800dpi, 1200dpi).
    - All standard vertical resolutions (standard, fine, superfine, 300dpi, 600dpi, 800dpi, 1200dpi).
    - All standard page widths (A4, B4, A3).
    - All standard page lengths (A4, B4, North American letter, North American legal, continuous).
    - Monitoring and sending identifier strings (CSI, TSI, and CIG).
    - Monitoring and sending sub-address strings (SUB).
    - Monitoring and sending polling sub-addresses (SEP).
    - Monitoring and sending polled sub-addresses (PSA).
    - Monitoring and sending sender identifications (SID).
    - Monitoring and sending passwords (PWD).
    - Monitoring of non-standard facility frames (NSF, NSC, and NSS).
    - Sending custom non-standard facility frames (NSF, NSC, and NSS).
    - Analogue modem and T.38 operation.

# How does it work?

Some of the following is paraphrased from some notes found a while ago on the Internet. I cannot remember exactly where they came from, but they are useful.

## The answer (CED) tone

The T.30 standard says an answering fax device must send CED (a 2100Hz tone) for approximately 3 seconds before sending the first handshake message. Some machines send an 1100Hz or 1850Hz tone, and some send no tone at all. In fact, this answer tone is so unpredictable, it cannot really be used. It should, however, always be generated according to the specification.

## Common Timing Deviations

The T.30 spec. specifies a number of time-outs. For example, after dialing a number, a calling fax system should listen for a response for 35 seconds before giving up. These time-out periods are as follows:

    - T1 - 35+-5s: the maximum time for which two fax system will attempt to identify each other
    - T2 - 6+-1s:  a time-out used to start the sequence for changing transmit parameters
    - T3 - 10+-5s: a time-out used in handling operator interrupts
    - T5 - 60+-5s: a time-out used in error correction mode

These time-outs are sometimes misinterpreted. In addition, they are routinely ignored, sometimes with good reason. For example, after placing a call, the calling fax system is supposed to wait for 35 seconds before giving up. If the answering unit does not answer on the first ring or if a voice answering machine is connected to the line, or if there are many delays through the network, the delay before answer can be much longer than 35 seconds.

Fax units that support error correction mode (ECM) can respond to a post-image handshake message with a receiver not ready (RNR) message. The calling unit then queries the receiving fax unit with a receiver ready (RR) message. If the answering unit is still busy (printing for example), it will repeat the RNR message. According to the T.30 standard, this sequence (RR/RNR RR/RNR) can be repeated for up to the end of T5 (60+-5s). However, many fax systems ignore the time-out and will continue the sequence indefinitely, unless the user manually overrides.

All the time-outs are subject to alteration, and sometimes misuse. Good T.30 implementations must do the right thing, and tolerate others doing the wrong thing.

## Variations in the inter-carrier gap

T.30 specifies 75+-20ms of silence between signals using different modulation schemes. Examples are between the end of a DCS signal and the start of a TCF signal, and between the end of an image and the start of a post-image signal. Many fax systems violate this requirement, especially for the silent period between DCS and TCF. This may be stretched to well over 100ms. If this period is too long, it can interfere with handshake signal error recovery, should a packet be corrupted on the line. Systems should ensure they stay within the prescribed T.30 limits, and be tolerant of others being out of spec..

## Other timing variations

Testing is required to determine the ability of a fax system to handle variations in the duration of pauses between unacknowledged handshake message repetitions, and also in the pauses between the receipt of a handshake command and the start of a response to that command. In order to reduce the total transmission time, many fax systems start sending a response message before the end of the command has been received.

## Other deviations from the T.30 standard

There are many other commonly encountered variations between machines, including:

    - frame sequence deviations
    - preamble and flag sequence variations
    - improper EOM usage
    - unusual data rate fallback sequences
    - common training pattern detection algorithms
    - image transmission deviations
    - use of the talker echo protect tone
    - image padding and short lines
    - RTP/RTN handshake message usage
    - long duration lines
    - nonstandard disconnect sequences
    - DCN usage