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 ESBadRequestException If RemoteEnrollee device not created prior to this call.
66 void getStatus(const GetStatusCb callback);
69 * Get an Enrollee's configuration which includes WiFi supported frequency and device name
71 * @param callback will give the requested configuration
73 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
75 * @see GetConfigurationStatusCb
77 void getConfiguration(const GetConfigurationStatusCb callback);
80 * Do security provisioning such as ownership tranfer to Enrollee.
82 * @param callback will give the result if the security provisioning succeeds or fails for some reasons
84 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
86 * @see SecurityProvStatusCb
88 void provisionSecurity(const SecurityProvStatusCb callback);
91 * Provision WiFi AP information and device configuration to Enrollee
92 * 1. WiFi AP information includes a SSID, password, auth type, and encryption type.
93 * 2. Device configuration includes a language (IETF language tags) and country (ISO 3166-1 Alpha-2)
95 * @param devProp a data structure storing the above information to be delivered
96 * @param callback will give the result if the provisioning succeeds or fails
98 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
101 * @see DevicePropProvStatusCb
103 void provisionDeviceProperties(const DeviceProp& devProp,
104 const DevicePropProvStatusCb callback);
107 * Provision Cloud information to Enrollee, which includes Auth code, auth provider,
108 * Cloud interface server URL, and etc.
109 * In this function, Discovery for the Enrollee will happen again in a given network.
110 * Because, this function is expected to call *AFTER* the Enrollee disconnects its Soft AP
111 * and successfully connects to the certain WiFi AP. In that case, Mediator should discover
112 * the Enrollee with a certain Device ID in the network.
114 * @param cloudProp a data structure storing the above information to be delivered
115 * @param callback will give the result if the provisioning succeeds or fails
117 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
120 * @see CloudPropProvStatusCb
122 void provisionCloudProperties(const CloudProp& cloudProp,
123 const CloudPropProvStatusCb callback);
126 RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource);
128 ESResult discoverResource();
130 static void onDiscoveredCallback(const std::shared_ptr<OC::OCResource> resource,
131 std::weak_ptr<RemoteEnrollee> this_ptr);
133 void onDeviceDiscovered(const std::shared_ptr<OC::OCResource> resource);
134 void initCloudResource();
136 void getStatusHandler
137 (const std::shared_ptr< GetEnrolleeStatus > status) const;
138 void getConfigurationStatusHandler
139 (const std::shared_ptr< GetConfigurationStatus > status) const;
140 void devicePropProvisioningStatusHandler
141 (const std::shared_ptr< DevicePropProvisioningStatus > status) const;
142 void cloudPropProvisioningStatusHandler
143 (const std::shared_ptr< CloudPropProvisioningStatus > status) const;
144 void securityStatusHandler
145 (const std::shared_ptr< SecProvisioningStatus > status) const;
148 std::shared_ptr< OC::OCResource > m_ocResource;
149 std::shared_ptr< EnrolleeResource > m_enrolleeResource;
150 std::shared_ptr< EnrolleeSecurity > m_enrolleeSecurity;
151 std::shared_ptr< CloudResource > m_cloudResource;
153 std::string m_deviceId;
154 bool m_discoveryResponse;
156 std::mutex m_discoverymtx;
157 std::condition_variable m_cond;
159 SecurityProvStatusCb m_securityProvStatusCb;
160 GetStatusCb m_getStatusCb;
161 GetConfigurationStatusCb m_getConfigurationStatusCb;
162 SecurityPinCb m_securityPinCb;
163 SecProvisioningDbPathCb m_secProvisioningDbPathCb;
164 DevicePropProvStatusCb m_devicePropProvStatusCb;
165 CloudPropProvStatusCb m_cloudPropProvStatusCb;
167 friend class EasySetup;
172 #endif //REMOTE_ENROLLEE_H_