Add cloud provisioning feature & modify mediator C++ class in easy setup
authorHeewon Park <h_w.park@samsung.com>
Fri, 10 Jun 2016 05:33:39 +0000 (14:33 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 14 Jun 2016 10:43:44 +0000 (10:43 +0000)
Major change:
- Implement a class to support cloud provisioning feature
  ; User can provide cloud access information to Enrollee device
  ; With the provided information, Enrollee can register to IoTivity cloud server
Minor change:
- RemoteEnrollee class constructor becomes a private method.
- Add cloud provision data model at ESRichcommon.h.
- DiscoverResource Logic moves to RemoteEnrollee class from EnrolleeResource class
  ; RemoteEnrollee class creates EnrolleeResource and CloudResource after corresponding resources are discovered
- Change the "initRemoteEnrollee" function signature which has no callback parameter
  ; If no provisioning resource is found, exception is thrown.

Change-Id: I0797720ce478e8b70680df53884bb28e67efbc37
Signed-off-by: Heewon Park <h_w.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8587
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
13 files changed:
service/easy-setup/mediator/richsdk/SConscript
service/easy-setup/mediator/richsdk/inc/CloudResource.h [new file with mode: 0755]
service/easy-setup/mediator/richsdk/inc/ESRichCommon.h
service/easy-setup/mediator/richsdk/inc/EasySetup.h
service/easy-setup/mediator/richsdk/inc/EnrolleeResource.h
service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h
service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h
service/easy-setup/mediator/richsdk/src/CloudResource.cpp [new file with mode: 0755]
service/easy-setup/mediator/richsdk/src/EasySetup.cpp
service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp
service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp
service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp

index aaf334afc687149b8048f7c7091fb064b9b7d5c3..de1eea070ae1f9f64905370dce3082bfd0554a19 100644 (file)
@@ -121,6 +121,7 @@ if target_os in ['linux']:
 
        es_common_src = ['src/RemoteEnrollee.cpp',
                'src/EnrolleeResource.cpp',
+               'src/CloudResource.cpp',
                'src/EasySetup.cpp',
                'src/ESException.cpp']
 
@@ -134,8 +135,8 @@ print "Files path is %s" % env.get('es_src')
 ######################################################################
 # Build RichSDK Mediator Sample App
 ################################################ ######################
-#if target_os == 'linux':
-#      SConscript('../../sampleapp/mediator/linux/richsdk_sample/SConscript')
+if target_os == 'linux':
+       SConscript('../../sampleapp/mediator/linux/richsdk_sample/SConscript')
 
 ######################################################################
 #Build UnitTestcases for Mediator[RichSDK]
diff --git a/service/easy-setup/mediator/richsdk/inc/CloudResource.h b/service/easy-setup/mediator/richsdk/inc/CloudResource.h
new file mode 100755 (executable)
index 0000000..f2ca9c6
--- /dev/null
@@ -0,0 +1,64 @@
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef CLOUD_RESOURCE_H_
+#define CLOUD_RESOURCE_H_
+
+#include <mutex>
+#include <memory>
+
+#include "ESRichCommon.h"
+
+#include "OCApi.h"
+
+using namespace OC;
+
+namespace OIC
+{
+    namespace Service
+    {
+        class OCResource;
+        /**
+         * This class contains the resource discovery methods.
+         *
+         * @see CloudResource
+         */
+        class CloudResource
+        {
+        public:
+            CloudResource(std::shared_ptr< OC::OCResource > resource);
+            ~CloudResource() = default;
+
+            void registerCloudProvisioningStatusCallback (CloudProvStatusCb callback);
+            void provisionEnrollee(const CloudProvInfo& cloudProvInfo);
+
+        private:
+            void onCloudProvResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+                    const int eCode);
+
+        private:
+            std::shared_ptr< OC::OCResource > m_ocResource;
+            CloudProvStatusCb m_cloudProvStatusCb;
+
+            DataProvInfo m_dataProvInfo;
+        };
+    }
+}
+#endif
index fb3ae83b40ed11a4199f5687a0fe61838996d5a1..7de9bb6e0b68daf10cc22e09d3e1189a8ad69aa7 100755 (executable)
@@ -25,6 +25,7 @@
 #include <string>
 #ifndef WITH_ARDUINO
 #include <memory>
+#include <vector>
 #endif
 
 #include "ocstack.h"
 using namespace std;
 
 // Defines
-#define OIC_STRING_MAX_VALUE    100
-#define IPV4_ADDR_SIZE          16
 #define IP_PORT                 55555
-#define NET_WIFI_SSID_SIZE      100
-#define NET_WIFI_PWD_SIZE       100
-#define NET_WIFI_AUTH_SIZE      100
-
-/**
- * @brief Mac address length for BT port
- */
-#define NET_MACADDR_SIZE 18
 
 /**
  * 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_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"
+#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                 "oic.r.prov"
+#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"
@@ -74,7 +67,6 @@ using namespace std;
 #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"
-#define OC_RSRVD_ES_URI_NET                             "/oic/net"
 
 /**
  * @brief Defines for Provisioning status accepted values
@@ -104,17 +96,6 @@ namespace OIC
             ES_UNAUTHORIZED = 31
         } ESResult;
 
-        /**
-         * Provosioning Status
-         */
-        typedef enum
-        {
-            DEVICE_PROVISIONED = 0,
-            DEVICE_NOT_PROVISIONED,
-            DEVICE_OWNED,
-            DEVICE_NOT_OWNED
-        } EasySetupState;
-
         /**
          * @brief  WIFI Authentication type of the Enroller
          */
@@ -139,61 +120,59 @@ namespace OIC
             TKIP_AES
         } WIFI_ENCTYPE;
 
-        /**
-         * @brief  Network information of the Enroller
-         */
-        typedef union
+        typedef enum
         {
-            /**
-             * @brief BT Mac Information
-             */
-            struct
-            {
-                char btMacAddress[NET_MACADDR_SIZE];   /**< BT mac address **/
-            } BT;
+            WIFI_24G = 0,
+            WIFI_5G,
+            WIFI_BOTH
+        } WIFI_FREQ;
 
-            /**
-             * @brief LE MAC Information
-             */
-            struct
-            {
-                char leMacAddress[NET_MACADDR_SIZE];   /**< BLE mac address **/
-            } LE;
+        typedef enum
+        {
+            WiFi_11A = 0,
+            WiFi_11B,
+            WiFi_11G,
+            WiFi_11N,
+            WiFi_11AC
+        } WIFI_MODE;
+
+        typedef struct
+        {
+            string authCode;
+            string authProvider;
+            string ciServer;
+        } CloudProvInfo;
 
-            /**
-             * @brief IP Information
-             */
+        typedef struct
+        {
             struct
             {
-                char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
-                char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
+                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**/
-                char authcode[NET_WIFI_AUTH_SIZE];
-                char authserverUrl[NET_WIFI_AUTH_SIZE];
-                char apiserverUrl[NET_WIFI_AUTH_SIZE];
             } WIFI;
-        } ProvData;
 
-        /**
-         * @brief Network Information
-         */
+            struct
+            {
+                string language;
+                string country;
+            } Device;
+        } DataProvInfo;
+
         typedef struct
         {
-            ProvData provData;    /**< Enroller Network Info**/
-            OCConnectivityType connType;    /**< Connectivity Type**/
-        } ProvConfig;
+            string id;
+            string name;
+            string language;
+            string country;
+        } DeviceConfig;
 
-        /**
-         * @brief This structure represent onboarding connection instance.
-        */
         typedef struct
         {
-         /*Actual use of ipAddress is for unicast discovery, but also used to identify the Enrollee device as of now,
-            device identification should be based on DeviceID in next release.*/
-           char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enrollee **/
-           bool isSecured;                 /**< Secure connection**/
-        }WiFiOnboadingConnection;
+            vector<WIFI_MODE> types;
+            WIFI_FREQ freq;
+        } NetworkInfo;
 
         typedef enum
         {
@@ -205,11 +184,11 @@ namespace OIC
 
         typedef enum
         {
-            ES_UNKNOWN = 0,
-            ES_ONBOARDED,
-            ES_OWNED,
-            ES_PROVISIONED
-        } CurrentESState;
+            ES_CLOUD_PROVISIONING_ERROR = -1,
+            ES_CLOUD_PROVISIONING_SUCCESS,
+            ES_ENROLLEE_FOUND,
+            ES_ENROLLEE_NOT_FOUND
+        }ESCloudProvState;
 
         typedef enum
         {
@@ -225,13 +204,12 @@ namespace OIC
         class SecProvisioningStatus
         {
         public:
-            SecProvisioningStatus(std::string deviceUUID, ESResult result) :
+            SecProvisioningStatus(string deviceUUID, ESResult result) :
                 m_devUUID(deviceUUID), m_result(result)
             {
-
             }
 
-            std::string getDeviceUUID()
+            const string getDeviceUUID()
             {
                 return m_devUUID;
             }
@@ -241,64 +219,72 @@ namespace OIC
                 return m_result;
             }
         private:
-            std::string m_devUUID;
+            string m_devUUID;
             ESResult m_result;
         };
 
-        class CapabilityData
+        class PropertyData
         {
         public:
-            CapabilityData()
+            PropertyData()
             {
+            }
 
+            PropertyData(DeviceConfig devConfig, NetworkInfo netInfo, bool cloudable) :
+                m_devConfig(devConfig), m_netInfo(netInfo), m_cloudable(cloudable)
+            {
             }
-        private:
-        };
 
-        class InitRemoteEnrolleeStatus
-        {
-        public:
-            InitRemoteEnrolleeStatus(ESResult result) :
-                    m_result(result)
+            const DeviceConfig getDevInfo()
             {
+                return m_devConfig;
+            }
 
+            const NetworkInfo getNetInfo()
+            {
+                return m_netInfo;
             }
 
-            ESResult getESResult()
+            bool isCloudable()
             {
-                return m_result;
+                return m_cloudable;
             }
+
         private:
-            ESResult m_result;
+            DeviceConfig m_devConfig;
+            NetworkInfo m_netInfo;
+            bool m_cloudable;
         };
 
-        class RequestCapabilityStatus
+        class RequestPropertyDataStatus
         {
         public:
-            RequestCapabilityStatus(ESResult result, const CapabilityData& data) :
-                    m_result(result), m_capabilityData(data)
+            RequestPropertyDataStatus(ESResult result, const PropertyData& data) :
+                    m_result(result), m_PropertyData(data)
             {
             }
+
             ESResult getESResult()
             {
                 return m_result;
             }
-            CapabilityData getCapabilityData()
+
+            const PropertyData getPropertyData()
             {
-                return m_capabilityData;
+                return m_PropertyData;
             }
+
         private:
             ESResult m_result;
-            CapabilityData m_capabilityData;
+            PropertyData m_PropertyData;
         };
 
