xref: /linux/drivers/isdn/hardware/mISDN/isdnhdlc.h (revision 8a7e8ff8ce8ae7d34ed979f41b572bfe7cab421c)
1*8a7e8ff8SDavid S. Miller /* SPDX-License-Identifier: GPL-2.0-or-later */
299c2aa15SArnd Bergmann /*
399c2aa15SArnd Bergmann  * hdlc.h  --  General purpose ISDN HDLC decoder.
499c2aa15SArnd Bergmann  *
599c2aa15SArnd Bergmann  * Implementation of a HDLC decoder/encoder in software.
699c2aa15SArnd Bergmann  * Necessary because some ISDN devices don't have HDLC
799c2aa15SArnd Bergmann  * controllers.
899c2aa15SArnd Bergmann  *
999c2aa15SArnd Bergmann  * Copyright (C)
1099c2aa15SArnd Bergmann  *	2009	Karsten Keil		<keil@b1-systems.de>
1199c2aa15SArnd Bergmann  *	2002	Wolfgang Mües		<wolfgang@iksw-muees.de>
1299c2aa15SArnd Bergmann  *	2001	Frode Isaksen		<fisaksen@bewan.com>
1399c2aa15SArnd Bergmann  *	2001	Kai Germaschewski	<kai.germaschewski@gmx.de>
1499c2aa15SArnd Bergmann  */
1599c2aa15SArnd Bergmann 
1699c2aa15SArnd Bergmann #ifndef __ISDNHDLC_H__
1799c2aa15SArnd Bergmann #define __ISDNHDLC_H__
1899c2aa15SArnd Bergmann 
1999c2aa15SArnd Bergmann struct isdnhdlc_vars {
2099c2aa15SArnd Bergmann 	int bit_shift;
2199c2aa15SArnd Bergmann 	int hdlc_bits1;
2299c2aa15SArnd Bergmann 	int data_bits;
2399c2aa15SArnd Bergmann 	int ffbit_shift;	/* encoding only */
2499c2aa15SArnd Bergmann 	int state;
2599c2aa15SArnd Bergmann 	int dstpos;
2699c2aa15SArnd Bergmann 
2799c2aa15SArnd Bergmann 	u16 crc;
2899c2aa15SArnd Bergmann 
2999c2aa15SArnd Bergmann 	u8 cbin;
3099c2aa15SArnd Bergmann 	u8 shift_reg;
3199c2aa15SArnd Bergmann 	u8 ffvalue;
3299c2aa15SArnd Bergmann 
3399c2aa15SArnd Bergmann 	/* set if transferring data */
3499c2aa15SArnd Bergmann 	u32 data_received:1;
3599c2aa15SArnd Bergmann 	/* set if D channel (send idle instead of flags) */
3699c2aa15SArnd Bergmann 	u32 dchannel:1;
3799c2aa15SArnd Bergmann 	/* set if 56K adaptation */
3899c2aa15SArnd Bergmann 	u32 do_adapt56:1;
3999c2aa15SArnd Bergmann 	/* set if in closing phase (need to send CRC + flag) */
4099c2aa15SArnd Bergmann 	u32 do_closing:1;
4199c2aa15SArnd Bergmann 	/* set if data is bitreverse */
4299c2aa15SArnd Bergmann 	u32 do_bitreverse:1;
4399c2aa15SArnd Bergmann };
4499c2aa15SArnd Bergmann 
4599c2aa15SArnd Bergmann /* Feature Flags */
4699c2aa15SArnd Bergmann #define HDLC_56KBIT	0x01
4799c2aa15SArnd Bergmann #define HDLC_DCHANNEL	0x02
4899c2aa15SArnd Bergmann #define HDLC_BITREVERSE	0x04
4999c2aa15SArnd Bergmann 
5099c2aa15SArnd Bergmann /*
5199c2aa15SArnd Bergmann   The return value from isdnhdlc_decode is
5299c2aa15SArnd Bergmann   the frame length, 0 if no complete frame was decoded,
5399c2aa15SArnd Bergmann   or a negative error number
5499c2aa15SArnd Bergmann */
5599c2aa15SArnd Bergmann #define HDLC_FRAMING_ERROR     1
5699c2aa15SArnd Bergmann #define HDLC_CRC_ERROR         2
5799c2aa15SArnd Bergmann #define HDLC_LENGTH_ERROR      3
5899c2aa15SArnd Bergmann 
5999c2aa15SArnd Bergmann extern void	isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features);
6099c2aa15SArnd Bergmann 
6199c2aa15SArnd Bergmann extern int	isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src,
6299c2aa15SArnd Bergmann 			int slen, int *count, u8 *dst, int dsize);
6399c2aa15SArnd Bergmann 
6499c2aa15SArnd Bergmann extern void	isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features);
6599c2aa15SArnd Bergmann 
6699c2aa15SArnd Bergmann extern int	isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src,
6799c2aa15SArnd Bergmann 			u16 slen, int *count, u8 *dst, int dsize);
6899c2aa15SArnd Bergmann 
6999c2aa15SArnd Bergmann #endif /* __ISDNHDLC_H__ */
70