replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / src / EnrolleeResource.cpp
index 5aa7fca..a1e35e9 100755 (executable)
@@ -36,27 +36,54 @@ namespace OIC
         EnrolleeResource::EnrolleeResource(std::shared_ptr< OC::OCResource > resource)
         {
             m_ocResource = resource;
+            m_getStatusCb = nullptr;
+            m_getConfigurationStatusCb = nullptr;
+            m_devicePropProvStatusCb = nullptr;
+            m_connectRequestStatusCb = nullptr;
         }
 
-        void EnrolleeResource::checkProvInformationCb(const HeaderOptions& /*headerOptions*/,
-                const OCRepresentation& rep, const int eCode)
+        void EnrolleeResource::onEnrolleeResourceSafetyCB(const HeaderOptions& headerOptions,
+                                                        const OCRepresentation& rep,
+                                                        const int eCode,
+                                                        ESEnrolleeResourceCb cb,
+                                                        std::weak_ptr<EnrolleeResource> this_ptr)
+        {
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onEnrolleeResourceSafetyCB");
+            std::shared_ptr<EnrolleeResource> Ptr = this_ptr.lock();
+            if(Ptr)
+            {
+                cb(headerOptions, rep, eCode);
+            }
+        }
+
+        void EnrolleeResource::onProvisioningResponse(const HeaderOptions& /*headerOptions*/,
+                const OCRepresentation& /*rep*/, const int eCode)
         {
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : %s, eCode = %d",
-                    rep.getUri().c_str(),
-                    eCode);
+            OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onProvisioningResponse : eCode = %d",
+                        eCode);
 
             if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED)
             {
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "checkProvInformationCb : Provisioning is failed ");
+                ESResult result = ESResult::ES_ERROR;
+
+                OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
+                            "onProvisioningResponse : Provisioning is failed ");
+
+                if(eCode == OCStackResult::OC_STACK_COMM_ERROR)
+                {
+                    OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "can't receive any response from Enrollee by a timeout threshold.");
+                    result = ESResult::ES_COMMUNICATION_ERROR;
+                }
+
                 std::shared_ptr< DevicePropProvisioningStatus > provStatus = std::make_shared<
-                        DevicePropProvisioningStatus >(ESResult::ES_ERROR);
+                        DevicePropProvisioningStatus >(result);
                 m_devicePropProvStatusCb(provStatus);
                 return;
             }
 
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                    "checkProvInformationCb : Provisioning is success. ");
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                    "onProvisioningResponse : Provisioning is success. ");
 
             std::shared_ptr< DevicePropProvisioningStatus > provStatus = std::make_shared<
                     DevicePropProvisioningStatus >(ESResult::ES_OK);
@@ -66,32 +93,32 @@ namespace OIC
         void EnrolleeResource::onGetStatusResponse(const HeaderOptions& /*headerOptions*/,
                 const OCRepresentation& rep, const int eCode)
         {
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onGetStatusResponse : %s, eCode = %d",
-                    rep.getUri().c_str(), eCode);
+            OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onGetStatusResponse : eCode = %d",
+                        eCode);
 
             if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED)
             {
                 ESResult result = ESResult::ES_ERROR;
 
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
                             "onGetStatusResponse : onGetStatusResponse is failed ");
 
-                if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ)
+                if(eCode == OCStackResult::OC_STACK_COMM_ERROR)
                 {
-                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "Mediator is unauthorized from Enrollee.");
-                    result = ESResult::ES_UNAUTHORIZED;
+                    OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "can't receive any response from Enrollee by a timeout threshold.");
+                    result = ESResult::ES_COMMUNICATION_ERROR;
                 }
 
-                EnrolleeStatus enrolleeStatus = {ES_STATE_INIT, ES_ERRCODE_NO_ERROR};
+                EnrolleeStatus enrolleeStatus(rep);
                 std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus = std::make_shared<
-                        GetEnrolleeStatus >(ESResult::ES_ERROR, enrolleeStatus);
+                        GetEnrolleeStatus >(result, enrolleeStatus);
 
                 m_getStatusCb(getEnrolleeStatus);
             }
             else
             {
-                EnrolleeStatus enrolleeStatus = parseEnrolleeStatusFromRepresentation(rep);
+                EnrolleeStatus enrolleeStatus(rep);
                 std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus = std::make_shared<
                         GetEnrolleeStatus >(ESResult::ES_OK, enrolleeStatus);
 
@@ -102,31 +129,31 @@ namespace OIC
         void EnrolleeResource::onGetConfigurationResponse(const HeaderOptions& /*headerOptions*/,
                 const OCRepresentation& rep, const int eCode)
         {
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onGetConfigurationResponse : %s, eCode = %d",
-                    rep.getUri().c_str(), eCode);
+            OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onGetConfigurationResponse : eCode = %d",
+                        eCode);
 
             if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED)
             {
-                ESResult result  = ESResult::ES_ERROR;
+                ESResult result = ESResult::ES_ERROR;
 
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
                             "onGetConfigurationResponse : onGetConfigurationResponse is failed ");
 
