replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / inc / ESRichCommon.h
index 7acf8b1..48584d1 100755 (executable)
 #include <vector>
 #endif
 
+#include "OCPlatform.h"
 #include "ocstack.h"
 #include "octypes.h"
+#ifdef __WITH_DTLS__
+#include "securevirtualresourcetypes.h"
+#include "OCProvisioningManager.hpp"
+#include "ocrandom.h"
+#endif
 
-using namespace std;
+#include "escommon.h"
 
-// Defines
-#define IP_PORT                 55555
-
-/**
- * Attributes used to form a proper easysetup conforming JSON message.
- */
-#define OC_RSRVD_ES_PROVSTATUS                       "ps"
-#define OC_RSRVD_ES_TRIGGER                              "tr"
-#define OC_RSRVD_ES_SSID                                     "tnn"
-#define OC_RSRVD_ES_CRED                                   "cd"
-#define OC_RSRVD_ES_SUPPORTEDWIFIMODE       "swmt"
-#define OC_RSRVD_ES_SUPPORTEDWIFIFREQ        "swf"
-#define OC_RSRVD_ES_AUTHTYPE                          "wat"
-#define OC_RSRVD_ES_ENCTYPE                             "wet"
-#define OC_RSRVD_ES_AUTHCODE                         "ac"
-#define OC_RSRVD_ES_AUTHPROVIDER                  "apn"
-#define OC_RSRVD_ES_CISERVER                            "cisurl"
-#define OC_RSRVD_ES_DEVNAME                            "dn"
-#define OC_RSRVD_ES_LANGUAGE                          "lang"
-#define OC_RSRVD_ES_COUNTRY                            "cont"
-#define OC_RSRVD_ES_TNT                                      "tnt"
-#define OC_RSRVD_ES_ANT                                     "ant"
-
-/**
- * Easysetup defined resoruce types and uris.
- */
-#define OC_RSRVD_ES_PROV_RES_TYPE                 "ocf.r.prov"
-#define OC_RSRVD_ES_URI_PROV                           "/.well-known/ocf/prov"
-#define OC_RSRVD_ES_RES_TYPE_WIFI                   "ocf.r.wifi"
-#define OC_RSRVD_ES_URI_WIFI                             "/.well-known/ocf/prov/wifi"
-#define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.r.cloudserver"
-#define OC_RSRVD_ES_URI_CLOUDSERVER            "/.well-known/ocf/prov/cloudserver"
-#define OC_RSRVD_ES_RES_TYPE_DEVCONF          "ocf.r.devconf"
-#define OC_RSRVD_ES_URI_DEVCONF                    "/.well-known/ocf/prov/devconf"
-
-/**
- * @brief Defines for Provisioning status accepted values
- */
-#define ES_PS_NEED_PROVISIONING         1
-#define ES_PS_PROVISIONING_COMPLETED    2
-#define ES_PS_TRIGGER_INIT_VALUE        0
-#define ES_PS_TRIGGER_CONNECTION        1
+using namespace OC;
+using namespace std;
 
 #ifndef WITH_ARDUINO
 namespace OIC
 {
     namespace Service
     {
-        typedef enum
+        /**
+         * @brief Properties of easysetup resource. It includes a provisioning status and last
+         *        error code.
+         */
+        class EnrolleeStatus
         {
-            ES_ERROR = -1,
-            ES_OK = 0,
-            ES_NETWORKFOUND = 1,
-            ES_NETWORKCONNECTED,
-            ES_NETWORKNOTCONNECTED,
-            ES_RESOURCECREATED = 11,
-            ES_RECVREQOFPROVRES = 21,
-            ES_RECVREQOFNETRES,
-            ES_RECVUPDATEOFPROVRES,
-            ES_RECVTRIGGEROFPROVRES,
-            ES_UNAUTHORIZED = 31
-        } ESResult;
+        public:
+
+            /**
+             * Constructor
+             */
+            EnrolleeStatus(const OCRepresentation& rep)
+            {
+                m_rep = rep;
+            }
+
+            EnrolleeStatus(const EnrolleeStatus& enrolleeStatus) :
+                m_rep(enrolleeStatus.getRepresentation())
+            {
+            }
+
+            EnrolleeStatus(const EnrolleeStatus&& enrolleeStatus) :
+                m_rep(std::move(enrolleeStatus.getRepresentation()))
+            {
+            }
+
+            /**
+             * Get a provisioning status property of Enrollee.
+             *
+             * @return a provisioning status property of Enrollee
+             */
+            ProvStatus getProvStatus() const
+            {
+                if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
+                {
+                    return static_cast<ProvStatus>(
+                                        m_rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
+                }
+                return ES_STATE_INIT;
+            }
+
+            /**
+             * Get a last error code property of Enrollee.
+             *
+             * @return a last error code property of Enrollee.
+             */
+            ESErrorCode getLastErrCode() const
+            {
+                if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
+                {
+                    return static_cast<ESErrorCode>(
+                                        m_rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
+                }
+                return ES_ERRCODE_NO_ERROR;
+            }
+
+            /**
+             * Get OCRepresentation object
+             *
+             * @return OCRepresentation object
+             */
+            const OCRepresentation& getRepresentation() const
+            {
+                return m_rep;
+            }
+        protected:
+            OCRepresentation m_rep;
+        };
 
         /**
-         * @brief  WIFI Authentication tlype of the Enroller
+         * @brief Data class stored for provisioning of coap cloud server properties
          */
-        typedef enum
+        class CloudProp
         {
-            NONE_AUTH = 0,
-            WEP,
-            WPA_PSK,
-            WPA2_PSK
-        } WIFI_AUTHTYPE;
+        public:
+
+            /**
+             * Constructor
+             */
+            CloudProp()
+            {
+                m_cloudID = "";
+                m_credID = 0;
+            }
+
+            CloudProp(const CloudProp& cloudProp) :
+                                            m_rep(cloudProp.toOCRepresentation()),
+                                            m_cloudID(cloudProp.getCloudID()),
+                                            m_credID(cloudProp.getCredID())
+            {
+            }
+
+            CloudProp(const CloudProp&& cloudProp) :
+                                            m_rep(std::move(cloudProp.toOCRepresentation())),
+                                            m_cloudID(cloudProp.getCloudID()),
+                                            m_credID(cloudProp.getCredID())
+            {
+            }
+
+            /**
+             * Constructor with OCRepresentation object. This is used for JNI communication.
+             */
+            CloudProp(const OCRepresentation &rep)
+            {
+                m_rep = rep;
+                m_cloudID = "";
+                m_credID = 0;
+            }
+
+            /**
+             * Set CoapCloudConf resource properties to be delivered to Enrollee
+             *
+             * @param authCode  Auth code issued by OAuth2.0-compatible account server
+             * @param authProvider Auth provider ID
+             * @param ciServer Cloud interface server URL which an Enrollee is going to registered
+             */
+            void setCloudProp(string authCode, string authProvider, string ciServer)
+            {
+                m_rep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
+                m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
+                m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
+            }
+
+            /**
+             * Set CoapCloudConf resource properties with Access token to be delivered to Enrollee
+             *
+             * @param accessToken  Access token which is given in a return of auth code issued by
+             *                     OAuth2.0-compatible account server
+             * @param tokenType Access token type, i.e. "bearer"
+             * @param authProvider Auth provider ID
+             * @param ciServer Cloud interface server URL which an Enrollee is going to registered
+             *
+             * @see OAUTH_TOKENTYPE
+             */
+            void setCloudPropWithAccessToken(string accessToken, OAUTH_TOKENTYPE tokenType,
+                                                string authProvider, string ciServer)
+            {
+                m_rep.setValue(OC_RSRVD_ES_ACCESSTOKEN, accessToken);
+                m_rep.setValue(OC_RSRVD_ES_ACCESSTOKEN_TYPE, tokenType);
+                m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
+                m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
+            }
+
+            /**
+             * Set CloudServer's UUID
+             *
+             * @param cloudID Cloud Interface server's UUID
+             */
+            void setCloudID(string cloudID)
+            {
+                m_cloudID = cloudID;
+            }
+
+            /**
+             * Set CloudServer's credential ID of certificate
+             *
+             * @param credID Cloud Interface server's credential ID of certificate
+             */
+            void setCredID(int credID)
+            {
+                m_credID = credID;
+            }
+
+            /**
+             * Get an auth code to be delivered.
+             *
+             * @return an auth code to be delivered.
+             */
+            std::string getAuthCode() const
+            {
+                if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
+                {
+                    return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
+                }
+                return std::string("");
+            }
+
+            /**
+             * Get an auth provider which issued an auth code
+             *
+             * @return an auth provider which issued an auth code
+             */
+            std::string getAuthProvider() const
+            {
+                if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
+                {
+                    return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
+                }
+                return std::string("");
+            }
+
+            /**
+             * Get a CI server to be delivered
+             *
+             * @return a CI server to be delivered
+             */
+            std::string getCiServer() const
+            {
+                if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
+                {
+                    return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
+                }
+                return std::string("");
+            }
+
+            /**
+             * Get a CI server's Uuid to be delivered
+             *
+             * @return a CI server's Uuid to be delivered
+             */
+            std::string getCloudID() const
+            {
+                return m_cloudID;
+            }
+
+            /**
+             * Get a CI server's credential ID of certificate
+             *
+             * @return a CI server's credential ID of certificated
+             */
+            int getCredID() const
+            {
+                return m_credID;
+            }
+
+            /**
+             * Get an access token to be delivered.
+             *
+             * @return an access token to be delivered.
+             */
+            std::string getAccessToken() const
+            {
+                if(m_rep.hasAttribute(OC_RSRVD_ES_ACCESSTOKEN))
+                {
+                    return m_rep.getValue<std::string>(OC_RSRVD_ES_ACCESSTOKEN);
+                }
+                return std::string("");
+            }
+
+            /**
+             * Get an access token type to be delivered.
+             *
+             * @return an access token type to be delivered.
+             */
+            OAUTH_TOKENTYPE getAccessTokenType() const
+            {
+
+                if(m_rep.hasAttribute(OC_RSRVD_ES_ACCESSTOKEN_TYPE))
+                {
+                    return static_cast<OAUTH_TOKENTYPE>(
+                                m_rep.getValue<int>(OC_RSRVD_ES_ACCESSTOKEN_TYPE));
+                }
+                return NONE_OAUTH_TOKENTYPE;
+            }
+
+            /**
+             * Get OCRepresentation object
+             *
+             * @return OCRepresentation object
+             */
+            const OCRepresentation &toOCRepresentation() const
+            {
+                return m_rep;
+            }
+        protected:
+            OCRepresentation m_rep;
+            std::string m_cloudID;
+            int m_credID;
+        };
 
         /**
-         * @brief  WIFI ecnrytion type of the Enroller
+         * @brief Data class stored for provisioning of Device properties which includes
+         *        properties of WiFiConf resource and DevConf resource
          */
-        typedef enum
+        class DeviceProp
         {
-            NONE_ENC = 0,
-            WEP_64,
-            WEP_128,
-            TKIP,
-            AES,
-            TKIP_AES
-        } WIFI_ENCTYPE;
-
-        typedef enum
-        {
-            WIFI_24G = 0,
-            WIFI_5G,
-            WIFI_BOTH
-        } WIFI_FREQ;
+        public:
 
-        typedef enum
-        {
-            WIFI_11A = 0,
-            WIFI_11B,
-            WIFI_11G,
-            WIFI_11N,
-            WIFI_11AC
-        } WIFI_MODE;
-
-        typedef struct
-        {
-            string authCode;
-            string authProvider;
-            string ciServer;
-        } CloudProvInfo;
+            /**
+             * Constructor
+             */
+            DeviceProp()
+            {
+            }
 
-        typedef struct
-        {
-            struct
+            DeviceProp(const DeviceProp& deviceProp) :
+                m_rep(deviceProp.toOCRepresentation())
             {
-                string ssid; /**< ssid of the Enroller**/
-                string pwd; /**< pwd of the Enroller**/
-                WIFI_AUTHTYPE authtype; /**< auth type of the Enroller**/
-                WIFI_ENCTYPE enctype; /**< encryption type of the Enroller**/
-            } WIFI;
+            }
 
-            struct
+            DeviceProp(const DeviceProp&& deviceProp) :
+                m_rep(std::move(deviceProp.toOCRepresentation()))
             {
-                string language;
-                string country;
-            } Device;
-        } DataProvInfo;
+            }
 
