[Update] process of provisioning was split.
authorHeewon Park <h_w.park@samsung.com>
Fri, 3 Jun 2016 06:21:23 +0000 (15:21 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 7 Jun 2016 02:19:12 +0000 (02:19 +0000)
Previously, Easy Setup for Mediator provided only 1 API, startProvisioning,
which was responsible for whole processes of easy setup.
We thought this approach had a limitation in case of user interaction required scenarios.
For this reason, we provide multiple APIs rather than a single API and
each of the processes of easy setup is as follows:

1. Discovery
2. SecurityProvisioning
3. Request Enrollee's resources
4. Data Provisioning (WiFi AP, device configuration information)
5. Cloud data provisioning (Auth Code, not implemented yet)

Change-Id: I172b9130531a0bb9e5b0f74aaee40a07523dcbd0
Signed-off-by: Heewon Park <h_w.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8427
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/mediator/richsdk/SConscript
service/easy-setup/mediator/richsdk/inc/ESRichCommon.h
service/easy-setup/mediator/richsdk/inc/EasySetup.h
service/easy-setup/mediator/richsdk/inc/EnrolleeResource.h [moved from service/easy-setup/mediator/richsdk/inc/RemoteEnrolleeResource.h with 76% similarity]
service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h
service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h
service/easy-setup/mediator/richsdk/src/EasySetup.cpp
service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp [moved from service/easy-setup/mediator/richsdk/src/RemoteEnrolleeResource.cpp with 66% similarity]
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp
service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp

index 1624ff1..aaf334a 100644 (file)
@@ -65,17 +65,17 @@ if target_os not in ['windows', 'winrt']:
 if target_os in ['linux']:
    easy_setup_env.AppendUnique(LIBS = ['pthread', 'dl', 'coap'])
 
-if target_os in ['android']:
-       easy_setup_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-       if env.get('SECURED') == '1':
-               easy_setup_env.AppendUnique(LIBPATH = [env.get('SRC_DIR')+'/android/android_api/base/libs/armeabi'])
-       easy_setup_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
-       easy_setup_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
-       easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'gnustl_shared'])
-       if env.get('SECURED') == '1':
-               easy_setup_env.AppendUnique(LIBS = ['ocpmapi','ocprovision'])
-       if not env.get('RELEASE'):
-               easy_setup_env.AppendUnique(LIBS = ['log'])
+#if target_os in ['android']:
+#      easy_setup_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+#      if env.get('SECURED') == '1':
+#              easy_setup_env.AppendUnique(LIBPATH = [env.get('SRC_DIR')+'/android/android_api/base/libs/armeabi'])
+#      easy_setup_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
+#      easy_setup_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+#      easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'gnustl_shared'])
+#      if env.get('SECURED') == '1':
+#              easy_setup_env.AppendUnique(LIBS = ['ocpmapi','ocprovision'])
+#      if not env.get('RELEASE'):
+#              easy_setup_env.AppendUnique(LIBS = ['log'])
 
 if target_os in ['linux']:
        easy_setup_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
@@ -85,7 +85,8 @@ if target_os in ['linux']:
        if env.get('SECURED') == '1':
                easy_setup_env.AppendUnique(LIBS = ['ocpmapi', 'ocprovision'])
 
-if target_os in ['android','linux']:
+#if target_os in ['android','linux']:
+if target_os in ['linux']:
        easy_setup_env.PrependUnique(CPPPATH = [
                env.get('SRC_DIR') + '/resource/c_common/oic_malloc/include',
                env.get('SRC_DIR') + '/resource/include',
@@ -113,12 +114,13 @@ print"easysetup_path %s" % easysetup_path
 
 es_src = None
 
-if target_os in ['android','linux']:
+#if target_os in ['android','linux']:
+if target_os in ['linux']:
        if env.get('SECURED') == '1':
                env.AppendUnique(es_src = [os.path.join(easysetup_path, 'src/EnrolleeSecurity.cpp')])
 
        es_common_src = ['src/RemoteEnrollee.cpp',
-               'src/RemoteEnrolleeResource.cpp',
+               'src/EnrolleeResource.cpp',
                'src/EasySetup.cpp',
                'src/ESException.cpp']
 
@@ -132,12 +134,12 @@ 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]
 ################################################ ######################
-if target_os == 'linux':
-    SConscript('unittests/SConscript')
+#if target_os == 'linux':
+#    SConscript('unittests/SConscript')
 
index e9e344b..fb3ae83 100755 (executable)
@@ -38,6 +38,7 @@ using namespace std;
 #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
@@ -47,19 +48,33 @@ using namespace std;
 /**
  * Attributes used to form a proper easysetup conforming JSON message.
  */
-#define OC_RSRVD_ES_PS                     "ps"
-#define OC_RSRVD_ES_TNN                    "tnn"
-#define OC_RSRVD_ES_CD                     "cd"
-#define OC_RSRVD_ES_TR                     "tr"
-#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_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_URI_PROV               "/oic/prov"
-#define OC_RSRVD_ES_URI_NET                "/oic/net"
+#define OC_RSRVD_ES_PROV_RES_TYPE                 "oic.r.prov"
+#define OC_RSRVD_ES_URI_PROV                           "/.well-known/ocf/prov"
+#define OC_RSRVD_ES_RES_TYPE_WIFI                   "ocf.r.wifi"
+#define OC_RSRVD_ES_URI_WIFI                             "/.well-known/ocf/prov/wifi"
+#define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.r.cloudserver"
+#define OC_RSRVD_ES_URI_CLOUDSERVER            "/.well-known/ocf/prov/cloudserver"
+#define OC_RSRVD_ES_RES_TYPE_DEVCONF          "ocf.r.devconf"
+#define OC_RSRVD_ES_URI_DEVCONF                    "/.well-known/ocf/prov/devconf"
+#define OC_RSRVD_ES_URI_NET                             "/oic/net"
 
 /**
  * @brief Defines for Provisioning status accepted values
@@ -74,26 +89,6 @@ namespace OIC
 {
     namespace Service
     {
-
-        /**
-        * Device Roles defined for each device type used in easy setup
-        */
-        typedef enum
-        {
-            ENROLLEE,
-            MEDIATOR,
-            ENROLLER,
-        } DeviceRole;
-
-        /**
-        * On-boarding connection to create Adhoc network.
-        */
-        typedef enum
-        {
-            SOFTAP,
-            BLE,
-        } OBConnection;
-
         typedef enum
         {
             ES_ERROR = -1,
@@ -106,70 +101,9 @@ namespace OIC
             ES_RECVREQOFNETRES,
             ES_RECVUPDATEOFPROVRES,
             ES_RECVTRIGGEROFPROVRES,
+            ES_UNAUTHORIZED = 31
         } ESResult;
 
-        typedef enum
-        {
-            /**
-             * Default state of the device
-             */
-            ES_INIT_STATE,
-
-            /**
-             * Device will move to this state once the on boarding begins
-             */
-            ES_ON_BOARDING_STATE,
-
-            /**
-             * Device will move to this state after successful on-boarding of the device
-             */
-            ES_ON_BOARDED_STATE,
-
-            /**
-             * Device will move to this state once the on boarding is done
-             */
-            ES_PROVISIONING_STATE,
-
-            /**
-             * Easy setup process is successful.
-             */
-            ES_PROVISIONED_STATE,
-
-            /**
-             * This state is arbitrary one, any time device can come into this state
-             * Device will move to this state if the ownership transfer initiated  by the Application
-             */
-            ES_OWNERSHIP_TRANSFERRING_STATE,
-
-            /**
-             * This state is arbitrary one, any time device can come into this state
-             * Device will move to this state if the ownership transfer is completed
-             */
-            ES_OWNERSHIP_TRANSFERRED_STATE,
-
-            /**
-             * This state is arbitrary one, any time device can come into this state
-             * Device will move to this state once the Application factory reset the device
-             */
-            ES_FACTORY_RESET_STATE,
-
-            /**
-             * Enrollee moves to this state after connecting to target network
-             */
-            ES_ON_BOARDED_TARGET_NETWORK_STATE,
-        }EnrolleeState;
-
-        /**
-         * Provisioning Device Status
-         */
-        typedef struct
-        {
-            // Address of remote server
-            OCDevAddr * addr;
-            // Indicates adaptor type on which the response was received
-            OCConnectivityType connType;
-        } EasySetupDeviceInfo;
-
         /**
          * Provosioning Status
          */
@@ -179,18 +113,31 @@ namespace OIC
             DEVICE_NOT_PROVISIONED,
             DEVICE_OWNED,
             DEVICE_NOT_OWNED
-        } EasySetupState, ProvStatus;
+        } EasySetupState;
 
         /**
-         * Response from queries to remote servers.
+         * @brief  WIFI Authentication type of the Enroller
          */
