comparison spandsp-0.0.3/spandsp-0.0.3/src/spandsp/v42.h @ 5:f762bf195c4b

import spandsp-0.0.3
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 16:00:21 +0200
parents
children
comparison
equal deleted inserted replaced
4:26cd8f1ef0b1 5:f762bf195c4b
1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * v42.h
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 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: v42.h,v 1.17 2006/10/24 13:22:02 steveu Exp $
26 */
27
28 /*! \page v42_page V.42 modem error correction
29 \section v42_page_sec_1 What does it do?
30 The V.42 specification defines an error correcting protocol for PSTN modems, based on
31 HDLC and LAP. This makes it similar to an X.25 link. A special variant of LAP, known
32 as LAP-M, is defined in the V.42 specification. A means for modems to determine if the
33 far modem supports V.42 is also defined.
34
35 \section v42_page_sec_2 How does it work?
36 */
37
38 #if !defined(_V42_H_)
39 #define _V42_H_
40
41 enum
42 {
43 LAPM_DETECT = 0,
44 LAPM_ESTABLISH = 1,
45 LAPM_DATA = 2,
46 LAPM_RELEASE = 3,
47 LAPM_SIGNAL = 4,
48 LAPM_SETPARM = 5,
49 LAPM_TEST = 6,
50 LAPM_UNSUPPORTED = 7
51 };
52
53 typedef void (*v42_status_func_t)(void *user_data, int status);
54 typedef void (*v42_frame_handler_t)(void *user_data, const uint8_t *pkt, int len);
55
56 typedef struct lapm_frame_queue_s
57 {
58 struct lapm_frame_queue_s *next;
59 int len;
60 uint8_t frame[];
61 } lapm_frame_queue_t;
62
63 /*!
64 LAP-M descriptor. This defines the working state for a single instance of LAP-M.
65 */
66 typedef struct
67 {
68 int handle;
69 hdlc_rx_state_t hdlc_rx;
70 hdlc_tx_state_t hdlc_tx;
71
72 v42_frame_handler_t iframe_receive;
73 void *iframe_receive_user_data;
74
75 v42_status_func_t status_callback;
76 void *status_callback_user_data;
77
78 int state;
79 int tx_waiting;
80 int debug;
81 /*! TRUE if originator. FALSE if answerer */
82 int we_are_originator;
83 /*! Remote network type (unknown, answerer. originator) */
84 int peer_is_originator;
85 /*! Next N(S) for transmission */
86 int next_tx_frame;
87 /*! The last of our frames which the peer acknowledged */
88 int last_frame_peer_acknowledged;
89 /*! Next N(R) for reception */
90 int next_expected_frame;
91 /*! The last of the peer's frames which we acknowledged */
92 int last_frame_we_acknowledged;
93 /*! TRUE if we sent an I or S frame with the F-bit set */
94 int solicit_f_bit;
95 /*! Retransmission count */
96 int retransmissions;
97 /*! TRUE if peer is busy */
98 int busy;
99
100 /*! Acknowledgement timer */
101 int t401_timer;
102 /*! Reply delay timer - optional */
103 int t402_timer;
104 /*! Inactivity timer - optional */
105 int t403_timer;
106 /*! Maximum number of octets in an information field */
107 int n401;
108 /*! Window size */
109 int window_size_k;
110
111 lapm_frame_queue_t *txqueue;
112 lapm_frame_queue_t *tx_next;
113 lapm_frame_queue_t *tx_last;
114 queue_t tx_queue;
115
116 span_sched_state_t sched;
117 /*! \brief Error and flow logging control */
118 logging_state_t logging;
119 } lapm_state_t;
120
121 /*!
122 V.42 descriptor. This defines the working state for a single instance of V.42.
123 */
124 typedef struct
125 {
126 /*! TRUE if we are the calling party, otherwise FALSE */
127 int caller;
128 /*! TRUE if we should detect whether the far end is V.42 capable. FALSE if we go
129 directly to protocol establishment */
130 int detect;
131
132 /*! Stage in negotiating V.42 support */
133 int rx_negotiation_step;
134 int rxbits;
135 int rxstream;
136 int rxoks;
137 int odp_seen;
138 int txbits;
139 int txstream;
140 int txadps;
141 /*! The LAP.M context */
142 lapm_state_t lapm;
143
144 /*! V.42 support detection timer */
145 int t400_timer;
146 /*! \brief Error and flow logging control */
147 logging_state_t logging;
148 } v42_state_t;
149
150 /*! Log the raw HDLC frames */
151 #define LAPM_DEBUG_LAPM_RAW (1 << 0)
152 /*! Log the interpreted frames */
153 #define LAPM_DEBUG_LAPM_DUMP (1 << 1)
154 /*! Log state machine changes */
155 #define LAPM_DEBUG_LAPM_STATE (1 << 2)
156
157 #ifdef __cplusplus
158 extern "C" {
159 #endif
160
161 const char *lapm_status_to_str(int status);
162
163 /*! Dump LAP.M frames in a raw and/or decoded forms
164 \param frame The frame itself
165 \param len The length of the frame, in octets
166 \param showraw TRUE if the raw octets should be dumped
167 \param txrx TRUE if tx, FALSE if rx. Used to highlight the packet's direction.
168 */
169 void lapm_dump(lapm_state_t *s, const uint8_t *frame, int len, int showraw, int txrx);
170
171 /*! Accept an HDLC packet
172 */
173 void lapm_receive(void *user_data, int ok, const uint8_t *buf, int len);
174
175 /*! Transmit a LAP.M frame
176 */
177 int lapm_tx(lapm_state_t *s, const void *buf, int len);
178
179 /*! Transmit a LAP.M information frame
180 */
181 int lapm_tx_iframe(lapm_state_t *s, const void *buf, int len, int cr);
182
183 /*! Send a break over a LAP.M connection
184 */
185 int lapm_break(lapm_state_t *s, int enable);
186
187 /*! Initiate an orderly release of a LAP.M connection
188 */
189 int lapm_release(lapm_state_t *s);
190
191 /*! Enable or disable loopback of a LAP.M connection
192 */
193 int lapm_loopback(lapm_state_t *s, int enable);
194
195 /*! Assign or remove a callback routine used to deal with V.42 status changes.
196 */
197 void v42_set_status_callback(v42_state_t *s, v42_status_func_t callback, void *user_data);
198
199 /*! Process a newly received bit for a V.42 context.
200 */
201 void v42_rx_bit(void *user_data, int bit);
202
203 /*! Get the next transmit bit for a V.42 context.
204 */
205 int v42_tx_bit(void *user_data);
206
207 /*! Initialise a V.42 context.
208 \param s The V.42 context.
209 \param caller TRUE if caller mode, else answerer mode.
210 \param frame_handler A callback function to handle received frames of data.
211 \param user_data An opaque pointer passed to the frame handler routine.
212 \return ???
213 */
214 v42_state_t *v42_init(v42_state_t *s, int caller, int detect, v42_frame_handler_t frame_handler, void *user_data);
215
216 /*! Restart a V.42 context.
217 \param s The V.42 context.
218 */
219 void v42_restart(v42_state_t *s);
220
221 /*! Release a V.42 context.
222 \param s The V.42 context.
223 \return 0 if OK */
224 int v42_release(v42_state_t *s);
225
226 #ifdef __cplusplus
227 }
228 #endif
229
230 #endif
231 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.