spandsp: hdlc.h Source File

spandsp 0.0.6

private/hdlc.h
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * private/hdlc.h
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2003 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 2.1,
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#if !defined(_SPANDSP_PRIVATE_HDLC_H_)
27#define _SPANDSP_PRIVATE_HDLC_H_
28
29/*!
30 HDLC receive descriptor. This contains all the state information for an HDLC receiver.
31 */
32 struct hdlc_rx_state_s
33{
34 /*! 2 for CRC-16, 4 for CRC-32 */
35 int crc_bytes;
36 /*! \brief Maximum permitted frame length. */
37 size_t max_frame_len;
38 /*! \brief The callback routine called to process each good received frame. */
39 hdlc_frame_handler_t frame_handler;
40 /*! \brief An opaque parameter passed to the frame callback routine. */
41 void *frame_user_data;
42 /*! \brief The callback routine called to report status changes. */
43 modem_rx_status_func_t status_handler;
44 /*! \brief An opaque parameter passed to the status callback routine. */
45 void *status_user_data;
46 /*! \brief TRUE if bad frames are to be reported. */
47 int report_bad_frames;
48 /*! \brief The number of consecutive flags which must be seen before framing is
49 declared OK. */
50 int framing_ok_threshold;
51 /*! \brief TRUE if framing OK has been announced. */
52 int framing_ok_announced;
53 /*! \brief Number of consecutive flags seen so far. */
54 int flags_seen;
55
56 /*! \brief The raw (stuffed) bit stream buffer. */
57 unsigned int raw_bit_stream;
58 /*! \brief The destuffed bit stream buffer. */
59 unsigned int byte_in_progress;
60 /*! \brief The current number of bits in byte_in_progress. */
61 int num_bits;
62 /*! \brief TRUE if in octet counting mode (e.g. for MTP). */
63 int octet_counting_mode;
64 /*! \brief Octet count, to achieve the functionality needed for things
65 like MTP. */
66 int octet_count;
67 /*! \brief The number of octets to be allowed between octet count reports. */
68 int octet_count_report_interval;
69
70 /*! \brief Buffer for a frame in progress. */
71 uint8_t buffer[HDLC_MAXFRAME_LEN + 4];
72 /*! \brief Length of a frame in progress. */
73 size_t len;
74
75 /*! \brief The number of bytes of good frames received (CRC not included). */
76 unsigned long int rx_bytes;
77 /*! \brief The number of good frames received. */
78 unsigned long int rx_frames;
79 /*! \brief The number of frames with CRC errors received. */
80 unsigned long int rx_crc_errors;
81 /*! \brief The number of too short and too long frames received. */
82 unsigned long int rx_length_errors;
83 /*! \brief The number of HDLC aborts received. */
84 unsigned long int rx_aborts;
85};
86
87/*!
88 HDLC transmit descriptor. This contains all the state information for an
89 HDLC transmitter.
90 */
91 struct hdlc_tx_state_s
92{
93 /*! 2 for CRC-16, 4 for CRC-32 */
94 int crc_bytes;
95 /*! \brief The callback routine called to indicate transmit underflow. */
96 hdlc_underflow_handler_t underflow_handler;
97 /*! \brief An opaque parameter passed to the callback routine. */
98 void *user_data;
99 /*! \brief The minimum flag octets to insert between frames. */
100 int inter_frame_flags;
101 /*! \brief TRUE if frame creation works in progressive mode. */
102 int progressive;
103 /*! \brief Maximum permitted frame length. */
104 size_t max_frame_len;
105
106 /*! \brief The stuffed bit stream being created. */
107 uint32_t octets_in_progress;
108 /*! \brief The number of bits currently in octets_in_progress. */
109 int num_bits;
110 /*! \brief The currently rotated state of the flag octet. */
111 int idle_octet;
112 /*! \brief The number of flag octets to send for a timed burst of flags. */
113 int flag_octets;
114 /*! \brief The number of abort octets to send for a timed burst of aborts. */
115 int abort_octets;
116 /*! \brief TRUE if the next underflow of timed flag octets should be reported */
117 int report_flag_underflow;
118
119 /*! \brief The current message being transmitted, with its CRC attached. */
120 uint8_t buffer[HDLC_MAXFRAME_LEN + 4];
121 /*! \brief The length of the message in the buffer. */
122 size_t len;
123 /*! \brief The current send position within the buffer. */
124 size_t pos;
125 /*! \brief The running CRC, as data fills the frame buffer. */
126 uint32_t crc;
127
128 /*! \brief The current byte being broken into bits for transmission. */
129 int byte;
130 /*! \brief The number of bits remaining in byte. */
131 int bits;
132
133 /*! \brief TRUE if transmission should end on buffer underflow .*/
134 int tx_end;
135};
136
137#endif
138/*- End of file ------------------------------------------------------------*/
HDLC_MAXFRAME_LEN
#define HDLC_MAXFRAME_LEN
Definition hdlc.h:46
hdlc_rx_state_s
Definition private/hdlc.h:33
hdlc_rx_state_s::len
size_t len
Length of a frame in progress.
Definition private/hdlc.h:73
hdlc_rx_state_s::framing_ok_threshold
int framing_ok_threshold
The number of consecutive flags which must be seen before framing is declared OK.
Definition private/hdlc.h:50
hdlc_rx_state_s::buffer
uint8_t buffer[HDLC_MAXFRAME_LEN+4]
Buffer for a frame in progress.
Definition private/hdlc.h:71
hdlc_rx_state_s::framing_ok_announced
int framing_ok_announced
TRUE if framing OK has been announced.
Definition private/hdlc.h:52
hdlc_rx_state_s::rx_crc_errors
unsigned long int rx_crc_errors
The number of frames with CRC errors received.
Definition private/hdlc.h:80
hdlc_rx_state_s::raw_bit_stream
unsigned int raw_bit_stream
The raw (stuffed) bit stream buffer.
Definition private/hdlc.h:57
hdlc_rx_state_s::byte_in_progress
unsigned int byte_in_progress
The destuffed bit stream buffer.
Definition private/hdlc.h:59
hdlc_rx_state_s::report_bad_frames
int report_bad_frames
TRUE if bad frames are to be reported.
Definition private/hdlc.h:47
hdlc_rx_state_s::rx_aborts
unsigned long int rx_aborts
The number of HDLC aborts received.
Definition private/hdlc.h:84
hdlc_rx_state_s::octet_counting_mode
int octet_counting_mode
TRUE if in octet counting mode (e.g. for MTP).
Definition private/hdlc.h:63
hdlc_rx_state_s::status_user_data
void * status_user_data
An opaque parameter passed to the status callback routine.
Definition private/hdlc.h:45
hdlc_rx_state_s::frame_handler
hdlc_frame_handler_t frame_handler
The callback routine called to process each good received frame.
Definition private/hdlc.h:39
hdlc_rx_state_s::rx_bytes
unsigned long int rx_bytes
The number of bytes of good frames received (CRC not included).
Definition private/hdlc.h:76
hdlc_rx_state_s::frame_user_data
void * frame_user_data
An opaque parameter passed to the frame callback routine.
Definition private/hdlc.h:41
hdlc_rx_state_s::flags_seen
int flags_seen
Number of consecutive flags seen so far.
Definition private/hdlc.h:54
hdlc_rx_state_s::max_frame_len
size_t max_frame_len
Maximum permitted frame length.
Definition private/hdlc.h:37
hdlc_rx_state_s::crc_bytes
int crc_bytes
Definition private/hdlc.h:35
hdlc_rx_state_s::rx_length_errors
unsigned long int rx_length_errors
The number of too short and too long frames received.
Definition private/hdlc.h:82
hdlc_rx_state_s::num_bits
int num_bits
The current number of bits in byte_in_progress.
Definition private/hdlc.h:61
hdlc_rx_state_s::octet_count_report_interval
int octet_count_report_interval
The number of octets to be allowed between octet count reports.
Definition private/hdlc.h:68
hdlc_rx_state_s::octet_count
int octet_count
Octet count, to achieve the functionality needed for things like MTP.
Definition private/hdlc.h:66
hdlc_rx_state_s::rx_frames
unsigned long int rx_frames
The number of good frames received.
Definition private/hdlc.h:78
hdlc_rx_state_s::status_handler
modem_rx_status_func_t status_handler
The callback routine called to report status changes.
Definition private/hdlc.h:43
hdlc_tx_state_s
Definition private/hdlc.h:92
hdlc_tx_state_s::bits
int bits
The number of bits remaining in byte.
Definition private/hdlc.h:131
hdlc_tx_state_s::flag_octets
int flag_octets
The number of flag octets to send for a timed burst of flags.
Definition private/hdlc.h:113
hdlc_tx_state_s::octets_in_progress
uint32_t octets_in_progress
The stuffed bit stream being created.
Definition private/hdlc.h:107
hdlc_tx_state_s::buffer
uint8_t buffer[HDLC_MAXFRAME_LEN+4]
The current message being transmitted, with its CRC attached.
Definition private/hdlc.h:120
hdlc_tx_state_s::pos
size_t pos
The current send position within the buffer.
Definition private/hdlc.h:124
hdlc_tx_state_s::len
size_t len
The length of the message in the buffer.
Definition private/hdlc.h:122
hdlc_tx_state_s::idle_octet
int idle_octet
The currently rotated state of the flag octet.
Definition private/hdlc.h:111
hdlc_tx_state_s::num_bits
int num_bits
The number of bits currently in octets_in_progress.
Definition private/hdlc.h:109
hdlc_tx_state_s::tx_end
int tx_end
TRUE if transmission should end on buffer underflow .
Definition private/hdlc.h:134
hdlc_tx_state_s::inter_frame_flags
int inter_frame_flags
The minimum flag octets to insert between frames.
Definition private/hdlc.h:100
hdlc_tx_state_s::crc
uint32_t crc
The running CRC, as data fills the frame buffer.
Definition private/hdlc.h:126
hdlc_tx_state_s::report_flag_underflow
int report_flag_underflow
TRUE if the next underflow of timed flag octets should be reported.
Definition private/hdlc.h:117
hdlc_tx_state_s::byte
int byte
The current byte being broken into bits for transmission.
Definition private/hdlc.h:129
hdlc_tx_state_s::progressive
int progressive
TRUE if frame creation works in progressive mode.
Definition private/hdlc.h:102
hdlc_tx_state_s::crc_bytes
int crc_bytes
Definition private/hdlc.h:94
hdlc_tx_state_s::abort_octets
int abort_octets
The number of abort octets to send for a timed burst of aborts.
Definition private/hdlc.h:115
hdlc_tx_state_s::underflow_handler
hdlc_underflow_handler_t underflow_handler
The callback routine called to indicate transmit underflow.
Definition private/hdlc.h:96
hdlc_tx_state_s::user_data
void * user_data
An opaque parameter passed to the callback routine.
Definition private/hdlc.h:98
hdlc_tx_state_s::max_frame_len
size_t max_frame_len
Maximum permitted frame length.
Definition private/hdlc.h:104