blob: fe2c1279c13960226356676a70ddbd9aa86de03a [file] [log] [blame]
Thomas Gleixner74ba9202019-05-20 09:19:02 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Karsten Keil6bd4bcd2009-07-08 19:11:09 +02003 * hdlc.h -- General purpose ISDN HDLC decoder.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * Implementation of a HDLC decoder/encoder in software.
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006 * Necessary because some ISDN devices don't have HDLC
Karsten Keil6bd4bcd2009-07-08 19:11:09 +02007 * controllers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Karsten Keil6bd4bcd2009-07-08 19:11:09 +02009 * Copyright (C)
Karsten Keilc38fc3b2009-07-08 20:31:42 +020010 * 2009 Karsten Keil <keil@b1-systems.de>
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020011 * 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
12 * 2001 Frode Isaksen <fisaksen@bewan.com>
13 * 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 */
15
16#ifndef __ISDNHDLC_H__
17#define __ISDNHDLC_H__
18
19struct isdnhdlc_vars {
20 int bit_shift;
21 int hdlc_bits1;
22 int data_bits;
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020023 int ffbit_shift; /* encoding only */
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 int state;
25 int dstpos;
26
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020027 u16 crc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020029 u8 cbin;
30 u8 shift_reg;
31 u8 ffvalue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020033 /* set if transferring data */
34 u32 data_received:1;
35 /* set if D channel (send idle instead of flags) */
36 u32 dchannel:1;
37 /* set if 56K adaptation */
38 u32 do_adapt56:1;
39 /* set if in closing phase (need to send CRC + flag) */
40 u32 do_closing:1;
Karsten Keilc38fc3b2009-07-08 20:31:42 +020041 /* set if data is bitreverse */
42 u32 do_bitreverse:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043};
44
Karsten Keilc38fc3b2009-07-08 20:31:42 +020045/* Feature Flags */
46#define HDLC_56KBIT 0x01
47#define HDLC_DCHANNEL 0x02
48#define HDLC_BITREVERSE 0x04
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50/*
51 The return value from isdnhdlc_decode is
52 the frame length, 0 if no complete frame was decoded,
53 or a negative error number
54*/
55#define HDLC_FRAMING_ERROR 1
56#define HDLC_CRC_ERROR 2
57#define HDLC_LENGTH_ERROR 3
58
Karsten Keilc38fc3b2009-07-08 20:31:42 +020059extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020061extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src,
62 int slen, int *count, u8 *dst, int dsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Karsten Keilc38fc3b2009-07-08 20:31:42 +020064extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020066extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src,
67 u16 slen, int *count, u8 *dst, int dsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#endif /* __ISDNHDLC_H__ */