-        typedef struct
-        {
-            string id;
-            string name;
-            string language;
-            string country;
-        } DeviceConfig;
+            /**
+             * Constructor with OCRepresentation object. This is used for JNI communication.
+             */
+            DeviceProp(const OCRepresentation &rep)
+            {
+                m_rep = rep;
+            }
 
-        typedef struct
-        {
-            vector<WIFI_MODE> types;
-            WIFI_FREQ freq;
-        } NetworkInfo;
+            /**
+             * Set WiFiConf resource properties to be delivered to Enrollee
+             *
+             * @param ssid Ssid of the Enroller
+             * @param pwd Pwd of the Enrolle
+             * @param authtype Auth type of the Enroller
+             * @param enctype Encryption type of the Enroller
+             *
+             * @see WIFI_AUTHTYPE
+             * @see WIFI_ENCTYPE
+             */
+            void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
+            {
+                m_rep.setValue(OC_RSRVD_ES_SSID, ssid);
+                m_rep.setValue(OC_RSRVD_ES_CRED, pwd);
+                m_rep.setValue(OC_RSRVD_ES_AUTHTYPE, authtype);
+                m_rep.setValue(OC_RSRVD_ES_ENCTYPE, enctype);
+            }
 
-        typedef enum
-        {
-            ES_PROVISIONING_ERROR = -1,
-            ES_NEED_PROVISIONING,
-            ES_PROVISIONED_ALREADY,
-            ES_PROVISIONING_SUCCESS
-        } ESDataProvState;
+            /**
+             * Get a SSID of Enroller
+             *
+             * @return a SSID of enroller
+             */
+            std::string getSsid() const
+            {
+                if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
+                {
+                    return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
+                }
+                return std::string("");
+            }
 
