From 9301cf12d7b41ec5970f25f7e2529f8a9f894949 Mon Sep 17 00:00:00 2001 From: Martin Turon Date: Thu, 26 Jan 2017 17:59:29 -0800 Subject: [PATCH] ncp: Remove deprecated flen encoding. (#1213) --- .../libopenthread-ncp-uart.vcxproj | 6 +- .../libopenthread-ncp-uart.vcxproj.filters | 10 +- src/ncp/Makefile.am | 2 - src/ncp/flen.cpp | 170 ------------------ src/ncp/flen.hpp | 162 ----------------- src/ncp/ncp_uart.hpp | 1 - 6 files changed, 4 insertions(+), 347 deletions(-) delete mode 100644 src/ncp/flen.cpp delete mode 100644 src/ncp/flen.hpp diff --git a/etc/visual-studio/libopenthread-ncp-uart.vcxproj b/etc/visual-studio/libopenthread-ncp-uart.vcxproj index 2028a1e1c..b5e3e0566 100644 --- a/etc/visual-studio/libopenthread-ncp-uart.vcxproj +++ b/etc/visual-studio/libopenthread-ncp-uart.vcxproj @@ -1,4 +1,4 @@ - + @@ -54,7 +54,6 @@ - @@ -62,7 +61,6 @@ - @@ -72,4 +70,4 @@ - \ No newline at end of file + diff --git a/etc/visual-studio/libopenthread-ncp-uart.vcxproj.filters b/etc/visual-studio/libopenthread-ncp-uart.vcxproj.filters index 1c903f4ab..ff54433e5 100644 --- a/etc/visual-studio/libopenthread-ncp-uart.vcxproj.filters +++ b/etc/visual-studio/libopenthread-ncp-uart.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -15,9 +15,6 @@ - - Source Files - Source Files @@ -35,9 +32,6 @@ - - Header Files - Header Files @@ -54,4 +48,4 @@ Header Files - \ No newline at end of file + diff --git a/src/ncp/Makefile.am b/src/ncp/Makefile.am index 6e9f41302..3330ab0a2 100644 --- a/src/ncp/Makefile.am +++ b/src/ncp/Makefile.am @@ -73,8 +73,6 @@ if OPENTHREAD_ENABLE_NCP_UART libopenthread_ncp_a_SOURCES += \ hdlc.cpp \ hdlc.hpp \ - flen.cpp \ - flen.hpp \ ncp_uart.cpp \ ncp_uart.hpp \ $(NULL) diff --git a/src/ncp/flen.cpp b/src/ncp/flen.cpp deleted file mode 100644 index 6ce7f4f22..000000000 --- a/src/ncp/flen.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2016, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @file - * This file implements an FLEN encoder and decoder. - */ - -#include -#include - -namespace Thread { -namespace Flen { - -enum -{ - kFlagSequence = 0x7e, ///< FLen Flag value -}; - -ThreadError Encoder::Init(uint8_t *aOutBuf, uint16_t &aOutLength) -{ - ThreadError error = kThreadError_None; - - mOutBuf = aOutBuf; - - VerifyOrExit(aOutLength >= 3, error = kThreadError_NoBufs); - aOutBuf[0] = kFlagSequence; - // Leave the next two bytes empty. - aOutLength = 3; - mOutLength = 0; - -exit: - return error; -} - -ThreadError Encoder::Encode(uint8_t aInByte, uint8_t *aOutBuf, uint16_t aOutLength) -{ - ThreadError error = kThreadError_None; - - VerifyOrExit(mOutOffset + 1 < aOutLength, error = kThreadError_NoBufs); - aOutBuf[mOutOffset++] = aInByte; - -exit: - return error; -} - -ThreadError Encoder::Encode(const uint8_t *aInBuf, uint16_t aInLength, uint8_t *aOutBuf, uint16_t &aOutLength) -{ - ThreadError error = kThreadError_None; - - mOutOffset = 0; - - for (int i = 0; i < aInLength; i++) - { - SuccessOrExit(error = Encode(aInBuf[i], aOutBuf, aOutLength)); - } - -exit: - aOutLength = mOutOffset; - mOutLength += aOutLength; - return error; -} - -ThreadError Encoder::Finalize(uint8_t *aOutBuf, uint16_t &aOutLength) -{ - ThreadError error = kThreadError_None; - - VerifyOrExit(mOutOffset < aOutLength, error = kThreadError_NoBufs); - - mOutBuf[1] = (mOutLength >> 8); - mOutBuf[2] = (mOutLength & 0xFF); - - aOutLength = 0; - -exit: - (void)aOutBuf; - return error; -} - - -Decoder::Decoder(uint8_t *aOutBuf, uint16_t aOutLength, FrameHandler aFrameHandler, void *aContext): - mState(kStateNeedFlag), - mFrameHandler(aFrameHandler), - mContext(aContext), - mOutBuf(aOutBuf), - mOutOffset(0), - mOutLength(aOutLength), - mReadLength(0) -{ -} - -void Decoder::Decode(const uint8_t *aInBuf, uint16_t aInLength) -{ - uint8_t byte; - - for (int i = 0; i < aInLength; i++) - { - byte = aInBuf[i]; - - switch (mState) - { - case kStateNeedFlag: - if (byte == kFlagSequence) - { - mState = kStateNeedLenH; - mOutOffset = 0; - } - - break; - - case kStateNeedLenH: - mReadLength = static_cast(byte << 8); - mState = kStateNeedLenL; - break; - - case kStateNeedLenL: - mReadLength += byte; - - if (mReadLength > mOutLength) - { - // Too big. - mState = kStateNeedFlag; - } - else - { - mState = kStateNeedData; - } - - break; - - case kStateNeedData: - mOutBuf[mOutOffset++] = byte; - - if (mOutOffset >= mReadLength) - { - mState = kStateNeedFlag; - mFrameHandler(mContext, mOutBuf, mReadLength); - } - - break; - } - } -} - -} // namespace Flen -} // namespace Thread diff --git a/src/ncp/flen.hpp b/src/ncp/flen.hpp deleted file mode 100644 index de04be7f9..000000000 --- a/src/ncp/flen.hpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2016, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @file - * This file includes definitions for an FLEN (flag/length) encoder and decoder. - */ - -#ifndef FLEN_HPP_ -#define FLEN_HPP_ - -#include -#include - -namespace Thread { - -/** - * @namespace Thread::Flen - * - * @brief - * This namespace includes definitions for the FLEN encoder and decoder. - * - */ -namespace Flen { - -/** - * This class implements the FLEN encoder. - * - */ -class Encoder -{ -public: - /** - * This method begins an FLEN frame and puts the initial bytes into @p aOutBuf. - * - * @param[in] aOutBuf A pointer to the output buffer. - * @param[inout] aOutLength On entry, the output buffer size; On exit, the output length. - * - * @retval kThreadError_None Successfully started the FLEN frame. - * @retval kThreadError_NoBufs Insufficient buffer space available to start the FLEN frame. - * - */ - ThreadError Init(uint8_t *aOutBuf, uint16_t &aOutLength); - - /** - * This method encodes the frame. - * - * @param[in] aInBuf A pointer to the input buffer. - * @param[in] aInLength The number of bytes in @p aInBuf to encode. - * @param[out] aOutBuf A pointer to the output buffer. - * @param[out] aOutLength On exit, the number of bytes placed in @p aOutBuf. - * - * @retval kThreadError_None Successfully encoded the FLEN frame. - * @retval kThreadError_NoBufs Insufficient buffer space available to encode the FLEN frame. - * - */ - ThreadError Encode(const uint8_t *aInBuf, uint16_t aInLength, uint8_t *aOutBuf, uint16_t &aOutLength); - - /** - * This method ends an FLEN frame and puts the initial bytes into @p aOutBuf. - * - * @param[in] aOutBuf A pointer to the output buffer. - * @param[inout] aOutLength On entry, the output buffer size; On exit, the output length. - * - * @retval kThreadError_None Successfully ended the FLEN frame. - * @retval kThreadError_NoBufs Insufficient buffer space available to end the FLEN frame. - * - */ - ThreadError Finalize(uint8_t *aOutBuf, uint16_t &aOutLength); - -private: - ThreadError Encode(uint8_t aInByte, uint8_t *aOutBuf, uint16_t aOutLength); - - uint8_t *mOutBuf; - uint16_t mOutOffset; - uint16_t mOutLength; -}; - -/** - * This class implements the FLEN decoder. - * - */ -class Decoder -{ -public: - /** - * This function pointer is called when a complete frame has been formed. - * - * @param[in] aContext A pointer to arbitrary context information. - * @param[in] aFrame A pointer to the frame. - * @param[in] aFrameLength The frame length in bytes. - * - */ - typedef void (*FrameHandler)(void *aContext, uint8_t *aFrame, uint16_t aFrameLength); - - /** - * This constructor initializes the decoder. - * - * @param[in] aOutBuf A pointer to the output buffer. - * @param[in] aOutLength Size of the output buffer in bytes. - * @param[in] aFrameHandler A pointer to a function that is called when a complete frame is received. - * @param[in] aContext A pointer to arbitrary context information. - * - */ - Decoder(uint8_t *aOutBuf, uint16_t aOutLength, FrameHandler aFrameHandler, void *aContext); - - /** - * This method streams bytes into the decoder. - * - * @param[in] aInBuf A pointer to the input buffer. - * @param[in] aInLength The number of bytes in @p aInBuf. - * - */ - void Decode(const uint8_t *aInBuf, uint16_t aInLength); - -private: - enum State - { - kStateNeedFlag = 0, - kStateNeedLenH, - kStateNeedLenL, - kStateNeedData, - }; - State mState; - - FrameHandler mFrameHandler; - void *mContext; - - uint8_t *mOutBuf; - uint16_t mOutOffset; - uint16_t mOutLength; - uint16_t mReadLength; -}; - -} // namespace Flen -} // namespace Thread - -#endif // FLEN_HPP_ diff --git a/src/ncp/ncp_uart.hpp b/src/ncp/ncp_uart.hpp index 609ee2a64..2adcd6444 100644 --- a/src/ncp/ncp_uart.hpp +++ b/src/ncp/ncp_uart.hpp @@ -40,7 +40,6 @@ #endif #include -#include #include #include