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 kStatusInsufficientStorage = 507, 81 }; 82 83 enum class PostError : std::uint8_t 84 { 85 kPostErrorNone = 0, ///< No error 86 kPostBadRequest = 1, ///< Bad request for post 87 kPostSetFail = 2, ///< Fail when set value 88 }; 89 90 enum class ConnectionState : std::uint8_t 91 { 92 kInit = 0, ///< Init 93 kReadWait = 1, ///< Wait to read 94 kReadTimeout = 2, ///< Reach read timeout 95 kCallbackWait = 3, ///< Wait for callback 96 kWriteWait = 4, ///< Wait for write 97 kWriteTimeout = 5, ///< Reach write timeout 98 kInternalError = 6, ///< Occur internal call error 99 kComplete = 7, ///< No longer need to be processed 100 101 }; 102 struct NodeInfo 103 { 104 otBorderAgentId mBaId; 105 std::string mRole; 106 uint32_t mNumOfRouter; 107 uint16_t mRloc16; 108 const uint8_t *mExtPanId; 109 const uint8_t *mExtAddress; 110 otIp6Address mRlocAddress; 111 otLeaderData mLeaderData; 112 std::string mNetworkName; 113 }; 114 115 struct DiagInfo 116 { 117 steady_clock::time_point mStartTime; 118 std::vector<otNetworkDiagTlv> mDiagContent; 119 }; 120 121 } // namespace rest 122 } // namespace otbr 123 124 #endif // OTBR_REST_TYPES_HPP_ 125