00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * private/t31.h - A T.31 compatible class 1 FAX modem interface. 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2004 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: t31.h,v 1.7 2009/02/12 12:38:39 steveu Exp $ 00026 */ 00027 00028 #if !defined(_SPANDSP_PRIVATE_T31_H_) 00029 #define _SPANDSP_PRIVATE_T31_H_ 00030 00031 /*! 00032 Analogue FAX front end channel descriptor. This defines the state of a single working 00033 instance of an analogue line FAX front end. 00034 */ 00035 typedef struct 00036 { 00037 fax_modems_state_t modems; 00038 00039 /*! The transmit signal handler to be used when the current one has finished sending. */ 00040 span_tx_handler_t *next_tx_handler; 00041 void *next_tx_user_data; 00042 00043 /*! \brief No of data bits in current_byte. */ 00044 int bit_no; 00045 /*! \brief The current data byte in progress. */ 00046 int current_byte; 00047 00048 /*! \brief Rx power meter, used to detect silence. */ 00049 power_meter_t rx_power; 00050 /*! \brief Last sample, used for an elementary HPF for the power meter. */ 00051 int16_t last_sample; 00052 /*! \brief The current silence threshold. */ 00053 int32_t silence_threshold_power; 00054 00055 /*! \brief Samples of silence heard */ 00056 int silence_heard; 00057 } t31_audio_front_end_state_t; 00058 00059 /*! 00060 Analogue FAX front end channel descriptor. This defines the state of a single working 00061 instance of an analogue line FAX front end. 00062 */ 00063 typedef struct 00064 { 00065 /*! \brief Internet Aware FAX mode bit mask. */ 00066 int iaf; 00067 /*! \brief Required time between T.38 transmissions, in ms. */ 00068 int ms_per_tx_chunk; 00069 /*! \brief Bit fields controlling the way data is packed into chunked for transmission. */ 00070 int chunking_modes; 00071 00072 /*! \brief Core T.38 IFP support */ 00073 t38_core_state_t t38; 00074 00075 /*! \brief The current transmit step being timed */ 00076 int timed_step; 00077 00078 /*! \brief TRUE is there has been some T.38 data missed */ 00079 int rx_data_missing; 00080 00081 /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current 00082 rate and the current specified packet interval. */ 00083 int octets_per_data_packet; 00084 00085 /*! \brief An HDLC context used when sending HDLC messages to the terminal port 00086 (ECM mode support). */ 00087 hdlc_tx_state_t hdlc_tx_term; 00088 /*! \brief An HDLC context used when receiving HDLC messages from the terminal port. 00089 (ECM mode support). */ 00090 hdlc_rx_state_t hdlc_rx_term; 00091 00092 struct 00093 { 00094 uint8_t buf[T31_T38_MAX_HDLC_LEN]; 00095 int len; 00096 } hdlc_rx; 00097 00098 struct 00099 { 00100 /*! \brief The number of extra bits in a fully stuffed version of the 00101 contents of the HDLC transmit buffer. This is needed to accurately 00102 estimate the playout time for this frame, through an analogue modem. */ 00103 int extra_bits; 00104 } hdlc_tx; 00105 00106 /*! \brief TRUE if we are using ECM mode. This is used to select HDLC faking, necessary 00107 with clunky class 1 modems. */ 00108 int ecm_mode; 00109 00110 /*! \brief Counter for trailing non-ECM bytes, used to flush out the far end's modem. */ 00111 int non_ecm_trailer_bytes; 00112 00113 /*! \brief The next queued tramsit indicator */ 00114 int next_tx_indicator; 00115 /*! \brief The current T.38 data type being transmitted */ 00116 int current_tx_data_type; 00117 00118 /*! \brief The current operating mode of the receiver. */ 00119 int current_rx_type; 00120 /*! \brief The current operating mode of the transmitter. */ 00121 int current_tx_type; 00122 00123 /*! \brief Current transmission bit rate. */ 00124 int tx_bit_rate; 00125 /*! \brief A "sample" count, used to time events. */ 00126 int32_t samples; 00127 /*! \brief The value for samples at the next transmission point. */ 00128 int32_t next_tx_samples; 00129 /*! \brief The current receive timeout. */ 00130 int32_t timeout_rx_samples; 00131 } t31_t38_front_end_state_t; 00132 00133 /*! 00134 T.31 descriptor. This defines the working state for a single instance of 00135 a T.31 FAX modem. 00136 */ 00137 struct t31_state_s 00138 { 00139 at_state_t at_state; 00140 t31_modem_control_handler_t *modem_control_handler; 00141 void *modem_control_user_data; 00142 00143 t31_audio_front_end_state_t audio; 00144 t31_t38_front_end_state_t t38_fe; 00145 /*! TRUE if working in T.38 mode. */ 00146 int t38_mode; 00147 00148 /*! HDLC buffer, for composing an HDLC frame from the computer to the channel. */ 00149 struct 00150 { 00151 uint8_t buf[T31_MAX_HDLC_LEN]; 00152 int len; 00153 int ptr; 00154 /*! \brief TRUE when the end of HDLC data from the computer has been detected. */ 00155 int final; 00156 } hdlc_tx; 00157 /*! Buffer for data from the computer to the channel. */ 00158 struct 00159 { 00160 uint8_t data[T31_TX_BUF_LEN]; 00161 /*! \brief The number of bytes stored in transmit buffer. */ 00162 int in_bytes; 00163 /*! \brief The number of bytes sent from the transmit buffer. */ 00164 int out_bytes; 00165 /*! \brief TRUE if the flow of real data has started. */ 00166 int data_started; 00167 /*! \brief TRUE if holding up further data into the buffer, for flow control. */ 00168 int holding; 00169 /*! \brief TRUE when the end of non-ECM data from the computer has been detected. */ 00170 int final; 00171 } tx; 00172 00173 /*! TRUE if DLE prefix just used */ 00174 int dled; 00175 00176 /*! \brief Samples of silence awaited, as specified in a "wait for silence" command */ 00177 int silence_awaited; 00178 00179 /*! \brief The current bit rate for the FAX fast message transfer modem. */ 00180 int bit_rate; 00181 /*! \brief TRUE if a valid HDLC frame has been received in the current reception period. */ 00182 int rx_frame_received; 00183 00184 /*! \brief Samples elapsed in the current call */ 00185 int64_t call_samples; 00186 int64_t dte_data_timeout; 00187 00188 /*! \brief The currently queued modem type. */ 00189 int modem; 00190 /*! \brief TRUE when short training mode has been selected by the computer. */ 00191 int short_train; 00192 queue_state_t *rx_queue; 00193 00194 /*! \brief Error and flow logging control */ 00195 logging_state_t logging; 00196 }; 00197 00198 #endif 00199 /*- End of file ------------------------------------------------------------*/