// SPDX-License-Identifier: GPL-2.0-or-later /* * isdnhdlc.c -- General purpose ISDN HDLC decoder. * * Copyright (C) * 2009 Karsten Keil <[email protected]> * 2002 Wolfgang Mües <[email protected]> * 2001 Frode Isaksen <[email protected]> * 2001 Kai Germaschewski <[email protected]> */ #include <linux/module.h> #include <linux/init.h> #include <linux/crc-ccitt.h> #include <linux/bitrev.h> #include "isdnhdlc.h" /*-------------------------------------------------------------------*/ MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …; /*-------------------------------------------------------------------*/ enum { … }; enum { … }; void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features) { … } EXPORT_SYMBOL(…); void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features) { … } EXPORT_SYMBOL(…); static int check_frame(struct isdnhdlc_vars *hdlc) { … } /* isdnhdlc_decode - decodes HDLC frames from a transparent bit stream. The source buffer is scanned for valid HDLC frames looking for flags (01111110) to indicate the start of a frame. If the start of the frame is found, the bit stuffing is removed (0 after 5 1's). When a new flag is found, the complete frame has been received and the CRC is checked. If a valid frame is found, the function returns the frame length excluding the CRC with the bit HDLC_END_OF_FRAME set. If the beginning of a valid frame is found, the function returns the length. If a framing error is found (too many 1s and not a flag) the function returns the length with the bit HDLC_FRAMING_ERROR set. If a CRC error is found the function returns the length with the bit HDLC_CRC_ERROR set. If the frame length exceeds the destination buffer size, the function returns the length with the bit HDLC_LENGTH_ERROR set. src - source buffer slen - source buffer length count - number of bytes removed (decoded) from the source buffer dst _ destination buffer dsize - destination buffer size returns - number of decoded bytes in the destination buffer and status flag. */ int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, int slen, int *count, u8 *dst, int dsize) { … } EXPORT_SYMBOL(…); /* isdnhdlc_encode - encodes HDLC frames to a transparent bit stream. The bit stream starts with a beginning flag (01111110). After that each byte is added to the bit stream with bit stuffing added (0 after 5 1's). When the last byte has been removed from the source buffer, the CRC (2 bytes is added) and the frame terminates with the ending flag. For the dchannel, the idle character (all 1's) is also added at the end. If this function is called with empty source buffer (slen=0), flags or idle character will be generated. src - source buffer slen - source buffer length count - number of bytes removed (encoded) from source buffer dst _ destination buffer dsize - destination buffer size returns - number of encoded bytes in the destination buffer */ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, u16 slen, int *count, u8 *dst, int dsize) { … } EXPORT_SYMBOL(…);