-        class ProvisioningStatus
+        class DataProvisioningStatus
         {
         public:
-            ProvisioningStatus(ESResult result, ESState esState) :
+            DataProvisioningStatus(ESResult result, ESState esState) :
                     m_result(result), m_esState(esState)
             {
-
             }
 
             ESResult getESResult()
@@ -310,63 +296,64 @@ namespace OIC
             {
                 return m_esState;
             }
+
         private:
             ESResult m_result;
             ESState m_esState;
         };
 
-        class EasySetupStatus
+        class CloudProvisioningStatus
         {
         public:
-            EasySetupStatus(const EasySetupState& easySetupState,
-                    const ProvConfig& provConfig) :
-                    m_easySetupState(easySetupState), m_ProvConfig(provConfig)
+            CloudProvisioningStatus(ESResult result, ESCloudProvState state) :
+                    m_result(result), m_esCloudState(state)
             {
-
             }
 
-            ProvConfig getProvConfig()
+            ESResult getESResult()
             {
-                return m_ProvConfig;
+                return m_result;
             }
 
-            EasySetupState getEasySetupState()
+            ESCloudProvState getESCloudState()
             {
-                return m_easySetupState;
+                return m_esCloudState;
             }
+
         private:
-            EasySetupState m_easySetupState;
-            ProvConfig m_ProvConfig;
+            ESResult m_result;
+            ESCloudProvState m_esCloudState;
         };
 
         /**
          * Callback function definition for providing Enrollee security status .
          */
-        typedef std::function< void(std::shared_ptr< InitRemoteEnrolleeStatus >) > InitRemoteEnrolleeStatusCb;
+        typedef function< void(shared_ptr< RequestPropertyDataStatus >) > RequestPropertyDataStatusCb;
 
         /**
          * Callback function definition for providing Enrollee security status .
          */
-        typedef std::function< void(std::shared_ptr< RequestCapabilityStatus >) > RequestCapabilityStatusCb;
+        typedef function< void(shared_ptr< DataProvisioningStatus >) > DataProvStatusCb;
+
         /**
          * Callback function definition for providing Enrollee security status .
          */
-        typedef std::function< void(std::shared_ptr< ProvisioningStatus >) > DataProvStatusCb;
+        typedef function< void(shared_ptr< CloudProvisioningStatus >) > CloudProvStatusCb;
 
         /**
          * Callback function definition for providing Enrollee security status .
          */
-        typedef std::function< void(std::shared_ptr<SecProvisioningStatus>) > EnrolleeSecStatusCb;
+        typedef function< void(shared_ptr<SecProvisioningStatus>) > EnrolleeSecStatusCb;
 
         /**
          * Callback definition to be invoked when the security stack expects a pin from application.
          */
-        typedef std::function< void(std::string&) > SecurityPinCb;
+        typedef function< void(string&) > SecurityPinCb;
 
         /**
          * Callback definition to be invoked when the stack expects a db path.
          */
-        typedef std::function< void(std::string&) > SecProvisioningDbPathCb;
+        typedef function< void(string&) > SecProvisioningDbPathCb;
 
     }
 }
index 15df9f682b5c69c7003c185fa44bf9f1efa78cad..058ae2e3befb6b433b0e241dcea600ed75ebf903 100644 (file)
@@ -51,14 +51,13 @@ namespace OIC
 
             /**
              * This API is used for creating a remote Enrollee  instance.
-             * @param WiFiOnboadingConnection Onboarding connection information for configuring the Enrollee.
              *
              * @throws ESBadRequestException If createEnrolleeDevice is invoked with the same
              *         provisioning information.
              *
              * @return Pointer to RemoteEnrollee instance.
              */
-            std::shared_ptr<RemoteEnrollee> createRemoteEnrollee(const WiFiOnboadingConnection& wifiOnboardingconn);
+            std::shared_ptr<RemoteEnrollee> createRemoteEnrollee();
 
         private:
             EasySetup();
index 7b4066bb362de7e475a4089bc7b79aae6d49d12c..07dce668ecfab367cc46941c1f9d6f4215b0fede 100755 (executable)
@@ -55,8 +55,8 @@ namespace OIC
              *
              * @throw ESBadRequestException is thrown if the parameters are invalid
              */
-            EnrolleeResource(const WiFiOnboadingConnection &onboardingconn);
-            // EnrolleeResource(const ProvConfig &enrolleeNWProvInfo,
+            EnrolleeResource(std::shared_ptr< OC::OCResource > resource);
+            // EnrolleeResource(const DataProvInfo &enrolleeNWProvInfo,
             //                                    const WiFiOnboadingConnection &onboardingconn);
 
             ~EnrolleeResource() = default;
@@ -69,31 +69,19 @@ namespace OIC
              * @throws InvalidParameterException If callback is an empty function or null.
              * @throws ESBadRequestException If registration is already completed.
              *
-             * @see ProvisioningStatus
+             * @see DataProvisioningStatus
              */
-            void registerInitRemoteEnrolleeStatusCallback (InitRemoteEnrolleeStatusCb callback);
-            void registerCapabilityStatusCallback (RequestCapabilityStatusCb callback);
+            void registerRequestPropertyDataStatusCallback (RequestPropertyDataStatusCb callback);
             void registerProvStatusCallback (DataProvStatusCb callback);
 
-            /**
-             * Construct Remote OIC resource using the enrollee host and connectivity information
-             * provided in the constructor of EnrolleeResource.
-             *
-             * @throws InvalidParameterException If the provided information is invalid.
-             * @throws ESBadRequestException If resource is already constructed.
-             *
-             * @see ProvisioningStatus
-             */
-            ESResult constructResourceObject();
-
-            void getCapabilityData();
+            void RequestPropertyData();
 
             /**
              * Function for provisioning of Remote Enrollee resource using the information provided.
              *
              * @throws InvalidParameterException If cb is empty.
              */
-            void provisionEnrollee();
+            void provisionEnrollee(const DataProvInfo& dataProvInfo);
 
             /**
              * Function for unprovisioning of Remote Enrollee and bring to unprovisioned state
@@ -102,36 +90,22 @@ namespace OIC
              */
             void unprovisionEnrollee();
 
-
-
         private:
             std::shared_ptr< OC::OCResource > m_ocResource;
-            std::mutex m_mutex;
-            InitRemoteEnrolleeStatusCb m_initRemoteEnrolleeStatusCb;
-            RequestCapabilityStatusCb m_requestCapabilityStatusCb;
+
+            RequestPropertyDataStatusCb m_RequestPropertyDataStatusCb;
             DataProvStatusCb m_dataProvStatusCb;
-            ProvConfig m_ProvConfig;
-            WiFiOnboadingConnection m_wifiOnboardingconn;
-            bool m_discoveryResponse;
 
-            void getCapabilityResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep,
-                    const int eCode);
+            DataProvInfo m_dataProvInfo;
 
+        private:
+            void onRequestPropertyDataResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+                    const int eCode);
             void getProvStatusResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep,
                     const int eCode);
-
             void checkProvInformationCb(const HeaderOptions& headerOptions, const OCRepresentation& rep,
                     const int eCode);
-
-            ESResult ESDiscoveryTimeout(unsigned short waittime);
-
-            void onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource);
-
-            void triggerNetworkConnection();
-
-            void triggerNetworkConnectionCb(
-                    const HeaderOptions& headerOptions, const OCRepresentation& rep,
-                    const int eCode);
+            PropertyData parsePropertyDataFromRepresentation(const OCRepresentation& rep);
         };
     }
 }
index 7f934b8f6ad4d369f2bb0768cc98b7761ffdc83c..13fd62492ef975a046ddfbcb29c9a193ef23ffa2 100755 (executable)
@@ -47,7 +47,7 @@ namespace OIC
             std::string secDbPath);
             ESResult registerCallbackHandler(EnrolleeSecStatusCb enrolleeSecStatusCb,
                     SecurityPinCb securityPinCb, SecProvisioningDbPathCb secProvisioningDbPathCb);
-            EasySetupState performOwnershipTransfer();
+            bool performOwnershipTransfer();
 
         private:
             std::shared_ptr< EnrolleeResource > m_EnrolleeResource;
index f479de10bc67a2a7f4a6a3cd54a110b11b8cde06..d329289b57d4a5bb6d85a8e3cf7a2a23855fb82a 100644 (file)
 #ifndef REMOTE_ENROLLEE_H_
 #define REMOTE_ENROLLEE_H_
 
+#include <memory>
+
 #include "ESRichCommon.h"
