Harald Welte | 85b9fba | 2018-05-11 17:36:13 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * hdlc.h -- General purpose ISDN HDLC decoder. |
| 3 | * |
| 4 | * Implementation of a HDLC decoder/encoder in software. |
| 5 | * Necessary because some ISDN devices don't have HDLC |
| 6 | * controllers. |
| 7 | * |
| 8 | * Copyright (C) |
| 9 | * 2009 Karsten Keil <keil@b1-systems.de> |
| 10 | * 2002 Wolfgang Mües <wolfgang@iksw-muees.de> |
| 11 | * 2001 Frode Isaksen <fisaksen@bewan.com> |
| 12 | * 2001 Kai Germaschewski <kai.germaschewski@gmx.de> |
| 13 | * |
| 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. |
| 18 | * |
| 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. |
| 23 | * |
| 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. |
| 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; |
| 36 | int ffbit_shift; /* encoding only */ |
| 37 | int state; |
| 38 | int dstpos; |
| 39 | |
| 40 | u16 crc; |
| 41 | |
| 42 | u8 cbin; |
| 43 | u8 shift_reg; |
| 44 | u8 ffvalue; |
| 45 | |
| 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; |
| 54 | /* set if data is bitreverse */ |
| 55 | u32 do_bitreverse:1; |
| 56 | }; |
| 57 | |
| 58 | /* Feature Flags */ |
| 59 | #define HDLC_56KBIT 0x01 |
| 60 | #define HDLC_DCHANNEL 0x02 |
| 61 | #define HDLC_BITREVERSE 0x04 |
| 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 | |
| 72 | extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features); |
| 73 | |
| 74 | extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, |
| 75 | int slen, int *count, u8 *dst, int dsize); |
| 76 | |
| 77 | extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features); |
| 78 | |
| 79 | extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, |
| 80 | u16 slen, int *count, u8 *dst, int dsize); |
| 81 | |
| 82 | #endif /* __ISDNHDLC_H__ */ |