Loading...
Searching...
No Matches
isdnhdlc.c File Reference
`#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.
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.

## Macro Definition Documentation

## crc_ccitt_byte

#define crc_ccitt_byte osmo_crc16_ccitt_byte

## handle_abort

#define handle_abort | ( |  | h | ) |

Value:
do { \
h->shift_reg = fast_abort[h->ffbit_shift - 1]; \
h->hdlc_bits1 = h->ffbit_shift - 2; \
if (h->hdlc_bits1 < 0) \
h->hdlc_bits1 = 0; \
h->data_bits = h->ffbit_shift - 1; \
h->state = HDLC_GET_DATA; \
h->data_received = 0; \
} while (0)
h
struct gad_raw_head h
subsys
char subsys[16]
logging sub-system
Definition gsmtap.h:9
HDLC_GET_DATA
@ HDLC_GET_DATA
Definition isdnhdlc.c:31

## handle_fast_flag

#define handle_fast_flag | ( |  | h | ) |

Value:
do { \
if (h->cbin == fast_flag[h->bit_shift]) { \
h->ffvalue = fast_flag_value[h->bit_shift]; \
h->state = HDLC_FAST_FLAG; \
h->ffbit_shift = h->bit_shift; \
h->bit_shift = 1; \
} else { \
h->state = HDLC_GET_DATA; \
h->data_received = 0; \
} \
} while (0)
HDLC_FAST_FLAG
@ HDLC_FAST_FLAG
Definition isdnhdlc.c:31

## Enumeration Type Documentation

## anonymous enum

anonymous enum

Enumerator
HDLC_FAST_IDLE |
HDLC_GET_FLAG_B0 |
HDLC_GETFLAG_B1A6 |
HDLC_GETFLAG_B7 |
HDLC_GET_DATA |
HDLC_FAST_FLAG |

## anonymous enum

anonymous enum

Enumerator
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 |

## Function Documentation

## check_frame()

static int check_frame | ( | struct osmo_isdnhdlc_vars * | hdlc | ) |

static

References osmo_isdnhdlc_vars::crc, osmo_isdnhdlc_vars::dstpos, OSMO_HDLC_CRC_ERROR, and OSMO_HDLC_FRAMING_ERROR.

Referenced by osmo_isdnhdlc_decode().

## 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.

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, len, 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.