-        typedef struct
+        typedef enum
         {
-            // EasySetup Status
-            EasySetupState provStatus;
-            // EasySetup Device Info
-            EasySetupDeviceInfo provDeviceInfo;
-        } EasySetupInfo, ProvisioningInfo;
+            NONE_AUTH = 0,
+            WEP,
+            WPA_PSK,
+            WPA2_PSK
+        } WIFI_AUTHTYPE;
+
+        /**
+         * @brief  WIFI ecnrytion type of the Enroller
+         */
+        typedef enum
+        {
+            NONE_ENC = 0,
+            WEP_64,
+            WEP_128,
+            TKIP,
+            AES,
+            TKIP_AES
+        } WIFI_ENCTYPE;
 
         /**
          * @brief  Network information of the Enroller
@@ -220,6 +167,11 @@ namespace OIC
             {
                 char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
                 char pwd[NET_WIFI_PWD_SIZE]; /**< 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;
 
@@ -233,23 +185,6 @@ namespace OIC
         } ProvConfig;
 
         /**
-         * Client applications implement this callback to consume responses received from Servers.
-         */
-        typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
-
-        /**
-         * @brief This structure represent configuration information to create wifi onboarding SoftAP or connection.
-        */
-
-        // Note : Below structure is not currently used but added for future purpose.
-        typedef struct
-        {
-            char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the onboarding Adhoc Wifi network**/
-            char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the onboarding Adhoc wifi network**/
-            bool isSecured;                 /**< Secure connection**/
-        }WiFiOnboardingConfig;
-
-        /**
          * @brief This structure represent onboarding connection instance.
         */
         typedef struct
@@ -287,11 +222,10 @@ namespace OIC
         /**
          * Security Provisioning Status
          */
-        class SecProvisioningResult
+        class SecProvisioningStatus
         {
         public:
-            std::shared_ptr< SecProvisioningResult > shared_ptr;
-            SecProvisioningResult(std::string deviceUUID, ESResult result) :
+            SecProvisioningStatus(std::string deviceUUID, ESResult result) :
                 m_devUUID(deviceUUID), m_result(result)
             {
 
@@ -311,25 +245,56 @@ namespace OIC
             ESResult m_result;
         };
 
-        /**
-         * Callback function definition for providing Enrollee security status .
-         */
-        typedef std::function< void(std::shared_ptr<SecProvisioningResult>) > EnrolleeSecStatusCb;
+        class CapabilityData
+        {
+        public:
+            CapabilityData()
+            {
 
-        /**
-         * Callback definition to be invoked when the security stack expects a pin from application.
-         */
-        typedef std::function< void(std::string&) > SecurityPinCb;
+            }
+        private:
+        };
 
-        /**
-         * Callback definition to be invoked when the stack expects a db path.
-         */
-        typedef std::function< void(std::string&) > SecProvisioningDbPathCb;
+        class InitRemoteEnrolleeStatus
+        {
+        public:
+            InitRemoteEnrolleeStatus(ESResult result) :
+                    m_result(result)
+            {
+
+            }
+
+            ESResult getESResult()
+            {
+                return m_result;
+            }
+        private:
+            ESResult m_result;
+        };
+
+        class RequestCapabilityStatus
+        {
+        public:
+            RequestCapabilityStatus(ESResult result, const CapabilityData& data) :
+                    m_result(result), m_capabilityData(data)
+            {
+            }
+            ESResult getESResult()
+            {
+                return m_result;
+            }
+            CapabilityData getCapabilityData()
+            {
+                return m_capabilityData;
+            }
+        private:
+            ESResult m_result;
+            CapabilityData m_capabilityData;
+        };
 
         class ProvisioningStatus
         {
         public:
-            std::shared_ptr< ProvisioningStatus > shared_ptr;
             ProvisioningStatus(ESResult result, ESState esState) :
                     m_result(result), m_esState(esState)
             {
@@ -353,7 +318,6 @@ namespace OIC
         class EasySetupStatus
         {
         public:
-            std::shared_ptr< EasySetupStatus > shared_ptr;
             EasySetupStatus(const EasySetupState& easySetupState,
                     const ProvConfig& provConfig) :
                     m_easySetupState(easySetupState), m_ProvConfig(provConfig)
@@ -374,6 +338,36 @@ namespace OIC
             EasySetupState m_easySetupState;
             ProvConfig m_ProvConfig;
         };
+
+        /**
+         * Callback function definition for providing Enrollee security status .
+         */
+        typedef std::function< void(std::shared_ptr< InitRemoteEnrolleeStatus >) > InitRemoteEnrolleeStatusCb;
+
+        /**
+         * Callback function definition for providing Enrollee security status .
+         */
+        typedef std::function< void(std::shared_ptr< RequestCapabilityStatus >) > RequestCapabilityStatusCb;
+        /**
+         * Callback function definition for providing Enrollee security status .
+         */
+        typedef std::function< void(std::shared_ptr< ProvisioningStatus >) > DataProvStatusCb;
+
+        /**
+         * Callback function definition for providing Enrollee security status .
+         */
+        typedef std::function< void(std::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;
+
+        /**
+         * Callback definition to be invoked when the stack expects a db path.
+         */
+        typedef std::function< void(std::string&) > SecProvisioningDbPathCb;
+
     }
 }
 #endif //WITH_ARDUINO
index b7914f4..15df9f6 100644 (file)
@@ -50,8 +50,7 @@ namespace OIC
             static EasySetup* getInstance();
 
             /**
-             * This API is used for creating a remote Enrollee device instance.
-             * @param ProvConfig Provisioning information for configuring the Enrollee.
+             * 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
@@ -59,20 +58,12 @@ namespace OIC
              *
              * @return Pointer to RemoteEnrollee instance.
              */
-            std::shared_ptr<RemoteEnrollee> createEnrolleeDevice (
-                         const ProvConfig& enrolleeNWProvInfo,
-                         const WiFiOnboadingConnection& wifiOnboardingconn);
+            std::shared_ptr<RemoteEnrollee> createRemoteEnrollee(const WiFiOnboadingConnection& wifiOnboardingconn);
+
         private:
             EasySetup();
             ~EasySetup();
 
-            RemoteEnrollee::shared_ptr findDeviceInProvisioningList(
-                                const ProvConfig& enrolleeNWProvInfo,
-                                const WiFiOnboadingConnection& wifiOnboardingconn);
-            bool addDeviceToProvisioningList(const RemoteEnrollee::shared_ptr remoteEnrollee);
-            bool deleteDeviceFromProvisioningList (const ProvConfig& enrolleeNWProvInfo);
-
-            std::vector< RemoteEnrollee::shared_ptr > m_activeEnrolleeList;
             static EasySetup *s_instance;
         };
     }
