t30.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * t30.h - definitions for T.30 fax processing
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2003 Steve Underwood
00009  *
00010  * All rights reserved.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License version 2, as
00014  * published by the Free Software Foundation.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  *
00025  * $Id: t30.h,v 1.75 2007/05/28 14:11:59 steveu Exp $
00026  */
00027 
00028 /*! \file */
00029 
00030 #if !defined(_SPANDSP_T30_H_)
00031 #define _SPANDSP_T30_H_
00032 
00033 /*! \page t30_page T.30 FAX protocol handling
00034 
00035 \section t30_page_sec_1 What does it do?
00036 The T.30 protocol is the core protocol used for FAX transmission. This module
00037 implements most of its key featrues. It does not interface to the outside work.
00038 Seperate modules do that for T.38, analogue line, and other forms of FAX
00039 communication.
00040 
00041 Current features of this module include:
00042 
00043     - FAXing to and from multi-page TIFF/F files, whose images are one of the standard
00044       FAX sizes.
00045     - T.4 1D (MH), T.4 2D,(MR) and T.6 (MMR) compression.
00046     - Error correction (ECM)
00047     - All standard resolutions and page sizes
00048 
00049 \section t30_page_sec_2 How does it work?
00050 
00051 Some of the following is paraphrased from some notes found a while ago on the Internet.
00052 I cannot remember exactly where they came from, but they are useful.
00053 
00054 The answer (CED) tone
00055 
00056 The T.30 standard says an answering fax device must send CED (a 2100Hz tone) for
00057 approximately 3 seconds before sending the first handshake message. Some machines
00058 send an 1100Hz or 1850Hz tone, and some send no tone at all. In fact, this answer
00059 tone is so unpredictable, it cannot really be used. It should, however, always be
00060 generated according to the specification.
00061 
00062 Common Timing Deviations
00063 
00064 The T.30 spec. specifies a number of time-outs. For example, after dialing a number,
00065 a calling fax system should listen for a response for 35 seconds before giving up.
00066 These time-out periods are as follows: 
00067 
00068     * T1 - 35+-5s: the maximum time for which two fax system will attempt to identify each other
00069     * T2 - 6+-1s:  a time-out used to start the sequence for changing transmit parameters
00070     * T3 - 10+-5s: a time-out used in handling operator interrupts
00071     * T5 - 60+-5s: a time-out used in error correction mode
00072 
00073 These time-outs are sometimes misinterpreted. In addition, they are routinely
00074 ignored, sometimes with good reason. For example, after placing a call, the
00075 calling fax system is supposed to wait for 35 seconds before giving up. If the
00076 answering unit does not answer on the first ring or if a voice answering machine
00077 is connected to the line, or if there are many delays through the network,
00078 the delay before answer can be much longer than 35 seconds. 
00079 
00080 Fax units that support error correction mode (ECM) can respond to a post-image
00081 handshake message with a receiver not ready (RNR) message. The calling unit then
00082 queries the receiving fax unit with a receiver ready (RR) message. If the
00083 answering unit is still busy (printing for example), it will repeat the RNR
00084 message. According to the T.30 standard, this sequence (RR/RNR RR/RNR) can be
00085 repeated for up to the end of T5 (60+-5s). However, many fax systems
00086 ignore the time-out and will continue the sequence indefinitely, unless the user
00087 manually overrides. 
00088 
00089 All the time-outs are subject to alteration, and sometimes misuse. Good T.30
00090 implementations must do the right thing, and tolerate others doing the wrong thing.
00091  
00092 Variations in the inter-carrier gap
00093 
00094 T.30 specifies 75+-20ms of silence between signals using different modulation
00095 schemes. Examples are between the end of a DCS signal and the start of a TCF signal,
00096 and between the end of an image and the start of a post-image signal. Many fax systems
00097 violate this requirement, especially for the silent period between DCS and TCF.
00098 This may be stretched to well over 100ms. If this period is too long, it can interfere with
00099 handshake signal error recovery, should a packet be corrupted on the line. Systems
00100 should ensure they stay within the prescribed T.30 limits, and be tolerant of others
00101 being out of spec.. 
00102 
00103 Other timing variations
00104 
00105 Testing is required to determine the ability of a fax system to handle
00106 variations in the duration of pauses between unacknowledged handshake message
00107 repetitions, and also in the pauses between the receipt of a handshake command and
00108 the start of a response to that command. In order to reduce the total
00109 transmission time, many fax systems start sending a response message before the
00110 end of the command has been received. 
00111 
00112 Other deviations from the T.30 standard
00113 
00114 There are many other commonly encountered variations between machines, including:
00115 
00116     * frame sequence deviations
00117     * preamble and flag sequence variations
00118     * improper EOM usage
00119     * unusual data rate fallback sequences
00120     * common training pattern detection algorithms
00121     * image transmission deviations
00122     * use of the talker echo protect tone
00123     * image padding and short lines
00124     * RTP/RTN handshake message usage
00125     * long duration lines
00126     * nonstandard disconnect sequences
00127     * DCN usage
00128 */
00129 
00130 #define T30_MAX_DIS_DTC_DCS_LEN     22
00131 #define T30_MAX_IDENT_LEN           21
00132 #define T30_MAX_LOCAL_NSF_LEN       100
00133 
00134 typedef struct t30_state_s t30_state_t;
00135 
00136 /*!
00137     T.30 phase B callback handler.
00138     \brief T.30 phase B callback handler.
00139     \param s The T.30 context.
00140     \param user_data An opaque pointer.
00141     \param result The phase B event code.
00142 */
00143 typedef void (t30_phase_b_handler_t)(t30_state_t *s, void *user_data, int result);
00144 
00145 /*!
00146     T.30 phase D callback handler.
00147     \brief T.30 phase D callback handler.
00148     \param s The T.30 context.
00149     \param user_data An opaque pointer.
00150     \param result The phase D event code.
00151 */
00152 typedef void (t30_phase_d_handler_t)(t30_state_t *s, void *user_data, int result);
00153 
00154 /*!
00155     T.30 phase E callback handler.
00156     \brief T.30 phase E callback handler.
00157     \param s The T.30 context.
00158     \param user_data An opaque pointer.
00159     \param completion_code The phase E completion code.
00160 */
00161 typedef void (t30_phase_e_handler_t)(t30_state_t *s, void *user_data, int completion_code);
00162 
00163 /*!
00164     T.30 document handler.
00165     \brief T.30 document handler.
00166     \param s The T.30 context.
00167     \param user_data An opaque pointer.
00168     \param result The document event code.
00169 */
00170 typedef int (t30_document_handler_t)(t30_state_t *s, void *user_data, int status);
00171 
00172 /*!
00173     T.30 set a receive or transmit type handler.
00174     \brief T.30 set a receive or transmit type handler.
00175     \param user_data An opaque pointer.
00176     \param type The modem, tone or silence to be sent or received.
00177     \param short_train TRUE if the short training sequence should be used (where one exists).
00178     \param use_hdlc FALSE for bit stream, TRUE for HDLC framing.
00179 */
00180 typedef void (t30_set_handler_t)(void *user_data, int type, int short_train, int use_hdlc);
00181 
00182 /*!
00183     T.30 send HDLC handler.
00184     \brief T.30 send HDLC handler.
00185     \param user_data An opaque pointer.
00186     \param msg The HDLC message.
00187     \param len The length of the message.
00188 */
00189 typedef void (t30_send_hdlc_handler_t)(void *user_data, const uint8_t *msg, int len);
00190 
00191 /*!
00192     T.30 protocol completion codes, at phase E.
00193 */
00194 enum
00195 {
00196     T30_ERR_OK = 0,         /*! OK */
00197 
00198     /* Link problems */
00199     T30_ERR_CEDTONE,        /*! The CED tone exceeded 5s */
00200     T30_ERR_T0_EXPIRED,     /*! Timed out waiting for initial communication */
00201     T30_ERR_T1_EXPIRED,     /*! Timed out waiting for the first message */
00202     T30_ERR_T3_EXPIRED,     /*! Timed out waiting for procedural interrupt */
00203     T30_ERR_HDLC_CARRIER,   /*! The HDLC carrier did not stop in a timely manner */
00204     T30_ERR_CANNOT_TRAIN,   /*! Failed to train with any of the compatible modems */
00205     T30_ERR_OPERINTFAIL,    /*! Operator intervention failed */
00206     T30_ERR_INCOMPATIBLE,   /*! Far end is not compatible */
00207     T30_ERR_RX_INCAPABLE,   /*! Far end is not able to receive */
00208     T30_ERR_TX_INCAPABLE,   /*! Far end is not able to transmit */
00209     T30_ERR_NORESSUPPORT,   /*! Far end cannot receive at the resolution of the image */
00210     T30_ERR_NOSIZESUPPORT,  /*! Far end cannot receive at the size of image */
00211     T30_ERR_UNEXPECTED,     /*! Unexpected message received */
00212 
00213     /* TIFF file problems */
00214     T30_ERR_FILEERROR,      /*! TIFF/F file cannot be opened */
00215     T30_ERR_NOPAGE,         /*! TIFF/F page not found */
00216     T30_ERR_BADTIFF,        /*! TIFF/F format is not compatible */
00217 
00218     /* Phase E status values returned to a transmitter */
00219     T30_ERR_BADDCSTX,       /*! Received bad response to DCS or training */
00220     T30_ERR_BADPGTX,        /*! Received a DCN from remote after sending a page */
00221     T30_ERR_ECMPHDTX,       /*! Invalid ECM response received from receiver */
00222     T30_ERR_T5_EXPIRED,     /*! Timed out waiting for receiver ready (ECM mode) */
00223     T30_ERR_GOTDCNTX,       /*! Received a DCN while waiting for a DIS */
00224     T30_ERR_INVALRSPTX,     /*! Invalid response after sending a page */
00225     T30_ERR_NODISTX,        /*! Received other than DIS while waiting for DIS */
00226     T30_ERR_PHBDEADTX,      /*! Received no response to DCS, training or TCF */
00227     T30_ERR_PHDDEADTX,      /*! No response after sending a page */
00228 
00229     /* Phase E status values returned to a receiver */
00230     T30_ERR_ECMPHDRX,       /*! Invalid ECM response received from transmitter */
00231     T30_ERR_GOTDCSRX,       /*! DCS received while waiting for DTC */
00232     T30_ERR_INVALCMDRX,     /*! Unexpected command after page received */
00233     T30_ERR_NOCARRIERRX,    /*! Carrier lost during fax receive */
00234     T30_ERR_NOEOLRX,        /*! Timed out while waiting for EOL (end Of line) */
00235     T30_ERR_NOFAXRX,        /*! Timed out while waiting for first line */
00236     T30_ERR_T2EXPDCNRX,     /*! Timer T2 expired while waiting for DCN */
00237     T30_ERR_T2EXPDRX,       /*! Timer T2 expired while waiting for phase D */
00238     T30_ERR_T2EXPFAXRX,     /*! Timer T2 expired while waiting for fax page */
00239     T30_ERR_T2EXPMPSRX,     /*! Timer T2 expired while waiting for next fax page */
00240     T30_ERR_T2EXPRRRX,      /*! Timer T2 expired while waiting for RR command */
00241     T30_ERR_T2EXPRX,        /*! Timer T2 expired while waiting for NSS, DCS or MCF */
00242     T30_ERR_DCNWHYRX,       /*! Unexpected DCN while waiting for DCS or DIS */
00243     T30_ERR_DCNDATARX,      /*! Unexpected DCN while waiting for image data */
00244     T30_ERR_DCNFAXRX,       /*! Unexpected DCN while waiting for EOM, EOP or MPS */
00245     T30_ERR_DCNPHDRX,       /*! Unexpected DCN after EOM or MPS sequence */
00246     T30_ERR_DCNRRDRX,       /*! Unexpected DCN after RR/RNR sequence */
00247     T30_ERR_DCNNORTNRX,     /*! Unexpected DCN after requested retransmission */
00248 
00249     T30_ERR_BADPAGE,        /*! TIFF/F page number tag missing */
00250     T30_ERR_BADTAG,         /*! Incorrect values for TIFF/F tags */
00251     T30_ERR_BADTIFFHDR,     /*! Bad TIFF/F header - incorrect values in fields */
00252     T30_ERR_NODATA,         /*! Data requested is not available (NSF, DIS, DCS) */
00253     T30_ERR_NOMEM,          /*! Cannot allocate memory for more pages */
00254     T30_ERR_NOPOLL,         /*! Poll not accepted */
00255     T30_ERR_RETRYDCN,       /*! Disconnected after permitted retries */
00256     T30_ERR_CALLDROPPED     /*! The call dropped prematurely */
00257 };
00258 
00259 /*!
00260     I/O modes for the T.30 protocol.
00261 */
00262 enum
00263 {
00264     T30_MODEM_NONE = 0,
00265     T30_MODEM_PAUSE,
00266     T30_MODEM_CED,
00267     T30_MODEM_CNG,
00268     T30_MODEM_V21,
00269     T30_MODEM_V27TER_2400,
00270     T30_MODEM_V27TER_4800,
00271     T30_MODEM_V29_7200,
00272     T30_MODEM_V29_9600,
00273     T30_MODEM_V17_7200,
00274     T30_MODEM_V17_9600,
00275     T30_MODEM_V17_12000,
00276     T30_MODEM_V17_14400,
00277     T30_MODEM_DONE
00278 };
00279 
00280 enum
00281 {
00282     T30_FRONT_END_SEND_STEP_COMPLETE = 0,
00283     T30_FRONT_END_SEND_COMPLETE,
00284     /*! The current receive has completed. This is only needed to report an
00285         unexpected end of the receive operation, as might happen with T.38
00286         dying. */
00287     T30_FRONT_END_RECEIVE_COMPLETE,
00288     T30_FRONT_END_SIGNAL_PRESENT,
00289     T30_FRONT_END_SIGNAL_ABSENT
00290 };
00291 
00292 enum
00293 {
00294     T30_SUPPORT_V27TER = 0x01,
00295     T30_SUPPORT_V29 = 0x02,
00296     T30_SUPPORT_V17 = 0x04,
00297     T30_SUPPORT_V34 = 0x08,
00298     T30_SUPPORT_IAF = 0x10,
00299 };
00300 
00301 enum
00302 {
00303     T30_SUPPORT_NO_COMPRESSION = 0x01,
00304     T30_SUPPORT_T4_1D_COMPRESSION = 0x02,
00305     T30_SUPPORT_T4_2D_COMPRESSION = 0x04,
00306     T30_SUPPORT_T6_COMPRESSION = 0x08,
00307     T30_SUPPORT_T85_COMPRESSION = 0x10,     /* Monochrome JBIG */
00308     T30_SUPPORT_T43_COMPRESSION = 0x20,     /* Colour JBIG */
00309     T30_SUPPORT_T45_COMPRESSION = 0x40      /* Run length colour compression */
00310 };
00311 
00312 enum
00313 {
00314     T30_SUPPORT_STANDARD_RESOLUTION = 0x01,
00315     T30_SUPPORT_FINE_RESOLUTION = 0x02,
00316     T30_SUPPORT_SUPERFINE_RESOLUTION = 0x04,
00317 
00318     T30_SUPPORT_R4_RESOLUTION = 0x10000,
00319     T30_SUPPORT_R8_RESOLUTION = 0x20000,
00320     T30_SUPPORT_R16_RESOLUTION = 0x40000,
00321 
00322     T30_SUPPORT_300_300_RESOLUTION = 0x100000,
00323     T30_SUPPORT_400_400_RESOLUTION = 0x200000,
00324     T30_SUPPORT_600_600_RESOLUTION = 0x400000,
00325     T30_SUPPORT_1200_1200_RESOLUTION = 0x800000,
00326     T30_SUPPORT_300_600_RESOLUTION = 0x1000000,
00327     T30_SUPPORT_400_800_RESOLUTION = 0x2000000,
00328     T30_SUPPORT_600_1200_RESOLUTION = 0x4000000
00329 };
00330 
00331 enum
00332 {
00333     T30_SUPPORT_215MM_WIDTH = 0x01,
00334     T30_SUPPORT_255MM_WIDTH = 0x02,
00335     T30_SUPPORT_303MM_WIDTH = 0x04,
00336 
00337     T30_SUPPORT_UNLIMITED_LENGTH = 0x10000,
00338     T30_SUPPORT_A4_LENGTH = 0x20000,
00339     T30_SUPPORT_B4_LENGTH = 0x40000,
00340     T30_SUPPORT_US_LETTER_LENGTH = 0x80000,
00341     T30_SUPPORT_US_LEGAL_LENGTH = 0x100000
00342 };
00343 
00344 enum
00345 {
00346     T30_SUPPORT_SEP = 0x01,
00347     T30_SUPPORT_PSA = 0x02
00348 };
00349 
00350 enum
00351 {
00352     T30_IAF_MODE_T37 = 0x01,
00353     T30_IAF_MODE_T38 = 0x02,
00354     T30_IAF_MODE_FLOW_CONTROL = 0x04,
00355     /*! Continuous flow mode means data is sent as fast as possible, usually across
00356         the Internet, where speed is not constrained by a PSTN modem. */
00357     T30_IAF_MODE_CONTINUOUS_FLOW = 0x08,
00358     /*! No TCF means TCF is not exchanged. The end points must sort out usable speed
00359         issues locally. */
00360     T30_IAF_MODE_NO_TCF = 0x10,
00361     /*! No fill bits means do not insert fill bits, even if the T.30 messages request
00362         them. */
00363     T30_IAF_MODE_NO_FILL_BITS = 0x20,
00364     /*! No indicators means do not send indicator messages when using T.38. */
00365     T30_IAF_MODE_NO_INDICATORS = 0x40
00366 };
00367 
00368 /*!
00369     T.30 FAX channel descriptor. This defines the state of a single working
00370     instance of a T.30 FAX channel.
00371 */
00372 struct t30_state_s
00373 {
00374     /* This must be kept the first thing in the structure, so it can be pointed
00375        to reliably as the structures change over time. */
00376     t4_state_t t4;
00377 
00378     /*! \brief TRUE is behaving as the calling party */
00379     int calling_party;
00380 
00381     /*! \brief The local identifier string. */
00382     char local_ident[T30_MAX_IDENT_LEN];
00383     /*! \brief The identifier string supplied by the remote FAX machine. */
00384     char far_ident[T30_MAX_IDENT_LEN];
00385     /*! \brief The sub-address string to be sent to the remote FAX machine. */
00386     char local_sub_address[T30_MAX_IDENT_LEN];
00387     /*! \brief The sub-address string supplied by the remote FAX machine. */
00388     char far_sub_address[T30_MAX_IDENT_LEN];
00389     /*! \brief The selective polling sub-address supplied by the remote FAX machine. */
00390     char sep_address[T30_MAX_IDENT_LEN];
00391     /*! \brief The polled sub-address supplied by the remote FAX machine. */
00392     char psa_address[T30_MAX_IDENT_LEN];
00393     /*! \brief A password to be associated with the T.30 context. */
00394     char local_password[T30_MAX_IDENT_LEN];
00395     /*! \brief A password expected from the far end. */
00396     char far_password[T30_MAX_IDENT_LEN];
00397     /*! \brief The text which will be used in FAX page header. No text results
00398                in no header line. */
00399     char header_info[50 + 1];
00400     /*! \brief The country of origin of the remote machine, if known, else NULL. */
00401     const char *country;
00402     /*! \brief The vendor of the remote machine, if known, else NULL. */
00403     const char *vendor;
00404     /*! \brief The model of the remote machine, if known, else NULL. */
00405     const char *model;
00406     uint8_t local_nsf[T30_MAX_LOCAL_NSF_LEN];
00407     int local_nsf_len;
00408 
00409     /*! \brief A pointer to a callback routine to be called when phase B events
00410         occur. */
00411     t30_phase_b_handler_t *phase_b_handler;
00412     /*! \brief An opaque pointer supplied in event B callbacks. */
00413     void *phase_b_user_data;
00414     /*! \brief A pointer to a callback routine to be called when phase D events
00415         occur. */
00416     t30_phase_d_handler_t *phase_d_handler;
00417     /*! \brief An opaque pointer supplied in event D callbacks. */
00418     void *phase_d_user_data;
00419     /*! \brief A pointer to a callback routine to be called when phase E events
00420         occur. */
00421     t30_phase_e_handler_t *phase_e_handler;
00422     /*! \brief An opaque pointer supplied in event E callbacks. */
00423     void *phase_e_user_data;
00424 
00425     /*! \brief A pointer to a callback routine to be called when document events
00426         (e.g. end of transmitted document) occur. */
00427     t30_document_handler_t *document_handler;
00428     /*! \brief An opaque pointer supplied in document callbacks. */
00429     void *document_user_data;
00430 
00431     t30_set_handler_t *set_rx_type_handler;
00432     void *set_rx_type_user_data;
00433     t30_set_handler_t *set_tx_type_handler;
00434     void *set_tx_type_user_data;
00435 
00436     t30_send_hdlc_handler_t *send_hdlc_handler;
00437     void *send_hdlc_user_data;
00438    
00439     int phase;
00440     int next_phase;
00441     int state;
00442     int step;
00443 
00444     uint8_t dcs_frame[T30_MAX_DIS_DTC_DCS_LEN];
00445     int dcs_len;
00446     uint8_t dis_dtc_frame[T30_MAX_DIS_DTC_DCS_LEN];
00447     int dis_dtc_len;
00448     /*! \brief TRUE if a valid DIS has been received from the far end. */
00449     int dis_received;
00450     /*! \brief TRUE if a valid passwrod has been received from the far end. */
00451     int far_password_ok;
00452 
00453     /*! \brief A flag to indicate a message is in progress. */
00454     int in_message;
00455 
00456     /*! \brief TRUE if the short training sequence should be used. */
00457     int short_train;
00458 
00459     /*! \brief A count of the number of bits in the trainability test. */
00460     int training_test_bits;
00461     int training_current_zeros;
00462     int training_most_zeros;
00463 
00464     /*! \brief The current fallback step for the fast message transfer modem. */
00465     int current_fallback;
00466     /*! \brief The subset of supported modems allowed at the current time, allowing for negotiation. */
00467     int current_permitted_modems;
00468     /*! \brief TRUE if a carrier is present. Otherwise FALSE. */
00469     int rx_signal_present;
00470     /*! \brief TRUE if a modem has trained correctly. */
00471     int rx_trained;
00472     int current_rx_type;
00473     int current_tx_type;
00474 
00475     /*! \brief T0 is the answer timeout when calling another FAX machine.
00476         Placing calls is handled outside the FAX processing, but this timeout keeps
00477         running until V.21 modulation is sent or received.
00478         T1 is the remote terminal identification timeout (in audio samples). */
00479     int timer_t0_t1;
00480     /*! \brief T2 is the HDLC command timeout.
00481                T4 is the HDLC response timeout (in audio samples). */
00482     int timer_t2_t4;
00483     /*! \brief TRUE if the T2/T4 timer is actually timing T4 */
00484     int timer_is_t4;
00485     /*! \brief Procedural interrupt timeout (in audio samples). */
00486     int timer_t3;
00487     /*! \brief This is only used in error correcting mode. */
00488     int timer_t5;
00489     /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
00490     int timer_t6;
00491     /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
00492     int timer_t7;
00493     /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
00494     int timer_t8;
00495 
00496     int far_end_detected;
00497 
00498     int local_interrupt_pending;
00499     int crp_enabled;
00500     int line_encoding;
00501     int min_row_bits;
00502     int x_resolution;
00503     int y_resolution;
00504     int image_width;
00505     int retries;
00506     /*! \brief TRUE if error correcting mode is used. */
00507     int error_correcting_mode;
00508     int ppr_count;
00509     int receiver_not_ready_count;
00510     int octets_per_ecm_frame;
00511     uint8_t ecm_data[256][260];
00512     int16_t ecm_len[256];
00513     uint8_t ecm_frame_map[3 + 32];
00514     
00515     /*! \brief The current page number in ECM mode */
00516     int ecm_page;
00517 
00518     /*! \brief The current block number in ECM mode */
00519     int ecm_block;
00520     
00521     /*! \brief The number of frames in the current block number in ECM mode */
00522     int ecm_frames;
00523 
00524     /*! \brief The number of frames in the current burst of image transmission in ECM mode */
00525     int ecm_frames_this_burst;
00526     int ecm_current_frame;
00527     int ecm_at_page_end;
00528     int next_tx_step;
00529     int next_rx_step;
00530     char rx_file[256];
00531     int rx_stop_page;
00532     char tx_file[256];
00533     int tx_start_page;
00534     int tx_stop_page;
00535     int current_status;
00536     int iaf;
00537     int supported_modems;
00538     int supported_compressions;
00539     int supported_resolutions;
00540     int supported_image_sizes;
00541     int supported_polling_features;
00542     int ecm_allowed;
00543     
00544     int last_pps_fcf2;
00545     int ecm_first_bad_frame;
00546 
00547     /*! \brief Error and flow logging control */
00548     logging_state_t logging;
00549 };
00550 
00551 typedef struct
00552 {
00553     /*! \brief The current bit rate for image transfer. */
00554     int bit_rate;
00555     /*! \brief TRUE if error correcting mode is used. */
00556     int error_correcting_mode;
00557     /*! \brief The number of pages transferred so far. */
00558     int pages_transferred;
00559     /*! \brief The number of pages in the file (<0 if not known). */
00560     int pages_in_file;
00561     /*! \brief The number of horizontal pixels in the most recent page. */
00562     int width;
00563     /*! \brief The number of vertical pixels in the most recent page. */
00564     int length;
00565     /*! \brief The number of bad pixel rows in the most recent page. */
00566     int bad_rows;
00567     /*! \brief The largest number of bad pixel rows in a block in the most recent page. */
00568     int longest_bad_row_run;
00569     /*! \brief The horizontal column-to-column resolution of the page in pixels per metre */
00570     int x_resolution;
00571     /*! \brief The vertical row-to-row resolution of the page in pixels per metre */
00572     int y_resolution;
00573     /*! \brief The type of compression used between the FAX machines */
00574     int encoding;
00575     /*! \brief The size of the image, in bytes */
00576     int image_size;
00577     /*! \brief Current status */
00578     int current_status;
00579 } t30_stats_t;
00580 
00581 #if defined(__cplusplus)
00582 extern "C"
00583 {
00584 #endif
00585 
00586 /*! Initialise a T.30 context.
00587     \brief Initialise a T.30 context.
00588     \param s The T.30 context.
00589     \param calling_party TRUE if the context is for a calling party. FALSE if the
00590            context is for an answering party.
00591     \return 0 for OK, else -1. */
00592 int t30_init(t30_state_t *s,
00593              int calling_party,
00594              t30_set_handler_t *set_rx_type_handler,
00595              void *set_rx_type_user_data,
00596              t30_set_handler_t *set_tx_type_handler,
00597              void *set_tx_type_user_data,
00598              t30_send_hdlc_handler_t *send_hdlc_handler,
00599              void *send_hdlc_user_data);
00600 
00601 /*! Release a T.30 context.
00602     \brief Release a T.30 context.
00603     \param s The T.30 context. */
00604 void t30_release(t30_state_t *s);
00605 
00606 /*! Restart a T.30 context.
00607     \brief Restart a T.30 context.
00608     \param s The T.30 context.
00609     \return 0 for OK, else -1. */
00610 int t30_restart(t30_state_t *s);
00611 
00612 /*! Create and initialise a T.30 context.
00613     \brief Create and initialise a T.30 context.
00614     \param calling_party TRUE if the context is for a calling party. FALSE if the
00615            context is for an answering party.
00616     \return A pointer to the FAX context, or NULL if one could not be created.
00617 */
00618 t30_state_t *t30_create(int calling_party,
00619                         t30_set_handler_t *set_rx_type_handler,
00620                         void *set_rx_type_user_data,
00621                         t30_set_handler_t *set_tx_type_handler,
00622                         void *set_tx_type_user_data,
00623                         t30_send_hdlc_handler_t *send_hdlc_handler,
00624                         void *send_hdlc_user_data);
00625 
00626 /*! Free a T.30 context.
00627     \brief Free a T.30 context.
00628     \param s The T.30 context. */
00629 void t30_free(t30_state_t *s);
00630 
00631 /*! Cleanup a T.30 context if the call terminates.
00632     \brief Cleanup a T.30 context if the call terminates.
00633     \param s The T.30 context. */
00634 void t30_terminate(t30_state_t *s);
00635 
00636 /*! Return a text name for a T.30 frame type.
00637     \brief Return a text name for a T.30 frame type.
00638     \param x The frametype octet.
00639     \return A pointer to the text name for the frame type. If the frame type is
00640             not value, the string "???" is returned. */
00641 const char *t30_frametype(uint8_t x);
00642 
00643 /*! Decode a DIS, DTC or DCS frame, and log the contents.
00644     \brief Decode a DIS, DTC or DCS frame, and log the contents.
00645     \param s The T.30 context.
00646     \param dis A pointer to the frame to be decoded.
00647     \param len The length of the frame. */
00648 void t30_decode_dis_dtc_dcs(t30_state_t *s, const uint8_t *dis, int len);
00649 
00650 /*! Convert a phase E completion code to a short text description.
00651     \brief Convert a phase E completion code to a short text description.
00652     \param result The result code.
00653     \return A pointer to the description. */
00654 const char *t30_completion_code_to_str(int result);
00655 
00656 /*! Set Internet aware FAX (IAF) mode.
00657     \brief Set Internet aware FAX (IAF) mode.
00658     \param s The T.30 context.
00659     \param iaf TRUE for IAF, or FALSE for non-IAF. */
00660 void t30_set_iaf_mode(t30_state_t *s, int iaf);
00661 
00662 /*! Set the sub-address associated with a T.30 context.
00663     \brief Set the sub-address associated with a T.30 context.
00664     \param s The T.30 context.
00665     \param sub_address A pointer to the sub-address.
00666     \return 0 for OK, else -1. */
00667 int t30_set_local_sub_address(t30_state_t *s, const char *sub_address);
00668 
00669 /*! Set the header information associated with a T.30 context.
00670     \brief Set the header information associated with a T.30 context.
00671     \param s The T.30 context.
00672     \param info A pointer to the information string.
00673     \return 0 for OK, else -1. */
00674 int t30_set_header_info(t30_state_t *s, const char *info);
00675 
00676 /*! Set the local identifier associated with a T.30 context.
00677     \brief Set the local identifier associated with a T.30 context.
00678     \param s The T.30 context.
00679     \param id A pointer to the identifier.
00680     \return 0 for OK, else -1. */
00681 int t30_set_local_ident(t30_state_t *s, const char *id);
00682 
00683 int t30_set_local_nsf(t30_state_t *s, const uint8_t *nsf, int len);
00684 
00685 /*! Get the sub-address associated with a T.30 context.
00686     \brief Get the sub-address associated with a T.30 context.
00687     \param s The T.30 context.
00688     \param sub_address A pointer to a buffer for the sub-address.  The buffer
00689            should be at least 21 bytes long.
00690     \return the length of the string. */
00691 size_t t30_get_sub_address(t30_state_t *s, char *sub_address);
00692 
00693 /*! Get the header information associated with a T.30 context.
00694     \brief Get the header information associated with a T.30 context.
00695     \param s The T.30 context.
00696     \param sub_address A pointer to a buffer for the header information.  The buffer
00697            should be at least 51 bytes long.
00698     \return the length of the string. */
00699 size_t t30_get_header_info(t30_state_t *s, char *info);
00700 
00701 /*! Get the local FAX machine identifier associated with a T.30 context.
00702     \brief Get the local identifier associated with a T.30 context.
00703     \param s The T.30 context.
00704     \param id A pointer to a buffer for the identifier. The buffer should
00705            be at least 21 bytes long.
00706     \return the length of the string. */
00707 size_t t30_get_local_ident(t30_state_t *s, char *id);
00708 
00709 /*! Get the remote FAX machine identifier associated with a T.30 context.
00710     \brief Get the remote identifier associated with a T.30 context.
00711     \param s The T.30 context.
00712     \param id A pointer to a buffer for the identifier. The buffer should
00713            be at least 21 bytes long.
00714     \return the length of the string. */
00715 size_t t30_get_far_ident(t30_state_t *s, char *id);
00716 
00717 /*! Get the country of origin of the remote FAX machine associated with a T.30 context.
00718     \brief Get the country of origin of the remote FAX machine associated with a T.30 context.
00719     \param s The T.30 context.
00720     \return a pointer to the country name, or NULL if the country is not known. */
00721 const char *t30_get_far_country(t30_state_t *s);
00722 
00723 /*! Get the name of the vendor of the remote FAX machine associated with a T.30 context.
00724     \brief Get the name of the vendor of the remote FAX machine associated with a T.30 context.
00725     \param s The T.30 context.
00726     \return a pointer to the vendor name, or NULL if the vendor is not known. */
00727 const char *t30_get_far_vendor(t30_state_t *s);
00728 
00729 /*! Get the name of the model of the remote FAX machine associated with a T.30 context.
00730     \brief Get the name of the model of the remote FAX machine associated with a T.30 context.
00731     \param s The T.30 context.
00732     \return a pointer to the model name, or NULL if the model is not known. */
00733 const char *t30_get_far_model(t30_state_t *s);
00734 
00735 /*! Get the current transfer statistics for the file being sent or received.
00736     \brief Get the current transfer statistics.
00737     \param s The T.30 context.
00738     \param t A pointer to a buffer for the statistics. */
00739 void t30_get_transfer_statistics(t30_state_t *s, t30_stats_t *t);
00740 
00741 /*! Set a callback function for T.30 phase B handling.
00742     \brief Set a callback function for T.30 phase B handling.
00743     \param s The T.30 context.
00744     \param handler The callback function
00745     \param user_data An opaque pointer passed to the callback function. */
00746 void t30_set_phase_b_handler(t30_state_t *s, t30_phase_b_handler_t *handler, void *user_data);
00747 
00748 /*! Set a callback function for T.30 phase D handling.
00749     \brief Set a callback function for T.30 phase D handling.
00750     \param s The T.30 context.
00751     \param handler The callback function
00752     \param user_data An opaque pointer passed to the callback function. */
00753 void t30_set_phase_d_handler(t30_state_t *s, t30_phase_d_handler_t *handler, void *user_data);
00754 
00755 /*! Set a callback function for T.30 phase E handling.
00756     \brief Set a callback function for T.30 phase E handling.
00757     \param s The T.30 context.
00758     \param handler The callback function
00759     \param user_data An opaque pointer passed to the callback function. */
00760 void t30_set_phase_e_handler(t30_state_t *s, t30_phase_e_handler_t *handler, void *user_data);
00761 
00762 /*! Set a callback function for T.30 end of document handling.
00763     \brief Set a callback function for T.30 end of document handling.
00764     \param s The T.30 context.
00765     \param handler The callback function
00766     \param user_data An opaque pointer passed to the callback function. */
00767 void t30_set_document_handler(t30_state_t *s, t30_document_handler_t *handler, void *user_data);
00768 
00769 /*! Specify the file name of the next TIFF file to be received by a T.30
00770     context.
00771     \brief Set next receive file name.
00772     \param s The T.30 context.
00773     \param file The file name
00774     \param stop_page The maximum page to receive. -1 for no restriction. */
00775 void t30_set_rx_file(t30_state_t *s, const char *file, int stop_page);
00776 
00777 /*! Specify the file name of the next TIFF file to be transmitted by a T.30
00778     context.
00779     \brief Set next transmit file name.
00780     \param s The T.30 context.
00781     \param file The file name
00782     \param start_page The first page to send. -1 for no restriction.
00783     \param stop_page The last page to send. -1 for no restriction. */
00784 void t30_set_tx_file(t30_state_t *s, const char *file, int start_page, int stop_page);
00785 
00786 /*! Specify which modem types are supported by a T.30 context.
00787     \brief Specify supported modems.
00788     \param s The T.30 context.
00789     \param supported_modems Bit field list of the supported modems. */
00790 void t30_set_supported_modems(t30_state_t *s, int supported_modems);
00791 
00792 /*! Specify a period of responding with receiver not ready.
00793     \brief Specify a period of responding with receiver not ready.
00794     \param s The T.30 context.
00795     \param count The number of times to report receiver not ready. */
00796 void t30_set_receiver_not_ready(t30_state_t *s, int count);
00797 
00798 /*! Specify which compression types are supported by a T.30 context.
00799     \brief Specify supported compression types.
00800     \param s The T.30 context.
00801     \param supported_compressions Bit field list of the supported compression types. */
00802 void t30_set_supported_compressions(t30_state_t *s, int supported_compressions);
00803 
00804 /*! Specify which resolutions are supported by a T.30 context.
00805     \brief Specify supported resolutions.
00806     \param s The T.30 context.
00807     \param supported_compressions Bit field list of the supported resolutions. */
00808 void t30_set_supported_resolutions(t30_state_t *s, int supported_resolutions);
00809 
00810 /*! Specify which images sizes are supported by a T.30 context.
00811     \brief Specify supported image sizes.
00812     \param s The T.30 context.
00813     \param supported_image_sizes Bit field list of the supported widths and lengths. */
00814 void t30_set_supported_image_sizes(t30_state_t *s, int supported_image_sizes);
00815 
00816 /*! Specify if error correction mode (ECM) is allowed by a T.30 context.
00817     \brief Select ECM capability.
00818     \param s The T.30 context.
00819     \param enabled TRUE for ECM capable, FALSE for not ECM capable. */
00820 void t30_set_ecm_capability(t30_state_t *s, int enabled);
00821 
00822 /*! Request a local interrupt of FAX exchange.
00823     \brief Request a local interrupt of FAX exchange.
00824     \param s The T.30 context.
00825     \param state TRUE to enable interrupt request, else FALSE. */
00826 void t30_local_interrupt_request(t30_state_t *s, int state);
00827 
00828 /*! Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.).
00829     \brief Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.).
00830     \param user_data The T.30 context.
00831     \param status The type of status change which occured. */
00832 void t30_front_end_status(void *user_data, int status);
00833 
00834 /*! Get a bit of received non-ECM image data.
00835     \brief Get a bit of received non-ECM image data.
00836     \param user_data An opaque pointer, which must point to the T.30 context.
00837     \return The next bit to transmit. */
00838 int t30_non_ecm_get_bit(void *user_data);
00839 
00840 /*! Get a byte of received non-ECM image data.
00841     \brief Get a byte of received non-ECM image data.
00842     \param user_data An opaque pointer, which must point to the T.30 context.
00843     \return The next byte to transmit. */
00844 int t30_non_ecm_get_byte(void *user_data);
00845 
00846 /*! Get a chunk of received non-ECM image data.
00847     \brief Get a bit of received non-ECM image data.
00848     \param user_data An opaque pointer, which must point to the T.30 context.
00849     \param buf The buffer to contain the data.
00850     \param max_len The maximum length of the chunk.
00851     \return The actual length of the chunk. */
00852 int t30_non_ecm_get_chunk(void *user_data, uint8_t buf[], int max_len);
00853 
00854 /*! Process a bit of received non-ECM image data.
00855     \brief Process a bit of received non-ECM image data
00856     \param user_data An opaque pointer, which must point to the T.30 context.
00857     \param bit The received bit. */
00858 void t30_non_ecm_put_bit(void *user_data, int bit);
00859 
00860 /*! Process a byte of received non-ECM image data.
00861     \brief Process a byte of received non-ECM image data
00862     \param user_data An opaque pointer, which must point to the T.30 context.
00863     \param byte The received byte. */
00864 void t30_non_ecm_put_byte(void *user_data, int byte);
00865 
00866 /*! Process a chunk of received non-ECM image data.
00867     \brief Process a chunk of received non-ECM image data
00868     \param user_data An opaque pointer, which must point to the T.30 context.
00869     \param buf The buffer containing the received data.
00870     \param len The length of the data in buf. */
00871 void t30_non_ecm_put_chunk(void *user_data, const uint8_t buf[], int len);
00872 
00873 /*! Process a received HDLC frame.
00874     \brief Process a received HDLC frame.
00875     \param s The T.30 context.
00876     \param ok TRUE if the frame was received without error.
00877     \param msg The HDLC message.
00878     \param int The length of the message, in octets. */
00879 void t30_hdlc_accept(void *user_data, int ok, const uint8_t *msg, int len);
00880 
00881 /*! Report the passage of time to the T.30 engine.
00882     \brief Report the passage of time to the T.30 engine.
00883     \param s The T.30 context.
00884     \param samples The time change in 1/8000th second steps. */
00885 void t30_timer_update(t30_state_t *s, int samples);
00886 
00887 #if defined(__cplusplus)
00888 }
00889 #endif
00890 
00891 #endif
00892 /*- End of file ------------------------------------------------------------*/

Generated on Tue Jul 24 11:29:28 2007 for libspandsp by  doxygen 1.5.2