libosmocore  1.5.1
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  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  */
28 
29 #ifndef __ISDNHDLC_H__
30 #define __ISDNHDLC_H__
31 
32 #include <stdint.h>
33 
35  int bit_shift;
37  int data_bits;
38  int ffbit_shift; /* encoding only */
39  int state;
40  int dstpos;
41 
42  uint16_t crc;
43 
44  uint8_t cbin;
45  uint8_t shift_reg;
46  uint8_t ffvalue;
47 
48  /* set if transferring data */
49  uint32_t data_received:1;
50  /* set if D channel (send idle instead of flags) */
51  uint32_t dchannel:1;
52  /* set if 56K adaptation */
53  uint32_t do_adapt56:1;
54  /* set if in closing phase (need to send CRC + flag) */
55  uint32_t do_closing:1;
56  /* set if data is bitreverse */
57  uint32_t do_bitreverse:1;
58 };
59 
60 /* Feature Flags */
61 #define OSMO_HDLC_F_56KBIT 0x01
62 #define OSMO_HDLC_F_DCHANNEL 0x02
63 #define OSMO_HDLC_F_BITREVERSE 0x04
64 
65 /*
66  The return value from isdnhdlc_decode is
67  the frame length, 0 if no complete frame was decoded,
68  or a negative error number
69 */
70 #define OSMO_HDLC_FRAMING_ERROR 1
71 #define OSMO_HDLC_CRC_ERROR 2
72 #define OSMO_HDLC_LENGTH_ERROR 3
73 
74 extern void osmo_isdnhdlc_rcv_init(struct osmo_isdnhdlc_vars *hdlc, uint32_t features);
75 
76 extern int osmo_isdnhdlc_decode(struct osmo_isdnhdlc_vars *hdlc, const uint8_t *src,
77  int slen, int *count, uint8_t *dst, int dsize);
78 
79 extern void osmo_isdnhdlc_out_init(struct osmo_isdnhdlc_vars *hdlc, uint32_t features);
80 
81 extern int osmo_isdnhdlc_encode(struct osmo_isdnhdlc_vars *hdlc, const uint8_t *src,
82  uint16_t slen, int *count, uint8_t *dst, int dsize);
83 
84 #endif /* __ISDNHDLC_H__ */
osmo_isdnhdlc_rcv_init
void osmo_isdnhdlc_rcv_init(struct osmo_isdnhdlc_vars *hdlc, uint32_t features)
Definition: isdnhdlc.c:47
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.
Definition: isdnhdlc.c:342
osmo_isdnhdlc_vars
Definition: isdnhdlc.h:34
osmo_isdnhdlc_vars::ffvalue
uint8_t ffvalue
Definition: isdnhdlc.h:46
osmo_isdnhdlc_vars::hdlc_bits1
int hdlc_bits1
Definition: isdnhdlc.h:36
osmo_isdnhdlc_vars::do_adapt56
uint32_t do_adapt56
Definition: isdnhdlc.h:53
osmo_isdnhdlc_vars::data_received
uint32_t data_received
Definition: isdnhdlc.h:49
osmo_isdnhdlc_vars::cbin
uint8_t cbin
Definition: isdnhdlc.h:44
osmo_isdnhdlc_vars::data_bits
int data_bits
Definition: isdnhdlc.h:37
osmo_isdnhdlc_vars::bit_shift
int bit_shift
Definition: isdnhdlc.h:35
osmo_isdnhdlc_vars::crc
uint16_t crc
Definition: isdnhdlc.h:42
osmo_isdnhdlc_vars::state
int state
Definition: isdnhdlc.h:39
osmo_isdnhdlc_vars::dchannel
uint32_t dchannel
Definition: isdnhdlc.h:51
osmo_isdnhdlc_vars::dstpos
int dstpos
Definition: isdnhdlc.h:40
osmo_isdnhdlc_out_init
void osmo_isdnhdlc_out_init(struct osmo_isdnhdlc_vars *hdlc, uint32_t features)
Definition: isdnhdlc.c:57
osmo_isdnhdlc_vars::do_bitreverse
uint32_t do_bitreverse
Definition: isdnhdlc.h:57
osmo_isdnhdlc_vars::shift_reg
uint8_t shift_reg
Definition: isdnhdlc.h:45
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.
Definition: isdnhdlc.c:121
osmo_isdnhdlc_vars::ffbit_shift
int ffbit_shift
Definition: isdnhdlc.h:38
osmo_isdnhdlc_vars::do_closing
uint32_t do_closing
Definition: isdnhdlc.h:55