@@ -18,8 +18,8 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#ifndef REMOTE_ENROLLEE_RESOURCE_H_
-#define REMOTE_ENROLLEE_RESOURCE_H_
+#ifndef ENROLLEE_RESOURCE_H_
+#define ENROLLEE_RESOURCE_H_
 
 #include <mutex>
 #include <memory>
@@ -40,28 +40,26 @@ namespace OIC
         /**
          * This class contains the resource discovery methods.
          *
-         * @see RemoteEnrolleeResource
+         * @see EnrolleeResource
          */
-        class RemoteEnrolleeResource
+        class EnrolleeResource
         {
             friend class EnrolleeSecurity;
 
         public:
-            typedef std::shared_ptr< RemoteEnrolleeResource > Ptr;
-
-            typedef std::function< void(std::shared_ptr< ProvisioningStatus >) > ProvStatusCb;
 
             /**
-             * RemoteEnrolleeResource constructor
+             * EnrolleeResource constructor
              *
              * @param enrolleeNWProvInfo Provisioning information for the Enrollee
              *
              * @throw ESBadRequestException is thrown if the parameters are invalid
              */
-            RemoteEnrolleeResource(const ProvConfig &enrolleeNWProvInfo,
-                                               const WiFiOnboadingConnection &onboardingconn);
+            EnrolleeResource(const WiFiOnboadingConnection &onboardingconn);
+            // EnrolleeResource(const ProvConfig &enrolleeNWProvInfo,
+            //                                    const WiFiOnboadingConnection &onboardingconn);
 
-            ~RemoteEnrolleeResource() = default;
+            ~EnrolleeResource() = default;
 
             /**
              * Register provisioning status handler.
@@ -73,11 +71,13 @@ namespace OIC
              *
              * @see ProvisioningStatus
              */
-            void registerProvStatusCallback (ProvStatusCb provStatusCb);
+            void registerInitRemoteEnrolleeStatusCallback (InitRemoteEnrolleeStatusCb callback);
+            void registerCapabilityStatusCallback (RequestCapabilityStatusCb callback);
+            void registerProvStatusCallback (DataProvStatusCb callback);
 
             /**
              * Construct Remote OIC resource using the enrollee host and connectivity information
-             * provided in the constructor of RemoteEnrolleeResource.
+             * provided in the constructor of EnrolleeResource.
              *
              * @throws InvalidParameterException If the provided information is invalid.
              * @throws ESBadRequestException If resource is already constructed.
@@ -86,6 +86,8 @@ namespace OIC
              */
             ESResult constructResourceObject();
 
+            void getCapabilityData();
+
             /**
              * Function for provisioning of Remote Enrollee resource using the information provided.
              *
@@ -105,11 +107,16 @@ namespace OIC
         private:
             std::shared_ptr< OC::OCResource > m_ocResource;
             std::mutex m_mutex;
-            ProvStatusCb m_provStatusCb;
+            InitRemoteEnrolleeStatusCb m_initRemoteEnrolleeStatusCb;
+            RequestCapabilityStatusCb m_requestCapabilityStatusCb;
+            DataProvStatusCb m_dataProvStatusCb;
             ProvConfig m_ProvConfig;
             WiFiOnboadingConnection m_wifiOnboardingconn;
             bool m_discoveryResponse;
 
+            void getCapabilityResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+                    const int eCode);
+
             void getProvStatusResponse(const HeaderOptions& headerOptions, const OCRepresentation& rep,
                     const int eCode);
 
index 5308b0b..7f934b8 100755 (executable)
@@ -32,7 +32,7 @@ namespace OIC
     {
 #define ENROLEE_SECURITY_TAG "ENROLEE_SECURITY"
 
-        class RemoteEnrolleeResource;
+        class EnrolleeResource;
         class OCSecureResource;
 
         /**
@@ -43,14 +43,14 @@ namespace OIC
         class EnrolleeSecurity
         {
         public:
-            EnrolleeSecurity(std::shared_ptr< RemoteEnrolleeResource > remoteEnrolleeResource,
+            EnrolleeSecurity(std::shared_ptr< EnrolleeResource > EnrolleeResource,
             std::string secDbPath);
             ESResult registerCallbackHandler(EnrolleeSecStatusCb enrolleeSecStatusCb,
                     SecurityPinCb securityPinCb, SecProvisioningDbPathCb secProvisioningDbPathCb);
             EasySetupState performOwnershipTransfer();
 
         private:
-            std::shared_ptr< RemoteEnrolleeResource > m_remoteEnrolleeResource;
+            std::shared_ptr< EnrolleeResource > m_EnrolleeResource;
             EnrolleeSecStatusCb m_enrolleeSecStatusCb;
             SecurityPinCb m_securityPinCb;
             SecProvisioningDbPathCb m_secProvisioningDbPathCb;
index 1fb83b3..f479de1 100644 (file)
@@ -27,7 +27,7 @@ namespace OIC
 {
     namespace Service
     {
-        class RemoteEnrolleeResource;
+        class EnrolleeResource;
         class EnrolleeSecurity;
 
         /**
@@ -45,23 +45,10 @@ namespace OIC
              *
              * @throw ESBadRequestException is thrown if the parameters are invalid
              */
-            RemoteEnrollee(const ProvConfig& enrolleeNWProvInfo, const WiFiOnboadingConnection& connection) ;
+            RemoteEnrollee(const WiFiOnboadingConnection& wifiOnboardingconn);
 
             ~RemoteEnrollee() = default;
 
-            typedef std::shared_ptr< RemoteEnrollee > shared_ptr;
-
-            /**
-             * Callback definition to be invoked when EasySetup status is changed.
-             * The same callback will be invoked when there is an error in the
-             * EasySetup process.
-             *
-             * @see registerResourceHandler
-             * @see ResourceState
-             */
-            typedef std::function< void(std::shared_ptr< EasySetupStatus >) >
-                                                                        EasySetupStatusCB;
-
 #ifdef __WITH_DTLS__
             /**
              * Register Security status and other information callback handlers.
@@ -80,18 +67,31 @@ namespace OIC
 #endif //__WITH_DTLS__
 
             /**
-             * Register EasySetup status handler.
+             * Start provisioning of target Enrollers information to the Enrollee.
              *
-             * @param callback Callback to get EasySetup status.
-             * @param secProvisioningDbCB Callback to be invoked when the stack expects a
-             *        path for the provisioning db.
+             * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
              *
-             * @throws InvalidParameterException If callback is an empty function or null.
-             * @throws ESBadRequestException If registration is already completed.
+             * @see RemoteEnrollee
+             */
+             void initRemoteEnrollee(InitRemoteEnrolleeStatusCb callback);
+
+             /**
+             * 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);
+
+            /**
+             * Start provisioning of target Enrollers information to the Enrollee.
              *
-             * @see EasySetupStatus
+             * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
+             *
+             * @see RemoteEnrollee
              */
-            void registerEasySetupStatusHandler(EasySetupStatusCB callback);
+            void getCapabilityData(RequestCapabilityStatusCb callback);
 
             /**
              * Start provisioning of target Enrollers information to the Enrollee.
@@ -100,7 +100,7 @@ namespace OIC
              *
              * @see RemoteEnrollee
              */
-            void startProvisioning();
+            void startDataProvisioning(const ProvConfig& dataProvConfig, DataProvStatusCb callback);
 
             /**
              * Stop provisioning process that is currently in progress.
@@ -130,11 +130,13 @@ namespace OIC
             WiFiOnboadingConnection getOnboardConn();
 
         private:
-            std::shared_ptr< RemoteEnrolleeResource > m_remoteResource;
-            EasySetupStatusCB m_easySetupStatusCb;
+            std::shared_ptr< EnrolleeResource > m_remoteResource;
             EnrolleeSecStatusCb m_enrolleeSecStatusCb;
+            InitRemoteEnrolleeStatusCb m_initRemoteEnrolleeStatusCb;
+            RequestCapabilityStatusCb m_requestCapabilityStatusCb;
             SecurityPinCb m_securityPinCb;
             SecProvisioningDbPathCb m_secProvisioningDbPathCb;
+            DataProvStatusCb m_dataProvStatusCb;
             ProvConfig m_ProvConfig;
             WiFiOnboadingConnection m_wifiOnboardingconn;
 
@@ -142,9 +144,11 @@ namespace OIC
             CurrentESState m_currentESState;
             bool m_isSecured;
 
-            void provisioningStatusHandler (std::shared_ptr< ProvisioningStatus > provStatus);
+            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< SecProvisioningResult > secProvisioningResult);
+            std::shared_ptr< SecProvisioningStatus > secProvisioningResult);
         };
     }
 }
index 3a6929e..3d6cb28 100644 (file)
@@ -46,82 +46,10 @@ namespace OIC
             return s_instance;
         }
 
-        RemoteEnrollee::shared_ptr EasySetup::findDeviceInProvisioningList (
-                            const ProvConfig& provConfig, const WiFiOnboadingConnection& onboardingconn)
+        std::shared_ptr<RemoteEnrollee> EasySetup::createRemoteEnrollee (const WiFiOnboadingConnection& wifiOnboardingconn)
         {
-            OIC_LOG(DEBUG,EASYSETUP_TAG,"Entered findDeviceInProvisioningList ()");
-
-            std::vector< std::shared_ptr< RemoteEnrollee > >::iterator it;
-
-            std::shared_ptr< RemoteEnrollee > remoteEnrollee = nullptr;
-            for(auto it : m_activeEnrolleeList)
-            {
-                OIC_LOG_V(DEBUG,EASYSETUP_TAG,"entered the iterator");
-
-                ProvConfig activeEnrolleConfig =  it->getProvConfig();
-                WiFiOnboadingConnection activeEnrolleConn = it->getOnboardConn();
-                if ((0 == memcmp(&activeEnrolleConfig.provData,
-                                &provConfig.provData, sizeof(ProvConfig))) &&
-                    (0 == memcmp(&activeEnrolleConn.ipAddress,
-                          &onboardingconn.ipAddress, sizeof(onboardingconn.ipAddress))))
-                {
-                    remoteEnrollee = it;
-                    return remoteEnrollee;
-                }
-            }
-
-            OIC_LOG_V(DEBUG,EASYSETUP_TAG,"Return nullptr for  findDeviceInProvisioningList call");
-            return remoteEnrollee;
-        }
-
-        bool EasySetup::addDeviceToProvisioningList(const RemoteEnrollee::shared_ptr remoteEnrollee)
-        {
-            ProvConfig remoteEnrolleConfig =  remoteEnrollee->getProvConfig();
-            WiFiOnboadingConnection remoteEnrolleConn = remoteEnrollee->getOnboardConn();
-
-            for (auto it : m_activeEnrolleeList)
-            {
-                ProvConfig activeEnrolleConfig =  it->getProvConfig();
-                WiFiOnboadingConnection activeEnrolleConn = it->getOnboardConn();
-                if ( (0 == memcmp(&activeEnrolleConfig.provData,
-                                &remoteEnrolleConfig.provData,
-                                sizeof(ProvConfig)))  &&
-                     (0 == memcmp(&activeEnrolleConn.ipAddress,
-                                &remoteEnrolleConn.ipAddress,
-                                sizeof(remoteEnrolleConn.ipAddress)))
-                   )
-                {
-                    return false;
-                }
-            }
-
-            OIC_LOG_V(DEBUG,EASYSETUP_TAG,"Adding new device RemoteEnrollee list");
-            m_activeEnrolleeList.push_back(remoteEnrollee);
-            return true;
+            return std::make_shared< RemoteEnrollee > (wifiOnboardingconn);
         }
-
-        std::shared_ptr<RemoteEnrollee> EasySetup::createEnrolleeDevice (
-                                        const ProvConfig& provConfig, const WiFiOnboadingConnection& wifiOnboardingconn)
-        {
-            if (findDeviceInProvisioningList(provConfig,wifiOnboardingconn) != nullptr)
-            {
-                throw ESBadRequestException { "Device already created exception" };
-            }
-
-            RemoteEnrollee::shared_ptr remoteEnrollee;
-
-            remoteEnrollee = std::make_shared< RemoteEnrollee > (provConfig, wifiOnboardingconn);
-
-
-            if (!addDeviceToProvisioningList (remoteEnrollee))
-            {
-                return nullptr;
-            }
-
-            return remoteEnrollee;
-        }
-
-
     }
 }
 
@@ -21,7 +21,7 @@
 #include <functional>
 #include <time.h>
 
-#include "RemoteEnrolleeResource.h"
+#include "EnrolleeResource.h"
 
 #include "OCPlatform.h"
 #include "ESException.h"
@@ -39,15 +39,21 @@ namespace OIC
         static const char ES_PROV_RES_URI[] = "/oic/prov";
         static const char ES_PROV_RES_TYPE[] = "oic.r.prov";
 
-        RemoteEnrolleeResource::RemoteEnrolleeResource(const ProvConfig &provConfig,
+        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 RemoteEnrolleeResource::triggerNetworkConnectionCb(
+*/
+        void EnrolleeResource::triggerNetworkConnectionCb(
                 const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep,
                 const int eCode)
         {
@@ -61,7 +67,7 @@ namespace OIC
                         "triggerNetworkConnectionCb : Trigger action failed ");
                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
                         ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
-                m_provStatusCb(provStatus);
+                m_dataProvStatusCb(provStatus);
                 return;
             }
             else
