diagchar_hdlc.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright (c) 2008-2009, 2012-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef DIAGCHAR_HDLC
  13. #define DIAGCHAR_HDLC
  14. enum diag_send_state_enum_type {
  15. DIAG_STATE_START,
  16. DIAG_STATE_BUSY,
  17. DIAG_STATE_CRC1,
  18. DIAG_STATE_CRC2,
  19. DIAG_STATE_TERM,
  20. DIAG_STATE_COMPLETE
  21. };
  22. struct diag_send_desc_type {
  23. const void *pkt;
  24. const void *last; /* Address of last byte to send. */
  25. enum diag_send_state_enum_type state;
  26. unsigned char terminate; /* True if this fragment
  27. terminates the packet */
  28. };
  29. struct diag_hdlc_dest_type {
  30. void *dest;
  31. void *dest_last;
  32. /* Below: internal use only */
  33. uint16_t crc;
  34. };
  35. struct diag_hdlc_decode_type {
  36. uint8_t *src_ptr;
  37. unsigned int src_idx;
  38. unsigned int src_size;
  39. uint8_t *dest_ptr;
  40. unsigned int dest_idx;
  41. unsigned int dest_size;
  42. int escaping;
  43. };
  44. void diag_hdlc_encode(struct diag_send_desc_type *src_desc,
  45. struct diag_hdlc_dest_type *enc);
  46. int diag_hdlc_decode(struct diag_hdlc_decode_type *hdlc);
  47. int crc_check(uint8_t *buf, uint16_t len);
  48. #define ESC_CHAR 0x7D
  49. #define ESC_MASK 0x20
  50. #endif