Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / ot-br-posix / repo / src / web / web-service / ot_client.hpp
1 /*
2  *  Copyright (c) 2019, 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 definitions for OpenThread daemon client.
32  */
33
34 #ifndef OTBR_WEB_WEB_SERVICE_OT_CLIENT_HPP_
35 #define OTBR_WEB_WEB_SERVICE_OT_CLIENT_HPP_
36
37 #include "openthread-br/config.h"
38
39 #include <stdint.h>
40
41 namespace otbr {
42 namespace Web {
43
44 #define OT_SCANNED_NET_BUFFER_SIZE 250
45 #define OT_SET_MAX_DATA_SIZE 250
46 #define OT_NETWORK_NAME_MAX_SIZE 17
47 #define OT_HARDWARE_ADDRESS_SIZE 8
48 #define OT_PREFIX_SIZE 8
49 #define OT_ROUTER_ROLE 2
50
51 struct WpanNetworkInfo
52 {
53     char     mNetworkName[OT_NETWORK_NAME_MAX_SIZE];
54     bool     mAllowingJoin;
55     uint16_t mPanId;
56     uint16_t mChannel;
57     uint64_t mExtPanId;
58     int8_t   mRssi;
59     uint8_t  mHardwareAddress[OT_HARDWARE_ADDRESS_SIZE];
60     uint8_t  mPrefix[OT_PREFIX_SIZE];
61 };
62
63 /**
64  * This class implements functionality of OpenThread client.
65  *
66  */
67 class OpenThreadClient
68 {
69 public:
70     /**
71      * This constructor creates an OpenThread client.
72      *
73      */
74     OpenThreadClient(void);
75     /**
76      * This destructor destories an OpenThread client.
77      *
78      */
79     ~OpenThreadClient(void);
80
81     /**
82      * This method connects to OpenThread daemon.
83      *
84      * @retval  true    Successfully connected to the daemon.
85      * @retval  false   Failed to connected to the daemon.
86      *
87      */
88     bool Connect(void);
89
90     /**
91      * This method executes OpenThread CLI.
92      *
93      * @param[in]   aFormat     C style format string.
94      * @param[in]   ...         C style format arguments.
95      *
96      * @returns A pointer to the output if succeeded, otherwise nullptr.
97      *
98      */
99     char *Execute(const char *aFormat, ...);
100
101     /**
102      * This method scans Thread network.
103      *
104      * @param[out]  aNetworks   A pointer to the buffer to store network information.
105      * @param[in]   aLength     Number of entries in @p aNetworks.
106      *
107      * @returns Number of entries found. 0 if none found.
108      *
109      */
110     int Scan(WpanNetworkInfo *aNetworks, int aLength);
111
112     /**
113      * This method performs factory reset.
114      *
115      */
116     bool FactoryReset(void);
117
118 private:
119     void Disconnect(void);
120
121     enum
122     {
123         kBufferSize     = 1024, ///< Maximum command line input and output buffer.
124         kDefaultTimeout = 800,  ///< Default timeout(ms) waiting for a command finish.
125     };
126
127     char mBuffer[kBufferSize];
128     int  mTimeout; /// Timeout in milliseconds
129     int  mSocket;
130 };
131
132 } // namespace Web
133 } // namespace otbr
134
135 #endif // OTBR_WEB_WEB_SERVICE_OT_CLIENT_HPP_