+#include "OCApi.h"
+
+using namespace OC;
 
 namespace OIC
 {
     namespace Service
     {
+        class OCResource;
         class EnrolleeResource;
+        class CloudResource;
         class EnrolleeSecurity;
 
         /**
@@ -38,15 +45,6 @@ namespace OIC
         class RemoteEnrollee
         {
         public:
-            /**
-             * RemoteEnrollee constructor
-             *
-             * @param enrolleeNWProvInfo Provisioning information for the Enrollee
-             *
-             * @throw ESBadRequestException is thrown if the parameters are invalid
-             */
-            RemoteEnrollee(const WiFiOnboadingConnection& wifiOnboardingconn);
-
             ~RemoteEnrollee() = default;
 
 #ifdef __WITH_DTLS__
@@ -73,25 +71,25 @@ namespace OIC
              *
              * @see RemoteEnrollee
              */
-             void initRemoteEnrollee(InitRemoteEnrolleeStatusCb callback);
+            void  initRemoteEnrollee();
 
-             /**
+            /**
              * Start provisioning of target Enrollers information to the Enrollee.
              *
              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
              *
              * @see RemoteEnrollee
              */
-            void startSecurityProvisioning(EnrolleeSecStatusCb callback);
+            void requestPropertyData(RequestPropertyDataStatusCb callback);
 
-            /**
+             /**
              * Start provisioning of target Enrollers information to the Enrollee.
              *
              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
              *
              * @see RemoteEnrollee
              */
-            void getCapabilityData(RequestCapabilityStatusCb callback);
+            void startSecurityProvisioning(EnrolleeSecStatusCb callback);
 
             /**
              * Start provisioning of target Enrollers information to the Enrollee.
@@ -100,55 +98,61 @@ namespace OIC
              *
              * @see RemoteEnrollee
              */
-            void startDataProvisioning(const ProvConfig& dataProvConfig, DataProvStatusCb callback);
+            void startDataProvisioning(DataProvStatusCb callback);
 
             /**
-             * Stop provisioning process that is currently in progress.
+             * Start provisioning of target Enrollers information to the Enrollee.
              *
-             * @throws BadRequestException If provisioning is not in progress.
-             */
-            void stopProvisioning();
-
-            /**
-             * Check if the Enrollee device provisioned.
+             * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
+             *
+             * @see RemoteEnrollee
              */
-            bool isEnrolleeProvisioned();
+            void startCloudProvisioning(CloudProvStatusCb callback);
 
             /**
              * Get the Provisioning information provided for the current Enrollee.
              *
-             * @return ProvConfig Provisioning information provided for the current Enrollee.
+             * @return DataProvInfo Provisioning information provided for the current Enrollee.
              */
-            ProvConfig getProvConfig ();
+            DataProvInfo getDataProvInfo();
 
-            /**
-             * Get the Onboarding connection information between Mediator and Enrollee.
-             *
-             * @return WiFiOnboadingConnection information between Mediator and Enrollee.
-             */
+            void setDataProvInfo(const DataProvInfo& );
+            void setCloudProvInfo(const CloudProvInfo& );
 
-            WiFiOnboadingConnection getOnboardConn();
+        private:
+            RemoteEnrollee();
+
+            ESResult discoverResource();
+            ESResult ESDiscoveryTimeout(unsigned short waittime);
+            void onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource);
+            void initCloudResource();
+
+            void RequestPropertyDataStatusHandler (std::shared_ptr< RequestPropertyDataStatus > status);
+            void dataProvisioningStatusHandler (std::shared_ptr< DataProvisioningStatus > status);
+            void cloudProvisioningStatusHandler (std::shared_ptr< CloudProvisioningStatus > status);
+            void easySetupSecurityStatusCallback(std::shared_ptr< SecProvisioningStatus > status);
 
         private:
-            std::shared_ptr< EnrolleeResource > m_remoteResource;
+            std::shared_ptr< OC::OCResource > m_ocResource;
+            std::shared_ptr< EnrolleeResource > m_enrolleeResource;
+            std::shared_ptr< EnrolleeSecurity > m_enrolleeSecurity;
+            std::shared_ptr< CloudResource > m_cloudResource;
+
+            std::string  m_deviceId;
+            bool m_discoveryResponse;
+
             EnrolleeSecStatusCb m_enrolleeSecStatusCb;
-            InitRemoteEnrolleeStatusCb m_initRemoteEnrolleeStatusCb;
-            RequestCapabilityStatusCb m_requestCapabilityStatusCb;
+            RequestPropertyDataStatusCb m_RequestPropertyDataStatusCb;
             SecurityPinCb m_securityPinCb;
             SecProvisioningDbPathCb m_secProvisioningDbPathCb;
             DataProvStatusCb m_dataProvStatusCb;
-            ProvConfig m_ProvConfig;
-            WiFiOnboadingConnection m_wifiOnboardingconn;
+            CloudProvStatusCb m_cloudProvStatusCb;
 
-            std::shared_ptr< EnrolleeSecurity > m_enrolleeSecurity;
-            CurrentESState m_currentESState;
-            bool m_isSecured;
-
-            void InitRemoteEnrolleeStatusHandler (std::shared_ptr< InitRemoteEnrolleeStatus > initRemoteEnrolleeStatus);
-            void requestCapabilityStatusHandler (std::shared_ptr< RequestCapabilityStatus > requestCapabilityStatus);
-            void dataProvisioningStatusHandler (std::shared_ptr< ProvisioningStatus > provStatus);
-            void easySetupSecurityStatusCallback(
-            std::shared_ptr< SecProvisioningStatus > secProvisioningResult);
+            DataProvInfo m_dataProvInfo;
+            CloudProvInfo m_cloudProvInfo;
+            PropertyData m_propertyData;
+
+            friend class EasySetup;
         };
     }
 }
diff --git a/service/easy-setup/mediator/richsdk/src/CloudResource.cpp b/service/easy-setup/mediator/richsdk/src/CloudResource.cpp
new file mode 100755 (executable)
index 0000000..ac15b59
--- /dev/null
@@ -0,0 +1,107 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <functional>
+
+#include "CloudResource.h"
+
+#include "OCPlatform.h"
+#include "ESException.h"
+#include "OCResource.h"
+#include "logger.h"
+
+namespace OIC
+{
+    namespace Service
+    {
+        #define ES_CLOUD_RES_TAG "ES_CLOUD_RESOURCE"
+
+        static const char ES_BASE_RES_URI[] = "/oic/res";
+
+        CloudResource::CloudResource(std::shared_ptr< OC::OCResource > resource)
+        {
+            m_ocResource = resource;
+        }
+
+        void CloudResource::provisionEnrollee(const CloudProvInfo& cloudProvInfo)
+        {
+            OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "Enter provisionEnrollee.");
+
+            OCRepresentation provisioningRepresentation;
+
+            provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHCODE, cloudProvInfo.authCode);
+            provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHPROVIDER, cloudProvInfo.authProvider);
+            provisioningRepresentation.setValue(OC_RSRVD_ES_CISERVER, cloudProvInfo.ciServer);
+
+            OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "provisionEnrollee : authCode - %s",
+                    (cloudProvInfo.authCode).c_str());
+            OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "provisionEnrollee : authProvider - %s",
+                    (cloudProvInfo.authProvider).c_str());
+            OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "provisionEnrollee : ciServer - %s",
+                    (cloudProvInfo.ciServer).c_str());
+
+            m_ocResource->post(OC_RSRVD_ES_PROV_RES_TYPE, BATCH_INTERFACE,
+                        provisioningRepresentation, QueryParamsMap(),
+                        std::function<
+                                void(const HeaderOptions& headerOptions,
+                                        const OCRepresentation& rep, const int eCode) >(
+                        std::bind(&CloudResource::onCloudProvResponse, this,
+                        std::placeholders::_1, std::placeholders::_2,
+                        std::placeholders::_3)));
+        }
+
+        void CloudResource::onCloudProvResponse(const HeaderOptions& /*headerOptions*/,
+                const OCRepresentation& rep, const int eCode)
+        {
+            OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "onCloudProvResponse : %s, eCode = %d",
+                    rep.getUri().c_str(), eCode);
+
+            if (eCode != 0)
+            {
+                ESResult result  = ESResult::ES_ERROR;
+
+                OIC_LOG(DEBUG, ES_CLOUD_RES_TAG,"onCloudProvResponse : onCloudProvResponse is failed ");
+
+                if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ)
+                {
+                    OIC_LOG(DEBUG, ES_CLOUD_RES_TAG, "Mediator is unauthorized from Enrollee.");
+                    result = ESResult::ES_UNAUTHORIZED;
+                }
+
+                std::shared_ptr< CloudProvisioningStatus > provStatus = std::make_shared<
+                        CloudProvisioningStatus >(result, ESCloudProvState::ES_CLOUD_PROVISIONING_ERROR);
+                m_cloudProvStatusCb(provStatus);
+            }
+            else
+            {
+                OIC_LOG(DEBUG, ES_CLOUD_RES_TAG,"onCloudProvResponse : onCloudProvResponse is success ");
+                std::shared_ptr< CloudProvisioningStatus > provStatus = std::make_shared<
+                        CloudProvisioningStatus >(ESResult::ES_OK, ESCloudProvState::ES_CLOUD_PROVISIONING_SUCCESS);
+                m_cloudProvStatusCb(provStatus);
+            }
+        }
+
+        void CloudResource::registerCloudProvisioningStatusCallback(CloudProvStatusCb callback)
+        {
+            OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "Enter registerCloudProvisioningStatusCallback.");
+            m_cloudProvStatusCb = callback;
+        }
+    }
+}
index 3d6cb284e33ca6d4e1e83e45b162f916672ff6c6..31d46151bfd59ac3f7a1905e1a630b54379cb332 100644 (file)
@@ -46,9 +46,9 @@ namespace OIC
             return s_instance;
         }
 
-        std::shared_ptr<RemoteEnrollee> EasySetup::createRemoteEnrollee (const WiFiOnboadingConnection& wifiOnboardingconn)
+        std::shared_ptr<RemoteEnrollee> EasySetup::createRemoteEnrollee ()
         {
-            return std::make_shared< RemoteEnrollee > (wifiOnboardingconn);
+            return std::shared_ptr< RemoteEnrollee > (new RemoteEnrollee());
         }
     }
 }
index 47b4545c65d8342576b67d8ea408ccbeb4331072..07b4ea852da4aca48c96aea55e5f08807571efb2 100755 (executable)
@@ -19,7 +19,6 @@
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
 #include <functional>
-#include <time.h>
 
 #include "EnrolleeResource.h"
 
@@ -32,73 +31,11 @@ namespace OIC
 {
     namespace Service
     {
-        #define ES_REMOTE_ENROLLEE_RES_TAG "ES_REMOTE_ENROLLEE_RES"
-        #define DISCOVERY_TIMEOUT 5
+        #define ES_REMOTE_ENROLLEE_RES_TAG "ES_ENROLLEE_RESOURCE"
 
-        static const char ES_BASE_RES_URI[] = "/oic/res";
-        static const char ES_PROV_RES_URI[] = "/oic/prov";
-        static const char ES_PROV_RES_TYPE[] = "oic.r.prov";
-
-        EnrolleeResource::EnrolleeResource(const WiFiOnboadingConnection &onboardingconn)
-        {
-            m_wifiOnboardingconn = onboardingconn;
-            m_discoveryResponse = false;
-        }
-/*
-        EnrolleeResource::EnrolleeResource(const ProvConfig &provConfig,
-                                                  const WiFiOnboadingConnection &onboardingconn)
-        {
-            m_ProvConfig = provConfig;
-            m_wifiOnboardingconn = onboardingconn;
-            m_discoveryResponse = false;
-        }
-*/
-        void EnrolleeResource::triggerNetworkConnectionCb(
-                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);
-
-            if (eCode != 0)
-            {
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "triggerNetworkConnectionCb : Trigger action failed ");
-                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
-                m_dataProvStatusCb(provStatus);
-                return;
-            }
-            else
-            {
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "triggerNetworkConnectionCb : Provisioning is success ");
-                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONING_SUCCESS);
-                m_dataProvStatusCb(provStatus);
-                return;
-            }
-        }
-
-        void EnrolleeResource::triggerNetworkConnection()
+        EnrolleeResource::EnrolleeResource(std::shared_ptr< OC::OCResource > resource)
         {
-            if (m_ocResource == nullptr)
-            {
-                throw ESBadRequestException("Resource is not initialized");
-            }
-
-            OCRepresentation provisioningRepresentation;
-
-            provisioningRepresentation.setValue(OC_RSRVD_ES_TRIGGER, 1);
-
-            m_ocResource->post(provisioningRepresentation, QueryParamsMap(),
-                    std::function<
-                            void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
-                                    const int eCode) >(
-                            std::bind(&EnrolleeResource::triggerNetworkConnectionCb, this,
-                                    std::placeholders::_1, std::placeholders::_2,
-                                    std::placeholders::_3)));
+            m_ocResource = resource;
         }
 
         void EnrolleeResource::checkProvInformationCb(const HeaderOptions& /*headerOptions*/,
@@ -112,56 +49,35 @@ namespace OIC
             {
                 OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
                         "checkProvInformationCb : Provisioning is failed ");
-                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
+                std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
+                        DataProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
                 m_dataProvStatusCb(provStatus);
                 return;
             }
