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.125 2009/04/12 09:12:10 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 /*! The maximum length of a DIS, DTC or DCS frame */ 00144 #define T30_MAX_DIS_DTC_DCS_LEN 22 00145 /*! The maximum length of the body of an ident string */ 00146 #define T30_MAX_IDENT_LEN 20 00147 /*! The maximum length of the user string to insert in page headers */ 00148 #define T30_MAX_PAGE_HEADER_INFO 50 00149 00150 typedef struct t30_state_s t30_state_t; 00151 00152 /*! 00153 T.30 phase B callback handler. This handler can be used to process addition 00154 information available in some FAX calls, such as passwords. The callback handler 00155 can access whatever additional information might have been received, using 00156 t30_get_received_info(). 00157 \brief T.30 phase B callback handler. 00158 \param s The T.30 context. 00159 \param user_data An opaque pointer. 00160 \param result The phase B event code. 00161 \return The new status. Normally, T30_ERR_OK is returned. 00162 */ 00163 typedef int (t30_phase_b_handler_t)(t30_state_t *s, void *user_data, int result); 00164 00165 /*! 00166 T.30 phase D callback handler. 00167 \brief T.30 phase D callback handler. 00168 \param s The T.30 context. 00169 \param user_data An opaque pointer. 00170 \param result The phase D event code. 00171 \return The new status. Normally, T30_ERR_OK is returned. 00172 */ 00173 typedef int (t30_phase_d_handler_t)(t30_state_t *s, void *user_data, int result); 00174 00175 /*! 00176 T.30 phase E callback handler. 00177 \brief T.30 phase E callback handler. 00178 \param s The T.30 context. 00179 \param user_data An opaque pointer. 00180 \param completion_code The phase E completion code. 00181 */ 00182 typedef void (t30_phase_e_handler_t)(t30_state_t *s, void *user_data, int completion_code); 00183 00184 /*! 00185 T.30 real time frame handler. 00186 \brief T.30 real time frame handler. 00187 \param s The T.30 context. 00188 \param user_data An opaque pointer. 00189 \param direction TRUE for incoming, FALSE for outgoing. 00190 \param msg The HDLC message. 00191 \param len The length of the message. 00192 */ 00193 typedef void (t30_real_time_frame_handler_t)(t30_state_t *s, 00194 void *user_data, 00195 int direction, 00196 const uint8_t msg[], 00197 int len); 00198 00199 /*! 00200 T.30 document handler. 00201 \brief T.30 document handler. 00202 \param s The T.30 context. 00203 \param user_data An opaque pointer. 00204 \param result The document event code. 00205 */ 00206 typedef int (t30_document_handler_t)(t30_state_t *s, void *user_data, int status); 00207 00208 /*! 00209 T.30 set a receive or transmit type handler. 00210 \brief T.30 set a receive or transmit type handler. 00211 \param user_data An opaque pointer. 00212 \param type The modem, tone or silence to be sent or received. 00213 \param bit_rate The bit rate of the modem to be sent or received. 00214 \param short_train TRUE if the short training sequence should be used (where one exists). 00215 \param use_hdlc FALSE for bit stream, TRUE for HDLC framing. 00216 */ 00217 typedef void (t30_set_handler_t)(void *user_data, int type, int bit_rate, int short_train, int use_hdlc); 00218 00219 /*! 00220 T.30 send HDLC handler. 00221 \brief T.30 send HDLC handler. 00222 \param user_data An opaque pointer. 00223 \param msg The HDLC message. 00224 \param len The length of the message. 00225 */ 00226 typedef void (t30_send_hdlc_handler_t)(void *user_data, const uint8_t msg[], int len); 00227 00228 /*! 00229 T.30 protocol completion codes, at phase E. 00230 */ 00231 enum 00232 { 00233 T30_ERR_OK = 0, /*! OK */ 00234 00235 /* Link problems */ 00236 T30_ERR_CEDTONE, /*! The CED tone exceeded 5s */ 00237 T30_ERR_T0_EXPIRED, /*! Timed out waiting for initial communication */ 00238 T30_ERR_T1_EXPIRED, /*! Timed out waiting for the first message */ 00239 T30_ERR_T3_EXPIRED, /*! Timed out waiting for procedural interrupt */ 00240 T30_ERR_HDLC_CARRIER, /*! The HDLC carrier did not stop in a timely manner */ 00241 T30_ERR_CANNOT_TRAIN, /*! Failed to train with any of the compatible modems */ 00242 T30_ERR_OPER_INT_FAIL, /*! Operator intervention failed */ 00243 T30_ERR_INCOMPATIBLE, /*! Far end is not compatible */ 00244 T30_ERR_RX_INCAPABLE, /*! Far end is not able to receive */ 00245 T30_ERR_TX_INCAPABLE, /*! Far end is not able to transmit */ 00246 T30_ERR_NORESSUPPORT, /*! Far end cannot receive at the resolution of the image */ 00247 T30_ERR_NOSIZESUPPORT, /*! Far end cannot receive at the size of image */ 00248 T30_ERR_UNEXPECTED, /*! Unexpected message received */ 00249 00250 /* Phase E status values returned to a transmitter */ 00251 T30_ERR_TX_BADDCS, /*! Received bad response to DCS or training */ 00252 T30_ERR_TX_BADPG, /*! Received a DCN from remote after sending a page */ 00253 T30_ERR_TX_ECMPHD, /*! Invalid ECM response received from receiver */ 00254 T30_ERR_TX_GOTDCN, /*! Received a DCN while waiting for a DIS */ 00255 T30_ERR_TX_INVALRSP, /*! Invalid response after sending a page */ 00256 T30_ERR_TX_NODIS, /*! Received other than DIS while waiting for DIS */ 00257 T30_ERR_TX_PHBDEAD, /*! Received no response to DCS, training or TCF */ 00258 T30_ERR_TX_PHDDEAD, /*! No response after sending a page */ 00259 T30_ERR_TX_T5EXP, /*! Timed out waiting for receiver ready (ECM mode) */ 00260 00261 /* Phase E status values returned to a receiver */ 00262 T30_ERR_RX_ECMPHD, /*! Invalid ECM response received from transmitter */ 00263 T30_ERR_RX_GOTDCS, /*! DCS received while waiting for DTC */ 00264 T30_ERR_RX_INVALCMD, /*! Unexpected command after page received */ 00265 T30_ERR_RX_NOCARRIER, /*! Carrier lost during fax receive */ 00266 T30_ERR_RX_NOEOL, /*! Timed out while waiting for EOL (end Of line) */ 00267 T30_ERR_RX_NOFAX, /*! Timed out while waiting for first line */ 00268 T30_ERR_RX_T2EXPDCN, /*! Timer T2 expired while waiting for DCN */ 00269 T30_ERR_RX_T2EXPD, /*! Timer T2 expired while waiting for phase D */ 00270 T30_ERR_RX_T2EXPFAX, /*! Timer T2 expired while waiting for fax page */ 00271 T30_ERR_RX_T2EXPMPS, /*! Timer T2 expired while waiting for next fax page */ 00272 T30_ERR_RX_T2EXPRR, /*! Timer T2 expired while waiting for RR command */ 00273 T30_ERR_RX_T2EXP, /*! Timer T2 expired while waiting for NSS, DCS or MCF */ 00274 T30_ERR_RX_DCNWHY, /*! Unexpected DCN while waiting for DCS or DIS */ 00275 T30_ERR_RX_DCNDATA, /*! Unexpected DCN while waiting for image data */ 00276 T30_ERR_RX_DCNFAX, /*! Unexpected DCN while waiting for EOM, EOP or MPS */ 00277 T30_ERR_RX_DCNPHD, /*! Unexpected DCN after EOM or MPS sequence */ 00278 T30_ERR_RX_DCNRRD, /*! Unexpected DCN after RR/RNR sequence */ 00279 T30_ERR_RX_DCNNORTN, /*! Unexpected DCN after requested retransmission */ 00280 00281 /* TIFF file problems */ 00282 T30_ERR_FILEERROR, /*! TIFF/F file cannot be opened */ 00283 T30_ERR_NOPAGE, /*! TIFF/F page not found */ 00284 T30_ERR_BADTIFF, /*! TIFF/F format is not compatible */ 00285 T30_ERR_BADPAGE, /*! TIFF/F page number tag missing */ 00286 T30_ERR_BADTAG, /*! Incorrect values for TIFF/F tags */ 00287 T30_ERR_BADTIFFHDR, /*! Bad TIFF/F header - incorrect values in fields */ 00288 T30_ERR_NOMEM, /*! Cannot allocate memory for more pages */ 00289 00290 /* General problems */ 00291 T30_ERR_RETRYDCN, /*! Disconnected after permitted retries */ 00292 T30_ERR_CALLDROPPED, /*! The call dropped prematurely */ 00293 00294 /* Feature negotiation issues */ 00295 T30_ERR_NOPOLL, /*! Poll not accepted */ 00296 T30_ERR_IDENT_UNACCEPTABLE, /*! Far end's ident is not acceptable */ 00297 T30_ERR_SUB_UNACCEPTABLE, /*! Far end's sub-address is not acceptable */ 00298 T30_ERR_SEP_UNACCEPTABLE, /*! Far end's selective polling address is not acceptable */ 00299 T30_ERR_PSA_UNACCEPTABLE, /*! Far end's polled sub-address is not acceptable */ 00300 T30_ERR_SID_UNACCEPTABLE, /*! Far end's sender identification is not acceptable */ 00301 T30_ERR_PWD_UNACCEPTABLE, /*! Far end's password is not acceptable */ 00302 T30_ERR_TSA_UNACCEPTABLE, /*! Far end's transmitting subscriber internet address is not acceptable */ 00303 T30_ERR_IRA_UNACCEPTABLE, /*! Far end's internet routing address is not acceptable */ 00304 T30_ERR_CIA_UNACCEPTABLE, /*! Far end's calling subscriber internet address is not acceptable */ 00305 T30_ERR_ISP_UNACCEPTABLE, /*! Far end's internet selective polling address is not acceptable */ 00306 T30_ERR_CSA_UNACCEPTABLE /*! Far end's called subscriber internet address is not acceptable */ 00307 }; 00308 00309 /*! 00310 I/O modes for the T.30 protocol. 00311 These are allocated such that the lower 4 bits represents the variant of the modem - e.g. the 00312 particular bit rate selected. 00313 */ 00314 enum 00315 { 00316 T30_MODEM_NONE = 0, 00317 T30_MODEM_PAUSE, 00318 T30_MODEM_CED, 00319 T30_MODEM_CNG, 00320 T30_MODEM_V21, 00321 T30_MODEM_V27TER, 00322 T30_MODEM_V29, 00323 T30_MODEM_V17, 00324 T30_MODEM_DONE 00325 }; 00326 00327 enum 00328 { 00329 T30_FRONT_END_SEND_STEP_COMPLETE = 0, 00330 /*! The current receive has completed. This is only needed to report an 00331 unexpected end of the receive operation, as might happen with T.38 00332 dying. */ 00333 T30_FRONT_END_RECEIVE_COMPLETE, 00334 T30_FRONT_END_SIGNAL_PRESENT, 00335 T30_FRONT_END_SIGNAL_ABSENT, 00336 T30_FRONT_END_CED_PRESENT, 00337 T30_FRONT_END_CNG_PRESENT 00338 }; 00339 00340 enum 00341 { 00342 /*! Support the V.27ter modem (2400, and 4800bps) for image transfer. */ 00343 T30_SUPPORT_V27TER = 0x01, 00344 /*! Support the V.29 modem (9600, and 7200bps) for image transfer. */ 00345 T30_SUPPORT_V29 = 0x02, 00346 /*! Support the V.17 modem (14400, 12000, 9600 and 7200bps) for image transfer. */ 00347 T30_SUPPORT_V17 = 0x04, 00348 /*! Support the V.34 modem (up to 33,600bps) for image transfer. */ 00349 T30_SUPPORT_V34 = 0x08, 00350 /*! Support the Internet Aware FAX mode (no bit rate limit) for image transfer. */ 00351 T30_SUPPORT_IAF = 0x10 00352 }; 00353 00354 enum 00355 { 00356 /*! No compression */ 00357 T30_SUPPORT_NO_COMPRESSION = 0x01, 00358 /*! T.1 1D compression */ 00359 T30_SUPPORT_T4_1D_COMPRESSION = 0x02, 00360 /*! T.4 2D compression */ 00361 T30_SUPPORT_T4_2D_COMPRESSION = 0x04, 00362 /*! T.6 2D compression */ 00363 T30_SUPPORT_T6_COMPRESSION = 0x08, 00364 /*! T.85 monochrome JBIG coding */ 00365 T30_SUPPORT_T85_COMPRESSION = 0x10, 00366 /*! T.43 colour JBIG coding */ 00367 T30_SUPPORT_T43_COMPRESSION = 0x20, 00368 /*! T.45 run length colour compression */ 00369 T30_SUPPORT_T45_COMPRESSION = 0x40, 00370 /*! T.81 + T.30 Annex E colour JPEG coding */ 00371 T30_SUPPORT_T81_COMPRESSION = 0x80, 00372 /*! T.81 + T.30 Annex K colour sYCC-JPEG coding */ 00373 T30_SUPPORT_SYCC_T81_COMPRESSION = 0x100 00374 }; 00375 00376 enum 00377 { 00378 /*! Support standard FAX Y-resolution 98/100dpi */ 00379 T30_SUPPORT_STANDARD_RESOLUTION = 0x01, 00380 /*! Support fine FAX Y-resolution 196/200dpi */ 00381 T30_SUPPORT_FINE_RESOLUTION = 0x02, 00382 /*! Support super-fine FAX Y-resolution 392/400dpi */ 00383 T30_SUPPORT_SUPERFINE_RESOLUTION = 0x04, 00384 00385 /*! Support half FAX X-resolution 100/102dpi */ 00386 T30_SUPPORT_R4_RESOLUTION = 0x10000, 00387 /*! Support standard FAX X-resolution 200/204dpi */ 00388 T30_SUPPORT_R8_RESOLUTION = 0x20000, 00389 /*! Support double FAX X-resolution 400dpi */ 00390 T30_SUPPORT_R16_RESOLUTION = 0x40000, 00391 00392 /*! Support 300dpi x 300 dpi */ 00393 T30_SUPPORT_300_300_RESOLUTION = 0x100000, 00394 /*! Support 400dpi x 400 dpi */ 00395 T30_SUPPORT_400_400_RESOLUTION = 0x200000, 00396 /*! Support 600dpi x 600 dpi */ 00397 T30_SUPPORT_600_600_RESOLUTION = 0x400000, 00398 /*! Support 1200dpi x 1200 dpi */ 00399 T30_SUPPORT_1200_1200_RESOLUTION = 0x800000, 00400 /*! Support 300dpi x 600 dpi */ 00401 T30_SUPPORT_300_600_RESOLUTION = 0x1000000, 00402 /*! Support 400dpi x 800 dpi */ 00403 T30_SUPPORT_400_800_RESOLUTION = 0x2000000, 00404 /*! Support 600dpi x 1200 dpi */ 00405 T30_SUPPORT_600_1200_RESOLUTION = 0x4000000 00406 }; 00407 00408 enum 00409 { 00410 T30_SUPPORT_215MM_WIDTH = 0x01, 00411 T30_SUPPORT_255MM_WIDTH = 0x02, 00412 T30_SUPPORT_303MM_WIDTH = 0x04, 00413 00414 T30_SUPPORT_UNLIMITED_LENGTH = 0x10000, 00415 T30_SUPPORT_A4_LENGTH = 0x20000, 00416 T30_SUPPORT_B4_LENGTH = 0x40000, 00417 T30_SUPPORT_US_LETTER_LENGTH = 0x80000, 00418 T30_SUPPORT_US_LEGAL_LENGTH = 0x100000 00419 }; 00420 00421 enum 00422 { 00423 /*! Enable support of identification, through the SID and/or PWD frames. */ 00424 T30_SUPPORT_IDENTIFICATION = 0x01, 00425 /*! Enable support of selective polling, through the SEP frame. */ 00426 T30_SUPPORT_SELECTIVE_POLLING = 0x02, 00427 /*! Enable support of polling sub-addressing, through the PSA frame. */ 00428 T30_SUPPORT_POLLED_SUB_ADDRESSING = 0x04, 00429 /*! Enable support of multiple selective polling, through repeated used of the SEP and PSA frames. */ 00430 T30_SUPPORT_MULTIPLE_SELECTIVE_POLLING = 0x08, 00431 /*! Enable support of sub-addressing, through the SUB frame. */ 00432 T30_SUPPORT_SUB_ADDRESSING = 0x10, 00433 /*! Enable support of transmitting subscriber internet address, through the TSA frame. */ 00434 T30_SUPPORT_TRANSMITTING_SUBSCRIBER_INTERNET_ADDRESS = 0x20, 00435 /*! Enable support of internet routing address, through the IRA frame. */ 00436 T30_SUPPORT_INTERNET_ROUTING_ADDRESS = 0x40, 00437 /*! Enable support of calling subscriber internet address, through the CIA frame. */ 00438 T30_SUPPORT_CALLING_SUBSCRIBER_INTERNET_ADDRESS = 0x80, 00439 /*! Enable support of internet selective polling address, through the ISP frame. */ 00440 T30_SUPPORT_INTERNET_SELECTIVE_POLLING_ADDRESS = 0x100, 00441 /*! Enable support of called subscriber internet address, through the CSA frame. */ 00442 T30_SUPPORT_CALLED_SUBSCRIBER_INTERNET_ADDRESS = 0x200, 00443 /*! Enable support of the field not valid (FNV) frame. */ 00444 T30_SUPPORT_FIELD_NOT_VALID = 0x400, 00445 /*! Enable support of the command repeat (CRP) frame. */ 00446 T30_SUPPORT_COMMAND_REPEAT = 0x800 00447 }; 00448 00449 enum 00450 { 00451 T30_IAF_MODE_T37 = 0x01, 00452 T30_IAF_MODE_T38 = 0x02, 00453 T30_IAF_MODE_FLOW_CONTROL = 0x04, 00454 /*! Continuous flow mode means data is sent as fast as possible, usually across 00455 the Internet, where speed is not constrained by a PSTN modem. */ 00456 T30_IAF_MODE_CONTINUOUS_FLOW = 0x08, 00457 /*! No TCF means TCF is not exchanged. The end points must sort out usable speed 00458 issues locally. */ 00459 T30_IAF_MODE_NO_TCF = 0x10, 00460 /*! No fill bits means do not insert fill bits, even if the T.30 messages request 00461 them. */ 00462 T30_IAF_MODE_NO_FILL_BITS = 0x20, 00463 /*! No indicators means do not send indicator messages when using T.38. */ 00464 T30_IAF_MODE_NO_INDICATORS = 0x40, 00465 /*! Use relaxed timers for T.38. This is appropriate when using TCP/TPKT for T.38, 00466 as there is no point in anything but a long backstop timeout in such a mode. */ 00467 T30_IAF_MODE_RELAXED_TIMERS = 0x80 00468 }; 00469 00470 typedef struct 00471 { 00472 /*! \brief The identifier string (CSI, TSI, CIG). */ 00473 char ident[T30_MAX_IDENT_LEN + 1]; 00474 /*! \brief The sub-address string (SUB). */ 00475 char sub_address[T30_MAX_IDENT_LEN + 1]; 00476 /*! \brief The selective polling sub-address (SEP). */ 00477 char selective_polling_address[T30_MAX_IDENT_LEN + 1]; 00478 /*! \brief The polled sub-address (PSA). */ 00479 char polled_sub_address[T30_MAX_IDENT_LEN + 1]; 00480 /*! \brief The sender identification (SID). */ 00481 char sender_ident[T30_MAX_IDENT_LEN + 1]; 00482 /*! \brief The password (PWD). */ 00483 char password[T30_MAX_IDENT_LEN + 1]; 00484 /*! \brief Non-standard facilities (NSF). */ 00485 uint8_t *nsf; 00486 size_t nsf_len; 00487 /*! \brief Non-standard facilities command (NSC). */ 00488 uint8_t *nsc; 00489 size_t nsc_len; 00490 /*! \brief Non-standard facilities set-up (NSS). */ 00491 uint8_t *nss; 00492 size_t nss_len; 00493 /*! \brief Transmitting subscriber internet address (TSA). */ 00494 int tsa_type; 00495 char *tsa; 00496 size_t tsa_len; 00497 /*! \brief Internet routing address (IRA). */ 00498 int ira_type; 00499 char *ira; 00500 size_t ira_len; 00501 /*! \brief Calling subscriber internet address (CIA). */ 00502 int cia_type; 00503 char *cia; 00504 size_t cia_len; 00505 /*! \brief Internet selective polling address (ISP). */ 00506 int isp_type; 00507 char *isp; 00508 size_t isp_len; 00509 /*! \brief Called subscriber internet address (CSA). */ 00510 int csa_type; 00511 char *csa; 00512 size_t csa_len; 00513 } t30_exchanged_info_t; 00514 00515 typedef struct 00516 { 00517 /*! \brief The current bit rate for image transfer. */ 00518 int bit_rate; 00519 /*! \brief TRUE if error correcting mode is used. */ 00520 int error_correcting_mode; 00521 /*! \brief The number of pages sent so far. */ 00522 int pages_tx; 00523 /*! \brief The number of pages received so far. */ 00524 int pages_rx; 00525 /*! \brief The number of pages in the file (<0 if not known). */ 00526 int pages_in_file; 00527 /*! \brief The horizontal column-to-column resolution of the page, in pixels per metre */ 00528 int x_resolution; 00529 /*! \brief The vertical row-to-row resolution of the page, in pixels per metre */ 00530 int y_resolution; 00531 /*! \brief The number of horizontal pixels in the most recent page. */ 00532 int width; 00533 /*! \brief The number of vertical pixels in the most recent page. */ 00534 int length; 00535 /*! \brief The size of the image, in bytes */ 00536 int image_size; 00537 /*! \brief The type of compression used between the FAX machines */ 00538 int encoding; 00539 /*! \brief The number of bad pixel rows in the most recent page. */ 00540 int bad_rows; 00541 /*! \brief The largest number of bad pixel rows in a block in the most recent page. */ 00542 int longest_bad_row_run; 00543 /*! \brief The number of HDLC frame retries, if error correcting mode is used. */ 00544 int error_correcting_mode_retries; 00545 /*! \brief Current status */ 00546 int current_status; 00547 } t30_stats_t; 00548 00549 #if defined(__cplusplus) 00550 extern "C" 00551 { 00552 #endif 00553 00554 /*! Initialise a T.30 context. 00555 \brief Initialise a T.30 context. 00556 \param s The T.30 context. 00557 \param calling_party TRUE if the context is for a calling party. FALSE if the 00558 context is for an answering party. 00559 \param set_rx_type_handler 00560 \param set_rx_type_user_data 00561 \param set_tx_type_handler 00562 \param set_tx_type_user_data 00563 \param send_hdlc_handler 00564 \param send_hdlc_user_data 00565 \return A pointer to the context, or NULL if there was a problem. */ 00566 SPAN_DECLARE(t30_state_t *) t30_init(t30_state_t *s, 00567 int calling_party, 00568 t30_set_handler_t *set_rx_type_handler, 00569 void *set_rx_type_user_data, 00570 t30_set_handler_t *set_tx_type_handler, 00571 void *set_tx_type_user_data, 00572 t30_send_hdlc_handler_t *send_hdlc_handler, 00573 void *send_hdlc_user_data); 00574 00575 /*! Release a T.30 context. 00576 \brief Release a T.30 context. 00577 \param s The T.30 context. 00578 \return 0 for OK, else -1. */ 00579 SPAN_DECLARE(int) t30_release(t30_state_t *s); 00580 00581 /*! Free a T.30 context. 00582 \brief Free a T.30 context. 00583 \param s The T.30 context. 00584 \return 0 for OK, else -1. */ 00585 SPAN_DECLARE(int) t30_free(t30_state_t *s); 00586 00587 /*! Restart a T.30 context. 00588 \brief Restart a T.30 context. 00589 \param s The T.30 context. 00590 \return 0 for OK, else -1. */ 00591 SPAN_DECLARE(int) t30_restart(t30_state_t *s); 00592 00593 /*! Check if a T.30 call is still active. This may be used to regularly poll 00594 if the job has finished. 00595 \brief Check if a T.30 call is still active. 00596 \param s The T.30 context. 00597 \return TRUE for call still active, or FALSE for call completed. */ 00598 SPAN_DECLARE(int) t30_call_active(t30_state_t *s); 00599 00600 /*! Cleanup a T.30 context if the call terminates. 00601 \brief Cleanup a T.30 context if the call terminates. 00602 \param s The T.30 context. */ 00603 SPAN_DECLARE(void) t30_terminate(t30_state_t *s); 00604 00605 /*! Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.). 00606 \brief Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.). 00607 \param user_data The T.30 context. 00608 \param status The type of status change which occured. */ 00609 SPAN_DECLARE(void) t30_front_end_status(void *user_data, int status); 00610 00611 /*! Get a bit of received non-ECM image data. 00612 \brief Get a bit of received non-ECM image data. 00613 \param user_data An opaque pointer, which must point to the T.30 context. 00614 \return The next bit to transmit. */ 00615 SPAN_DECLARE_NONSTD(int) t30_non_ecm_get_bit(void *user_data); 00616 00617 /*! Get a byte of received non-ECM image data. 00618 \brief Get a byte of received non-ECM image data. 00619 \param user_data An opaque pointer, which must point to the T.30 context. 00620 \return The next byte to transmit. */ 00621 SPAN_DECLARE(int) t30_non_ecm_get_byte(void *user_data); 00622 00623 /*! Get a chunk of received non-ECM image data. 00624 \brief Get a bit of received non-ECM image data. 00625 \param user_data An opaque pointer, which must point to the T.30 context. 00626 \param buf The buffer to contain the data. 00627 \param max_len The maximum length of the chunk. 00628 \return The actual length of the chunk. */ 00629 SPAN_DECLARE(int) t30_non_ecm_get_chunk(void *user_data, uint8_t buf[], int max_len); 00630 00631 /*! Process a bit of received non-ECM image data. 00632 \brief Process a bit of received non-ECM image data 00633 \param user_data An opaque pointer, which must point to the T.30 context. 00634 \param bit The received bit. */ 00635 SPAN_DECLARE_NONSTD(void) t30_non_ecm_put_bit(void *user_data, int bit); 00636 00637 /*! Process a byte of received non-ECM image data. 00638 \brief Process a byte of received non-ECM image data 00639 \param user_data An opaque pointer, which must point to the T.30 context. 00640 \param byte The received byte. */ 00641 SPAN_DECLARE(void) t30_non_ecm_put_byte(void *user_data, int byte); 00642 00643 /*! Process a chunk of received non-ECM image data. 00644 \brief Process a chunk of received non-ECM image data 00645 \param user_data An opaque pointer, which must point to the T.30 context. 00646 \param buf The buffer containing the received data. 00647 \param len The length of the data in buf. */ 00648 SPAN_DECLARE(void) t30_non_ecm_put_chunk(void *user_data, const uint8_t buf[], int len); 00649 00650 /*! Process a received HDLC frame. 00651 \brief Process a received HDLC frame. 00652 \param user_data The T.30 context. 00653 \param msg The HDLC message. 00654 \param len The length of the message, in octets. 00655 \param ok TRUE if the frame was received without error. */ 00656 SPAN_DECLARE_NONSTD(void) t30_hdlc_accept(void *user_data, const uint8_t msg[], int len, int ok); 00657 00658 /*! Report the passage of time to the T.30 engine. 00659 \brief Report the passage of time to the T.30 engine. 00660 \param s The T.30 context. 00661 \param samples The time change in 1/8000th second steps. */ 00662 SPAN_DECLARE(void) t30_timer_update(t30_state_t *s, int samples); 00663 00664 /*! Get the current transfer statistics for the file being sent or received. 00665 \brief Get the current transfer statistics. 00666 \param s The T.30 context. 00667 \param t A pointer to a buffer for the statistics. */ 00668 SPAN_DECLARE(void) t30_get_transfer_statistics(t30_state_t *s, t30_stats_t *t); 00669 00670 /*! Request a local interrupt of FAX exchange. 00671 \brief Request a local interrupt of FAX exchange. 00672 \param s The T.30 context. 00673 \param state TRUE to enable interrupt request, else FALSE. */ 00674 SPAN_DECLARE(void) t30_local_interrupt_request(t30_state_t *s, int state); 00675 00676 #if defined(__cplusplus) 00677 } 00678 #endif 00679 00680 #endif 00681 /*- End of file ------------------------------------------------------------*/