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