+            // int ps = -1;
+            // rep.getValue(OC_RSRVD_ES_PROVSTATUS, ps);
+            // OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : ps - %d", ps);
 
-            int ps = -1;
-
-            rep.getValue(OC_RSRVD_ES_PROVSTATUS, ps);
-
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : ps - %d", ps);
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                    "checkProvInformationCb : Provisioning is success. "
+                    "Now trigger network connection ");
 
-            //Provisioning status check
-            if (ps == ES_PS_PROVISIONING_COMPLETED)
-            {
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "checkProvInformationCb : Provisioning is success. "
-                        "Now trigger network connection ");
-
-                #ifdef REMOTE_ARDUINO_ENROLEE
-                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONING_SUCCESS);
-                m_dataProvStatusCb(provStatus);
-                #endif
-
-                triggerNetworkConnection();
-                return;
-            }
-            else
-            {
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "checkProvInformationCb : Provisioning is failed ");
-                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
-                m_dataProvStatusCb(provStatus);
-                return;
-            }
+            std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
+                    DataProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONING_SUCCESS);
+            m_dataProvStatusCb(provStatus);
         }
 
-        void EnrolleeResource::getCapabilityResponse(const HeaderOptions& /*headerOptions*/,
+        void EnrolleeResource::onRequestPropertyDataResponse(const HeaderOptions& /*headerOptions*/,
                 const OCRepresentation& rep, const int eCode)
         {
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getCapabilityResponse : %s, eCode = %d",
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onRequestPropertyDataResponse : %s, eCode = %d",
                     rep.getUri().c_str(), eCode);
 
             if (eCode != 0)
             {
                 ESResult result  = ESResult::ES_ERROR;
 
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,"getCapabilityResponse : getCapabilityResponse is failed ");
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,"onRequestPropertyDataResponse : onRequestPropertyDataResponse is failed ");
 
                 if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ)
                 {
@@ -170,18 +86,20 @@ namespace OIC
                     result = ESResult::ES_UNAUTHORIZED;
                 }
 
-                CapabilityData capabilityData;
-                std::shared_ptr< RequestCapabilityStatus > requestCapabilityStatus = std::make_shared<
-                        RequestCapabilityStatus >(result, capabilityData);
-                m_requestCapabilityStatusCb(requestCapabilityStatus);
-
-                return;
+                PropertyData propertyData;
+                std::shared_ptr< RequestPropertyDataStatus > requestPropertyDataStatus = std::make_shared<
+                        RequestPropertyDataStatus >(result, propertyData );
+                m_RequestPropertyDataStatusCb(requestPropertyDataStatus);
             }
 
-            CapabilityData capabilityData = CapabilityData();
-            std::shared_ptr< RequestCapabilityStatus > requestCapabilityStatus = std::make_shared<
-                    RequestCapabilityStatus >(ESResult::ES_OK, capabilityData);
-            m_requestCapabilityStatusCb(requestCapabilityStatus);
+            else
+            {
+                PropertyData propertyData = parsePropertyDataFromRepresentation(rep);
+
+                std::shared_ptr< RequestPropertyDataStatus > requestPropertyDataStatus = std::make_shared<
+                        RequestPropertyDataStatus >(ESResult::ES_OK, propertyData);
+                m_RequestPropertyDataStatusCb(requestPropertyDataStatus);
+            }
         }
 
         void EnrolleeResource::getProvStatusResponse(const HeaderOptions& /*headerOptions*/,
@@ -203,8 +121,8 @@ namespace OIC
                         "Mediator is unauthorized from Enrollee.");
                     result = ESResult::ES_UNAUTHORIZED;
                 }
-                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(result, ESState::ES_PROVISIONING_ERROR);
+                std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
+                        DataProvisioningStatus >(result, ESState::ES_PROVISIONING_ERROR);
                 m_dataProvStatusCb(provStatus);
 
                 return;
@@ -217,41 +135,33 @@ namespace OIC
             OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ps - %d",
                     ps);
 
-            if (ps == ES_PS_NEED_PROVISIONING) //Indicates the need for provisioning
+            //if (ps == ES_PS_NEED_PROVISIONING) //Indicates the need for provisioning
+            if (ps == 0) //Indicates the need for provisioning
             {
                 OCRepresentation provisioningRepresentation;
 
-                provisioningRepresentation.setValue(OC_RSRVD_ES_SSID,
-                std::string(m_ProvConfig.provData.WIFI.ssid));
-                provisioningRepresentation.setValue(OC_RSRVD_ES_CRED,
-                std::string(m_ProvConfig.provData.WIFI.pwd));
-                provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHCODE,
-                std::string(m_ProvConfig.provData.WIFI.authcode));
-                provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHPROVIDER,
-                std::string(m_ProvConfig.provData.WIFI.authserverUrl));
-                provisioningRepresentation.setValue(OC_RSRVD_ES_CISERVER,
-                std::string(m_ProvConfig.provData.WIFI.apiserverUrl));
-                provisioningRepresentation.setValue( OC_RSRVD_ES_AUTHTYPE,
-                m_ProvConfig.provData.WIFI.authtype);
-                provisioningRepresentation.setValue(OC_RSRVD_ES_ENCTYPE,
-                m_ProvConfig.provData.WIFI.enctype);
+                provisioningRepresentation.setValue(OC_RSRVD_ES_SSID, m_dataProvInfo.WIFI.ssid);
+                provisioningRepresentation.setValue(OC_RSRVD_ES_CRED, m_dataProvInfo.WIFI.pwd);
+                provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHTYPE, m_dataProvInfo.WIFI.authtype);
+                provisioningRepresentation.setValue(OC_RSRVD_ES_ENCTYPE, m_dataProvInfo.WIFI.enctype);
+                provisioningRepresentation.setValue(OC_RSRVD_ES_LANGUAGE, m_dataProvInfo.Device.language);
+                provisioningRepresentation.setValue(OC_RSRVD_ES_COUNTRY, m_dataProvInfo.Device.country);
 
                 OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ssid - %s",
-                        m_ProvConfig.provData.WIFI.ssid);
+                        (m_dataProvInfo.WIFI.ssid).c_str());
                 OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : pwd - %s",
-                        m_ProvConfig.provData.WIFI.pwd);
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : AuthCode - %s",
-                        m_ProvConfig.provData.WIFI.authcode);
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : AuthServerUrl - %s",
-                        m_ProvConfig.provData.WIFI.authserverUrl);
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : APIServerUrl - %s",
-                        m_ProvConfig.provData.WIFI.apiserverUrl);
+                        (m_dataProvInfo.WIFI.pwd).c_str());
                 OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : authtype - %d",
-                        m_ProvConfig.provData.WIFI.authtype);
+                        m_dataProvInfo.WIFI.authtype);
                 OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : enctype - %d",
-                        m_ProvConfig.provData.WIFI.enctype);
-
-                m_ocResource->post(provisioningRepresentation, QueryParamsMap(),
+                        m_dataProvInfo.WIFI.enctype);
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : language - %s",
+                        (m_dataProvInfo.Device.language).c_str());
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : country - %s",
+                        (m_dataProvInfo.Device.country).c_str());
+
+                m_ocResource->post(OC_RSRVD_ES_PROV_RES_TYPE, BATCH_INTERFACE,
+                        provisioningRepresentation, QueryParamsMap(),
                         std::function<
                                 void(const HeaderOptions& headerOptions,
                                         const OCRepresentation& rep, const int eCode) >(
@@ -263,20 +173,15 @@ namespace OIC
             {
                 OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
                         "getProvStatusResponse : Provisioning is successful");
-                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONED_ALREADY);
+                std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
+                        DataProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONED_ALREADY);
                 m_dataProvStatusCb(provStatus);
             }
         }
 
-        void EnrolleeResource::registerInitRemoteEnrolleeStatusCallback (InitRemoteEnrolleeStatusCb callback)
+        void EnrolleeResource::registerRequestPropertyDataStatusCallback(RequestPropertyDataStatusCb callback)
         {
-            m_initRemoteEnrolleeStatusCb = callback;
-        }
-
-        void EnrolleeResource::registerCapabilityStatusCallback(RequestCapabilityStatusCb callback)
-        {
-            m_requestCapabilityStatusCb = callback;
+            m_RequestPropertyDataStatusCb = callback;
         }
 
         void EnrolleeResource::registerProvStatusCallback(DataProvStatusCb callback)
@@ -284,234 +189,7 @@ namespace OIC
             m_dataProvStatusCb = callback;
         }
 
