v8.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * v8.h - V.8 modem negotiation processing.
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: v8.h,v 1.23 2008/09/04 14:40:05 steveu Exp $
00026  */
00027  
00028 /*! \file */
00029 
00030 /*! \page v8_page The V.8 modem negotiation protocol
00031 \section v8_page_sec_1 What does it do?
00032 The V.8 specification defines a procedure to be used as PSTN modem answer phone calls,
00033 which allows the modems to negotiate the optimum modem standard, which both ends can
00034 support.
00035 
00036 \section v8_page_sec_2 How does it work?
00037 At startup the modems communicate using the V.21 standard at 300 bits/second. They
00038 exchange simple messages about their capabilities, and choose the modem standard they
00039 will use for data communication. The V.8 protocol then terminates, and the modems
00040 being negotiating and training with their chosen modem standard.
00041 */
00042 
00043 #if !defined(_SPANDSP_V8_H_)
00044 #define _SPANDSP_V8_H_
00045 
00046 typedef struct v8_result_s v8_result_t;
00047 
00048 typedef void (v8_result_handler_t)(void *user_data, v8_result_t *result);
00049 
00050 enum v8_call_function_e
00051 {
00052     V8_CALL_TBS = 0,
00053     V8_CALL_H324,
00054     V8_CALL_V18,
00055     V8_CALL_T101,
00056     V8_CALL_T30_TX,
00057     V8_CALL_T30_RX,
00058     V8_CALL_V_SERIES,
00059     V8_CALL_FUNCTION_EXTENSION
00060 };
00061 
00062 enum v8_modulation_e
00063 {
00064     V8_MOD_V17          = (1 << 0),     /* V.17 half-duplex */
00065     V8_MOD_V21          = (1 << 1),     /* V.21 duplex */
00066     V8_MOD_V22          = (1 << 2),     /* V.22/V22.bis duplex */
00067     V8_MOD_V23HALF      = (1 << 3),     /* V.23 half-duplex */
00068     V8_MOD_V23          = (1 << 4),     /* V.23 duplex */
00069     V8_MOD_V26BIS       = (1 << 5),     /* V.23 duplex */
00070     V8_MOD_V26TER       = (1 << 6),     /* V.23 duplex */
00071     V8_MOD_V27TER       = (1 << 7),     /* V.23 duplex */
00072     V8_MOD_V29          = (1 << 8),     /* V.29 half-duplex */
00073     V8_MOD_V32          = (1 << 9),     /* V.32/V32.bis duplex */
00074     V8_MOD_V34HALF      = (1 << 10),    /* V.34 half-duplex */
00075     V8_MOD_V34          = (1 << 11),    /* V.34 duplex */
00076     V8_MOD_V90          = (1 << 12),    /* V.90 duplex */
00077     V8_MOD_V92          = (1 << 13),    /* V.92 duplex */
00078 
00079     V8_MOD_FAILED       = (1 << 15)     /* Indicates failure to negotiate */
00080 };
00081 
00082 enum v8_protocol_e
00083 {
00084     V8_PROTOCOL_NONE = 0,
00085     V8_PROTOCOL_LAPM_V42 = 1,
00086     V8_PROTOCOL_EXTENSION = 7
00087 };
00088 
00089 enum v8_pstn_access_e
00090 {
00091     V8_PSTN_ACCESS_CALL_DCE_CELLULAR = 0x20,
00092     V8_PSTN_ACCESS_ANSWER_DCE_CELLULAR = 0x40,
00093     V8_PSTN_ACCESS_DCE_ON_DIGTIAL = 0x80
00094 };
00095 
00096 enum v8_pcm_modem_availability_e
00097 {
00098     V8_PSTN_PCM_MODEM_V90_V92_ANALOGUE = 0x20,
00099     V8_PSTN_PCM_MODEM_V90_V92_DIGITAL = 0x40,
00100     V8_PSTN_PCM_MODEM_V91 = 0x80
00101 };
00102 
00103 typedef struct
00104 {
00105     /*! \brief TRUE if we are the calling modem */
00106     int caller;
00107     /*! \brief The current state of the V8 protocol */
00108     int state;
00109     int negotiation_timer;
00110     int ci_timer;
00111     int ci_count;
00112     fsk_tx_state_t v21tx;
00113     fsk_rx_state_t v21rx;
00114     queue_state_t *tx_queue;
00115     modem_connect_tones_tx_state_t ansam_tx;
00116     modem_connect_tones_rx_state_t ansam_rx;
00117 
00118     v8_result_handler_t *result_handler;
00119     void *result_handler_user_data;
00120 
00121     /*! \brief Modulation schemes available at this end. */
00122     int available_modulations;
00123     int common_modulations;
00124     int negotiated_modulation;
00125     int far_end_modulations;
00126     
00127     int call_function;
00128     int protocol;
00129     int pstn_access;
00130     int nsf_seen;
00131     int pcm_modem_availability;
00132     int t66_seen;
00133 
00134     /* V8 data parsing */
00135     unsigned int bit_stream;
00136     int bit_cnt;
00137     /* Indicates the type of message coming up */
00138     int preamble_type;
00139     uint8_t rx_data[64];
00140     int rx_data_ptr;
00141     
00142     /*! \brief a reference copy of the last CM or JM message, used when
00143                testing for matches. */
00144     uint8_t cm_jm_data[64];
00145     int cm_jm_count;
00146     int got_cm_jm;
00147     int got_cj;
00148     int zero_byte_count;
00149     /*! \brief Error and flow logging control */
00150     logging_state_t logging;
00151 } v8_state_t;
00152 
00153 struct v8_result_s
00154 {
00155     int call_function;
00156     int available_modulations;
00157     int negotiated_modulation;
00158     int protocol;
00159     int pstn_access;
00160     int nsf_seen;
00161     int pcm_modem_availability;
00162     int t66_seen;
00163 };
00164 
00165 #if defined(__cplusplus)
00166 extern "C"
00167 {
00168 #endif
00169 
00170 /*! Initialise a V.8 context.
00171     \brief Initialise a V.8 context.
00172     \param s The V.8 context.
00173     \param caller TRUE if caller mode, else answerer mode.
00174     \param available_modulations A bitwise list of the modulation schemes to be
00175            advertised as available here.
00176     \param result_handler The callback routine used to handle the results of negotiation.
00177     \param user_data An opaque pointer passed to the result_handler routine.
00178     \return A pointer to the V.8 context, or NULL if there was a problem. */
00179 v8_state_t *v8_init(v8_state_t *s,
00180                     int caller,
00181                     int available_modulations,
00182                     v8_result_handler_t *result_handler,
00183                     void *user_data);
00184 
00185 /*! Release a V.8 context.
00186     \brief Release a V.8 context.
00187     \param s The V.8 context.
00188     \return 0 for OK. */
00189 int v8_release(v8_state_t *s);
00190 
00191 /*! Generate a block of V.8 audio samples.
00192     \brief Generate a block of V.8 audio samples.
00193     \param s The V.8 context.
00194     \param amp The audio sample buffer.
00195     \param max_len The number of samples to be generated.
00196     \return The number of samples actually generated.
00197 */
00198 int v8_tx(v8_state_t *s, int16_t *amp, int max_len);
00199 
00200 /*! Process a block of received V.8 audio samples.
00201     \brief Process a block of received V.8 audio samples.
00202     \param s The V.8 context.
00203     \param amp The audio sample buffer.
00204     \param len The number of samples in the buffer.
00205 */
00206 int v8_rx(v8_state_t *s, const int16_t *amp, int len);
00207 
00208 /*! Log the list of supported modulations.
00209     \brief Log the list of supported modulations.
00210     \param s The V.8 context.
00211     \param modulation_schemes The list of supported modulations. */
00212 void v8_log_supported_modulations(v8_state_t *s, int modulation_schemes);
00213 
00214 const char *v8_call_function_to_str(int call_function);
00215 const char *v8_modulation_to_str(int modulation_scheme);
00216 const char *v8_protocol_to_str(int protocol);
00217 const char *v8_pstn_access_to_str(int pstn_access);
00218 const char *v8_pcm_modem_availability_to_str(int pcm_modem_availability);
00219 
00220 #if defined(__cplusplus)
00221 }
00222 #endif
00223 
00224 #endif
00225 /*- End of file ------------------------------------------------------------*/

Generated on Tue Oct 7 20:25:50 2008 for spandsp by  doxygen 1.5.6