isdnhdlc.h File Reference
`#include <stdint.h>`

Go to the source code of this file.

## Data Structures

struct | osmo_isdnhdlc_vars

## Macros

#define | OSMO_HDLC_F_56KBIT 0x01
#define | OSMO_HDLC_F_DCHANNEL 0x02
#define | OSMO_HDLC_F_BITREVERSE 0x04
#define | OSMO_HDLC_FRAMING_ERROR 1
#define | OSMO_HDLC_CRC_ERROR 2
#define | OSMO_HDLC_LENGTH_ERROR 3

## Functions

void | osmo_isdnhdlc_rcv_init (struct osmo_isdnhdlc_vars *hdlc, uint32_t features)
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...
void | osmo_isdnhdlc_out_init (struct osmo_isdnhdlc_vars *hdlc, uint32_t features)
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...

## Macro Definition Documentation

## OSMO_HDLC_CRC_ERROR

#define OSMO_HDLC_CRC_ERROR 2

## OSMO_HDLC_F_56KBIT

#define OSMO_HDLC_F_56KBIT 0x01

## OSMO_HDLC_F_BITREVERSE

#define OSMO_HDLC_F_BITREVERSE 0x04

## OSMO_HDLC_F_DCHANNEL

#define OSMO_HDLC_F_DCHANNEL 0x02

## OSMO_HDLC_FRAMING_ERROR

#define OSMO_HDLC_FRAMING_ERROR 1

## OSMO_HDLC_LENGTH_ERROR

#define OSMO_HDLC_LENGTH_ERROR 3

## Function Documentation

## 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 with the bit HDLC_END_OF_FRAME set. 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 the length with the bit OSMO_HDLC_FRAMING_ERROR set. If a CRC error is found the function returns the length with the bit OSMO_HDLC_CRC_ERROR set. If the frame length exceeds the destination buffer size, the function returns the length with the bit OSMO_HDLC_LENGTH_ERROR set.

Parameters

  [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

Returns
  number of decoded bytes in the destination buffer and status flag.

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.

## osmo_isdnhdlc_encode()

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.

Parameters

  [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

Returns
  - number of encoded bytes in the destination buffer

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, osmo_revbytebits_8(), osmo_isdnhdlc_vars::shift_reg, osmo_isdnhdlc_vars::state, and STOPPED.

## osmo_isdnhdlc_out_init()

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.

## osmo_isdnhdlc_rcv_init()

void osmo_isdnhdlc_rcv_init | ( | struct osmo_isdnhdlc_vars * | hdlc,
|  | uint32_t | features
| ) |  |

References osmo_isdnhdlc_vars::do_adapt56, osmo_isdnhdlc_vars::do_bitreverse, HDLC_GET_DATA, OSMO_HDLC_F_56KBIT, OSMO_HDLC_F_BITREVERSE, and osmo_isdnhdlc_vars::state.