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. |
| 5 | * Neccessary 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) |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame^] | 13 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame^] | 18 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame^] | 23 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #ifndef __ISDNHDLC_H__ |
| 29 | #define __ISDNHDLC_H__ |
| 30 | |
| 31 | struct isdnhdlc_vars { |
| 32 | int bit_shift; |
| 33 | int hdlc_bits1; |
| 34 | int data_bits; |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame^] | 35 | int ffbit_shift; /* encoding only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | int state; |
| 37 | int dstpos; |
| 38 | |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame^] | 39 | u16 crc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame^] | 41 | u8 cbin; |
| 42 | u8 shift_reg; |
| 43 | u8 ffvalue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame^] | 45 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | }; |
| 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 Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame^] | 65 | extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, int do_adapt56); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame^] | 67 | extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, |
| 68 | int slen, int *count, u8 *dst, int dsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame^] | 70 | extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel, |
| 71 | int do_adapt56); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Karsten Keil | 6bd4bcd | 2009-07-08 19:11:09 +0200 | [diff] [blame^] | 73 | extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, |
| 74 | u16 slen, int *count, u8 *dst, int dsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | #endif /* __ISDNHDLC_H__ */ |