libosmocore 1.6.0.113-b17c
Osmocom core library
isdnhdlc.h
Go to the documentation of this file.
1/*
2 * isdnhdlc.h -- General purpose ISDN HDLC decoder.
3 *
4 * Implementation of a HDLC decoder/encoder in software.
5 * Necessary because some ISDN devices don't have HDLC
6 * controllers.
7 *
8 * Copyright (C)
9 * 2009 Karsten Keil <keil@b1-systems.de>
10 * 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
11 * 2001 Frode Isaksen <fisaksen@bewan.com>
12 * 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 */
24
25#ifndef __ISDNHDLC_H__
26#define __ISDNHDLC_H__
27
28#include <stdint.h>
29
34 int ffbit_shift; /* encoding only */
35 int state;
36 int dstpos;
37
38 uint16_t crc;
39
40 uint8_t cbin;
41 uint8_t shift_reg;
42 uint8_t ffvalue;
43
44 /* set if transferring data */
45 uint32_t data_received:1;
46 /* set if D channel (send idle instead of flags) */
47 uint32_t dchannel:1;
48 /* set if 56K adaptation */
49 uint32_t do_adapt56:1;
50 /* set if in closing phase (need to send CRC + flag) */
51 uint32_t do_closing:1;
52 /* set if data is bitreverse */
53 uint32_t do_bitreverse:1;
54};
55
56/* Feature Flags */
57#define OSMO_HDLC_F_56KBIT 0x01
58#define OSMO_HDLC_F_DCHANNEL 0x02
59#define OSMO_HDLC_F_BITREVERSE 0x04
60
61/*
62 The return value from isdnhdlc_decode is
63 the frame length, 0 if no complete frame was decoded,
64 or a negative error number
65*/
66#define OSMO_HDLC_FRAMING_ERROR 1
67#define OSMO_HDLC_CRC_ERROR 2
68#define OSMO_HDLC_LENGTH_ERROR 3
69
70extern void osmo_isdnhdlc_rcv_init(struct osmo_isdnhdlc_vars *hdlc, uint32_t features);
71
72extern int osmo_isdnhdlc_decode(struct osmo_isdnhdlc_vars *hdlc, const uint8_t *src,
73 int slen, int *count, uint8_t *dst, int dsize);
74
75extern void osmo_isdnhdlc_out_init(struct osmo_isdnhdlc_vars *hdlc, uint32_t features);
76
77extern int osmo_isdnhdlc_encode(struct osmo_isdnhdlc_vars *hdlc, const uint8_t *src,
78 uint16_t slen, int *count, uint8_t *dst, int dsize);
79
80#endif /* __ISDNHDLC_H__ */
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.
Definition: isdnhdlc.c:338
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.
Definition: isdnhdlc.c:117
void osmo_isdnhdlc_rcv_init(struct osmo_isdnhdlc_vars *hdlc, uint32_t features)
Definition: isdnhdlc.c:43
void osmo_isdnhdlc_out_init(struct osmo_isdnhdlc_vars *hdlc, uint32_t features)
Definition: isdnhdlc.c:53
Definition: isdnhdlc.h:30
uint32_t do_adapt56
Definition: isdnhdlc.h:49
uint16_t crc
Definition: isdnhdlc.h:38
int hdlc_bits1
Definition: isdnhdlc.h:32
int dstpos
Definition: isdnhdlc.h:36
int ffbit_shift
Definition: isdnhdlc.h:34
uint32_t data_received
Definition: isdnhdlc.h:45
uint32_t do_closing
Definition: isdnhdlc.h:51
uint8_t cbin
Definition: isdnhdlc.h:40
uint8_t ffvalue
Definition: isdnhdlc.h:42
uint8_t shift_reg
Definition: isdnhdlc.h:41
int bit_shift
Definition: isdnhdlc.h:31
uint32_t dchannel
Definition: isdnhdlc.h:47
uint32_t do_bitreverse
Definition: isdnhdlc.h:53
int state
Definition: isdnhdlc.h:35
int data_bits
Definition: isdnhdlc.h:33