lapm.h

00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * lapm.h
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2006 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$
00026  */
00027 
00028 /*! \page lapm_page LAP.M
00029 \section lapm_page_sec_1 What does it do?
00030 
00031 \section lapm_page_sec_2 How does it work?
00032 */
00033 
00034 #if !defined(_SPANDSP_LAPM_H_)
00035 #define _SPANDSP_LAPM_H_
00036 
00037 enum
00038 {
00039     LAPM_DETECT = 0,
00040     LAPM_ESTABLISH = 1,
00041     LAPM_DATA = 2,
00042     LAPM_RELEASE = 3,
00043     LAPM_SIGNAL = 4,
00044     LAPM_SETPARM = 5,
00045     LAPM_TEST = 6,
00046     LAPM_UNSUPPORTED = 7
00047 };
00048 
00049 typedef void (*v42_status_func_t)(void *user_data, int status);
00050 typedef void (*v42_frame_handler_t)(void *user_data, const uint8_t *pkt, int len);
00051 
00052 typedef struct lapm_frame_queue_s
00053 {
00054     struct lapm_frame_queue_s *next;
00055     int len;
00056     uint8_t frame[];
00057 } lapm_frame_queue_t;
00058 
00059 /*!
00060     LAP-M descriptor. This defines the working state for a single instance of LAP-M.
00061 */
00062 typedef struct
00063 {
00064     int handle;
00065     hdlc_rx_state_t hdlc_rx;
00066     hdlc_tx_state_t hdlc_tx;
00067     
00068     v42_frame_handler_t iframe_receive;
00069     void *iframe_receive_user_data;
00070 
00071     v42_status_func_t status_callback;
00072     void *status_callback_user_data;
00073 
00074     int state;
00075     int tx_waiting;
00076     int debug;
00077     /*! TRUE if originator. FALSE if answerer */
00078     int we_are_originator;
00079     /*! Remote network type (unknown, answerer. originator) */
00080     int peer_is_originator;
00081     /*! Next N(S) for transmission */
00082     int next_tx_frame;
00083     /*! The last of our frames which the peer acknowledged */
00084     int last_frame_peer_acknowledged;
00085     /*! Next N(R) for reception */
00086     int next_expected_frame;
00087     /*! The last of the peer's frames which we acknowledged */
00088     int last_frame_we_acknowledged;
00089     /*! TRUE if we sent an I or S frame with the F-bit set */
00090     int solicit_f_bit;
00091     /*! Retransmission count */
00092     int retransmissions;
00093     /*! TRUE if peer is busy */
00094     int busy;
00095 
00096     /*! Acknowledgement timer */
00097     int t401_timer;
00098     /*! Reply delay timer - optional */
00099     int t402_timer;
00100     /*! Inactivity timer - optional */
00101     int t403_timer;
00102     /*! Maximum number of octets in an information field */
00103     int n401;
00104     /*! Window size */
00105     int window_size_k;
00106         
00107     lapm_frame_queue_t *txqueue;
00108     lapm_frame_queue_t *tx_next;
00109     lapm_frame_queue_t *tx_last;
00110     queue_t tx_queue;
00111     
00112     span_sched_state_t sched;
00113     /*! \brief Error and flow logging control */
00114     logging_state_t logging;
00115 } lapm_state_t;
00116 
00117 /*! Log the raw HDLC frames */
00118 #define LAPM_DEBUG_LAPM_RAW         (1 << 0)
00119 /*! Log the interpreted frames */
00120 #define LAPM_DEBUG_LAPM_DUMP        (1 << 1)
00121 /*! Log state machine changes */
00122 #define LAPM_DEBUG_LAPM_STATE       (1 << 2)
00123 
00124 #if defined(__cplusplus)
00125 extern "C"
00126 {
00127 #endif
00128 
00129 const char *lapm_status_to_str(int status);
00130 
00131 /*! Dump LAP.M frames in a raw and/or decoded forms
00132     \param frame The frame itself
00133     \param len The length of the frame, in octets
00134     \param showraw TRUE if the raw octets should be dumped
00135     \param txrx TRUE if tx, FALSE if rx. Used to highlight the packet's direction.
00136 */
00137 void lapm_dump(lapm_state_t *s, const uint8_t *frame, int len, int showraw, int txrx);
00138 
00139 /*! Accept an HDLC packet
00140 */
00141 void lapm_receive(void *user_data, int ok, const uint8_t *buf, int len);
00142 
00143 /*! Transmit a LAP.M frame
00144 */
00145 int lapm_tx(lapm_state_t *s, const void *buf, int len);
00146 
00147 /*! Transmit a LAP.M information frame
00148 */
00149 int lapm_tx_iframe(lapm_state_t *s, const void *buf, int len, int cr);
00150 
00151 /*! Send a break over a LAP.M connection
00152 */
00153 int lapm_break(lapm_state_t *s, int enable);
00154 
00155 /*! Initiate an orderly release of a LAP.M connection
00156 */
00157 int lapm_release(lapm_state_t *s);
00158 
00159 /*! Enable or disable loopback of a LAP.M connection
00160 */
00161 int lapm_loopback(lapm_state_t *s, int enable);
00162 
00163 #if defined(__cplusplus)
00164 }
00165 #endif
00166 
00167 #endif
00168 /*- End of file ------------------------------------------------------------*/

Generated on Tue Oct 7 20:25:46 2008 for spandsp by  doxygen 1.5.6