t31.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * 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 General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00025  *
00026  * $Id: t31.h,v 1.22 2005/11/24 13:04:52 steveu Exp $
00027  */
00028 
00029 /*! \file */
00030 
00031 #if !defined(_T31_H_)
00032 #define _T31_H_
00033 
00034 /*! \page t31_page T.31 Class 1 FAX modem protocol handling
00035 \section t31_page_sec_1 What does it do?
00036 The T.31 class 1 FAX modem modules implements a class 1 interface to the FAX
00037 modems in spandsp.
00038 
00039 \section t31_page_sec_2 How does it work?
00040 */
00041 
00042 typedef struct t31_state_s t31_state_t;
00043 
00044 typedef int (t31_modem_control_handler_t)(t31_state_t *s, void *user_data, int op, const char *num);
00045 typedef int (t31_at_tx_handler_t)(t31_state_t *s, void *user_data, const uint8_t *buf, int len);
00046 
00047 enum t31_rx_mode_e
00048 {
00049     AT_MODE_ONHOOK_COMMAND,
00050     AT_MODE_OFFHOOK_COMMAND,
00051     AT_MODE_CONNECTED,
00052     AT_MODE_DELIVERY,
00053     AT_MODE_HDLC,
00054     AT_MODE_STUFFED
00055 };
00056 
00057 enum t31_call_event_e
00058 {
00059     T31_CALL_EVENT_ALERTING = 1,
00060     T31_CALL_EVENT_CONNECTED,
00061     T31_CALL_EVENT_ANSWERED,
00062     T31_CALL_EVENT_BUSY,
00063     T31_CALL_EVENT_NO_DIALTONE,
00064     T31_CALL_EVENT_NO_ANSWER,
00065     T31_CALL_EVENT_HANGUP
00066 };
00067 
00068 enum t31_modem_control_operation_e
00069 {
00070     T31_MODEM_CONTROL_CALL,
00071     T31_MODEM_CONTROL_ANSWER,
00072     T31_MODEM_CONTROL_HANGUP,
00073     T31_MODEM_CONTROL_DTR,
00074     T31_MODEM_CONTROL_RTS,
00075     T31_MODEM_CONTROL_CTS,
00076     T31_MODEM_CONTROL_CAR,
00077     T31_MODEM_CONTROL_RNG,
00078     T31_MODEM_CONTROL_DSR
00079 };
00080 
00081 #define T31_TX_BUF_LEN      (4096*32)
00082 
00083 /*!
00084     T.31 profile.
00085 */
00086 typedef struct
00087 {
00088     /*! TRUE if character echo is enabled */
00089     int echo;
00090     /*! TRUE if verbose reporting is enabled */
00091     int verbose;
00092     /*! TRUE if result codes are verbose */
00093     int result_code_format;
00094     /*! TRUE if pulse dialling is the default */
00095     int pulse_dial;
00096     /*! ??? */
00097     int double_escape;
00098     /*! ??? */
00099     int adaptive_receive;
00100     /*! The state of all possible S registers */
00101     uint8_t s_regs[100];
00102 } t31_profile_t;
00103 
00104 /*!
00105     T.31 descriptor. This defines the working state for a single instance of
00106     a T.31 FAX modem.
00107 */
00108 struct t31_state_s
00109 {
00110     int country_of_installation;
00111     char line[256];
00112     uint8_t hdlc_buf[256];
00113     int hdlc_len;
00114     /*! TRUE if DLE prefix just used */
00115     int dled;
00116     int line_ptr;
00117     int at_rx_mode;
00118     /*! This is no real DTE rate. This variable is for compatibility this serially
00119         connected modems. */
00120     int dte_rate;
00121     int dte_char_format;
00122     int dte_parity;
00123     /*! The currently select FAX modem class. 0 = data modem mode. */
00124     int fclass_mode;
00125     int display_callid;
00126     int callid_displayed;
00127     const char *call_date;
00128     const char *call_time;
00129     const char *originating_name;
00130     const char *originating_number;
00131     const char *originating_ani;
00132     const char *destination_number;
00133     t31_profile_t p;
00134     uint8_t rx_data[256];
00135     int rx_data_bytes;
00136     uint8_t tx_data[T31_TX_BUF_LEN];
00137     int tx_in_bytes;
00138     int tx_out_bytes;
00139     int tx_holding;
00140     int bit_no;
00141     int current_byte;
00142 
00143     /*! \brief The current bit rate for the fast message transfer modem. */
00144     int bit_rate;
00145     /*! \brief TRUE is a carrier is presnt. Otherwise FALSE. */
00146     int rx_signal_present;
00147     int rx_message_received;
00148 
00149     /*! \brief A tone generator context used to generate supervisory tones during
00150                FAX handling. */
00151     tone_gen_state_t tone_gen;
00152     /*! \brief An HDLC context used when receiving HDLC over V.21 messages. */
00153     hdlc_rx_state_t hdlcrx;
00154     /*! \brief An HDLC context used when transmitting HDLC over V.21 messages. */
00155     hdlc_tx_state_t hdlctx;
00156     /*! \brief A V.21 FSK modem context used when transmitting HDLC over V.21
00157                messages. */
00158     fsk_tx_state_t v21tx;
00159     /*! \brief A V.21 FSK modem context used when receiving HDLC over V.21
00160                messages. */
00161     fsk_rx_state_t v21rx;
00162 
00163 #if defined(ENABLE_V17)
00164     /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps
00165                12000bps or 14400bps*/
00166     v17_tx_state_t v17tx;
00167     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps
00168                12000bps or 14400bps*/
00169     v17_rx_state_t v17rx;
00170 #endif
00171 
00172     /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
00173                9600bps */
00174     v29_tx_state_t v29tx;
00175     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
00176                9600bps */
00177     v29_rx_state_t v29rx;
00178 
00179     /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or
00180                4800bps */
00181     v27ter_tx_state_t v27ter_tx;
00182     /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or
00183                4800bps */
00184     v27ter_rx_state_t v27ter_rx;
00185     /*! \brief Rx power meter, use to detect silence */
00186     power_meter_t rx_power;
00187     int32_t silence_threshold_power;
00188 
00189     /*! \brief A counter for audio samples when inserting timed silences according
00190                to the ITU specifications. */
00191     int silent_samples;
00192         /*! \brief Samples of silence heard */
00193     int silence_heard;
00194         /*! \brief Samples of silence awaited */
00195     int silence_awaited;
00196     /*! \brief Samples elapsed in the current call */
00197     int64_t call_samples;
00198     int64_t last_dtedata_samples;
00199     int dohangup;
00200     int modem;
00201     int transmit;
00202     int short_train;
00203     int dte_is_waiting;
00204     int carrier_loss_timeout;
00205     int dte_inactivity_timeout;
00206     int dte_inactivity_action;
00207     int hdlc_final;
00208     int data_final;
00209     queue_t rx_queue;
00210 
00211     t31_modem_control_handler_t *modem_control_handler;
00212     void *modem_control_user_data;
00213     t31_at_tx_handler_t *at_tx_handler;
00214     void *at_tx_user_data;
00215 
00216     /*! \brief Error and flow logging control */
00217     logging_state_t logging;
00218 };
00219 
00220 #ifdef __cplusplus
00221 extern "C" {
00222 #endif
00223 
00224 void t31_call_event(t31_state_t *s, int event);
00225 
00226 int t31_at_rx(t31_state_t *s, const char *t, int len);
00227 
00228 /*! Process a block of received T.31 modem audio samples.
00229     \brief Process a block of received T.31 modem audio samples.
00230     \param s The T.31 modem context.
00231     \param amp The audio sample buffer.
00232     \param len The number of samples in the buffer.
00233     \return The number of samples unprocessed. */
00234 int t31_rx(t31_state_t *s, int16_t *buf, int len);
00235 
00236 /*! Generate a block of T.31 modem audio samples.
00237     \brief Generate a block of T.31 modem audio samples.
00238     \param s The T.31 modem context.
00239     \param amp The audio sample buffer.
00240     \param max_len The number of samples to be generated.
00241     \return The number of samples actually generated.
00242 */
00243 int t31_tx(t31_state_t *s, int16_t *buf, int max_len);
00244 
00245 /*! Initialise a T.31 context. This must be called before the first
00246     use of the context, to initialise its contents.
00247     \brief Initialise a T.31 context.
00248     \param s The T.31 context.
00249     \param at_tx_handler ???.
00250     \param at_tx_user_data ???.
00251     \param modem_control_handler ???.
00252     \param modem_control_user_data ???.
00253     \return ???. */
00254 int t31_init(t31_state_t *s,
00255              t31_at_tx_handler_t *at_tx_handler,
00256              void *at_tx_user_data,
00257              t31_modem_control_handler_t *modem_control_handler,
00258              void *modem_control_user_data);
00259 
00260 #ifdef __cplusplus
00261 }
00262 #endif
00263 
00264 #endif
00265 /*- End of file ------------------------------------------------------------*/

Generated on Fri Nov 10 09:40:24 2006 for libspandsp by  doxygen 1.5.1