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.68 2007/04/05 19:20:50 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 
00133 typedef struct t30_state_s t30_state_t;
00134 
00135 /*!
00136     T.30 phase B callback handler.
00137     \brief T.30 phase B callback handler.
00138     \param s The T.30 context.
00139     \param user_data An opaque pointer.
00140     \param result The phase B event code.
00141 */
00142 typedef void (t30_phase_b_handler_t)(t30_state_t *s, void *user_data, int result);
00143 
00144 /*!
00145     T.30 phase D callback handler.
00146     \brief T.30 phase D callback handler.
00147     \param s The T.30 context.
00148     \param user_data An opaque pointer.
00149     \param result The phase D event code.
00150 */
00151 typedef void (t30_phase_d_handler_t)(t30_state_t *s, void *user_data, int result);
00152 
00153 /*!
00154     T.30 phase E callback handler.
00155     \brief T.30 phase E callback handler.
00156     \param s The T.30 context.
00157     \param user_data An opaque pointer.
00158     \param completion_code The phase E completion code.
00159 */
00160 typedef void (t30_phase_e_handler_t)(t30_state_t *s, void *user_data, int completion_code);
00161 
00162 /*!
00163     T.30 document handler.
00164     \brief T.30 document handler.
00165     \param s The T.30 context.
00166     \param user_data An opaque pointer.
00167     \param result The document event code.
00168 */
00169 typedef int (t30_document_handler_t)(t30_state_t *s, void *user_data, int status);
00170 
00171 /*!
00172     T.30 set a receive or transmit type handler.
00173     \brief T.30 set a receive or transmit type handler.
00174     \param user_data An opaque pointer.
00175     \param type The modem, tone or silence to be sent or received.
00176     \param short_train TRUE if the short training sequence should be used (where one exists).
00177     \param use_hdlc FALSE for bit stream, TRUE for HDLC framing.
00178 */
00179 typedef void (t30_set_handler_t)(void *user_data, int type, int short_train, int use_hdlc);
00180 
00181 /*!
00182     T.30 send HDLC handler.
00183     \brief T.30 send HDLC handler.
00184     \param user_data An opaque pointer.
00185     \param msg The HDLC message.
00186     \param len The length of the message.
00187 */
00188 typedef void (t30_send_hdlc_handler_t)(void *user_data, const uint8_t *msg, int len);
00189 
00190 /*!
00191     T.30 protocol completion codes, at phase E.
00192 */
00193 enum
00194 {
00195     T30_ERR_OK = 0,         /*! OK */
00196 
00197     /* External problems */
00198     T30_ERR_CEDTONE,        /*! The CED tone exceeded 5s */
00199     T30_ERR_T0EXPIRED,      /*! Timed out waiting for initial communication */
00200     T30_ERR_T1EXPIRED,      /*! Timed out waiting for the first message */
00201     T30_ERR_T3EXPIRED,      /*! Timed out waiting for procedural interrupt */
00202     T30_ERR_HDLCCARR,       /*! The HDLC carrier did not stop in a timely manner */
00203     T30_ERR_CANNOTTRAIN,    /*! Failed to train with any of the compatible modems */
00204     T30_ERR_OPERINTFAIL,    /*! Operator intervention failed */
00205     T30_ERR_INCOMPATIBLE,   /*! Far end is not compatible */
00206     T30_ERR_NOTRXCAPABLE,   /*! Far end is not receive capable */
00207     T30_ERR_NOTTXCAPABLE,   /*! Far end is not transmit capable */
00208     T30_ERR_UNEXPECTED,     /*! Unexpected message received */
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 
00212     /* Internal problems */
00213     T30_ERR_FILEERROR,      /*! TIFF/F file cannot be opened */
00214     T30_ERR_NOPAGE,         /*! TIFF/F page not found */
00215     T30_ERR_BADTIFF,        /*! TIFF/F format is not compatible */
00216     T30_ERR_UNSUPPORTED,    /*! Unsupported feature */
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_ECMRNRTX,       /*! Timer T5 expired, receiver not ready */
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_NXTCMDTX,       /*! Timed out waiting for next send_page command from driver */
00227     T30_ERR_PHBDEADTX,      /*! Received no response to DCS, training or TCF */
00228     T30_ERR_PHDDEADTX,      /*! No response after sending a page */
00229 
00230     /* Phase E status values returned to a receiver */
00231     T30_ERR_ECMPHDRX,       /*! Invalid ECM response received from transmitter */
00232     T30_ERR_GOTDCSRX,       /*! DCS received while waiting for DTC */
00233     T30_ERR_INVALCMDRX,     /*! Unexpected command after page received */
00234     T30_ERR_NOCARRIERRX,    /*! Carrier lost during fax receive */
00235     T30_ERR_NOEOLRX,        /*! Timed out while waiting for EOL (end Of line) */
00236     T30_ERR_NOFAXRX,        /*! Timed out while waiting for first line */
00237     T30_ERR_NXTCMDRX,       /*! Timed out waiting for next receive page command */
00238     T30_ERR_T2EXPDCNRX,     /*! Timer T2 expired while waiting for DCN */
00239     T30_ERR_T2EXPDRX,       /*! Timer T2 expired while waiting for phase D */
00240     T30_ERR_T2EXPFAXRX,     /*! Timer T2 expired while waiting for fax page */
00241     T30_ERR_T2EXPMPSRX,     /*! Timer T2 expired while waiting for next fax page */
00242     T30_ERR_T2EXPRRRX,      /*! Timer T2 expired while waiting for RR command */
00243     T30_ERR_T2EXPRX,        /*! Timer T2 expired while waiting for NSS, DCS or MCF */
00244     T30_ERR_DCNWHYRX,       /*! Unexpected DCN while waiting for DCS or DIS */
00245     T30_ERR_DCNDATARX,      /*! Unexpected DCN while waiting for image data */
00246     T30_ERR_DCNFAXRX,       /*! Unexpected DCN while waiting for EOM, EOP or MPS */
00247     T30_ERR_DCNPHDRX,       /*! Unexpected DCN after EOM or MPS sequence */
00248     T30_ERR_DCNRRDRX,       /*! Unexpected DCN after RR/RNR sequence */
00249     T30_ERR_DCNNORTNRX,     /*! Unexpected DCN after requested retransmission */
00250 
00251     T30_ERR_BADPAGE,        /*! TIFF/F page number tag missing */
00252     T30_ERR_BADTAG,         /*! Incorrect values for TIFF/F tags */
00253     T30_ERR_BADTIFFHDR,     /*! Bad TIFF/F header - incorrect values in fields */
00254     T30_ERR_BADPARM,        /*! Invalid value for fax parameter */
00255     T30_ERR_BADSTATE,       /*! Invalid initial state value specified */
00256     T30_ERR_CMDDATA,        /*! Last command contained invalid data */
00257     T30_ERR_DISCONNECT,     /*! Fax call disconnected by the other station */
00258     T30_ERR_INVALARG,       /*! Illegal argument to function */
00259     T30_ERR_INVALFUNC,      /*! Illegal call to function */
00260     T30_ERR_NODATA,         /*! Data requested is not available (NSF, DIS, DCS) */
00261     T30_ERR_NOMEM,          /*! Cannot allocate memory for more pages */
00262     T30_ERR_NOPOLL,         /*! Poll not accepted */
00263     T30_ERR_NOSTATE,        /*! Initial state value not set */
00264     T30_ERR_RETRYDCN,       /*! Disconnected after permitted retries */
00265     T30_ERR_CALLDROPPED     /*! The call dropped prematurely */
00266 };
00267 
00268 /*!
00269     I/O modes for the T.30 protocol.
00270 */
00271 enum
00272 {
00273     T30_MODEM_NONE = 0,
00274     T30_MODEM_PAUSE,
00275     T30_MODEM_CED,
00276     T30_MODEM_CNG,
00277     T30_MODEM_V21,
00278     T30_MODEM_V27TER_2400,
00279     T30_MODEM_V27TER_4800,
00280     T30_MODEM_V29_7200,
00281     T30_MODEM_V29_9600,
00282     T30_MODEM_V17_7200,
00283     T30_MODEM_V17_9600,
00284     T30_MODEM_V17_12000,
00285     T30_MODEM_V17_14400,
00286     T30_MODEM_DONE
00287 };
00288 
00289 enum
00290 {
00291     T30_SUPPORT_V27TER = 0x01,
00292     T30_SUPPORT_V29 = 0x02,
00293     T30_SUPPORT_V17 = 0x04,
00294     T30_SUPPORT_V34 = 0x08,
00295     T30_SUPPORT_IAF = 0x10,
00296 };
00297 
00298 enum
00299 {
00300     T30_SUPPORT_NO_COMPRESSION = 0x01,
00301     T30_SUPPORT_T4_1D_COMPRESSION = 0x02,
00302     T30_SUPPORT_T4_2D_COMPRESSION = 0x04,
00303     T30_SUPPORT_T6_COMPRESSION = 0x08,
00304     T30_SUPPORT_T85_COMPRESSION = 0x10,     /* Monochrome JBIG */
00305     T30_SUPPORT_T43_COMPRESSION = 0x20,     /* Colour JBIG */
00306     T30_SUPPORT_T45_COMPRESSION = 0x40      /* Run length colour compression */
00307 };
00308 
00309 enum
00310 {
00311     T30_SUPPORT_STANDARD_RESOLUTION = 0x01,
00312     T30_SUPPORT_FINE_RESOLUTION = 0x02,
00313     T30_SUPPORT_SUPERFINE_RESOLUTION = 0x04,
00314 
00315     T30_SUPPORT_R4_RESOLUTION = 0x10000,
00316     T30_SUPPORT_R8_RESOLUTION = 0x20000,
00317     T30_SUPPORT_R16_RESOLUTION = 0x40000,
00318 
00319     T30_SUPPORT_300_300_RESOLUTION = 0x100000,
00320     T30_SUPPORT_400_400_RESOLUTION = 0x200000,
00321     T30_SUPPORT_600_600_RESOLUTION = 0x400000,
00322     T30_SUPPORT_1200_1200_RESOLUTION = 0x800000,
00323     T30_SUPPORT_300_600_RESOLUTION = 0x1000000,
00324     T30_SUPPORT_400_800_RESOLUTION = 0x2000000,
00325     T30_SUPPORT_600_1200_RESOLUTION = 0x4000000
00326 };
00327 
00328 enum
00329 {
00330     T30_SUPPORT_215MM_WIDTH = 0x01,
00331     T30_SUPPORT_255MM_WIDTH = 0x02,
00332     T30_SUPPORT_303MM_WIDTH = 0x04,
00333 
00334     T30_SUPPORT_UNLIMITED_LENGTH = 0x10000,
00335     T30_SUPPORT_A4_LENGTH = 0x20000,
00336     T30_SUPPORT_B4_LENGTH = 0x40000,
00337     T30_SUPPORT_US_LETTER_LENGTH = 0x80000,
00338     T30_SUPPORT_US_LEGAL_LENGTH = 0x100000
00339 };
00340 
00341 enum
00342 {
00343     T30_SUPPORT_SEP = 0x01,
00344     T30_SUPPORT_PSA = 0x02
00345 };
00346 
00347 enum
00348 {
00349     T30_IAF_MODE_T37 = 0x01,
00350     T30_IAF_MODE_T38 = 0x02,
00351     T30_IAF_MODE_FLOW_CONTROL = 0x04,
00352     /*! Continuous flow mode means data is sent as fast as possible, usually across
00353         the Internet, where speed is not constrained by a PSTN modem. */
00354     T30_IAF_MODE_CONTINUOUS_FLOW = 0x08,
00355     /*! No TCF means TCF is not exchanged. The end points must sort out usable speed
00356         issues locally. */
00357     T30_IAF_MODE_NO_TCF = 0x10,
00358     /*! No fill bits means do not insert fill bits, even if the T.30 messages request
00359         them. */
00360     T30_IAF_MODE_NO_FILL_BITS = 0x20,
00361     /*! No indicators means do not send indicator messages when using T.38. */
00362     T30_IAF_MODE_NO_INDICATORS = 0x40
00363 };
00364 
00365 /*!
00366     T.30 FAX channel descriptor. This defines the state of a single working
00367     instance of a T.30 FAX channel.
00368 */
00369 struct t30_state_s
00370 {
00371     /* This must be kept the first thing in the structure, so it can be pointed
00372        to reliably as the structures change over time. */
00373     t4_state_t t4;
00374 
00375     /*! \brief TRUE is behaving as the calling party */
00376     int calling_party;
00377 
00378     /*! \brief The local identifier string. */
00379     char local_ident[T30_MAX_IDENT_LEN];
00380     /*! \brief The identifier string supplied by the remote FAX machine. */
00381     char far_ident[T30_MAX_IDENT_LEN];
00382     /*! \brief The sub-address string to be sent to the remote FAX machine. */
00383     char local_sub_address[T30_MAX_IDENT_LEN];
00384     /*! \brief The sub-address string supplied by the remote FAX machine. */
00385     char far_sub_address[T30_MAX_IDENT_LEN];
00386     /*! \brief The selective polling sub-address supplied by the remote FAX machine. */
00387     char sep_address[T30_MAX_IDENT_LEN];
00388     /*! \brief The polled sub-address supplied by the remote FAX machine. */
00389     char psa_address[T30_MAX_IDENT_LEN];
00390     /*! \brief A password to be associated with the T.30 context. */
00391     char local_password[T30_MAX_IDENT_LEN];
00392     /*! \brief A password expected from the far end. */
00393     char far_password[T30_MAX_IDENT_LEN];
00394     /*! \brief The text which will be used in FAX page header. No text results
00395                in no header line. */
00396     char header_info[50 + 1];
00397     /*! \brief The country of origin of the remote machine, if known, else NULL. */
00398     const char *country;
00399     /*! \brief The vendor of the remote machine, if known, else NULL. */
00400     const char *vendor;
00401     /*! \brief The model of the remote machine, if known, else NULL. */
00402     const char *model;
00403     uint8_t local_nsf[100];
00404     int local_nsf_len;
00405 
00406     /*! \brief A pointer to a callback routine to be called when phase B events
00407         occur. */
00408     t30_phase_b_handler_t *phase_b_handler;
00409     /*! \brief An opaque pointer supplied in event B callbacks. */
00410     void *phase_b_user_data;
00411     /*! \brief A pointer to a callback routine to be called when phase D events
00412         occur. */
00413     t30_phase_d_handler_t *phase_d_handler;
00414     /*! \brief An opaque pointer supplied in event D callbacks. */
00415     void *phase_d_user_data;
00416     /*! \brief A pointer to a callback routine to be called when phase E events
00417         occur. */
00418     t30_phase_e_handler_t *phase_e_handler;
00419     /*! \brief An opaque pointer supplied in event E callbacks. */
00420     void *phase_e_user_data;
00421 
00422     /*! \brief A pointer to a callback routine to be called when document events
00423         (e.g. end of transmitted document) occur. */
00424     t30_document_handler_t *document_handler;
00425     /*! \brief An opaque pointer supplied in document callbacks. */
00426     void *document_user_data;
00427 
00428     t30_set_handler_t *set_rx_type_handler;
00429     void *set_rx_type_user_data;
00430     t30_set_handler_t *set_tx_type_handler;
00431     void *set_tx_type_user_data;
00432 
00433     t30_send_hdlc_handler_t *send_hdlc_handler;
00434     void *send_hdlc_user_data;
00435    
00436     int phase;
00437     int next_phase;
00438     int state;
00439     int step;
00440 
00441     uint8_t dcs_frame[T30_MAX_DIS_DTC_DCS_LEN];
00442     int dcs_len;
00443     uint8_t dis_dtc_frame[T30_MAX_DIS_DTC_DCS_LEN];
00444     int dis_dtc_len;
00445     /*! \brief TRUE if a valid DIS has been received from the far end. */
00446     int dis_received;
00447     /*! \brief TRUE if a valid passwrod has been received from the far end. */
00448     int far_password_ok;
00449 
00450     /*! \brief A flag to indicate a message is in progress. */
00451     int in_message;
00452 
00453     /*! \brief TRUE if the short training sequence should be used. */
00454     int short_train;
00455 
00456     /*! \brief A count of the number of bits in the trainability test. */
00457     int training_test_bits;
00458     int training_current_zeros;
00459     int training_most_zeros;
00460 
00461     /*! \brief The current fallback step for the fast message transfer modem. */
00462     int current_fallback;
00463     /*! \brief The subset of supported modems allowed at the current time, allowing for negotiation. */
00464     int current_permitted_modems;
00465     /*! \brief TRUE if a carrier is present. Otherwise FALSE. */
00466     int rx_signal_present;
00467     /*! \brief TRUE if a modem has trained correctly. */
00468     int rx_trained;
00469     int current_rx_type;
00470     int current_tx_type;
00471 
00472     /*! \brief T0 is the answer timeout when calling another FAX machine.
00473         Placing calls is handled outside the FAX processing, but this timeout keeps
00474         running until V.21 modulation is sent or received.
00475         T1 is the remote terminal identification timeout (in audio samples). */
00476     int timer_t0_t1;
00477     /*! \brief T2 is the HDLC command timeout.
00478                T4 is the HDLC response timeout (in audio samples). */
00479     int timer_t2_t4;
00480     /*! \brief TRUE if the T2/T4 timer is actually timing T4 */
00481     int timer_is_t4;
00482     /*! \brief Procedural interrupt timeout (in audio samples). */
00483     int timer_t3;
00484     /*! \brief This is only used in error correcting mode. */
00485     int timer_t5;
00486     /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
00487     int timer_t6;
00488     /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
00489     int timer_t7;
00490     /*! \brief This is only used in full duplex (e.g. ISDN) modes. */
00491     int timer_t8;
00492 
00493     int far_end_detected;
00494 
00495     int local_interrupt_pending;
00496     int crp_enabled;
00497     int line_encoding;
00498     int min_row_bits;
00499     int x_resolution;
00500     int y_resolution;
00501     int image_width;
00502     int retries;
00503     int error_correcting_mode;
00504     int ppr_count;
00505     int octets_per_ecm_frame;
00506     uint8_t ecm_data[256][260];
00507     int16_t ecm_len[256];
00508     uint8_t ecm_frame_map[3 + 32];
00509     
00510     /*! \brief The current page number in ECM mode */
00511     int ecm_page;
00512 
00513     /*! \brief The current block number in ECM mode */
00514     int ecm_block;
00515     
00516     /*! \brief The number of frames in the current block number in ECM mode */
00517     int ecm_frames;
00518 
00519     /*! \brief The number of frames in the current burst of image transmission in ECM mode */
00520     int ecm_frames_this_burst;
00521     int ecm_current_frame;
00522     int ecm_at_page_end;
00523     int next_tx_step;
00524     int next_rx_step;
00525     char rx_file[256];
00526     int rx_stop_page;
00527     char tx_file[256];
00528     int tx_start_page;
00529     int tx_stop_page;
00530     int current_status;
00531     int iaf;
00532     int supported_modems;
00533     int supported_compressions;
00534     int supported_resolutions;
00535     int supported_image_sizes;
00536     int supported_polling_features;
00537     int ecm_allowed;
00538     /*! \brief Error and flow logging control */
00539     logging_state_t logging;
00540 };
00541 
00542 typedef struct
00543 {
00544     /*! \brief The current bit rate for image transfer. */
00545     int bit_rate;
00546     /*! \brief TRUE if error correcting mode is used. */
00547     int error_correcting_mode;
00548     /*! \brief The number of pages transferred so far. */
00549     int pages_transferred;
00550     /*! \brief The number of horizontal pixels in the most recent page. */
00551     int width;
00552     /*! \brief The number of vertical pixels in the most recent page. */
00553     int length;
00554     /*! \brief The number of bad pixel rows in the most recent page. */
00555     int bad_rows;
00556     /*! \brief The largest number of bad pixel rows in a block in the most recent page. */
00557     int longest_bad_row_run;
00558     /*! \brief The horizontal column-to-column resolution of the page in pixels per metre */
00559     int x_resolution;
00560     /*! \brief The vertical row-to-row resolution of the page in pixels per metre */
00561     int y_resolution;
00562     /*! \brief The type of compression used between the FAX machines */
00563     int encoding;
00564     /*! \brief The size of the image, in bytes */
00565     int image_size;
00566     /*! \brief Current status */
00567     int current_status;
00568 } t30_stats_t;
00569 
00570 #ifdef __cplusplus
00571 extern "C"
00572 {
00573 #endif
00574 
00575 /*! Initialise a T.30 context.
00576     \brief Initialise a T.30 context.
00577     \param s The T.30 context.
00578     \param calling_party TRUE if the context is for a calling party. FALSE if the
00579            context is for an answering party.
00580     \return 0 for OK, else -1. */
00581 int t30_init(t30_state_t *s,
00582              int calling_party,
00583              t30_set_handler_t *set_rx_type_handler,
00584              void *set_rx_type_user_data,
00585              t30_set_handler_t *set_tx_type_handler,
00586              void *set_tx_type_user_data,
00587              t30_send_hdlc_handler_t *send_hdlc_handler,
00588              void *send_hdlc_user_data);
00589 
00590 /*! Release a T.30 context.
00591     \brief Release a T.30 context.
00592     \param s The T.30 context. */
00593 void t30_release(t30_state_t *s);
00594 
00595 /*! Restart a T.30 context.
00596     \brief Restart a T.30 context.
00597     \param s The T.30 context.
00598     \return 0 for OK, else -1. */
00599 int t30_restart(t30_state_t *s);
00600 
00601 /*! Create and initialise a T.30 context.
00602     \brief Create and initialise a T.30 context.
00603     \param calling_party TRUE if the context is for a calling party. FALSE if the
00604            context is for an answering party.
00605     \return A pointer to the FAX context, or NULL if one could not be created.
00606 */
00607 t30_state_t *t30_create(int calling_party,
00608                         t30_set_handler_t *set_rx_type_handler,
00609                         void *set_rx_type_user_data,
00610                         t30_set_handler_t *set_tx_type_handler,
00611                         void *set_tx_type_user_data,
00612                         t30_send_hdlc_handler_t *send_hdlc_handler,
00613                         void *send_hdlc_user_data);
00614 
00615 /*! Free a T.30 context.
00616     \brief Free a T.30 context.
00617     \param s The T.30 context. */
00618 void t30_free(t30_state_t *s);
00619 
00620 /*! Cleanup a T.30 context if the call terminates.
00621     \brief Cleanup a T.30 context if the call terminates.
00622     \param s The T.30 context. */
00623 void t30_terminate(t30_state_t *s);
00624 
00625 /*! Return a text name for a T.30 frame type.
00626     \brief Return a text name for a T.30 frame type.
00627     \param x The frametype octet.
00628     \return A pointer to the text name for the frame type. If the frame type is
00629             not value, the string "???" is returned. */
00630 const char *t30_frametype(uint8_t x);
00631 
00632 /*! Decode a DIS, DTC or DCS frame, and log the contents.
00633     \brief Decode a DIS, DTC or DCS frame, and log the contents.
00634     \param s The T.30 context.
00635     \param dis A pointer to the frame to be decoded.
00636     \param len The length of the frame. */
00637 void t30_decode_dis_dtc_dcs(t30_state_t *s, const uint8_t *dis, int len);
00638 
00639 /*! Convert a phase E completion code to a short text description.
00640     \brief Convert a phase E completion code to a short text description.
00641     \param result The result code.
00642     \return A pointer to the description. */
00643 const char *t30_completion_code_to_str(int result);
00644 
00645 /*! Set Internet aware FAX (IAF) mode.
00646     \brief Set Internet aware FAX (IAF) mode.
00647     \param s The T.30 context.
00648     \param iaf TRUE for IAF, or FALSE for non-IAF. */
00649 void t30_set_iaf_mode(t30_state_t *s, int iaf);
00650 
00651 /*! Set the sub-address associated with a T.30 context.
00652     \brief Set the sub-address associated with a T.30 context.
00653     \param s The T.30 context.
00654     \param sub_address A pointer to the sub-address.
00655     \return 0 for OK, else -1. */
00656 int t30_set_local_sub_address(t30_state_t *s, const char *sub_address);
00657 
00658 /*! Set the header information associated with a T.30 context.
00659     \brief Set the header information associated with a T.30 context.
00660     \param s The T.30 context.
00661     \param info A pointer to the information string.
00662     \return 0 for OK, else -1. */
00663 int t30_set_header_info(t30_state_t *s, const char *info);
00664 
00665 /*! Set the local identifier associated with a T.30 context.
00666     \brief Set the local identifier associated with a T.30 context.
00667     \param s The T.30 context.
00668     \param id A pointer to the identifier.
00669     \return 0 for OK, else -1. */
00670 int t30_set_local_ident(t30_state_t *s, const char *id);
00671 
00672 int t30_set_local_nsf(t30_state_t *s, const uint8_t *nsf, int len);
00673 
00674 /*! Get the sub-address associated with a T.30 context.
00675     \brief Get the sub-address associated with a T.30 context.
00676     \param s The T.30 context.
00677     \param sub_address A pointer to a buffer for the sub-address.  The buffer
00678            should be at least 21 bytes long.
00679     \return the length of the string. */
00680 size_t t30_get_sub_address(t30_state_t *s, char *sub_address);
00681 
00682 /*! Get the header information associated with a T.30 context.
00683     \brief Get the header information associated with a T.30 context.
00684     \param s The T.30 context.
00685     \param sub_address A pointer to a buffer for the header information.  The buffer
00686            should be at least 51 bytes long.
00687     \return the length of the string. */
00688 size_t t30_get_header_info(t30_state_t *s, char *info);
00689 
00690 /*! Get the local FAX machine identifier associated with a T.30 context.
00691     \brief Get the local identifier associated with a T.30 context.
00692     \param s The T.30 context.
00693     \param id A pointer to a buffer for the identifier. The buffer should
00694            be at least 21 bytes long.
00695     \return the length of the string. */
00696 size_t t30_get_local_ident(t30_state_t *s, char *id);
00697 
00698 /*! Get the remote FAX machine identifier associated with a T.30 context.
00699     \brief Get the remote identifier associated with a T.30 context.
00700     \param s The T.30 context.
00701     \param id A pointer to a buffer for the identifier. The buffer should
00702            be at least 21 bytes long.
00703     \return the length of the string. */
00704 size_t t30_get_far_ident(t30_state_t *s, char *id);
00705 
00706 /*! Get the country of origin of the remote FAX machine associated with a T.30 context.
00707     \brief Get the country of origin of the remote FAX machine associated with a T.30 context.
00708     \param s The T.30 context.
00709     \return a pointer to the country name, or NULL if the country is not known. */
00710 const char *t30_get_far_country(t30_state_t *s);
00711 
00712 /*! Get the name of the vendor of the remote FAX machine associated with a T.30 context.
00713     \brief Get the name of the vendor of the remote FAX machine associated with a T.30 context.
00714     \param s The T.30 context.
00715     \return a pointer to the vendor name, or NULL if the vendor is not known. */
00716 const char *t30_get_far_vendor(t30_state_t *s);
00717 
00718 /*! Get the name of the model of the remote FAX machine associated with a T.30 context.
00719     \brief Get the name of the model of the remote FAX machine associated with a T.30 context.
00720     \param s The T.30 context.
00721     \return a pointer to the model name, or NULL if the model is not known. */
00722 const char *t30_get_far_model(t30_state_t *s);
00723 
00724 /*! Get the current transfer statistics for the file being sent or received.
00725     \brief Get the current transfer statistics.
00726     \param s The T.30 context.
00727     \param t A pointer to a buffer for the statistics. */
00728 void t30_get_transfer_statistics(t30_state_t *s, t30_stats_t *t);
00729 
00730 /*! Set a callback function for T.30 phase B handling.
00731     \brief Set a callback function for T.30 phase B handling.
00732     \param s The T.30 context.
00733     \param handler The callback function
00734     \param user_data An opaque pointer passed to the callback function. */
00735 void t30_set_phase_b_handler(t30_state_t *s, t30_phase_b_handler_t *handler, void *user_data);
00736 
00737 /*! Set a callback function for T.30 phase D handling.
00738     \brief Set a callback function for T.30 phase D handling.
00739     \param s The T.30 context.
00740     \param handler The callback function
00741     \param user_data An opaque pointer passed to the callback function. */
00742 void t30_set_phase_d_handler(t30_state_t *s, t30_phase_d_handler_t *handler, void *user_data);
00743 
00744 /*! Set a callback function for T.30 phase E handling.
00745     \brief Set a callback function for T.30 phase E handling.
00746     \param s The T.30 context.
00747     \param handler The callback function
00748     \param user_data An opaque pointer passed to the callback function. */
00749 void t30_set_phase_e_handler(t30_state_t *s, t30_phase_e_handler_t *handler, void *user_data);
00750 
00751 /*! Set a callback function for T.30 end of document handling.
00752     \brief Set a callback function for T.30 end of document handling.
00753     \param s The T.30 context.
00754     \param handler The callback function
00755     \param user_data An opaque pointer passed to the callback function. */
00756 void t30_set_document_handler(t30_state_t *s, t30_document_handler_t *handler, void *user_data);
00757 
00758 /*! Specify the file name of the next TIFF file to be received by a T.30
00759     context.
00760     \brief Set next receive file name.
00761     \param s The T.30 context.
00762     \param file The file name
00763     \param stop_page The maximum page to receive. -1 for no restriction. */
00764 void t30_set_rx_file(t30_state_t *s, const char *file, int stop_page);
00765 
00766 /*! Specify the file name of the next TIFF file to be transmitted by a T.30
00767     context.
00768     \brief Set next transmit file name.
00769     \param s The T.30 context.
00770     \param file The file name
00771     \param start_page The first page to send. -1 for no restriction.
00772     \param stop_page The last page to send. -1 for no restriction. */
00773 void t30_set_tx_file(t30_state_t *s, const char *file, int start_page, int stop_page);
00774 
00775 /*! Specify which modem types are supported by a T.30 context.
00776     \brief Specify supported modems.
00777     \param s The T.30 context.
00778     \param supported_modems Bit field list of the supported modems. */
00779 void t30_set_supported_modems(t30_state_t *s, int supported_modems);
00780 
00781 /*! Specify which compression types are supported by a T.30 context.
00782     \brief Specify supported compression types.
00783     \param s The T.30 context.
00784     \param supported_compressions Bit field list of the supported compression types. */
00785 void t30_set_supported_compressions(t30_state_t *s, int supported_compressions);
00786 
00787 /*! Specify which resolutions are supported by a T.30 context.
00788     \brief Specify supported resolutions.
00789     \param s The T.30 context.
00790     \param supported_compressions Bit field list of the supported resolutions. */
00791 void t30_set_supported_resolutions(t30_state_t *s, int supported_resolutions);
00792 
00793 /*! Specify which images sizes are supported by a T.30 context.
00794     \brief Specify supported image sizes.
00795     \param s The T.30 context.
00796     \param supported_image_sizes Bit field list of the supported widths and lengths. */
00797 void t30_set_supported_image_sizes(t30_state_t *s, int supported_image_sizes);
00798 
00799 /*! Specify if error correction mode (ECM) is allowed by a T.30 context.
00800     \brief Select ECM capability.
00801     \param s The T.30 context.
00802     \param enabled TRUE for ECM capable, FALSE for not ECM capable. */
00803 void t30_set_ecm_capability(t30_state_t *s, int enabled);
00804 
00805 /*! Request a local interrupt of FAX exchange.
00806     \brief Request a local interrupt of FAX exchange.
00807     \param s The T.30 context.
00808     \param state TRUE to enable interrupt request, else FALSE. */
00809 void t30_local_interrupt_request(t30_state_t *s, int state);
00810 
00811 /*! Inform the T.30 engine the current transmission has completed.
00812     \brief Inform the T.30 engine the current transmission has completed.
00813     \param s The T.30 context. */
00814 void t30_send_complete(void *user_data);
00815 
00816 /*! Inform the T.30 engine the current receive has completed. This is
00817     only needed to report an unexpected end of the receive operation, as
00818     might happen with T.38 dying.
00819     \brief Inform the T.30 engine the current receive has completed.
00820     \param s The T.30 context. */
00821 void t30_receive_complete(void *user_data);
00822 
00823 /*! Get a bit of received non-ECM image data.
00824     \brief Get a bit of received non-ECM image data.
00825     \param user_data An opaque pointer, which must point to the T.30 context.
00826     \return The next bit to transmit. */
00827 int t30_non_ecm_get_bit(void *user_data);
00828 
00829 /*! Get a byte of received non-ECM image data.
00830     \brief Get a byte of received non-ECM image data.
00831     \param user_data An opaque pointer, which must point to the T.30 context.
00832     \return The next byte to transmit. */
00833 int t30_non_ecm_get_byte(void *user_data);
00834 
00835 /*! Get a chunk of received non-ECM image data.
00836     \brief Get a bit of received non-ECM image data.
00837     \param user_data An opaque pointer, which must point to the T.30 context.
00838     \param buf The buffer to contain the data.
00839     \param max_len The maximum length of the chunk.
00840     \return The actual length of the chunk. */
00841 int t30_non_ecm_get_chunk(void *user_data, uint8_t buf[], int max_len);
00842 
00843 /*! Process a bit of received non-ECM image data.
00844     \brief Process a bit of received non-ECM image data
00845     \param user_data An opaque pointer, which must point to the T.30 context.
00846     \param bit The received bit. */
00847 void t30_non_ecm_put_bit(void *user_data, int bit);
00848 
00849 /*! Process a byte of received non-ECM image data.
00850     \brief Process a byte of received non-ECM image data
00851     \param user_data An opaque pointer, which must point to the T.30 context.
00852     \param byte The received byte. */
00853 void t30_non_ecm_put_byte(void *user_data, int byte);
00854 
00855 /*! Process a chunk of received non-ECM image data.
00856     \brief Process a chunk of received non-ECM image data
00857     \param user_data An opaque pointer, which must point to the T.30 context.
00858     \param buf The buffer containing the received data.
00859     \param len The length of the data in buf. */
00860 void t30_non_ecm_put_chunk(void *user_data, const uint8_t buf[], int len);
00861 
00862 /*! Process a received HDLC frame.
00863     \brief Process a received HDLC frame.
00864     \param s The T.30 context.
00865     \param ok TRUE if the frame was received without error.
00866     \param msg The HDLC message.
00867     \param int The length of the message, in octets. */
00868 void t30_hdlc_accept(void *user_data, int ok, const uint8_t *msg, int len);
00869 
00870 /*! Report the passage of time to the T.30 engine.
00871     \brief Report the passage of time to the T.30 engine.
00872     \param s The T.30 context.
00873     \param samples The time change in 1/8000th second steps. */
00874 void t30_timer_update(t30_state_t *s, int samples);
00875 
00876 #ifdef __cplusplus
00877 }
00878 #endif
00879 
00880 #endif
00881 /*- End of file ------------------------------------------------------------*/

Generated on Fri Apr 13 13:16:32 2007 for libspandsp by  doxygen 1.5.2