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;
57 * Register Security status and other information callback handlers.
59 * @param secProvisioningDbCb Callback to be invoked when the stack expects a
60 * path for the provisioning db.
61 * @param securityPinCb Callback to get security pin during pin based ownership transfer.
63 * @throws InvalidParameterException If callback is an empty function or null.
64 * @throws ESBadRequestException If registration is already completed.
66 * @see SecProvisioningResult
68 ESResult registerSecurityCallbackHandler(const SecurityPinCb securityPinCb,
69 const SecProvisioningDbPathCb secProvisioningDbPathCb);
70 #endif //__WITH_DTLS__
73 * Get an Enrollee's status which includes provisioning status and last error code
75 * @param callback will give the requested status
77 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
81 void getStatus(const GetStatusCb callback);
84 * Get an Enrollee's configuration which includes WiFi supported frequency and device name
86 * @param callback will give the requested configuration
88 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
90 * @see GetConfigurationStatusCb
92 void getConfiguration(const GetConfigurationStatusCb callback);
95 * Do security provisioning such as ownership tranfer to Enrollee.
97 * @param callback will give the result if the security provisioning succeeds or fails for some reasons
99 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
101 * @see SecurityProvStatusCb
103 void provisionSecurity(const SecurityProvStatusCb callback);
106 * Provision WiFi AP information and device configuration to Enrollee
107 * 1. WiFi AP information includes a SSID, password, auth type, and encryption type.
108 * 2. Device configuration includes a language (IETF language tags) and country (ISO 3166-1 Alpha-2)
110 * @param devProp a data structure storing the above information to be delivered
111 * @param callback will give the result if the provisioning succeeds or fails
113 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
116 * @see DevicePropProvStatusCb
118 void provisionDeviceProperties(const DeviceProp& devProp,
119 const DevicePropProvStatusCb callback);
122 * Provision Cloud information to Enrollee, which includes Auth code, auth provider,
123 * Cloud interface server URL, and etc.
124 * In this function, Discovery for the Enrollee will happen again in a given network.
125 * Because, this function is expected to call *AFTER* the Enrollee disconnects its Soft AP
126 * and successfully connects to the certain WiFi AP. In that case, Mediator should discover
127 * the Enrollee with a certain Device ID in the network.
129 * @param cloudProp a data structure storing the above information to be delivered
130 * @param callback will give the result if the provisioning succeeds or fails
132 * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
135 * @see CloudPropProvStatusCb
137 void provisionCloudProperties(const CloudProp& cloudProp,
138 const CloudPropProvStatusCb callback);
141 RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource);
143 ESResult discoverResource();
144 void onDeviceDiscovered(const std::shared_ptr<OC::OCResource> resource);
145 void initCloudResource();
147 void getStatusHandler
148 (const std::shared_ptr< GetEnrolleeStatus > status) const;
149 void getConfigurationStatusHandler
150 (const std::shared_ptr< GetConfigurationStatus > status) const;
151 void devicePropProvisioningStatusHandler
152 (const std::shared_ptr< DevicePropProvisioningStatus > status) const;
153 void cloudPropProvisioningStatusHandler
154 (const std::shared_ptr< CloudPropProvisioningStatus > status) const;
155 void securityStatusHandler
156 (const std::shared_ptr< SecProvisioningStatus > status) const;
159 std::shared_ptr< OC::OCResource > m_ocResource;
160 std::shared_ptr< EnrolleeResource > m_enrolleeResource;
161 std::shared_ptr< EnrolleeSecurity > m_enrolleeSecurity;
162 std::shared_ptr< CloudResource > m_cloudResource;
164 std::string m_deviceId;
165 bool m_discoveryResponse;
167 std::mutex m_discoverymtx;
168 std::condition_variable m_cond;
170 SecurityProvStatusCb m_securityProvStatusCb;
171 GetStatusCb m_getStatusCb;
172 GetConfigurationStatusCb m_getConfigurationStatusCb;
173 SecurityPinCb m_securityPinCb;
174 SecProvisioningDbPathCb m_secProvisioningDbPathCb;
175 DevicePropProvStatusCb m_devicePropProvStatusCb;
176 CloudPropProvStatusCb m_cloudPropProvStatusCb;
178 friend class EasySetup;
183 #endif //REMOTE_ENROLLEE_H_