Go to the documentation of this file.
40 #if !defined(_SPANDSP_HDLC_H_)
41 #define _SPANDSP_HDLC_H_
46 #define HDLC_MAXFRAME_LEN 400
48 typedef void (*hdlc_frame_handler_t)(
void *user_data,
const uint8_t *pkt,
int len,
int ok);
49 typedef void (*hdlc_underflow_handler_t)(
void *user_data);
79 #if defined(__cplusplus)
98 int report_bad_frames,
99 int framing_ok_threshold,
100 hdlc_frame_handler_t handler,
192 hdlc_underflow_handler_t handler,
269 #if defined(__cplusplus)
hdlc_underflow_handler_t underflow_handler
The callback routine called to indicate transmit underflow.
Definition: private/hdlc.h:96
int hdlc_tx_free(hdlc_tx_state_t *s)
Free an HDLC transmitter context.
Definition: hdlc.c:665
unsigned long int rx_frames
The number of good frames received.
Definition: private/hdlc.h:78
unsigned long int aborts
The number of HDLC aborts received.
Definition: hdlc.h:70
int crc_itu32_check(const uint8_t *buf, int len)
Check the ITU/CCITT CRC-32 value in a frame.
Definition: crc.c:105
void * user_data
An opaque parameter passed to the callback routine.
Definition: private/hdlc.h:98
@ SIG_STATUS_OCTET_REPORT
Regular octet report for things like HDLC to the MTP standards.
Definition: async.h:79
int hdlc_tx_restart(hdlc_tx_state_t *s)
Re-initialise an HDLC transmitter context.
Definition: hdlc.c:605
@ SIG_STATUS_ABORT
An abort signal (e.g. an HDLC abort) has been received.
Definition: async.h:73
hdlc_tx_state_t * hdlc_tx_init(hdlc_tx_state_t *s, int crc32, int inter_frame_flags, int progressive, hdlc_underflow_handler_t handler, void *user_data)
Initialise an HDLC transmitter context.
Definition: hdlc.c:626
int gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s)
Definition: gsm0610_encode.c:168
void(* modem_status_func_t)(void *user_data, int status)
Definition: async.h:114
void hdlc_rx_set_max_frame_len(hdlc_rx_state_t *s, size_t max_len)
Set the maximum frame length for an HDLC receiver context.
Definition: hdlc.c:300
unsigned long int rx_length_errors
The number of too short and too long frames received.
Definition: private/hdlc.h:82
int framing_ok_announced
TRUE if framing OK has been announced.
Definition: private/hdlc.h:52
@ SIG_STATUS_CARRIER_UP
The carrier signal is up. This merely indicates that carrier energy has been seen....
Definition: async.h:58
int hdlc_tx_release(hdlc_tx_state_t *s)
Release an HDLC transmitter context.
Definition: hdlc.c:659
int bits
The number of bits remaining in byte.
Definition: private/hdlc.h:131
int hdlc_tx_abort(hdlc_tx_state_t *s)
Send an abort.
Definition: hdlc.c:440
int16_t v[9]
Definition: private/gsm0610.h:54
int byte
The current byte being broken into bits for transmission.
Definition: private/hdlc.h:129
@ SIG_STATUS_TRAINING_IN_PROGRESS
The modem is training. This is an early indication that the signal seems to be of the right type....
Definition: async.h:63
void * frame_user_data
An opaque parameter passed to the frame callback routine.
Definition: private/hdlc.h:41
unsigned long int length_errors
The number of too short and too long frames received.
Definition: hdlc.h:68
modem_rx_status_func_t status_handler
The callback routine called to report status changes.
Definition: private/hdlc.h:43
size_t max_frame_len
Maximum permitted frame length.
Definition: private/hdlc.h:104
int flags_seen
Number of consecutive flags seen so far.
Definition: private/hdlc.h:54
int hdlc_rx_release(hdlc_rx_state_t *s)
Release an HDLC receiver context.
Definition: hdlc.c:364
int abort_octets
The number of abort octets to send for a timed burst of aborts.
Definition: private/hdlc.h:115
gsm0610_state_t * gsm0610_init(gsm0610_state_t *s, int packing)
Definition: gsm0610_encode.c:114
void hdlc_rx_set_frame_handler(hdlc_rx_state_t *s, hdlc_frame_handler_t handler, void *user_data)
Change the put_bit function associated with an HDLC receiver context.
Definition: hdlc.c:350
void hdlc_rx_set_octet_counting_report_interval(hdlc_rx_state_t *s, int interval)
Set the octet counting report interval.
Definition: hdlc.c:307
unsigned long int good_frames
The number of good frames received.
Definition: hdlc.h:64
int num_bits
The current number of bits in byte_in_progress.
Definition: private/hdlc.h:61
uint32_t crc
The running CRC, as data fills the frame buffer.
Definition: private/hdlc.h:126
@ SIG_STATUS_FRAMING_OK
Packet framing (e.g. HDLC framing) is OK.
Definition: async.h:69
int framing_ok_threshold
The number of consecutive flags which must be seen before framing is declared OK.
Definition: private/hdlc.h:50
SPAN_DECLARE_NONSTD(int) async_tx_get_bit(void *user_data)
Get the next bit of a transmitted serial bit stream.
int idle_octet
The currently rotated state of the flag octet.
Definition: private/hdlc.h:111
int16_t nrp
Definition: private/gsm0610.h:52
int gsm0610_encode(gsm0610_state_t *s, uint8_t code[], const int16_t amp[], int len)
Definition: gsm0610_encode.c:310
int hdlc_rx_free(hdlc_rx_state_t *s)
Free an HDLC receiver context.
Definition: hdlc.c:370
int hdlc_rx_restart(hdlc_rx_state_t *s)
Re-initialise an HDLC receiver context.
Definition: hdlc.c:313
int hdlc_tx_restart(hdlc_tx_state_t *s)
Re-initialise an HDLC transmitter context.
Definition: hdlc.c:605
size_t len
The length of the message in the buffer.
Definition: private/hdlc.h:122
int hdlc_tx_flags(hdlc_tx_state_t *s, int len)
Transmit a specified quantity of flag octets, typically as a preamble.
Definition: hdlc.c:424
int crc_bytes
Definition: private/hdlc.h:94
void hdlc_tx_set_max_frame_len(hdlc_tx_state_t *s, size_t max_len)
Set the maximum frame length for an HDLC transmitter context.
Definition: hdlc.c:599
int hdlc_tx_release(hdlc_tx_state_t *s)
Release an HDLC transmitter context.
Definition: hdlc.c:659
int crc_bytes
Definition: private/hdlc.h:35
size_t pos
The current send position within the buffer.
Definition: private/hdlc.h:124
int crc_itu16_check(const uint8_t *buf, int len)
Check the ITU/CCITT CRC-16 value in a frame.
Definition: crc.c:196
int16_t mp
Definition: private/gsm0610.h:44
int octet_counting_mode
TRUE if in octet counting mode (e.g. for MTP).
Definition: private/hdlc.h:63
int hdlc_rx_release(hdlc_rx_state_t *s)
Release an HDLC receiver context.
Definition: hdlc.c:364
int report_flag_underflow
TRUE if the next underflow of timed flag octets should be reported.
Definition: private/hdlc.h:117
int flag_octets
The number of flag octets to send for a timed burst of flags.
Definition: private/hdlc.h:113
@ SIG_STATUS_TRAINING_FAILED
The modem has failed to train.
Definition: async.h:67
#define HDLC_MAXFRAME_LEN
Definition: hdlc.h:46
int report_bad_frames
TRUE if bad frames are to be reported.
Definition: private/hdlc.h:47
int gsm0610_release(gsm0610_state_t *s)
Definition: gsm0610_encode.c:130
void hdlc_rx_set_octet_counting_report_interval(hdlc_rx_state_t *s, int interval)
Set the octet counting report interval.
Definition: hdlc.c:307
@ SIG_STATUS_CARRIER_DOWN
The carrier signal has dropped.
Definition: async.h:54
size_t len
Length of a frame in progress.
Definition: private/hdlc.h:73
hdlc_frame_handler_t frame_handler
The callback routine called to process each good received frame.
Definition: private/hdlc.h:39
int hdlc_tx_corrupt_frame(hdlc_tx_state_t *s)
Corrupt the frame currently being transmitted, by giving it the wrong CRC.
Definition: hdlc.c:450
void hdlc_rx_set_status_handler(hdlc_rx_state_t *s, modem_status_func_t handler, void *user_data)
Change the status report function associated with an HDLC receiver context.
Definition: hdlc.c:357
int octet_count_report_interval
The number of octets to be allowed between octet count reports.
Definition: private/hdlc.h:68
Definition: private/hdlc.h:33
int progressive
TRUE if frame creation works in progressive mode.
Definition: private/hdlc.h:102
size_t max_frame_len
Maximum permitted frame length.
Definition: private/hdlc.h:37
int gsm0610_decode(gsm0610_state_t *s, int16_t amp[], const uint8_t code[], int len)
Definition: gsm0610_decode.c:312
int hdlc_rx_get_stats(hdlc_rx_state_t *s, hdlc_rx_stats_t *t)
Get the current receive statistics.
Definition: hdlc.c:377
unsigned long int rx_bytes
The number of bytes of good frames received (CRC not included).
Definition: private/hdlc.h:76
unsigned long int bytes
The number of bytes of good frames received (CRC not included).
Definition: hdlc.h:62
Definition: private/gsm0610.h:34
int tx_end
TRUE if transmission should end on buffer underflow .
Definition: private/hdlc.h:134
unsigned int raw_bit_stream
The raw (stuffed) bit stream buffer.
Definition: private/hdlc.h:57
hdlc_rx_state_t * hdlc_rx_init(hdlc_rx_state_t *s, int crc32, int report_bad_frames, int framing_ok_threshold, hdlc_frame_handler_t handler, void *user_data)
Initialise an HDLC receiver context.
Definition: hdlc.c:327
uint32_t octets_in_progress
The stuffed bit stream being created.
Definition: private/hdlc.h:107
uint16_t crc_itu16_calc(const uint8_t *buf, int len, uint16_t crc)
Calculate the ITU/CCITT CRC-16 value in buffer by whole bytes.
Definition: crc.c:153
void hdlc_rx_set_frame_handler(hdlc_rx_state_t *s, hdlc_frame_handler_t handler, void *user_data)
Change the put_bit function associated with an HDLC receiver context.
Definition: hdlc.c:350
int32_t vec_min_maxi16(const int16_t x[], int n, int16_t out[])
Find the minimum and maximum values in an int16_t vector.
Definition: vector_int.c:287
int hdlc_tx_frame(hdlc_tx_state_t *s, const uint8_t *frame, size_t len)
Transmit a frame.
Definition: hdlc.c:389
int gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[])
Definition: gsm0610_decode.c:125
hdlc_tx_state_t * hdlc_tx_init(hdlc_tx_state_t *s, int crc32, int inter_frame_flags, int progressive, hdlc_underflow_handler_t handler, void *user_data)
Initialise an HDLC transmitter context.
Definition: hdlc.c:626
void hdlc_rx_set_max_frame_len(hdlc_rx_state_t *s, size_t max_len)
Set the maximum frame length for an HDLC receiver context.
Definition: hdlc.c:300
int32_t vec_dot_prodi16(const int16_t x[], const int16_t y[], int n)
Find the dot product of two int16_t vectors.
Definition: vector_int.c:50
int hdlc_rx_free(hdlc_rx_state_t *s)
Free an HDLC receiver context.
Definition: hdlc.c:370
uint32_t crc_itu32_calc(const uint8_t *buf, int len, uint32_t crc)
Calculate the ITU/CCITT CRC-32 value in buffer.
Definition: crc.c:76
int hdlc_rx_restart(hdlc_rx_state_t *s)
Re-initialise an HDLC receiver context.
Definition: hdlc.c:313
uint8_t buffer[HDLC_MAXFRAME_LEN+4]
Buffer for a frame in progress.
Definition: private/hdlc.h:71
int hdlc_tx_corrupt_frame(hdlc_tx_state_t *s)
Corrupt the frame currently being transmitted, by giving it the wrong CRC.
Definition: hdlc.c:450
int hdlc_tx_free(hdlc_tx_state_t *s)
Free an HDLC transmitter context.
Definition: hdlc.c:665
void * status_user_data
An opaque parameter passed to the status callback routine.
Definition: private/hdlc.h:45
void hdlc_rx_set_status_handler(hdlc_rx_state_t *s, modem_status_func_t handler, void *user_data)
Change the status report function associated with an HDLC receiver context.
Definition: hdlc.c:357
int num_bits
The number of bits currently in octets_in_progress.
Definition: private/hdlc.h:109
int16_t z1
Definition: private/gsm0610.h:41
unsigned long int rx_crc_errors
The number of frames with CRC errors received.
Definition: private/hdlc.h:80
Definition: private/hdlc.h:92
int hdlc_rx_get_stats(hdlc_rx_state_t *s, hdlc_rx_stats_t *t)
Get the current receive statistics.
Definition: hdlc.c:377
int octet_count
Octet count, to achieve the functionality needed for things like MTP.
Definition: private/hdlc.h:66
SPAN_DECLARE_NONSTD(void) hdlc_rx_put_bit(hdlc_rx_state_t *s
Put a single bit of data to an HDLC receiver.
int inter_frame_flags
The minimum flag octets to insert between frames.
Definition: private/hdlc.h:100
unsigned long int crc_errors
The number of frames with CRC errors received.
Definition: hdlc.h:66
hdlc_rx_state_t * hdlc_rx_init(hdlc_rx_state_t *s, int crc32, int report_bad_frames, int framing_ok_threshold, hdlc_frame_handler_t handler, void *user_data)
Initialise an HDLC receiver context.
Definition: hdlc.c:327
@ SIG_STATUS_TRAINING_SUCCEEDED
The modem has trained, and is ready for data exchange.
Definition: async.h:65
int16_t u[8]
Definition: private/gsm0610.h:47
int hdlc_tx_frame(hdlc_tx_state_t *s, const uint8_t *frame, size_t len)
Transmit a frame.
Definition: hdlc.c:389
uint8_t buffer[HDLC_MAXFRAME_LEN+4]
The current message being transmitted, with its CRC attached.
Definition: private/hdlc.h:120
int hdlc_tx_abort(hdlc_tx_state_t *s)
Send an abort.
Definition: hdlc.c:440
@ SIG_STATUS_END_OF_DATA
The data stream has ended.
Definition: async.h:71
int hdlc_tx_flags(hdlc_tx_state_t *s, int len)
Transmit a specified quantity of flag octets, typically as a preamble.
Definition: hdlc.c:424
unsigned long int rx_aborts
The number of HDLC aborts received.
Definition: private/hdlc.h:84
void hdlc_tx_set_max_frame_len(hdlc_tx_state_t *s, size_t max_len)
Set the maximum frame length for an HDLC transmitter context.
Definition: hdlc.c:599
unsigned int byte_in_progress
The destuffed bit stream buffer.
Definition: private/hdlc.h:59