2 * Copyright (c) 2017, The OpenThread Authors.
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.
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.
31 * This file implements the wpan controller service
34 #ifndef OTBR_WEB_WEB_SERVICE_WPAN_SERVICE_
35 #define OTBR_WEB_WEB_SERVICE_WPAN_SERVICE_
37 #include "openthread-br/config.h"
45 #include <json/json.h>
46 #include <json/writer.h>
48 #include "common/logging.hpp"
49 #include "utils/hex.hpp"
50 #include "utils/pskc.hpp"
51 #include "web/web-service/ot_client.hpp"
54 * WPAN parameter constants
58 #define OT_EXTENDED_PANID_LENGTH 8
59 #define OT_HARDWARE_ADDRESS_LENGTH 8
60 #define OT_NETWORK_NAME_LENGTH 16
61 #define OT_PANID_LENGTH 2
62 #define OT_PSKC_MAX_LENGTH 16
63 #define OT_HEX_PREFIX_LENGTH 2
64 #define OT_PUBLISH_SERVICE_INTERVAL 20
70 * This class provides web service to manage WPAN.
77 * This method handles the http request to join network.
79 * @param[in] aJoinRequest A reference to the http request of joining network.
81 * @returns The string to the http response of joining network.
84 std::string HandleJoinNetworkRequest(const std::string &aJoinRequest);
87 * This method handles the http request to form network.
89 * @param[in] aFormRequest A reference to the http request of forming network.
91 * @returns The string to the http response of forming network.
94 std::string HandleFormNetworkRequest(const std::string &aFormRequest);
97 * This method handles the http request to add on-mesh prefix.
99 * @param[in] aAddPrefixRequest A reference to the http request of adding on-mesh prefix.
101 * @returns The string to the http response of adding on-mesh prefix.
104 std::string HandleAddPrefixRequest(const std::string &aAddPrefixRequest);
107 * This method handles the http request to delete on-mesh prefix http request.
109 * @param[in] aDeleteRequest A reference to the http request of deleting on-mesh prefix.
111 * @returns The string to the http response of deleting on-mesh prefix.
114 std::string HandleDeletePrefixRequest(const std::string &aDeleteRequest);
117 * This method handles http request to get netowrk status.
119 * @returns The string to the http response of getting status.
122 std::string HandleStatusRequest(void);
125 * This method handles http request to get available networks.
127 * @returns The string to the http response of getting available networks.
130 std::string HandleAvailableNetworkRequest(void);
133 * This method handles http request to commission device
135 * @returns The string to the http response of commissioning
138 std::string HandleCommission(const std::string &aCommissionRequest);
141 * This method sets the Thread interface name.
143 * @param[in] aIfName The pointer to the Thread interface name.
146 void SetInterfaceName(const char *aIfName)
148 strncpy(mIfName, aIfName, sizeof(mIfName) - 1);
149 mIfName[sizeof(mIfName) - 1] = '\0';
153 * This method gets status of wpan service.
155 * @param[inout] aNetworkName The pointer to the network name.
156 * @param[inout] aIfName The pointer to the extended PAN ID.
158 * @retval kWpanStatus_OK Successfully started the Thread service.
159 * @retval kWpanStatus_Offline Not started the Thread service.
160 * @retval kWpanStatus_Down The Thread service was down.
163 int GetWpanServiceStatus(std::string &aNetworkName, std::string &aExtPanId) const;
166 * This method starts commissioner and wait for a device to join
168 * @param[in] aPskd Joiner pskd
169 * @param[in] aNetworkPassword Network password
171 * @returns The string to the http response of getting available networks.
174 std::string CommissionDevice(const char *aPskd, const char *aNetworkPassword);
177 int commitActiveDataset(otbr::Web::OpenThreadClient &aClient,
178 const std::string & aMasterKey,
179 const std::string & aNetworkName,
183 static std::string escapeOtCliEscapable(const std::string &aArg);
185 WpanNetworkInfo mNetworks[OT_SCANNED_NET_BUFFER_SIZE];
187 char mIfName[IFNAMSIZ];
188 std::string mNetworkName;
189 std::string mExtPanId;
194 kWpanStatus_Associating,
196 kWpanStatus_FormFailed,
197 kWpanStatus_GetPropertyFailed,
198 kWpanStatus_JoinFailed,
199 kWpanStatus_LeaveFailed,
200 kWpanStatus_NetworkNotFound,
202 kWpanStatus_ParseRequestFailed,
203 kWpanStatus_ScanFailed,
204 kWpanStatus_SetFailed,
205 kWpanStatus_SetGatewayFailed,
206 kWpanStatus_Uninitialized,
211 kPropertyType_String = 0,
215 static const char *kBorderAgentHost;
216 static const char *kBorderAgentPort;
222 #endif // OTBR_WEB_WEB_SERVICE_WPAN_SERVICE_