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