@@ -70,12 +76,12 @@ namespace OIC
                         "triggerNetworkConnectionCb : Provisioning is success ");
                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
                         ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONING_SUCCESS);
-                m_provStatusCb(provStatus);
+                m_dataProvStatusCb(provStatus);
                 return;
             }
         }
 
-        void RemoteEnrolleeResource::triggerNetworkConnection()
+        void EnrolleeResource::triggerNetworkConnection()
         {
             if (m_ocResource == nullptr)
             {
@@ -84,18 +90,18 @@ namespace OIC
 
             OCRepresentation provisioningRepresentation;
 
-            provisioningRepresentation.setValue(OC_RSRVD_ES_TR, 1);
+            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(&RemoteEnrolleeResource::triggerNetworkConnectionCb, this,
+                            std::bind(&EnrolleeResource::triggerNetworkConnectionCb, this,
                                     std::placeholders::_1, std::placeholders::_2,
                                     std::placeholders::_3)));
         }
 
-        void RemoteEnrolleeResource::checkProvInformationCb(const HeaderOptions& /*headerOptions*/,
+        void EnrolleeResource::checkProvInformationCb(const HeaderOptions& /*headerOptions*/,
                 const OCRepresentation& rep, const int eCode)
         {
             OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : %s, eCode = %d",
@@ -108,13 +114,13 @@ namespace OIC
                         "checkProvInformationCb : Provisioning is failed ");
                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
                         ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
-                m_provStatusCb(provStatus);
+                m_dataProvStatusCb(provStatus);
                 return;
             }
 
             int ps = -1;
 
