Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 2 | * hdlc.h -- General purpose ISDN HDLC decoder. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Implementation of a HDLC decoder/encoder in software. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5 | * Necessary because some ISDN devices don't have HDLC |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 6 | * controllers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 8 | * Copyright (C) |
Karsten Keil | c38fc3b | 2009-07-08 20:31:42 +0200 | [diff] [blame] | 9 | * 2009 Karsten Keil <keil@b1-systems.de> |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 10 | * 2002 Wolfgang Mües <wolfgang@iksw-muees.de> |
| 11 | * 2001 Frode Isaksen <fisaksen@bewan.com> |
| 12 | * 2001 Kai Germaschewski <kai.germaschewski@gmx.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #ifndef __ISDNHDLC_H__ |
| 30 | #define __ISDNHDLC_H__ |
| 31 | |
| 32 | struct isdnhdlc_vars { |
| 33 | int bit_shift; |
| 34 | int hdlc_bits1; |
| 35 | int data_bits; |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 36 | int ffbit_shift; /* encoding only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | int state; |
| 38 | int dstpos; |
| 39 | |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 40 | u16 crc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 42 | u8 cbin; |
| 43 | u8 shift_reg; |
| 44 | u8 ffvalue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 46 | /* 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 Keil | c38fc3b | 2009-07-08 20:31:42 +0200 | [diff] [blame] | 54 | /* set if data is bitreverse */ |
| 55 | u32 do_bitreverse:1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Karsten Keil | c38fc3b | 2009-07-08 20:31:42 +0200 | [diff] [blame] | 58 | /* Feature Flags */ |
| 59 | #define HDLC_56KBIT 0x01 |
| 60 | #define HDLC_DCHANNEL 0x02 |
| 61 | #define HDLC_BITREVERSE 0x04 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 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 Keil | c38fc3b | 2009-07-08 20:31:42 +0200 | [diff] [blame] | 72 | extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 74 | extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, |
| 75 | int slen, int *count, u8 *dst, int dsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Karsten Keil | c38fc3b | 2009-07-08 20:31:42 +0200 | [diff] [blame] | 77 | extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame] | 79 | extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, |
| 80 | u16 slen, int *count, u8 *dst, int dsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | #endif /* __ISDNHDLC_H__ */ |