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.124 2009/02/20 12:34:20 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 T30_FRONT_END_CED_PRESENT, 00334 T30_FRONT_END_CNG_PRESENT 00335 }; 00336 00337 enum 00338 { 00339 /*! Support the V.27ter modem (2400, and 4800bps) for image transfer. */ 00340 T30_SUPPORT_V27TER = 0x01, 00341 /*! Support the V.29 modem (9600, and 7200bps) for image transfer. */ 00342 T30_SUPPORT_V29 = 0x02, 00343 /*! Support the V.17 modem (14400, 12000, 9600 and 7200bps) for image transfer. */ 00344 T30_SUPPORT_V17 = 0x04, 00345 /*! Support the V.34 modem (up to 33,600bps) for image transfer. */ 00346 T30_SUPPORT_V34 = 0x08, 00347 /*! Support the Internet Aware FAX mode (no bit rate limit) for image transfer. */ 00348 T30_SUPPORT_IAF = 0x10 00349 }; 00350 00351 enum 00352 { 00353 /*! No compression */ 00354 T30_SUPPORT_NO_COMPRESSION = 0x01, 00355 /*! T.1 1D compression */ 00356 T30_SUPPORT_T4_1D_COMPRESSION = 0x02, 00357 /*! T.4 2D compression */ 00358 T30_SUPPORT_T4_2D_COMPRESSION = 0x04, 00359 /*! T.6 2D compression */ 00360 T30_SUPPORT_T6_COMPRESSION = 0x08, 00361 /*! T.85 monochrome JBIG coding */ 00362 T30_SUPPORT_T85_COMPRESSION = 0x10, 00363 /*! T.43 colour JBIG coding */ 00364 T30_SUPPORT_T43_COMPRESSION = 0x20, 00365 /*! T.45 run length colour compression */ 00366 T30_SUPPORT_T45_COMPRESSION = 0x40, 00367 /*! T.81 + T.30 Annex E colour JPEG coding */ 00368 T30_SUPPORT_T81_COMPRESSION = 0x80, 00369 /*! T.81 + T.30 Annex K colour sYCC-JPEG coding */ 00370 T30_SUPPORT_SYCC_T81_COMPRESSION = 0x100 00371 }; 00372 00373 enum 00374 { 00375 /*! Support standard FAX Y-resolution 98/100dpi */ 00376 T30_SUPPORT_STANDARD_RESOLUTION = 0x01, 00377 /*! Support fine FAX Y-resolution 196/200dpi */ 00378 T30_SUPPORT_FINE_RESOLUTION = 0x02, 00379 /*! Support super-fine FAX Y-resolution 392/400dpi */ 00380 T30_SUPPORT_SUPERFINE_RESOLUTION = 0x04, 00381 00382 /*! Support half FAX X-resolution 100/102dpi */ 00383 T30_SUPPORT_R4_RESOLUTION = 0x10000, 00384 /*! Support standard FAX X-resolution 200/204dpi */ 00385 T30_SUPPORT_R8_RESOLUTION = 0x20000, 00386 /*! Support double FAX X-resolution 400dpi */ 00387 T30_SUPPORT_R16_RESOLUTION = 0x40000, 00388 00389 /*! Support 300dpi x 300 dpi */ 00390 T30_SUPPORT_300_300_RESOLUTION = 0x100000, 00391 /*! Support 400dpi x 400 dpi */ 00392 T30_SUPPORT_400_400_RESOLUTION = 0x200000, 00393 /*! Support 600dpi x 600 dpi */ 00394 T30_SUPPORT_600_600_RESOLUTION = 0x400000, 00395 /*! Support 1200dpi x 1200 dpi */ 00396 T30_SUPPORT_1200_1200_RESOLUTION = 0x800000, 00397 /*! Support 300dpi x 600 dpi */ 00398 T30_SUPPORT_300_600_RESOLUTION = 0x1000000, 00399 /*! Support 400dpi x 800 dpi */ 00400 T30_SUPPORT_400_800_RESOLUTION = 0x2000000, 00401 /*! Support 600dpi x 1200 dpi */ 00402 T30_SUPPORT_600_1200_RESOLUTION = 0x4000000 00403 }; 00404 00405 enum 00406 { 00407 T30_SUPPORT_215MM_WIDTH = 0x01, 00408 T30_SUPPORT_255MM_WIDTH = 0x02, 00409 T30_SUPPORT_303MM_WIDTH = 0x04, 00410 00411 T30_SUPPORT_UNLIMITED_LENGTH = 0x10000, 00412 T30_SUPPORT_A4_LENGTH = 0x20000, 00413 T30_SUPPORT_B4_LENGTH = 0x40000, 00414 T30_SUPPORT_US_LETTER_LENGTH = 0x80000, 00415 T30_SUPPORT_US_LEGAL_LENGTH = 0x100000 00416 }; 00417 00418 enum 00419 { 00420 /*! Enable support of identification, through the SID and/or PWD frames. */ 00421 T30_SUPPORT_IDENTIFICATION = 0x01, 00422 /*! Enable support of selective polling, through the SEP frame. */ 00423 T30_SUPPORT_SELECTIVE_POLLING = 0x02, 00424 /*! Enable support of polling sub-addressing, through the PSA frame. */ 00425 T30_SUPPORT_POLLED_SUB_ADDRESSING = 0x04, 00426 /*! Enable support of multiple selective polling, through repeated used of the SEP and PSA frames. */ 00427 T30_SUPPORT_MULTIPLE_SELECTIVE_POLLING = 0x08, 00428 /*! Enable support of sub-addressing, through the SUB frame. */ 00429 T30_SUPPORT_SUB_ADDRESSING = 0x10, 00430 /*! Enable support of transmitting subscriber internet address, through the TSA frame. */ 00431 T30_SUPPORT_TRANSMITTING_SUBSCRIBER_INTERNET_ADDRESS = 0x20, 00432 /*! Enable support of internet routing address, through the IRA frame. */ 00433 T30_SUPPORT_INTERNET_ROUTING_ADDRESS = 0x40, 00434 /*! Enable support of calling subscriber internet address, through the CIA frame. */ 00435 T30_SUPPORT_CALLING_SUBSCRIBER_INTERNET_ADDRESS = 0x80, 00436 /*! Enable support of internet selective polling address, through the ISP frame. */ 00437 T30_SUPPORT_INTERNET_SELECTIVE_POLLING_ADDRESS = 0x100, 00438 /*! Enable support of called subscriber internet address, through the CSA frame. */ 00439 T30_SUPPORT_CALLED_SUBSCRIBER_INTERNET_ADDRESS = 0x200, 00440 /*! Enable support of the field not valid (FNV) frame. */ 00441 T30_SUPPORT_FIELD_NOT_VALID = 0x400, 00442 /*! Enable support of the command repeat (CRP) frame. */ 00443 T30_SUPPORT_COMMAND_REPEAT = 0x800 00444 }; 00445 00446 enum 00447 { 00448 T30_IAF_MODE_T37 = 0x01, 00449 T30_IAF_MODE_T38 = 0x02, 00450 T30_IAF_MODE_FLOW_CONTROL = 0x04, 00451 /*! Continuous flow mode means data is sent as fast as possible, usually across 00452 the Internet, where speed is not constrained by a PSTN modem. */ 00453 T30_IAF_MODE_CONTINUOUS_FLOW = 0x08, 00454 /*! No TCF means TCF is not exchanged. The end points must sort out usable speed 00455 issues locally. */ 00456 T30_IAF_MODE_NO_TCF = 0x10, 00457 /*! No fill bits means do not insert fill bits, even if the T.30 messages request 00458 them. */ 00459 T30_IAF_MODE_NO_FILL_BITS = 0x20, 00460 /*! No indicators means do not send indicator messages when using T.38. */ 00461 T30_IAF_MODE_NO_INDICATORS = 0x40, 00462 /*! Use relaxed timers for T.38. This is appropriate when using TCP/TPKT for T.38, 00463 as there is no point in anything but a long backstop timeout in such a mode. */ 00464 T30_IAF_MODE_RELAXED_TIMERS = 0x80 00465 }; 00466 00467 typedef struct 00468 { 00469 /*! \brief The identifier string (CSI, TSI, CIG). */ 00470 char ident[T30_MAX_IDENT_LEN + 1]; 00471 /*! \brief The sub-address string (SUB). */ 00472 char sub_address[T30_MAX_IDENT_LEN + 1]; 00473 /*! \brief The selective polling sub-address (SEP). */ 00474 char selective_polling_address[T30_MAX_IDENT_LEN + 1]; 00475 /*! \brief The polled sub-address (PSA). */ 00476 char polled_sub_address[T30_MAX_IDENT_LEN + 1]; 00477 /*! \brief The sender identification (SID). */ 00478 char sender_ident[T30_MAX_IDENT_LEN + 1]; 00479 /*! \brief The password (PWD). */ 00480 char password[T30_MAX_IDENT_LEN + 1]; 00481 /*! \brief Non-standard facilities (NSF). */ 00482 uint8_t *nsf; 00483 size_t nsf_len; 00484 /*! \brief Non-standard facilities command (NSC). */ 00485 uint8_t *nsc; 00486 size_t nsc_len; 00487 /*! \brief Non-standard facilities set-up (NSS). */ 00488 uint8_t *nss; 00489 size_t nss_len; 00490 /*! \brief Transmitting subscriber internet address (TSA). */ 00491 int tsa_type; 00492 char *tsa; 00493 size_t tsa_len; 00494 /*! \brief Internet routing address (IRA). */ 00495 int ira_type; 00496 char *ira; 00497 size_t ira_len; 00498 /*! \brief Calling subscriber internet address (CIA). */ 00499 int cia_type; 00500 char *cia; 00501 size_t cia_len; 00502 /*! \brief Internet selective polling address (ISP). */ 00503 int isp_type; 00504 char *isp; 00505 size_t isp_len; 00506 /*! \brief Called subscriber internet address (CSA). */ 00507 int csa_type; 00508 char *csa; 00509 size_t csa_len; 00510 } t30_exchanged_info_t; 00511 00512 typedef struct 00513 { 00514 /*! \brief The current bit rate for image transfer. */ 00515 int bit_rate; 00516 /*! \brief TRUE if error correcting mode is used. */ 00517 int error_correcting_mode; 00518 /*! \brief The number of pages sent so far. */ 00519 int pages_tx; 00520 /*! \brief The number of pages received so far. */ 00521 int pages_rx; 00522 /*! \brief The number of pages in the file (<0 if not known). */ 00523 int pages_in_file; 00524 /*! \brief The horizontal column-to-column resolution of the page, in pixels per metre */ 00525 int x_resolution; 00526 /*! \brief The vertical row-to-row resolution of the page, in pixels per metre */ 00527 int y_resolution; 00528 /*! \brief The number of horizontal pixels in the most recent page. */ 00529 int width; 00530 /*! \brief The number of vertical pixels in the most recent page. */ 00531 int length; 00532 /*! \brief The size of the image, in bytes */ 00533 int image_size; 00534 /*! \brief The type of compression used between the FAX machines */ 00535 int encoding; 00536 /*! \brief The number of bad pixel rows in the most recent page. */ 00537 int bad_rows; 00538 /*! \brief The largest number of bad pixel rows in a block in the most recent page. */ 00539 int longest_bad_row_run; 00540 /*! \brief The number of HDLC frame retries, if error correcting mode is used. */ 00541 int error_correcting_mode_retries; 00542 /*! \brief Current status */ 00543 int current_status; 00544 } t30_stats_t; 00545 00546 #if defined(__cplusplus) 00547 extern "C" 00548 { 00549 #endif 00550 00551 /*! Initialise a T.30 context. 00552 \brief Initialise a T.30 context. 00553 \param s The T.30 context. 00554 \param calling_party TRUE if the context is for a calling party. FALSE if the 00555 context is for an answering party. 00556 \param set_rx_type_handler 00557 \param set_rx_type_user_data 00558 \param set_tx_type_handler 00559 \param set_tx_type_user_data 00560 \param send_hdlc_handler 00561 \param send_hdlc_user_data 00562 \return A pointer to the context, or NULL if there was a problem. */ 00563 SPAN_DECLARE(t30_state_t *) t30_init(t30_state_t *s, 00564 int calling_party, 00565 t30_set_handler_t *set_rx_type_handler, 00566 void *set_rx_type_user_data, 00567 t30_set_handler_t *set_tx_type_handler, 00568 void *set_tx_type_user_data, 00569 t30_send_hdlc_handler_t *send_hdlc_handler, 00570 void *send_hdlc_user_data); 00571 00572 /*! Release a T.30 context. 00573 \brief Release a T.30 context. 00574 \param s The T.30 context. 00575 \return 0 for OK, else -1. */ 00576 SPAN_DECLARE(int) t30_release(t30_state_t *s); 00577 00578 /*! Free a T.30 context. 00579 \brief Free a T.30 context. 00580 \param s The T.30 context. 00581 \return 0 for OK, else -1. */ 00582 SPAN_DECLARE(int) t30_free(t30_state_t *s); 00583 00584 /*! Restart a T.30 context. 00585 \brief Restart a T.30 context. 00586 \param s The T.30 context. 00587 \return 0 for OK, else -1. */ 00588 SPAN_DECLARE(int) t30_restart(t30_state_t *s); 00589 00590 /*! Check if a T.30 call is still active. This may be used to regularly poll 00591 if the job has finished. 00592 \brief Check if a T.30 call is still active. 00593 \param s The T.30 context. 00594 \return TRUE for call still active, or FALSE for call completed. */ 00595 SPAN_DECLARE(int) t30_call_active(t30_state_t *s); 00596 00597 /*! Cleanup a T.30 context if the call terminates. 00598 \brief Cleanup a T.30 context if the call terminates. 00599 \param s The T.30 context. */ 00600 SPAN_DECLARE(void) t30_terminate(t30_state_t *s); 00601 00602 /*! Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.). 00603 \brief Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.). 00604 \param user_data The T.30 context. 00605 \param status The type of status change which occured. */ 00606 SPAN_DECLARE(void) t30_front_end_status(void *user_data, int status); 00607 00608 /*! Get a bit of received non-ECM image data. 00609 \brief Get a bit of received non-ECM image data. 00610 \param user_data An opaque pointer, which must point to the T.30 context. 00611 \return The next bit to transmit. */ 00612 SPAN_DECLARE_NONSTD(int) t30_non_ecm_get_bit(void *user_data); 00613 00614 /*! Get a byte of received non-ECM image data. 00615 \brief Get a byte of received non-ECM image data. 00616 \param user_data An opaque pointer, which must point to the T.30 context. 00617 \return The next byte to transmit. */ 00618 SPAN_DECLARE(int) t30_non_ecm_get_byte(void *user_data); 00619 00620 /*! Get a chunk of received non-ECM image data. 00621 \brief Get a bit of received non-ECM image data. 00622 \param user_data An opaque pointer, which must point to the T.30 context. 00623 \param buf The buffer to contain the data. 00624 \param max_len The maximum length of the chunk. 00625 \return The actual length of the chunk. */ 00626 SPAN_DECLARE(int) t30_non_ecm_get_chunk(void *user_data, uint8_t buf[], int max_len); 00627 00628 /*! Process a bit of received non-ECM image data. 00629 \brief Process a bit of received non-ECM image data 00630 \param user_data An opaque pointer, which must point to the T.30 context. 00631 \param bit The received bit. */ 00632 SPAN_DECLARE_NONSTD(void) t30_non_ecm_put_bit(void *user_data, int bit); 00633 00634 /*! Process a byte of received non-ECM image data. 00635 \brief Process a byte of received non-ECM image data 00636 \param user_data An opaque pointer, which must point to the T.30 context. 00637 \param byte The received byte. */ 00638 SPAN_DECLARE(void) t30_non_ecm_put_byte(void *user_data, int byte); 00639 00640 /*! Process a chunk of received non-ECM image data. 00641 \brief Process a chunk of received non-ECM image data 00642 \param user_data An opaque pointer, which must point to the T.30 context. 00643 \param buf The buffer containing the received data. 00644 \param len The length of the data in buf. */ 00645 SPAN_DECLARE(void) t30_non_ecm_put_chunk(void *user_data, const uint8_t buf[], int len); 00646 00647 /*! Process a received HDLC frame. 00648 \brief Process a received HDLC frame. 00649 \param user_data The T.30 context. 00650 \param msg The HDLC message. 00651 \param len The length of the message, in octets. 00652 \param ok TRUE if the frame was received without error. */ 00653 SPAN_DECLARE_NONSTD(void) t30_hdlc_accept(void *user_data, const uint8_t *msg, int len, int ok); 00654 00655 /*! Report the passage of time to the T.30 engine. 00656 \brief Report the passage of time to the T.30 engine. 00657 \param s The T.30 context. 00658 \param samples The time change in 1/8000th second steps. */ 00659 SPAN_DECLARE(void) t30_timer_update(t30_state_t *s, int samples); 00660 00661 /*! Get the current transfer statistics for the file being sent or received. 00662 \brief Get the current transfer statistics. 00663 \param s The T.30 context. 00664 \param t A pointer to a buffer for the statistics. */ 00665 SPAN_DECLARE(void) t30_get_transfer_statistics(t30_state_t *s, t30_stats_t *t); 00666 00667 /*! Request a local interrupt of FAX exchange. 00668 \brief Request a local interrupt of FAX exchange. 00669 \param s The T.30 context. 00670 \param state TRUE to enable interrupt request, else FALSE. */ 00671 SPAN_DECLARE(void) t30_local_interrupt_request(t30_state_t *s, int state); 00672 00673 #if defined(__cplusplus) 00674 } 00675 #endif 00676 00677 #endif 00678 /*- End of file ------------------------------------------------------------*/