-            rep.getValue(OC_RSRVD_ES_PS, ps);
+            rep.getValue(OC_RSRVD_ES_PROVSTATUS, ps);
 
             OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : ps - %d", ps);
 
@@ -128,7 +134,7 @@ namespace OIC
                 #ifdef REMOTE_ARDUINO_ENROLEE
                  std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
                         ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONING_SUCCESS);
-                m_provStatusCb(provStatus);
+                m_dataProvStatusCb(provStatus);
                 #endif
 
                 triggerNetworkConnection();
@@ -140,12 +146,45 @@ namespace OIC
                         "checkProvInformationCb : Provisioning is failed ");
                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
                         ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
-                m_provStatusCb(provStatus);
+                m_dataProvStatusCb(provStatus);
+                return;
+            }
+        }
+
+        void EnrolleeResource::getCapabilityResponse(const HeaderOptions& /*headerOptions*/,
+                const OCRepresentation& rep, const int eCode)
+        {
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getCapabilityResponse : %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 ");
+
+                if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ)
+                {
+                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "Mediator is unauthorized from Enrollee.");
+                    result = ESResult::ES_UNAUTHORIZED;
+                }
+
+                CapabilityData capabilityData;
+                std::shared_ptr< RequestCapabilityStatus > requestCapabilityStatus = std::make_shared<
+                        RequestCapabilityStatus >(result, capabilityData);
+                m_requestCapabilityStatusCb(requestCapabilityStatus);
+
                 return;
             }
+
+            CapabilityData capabilityData = CapabilityData();
+            std::shared_ptr< RequestCapabilityStatus > requestCapabilityStatus = std::make_shared<
+                    RequestCapabilityStatus >(ESResult::ES_OK, capabilityData);
+            m_requestCapabilityStatusCb(requestCapabilityStatus);
         }
 
-        void RemoteEnrolleeResource::getProvStatusResponse(const HeaderOptions& /*headerOptions*/,
+        void EnrolleeResource::getProvStatusResponse(const HeaderOptions& /*headerOptions*/,
                 const OCRepresentation& rep, const int eCode)
         {
             OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : %s, eCode = %d",
@@ -154,17 +193,26 @@ namespace OIC
 
             if (eCode != 0)
             {
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "getProvStatusResponse : Provisioning is failed ");
+                ESResult result  = ESResult::ES_ERROR;
+
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,"getProvStatusResponse : Provisioning is failed ");
+
+                if (eCode == OCStackResult::OC_STACK_UNAUTHORIZED_REQ)
+                {
+                    OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "Mediator is unauthorized from Enrollee.");
+                    result = ESResult::ES_UNAUTHORIZED;
+                }
                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
-                m_provStatusCb(provStatus);
+                        ProvisioningStatus >(result, ESState::ES_PROVISIONING_ERROR);
+                m_dataProvStatusCb(provStatus);
+
                 return;
             }
 
             int ps = -1;
 
-            rep.getValue(OC_RSRVD_ES_PS, ps);
+            rep.getValue(OC_RSRVD_ES_PROVSTATUS, ps);
 
             OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ps - %d",
                     ps);
