replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / inc / ESRichCommon.h
1 //******************************************************************
2 //
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef ES_COMMON_RICH_H_
22 #define ES_COMMON_RICH_H_
23
24 #include <iostream>
25 #include <string>
26 #ifndef WITH_ARDUINO
27 #include <memory>
28 #include <vector>
29 #endif
30
31 #include "OCPlatform.h"
32 #include "ocstack.h"
33 #include "octypes.h"
34 #ifdef __WITH_DTLS__
35 #include "securevirtualresourcetypes.h"
36 #include "OCProvisioningManager.hpp"
37 #include "ocrandom.h"
38 #endif
39
40 #include "escommon.h"
41
42 using namespace OC;
43 using namespace std;
44
45 #ifndef WITH_ARDUINO
46 namespace OIC
47 {
48     namespace Service
49     {
50         /**
51          * @brief Properties of easysetup resource. It includes a provisioning status and last
52          *        error code.
53          */
54         class EnrolleeStatus
55         {
56         public:
57
58             /**
59              * Constructor
60              */
61             EnrolleeStatus(const OCRepresentation& rep)
62             {
63                 m_rep = rep;
64             }
65
66             EnrolleeStatus(const EnrolleeStatus& enrolleeStatus) :
67                 m_rep(enrolleeStatus.getRepresentation())
68             {
69             }
70
71             EnrolleeStatus(const EnrolleeStatus&& enrolleeStatus) :
72                 m_rep(std::move(enrolleeStatus.getRepresentation()))
73             {
74             }
75
76             /**
77              * Get a provisioning status property of Enrollee.
78              *
79              * @return a provisioning status property of Enrollee
80              */
81             ProvStatus getProvStatus() const
82             {
83                 if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
84                 {
85                     return static_cast<ProvStatus>(
86                                         m_rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
87                 }
88                 return ES_STATE_INIT;
89             }
90
91             /**
92              * Get a last error code property of Enrollee.
93              *
94              * @return a last error code property of Enrollee.
95              */
96             ESErrorCode getLastErrCode() const
97             {
98                 if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
99                 {
100                     return static_cast<ESErrorCode>(
101                                         m_rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
102                 }
103                 return ES_ERRCODE_NO_ERROR;
104             }
105
106             /**
107              * Get OCRepresentation object
108              *
109              * @return OCRepresentation object
110              */
111             const OCRepresentation& getRepresentation() const
112             {
113                 return m_rep;
114             }
115         protected:
116             OCRepresentation m_rep;
117         };
118
119         /**
120          * @brief Data class stored for provisioning of coap cloud server properties
121          */
122         class CloudProp
123         {
124         public:
125
126             /**
127              * Constructor
128              */
129             CloudProp()
130             {
131                 m_cloudID = "";
132                 m_credID = 0;
133             }
134
135             CloudProp(const CloudProp& cloudProp) :
136                                             m_rep(cloudProp.toOCRepresentation()),
137                                             m_cloudID(cloudProp.getCloudID()),
138                                             m_credID(cloudProp.getCredID())
139             {
140             }
141
142             CloudProp(const CloudProp&& cloudProp) :
143                                             m_rep(std::move(cloudProp.toOCRepresentation())),
144                                             m_cloudID(cloudProp.getCloudID()),
145                                             m_credID(cloudProp.getCredID())
146             {
147             }
148
149             /**
150              * Constructor with OCRepresentation object. This is used for JNI communication.
151              */
152             CloudProp(const OCRepresentation &rep)
153             {
154                 m_rep = rep;
155                 m_cloudID = "";
156                 m_credID = 0;
157             }
158
159             /**
160              * Set CoapCloudConf resource properties to be delivered to Enrollee
161              *
162              * @param authCode  Auth code issued by OAuth2.0-compatible account server
163              * @param authProvider Auth provider ID
164              * @param ciServer Cloud interface server URL which an Enrollee is going to registered
165              */
166             void setCloudProp(string authCode, string authProvider, string ciServer)
167             {
168                 m_rep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
169                 m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
170                 m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
171             }
172
173             /**
174              * Set CoapCloudConf resource properties with Access token to be delivered to Enrollee
175              *
176              * @param accessToken  Access token which is given in a return of auth code issued by
177              *                     OAuth2.0-compatible account server
178              * @param tokenType Access token type, i.e. "bearer"
179              * @param authProvider Auth provider ID
180              * @param ciServer Cloud interface server URL which an Enrollee is going to registered
181              *
182              * @see OAUTH_TOKENTYPE
183              */
184             void setCloudPropWithAccessToken(string accessToken, OAUTH_TOKENTYPE tokenType,
185                                                 string authProvider, string ciServer)
186             {
187                 m_rep.setValue(OC_RSRVD_ES_ACCESSTOKEN, accessToken);
188                 m_rep.setValue(OC_RSRVD_ES_ACCESSTOKEN_TYPE, tokenType);
189                 m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
190                 m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
191             }
192
193             /**
194              * Set CloudServer's UUID
195              *
196              * @param cloudID Cloud Interface server's UUID
197              */
198             void setCloudID(string cloudID)
199             {
200                 m_cloudID = cloudID;
201             }
202
203             /**
204              * Set CloudServer's credential ID of certificate
205              *
206              * @param credID Cloud Interface server's credential ID of certificate
207              */
208             void setCredID(int credID)
209             {
210                 m_credID = credID;
211             }
212
213             /**
214              * Get an auth code to be delivered.
215              *
216              * @return an auth code to be delivered.
217              */
218             std::string getAuthCode() const
219             {
220                 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
221                 {
222                     return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
223                 }
224                 return std::string("");
225             }
226
227             /**
228              * Get an auth provider which issued an auth code
229              *
230              * @return an auth provider which issued an auth code
231              */
232             std::string getAuthProvider() const
233             {
234                 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
235                 {
236                     return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
237                 }
238                 return std::string("");
239             }
240
241             /**
242              * Get a CI server to be delivered
243              *
244              * @return a CI server to be delivered
245              */
246             std::string getCiServer() const
247             {
248                 if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
249                 {
250                     return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
251                 }
252                 return std::string("");
253             }
254
255             /**
256              * Get a CI server's Uuid to be delivered
257              *
258              * @return a CI server's Uuid to be delivered
259              */
260             std::string getCloudID() const
261             {
262                 return m_cloudID;
263             }
264
265             /**
266              * Get a CI server's credential ID of certificate
267              *
268              * @return a CI server's credential ID of certificated
269              */
270             int getCredID() const
271             {
272                 return m_credID;
273             }
274
275             /**
276              * Get an access token to be delivered.
277              *
278              * @return an access token to be delivered.
279              */
280             std::string getAccessToken() const
281             {
282                 if(m_rep.hasAttribute(OC_RSRVD_ES_ACCESSTOKEN))
283                 {
284                     return m_rep.getValue<std::string>(OC_RSRVD_ES_ACCESSTOKEN);
285                 }
286                 return std::string("");
287             }
288
289             /**
290              * Get an access token type to be delivered.
291              *
292              * @return an access token type to be delivered.
293              */
294             OAUTH_TOKENTYPE getAccessTokenType() const
295             {
296
297                 if(m_rep.hasAttribute(OC_RSRVD_ES_ACCESSTOKEN_TYPE))
298                 {
299                     return static_cast<OAUTH_TOKENTYPE>(
300                                 m_rep.getValue<int>(OC_RSRVD_ES_ACCESSTOKEN_TYPE));
301                 }
302                 return NONE_OAUTH_TOKENTYPE;
303             }
304
305             /**
306              * Get OCRepresentation object
307              *
308              * @return OCRepresentation object
309              */
310             const OCRepresentation &toOCRepresentation() const
311             {
312                 return m_rep;
313             }
314         protected:
315             OCRepresentation m_rep;
316             std::string m_cloudID;
317             int m_credID;
318         };
319
320         /**
321          * @brief Data class stored for provisioning of Device properties which includes
322          *        properties of WiFiConf resource and DevConf resource
323          */
324         class DeviceProp
325         {
326         public:
327
328             /**
329              * Constructor
330              */
331             DeviceProp()
332             {
333             }
334
335             DeviceProp(const DeviceProp& deviceProp) :
336                 m_rep(deviceProp.toOCRepresentation())
337             {
338             }
339
340             DeviceProp(const DeviceProp&& deviceProp) :
341                 m_rep(std::move(deviceProp.toOCRepresentation()))
342             {
343             }
344
345             /**
346              * Constructor with OCRepresentation object. This is used for JNI communication.
347              */
348             DeviceProp(const OCRepresentation &rep)
349             {
350                 m_rep = rep;
351             }
352
353             /**
354              * Set WiFiConf resource properties to be delivered to Enrollee
355              *
356              * @param ssid Ssid of the Enroller
357              * @param pwd Pwd of the Enrolle
358              * @param authtype Auth type of the Enroller
359              * @param enctype Encryption type of the Enroller
360              *
361              * @see WIFI_AUTHTYPE
362              * @see WIFI_ENCTYPE
363              */
364             void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
365             {
366                 m_rep.setValue(OC_RSRVD_ES_SSID, ssid);
367                 m_rep.setValue(OC_RSRVD_ES_CRED, pwd);
368                 m_rep.setValue(OC_RSRVD_ES_AUTHTYPE, authtype);
369                 m_rep.setValue(OC_RSRVD_ES_ENCTYPE, enctype);
370             }
371
372             /**
373              * Get a SSID of Enroller
374              *
375              * @return a SSID of enroller
376              */
377             std::string getSsid() const
378             {
379                 if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
380                 {
381                     return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
382                 }
383                 return std::string("");
384             }
385
386             /**
387              * Get a password of Enroller
388              *
389              * @return a password of enroller
390              */
391             std::string getPassword() const
392             {
393                 if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
394                 {
395                     return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
396                 }
397                 return std::string("");
398             }
399
400             /**
401              * Get an auth type of Enroller
402              *
403              * @return an auth type of enroller
404              *
405              * @see WIFI_AUTHTYPE
406              */
407             WIFI_AUTHTYPE getAuthType() const
408             {
409                 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
410                 {
411                     return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
412                 }
413                 return NONE_AUTH;
414             }
415
416             /**
417              * Get an encryption type of Enroller
418              *
419              * @return an encryption type of enroller
420              *
421              * @see WIFI_ENCTYPE
422              */
423             WIFI_ENCTYPE getEncType() const
424             {
425                 if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
426                 {
427                     return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
428                 }
429                 return NONE_ENC;
430             }
431
432             /**
433              * Get OCRepresentation object
434              *
435              * @return OCRepresentation object
436              */
437             const OCRepresentation &toOCRepresentation() const
438             {
439                 return m_rep;
440             }
441
442         protected:
443             OCRepresentation m_rep;
444         };
445
446         /**
447          * Security Provisioning Status
448          */
449         class SecProvisioningStatus
450         {
451         public:
452             SecProvisioningStatus(string deviceUUID, ESResult result) :
453                 m_devUUID(deviceUUID), m_result(result)
454             {
455 #ifdef __WITH_DTLS__
456                 m_selectedOTMethod = OIC_JUST_WORKS;
457                 m_isMOTEnabled = false;
458                 m_isOwned = false;
459                 m_ownerID = {};
460 #endif
461             }
462 #ifdef __WITH_DTLS__
463             SecProvisioningStatus(std::shared_ptr<OCSecureResource> resource, ESResult result) :
464                 m_result(result)
465             {
466                 m_isMOTEnabled = false;
467                 if(resource.get() != nullptr)
468                 {
469                     m_devUUID = resource->getDeviceID();
470                     m_isOwned = resource->getOwnedStatus();
471 #ifdef MULTIPLE_OWNER
472                     m_isMOTEnabled = resource->isMOTEnabled();
473 #endif
474
475                     if( OC_STACK_OK != resource->getOTMethod(&m_selectedOTMethod) )
476                     {
477                         m_selectedOTMethod = OIC_OXM_COUNT; // Out-of-range
478                     }
479
480                     if(resource->getOwnedStatus())
481                     {
482                         char uuidString[UUID_STRING_SIZE] = {};
483                         if(RAND_UUID_OK == OCConvertUuidToString(resource->getDevPtr()->doxm->owner.id, uuidString))
484                         {
485                             m_ownerID = uuidString;
486                         }
487                         else
488                         {
489                             m_ownerID = {};
490                         }
491                     }
492                 }
493             }
494
495             OicSecOxm_t getSelectedOTMethod() const
496             {
497                 return m_selectedOTMethod;
498             }
499
500             bool isMOTEnabled() const
501             {
502                 return m_isMOTEnabled;
503             }
504
505             bool isOwnedDevice() const
506             {
507                 return m_isOwned;
508             }
509
510             const std::string getOwnerID()
511             {
512                 return m_ownerID;
513             }
514 #endif
515             const std::string getDeviceUUID()
516             {
517                 return m_devUUID;
518             }
519             /**
520              * Get a result for about security provisioning is success or not.
521              *
522              * @return ::ES_OK\n
523              *         ::ES_SEC_OPERATION_IS_NOT_SUPPORTED\n
524              *         ::ES_SECURE_RESOURCE_DISCOVERY_FAILURE\n
525              *         ::ES_OWNERSHIP_TRANSFER_FAILURE\n
526              *         ::ES_ERROR\n
527              */
528             ESResult getESResult()
529             {
530                 return m_result;
531             }
532         private:
533             string m_devUUID;
534             ESResult m_result;
535 #ifdef __WITH_DTLS__
536             OicSecOxm_t m_selectedOTMethod;
537             bool m_isMOTEnabled;
538             bool m_isOwned;
539             std::string m_ownerID;
540 #endif
541         };
542
543         /**
544          * @breif This provide a set of getter APIs from received response for getConfiguration().
545          *        Received information includes a device name, WiFi supported mode, and frequency.
546          *        Additionally, you can know if Enrollee can be access to cloud server with this
547          *        object.
548          */
549         class EnrolleeConf
550         {
551         public:
552             /**
553              * Constructor
554              * The expected OCRepresentation is one for collection resource and has several child
555              * OCRepresentation object corresponding to WiFiConf, DevConf, and CoapCloudConf
556              * resources' representations.
557              */
558             EnrolleeConf(const OCRepresentation& rep) :
559                 m_EasySetupRep(rep)
560             {
561             }
562
563             EnrolleeConf(const EnrolleeConf& enrolleeConf) :
564                 m_EasySetupRep(enrolleeConf.getEasySetupRep())
565             {
566             }
567
568             EnrolleeConf(const EnrolleeConf&& enrolleeConf) :
569                 m_EasySetupRep(std::move(enrolleeConf.getEasySetupRep()))
570             {
571             }
572
573             /**
574              * Get a device name of Enrollee. It is Device's human-friendly name like device model
575              * name.
576              *
577              * @return a device name of Enrollee
578              */
579             std::string getDeviceName() const
580             {
581                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
582                 for(auto child = children.begin(); child != children.end(); ++child)
583                 {
584                     if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
585                     {
586                         OCRepresentation rep;
587                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
588                         {
589                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
590                         }
591                         else
592                         {
593                             return std::string("");
594                         }
595
596                         if(rep.hasAttribute(OC_RSRVD_ES_DEVNAME))
597                         {
598                             return rep.getValue<std::string>(OC_RSRVD_ES_DEVNAME);
599                         }
600                     }
601                 }
602                 return std::string("");
603             }
604
605             /**
606              * Get a set of WiFi supported modes of Enrollee
607              *
608              * @return a set of WiFi supported modes of Enrollee
609              *
610              * @see WIFI_MODE
611              */
612             vector<WIFI_MODE> getWiFiModes() const
613             {
614                 vector<WIFI_MODE> modes;
615                 modes.clear();
616
617                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
618                 for(auto child = children.begin(); child != children.end(); ++child)
619                 {
620                     if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
621                     {
622                         OCRepresentation rep;
623                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
624                         {
625                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
626                         }
627                         else
628                         {
629                             return modes;
630                         }
631
632                         if(rep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
633                         {
634                             for(auto it : rep.getValue
635                                         <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
636                             {
637                                 modes.push_back(static_cast<WIFI_MODE>(it));
638                             }
639                         }
640                     }
641                 }
642                 return modes;
643             }
644
645             /**
646              * Get a WiFi supported frequency of Enrollee
647              *
648              * @return a WiFi supported frequency of Enrollee
649              *
650              * @see WIFI_FREQ
651              */
652             WIFI_FREQ getWiFiFreq() const
653             {
654                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
655                 for(auto child = children.begin(); child != children.end(); ++child)
656                 {
657                     if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
658                     {
659                         OCRepresentation rep;
660                         if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
661                         {
662                             rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
663                         }
664                         else
665                         {
666                             return WIFI_FREQ_NONE;
667                         }
668
669                         if(rep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
670                         {
671                             return static_cast<WIFI_FREQ>(
672                                         rep.getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
673                         }
674                     }
675                 }
676                 return WIFI_FREQ_NONE;
677             }
678
679             /**
680              * Get a provisioning status property of Enrollee.
681              *
682              * @return a provisioning status property of Enrollee
683              */
684             ProvStatus getProvStatus() const
685             {
686                 OCRepresentation rep;
687                 if(m_EasySetupRep.hasAttribute(OC_RSRVD_REPRESENTATION))
688                 {
689                     rep = m_EasySetupRep.getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
690                 }
691                 else
692                 {
693                     return ES_STATE_INIT;
694                 }
695
696                 if(rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
697                 {
698                     return static_cast<ProvStatus>(
699                                         rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
700                 }
701                 return ES_STATE_INIT;
702             }
703
704             /**
705              * Get a last error code property of Enrollee.
706              *
707              * @return a last error code property of Enrollee.
708              */
709             ESErrorCode getLastErrCode() const
710             {
711                 OCRepresentation rep;
712                 if(m_EasySetupRep.hasAttribute(OC_RSRVD_REPRESENTATION))
713                 {
714                     rep = m_EasySetupRep.getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
715                 }
716                 else
717                 {
718                     return ES_ERRCODE_NO_ERROR;
719                 }
720
721                 if(rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
722                 {
723                     return static_cast<ESErrorCode>(
724                                         rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
725                 }
726                 return ES_ERRCODE_NO_ERROR;
727             }
728
729             /**
730              * Get an accessibility to cloud server of an Enrollee
731              *
732              * @return an accessibility to cloud server of an Enrollee
733              */
734             bool isCloudAccessible() const
735             {
736                 std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
737                 for(auto child = children.begin(); child != children.end(); ++child)
738                 {
739                     for(auto rt : child->getResourceTypes())
740                     {
741                         if(0 == rt.compare(OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF))
742                         {
743                             return true;
744                         }
745                     }
746                 }
747                 return false;
748             }
749
750             /**
751              * Get OCRepresentation object
752              *
753              * @return OCRepresentation object
754              */
755             const OCRepresentation& getEasySetupRep() const
756             {
757                 return m_EasySetupRep;
758             }
759
760         protected:
761             OCRepresentation m_EasySetupRep;
762         };
763
764         /**
765          * Status object for getStatus API. This object is given to application
766          * when a response for GET request to provisioning resource at Enrollee is arrived.
767          * It returns a result of the API and requested data delivered in the response which includes
768          * a provisioning status and last error code stored in Enrollee.
769          *
770          * @see EnrolleeStatus
771          */
772         class GetEnrolleeStatus
773         {
774         public:
775             /**
776              * Constructor
777              */
778             GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
779                 m_result(result), m_enrolleeStatus(status)
780             {
781             }
782
783             /**
784              * Get a result of getting provisioning status and last error code of Enrollee
785              *
786              * @return ::ES_OK\n
787              *         ::ES_COMMUNICATION_ERROR\n
788              *         ::ES_ERROR\n
789              * @see ESResult
790              */
791             ESResult getESResult()
792             {
793                 return m_result;
794             }
795
796             /**
797              * Get Enrollee's status and last error code properties
798              *
799              * @return Enrollee's status and last error code properties
800              *
801              * @see EnrolleeStatus
802              */
803             const EnrolleeStatus& getEnrolleeStatus()
804             {
805                 return m_enrolleeStatus;
806             }
807
808         private:
809             ESResult m_result;
810             EnrolleeStatus m_enrolleeStatus;
811         };
812
813         /**
814          * Status object for getConfiguration API. This object is given to application
815          * when a response for GET request to provisioning resource at Enrollee is arrived.
816          * It returns a result of the API and requested data delivered in the response which includes
817          * WiFi configuration and device configuration stored in Enrollee.
818          *
819          * @see EnrolleeConf
820          */
821         class GetConfigurationStatus
822         {
823         public:
824             /**
825              * Constructor
826              */
827             GetConfigurationStatus(ESResult result, const EnrolleeConf& conf) :
828                     m_result(result), m_enrolleeConf(conf)
829             {
830             }
831
832             /**
833              * Get a result of getting preconfiguration of Enrollee
834              *
835              * @return ::ES_OK\n
836              *         ::ES_COMMUNICATION_ERROR\n
837              *         ::ES_ERROR\n
838              *
839              * @see ESResult
840              */
841             ESResult getESResult()
842             {
843                 return m_result;
844             }
845
846             /**
847              * Get Enrollee's pre-configuration properties
848              *
849              * @return Enrollee's pre-configuration properties
850              *
851              * @see EnrolleeConf
852              */
853             EnrolleeConf& getEnrolleeConf()
854             {
855                 return m_enrolleeConf;
856             }
857
858         private:
859             ESResult m_result;
860             EnrolleeConf m_enrolleeConf;
861         };
862
863         /**
864          * Status object for provisionDeviceProperties API. This object is given to application
865          * when a response for GET request to provisioning resource at Enrollee is arrived.
866          * It returns a result of the request.
867          */
868         class DevicePropProvisioningStatus
869         {
870         public:
871             /**
872              * Constructor
873              */
874             DevicePropProvisioningStatus(ESResult result) :
875                     m_result(result)
876             {
877             }
878
879             /**
880              * Get a result of Device property provisioning
881              *
882              * @return ::ES_OK\n
883              *         ::ES_COMMUNICATION_ERROR\n
884              *         ::ES_ERROR\n
885              *
886              * @see ESResult
887              */
888             ESResult getESResult()
889             {
890                 return m_result;
891             }
892
893         private:
894             ESResult m_result;
895         };
896
897         /**
898          * Status object for provisionCloudProperties API. This object is given to application
899          * when a response for GET request to provisioning resource at Enrollee is arrived.
900          * It returns a result of the request and status of this provisioning. The status provides
901          * an information if the enrollee is found in a given network and the provisioning is
902          * successfully done.
903          */
904         class CloudPropProvisioningStatus
905         {
906         public:
907             /**
908              * Constructor
909              */
910             CloudPropProvisioningStatus(ESResult result) :
911                     m_result(result)
912             {
913             }
914
915             /**
916              * Get a result of Cloud property provisioning
917              *
918              * @return ::ES_OK\n
919              *         ::ES_ENROLLEE_DISCOVERY_FAILURE\n
920              *         ::ES_SECURE_RESOURCE_DISCOVERY_FAILURE\n
921              *         ::ES_ACL_PROVISIONING_FAILURE\n
922              *         ::ES_CERT_PROVISIONING_FAILURE\n
923              *         ::ES_COMMUNICATION_ERROR\n
924              *         ::ES_ERROR\n
925              *
926              * @see ESResult
927              */
928             ESResult getESResult()
929             {
930                 return m_result;
931             }
932
933         private:
934             ESResult m_result;
935         };
936
937         /**
938          * Status object for connect API. This object is given to application
939          * when a response for 'Connect' request from Enrollee is arrived.
940          */
941         class ConnectRequestStatus
942         {
943         public:
944             /**
945              * Constructor
946              */
947             ConnectRequestStatus(ESResult result) :
948                     m_result(result)
949             {
950             }
951
952             /**
953              * Get a result of Connect request
954              *
955              * @return ::ES_OK\n
956              *         ::ES_COMMUNICATION_ERROR\n
957              *         ::ES_ERROR\n
958              *
959              * @see ESResult
960              */
961             ESResult getESResult()
962             {
963                 return m_result;
964             }
965
966         private:
967             ESResult m_result;
968         };
969
970         class ESOwnershipTransferData
971         {
972         public:
973 #ifdef __WITH_DTLS__
974             ESOwnershipTransferData() :
975                 m_MOTMethod(OIC_OXM_COUNT), m_preconfiguredPin("")
976             {
977             }
978
979             ESOwnershipTransferData(const ESOwnershipTransferData& data) :
980                 m_MOTMethod(data.getMOTMethod()),
981                 m_preconfiguredPin(data.getPreConfiguredPin())
982             {
983             }
984
985             ESResult setMOTMethod(OicSecOxm_t method)
986             {
987 #ifdef MULTIPLE_OWNER
988                 if(OIC_RANDOM_DEVICE_PIN != method)
989                 {
990                     return ES_ERROR;
991                 }
992
993                 m_MOTMethod = method;
994                 return ES_OK;
995 #else
996                 (void) method;
997
998                 return ES_ERROR;
999 #endif
1000             }
1001
1002             ESResult setMOTMethod(OicSecOxm_t method, const std::string& pin)
1003             {
1004 #ifdef MULTIPLE_OWNER
1005                 if(OIC_PRECONFIG_PIN != method || pin.empty())
1006                 {
1007                     return ES_ERROR;
1008                 }
1009
1010                 m_preconfiguredPin = pin;
1011                 m_MOTMethod = method;
1012                 return ES_OK;
1013 #else
1014                 (void) method;
1015                 (void) pin;
1016
1017                 return ES_ERROR;
1018 #endif
1019             }
1020
1021             OicSecOxm_t getMOTMethod() const
1022             {
1023                 return m_MOTMethod;
1024             }
1025
1026             std::string getPreConfiguredPin() const
1027             {
1028                 return m_preconfiguredPin;
1029             }
1030
1031         private:
1032             OicSecOxm_t m_MOTMethod;
1033             std::string m_preconfiguredPin;
1034 #endif
1035         };
1036
1037         /**
1038          * Callback function definition for providing Enrollee status
1039          */
1040         typedef function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb;
1041
1042         /**
1043          * Callback function definition for providing Enrollee configuration status
1044          */
1045         typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
1046
1047         /**
1048          * Callback function definition for providing Enrollee device property provisioning status
1049          */
1050         typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
1051
1052         /**
1053          * Callback function definition for providing Enrollee cloud property provisioning status
1054          */
1055         typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
1056
1057         /**
1058          * Callback function definition for providing 'Connect' request status
1059          */
1060         typedef function< void(shared_ptr< ConnectRequestStatus >) > ConnectRequestStatusCb;
1061
1062
1063         /**
1064          * Callback function definition for providing Enrollee security provisioning status
1065          */
1066         typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
1067
1068         /**
1069          * Callback function definition for providing Enrollee security provisioning status.
1070          * This callback is an overloaded version of SecurityProvStatusCb, which has
1071          * ESOwnershipTransferData as a return value.
1072          */
1073         typedef function< ESOwnershipTransferData(shared_ptr<SecProvisioningStatus>) >
1074                                                                     SecurityProvStatusCbWithOption;
1075
1076         /**
1077          * Callback definition to be invoked when the security stack expects a pin from application
1078          */
1079         typedef function< void(string&) > SecurityPinCb;
1080
1081         /**
1082          * Callback definition to be invoked when the stack expects a db path
1083          */
1084         typedef function< void(string&) > SecProvisioningDbPathCb;
1085
1086     }
1087 }
1088 #endif //WITH_ARDUINO
1089
1090 #endif //ES_COMMON_RICH_H_