libosmocore 1.10.0.9-9764
Osmocom core library
|
#include <string.h>
#include <osmocom/core/crc16.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/isdnhdlc.h>
Macros | |
#define | crc_ccitt_byte osmo_crc16_ccitt_byte |
#define | handle_fast_flag(h) |
#define | handle_abort(h) |
Enumerations | |
enum | { HDLC_FAST_IDLE , HDLC_GET_FLAG_B0 , HDLC_GETFLAG_B1A6 , HDLC_GETFLAG_B7 , HDLC_GET_DATA , HDLC_FAST_FLAG } |
enum | { HDLC_SEND_DATA , HDLC_SEND_CRC1 , HDLC_SEND_FAST_FLAG , HDLC_SEND_FIRST_FLAG , HDLC_SEND_CRC2 , HDLC_SEND_CLOSING_FLAG , HDLC_SEND_IDLE1 , HDLC_SEND_FAST_IDLE , HDLC_SENDFLAG_B0 , HDLC_SENDFLAG_B1A6 , HDLC_SENDFLAG_B7 , STOPPED , HDLC_SENDFLAG_ONE } |
Functions | |
void | osmo_isdnhdlc_rcv_init (struct osmo_isdnhdlc_vars *hdlc, uint32_t features) |
void | osmo_isdnhdlc_out_init (struct osmo_isdnhdlc_vars *hdlc, uint32_t features) |
static int | check_frame (struct osmo_isdnhdlc_vars *hdlc) |
int | osmo_isdnhdlc_decode (struct osmo_isdnhdlc_vars *hdlc, const uint8_t *src, int slen, int *count, uint8_t *dst, int dsize) |
decodes HDLC frames from a transparent bit stream. More... | |
int | osmo_isdnhdlc_encode (struct osmo_isdnhdlc_vars *hdlc, const uint8_t *src, uint16_t slen, int *count, uint8_t *dst, int dsize) |
encodes HDLC frames to a transparent bit stream. More... | |
#define crc_ccitt_byte osmo_crc16_ccitt_byte |
#define handle_abort | ( | h | ) |
#define handle_fast_flag | ( | h | ) |
anonymous enum |
anonymous enum |
|
static |
References osmo_isdnhdlc_vars::crc, osmo_isdnhdlc_vars::dstpos, OSMO_HDLC_CRC_ERROR, and OSMO_HDLC_FRAMING_ERROR.
Referenced by osmo_isdnhdlc_decode().
int osmo_isdnhdlc_decode | ( | struct osmo_isdnhdlc_vars * | hdlc, |
const uint8_t * | src, | ||
int | slen, | ||
int * | count, | ||
uint8_t * | dst, | ||
int | dsize | ||
) |
decodes HDLC frames from a transparent bit stream.
The source buffer is scanned for valid HDLC frames looking for flags (01111110) to indicate the start of a frame. If the start of the frame is found, the bit stuffing is removed (0 after 5 1's). When a new flag is found, the complete frame has been received and the CRC is checked. If a valid frame is found, the function returns the frame length excluding the CRC. If the beginning of a valid frame is found, the function returns the length. If a framing error is found (too many 1s and not a flag) the function returns -OSMO_HDLC_FRAMING_ERROR. If a CRC error is found the function returns -OSMO_HDLC_CRC_ERROR. If the frame length exceeds the destination buffer size, the function returns the length with the bit OSMO_HDLC_LENGTH_ERROR set.
[in] | src | source buffer |
[in] | slen | source buffer length |
[out] | count | number of bytes removed (decoded) from the source buffer |
[out] | dst | destination buffer |
[in] | dsize | destination buffer size |
References osmo_isdnhdlc_vars::bit_shift, osmo_isdnhdlc_vars::cbin, check_frame(), osmo_isdnhdlc_vars::crc, crc_ccitt_byte, osmo_isdnhdlc_vars::data_bits, osmo_isdnhdlc_vars::data_received, osmo_isdnhdlc_vars::do_adapt56, osmo_isdnhdlc_vars::do_bitreverse, osmo_isdnhdlc_vars::dstpos, osmo_isdnhdlc_vars::ffbit_shift, osmo_isdnhdlc_vars::ffvalue, handle_abort, handle_fast_flag, osmo_isdnhdlc_vars::hdlc_bits1, HDLC_FAST_FLAG, HDLC_FAST_IDLE, HDLC_GET_DATA, HDLC_GET_FLAG_B0, HDLC_GETFLAG_B1A6, HDLC_GETFLAG_B7, OSMO_HDLC_FRAMING_ERROR, OSMO_HDLC_LENGTH_ERROR, osmo_revbytebits_8(), osmo_isdnhdlc_vars::shift_reg, osmo_isdnhdlc_vars::state, and STOPPED.
int osmo_isdnhdlc_encode | ( | struct osmo_isdnhdlc_vars * | hdlc, |
const uint8_t * | src, | ||
uint16_t | slen, | ||
int * | count, | ||
uint8_t * | dst, | ||
int | dsize | ||
) |
encodes HDLC frames to a transparent bit stream.
The bit stream starts with a beginning flag (01111110). After that each byte is added to the bit stream with bit stuffing added (0 after 5 1's). When the last byte has been removed from the source buffer, the CRC (2 bytes is added) and the frame terminates with the ending flag. For the dchannel, the idle character (all 1's) is also added at the end. If this function is called with empty source buffer (slen=0), flags or idle character will be generated.
[in] | src | source buffer |
[in] | slen | source buffer length |
[out] | count | number of bytes removed (encoded) from source buffer |
[out] | dst | destination buffer |
[in] | dsize | destination buffer size |
References osmo_isdnhdlc_vars::bit_shift, osmo_isdnhdlc_vars::cbin, osmo_isdnhdlc_vars::crc, crc_ccitt_byte, osmo_isdnhdlc_vars::data_bits, osmo_isdnhdlc_vars::data_received, osmo_isdnhdlc_vars::dchannel, osmo_isdnhdlc_vars::do_adapt56, osmo_isdnhdlc_vars::do_bitreverse, osmo_isdnhdlc_vars::do_closing, osmo_isdnhdlc_vars::ffvalue, osmo_isdnhdlc_vars::hdlc_bits1, HDLC_SEND_CLOSING_FLAG, HDLC_SEND_CRC1, HDLC_SEND_CRC2, HDLC_SEND_DATA, HDLC_SEND_FAST_FLAG, HDLC_SEND_FAST_IDLE, HDLC_SEND_FIRST_FLAG, HDLC_SEND_IDLE1, HDLC_SENDFLAG_B0, HDLC_SENDFLAG_B1A6, HDLC_SENDFLAG_B7, HDLC_SENDFLAG_ONE, len(), osmo_revbytebits_8(), osmo_isdnhdlc_vars::shift_reg, osmo_isdnhdlc_vars::state, and STOPPED.
void osmo_isdnhdlc_out_init | ( | struct osmo_isdnhdlc_vars * | hdlc, |
uint32_t | features | ||
) |
References osmo_isdnhdlc_vars::cbin, osmo_isdnhdlc_vars::data_bits, osmo_isdnhdlc_vars::dchannel, osmo_isdnhdlc_vars::do_adapt56, osmo_isdnhdlc_vars::do_bitreverse, osmo_isdnhdlc_vars::ffvalue, HDLC_SEND_FAST_FLAG, HDLC_SEND_FIRST_FLAG, HDLC_SENDFLAG_B0, OSMO_HDLC_F_56KBIT, OSMO_HDLC_F_BITREVERSE, OSMO_HDLC_F_DCHANNEL, and osmo_isdnhdlc_vars::state.
void osmo_isdnhdlc_rcv_init | ( | struct osmo_isdnhdlc_vars * | hdlc, |
uint32_t | features | ||
) |