-        typedef enum
-        {
-            ES_CLOUD_PROVISIONING_ERROR = -1,
-            ES_CLOUD_PROVISIONING_SUCCESS,
-            ES_CLOUD_ENROLLEE_FOUND,
-            ES_CLOUD_ENROLLEE_NOT_FOUND
-        }ESCloudProvState;
+            /**
+             * Get a password of Enroller
+             *
+             * @return a password of enroller
+             */
+            std::string getPassword() const
+            {
+                if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
+                {
+                    return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
+                }
+                return std::string("");
+            }
 
-        typedef enum
-        {
-            ES_SEC_UNKNOWN = 0,
-            ES_SEC_OWNED,
-            ES_SEC_ACL_PROVISIONED,
-            ES_SEC_CREDS_PROVISIONED
-        } EnrolleeSecState;
+            /**
+             * Get an auth type of Enroller
+             *
+             * @return an auth type of enroller
+             *
+             * @see WIFI_AUTHTYPE
+             */
+            WIFI_AUTHTYPE getAuthType() const
+            {
+                if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
+                {
+                    return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
+                }
+                return NONE_AUTH;
+            }
+
+            /**
+             * Get an encryption type of Enroller
+             *
+             * @return an encryption type of enroller
+             *
+             * @see WIFI_ENCTYPE
+             */
+            WIFI_ENCTYPE getEncType() const
+            {
+                if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
+                {
+                    return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
+                }
+                return NONE_ENC;
+            }
+
+            /**
+             * Get OCRepresentation object
+             *
+             * @return OCRepresentation object
+             */
+            const OCRepresentation &toOCRepresentation() const
+            {
+                return m_rep;
+            }
+
+        protected:
+            OCRepresentation m_rep;
+        };
 
         /**
          * Security Provisioning Status
@@ -207,13 +452,79 @@ namespace OIC
             SecProvisioningStatus(string deviceUUID, ESResult result) :
                 m_devUUID(deviceUUID), m_result(result)
             {
+#ifdef __WITH_DTLS__
+                m_selectedOTMethod = OIC_JUST_WORKS;
+                m_isMOTEnabled = false;
+                m_isOwned = false;
+                m_ownerID = {};
+#endif
+            }
+#ifdef __WITH_DTLS__
+            SecProvisioningStatus(std::shared_ptr<OCSecureResource> resource, ESResult result) :
+                m_result(result)
+            {
+                m_isMOTEnabled = false;
+                if(resource.get() != nullptr)
+                {
+                    m_devUUID = resource->getDeviceID();
+                    m_isOwned = resource->getOwnedStatus();
+#ifdef MULTIPLE_OWNER
+                    m_isMOTEnabled = resource->isMOTEnabled();
+#endif
+
+                    if( OC_STACK_OK != resource->getOTMethod(&m_selectedOTMethod) )
+                    {
+                        m_selectedOTMethod = OIC_OXM_COUNT; // Out-of-range
+                    }
+
+                    if(resource->getOwnedStatus())
+                    {
+                        char uuidString[UUID_STRING_SIZE] = {};
+                        if(RAND_UUID_OK == OCConvertUuidToString(resource->getDevPtr()->doxm->owner.id, uuidString))
+                        {
+                            m_ownerID = uuidString;
+                        }
+                        else
+                        {
+                            m_ownerID = {};
+                        }
+                    }
+                }
             }
 
-            const string getDeviceUUID()
+            OicSecOxm_t getSelectedOTMethod() const
             {
-                return m_devUUID;
+                return m_selectedOTMethod;
+            }
+
+            bool isMOTEnabled() const
+            {
+                return m_isMOTEnabled;
             }
 
+            bool isOwnedDevice() const
+            {
+                return m_isOwned;
+            }
+
+            const std::string getOwnerID()
+            {
+                return m_ownerID;
+            }
+#endif
+            const std::string getDeviceUUID()
+            {
+                return m_devUUID;
+            }
+            /**
+             * Get a result for about security provisioning is success or not.
+             *
+             * @return ::ES_OK\n
+             *         ::ES_SEC_OPERATION_IS_NOT_SUPPORTED\n
+             *         ::ES_SECURE_RESOURCE_DISCOVERY_FAILURE\n
+             *         ::ES_OWNERSHIP_TRANSFER_FAILURE\n
+             *         ::ES_ERROR\n
+             */
             ESResult getESResult()
             {
                 return m_result;
@@ -221,137 +532,554 @@ namespace OIC
         private:
             string m_devUUID;
             ESResult m_result;
+#ifdef __WITH_DTLS__
+            OicSecOxm_t m_selectedOTMethod;
+            bool m_isMOTEnabled;
+            bool m_isOwned;
+            std::string m_ownerID;
+#endif
         };
 