-        ESResult EnrolleeResource::ESDiscoveryTimeout(unsigned short waittime)
-        {
-            struct timespec startTime;
-            startTime.tv_sec=0;
-            startTime.tv_sec=0;
-            struct timespec currTime;
-            currTime.tv_sec=0;
-            currTime.tv_nsec=0;
-
-            ESResult res = ES_OK;
-            #ifdef _POSIX_MONOTONIC_CLOCK
-                int clock_res = clock_gettime(CLOCK_MONOTONIC, &startTime);
-            #else
-                int clock_res = clock_gettime(CLOCK_REALTIME, &startTime);
-            #endif
-
-            if (0 != clock_res)
-            {
-                return ES_ERROR;
-            }
-
-            while (ES_OK == res || m_discoveryResponse == false)
-            {
-                #ifdef _POSIX_MONOTONIC_CLOCK
-                        clock_res = clock_gettime(CLOCK_MONOTONIC, &currTime);
-                #else
-                        clock_res = clock_gettime(CLOCK_REALTIME, &currTime);
-                #endif
-
-                if (0 != clock_res)
-                {
-                    std::shared_ptr< InitRemoteEnrolleeStatus > initRemoteEnrolleeStatus = std::make_shared<
-                        InitRemoteEnrolleeStatus >(ESResult::ES_ERROR);
-                    m_initRemoteEnrolleeStatusCb(initRemoteEnrolleeStatus);
-                    return ES_ERROR;
-                }
-                long elapsed = (currTime.tv_sec - startTime.tv_sec);
-                if (elapsed > waittime)
-                {
-                    return ES_OK;
-                }
-                if (m_discoveryResponse)
-                {
-                    res = ES_OK;
-                }
-             }
-             return res;
-        }
-
-        void EnrolleeResource::onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource)
-        {
-            OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onDeviceDiscovered");
-
-            std::string resourceURI;
-            std::string hostAddress;
-            std::string hostDeviceID;
-            try
-            {
-                if(resource)
-                {
-                    // Get the resource URI
-                    resourceURI = resource->uri();
-                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                            "URI of the resource: %s", resourceURI.c_str());
-
-                    // Get the resource host address
-                    hostAddress = resource->host();
-                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                            "Host address of the resource: %s", hostAddress.c_str());
-
-                    hostDeviceID = resource->sid();
-                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                            "Host DeviceID of the resource: %s", hostDeviceID.c_str());
-                    /*
-                     * Easysetup is always performed with a single Enrollee device and
-                     * in a private network (SoftAP or BLE), so the assumption is that
-                     * only the intended device will respond for the discovery.
-                     * With the above assumption the below two statements are written.
-                     */
-                    m_ocResource = resource;
-                    m_discoveryResponse = true;
-
-                    std::shared_ptr< InitRemoteEnrolleeStatus > initRemoteEnrolleeStatus = std::make_shared<
-                        InitRemoteEnrolleeStatus >(ESResult::ES_OK);
-                    m_initRemoteEnrolleeStatusCb(initRemoteEnrolleeStatus);
-                }
-                else
-                {
-                    OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "Resource is invalid");
-
-                    std::shared_ptr< InitRemoteEnrolleeStatus > initRemoteEnrolleeStatus = std::make_shared<
-                        InitRemoteEnrolleeStatus >(ESResult::ES_ERROR);
-                    m_initRemoteEnrolleeStatusCb(initRemoteEnrolleeStatus);
-                }
-
-            }
-            catch(std::exception& e)
-            {
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "Exception in foundResource: %s", e.what());
-            }
-        }
-
-
-        ESResult EnrolleeResource::constructResourceObject()
-        {
-            if (m_ocResource != nullptr)
-            {
-                throw ESBadRequestException("Remote resource is already created");
-            }
-
-#ifdef REMOTE_ARDUINO_ENROLEE
-            //This process will create OCResource with port 55555 which is specific
-            // to Arduino WiFi enrollee
-            try
-            {
-
-                std::vector< std::string > interface =
-                {   DEFAULT_INTERFACE};
-                std::vector< std::string > resTypes =
-                {   ES_PROV_RES_TYPE};
-
-                OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "Before OCPlatform::constructResourceObject");
-
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "m_host = %s",
-                        m_wifiOnboardingconn.ipAddress);
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "ES_PROV_RES_URI = %s", ES_PROV_RES_URI);
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "m_connectivityType = %d",
-                        m_ProvConfig.connType);
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "resTypes = %s",
-                        resTypes.at(0).c_str());
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "interface = %s", interface.at(0).c_str());
-
-                std::string host;
-                if(m_wifiOnboardingconn.isSecured)
-                {
-                    host.append("coaps://");
-                }
-                else
-                {
-                    host.append("coap://");
-                }
-
-                if(m_ProvConfig.connType == CT_ADAPTER_IP)
-                {
-                    // TODO : RemoteEnrollee is current handling easysetup on IP transport.
-                    // WiFiRemoteEnrollee need to extend RemoteEnrollee for providing IP specific
-                    // Enrollee easysetup.
-
-                    host.append(m_wifiOnboardingconn.ipAddress);
-                    //TODO : If the target Enrollee is not a Arduino Wi-Fi device,
-                    // then the port number will be found during resource discovery instead of
-                    // using 55555
-                    host.append(":55555");
-                }
-
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "HOST = %s", host.c_str());
-
-                m_ocResource = OC::OCPlatform::constructResourceObject(host,
-                        ES_PROV_RES_URI,
-                        m_ProvConfig.connType,
-                        true,
-                        resTypes,
-                        interface);
-                OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "created OCResource : %s", m_ocResource->uri().c_str());
-
-                return ES_OK;
-            }
-            catch (OCException & e)
-            {
-                OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "Exception for constructResourceObject : %s", e.reason().c_str());
-                return ES_ERROR;
-            }
-#else
-            std::string host("");
-            std::string query("");
-
-            if (m_wifiOnboardingconn.isSecured)
-            {
-                host.append("coaps://");
-            }
-            else
-            {
-                host.append("coap://");
-            }
-
-            query.append(ES_BASE_RES_URI);
-            query.append("?rt=");
-            query.append(ES_PROV_RES_TYPE);
-
-            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "Before OCPlatform::constructResourceObject");
-
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "host = %s", host.c_str());
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "query = %s", query.c_str());
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "m_connectivityType = %d",
-                    m_ProvConfig.connType);
-
-            m_discoveryResponse = false;
-            std::function< void (std::shared_ptr<OC::OCResource>) > onDeviceDiscoveredCb =
-                    std::bind(&EnrolleeResource::onDeviceDiscovered, this,
-                                                    std::placeholders::_1);
-            OCStackResult result = OC::OCPlatform::findResource("", query, CT_DEFAULT,
-                    onDeviceDiscoveredCb);
-
-            if (result != OCStackResult::OC_STACK_OK)
-            {
-                OIC_LOG(ERROR,ES_REMOTE_ENROLLEE_RES_TAG,
-                        "Failed to create device using constructResourceObject");
-                return ES_ERROR;
-            }
-
-
-            ESResult foundResponse = ESDiscoveryTimeout (DISCOVERY_TIMEOUT);
-
-            if (foundResponse ==ES_ERROR || !m_discoveryResponse)
-            {
-                OIC_LOG(ERROR,ES_REMOTE_ENROLLEE_RES_TAG,
-                        "Failed to create device using constructResourceObject");
-                return ES_ERROR;
-            }
-
-            return ES_OK;
-#endif
-        }
-
-        void EnrolleeResource::getCapabilityData()
+        void EnrolleeResource::RequestPropertyData()
         {
             if (m_ocResource == nullptr)
             {
@@ -521,28 +199,28 @@ namespace OIC
             OC::QueryParamsMap query;
             OC::OCRepresentation rep;
 
-            std::function< OCStackResult(void) > getCapabilityStatus = [&]
+            std::function< OCStackResult(void) > requestPropertyDataStatus = [&]
             {   return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
                         BATCH_INTERFACE, query, std::function<void(const HeaderOptions& headerOptions,
                         const OCRepresentation& rep, const int eCode) >(
-                                std::bind(&EnrolleeResource::getCapabilityResponse, this,
+                                std::bind(&EnrolleeResource::onRequestPropertyDataResponse, this,
                                         std::placeholders::_1, std::placeholders::_2,
                                         std::placeholders::_3)));
             };
 
-            OCStackResult result = getCapabilityStatus();
+            OCStackResult result = requestPropertyDataStatus();
 
             if (result != OCStackResult::OC_STACK_OK)
             {
-                CapabilityData capabilityData;
-                std::shared_ptr< RequestCapabilityStatus > requestCapabilityStatus = std::make_shared<
-                        RequestCapabilityStatus >(ESResult::ES_ERROR, capabilityData);
-                m_requestCapabilityStatusCb(requestCapabilityStatus);
+                PropertyData propertyData;
+                std::shared_ptr< RequestPropertyDataStatus > requestPropertyDataStatus = std::make_shared<
+                        RequestPropertyDataStatus >(ESResult::ES_ERROR, propertyData);
+                m_RequestPropertyDataStatusCb(requestPropertyDataStatus);
                 return;
             }
         }
 
-        void EnrolleeResource::provisionEnrollee()
+        void EnrolleeResource::provisionEnrollee(const DataProvInfo& dataProvInfo)
 
         {
             if (m_ocResource == nullptr)
@@ -550,6 +228,8 @@ namespace OIC
                 throw ESBadRequestException("Resource is not initialized");
             }
 
+            m_dataProvInfo = dataProvInfo;
+
             OC::QueryParamsMap query;
             OC::OCRepresentation rep;
 
@@ -568,8 +248,8 @@ namespace OIC
 
             if (result != OCStackResult::OC_STACK_OK)
             {
-                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
+                std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
+                        DataProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
                 m_dataProvStatusCb(provStatus);
                 return;
             }
@@ -595,5 +275,75 @@ namespace OIC
                     std::placeholders::_1, std::placeholders::_2,
                     std::placeholders::_3)));
         }
+
+        PropertyData EnrolleeResource::parsePropertyDataFromRepresentation(const OCRepresentation& rep)
+        {
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Enter parsePropertyDataFromRepresentation");
+
+            DeviceConfig devInfo;
+            NetworkInfo netInfo;
+            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> types = prop->getValue<std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE);
+
+                        for(auto type = types.begin(); type != types.end(); ++type)
+                        {
+                            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_SUPPORTEDWIFIMODE = %d",
+                                *type);
+                            netInfo.types.push_back(static_cast<WIFI_MODE>(*type));
+                        }
+
+                        netInfo.freq = static_cast<WIFI_FREQ>(prop->getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
+
+
+                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_SUPPORTEDWIFIFREQ = %d",
+                                netInfo.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;
+                        devInfo.name = prop->getValue<std::string>(OC_RSRVD_ES_DEVNAME);
+                        devInfo.language = prop->getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
+                        devInfo.country = prop->getValue<std::string>(OC_RSRVD_ES_COUNTRY);
+
+                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_DEVNAME = %s",
+                                devInfo.name.c_str());
+                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_LANGUAGE = %s",
+                                devInfo.language.c_str());
+                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_COUNTRY = %s",
+                                devInfo.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 PropertyData(devInfo, netInfo, cloudable);
+        }
+
     }
 }
index 211958de920ca28a2e1535b000faa9637f086777..fea39d2b7e1396ab1fbe966d0e891153a18f710f 100755 (executable)
@@ -139,10 +139,8 @@ namespace OIC
             }
         }
 
-        EasySetupState EnrolleeSecurity::performOwnershipTransfer()
+        bool EnrolleeSecurity::performOwnershipTransfer()
         {
-            EasySetupState ownershipStatus = DEVICE_NOT_OWNED;
-
             OC::DeviceList_t pUnownedDevList, pOwnedDevList;
 
             pOwnedDevList.clear();
@@ -183,7 +181,6 @@ namespace OIC
             if (result != OC_STACK_OK)
             {
                 OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "UnOwned Discovery failed.");
-                ownershipStatus = DEVICE_NOT_OWNED;
                 //Throw exception
                 throw ESPlatformException(result);
             }
@@ -213,21 +210,17 @@ namespace OIC
                     if (m_unownedDevice->doOwnershipTransfer(ownershipTransferCb) != OC_STACK_OK)
                     {
                         OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "OwnershipTransferCallback is failed");
-                        ownershipStatus = DEVICE_NOT_OWNED;
-                        return ownershipStatus;
+                        return false;
                     }
-                    ownershipStatus = DEVICE_OWNED;
                 }
             }
             else
             {
-                OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "No unSecure devices found.");
-                ownershipStatus = DEVICE_NOT_OWNED;
-
-                return ownershipStatus;
+                OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "No unOwned devices found.");
+                return false;
             }
 
-            return ownershipStatus;
+            return true;
         }
     }
 }
index 427556e108f31ebca393f86f49daeefb1ec2e2a1..22fd384b36cfe6b0001441e0028c139f9e70df5b 100755 (executable)
 
 #include "RemoteEnrollee.h"
 #include "EnrolleeResource.h"
+#include "CloudResource.h"
+#include "OCPlatform.h"
 #include "ESException.h"
 #include "logger.h"
