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 Lesser General Public License version 2.1,
00014  * as 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 Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License 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.117 2008/10/13 13:14:00 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     - V.27ter, V.29 and V.17 modes (2400bps, to 14,400bps).
00046     - T.4 1D (MH), T.4 2D,(MR) and T.6 (MMR) compression.
00047     - Error correction mode (ECM).
00048     - All standard horizonal resolutions (R8, R16, 300dpi, 600dpi, 800dpi, 1200dpi).
00049     - All standard vertical resolutions (standard, fine, superfine, 300dpi, 600dpi, 800dpi, 1200dpi).
00050     - All standard page widths (A4, B4, A3).
00051     - All standard page lengths (A4, B4, North American letter, North American legal, continuous).
00052     - Monitoring and sending identifier strings (CSI, TSI, and CIG).
00053     - Monitoring and sending sub-address strings (SUB).
00054     - Monitoring and sending polling sub-addresses (SEP).
00055     - Monitoring and sending polled sub-addresses (PSA).
00056     - Monitoring and sending sender identifications (SID).
00057     - Monitoring and sending passwords (PWD).
00058     - Monitoring of non-standard facility frames (NSF, NSC, and NSS).
00059     - Sending custom non-standard facility frames (NSF, NSC, and NSS).
00060     - Analogue modem and T.38 operation.
00061 
00062 \section t30_page_sec_2 How does it work?
00063 
00064 Some of the following is paraphrased from some notes found a while ago on the Internet.
00065 I cannot remember exactly where they came from, but they are useful.
00066 
00067 \subsection t30_page_sec_2a The answer (CED) tone
00068 
00069 The T.30 standard says an answering fax device must send CED (a 2100Hz tone) for
00070 approximately 3 seconds before sending the first handshake message. Some machines
00071 send an 1100Hz or 1850Hz tone, and some send no tone at all. In fact, this answer
00072 tone is so unpredictable, it cannot really be used. It should, however, always be
00073 generated according to the specification.
00074 
00075 \subsection t30_page_sec_2b Common Timing Deviations
00076 
00077 The T.30 spec. specifies a number of time-outs. For example, after dialing a number,
00078 a calling fax system should listen for a response for 35 seconds before giving up.
00079 These time-out periods are as follows: 
00080 
00081     - T1 - 35+-5s: the maximum time for which two fax system will attempt to identify each other
00082     - T2 - 6+-1s:  a time-out used to start the sequence for changing transmit parameters
00083     - T3 - 10+-5s: a time-out used in handling operator interrupts
00084     - T5 - 60+-5s: a time-out used in error correction mode
00085 
00086 These time-outs are sometimes misinterpreted. In addition, they are routinely
00087 ignored, sometimes with good reason. For example, after placing a call, the
00088 calling fax system is supposed to wait for 35 seconds before giving up. If the
00089 answering unit does not answer on the first ring or if a voice answering machine
00090 is connected to the line, or if there are many delays through the network,
00091 the delay before answer can be much longer than 35 seconds. 
00092 
00093 Fax units that support error correction mode (ECM) can respond to a post-image
00094 handshake message with a receiver not ready (RNR) message. The calling unit then
00095 queries the receiving fax unit with a receiver ready (RR) message. If the
00096 answering unit is still busy (printing for example), it will repeat the RNR
00097 message. According to the T.30 standard, this sequence (RR/RNR RR/RNR) can be
00098 repeated for up to the end of T5 (60+-5s). However, many fax systems
00099 ignore the time-out and will continue the sequence indefinitely, unless the user
00100 manually overrides. 
00101 
00102 All the time-outs are subject to alteration, and sometimes misuse. Good T.30
00103 implementations must do the right thing, and tolerate others doing the wrong thing.
00104 
00105 \subsection t30_page_sec_2c Variations in the inter-carrier gap
00106 
00107 T.30 specifies 75+-20ms of silence between signals using different modulation
00108 schemes. Examples are between the end of a DCS signal and the start of a TCF signal,
00109 and between the end of an image and the start of a post-image signal. Many fax systems
00110 violate this requirement, especially for the silent period between DCS and TCF.
00111 This may be stretched to well over 100ms. If this period is too long, it can interfere with
00112 handshake signal error recovery, should a packet be corrupted on the line. Systems
00113 should ensure they stay within the prescribed T.30 limits, and be tolerant of others
00114 being out of spec.. 
00115 
00116 \subsection t30_page_sec_2d Other timing variations
00117 
00118 Testing is required to determine the ability of a fax system to handle
00119 variations in the duration of pauses between unacknowledged handshake message
00120 repetitions, and also in the pauses between the receipt of a handshake command and
00121 the start of a response to that command. In order to reduce the total
00122 transmission time, many fax systems start sending a response message before the
00123 end of the command has been received. 
00124 
00125 \subsection t30_page_sec_2e Other deviations from the T.30 standard
00126 
00127 There are many other commonly encountered variations between machines, including:
00128 
00129     - frame sequence deviations
00130     - preamble and flag sequence variations
00131     - improper EOM usage
00132     - unusual data rate fallback sequences
00133     - common training pattern detection algorithms
00134     - image transmission deviations
00135     - use of the talker echo protect tone
00136     - image padding and short lines
00137     - RTP/RTN handshake message usage
00138     - long duration lines
00139     - nonstandard disconnect sequences
00140     - DCN usage
00141 */
00142 
00143 #define T30_MAX_DIS_DTC_DCS_LEN     22
00144 #define T30_MAX_IDENT_LEN           20
00145 #define T30_MAX_PAGE_HEADER_INFO    50
00146 
00147 typedef struct t30_state_s t30_state_t;
00148 
00149 /*!
00150     T.30 phase B callback handler. This handler can be used to process addition
00151     information available in some FAX calls, such as passwords. The callback handler
00152     can access whatever additional information might have been received, using
00153     t30_get_received_info().
00154     \brief T.30 phase B callback handler.
00155     \param s The T.30 context.
00156     \param user_data An opaque pointer.
00157     \param result The phase B event code.
00158     \return The new status. Normally, T30_ERR_OK is returned.
00159 */
00160 typedef int (t30_phase_b_handler_t)(t30_state_t *s, void *user_data, int result);
00161 
00162 /*!
00163     T.30 phase D callback handler.
00164     \brief T.30 phase D callback handler.
00165     \param s The T.30 context.
00166     \param user_data An opaque pointer.
00167     \param result The phase D event code.
00168     \return The new status. Normally, T30_ERR_OK is returned.
00169 */
00170 typedef int (t30_phase_d_handler_t)(t30_state_t *s, void *user_data, int result);
00171 
00172 /*!
00173     T.30 phase E callback handler.
00174     \brief T.30 phase E callback handler.
00175     \param s The T.30 context.
00176     \param user_data An opaque pointer.
00177     \param completion_code The phase E completion code.
00178 */
00179 typedef void (t30_phase_e_handler_t)(t30_state_t *s, void *user_data, int completion_code);
00180 
00181 /*!
00182     T.30 real time frame handler.
00183     \brief T.30 real time frame handler.
00184     \param s The T.30 context.
00185     \param user_data An opaque pointer.
00186     \param direction TRUE for incoming, FALSE for outgoing.
00187     \param msg The HDLC message.
00188     \param len The length of the message.
00189 */
00190 typedef void (t30_real_time_frame_handler_t)(t30_state_t *s,
00191                                              void *user_data,
00192                                              int direction,
00193                                              const uint8_t *msg,
00194                                              int len);
00195 
00196 /*!
00197     T.30 document handler.
00198     \brief T.30 document handler.
00199     \param s The T.30 context.
00200     \param user_data An opaque pointer.
00201     \param result The document event code.
00202 */
00203 typedef int (t30_document_handler_t)(t30_state_t *s, void *user_data, int status);
00204 
00205 /*!
00206     T.30 set a receive or transmit type handler.
00207     \brief T.30 set a receive or transmit type handler.
00208     \param user_data An opaque pointer.
00209     \param type The modem, tone or silence to be sent or received.
00210     \param bit_rate The bit rate of the modem to be sent or received.
00211     \param short_train TRUE if the short training sequence should be used (where one exists).
00212     \param use_hdlc FALSE for bit stream, TRUE for HDLC framing.
00213 */
00214 typedef void (t30_set_handler_t)(void *user_data, int type, int bit_rate, int short_train, int use_hdlc);
00215 
00216 /*!
00217     T.30 send HDLC handler.
00218     \brief T.30 send HDLC handler.
00219     \param user_data An opaque pointer.
00220     \param msg The HDLC message.
00221     \param len The length of the message.
00222 */
00223 typedef void (t30_send_hdlc_handler_t)(void *user_data, const uint8_t *msg, int len);
00224 
00225 /*!
00226     T.30 protocol completion codes, at phase E.
00227 */
00228 enum
00229 {
00230     T30_ERR_OK = 0,             /*! OK */
00231 
00232     /* Link problems */
00233     T30_ERR_CEDTONE,            /*! The CED tone exceeded 5s */
00234     T30_ERR_T0_EXPIRED,         /*! Timed out waiting for initial communication */
00235     T30_ERR_T1_EXPIRED,         /*! Timed out waiting for the first message */
00236     T30_ERR_T3_EXPIRED,         /*! Timed out waiting for procedural interrupt */
00237     T30_ERR_HDLC_CARRIER,       /*! The HDLC carrier did not stop in a timely manner */
00238     T30_ERR_CANNOT_TRAIN,       /*! Failed to train with any of the compatible modems */
00239     T30_ERR_OPER_INT_FAIL,      /*! Operator intervention failed */
00240     T30_ERR_INCOMPATIBLE,       /*! Far end is not compatible */
00241     T30_ERR_RX_INCAPABLE,       /*! Far end is not able to receive */
00242     T30_ERR_TX_INCAPABLE,       /*! Far end is not able to transmit */
00243     T30_ERR_NORESSUPPORT,       /*! Far end cannot receive at the resolution of the image */
00244     T30_ERR_NOSIZESUPPORT,      /*! Far end cannot receive at the size of image */
00245     T30_ERR_UNEXPECTED,         /*! Unexpected message received */
00246 
00247     /* Phase E status values returned to a transmitter */
00248     T30_ERR_TX_BADDCS,          /*! Received bad response to DCS or training */
00249     T30_ERR_TX_BADPG,           /*! Received a DCN from remote after sending a page */
00250     T30_ERR_TX_ECMPHD,          /*! Invalid ECM response received from receiver */
00251     T30_ERR_TX_GOTDCN,          /*! Received a DCN while waiting for a DIS */
00252     T30_ERR_TX_INVALRSP,        /*! Invalid response after sending a page */
00253     T30_ERR_TX_NODIS,           /*! Received other than DIS while waiting for DIS */
00254     T30_ERR_TX_PHBDEAD,         /*! Received no response to DCS, training or TCF */
00255     T30_ERR_TX_PHDDEAD,         /*! No response after sending a page */
00256     T30_ERR_TX_T5EXP,           /*! Timed out waiting for receiver ready (ECM mode) */
00257 
00258     /* Phase E status values returned to a receiver */
00259     T30_ERR_RX_ECMPHD,          /*! Invalid ECM response received from transmitter */
00260     T30_ERR_RX_GOTDCS,          /*! DCS received while waiting for DTC */
00261     T30_ERR_RX_INVALCMD,        /*! Unexpected command after page received */
00262     T30_ERR_RX_NOCARRIER,       /*! Carrier lost during fax receive */
00263     T30_ERR_RX_NOEOL,           /*! Timed out while waiting for EOL (end Of line) */
00264     T30_ERR_RX_NOFAX,           /*! Timed out while waiting for first line */
00265     T30_ERR_RX_T2EXPDCN,        /*! Timer T2 expired while waiting for DCN */
00266     T30_ERR_RX_T2EXPD,          /*! Timer T2 expired while waiting for phase D */
00267     T30_ERR_RX_T2EXPFAX,        /*! Timer T2 expired while waiting for fax page */
00268     T30_ERR_RX_T2EXPMPS,        /*! Timer T2 expired while waiting for next fax page */
00269     T30_ERR_RX_T2EXPRR,         /*! Timer T2 expired while waiting for RR command */
00270     T30_ERR_RX_T2EXP,           /*! Timer T2 expired while waiting for NSS, DCS or MCF */
00271     T30_ERR_RX_DCNWHY,          /*! Unexpected DCN while waiting for DCS or DIS */
00272     T30_ERR_RX_DCNDATA,         /*! Unexpected DCN while waiting for image data */
00273     T30_ERR_RX_DCNFAX,          /*! Unexpected DCN while waiting for EOM, EOP or MPS */
00274     T30_ERR_RX_DCNPHD,          /*! Unexpected DCN after EOM or MPS sequence */
00275     T30_ERR_RX_DCNRRD,          /*! Unexpected DCN after RR/RNR sequence */
00276     T30_ERR_RX_DCNNORTN,        /*! Unexpected DCN after requested retransmission */
00277 
00278     /* TIFF file problems */
00279     T30_ERR_FILEERROR,          /*! TIFF/F file cannot be opened */
00280     T30_ERR_NOPAGE,             /*! TIFF/F page not found */
00281     T30_ERR_BADTIFF,            /*! TIFF/F format is not compatible */
00282     T30_ERR_BADPAGE,            /*! TIFF/F page number tag missing */
00283     T30_ERR_BADTAG,             /*! Incorrect values for TIFF/F tags */
00284     T30_ERR_BADTIFFHDR,         /*! Bad TIFF/F header - incorrect values in fields */
00285     T30_ERR_NOMEM,              /*! Cannot allocate memory for more pages */
00286     
00287     /* General problems */
00288     T30_ERR_RETRYDCN,           /*! Disconnected after permitted retries */
00289     T30_ERR_CALLDROPPED,        /*! The call dropped prematurely */
00290     
00291     /* Feature negotiation issues */
00292     T30_ERR_NOPOLL,             /*! Poll not accepted */
00293     T30_ERR_IDENT_UNACCEPTABLE, /*! Far end's ident is not acceptable */
00294     T30_ERR_SUB_UNACCEPTABLE,   /*! Far end's sub-address is not acceptable */
00295     T30_ERR_SEP_UNACCEPTABLE,   /*! Far end's selective polling address is not acceptable */
00296     T30_ERR_PSA_UNACCEPTABLE,   /*! Far end's polled sub-address is not acceptable */
00297     T30_ERR_SID_UNACCEPTABLE,   /*! Far end's sender identification is not acceptable */
00298     T30_ERR_PWD_UNACCEPTABLE,   /*! Far end's password is not acceptable */
00299     T30_ERR_TSA_UNACCEPTABLE,   /*! Far end's transmitting subscriber internet address is not acceptable */
00300     T30_ERR_IRA_UNACCEPTABLE,   /*! Far end's internet routing address is not acceptable */
00301     T30_ERR_CIA_UNACCEPTABLE,   /*! Far end's calling subscriber internet address is not acceptable */
00302     T30_ERR_ISP_UNACCEPTABLE,   /*! Far end's internet selective polling address is not acceptable */
00303     T30_ERR_CSA_UNACCEPTABLE    /*! Far end's called subscriber internet address is not acceptable */
00304 };
00305 
00306 /*!
00307     I/O modes for the T.30 protocol.
00308     These are allocated such that the lower 4 bits represents the variant of the modem - e.g. the
00309     particular bit rate selected.
00310 */
00311 enum
00312 {
00313     T30_MODEM_NONE = 0,
00314     T30_MODEM_PAUSE,
00315     T30_MODEM_CED,
00316     T30_MODEM_CNG,
00317     T30_MODEM_V21,
00318     T30_MODEM_V27TER,
00319     T30_MODEM_V29,
00320     T30_MODEM_V17,
00321     T30_MODEM_DONE
00322 };
00323 
00324 enum
00325 {
00326     T30_FRONT_END_SEND_STEP_COMPLETE = 0,
00327     /*! The current receive has completed. This is only needed to report an
00328         unexpected end of the receive operation, as might happen with T.38
00329         dying. */
00330     T30_FRONT_END_RECEIVE_COMPLETE,
00331     T30_FRONT_END_SIGNAL_PRESENT,
00332     T30_FRONT_END_SIGNAL_ABSENT
00333 };
00334 
00335 enum
00336 {
00337     T30_SUPPORT_V27TER = 0x01,
00338     T30_SUPPORT_V29 = 0x02,
00339     T30_SUPPORT_V17 = 0x04,
00340     T30_SUPPORT_V34 = 0x08,
00341     T30_SUPPORT_IAF = 0x10
00342 };
00343 
00344 enum
00345 {
00346     T30_SUPPORT_NO_COMPRESSION = 0x01,
00347     T30_SUPPORT_T4_1D_COMPRESSION = 0x02,
00348     T30_SUPPORT_T4_2D_COMPRESSION = 0x04,
00349     T30_SUPPORT_T6_COMPRESSION = 0x08,
00350     T30_SUPPORT_T85_COMPRESSION = 0x10,     /* Monochrome JBIG */
00351     T30_SUPPORT_T43_COMPRESSION = 0x20,     /* Colour JBIG */
00352     T30_SUPPORT_T45_COMPRESSION = 0x40      /* Run length colour compression */
00353 };
00354 
00355 enum
00356 {
00357     T30_SUPPORT_STANDARD_RESOLUTION = 0x01,
00358     T30_SUPPORT_FINE_RESOLUTION = 0x02,
00359     T30_SUPPORT_SUPERFINE_RESOLUTION = 0x04,
00360 
00361     T30_SUPPORT_R4_RESOLUTION = 0x10000,
00362     T30_SUPPORT_R8_RESOLUTION = 0x20000,
00363     T30_SUPPORT_R16_RESOLUTION = 0x40000,
00364 
00365     T30_SUPPORT_300_300_RESOLUTION = 0x100000,
00366     T30_SUPPORT_400_400_RESOLUTION = 0x200000,
00367     T30_SUPPORT_600_600_RESOLUTION = 0x400000,
00368     T30_SUPPORT_1200_1200_RESOLUTION = 0x800000,
00369     T30_SUPPORT_300_600_RESOLUTION = 0x1000000,
00370     T30_SUPPORT_400_800_RESOLUTION = 0x2000000,
00371     T30_SUPPORT_600_1200_RESOLUTION = 0x4000000
00372 };
00373 
00374 enum
00375 {
00376     T30_SUPPORT_215MM_WIDTH = 0x01,
00377     T30_SUPPORT_255MM_WIDTH = 0x02,
00378     T30_SUPPORT_303MM_WIDTH = 0x04,
00379 
00380     T30_SUPPORT_UNLIMITED_LENGTH = 0x10000,
00381     T30_SUPPORT_A4_LENGTH = 0x20000,
00382     T30_SUPPORT_B4_LENGTH = 0x40000,
00383     T30_SUPPORT_US_LETTER_LENGTH = 0x80000,
00384     T30_SUPPORT_US_LEGAL_LENGTH = 0x100000
00385 };
00386 
00387 enum
00388 {
00389     /*! Enable support of identification, through the SID and/or PWD frames */
00390     T30_SUPPORT_IDENTIFICATION = 0x01,
00391     /*! Enable support of selective polling, through the SEP frame */
00392     T30_SUPPORT_SELECTIVE_POLLING = 0x02,
00393     /*! Enable support of polling sub-addressing, through the PSA frame */
00394     T30_SUPPORT_POLLED_SUB_ADDRESSING = 0x04,
00395     /*! Enable support of multiple selective polling, through repeated used of the SEP and PSA frames */
00396     T30_SUPPORT_MULTIPLE_SELECTIVE_POLLING = 0x08,
00397     /*! Enable support of sub-addressing, through the SUB frame */
00398     T30_SUPPORT_SUB_ADDRESSING = 0x10,
00399     /*! Enable support of transmitting subscriber internet address, through the TSA frame */
00400     T30_SUPPORT_TRANSMITTING_SUBSCRIBER_INTERNET_ADDRESS = 0x20,
00401     /*! Enable support of internet routing address, through the IRA frame */
00402     T30_SUPPORT_INTERNET_ROUTING_ADDRESS = 0x40,
00403     /*! Enable support of calling subscriber internet address, through the CIA frame */
00404     T30_SUPPORT_CALLING_SUBSCRIBER_INTERNET_ADDRESS = 0x80,
00405     /*! Enable support of internet selective polling address, through the ISP frame */
00406     T30_SUPPORT_INTERNET_SELECTIVE_POLLING_ADDRESS = 0x100,
00407     /*! Enable support of called subscriber internet address, through the CSA frame */
00408     T30_SUPPORT_CALLED_SUBSCRIBER_INTERNET_ADDRESS = 0x200,
00409     /*! Enable support of the field not valid (FNV) frame */
00410     T30_SUPPORT_FIELD_NOT_VALID = 0x400,
00411     /*! Enable support of the command repeat (CRP) frame */
00412     T30_SUPPORT_COMMAND_REPEAT = 0x800
00413 };
00414 
00415 enum
00416 {
00417     T30_IAF_MODE_T37 = 0x01,
00418     T30_IAF_MODE_T38 = 0x02,
00419     T30_IAF_MODE_FLOW_CONTROL = 0x04,
00420     /*! Continuous flow mode means data is sent as fast as possible, usually across
00421         the Internet, where speed is not constrained by a PSTN modem. */
00422     T30_IAF_MODE_CONTINUOUS_FLOW = 0x08,
00423     /*! No TCF means TCF is not exchanged. The end points must sort out usable speed
00424         issues locally. */
00425     T30_IAF_MODE_NO_TCF = 0x10,
00426     /*! No fill bits means do not insert fill bits, even if the T.30 messages request
00427         them. */
00428     T30_IAF_MODE_NO_FILL_BITS = 0x20,
00429     /*! No indicators means do not send indicator messages when using T.38. */
00430     T30_IAF_MODE_NO_INDICATORS = 0x40
00431 };
00432 
00433 typedef struct
00434 {
00435     /*! \brief The identifier string (CSI, TSI, CIG). */
00436     char ident[T30_MAX_IDENT_LEN + 1];
00437     /*! \brief The sub-address string (SUB). */
00438     char sub_address[T30_MAX_IDENT_LEN + 1];
00439     /*! \brief The selective polling sub-address (SEP). */
00440     char selective_polling_address[T30_MAX_IDENT_LEN + 1];
00441     /*! \brief The polled sub-address (PSA). */
00442     char polled_sub_address[T30_MAX_IDENT_LEN + 1];
00443     /*! \brief The sender identification (SID). */
00444     char sender_ident[T30_MAX_IDENT_LEN + 1];
00445     /*! \brief The password (PWD). */
00446     char password[T30_MAX_IDENT_LEN + 1];
00447     /*! \brief Non-standard facilities (NSF). */
00448     uint8_t *nsf;
00449     size_t nsf_len;
00450     /*! \brief Non-standard facilities command (NSC). */
00451     uint8_t *nsc;
00452     size_t nsc_len;
00453     /*! \brief Non-standard facilities set-up (NSS). */
00454     uint8_t *nss;
00455     size_t nss_len;
00456     /*! \brief Transmitting subscriber internet address (TSA). */
00457     int tsa_type;
00458     char *tsa;
00459     size_t tsa_len;
00460     /*! \brief Internet routing address (IRA). */
00461     int ira_type;
00462     char *ira;
00463     size_t ira_len;
00464     /*! \brief Calling subscriber internet address (CIA). */
00465     int cia_type;
00466     char *cia;
00467     size_t cia_len;
00468     /*! \brief Internet selective polling address (ISP). */
00469     int isp_type;
00470     char *isp;
00471     size_t isp_len;
00472     /*! \brief Called subscriber internet address (CSA). */
00473     int csa_type;
00474     char *csa;
00475     size_t csa_len;
00476 } t30_exchanged_info_t;
00477 
00478 typedef struct
00479 {
00480     /*! \brief The current bit rate for image transfer. */
00481     int bit_rate;
00482     /*! \brief TRUE if error correcting mode is used. */
00483     int error_correcting_mode;
00484     /*! \brief The number of pages transferred so far. */
00485     int pages_transferred;
00486     /*! \brief The number of pages in the file (<0 if not known). */
00487     int pages_in_file;
00488     /*! \brief The number of horizontal pixels in the most recent page. */
00489     int width;
00490     /*! \brief The number of vertical pixels in the most recent page. */
00491     int length;
00492     /*! \brief The number of bad pixel rows in the most recent page. */
00493     int bad_rows;
00494     /*! \brief The largest number of bad pixel rows in a block in the most recent page. */
00495     int longest_bad_row_run;
00496     /*! \brief The horizontal column-to-column resolution of the page in pixels per metre */
00497     int x_resolution;
00498     /*! \brief The vertical row-to-row resolution of the page in pixels per metre */
00499     int y_resolution;
00500     /*! \brief The type of compression used between the FAX machines */
00501     int encoding;
00502     /*! \brief The size of the image, in bytes */
00503     int image_size;
00504     /*! \brief Current status */
00505     int current_status;
00506 } t30_stats_t;
00507 
00508 #if defined(__cplusplus)
00509 extern "C"
00510 {
00511 #endif
00512 
00513 /*! Initialise a T.30 context.
00514     \brief Initialise a T.30 context.
00515     \param s The T.30 context.
00516     \param calling_party TRUE if the context is for a calling party. FALSE if the
00517            context is for an answering party.
00518     \param set_rx_type_handler
00519     \param set_rx_type_user_data
00520     \param set_tx_type_handler
00521     \param set_tx_type_user_data
00522     \param send_hdlc_handler
00523     \param send_hdlc_user_data
00524     \return A pointer to the context, or NULL if there was a problem. */
00525 t30_state_t *t30_init(t30_state_t *s,
00526                       int calling_party,
00527                       t30_set_handler_t *set_rx_type_handler,
00528                       void *set_rx_type_user_data,
00529                       t30_set_handler_t *set_tx_type_handler,
00530                       void *set_tx_type_user_data,
00531                       t30_send_hdlc_handler_t *send_hdlc_handler,
00532                       void *send_hdlc_user_data);
00533 
00534 /*! Release a T.30 context.
00535     \brief Release a T.30 context.
00536     \param s The T.30 context.
00537     \return 0 for OK, else -1. */
00538 int t30_release(t30_state_t *s);
00539 
00540 /*! Free a T.30 context.
00541     \brief Free a T.30 context.
00542     \param s The T.30 context.
00543     \return 0 for OK, else -1. */
00544 int t30_free(t30_state_t *s);
00545 
00546 /*! Restart a T.30 context.
00547     \brief Restart a T.30 context.
00548     \param s The T.30 context.
00549     \return 0 for OK, else -1. */
00550 int t30_restart(t30_state_t *s);
00551 
00552 /*! Check if a T.30 call is still active. This may be used to regularly poll
00553     if the job has finished.
00554     \brief Check if a T.30 call is still active.
00555     \param s The T.30 context.
00556     \return TRUE for call still active, or FALSE for call completed. */
00557 int t30_call_active(t30_state_t *s);
00558 
00559 /*! Cleanup a T.30 context if the call terminates.
00560     \brief Cleanup a T.30 context if the call terminates.
00561     \param s The T.30 context. */
00562 void t30_terminate(t30_state_t *s);
00563 
00564 /*! Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.).
00565     \brief Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.).
00566     \param user_data The T.30 context.
00567     \param status The type of status change which occured. */
00568 void t30_front_end_status(void *user_data, int status);
00569 
00570 /*! Get a bit of received non-ECM image data.
00571     \brief Get a bit of received non-ECM image data.
00572     \param user_data An opaque pointer, which must point to the T.30 context.
00573     \return The next bit to transmit. */
00574 int t30_non_ecm_get_bit(void *user_data);
00575 
00576 /*! Get a byte of received non-ECM image data.
00577     \brief Get a byte of received non-ECM image data.
00578     \param user_data An opaque pointer, which must point to the T.30 context.
00579     \return The next byte to transmit. */
00580 int t30_non_ecm_get_byte(void *user_data);
00581 
00582 /*! Get a chunk of received non-ECM image data.
00583     \brief Get a bit of received non-ECM image data.
00584     \param user_data An opaque pointer, which must point to the T.30 context.
00585     \param buf The buffer to contain the data.
00586     \param max_len The maximum length of the chunk.
00587     \return The actual length of the chunk. */
00588 int t30_non_ecm_get_chunk(void *user_data, uint8_t buf[], int max_len);
00589 
00590 /*! Process a bit of received non-ECM image data.
00591     \brief Process a bit of received non-ECM image data
00592     \param user_data An opaque pointer, which must point to the T.30 context.
00593     \param bit The received bit. */
00594 void t30_non_ecm_put_bit(void *user_data, int bit);
00595 
00596 /*! Process a byte of received non-ECM image data.
00597     \brief Process a byte of received non-ECM image data
00598     \param user_data An opaque pointer, which must point to the T.30 context.
00599     \param byte The received byte. */
00600 void t30_non_ecm_put_byte(void *user_data, int byte);
00601 
00602 /*! Process a chunk of received non-ECM image data.
00603     \brief Process a chunk of received non-ECM image data
00604     \param user_data An opaque pointer, which must point to the T.30 context.
00605     \param buf The buffer containing the received data.
00606     \param len The length of the data in buf. */
00607 void t30_non_ecm_put_chunk(void *user_data, const uint8_t buf[], int len);
00608 
00609 /*! Process a received HDLC frame.
00610     \brief Process a received HDLC frame.
00611     \param user_data The T.30 context.
00612     \param msg The HDLC message.
00613     \param len The length of the message, in octets.
00614     \param ok TRUE if the frame was received without error. */
00615 void t30_hdlc_accept(void *user_data, const uint8_t *msg, int len, int ok);
00616 
00617 /*! Report the passage of time to the T.30 engine.
00618     \brief Report the passage of time to the T.30 engine.
00619     \param s The T.30 context.
00620     \param samples The time change in 1/8000th second steps. */
00621 void t30_timer_update(t30_state_t *s, int samples);
00622 
00623 /*! Get the current transfer statistics for the file being sent or received.
00624     \brief Get the current transfer statistics.
00625     \param s The T.30 context.
00626     \param t A pointer to a buffer for the statistics. */
00627 void t30_get_transfer_statistics(t30_state_t *s, t30_stats_t *t);
00628 
00629 /*! Request a local interrupt of FAX exchange.
00630     \brief Request a local interrupt of FAX exchange.
00631     \param s The T.30 context.
00632     \param state TRUE to enable interrupt request, else FALSE. */
00633 void t30_local_interrupt_request(t30_state_t *s, int state);
00634 
00635 #if defined(__cplusplus)
00636 }
00637 #endif
00638 
00639 #endif
00640 /*- End of file ------------------------------------------------------------*/

Generated on Thu Feb 12 14:16:07 2009 for spandsp by  doxygen 1.5.5