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;
43 * This class represents Remote Enrollee device instance. What operation the class provides:
44 * 1) Ownership transfer for enabling secured communication between Mediator and Enrollee
46 * 2) Provision WiFi AP information used for which Enrollee is going to connect to the AP
47 * 3) Provision Device confiruation setting, i.e. language, country, and etc
48 * 4) Provision Cloud information used for which Enrollee is going to register to the cloud
53 ~RemoteEnrollee() = default;
56 * Get an Enrollee's status which includes provisioning status and last error code
58 * @param callback will give the requested status
60 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
64 void getStatus(const GetStatusCb callback);
67 * Get an Enrollee's configuration which includes WiFi supported frequency and device name
69 * @param callback will give the requested configuration
71 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
73 * @see GetConfigurationStatusCb
75 void getConfiguration(const GetConfigurationStatusCb callback);
78 * Do security provisioning such as ownership tranfer to Enrollee.
80 * @param callback will give the result if the security provisioning succeeds or fails for some reasons
82 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
84 * @see SecurityProvStatusCb
86 void provisionSecurity(const SecurityProvStatusCb callback);
89 * Provision WiFi AP information and device configuration to Enrollee
90 * 1. WiFi AP information includes a SSID, password, auth type, and encryption type.
91 * 2. Device configuration includes a language (IETF language tags) and country (ISO 3166-1 Alpha-2)
93 * @param devProp a data structure storing the above information to be delivered
94 * @param callback will give the result if the provisioning succeeds or fails
96 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
99 * @see DevicePropProvStatusCb
101 void provisionDeviceProperties(const DeviceProp& devProp,
102 const DevicePropProvStatusCb callback);
105 * Provision Cloud information to Enrollee, which includes Auth code, auth provider,
106 * Cloud interface server URL, and etc.
107 * In this function, Discovery for the Enrollee will happen again in a given network.
108 * Because, this function is expected to call *AFTER* the Enrollee disconnects its Soft AP
109 * and successfully connects to the certain WiFi AP. In that case, Mediator should discover
110 * the Enrollee with a certain Device ID in the network.
112 * @param cloudProp 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 ESBadRequestException If RemoteEnrollee device not created prior to this call.
118 * @see CloudPropProvStatusCb
120 void provisionCloudProperties(const CloudProp& cloudProp,
121 const CloudPropProvStatusCb callback);
124 RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource);
126 ESResult discoverResource();
127 void onDeviceDiscovered(const std::shared_ptr<OC::OCResource> resource);
128 void initCloudResource();
130 void getStatusHandler
131 (const std::shared_ptr< GetEnrolleeStatus > status) const;
132 void getConfigurationStatusHandler
133 (const std::shared_ptr< GetConfigurationStatus > status) const;
134 void devicePropProvisioningStatusHandler
135 (const std::shared_ptr< DevicePropProvisioningStatus > status) const;
136 void cloudPropProvisioningStatusHandler
137 (const std::shared_ptr< CloudPropProvisioningStatus > status) const;
138 void securityStatusHandler
139 (const std::shared_ptr< SecProvisioningStatus > status) const;
142 std::shared_ptr< OC::OCResource > m_ocResource;
143 std::shared_ptr< EnrolleeResource > m_enrolleeResource;
144 std::shared_ptr< EnrolleeSecurity > m_enrolleeSecurity;
145 std::shared_ptr< CloudResource > m_cloudResource;
147 std::string m_deviceId;
148 bool m_discoveryResponse;
150 std::mutex m_discoverymtx;
151 std::condition_variable m_cond;
153 SecurityProvStatusCb m_securityProvStatusCb;
154 GetStatusCb m_getStatusCb;
155 GetConfigurationStatusCb m_getConfigurationStatusCb;
156 SecurityPinCb m_securityPinCb;
157 SecProvisioningDbPathCb m_secProvisioningDbPathCb;
158 DevicePropProvStatusCb m_devicePropProvStatusCb;
159 CloudPropProvStatusCb m_cloudPropProvStatusCb;
161 friend class EasySetup;
166 #endif //REMOTE_ENROLLEE_H_