+#include "OCResource.h"
 #ifdef __WITH_DTLS__
 #include "EnrolleeSecurity.h"
 #endif //__WITH_DTLS
 
 namespace OIC
 {
-    #define ES_REMOTE_ENROLLEE_TAG "ES_REMOTE_ENROLLEE"
-
     namespace Service
     {
-        RemoteEnrollee::RemoteEnrollee(const WiFiOnboadingConnection& wifiOnboardingconn) :
-                m_wifiOnboardingconn(wifiOnboardingconn)
-        {
-            m_requestCapabilityStatusCb = nullptr;
-            m_currentESState = CurrentESState::ES_ONBOARDED;
-            m_isSecured = m_wifiOnboardingconn.isSecured;
-
-            m_remoteResource = std::make_shared< EnrolleeResource >(m_wifiOnboardingconn);
+        static const char ES_BASE_RES_URI[] = "/oic/res";
+        #define ES_REMOTE_ENROLLEE_TAG "ES_REMOTE_ENROLLEE"
+        #define DISCOVERY_TIMEOUT 5
 
-            OIC_LOG ( DEBUG, ES_REMOTE_ENROLLEE_TAG, "Inside RemoteEnrollee constr");
+        RemoteEnrollee::RemoteEnrollee()
+        {
+            m_enrolleeSecStatusCb = nullptr;
+            m_RequestPropertyDataStatusCb = nullptr;
+            m_securityPinCb = nullptr;
+            m_secProvisioningDbPathCb = nullptr;
+            m_dataProvStatusCb = nullptr;
+            m_cloudProvStatusCb = nullptr;
+
+            //m_deviceId = nullptr;
         }
 
 #ifdef __WITH_DTLS__
@@ -60,98 +65,243 @@ namespace OIC
 #endif //__WITH_DTLS__
 
         void RemoteEnrollee::easySetupSecurityStatusCallback(
-                        std::shared_ptr< SecProvisioningStatus > secProvisioningStatus)
+                        std::shared_ptr< SecProvisioningStatus > status)
         {
             OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "easySetupStatusCallback status is, UUID = %s, "
-                    "Status = %d", secProvisioningStatus->getDeviceUUID().c_str(),
-                    secProvisioningStatus->getResult());
+                    "Status = %d", status->getDeviceUUID().c_str(),
+                    status->getResult());
 
-            if(secProvisioningStatus->getResult() == ES_OK)
+            if(status->getResult() == ES_OK)
             {
                 OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Ownership and ACL are successful. "
                         "Continue with Network information provisioning");
 
-                m_currentESState = CurrentESState::ES_OWNED;
-
                 OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Before ProvisionEnrollee");
 
-                m_enrolleeSecStatusCb(secProvisioningStatus);
+                m_enrolleeSecStatusCb(status);
             }
             else
             {
                 OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Ownership and ACL are fail");
 
-                m_enrolleeSecStatusCb(secProvisioningStatus);
+                m_enrolleeSecStatusCb(status);
             }
         }
 
-        void RemoteEnrollee::InitRemoteEnrolleeStatusHandler (
-                std::shared_ptr< InitRemoteEnrolleeStatus > initRemoteEnrolleeStatus)
+        void RemoteEnrollee::RequestPropertyDataStatusHandler (
+                std::shared_ptr< RequestPropertyDataStatus > status)
         {
-            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering InitRemoteEnrolleeStatusHandler");
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering RequestPropertyDataStatusHandler");
 
-            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"initRemoteEnrolleeStatus = %d", initRemoteEnrolleeStatus->getESResult());
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"RequestPropertyDataStatus = %d", status->getESResult());
 
-            m_initRemoteEnrolleeStatusCb(initRemoteEnrolleeStatus);
+            if(status->getESResult() == ES_OK)
+            {
+                m_propertyData = status->getPropertyData();
+            }
+
+            m_RequestPropertyDataStatusCb(status);
         }
 
-        void RemoteEnrollee::requestCapabilityStatusHandler (
-                std::shared_ptr< RequestCapabilityStatus > requestCapabilityStatus)
+        void RemoteEnrollee::dataProvisioningStatusHandler(
+                std::shared_ptr< DataProvisioningStatus > status)
         {
-            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering requestCapabilityStatusHandler");
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering dataProvisioningStatusHandler");
 
-            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"requestCapabilityStatus = %d", requestCapabilityStatus->getESResult());
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", status->getESResult());
 
-            m_requestCapabilityStatusCb(requestCapabilityStatus);
+            if (status->getESResult() == ES_OK)
+            {
+                if (status->getESState() >= ESState::ES_PROVISIONED_ALREADY)
+                {
+                    OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", status->getESResult());
+                }
+            }
+            m_dataProvStatusCb(status);
+
+            return;
         }
 
-        void RemoteEnrollee::dataProvisioningStatusHandler(
-                std::shared_ptr< ProvisioningStatus > provStatus)
+        void RemoteEnrollee::cloudProvisioningStatusHandler (
+                std::shared_ptr< CloudProvisioningStatus > status)
         {
-            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering dataprovisioningStatusHandler");
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering cloudProvisioningStatusHandler");
+
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"CloudProvStatus = %d", status->getESCloudState());
 
-            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", provStatus->getESResult());
+            m_cloudProvStatusCb(status);
+            return;
+        }
 
-            if (provStatus->getESResult() == ES_OK)
+        ESResult RemoteEnrollee::ESDiscoveryTimeout(unsigned short waittime)
+        {
+            struct timespec startTime;
+            startTime.tv_sec=0;
+            startTime.tv_sec=0;
+            struct timespec currTime;
+            currTime.tv_sec=0;
+            currTime.tv_nsec=0;
+
+            ESResult res = ES_OK;
+            #ifdef _POSIX_MONOTONIC_CLOCK
+                int clock_res = clock_gettime(CLOCK_MONOTONIC, &startTime);
+            #else
+                int clock_res = clock_gettime(CLOCK_REALTIME, &startTime);
+            #endif
+
+            if (0 != clock_res)
             {
-                if (provStatus->getESState() >= ESState::ES_PROVISIONED_ALREADY)
+                return ES_ERROR;
+            }
+
+            while (ES_OK == res || m_discoveryResponse == false)
+            {
+                #ifdef _POSIX_MONOTONIC_CLOCK
+                        clock_res = clock_gettime(CLOCK_MONOTONIC, &currTime);
+                #else
+                        clock_res = clock_gettime(CLOCK_REALTIME, &currTime);
+                #endif
+
+                if (0 != clock_res)
                 {
-                    OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", provStatus->getESResult());
-                    m_currentESState = CurrentESState::ES_PROVISIONED;
+                    return ES_ERROR;
                 }
-            }
-            m_dataProvStatusCb(provStatus);
+                long elapsed = (currTime.tv_sec - startTime.tv_sec);
+                if (elapsed > waittime)
+                {
+                    return ES_OK;
+                }
+                if (m_discoveryResponse)
+                {
+                    res = ES_OK;
+                }
+             }
+             return res;
+        }
 
-            return;
+        void RemoteEnrollee::onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource)
+        {
+            OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onDeviceDiscovered");
+
+            std::string resourceURI;
+            std::string hostAddress;
+            std::string hostDeviceID;
+            try
+            {
+                if(resource)
+                {
+                    // Get the resource URI
+                    resourceURI = resource->uri();
+                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,
+                            "URI of the resource: %s", resourceURI.c_str());
+
+                    // Get the resource host address
+                    hostAddress = resource->host();
+                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,
+                            "Host address of the resource: %s", hostAddress.c_str());
+
+                    hostDeviceID = resource->sid();
+                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,
+                            "Host DeviceID of the resource: %s", hostDeviceID.c_str());
+
+                    if(m_deviceId .empty())
+                    {
+                        /*
+                         * Easysetup is always performed with a single Enrollee device and
+                         * in a private network (SoftAP or BLE), so the assumption is that
+                         * only the intended device will respond for the discovery.
+                         * With the above assumption the below two statements are written.
+                         */
+                        m_ocResource = resource;
+                        m_deviceId = resource->sid();
+                        m_discoveryResponse = true;
+                    }
+
+                    else if(!m_deviceId.empty() && m_deviceId == hostDeviceID)
+                    {
+                        OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_TAG, "Find matched CloudResource");
+                        m_ocResource = resource;
+                        m_discoveryResponse = true;
+                    }
+                }
+            }
+            catch(std::exception& e)
+            {
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,
+                        "Exception in foundResource: %s", e.what());
+            }
         }
 
-        void RemoteEnrollee::initRemoteEnrollee(InitRemoteEnrolleeStatusCb callback)
+        ESResult RemoteEnrollee::discoverResource()
         {
-            ESResult result = ES_ERROR;
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Enter discoverResource");
 
-            if(!callback)
+            if (m_ocResource != nullptr)
             {
-                throw ESInvalidParameterException("Callback is empty");
+                throw ESBadRequestException("resource is already created");
             }
 
-            m_initRemoteEnrolleeStatusCb = callback;
+            std::string query("");
+            query.append(ES_BASE_RES_URI);
+            query.append("?rt=");
+            query.append(OC_RSRVD_ES_PROV_RES_TYPE);
+
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "query = %s", query.c_str());
+
+            m_discoveryResponse = false;
 
-            if (m_remoteResource != nullptr)
+            std::function< void (std::shared_ptr<OC::OCResource>) > onDeviceDiscoveredCb =
+                    std::bind(&RemoteEnrollee::onDeviceDiscovered, this,
+                                                    std::placeholders::_1);
+            OCStackResult result = OC::OCPlatform::findResource("", query, CT_DEFAULT,
+                    onDeviceDiscoveredCb);
+
+            if (result != OCStackResult::OC_STACK_OK)
             {
-                throw ESBadRequestException ("Already created");
+                OIC_LOG(ERROR,ES_REMOTE_ENROLLEE_TAG,
+                        "Failed discoverResource");
+                return ES_ERROR;
             }
 
-            InitRemoteEnrolleeStatusCb initRemoteEnrolleeStatusCb = std::bind(
-                    &RemoteEnrollee::InitRemoteEnrolleeStatusHandler, this, std::placeholders::_1);
-            m_remoteResource->registerInitRemoteEnrolleeStatusCallback(initRemoteEnrolleeStatusCb);
+            ESResult foundResponse = ESDiscoveryTimeout (DISCOVERY_TIMEOUT);
 
