1 //******************************************************************
3 // Copyright 2016 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 ES_COMMON_RICH_H_
22 #define ES_COMMON_RICH_H_
31 #include "OCPlatform.h"
46 * @brief Properties of provisioning resource. It includes a provisioning status and last
56 EnrolleeStatus(const OCRepresentation& rep) { m_rep = rep; }
59 * Get a provisioning status property of Enrollee.
61 * @return a provisioning status property of Enrollee
63 ProvStatus getProvStatus()
65 if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
66 return static_cast<ProvStatus>(
67 m_rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
72 * Get a last error code property of Enrollee.
74 * @return a last error code property of Enrollee.
76 ESErrorCode getLastErrCode()
78 if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
79 return static_cast<ESErrorCode>(
80 m_rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
81 return ES_ERRCODE_NO_ERROR;
85 * Get OCRepresentation object
87 * @return OCRepresentation object
89 const OCRepresentation& getRepresentation()
94 OCRepresentation m_rep;
98 * @brief Data class stored for Cloud server property provisioning
110 * Constructor with OCRepresentation object. This is used for JNI communication.
112 CloudProp(const OCRepresentation &rep)
119 * Set CloudServer resource properties to be delivered to Enrollee
121 * @param authCode Auth code issued by OAuth2.0-compatible account server
122 * @param authProvider Auth provider ID
123 * @param ciServer Cloud interface server URL which an Enrollee is going to registered
125 void setCloudProp(string authCode, string authProvider, string ciServer)
127 m_rep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
128 m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
129 m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
133 * Set CloudServer's UUID
135 * @param cloudID Cloud Interface server's UUID
137 void setCloudID(string cloudID)
143 * Get an auth code to be delivered.
145 * @return an auth code to be delivered.
147 std::string getAuthCode()
149 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
150 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
151 return std::string("");
155 * Get an auth provider which issued an auth code
157 * @return an auth provider which issued an auth code
159 std::string getAuthProvider()
161 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
162 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
163 return std::string("");
167 * Get a CI server to be delivered
169 * @return a CI server to be delivered
171 std::string getCiServer()
173 if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
174 return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
175 return std::string("");
179 * Get a CI server's Uuid to be delivered
181 * @return a CI server's Uuid to be delivered
183 std::string getCloudID() const
189 * Get OCRepresentation object
191 * @return OCRepresentation object
193 const OCRepresentation &toOCRepresentation() const
198 OCRepresentation m_rep;
199 std::string m_cloudID;
203 * @brief Data class stored for Device property provisioning which includes a WiFi
204 * and device configuration provisioning
216 * Constructor with OCRepresentation object. This is used for JNI communication.
218 DeviceProp(const OCRepresentation &rep) { m_rep = rep; }
221 * Set WiFi resource properties to be delivered to Enrollee
223 * @param ssid Ssid of the Enroller
224 * @param pwd Pwd of the Enrolle
225 * @param authtype Auth type of the Enroller
226 * @param enctype Encryption type of the Enroller
231 void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
233 m_rep.setValue(OC_RSRVD_ES_SSID, ssid);
234 m_rep.setValue(OC_RSRVD_ES_CRED, pwd);
235 m_rep.setValue(OC_RSRVD_ES_AUTHTYPE, authtype);
236 m_rep.setValue(OC_RSRVD_ES_ENCTYPE, enctype);
240 * Set DevConf resource properties to be delivered to Enrollee
242 * @param language IETF language tag using ISO 639X
243 * @param country ISO Country Code (ISO 3166-1 Alpha-2)
245 void setDevConfProp(string language, string country)
247 m_rep.setValue(OC_RSRVD_ES_LANGUAGE, language);
248 m_rep.setValue(OC_RSRVD_ES_COUNTRY, country);
252 * Get a SSID of Enroller
254 * @return a SSID of enroller
256 std::string getSsid()
258 if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
259 return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
260 return std::string("");
264 * Get a password of Enroller
266 * @return a password of enroller
268 std::string getPassword()
270 if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
271 return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
272 return std::string("");
276 * Get an auth type of Enroller
278 * @return an auth type of enroller
282 WIFI_AUTHTYPE getAuthType()
284 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
285 return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
290 * Get an encryption type of Enroller
292 * @return an encryption type of enroller
296 WIFI_ENCTYPE getEncType()
298 if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
299 return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
304 * Get a language to be set. A language is expressed in IETF language tag
307 * @return a language to be set
309 std::string getLanguage()
311 if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
312 return m_rep.getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
313 return std::string("");
317 * Get a country to be set. A country is expressed in ISO Country Code
318 * (ISO 3166-1 Alpha-2)
320 * @return a country to be set
322 std::string getCountry()
324 if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
325 return m_rep.getValue<std::string>(OC_RSRVD_ES_COUNTRY);
326 return std::string("");
330 * Get OCRepresentation object
332 * @return OCRepresentation object
334 const OCRepresentation &toOCRepresentation() const
340 OCRepresentation m_rep;
344 * @brief Provisioning state in cloud server property provisioning.
348 ES_CLOUD_PROVISIONING_ERROR = -1, /**< An error in cloud provisioning happens **/
349 ES_CLOUD_PROVISIONING_SUCCESS, /**< Cloud provisioning is successfully done **/
350 ES_CLOUD_ENROLLEE_FOUND, /**< An enrollee is found in a given network **/
351 ES_CLOUD_ENROLLEE_NOT_FOUND /**< NO enrollee is found in a given network **/
355 * Security Provisioning Status
357 class SecProvisioningStatus
360 SecProvisioningStatus(string deviceUUID, ESResult result) :
361 m_devUUID(deviceUUID), m_result(result)
365 const string getDeviceUUID()
370 ESResult getESResult()
380 * @breif This provide a set of getter APIs from received response for getConfiguration().
381 * Received information includes a device name, WiFi supported mode, and frequency.
382 * Additionally, you can know if Enrollee can be access to cloud server with this
390 * The expected OCRepresentation is one for collection resource and has several child
391 * OCRepresentation object corresponding to WiFi, DevConf, and CloudServer resource's
394 EnrolleeConf(const OCRepresentation& rep)
398 std::vector<OCRepresentation> children = rep.getChildren();
400 for(auto child = children.begin(); child != children.end(); ++child)
402 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
406 else if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
408 m_DevConfRep = *child;
410 else if(child->getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
418 * Get a device name of Enrollee. It is Device's human-friendly name like device model
421 * @return a device name of Enrollee
423 std::string getDeviceName()
425 if(m_DevConfRep.hasAttribute(OC_RSRVD_ES_DEVNAME))
426 return m_DevConfRep.getValue<std::string>(OC_RSRVD_ES_DEVNAME);
427 return std::string("");
431 * Get a set of WiFi supported modes of Enrollee
433 * @return a set of WiFi supported modes of Enrollee
437 vector<WIFI_MODE> getWiFiModes()
439 vector<WIFI_MODE> modes;
442 if(m_WiFiRep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
444 for(auto it : m_WiFiRep.getValue
445 <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
447 modes.push_back(static_cast<WIFI_MODE>(it));
454 * Get a WiFi supported frequency of Enrollee
456 * @return a WiFi supported frequency of Enrollee
460 WIFI_FREQ getWiFiFreq()
462 if(m_WiFiRep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
463 return static_cast<WIFI_FREQ>(
464 m_WiFiRep.getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
465 return WIFI_FREQ_NONE;
469 * Get an accessibility to cloud server of an Enrollee
471 * @return an accessibility to cloud server of an Enrollee
473 bool isCloudAccessible()
475 if(m_CloudRep.getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
483 * Get OCRepresentation object
485 * @return OCRepresentation object
487 const OCRepresentation& getProvResRep()
493 OCRepresentation m_ProvRep, m_WiFiRep, m_DevConfRep, m_CloudRep;
497 * Status object for getStatus API. This object is given to application
498 * when a response for GET request to provisioning resource at Enrollee is arrived.
499 * It returns a result of the API and requested data delivered in the response which includes
500 * a provisioning status and last error code stored in Enrollee.
502 * @see EnrolleeStatus
504 class GetEnrolleeStatus
507 GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
508 m_result(result), m_enrolleeStatus(status)
512 ESResult getESResult()
517 const EnrolleeStatus& getEnrolleeStatus()
519 return m_enrolleeStatus;
524 EnrolleeStatus m_enrolleeStatus;
528 * Status object for getConfiguration API. This object is given to application
529 * when a response for GET request to provisioning resource at Enrollee is arrived.
530 * It returns a result of the API and requested data delivered in the response which includes
531 * WiFi configuration and device configuration stored in Enrollee.
535 class GetConfigurationStatus
538 GetConfigurationStatus(ESResult result, const EnrolleeConf& conf) :
539 m_result(result), m_enrolleeConf(conf)
543 ESResult getESResult()
548 const EnrolleeConf& getEnrolleeConf()
550 return m_enrolleeConf;
555 EnrolleeConf m_enrolleeConf;
559 * Status object for provisionDeviceProperties API. This object is given to application
560 * when a response for GET request to provisioning resource at Enrollee is arrived.
561 * It returns a result of the request.
563 class DevicePropProvisioningStatus
566 DevicePropProvisioningStatus(ESResult result) :
571 ESResult getESResult()
582 * Status object for provisionCloudProperties API. This object is given to application
583 * when a response for GET request to provisioning resource at Enrollee is arrived.
584 * It returns a result of the request and status of this provisioning. The status provides
585 * an information if the enrollee is found in a given network and the provisioning is
588 class CloudPropProvisioningStatus
591 CloudPropProvisioningStatus(ESResult result, ESCloudProvState state) :
592 m_result(result), m_esCloudState(state)
596 ESResult getESResult()
601 ESCloudProvState getESCloudState()
603 return m_esCloudState;
608 ESCloudProvState m_esCloudState;
612 * Callback function definition for providing Enrollee status
614 typedef function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb;
617 * Callback function definition for providing Enrollee configuration status
619 typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
622 * Callback function definition for providing Enrollee device property provisioning status
624 typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
627 * Callback function definition for providing Enrollee cloud property provisioning status
629 typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
632 * Callback function definition for providing Enrollee security provisioning status
634 typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
637 * Callback definition to be invoked when the security stack expects a pin from application
639 typedef function< void(string&) > SecurityPinCb;
642 * Callback definition to be invoked when the stack expects a db path
644 typedef function< void(string&) > SecProvisioningDbPathCb;
648 #endif //WITH_ARDUINO
650 #endif //ES_COMMON_RICH_H_