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