-                if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ)
+                if(eCode == OCStackResult::OC_STACK_COMM_ERROR)
                 {
-                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "Mediator is unauthorized from Enrollee.");
-                    result = ESResult::ES_UNAUTHORIZED;
+                    OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "can't receive any response from Enrollee by a timeout threshold.");
+                    result = ESResult::ES_COMMUNICATION_ERROR;
                 }
 
-                EnrolleeConf enrolleeConf;
+                EnrolleeConf enrolleeConf(rep);
                 std::shared_ptr< GetConfigurationStatus > getConfigurationStatus = std::make_shared<
                         GetConfigurationStatus >(result, enrolleeConf);
                 m_getConfigurationStatusCb(getConfigurationStatus);
             }
             else
             {
-                EnrolleeConf enrolleeConf = parseEnrolleeConfFromRepresentation(rep);
+                EnrolleeConf enrolleeConf(rep);
 
                 std::shared_ptr< GetConfigurationStatus > getConfigurationStatus = std::make_shared<
                         GetConfigurationStatus >(ESResult::ES_OK, enrolleeConf);
@@ -134,23 +161,69 @@ namespace OIC
             }
         }
 
-        void EnrolleeResource::registerGetStatusCallback(GetStatusCb callback)
+         void EnrolleeResource::onConnectRequestResponse(const HeaderOptions& /*headerOptions*/,
+                const OCRepresentation& /*rep*/, const int eCode)
+        {
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onConnectRequestResponse : eCode = %d",
+                        eCode);
+
+            if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED)
+            {
+                ESResult result = ESResult::ES_ERROR;
+
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                            "onConnectRequestResponse : onConnectRequestResponse is failed ");
+
+                if(eCode == OCStackResult::OC_STACK_COMM_ERROR)
+                {
+                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "can't receive any response from Enrollee by a timeout threshold.");
+                    result = ESResult::ES_COMMUNICATION_ERROR;
+                }
+
+                std::shared_ptr< ConnectRequestStatus > connectRequestStatus = std::make_shared<
+                        ConnectRequestStatus >(result);
+                m_connectRequestStatusCb(connectRequestStatus);
+                return;
+            }
+
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                    "onConnectRequestResponse : Provisioning is success. ");
+
+            std::shared_ptr< ConnectRequestStatus > connectRequestStatus = std::make_shared<
+                    ConnectRequestStatus >(ESResult::ES_OK);
+            m_connectRequestStatusCb(connectRequestStatus);
+        }
+
+
+        void EnrolleeResource::registerGetStatusCallback(
+            const GetStatusCb callback)
         {
             m_getStatusCb = callback;
         }
 
-        void EnrolleeResource::registerGetConfigurationStatusCallback(GetConfigurationStatusCb callback)
+        void EnrolleeResource::registerGetConfigurationStatusCallback(
+            const GetConfigurationStatusCb callback)
         {
             m_getConfigurationStatusCb = callback;
         }
 
-        void EnrolleeResource::registerDevicePropProvStatusCallback(DevicePropProvStatusCb callback)
+        void EnrolleeResource::registerDevicePropProvStatusCallback(
+            const DevicePropProvStatusCb callback)
         {
             m_devicePropProvStatusCb = callback;
         }
 
