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