@@ -173,21 +221,41 @@ namespace OIC
             {
                 OCRepresentation provisioningRepresentation;
 
-                provisioningRepresentation.setValue(OC_RSRVD_ES_TNN,
+                provisioningRepresentation.setValue(OC_RSRVD_ES_SSID,
                 std::string(m_ProvConfig.provData.WIFI.ssid));
-                provisioningRepresentation.setValue(OC_RSRVD_ES_CD,
+                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);
 
                 OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ssid - %s",
                         m_ProvConfig.provData.WIFI.ssid);
                 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);
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : authtype - %d",
+                        m_ProvConfig.provData.WIFI.authtype);
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : enctype - %d",
+                        m_ProvConfig.provData.WIFI.enctype);
 
                 m_ocResource->post(provisioningRepresentation, QueryParamsMap(),
                         std::function<
                                 void(const HeaderOptions& headerOptions,
                                         const OCRepresentation& rep, const int eCode) >(
-                        std::bind(&RemoteEnrolleeResource::checkProvInformationCb, this,
+                        std::bind(&EnrolleeResource::checkProvInformationCb, this,
                         std::placeholders::_1, std::placeholders::_2,
                         std::placeholders::_3)));
             }
@@ -197,16 +265,26 @@ namespace OIC
                         "getProvStatusResponse : Provisioning is successful");
                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
                         ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONED_ALREADY);
-                m_provStatusCb(provStatus);
+                m_dataProvStatusCb(provStatus);
             }
         }
 
-        void RemoteEnrolleeResource::registerProvStatusCallback(ProvStatusCb provStatusCb)
+        void EnrolleeResource::registerInitRemoteEnrolleeStatusCallback (InitRemoteEnrolleeStatusCb callback)
+        {
+            m_initRemoteEnrolleeStatusCb = callback;
+        }
+
+        void EnrolleeResource::registerCapabilityStatusCallback(RequestCapabilityStatusCb callback)
+        {
+            m_requestCapabilityStatusCb = callback;
+        }
+
+        void EnrolleeResource::registerProvStatusCallback(DataProvStatusCb callback)
         {
-            m_provStatusCb = provStatusCb;
+            m_dataProvStatusCb = callback;
         }
 
-        ESResult RemoteEnrolleeResource::ESDiscoveryTimeout(unsigned short waittime)
+        ESResult EnrolleeResource::ESDiscoveryTimeout(unsigned short waittime)
         {
             struct timespec startTime;
             startTime.tv_sec=0;
@@ -237,6 +315,9 @@ namespace OIC
 
                 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);
@@ -252,12 +333,13 @@ namespace OIC
              return res;
         }
 
-        void RemoteEnrolleeResource::onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource)
+        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)
@@ -272,6 +354,9 @@ namespace OIC
                     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
@@ -280,10 +365,18 @@ namespace OIC
                      */
                     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);
                 }
 
             }
@@ -295,7 +388,7 @@ namespace OIC
         }
 
 
-        ESResult RemoteEnrolleeResource::constructResourceObject()
+        ESResult EnrolleeResource::constructResourceObject()
         {
             if (m_ocResource != nullptr)
             {
@@ -379,30 +472,20 @@ namespace OIC
                 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);
-            }
-
             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, "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(&RemoteEnrolleeResource::onDeviceDiscovered, this,
+                    std::bind(&EnrolleeResource::onDeviceDiscovered, this,
                                                     std::placeholders::_1);
             OCStackResult result = OC::OCPlatform::findResource("", query, CT_DEFAULT,
                     onDeviceDiscoveredCb);
@@ -428,7 +511,38 @@ namespace OIC
 #endif
         }
 
-        void RemoteEnrolleeResource::provisionEnrollee()
+        void EnrolleeResource::getCapabilityData()
+        {
+            if (m_ocResource == nullptr)
+            {
+                throw ESBadRequestException("Resource is not initialized");
+            }
+
+            OC::QueryParamsMap query;
+            OC::OCRepresentation rep;
+
+            std::function< OCStackResult(void) > getCapabilityStatus = [&]
+            {   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::placeholders::_1, std::placeholders::_2,
+                                        std::placeholders::_3)));
+            };
+
+            OCStackResult result = getCapabilityStatus();
+
+            if (result != OCStackResult::OC_STACK_OK)
+            {
+                CapabilityData capabilityData;
+                std::shared_ptr< RequestCapabilityStatus > requestCapabilityStatus = std::make_shared<
+                        RequestCapabilityStatus >(ESResult::ES_ERROR, capabilityData);
+                m_requestCapabilityStatusCb(requestCapabilityStatus);
+                return;
+            }
+        }
+
+        void EnrolleeResource::provisionEnrollee()
 
         {
             if (m_ocResource == nullptr)
@@ -445,7 +559,7 @@ namespace OIC
                         std::function<
                         void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
                                 const int eCode) >(
-                                std::bind(&RemoteEnrolleeResource::getProvStatusResponse, this,
+                                std::bind(&EnrolleeResource::getProvStatusResponse, this,
                                         std::placeholders::_1, std::placeholders::_2,
                                         std::placeholders::_3)));
             };
@@ -456,12 +570,12 @@ namespace OIC
             {
                 std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
                         ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
-                m_provStatusCb(provStatus);
+                m_dataProvStatusCb(provStatus);
                 return;
             }
         }
 