-        class PropertyData
+        /**
+         * @breif This provide a set of getter APIs from received response for getConfiguration().
+         *        Received information includes a device name, WiFi supported mode, and frequency.
+         *        Additionally, you can know if Enrollee can be access to cloud server with this
+         *        object.
+         */
+        class EnrolleeConf
         {
         public:
-            PropertyData()
+            /**
+             * Constructor
+             * The expected OCRepresentation is one for collection resource and has several child
+             * OCRepresentation object corresponding to WiFiConf, DevConf, and CoapCloudConf
+             * resources' representations.
+             */
+            EnrolleeConf(const OCRepresentation& rep) :
+                m_EasySetupRep(rep)
             {
             }
 
-            PropertyData(DeviceConfig devConfig, NetworkInfo netInfo, bool cloudable) :
-                m_devConfig(devConfig), m_netInfo(netInfo), m_cloudable(cloudable)
+            EnrolleeConf(const EnrolleeConf& enrolleeConf) :
+                m_EasySetupRep(enrolleeConf.getEasySetupRep())
             {
             }
 
-            const DeviceConfig& getDevConf() const
+            EnrolleeConf(const EnrolleeConf&& enrolleeConf) :
+                m_EasySetupRep(std::move(enrolleeConf.getEasySetupRep()))
             {
-                return m_devConfig;
             }
 
-            const NetworkInfo& getNetInfo() const
+            /**
+             * Get a device name of Enrollee. It is Device's human-friendly name like device model
+             * name.
+             *
+             * @return a device name of Enrollee
+             */
+            std::string getDeviceName() const
             {
-                return m_netInfo;
+                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
+                for(auto child = children.begin(); child != children.end(); ++child)
+                {
+                    if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
+                    {
+                        OCRepresentation rep;
+                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
+                        {
+                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
+                        }
+                        else
+                        {
+                            return std::string("");
+                        }
+
+                        if(rep.hasAttribute(OC_RSRVD_ES_DEVNAME))
+                        {
+                            return rep.getValue<std::string>(OC_RSRVD_ES_DEVNAME);
+                        }
+                    }
+                }
+                return std::string("");
             }
 
-            const bool isCloudable() const
+            /**
+             * Get a set of WiFi supported modes of Enrollee
+             *
+             * @return a set of WiFi supported modes of Enrollee
+             *
+             * @see WIFI_MODE
+             */
+            vector<WIFI_MODE> getWiFiModes() const
             {
-                return m_cloudable;
+                vector<WIFI_MODE> modes;
+                modes.clear();
+
+                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
+                for(auto child = children.begin(); child != children.end(); ++child)
+                {
+                    if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
+                    {
+                        OCRepresentation rep;
+                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
+                        {
+                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
+                        }
+                        else
+                        {
+                            return modes;
+                        }
+
+                        if(rep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
+                        {
+                            for(auto it : rep.getValue
+                                        <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
+                            {
+                                modes.push_back(static_cast<WIFI_MODE>(it));
+                            }
+                        }
+                    }
+                }
+                return modes;
             }
 
-        private:
-            DeviceConfig m_devConfig;
-            NetworkInfo m_netInfo;
-            bool m_cloudable;
+            /**
+             * Get a WiFi supported frequency of Enrollee
+             *
+             * @return a WiFi supported frequency of Enrollee
+             *
+             * @see WIFI_FREQ
+             */
+            WIFI_FREQ getWiFiFreq() const
+            {
+                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
+                for(auto child = children.begin(); child != children.end(); ++child)
+                {
+                    if(child->getUri().find(OC_RSRVD_ES_URI_WIFICONF) != std::string::npos)
+                    {
+                        OCRepresentation rep;
+                        if(child->hasAttribute(OC_RSRVD_REPRESENTATION))
+                        {
+                            rep = child->getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
+                        }
+                        else
+                        {
+                            return WIFI_FREQ_NONE;
+                        }
+
+                        if(rep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
+                        {
+                            return static_cast<WIFI_FREQ>(
+                                        rep.getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
+                        }
+                    }
+                }
+                return WIFI_FREQ_NONE;
+            }
+
+            /**
+             * Get a provisioning status property of Enrollee.
+             *
+             * @return a provisioning status property of Enrollee
+             */
+            ProvStatus getProvStatus() const
+            {
+                OCRepresentation rep;
+                if(m_EasySetupRep.hasAttribute(OC_RSRVD_REPRESENTATION))
+                {
+                    rep = m_EasySetupRep.getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
+                }
+                else
+                {
+                    return ES_STATE_INIT;
+                }
+
+                if(rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
+                {
+                    return static_cast<ProvStatus>(
+                                        rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
+                }
+                return ES_STATE_INIT;
+            }
+
+            /**
+             * Get a last error code property of Enrollee.
+             *
+             * @return a last error code property of Enrollee.
+             */
+            ESErrorCode getLastErrCode() const
+            {
+                OCRepresentation rep;
+                if(m_EasySetupRep.hasAttribute(OC_RSRVD_REPRESENTATION))
+                {
+                    rep = m_EasySetupRep.getValue<OCRepresentation>(OC_RSRVD_REPRESENTATION);
+                }
+                else
+                {
+                    return ES_ERRCODE_NO_ERROR;
+                }
+
+                if(rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
+                {
+                    return static_cast<ESErrorCode>(
+                                        rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
+                }
+                return ES_ERRCODE_NO_ERROR;
+            }
+
+            /**
+             * Get an accessibility to cloud server of an Enrollee
+             *
+             * @return an accessibility to cloud server of an Enrollee
+             */
+            bool isCloudAccessible() const
+            {
+                std::vector<OCRepresentation> children = m_EasySetupRep.getChildren();
+                for(auto child = children.begin(); child != children.end(); ++child)
+                {
+                    for(auto rt : child->getResourceTypes())
+                    {
+                        if(0 == rt.compare(OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF))
+                        {
+                            return true;
+                        }
+                    }
+                }
+                return false;
+            }
+
+            /**
+             * Get OCRepresentation object
+             *
+             * @return OCRepresentation object
+             */
+            const OCRepresentation& getEasySetupRep() const
+            {
+                return m_EasySetupRep;
+            }
+
+        protected:
+            OCRepresentation m_EasySetupRep;
         };
 
-        class RequestPropertyDataStatus
+        /**
+         * Status object for getStatus API. This object is given to application
+         * when a response for GET request to provisioning resource at Enrollee is arrived.
+         * It returns a result of the API and requested data delivered in the response which includes
+         * a provisioning status and last error code stored in Enrollee.
+         *
+         * @see EnrolleeStatus
+         */
+        class GetEnrolleeStatus
         {
         public:
-            RequestPropertyDataStatus(ESResult result, const PropertyData& data) :
-                    m_result(result), m_propertyData(data)
+            /**
+             * Constructor
+             */
+            GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
+                m_result(result), m_enrolleeStatus(status)
             {
             }
 
+            /**
+             * Get a result of getting provisioning status and last error code of Enrollee
+             *
+             * @return ::ES_OK\n
+             *         ::ES_COMMUNICATION_ERROR\n
+             *         ::ES_ERROR\n
+             * @see ESResult
+             */
             ESResult getESResult()
             {
                 return m_result;
             }
 
-            const PropertyData& getPropertyData()
+            /**
+             * Get Enrollee's status and last error code properties
+             *
+             * @return Enrollee's status and last error code properties
+             *
+             * @see EnrolleeStatus
+             */
+            const EnrolleeStatus& getEnrolleeStatus()
             {
-                return m_propertyData;
+                return m_enrolleeStatus;
             }
 
         private:
             ESResult m_result;
-            PropertyData m_propertyData;
+            EnrolleeStatus m_enrolleeStatus;
         };
 
-        class DataProvisioningStatus
+        /**
+         * Status object for getConfiguration API. This object is given to application
+         * when a response for GET request to provisioning resource at Enrollee is arrived.
+         * It returns a result of the API and requested data delivered in the response which includes
+         * WiFi configuration and device configuration stored in Enrollee.
+         *
+         * @see EnrolleeConf
+         */
+        class GetConfigurationStatus
         {
         public:
-            DataProvisioningStatus(ESResult result, ESDataProvState dataProvState) :
-                    m_result(result), m_state(dataProvState)
+            /**
+             * Constructor
+             */
+            GetConfigurationStatus(ESResult result, const EnrolleeConf& conf) :
+                    m_result(result), m_enrolleeConf(conf)
             {
             }
 
+            /**
+             * Get a result of getting preconfiguration of Enrollee
+             *
+             * @return ::ES_OK\n
+             *         ::ES_COMMUNICATION_ERROR\n
+             *         ::ES_ERROR\n
+             *
+             * @see ESResult
+             */
             ESResult getESResult()
             {
                 return m_result;
             }
 
-            ESDataProvState getESDataProvState()
+            /**
+             * Get Enrollee's pre-configuration properties
+             *
+             * @return Enrollee's pre-configuration properties
+             *
+             * @see EnrolleeConf
+             */
+            EnrolleeConf& getEnrolleeConf()
             {
-                return m_state;
+                return m_enrolleeConf;
             }
 
         private:
             ESResult m_result;
-            ESDataProvState m_state;
+            EnrolleeConf m_enrolleeConf;
         };
 
-        class CloudProvisioningStatus
+        /**
+         * Status object for provisionDeviceProperties API. This object is given to application
+         * when a response for GET request to provisioning resource at Enrollee is arrived.
+         * It returns a result of the request.
+         */
+        class DevicePropProvisioningStatus
         {
         public:
-            CloudProvisioningStatus(ESResult result, ESCloudProvState state) :
-                    m_result(result), m_esCloudState(state)
+            /**
+             * Constructor
+             */
+            DevicePropProvisioningStatus(ESResult result) :
+                    m_result(result)
             {
             }
 
+            /**
+             * Get a result of Device property provisioning
+             *
+             * @return ::ES_OK\n
+             *         ::ES_COMMUNICATION_ERROR\n
+             *         ::ES_ERROR\n
+             *
+             * @see ESResult
+             */
             ESResult getESResult()
             {
                 return m_result;
             }
 
-            ESCloudProvState getESCloudState()
+        private:
+            ESResult m_result;
+        };
+
+        /**
+         * Status object for provisionCloudProperties API. This object is given to application
+         * when a response for GET request to provisioning resource at Enrollee is arrived.
+         * It returns a result of the request and status of this provisioning. The status provides
+         * an information if the enrollee is found in a given network and the provisioning is
+         * successfully done.
+         */
+        class CloudPropProvisioningStatus
+        {
+        public:
+            /**
+             * Constructor
+             */
+            CloudPropProvisioningStatus(ESResult result) :
+                    m_result(result)
+            {
+            }
+
+            /**
+             * Get a result of Cloud property provisioning
+             *
+             * @return ::ES_OK\n
+             *         ::ES_ENROLLEE_DISCOVERY_FAILURE\n
+             *         ::ES_SECURE_RESOURCE_DISCOVERY_FAILURE\n
+             *         ::ES_ACL_PROVISIONING_FAILURE\n
+             *         ::ES_CERT_PROVISIONING_FAILURE\n
+             *         ::ES_COMMUNICATION_ERROR\n
+             *         ::ES_ERROR\n
+             *
+             * @see ESResult
+             */
+            ESResult getESResult()
             {
-                return m_esCloudState;
+                return m_result;
             }
 
         private:
             ESResult m_result;
-            ESCloudProvState m_esCloudState;
         };
 
         /**
-         * Callback function definition for providing Enrollee security status .
+         * Status object for connect API. This object is given to application
+         * when a response for 'Connect' request from Enrollee is arrived.
          */
-        typedef function< void(shared_ptr< RequestPropertyDataStatus >) > RequestPropertyDataStatusCb;
+        class ConnectRequestStatus
+        {
+        public:
+            /**
+             * Constructor
+             */
+            ConnectRequestStatus(ESResult result) :
+                    m_result(result)
+            {
+            }
+
+            /**
+             * Get a result of Connect request
+             *
+             * @return ::ES_OK\n
+             *         ::ES_COMMUNICATION_ERROR\n
+             *         ::ES_ERROR\n
+             *
+             * @see ESResult
+             */
+            ESResult getESResult()
+            {
+                return m_result;
+            }
+
+        private:
+            ESResult m_result;
+        };
+
+        class ESOwnershipTransferData
+        {
+        public:
+#ifdef __WITH_DTLS__
+            ESOwnershipTransferData() :
+                m_MOTMethod(OIC_OXM_COUNT), m_preconfiguredPin("")
+            {
+            }
+
+            ESOwnershipTransferData(const ESOwnershipTransferData& data) :
+                m_MOTMethod(data.getMOTMethod()),
+                m_preconfiguredPin(data.getPreConfiguredPin())
+            {
+            }
+
+            ESResult setMOTMethod(OicSecOxm_t method)
+            {
+#ifdef MULTIPLE_OWNER
+                if(OIC_RANDOM_DEVICE_PIN != method)
+                {
+                    return ES_ERROR;
+                }
+
+                m_MOTMethod = method;
+                return ES_OK;
+#else
+                (void) method;
+
+                return ES_ERROR;
+#endif
+            }
+
+            ESResult setMOTMethod(OicSecOxm_t method, const std::string& pin)
+            {
+#ifdef MULTIPLE_OWNER
+                if(OIC_PRECONFIG_PIN != method || pin.empty())
+                {
+                    return ES_ERROR;
+                }
+
+                m_preconfiguredPin = pin;
+                m_MOTMethod = method;
+                return ES_OK;
+#else
+                (void) method;
+                (void) pin;
+
+                return ES_ERROR;
+#endif
+            }
+
+            OicSecOxm_t getMOTMethod() const
+            {
+                return m_MOTMethod;
+            }
+
+            std::string getPreConfiguredPin() const
+            {
+                return m_preconfiguredPin;
+            }
+
+        private:
+            OicSecOxm_t m_MOTMethod;
+            std::string m_preconfiguredPin;
+#endif
+        };
+
+        /**
+         * Callback function definition for providing Enrollee status
+         */
+        typedef function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb;
+
+        /**
+         * Callback function definition for providing Enrollee configuration status
+         */
+        typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
 
         /**
-         * Callback function definition for providing Enrollee security status .
+         * Callback function definition for providing Enrollee device property provisioning status
          */
-        typedef function< void(shared_ptr< DataProvisioningStatus >) > DataProvStatusCb;
+        typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
 
         /**
-         * Callback function definition for providing Enrollee security status .
+         * Callback function definition for providing Enrollee cloud property provisioning status
          */
-        typedef function< void(shared_ptr< CloudProvisioningStatus >) > CloudProvStatusCb;
+        typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
 
         /**
-         * Callback function definition for providing Enrollee security status .
+         * Callback function definition for providing 'Connect' request status
+         */
+        typedef function< void(shared_ptr< ConnectRequestStatus >) > ConnectRequestStatusCb;
+
+
+        /**
+         * Callback function definition for providing Enrollee security provisioning status
          */
         typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
 
         /**
-         * Callback definition to be invoked when the security stack expects a pin from application.
+         * Callback function definition for providing Enrollee security provisioning status.
+         * This callback is an overloaded version of SecurityProvStatusCb, which has
+         * ESOwnershipTransferData as a return value.
+         */
+        typedef function< ESOwnershipTransferData(shared_ptr<SecProvisioningStatus>) >
+                                                                    SecurityProvStatusCbWithOption;
+
+        /**
+         * Callback definition to be invoked when the security stack expects a pin from application
          */
         typedef function< void(string&) > SecurityPinCb;
 
         /**
-         * Callback definition to be invoked when the stack expects a db path.
+         * Callback definition to be invoked when the stack expects a db path
          */
         typedef function< void(string&) > SecProvisioningDbPathCb;