blob: 96521370c782a5e916ef50fea59a07aaab960e3a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Karsten Keil6bd4bcd2009-07-08 19:11:09 +02002 * hdlc.h -- General purpose ISDN HDLC decoder.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Implementation of a HDLC decoder/encoder in software.
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005 * Necessary because some ISDN devices don't have HDLC
Karsten Keil6bd4bcd2009-07-08 19:11:09 +02006 * controllers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Karsten Keil6bd4bcd2009-07-08 19:11:09 +02008 * Copyright (C)
Karsten Keilc38fc3b2009-07-08 20:31:42 +02009 * 2009 Karsten Keil <keil@b1-systems.de>
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020010 * 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
11 * 2001 Frode Isaksen <fisaksen@bewan.com>
12 * 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020014 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 *
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020019 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 *
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020024 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 */
28
29#ifndef __ISDNHDLC_H__
30#define __ISDNHDLC_H__
31
32struct isdnhdlc_vars {
33 int bit_shift;
34 int hdlc_bits1;
35 int data_bits;
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020036 int ffbit_shift; /* encoding only */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 int state;
38 int dstpos;
39
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020040 u16 crc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020042 u8 cbin;
43 u8 shift_reg;
44 u8 ffvalue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020046 /* set if transferring data */
47 u32 data_received:1;
48 /* set if D channel (send idle instead of flags) */
49 u32 dchannel:1;
50 /* set if 56K adaptation */
51 u32 do_adapt56:1;
52 /* set if in closing phase (need to send CRC + flag) */
53 u32 do_closing:1;
Karsten Keilc38fc3b2009-07-08 20:31:42 +020054 /* set if data is bitreverse */
55 u32 do_bitreverse:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056};
57
Karsten Keilc38fc3b2009-07-08 20:31:42 +020058/* Feature Flags */
59#define HDLC_56KBIT 0x01
60#define HDLC_DCHANNEL 0x02
61#define HDLC_BITREVERSE 0x04
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63/*
64 The return value from isdnhdlc_decode is
65 the frame length, 0 if no complete frame was decoded,
66 or a negative error number
67*/
68#define HDLC_FRAMING_ERROR 1
69#define HDLC_CRC_ERROR 2
70#define HDLC_LENGTH_ERROR 3
71
Karsten Keilc38fc3b2009-07-08 20:31:42 +020072extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020074extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src,
75 int slen, int *count, u8 *dst, int dsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Karsten Keilc38fc3b2009-07-08 20:31:42 +020077extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020079extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src,
80 u16 slen, int *count, u8 *dst, int dsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82#endif /* __ISDNHDLC_H__ */