5
|
1 /*
|
|
2 * SpanDSP - a series of DSP components for telephony
|
|
3 *
|
|
4 * v8.h - V.8 modem negotiation processing.
|
|
5 *
|
|
6 * Written by Steve Underwood <steveu@coppice.org>
|
|
7 *
|
|
8 * Copyright (C) 2004 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 General Public License version 2, as
|
|
14 * 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 General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
24 *
|
|
25 * $Id: v8.h,v 1.14 2006/11/22 13:46:06 steveu Exp $
|
|
26 */
|
|
27
|
|
28 /*! \file */
|
|
29
|
|
30 /*! \page v8_page The V.8 modem negotiation protocol
|
|
31 \section v8_page_sec_1 What does it do?
|
|
32 The V.8 specification defines a procedure to be used as PSTN modem answer phone calls,
|
|
33 which allows the modems to negotiate the optimum modem standard, which both ends can
|
|
34 support.
|
|
35
|
|
36 \section v8_page_sec_2 How does it work?
|
|
37 At startup the modems communicate using the V.21 standard at 300 bits/second. They
|
|
38 exchange simple messages about their capabilities, and choose the modem standard they
|
|
39 will use for data communication. The V.8 protocol then terminates, and the modems
|
|
40 being negotiating and training with their chosen modem standard.
|
|
41 */
|
|
42
|
|
43 #if !defined(_V8_H_)
|
|
44 #define _V8_H_
|
|
45
|
|
46 typedef struct v8_result_s v8_result_t;
|
|
47
|
|
48 typedef void (v8_result_handler_t)(void *user_data, v8_result_t *result);
|
|
49
|
|
50 enum v8_call_function_e
|
|
51 {
|
|
52 V8_CALL_TBS = 0,
|
|
53 V8_CALL_H324,
|
|
54 V8_CALL_V18,
|
|
55 V8_CALL_T101,
|
|
56 V8_CALL_T30_TX,
|
|
57 V8_CALL_T30_RX,
|
|
58 V8_CALL_V_SERIES,
|
|
59 V8_CALL_FUNCTION_EXTENSION
|
|
60 };
|
|
61
|
|
62 enum v8_modulation_e
|
|
63 {
|
|
64 V8_MOD_V17 = (1 << 0), /* V.17 half-duplex */
|
|
65 V8_MOD_V21 = (1 << 1), /* V.21 duplex */
|
|
66 V8_MOD_V22 = (1 << 2), /* V.22/V22.bis duplex */
|
|
67 V8_MOD_V23HALF = (1 << 3), /* V.23 half-duplex */
|
|
68 V8_MOD_V23 = (1 << 4), /* V.23 duplex */
|
|
69 V8_MOD_V26BIS = (1 << 5), /* V.23 duplex */
|
|
70 V8_MOD_V26TER = (1 << 6), /* V.23 duplex */
|
|
71 V8_MOD_V27TER = (1 << 7), /* V.23 duplex */
|
|
72 V8_MOD_V29 = (1 << 8), /* V.29 half-duplex */
|
|
73 V8_MOD_V32 = (1 << 9), /* V.32/V32.bis duplex */
|
|
74 V8_MOD_V34HALF = (1 << 10), /* V.34 half-duplex */
|
|
75 V8_MOD_V34 = (1 << 11), /* V.34 duplex */
|
|
76 V8_MOD_V90 = (1 << 12), /* V.90 duplex */
|
|
77 V8_MOD_V92 = (1 << 13), /* V.92 duplex */
|
|
78
|
|
79 V8_MOD_FAILED = (1 << 15), /* Indicates failure to negotiate */
|
|
80 };
|
|
81
|
|
82 enum v8_protocol_e
|
|
83 {
|
|
84 V8_PROTOCOL_NONE = 0,
|
|
85 V8_PROTOCOL_LAPM_V42 = 1,
|
|
86 V8_PROTOCOL_EXTENSION = 7
|
|
87 };
|
|
88
|
|
89 enum v8_pstn_access_e
|
|
90 {
|
|
91 V8_PSTN_ACCESS_CALL_DCE_CELLULAR = 0x20,
|
|
92 V8_PSTN_ACCESS_ANSWER_DCE_CELLULAR = 0x40,
|
|
93 V8_PSTN_ACCESS_DCE_ON_DIGTIAL = 0x80
|
|
94 };
|
|
95
|
|
96 enum v8_pcm_modem_availability_e
|
|
97 {
|
|
98 V8_PSTN_PCM_MODEM_V90_V92_ANALOGUE = 0x20,
|
|
99 V8_PSTN_PCM_MODEM_V90_V92_DIGITAL = 0x40,
|
|
100 V8_PSTN_PCM_MODEM_V91 = 0x80
|
|
101 };
|
|
102
|
|
103 typedef struct
|
|
104 {
|
|
105 /*! \brief TRUE if we are the calling modem */
|
|
106 int caller;
|
|
107 /*! \brief The current state of the V8 protocol */
|
|
108 int state;
|
|
109 int negotiation_timer;
|
|
110 int ci_timer;
|
|
111 int ci_count;
|
|
112 fsk_tx_state_t v21tx;
|
|
113 fsk_rx_state_t v21rx;
|
|
114 queue_t tx_queue;
|
|
115 modem_connect_tones_tx_state_t ec_dis_tx;
|
|
116 modem_connect_tones_rx_state_t ec_dis_rx;
|
|
117
|
|
118 v8_result_handler_t *result_handler;
|
|
119 void *result_handler_user_data;
|
|
120
|
|
121 /*! \brief Modulation schemes available at this end. */
|
|
122 int available_modulations;
|
|
123 int common_modulations;
|
|
124 int negotiated_modulation;
|
|
125 int far_end_modulations;
|
|
126
|
|
127 int call_function;
|
|
128 int protocol;
|
|
129 int pstn_access;
|
|
130 int nsf_seen;
|
|
131 int pcm_modem_availability;
|
|
132 int t66_seen;
|
|
133
|
|
134 /* V8 data parsing */
|
|
135 unsigned int bit_stream;
|
|
136 int bit_cnt;
|
|
137 /* Indicates the type of message coming up */
|
|
138 int preamble_type;
|
|
139 uint8_t rx_data[64];
|
|
140 int rx_data_ptr;
|
|
141
|
|
142 /*! \brief a reference copy of the last CM or JM message, used when
|
|
143 testing for matches. */
|
|
144 uint8_t cm_jm_data[64];
|
|
145 int cm_jm_count;
|
|
146 int got_cm_jm;
|
|
147 int got_cj;
|
|
148 int zero_byte_count;
|
|
149 /*! \brief Error and flow logging control */
|
|
150 logging_state_t logging;
|
|
151 } v8_state_t;
|
|
152
|
|
153 struct v8_result_s
|
|
154 {
|
|
155 int call_function;
|
|
156 int available_modulations;
|
|
157 int negotiated_modulation;
|
|
158 int protocol;
|
|
159 int pstn_access;
|
|
160 int nsf_seen;
|
|
161 int pcm_modem_availability;
|
|
162 int t66_seen;
|
|
163 };
|
|
164
|
|
165 #ifdef __cplusplus
|
|
166 extern "C" {
|
|
167 #endif
|
|
168
|
|
169 /*! Initialise a V.8 context.
|
|
170 \brief Initialise a V.8 context.
|
|
171 \param s The V.8 context.
|
|
172 \param caller TRUE if caller mode, else answerer mode.
|
|
173 \param available_modulations A bitwise list of the modulation schemes to be
|
|
174 advertised as available here.
|
|
175 \param result_handler The callback routine used to handle the results of negotiation.
|
|
176 \param user_data An opaque pointer passed to the result_handler routine.
|
|
177 \return A pointer to the V.8 context, or NULL if there was a problem. */
|
|
178 v8_state_t *v8_init(v8_state_t *s,
|
|
179 int caller,
|
|
180 int available_modulations,
|
|
181 v8_result_handler_t *result_handler,
|
|
182 void *user_data);
|
|
183
|
|
184 /*! Release a V.8 context.
|
|
185 \brief Release a V.8 context.
|
|
186 \param s The V.8 context.
|
|
187 \return 0 for OK. */
|
|
188 int v8_release(v8_state_t *s);
|
|
189
|
|
190 /*! Generate a block of V.8 audio samples.
|
|
191 \brief Generate a block of V.8 audio samples.
|
|
192 \param s The V.8 context.
|
|
193 \param amp The audio sample buffer.
|
|
194 \param max_len The number of samples to be generated.
|
|
195 \return The number of samples actually generated.
|
|
196 */
|
|
197 int v8_tx(v8_state_t *s, int16_t *amp, int max_len);
|
|
198
|
|
199 /*! Process a block of received V.8 audio samples.
|
|
200 \brief Process a block of received V.8 audio samples.
|
|
201 \param s The V.8 context.
|
|
202 \param amp The audio sample buffer.
|
|
203 \param len The number of samples in the buffer.
|
|
204 */
|
|
205 int v8_rx(v8_state_t *s, const int16_t *amp, int len);
|
|
206
|
|
207 /*! Log the list of supported modulations.
|
|
208 \brief Log the list of supported modulations.
|
|
209 \param s The V.8 context.
|
|
210 \param modulation_schemes The list of supported modulations. */
|
|
211 void v8_log_supported_modulations(v8_state_t *s, int modulation_schemes);
|
|
212
|
|
213 const char *v8_call_function_to_str(int call_function);
|
|
214 const char *v8_modulation_to_str(int modulation_scheme);
|
|
215 const char *v8_protocol_to_str(int protocol);
|
|
216 const char *v8_pstn_access_to_str(int pstn_access);
|
|
217 const char *v8_pcm_modem_availability_to_str(int pcm_modem_availability);
|
|
218
|
|
219 #ifdef __cplusplus
|
|
220 }
|
|
221 #endif
|
|
222
|
|
223 #endif
|
|
224 /*- End of file ------------------------------------------------------------*/
|