v42.h

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 
00026 /*! \page v42_page V.42 modem error correction
00027 \section v42_page_sec_1 What does it do?
00028 The V.42 specification defines an error correcting protocol for PSTN modems, based on
00029 HDLC and LAP. This makes it similar to an X.25 link. A special variant of LAP, known
00030 as LAP-M, is defined in the V.42 specification. A means for modems to determine if the
00031 far modem supports V.42 is also defined.
00032 
00033 \section v42_page_sec_2 How does it work?
00034 */
00035 
00036 #if !defined(_SPANDSP_V42_H_)
00037 #define _SPANDSP_V42_H_
00038 
00039 enum
00040 {
00041     LAPM_DETECT = 0,
00042     LAPM_ESTABLISH = 1,
00043     LAPM_DATA = 2,
00044     LAPM_RELEASE = 3,
00045     LAPM_SIGNAL = 4,
00046     LAPM_SETPARM = 5,
00047     LAPM_TEST = 6,
00048     LAPM_UNSUPPORTED = 7
00049 };
00050 
00051 typedef void (*v42_status_func_t)(void *user_data, int status);
00052 typedef void (*v42_frame_handler_t)(void *user_data, const uint8_t *pkt, int len);
00053 
00054 typedef struct lapm_frame_queue_s
00055 {
00056     struct lapm_frame_queue_s *next;
00057     int len;
00058     uint8_t frame[];
00059 } lapm_frame_queue_t;
00060 
00061 /*!
00062     LAP-M descriptor. This defines the working state for a single instance of LAP-M.
00063 */
00064 typedef struct lapm_state_s lapm_state_t;
00065 
00066 /*!
00067     V.42 descriptor. This defines the working state for a single instance of V.42.
00068 */
00069 typedef struct v42_state_s v42_state_t;
00070 
00071 /*! Log the raw HDLC frames */
00072 #define LAPM_DEBUG_LAPM_RAW         (1 << 0)
00073 /*! Log the interpreted frames */
00074 #define LAPM_DEBUG_LAPM_DUMP        (1 << 1)
00075 /*! Log state machine changes */
00076 #define LAPM_DEBUG_LAPM_STATE       (1 << 2)
00077 
00078 #if defined(__cplusplus)
00079 extern "C"
00080 {
00081 #endif
00082 
00083 SPAN_DECLARE(const char *) lapm_status_to_str(int status);
00084 
00085 /*! Dump LAP.M frames in a raw and/or decoded forms
00086     \param frame The frame itself
00087     \param len The length of the frame, in octets
00088     \param showraw TRUE if the raw octets should be dumped
00089     \param txrx TRUE if tx, FALSE if rx. Used to highlight the packet's direction.
00090 */
00091 SPAN_DECLARE(void) lapm_dump(lapm_state_t *s, const uint8_t *frame, int len, int showraw, int txrx);
00092 
00093 /*! Accept an HDLC packet
00094 */
00095 SPAN_DECLARE_NONSTD(void) lapm_receive(void *user_data, const uint8_t *buf, int len, int ok);
00096 
00097 /*! Transmit a LAP.M frame
00098 */
00099 SPAN_DECLARE(int) lapm_tx(lapm_state_t *s, const void *buf, int len);
00100 
00101 /*! Transmit a LAP.M information frame
00102 */
00103 SPAN_DECLARE(int) lapm_tx_iframe(lapm_state_t *s, const void *buf, int len, int cr);
00104 
00105 /*! Send a break over a LAP.M connection
00106 */
00107 SPAN_DECLARE(int) lapm_break(lapm_state_t *s, int enable);
00108 
00109 /*! Initiate an orderly release of a LAP.M connection
00110 */
00111 SPAN_DECLARE(int) lapm_release(lapm_state_t *s);
00112 
00113 /*! Enable or disable loopback of a LAP.M connection
00114 */
00115 SPAN_DECLARE(int) lapm_loopback(lapm_state_t *s, int enable);
00116 
00117 /*! Assign or remove a callback routine used to deal with V.42 status changes.
00118 */
00119 SPAN_DECLARE(void) v42_set_status_callback(v42_state_t *s, v42_status_func_t callback, void *user_data);
00120 
00121 /*! Process a newly received bit for a V.42 context.
00122 */
00123 SPAN_DECLARE(void) v42_rx_bit(void *user_data, int bit);
00124 
00125 /*! Get the next transmit bit for a V.42 context.
00126 */
00127 SPAN_DECLARE(int) v42_tx_bit(void *user_data);
00128 
00129 /*! Initialise a V.42 context.
00130     \param s The V.42 context.
00131     \param calling_party TRUE if caller mode, else answerer mode.
00132     \param frame_handler A callback function to handle received frames of data.
00133     \param user_data An opaque pointer passed to the frame handler routine.
00134     \return ???
00135 */
00136 SPAN_DECLARE(v42_state_t *) v42_init(v42_state_t *s, int calling_party, int detect, v42_frame_handler_t frame_handler, void *user_data);
00137 
00138 /*! Restart a V.42 context.
00139     \param s The V.42 context.
00140 */
00141 SPAN_DECLARE(void) v42_restart(v42_state_t *s);
00142 
00143 /*! Release a V.42 context.
00144     \param s The V.42 context.
00145     \return 0 if OK */
00146 SPAN_DECLARE(int) v42_release(v42_state_t *s);
00147 
00148 /*! Free a V.42 context.
00149     \param s The V.42 context.
00150     \return 0 if OK */
00151 SPAN_DECLARE(int) v42_free(v42_state_t *s);
00152 
00153 #if defined(__cplusplus)
00154 }
00155 #endif
00156 
00157 #endif
00158 /*- End of file ------------------------------------------------------------*/

Generated on Thu Dec 9 21:11:51 2010 for spandsp by  doxygen 1.5.9