+        void EnrolleeResource::registerConnectRequestStatusCallback(
+            const ConnectRequestStatusCb callback)
+        {
+            m_connectRequestStatusCb = callback;
+        }
+
         void EnrolleeResource::getStatus()
         {
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getStatus IN");
+
             if (m_ocResource == nullptr)
             {
                 throw ESBadRequestException("Resource is not initialized");
@@ -160,19 +233,23 @@ namespace OIC
             OC::OCRepresentation rep;
 
             std::function< OCStackResult(void) > getStatus = [&]
-            {   return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
-                        DEFAULT_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
-                        const OCRepresentation& rep, const int eCode) >(
+            {
+                ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB,
+                                std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+                                static_cast<ESEnrolleeResourceCb>(
                                 std::bind(&EnrolleeResource::onGetStatusResponse, this,
-                                        std::placeholders::_1, std::placeholders::_2,
-                                        std::placeholders::_3)));
+                                std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),
+                                shared_from_this());
+
+                return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
+                        DEFAULT_INTERFACE, query, cb, OC::QualityOfService::HighQos);
             };
 
             OCStackResult result = getStatus();
 
             if (result != OCStackResult::OC_STACK_OK)
             {
-                EnrolleeStatus enrolleeStatus = {ES_STATE_INIT, ES_ERRCODE_NO_ERROR};
+                EnrolleeStatus enrolleeStatus(rep);// = {ES_STATE_INIT, ES_ERRCODE_NO_ERROR};
                 std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus = std::make_shared<
                         GetEnrolleeStatus >(ESResult::ES_ERROR, enrolleeStatus);
 
@@ -180,10 +257,13 @@ namespace OIC
 
                 return;
             }
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getStatus OUT");
         }
 
         void EnrolleeResource::getConfiguration()
         {
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getConfiguration IN");
+
             if (m_ocResource == nullptr)
             {
                 throw ESBadRequestException("Resource is not initialized");
@@ -193,155 +273,87 @@ namespace OIC
             OC::OCRepresentation rep;
 
             std::function< OCStackResult(void) > getConfigurationStatus = [&]
-            {   return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
-                        BATCH_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
-                        const OCRepresentation& rep, const int eCode) >(
+            {
+                ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB,
+                                std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+                                static_cast<ESEnrolleeResourceCb>(
                                 std::bind(&EnrolleeResource::onGetConfigurationResponse, this,
-                                        std::placeholders::_1, std::placeholders::_2,
-                                        std::placeholders::_3)));
+                                std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),
+                                shared_from_this());
+
+                return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
+                        BATCH_INTERFACE, query, cb, OC::QualityOfService::HighQos);
             };
 
             OCStackResult result = getConfigurationStatus();
 
             if (result != OCStackResult::OC_STACK_OK)
             {
-                EnrolleeConf enrolleeConf;
+                EnrolleeConf enrolleeConf(rep);
                 std::shared_ptr< GetConfigurationStatus > getConfigurationStatus = std::make_shared<
                         GetConfigurationStatus >(ESResult::ES_ERROR, enrolleeConf);
                 m_getConfigurationStatusCb(getConfigurationStatus);
                 return;
             }
-        }
 
-        void EnrolleeResource::provisionEnrollee(const DeviceProp& deviceProp)
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getConfiguration OUT");
+        }
 
+        void EnrolleeResource::provisionProperties(const DeviceProp& deviceProp)
         {
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "provisionProperties IN");
             if (m_ocResource == nullptr)
             {
                 throw ESBadRequestException("Resource is not initialized");
             }
 
             OC::QueryParamsMap query;
