blob: 2ba46f5a8833cd43b9295fe89489f74c6908b0db [file] [log] [blame]
Ravi Aravamudhan5dccccb2013-08-09 16:57:34 -07001/* Copyright (c) 2008-2009, 2012-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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
13#ifndef DIAGCHAR_HDLC
14#define DIAGCHAR_HDLC
15
16enum diag_send_state_enum_type {
17 DIAG_STATE_START,
18 DIAG_STATE_BUSY,
19 DIAG_STATE_CRC1,
20 DIAG_STATE_CRC2,
21 DIAG_STATE_TERM,
22 DIAG_STATE_COMPLETE
23};
24
25struct diag_send_desc_type {
26 const void *pkt;
27 const void *last; /* Address of last byte to send. */
28 enum diag_send_state_enum_type state;
29 unsigned char terminate; /* True if this fragment
30 terminates the packet */
31};
32
33struct diag_hdlc_dest_type {
34 void *dest;
35 void *dest_last;
36 /* Below: internal use only */
37 uint16_t crc;
38};
39
40struct diag_hdlc_decode_type {
41 uint8_t *src_ptr;
42 unsigned int src_idx;
43 unsigned int src_size;
44 uint8_t *dest_ptr;
45 unsigned int dest_idx;
46 unsigned int dest_size;
47 int escaping;
48
49};
50
51void diag_hdlc_encode(struct diag_send_desc_type *src_desc,
52 struct diag_hdlc_dest_type *enc);
53
54int diag_hdlc_decode(struct diag_hdlc_decode_type *hdlc);
55
Ravi Aravamudhan5dccccb2013-08-09 16:57:34 -070056int crc_check(uint8_t *buf, uint16_t len);
57
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070058#define ESC_CHAR 0x7D
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059#define ESC_MASK 0x20
60
61#endif