hdlc.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * hdlc.h -- General purpose ISDN HDLC decoder.
  3. *
  4. * Implementation of a HDLC decoder/encoder in software.
  5. * Necessary because some ISDN devices don't have HDLC
  6. * controllers.
  7. *
  8. * Copyright (C)
  9. * 2009 Karsten Keil <keil@b1-systems.de>
  10. * 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
  11. * 2001 Frode Isaksen <fisaksen@bewan.com>
  12. * 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. */
  28. #ifndef __ISDNHDLC_H__
  29. #define __ISDNHDLC_H__
  30. struct isdnhdlc_vars {
  31. int bit_shift;
  32. int hdlc_bits1;
  33. int data_bits;
  34. int ffbit_shift; /* encoding only */
  35. int state;
  36. int dstpos;
  37. u16 crc;
  38. u8 cbin;
  39. u8 shift_reg;
  40. u8 ffvalue;
  41. /* set if transferring data */
  42. u32 data_received:1;
  43. /* set if D channel (send idle instead of flags) */
  44. u32 dchannel:1;
  45. /* set if 56K adaptation */
  46. u32 do_adapt56:1;
  47. /* set if in closing phase (need to send CRC + flag) */
  48. u32 do_closing:1;
  49. /* set if data is bitreverse */
  50. u32 do_bitreverse:1;
  51. };
  52. /* Feature Flags */
  53. #define HDLC_56KBIT 0x01
  54. #define HDLC_DCHANNEL 0x02
  55. #define HDLC_BITREVERSE 0x04
  56. /*
  57. The return value from isdnhdlc_decode is
  58. the frame length, 0 if no complete frame was decoded,
  59. or a negative error number
  60. */
  61. #define HDLC_FRAMING_ERROR 1
  62. #define HDLC_CRC_ERROR 2
  63. #define HDLC_LENGTH_ERROR 3
  64. extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features);
  65. extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src,
  66. int slen, int *count, u8 *dst, int dsize);
  67. extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features);
  68. extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src,
  69. u16 slen, int *count, u8 *dst, int dsize);
  70. #endif /* __ISDNHDLC_H__ */