private/hdlc.h

00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * private/hdlc.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: hdlc.h,v 1.1 2008/11/30 05:43:37 steveu Exp $
00026  */
00027 
00028 #if !defined(_SPANDSP_PRIVATE_HDLC_H_)
00029 #define _SPANDSP_PRIVATE_HDLC_H_
00030 
00031 /*!
00032     HDLC receive descriptor. This contains all the state information for an HDLC receiver.
00033  */
00034 struct hdlc_rx_state_s
00035 {
00036     /*! 2 for CRC-16, 4 for CRC-32 */
00037     int crc_bytes;
00038     /*! \brief Maximum permitted frame length. */
00039     size_t max_frame_len;
00040     /*! \brief The callback routine called to process each good received frame. */
00041     hdlc_frame_handler_t frame_handler;
00042     /*! \brief An opaque parameter passed to the callback routine. */
00043     void *user_data;
00044     /*! \brief TRUE if bad frames are to be reported. */
00045     int report_bad_frames;
00046     /*! \brief The number of consecutive flags which must be seen before framing is
00047         declared OK. */
00048     int framing_ok_threshold;
00049     /*! \brief TRUE if framing OK has been announced. */
00050     int framing_ok_announced;
00051     /*! \brief Number of consecutive flags seen so far. */
00052     int flags_seen;
00053 
00054     /*! \brief The raw (stuffed) bit stream buffer. */
00055     unsigned int raw_bit_stream;
00056     /*! \brief The destuffed bit stream buffer. */
00057     unsigned int byte_in_progress;
00058     /*! \brief The current number of bits in byte_in_progress. */
00059     int num_bits;
00060     /*! \brief TRUE if in octet counting mode (e.g. for MTP). */
00061     int octet_counting_mode;
00062     /*! \brief Octet count, to achieve the functionality needed for things
00063                like MTP. */
00064     int octet_count;
00065     /*! \brief The number of octets to be allowed between octet count reports. */
00066     int octet_count_report_interval;
00067 
00068     /*! \brief Buffer for a frame in progress. */
00069     uint8_t buffer[HDLC_MAXFRAME_LEN + 4];
00070     /*! \brief Length of a frame in progress. */
00071     size_t len;
00072 
00073     /*! \brief The number of bytes of good frames received (CRC not included). */
00074     unsigned long int rx_bytes;
00075     /*! \brief The number of good frames received. */
00076     unsigned long int rx_frames;
00077     /*! \brief The number of frames with CRC errors received. */
00078     unsigned long int rx_crc_errors;
00079     /*! \brief The number of too short and too long frames received. */
00080     unsigned long int rx_length_errors;
00081     /*! \brief The number of HDLC aborts received. */
00082     unsigned long int rx_aborts;
00083 };
00084 
00085 /*!
00086     HDLC transmit descriptor. This contains all the state information for an
00087     HDLC transmitter.
00088  */
00089 struct hdlc_tx_state_s
00090 {
00091     /*! 2 for CRC-16, 4 for CRC-32 */
00092     int crc_bytes;
00093     /*! \brief The callback routine called to indicate transmit underflow. */
00094     hdlc_underflow_handler_t underflow_handler;
00095     /*! \brief An opaque parameter passed to the callback routine. */
00096     void *user_data;
00097     /*! \brief The minimum flag octets to insert between frames. */
00098     int inter_frame_flags;
00099     /*! \brief TRUE if frame creation works in progressive mode. */
00100     int progressive;
00101     /*! \brief Maximum permitted frame length. */
00102     size_t max_frame_len;
00103 
00104     /*! \brief The stuffed bit stream being created. */
00105     uint32_t octets_in_progress;
00106     /*! \brief The number of bits currently in octets_in_progress. */
00107     int num_bits;
00108     /*! \brief The currently rotated state of the flag octet. */
00109     int idle_octet;
00110     /*! \brief The number of flag octets to send for a timed burst of flags. */
00111     int flag_octets;
00112     /*! \brief The number of abort octets to send for a timed burst of aborts. */
00113     int abort_octets;
00114     /*! \brief TRUE if the next underflow of timed flag octets should be reported */
00115     int report_flag_underflow;
00116 
00117     /*! \brief The current message being transmitted, with its CRC attached. */
00118     uint8_t buffer[HDLC_MAXFRAME_LEN + 4];
00119     /*! \brief The length of the message in the buffer. */
00120     size_t len;
00121     /*! \brief The current send position within the buffer. */
00122     int pos;
00123     /*! \brief The running CRC, as data fills the frame buffer. */
00124     uint32_t crc;
00125 
00126     /*! \brief The current byte being broken into bits for transmission. */
00127     int byte;
00128     /*! \brief The number of bits remaining in byte. */
00129     int bits;
00130     
00131     /*! \brief TRUE if transmission should end on buffer underflow .*/
00132     int tx_end;
00133 };
00134 
00135 #endif
00136 /*- End of file ------------------------------------------------------------*/

Generated on Thu Feb 12 14:16:07 2009 for spandsp by  doxygen 1.5.5