1 /* 2 * Copyright (c) 2020, The OpenThread Authors. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of the copyright holder nor the 13 * names of its contributors may be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * @file 31 * This file includes type definitions for OTBR-REST. 32 */ 33 34 #ifndef OTBR_REST_TYPES_HPP_ 35 #define OTBR_REST_TYPES_HPP_ 36 37 #include "openthread-br/config.h" 38 39 #include <chrono> 40 #include <string> 41 #include <vector> 42 43 #include <openthread/border_agent.h> 44 45 #include "openthread/netdiag.h" 46 47 #define OT_REST_ACCEPT_HEADER "Accept" 48 #define OT_REST_CONTENT_TYPE_HEADER "Content-Type" 49 50 #define OT_REST_CONTENT_TYPE_JSON "application/json" 51 #define OT_REST_CONTENT_TYPE_PLAIN "text/plain" 52 53 using std::chrono::steady_clock; 54 55 namespace otbr { 56 namespace rest { 57 58 enum class HttpMethod : std::uint8_t 59 { 60 kDelete = 0, ///< DELETE 61 kGet = 1, ///< GET 62 kHead = 2, ///< HEAD 63 kPost = 3, ///< POST 64 kPut = 4, ///< PUT 65 kOptions = 6, ///< OPTIONS 66 67 }; 68 69 enum class HttpStatusCode : std::uint16_t 70 { 71 kStatusOk = 200, 72 kStatusCreated = 201, 73 kStatusNoContent = 204, 74 kStatusBadRequest = 400, 75 kStatusResourceNotFound = 404, 76 kStatusMethodNotAllowed = 405, 77 kStatusRequestTimeout = 408, 78 kStatusConflict = 409, 79 kStatusInternalServerError = 500, 80 }; 81 82 enum class PostError : std::uint8_t 83 { 84 kPostErrorNone = 0, ///< No error 85 kPostBadRequest = 1, ///< Bad request for post 86 kPostSetFail = 2, ///< Fail when set value 87 }; 88 89 enum class ConnectionState : std::uint8_t 90 { 91 kInit = 0, ///< Init 92 kReadWait = 1, ///< Wait to read 93 kReadTimeout = 2, ///< Reach read timeout 94 kCallbackWait = 3, ///< Wait for callback 95 kWriteWait = 4, ///< Wait for write 96 kWriteTimeout = 5, ///< Reach write timeout 97 kInternalError = 6, ///< Occur internal call error 98 kComplete = 7, ///< No longer need to be processed 99 100 }; 101 struct NodeInfo 102 { 103 otBorderAgentId mBaId; 104 std::string mRole; 105 uint32_t mNumOfRouter; 106 uint16_t mRloc16; 107 const uint8_t *mExtPanId; 108 const uint8_t *mExtAddress; 109 otIp6Address mRlocAddress; 110 otLeaderData mLeaderData; 111 std::string mNetworkName; 112 }; 113 114 struct DiagInfo 115 { 116 steady_clock::time_point mStartTime; 117 std::vector<otNetworkDiagTlv> mDiagContent; 118 }; 119 120 } // namespace rest 121 } // namespace otbr 122 123 #endif // OTBR_REST_TYPES_HPP_ 124