1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef REMOTE_ENROLLEE_H_
22 #define REMOTE_ENROLLEE_H_
26 #include <condition_variable>
28 #include "ESRichCommon.h"
38 class EnrolleeResource;
40 class EnrolleeSecurity;
42 typedef std::function<void(const std::shared_ptr<OC::OCResource> resource)> onDeviceDiscoveredCb;
45 * This class represents Remote Enrollee device instance. What operation the class provides:
46 * 1) Ownership transfer for enabling secured communication between Mediator and Enrollee
48 * 2) Provision WiFi AP information used for which Enrollee is going to connect to the AP
49 * 3) Provision Device confiruation setting, i.e. language, country, and etc
50 * 4) Provision Cloud information used for which Enrollee is going to register to the cloud
52 class RemoteEnrollee : public std::enable_shared_from_this<RemoteEnrollee>
55 ~RemoteEnrollee() = default;
58 * Get an Enrollee's status which includes provisioning status and last error code
60 * @param callback will give the requested status
62 * @throws ESInvalidParameterException If callback is null.
63 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
67 void getStatus(const GetStatusCb callback);
70 * Get an Enrollee's configuration which includes WiFi supported frequency and device name
72 * @param callback will give the requested configuration
74 * @throws ESInvalidParameterException If callback is null.
75 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
77 * @see GetConfigurationStatusCb
79 void getConfiguration(const GetConfigurationStatusCb callback);
82 * Do security provisioning such as ownership tranfer to Enrollee.
84 * @param callback will give the result if the security provisioning succeeds or fails for some reasons
86 * @throws ESInvalidParameterException If callback is null.
87 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
89 * @see SecurityProvStatusCb
91 void provisionSecurity(const SecurityProvStatusCb callback);
94 * Do security provisioning such as ownership tranfer to Enrollee which may require more
95 * specific user selections like a type of ownership transfer method or pre-configured
96 * pin number used to Pre-configured pin-based MOT.
98 * @param callback will give the result if the security provisioning succeeds or fails for some reasons.
100 * @throws ESInvalidParameterException If callback is null.
101 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
103 * @see SecurityProvStatusCb
105 void provisionSecurity(const SecurityProvStatusCbWithOption callback);
108 * Provision WiFi AP information and device configuration to Enrollee
109 * 1. WiFi AP information includes a SSID, password, auth type, and encryption type.
110 * 2. Device configuration includes a language (IETF language tags) and country (ISO 3166-1 Alpha-2)
112 * @param devProp a data structure storing the above information to be delivered
113 * @param callback will give the result if the provisioning succeeds or fails
115 * @throws ESInvalidParameterException If callback is null.
116 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
119 * @see DevicePropProvStatusCb
121 void provisionDeviceProperties(const DeviceProp& devProp,
122 const DevicePropProvStatusCb callback);
125 * Provision Cloud information to Enrollee, which includes Auth code, auth provider,
126 * Cloud interface server URL, and etc.
127 * In this function, Discovery for the Enrollee will happen again in a given network.
128 * Because, this function is expected to call *AFTER* the Enrollee disconnects its Soft AP
129 * and successfully connects to the certain WiFi AP. In that case, Mediator should discover
130 * the Enrollee with a certain Device ID in the network.
132 * @param cloudProp a data structure storing the above information to be delivered
133 * @param callback will give the result if the provisioning succeeds or fails
135 * @throws ESInvalidParameterException If callback is null.
136 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
139 * @see CloudPropProvStatusCb
141 void provisionCloudProperties(const CloudProp& cloudProp,
142 const CloudPropProvStatusCb callback);
145 * Provision Cloud information to Enrollee, which includes Auth code, auth provider,
146 * Cloud interface server URL, and etc.
147 * Note that, this API is skipping finding Enrollee in a given network. Instead, an OCResource
148 * given as a first parameter will be considered to the Enrollee for cloud provisioning.
150 * @param resource an OCResource corresponding to a target Enrollee for cloud provisioning
151 * @param cloudProp a data structure storing the above information to be delivered
152 * @param callback will give the result if the provisioning succeeds or fails
154 * @throws ESInvalidParameterException If callback is null.
155 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
158 * @see CloudPropProvStatusCb
160 void provisionCloudProperties(const std::shared_ptr< OC::OCResource > resource,
161 const CloudProp& cloudProp,
162 const CloudPropProvStatusCb callback);
165 * Notify an Enrollee to Connect WiFi/Cloud
167 * @param connectTypes Target configurations to be connected. E.g. WiFi and coap cloud server
168 * @param callback will give the result if the connect request succeeds or fails
170 * @see ES_CONNECT_TYPE
171 * @see ConnectRequestStatusCb
173 void requestToConnect(const std::vector<ES_CONNECT_TYPE> &connectTypes, const ConnectRequestStatusCb callback);
176 RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource);
178 ESResult discoverResource();
180 static void onDiscoveredCallback(const std::shared_ptr<OC::OCResource> resource,
181 std::weak_ptr<RemoteEnrollee> this_ptr);
183 static void onGetStatusHandlerCallback(
184 const std::shared_ptr< GetEnrolleeStatus > status,
185 std::weak_ptr<RemoteEnrollee> this_ptr);
187 static void onGetConfigurationStatusHandlerCallback(
188 const std::shared_ptr< GetConfigurationStatus > status,
189 std::weak_ptr<RemoteEnrollee> this_ptr);
191 static void onDevicePropProvisioningStatusHandlerCallback(
192 const std::shared_ptr< DevicePropProvisioningStatus > status,
193 std::weak_ptr<RemoteEnrollee> this_ptr);
195 static void onCloudPropProvisioningStatusHandlerCallback(
196 const std::shared_ptr< CloudPropProvisioningStatus > status,
197 std::weak_ptr<RemoteEnrollee> this_ptr);
199 static void onConnectRequestStatusHandlerCallback(
200 const std::shared_ptr< ConnectRequestStatus > status,
201 std::weak_ptr<RemoteEnrollee> this_ptr);
203 static void onSecurityStatusHandlerCallback(
204 const std::shared_ptr< SecProvisioningStatus > status,
205 std::weak_ptr<RemoteEnrollee> this_ptr);
207 static ESOwnershipTransferData onSecurityStatusWithOptionHandlerCallback(
208 const std::shared_ptr< SecProvisioningStatus > status,
209 std::weak_ptr<RemoteEnrollee> this_ptr);
211 void onDeviceDiscovered(const std::shared_ptr<OC::OCResource> resource);
212 void initCloudResource();
214 void getStatusHandler
215 (const std::shared_ptr< GetEnrolleeStatus > status) const;
216 void getConfigurationStatusHandler
217 (const std::shared_ptr< GetConfigurationStatus > status) const;
218 void devicePropProvisioningStatusHandler
219 (const std::shared_ptr< DevicePropProvisioningStatus > status) const;
220 void cloudPropProvisioningStatusHandler
221 (const std::shared_ptr< CloudPropProvisioningStatus > status) const;
222 void connectRequestStatusHandler(
223 const std::shared_ptr< ConnectRequestStatus > status) const;
224 void securityStatusHandler
225 (const std::shared_ptr< SecProvisioningStatus > status) const;
226 ESOwnershipTransferData securityStatusWithOptionHandler
227 (const std::shared_ptr< SecProvisioningStatus > status) const;
230 std::shared_ptr< OC::OCResource > m_ocResource;
231 std::shared_ptr< EnrolleeResource > m_enrolleeResource;
232 std::shared_ptr< EnrolleeSecurity > m_localEnrolleeSecurity;
233 std::shared_ptr< EnrolleeSecurity > m_cloudEnrolleeSecurity;
234 std::shared_ptr< CloudResource > m_cloudResource;
236 std::string m_deviceId;
237 bool m_discoveryResponse;
239 std::mutex m_discoverymtx;
240 std::condition_variable m_cond;
242 SecurityProvStatusCb m_securityProvStatusCb;
243 SecurityProvStatusCbWithOption m_securityProvStatusCbWithOption;
244 GetStatusCb m_getStatusCb;
245 GetConfigurationStatusCb m_getConfigurationStatusCb;
246 SecurityPinCb m_securityPinCb;
247 SecProvisioningDbPathCb m_secProvisioningDbPathCb;
248 DevicePropProvStatusCb m_devicePropProvStatusCb;
249 CloudPropProvStatusCb m_cloudPropProvStatusCb;
250 ConnectRequestStatusCb m_connectRequestStatusCb;
252 friend class EasySetup;
257 #endif //REMOTE_ENROLLEE_H_