isdnhdlc.h 1.7 KB

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