blob: 8f3540c7f6923ff37e0661a196119b0db79304b7 [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.
5 * Neccessary 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)
9 * 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
10 * 2001 Frode Isaksen <fisaksen@bewan.com>
11 * 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020013 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 *
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020018 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020023 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 */
27
28#ifndef __ISDNHDLC_H__
29#define __ISDNHDLC_H__
30
31struct isdnhdlc_vars {
32 int bit_shift;
33 int hdlc_bits1;
34 int data_bits;
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020035 int ffbit_shift; /* encoding only */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 int state;
37 int dstpos;
38
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020039 u16 crc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020041 u8 cbin;
42 u8 shift_reg;
43 u8 ffvalue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020045 /* set if transferring data */
46 u32 data_received:1;
47 /* set if D channel (send idle instead of flags) */
48 u32 dchannel:1;
49 /* set if 56K adaptation */
50 u32 do_adapt56:1;
51 /* set if in closing phase (need to send CRC + flag) */
52 u32 do_closing:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053};
54
55
56/*
57 The return value from isdnhdlc_decode is
58 the frame length, 0 if no complete frame was decoded,
59 or a negative error number
60*/
61#define HDLC_FRAMING_ERROR 1
62#define HDLC_CRC_ERROR 2
63#define HDLC_LENGTH_ERROR 3
64
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020065extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, int do_adapt56);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020067extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src,
68 int slen, int *count, u8 *dst, int dsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020070extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel,
71 int do_adapt56);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Karsten Keil6bd4bcd2009-07-08 19:11:09 +020073extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src,
74 u16 slen, int *count, u8 *dst, int dsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76#endif /* __ISDNHDLC_H__ */