-            OC::OCRepresentation provisioningRepresentation;
-
-            provisioningRepresentation.setValue(OC_RSRVD_ES_SSID, deviceProp.WIFI.ssid);
-            provisioningRepresentation.setValue(OC_RSRVD_ES_CRED, deviceProp.WIFI.pwd);
-            provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHTYPE, deviceProp.WIFI.authtype);
-            provisioningRepresentation.setValue(OC_RSRVD_ES_ENCTYPE, deviceProp.WIFI.enctype);
-            provisioningRepresentation.setValue(OC_RSRVD_ES_LANGUAGE, deviceProp.Device.language);
-            provisioningRepresentation.setValue(OC_RSRVD_ES_COUNTRY, deviceProp.Device.country);
-
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ssid - %s",
-                    (deviceProp.WIFI.ssid).c_str());
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : pwd - %s",
-                    (deviceProp.WIFI.pwd).c_str());
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : authtype - %d",
-                    deviceProp.WIFI.authtype);
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : enctype - %d",
-                    deviceProp.WIFI.enctype);
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : language - %s",
-                    (deviceProp.Device.language).c_str());
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : country - %s",
-                    (deviceProp.Device.country).c_str());
-
-            m_ocResource->post(OC_RSRVD_ES_RES_TYPE_PROV, BATCH_INTERFACE,
-                    provisioningRepresentation, QueryParamsMap(),
-                    std::function<
-                            void(const HeaderOptions& headerOptions,
-                                    const OCRepresentation& rep, const int eCode) >(
-                    std::bind(&EnrolleeResource::checkProvInformationCb, this,
-                    std::placeholders::_1, std::placeholders::_2,
-                    std::placeholders::_3)));
-        }
-
-        EnrolleeConf EnrolleeResource::parseEnrolleeConfFromRepresentation(const OCRepresentation& rep)
-        {
-            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Enter parseEnrolleeConfFromRepresentation");
-
-            DeviceConfig devConf;
-            WiFiConfig wifiConf;
-            bool cloudable = false;
-
-            std::vector<OCRepresentation> children = rep.getChildren();
-
-            for(auto prop = children.begin(); prop != children.end(); ++prop)
-            {
-                if(prop->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
-                {
-                    OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Find wifi resource");
-                    if(prop->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE)
-                                && prop->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
-                    {
-                        std::vector<int> modes = prop->getValue<std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE);
+            OC::OCRepresentation provisioningRepresentation = deviceProp.toOCRepresentation();
 
-                        for(auto mode = modes.begin(); mode != modes.end(); ++mode)
-                        {
-                            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_SUPPORTEDWIFIMODE = %d",
-                                *mode);
-                            wifiConf.modes.push_back(static_cast<WIFI_MODE>(*mode));
-                        }
+            ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB,
+                            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+                            static_cast<ESEnrolleeResourceCb>(
+                            std::bind(&EnrolleeResource::onProvisioningResponse, this,
+                            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),
+                            shared_from_this());
 
-                        wifiConf.freq = static_cast<WIFI_FREQ>(prop->getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
+            m_ocResource->post(OC_RSRVD_ES_RES_TYPE_EASYSETUP, BATCH_INTERFACE,
+                    provisioningRepresentation, QueryParamsMap(), cb, OC::QualityOfService::HighQos);
 
-
-                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_SUPPORTEDWIFIFREQ = %d",
-                                wifiConf.freq);
-                    }
-                }
-
-                else if(prop->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
-                {
-                    OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Find devconf");
-                    if(prop->hasAttribute(OC_RSRVD_ES_DEVNAME)
-                                && prop->hasAttribute(OC_RSRVD_ES_LANGUAGE)
-                                && prop->hasAttribute(OC_RSRVD_ES_COUNTRY))
-                    {
-                        //TODO:: setting DeviceID.
-                        //devInfo.id = devId;
-                        devConf.name = prop->getValue<std::string>(OC_RSRVD_ES_DEVNAME);
-                        devConf.language = prop->getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
-                        devConf.country = prop->getValue<std::string>(OC_RSRVD_ES_COUNTRY);
-
-                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_DEVNAME = %s",
-                                devConf.name.c_str());
-                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_LANGUAGE = %s",
-                                devConf.language.c_str());
-                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_COUNTRY = %s",
-                                devConf.country.c_str());
-                    }
-                }
-
-                else if(prop->getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
-                {
-                    OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Find cloudserver");
-                    cloudable = true;
-                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "cloudable = %d",
-                                cloudable);
-                }
-            }
-
-            return EnrolleeConf(devConf, wifiConf, cloudable);
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "provisionProperties OUT");
         }
 
-        EnrolleeStatus EnrolleeResource::parseEnrolleeStatusFromRepresentation(const OCRepresentation& rep)
+        void EnrolleeResource::requestToConnect(const std::vector<ES_CONNECT_TYPE> &connectTypes)
         {
-            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Enter parseEnrolleeStatusFromRepresentation");
-
-            EnrolleeStatus enrolleeStatus;
-
-            if(rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
+            OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "requestToConnect IN");
+            if (m_ocResource == nullptr)
             {
-                enrolleeStatus.provStatus = static_cast<ProvStatus>(
-                                                        rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
+                throw ESBadRequestException("Resource is not initialized");
             }
 
-            if(rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
+            OC::QueryParamsMap query;
+            OC::OCRepresentation requestRepresentation;
+            std::vector<int> connectTypes_int;
+            connectTypes_int.clear();
+
+            for(auto it : connectTypes)
             {
-                enrolleeStatus.lastErrCode = static_cast<ESErrorCode>(
-                                                        rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
+                connectTypes_int.push_back(static_cast<int>(it));
             }
 
-            return enrolleeStatus;
+            requestRepresentation.setValue<std::vector<int>>(OC_RSRVD_ES_CONNECT, connectTypes_int);
+
+            ESEnrolleeResourceCb cb = std::bind(&EnrolleeResource::onEnrolleeResourceSafetyCB,
+                            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
+                            static_cast<ESEnrolleeResourceCb>(
+                            std::bind(&EnrolleeResource::onConnectRequestResponse, this,
+                            std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),
+                            shared_from_this());
+
+            m_ocResource->post(OC_RSRVD_ES_RES_TYPE_EASYSETUP, OC_RSRVD_INTERFACE_DEFAULT,
+                    requestRepresentation, QueryParamsMap(), cb, OC::QualityOfService::HighQos);
+
+            OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "requestToConnect OUT");
         }
     }
 }