-            result = m_remoteResource->constructResourceObject();
+            if (foundResponse == ES_ERROR || !m_discoveryResponse)
+            {
+                OIC_LOG(ERROR,ES_REMOTE_ENROLLEE_TAG,
+                        "Failed discoverResource because timeout");
+                return ES_ERROR;
+            }
+            return ES_OK;
+        }
+
+        void RemoteEnrollee::initRemoteEnrollee()
+        {
+            ESResult result = ES_ERROR;
+
+            if (m_enrolleeResource != nullptr)
+            {
+                throw ESBadRequestException ("Already created");
+            }
+
+            result = discoverResource();
 
             if (result == ES_ERROR)
             {
                 OIC_LOG(ERROR,ES_REMOTE_ENROLLEE_TAG,
-                                    "Failed to create device using constructResourceObject");
-                throw ESBadRequestException ("Device not created");
+                                    "Failed to create resource object using discoverResource");
+                throw ESBadRequestException ("Resource object not created");
+            }
+
+            else
+            {
+                if(m_ocResource != nullptr)
+                {
+                    m_enrolleeResource = std::make_shared<EnrolleeResource>(std::move(m_ocResource));
+                }
+                else
+                {
+                    throw ESBadGetException ("Resource handle is invalid");
+                }
             }
         }
 
@@ -161,110 +311,188 @@ namespace OIC
 
             m_enrolleeSecStatusCb = callback;
 
-            if (m_isSecured && m_currentESState < CurrentESState::ES_OWNED)
-            {
-                EnrolleeSecStatusCb securityProvStatusCb = std::bind(
-                        &RemoteEnrollee::easySetupSecurityStatusCallback,
-                        this,
-                        std::placeholders::_1);
-                //TODO : DBPath is passed empty as of now. Need to take dbpath from application.
-                m_enrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_remoteResource, "");
+            EnrolleeSecStatusCb securityProvStatusCb = std::bind(
+                    &RemoteEnrollee::easySetupSecurityStatusCallback,
+                    this,
+                    std::placeholders::_1);
+            //TODO : DBPath is passed empty as of now. Need to take dbpath from application.
+            m_enrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_enrolleeResource, "");
 
-                m_enrolleeSecurity->registerCallbackHandler(securityProvStatusCb,
-                        m_securityPinCb, m_secProvisioningDbPathCb);
+            m_enrolleeSecurity->registerCallbackHandler(securityProvStatusCb,
+                    m_securityPinCb, m_secProvisioningDbPathCb);
 
-                try
-                {
-                    EasySetupState easySetupState = m_enrolleeSecurity->performOwnershipTransfer();
-                    if (easySetupState == DEVICE_NOT_OWNED)
-                    {
-                        OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG,
-                                "performOwnershipTransfer returned : %d",
-                                easySetupState);
-                        return;
-                    }
-                    else if (easySetupState == DEVICE_OWNED)
-                    {
-                        OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG,
-                                "performOwnershipTransfer returned : %d",
-                                easySetupState);
-                        OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Before ProvisionEnrollee");
-                    }
-                }
-                catch (OCException & e)
+            try
+            {
+                if (!m_enrolleeSecurity->performOwnershipTransfer())
                 {
-                    OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,
-                            "Exception for performOwnershipTransfer : %s", e.reason().c_str());
-                    return ;
+                    OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Fail performOwnershipTransfer");
+                    std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
+                            std::make_shared< SecProvisioningStatus >(nullptr, ES_ERROR);
+                    m_enrolleeSecStatusCb(securityProvisioningStatus);
+                    return;
                 }
             }
+            catch (OCException & e)
+            {
+                OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,
+                        "Exception for performOwnershipTransfer : %s", e.reason().c_str());
+                return ;
+            }
+#else
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Mediator is unsecured.");
+
+            std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
+                     std::make_shared< SecProvisioningStatus >(nullptr, ES_ERROR);
+            m_enrolleeSecStatusCb(securityProvisioningStatus);
 #endif
         }
 
-        void RemoteEnrollee::getCapabilityData(RequestCapabilityStatusCb callback)
+        void RemoteEnrollee::requestPropertyData(RequestPropertyDataStatusCb callback)
         {
-            ESResult result = ES_ERROR;
-
             if(!callback)
             {
                 throw ESInvalidParameterException("Callback is empty");
             }
 
-            m_requestCapabilityStatusCb = callback;
+            m_RequestPropertyDataStatusCb = callback;
 
-            if (m_remoteResource == nullptr)
+            if (m_enrolleeResource == nullptr)
             {
                 throw ESBadRequestException ("Device not created");
             }
 
-            RequestCapabilityStatusCb requestCapabilityStatusCb = std::bind(
-                    &RemoteEnrollee::requestCapabilityStatusHandler, this, std::placeholders::_1);
-            m_remoteResource->registerCapabilityStatusCallback(requestCapabilityStatusCb);
-            m_remoteResource->getCapabilityData();
+            RequestPropertyDataStatusCb RequestPropertyDataStatusCb = std::bind(
+                    &RemoteEnrollee::RequestPropertyDataStatusHandler, this, std::placeholders::_1);
+            m_enrolleeResource->registerRequestPropertyDataStatusCallback(RequestPropertyDataStatusCb);
+            m_enrolleeResource->RequestPropertyData();
         }
 
-        void RemoteEnrollee::startDataProvisioning(const ProvConfig& dataProvConfig, DataProvStatusCb callback)
+        void RemoteEnrollee::startDataProvisioning(DataProvStatusCb callback)
         {
-            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Before ProvisionEnrollee");
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Enter startDataProvisioning");
+
+            if(!callback)
+            {
+                throw ESInvalidParameterException("Callback is empty");
+            }
+
+            m_dataProvStatusCb = callback;
+
+            if (m_enrolleeResource == nullptr)
+            {
+                throw ESBadRequestException ("Device not created");
+            }
+
+            if(m_dataProvInfo.WIFI.ssid.empty())
+            {
+                throw ESBadRequestException ("Invalid Provisiong Data.");
+            }
 
-            m_ProvConfig = dataProvConfig;
             m_dataProvStatusCb = callback;
 
             DataProvStatusCb dataProvStatusCb = std::bind(
                     &RemoteEnrollee::dataProvisioningStatusHandler, this, std::placeholders::_1);
 
-            m_remoteResource->registerProvStatusCallback(dataProvStatusCb);
-            m_remoteResource->provisionEnrollee();
+            m_enrolleeResource->registerProvStatusCallback(dataProvStatusCb);
+            m_enrolleeResource->provisionEnrollee(m_dataProvInfo);
         }
 
-        void RemoteEnrollee::stopProvisioning()
+        void RemoteEnrollee::initCloudResource()
         {
-            m_currentESState = CurrentESState::ES_UNKNOWN;
+            ESResult result = ES_ERROR;
+
+            if (m_cloudResource != nullptr)
+            {
+                throw ESBadRequestException ("Already created");
+            }
+
+            result = discoverResource();
+
+            if (result == ES_ERROR)
+            {
+                OIC_LOG(ERROR,ES_REMOTE_ENROLLEE_TAG,
+                                    "Failed to create resource object using discoverResource");
+                throw ESBadRequestException ("Resource object not created");
+            }
+
+            else
+            {
+                if(m_ocResource != nullptr)
+                {
+                    m_cloudResource = std::make_shared<CloudResource>(std::move(m_ocResource));
 
-            m_remoteResource->unprovisionEnrollee();
+                    std::shared_ptr< CloudProvisioningStatus > provStatus = std::make_shared<
+                        CloudProvisioningStatus >(ESResult::ES_ERROR, ESCloudProvState::ES_ENROLLEE_FOUND);
+                    m_cloudProvStatusCb(provStatus);
+                }
+                else
+                {
+                    throw ESBadGetException ("Resource handle is invalid");
+                }
+            }
         }
 
-        bool RemoteEnrollee::isEnrolleeProvisioned()
+
+        void RemoteEnrollee::startCloudProvisioning(CloudProvStatusCb callback)
         {
-            if(m_currentESState >= CurrentESState::ES_PROVISIONED)
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Enter startCloudProvisioning");
+
+            ESResult result = ES_ERROR;
+
+            if(!callback)
             {
-                return true;
+                throw ESInvalidParameterException("Callback is empty");
             }
-            else
+
+            m_cloudProvStatusCb = callback;
+
+            try
+            {
+                initCloudResource();
+            }
+
+            catch (const std::exception& e)
+            {
+                OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,
+                    "Exception caught in startCloudProvisioning = %s", e.what());
+
+                std::shared_ptr< CloudProvisioningStatus > provStatus = std::make_shared<
+                        CloudProvisioningStatus >(ESResult::ES_ERROR, ESCloudProvState::ES_ENROLLEE_NOT_FOUND);
+                m_cloudProvStatusCb(provStatus);
+            }
+
+            if (m_cloudResource == nullptr)
             {
-                return false;
+                throw ESBadRequestException ("Cloud Resource not created");
             }
+
+            if(m_cloudProvInfo.authCode.empty()
+                || m_cloudProvInfo.authProvider.empty()
+                || m_cloudProvInfo.ciServer.empty())
+            {
+                throw ESBadRequestException ("Invalid Cloud Provisiong Info.");
+            }
+
+            CloudProvStatusCb cloudProvStatusCb = std::bind(
+                    &RemoteEnrollee::cloudProvisioningStatusHandler, this, std::placeholders::_1);
+
+            m_cloudResource->registerCloudProvisioningStatusCallback(cloudProvStatusCb);
+            m_cloudResource->provisionEnrollee(m_cloudProvInfo);
         }
 
-        ProvConfig RemoteEnrollee::getProvConfig ()
+        void RemoteEnrollee::setDataProvInfo(const DataProvInfo& dataProvInfo)
         {
-            return m_ProvConfig;
+            m_dataProvInfo = dataProvInfo;
         }
 
-       WiFiOnboadingConnection RemoteEnrollee::getOnboardConn()
-       {
-         return m_wifiOnboardingconn;
-       }
+        void RemoteEnrollee::setCloudProvInfo(const CloudProvInfo& cloudProvInfo)
+        {
+            m_cloudProvInfo = cloudProvInfo;
+        }
 
+        DataProvInfo RemoteEnrollee::getDataProvInfo()
+        {
+            return m_dataProvInfo;
+        }
     }
 }
index ec960bcb33c5a676385ab3fa0731e0056e362da6..20ea7b7bb50edfd0ce7d28b77e004574150b59b1 100755 (executable)
 
 #include "oic_string.h"
 #include "EasySetup.h"
+#include "ESRichCommon.h"
 #include "OCPlatform.h"
 #include "logger.h"
 #include "OCProvisioningManager.h"
 
-
 #define ES_SAMPLE_APP_TAG "ES_SAMPLE_APP_TAG"
 #define DECLARE_MENU(FUNC, ...) { #FUNC, FUNC }
 
@@ -37,34 +37,26 @@ using namespace OC;
 using namespace OIC::Service;
 
 static EasySetup *easySetupIntance = nullptr;
-static ProvConfig netInfo;
-static WiFiOnboadingConnection onboardingConn;
-static RemoteEnrollee::shared_ptr remoteEnrollee = nullptr;
+static std::shared_ptr<RemoteEnrollee> remoteEnrollee = nullptr;
 
 static std::string ipaddress, ssid, pwd;
 char security;
 
-struct CloseApp
-{
-};
-
 typedef void (*Runner)();
 
 Runner g_currentRun;
 
