Ravi Aravamudhan | 5dccccb | 2013-08-09 16:57:34 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2008-2009, 2012-2013, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 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 | |
| 13 | #ifndef DIAGCHAR_HDLC |
| 14 | #define DIAGCHAR_HDLC |
| 15 | |
| 16 | enum 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 | |
| 25 | struct 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 | |
| 33 | struct diag_hdlc_dest_type { |
| 34 | void *dest; |
| 35 | void *dest_last; |
| 36 | /* Below: internal use only */ |
| 37 | uint16_t crc; |
| 38 | }; |
| 39 | |
| 40 | struct 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 | |
| 51 | void diag_hdlc_encode(struct diag_send_desc_type *src_desc, |
| 52 | struct diag_hdlc_dest_type *enc); |
| 53 | |
| 54 | int diag_hdlc_decode(struct diag_hdlc_decode_type *hdlc); |
| 55 | |
Ravi Aravamudhan | 5dccccb | 2013-08-09 16:57:34 -0700 | [diff] [blame] | 56 | int crc_check(uint8_t *buf, uint16_t len); |
| 57 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 58 | #define ESC_CHAR 0x7D |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 59 | #define ESC_MASK 0x20 |
| 60 | |
| 61 | #endif |