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)
61 EnrolleeStatus(const EnrolleeStatus& enrolleeStatus) :
62 m_rep(enrolleeStatus.getRepresentation())
66 EnrolleeStatus(const EnrolleeStatus&& enrolleeStatus) :
67 m_rep(std::move(enrolleeStatus.getRepresentation()))
72 * Get a provisioning status property of Enrollee.
74 * @return a provisioning status property of Enrollee
76 ProvStatus getProvStatus()
78 if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
80 return static_cast<ProvStatus>(
81 m_rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
87 * Get a last error code property of Enrollee.
89 * @return a last error code property of Enrollee.
91 ESErrorCode getLastErrCode()
93 if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
95 return static_cast<ESErrorCode>(
96 m_rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
98 return ES_ERRCODE_NO_ERROR;
102 * Get OCRepresentation object
104 * @return OCRepresentation object
106 const OCRepresentation& getRepresentation() const
111 OCRepresentation m_rep;
115 * @brief Data class stored for Cloud server property provisioning
130 CloudProp(const CloudProp& cloudProp) :
131 m_rep(cloudProp.toOCRepresentation()),
132 m_cloudID(cloudProp.getCloudID()),
133 m_credID(cloudProp.getCredID())
137 CloudProp(const CloudProp&& cloudProp) :
138 m_rep(std::move(cloudProp.toOCRepresentation())),
139 m_cloudID(cloudProp.getCloudID()),
140 m_credID(cloudProp.getCredID())
145 * Constructor with OCRepresentation object. This is used for JNI communication.
147 CloudProp(const OCRepresentation &rep)
155 * Set CloudServer resource properties to be delivered to Enrollee
157 * @param authCode Auth code issued by OAuth2.0-compatible account server
158 * @param authProvider Auth provider ID
159 * @param ciServer Cloud interface server URL which an Enrollee is going to registered
161 void setCloudProp(string authCode, string authProvider, string ciServer)
163 m_rep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
164 m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
165 m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
169 * Set CloudServer's UUID
171 * @param cloudID Cloud Interface server's UUID
173 void setCloudID(string cloudID)
179 * Set CloudServer's credential ID of certificate
181 * @param credID Cloud Interface server's credential ID of certificate
183 void setCredID(int credID)
189 * Get an auth code to be delivered.
191 * @return an auth code to be delivered.
193 std::string getAuthCode() const
195 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
197 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
199 return std::string("");
203 * Get an auth provider which issued an auth code
205 * @return an auth provider which issued an auth code
207 std::string getAuthProvider() const
209 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
211 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
213 return std::string("");
217 * Get a CI server to be delivered
219 * @return a CI server to be delivered
221 std::string getCiServer() const
223 if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
225 return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
227 return std::string("");
231 * Get a CI server's Uuid to be delivered
233 * @return a CI server's Uuid to be delivered
235 std::string getCloudID() const
241 * Get a CI server's credential ID of certificate
243 * @return a CI server's credential ID of certificated
245 int getCredID() const
251 * Get OCRepresentation object
253 * @return OCRepresentation object
255 const OCRepresentation &toOCRepresentation() const
260 OCRepresentation m_rep;
261 std::string m_cloudID;
266 * @brief Data class stored for Device property provisioning which includes a WiFi
267 * and device configuration provisioning
280 DeviceProp(const DeviceProp& deviceProp) :
281 m_rep(deviceProp.toOCRepresentation())
285 DeviceProp(const DeviceProp&& deviceProp) :
286 m_rep(std::move(deviceProp.toOCRepresentation()))
291 * Constructor with OCRepresentation object. This is used for JNI communication.
293 DeviceProp(const OCRepresentation &rep)
299 * Set WiFi resource properties to be delivered to Enrollee
301 * @param ssid Ssid of the Enroller
302 * @param pwd Pwd of the Enrolle
303 * @param authtype Auth type of the Enroller
304 * @param enctype Encryption type of the Enroller
309 void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
311 m_rep.setValue(OC_RSRVD_ES_SSID, ssid);
312 m_rep.setValue(OC_RSRVD_ES_CRED, pwd);
313 m_rep.setValue(OC_RSRVD_ES_AUTHTYPE, authtype);
314 m_rep.setValue(OC_RSRVD_ES_ENCTYPE, enctype);
318 * Set DevConf resource properties to be delivered to Enrollee
320 * @param language IETF language tag using ISO 639X
321 * @param country ISO Country Code (ISO 3166-1 Alpha-2)
323 void setDevConfProp(string language, string country, string location)
325 m_rep.setValue(OC_RSRVD_ES_LANGUAGE, language);
326 m_rep.setValue(OC_RSRVD_ES_COUNTRY, country);
327 m_rep.setValue(OC_RSRVD_ES_LOCATION, location);
331 * Get a SSID of Enroller
333 * @return a SSID of enroller
335 std::string getSsid() const
337 if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
339 return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
341 return std::string("");
345 * Get a password of Enroller
347 * @return a password of enroller
349 std::string getPassword() const
351 if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
353 return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
355 return std::string("");
359 * Get an auth type of Enroller
361 * @return an auth type of enroller
365 WIFI_AUTHTYPE getAuthType() const
367 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
369 return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
375 * Get an encryption type of Enroller
377 * @return an encryption type of enroller
381 WIFI_ENCTYPE getEncType() const
383 if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
385 return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
391 * Get a language to be set. A language is expressed in IETF language tag
394 * @return a language to be set
396 std::string getLanguage() const
398 if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
400 return m_rep.getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
402 return std::string("");
406 * Get a country to be set. A country is expressed in ISO Country Code
407 * (ISO 3166-1 Alpha-2)
409 * @return a country to be set
411 std::string getCountry() const
413 if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
415 return m_rep.getValue<std::string>(OC_RSRVD_ES_COUNTRY);
417 return std::string("");
421 * Get a location to be set. A location is GPS information
423 * @return a country to be set
425 std::string getLocation() const
427 if(m_rep.hasAttribute(OC_RSRVD_ES_LOCATION))
429 return m_rep.getValue<std::string>(OC_RSRVD_ES_LOCATION);
431 return std::string("");
435 * Get OCRepresentation object
437 * @return OCRepresentation object
439 const OCRepresentation &toOCRepresentation() const
445 OCRepresentation m_rep;
449 * Security Provisioning Status
451 class SecProvisioningStatus
454 SecProvisioningStatus(string deviceUUID, ESResult result) :
455 m_devUUID(deviceUUID), m_result(result)
459 const string getDeviceUUID()
465 * Get a result for about security provisioning is success or not.
468 * ::ES_SEC_OPERATION_IS_NOT_SUPPORTED\n
469 * ::ES_SECURE_RESOURCE_DISCOVERY_FAILURE\n
470 * ::ES_OWNERSHIP_TRANSFER_FAILURE\n
473 ESResult getESResult()
483 * @breif This provide a set of getter APIs from received response for getConfiguration().
484 * Received information includes a device name, WiFi supported mode, and frequency.
485 * Additionally, you can know if Enrollee can be access to cloud server with this
493 * The expected OCRepresentation is one for collection resource and has several child
494 * OCRepresentation object corresponding to WiFi, DevConf, and CloudServer resource's
497 EnrolleeConf(const OCRepresentation& rep) :
502 EnrolleeConf(const EnrolleeConf& enrolleeConf) :
503 m_ProvRep(enrolleeConf.getProvResRep())
507 EnrolleeConf(const EnrolleeConf&& enrolleeConf) :
508 m_ProvRep(std::move(enrolleeConf.getProvResRep()))
513 * Get a device name of Enrollee. It is Device's human-friendly name like device model
516 * @return a device name of Enrollee
518 std::string getDeviceName() const
520 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
521 for(auto child = children.begin(); child != children.end(); ++child)
523 if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
525 OCRepresentation rep;
526 if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
528 rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
532 return std::string("");
535 if(rep.hasAttribute(OC_RSRVD_ES_DEVNAME))
537 return rep.getValue<std::string>(OC_RSRVD_ES_DEVNAME);
541 return std::string("");
545 * Get a model number of Enrollee.
547 * @return a model number of Enrollee
549 std::string getModelNumber() const
551 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
552 for(auto child = children.begin(); child != children.end(); ++child)
554 if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
556 OCRepresentation rep;
557 if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
559 rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
563 return std::string("");
566 if(rep.hasAttribute(OC_RSRVD_ES_MODELNUMBER))
568 return rep.getValue<std::string>(OC_RSRVD_ES_MODELNUMBER);
572 return std::string("");
576 * Get a set of WiFi supported modes of Enrollee
578 * @return a set of WiFi supported modes of Enrollee
582 vector<WIFI_MODE> getWiFiModes() const
584 vector<WIFI_MODE> modes;
587 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
588 for(auto child = children.begin(); child != children.end(); ++child)
590 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
592 OCRepresentation rep;
593 if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
595 rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
602 if(rep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
604 for(auto it : rep.getValue
605 <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
607 modes.push_back(static_cast<WIFI_MODE>(it));
616 * Get a WiFi supported frequency of Enrollee
618 * @return a WiFi supported frequency of Enrollee
622 WIFI_FREQ getWiFiFreq() const
624 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
625 for(auto child = children.begin(); child != children.end(); ++child)
627 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
629 OCRepresentation rep;
630 if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
632 rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
636 return WIFI_FREQ_NONE;
639 if(rep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
641 return static_cast<WIFI_FREQ>(
642 rep.getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
646 return WIFI_FREQ_NONE;
650 * Get an accessibility to cloud server of an Enrollee
652 * @return an accessibility to cloud server of an Enrollee
654 bool isCloudAccessible() const
656 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
657 for(auto child = children.begin(); child != children.end(); ++child)
659 for(auto rt : child->getResourceTypes())
661 if(0 == rt.compare(OC_RSRVD_ES_RES_TYPE_CLOUDSERVER))
671 * Get OCRepresentation object
673 * @return OCRepresentation object
675 const OCRepresentation& getProvResRep() const
681 OCRepresentation m_ProvRep;
685 * Status object for getStatus API. This object is given to application
686 * when a response for GET request to provisioning resource at Enrollee is arrived.
687 * It returns a result of the API and requested data delivered in the response which includes
688 * a provisioning status and last error code stored in Enrollee.
690 * @see EnrolleeStatus
692 class GetEnrolleeStatus
698 GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
699 m_result(result), m_enrolleeStatus(status)
704 * Get a result of getting provisioning status and last error code of Enrollee
707 * ::ES_COMMUNICATION_ERROR\n
711 ESResult getESResult()
717 * Get Enrollee's status and last error code properties
719 * @return Enrollee's status and last error code properties
721 * @see EnrolleeStatus
723 const EnrolleeStatus& getEnrolleeStatus()
725 return m_enrolleeStatus;
730 EnrolleeStatus m_enrolleeStatus;
734 * Status object for getConfiguration API. This object is given to application
735 * when a response for GET request to provisioning resource at Enrollee is arrived.
736 * It returns a result of the API and requested data delivered in the response which includes
737 * WiFi configuration and device configuration stored in Enrollee.
741 class GetConfigurationStatus
747 GetConfigurationStatus(ESResult result, const EnrolleeConf& conf) :
748 m_result(result), m_enrolleeConf(conf)
753 * Get a result of getting preconfiguration of Enrollee
756 * ::ES_COMMUNICATION_ERROR\n
761 ESResult getESResult()
767 * Get Enrollee's pre-configuration properties
769 * @return Enrollee's pre-configuration properties
773 EnrolleeConf& getEnrolleeConf()
775 return m_enrolleeConf;
780 EnrolleeConf m_enrolleeConf;
784 * Status object for provisionDeviceProperties API. This object is given to application
785 * when a response for GET request to provisioning resource at Enrollee is arrived.
786 * It returns a result of the request.
788 class DevicePropProvisioningStatus
794 DevicePropProvisioningStatus(ESResult result) :
800 * Get a result of Device property provisioning
803 * ::ES_COMMUNICATION_ERROR\n
808 ESResult getESResult()
818 * Status object for provisionCloudProperties API. This object is given to application
819 * when a response for GET request to provisioning resource at Enrollee is arrived.
820 * It returns a result of the request and status of this provisioning. The status provides
821 * an information if the enrollee is found in a given network and the provisioning is
824 class CloudPropProvisioningStatus
830 CloudPropProvisioningStatus(ESResult result) :
836 * Get a result of Cloud property provisioning
839 * ::ES_ENROLLEE_DISCOVERY_FAILURE\n
840 * ::ES_SECURE_RESOURCE_DISCOVERY_FAILURE\n
841 * ::ES_ACL_PROVISIONING_FAILURE\n
842 * ::ES_CERT_PROVISIONING_FAILURE\n
843 * ::ES_COMMUNICATION_ERROR\n
848 ESResult getESResult()
858 * Callback function definition for providing Enrollee status
860 typedef function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb;
863 * Callback function definition for providing Enrollee configuration status
865 typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
868 * Callback function definition for providing Enrollee device property provisioning status
870 typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
873 * Callback function definition for providing Enrollee cloud property provisioning status
875 typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
878 * Callback function definition for providing Enrollee security provisioning status
880 typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
883 * Callback definition to be invoked when the security stack expects a pin from application
885 typedef function< void(string&) > SecurityPinCb;
888 * Callback definition to be invoked when the stack expects a db path
890 typedef function< void(string&) > SecProvisioningDbPathCb;
894 #endif //WITH_ARDUINO
896 #endif //ES_COMMON_RICH_H_