^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * hdlc.h -- General purpose ISDN HDLC decoder.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Implementation of a HDLC decoder/encoder in software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Necessary because some ISDN devices don't have HDLC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * controllers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * 2009 Karsten Keil <keil@b1-systems.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * 2001 Frode Isaksen <fisaksen@bewan.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #ifndef __ISDNHDLC_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define __ISDNHDLC_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct isdnhdlc_vars {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) int bit_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) int hdlc_bits1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int data_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int ffbit_shift; /* encoding only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int dstpos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) u16 crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) u8 cbin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u8 shift_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u8 ffvalue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* set if transferring data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) u32 data_received:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* set if D channel (send idle instead of flags) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u32 dchannel:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* set if 56K adaptation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u32 do_adapt56:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* set if in closing phase (need to send CRC + flag) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u32 do_closing:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* set if data is bitreverse */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u32 do_bitreverse:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* Feature Flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define HDLC_56KBIT 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define HDLC_DCHANNEL 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define HDLC_BITREVERSE 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) The return value from isdnhdlc_decode is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) the frame length, 0 if no complete frame was decoded,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) or a negative error number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define HDLC_FRAMING_ERROR 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define HDLC_CRC_ERROR 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define HDLC_LENGTH_ERROR 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int slen, int *count, u8 *dst, int dsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u16 slen, int *count, u8 *dst, int dsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #endif /* __ISDNHDLC_H__ */