spandsp  0.0.6
t30.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * t30.h - definitions for T.30 fax processing
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2003 Steve Underwood
9  *
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 2.1,
14  * as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 /*! \file */
27 
28 #if !defined(_SPANDSP_T30_H_)
29 #define _SPANDSP_T30_H_
30 
31 /*! \page t30_page T.30 FAX protocol handling
32 
33 \section t30_page_sec_1 What does it do?
34 The T.30 protocol is the core protocol used for FAX transmission. This module
35 implements most of its key featrues. It does not interface to the outside work.
36 Seperate modules do that for T.38, analogue line, and other forms of FAX
37 communication.
38 
39 Current features of this module include:
40 
41  - FAXing to and from multi-page TIFF/F files, whose images are one of the standard
42  FAX sizes.
43  - V.27ter, V.29 and V.17 modes (2400bps, to 14,400bps).
44  - T.4 1D (MH), T.4 2D,(MR) and T.6 (MMR) compression.
45  - Error correction mode (ECM).
46  - All standard horizonal resolutions (R8, R16, 300dpi, 600dpi, 800dpi, 1200dpi).
47  - All standard vertical resolutions (standard, fine, superfine, 300dpi, 600dpi, 800dpi, 1200dpi).
48  - All standard page widths (A4, B4, A3).
49  - All standard page lengths (A4, B4, North American letter, North American legal, continuous).
50  - Monitoring and sending identifier strings (CSI, TSI, and CIG).
51  - Monitoring and sending sub-address strings (SUB).
52  - Monitoring and sending polling sub-addresses (SEP).
53  - Monitoring and sending polled sub-addresses (PSA).
54  - Monitoring and sending sender identifications (SID).
55  - Monitoring and sending passwords (PWD).
56  - Monitoring of non-standard facility frames (NSF, NSC, and NSS).
57  - Sending custom non-standard facility frames (NSF, NSC, and NSS).
58  - Analogue modem and T.38 operation.
59 
60 \section t30_page_sec_2 How does it work?
61 
62 Some of the following is paraphrased from some notes found a while ago on the Internet.
63 I cannot remember exactly where they came from, but they are useful.
64 
65 \subsection t30_page_sec_2a The answer (CED) tone
66 
67 The T.30 standard says an answering fax device must send CED (a 2100Hz tone) for
68 approximately 3 seconds before sending the first handshake message. Some machines
69 send an 1100Hz or 1850Hz tone, and some send no tone at all. In fact, this answer
70 tone is so unpredictable, it cannot really be used. It should, however, always be
71 generated according to the specification.
72 
73 \subsection t30_page_sec_2b Common Timing Deviations
74 
75 The T.30 spec. specifies a number of time-outs. For example, after dialing a number,
76 a calling fax system should listen for a response for 35 seconds before giving up.
77 These time-out periods are as follows:
78 
79  - T1 - 35+-5s: the maximum time for which two fax system will attempt to identify each other
80  - T2 - 6+-1s: a time-out used to start the sequence for changing transmit parameters
81  - T3 - 10+-5s: a time-out used in handling operator interrupts
82  - T5 - 60+-5s: a time-out used in error correction mode
83 
84 These time-outs are sometimes misinterpreted. In addition, they are routinely
85 ignored, sometimes with good reason. For example, after placing a call, the
86 calling fax system is supposed to wait for 35 seconds before giving up. If the
87 answering unit does not answer on the first ring or if a voice answering machine
88 is connected to the line, or if there are many delays through the network,
89 the delay before answer can be much longer than 35 seconds.
90 
91 Fax units that support error correction mode (ECM) can respond to a post-image
92 handshake message with a receiver not ready (RNR) message. The calling unit then
93 queries the receiving fax unit with a receiver ready (RR) message. If the
94 answering unit is still busy (printing for example), it will repeat the RNR
95 message. According to the T.30 standard, this sequence (RR/RNR RR/RNR) can be
96 repeated for up to the end of T5 (60+-5s). However, many fax systems
97 ignore the time-out and will continue the sequence indefinitely, unless the user
98 manually overrides.
99 
100 All the time-outs are subject to alteration, and sometimes misuse. Good T.30
101 implementations must do the right thing, and tolerate others doing the wrong thing.
102 
103 \subsection t30_page_sec_2c Variations in the inter-carrier gap
104 
105 T.30 specifies 75+-20ms of silence between signals using different modulation
106 schemes. Examples are between the end of a DCS signal and the start of a TCF signal,
107 and between the end of an image and the start of a post-image signal. Many fax systems
108 violate this requirement, especially for the silent period between DCS and TCF.
109 This may be stretched to well over 100ms. If this period is too long, it can interfere with
110 handshake signal error recovery, should a packet be corrupted on the line. Systems
111 should ensure they stay within the prescribed T.30 limits, and be tolerant of others
112 being out of spec..
113 
114 \subsection t30_page_sec_2d Other timing variations
115 
116 Testing is required to determine the ability of a fax system to handle
117 variations in the duration of pauses between unacknowledged handshake message
118 repetitions, and also in the pauses between the receipt of a handshake command and
119 the start of a response to that command. In order to reduce the total
120 transmission time, many fax systems start sending a response message before the
121 end of the command has been received.
122 
123 \subsection t30_page_sec_2e Other deviations from the T.30 standard
124 
125 There are many other commonly encountered variations between machines, including:
126 
127  - frame sequence deviations
128  - preamble and flag sequence variations
129  - improper EOM usage
130  - unusual data rate fallback sequences
131  - common training pattern detection algorithms
132  - image transmission deviations
133  - use of the talker echo protect tone
134  - image padding and short lines
135  - RTP/RTN handshake message usage
136  - long duration lines
137  - nonstandard disconnect sequences
138  - DCN usage
139 */
140 
141 /*! The maximum length of a DIS, DTC or DCS frame */
142 #define T30_MAX_DIS_DTC_DCS_LEN 22
143 /*! The maximum length of the body of an ident string */
144 #define T30_MAX_IDENT_LEN 20
145 /*! The maximum length of the user string to insert in page headers */
146 #define T30_MAX_PAGE_HEADER_INFO 50
147 
148 typedef struct t30_state_s t30_state_t;
149 
150 /*!
151  T.30 phase B callback handler. This handler can be used to process addition
152  information available in some FAX calls, such as passwords. The callback handler
153  can access whatever additional information might have been received, using
154  t30_get_received_info().
155  \brief T.30 phase B callback handler.
156  \param s The T.30 context.
157  \param user_data An opaque pointer.
158  \param result The phase B event code.
159  \return The new status. Normally, T30_ERR_OK is returned.
160 */
161 typedef int (t30_phase_b_handler_t)(t30_state_t *s, void *user_data, int result);
162 
163 /*!
164  T.30 phase D callback handler.
165  \brief T.30 phase D callback handler.
166  \param s The T.30 context.
167  \param user_data An opaque pointer.
168  \param result The phase D event code.
169  \return The new status. Normally, T30_ERR_OK is returned.
170 */
171 typedef int (t30_phase_d_handler_t)(t30_state_t *s, void *user_data, int result);
172 
173 /*!
174  T.30 phase E callback handler.
175  \brief T.30 phase E callback handler.
176  \param s The T.30 context.
177  \param user_data An opaque pointer.
178  \param completion_code The phase E completion code.
179 */
180 typedef void (t30_phase_e_handler_t)(t30_state_t *s, void *user_data, int completion_code);
181 
182 /*!
183  T.30 real time frame handler.
184  \brief T.30 real time frame handler.
185  \param s The T.30 context.
186  \param user_data An opaque pointer.
187  \param direction TRUE for incoming, FALSE for outgoing.
188  \param msg The HDLC message.
189  \param len The length of the message.
190 */
192  void *user_data,
193  int direction,
194  const uint8_t msg[],
195  int len);
196 
197 /*!
198  T.30 document handler.
199  \brief T.30 document handler.
200  \param s The T.30 context.
201  \param user_data An opaque pointer.
202  \param result The document event code.
203 */
204 typedef int (t30_document_handler_t)(t30_state_t *s, void *user_data, int status);
205 
206 /*!
207  T.30 set a receive or transmit type handler.
208  \brief T.30 set a receive or transmit type handler.
209  \param user_data An opaque pointer.
210  \param type The modem, tone or silence to be sent or received.
211  \param bit_rate The bit rate of the modem to be sent or received.
212  \param short_train TRUE if the short training sequence should be used (where one exists).
213  \param use_hdlc FALSE for bit stream, TRUE for HDLC framing.
214 */
215 typedef void (t30_set_handler_t)(void *user_data, int type, int bit_rate, int short_train, int use_hdlc);
216 
217 /*!
218  T.30 send HDLC handler.
219  \brief T.30 send HDLC handler.
220  \param user_data An opaque pointer.
221  \param msg The HDLC message.
222  \param len The length of the message.
223 */
224 typedef void (t30_send_hdlc_handler_t)(void *user_data, const uint8_t msg[], int len);
225 
226 /*!
227  T.30 protocol completion codes, at phase E.
228 */
229 enum
230 {
231  T30_ERR_OK = 0, /*! OK */
232 
233  /* Link problems */
234  T30_ERR_CEDTONE, /*! The CED tone exceeded 5s */
235  T30_ERR_T0_EXPIRED, /*! Timed out waiting for initial communication */
236  T30_ERR_T1_EXPIRED, /*! Timed out waiting for the first message */
237  T30_ERR_T3_EXPIRED, /*! Timed out waiting for procedural interrupt */
238  T30_ERR_HDLC_CARRIER, /*! The HDLC carrier did not stop in a timely manner */
239  T30_ERR_CANNOT_TRAIN, /*! Failed to train with any of the compatible modems */
240  T30_ERR_OPER_INT_FAIL, /*! Operator intervention failed */
241  T30_ERR_INCOMPATIBLE, /*! Far end is not compatible */
242  T30_ERR_RX_INCAPABLE, /*! Far end is not able to receive */
243  T30_ERR_TX_INCAPABLE, /*! Far end is not able to transmit */
244  T30_ERR_NORESSUPPORT, /*! Far end cannot receive at the resolution of the image */
245  T30_ERR_NOSIZESUPPORT, /*! Far end cannot receive at the size of image */
246  T30_ERR_UNEXPECTED, /*! Unexpected message received */
247 
248  /* Phase E status values returned to a transmitter */
249  T30_ERR_TX_BADDCS, /*! Received bad response to DCS or training */
250  T30_ERR_TX_BADPG, /*! Received a DCN from remote after sending a page */
251  T30_ERR_TX_ECMPHD, /*! Invalid ECM response received from receiver */
252  T30_ERR_TX_GOTDCN, /*! Received a DCN while waiting for a DIS */
253  T30_ERR_TX_INVALRSP, /*! Invalid response after sending a page */
254  T30_ERR_TX_NODIS, /*! Received other than DIS while waiting for DIS */
255  T30_ERR_TX_PHBDEAD, /*! Received no response to DCS, training or TCF */
256  T30_ERR_TX_PHDDEAD, /*! No response after sending a page */
257  T30_ERR_TX_T5EXP, /*! Timed out waiting for receiver ready (ECM mode) */
258 
259  /* Phase E status values returned to a receiver */
260  T30_ERR_RX_ECMPHD, /*! Invalid ECM response received from transmitter */
261  T30_ERR_RX_GOTDCS, /*! DCS received while waiting for DTC */
262  T30_ERR_RX_INVALCMD, /*! Unexpected command after page received */
263  T30_ERR_RX_NOCARRIER, /*! Carrier lost during fax receive */
264  T30_ERR_RX_NOEOL, /*! Timed out while waiting for EOL (end of line) */
265  T30_ERR_RX_NOFAX, /*! Timed out while waiting for first line */
266  T30_ERR_RX_T2EXPDCN, /*! Timer T2 expired while waiting for DCN */
267  T30_ERR_RX_T2EXPD, /*! Timer T2 expired while waiting for phase D */
268  T30_ERR_RX_T2EXPFAX, /*! Timer T2 expired while waiting for fax page */
269  T30_ERR_RX_T2EXPMPS, /*! Timer T2 expired while waiting for next fax page */
270  T30_ERR_RX_T2EXPRR, /*! Timer T2 expired while waiting for RR command */
271  T30_ERR_RX_T2EXP, /*! Timer T2 expired while waiting for NSS, DCS or MCF */
272  T30_ERR_RX_DCNWHY, /*! Unexpected DCN while waiting for DCS or DIS */
273  T30_ERR_RX_DCNDATA, /*! Unexpected DCN while waiting for image data */
274  T30_ERR_RX_DCNFAX, /*! Unexpected DCN while waiting for EOM, EOP or MPS */
275  T30_ERR_RX_DCNPHD, /*! Unexpected DCN after EOM or MPS sequence */
276  T30_ERR_RX_DCNRRD, /*! Unexpected DCN after RR/RNR sequence */
277  T30_ERR_RX_DCNNORTN, /*! Unexpected DCN after requested retransmission */
278 
279  /* TIFF file problems */
280  T30_ERR_FILEERROR, /*! TIFF/F file cannot be opened */
281  T30_ERR_NOPAGE, /*! TIFF/F page not found */
282  T30_ERR_BADTIFF, /*! TIFF/F format is not compatible */
283  T30_ERR_BADPAGE, /*! TIFF/F page number tag missing */
284  T30_ERR_BADTAG, /*! Incorrect values for TIFF/F tags */
285  T30_ERR_BADTIFFHDR, /*! Bad TIFF/F header - incorrect values in fields */
286  T30_ERR_NOMEM, /*! Cannot allocate memory for more pages */
287 
288  /* General problems */
289  T30_ERR_RETRYDCN, /*! Disconnected after permitted retries */
290  T30_ERR_CALLDROPPED, /*! The call dropped prematurely */
291 
292  /* Feature negotiation issues */
293  T30_ERR_NOPOLL, /*! Poll not accepted */
294  T30_ERR_IDENT_UNACCEPTABLE, /*! Far end's ident is not acceptable */
295  T30_ERR_SUB_UNACCEPTABLE, /*! Far end's sub-address is not acceptable */
296  T30_ERR_SEP_UNACCEPTABLE, /*! Far end's selective polling address is not acceptable */
297  T30_ERR_PSA_UNACCEPTABLE, /*! Far end's polled sub-address is not acceptable */
298  T30_ERR_SID_UNACCEPTABLE, /*! Far end's sender identification is not acceptable */
299  T30_ERR_PWD_UNACCEPTABLE, /*! Far end's password is not acceptable */
300  T30_ERR_TSA_UNACCEPTABLE, /*! Far end's transmitting subscriber internet address is not acceptable */
301  T30_ERR_IRA_UNACCEPTABLE, /*! Far end's internet routing address is not acceptable */
302  T30_ERR_CIA_UNACCEPTABLE, /*! Far end's calling subscriber internet address is not acceptable */
303  T30_ERR_ISP_UNACCEPTABLE, /*! Far end's internet selective polling address is not acceptable */
304  T30_ERR_CSA_UNACCEPTABLE /*! Far end's called subscriber internet address is not acceptable */
305 };
306 
307 /*!
308  I/O modes for the T.30 protocol.
309  These are allocated such that the lower 4 bits represents the variant of the modem - e.g. the
310  particular bit rate selected.
311 */
312 enum
313 {
314  T30_MODEM_NONE = 0,
315  T30_MODEM_PAUSE,
316  T30_MODEM_CED,
317  T30_MODEM_CNG,
318  T30_MODEM_V21,
319  T30_MODEM_V27TER,
320  T30_MODEM_V29,
321  T30_MODEM_V17,
322  T30_MODEM_V34HDX,
323  T30_MODEM_DONE
324 };
325 
326 enum
327 {
328  T30_FRONT_END_SEND_STEP_COMPLETE = 0,
329  /*! The current receive has completed. This is only needed to report an
330  unexpected end of the receive operation, as might happen with T.38
331  dying. */
333  T30_FRONT_END_SIGNAL_PRESENT,
334  T30_FRONT_END_SIGNAL_ABSENT,
335  T30_FRONT_END_CED_PRESENT,
336  T30_FRONT_END_CNG_PRESENT
337 };
338 
339 enum
340 {
341  /*! Support the V.27ter modem (2400, and 4800bps) for image transfer. */
343  /*! Support the V.29 modem (9600, and 7200bps) for image transfer. */
345  /*! Support the V.17 modem (14400, 12000, 9600 and 7200bps) for image transfer. */
347  /*! Support the V.34 modem (up to 33,600bps) for image transfer. */
349  /*! Support the Internet aware FAX mode (no bit rate limit) for image transfer. */
351 };
352 
353 enum
354 {
355  /*! No compression */
357  /*! T.1 1D compression */
359  /*! T.4 2D compression */
361  /*! T.6 2D compression */
363  /*! T.85 monochrome JBIG compression, with fixed L0 */
365  /*! T.85 monochrome JBIG compression, with variable L0 */
367  /*! T.43 colour JBIG compression */
369  /*! T.45 run length colour compression */
371  /*! T.81 + T.30 Annex E colour JPEG compression */
373  /*! T.81 + T.30 Annex K colour sYCC-JPEG compression */
375  /*! T.88 monochrome JBIG2 compression */
377 };
378 
379 enum
380 {
381  /*! Support standard FAX Y-resolution 98/100dpi */
383  /*! Support fine FAX Y-resolution 196/200dpi */
385  /*! Support super-fine FAX Y-resolution 392/400dpi */
387 
388  /*! Support half FAX X-resolution 100/102dpi */
390  /*! Support standard FAX X-resolution 200/204dpi */
392  /*! Support double FAX X-resolution 400dpi */
394 
395  /*! Support 300dpi x 300 dpi */
397  /*! Support 400dpi x 400 dpi */
399  /*! Support 600dpi x 600 dpi */
401  /*! Support 1200dpi x 1200 dpi */
403  /*! Support 300dpi x 600 dpi */
405  /*! Support 400dpi x 800 dpi */
407  /*! Support 600dpi x 1200 dpi */
409 };
410 
411 enum
412 {
413  T30_SUPPORT_215MM_WIDTH = 0x01,
414  T30_SUPPORT_255MM_WIDTH = 0x02,
415  T30_SUPPORT_303MM_WIDTH = 0x04,
416 
417  T30_SUPPORT_UNLIMITED_LENGTH = 0x10000,
418  T30_SUPPORT_A4_LENGTH = 0x20000,
419  T30_SUPPORT_B4_LENGTH = 0x40000,
420  T30_SUPPORT_US_LETTER_LENGTH = 0x80000,
421  T30_SUPPORT_US_LEGAL_LENGTH = 0x100000
422 };
423 
424 enum
425 {
426  /*! Enable support of identification, through the SID and/or PWD frames. */
428  /*! Enable support of selective polling, through the SEP frame. */
430  /*! Enable support of polling sub-addressing, through the PSA frame. */
432  /*! Enable support of multiple selective polling, through repeated used of the SEP and PSA frames. */
434  /*! Enable support of sub-addressing, through the SUB frame. */
436  /*! Enable support of transmitting subscriber internet address, through the TSA frame. */
438  /*! Enable support of internet routing address, through the IRA frame. */
440  /*! Enable support of calling subscriber internet address, through the CIA frame. */
442  /*! Enable support of internet selective polling address, through the ISP frame. */
444  /*! Enable support of called subscriber internet address, through the CSA frame. */
446  /*! Enable support of the field not valid (FNV) frame. */
448  /*! Enable support of the command repeat (CRP) frame. */
450 };
451 
452 enum
453 {
454  T30_IAF_MODE_T37 = 0x01,
455  T30_IAF_MODE_T38 = 0x02,
456  T30_IAF_MODE_FLOW_CONTROL = 0x04,
457  /*! Continuous flow mode means data is sent as fast as possible, usually across
458  the Internet, where speed is not constrained by a PSTN modem. */
460  /*! No TCF means TCF is not exchanged. The end points must sort out usable speed
461  issues locally. */
463  /*! No fill bits means do not insert fill bits, even if the T.30 messages request
464  them. */
466  /*! No indicators means do not send indicator messages when using T.38. */
468  /*! Use relaxed timers for T.38. This is appropriate when using TCP/TPKT for T.38,
469  as there is no point in anything but a long backstop timeout in such a mode. */
471 };
472 
473 typedef struct
474 {
475  /*! \brief The identifier string (CSI, TSI, CIG). */
476  char ident[T30_MAX_IDENT_LEN + 1];
477  /*! \brief The sub-address string (SUB). */
478  char sub_address[T30_MAX_IDENT_LEN + 1];
479  /*! \brief The selective polling sub-address (SEP). */
480  char selective_polling_address[T30_MAX_IDENT_LEN + 1];
481  /*! \brief The polled sub-address (PSA). */
482  char polled_sub_address[T30_MAX_IDENT_LEN + 1];
483  /*! \brief The sender identification (SID). */
484  char sender_ident[T30_MAX_IDENT_LEN + 1];
485  /*! \brief The password (PWD). */
486  char password[T30_MAX_IDENT_LEN + 1];
487  /*! \brief Non-standard facilities (NSF). */
488  uint8_t *nsf;
489  size_t nsf_len;
490  /*! \brief Non-standard facilities command (NSC). */
491  uint8_t *nsc;
492  size_t nsc_len;
493  /*! \brief Non-standard facilities set-up (NSS). */
494  uint8_t *nss;
495  size_t nss_len;
496  /*! \brief Transmitting subscriber internet address (TSA). */
497  int tsa_type;
498  char *tsa;
499  size_t tsa_len;
500  /*! \brief Internet routing address (IRA). */
501  int ira_type;
502  char *ira;
503  size_t ira_len;
504  /*! \brief Calling subscriber internet address (CIA). */
505  int cia_type;
506  char *cia;
507  size_t cia_len;
508  /*! \brief Internet selective polling address (ISP). */
509  int isp_type;
510  char *isp;
511  size_t isp_len;
512  /*! \brief Called subscriber internet address (CSA). */
513  int csa_type;
514  char *csa;
515  size_t csa_len;
517 
518 typedef struct
519 {
520  /*! \brief The current bit rate for image transfer. */
521  int bit_rate;
522  /*! \brief TRUE if error correcting mode is used. */
524  /*! \brief The number of pages sent so far. */
525  int pages_tx;
526  /*! \brief The number of pages received so far. */
527  int pages_rx;
528  /*! \brief The number of pages in the file (<0 if not known). */
530  /*! \brief The horizontal column-to-column resolution of the most recent page, in pixels per metre */
532  /*! \brief The vertical row-to-row resolution of the most recent page, in pixels per metre */
534  /*! \brief The number of horizontal pixels in the most recent page. */
535  int width;
536  /*! \brief The number of vertical pixels in the most recent page. */
537  int length;
538  /*! \brief The size of the image, in bytes */
540  /*! \brief The type of compression used between the FAX machines */
541  int encoding;
542  /*! \brief The number of bad pixel rows in the most recent page. */
543  int bad_rows;
544  /*! \brief The largest number of bad pixel rows in a block in the most recent page. */
546  /*! \brief The number of HDLC frame retries, if error correcting mode is used. */
548  /*! \brief Current status. */
550 #if 0
551  /*! \brief The number of RTP events in this call. */
552  int rtp_events;
553  /*! \brief The number of RTN events in this call. */
554  int rtn_events;
555 #endif
556 } t30_stats_t;
557 
558 #if defined(__cplusplus)
559 extern "C"
560 {
561 #endif
562 
563 /*! Initialise a T.30 context.
564  \brief Initialise a T.30 context.
565  \param s The T.30 context.
566  \param calling_party TRUE if the context is for a calling party. FALSE if the
567  context is for an answering party.
568  \param set_rx_type_handler
569  \param set_rx_type_user_data
570  \param set_tx_type_handler
571  \param set_tx_type_user_data
572  \param send_hdlc_handler
573  \param send_hdlc_user_data
574  \return A pointer to the context, or NULL if there was a problem. */
575 SPAN_DECLARE(t30_state_t *) t30_init(t30_state_t *s,
576  int calling_party,
578  void *set_rx_type_user_data,
580  void *set_tx_type_user_data,
582  void *send_hdlc_user_data);
583 
584 /*! Release a T.30 context.
585  \brief Release a T.30 context.
586  \param s The T.30 context.
587  \return 0 for OK, else -1. */
588 SPAN_DECLARE(int) t30_release(t30_state_t *s);
589 
590 /*! Free a T.30 context.
591  \brief Free a T.30 context.
592  \param s The T.30 context.
593  \return 0 for OK, else -1. */
594 SPAN_DECLARE(int) t30_free(t30_state_t *s);
595 
596 /*! Restart a T.30 context.
597  \brief Restart a T.30 context.
598  \param s The T.30 context.
599  \return 0 for OK, else -1. */
600 SPAN_DECLARE(int) t30_restart(t30_state_t *s);
601 
602 /*! Check if a T.30 call is still active. This may be used to regularly poll
603  if the job has finished.
604  \brief Check if a T.30 call is still active.
605  \param s The T.30 context.
606  \return TRUE for call still active, or FALSE for call completed. */
607 SPAN_DECLARE(int) t30_call_active(t30_state_t *s);
608 
609 /*! Cleanup a T.30 context if the call terminates.
610  \brief Cleanup a T.30 context if the call terminates.
611  \param s The T.30 context. */
612 SPAN_DECLARE(void) t30_terminate(t30_state_t *s);
613 
614 /*! Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.).
615  \brief Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.).
616  \param user_data The T.30 context.
617  \param status The type of status change which occured. */
618 SPAN_DECLARE(void) t30_front_end_status(void *user_data, int status);
619 
620 /*! Get a bit of received non-ECM image data.
621  \brief Get a bit of received non-ECM image data.
622  \param user_data An opaque pointer, which must point to the T.30 context.
623  \return The next bit to transmit. */
624 SPAN_DECLARE_NONSTD(int) t30_non_ecm_get_bit(void *user_data);
625 
626 /*! Get a byte of received non-ECM image data.
627  \brief Get a byte of received non-ECM image data.
628  \param user_data An opaque pointer, which must point to the T.30 context.
629  \return The next byte to transmit. */
630 SPAN_DECLARE(int) t30_non_ecm_get_byte(void *user_data);
631 
632 /*! Get a chunk of received non-ECM image data.
633  \brief Get a bit of received non-ECM image data.
634  \param user_data An opaque pointer, which must point to the T.30 context.
635  \param buf The buffer to contain the data.
636  \param max_len The maximum length of the chunk.
637  \return The actual length of the chunk. */
638 SPAN_DECLARE(int) t30_non_ecm_get_chunk(void *user_data, uint8_t buf[], int max_len);
639 
640 /*! Process a bit of received non-ECM image data.
641  \brief Process a bit of received non-ECM image data
642  \param user_data An opaque pointer, which must point to the T.30 context.
643  \param bit The received bit. */
644 SPAN_DECLARE_NONSTD(void) t30_non_ecm_put_bit(void *user_data, int bit);
645 
646 /*! Process a byte of received non-ECM image data.
647  \brief Process a byte of received non-ECM image data
648  \param user_data An opaque pointer, which must point to the T.30 context.
649  \param byte The received byte. */
650 SPAN_DECLARE(void) t30_non_ecm_put_byte(void *user_data, int byte);
651 
652 /*! Process a chunk of received non-ECM image data.
653  \brief Process a chunk of received non-ECM image data
654  \param user_data An opaque pointer, which must point to the T.30 context.
655  \param buf The buffer containing the received data.
656  \param len The length of the data in buf. */
657 SPAN_DECLARE(void) t30_non_ecm_put_chunk(void *user_data, const uint8_t buf[], int len);
658 
659 /*! Process a received HDLC frame.
660  \brief Process a received HDLC frame.
661  \param user_data The T.30 context.
662  \param msg The HDLC message.
663  \param len The length of the message, in octets.
664  \param ok TRUE if the frame was received without error. */
665 SPAN_DECLARE_NONSTD(void) t30_hdlc_accept(void *user_data, const uint8_t msg[], int len, int ok);
666 
667 /*! Report the passage of time to the T.30 engine.
668  \brief Report the passage of time to the T.30 engine.
669  \param s The T.30 context.
670  \param samples The time change in 1/8000th second steps. */
671 SPAN_DECLARE(void) t30_timer_update(t30_state_t *s, int samples);
672 
673 /*! Get the current transfer statistics for the file being sent or received.
674  \brief Get the current transfer statistics.
675  \param s The T.30 context.
676  \param t A pointer to a buffer for the statistics. */
677 SPAN_DECLARE(void) t30_get_transfer_statistics(t30_state_t *s, t30_stats_t *t);
678 
679 /*! Request a local interrupt of FAX exchange.
680  \brief Request a local interrupt of FAX exchange.
681  \param s The T.30 context.
682  \param state TRUE to enable interrupt request, else FALSE. */
683 SPAN_DECLARE(void) t30_local_interrupt_request(t30_state_t *s, int state);
684 
685 /*! Allow remote interrupts of FAX exchange.
686  \brief Allow remote interrupts of FAX exchange.
687  \param s The T.30 context.
688  \param state TRUE to allow interruptd, else FALSE. */
689 SPAN_DECLARE(void) t30_remote_interrupts_allowed(t30_state_t *s, int state);
690 
691 #if defined(__cplusplus)
692 }
693 #endif
694 
695 #endif
696 /*- End of file ------------------------------------------------------------*/
Definition: t30.h:253
Definition: t30.h:252
Definition: t30.h:245
Definition: t30.h:274
Definition: t30.h:277
Definition: t30.h:366
Definition: t30.h:250
Definition: t30.h:459
Definition: t30.h:270
Definition: t30.h:348
int pages_rx
The number of pages received so far.
Definition: t30.h:527
Definition: t30.h:243
Definition: t30.h:293
Definition: t30.h:271
Definition: t30.h:470
Definition: t30.h:447
void() t30_real_time_frame_handler_t(t30_state_t *s, void *user_data, int direction, const uint8_t msg[], int len)
T.30 real time frame handler.
Definition: t30.h:191
#define T30_MAX_IDENT_LEN
Definition: t30.h:144
int t30_non_ecm_get_chunk(void *user_data, uint8_t buf[], int max_len)
Get a bit of received non-ECM image data.
Definition: t30.c:5608
Definition: t30.h:429
void * send_hdlc_user_data
An opaque pointer passed to the transmitted HDLC frame handler.
Definition: private/t30.h:134
int() t30_document_handler_t(t30_state_t *s, void *user_data, int status)
T.30 document handler.
Definition: t30.h:204
int cia_type
Calling subscriber internet address (CIA).
Definition: t30.h:505
Definition: t30.h:364
Definition: t30.h:249
int image_size
The size of the image, in bytes.
Definition: t30.h:539
int calling_party
True if behaving as the calling party.
Definition: private/t30.h:47
Definition: t30.h:376
int tsa_type
Transmitting subscriber internet address (TSA).
Definition: t30.h:497
Definition: private/t30.h:35
int bit_rate
The current bit rate for image transfer.
Definition: t30.h:521
Definition: t30.h:284
uint8_t * nsc
Non-standard facilities command (NSC).
Definition: t30.h:491
Definition: t30.h:368
int x_resolution
The horizontal column-to-column resolution of the most recent page, in pixels per metre...
Definition: t30.h:531
SPAN_DECLARE_NONSTD(int) t30_non_ecm_get_bit(void *user_data)
Get a bit of received non-ECM image data.
Definition: t30.h:406
Definition: t30.h:286
int rtp_events
The number of RTP events.
Definition: private/t30.h:301
Definition: t30.h:400
int csa_type
Called subscriber internet address (CSA).
Definition: t30.h:513
int encoding
The type of compression used between the FAX machines.
Definition: t30.h:541
Definition: t30.h:360
t30_state_t * t30_init(t30_state_t *s, int calling_party, t30_set_handler_t *set_rx_type_handler, void *set_rx_type_user_data, t30_set_handler_t *set_tx_type_handler, void *set_tx_type_user_data, t30_send_hdlc_handler_t *send_hdlc_handler, void *send_hdlc_user_data)
Initialise a T.30 context.
Definition: t30.c:6327
Definition: t30.h:240
int isp_type
Internet selective polling address (ISP).
Definition: t30.h:509
void t30_front_end_status(void *user_data, int status)
Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.).
Definition: t30.c:5833
Definition: t30.h:269
Definition: t30.h:235
Definition: t30.h:465
int short_train
True if the short training sequence should be used.
Definition: private/t30.h:166
Definition: t30.h:251
void t30_non_ecm_put_chunk(void *user_data, const uint8_t buf[], int len)
Process a chunk of received non-ECM image data.
Definition: t30.c:5498
int() t30_phase_b_handler_t(t30_state_t *s, void *user_data, int result)
T.30 phase B callback handler.
Definition: t30.h:161
Definition: t30.h:241
Definition: t30.h:391
int t30_non_ecm_get_byte(void *user_data)
Get a byte of received non-ECM image data.
Definition: t30.c:5573
void() t30_phase_e_handler_t(t30_state_t *s, void *user_data, int completion_code)
T.30 phase E callback handler.
Definition: t30.h:180
int t30_restart(t30_state_t *s)
Restart a T.30 context.
Definition: t30.c:6287
int ira_type
Internet routing address (IRA).
Definition: t30.h:501
t30_set_handler_t * set_tx_type_handler
The handler for changes to the transmit mode.
Definition: private/t30.h:127
Definition: t30.h:237
Definition: t30.h:289
Definition: t30.h:467
int() t30_phase_d_handler_t(t30_state_t *s, void *user_data, int result)
T.30 phase D callback handler.
Definition: t30.h:171
Definition: t30.h:393
Definition: t30.h:282
Definition: t30.h:267
void t30_timer_update(t30_state_t *s, int samples)
Report the passage of time to the T.30 engine.
Definition: t30.c:6127
int rtn_events
The number of RTN events.
Definition: private/t30.h:303
Definition: t30.h:263
Definition: t30.h:301
int t30_call_active(t30_state_t *s)
Check if a T.30 call is still active.
Definition: t30.c:6385
Definition: t30.h:246
Definition: t30.h:298
Definition: t30.h:273
int t30_release(t30_state_t *s)
Release a T.30 context.
Definition: t30.c:6368
int longest_bad_row_run
The largest number of bad pixel rows in a block in the most recent page.
Definition: t30.h:545
Definition: t30.h:264
Definition: t30.h:350
Definition: t30.h:266
Definition: t30.h:303
Definition: t30.h:344
Definition: t30.h:256
void * set_rx_type_user_data
An opaque pointer passed to the handler for changes to the receive mode.
Definition: private/t30.h:125
Definition: t30.h:242
Definition: t30.h:408
Definition: t30.h:396
Definition: t30.h:275
uint8_t * nsf
Non-standard facilities (NSF).
Definition: t30.h:488
Definition: t30.h:276
Definition: t30.h:462
Definition: t30.h:300
int current_status
Current status.
Definition: t30.h:549
Definition: t30.h:398
Definition: t30.h:299
Definition: t30.h:295
Definition: t30.h:449
void t30_remote_interrupts_allowed(t30_state_t *s, int state)
Allow remote interrupts of FAX exchange.
Definition: t30.c:6281
Definition: t30.h:238
Definition: t30.h:290
Definition: t30.h:285
Definition: t30.h:262
int pages_in_file
The number of pages in the file (<0 if not known).
Definition: t30.h:529
Definition: t30.h:372
Definition: t30.h:297
Definition: t30.h:280
void * set_tx_type_user_data
An opaque pointer passed to the handler for changes to the transmit mode.
Definition: private/t30.h:129
Definition: t30.h:356
Definition: t30.h:239
Definition: t30.h:236
void t30_non_ecm_put_byte(void *user_data, int byte)
Process a byte of received non-ECM image data.
Definition: t30.c:5457
void t30_get_transfer_statistics(t30_state_t *s, t30_stats_t *t)
Get the current transfer statistics.
Definition: t30.c:6229
Definition: t30.h:272
Definition: t30.h:382
void t30_local_interrupt_request(t30_state_t *s, int state)
Request a local interrupt of FAX exchange.
Definition: t30.c:6269
Definition: t30.h:346
int t30_free(t30_state_t *s)
Free a T.30 context.
Definition: t30.c:6377
Definition: t30.h:294
Definition: t30.h:404
Definition: t30.h:358
Definition: t30.h:255
Definition: t30.h:257
Definition: t30.h:427
Definition: t30.h:370
Definition: t30.h:244
Definition: t30.h:254
Definition: t30.h:342
Definition: t30.h:302
t30_send_hdlc_handler_t * send_hdlc_handler
The transmitted HDLC frame handler.
Definition: private/t30.h:132
Definition: t30.h:265
t30_set_handler_t * set_rx_type_handler
The handler for changes to the receive mode.
Definition: private/t30.h:123
Definition: t30.h:362
void() t30_send_hdlc_handler_t(void *user_data, const uint8_t msg[], int len)
T.30 send HDLC handler.
Definition: t30.h:224
int length
The number of vertical pixels in the most recent page.
Definition: t30.h:537
void t30_terminate(t30_state_t *s)
Cleanup a T.30 context if the call terminates.
Definition: t30.c:6196
Definition: t30.h:281
Definition: t30.h:384
Definition: t30.h:296
Definition: t30.h:234
Definition: t30.h:283
int error_correcting_mode
TRUE if error correcting mode is used.
Definition: t30.h:523
Definition: t30.h:261
int error_correcting_mode_retries
The number of HDLC frame retries, if error correcting mode is used.
Definition: t30.h:547
Definition: t30.h:260
void() t30_set_handler_t(void *user_data, int type, int bit_rate, int short_train, int use_hdlc)
T.30 set a receive or transmit type handler.
Definition: t30.h:215
int width
The number of horizontal pixels in the most recent page.
Definition: t30.h:535
Definition: t30.h:389
Definition: t30.h:268
int y_resolution
The vertical row-to-row resolution of the most recent page, in pixels per metre.
Definition: t30.h:533
Definition: t30.h:304
Definition: t30.h:435
Definition: t30.h:473
uint8_t * nss
Non-standard facilities set-up (NSS).
Definition: t30.h:494
Definition: t30.h:332
Definition: t30.h:518
int state
The current state of the T.30 state machine.
Definition: private/t30.h:146
int bad_rows
The number of bad pixel rows in the most recent page.
Definition: t30.h:543
int pages_tx
The number of pages sent so far.
Definition: t30.h:525