-        void RemoteEnrolleeResource::unprovisionEnrollee()
+        void EnrolleeResource::unprovisionEnrollee()
         {
             if (m_ocResource == nullptr)
             {
@@ -470,14 +584,14 @@ namespace OIC
 
             OCRepresentation provisioningRepresentation;
 
-            provisioningRepresentation.setValue(OC_RSRVD_ES_TNN, "");
-            provisioningRepresentation.setValue(OC_RSRVD_ES_CD, "");
+            provisioningRepresentation.setValue(OC_RSRVD_ES_SSID, "");
+            provisioningRepresentation.setValue(OC_RSRVD_ES_CRED, "");
 
             m_ocResource->post(provisioningRepresentation, QueryParamsMap(),
                     std::function<
                             void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
                                     const int eCode) >(
-                    std::bind(&RemoteEnrolleeResource::checkProvInformationCb, this,
+                    std::bind(&EnrolleeResource::checkProvInformationCb, this,
                     std::placeholders::_1, std::placeholders::_2,
                     std::placeholders::_3)));
         }
index 0f35ce6..211958d 100755 (executable)
@@ -23,7 +23,7 @@
 #include "EnrolleeSecurity.h"
 #include "oxmjustworks.h"
 #include "oxmrandompin.h"
-#include "RemoteEnrolleeResource.h"
+#include "EnrolleeResource.h"
 #include "logger.h"
 #include "ESException.h"
 #include "oic_malloc.h"
@@ -47,11 +47,11 @@ namespace OIC
 #define ES_SEC_DISCOVERY_TIMEOUT 5
 
         EnrolleeSecurity::EnrolleeSecurity(
-        std::shared_ptr< RemoteEnrolleeResource > remoteEnrolleeResource,
+        std::shared_ptr< EnrolleeResource > EnrolleeResource,
         std::string secDbPath)
         {
             m_enrolleeSecState = EnrolleeSecState::ES_SEC_UNKNOWN;
-            m_remoteEnrolleeResource = remoteEnrolleeResource;
+            m_EnrolleeResource = EnrolleeResource;
         }
 
         ESResult EnrolleeSecurity::registerCallbackHandler(EnrolleeSecStatusCb enrolleeSecStatusCb,
@@ -108,10 +108,10 @@ namespace OIC
             {
                 OIC_LOG(ERROR, ENROLEE_SECURITY_TAG,"Error!!! in OwnershipTransfer");
 
-                std::shared_ptr< SecProvisioningResult > securityProvisioningStatus = nullptr;
+                std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus = nullptr;
                 std::string uuid;
                 convertUUIDToString(result->at(0).deviceId, uuid);
-                securityProvisioningStatus = std::make_shared< SecProvisioningResult >(uuid,
+                securityProvisioningStatus = std::make_shared< SecProvisioningStatus >(uuid,
                         ES_ERROR);
 
                 m_enrolleeSecStatusCb(securityProvisioningStatus);
@@ -127,8 +127,8 @@ namespace OIC
                     convertUUIDToString(result->at(0).deviceId, uuid);
 
                     OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "UUID : %s",uuid.c_str());
-                    std::shared_ptr< SecProvisioningResult > securityProvisioningStatus = nullptr;
-                    securityProvisioningStatus = std::make_shared< SecProvisioningResult >(uuid,
+                    std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus = nullptr;
+                    securityProvisioningStatus = std::make_shared< SecProvisioningStatus >(uuid,
                             ES_OK);
 
                     m_enrolleeSecStatusCb(securityProvisioningStatus);
@@ -216,7 +216,7 @@ namespace OIC
                         ownershipStatus = DEVICE_NOT_OWNED;
                         return ownershipStatus;
                     }
-                    ownershipStatus = DEVICE_NOT_OWNED;
+                    ownershipStatus = DEVICE_OWNED;
                 }
             }
             else
index cb6cb7a..427556e 100755 (executable)
@@ -19,7 +19,7 @@
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
 #include "RemoteEnrollee.h"
-#include "RemoteEnrolleeResource.h"
+#include "EnrolleeResource.h"
 #include "ESException.h"
 #include "logger.h"
 #ifdef __WITH_DTLS__
@@ -32,11 +32,14 @@ namespace OIC
 
     namespace Service
     {
-        RemoteEnrollee::RemoteEnrollee(const ProvConfig& provConfig, const WiFiOnboadingConnection& connection) :
-                m_ProvConfig(provConfig), m_wifiOnboardingconn(connection)
+        RemoteEnrollee::RemoteEnrollee(const WiFiOnboadingConnection& wifiOnboardingconn) :
+                m_wifiOnboardingconn(wifiOnboardingconn)
         {
-            m_currentESState = CurrentESState::ES_UNKNOWN;
-            m_isSecured = connection.isSecured; //enrolleeNWProvInfo.needSecuredEasysetup;
+            m_requestCapabilityStatusCb = nullptr;
+            m_currentESState = CurrentESState::ES_ONBOARDED;
+            m_isSecured = m_wifiOnboardingconn.isSecured;
+
+            m_remoteResource = std::make_shared< EnrolleeResource >(m_wifiOnboardingconn);
 
             OIC_LOG ( DEBUG, ES_REMOTE_ENROLLEE_TAG, "Inside RemoteEnrollee constr");
         }
@@ -56,34 +59,14 @@ namespace OIC
         }
 #endif //__WITH_DTLS__
 
-        void RemoteEnrollee::registerEasySetupStatusHandler(EasySetupStatusCB callback)
-        {
-            OIC_LOG ( DEBUG, ES_REMOTE_ENROLLEE_TAG, "Entered registerStatusHandler");
-            if(!callback)
-            {
-                throw ESInvalidParameterException("Callback is empty");
-            }
-
-            if (m_easySetupStatusCb)
-            {
-                throw ESBadRequestException("Callback handler already registered");
-            }
-            else
-            {
-                m_easySetupStatusCb = callback;
-
-                m_remoteResource = std::make_shared< RemoteEnrolleeResource >(m_ProvConfig, m_wifiOnboardingconn);
-            }
-        }
-
         void RemoteEnrollee::easySetupSecurityStatusCallback(
-                        std::shared_ptr< SecProvisioningResult > secProvisioningResult)
+                        std::shared_ptr< SecProvisioningStatus > secProvisioningStatus)
         {
             OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "easySetupStatusCallback status is, UUID = %s, "
-                    "Status = %d", secProvisioningResult->getDeviceUUID().c_str(),
-                    secProvisioningResult->getResult());
+                    "Status = %d", secProvisioningStatus->getDeviceUUID().c_str(),
+                    secProvisioningStatus->getResult());
 
-            if(secProvisioningResult->getResult() == ES_OK)
+            if(secProvisioningStatus->getResult() == ES_OK)
             {
                 OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Ownership and ACL are successful. "
                         "Continue with Network information provisioning");
@@ -92,117 +75,75 @@ namespace OIC
 
                 OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Before ProvisionEnrollee");
 
-                RemoteEnrolleeResource::ProvStatusCb provStatusCb = std::bind(
-                        &RemoteEnrollee::provisioningStatusHandler, this, std::placeholders::_1);
-
-                m_remoteResource->registerProvStatusCallback(provStatusCb);
-                m_remoteResource->provisionEnrollee();
+                m_enrolleeSecStatusCb(secProvisioningStatus);
             }
             else
             {
-                OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Ownership and ACL are successful");
-                std::shared_ptr< EasySetupStatus > easySetupStatus = nullptr;
-                easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,
-                                            m_ProvConfig);
-                if (m_easySetupStatusCb)
-                {
-                    if (easySetupStatus)
-                    {
-                        m_easySetupStatusCb(easySetupStatus);
-                    }
-                    else
-                    {
-                        m_easySetupStatusCb(nullptr);
-                    }
-                }
+                OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Ownership and ACL are fail");
+
+                m_enrolleeSecStatusCb(secProvisioningStatus);
             }
         }
 
