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