18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * hdlc.h  --  General purpose ISDN HDLC decoder.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Implementation of a HDLC decoder/encoder in software.
68c2ecf20Sopenharmony_ci * Necessary because some ISDN devices don't have HDLC
78c2ecf20Sopenharmony_ci * controllers.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Copyright (C)
108c2ecf20Sopenharmony_ci *	2009	Karsten Keil		<keil@b1-systems.de>
118c2ecf20Sopenharmony_ci *	2002	Wolfgang Mües		<wolfgang@iksw-muees.de>
128c2ecf20Sopenharmony_ci *	2001	Frode Isaksen		<fisaksen@bewan.com>
138c2ecf20Sopenharmony_ci *	2001	Kai Germaschewski	<kai.germaschewski@gmx.de>
148c2ecf20Sopenharmony_ci */
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#ifndef __ISDNHDLC_H__
178c2ecf20Sopenharmony_ci#define __ISDNHDLC_H__
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistruct isdnhdlc_vars {
208c2ecf20Sopenharmony_ci	int bit_shift;
218c2ecf20Sopenharmony_ci	int hdlc_bits1;
228c2ecf20Sopenharmony_ci	int data_bits;
238c2ecf20Sopenharmony_ci	int ffbit_shift;	/* encoding only */
248c2ecf20Sopenharmony_ci	int state;
258c2ecf20Sopenharmony_ci	int dstpos;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	u16 crc;
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	u8 cbin;
308c2ecf20Sopenharmony_ci	u8 shift_reg;
318c2ecf20Sopenharmony_ci	u8 ffvalue;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	/* set if transferring data */
348c2ecf20Sopenharmony_ci	u32 data_received:1;
358c2ecf20Sopenharmony_ci	/* set if D channel (send idle instead of flags) */
368c2ecf20Sopenharmony_ci	u32 dchannel:1;
378c2ecf20Sopenharmony_ci	/* set if 56K adaptation */
388c2ecf20Sopenharmony_ci	u32 do_adapt56:1;
398c2ecf20Sopenharmony_ci	/* set if in closing phase (need to send CRC + flag) */
408c2ecf20Sopenharmony_ci	u32 do_closing:1;
418c2ecf20Sopenharmony_ci	/* set if data is bitreverse */
428c2ecf20Sopenharmony_ci	u32 do_bitreverse:1;
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* Feature Flags */
468c2ecf20Sopenharmony_ci#define HDLC_56KBIT	0x01
478c2ecf20Sopenharmony_ci#define HDLC_DCHANNEL	0x02
488c2ecf20Sopenharmony_ci#define HDLC_BITREVERSE	0x04
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/*
518c2ecf20Sopenharmony_ci  The return value from isdnhdlc_decode is
528c2ecf20Sopenharmony_ci  the frame length, 0 if no complete frame was decoded,
538c2ecf20Sopenharmony_ci  or a negative error number
548c2ecf20Sopenharmony_ci*/
558c2ecf20Sopenharmony_ci#define HDLC_FRAMING_ERROR     1
568c2ecf20Sopenharmony_ci#define HDLC_CRC_ERROR         2
578c2ecf20Sopenharmony_ci#define HDLC_LENGTH_ERROR      3
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciextern void	isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features);
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciextern int	isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src,
628c2ecf20Sopenharmony_ci			int slen, int *count, u8 *dst, int dsize);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ciextern void	isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features);
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ciextern int	isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src,
678c2ecf20Sopenharmony_ci			u16 slen, int *count, u8 *dst, int dsize);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#endif /* __ISDNHDLC_H__ */
70