1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef HEADER_HDLC_LITE_H_INCLUDED 18 #define HEADER_HDLC_LITE_H_INCLUDED 1 19 20 #include <stdint.h> 21 #include <stdbool.h> 22 23 #if defined(__cplusplus) 24 extern "C" { 25 #endif 26 27 static const uint8_t kHdlcResetSignal[] = { 0x7E, 0x13, 0x11, 0x7E }; 28 static const uint16_t kHdlcCrcCheckValue = 0xf0b8; 29 static const uint16_t kHdlcCrcResetValue = 0xffff; 30 31 #define HDLC_BYTE_FLAG 0x7E 32 #define HDLC_BYTE_ESC 0x7D 33 #define HDLC_BYTE_XON 0x11 34 #define HDLC_BYTE_XOFF 0x13 35 #define HDLC_BYTE_SPECIAL 0xF8 36 #define HDLC_ESCAPE_XFORM 0x20 37 38 /** HDLC CRC function */ 39 extern uint16_t hdlc_crc16(uint16_t fcs, uint8_t byte); 40 41 /** HDLC CRC Finalize function */ 42 extern uint16_t hdlc_crc16_finalize(uint16_t fcs); 43 44 /** Returns true if the byte needs to be escaped, false otherwise */ 45 extern bool hdlc_byte_needs_escape(uint8_t byte); 46 47 /** 48 * Writes one or two HDLC-encoded bytes to out_buffer, 49 * and returns how many bytes were written. 50 */ 51 extern int hdlc_write_byte(uint8_t* out_buffer, uint8_t byte); 52 53 #if defined(__cplusplus) 54 } 55 #endif 56 57 #endif // HEADER_HDLC_LITE_H_INCLUDED 58