libspandsp 0.0.4
|
00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * v42.h 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2003 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: v42.h,v 1.25 2008/04/17 14:27:01 steveu Exp $ 00026 */ 00027 00028 /*! \page v42_page V.42 modem error correction 00029 \section v42_page_sec_1 What does it do? 00030 The V.42 specification defines an error correcting protocol for PSTN modems, based on 00031 HDLC and LAP. This makes it similar to an X.25 link. A special variant of LAP, known 00032 as LAP-M, is defined in the V.42 specification. A means for modems to determine if the 00033 far modem supports V.42 is also defined. 00034 00035 \section v42_page_sec_2 How does it work? 00036 */ 00037 00038 #if !defined(_SPANDSP_V42_H_) 00039 #define _SPANDSP_V42_H_ 00040 00041 enum 00042 { 00043 LAPM_DETECT = 0, 00044 LAPM_ESTABLISH = 1, 00045 LAPM_DATA = 2, 00046 LAPM_RELEASE = 3, 00047 LAPM_SIGNAL = 4, 00048 LAPM_SETPARM = 5, 00049 LAPM_TEST = 6, 00050 LAPM_UNSUPPORTED = 7 00051 }; 00052 00053 typedef void (*v42_status_func_t)(void *user_data, int status); 00054 typedef void (*v42_frame_handler_t)(void *user_data, const uint8_t *pkt, int len); 00055 00056 typedef struct lapm_frame_queue_s 00057 { 00058 struct lapm_frame_queue_s *next; 00059 int len; 00060 uint8_t frame[]; 00061 } lapm_frame_queue_t; 00062 00063 /*! 00064 LAP-M descriptor. This defines the working state for a single instance of LAP-M. 00065 */ 00066 typedef struct 00067 { 00068 int handle; 00069 hdlc_rx_state_t hdlc_rx; 00070 hdlc_tx_state_t hdlc_tx; 00071 00072 v42_frame_handler_t iframe_receive; 00073 void *iframe_receive_user_data; 00074 00075 v42_status_func_t status_callback; 00076 void *status_callback_user_data; 00077 00078 int state; 00079 int tx_waiting; 00080 int debug; 00081 /*! TRUE if originator. FALSE if answerer */ 00082 int we_are_originator; 00083 /*! Remote network type (unknown, answerer. originator) */ 00084 int peer_is_originator; 00085 /*! Next N(S) for transmission */ 00086 int next_tx_frame; 00087 /*! The last of our frames which the peer acknowledged */ 00088 int last_frame_peer_acknowledged; 00089 /*! Next N(R) for reception */ 00090 int next_expected_frame; 00091 /*! The last of the peer's frames which we acknowledged */ 00092 int last_frame_we_acknowledged; 00093 /*! TRUE if we sent an I or S frame with the F-bit set */ 00094 int solicit_f_bit; 00095 /*! Retransmission count */ 00096 int retransmissions; 00097 /*! TRUE if peer is busy */ 00098 int busy; 00099 00100 /*! Acknowledgement timer */ 00101 int t401_timer; 00102 /*! Reply delay timer - optional */ 00103 int t402_timer; 00104 /*! Inactivity timer - optional */ 00105 int t403_timer; 00106 /*! Maximum number of octets in an information field */ 00107 int n401; 00108 /*! Window size */ 00109 int window_size_k; 00110 00111 lapm_frame_queue_t *txqueue; 00112 lapm_frame_queue_t *tx_next; 00113 lapm_frame_queue_t *tx_last; 00114 queue_state_t *tx_queue; 00115 00116 span_sched_state_t sched; 00117 /*! \brief Error and flow logging control */ 00118 logging_state_t logging; 00119 } lapm_state_t; 00120 00121 /*! 00122 V.42 descriptor. This defines the working state for a single instance of V.42. 00123 */ 00124 typedef struct 00125 { 00126 /*! TRUE if we are the calling party, otherwise FALSE */ 00127 int caller; 00128 /*! TRUE if we should detect whether the far end is V.42 capable. FALSE if we go 00129 directly to protocol establishment */ 00130 int detect; 00131 00132 /*! Stage in negotiating V.42 support */ 00133 int rx_negotiation_step; 00134 int rxbits; 00135 int rxstream; 00136 int rxoks; 00137 int odp_seen; 00138 int txbits; 00139 int txstream; 00140 int txadps; 00141 /*! The LAP.M context */ 00142 lapm_state_t lapm; 00143 00144 /*! V.42 support detection timer */ 00145 int t400_timer; 00146 /*! \brief Error and flow logging control */ 00147 logging_state_t logging; 00148 } v42_state_t; 00149 00150 /*! Log the raw HDLC frames */ 00151 #define LAPM_DEBUG_LAPM_RAW (1 << 0) 00152 /*! Log the interpreted frames */ 00153 #define LAPM_DEBUG_LAPM_DUMP (1 << 1) 00154 /*! Log state machine changes */ 00155 #define LAPM_DEBUG_LAPM_STATE (1 << 2) 00156 00157 #if defined(__cplusplus) 00158 extern "C" 00159 { 00160 #endif 00161 00162 const char *lapm_status_to_str(int status); 00163 00164 /*! Dump LAP.M frames in a raw and/or decoded forms 00165 \param frame The frame itself 00166 \param len The length of the frame, in octets 00167 \param showraw TRUE if the raw octets should be dumped 00168 \param txrx TRUE if tx, FALSE if rx. Used to highlight the packet's direction. 00169 */ 00170 void lapm_dump(lapm_state_t *s, const uint8_t *frame, int len, int showraw, int txrx); 00171 00172 /*! Accept an HDLC packet 00173 */ 00174 void lapm_receive(void *user_data, const uint8_t *buf, int len, int ok); 00175 00176 /*! Transmit a LAP.M frame 00177 */ 00178 int lapm_tx(lapm_state_t *s, const void *buf, int len); 00179 00180 /*! Transmit a LAP.M information frame 00181 */ 00182 int lapm_tx_iframe(lapm_state_t *s, const void *buf, int len, int cr); 00183 00184 /*! Send a break over a LAP.M connection 00185 */ 00186 int lapm_break(lapm_state_t *s, int enable); 00187 00188 /*! Initiate an orderly release of a LAP.M connection 00189 */ 00190 int lapm_release(lapm_state_t *s); 00191 00192 /*! Enable or disable loopback of a LAP.M connection 00193 */ 00194 int lapm_loopback(lapm_state_t *s, int enable); 00195 00196 /*! Assign or remove a callback routine used to deal with V.42 status changes. 00197 */ 00198 void v42_set_status_callback(v42_state_t *s, v42_status_func_t callback, void *user_data); 00199 00200 /*! Process a newly received bit for a V.42 context. 00201 */ 00202 void v42_rx_bit(void *user_data, int bit); 00203 00204 /*! Get the next transmit bit for a V.42 context. 00205 */ 00206 int v42_tx_bit(void *user_data); 00207 00208 /*! Initialise a V.42 context. 00209 \param s The V.42 context. 00210 \param caller TRUE if caller mode, else answerer mode. 00211 \param frame_handler A callback function to handle received frames of data. 00212 \param user_data An opaque pointer passed to the frame handler routine. 00213 \return ??? 00214 */ 00215 v42_state_t *v42_init(v42_state_t *s, int caller, int detect, v42_frame_handler_t frame_handler, void *user_data); 00216 00217 /*! Restart a V.42 context. 00218 \param s The V.42 context. 00219 */ 00220 void v42_restart(v42_state_t *s); 00221 00222 /*! Release a V.42 context. 00223 \param s The V.42 context. 00224 \return 0 if OK */ 00225 int v42_release(v42_state_t *s); 00226 00227 #if defined(__cplusplus) 00228 } 00229 #endif 00230 00231 #endif 00232 /*- End of file ------------------------------------------------------------*/