-int processUserInput(int min, int max)
+int processUserInput(int min = std::numeric_limits<int>::min(),
+        int max = std::numeric_limits<int>::max())
 {
     assert(min <= max);
 
     int input;
 
     std::cin >> input;
+    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
 
-    if (!std::cin.fail())
-    {
-        if(input == max + 1) throw CloseApp();
-        if(min <= input && input <= max) return input;
-    }
+    if (!std::cin.fail() && min <= input && input <= max) return input;
 
     std::cin.clear();
     std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
@@ -72,112 +64,198 @@ int processUserInput(int min, int max)
     throw std::runtime_error("Invalid Input, please try again");
 }
 
-void easySetupStatusCallback (std::shared_ptr< EasySetupStatus > easySetupStatus)
+void printPropertyData(PropertyData propData)
 {
-    OIC_LOG_V(DEBUG, ES_SAMPLE_APP_TAG, "easySetupStatusCallback status is Status = %d",
-            easySetupStatus->getEasySetupState());
+    cout << "===========================================" << endl;
+    DeviceConfig devConfig = propData.getDevInfo();
+    NetworkInfo netInfo = propData.getNetInfo();
+    bool cloudable = propData.isCloudable();
+
+    cout << "\tDeviceConfig.id : " << devConfig.id << endl;
+    cout << "\tDeviceConfig.name : " << devConfig.name << endl;
+    cout << "\tDeviceConfig.language : " << devConfig.language << endl;
+    cout << "\tDeviceConfig.country : " << devConfig.country << endl;
 
+    for(auto type = netInfo.types.begin(); type != netInfo.types.end(); ++type)
+    {
+        cout << "\tnetInfo.types : " << static_cast<int>(*type) << endl;
+    }
+    cout << "\tnetInfo.freq : " << static_cast<int>(netInfo.freq) << endl;
+    cout << "===========================================" << endl;
 }
 
-void startProvisioning()
+void RequestPropertyDataStatusCallback(std::shared_ptr< RequestPropertyDataStatus > requestPropertyDataStatus)
 {
-    try
+    cout << "Enter RequestPropertyDataStatusCb." << endl;
+
+    if(requestPropertyDataStatus->getESResult() != ES_OK)
     {
-        remoteEnrollee->startProvisioning();
+      cout << "requestPropertyDataStatus is failed." << endl;
+      return;
     }
-    catch(OCException &exception)
+    else
     {
-        std::cout << "Exception : " << exception.reason();
+      cout << "requestPropertyDataStatus is success." << endl;
+      printPropertyData(requestPropertyDataStatus->getPropertyData());
     }
 }
 
-void initEasySetup()
+void dataProvisioningStatusCallback(std::shared_ptr< DataProvisioningStatus > provStatus)
 {
+    cout << "Enter dataProvisioningStatusCallback." << endl;
 
+    if(provStatus->getESResult() != ES_OK)
+    {
+      cout << "dataProvisioningStatusCallback is failed." << endl;
+      return;
+    }
+    else
+    {
+      cout << "dataProvisioningStatusCallback is success." << endl;
+      cout << "ESState : " << provStatus->getESState() << endl;
+    }
+}
+
+void cloudProvisioningStatusCallback(std::shared_ptr< CloudProvisioningStatus > status)
+{
+    cout << "Enter cloudProvisioningStatusCallback." << endl;
+    cout << "CloudProvStatus : " <<  status->getESCloudState() << endl;
+}
+
+void createRemoteEnrollee()
+{
     easySetupIntance = EasySetup::getInstance();
+    try
+    {
+        remoteEnrollee = easySetupIntance->createRemoteEnrollee();
+    }
+    catch (OCException &e)
+    {
+        std::cout << "Exception during createEnrolleeDevice call" << e.reason();
+        return;
+    }
+    cout << "createRemoteEnrollee is success." << endl;
+}
+
+void initRemoteEnrollee()
+{
+    try
+    {
+        remoteEnrollee->initRemoteEnrollee();
+    }
+    catch (OCException &e)
+    {
+        std::cout << "Exception during initRemoteEnrollee call" << e.reason();
+        return;
+    }
+}
+
+void requestPropertyData()
+{
+    try
+    {
+        remoteEnrollee->requestPropertyData(RequestPropertyDataStatusCallback);
+    }
+    catch (OCException &e)
+    {
+        std::cout << "Exception during requestPropertyData call" << e.reason();
+        return;
+    }
+}
 
-    cout<<"\n Enter the IP address : ";
-    cin>>ipaddress;
-    cout<<"\n Enter the Target Network SSID : ";
-    cin>>ssid;
-    cout<<"\n Enter the Target Network Password : ";
-    cin>>pwd;
-    cout<<"\n Enable Security: [Y/N] ";
-    cin>>security;
+void setDataProvInfo()
+{
+    DataProvInfo dataProvInfo;
+    dataProvInfo.WIFI.ssid = "Iotivity_2.4G";
+    dataProvInfo.WIFI.pwd = "1234567890";
+    dataProvInfo.WIFI.authtype = WPA2_PSK;
+    dataProvInfo.WIFI.enctype = TKIP_AES;
+    dataProvInfo.Device.language = "korean";
+    dataProvInfo.Device.country = "korea";
+
+    remoteEnrollee->setDataProvInfo(dataProvInfo);
+}
+
+void setCloudProvInfo()
+{
+    CloudProvInfo cloudProvInfo;
+    cloudProvInfo.authCode = "authCode";
+    cloudProvInfo.authProvider = "authProvider";
+    cloudProvInfo.ciServer = "ciServer";
 
-    if ( ipaddress.size() == 0 || ssid.size() == 0  || pwd.size()==0 )
+    remoteEnrollee->setCloudProvInfo(cloudProvInfo);
+}
+
+void startDataProvisioning()
+{
+    try
     {
-         cout<<"\n Invalid information try again !!!";
+        remoteEnrollee->startDataProvisioning(dataProvisioningStatusCallback);
     }
-    else
-     {
-           cout <<"\n Entered details are :  \n";
-           cout<<"\n IP address : "<<ipaddress;
-           cout<<"\n Target Network SSID : "<<ssid;
-           cout<<"\n Target Network Password : "<<pwd;
-
-          if (security == 'Y' || security == 'y' )
-          {
-                  onboardingConn.isSecured = true;
-                  cout<<"\n Security is Enabled\n\n\n";
-           }
-           else
-           {
-                 onboardingConn.isSecured = false;
-                 cout<<"\n Security is not Enabled\n\n\n";
-           }
-
-          netInfo.connType = CT_ADAPTER_IP;
-
-         OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
-         OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
-
-         OICStrcpy(onboardingConn.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
-
-         try
-         {
-             remoteEnrollee = easySetupIntance->createEnrolleeDevice(netInfo,onboardingConn);
-         }
-         catch (OCException &e)
-         {
-             std::cout << "Exception during createEnrolleeDevice call" << e.reason();
-             return;
-         }
-
-         remoteEnrollee->registerEasySetupStatusHandler(&easySetupStatusCallback);
+    catch (OCException &e)
+    {
+        std::cout << "Exception during startDataProvisioning call" << e.reason();
+        return;
     }
+}
 
+void startCloudProvisioning()
+{
+    try
+    {
+        remoteEnrollee->startCloudProvisioning(cloudProvisioningStatusCallback);
+    }
+    catch (OCException &e)
+    {
+        std::cout << "Exception during startDataProvisioning call" << e.reason();
+        return;
+    }
 }
-void runEasySetupMenu()
+
+void DisplayMenu()
 {
-    constexpr int EASY_SETUP_INIT = 1;
-    constexpr int START_PROVISIONING = 2;
-    constexpr int STOP_PROVISIONING = 3;
-    constexpr int STOP_EASY_SETUP = 4;
+    constexpr int CREATE_REMOTE_ENROLLEE = 1;
+    constexpr int EASY_SETUP_INIT = 2;
+    constexpr int REQUEST_PROPERTY_DATA = 3;
+    constexpr int SET_DATA_PROVISIONING_INFO = 4;
+    constexpr int START_DATA_PROVISIONING = 5;
+    constexpr int SET_CLOUD_PROVISIONING_INFO = 6;
+    constexpr int START_CLOUD_PROVISIONING = 7;
 
     std::cout << "========================================================\n";
+    std::cout << CREATE_REMOTE_ENROLLEE << ". Create Remote Enrollee                    \n";
     std::cout << EASY_SETUP_INIT << ". Easy Setup Init                    \n";
-    std::cout << START_PROVISIONING << ". Start Provisioning              \n";
-    std::cout << STOP_PROVISIONING << ". Stop Provisioning                \n";
-    std::cout << STOP_EASY_SETUP << ". Stop Easy Setup                    \n";
-    std::cout << STOP_EASY_SETUP + 1 << ". Quit                           \n";
+    std::cout << REQUEST_PROPERTY_DATA << ". Request PropertyData              \n";
+    std::cout << SET_DATA_PROVISIONING_INFO << ". Set Data Provisioning Info              \n";
+    std::cout << START_DATA_PROVISIONING << ". Start Data Provisioning              \n";
+    std::cout << SET_CLOUD_PROVISIONING_INFO << ". Set Cloud Provisioning Info              \n";
+    std::cout << START_CLOUD_PROVISIONING << ". Start Cloud Provisioning              \n";
     std::cout << "========================================================\n";
 
-    int selection = processUserInput(EASY_SETUP_INIT, STOP_EASY_SETUP);
+    int selection = processUserInput(CREATE_REMOTE_ENROLLEE, START_CLOUD_PROVISIONING);
 
     switch (selection)
     {
+        case CREATE_REMOTE_ENROLLEE:
+            createRemoteEnrollee();
+            break;
         case EASY_SETUP_INIT:
-            initEasySetup();
+            initRemoteEnrollee();
+            break;
+        case REQUEST_PROPERTY_DATA:
+            requestPropertyData();
+            break;
+        case SET_DATA_PROVISIONING_INFO:
+            setDataProvInfo();
             break;
-        case START_PROVISIONING:
-            startProvisioning();
+        case START_DATA_PROVISIONING:
+            startDataProvisioning();
             break;
-        case STOP_PROVISIONING:
-            //stopProvisioning();
+        case SET_CLOUD_PROVISIONING_INFO:
+            setCloudProvInfo();
             break;
-        case STOP_EASY_SETUP:
-            //stopEasySetup();
+        case START_CLOUD_PROVISIONING:
+            startCloudProvisioning();
             break;
         default:
             break;
@@ -211,22 +289,16 @@ int main()
     }
 #endif
 
-    g_currentRun = runEasySetupMenu;
-
     while (true)
     {
         try
         {
-            g_currentRun();
+            DisplayMenu();
         }
         catch (const std::exception& e)
         {
             std::cout << "Exception caught in main " << e.what() << std::endl;
         }
-        catch (const CloseApp&)
-        {
-            break;
-        }
     }
 
     std::cout << "Stopping the client" << std::endl;