hdlc.h 2.2 KB

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