-        void RemoteEnrollee::provisioningStatusHandler(
-                std::shared_ptr< ProvisioningStatus > provStatus)
+        void RemoteEnrollee::InitRemoteEnrolleeStatusHandler (
+                std::shared_ptr< InitRemoteEnrolleeStatus > initRemoteEnrolleeStatus)
         {
-            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering ProvisioningStatusHandler");
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering InitRemoteEnrolleeStatusHandler");
 
-            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", provStatus->getESResult());
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"initRemoteEnrolleeStatus = %d", initRemoteEnrolleeStatus->getESResult());
 
-            std::shared_ptr< EasySetupStatus > easySetupStatus = nullptr;
+            m_initRemoteEnrolleeStatusCb(initRemoteEnrolleeStatus);
+        }
 
-            if (m_isSecured)
-            {
-                if (m_currentESState >= CurrentESState::ES_OWNED)
-                {
-                    goto CALLBACK_CHECK;
-                }
-                else
-                {
-                    goto FAILURE;
-                }
-            }
-            else
-            {
-                goto CALLBACK_CHECK;
-            }
+        void RemoteEnrollee::requestCapabilityStatusHandler (
+                std::shared_ptr< RequestCapabilityStatus > requestCapabilityStatus)
+        {
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering requestCapabilityStatusHandler");
+
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"requestCapabilityStatus = %d", requestCapabilityStatus->getESResult());
 
-            CALLBACK_CHECK:
+            m_requestCapabilityStatusCb(requestCapabilityStatus);
+        }
+
+        void RemoteEnrollee::dataProvisioningStatusHandler(
+                std::shared_ptr< ProvisioningStatus > provStatus)
+        {
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering dataprovisioningStatusHandler");
+
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", provStatus->getESResult());
 
             if (provStatus->getESResult() == ES_OK)
             {
                 if (provStatus->getESState() >= ESState::ES_PROVISIONED_ALREADY)
                 {
-                    easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_PROVISIONED,
-                            m_ProvConfig);
-                }
-                else
-                {
-                    easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,
-                            m_ProvConfig);
-                }
-            }
-            else
-            {
-                easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,
-                        m_ProvConfig);
-            }
-
-            if (m_easySetupStatusCb)
-            {
-                if (easySetupStatus)
-                {
-                    m_easySetupStatusCb(easySetupStatus);
-                }
-                else
-                {
-                    m_easySetupStatusCb(nullptr);
+                    OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", provStatus->getESResult());
+                    m_currentESState = CurrentESState::ES_PROVISIONED;
                 }
             }
+            m_dataProvStatusCb(provStatus);
 
             return;
+        }
 
-            FAILURE:
-
-            easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,
-                                    m_ProvConfig);
+        void RemoteEnrollee::initRemoteEnrollee(InitRemoteEnrolleeStatusCb callback)
+        {
+            ESResult result = ES_ERROR;
 
-            if (easySetupStatus)
-            {
-                m_easySetupStatusCb(easySetupStatus);
-            }
-            else
+            if(!callback)
             {
-                m_easySetupStatusCb(nullptr);
+                throw ESInvalidParameterException("Callback is empty");
             }
-            return;
-        }
 
-        void RemoteEnrollee::startProvisioning()
-        {
-            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering startProvisioning");
-            if (m_remoteResource == nullptr)
+            m_initRemoteEnrolleeStatusCb = callback;
+
+            if (m_remoteResource != nullptr)
             {
-                throw ESBadRequestException ("Device not created");
+                throw ESBadRequestException ("Already created");
             }
 
-            ESResult result = ES_ERROR;
+            InitRemoteEnrolleeStatusCb initRemoteEnrolleeStatusCb = std::bind(
+                    &RemoteEnrollee::InitRemoteEnrolleeStatusHandler, this, std::placeholders::_1);
+            m_remoteResource->registerInitRemoteEnrolleeStatusCallback(initRemoteEnrolleeStatusCb);
 
             result = m_remoteResource->constructResourceObject();
 
@@ -212,10 +153,14 @@ namespace OIC
                                     "Failed to create device using constructResourceObject");
                 throw ESBadRequestException ("Device not created");
             }
+        }
 
-            m_currentESState = CurrentESState::ES_ONBOARDED;
-
+        void RemoteEnrollee::startSecurityProvisioning(EnrolleeSecStatusCb callback)
+        {
 #ifdef __WITH_DTLS__
+
+            m_enrolleeSecStatusCb = callback;
+
             if (m_isSecured && m_currentESState < CurrentESState::ES_OWNED)
             {
                 EnrolleeSecStatusCb securityProvStatusCb = std::bind(
@@ -244,13 +189,6 @@ namespace OIC
                                 "performOwnershipTransfer returned : %d",
                                 easySetupState);
                         OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Before ProvisionEnrollee");
-
-                        RemoteEnrolleeResource::ProvStatusCb provStatusCb = std::bind(
-                                &RemoteEnrollee::provisioningStatusHandler,
-                                this, std::placeholders::_1);
-
-                        m_remoteResource->registerProvStatusCallback(provStatusCb);
-                        m_remoteResource->provisionEnrollee();
                     }
                 }
                 catch (OCException & e)
@@ -260,15 +198,43 @@ namespace OIC
                     return ;
                 }
             }
-#else
+#endif
+        }
+
+        void RemoteEnrollee::getCapabilityData(RequestCapabilityStatusCb callback)
+        {
+            ESResult result = ES_ERROR;
+
+            if(!callback)
+            {
+                throw ESInvalidParameterException("Callback is empty");
+            }
+
+            m_requestCapabilityStatusCb = callback;
+
+            if (m_remoteResource == nullptr)
+            {
+                throw ESBadRequestException ("Device not created");
+            }
+
+            RequestCapabilityStatusCb requestCapabilityStatusCb = std::bind(
+                    &RemoteEnrollee::requestCapabilityStatusHandler, this, std::placeholders::_1);
+            m_remoteResource->registerCapabilityStatusCallback(requestCapabilityStatusCb);
+            m_remoteResource->getCapabilityData();
+        }
+
+        void RemoteEnrollee::startDataProvisioning(const ProvConfig& dataProvConfig, DataProvStatusCb callback)
+        {
             OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Before ProvisionEnrollee");
 
-            RemoteEnrolleeResource::ProvStatusCb provStatusCb = std::bind(
-                    &RemoteEnrollee::provisioningStatusHandler, this, std::placeholders::_1);
+            m_ProvConfig = dataProvConfig;
+            m_dataProvStatusCb = callback;
+
+            DataProvStatusCb dataProvStatusCb = std::bind(
+                    &RemoteEnrollee::dataProvisioningStatusHandler, this, std::placeholders::_1);
 
-            m_remoteResource->registerProvStatusCallback(provStatusCb);
+            m_remoteResource->registerProvStatusCallback(dataProvStatusCb);
             m_remoteResource->provisionEnrollee();
-#endif
         }
 
         void RemoteEnrollee::stopProvisioning()