hdlc.c File Reference

#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include "spandsp/telephony.h"
#include "spandsp/power_meter.h"
#include "spandsp/async.h"
#include "spandsp/hdlc.h"
#include "spandsp/fsk.h"
#include "spandsp/bit_operations.h"
#include "spandsp/timing.h"

Functions

uint32_t crc_itu32_calc (const uint8_t *buf, int len, uint32_t crc)
 Calculate the ITU/CCITT CRC-32 value in buffer.
int crc_itu32_append (uint8_t *buf, int len)
 Append an ITU/CCITT CRC-32 value to a frame.
int crc_itu32_check (const uint8_t *buf, int len)
 Check the ITU/CCITT CRC-32 value in a frame.
uint16_t crc_itu16_calc (const uint8_t *buf, int len, uint16_t crc)
 Calculate the ITU/CCITT CRC-16 value in buffer.
int crc_itu16_append (uint8_t *buf, int len)
 Append an ITU/CCITT CRC-16 value to a frame.
int crc_itu16_check (const uint8_t *buf, int len)
 Check the ITU/CCITT CRC-16 value in a frame.
void hdlc_rx_put_bit (hdlc_rx_state_t *s, int new_bit)
void hdlc_rx_put_byte (hdlc_rx_state_t *s, int new_byte)
int hdlc_tx_frame (hdlc_tx_state_t *s, const uint8_t *frame, int len)
 Transmit a frame.
int hdlc_tx_preamble (hdlc_tx_state_t *s, int len)
 Transmit a specified quantity of flag octets as a preamble.
int hdlc_tx_corrupt_frame (hdlc_tx_state_t *s)
 Corrupt the frame currently being transmitted, by giving it the wrong CRC.
int hdlc_tx_get_byte (hdlc_tx_state_t *s)
 Get the next byte for transmission.
int hdlc_tx_get_bit (hdlc_tx_state_t *s)
 Get the next bit for transmission.
hdlc_rx_state_thdlc_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.
int hdlc_rx_get_stats (hdlc_rx_state_t *s, hdlc_rx_stats_t *t)
 Get the current receive statistics.
void hdlc_tx_set_max_frame_len (hdlc_tx_state_t *s, int max_len)
 Set the maximum frame length for an HDLC transmitter context.
hdlc_tx_state_thdlc_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.

Detailed Description


Function Documentation

int crc_itu16_append ( uint8_t *  buf,
int  len 
)

Append an ITU/CCITT CRC-16 value to a frame.

Parameters:
buf The buffer containing the frame. This must be at least 2 bytes longer than the frame it contains, to allow room for the CRC value.
len The length of the frame.
Returns:
The new length of the frame.

uint16_t crc_itu16_calc ( const uint8_t *  buf,
int  len,
uint16_t  crc 
)

Calculate the ITU/CCITT CRC-16 value in buffer.

Parameters:
buf The buffer containing the data.
len The length of the frame.
crc The initial CRC value. This is usually 0xFFFF, or 0 for a new block (it depends on the application). It is previous returned CRC value for the continuation of a block.
Returns:
The CRC value.

int crc_itu16_check ( const uint8_t *  buf,
int  len 
)

Check the ITU/CCITT CRC-16 value in a frame.

Parameters:
buf The buffer containing the frame.
len The length of the frame.
Returns:
TRUE if the CRC is OK, else FALSE.

int crc_itu32_append ( uint8_t *  buf,
int  len 
)

Append an ITU/CCITT CRC-32 value to a frame.

Parameters:
buf The buffer containing the frame. This must be at least 2 bytes longer than the frame it contains, to allow room for the CRC value.
len The length of the frame.
Returns:
The new length of the frame.

uint32_t crc_itu32_calc ( const uint8_t *  buf,
int  len,
uint32_t  crc 
)

Calculate the ITU/CCITT CRC-32 value in buffer.

Parameters:
buf The buffer containing the data.
len The length of the frame.
crc The initial CRC value. This is usually 0xFFFFFFFF, or 0 for a new block (it depends on the application). It is previous returned CRC value for the continuation of a block.
Returns:
The CRC value.

int crc_itu32_check ( const uint8_t *  buf,
int  len 
)

Check the ITU/CCITT CRC-32 value in a frame.

Parameters:
buf The buffer containing the frame.
len The length of the frame.
Returns:
TRUE if the CRC is OK, else FALSE.

int hdlc_rx_get_stats ( hdlc_rx_state_t s,
hdlc_rx_stats_t t 
)

Get the current receive statistics.

Parameters:
s A pointer to an HDLC receiver context.
t A pointer to the buffer for the statistics.
Returns:
0 for OK, else -1.

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.

Parameters:
s A pointer to an HDLC receiver context.
crc32 TRUE to use ITU CRC32. FALSE to use ITU CRC16.
report_bad_frames TRUE to request the reporting of bad frames.
framing_ok_threshold The number of back-to-back flags needed to start the framing OK condition. This may be used where a series of flag octets is used as a preamble, such as in the T.30 protocol.
handler The function to be called when a good HDLC frame is received.
user_data An opaque parameter for the callback routine.
Returns:
A pointer to the HDLC receiver context.

int hdlc_tx_corrupt_frame ( hdlc_tx_state_t s  ) 

Corrupt the frame currently being transmitted, by giving it the wrong CRC.

Parameters:
s A pointer to an HDLC transmitter context.
Returns:
0 if the frame was corrupted, else -1.

int hdlc_tx_frame ( hdlc_tx_state_t s,
const uint8_t *  frame,
int  len 
)

Transmit a frame.

Parameters:
s A pointer to an HDLC transmitter context.
frame A pointer to the frame to be transmitted.
len The length of the frame to be transmitted.
Returns:
0 if the frame was accepted for transmission, else -1.

int hdlc_tx_get_bit ( hdlc_tx_state_t s  ) 

Get the next bit for transmission.

Parameters:
s A pointer to an HDLC transmitter context.
Returns:
The next bit for transmission.

int hdlc_tx_get_byte ( hdlc_tx_state_t s  ) 

Get the next byte for transmission.

Parameters:
s A pointer to an HDLC transmitter context.
Returns:
The next byte for transmission.

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.

Parameters:
s A pointer to an HDLC transmitter context.
crc32 TRUE to use ITU CRC32. FALSE to use ITU CRC16.
inter_frame_flags The minimum flag octets to insert between frames (usually one).
progressive TRUE if frame creation works in progressive mode.
handler The callback function called when the HDLC transmitter underflows.
user_data An opaque parameter for the callback routine.
Returns:
A pointer to the HDLC transmitter context.

int hdlc_tx_preamble ( hdlc_tx_state_t s,
int  len 
)

Transmit a specified quantity of flag octets as a preamble.

Parameters:
s A pointer to an HDLC transmitter context.
len The length of the required preamble, in flag octets. If len is zero this requests that HDLC transmission be terminated when the buffers have fully drained.
Returns:
0 if the preamble was accepted for transmission, else -1.

void hdlc_tx_set_max_frame_len ( hdlc_tx_state_t s,
int  max_len 
)

Set the maximum frame length for an HDLC transmitter context.

Parameters:
s A pointer to an HDLC transmitter context.
max_len The maximum length.


Generated on Tue Jul 24 11:29:29 2007 for libspandsp by  doxygen 1.5.2