Merge branch 'master' into extended-easysetup
authoruzchoi <uzchoi@samsung.com>
Mon, 11 Jul 2016 02:54:47 +0000 (11:54 +0900)
committeruzchoi <uzchoi@samsung.com>
Mon, 11 Jul 2016 02:56:51 +0000 (11:56 +0900)
Change-Id: Ifad200718955d1f1382178e72c36866b538af622

65 files changed:
service/easy-setup/enrollee/SConscript
service/easy-setup/enrollee/arduino/easysetup.cpp [deleted file]
service/easy-setup/enrollee/arduino/onboarding.cpp [deleted file]
service/easy-setup/enrollee/arduino/resourcehandler.cpp [deleted file]
service/easy-setup/enrollee/arduino/softap.cpp [deleted file]
service/easy-setup/enrollee/arduino/wifi/networkhandler.cpp [deleted file]
service/easy-setup/enrollee/arduino/wifi/networkhandler.h [deleted file]
service/easy-setup/enrollee/inc/easysetup.h
service/easy-setup/enrollee/linux/wifi/networkhandler.c [deleted file]
service/easy-setup/enrollee/linux/wifi/networkhandler.h [deleted file]
service/easy-setup/enrollee/linux/wifi/softapnative.c [deleted file]
service/easy-setup/enrollee/linux/wifi/softapnative.h [deleted file]
service/easy-setup/enrollee/src/easysetup.c [changed mode: 0644->0755]
service/easy-setup/enrollee/src/onboarding.c [deleted file]
service/easy-setup/enrollee/src/onboarding.h [deleted file]
service/easy-setup/enrollee/src/resourcehandler.c
service/easy-setup/enrollee/src/resourcehandler.h [changed mode: 0644->0755]
service/easy-setup/enrollee/src/softap.c [deleted file]
service/easy-setup/enrollee/src/softap.h [deleted file]
service/easy-setup/enrollee/tizen/wifi/networkhandler.c [deleted file]
service/easy-setup/enrollee/tizen/wifi/networkhandler.h [deleted file]
service/easy-setup/enrollee/tizen/wifi/softapnative.c [deleted file]
service/easy-setup/enrollee/tizen/wifi/softapnative.h [deleted file]
service/easy-setup/inc/escommon.h
service/easy-setup/mediator/SConscript
service/easy-setup/mediator/richsdk/SConscript
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvInfo.java [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningCallback.java [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningStatus.java [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESCloudProvState.java [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESResult.java [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetup.java [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceWiFiOnboarding.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/RemoteEnrollee.java [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/jni/Android.mk
service/easy-setup/mediator/richsdk/android/jni/JniCloudProvisioningStatusListener.cpp [new file with mode: 0755]
service/easy-setup/mediator/richsdk/android/jni/JniCloudProvisioningStatusListener.h [moved from service/easy-setup/mediator/richsdk/android/jni/JniProvisioningStatusListener.h with 71% similarity, mode: 0755]
service/easy-setup/mediator/richsdk/android/jni/JniDataProvisioningStatusListener.cpp [new file with mode: 0644]
service/easy-setup/mediator/richsdk/android/jni/JniDataProvisioningStatusListener.h [new file with mode: 0644]
service/easy-setup/mediator/richsdk/android/jni/JniEasySetup.cpp [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/jni/JniEasySetup.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/jni/JniEsUtils.cpp [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/jni/JniEsUtils.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/jni/JniJvm.cpp [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/jni/JniJvm.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.cpp [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/android/jni/JniRequestPropertyDataStatusListener.cpp [new file with mode: 0644]
service/easy-setup/mediator/richsdk/android/jni/JniRequestPropertyDataStatusListener.h [new file with mode: 0644]
service/easy-setup/mediator/richsdk/android/jni/JniSecurityStatusListener.cpp [moved from service/easy-setup/mediator/richsdk/android/jni/JniProvisioningStatusLisener.cpp with 57% similarity]
service/easy-setup/mediator/richsdk/android/jni/JniSecurityStatusListener.h [new file with mode: 0644]
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 [moved from service/easy-setup/mediator/richsdk/inc/RemoteEnrolleeResource.h with 60% similarity]
service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h
service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h [changed mode: 0644->0755]
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 [new file with mode: 0755]
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp
service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp
service/easy-setup/mediator/richsdk/src/RemoteEnrolleeResource.cpp [deleted file]
service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c
service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp

index 8d255aa..53d2cfb 100644 (file)
@@ -90,12 +90,11 @@ if target_os == 'linux':
 # Tizen Enrollee
 ######################################################################
 if target_os == 'tizen':
-       enrollee_env.AppendUnique(LIBPATH = [enrollee_env.get('BUILD_DIR')])
-       enrollee_env.AppendUnique(RPATH = [enrollee_env.get('BUILD_DIR')])
-       enrollee_env.AppendUnique(CXXFLAGS = ['-pthread'])
-       enrollee_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
-       enrollee_env.AppendUnique(CPPPATH = [
-                              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi'])
+   enrollee_env.AppendUnique(LIBPATH = [enrollee_env.get('BUILD_DIR')])
+   enrollee_env.AppendUnique(RPATH = [enrollee_env.get('BUILD_DIR')])
+   enrollee_env.AppendUnique(CXXFLAGS = ['-pthread'])
+   enrollee_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
+   enrollee_env.AppendUnique(CPPPATH = [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi'])
 
 ######################################################################
 # Arduino Enrollee
@@ -113,12 +112,13 @@ if target_os == 'arduino':
 es_enrollee_src = None
 
 if target_os == 'linux':
-       es_enrollee_common_src =        [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/softapnative.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/networkhandler.c']
+       es_enrollee_common_src = [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
+               #enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.c',
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c'
+               #enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.c',
+               #enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/softapnative.c',
+               #enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/networkhandler.c'
+               ]
 
        enrollee_env.AppendUnique(es_enrollee_src = es_enrollee_common_src)
 
@@ -126,31 +126,41 @@ if target_os == 'linux':
        enrollee_env.InstallTarget(enrollee_sdk_shared, 'libESEnrollee')
 
 if target_os == 'tizen':
-       enrollee_sdk_shared = enrollee_env.SharedLibrary('ESEnrolleeSDK', [
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi/networkhandler.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi/softapnative.c'])
-       enrollee_env.InstallTarget(enrollee_sdk_shared, 'libESEnrolleeSDK')
+       es_enrollee_common_src = [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
+               #enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.c',
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c'
+               #enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.c',
+               #enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/softapnative.c',
+               #enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/networkhandler.c'
+               ]
+
+       enrollee_env.AppendUnique(es_enrollee_src = es_enrollee_common_src)
+       enrollee_sdk_shared = enrollee_env.SharedLibrary('ESEnrolleeSDK', enrollee_env.get('es_enrollee_src'))
+       enrollee_env.InstallTarget(enrollee_sdk_shared, 'libESEnrollee')
        enrollee_env.UserInstallTargetLib(enrollee_sdk_shared, 'libESEnrolleeSDK')
 
 if target_os == 'arduino':
        es_sdk_static = enrollee_env.StaticLibrary('ESEnrolleeSDK', [
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/easysetup.cpp',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/onboarding.cpp',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/softap.cpp',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/resourcehandler.cpp',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/wifi/networkhandler.cpp'])
+#              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/easysetup.cpp',
+#              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/onboarding.cpp',
+#              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/softap.cpp',
+#              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/resourcehandler.cpp',
+#              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/wifi/networkhandler.cpp'])
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
+               #enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.c',
+               #enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.c',
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c'
+               #enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/wifi/networkhandler.cpp'
+               ])
+
        enrollee_env.InstallTarget(es_sdk_static, 'libESEnrolleeSDK')
 
 #Go to build sample apps
-if target_os == 'arduino':
-       SConscript('../sampleapp/enrollee/arduino/SConscript')
+#if target_os == 'arduino':
+#      SConscript('../sampleapp/enrollee/arduino/SConscript')
 
 if target_os == 'linux':
        SConscript('../sampleapp/enrollee/linux/SConscript')
        #Build UnitTestcases for Enrollee
-       SConscript('../enrollee/unittests/SConscript')
+#      SConscript('../enrollee/unittests/SConscript')
 
diff --git a/service/easy-setup/enrollee/arduino/easysetup.cpp b/service/easy-setup/enrollee/arduino/easysetup.cpp
deleted file mode 100644 (file)
index b3f0aff..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * @file
- *
- * This file contains the implementation for EasySetup Enrollee device
- */
-
-#include "easysetup.h"
-#include "softap.h"
-#include "onboarding.h"
-#include "logger.h"
-#include "resourcehandler.h"
-
-/**
- * @var ES_ENROLLEE_TAG
- * @brief Logging tag for module name.
- */
-#define ES_ENROLLEE_TAG "ES"
-
-//-----------------------------------------------------------------------------
-// Private variables
-//-----------------------------------------------------------------------------
-
-/**
- * @var gTargetSsid
- * @brief Target SSID of the Soft Access point to which the device has to connect
- */
-static char gTargetSsid[MAXSSIDLEN];
-
-/**
- * @var gTargetPass
- * @brief Password of the target access point to which the device has to connect
- */
-static char gTargetPass[MAXNETCREDLEN];
-
-/**
- * @var gEnrolleeStatusCb
- * @brief Fucntion pointer holding the callback for intimation of EasySetup Enrollee status callback
- */
-static ESEnrolleeEventCallback gEnrolleeStatusCb = NULL;
-
-/**
- * @var gIsSecured
- * @brief Variable to check if secure mode is enabled or not.
- */
-static bool gIsSecured = false;
-
-//-----------------------------------------------------------------------------
-// Private internal function prototypes
-//-----------------------------------------------------------------------------
-void ESOnboardingCallback(ESResult esResult);
-void ESProvisioningCallback(ESResult esResult);
-void ESOnboardingCallbackTargetNet(ESResult esResult);
-static bool ESEnrolleeValidateParam(OCConnectivityType networkType, const char *ssid,
-                                                const char *passwd, ESEnrolleeEventCallback cb);
-
-
-void ESOnboardingCallback(ESResult esResult)
-{
-        OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESOnboardingCallback with  result = %d", esResult);
-        if(esResult == ES_OK)
-        {
-            gEnrolleeStatusCb(esResult, ES_ON_BOARDED_STATE);
-        }
-        else
-        {
-            OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG,
-                        "Onboarding is failed callback result is = %d", esResult);
-            gEnrolleeStatusCb(esResult, ES_INIT_STATE);
-        }
-}
-
-void ESProvisioningCallback(ESResult esResult)
-{
-    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESProvisioningCallback with  result = %d", esResult);
-
-    if (esResult == ES_RECVTRIGGEROFPROVRES)
-    {
-        GetTargetNetworkInfoFromProvResource(gTargetSsid, gTargetPass);
-        gEnrolleeStatusCb(ES_OK, ES_PROVISIONED_STATE);
-        OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "Connecting with target network");
-
-        // Connecting/onboarding to target network
-        ConnectToWiFiNetwork(gTargetSsid, gTargetPass, ESOnboardingCallbackTargetNet);
-    }
-    else
-    {
-       OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Provisioning is failed callback result is = %d", esResult);
-       // Resetting Enrollee to ONBOARDED_STATE as Enrollee is alreday onboarded in previous step
-       gEnrolleeStatusCb(ES_OK, ES_ON_BOARDED_STATE);
-    }
-}
-
-void ESOnboardingCallbackTargetNet(ESResult esResult)
-{
-    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESOnboardingCallback on target network with result = %d",
-                                                                                        esResult);
-    if(esResult == ES_OK)
-    {
-        gEnrolleeStatusCb(esResult, ES_ON_BOARDED_TARGET_NETWORK_STATE);
-    }
-    else
-    {
-        OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG,
-                    "Onboarding is failed on target network and callback result is = %d", esResult);
-        // Resetting Enrollee state to the ES_PROVISIONED_STATE
-        // as device is already being provisioned with target network creds.
-        gEnrolleeStatusCb(esResult, ES_PROVISIONED_STATE);
-    }
-}
-
-ESResult ESInitEnrollee(OCConnectivityType networkType, const char *ssid, const char *passwd,
-        bool isSecured,
-        ESEnrolleeEventCallback cb)
-{
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitEnrollee IN");
-    if(!ESEnrolleeValidateParam(networkType,ssid,passwd,cb))
-    {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG,
-                            "ESInitEnrollee::Stopping Easy setup due to invalid parameters");
-        return ES_ERROR;
-    }
-
-    //Init callback
-    gEnrolleeStatusCb = cb;
-
-    gIsSecured = isSecured;
-
-    // TODO : This onboarding state has to be set by lower layer, as they better
-    // knows when actually on-boarding started.
-    cb(ES_ERROR,ES_ON_BOARDING_STATE);
-
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "received callback");
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "onboarding now..");
-
-    if(!ESOnboard(ssid, passwd, ESOnboardingCallback))
-    {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESInitEnrollee::On-boarding failed");
-        cb(ES_ERROR, ES_INIT_STATE);
-        return ES_ERROR;
-    }
-
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitEnrollee OUT");
-    return ES_OK;
-}
-
-ESResult ESTerminateEnrollee()
-{
-    UnRegisterResourceEventCallBack();
-
-    //Delete Prov resource
-    if (DeleteProvisioningResource() != OC_STACK_OK)
-    {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "Deleting prov resource error!!");
-        return ES_ERROR;
-    }
-
-    OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESTerminateEnrollee success");
-    return ES_OK;
-}
-
-ESResult ESInitProvisioning()
-{
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitProvisioning <<IN>>");
-
-    if (CreateProvisioningResource(gIsSecured) != OC_STACK_OK)
-    {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "CreateProvisioningResource error");
-        return ES_ERROR;
-    }
-
-    RegisterResourceEventCallBack(ESProvisioningCallback);
-
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitProvisioning <<OUT>>");
-    return ES_RESOURCECREATED;
-}
-
-static bool ESEnrolleeValidateParam(OCConnectivityType /*networkType*/, const char *ssid,
-                                                const char *passwd, ESEnrolleeEventCallback cb)
-{
-    if (!ssid || !passwd || !cb)
-    {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESEnrolleeValidateParam - Invalid parameters");
-        return false;
-    }
-    return true;
-}
-
diff --git a/service/easy-setup/enrollee/arduino/onboarding.cpp b/service/easy-setup/enrollee/arduino/onboarding.cpp
deleted file mode 100644 (file)
index aaf1509..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * @file
- *
- * This file has methods for on-boarding the Enrollee device.
- * This will contain template methods that will have core business logic & negotiation algorithm
- * on various on-boarding methods.
- */
-
-#include "easysetup.h"
-#include "softap.h"
-#include "onboarding.h"
-
-#include "logger.h"
-#include "resourcehandler.h"
-
-/**
- * @var ES_ENROLLEE_TAG
- * @brief Logging tag for module name.
- */
-#define ES_ENROLLEE_TAG "ES_SOFTAP"
-
-/**
- * It will return true on-boarding type is soft AP
- */
-bool ESSoftapOnboarding()
-{
-    // TODO: To be changed based on user config. Current version, hardcoded to SoftAp onboarding
-    return true;
-}
-
-/**
- * It will return true on-boarding type is BLE
- */
-bool ESBleOnboarding()
-{
-    //BLE onboarding is not supported with current version.
-    return false;
-}
-
-/**
- * It will do onboarding based on the user's configuration.
- */
-bool ESOnboard(const char * ssid, const char* passwd, ESEnrolleeNetworkEventCallback cb)
-{
-    OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "ESOnboard IN");
-
-    if (ESSoftapOnboarding())
-    {
-        OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "Connecting to Mediator SoftAp");
-        ConnectToWiFiNetwork(ssid, passwd, cb);
-        return true;
-    }
-    else if (ESBleOnboarding())
-    {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESOnboard::Ble onboarding is not supported");
-        // TODO:
-        return false;
-    }
-    else
-    {
-        // TODO:
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESOnboard::Invalid onboarding option");
-        return false;
-    }
-}
-
diff --git a/service/easy-setup/enrollee/arduino/resourcehandler.cpp b/service/easy-setup/enrollee/arduino/resourcehandler.cpp
deleted file mode 100755 (executable)
index 0d32276..0000000
+++ /dev/null
@@ -1,392 +0,0 @@
-//******************************************************************
-//
-// 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 "resourcehandler.h"
-
-#include <stdio.h>
-
-#include "ocpayload.h"
-#include "oic_string.h"
-
-/**
- * @var ES_RH_TAG
- * @brief Logging tag for module name.
- */
-#define ES_RH_TAG "ES_RH"
-//-----------------------------------------------------------------------------
-// Private variables
-//-----------------------------------------------------------------------------
-
-/**
- * @var gProvResource
- * @brief Structure for holding the Provisioning status and target information required to
- * connect to the target network
- */
-static ProvResource gProvResource;
-
-/**
- * @var gNetResource
- * @brief Structure forr holding the Provisioning status of network information
- */
-static NetResource gNetResource;
-
-//-----------------------------------------------------------------------------
-// Private internal function prototypes
-//-----------------------------------------------------------------------------
-OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest *ehRequest,
-        void *callback);
-const char *getResult(OCStackResult result);
-OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
-OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
-OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
-OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest);
-
-ESEnrolleeResourceEventCallback gNetworkInfoProvEventCb = NULL;
-
-void RegisterResourceEventCallBack(ESEnrolleeResourceEventCallback cb)
-{
-    gNetworkInfoProvEventCb = cb;
-}
-
-void UnRegisterResourceEventCallBack()
-{
-    if (gNetworkInfoProvEventCb)
-    {
-        gNetworkInfoProvEventCb = NULL;
-    }
-}
-
-void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
-{
-    if (name != NULL && pass != NULL)
-    {
-        OICStrcpy(name, MAXSSIDLEN, gProvResource.tnn);
-        OICStrcpy(pass, MAXNETCREDLEN, gProvResource.cd);
-    }
-}
-
-OCStackResult CreateProvisioningResource(bool isSecured)
-{
-    gProvResource.ps = ES_PS_NEED_PROVISIONING;
-    gProvResource.tr = ES_PS_TRIGGER_INIT_VALUE;
-
-    gProvResource.tnt = CT_ADAPTER_IP;
-    OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), "Unknown");
-    OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), "Unknown");
-
-    OCStackResult res = OC_STACK_ERROR;
-    if (isSecured)
-    {
-        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
-        OC_RSRVD_INTERFACE_DEFAULT,
-        OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
-        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
-    }
-    else
-    {
-        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
-        OC_RSRVD_INTERFACE_DEFAULT,
-        OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
-        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
-    }
-
-    OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
-    return res;
-}
-
-OCStackResult DeleteProvisioningResource()
-{
-    OCStackResult res = OCDeleteResource(gProvResource.handle);
-    if (res != OC_STACK_OK)
-    {
-        OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
-    }
-
-    return res;
-}
-
-OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-    if (!ehRequest)
-    {
-        OIC_LOG(ERROR, ES_RH_TAG, "Request is Null");
-        return ehResult;
-    }
-    if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
-    {
-        OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
-        return ehResult;
-    }
-
-    OCRepPayload *getResp = constructResponse(ehRequest);
-    if (!getResp)
-    {
-        OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
-        return OC_EH_ERROR;
-    }
-
-    *payload = getResp;
-    ehResult = OC_EH_OK;
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
-{
-    OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-    if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
-    {
-        OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
-        return ehResult;
-    }
-
-    OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
-    if (!input)
-    {
-        OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
-        return ehResult;
-    }
-
-    char* tnn;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn))
-    {
-        OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), tnn);
-        OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.tnn %s", gProvResource.tnn);
-
-        gProvResource.ps = ES_PS_PROVISIONING_COMPLETED;
-    }
-
-    char* cd;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
-    {
-        OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), cd);
-        OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd);
-    }
-
-    OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %lld", gProvResource.ps);
-
-    int64_t tr;
-    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_TR, &tr))
-    {
-        // Triggering
-        gProvResource.tr = tr;
-    }
-
-    //ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
-    // A new request for provisioning means overriding existing network provisioning information.
-    if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED && tr == ES_PS_TRIGGER_CONNECTION)
-    {
-        OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed."
-                "Tiggering the network connection");
-
-        if (gNetworkInfoProvEventCb)
-        {
-            gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES);
-            ehResult = OC_EH_OK;
-        }
-        else
-        {
-            gProvResource.tr = ES_PS_TRIGGER_INIT_VALUE;
-            OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL."
-                    "Network handler not registered. Failed to connect to the network");
-            ehResult = OC_EH_ERROR;
-        }
-
-        return ehResult;
-    }
-    else if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED)
-    {
-        OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed. "
-                "This a request to override the existing the network provisioning information");
-    }
-    else
-    {
-        OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
-    }
-
-    OCRepPayload *getResp = constructResponse(ehRequest);
-    if (!getResp)
-    {
-        OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
-        return OC_EH_ERROR;
-    }
-
-    *payload = getResp;
-    ehResult = OC_EH_OK;
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * /*ehRequest*/,
-        OCRepPayload** /*payload*/)
-{
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-
-    return ehResult;
-}
-
-OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
-{
-    OCRepPayload* payload = OCRepPayloadCreate();
-    if (!payload)
-    {
-        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-        return NULL;
-    }
-
-    if (ehRequest->resource == gProvResource.handle)
-    {
-        OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
-        OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
-        OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS, gProvResource.ps);
-        OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TNT, gProvResource.tnt);
-    }
-    else if (ehRequest->requestHandle == gNetResource.handle)
-    {
-
-        OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_NET);
-        OCRepPayloadSetPropInt(payload, "ant", gNetResource.ant[0]);
-    }
-    return payload;
-}
-
-/**
- * This is the entity handler for the registered resource.
- * This is invoked by OCStack whenever it recevies a request for this resource.
- */
-OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest* entityHandlerRequest, void *callback)
-{
-    (void) callback;
-    OCEntityHandlerResult ehRet = OC_EH_OK;
-    OCEntityHandlerResponse response =
-    { 0, 0, OC_EH_ERROR, 0, 0,
-    { },
-    { 0 }, false };
-    OCRepPayload* payload = NULL;
-
-    if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
-    {
-        if (OC_REST_GET == entityHandlerRequest->method)
-        {
-            OIC_LOG(INFO, ES_RH_TAG, "Received GET request");
-            ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
-        }
-        else if (OC_REST_PUT == entityHandlerRequest->method)
-        {
-            OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
-
-            //PUT request will be handled in the internal implementation
-            if (gProvResource.handle != NULL
-                    && entityHandlerRequest->resource == gProvResource.handle)
-            {
-                ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
-            }
-            else
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
-                ehRet = OC_EH_ERROR;
-            }
-        }
-        else if (OC_REST_POST == entityHandlerRequest->method)
-        {
-            OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
-            if (gProvResource.handle != NULL
-                    && entityHandlerRequest->resource == gProvResource.handle)
-            {
-                ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
-            }
-            else
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
-                ehRet = OC_EH_ERROR;
-            }
-        }
-
-        if (ehRet == OC_EH_OK)
-        {
-            // Format the response.  Note this requires some info about the request
-            response.requestHandle = entityHandlerRequest->requestHandle;
-            response.resourceHandle = entityHandlerRequest->resource;
-            response.ehResult = ehRet;
-            //response uses OCPaylod while all get,put methodes use OCRepPayload
-            response.payload = (OCPayload*) (payload);
-            response.numSendVendorSpecificHeaderOptions = 0;
-            memset(response.sendVendorSpecificHeaderOptions, 0,
-                    sizeof(response.sendVendorSpecificHeaderOptions));
-            memset(response.resourceUri, 0, sizeof(response.resourceUri));
-            // Indicate that response is NOT in a persistent buffer
-            response.persistentBufferFlag = 0;
-
-            // Send the response
-            if (OCDoResponse(&response) != OC_STACK_OK)
-            {
-                OIC_LOG(ERROR, ES_RH_TAG, "Error sending response");
-                ehRet = OC_EH_ERROR;
-            }
-        }
-    }
-
-    return ehRet;
-}
-
-const char *getResult(OCStackResult result)
-{
-    switch (result)
-    {
-        case OC_STACK_OK:
-            return "OC_STACK_OK";
-        case OC_STACK_INVALID_URI:
-            return "OC_STACK_INVALID_URI";
-        case OC_STACK_INVALID_QUERY:
-            return "OC_STACK_INVALID_QUERY";
-        case OC_STACK_INVALID_IP:
-            return "OC_STACK_INVALID_IP";
-        case OC_STACK_INVALID_PORT:
-            return "OC_STACK_INVALID_PORT";
-        case OC_STACK_INVALID_CALLBACK:
-            return "OC_STACK_INVALID_CALLBACK";
-        case OC_STACK_INVALID_METHOD:
-            return "OC_STACK_INVALID_METHOD";
-        case OC_STACK_NO_MEMORY:
-            return "OC_STACK_NO_MEMORY";
-        case OC_STACK_COMM_ERROR:
-            return "OC_STACK_COMM_ERROR";
-        case OC_STACK_INVALID_PARAM:
-            return "OC_STACK_INVALID_PARAM";
-        case OC_STACK_NOTIMPL:
-            return "OC_STACK_NOTIMPL";
-        case OC_STACK_NO_RESOURCE:
-            return "OC_STACK_NO_RESOURCE";
-        case OC_STACK_RESOURCE_ERROR:
-            return "OC_STACK_RESOURCE_ERROR";
-        case OC_STACK_SLOW_RESOURCE:
-            return "OC_STACK_SLOW_RESOURCE";
-        case OC_STACK_NO_OBSERVERS:
-            return "OC_STACK_NO_OBSERVERS";
-        case OC_STACK_ERROR:
-            return "OC_STACK_ERROR";
-        default:
-            return "UNKNOWN";
-    }
-}
-
diff --git a/service/easy-setup/enrollee/arduino/softap.cpp b/service/easy-setup/enrollee/arduino/softap.cpp
deleted file mode 100644 (file)
index 4199e9a..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-//      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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * These are adapter APIs will make caller modules agnostic to platform.
- */
-
-#include "softapnative.h"
-#include "easysetup.h"
-#include "softap.h"
-#include "networkhandler.h"
-
-void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
-                                                            const char* device_name );
-
-ESEnrolleeNetworkEventCallback gCallback;
-
-/**
- * It will return Device which is creating Soft AP.
- * i.e.Enrollee or Mediator.
- * This decesion is based on, what is the value set for ES_SOFTAP_MODE in build command as well as 
- * in iotivity.spec file.
- */
-DeviceRole ESSoftapHost()
-{
-#ifdef ENROLLEE_SOFTAP
-    //SoftAp at enrollee
-    return ENROLLEE;
-#else
-    //SoftAp at mediator
-    return MEDIATOR;
-#endif
-}
-
-/**
- * It will return true if the Soft AP is created at Enrollee device
- */
-bool ESSoftapAtEnrollee()
-{
-    return ( ESSoftapHost() == ENROLLEE) ? true : false;
-}
-
-/**
- * It will return true if the Soft AP is created at Mediator device
- */
-bool ESSoftapAtMediator()
-{
-    return (ESSoftapHost() == MEDIATOR) ? true : false;
-}
-
-/**
- * This API will map result returned from the native to the caller.
- * Callback API's signature needs to be modified under build switch according
- * to the underline platform.
- */
-void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
-                                                                const char* device_name)
-{
-    if(SOFTAP_SUCCESS ==  result) //on Success
-    {
-        gCallback(ES_OK);
-    }
-    else //on Failure
-    {
-        gCallback(ES_ERROR);
-    }
-}
-
-/**
- * This API will create the softap at enrollee
- */
-void ESCreateSoftap(const char * ssid, const char* passwd, ESEnrolleeNetworkEventCallback cb)
-{
-    gCallback = cb;
-
-    // TODO: To be implemented
-    // Create Soft AP through native APIs -- start
-    // native API call by and pass ESCreateSoftapCallback() as callback
-    ESCreateSoftapNative(ssid, passwd,ESCreateSoftapCallback);
-    // Create Soft AP through native APIs -- end
-}
-
diff --git a/service/easy-setup/enrollee/arduino/wifi/networkhandler.cpp b/service/easy-setup/enrollee/arduino/wifi/networkhandler.cpp
deleted file mode 100644 (file)
index fae1fd5..0000000
+++ /dev/null
@@ -1,249 +0,0 @@
-//******************************************************************
-//
-// 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 "networkhandler.h"
-
-// Arduino WiFi Shield includes
-#include <SPI.h>
-#include <WiFi.h>
-#include <WiFiUdp.h>
-
-#include <string.h>
-
-#include "logger.h"
-
-/**
- * @var ES_NH_TAG
- * @brief Logging tag for module name.
- */
-#define ES_NH_TAG "ES_NH"
-
-//-----------------------------------------------------------------------------
-// Defines
-//-----------------------------------------------------------------------------
-/**
- *  ES_MAX_NETWORK_RETRY sets the default number of retry count for network connection.
- */
-#define ES_MAX_NETWORK_RETRY (5)
-
-//-----------------------------------------------------------------------------
-// Private variables
-//-----------------------------------------------------------------------------
-static IPAddress enrolleeIP;
-
-/**
- * @var g_retryCounter
- * @brief Retry counter for cancelling network retry. Currently network retry is
- *          limited to 5 attempts
- */
-static uint16_t g_retryCounter = 0;
-
-
-
-//-----------------------------------------------------------------------------
-// Private internal function prototypes
-//-----------------------------------------------------------------------------
-int findNetwork(const char *ssid);
-int ConnectToNetwork(const char *ssid, const char *pass);
-void printEncryptionType(int thisType);
-
-// Arduino WiFi Shield
-// Note : Arduino WiFi Shield currently does NOT support multicast and therefore
-// this server will NOT be listening on 224.0.1.187 multicast address.
-static const char ARDUINO_WIFI_SHIELD_UDP_FW_VER[] = "1.1.0";
-
-ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass,
-                                                            ESEnrolleeNetworkEventCallback cb)
-{
-    char *fwVersion;
-    int status = WL_IDLE_STATUS;
-    int res;
-
-    // check for the presence of the shield:
-    if (WiFi.status() == WL_NO_SHIELD)
-    {
-        OIC_LOG(ERROR, ES_NH_TAG, "WiFi shield not present");
-        return ES_ERROR;
-    }
-
-    // Verify that WiFi Shield is running the firmware with all UDP fixes
-    fwVersion = WiFi.firmwareVersion();
-    OIC_LOG_V(INFO, ES_NH_TAG, "WiFi Shield Firmware version %s", fwVersion);
-    if (strncmp(fwVersion, ARDUINO_WIFI_SHIELD_UDP_FW_VER, sizeof(ARDUINO_WIFI_SHIELD_UDP_FW_VER))
-            != 0)
-    {
-        OIC_LOG(DEBUG, ES_NH_TAG, "!!!!! Upgrade WiFi Shield Firmware version !!!!!!");
-        return ES_ERROR;
-    }
-
-    //Retry counter is reset everytime the ConnectToWiFiNetwork is invoked
-    g_retryCounter = 0;
-
-    OIC_LOG_V(INFO, ES_NH_TAG, "Finding SSID: %s", ssid);
-
-    while ((findNetwork(ssid) == 0) && g_retryCounter < ES_MAX_NETWORK_RETRY) // found
-    {
-        delay(1000);
-        g_retryCounter++;
-    }
-
-    if(g_retryCounter == ES_MAX_NETWORK_RETRY){
-        OIC_LOG_V(ERROR, ES_NH_TAG, "Connection to network failed after %d attempts",
-                  g_retryCounter);
-        return ES_ERROR;
-    }
-
-    if (cb != NULL)
-    {
-        cb(ES_OK);
-    }
-
-    if (WiFi.status() == WL_CONNECTED)
-        WiFi.disconnect();
-
-    //Retry counter is reset everytime the ConnectToWiFiNetwork is invoked
-    g_retryCounter = 0;
-
-    res = ConnectToNetwork(ssid, pass);
-
-    if (res == 0)
-    {
-        return ES_NETWORKCONNECTED;
-    }
-    else
-    {
-        return ES_NETWORKNOTCONNECTED;
-    }
-}
-
-int findNetwork(const char *ssid)
-{
-    int res = 0;
-    // scan for nearby networks:
-    Serial.println("** Scan Networks **");
-    int numSsid = WiFi.scanNetworks();
-    if (numSsid == -1)
-    {
-        Serial.println("Couldn't get a wifi connection");
-
-        return res;
-    }
-
-    // print the list of networks seen:
-    Serial.print("number of available networks:");
-    Serial.println(numSsid);
-
-    // print the network number and name for each network found:
-    for (int thisNet = 0; thisNet < numSsid; thisNet++)
-    {
-        Serial.print(thisNet);
-        Serial.print(") ");
-        Serial.print(WiFi.SSID(thisNet));
-        Serial.print("\tEncryption: ");
-        printEncryptionType(WiFi.encryptionType(thisNet));
-
-        if (strcmp(WiFi.SSID(thisNet), ssid) == 0)
-        {
-            res = 1;
-        }
-    }
-
-    return res;
-}
-
-int ConnectToNetwork(const char *ssid, const char *pass)
-{
-    int status = WL_IDLE_STATUS;
-
-    // attempt to connect to Wifi network:
-    while (status != WL_CONNECTED && g_retryCounter < ES_MAX_NETWORK_RETRY)
-    {
-        OIC_LOG_V(INFO, ES_NH_TAG, "Attempting to connect to SSID: %s", ssid);
-
-        status = WiFi.begin((char *) ssid, (char *) pass);
-
-        // wait 10 seconds for connection:
-        delay(10000);
-
-        g_retryCounter++;
-    }
-
-    if(g_retryCounter == ES_MAX_NETWORK_RETRY){
-        OIC_LOG_V(ERROR, ES_NH_TAG, "Connection to network failed after %d attempts",
-                  g_retryCounter);
-        return ES_ERROR;
-    }
-
-    OIC_LOG(DEBUG, ES_NH_TAG, "Connected to wifi");
-
-    enrolleeIP = WiFi.localIP();
-    OIC_LOG_V(INFO, ES_NH_TAG, "IP Address:  %d.%d.%d.%d", enrolleeIP[0], enrolleeIP[1],
-                                                           enrolleeIP[2], enrolleeIP[3]);
-
-    char buf[50];
-    sprintf(buf, "IP Address:  %d.%d.%d.%d", enrolleeIP[0], enrolleeIP[1],
-                                             enrolleeIP[2], enrolleeIP[3]);
-    Serial.println(buf);
-
-    return 0;
-}
-
-ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info)
-{
-    if (targetType == CT_ADAPTER_IP && WiFi.status() == WL_CONNECTED)
-    {
-        info->type = CT_ADAPTER_IP;
-        info->ipaddr = WiFi.localIP();
-        if((sizeof(info->ssid) >= MAXSSIDLEN) && (strlen(WiFi.SSID()) <= MAXSSIDLEN))
-        {
-            strcpy(info->ssid, WiFi.SSID());
-            return ES_OK;
-        }
-        else
-        {
-            return ES_ERROR;
-        }
-    }
-
-    return ES_ERROR;
-}
-
-void printEncryptionType(int thisType)
-{
-    // read the encryption type and print out the name:
-    switch (thisType)
-    {
-        case ENC_TYPE_WEP:
-            Serial.println("WEP");
-            break;
-        case ENC_TYPE_TKIP:
-            Serial.println("WPA");
-            break;
-        case ENC_TYPE_CCMP:
-            Serial.println("WPA2");
-            break;
-        case ENC_TYPE_NONE:
-            Serial.println("None");
-            break;
-        case ENC_TYPE_AUTO:
-            Serial.println("Auto");
-            break;
-    }
-}
diff --git a/service/easy-setup/enrollee/arduino/wifi/networkhandler.h b/service/easy-setup/enrollee/arduino/wifi/networkhandler.h
deleted file mode 100644 (file)
index f1503e1..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * @file
- *
- * This file contains IP network handling functionality for Enrollee device
- */
-
-#ifndef ES_NETWORK_HANDLER_H_
-#define ES_NETWORK_HANDLER_H_
-
-// Do not remove the include below
-#include "Arduino.h"
-
-// Arduino WiFi Shield includes
-#include <SPI.h>
-#include <WiFi.h>
-#include <WiFiUdp.h>
-
-#include <string.h>
-#include "logger.h"
-#include "escommon.h"
-
-#define MAXSSIDLEN 33
-#define MAXNETCREDLEN 20
-#define MAXNUMTYPE 5
-#define MAXADDRLEN 15
-
-/*
- * Callback function for updating the Network status to the subscribers
- *
- * @param esResult ESResult provides the current state of the network connection status
- */
-typedef void (*ESEnrolleeNetworkEventCallback)(ESResult esResult);
-
-typedef struct
-{
-    OCConnectivityType type;
-    // for WiFI
-    IPAddress ipaddr;
-    char ssid[MAXSSIDLEN];
-    // for BT, BLE
-    byte mac[6];
-} NetworkInfo;
-
-ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass,
-                                                            ESEnrolleeNetworkEventCallback);
-ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info);
-
-#endif
index 00102a9..6b65ca4 100755 (executable)
@@ -42,27 +42,54 @@ extern "C" {
  */
 typedef void (*ESEnrolleeEventCallback)(ESResult esResult, ESEnrolleeState enrolleeState);
 
+
+
+typedef struct
+{
+    void (*WiFiProvCb) (ESWiFiProvData *);
+    void (*DevConfProvCb) (ESDevConfProvData *);
+    void (*CloudDataProvCb) (ESCloudProvData *);
+} ESProvisioningCallbacks;
+
 /**
  * This function Initializes the EasySetup. This API must be called prior to invoking any other API
  *
- * @param networkType       NetworkType on which OnBoarding has to be performed.
- * @param ssid              SSID of the target SoftAP network to which the Enrollee is connecting.
- * @param passwd            Password of the target SoftAP network to which the Enrollee is
- *                          connecting
  * @param isSecured         True if the Enrollee is operating in secured mode.
- * @param eventCallback     ESEnrolleeEventCallback for for updating the Enrollee OnBoarding status
- *                          result to the application
+ * @param resourceMask      Provisining Resource Type which application wants to make.
+ *                          ES_WIFI_RESOURCE = 0x01,
+ *                          ES_CLOUD_RESOURCE = 0x02,
+ *                          ES_DEVCONF_RESOURCE = 0x04
+ * @param callbacks         ESProvisioningCallbacks for updating Provisioning Resources' data to the application
  * @return ::ES_OK on success, some other value upon failure.
  */
-ESResult ESInitEnrollee(OCConnectivityType networkType, const char *ssid, const char *passwd,
-                                bool isSecured, ESEnrolleeEventCallback eventCallback);
+ESResult ESInitEnrollee(bool isSecured, ESResourceMask resourceMask, ESProvisioningCallbacks callbacks);
+
 
 /**
- * This function performs initialization of Provisioning and Network resources needed for EasySetup
- * process.
+ * This function Sets Device Information.
+ *
+ * @param deviceProperty   Contains device information composed of WiFi Structure & DevConf Structure
+ * @return ::ES_OK on success, some other value upon failure.
+ */
+ESResult ESSetDeviceProperty(ESDeviceProperty *deviceProperty);
+
+
+/**
+ * This function Sets Enrollee's State.
+ *
+ * @param esState   Contains current enrollee's state.
+ * @return ::ES_OK on success, some other value upon failure.
+ */
+ESResult ESSetState(ESEnrolleeState esState);
+
+
+/**
+ * This function Sets Enrollee's Error Code.
+ *
+ * @param esErrCode   Contains enrollee's error code.
  * @return ::ES_OK on success, some other value upon failure.
  */
-ESResult ESInitProvisioning();
+ESResult ESSetErrorCode(ESErrorCode esErrCode);
 
 /**
  * This function performs termination of Provisioning and Network resources.
diff --git a/service/easy-setup/enrollee/linux/wifi/networkhandler.c b/service/easy-setup/enrollee/linux/wifi/networkhandler.c
deleted file mode 100644 (file)
index 24b7dea..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/******************************************************************
- *
- * 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 "networkhandler.h"
-
-#include <unistd.h>
-
-#include "logger.h"
-#include "easysetup.h"
-#include "oic_string.h"
-
-#define LOG_TAG "LINUX ES"
-
-const char *gSsid = "DLNA_LISMORE1";
-const char *gPass = "dlna@010203";
-char *gIpAddress;
-ESEnrolleeNetworkEventCallback gNetworkEventCb;
-
-/*
- * All the functions defined in this file are stub functions to be implemented by the end user of
- * Easysetup Enrollee applications.
- */
-static void ESActivateWifi()
-{
-
-}
-
-static void start()
-{
-    OIC_LOG(INFO, LOG_TAG, "START");
-    ESActivateWifi();
-}
-
-void ConnectToWiFiNetwork(const char *ssid, const char *pass,
-                                                        ESEnrolleeNetworkEventCallback cb)
-{
-    OIC_LOG_V(INFO, LOG_TAG, "ConnectToWiFiNetwork %s %s",ssid,pass);
-    gPass = pass;
-    gSsid = ssid;
-    gNetworkEventCb = cb;
-    start();
-}
-
-ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info)
-{
-    if (targetType == CT_ADAPTER_IP)
-    {
-        info->type = CT_ADAPTER_IP;
-        info->ipaddr = gIpAddress;
-        if (strlen(gSsid) <= MAXSSIDLEN)
-        {
-            OICStrcpy(info->ssid, sizeof(info->ssid), gSsid);
-            return ES_OK;
-        }
-        else
-        {
-            return ES_ERROR;
-        }
-    }
-
-    return ES_ERROR;
-}
-
diff --git a/service/easy-setup/enrollee/linux/wifi/networkhandler.h b/service/easy-setup/enrollee/linux/wifi/networkhandler.h
deleted file mode 100644 (file)
index b70be01..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * @file
- *
- * This file contains IP network handling functionality for Enrollee device
- */
-
-#ifndef ES_NETWORK_HANDLER_H_
-#define ES_NETWORK_HANDLER_H_
-
-
-#include <string.h>
-#include "easysetup.h"
-#include "logger.h"
-#include "escommon.h"
-
-#define MAXSSIDLEN 33
-#define MAXNETCREDLEN 20
-#define MAXNUMTYPE 5
-#define MAXADDRLEN 15
-
-/*
- * Callback function for updating the Network status to the subscribers
- *
- * @param esResult ESResult provides the current state of the network connection status
- */
-typedef void (*ESEnrolleeNetworkEventCallback)(ESResult esResult);
-
-typedef struct
-{
-    OCConnectivityType type;
-    // for WiFI
-    //IPAddress ipaddr;
-    char *ipaddr;
-    char ssid[MAXSSIDLEN];
-    // for BT, BLE
-    //byte mac[6];
-} NetworkInfo;
-
-void ConnectToWiFiNetwork(const char *ssid, const char *pass,
-                                                            ESEnrolleeNetworkEventCallback);
-ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info);
-
-#endif
diff --git a/service/easy-setup/enrollee/linux/wifi/softapnative.c b/service/easy-setup/enrollee/linux/wifi/softapnative.c
deleted file mode 100644 (file)
index d6861a0..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-//******************************************************************
-//
-// 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 "softapnative.h"
-
-/**
- * This API will create the Soft AP at Enrollee device. 
- */
-void ESCreateSoftapNative(const char * ssid, const char* passwd, SoftAPCallbackNative cb)
-{
-    const char *ip, *macaddr, *devicename;
-
-    // Soft is created successfully. This callback may be send from other cascaded callbacks
-    cb(SOFTAP_SUCCESS, ip, macaddr, devicename);
-
-    // TODO: Use below code to indicate failed on-boarding / softap creation
-    // Soft creation is failed. This callback may be send from other cascaded callbacks 
-    //cb(SOFTAP_FAILED, nullptr,nullptr,nullptr);
-}
-
diff --git a/service/easy-setup/enrollee/linux/wifi/softapnative.h b/service/easy-setup/enrollee/linux/wifi/softapnative.h
deleted file mode 100644 (file)
index 35c3773..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * @file
- *
- * This file contains the API declaration for creating & configuration for SoftAP 
- */
-
-#ifndef EASYSETUP_ENROLLEE_SOFTAP_H__
-#define EASYSETUP_ENROLLEE_SOFTAP_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-
-#define SOFTAP_SUCCESS  1
-#define SOFTAP_FAILED   0
-
-
-//This callback signagure may get changed as per the native implementation.
-typedef void (*SoftAPCallbackNative)(int result, const char *ip, const char* mac_addr,
-                                                                        const char*device_name);
-
-void ESCreateSoftapNative(const char * ssid, const char* passwd, SoftAPCallbackNative cb);
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-
-#endif /* EASYSETUP_ENROLLEE_SOFTAP_H__ */
-
-
-
old mode 100644 (file)
new mode 100755 (executable)
index cb6d260..2e9d9d3
  */
 
 #include "easysetup.h"
-#include "softap.h"
-#include "onboarding.h"
 #include "logger.h"
 #include "resourcehandler.h"
-#include "easysetupcallbacks.h"
+#include "oic_string.h"
 
 /**
  * @var ES_ENROLLEE_TAG
  * @var gTargetSsid
  * @brief Target SSID of the Soft Access point to which the device has to connect
  */
-static char gTargetSsid[MAXSSIDLEN];
+// static char gTargetSsid[MAXSSIDLEN];
 
 /**
  * @var gTargetPass
  * @brief Password of the target access point to which the device has to connect
  */
-static char gTargetPass[MAXNETCREDLEN];
+// static char gTargetPass[MAXNETCREDLEN];
 
 /**
  * @var gEnrolleeStatusCb
  * @brief Fucntion pointer holding the callback for intimation of EasySetup Enrollee status callback
  */
-static ESEnrolleeEventCallback gEnrolleeStatusCb = NULL;
+// static ESEnrolleeEventCallback gEnrolleeStatusCb = NULL;
 
 /**
  * @var gIsSecured
@@ -65,134 +63,219 @@ static ESEnrolleeEventCallback gEnrolleeStatusCb = NULL;
  */
 static bool gIsSecured = false;
 
-void ESOnboardingCallback(ESResult esResult)
-{
-        OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESOnboardingCallback with  result = %d", esResult);
-        if(esResult == ES_OK)
-        {
-            gEnrolleeStatusCb(esResult, ES_ON_BOARDED_STATE);
-        }
-        else
-        {
-            OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG,
-                        "Onboarding is failed callback result is = %d", esResult);
-            gEnrolleeStatusCb(esResult, ES_INIT_STATE);
-        }
-}
+static ESProvisioningCallbacks gESProvisioningCb;
+static ESDeviceProperty gESDeviceProperty;
 
-void ESProvisioningCallback(ESResult esResult)
+void ESWiFiRsrcCallback(ESResult esResult, ESWiFiProvData *eventData)
 {
-    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESProvisioningCallback with  result = %d", esResult);
+    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESWiFiRsrcCallback IN");
 
-    if (esResult == ES_RECVTRIGGEROFPROVRES)
+    if(esResult != ES_OK)
     {
-        GetTargetNetworkInfoFromProvResource(gTargetSsid, gTargetPass);
-        gEnrolleeStatusCb(ES_OK, ES_PROVISIONED_STATE);
-        OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "Connecting with target network");
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "ESWiFiRsrcCallback Error Occured");
+        return;
+    }
 
-        // Connecting/onboarding to target network
-        ConnectToWiFiNetwork(gTargetSsid, gTargetPass, ESOnboardingCallbackTargetNet);
+    // deliver data to ESProvisioningCallbacks
+    if(gESProvisioningCb.WiFiProvCb != NULL)
+    {
+        gESProvisioningCb.WiFiProvCb(eventData);
     }
     else
     {
-       OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Provisioning is failed callback result is = %d", esResult);
-       // Resetting Enrollee to ONBOARDED_STATE as Enrollee is alreday onboarded in previous step
-       gEnrolleeStatusCb(ES_OK, ES_ON_BOARDED_STATE);
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "WiFiProvCb is NULL");
+        return;
     }
 }
 
-void ESOnboardingCallbackTargetNet(ESResult esResult)
+void ESCloudRsrcCallback(ESResult esResult, ESCloudProvData *eventData)
 {
-    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESOnboardingCallback on target network with result = %d",
-                                                                                        esResult);
-    if(esResult == ES_OK)
+    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESCloudRsrcCallback IN");
+
+    if(esResult != ES_OK)
+    {
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "ESCloudRsrcCallback Error Occured");
+        return;
+    }
+
+    if(gESProvisioningCb.CloudDataProvCb != NULL)
     {
-        gEnrolleeStatusCb(esResult, ES_ON_BOARDED_TARGET_NETWORK_STATE);
+        gESProvisioningCb.CloudDataProvCb(eventData);
     }
     else
     {
-        OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG,
-                    "Onboarding is failed on target network and callback result is = %d", esResult);
-        // Resetting Enrollee state to the ES_PROVISIONED_STATE
-        // as device is already being provisioned with target network creds.
-        gEnrolleeStatusCb(esResult, ES_PROVISIONED_STATE);
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "CloudDataProvCb is NULL");
+        return;
     }
 }
 
-ESResult ESInitEnrollee(OCConnectivityType networkType, const char *ssid, const char *passwd,
-        bool isSecured,
-        ESEnrolleeEventCallback cb)
+void ESDevconfRsrcallback(ESResult esResult, ESDevConfProvData *eventData)
 {
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitEnrollee IN");
-    if(!ESEnrolleeValidateParam(networkType,ssid,passwd,cb))
+    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESDevconfRsrcallback IN");
+
+    if(esResult != ES_OK)
     {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG,
-                            "ESInitEnrollee::Stopping Easy setup due to invalid parameters");
-        return ES_ERROR;
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "ESDevconfRsrcallback Error Occured");
+        return;
+    }
+
+    if(gESProvisioningCb.DevConfProvCb != NULL)
+    {
+        gESProvisioningCb.DevConfProvCb(eventData);
+    }
+    else
+    {
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "DevConfProvCb is NULL");
+        return;
     }
+}
 
-    //Init callback
-    gEnrolleeStatusCb = cb;
+ESResult ESInitEnrollee(bool isSecured, ESResourceMask resourceMask, ESProvisioningCallbacks callbacks)
+{
+    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitEnrollee IN");
 
     gIsSecured = isSecured;
 
-    // TODO : This onboarding state has to be set by lower layer, as they better
-    // knows when actually on-boarding started.
-    cb(ES_ERROR,ES_ON_BOARDING_STATE);
-
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "received callback");
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "onboarding now..");
+    if((resourceMask & ES_WIFI_RESOURCE) == ES_WIFI_RESOURCE)
+    {
+        if(callbacks.WiFiProvCb != NULL)
+        {
+            gESProvisioningCb.WiFiProvCb = callbacks.WiFiProvCb;
+            RegisterWifiRsrcEventCallBack(ESWiFiRsrcCallback);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_ENROLLEE_TAG, "WiFiProvCb NULL");
+            return ES_ERROR;
+        }
+    }
+    if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
+    {
+        if(callbacks.DevConfProvCb != NULL)
+        {
+            gESProvisioningCb.DevConfProvCb = callbacks.DevConfProvCb;
+            RegisterDevConfRsrcEventCallBack(ESDevconfRsrcallback);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_ENROLLEE_TAG, "DevConfProvCb NULL");
+            return ES_ERROR;
+        }
+    }
+    if((resourceMask & ES_CLOUD_RESOURCE) == ES_CLOUD_RESOURCE)
+    {
+        if(callbacks.DevConfProvCb != NULL)
+        {
+            gESProvisioningCb.CloudDataProvCb = callbacks.CloudDataProvCb;
+            RegisterCloudRsrcEventCallBack(ESCloudRsrcCallback);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_ENROLLEE_TAG, "CloudDataProvCb NULL");
+            return ES_ERROR;
+        }
+    }
 
-    if(!ESOnboard(ssid, passwd, ESOnboardingCallback))
+    if(CreateEasySetupResources(gIsSecured, resourceMask) != OC_STACK_OK)
     {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESInitEnrollee::On-boarding failed");
-        cb(ES_ERROR, ES_INIT_STATE);
+        UnRegisterResourceEventCallBack();
+
+        if (DeleteEasySetupResources() != OC_STACK_OK)
+        {
+            OIC_LOG(ERROR, ES_ENROLLEE_TAG, "Deleting prov resource error!!");
+        }
+
         return ES_ERROR;
     }
 
+
     OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitEnrollee OUT");
     return ES_OK;
 }
 
-ESResult ESTerminateEnrollee()
+ESResult ESSetDeviceProperty(ESDeviceProperty *deviceProperty)
 {
-    UnRegisterResourceEventCallBack();
+    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetDeviceProperty IN");
 
-    //Delete Prov resource
-    if (DeleteProvisioningResource() != OC_STACK_OK)
+    if(SetDeviceProperty(deviceProperty) != OC_STACK_OK)
     {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "Deleting prov resource error!!");
+        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetDeviceProperty Error");
         return ES_ERROR;
     }
 
-    OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESTerminateEnrollee success");
+    int modeIdx = 0;
+    while((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
+    {
+        (gESDeviceProperty.WiFi).mode[modeIdx] = (deviceProperty->WiFi).mode[modeIdx];
+        OIC_LOG_V(INFO, ES_ENROLLEE_TAG, "WiFi Mode : %d", (gESDeviceProperty.WiFi).mode[modeIdx]);
+        modeIdx ++;
+    }
+    (gESDeviceProperty.WiFi).freq = (deviceProperty->WiFi).freq;
+    OIC_LOG_V(INFO, ES_ENROLLEE_TAG, "WiFi Freq : %d", (gESDeviceProperty.WiFi).freq);
+
+    OICStrcpy((gESDeviceProperty.DevConf).deviceName, MAX_DEVICELEN, (deviceProperty->DevConf).deviceName);
+    OIC_LOG_V(INFO, ES_ENROLLEE_TAG, "Device Name : %s", (gESDeviceProperty.DevConf).deviceName);
+
+    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetDeviceProperty OUT");
     return ES_OK;
 }
 
-ESResult ESInitProvisioning()
+ESResult ESSetState(ESEnrolleeState esState)
 {
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitProvisioning <<IN>>");
+    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetState IN");
 
-    if (CreateProvisioningResource(gIsSecured) != OC_STACK_OK)
+    if(esState <= 0 || esState >= 6)
     {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "CreateProvisioningResource error");
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "Invalid ESEnrolleeState : %d", esState);
         return ES_ERROR;
     }
 
-    RegisterResourceEventCallBack(ESProvisioningCallback);
+    if(SetEnrolleeState(esState) != OC_STACK_OK)
+    {
+        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetState Error");
+        return ES_ERROR;
+    }
 
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitProvisioning <<OUT>>");
-    return ES_RESOURCECREATED;
+    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetState OUT");
+    return ES_OK;
 }
 
-static bool ESEnrolleeValidateParam(OCConnectivityType networkType, const char *ssid,
-                                                const char *passwd, ESEnrolleeEventCallback cb)
+ESResult ESSetErrorCode(ESErrorCode esErrCode)
 {
-    if (!ssid || !passwd || !cb)
+    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetErrorCode IN");
+
+    if(esErrCode <= 0 || esErrCode >= 7)
     {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESEnrolleeValidateParam - Invalid parameters");
-        return false;
+        if(esErrCode != 999)
+        {
+            OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "Invalid ESErrorCode : %d", esErrCode);
+            return ES_ERROR;
+        }
+    }
+
+    if(SetEnrolleeErrCode(esErrCode) != OC_STACK_OK)
+    {
+        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetErrorCode Error");
+        return ES_ERROR;
     }
-    return true;
+
+    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetErrorCode OUT");
+    return ES_OK;
 }
 
+ESResult ESTerminateEnrollee()
+{
+    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESTerminateEnrollee IN");
+
+    UnRegisterResourceEventCallBack();
+
+    //Delete Prov resource
+    if (DeleteEasySetupResources() != OC_STACK_OK)
+    {
+        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "Deleting prov resource error!!");
+        return ES_ERROR;
+    }
+
+    OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESTerminateEnrollee success");
+    return ES_OK;
+}
diff --git a/service/easy-setup/enrollee/src/onboarding.c b/service/easy-setup/enrollee/src/onboarding.c
deleted file mode 100644 (file)
index da9acaa..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * @file
- *
- * This file has methods for on-boarding the Enrollee device.
- * This will contain template methods that will have core business logic & negotiation algorithm
- * on various on-boarding methods.
- */
-
-#include "easysetup.h"
-#include "softap.h"
-#include "onboarding.h"
-
-#include "logger.h"
-#include "resourcehandler.h"
-
-/**
- * @var ES_ENROLLEE_TAG
- * @brief Logging tag for module name.
- */
-#define ES_ENROLLEE_TAG "ES_SOFTAP"
-
-/**
- * It will return true on-boarding type is soft AP
- */
-bool ESSoftapOnboarding()
-{
-    // TODO: To be changed based on user config. Current version, hardcoded to SoftAp onboarding
-    return true;
-}
-
-/**
- * It will return true on-boarding type is BLE
- */
-bool ESBleOnboarding()
-{
-    //BLE onboarding is not supported with current version.
-    return false;
-}
-
-/**
- * It will do onboarding based on the user's configuration.
- */
-bool ESOnboard(const char * ssid, const char* passwd, ESEnrolleeNetworkEventCallback cb)
-{
-    OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "ESOnboard IN");
-
-    if (ESSoftapOnboarding())
-    {
-        if (ESSoftapAtEnrollee())
-        {
-            OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "Create SoftAp at enrollee");
-            ESCreateSoftap(ssid, passwd, cb);
-        }
-        else
-        {
-            OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "Connecting to Mediator SoftAp");
-            ConnectToWiFiNetwork(ssid, passwd, cb);
-        }
-        return true;
-    }
-    else if (ESBleOnboarding())
-    {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESOnboard::Ble onboarding is not supported");
-        // TODO:
-        return false;
-    }
-    else
-    {
-        // TODO:
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESOnboard::Invalid onboarding option");
-        return false;
-    }
-}
-
diff --git a/service/easy-setup/enrollee/src/onboarding.h b/service/easy-setup/enrollee/src/onboarding.h
deleted file mode 100644 (file)
index dc0ecd6..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-
-#ifndef EASYSETUP_ENROLLEE_ONBOARDING_H__
-#define EASYSETUP_ENROLLEE_ONBOARDING_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus:$
-
-#include "networkhandler.h"
-
-/**
- * @file
- *
- * This file contains APIs to on-board ( connect ) Enrollee device into Ad-hoc network
- * @Note :  Some of the APIs of this file need to be modified by the OEM according to the
- *          device configuration
- */
-
-/**
- * This function on-board Enrollee device onto ad-hoc network.
- * @param ssid                              SSID of the target SoftAP network to which the Enrollee
- *                                          is connecting.
- * @param passwd                            Password of the target SoftAP network to which the
- *                                          Enrollee is connecting.
- * @param ESEnrolleeNetworkEventCallback    Callback function for result update
- * @return ::True, if on-boarding is successful.
- */
-
-bool ESOnboard(const char * ssid, const char* passwd, ESEnrolleeNetworkEventCallback cb);
-
-/**
- * This function verify if the on-boarding is through SoftAP.
- * @return ::True, if Soft AP on-boarding enabled.
- * @Note : This API to be modified by the OEM according to the device configuration
- */
-bool ESSoftapOnboarding();
-
-/**
- * This function verify if the on-boarding is through Ble beacons.
- * @return ::True, if Ble beacons enabled.
- * @Note : This API to be modified by the OEM according to the device configuration
- */
-bool ESBleOnboarding();
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-
-#endif /* EASYSETUP_ENROLLEE_ONBOARDING_H__ */
index 249d586..2917799 100755 (executable)
  * connect to the target network
  */
 static ProvResource gProvResource;
+static WiFiResource gWiFiResource;
+static CloudResource gCloudResource;
+static DevConfResource gDevConfResource;
 
 /**
- * @var gNetResource
- * @brief Structure forr holding the Provisioning status of network information
+ * @var gWiFiData
+ * @brief Structure for holding the target information required to
+ * connect to the target network
+ */
+ static ESWiFiProvData gWiFiData;
+
+/**
+ * @var gDevConfData
+ * @brief Structure for holding the device information
  */
-static NetResource gNetResource;
+ static ESDevConfProvData gDevConfData;
+
+/**
+ * @var gCloudData
+ * @brief Structure for holding the cloud information required to
+ * connect to CI Server
+ */
+ static ESCloudProvData gCloudData;
+
+
 
 //-----------------------------------------------------------------------------
 // Private internal function prototypes
@@ -56,20 +75,43 @@ const char *getResult(OCStackResult result);
 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
-OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest);
+void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
+void updateWiFiResource(OCRepPayload* input);
+void updateCloudResource(OCRepPayload* input);
+void updateDevConfResource(OCRepPayload* input);
 
-ESEnrolleeResourceEventCallback gNetworkInfoProvEventCb = NULL;
+ESWiFiCB gWifiRsrcEvtCb = NULL;
+ESCloudCB gCloudRsrcEvtCb = NULL;
+ESDevConfCB gDevConfRsrcEvtCb = NULL;
 
-void RegisterResourceEventCallBack(ESEnrolleeResourceEventCallback cb)
+void RegisterWifiRsrcEventCallBack(ESWiFiCB cb)
 {
-    gNetworkInfoProvEventCb = cb;
+    gWifiRsrcEvtCb = cb;
+}
+
+void RegisterCloudRsrcEventCallBack(ESCloudCB cb)
+{
+    gCloudRsrcEvtCb = cb;
+}
+
+void RegisterDevConfRsrcEventCallBack(ESDevConfCB cb)
+{
+    gDevConfRsrcEvtCb = cb;
 }
 
 void UnRegisterResourceEventCallBack()
 {
-    if (gNetworkInfoProvEventCb)
+    if (gWifiRsrcEvtCb)
+    {
+        gWifiRsrcEvtCb = NULL;
+    }
+    if (gCloudRsrcEvtCb)
+    {
+        gCloudRsrcEvtCb = NULL;
+    }
+    if (gDevConfRsrcEvtCb)
     {
-        gNetworkInfoProvEventCb = NULL;
+        gDevConfRsrcEvtCb = NULL;
     }
 }
 
@@ -77,174 +119,332 @@ void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
 {
     if (name != NULL && pass != NULL)
     {
-        OICStrcpy(name, MAXSSIDLEN, gProvResource.tnn);
-        OICStrcpy(pass, MAXNETCREDLEN, gProvResource.cd);
+        OICStrcpy(name, MAX_SSIDLEN, gWiFiResource.ssid);
+        OICStrcpy(pass, MAX_CREDLEN, gWiFiResource.cred);
     }
 }
 
-OCStackResult CreateProvisioningResource(bool isSecured)
+OCStackResult initProvResource(bool isSecured)
 {
-    gProvResource.ps = ES_PS_NEED_PROVISIONING;
-    gProvResource.tr = ES_PS_TRIGGER_INIT_VALUE;
-
-    gProvResource.tnt = CT_ADAPTER_IP;
-    OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), "Unknown");
-    OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), "Unknown");
+    gProvResource.status = NO_PROVISION;
+    gProvResource.trigger = false;
+    gProvResource.lastErrCode = ES_ERRCODE_NONE;
+    OICStrcpy(gProvResource.errorMessage, MAX_ERRMSGLEN, "");
+    OICStrcpy(gProvResource.ocfWebLinks, MAX_WEBLINKLEN, "");
 
     OCStackResult res = OC_STACK_ERROR;
     if (isSecured)
     {
-        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
+        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_RES_TYPE_PROV,
         OC_RSRVD_INTERFACE_DEFAULT,
         OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
-    }
-    else
+    }else
     {
-        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
+        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_RES_TYPE_PROV,
         OC_RSRVD_INTERFACE_DEFAULT,
         OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
     }
+    if(res)
+    {
+        OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
+        return res;
+    }
+
+    res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_LL);
+    if(res)
+    {
+        OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
+        return res;
+    }
+    res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_BATCH);
+    if(res)
+    {
+        OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
+        return res;
+    }
 
     OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
     return res;
 }
 
-OCStackResult DeleteProvisioningResource()
+OCStackResult initWiFiResource(bool isSecured)
 {
-    OCStackResult res = OCDeleteResource(gProvResource.handle);
-    if (res != OC_STACK_OK)
+    OCStackResult res = OC_STACK_ERROR;
+
+    gWiFiResource.supportedFreq = WiFi_BOTH;
+    gWiFiResource.supportedMode[0] = WiFi_11A;
+    gWiFiResource.supportedMode[1] = WiFi_11B;
+    gWiFiResource.supportedMode[2] = WiFi_11G;
+    gWiFiResource.supportedMode[3] = WiFi_11N;
+    gWiFiResource.numMode = 4;
+    gWiFiResource.authType = NONE_AUTH;
+    gWiFiResource.encType = NONE_ENC;
+    OICStrcpy(gWiFiResource.ssid, sizeof(gWiFiResource.ssid), "");
+    OICStrcpy(gWiFiResource.cred, sizeof(gWiFiResource.cred), "");
+
+    if (isSecured)
     {
-        OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
+        res = OCCreateResource(&gWiFiResource.handle, OC_RSRVD_ES_RES_TYPE_WIFI,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_WIFI, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
+    }else
+    {
+        res = OCCreateResource(&gWiFiResource.handle, OC_RSRVD_ES_RES_TYPE_WIFI,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_WIFI, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
     }
 
+    OIC_LOG_V(INFO, ES_RH_TAG, "Created WiFi resource with result: %s", getResult(res));
     return res;
+
 }
 
-OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
+OCStackResult initCloudServerResource(bool isSecured)
 {
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-    if (!ehRequest)
+    OCStackResult res = OC_STACK_ERROR;
+
+    OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), "");
+    OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), "");
+    OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), "");
+
+    if (isSecured)
     {
-        OIC_LOG(ERROR, ES_RH_TAG, "Request is Null");
-        return ehResult;
-    }
-    if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+        res = OCCreateResource(&gCloudResource.handle, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_CLOUDSERVER, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
+    }else
     {
-        OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
-        return ehResult;
+        res = OCCreateResource(&gCloudResource.handle, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_CLOUDSERVER, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
     }
 
-    OCRepPayload *getResp = constructResponse(ehRequest);
-    if (!getResp)
+    OIC_LOG_V(INFO, ES_RH_TAG, "Created CloudServer resource with result: %s", getResult(res));
+    return res;
+
+}
+
+OCStackResult initDevConfResource(bool isSecured)
+{
+    OCStackResult res = OC_STACK_ERROR;
+
+    OICStrcpy(gDevConfResource.devName, sizeof(gDevConfResource.devName), "");
+    OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), "");
+    OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), "");
+
+    if (isSecured)
     {
-        OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
-        return OC_EH_ERROR;
+        res = OCCreateResource(&gDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
+    }else
+    {
+        res = OCCreateResource(&gDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
     }
 
-    *payload = getResp;
-    ehResult = OC_EH_OK;
+    OIC_LOG_V(INFO, ES_RH_TAG, "Created DevConf resource with result: %s", getResult(res));
+    return res;
 
-    return ehResult;
 }
 
-OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
+void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
 {
-    OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-    if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+    OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.status %d", gProvResource.status);
+
+    if(ehRequest->query)
     {
-        OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
-        return ehResult;
+        if(strstr(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
+        {
+        // When Provisioning resource has a POST with BatchInterface
+            updateCloudResource(input);
+            updateWiFiResource(input);
+            updateDevConfResource(input);
+        }
     }
+}
 
-    OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
-    if (!input)
+void updateWiFiResource(OCRepPayload* input)
+{
+    char* ssid = NULL;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
     {
-        OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
-        return ehResult;
+        OICStrcpy(gWiFiResource.ssid, sizeof(gWiFiResource.ssid), ssid);
+        OICStrcpy(gWiFiData.ssid, sizeof(gWiFiData.ssid), ssid);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.ssid : %s", gWiFiResource.ssid);
     }
 
-    char* tnn;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn))
+    char* cred = NULL;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
     {
-        OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), tnn);
-        OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.tnn %s", gProvResource.tnn);
+        OICStrcpy(gWiFiResource.cred, sizeof(gWiFiResource.cred), cred);
+        OICStrcpy(gWiFiData.pwd, sizeof(gWiFiData.pwd), cred);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.cred %s", gWiFiResource.cred);
+    }
 
-        gProvResource.ps = ES_PS_PROVISIONING_COMPLETED;
+    int64_t authType = -1;
+    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_AUTHTYPE, &authType))
+    {
+        gWiFiResource.authType = authType;
+        gWiFiData.authtype = gWiFiResource.authType;
+        OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.authType %u", gWiFiResource.authType);
     }
 
-    char* cd;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
+    int64_t encType = -1;
+    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ENCTYPE, &encType))
     {
-        OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), cd);
-        OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd);
+        gWiFiResource.encType = encType;
+        gWiFiData.enctype = gWiFiResource.encType;
+        OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.encType %u", gWiFiResource.encType);
     }
 
-    OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %lld", gProvResource.ps);
+    if(ssid || cred || authType!= -1 || encType != -1)
+    {
+        OIC_LOG(INFO, ES_RH_TAG, "Send WiFiRsrc Callback To ES");
 
-    int64_t tr;
-    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_TR, &tr))
+        // TODO : Need to check appropriateness of gWiFiData
+        if(gWifiRsrcEvtCb != NULL)
+        {
+            gWifiRsrcEvtCb(ES_OK, &gWiFiData);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "gWifiRsrcEvtCb is NULL");
+        }
+    }
+
+}
+
+void updateCloudResource(OCRepPayload* input)
+{
+    char *authCode = NULL;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &authCode))
     {
-        // Triggering
-        gProvResource.tr = tr;
+        OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), authCode);
+        OICStrcpy(gCloudData.authCode, sizeof(gCloudData.authCode), authCode);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authCode %s", gCloudResource.authCode);
     }
 
-    //ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
-    // A new request for provisioning means overriding existing network provisioning information.
-    if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED && tr == ES_PS_TRIGGER_CONNECTION)
+    char *authProvider = NULL;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &authProvider))
+    {
+        OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), authProvider);
+        OICStrcpy(gCloudData.authProvider, sizeof(gCloudData.authProvider), authProvider);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authServerUrl %s", gCloudResource.authProvider);
+    }
+
+    char *ciServer = NULL;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CISERVER, &ciServer))
+    {
+        OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), ciServer);
+        OICStrcpy(gCloudData.ciServer, sizeof(gCloudData.ciServer), ciServer);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.ciServer %s", gCloudResource.ciServer);
+    }
+
+    if(authCode || authProvider || ciServer)
     {
-        OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed."
-                "Tiggering the network connection");
+        OIC_LOG(INFO, ES_RH_TAG, "Send CloudRsrc Callback To ES");
 
-        if (gNetworkInfoProvEventCb)
+        // TODO : Need to check appropriateness of gCloudData
+        if(gCloudRsrcEvtCb != NULL)
         {
-            gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES);
-            ehResult = OC_EH_OK;
+            gCloudRsrcEvtCb(ES_OK, &gCloudData);
         }
         else
         {
-            gProvResource.tr = ES_PS_TRIGGER_INIT_VALUE;
-            OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL."
-                    "Network handler not registered. Failed to connect to the network");
-            ehResult = OC_EH_ERROR;
+            OIC_LOG(ERROR, ES_RH_TAG, "gCloudRsrcEvtCb is NULL");
         }
+    }
+}
 
-        return ehResult;
+void updateDevConfResource(OCRepPayload* input)
+{
+    char *country = NULL;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &country))
+    {
+        OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), country);
+        OICStrcpy(gDevConfData.country, sizeof(gDevConfData.country), country);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.country %s", gDevConfResource.country);
     }
-    else if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED)
+
+    char *language = NULL;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &language))
     {
-        OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed. "
-                "This a request to override the existing the network provisioning information");
+        OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), language);
+        OICStrcpy(gDevConfData.language, sizeof(gDevConfData.language), language);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.language %s", gDevConfResource.language);
     }
-    else
+
+    if(country || language)
     {
-        OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
+        OIC_LOG(INFO, ES_RH_TAG, "Send DevConfRsrc Callback To ES");
+
+        // TODO : Need to check appropriateness of gDevConfData
+        if(gDevConfRsrcEvtCb != NULL)
+        {
+            gDevConfRsrcEvtCb(ES_OK, &gDevConfData);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "gDevConfRsrcEvtCb is NULL");
+        }
     }
+}
 
-    OCRepPayload *getResp = constructResponse(ehRequest);
-    if (!getResp)
+OCRepPayload* constructResponseOfWiFi()
+{
+    OCRepPayload* payload = OCRepPayloadCreate();
+    if (!payload)
     {
-        OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
-        return OC_EH_ERROR;
+        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+        return NULL;
     }
 
-    *payload = getResp;
-    ehResult = OC_EH_OK;
+    OIC_LOG(INFO, ES_RH_TAG, "constructResponse wifi res");
+    OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_WIFI);
 
-    return ehResult;
+    size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
+    OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)gWiFiResource.supportedMode, dimensions);
+
+    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, gWiFiResource.ssid);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CRED, gWiFiResource.cred);
+    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) gWiFiResource.authType);
+    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) gWiFiResource.encType);
+
+    printf("%s\n", gWiFiResource.ssid);
+
+    return payload;
 }
 
-OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * ehRequest,
-        OCRepPayload** payload)
+OCRepPayload* constructResponseOfCloud()
 {
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
+    OCRepPayload* payload = OCRepPayloadCreate();
+    if (!payload)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+        return NULL;
+    }
 
-    return ehResult;
+    OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
+    OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_CLOUDSERVER);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHCODE, gCloudResource.authCode);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHPROVIDER, gCloudResource.authProvider);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CISERVER, gCloudResource.ciServer);
+
+    return payload;
 }
 
-OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
+OCRepPayload* constructResponseOfDevConf()
 {
     OCRepPayload* payload = OCRepPayloadCreate();
     if (!payload)
@@ -253,22 +453,297 @@ OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
         return NULL;
     }
 
-    if (ehRequest->resource == gProvResource.handle)
+    OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
+    OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_DEVCONF);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_DEVNAME, gDevConfResource.devName);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LANGUAGE, gDevConfResource.language);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_COUNTRY, gDevConfResource.country);
+
+    return payload;
+}
+
+OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
+{
+    OCRepPayload* payload = OCRepPayloadCreate();
+    if (!payload)
     {
-        OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
-        OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
-        OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS, gProvResource.ps);
-        OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TNT, gProvResource.tnt);
+        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+        return NULL;
     }
-    else if (ehRequest->requestHandle == gNetResource.handle)
+
+    OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
+    OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
+    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, gProvResource.status);
+    OCRepPayloadSetPropBool(payload, OC_RSRVD_ES_TRIGGER, gProvResource.trigger);
+    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, gProvResource.lastErrCode);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_ERRORMESSAGE, gProvResource.errorMessage);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LINKS, gProvResource.ocfWebLinks);
+
+    if(ehRequest->query)
     {
+        if(strstr(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
+        {// When Provisioning resource has a GET with BatchInterface
+            payload->next = constructResponseOfWiFi();
 
-        OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_NET);
-        OCRepPayloadSetPropInt(payload, "ant", gNetResource.ant[0]);
+            if(payload->next)
+                payload->next->next = constructResponseOfCloud();
+            else
+                return payload;
+
+            if(payload->next->next)
+                payload->next->next->next = constructResponseOfDevConf();
+            else
+                return payload;
+        }
     }
+
     return payload;
 }
 
+
+OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask)
+{
+    OCStackResult res = OC_STACK_ERROR;
+    bool maskFlag = false;
+
+    res = initProvResource(isSecured);
+    if(res != OC_STACK_OK)
+    {
+        // TODO: destroy logic will be added
+        OIC_LOG_V(ERROR, ES_RH_TAG, "initProvResource result: %s", getResult(res));
+
+        return res;
+    }
+
+    if((resourceMask & ES_WIFI_RESOURCE) == ES_WIFI_RESOURCE)
+    {
+        maskFlag = true;
+        res = initWiFiResource(isSecured);
+        if(res != OC_STACK_OK)
+        {
+            OIC_LOG_V(ERROR, ES_RH_TAG, "initWiFiResource result: %s", getResult(res));
+            return res;
+        }
+
+        res = OCBindResource(gProvResource.handle, gWiFiResource.handle);
+        if(res != OC_STACK_OK)
+        {
+            OIC_LOG_V(ERROR, ES_RH_TAG, "Bind WiFiResource result: %s", getResult(res));
+            return res;
+        }
+
+    }
+
+    if((resourceMask & ES_CLOUD_RESOURCE) == ES_CLOUD_RESOURCE)
+    {
+        maskFlag = true;
+        res = initCloudServerResource(isSecured);
+        if(res != OC_STACK_OK)
+        {
+            OIC_LOG_V(ERROR, ES_RH_TAG, "initCloudResource result: %s", getResult(res));
+            return res;
+        }
+
+        res = OCBindResource(gProvResource.handle, gCloudResource.handle);
+        if(res != OC_STACK_OK)
+        {
+            OIC_LOG_V(ERROR, ES_RH_TAG, "Bind CloudResource result: %s", getResult(res));
+            return res;
+        }
+    }
+
+    if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
+    {
+        maskFlag = true;
+        res = initDevConfResource(isSecured);
+        if(res != OC_STACK_OK)
+        {
+            OIC_LOG_V(ERROR, ES_RH_TAG, "initDevConf result: %s", getResult(res));
+            return res;
+        }
+
+        res = OCBindResource(gProvResource.handle, gDevConfResource.handle);
+        if(res != OC_STACK_OK)
+        {
+            OIC_LOG_V(ERROR, ES_RH_TAG, "Bind DevConfResource result: %s", getResult(res));
+            return res;
+        }
+    }
+
+
+    if(maskFlag == false)
+    {
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Invalid ResourceMask");
+        return OC_STACK_ERROR;
+
+    }
+
+    OIC_LOG_V(INFO, ES_RH_TAG, "Created all resources with result: %s", getResult(res));
+
+    return res;
+}
+
+OCStackResult DeleteProvisioningResource()
+{
+    OCStackResult res = OCDeleteResource(gProvResource.handle);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
+    }
+
+    return res;
+}
+
+OCStackResult DeleteEasySetupResources()
+{
+    OCStackResult res = OCDeleteResource(gWiFiResource.handle);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting WiFi resource error with result: %s", getResult(res));
+    }
+    res = OCDeleteResource(gCloudResource.handle);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting CloudServer resource error with result: %s", getResult(res));
+    }
+    res = OCDeleteResource(gDevConfResource.handle);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting DevConf resource error with result: %s", getResult(res));
+    }
+
+    res = OCDeleteResource(gProvResource.handle);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
+    }
+
+    return res;
+}
+
+OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
+{
+    OCEntityHandlerResult ehResult = OC_EH_ERROR;
+    if (!ehRequest)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Request is Null");
+        return ehResult;
+    }
+    if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
+        return ehResult;
+    }
+
+    OCRepPayload *getResp = NULL;
+
+    if(ehRequest->resource == gProvResource.handle)
+        getResp = constructResponseOfProv(ehRequest);
+    else if(ehRequest->resource == gWiFiResource.handle)
+        getResp = constructResponseOfWiFi();
+    else if(ehRequest->resource == gCloudResource.handle)
+        getResp = constructResponseOfCloud();
+    else if(ehRequest->resource == gDevConfResource.handle)
+        getResp = constructResponseOfDevConf();
+
+    if (!getResp)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
+        return OC_EH_ERROR;
+    }
+
+    *payload = getResp;
+    ehResult = OC_EH_OK;
+
+    return ehResult;
+}
+
+OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
+{
+    OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
+    OCEntityHandlerResult ehResult = OC_EH_ERROR;
+    if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
+        return ehResult;
+    }
+
+    OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
+    if (!input)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
+        return ehResult;
+    }
+
+    if(ehRequest->resource == gProvResource.handle)
+        updateProvResource(ehRequest, input);
+    else if(ehRequest->resource == gWiFiResource.handle)
+        updateWiFiResource(input);
+    else if(ehRequest->resource == gCloudResource.handle)
+        updateCloudResource(input);
+    else if(ehRequest->resource == gDevConfResource.handle)
+        updateDevConfResource(input);
+
+    // TBD : Discuss about triggering flag (to be existed or not)
+    // ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
+    // A new request for provisioning means overriding existing network provisioning information.
+    // if (gProvResource.trigger)
+    // {
+    //     OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed."
+    //             "Tiggering the network connection");
+
+    //     if (gNetworkInfoProvEventCb)
+    //     {
+    //         gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES);
+    //         ehResult = OC_EH_OK;
+    //     }
+    //     else
+    //     {
+    //         OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL."
+    //                 "Network handler not registered. Failed to connect to the network");
+    //         ehResult = OC_EH_ERROR;
+    //         return ehResult;
+    //     }
+    // }
+    // else
+    // {
+    //     OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
+    // }
+
+    OCRepPayload *getResp = NULL;
+    if(ehRequest->resource == gProvResource.handle)
+        getResp = constructResponseOfProv(ehRequest);
+    else if(ehRequest->resource == gWiFiResource.handle)
+        getResp = constructResponseOfWiFi();
+    else if(ehRequest->resource == gCloudResource.handle)
+        getResp = constructResponseOfCloud();
+    else if(ehRequest->resource == gDevConfResource.handle)
+        getResp = constructResponseOfDevConf();
+
+    if (gProvResource.trigger)// Trigger false should be restored after executed
+        gProvResource.trigger = false;
+
+    if (!getResp)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
+        return OC_EH_ERROR;
+    }
+
+    *payload = getResp;
+    ehResult = OC_EH_OK;
+
+    return ehResult;
+}
+
+OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * ehRequest,
+        OCRepPayload** payload)
+{
+    (void) ehRequest;
+    (void) payload;
+    OCEntityHandlerResult ehResult = OC_EH_ERROR;
+
+    return ehResult;
+}
 /**
  * This is the entity handler for the registered resource.
  * This is invoked by OCStack whenever it recevies a request for this resource.
@@ -296,8 +771,7 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
             OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
 
             //PUT request will be handled in the internal implementation
-            if (gProvResource.handle != NULL
-                    && entityHandlerRequest->resource == gProvResource.handle)
+            if (gProvResource.handle != NULL)
             {
                 ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
             }
@@ -310,8 +784,7 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
         else if (OC_REST_POST == entityHandlerRequest->method)
         {
             OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
-            if (gProvResource.handle != NULL
-                    && entityHandlerRequest->resource == gProvResource.handle)
+            if (gProvResource.handle != NULL)
             {
                 ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
             }
@@ -349,6 +822,50 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
     return ehRet;
 }
 
+OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty)
+{
+    OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty IN");
+
+    gWiFiResource.supportedFreq = (deviceProperty->WiFi).freq;
+    OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Freq : %d", gWiFiResource.supportedFreq);
+
+    int modeIdx = 0;
+    while((deviceProperty->WiFi).mode[modeIdx] != WiFi_EOF)
+    {
+        gWiFiResource.supportedMode[modeIdx] = (deviceProperty->WiFi).mode[modeIdx];
+        OIC_LOG_V(INFO, ES_RH_TAG, "WiFi Mode : %d", gWiFiResource.supportedMode[modeIdx]);
+        modeIdx ++;
+    }
+    gWiFiResource.numMode = modeIdx;
+
+    OICStrcpy(gDevConfResource.devName, MAX_DEVICELEN, (deviceProperty->DevConf).deviceName);
+    OIC_LOG_V(INFO, ES_RH_TAG, "Device Name : %s", gDevConfResource.devName);
+
+    OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty OUT");
+    return OC_STACK_OK;
+}
+
+OCStackResult SetEnrolleeState(ESEnrolleeState esState)
+{
+    OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState IN");
+
+    gProvResource.status = esState;
+    OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee Status : %d", gProvResource.status);
+
+    OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState OUT");
+    return OC_STACK_OK;
+}
+
+OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
+{
+    OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode IN");
+
+    gProvResource.lastErrCode = esErrCode;
+    OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee ErrorCode : %d", gProvResource.lastErrCode);
+
+    OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode OUT");
+    return OC_STACK_OK;
+}
 const char *getResult(OCStackResult result)
 {
     switch (result)
old mode 100644 (file)
new mode 100755 (executable)
index ad470dc..cca35ed
@@ -24,7 +24,6 @@
 #include "logger.h"
 #include "ocstack.h"
 #include "escommon.h"
-#include "networkhandler.h"
 #include "octypes.h"
 
 #ifndef ES_RESOURCE_HANDLER_H_
 extern "C" {
 #endif
 
-typedef void (*ESEnrolleeResourceEventCallback)(ESResult);
+typedef void (*ESWiFiCB) (ESResult, ESWiFiProvData *);
+typedef void (*ESCloudCB) (ESResult, ESCloudProvData *);
+typedef void (*ESDevConfCB) (ESResult, ESDevConfProvData *);
 
 /* Structure to represent a Light resource */
 typedef struct PROVRESOURCE
 {
     OCResourceHandle handle;
-    int64_t ps; // provisiong status, 1 : need to provisioning, 2 : Connected to Enroller.
-    int64_t tr; // Trigger network connection, 0 : Init value, 1 : Connected to the target network.
-    int64_t tnt; // target network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
-    char tnn[MAXSSIDLEN]; // target network name, i.e. SSID for WLAN, MAC address for BT.
-    char cd[MAXNETCREDLEN]; // credential information.
+    ProvStatus status; // provisiong status
+    bool trigger; // Trigger network connection, 0 : Init value, 1 : Connected to the target network.
+    ESErrorCode lastErrCode;
+    char errorMessage[MAX_ERRMSGLEN];
+    char ocfWebLinks[MAX_WEBLINKLEN];
 } ProvResource;
 
-/* Structure to represent a Light resource */
-typedef struct NETRESOURCE
+typedef struct
 {
     OCResourceHandle handle;
-    int64_t cnt; // current network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
-    int64_t ant[MAXNUMTYPE]; // available network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
-    char ipaddr[MAXADDRLEN]; // ip address.
-    char cnn[MAXSSIDLEN]; // current network name.
-} NetResource;
+    WIFI_MODE supportedMode[NUM_WIFIMODE];
+    uint8_t numMode;        // the number of device's supported wifi modes
+    WIFI_FREQ supportedFreq;
+    char ssid[MAX_SSIDLEN]; // target network name, i.e. SSID for WLAN, MAC address for BT.
+    char cred[MAX_CREDLEN]; // credential information.
+    WIFI_AUTHTYPE authType;
+    WIFI_ENCTYPE encType;
+} WiFiResource;
+
+typedef struct
+{
+    OCResourceHandle handle;
+    char authCode[OIC_STRING_MAX_VALUE];
+    char authProvider[OIC_STRING_MAX_VALUE];
+    char ciServer[OIC_STRING_MAX_VALUE];
+} CloudResource;
+
+typedef struct
+{
+    OCResourceHandle handle;
+    char devName[MAX_DEVICELEN];
+    char language[OIC_STRING_MAX_VALUE];
+    char country[OIC_STRING_MAX_VALUE];
+} DevConfResource;
+
+
+OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask);
+OCStackResult DeleteEasySetupResources();
 
-OCStackResult CreateProvisioningResource(bool isSecured);
-OCStackResult DeleteProvisioningResource();
+OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty);
+OCStackResult SetEnrolleeState(ESEnrolleeState esState);
+OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode);
 
 void GetTargetNetworkInfoFromProvResource(char *, char *);
-void RegisterResourceEventCallBack(ESEnrolleeResourceEventCallback);
+void RegisterWifiRsrcEventCallBack(ESWiFiCB);
+void RegisterCloudRsrcEventCallBack(ESCloudCB);
+void RegisterDevConfRsrcEventCallBack(ESDevConfCB);
 void UnRegisterResourceEventCallBack(void);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif //ES_RESOURCE_HANDLER_H_
\ No newline at end of file
+#endif //ES_RESOURCE_HANDLER_H_
diff --git a/service/easy-setup/enrollee/src/softap.c b/service/easy-setup/enrollee/src/softap.c
deleted file mode 100644 (file)
index 00df2a9..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-//      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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * These are adapter APIs will make caller modules agnostic to platform.
- */
-
-#include "softapnative.h"
-#include "easysetup.h"
-#include "softap.h"
-#include "networkhandler.h"
-
-void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
-                                                            const char* device_name );
-
-ESEnrolleeNetworkEventCallback gCallback;
-
-/**
- * It will return Device which is creating Soft AP.
- * i.e.Enrollee or Mediator.
- * This decision is based on, what is the value set for ES_SOFTAP_MODE in build command as well as
- * in iotivity.spec file.
- */
-DeviceRole ESSoftapHost()
-{
-#ifdef ENROLLEE_SOFTAP
-    //SoftAp at enrollee
-    return ENROLLEE;
-#else
-    //SoftAp at mediator
-    return MEDIATOR;
-#endif
-}
-
-/**
- * It will return true if the Soft AP is created at Enrollee device
- */
-bool ESSoftapAtEnrollee()
-{
-    return ( ESSoftapHost() == ENROLLEE) ? true : false;
-}
-
-/**
- * It will return true if the Soft AP is created at Mediator device
- */
-bool ESSoftapAtMediator()
-{
-    return (ESSoftapHost() == MEDIATOR) ? true : false;
-}
-
-/**
- * This API will map result returned from the native to the caller.
- * Callback API's signature needs to be modified under build switch according
- * to the underline platform.
- */
-void ESCreateSoftapCallback(int result, const char *ip, const char* mac_addr,
-                                                                const char* device_name)
-{
-    if(SOFTAP_SUCCESS ==  result) //on Success
-    {
-        gCallback(ES_OK);
-    }
-    else //on Failure
-    {
-        gCallback(ES_ERROR);
-    }
-}
-
-/**
- * This API will create the softap at enrollee
- */
-void ESCreateSoftap(const char * ssid, const char* passwd, ESEnrolleeNetworkEventCallback cb)
-{
-    gCallback = cb;
-
-    // TODO: To be implemented
-    // Create Soft AP through native APIs -- start
-    // native API call by and pass ESCreateSoftapCallback() as callback
-    ESCreateSoftapNative(ssid, passwd,ESCreateSoftapCallback);
-    // Create Soft AP through native APIs -- end
-}
-
diff --git a/service/easy-setup/enrollee/src/softap.h b/service/easy-setup/enrollee/src/softap.h
deleted file mode 100644 (file)
index df532de..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-
-#ifndef EASYSETUP_ENROLLEE_SOFTAP_H__
-#define EASYSETUP_ENROLLEE_SOFTAP_H__
-
-#include "escommon.h"
-#include "networkhandler.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @file
- *
- * This file contains platform agnostic API for creation of Soft AP
- * @Note :  Some of the APIs of this file need to be modified by the OEM according to the device
- *          configuration
- */
-
-/**
- * This function verify if the Soft AP is created at Enrollee device.
- * @return ::True, if Soft AP is created at Enrollee device.
- * @Note : This API needs to be modified by the OEM according to the device configuration
- */
-
-bool ESSoftapAtEnrollee();
-
-/**
- * This function verify if the Soft AP is created at Mediator device.
- * @return ::True, if Soft AP is created at Mediator device.
- * @Note : This API needs to be modified by the OEM according to the device configuration
- */
-
-bool ESSoftapAtMediator();
-
-
-/**
- * This function finds which Device (Enrollee or Mediator) is creating Soft AP.
- * @return ::DeviceRole (ENROLLEE or MEDIATOR)
- * @Note : This API needs to be modified by the OEM according to the device configuration
- */
-
-DeviceRole ESSoftapHost();
-
-/**
- * This function Initializes the EasySetup. This API must be called prior to invoking any other API
- *
- * @param ssid                  SSID of the target SoftAP network to which the Enrollee is
- *                              connecting.
- * @param passwd                Password of the target SoftAP network to which the Enrollee is
- *                              connecting
- * @param ESEnrolleeNetworkEventCallback Callback function for result update
- * @return ::void.
- */
-void ESCreateSoftap(const char * ssid, const char* passwd, ESEnrolleeNetworkEventCallback cb);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* EASYSETUP_ENROLLEE_SOFTAP_H__ */
-
-
-
diff --git a/service/easy-setup/enrollee/tizen/wifi/networkhandler.c b/service/easy-setup/enrollee/tizen/wifi/networkhandler.c
deleted file mode 100644 (file)
index ef83e92..0000000
+++ /dev/null
@@ -1,184 +0,0 @@
-/******************************************************************
- *
- * 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 "networkhandler.h"
-
-#include <wifi.h>
-#include <unistd.h>
-
-#include "logger.h"
-#include "easysetup.h"
-#include "oic_string.h"
-
-#define LOG_TAG "TIZEN ES"
-
-const char *gSsid = "DLNA_LISMORE1";
-const char *gPass = "dlna@010203";
-char *gIpAddress = NULL;
-wifi_ap_h connectedWifi;
-ESEnrolleeNetworkEventCallback gNetworkEventCb;
-static void ESActivateWifi();
-
-static const char*
-print_state(wifi_connection_state_e state)
-{
-    switch (state)
-    {
-        case WIFI_CONNECTION_STATE_DISCONNECTED:
-            return "Disconnected";
-        case WIFI_CONNECTION_STATE_ASSOCIATION:
-            return "Association";
-        case WIFI_CONNECTION_STATE_CONNECTED:
-            return "Connected";
-        case WIFI_CONNECTION_STATE_CONFIGURATION:
-            return "Configuration";
-    }
-}
-
-void __wifi_connected_cb(wifi_error_e error_code, void *user_data)
-{
-    OIC_LOG(INFO,LOG_TAG,"#### __connected ");
-
-    if (gIpAddress)
-        free(gIpAddress);
-
-    wifi_ap_get_ip_address(connectedWifi, WIFI_ADDRESS_FAMILY_IPV4, &gIpAddress);
-    OIC_LOG_V(INFO,LOG_TAG,"#### __connected, Ipaddress=%s", gIpAddress);
-    gNetworkEventCb(ES_OK);
-
-}
-
-bool __wifi_found_ap_cb(wifi_ap_h ap, void *user_data)
-{
-    OIC_LOG(INFO,LOG_TAG,"#### __wifi_found_ap_cb received ");
-
-    int error_code = 0;
-    char *ap_name = NULL;
-    wifi_connection_state_e state;
-
-    error_code = wifi_ap_get_essid(ap, &ap_name);
-    if (error_code != WIFI_ERROR_NONE)
-    {
-        OIC_LOG(ERROR,LOG_TAG,"#### Fail to get AP name.");
-
-        return false;
-    }
-    error_code = wifi_ap_get_connection_state(ap, &state);
-    if (error_code != WIFI_ERROR_NONE)
-    {
-        OIC_LOG(ERROR,LOG_TAG,"#### Fail to get state.");
-        free(ap_name);
-
-        return false;
-    }
-    OIC_LOG_V(INFO,LOG_TAG,"#### AP name : %s, state : %s", ap_name, print_state(state));
-
-    if (strcmp(ap_name, gSsid) == 0)
-    {
-        OIC_LOG(INFO,LOG_TAG,"#### network found");
-        wifi_ap_set_passphrase(ap, gPass);
-        connectedWifi = ap;
-        error_code = wifi_connect(ap, __wifi_connected_cb, NULL);
-        OIC_LOG_V(INFO,LOG_TAG,"Code=%d", error_code);
-    }
-    OIC_LOG(INFO,LOG_TAG,"#### __wifi_found_ap_cb received ");
-    free(ap_name);
-    return true;
-}
-void __scan_request_cb(wifi_error_e error_code, void *user_data)
-{
-    OIC_LOG(INFO, LOG_TAG, "__scan_request_cb");
-    int error_code1;
-    error_code1 = wifi_foreach_found_aps(__wifi_found_ap_cb, NULL);
-    if (error_code1 != WIFI_ERROR_NONE)
-        OIC_LOG(INFO,LOG_TAG,"#### Fail to scan");
-
-    OIC_LOG(INFO, LOG_TAG,"#### __scan_request_cb exit ");
-}
-
-static void __wifi_activated_cb(wifi_error_e result, void *user_data)
-{
-    OIC_LOG(INFO, LOG_TAG, "__wifi_activated_cb");
-    if (result == WIFI_ERROR_NONE)
-    {
-        OIC_LOG(INFO,LOG_TAG,"#### Success to activate Wi-Fi device!");
-    }
-    wifi_scan(__scan_request_cb, NULL);
-
-}
-static void ESActivateWifi()
-{
-    int error_code;
-    error_code = wifi_initialize();
-    OIC_LOG_V(INFO,LOG_TAG,"#### WIFI INITIALIZED WITH STATUS :%d", error_code);
-
-    error_code = wifi_activate(__wifi_activated_cb, NULL);
-    OIC_LOG_V(INFO,LOG_TAG,"#### WIFI ACTIVATED WITH STATUS :%d", error_code);
-
-    bool wifi_activated = false;
-    wifi_is_activated(&wifi_activated);
-    if (wifi_activated)
-    {
-        OIC_LOG(INFO,LOG_TAG,"#### Success to get Wi-Fi device state.");
-        int scan_result = wifi_scan(__scan_request_cb, NULL);
-        OIC_LOG_V(INFO,LOG_TAG,"#### Wifi scan result:%d", scan_result);
-    }
-    else
-    {
-        OIC_LOG(ERROR,LOG_TAG, "#### Fail to get Wi-Fi device state.");
-    }
-}
-
-static void start()
-{
-    OIC_LOG(INFO, LOG_TAG, "START");
-    ESActivateWifi();
-}
-
-void ConnectToWiFiNetwork(const char *ssid, const char *pass,
-                                                            ESEnrolleeNetworkEventCallback cb)
-{
-    OIC_LOG_V(INFO, LOG_TAG, "ConnectToWiFiNetwork %s %s",ssid,pass);
-    gPass = pass;
-    gSsid = ssid;
-    gNetworkEventCb = cb;
-    start();
-}
-
-ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info)
-{
-    if (targetType == CT_ADAPTER_IP)
-    {
-        info->type = CT_ADAPTER_IP;
-        info->ipaddr = gIpAddress;
-        if (strlen(gSsid) <= MAXSSIDLEN)
-        {
-            OICStrcpy(info->ssid, sizeof(info->ssid), gSsid);
-            return ES_OK;
-        }
-        else
-        {
-            return ES_ERROR;
-        }
-    }
-
-    return ES_ERROR;
-}
-
diff --git a/service/easy-setup/enrollee/tizen/wifi/networkhandler.h b/service/easy-setup/enrollee/tizen/wifi/networkhandler.h
deleted file mode 100644 (file)
index 410b665..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/**
- * @file
- *
- * This file contains IP network handling functionality for Enrollee device
- */
-
-#ifndef ES_NETWORK_HANDLER_H_
-#define ES_NETWORK_HANDLER_H_
-
-
-#include <string.h>
-#include "easysetup.h"
-#include "logger.h"
-#include "escommon.h"
-
-#define MAXSSIDLEN 33
-#define MAXNETCREDLEN 20
-#define MAXNUMTYPE 5
-#define MAXADDRLEN 15
-
-/*
- * Callback function for updating the Network status to the subscribers
- *
- * @param esResult ESResult provides the current state of the network connection status
- */
-typedef void (*ESEnrolleeNetworkEventCallback)(ESResult esResult);
-
-typedef struct
-{
-    OCConnectivityType type;
-    // for WiFI
-    //IPAddress ipaddr;
-    char *ipaddr;
-    char ssid[MAXSSIDLEN];
-    // for BT, BLE
-    //byte mac[6];
-} NetworkInfo;
-
-void ConnectToWiFiNetwork(const char *ssid, const char *pass,
-                                                                ESEnrolleeNetworkEventCallback);
-ESResult getCurrentNetworkInfo(OCConnectivityType targetType, NetworkInfo *info);
-
-#endif
diff --git a/service/easy-setup/enrollee/tizen/wifi/softapnative.c b/service/easy-setup/enrollee/tizen/wifi/softapnative.c
deleted file mode 100644 (file)
index ae47dda..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-//******************************************************************
-//
-// 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 "softapnative.h"
-
-/**
- * This API will create the Soft AP at Enrollee device. 
- */
-void ESCreateSoftapNative(const char * ssid, const char* passwd, SoftAPCallbackNative cb)
-{
-    // TODO: Assign proper values after hardware integration is supported to create SoftAp
-    //We are not using this now. Assiging NULL to remove SVACE error
-    const char *ip = (char *)0;
-    const char *macaddr = (char *)0;
-    const char *devicename = (char *)0;
-
-    // Soft is created successfully. This callback may be send from other cascaded callbacks
-    cb(SOFTAP_SUCCESS, ip, macaddr, devicename);
-
-    // TODO: Use below code to indicate failed on-boarding / softap creation
-    // Soft creation is failed. This callback may be send from other cascaded callbacks 
-    //cb(SOFTAP_FAILED, nullptr,nullptr,nullptr);
-}
-
diff --git a/service/easy-setup/enrollee/tizen/wifi/softapnative.h b/service/easy-setup/enrollee/tizen/wifi/softapnative.h
deleted file mode 100644 (file)
index 10774ed..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-
-
-#ifndef EASYSETUP_ENROLLEE_SOFTAP_H__
-#define EASYSETUP_ENROLLEE_SOFTAP_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-
-#define SOFTAP_SUCCESS  1
-#define SOFTAP_FAILED   0
-
-/**
- * @file
- *
- * This file contains the API declaration for creating & configuration for SoftAP
- */
-
-//This callback signagure may get changed as per the native implementation.
-typedef void (*SoftAPCallbackNative)(int result, const char *ip, const char* mac_addr,
-                                                                        const char*device_name);
-/**
- * This API creats the Soft AP using the platform specific native system calls.
- * @Note This API to be implemented by the OEM if Enrollee device SoC supports SoftAP
- *
- * @param networkType           NetworkType on which OnBoarding has to be performed.
- * @param ssid                  SSID of the target SoftAP network to which the Enrollee is
- *                              connecting.
- * @param passwd                Password of the target SoftAP network to which the Enrollee is
- *                              connecting
- * @param SoftAPCallbackNative  EventCallback for for updating the Enrollee OnBoarding status
- *                              result to the application
- */
-
-void ESCreateSoftapNative(const char * ssid, const char* passwd, SoftAPCallbackNative cb);
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-
-#endif /* EASYSETUP_ENROLLEE_SOFTAP_H__ */
-
-
-
index 17ec815..3dbd58e 100755 (executable)
@@ -28,8 +28,6 @@
 #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
 
 /**
  * @brief Mac address length for BT port
 /**
  * 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_LAST_ERRORCODE         "lec"
+#define OC_RSRVD_ES_ERRORMESSAGE           "em"
+#define OC_RSRVD_ES_LINKS                  "links"
+#define OC_RSRVD_ES_TRIGGER                "tr"
+#define OC_RSRVD_ES_SUPPORTEDWIFIMODE      "swmt"
+#define OC_RSRVD_ES_SUPPORTEDWIFIFREQ      "swf"
+#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"
 
 /**
  * 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_RES_TYPE_PROV         "ocf.r.prov"
+#define OC_RSRVD_ES_URI_PROV              "/.well-known/ocf/prov"
+#define OC_RSRVD_ES_RES_TYPE_WIFI         "ocf.r.wifi"
+#define OC_RSRVD_ES_URI_WIFI              "/.well-known/ocf/prov/wifi"
+#define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.r.cloudserver"
+#define OC_RSRVD_ES_URI_CLOUDSERVER       "/.well-known/ocf/prov/cloudserver"
+#define OC_RSRVD_ES_RES_TYPE_DEVCONF      "ocf.r.devconf"
+#define OC_RSRVD_ES_URI_DEVCONF           "/.well-known/ocf/prov/devconf"
+
+#define NUM_WIFIMODE    10
+#define MAX_SSIDLEN 33
+#define MAX_CREDLEN 20
+
+#define MAX_DEVICELEN 100
+#define MAX_ERRMSGLEN 100
+#define MAX_WEBLINKLEN 100
 
-/**
- * @brief Defines for Provisioning status accepted values
- */
-#define ES_PS_NEED_PROVISIONING         1
-#define ES_PS_PROVISIONING_COMPLETED    2
-#define ES_PS_TRIGGER_INIT_VALUE        0
-#define ES_PS_TRIGGER_CONNECTION        1
+typedef enum
+{
+    NO_PROVISION = 0,
+    CONNECTED_ENROLLER,
+    FAILED_CONNECTION
+} PROV_STATUS;
+
+typedef enum
+{
+    WiFi_11A = 0,
+    WiFi_11B,
+    WiFi_11G,
+    WiFi_11N,
+    WiFi_11AC,
+    WiFi_EOF = 999,
+} WIFI_MODE;
 
+typedef enum
+{
+    WiFi_24G = 0,
+    WiFi_5G,
+    WiFi_BOTH
+} WIFI_FREQ;
+
+typedef enum
+{
+    NONE_AUTH = 0,
+    WEP,
+    WPA_PSK,
+    WPA2_PSK
+} WIFI_AUTHTYPE;
+
+typedef enum
+{
+    NONE_ENC = 0,
+    WEP_64,
+    WEP_128,
+    TKIP,
+    AES,
+    TKIP_AES
+} WIFI_ENCTYPE;
 
 /**
 * Device Roles defined for each device type used in easy setup
@@ -93,62 +148,116 @@ typedef enum
     ES_RECVREQOFNETRES,
     ES_RECVUPDATEOFPROVRES,
     ES_RECVTRIGGEROFPROVRES,
+    ES_UNAUTHORIZED = 31
 } ESResult;
 
 typedef enum
 {
+    ES_WIFI_RESOURCE = 0x01,
+    ES_CLOUD_RESOURCE = 0x02,
+    ES_DEVCONF_RESOURCE = 0x04
+} ESResourceMask;
+
+typedef struct
+{
+    char ssid[MAX_SSIDLEN]; /**< ssid of the Enroller**/
+    char pwd[MAX_CREDLEN]; /**< pwd of the Enroller**/
+    WIFI_AUTHTYPE authtype; /**< auth type of the Enroller**/
+    WIFI_ENCTYPE enctype; /**< encryption type of the Enroller**/
+} ESWiFiProvData;
+
+typedef struct
+{
+    char language[OIC_STRING_MAX_VALUE];
+    char country[OIC_STRING_MAX_VALUE];
+} ESDevConfProvData;
+
+typedef struct
+{
+    char authCode[OIC_STRING_MAX_VALUE];
+    char authProvider[OIC_STRING_MAX_VALUE];
+    char ciServer[OIC_STRING_MAX_VALUE];
+} ESCloudProvData;
+
+typedef struct
+{
+    struct
+    {
+        WIFI_MODE mode[NUM_WIFIMODE];
+        WIFI_FREQ freq;
+    } WiFi;
+    struct
+    {
+        char deviceName[MAX_DEVICELEN];
+    } DevConf;
+} ESDeviceProperty;
+
+typedef enum
+{
     /**
      * Default state of the device
      */
-    ES_INIT_STATE,
+    ES_STATE_INIT = 1,
 
     /**
-     * Device will move to this state once the on boarding begins
-     */
-    ES_ON_BOARDING_STATE,
+    * Status indicating successful cnnection to target network
+    */
+    ES_STATE_CONNECTED_TO_ENROLLER,
 
     /**
-     * Device will move to this state after successful on-boarding of the device
-     */
-    ES_ON_BOARDED_STATE,
+    * Status indicating failure connection to target network
+    */
+    ES_STATE_CONNECTED_FAIL_TO_ENROLLER,
 
     /**
-     * Device will move to this state once the on boarding is done
-     */
-    ES_PROVISIONING_STATE,
+    * Status indicating successful registration to cloud
+    */
+    ES_STATE_REGISTERED_TO_CLOUD,
 
     /**
-     * Easy setup process is successful.
-     */
-    ES_PROVISIONED_STATE,
+    * Status indicating failure registeration to cloud
+    */
+    ES_STATE_REGISTRRED_FAIL_TO_CLOUD
+} ESEnrolleeState;
+
+typedef enum
+{
+    /**
+    * Error Code that given WiFi's SSID is not found
+    */
+    ES_ERRCODE_SSID_NOT_FOUND = 1,
 
     /**
-     * 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,
+    * Error Code that given WiFi's Password is wrong
+    */
+    ES_ERRCODE_PW_WRONG,
 
     /**
-     * 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,
+    * Error Code that IP address is not allocated
+    */
+    ES_ERRCODE_IP_NOT_ALLOCATED,
 
     /**
-     * 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,
+    * Error Code that there is no Internet connection
+    */
+    ES_ERRCODE_NO_INTERNETCONNECTION,
 
     /**
-     * Enrollee moves to this state after connecting to target network
-     */
-    ES_ON_BOARDED_TARGET_NETWORK_STATE,
-}ESEnrolleeState;
+    * Error Code that Timeout occured
+    */
+    ES_ERRCODE_TIMEOUT,
+
+    /**
+    * Error Code that Unknown error occured
+    */
+    ES_ERRCODE_UNKNOWN,
+
+    /**
+    * No Error Occured
+    */
+    ES_ERRCODE_NONE = 999
+} ESErrorCode;
 
-/**
- * Provisioning Device Status
- */
 typedef struct
 {
     // Address of remote server
@@ -162,10 +271,11 @@ typedef struct
  */
 typedef enum
 {
-    DEVICE_PROVISIONED = 0,
-    DEVICE_NOT_PROVISIONED,
-    DEVICE_OWNED,
-    DEVICE_NOT_OWNED
+    ES_NEED_PROVISION = 1,
+    ES_CONNECTED_TO_ENROLLER,
+    ES_CONNECTED_FAIL_TO_ENROLLER,
+    ES_REGISTERED_TO_CLOUD,
+    ES_REGISTERED_FAIL_TO_CLOUD
 } EasySetupState, ProvStatus;
 
 /**
@@ -205,8 +315,8 @@ typedef union
      */
     struct
     {
-        char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
-        char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
+        char ssid[MAX_SSIDLEN]; /**< ssid of the Enroller**/
+        char pwd[MAX_CREDLEN]; /**< pwd of the Enroller**/
     } WIFI;
 } ProvData;
 
@@ -231,8 +341,8 @@ typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
 
 // 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**/
+    char ssid[MAX_SSIDLEN]; /**< ssid of the onboarding Adhoc Wifi network**/
+    char pwd[MAX_CREDLEN]; /**< pwd of the onboarding Adhoc wifi network**/
     bool isSecured;                 /**< Secure connection**/
 }WiFiOnboardingConfig;
 
@@ -246,4 +356,5 @@ typedef struct {
    bool isSecured;                 /**< Secure connection**/
 }WiFiOnboadingConnection;
 
+
 #endif //ES_COMMON_H_
index 0e35382..57de9b6 100644 (file)
@@ -26,7 +26,7 @@ Import('env')
 target_os = env.get('TARGET_OS')
 
 # Build easy-setup Mediator C SDK
-SConscript('csdk/SConscript')
+#SConscript('csdk/SConscript')
 
 # Build easy-setup Mediator Rich [C++] SDK
 SConscript('richsdk/SConscript')
index 8ed21ad..f7cd0d9 100644 (file)
@@ -86,6 +86,7 @@ if target_os in ['linux']:
                easy_setup_env.AppendUnique(LIBS = ['ocpmapi', 'ocprovision'])
 
 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',
@@ -114,11 +115,13 @@ print"easysetup_path %s" % easysetup_path
 es_src = None
 
 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/CloudResource.cpp',
                'src/EasySetup.cpp',
                'src/ESException.cpp']
 
@@ -138,6 +141,6 @@ if target_os == 'linux':
 ######################################################################
 #Build UnitTestcases for Mediator[RichSDK]
 ################################################ ######################
-if target_os == 'linux':
-    SConscript('unittests/SConscript')
+#if target_os == 'linux':
+#    SConscript('unittests/SConscript')
 
diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvInfo.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvInfo.java
new file mode 100755 (executable)
index 0000000..ebe7a97
--- /dev/null
@@ -0,0 +1,62 @@
+/**
+ * ***************************************************************
+ *
+ * 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.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * This class contains on cloud provisioning information.
+ * It implements ProvisioningInfo interface and provide configuration object specific to cloud registration
+ */
+public class CloudProvInfo {
+
+    private final String mAuthCode;
+    private final String mAuthProvider;
+    private final String mCiServer;
+
+    public CloudProvInfo(String authCode, String authProvider, String ciServer) {
+        mAuthCode = authCode;
+        mAuthProvider = authProvider;
+        mCiServer = ciServer;
+    }
+
+    /**
+     * This method returns the authCode used for the first registration to IoTivity cloud
+     * @return AuthCode for sign-up to IoTivity cloud
+     */
+    public String getAuthCode() {
+        return mAuthCode;
+    }
+
+    /**
+     * This method returns the auth provider which issued the given AuthCode
+     * @return Auth provider which issued the given AuthCode
+     */
+    public String getAuthProvider() {
+        return mAuthProvider;
+    }
+
+       /**
+     * This method returns the Cloud Interface server's URL to be registered
+     * @return CI server's URL to be registered
+     */
+    public String getCiServer() {
+        return mCiServer;
+    }
+}
diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningCallback.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningCallback.java
new file mode 100755 (executable)
index 0000000..7e7aeb5
--- /dev/null
@@ -0,0 +1,28 @@
+/**
+ * ***************************************************************
+ *
+ * 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.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import org.iotivity.service.easysetup.mediator.CloudProvisioningStatus;
+
+public abstract class CloudProvisioningCallback {
+       public abstract void onProgress(CloudProvisioningStatus status);
+}
+
diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningStatus.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProvisioningStatus.java
new file mode 100755 (executable)
index 0000000..3bee761
--- /dev/null
@@ -0,0 +1,47 @@
+/**
+ * ***************************************************************
+ *
+ * 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.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * This interface facilitates Application to get progress & result of Cloud provisioning
+ * process in easy setup
+ */
+public class CloudProvisioningStatus
+{
+    private ESResult m_result;
+    private ESCloudProvState m_esCloudState;
+
+    public CloudProvisioningStatus(int result, int state)
+    {
+        m_result = ESResult.fromInt(result);
+        m_esCloudState = ESCloudProvState.fromInt(state);
+    }
+
+    public ESResult getESResult()
+    {
+        return m_result;
+    }
+
+    public ESCloudProvState getESCloudState()
+    {
+        return m_esCloudState;
+    }
+};
diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESCloudProvState.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESCloudProvState.java
new file mode 100755 (executable)
index 0000000..6b31dfc
--- /dev/null
@@ -0,0 +1,65 @@
+/**
+ * ***************************************************************
+ *
+ * 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.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * It defines various states of the cloud provisioning during easy setup process
+ */
+public enum ESCloudProvState {
+
+    /**
+     * Some error occurs during cloud data provisioning
+     */
+    ES_CLOUD_PROVISIONING_ERROR(-1),
+
+    /**
+     * Cloud data provisioning is successfully done
+     */
+    ES_CLOUD_PROVISIONING_SUCCESS(0),
+
+    /**
+     * Target enrollee which needs a cloud provisioning is found in a network
+     */
+    ES_CLOUD_ENROLLEE_FOUND(1),
+
+    /**
+     * Target enrollee which needs a cloud provisioning is NOT found in a network
+     */
+    ES_CLOUD_ENROLLEE_NOT_FOUND(2);
+
+    private int value;
+
+    private ESCloudProvState(int value) {
+        this.value = value;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+    public static ESCloudProvState fromInt(int i) {
+        for (ESCloudProvState b : ESCloudProvState.values()) {
+            if (b.getValue() == i) { return b; }
+        }
+        return null;
+    }
+};
+
diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESResult.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESResult.java
new file mode 100755 (executable)
index 0000000..f7bdd24
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * ***************************************************************
+ *
+ * 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.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * It defines an result during easy setup process, which is same as one in Easy Setup C++ SDK
+ */
+public enum ESResult {
+    ES_ERROR(-1),
+    ES_OK(0),
+    ES_NETWORKFOUND(1),
+    ES_NETWORKCONNECTED(2),
+    ES_NETWORKNOTCONNECTED(3),
+    ES_RESOURCECREATED(11),
+    ES_RECVREQOFPROVRES(21),
+    ES_RECVREQOFNETRES(22),
+    ES_RECVUPDATEOFPROVRES(23),
+    ES_RECVTRIGGEROFPROVRES(24),
+    ES_UNAUTHORIZED(25);
+
+    private int value;
+
+    private ESResult(int value) {
+        this.value = value;
+    }
+
+       public int getValue() {
+        return value;
+    }
+
+       public static ESResult fromInt(int i) {
+        for (ESResult b : ESResult.values()) {
+            if (b.getValue() == i) { return b; }
+        }
+        return null;
+    }
+};
\ No newline at end of file
diff --git a/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetup.java b/service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetup.java
new file mode 100755 (executable)
index 0000000..2e47b0e
--- /dev/null
@@ -0,0 +1,95 @@
+/**
+ * ***************************************************************
+ *
+ * Copyright 2017 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.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import android.content.Context;
+import android.util.Log;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ * <To be modified>
+ * This is facade class, a single point of contact for Application.
+ * It contains set of APIs to do easy setup of the enrolling device.
+ * ON-BOARDING - This is a step to establish connectivity between the device & Mediator device.
+ * PROVISION   - This is a step where the netowork's detail & credentials are given to the
+ * enrolling device.
+ */
+public class EasySetup {
+
+    private static final String TAG = EasySetup.class.getName();
+
+    private static EasySetup sInstance;
+
+    private static Context mContext;
+
+    private ArrayList<RemoteEnrollee> mRemoteEnrolleeList;
+
+    protected RemoteEnrollee mRemoteEnrollee;
+
+    //function to call the native nativeCreateRemoteEnrollee
+    private native RemoteEnrollee nativeCreateRemoteEnrollee();
+
+    static {
+        // Load Easy Setup JNI interface
+        System.loadLibrary("ESMediatorRich");
+        System.loadLibrary("easysetup-jni");
+    }
+
+    private EasySetup() {
+        mRemoteEnrolleeList = new ArrayList<RemoteEnrollee>();
+        mContext = null;
+    }
+
+    /**
+     * Gives a singleton instance of Easy setup and initialize the easy setup
+     */
+    public synchronized static EasySetup getInstance(Context context) {
+        if (sInstance == null) {
+            sInstance = new EasySetup();
+            mContext = context;
+        }
+        return sInstance;
+    }
+
+    /**
+     * API to create a new RemoteEnrollee instance
+     */
+    public synchronized RemoteEnrollee createRemoteEnrollee()
+    {
+        // native call
+        mRemoteEnrollee = nativeCreateRemoteEnrollee();
+        mRemoteEnrolleeList.add(mRemoteEnrollee);
+        return mRemoteEnrollee;
+    }
+
+    /**
+     * Reset the Easy setup
+     */
+    public void finish() {
+        //Call the stop Provisioning
+        //for (RemoteEnrollee remoteEnrollee : mRemoteEnrolleeList)
+        //    remoteEnrollee.stopProvisioningProcess();
+        }
+}
index 66f12d0..ffa1b4d 100644 (file)
@@ -142,6 +142,7 @@ public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {
         mProvisioningCallback.onProgress(this);
         final EnrolleeDevice device = this;
         if (mProvConfig.getConnType() == ProvisioningConfig.ConnType.WiFi) {
+            /*
              try {
                  mRemoteEnrollee.registerProvisioningHandler(new IProvisionStatusNativeHandler() {
                      @Override
@@ -154,22 +155,26 @@ public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {
                          }
                      }
                  });
+
                  //native call
                 mRemoteEnrollee.startProvision();
              }catch(ESException e) {
                  Log.i(TAG,"startProvisioningProcess Register Listener to native exception");
              }
+             */
         }
     }
 
     protected void stopProvisioningProcess(){
         if(mState == EnrolleeState.DEVICE_PROVISIONING_STATE)
         {    //native call
+            /*
             try {
                 mRemoteEnrollee.stopProvision();
             } catch (ESException e) {
                 Log.i(TAG,"stopProvisioningProcess exception");
             }
+            */
         }else{
            Log.i(TAG,"stopProvisioningProcess : Provisioning is not in progress");
         }
old mode 100644 (file)
new mode 100755 (executable)
index 38328bc..9e4d35c
@@ -1,22 +1,22 @@
 /**
  * ***************************************************************
- * <p/>
+ *
  * Copyright 2016 Samsung Electronics All Rights Reserved.
- * <p/>
- * <p/>
- * <p/>
+ *
+ *
+ *
  * 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
- * <p/>
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
  * 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.
- * <p/>
+ *
  * ****************************************************************
  */
 
@@ -30,30 +30,26 @@ public class RemoteEnrollee{
     public static final String TAG = RemoteEnrollee.class.getName();
     private long m_nativeHandle;
 
-    private native void nativeStartProvision();
-    private native void nativeStopProvision();
-    private native void nativeRegisterProvisioningHandler(IProvisionStatusNativeHandler listener);
+    private native void nativeSetCloudProvInfo(String authCode, String autoProvider, String ciServer);
+    private native void nativeStartCloudProvisioning(CloudProvisioningCallback callback);
 
     /* constructor will be invoked from the native layer */
     private RemoteEnrollee(long nativeHandle){
         this.m_nativeHandle = nativeHandle;
     }
 
-    /* Register native Listener for the Provisioning state */
-    public void registerProvisioningHandler( IProvisionStatusNativeHandler provisioningListener) throws ESException{
-       // this.provisioningListener = provisioningListener;
-        nativeRegisterProvisioningHandler(provisioningListener);
-        Log.i(TAG, "JNI Callback is registered for getting provisioning status");
+       /* native setCloudProvInfo */
+    public void setCloudProvInfo(CloudProvInfo cloudInfo) throws ESException{
+       nativeSetCloudProvInfo(cloudInfo.getAuthCode(), cloudInfo.getAuthProvider(), cloudInfo.getCiServer());
+       }
+
+    /* native startCloudProvisioning */
+    public void startCloudProvisioning(CloudProvisioningCallback callback) throws ESException{
+        if(callback != null)
+        {
+            nativeStartCloudProvisioning(callback);
+            return;
+        }
+        Log.d(TAG, "CloudProvisioningCallback is null ");
     }
-
-    /* native StartProvision */
-    public void startProvision() throws ESException{
-    nativeStartProvision();
-}
-
-    /* native stopProvision */
-    public void stopProvision() throws  ESException{
-    nativeStopProvision();
-}
-
 }
index fe63791..b14b2c4 100644 (file)
@@ -20,7 +20,7 @@ LOCAL_MODULE    := easysetup-jni
 DEFINE_FLAG =  -DWITH_POSIX -D__ANDROID__
 
 #Add Debug flags here
-DEBUG_FLAG      = -DTB_LOG
+DEBUG_FLAG = -DTB_LOG
 
 BUILD_FLAG = $(DEFINE_FLAG) $(DEBUG_FLAG)
 
@@ -34,7 +34,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) \
                                        $(LOCAL_PATH)/../../src \
                                        $(LOCAL_PATH)/../../../../inc \
                                        $(LOCAL_PATH)/../../../../../../resource/csdk/logger/include \
-                                   $(LOCAL_PATH)/../../../../../../resource/csdk/connectivity/common/inc \
+                                       $(LOCAL_PATH)/../../../../../../resource/csdk/connectivity/common/inc \
                                        $(LOCAL_PATH)/../../../../../../resource/c_common/oic_string/include \
                                        $(LOCAL_PATH)/../../../../../../resource/include \
                                        $(LOCAL_PATH)/../../../../../../resource/c_common \
@@ -46,7 +46,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) \
                                        $(LOCAL_PATH)/../../../../../../resource/csdk/security/include \
                                        $(LOCAL_PATH)/../../../../../../extlibs/cjson \
                                        $(LOCAL_PATH)/../../../../../../extlibs/boost/boost_1_58_0 \
-                    $(LOCAL_PATH)/../../../../../../extlibs/timer \
+                                       $(LOCAL_PATH)/../../../../../../extlibs/timer \
                                        $(LOCAL_PATH)/../../../../../../android/android_api/base/jni \
 
 LOCAL_SRC_FILES += $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/*.cpp))
diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniCloudProvisioningStatusListener.cpp b/service/easy-setup/mediator/richsdk/android/jni/JniCloudProvisioningStatusListener.cpp
new file mode 100755 (executable)
index 0000000..3162b55
--- /dev/null
@@ -0,0 +1,133 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "JniCloudProvisioningStatusListener.h"
+#include "JniRemoteEnrollee.h"
+
+using namespace OIC::Service;
+
+JniCloudProvisioningStatusListener::JniCloudProvisioningStatusListener(JNIEnv *env, jobject jListener,
+        JniRemoteEnrollee *owner)
+    : m_ownerResource(owner)
+{
+    m_jwListener = env->NewWeakGlobalRef(jListener);
+}
+
+JniCloudProvisioningStatusListener::~JniCloudProvisioningStatusListener()
+{
+    LOGI("~JniCloudProvisioningStatusListener()");
+    if (m_jwListener)
+    {
+        jint ret;
+        JNIEnv *env = GetESJNIEnv(ret);
+        if (NULL == env) return;
+        env->DeleteWeakGlobalRef(m_jwListener);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    }
+}
+
+void JniCloudProvisioningStatusListener::onCloudProvisioningStatus(std::shared_ptr<CloudProvisioningStatus>
+        cloudProvisioningStatus)
+{
+
+    LOGI("JniCloudProvisioningStatusListener::onCloudProvisioningStatus enter");
+
+    jint ret;
+    JNIEnv *env = GetESJNIEnv(ret);
+    if (NULL == env) return;
+    jobject jListener = env->NewLocalRef(m_jwListener);
+    if (!jListener)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    jclass clsL = env->GetObjectClass(jListener);
+    if (!clsL)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    jmethodID midL = env->GetMethodID(clsL, "onProgress",
+                                      "(Lorg/iotivity/service/easysetup/mediator/"
+                                      "CloudProvisioningStatus;"
+                                      ")V");
+    if (!midL)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    ESResult esResult = cloudProvisioningStatus->getESResult();
+    ESCloudProvState cloudProvisionState = cloudProvisioningStatus->getESCloudState();
+
+    //create the java object
+    jobject jCloudProvisioningStatus = NULL;
+    jCloudProvisioningStatus = env->NewObject(g_cls_CloudProvisioningStatus,
+                                                g_mid_CloudProvisioningStatus_ctor,
+                                                (jint)esResult,
+                                                (jint)cloudProvisionState);
+
+    LOGI("JniCloudProvisioningStatus::onCloudProvisioningStatus - %d, %d", esResult, cloudProvisionState);
+    if (!jCloudProvisioningStatus)
+    {
+        LOGE("JniCloudProvisioningStatus::onCloudProvisioningStatus Unable to create the java object");
+        return ;
+    }
+
+    env->CallVoidMethod(jListener, midL, jCloudProvisioningStatus);
+
+    bool needRemoveListener = false;
+
+    if(cloudProvisionState == ES_CLOUD_PROVISIONING_ERROR ||
+            cloudProvisionState == ES_CLOUD_PROVISIONING_SUCCESS )
+    {
+        needRemoveListener = true;
+    }
+
+    if (env->ExceptionCheck())
+    {
+        LOGE("Java exception is thrown");
+        if(needRemoveListener)
+            checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+}
+
+void JniCloudProvisioningStatusListener::checkExAndRemoveListener(JNIEnv *env)
+{
+    if (env->ExceptionCheck())
+    {
+        jthrowable ex = env->ExceptionOccurred();
+        env->ExceptionClear();
+        m_ownerResource->removeStatusListener<JniCloudProvisioningStatusListener>(env, m_jwListener);
+        env->Throw((jthrowable)ex);
+    }
+    else
+    {
+        m_ownerResource->removeStatusListener<JniCloudProvisioningStatusListener>(env, m_jwListener);
+    }
+}
@@ -3,7 +3,6 @@
  * 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
@@ -22,8 +21,8 @@
  *   @brief  This file contains JNI Provisioing status Listener class
  */
 
-#ifndef __JNI_ES_PROVISIONING_STATUS_LISTENER_H_
-#define __JNI_ES_PROVISIONING_STATUS_LISTENER_H_
+#ifndef __JNI_ES_CLOUD_PROVISIONING_STATUS_LISTENER_H_
+#define __JNI_ES_CLOUD_PROVISIONING_STATUS_LISTENER_H_
 
 #include <jni.h>
 
@@ -37,27 +36,27 @@ class JniRemoteEnrollee;
 using namespace OIC::Service;
 
 /**
- * @class   JniProvisioningStatusListener
- * @brief   This class provides functions for handling the provisioning status callback between the Java and native layer
+ * @class   JniCloudProvisioningStatusListener
+ * @brief   This class provides functions for handling the cloud provisioning status callback between the Java and native layer
  *
  */
-class JniProvisioningStatusListener
+class JniCloudProvisioningStatusListener
 {
     public:
         /**
          * @brief constructor
          */
-        JniProvisioningStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource);
+        JniCloudProvisioningStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource);
 
         /**
          * @brief destructor
         */
-        ~JniProvisioningStatusListener();
+        ~JniCloudProvisioningStatusListener();
 
         /**
          * @brief callback function that will be passed to Native layer
         */
-        void provisionStatusCallback (std::shared_ptr<EasySetupStatus> easySetupStatus);
+        void onCloudProvisioningStatus (std::shared_ptr<CloudProvisioningStatus> cloudProvisioningStatus);
 
     private:
         jweak m_jwListener;
@@ -66,3 +65,4 @@ class JniProvisioningStatusListener
 };
 
 #endif //__JNI_ES_PROVISIONING_STATUS_LISTENER_H_
+
diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniDataProvisioningStatusListener.cpp b/service/easy-setup/mediator/richsdk/android/jni/JniDataProvisioningStatusListener.cpp
new file mode 100644 (file)
index 0000000..300a841
--- /dev/null
@@ -0,0 +1,125 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "JniDataProvisioningStatusListener.h"
+#include "JniRemoteEnrollee.h"
+
+using namespace OIC::Service;
+
+JniDataProvisioningStatusListener::JniDataProvisioningStatusListener(JNIEnv *env, jobject jListener,
+        JniRemoteEnrollee *owner)
+    : m_ownerResource(owner)
+{
+    m_jwListener = env->NewWeakGlobalRef(jListener);
+}
+
+JniDataProvisioningStatusListener::~JniDataProvisioningStatusListener()
+{
+    LOGI("~JniDataProvisioningStatusListener()");
+    if (m_jwListener)
+    {
+        jint ret;
+        JNIEnv *env = GetESJNIEnv(ret);
+        if (NULL == env) return;
+        env->DeleteWeakGlobalRef(m_jwListener);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    }
+}
+
+void JniDataProvisioningStatusListener::dataProvisionStatusCallback (std::shared_ptr<DataProvisioningStatus>
+        dataProvStatusCb)
+{
+
+    LOGI("JniDataProvisioningStatusListener::provisioiningStatusCallback enter");
+
+    jint ret;
+    JNIEnv *env = GetESJNIEnv(ret);
+    if (NULL == env) return;
+    jobject jListener = env->NewLocalRef(m_jwListener);
+    if (!jListener)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    jclass clsL = env->GetObjectClass(jListener);
+    if (!clsL)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+    //TODO:
+    jmethodID midL = env->GetMethodID(clsL, "onProgress",
+                                      "(Lorg/iotivity/service/easysetup/mediator/"
+                                      "DataProvisioningCallback;"
+                                      ")V");
+
+    if (!midL)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    int nativeESResult = convertNativeDataProvResultToInt(dataProvStatusCb->getESResult());
+    int nativeESDataProvState = convertNativeDataProvStateToInt(dataProvStatusCb->getESDataProvState());
+
+    jobject jDataProvisioningStatus = NULL;
+    jDataProvisioningStatus = env->NewObject(g_cls_DataProvisioningStatus,
+                                                g_mid_DataProvisioningStatus_ctor,
+                                                (jint)nativeESResult,
+                                                (jint)nativeESDataProvState);
+
+    LOGI("JniDataProvisioningStatus::onDataProvisioningStatus - %d, %d", nativeESResult, nativeESDataProvState);
+    if (!jDataProvisioningStatus)
+    {
+        LOGE("JniDataProvisioningStatus::onDataProvisioningStatus Unable to create the java object");
+        return ;
+    }
+
+    env->CallVoidMethod(jListener, midL, jDataProvisioningStatus);
+
+    if (env->ExceptionCheck())
+    {
+        LOGE("Java exception is thrown");
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+}
+
+void JniDataProvisioningStatusListener::checkExAndRemoveListener(JNIEnv *env)
+{
+    if (env->ExceptionCheck())
+    {
+        jthrowable ex = env->ExceptionOccurred();
+        env->ExceptionClear();
+        m_ownerResource->removeStatusListener<JniDataProvisioningStatusListener>(env, m_jwListener);
+        env->Throw((jthrowable)ex);
+    }
+    else
+    {
+        m_ownerResource->removeStatusListener<JniDataProvisioningStatusListener>(env, m_jwListener);
+    }
+}
diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniDataProvisioningStatusListener.h b/service/easy-setup/mediator/richsdk/android/jni/JniDataProvisioningStatusListener.h
new file mode 100644 (file)
index 0000000..235ead8
--- /dev/null
@@ -0,0 +1,59 @@
+/******************************************************************
+ *
+ * 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 __JNI_ES_DATA_PROVISIONING_STATUS_LISTENER_H_
+#define __JNI_ES_DATA_PROVISIONING_STATUS_LISTENER_H_
+
+#include <jni.h>
+
+#include "RemoteEnrollee.h"
+#include "ESRichCommon.h"
+
+#include "JniJvm.h"
+
+class JniRemoteEnrollee;
+
+using namespace OIC::Service;
+
+class JniDataProvisioningStatusListener
+{
+    public:
+        /**
+         * @brief constructor
+         */
+        JniDataProvisioningStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource);
+
+        /**
+         * @brief destructor
+        */
+        ~JniDataProvisioningStatusListener();
+
+        /**
+         * @brief callback function that will be passed to Native layer
+        */
+        void dataProvisionStatusCallback (std::shared_ptr<DataProvisioningStatus> dataProvisioningStatus);
+
+    private:
+        jweak m_jwListener;
+        JniRemoteEnrollee *m_ownerResource;
+        void checkExAndRemoveListener(JNIEnv *env);
+};
+
+#endif //__JNI_ES_DATA_PROVISIONING_STATUS_LISTENER_H_
old mode 100644 (file)
new mode 100755 (executable)
index a237936..4c4b4d8
@@ -26,42 +26,23 @@ using namespace OIC::Service;
 extern "C" {
 #endif
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_service_easysetup_mediator_EasySetupService_nativeCreateEnrolleeDevice
-(JNIEnv *env, jobject interfaceClass, jstring ip, jstring ssid, jstring password,
- jint connectivityType, jboolean isSecured)
+Java_org_iotivity_service_easysetup_mediator_EasySetup_nativeCreateRemoteEnrollee
+(JNIEnv *env, jobject interfaceClass)
 {
 
-    LOGI("JniEasySetup::nativeCreateEnrolleeDevice enter");
+    LOGI("JniEasySetup::nativeCreateRemoteEnrollee enter");
 
     std::shared_ptr<RemoteEnrollee> nativeRemoteEnrollee;
     jobject jRemoteEnrollee;
-    ProvConfig netInfo;
-    WiFiOnboadingConnection onboardConn;
-
-    const char *cIp = (env)->GetStringUTFChars(ip, NULL);
-    const char *cSssid = (env)->GetStringUTFChars(ssid, NULL);
-    const char *cPassword = (env)->GetStringUTFChars(password, NULL);
-
-    std::string sIp(cIp);
-    std::string sSssid(cSssid);
-    std::string sPassword(cPassword);
-
-    netInfo.connType = getOCConnectivityTypeFromInt(connectivityType);
-
-    onboardConn.isSecured = bool(isSecured);
-
-    OICStrcpy(onboardConn.ipAddress, IPV4_ADDR_SIZE - 1, sIp.c_str());
-    OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, sSssid.c_str());
-    OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, sPassword.c_str());
 
     try
     {
-        nativeRemoteEnrollee = EasySetup::getInstance()->createEnrolleeDevice(netInfo,onboardConn);
+        nativeRemoteEnrollee = EasySetup::getInstance()->createRemoteEnrollee();
         //create the java object
         jRemoteEnrollee = env->NewObject(g_cls_RemoteEnrollee, g_mid_RemoteEnrollee_ctor);
         if (!jRemoteEnrollee)
         {
-            LOGE("JniEasySetup::nativeCreateEnrolleeDevice Unable to create the java object");
+            LOGE("JniEasySetup::nativeCreateRemoteEnrollee Unable to create the java object");
             return NULL;
         }
 
@@ -70,12 +51,12 @@ Java_org_iotivity_service_easysetup_mediator_EasySetupService_nativeCreateEnroll
     }
     catch (ESBadRequestException exception)
     {
-        LOGE("JniEasySetup::nativeCreateEnrolleeDevice Unable to create the Native EnrolleeDevice");
+        LOGE("JniEasySetup::nativeCreateRemoteEnrollee Unable to create the Native EnrolleeDevice");
         //throw the exception to java layer
         throwESException( env,  exception.what());
     }
 
-    LOGI("JniEasySetup::nativeCreateEnrolleeDevice exit");
+    LOGI("JniEasySetup::nativeCreateRemoteEnrollee exit");
 
     return jRemoteEnrollee;
 }
old mode 100644 (file)
new mode 100755 (executable)
index 2af8935..99fbc80
@@ -47,18 +47,11 @@ extern "C" {
 /**
  * API for creating and returning the RemoteEnrollee object to Java Layer
  *
- * @param ip - ip address of Enrollee
- * @param ssid - ssid of the Enroller
- * @param password - password of the enroller
- * @param connectivityType - Connectivity Type
- * @param needSecuredEasysetup - need secured easy setup or not
- *
  * @return jobject - RemoteEnrolleee
  */
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_service_easysetup_mediator_EasySetupService_nativeCreateEnrolleeDevice
-(JNIEnv *env, jobject interfaceClass, jstring ip, jstring ssid, jstring password,
- jint connectivityType, jboolean needSecuredEasysetup);
+Java_org_iotivity_service_easysetup_mediator_EasySetup_nativeCreateRemoteEnrollee
+(JNIEnv *env, jobject interfaceClass);
 
 #ifdef __cplusplus
 }
old mode 100644 (file)
new mode 100755 (executable)
index 991ad31..852314f
@@ -45,18 +45,112 @@ OCConnectivityType  getOCConnectivityTypeFromInt(int connectivityType)
     return CT_DEFAULT;
 }
 
-int convertNativeProvisionStateToInt(EasySetupState nativeState)
+WIFI_AUTHTYPE getWifiAuthTypeFromInt(int authType)
+{
+    switch (authType)
+    {
+        case 0:
+            return WIFI_AUTHTYPE::NONE_AUTH;
+        case 1:
+            return WIFI_AUTHTYPE::WEP;
+        case 2:
+            return WIFI_AUTHTYPE::WPA_PSK;
+        case 3:
+            return WIFI_AUTHTYPE::WPA2_PSK;
+    }
+    return NONE_AUTH;
+}
+
+WIFI_ENCTYPE getWifiEncTypeFromInt(int encType)
+{
+    switch (encType)
+    {
+        case 0:
+            return WIFI_ENCTYPE::NONE_ENC;
+        case 1:
+            return WIFI_ENCTYPE::WEP_64;
+        case 2:
+            return WIFI_ENCTYPE::WEP_128;
+        case 3:
+            return WIFI_ENCTYPE::TKIP;
+        case 4:
+            return WIFI_ENCTYPE::AES;
+        case 5:
+            return WIFI_ENCTYPE::TKIP_AES;
+    }
+    return NONE_ENC;
+}
+
+int convertNativeWifiFreqToInt(WIFI_FREQ wifiFreq)
+{
+    switch (wifiFreq)
+    {
+        case WIFI_FREQ::WIFI_24G:
+            return 0;
+        case WIFI_FREQ::WIFI_5G:
+            return 1;
+        case WIFI_FREQ::WIFI_BOTH:
+            return 2;
+    }
+}
+
+int convertNativeWifiModeToInt(WIFI_MODE wifiMode)
+{
+    switch (wifiMode)
+    {
+        case WIFI_MODE::WIFI_11A:
+            return 0;
+        case WIFI_MODE::WIFI_11B:
+            return 1;
+        case WIFI_MODE::WIFI_11G:
+            return 2;
+        case WIFI_MODE::WIFI_11N:
+            return 3;
+        case WIFI_MODE::WIFI_11AC:
+            return 4;
+    }
+}
+
+int convertNativeDataProvStateToInt(ESDataProvState nativeState)
 {
     switch (nativeState)
     {
-        case EasySetupState::DEVICE_PROVISIONED:
+        case ESDataProvState::ES_PROVISIONING_ERROR:
+            return -1;
+        case ESDataProvState::ES_NEED_PROVISIONING:
+            return 0;
+        case ESDataProvState::ES_PROVISIONED_ALREADY:
+            return 1;
+        case ESDataProvState::ES_PROVISIONING_SUCCESS:
+            return 2;
+    }
+}
+
+int convertNativeDataProvResultToInt(ESResult nativeResult)
+{
+    switch (nativeResult)
+    {
+        case ESResult::ES_ERROR:
+            return -1;
+        case ESResult::ES_OK:
             return 0;
-        case EasySetupState::DEVICE_NOT_PROVISIONED:
+        case ESResult::ES_NETWORKFOUND:
             return 1;
-        case EasySetupState::DEVICE_OWNED:
+        case ESResult::ES_NETWORKCONNECTED:
             return 2;
-        case EasySetupState::DEVICE_NOT_OWNED:
+        case ESResult::ES_NETWORKNOTCONNECTED:
             return 3;
+        case ESResult::ES_RESOURCECREATED:
+            return 11;
+        case ESResult::ES_RECVREQOFPROVRES:
+            return 21;
+        case ESResult::ES_RECVREQOFNETRES:
+            return 22;
+        case ESResult::ES_RECVUPDATEOFPROVRES:
+            return 23;
+        case ESResult::ES_RECVTRIGGEROFPROVRES:
+            return 24;
+        case ESResult::ES_UNAUTHORIZED:
+            return 31;
     }
-    return -1;
 }
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index f65a68c..526b04e
@@ -47,9 +47,10 @@ void throwESException(JNIEnv *env, std::string reason);
 */
 OCConnectivityType  getOCConnectivityTypeFromInt(int connectivityType);
 
-/**
-* @brief Convert EasySetupState Enum Value to int
-*/
-int convertNativeProvisionStateToInt(EasySetupState nativeState);
-
+WIFI_AUTHTYPE getWifiAuthTypeFromInt(int authType);
+WIFI_ENCTYPE getWifiEncTypeFromInt(int encType);
+int convertNativeWifiFreqToInt(WIFI_FREQ wifiFreq);
+int convertNativeWifiModeToInt(WIFI_MODE wifiMode);
+int convertNativeDataProvStateToInt(ESDataProvState nativeState);
+int convertNativeDataProvResultToInt(ESResult nativeResult);
 #endif //__JNI_ES_UTILS_H_
old mode 100644 (file)
new mode 100755 (executable)
index 2e02060..bf43627
 JavaVM *g_jvm = NULL;
 
 jclass g_cls_RemoteEnrollee = NULL;
+jclass g_cls_PropertyData = NULL;
+jclass g_cls_DeviceConfig = NULL;
+jclass g_cls_NetworkInfo = NULL;
+jclass g_cls_RequestPropertyDataStatus = NULL;
+jclass g_cls_SecurityProvisioningStatus = NULL;
+jclass g_cls_DataProvisioningStatus = NULL;
 jclass g_cls_ESException = NULL;
+jclass g_cls_CloudProvisioningStatus = NULL;
 
 jmethodID g_mid_RemoteEnrollee_ctor = NULL;
 jmethodID g_mid_ESException_ctor = NULL;
+jmethodID g_mid_PropertyData_ctor = NULL;
+jmethodID g_mid_DeviceConfig_ctor = NULL;
+jmethodID g_mid_NetworkInfo_ctor = NULL;
+jmethodID g_mid_RequestPropertyDataStatus_ctor = NULL;
+jmethodID g_mid_SecurityProvisioningStatus_ctor = NULL;
+jmethodID g_mid_DataProvisioningStatus_ctor = NULL;
+jmethodID g_mid_CloudProvisioningStatus_ctor = NULL;
 
 // JNI OnLoad
 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
@@ -42,7 +56,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
 
     jclass clazz = nullptr;
 
-    //Remote Enrollee
+    // Remote Enrollee
     clazz = env->FindClass("org/iotivity/service/easysetup/mediator/RemoteEnrollee");
     if (!clazz) return JNI_ERR;
     g_cls_RemoteEnrollee = (jclass)env->NewGlobalRef(clazz);
@@ -52,7 +66,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
                                 "(J)V");
     if (!g_mid_RemoteEnrollee_ctor) return JNI_ERR;
 
-    //ESException
+    // ESException
     clazz = env->FindClass("org/iotivity/service/easysetup/mediator/ESException");
     if (!clazz) return JNI_ERR;
     g_cls_ESException = (jclass)env->NewGlobalRef(clazz);
@@ -61,6 +75,83 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
     g_mid_ESException_ctor = env->GetMethodID(g_cls_ESException, "<init>", "(Ljava/lang/String;)V");
     if (!g_mid_ESException_ctor) return JNI_ERR;
 
+   // DeviceConfig
+    clazz = env->FindClass("org/iotivity/service/easysetup/mediator/DeviceConfig");
+    if (!clazz) return JNI_ERR;
+
+    g_cls_DeviceConfig = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_DeviceConfig_ctor = env->GetMethodID(g_cls_DeviceConfig, "<init>",
+                                "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
+    if (!g_mid_DeviceConfig_ctor) return JNI_ERR;
+
+    // NetworkInfo
+    clazz = env->FindClass("org/iotivity/service/easysetup/mediator/NetworkInfo");
+    if (!clazz) return JNI_ERR;
+
+    g_cls_NetworkInfo = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_NetworkInfo_ctor = env->GetMethodID(g_cls_NetworkInfo, "<init>",
+                                "(Ljava.util.ArrayList;I)V");
+    if (!g_mid_NetworkInfo_ctor) return JNI_ERR;
+
+    // PropertyData
+    clazz = env->FindClass("org/iotivity/service/easysetup/mediator/PropertyData");
+    if (!clazz) return JNI_ERR;
+
+    g_cls_PropertyData = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_PropertyData_ctor = env->GetMethodID(g_cls_PropertyData, "<init>",
+                                "(LDeviceConfig;LNetworkInfo;Z)V");
+    if (!g_mid_PropertyData_ctor) return JNI_ERR;
+
+    // RequestPropertyDataStatus
+
+    clazz = env->FindClass("org/iotivity/service/easysetup/mediator/RequestPropertyDataStatus");
+    if (!clazz) return JNI_ERR;
+
+    g_cls_RequestPropertyDataStatus = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_RequestPropertyDataStatus_ctor = env->GetMethodID(g_cls_RequestPropertyDataStatus, "<init>",
+                                "(ILPropertyData;)V");
+    if (!g_mid_RequestPropertyDataStatus_ctor) return JNI_ERR;
+
+    // SecurityProvisioningStatus
+    clazz = env->FindClass("org/iotivity/service/easysetup/mediator/SecurityProvisioningStatus");
+    if (!clazz) return JNI_ERR;
+
+    g_cls_SecurityProvisioningStatus = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_SecurityProvisioningStatus_ctor = env->GetMethodID(g_cls_SecurityProvisioningStatus, "<init>",
+                                "(ILjava/lang/String;)V");
+    if (!g_mid_SecurityProvisioningStatus_ctor) return JNI_ERR;
+
+    // DataProvisioningStatus
+    clazz = env->FindClass("org/iotivity/service/easysetup/mediator/DataProvisioningStatus");
+    if (!clazz) return JNI_ERR;
+
+    g_cls_DataProvisioningStatus = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_DataProvisioningStatus_ctor = env->GetMethodID(g_cls_DataProvisioningStatus, "<init>",
+                                "(II)V");
+    if (!g_mid_DataProvisioningStatus_ctor) return JNI_ERR;
+
+    // CloudProvisioningStatus
+    clazz = env->FindClass("org/iotivity/service/easysetup/mediator/CloudProvisioningStatus");
+    if (!clazz) return JNI_ERR;
+    g_cls_CloudProvisioningStatus = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_CloudProvisioningStatus_ctor = env->GetMethodID(g_cls_CloudProvisioningStatus, "<init>",
+                                "(II)V");
+    if (!g_mid_CloudProvisioningStatus_ctor) return JNI_ERR;
+
     return JNI_CURRENT_VERSION;
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index 8f69842..7b3726d
@@ -29,7 +29,7 @@
 #define __JNI_ES_JVM_H
 
 #include <jni.h>
-#include<string>
+#include <string>
 #include <android/log.h>
 
 #define ESTAG "ES-JNI"
@@ -43,9 +43,23 @@ extern JavaVM *g_jvm;
 
 extern jclass g_cls_RemoteEnrollee;
 extern jclass g_cls_ESException;
-
-extern jmethodID g_mid_RemoteEnrollee_ctor ;
+extern jclass g_cls_PropertyData;
+extern jclass g_cls_DeviceConfig;
+extern jclass g_cls_NetworkInfo;
+extern jclass g_cls_RequestPropertyDataStatus;
+extern jclass g_cls_SecurityProvisioningStatus;
+extern jclass g_cls_DataProvisioningStatus;
+extern jclass g_cls_CloudProvisioningStatus;
+
+extern jmethodID g_mid_RemoteEnrollee_ctor;
 extern jmethodID g_mid_ESException_ctor;
+extern jmethodID g_mid_PropertyData_ctor;
+extern jmethodID g_mid_DeviceConfig_ctor;
+extern jmethodID g_mid_NetworkInfo_ctor;
+extern jmethodID g_mid_RequestPropertyDataStatus_ctor;
+extern jmethodID g_mid_SecurityProvisioningStatus_ctor;
+extern jmethodID g_mid_DataProvisioningStatus_ctor;
+extern jmethodID g_mid_CloudProvisioningStatus_ctor;
 
 typedef void(*RemoveListenerCallback)(JNIEnv *env, jobject jListener);
 
old mode 100644 (file)
new mode 100755 (executable)
index 353d642..c84b68d
@@ -35,7 +35,6 @@ JniRemoteEnrollee::~JniRemoteEnrollee()
     if (NULL == env) return;
 
     if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
-
 }
 
 JniRemoteEnrollee *JniRemoteEnrollee::getJniRemoteEnrollee(JNIEnv *env, jobject thiz)
@@ -52,108 +51,221 @@ JniRemoteEnrollee *JniRemoteEnrollee::getJniRemoteEnrollee(JNIEnv *env, jobject
     return remoteEnrollee;
 }
 
-void JniRemoteEnrollee::startProvisioning(JNIEnv *env)
+void JniRemoteEnrollee::initRemoteEnrollee(JNIEnv *env)
 {
     try
     {
-        m_sharedResource->startProvisioning();
+        m_sharedResource->initRemoteEnrollee();
     }
     catch (ESBadRequestException exception)
     {
-        LOGE("JNI startProvisioning :: Exception occured");
+        LOGE("JNI initRemoteEnrollee :: Exception occured");
         //throw the exception to java
         throwESException( env,  exception.what());
     }
 }
-void JniRemoteEnrollee::stopProvisioning(JNIEnv *env)
+
+void JniRemoteEnrollee::requestPropertyData(JNIEnv *env, jobject jListener)
 {
+    JniRequestPropertyDataStatusListener *onRequestPropertyDataStatusReceived =
+                    addStatusListener<JniRequestPropertyDataStatusListener>(env, jListener);
+
+    RequestPropertyDataStatusCb requestPropertyDataStatusCallback = [onRequestPropertyDataStatusReceived]
+            (std::shared_ptr<OIC::Service::RequestPropertyDataStatus > requestPropertyDataStatus)
+    {
+        onRequestPropertyDataStatusReceived->requestPropertyDataStatusCallback(requestPropertyDataStatus);
+    };
+
     try
     {
-        m_sharedResource->stopProvisioning();
+        m_sharedResource->requestPropertyData(requestPropertyDataStatusCallback);
     }
     catch (ESBadRequestException exception)
     {
-        LOGE("JNI stopProvisioning :: Exception occured");
+        LOGE("JNI requestPropertyData :: Exception occured");
         //throw the exception to java
         throwESException( env,  exception.what());
     }
 }
 
-void JniRemoteEnrollee::registerProvisioningHandler(JNIEnv *env, jobject jListener)
+void JniRemoteEnrollee::startSecurityProvisioning(JNIEnv *env, jobject jListener)
 {
-    JniProvisioningStatusListener *onProvisioningStatusReceived = addProvisioningStatusListener(env,
-            jListener);
+    JniSecurityStatusListener *onSecurityProvStatusReceived =
+                    addStatusListener<JniSecurityStatusListener>(env, jListener);
+
+    SecurityProvStatusCb secProvStatusCallback = [onSecurityProvStatusReceived]
+            (std::shared_ptr<OIC::Service::SecProvisioningStatus > SecProvisioningStatus)
+    {
+        onSecurityProvStatusReceived->secProvisionStatusCallback(SecProvisioningStatus);
+    };
+
+    try
+    {
+        m_sharedResource->startSecurityProvisioning(secProvStatusCallback);
+    }
+    catch (ESBadRequestException exception)
+    {
+        LOGE("JNI startSecurityProvisioning :: Exception occured");
+        //throw the exception to java
+        throwESException( env,  exception.what());
+    }
+}
 
-    RemoteEnrollee::EasySetupStatusCB provisionStatusCallback = [onProvisioningStatusReceived]
-            (std::shared_ptr< OIC::Service::EasySetupStatus > easySetupStatus)
+void JniRemoteEnrollee::startDataProvisioning(JNIEnv *env, jobject jListener)
+{
+    JniDataProvisioningStatusListener *onDataProvStatusReceived =
+                    addStatusListener<JniDataProvisioningStatusListener>(env, jListener);
 
+    DataProvStatusCb dataProvStatusCallback = [onDataProvStatusReceived]
+            (std::shared_ptr<OIC::Service::DataProvisioningStatus > dataProvisioningStatus)
     {
-        onProvisioningStatusReceived->provisionStatusCallback(easySetupStatus);
+        onDataProvStatusReceived->dataProvisionStatusCallback(dataProvisioningStatus);
     };
 
     try
     {
-        m_sharedResource->registerEasySetupStatusHandler(provisionStatusCallback);
+        m_sharedResource->startDataProvisioning(dataProvStatusCallback);
     }
-    catch (ESException exception)
+    catch (ESBadRequestException exception)
     {
-        LOGE("JNI stopProvisioning :: Exception occured");
+        LOGE("JNI startDataProvisioning :: Exception occured");
         //throw the exception to java
         throwESException( env,  exception.what());
     }
+}
+
+void JniRemoteEnrollee::setDataProvInfo(JNIEnv *env, jstring jssid, jstring jpwd, jint jauthType,
+    jint jencType, jstring jlanguage, jstring jcountry)
+{
+    DataProvInfo info;
+
+    info.WIFI.ssid = env->GetStringUTFChars(jssid, NULL);
+    info.WIFI.pwd = env->GetStringUTFChars(jpwd, NULL);
+    info.WIFI.authtype = getWifiAuthTypeFromInt(jauthType);
+    info.WIFI.enctype = getWifiEncTypeFromInt(jencType);
+    info.Device.language = env->GetStringUTFChars(jlanguage, NULL);
+    info.Device.country = env->GetStringUTFChars(jcountry, NULL);
 
+    m_sharedResource->setDataProvInfo(info);
 }
 
-JniProvisioningStatusListener *JniRemoteEnrollee::addProvisioningStatusListener(JNIEnv *env,
-        jobject jListener)
+void JniRemoteEnrollee::setCloudProvInfo(JNIEnv *env, jstring jauthCode, jstring jauthProvider, jstring jciServer)
 {
-    return this->m_provisioingStatus.addListener(env, jListener, this);
+    CloudProvInfo info;
+    info.authCode = env->GetStringUTFChars(jauthCode, NULL);
+    info.authProvider = env->GetStringUTFChars(jauthProvider, NULL);
+    info.ciServer = env->GetStringUTFChars(jciServer, NULL);
+
+    m_sharedResource->setCloudProvInfo(info);
 }
 
-void JniRemoteEnrollee::removeProvisioningStatusListener(JNIEnv *env, jobject jListener)
+void JniRemoteEnrollee::startCloudProvisioning(JNIEnv *env, jobject jListener)
 {
-    this->m_provisioingStatus.removeListener(env, jListener);
+    JniCloudProvisioningStatusListener *onCloudProvisioningStatusReceived =
+                    addStatusListener<JniCloudProvisioningStatusListener>(env, jListener);
+
+    CloudProvStatusCb provisionStatusCallback = [onCloudProvisioningStatusReceived]
+            (std::shared_ptr< OIC::Service::CloudProvisioningStatus > cloudProvisioningStatus)
+
+    {
+        onCloudProvisioningStatusReceived->onCloudProvisioningStatus(cloudProvisioningStatus);
+    };
+
+    try
+    {
+        m_sharedResource->startCloudProvisioning(provisionStatusCallback);
+    }
+    catch (ESBadRequestException exception)
+    {
+        LOGE("JNI startProvisioning :: Exception occured");
+        //throw the exception to java
+        throwESException(env, exception.what());
+    }
 }
 
+//JNI
 JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartProvision
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeInitRemoteEnrollee
 (JNIEnv *env, jobject jClass)
 {
-    LOGD("nativeStartProvision Enter");
+    LOGD("nativeInitRemoteEnrollee Enter");
 
     JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
-    remoteEnrollee->startProvisioning(env);
+    remoteEnrollee->initRemoteEnrollee(env);
 
-    LOGD("nativeStartProvision Exit");
+    LOGD("nativeInitRemoteEnrollee Exit");
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStopProvision
-(JNIEnv *env, jobject jClass)
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeRequestPropertyData
+(JNIEnv *env, jobject jClass, jobject jListener)
 {
+    LOGD("nativeRequestPropertyData Enter");
 
-    LOGD("nativeStopProvision Enter");
+    JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+    remoteEnrollee->requestPropertyData(env, jListener);
+
+    LOGD("nativeRequestPropertyData Exit");
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartSecurityProvision
+(JNIEnv *env, jobject jClass, jobject jListener)
+{
+    LOGD("nativeStartSecurityProvision Enter");
 
     JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
-    remoteEnrollee->stopProvisioning(env);
+    remoteEnrollee->startSecurityProvisioning(env, jListener);
 
-    LOGD("nativeStopProvision Exit");
+    LOGD("nativeStartSecurityProvision Exit");
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeRegisterProvisioningHandler
-(JNIEnv *env, jobject jClass, jobject provisiongListener)
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartDataProvision
+(JNIEnv *env, jobject jClass, jobject jListener)
 {
-    LOGD("nativeRegisterProvisioningHandler Enter");
+    LOGD("nativeStartDataProvision Enter");
+
+    JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+    remoteEnrollee->startDataProvisioning(env, jListener);
+
+    LOGD("nativeStartDataProvision Exit");
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetDataProvInfo
+(JNIEnv *env, jobject jClass, jstring jssid, jstring jpwd, jint jauthType, jint jencType,
+    jstring jlanguage, jstring jcountry)
+{
+    LOGD("nativeSetDataProvInfo Enter");
 
-    if (!provisiongListener)
-    {
-        LOGE("nativeRegisterProvisioningHandler : listener is NULL");
-        return;
-    }
     JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
-    remoteEnrollee->registerProvisioningHandler(env, provisiongListener);
+    remoteEnrollee->setDataProvInfo(env, jssid, jpwd, jauthType, jencType, jlanguage, jcountry);
 
-    LOGD("nativeRegisterProvisioningHandler Exit");
+    LOGD("nativeSetDataProvInfo Exit");
 }
 
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetCloudProvInfo
+(JNIEnv *env, jobject jClass, jstring jauthCode, jstring jauthProvider, jstring jciServer)
+{
+    LOGD("nativeSetCloudProvInfo Enter");
+
+    // TODO
+    JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+    remoteEnrollee->setCloudProvInfo(env, jauthCode, jauthProvider, jciServer);
+
+    LOGD("nativeSetCloudProvInfo Exit");
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartCloudProvisioning
+(JNIEnv *env, jobject jClass, jobject jListener)
+{
+    LOGD("nativeStartCloudProvisioning Enter");
+
+    JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
+    remoteEnrollee->startCloudProvisioning(env, jListener);
+
+    LOGD("nativeStartCloudProvisioning Exit");
+}
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index de1f297..22a12ec
 
 #include "JniJvm.h"
 #include "JniEsUtils.h"
-#include "JniProvisioningStatusListener.h"
+#include "JniRequestPropertyDataStatusListener.h"
+#include "JniSecurityStatusListener.h"
+#include "JniDataProvisioningStatusListener.h"
+#include "JniCloudProvisioningStatusListener.h"
 #include "JniEsListenerManager.h"
 
 using namespace OIC::Service;
@@ -59,18 +62,30 @@ class JniRemoteEnrollee
         ~JniRemoteEnrollee();
 
         // ***** JNI APIs internally call the APIs of this class ***** //
+        void initRemoteEnrollee(JNIEnv *env);
+        void requestPropertyData(JNIEnv *env, jobject jListener);
+        void startSecurityProvisioning(JNIEnv *env, jobject jListener);
+        void startDataProvisioning(JNIEnv *env, jobject jListener);
+        void startCloudProvisioning(JNIEnv *env, jobject jListener);
+        void setDataProvInfo(JNIEnv *env, jstring jssid, jstring jpwd, jint jauthType,
+                                            jint jencType, jstring jlanguage, jstring jcountry);
+        void setCloudProvInfo(JNIEnv *env, jstring authCode, jstring authProvider, jstring ciServer);
 
-        void startProvisioning(JNIEnv *env);
-        void stopProvisioning(JNIEnv *env);
-        void registerProvisioningHandler(JNIEnv *env, jobject jListener);
+        static JniRemoteEnrollee *getJniRemoteEnrollee(JNIEnv *env, jobject thiz);
 
-        JniProvisioningStatusListener *addProvisioningStatusListener(JNIEnv *env, jobject jListener);
-        void removeProvisioningStatusListener(JNIEnv *env, jobject jListener);
+        template <class T>
+        T *addStatusListener(JNIEnv *env, jobject jListener)
+        {
+            return JniEsListenerManager<T>().addListener(env, jListener, this);
+        };
 
-        static JniRemoteEnrollee *getJniRemoteEnrollee(JNIEnv *env, jobject thiz);
+        template <class T>
+        void removeStatusListener(JNIEnv *env, jobject jListener)
+        {
+            JniEsListenerManager<T>().removeListener(env, jListener);
+        };
 
     private:
-        JniEsListenerManager<JniProvisioningStatusListener> m_provisioingStatus;
         std::shared_ptr<RemoteEnrollee> m_sharedResource;
 
 };
@@ -81,27 +96,54 @@ extern "C" {
 #endif
 
 /**
- * API for starting the provisioning process.
+ * API for starting the initRemoteEnrollee process.
  */
 JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartProvision
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeInitRemoteEnrollee
 (JNIEnv *env, jobject jClass);
 
 /**
- * API for stopping the provisioning process.
+ * API for starting the Request PropertyData process.
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeRequestPropertyData
+(JNIEnv *env, jobject jClass, jobject jListener);
+
+/**
+ * API for starting the Sequrity provisioning process.
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartSecurityProvision
+(JNIEnv *env, jobject jClass, jobject jListener);
+
+/**
+ * API for starting the Data provisioning process.
  */
 JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStopProvision
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartDataProvision
 (JNIEnv *env, jobject jClass);
 
 /**
- * API for setting the lisener for recieiving provisioning status.
- *
- * @param provisiongListener - Provisioning listener [callback from native layer will be passing to this listener]
+ * API for setting data provisioning information.
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetDataProvInfo
+(JNIEnv *env, jobject jClass, jstring jssid, jstring jpwd, jint jauthType, jint jencType,
+    jstring jlanguage, jstring jcountry);
+
+/**
+ * API for setting cloud provisioning information.
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeSetCloudProvInfo
+(JNIEnv *env, jobject jClass, jstring jauthCode, jstring jauthProvider, jstring jciServer);
+
+/**
+ * API for starting the cloud provisioning process.
  */
 JNIEXPORT void JNICALL
-Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeRegisterProvisioningHandler
-(JNIEnv *env, jobject jClass, jobject provisiongListener);
+Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartCloudProvisioning
+(JNIEnv *env, jobject jClass, jobject jListener);
 
 #ifdef __cplusplus
 }
diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniRequestPropertyDataStatusListener.cpp b/service/easy-setup/mediator/richsdk/android/jni/JniRequestPropertyDataStatusListener.cpp
new file mode 100644 (file)
index 0000000..b70bdca
--- /dev/null
@@ -0,0 +1,155 @@
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "JniRequestPropertyDataStatusListener.h"
+#include "JniRemoteEnrollee.h"
+
+using namespace OIC::Service;
+
+JniRequestPropertyDataStatusListener::JniRequestPropertyDataStatusListener(JNIEnv *env, jobject jListener,
+        JniRemoteEnrollee *owner)
+    : m_ownerResource(owner)
+{
+    m_jwListener = env->NewWeakGlobalRef(jListener);
+}
+
+JniRequestPropertyDataStatusListener::~JniRequestPropertyDataStatusListener()
+{
+    LOGI("~JniRequestPropertyDataStatusListener()");
+    if (m_jwListener)
+    {
+        jint ret;
+        JNIEnv *env = GetESJNIEnv(ret);
+        if (NULL == env) return;
+        env->DeleteWeakGlobalRef(m_jwListener);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+    }
+}
+
+void JniRequestPropertyDataStatusListener::requestPropertyDataStatusCallback (
+    std::shared_ptr<RequestPropertyDataStatus> requestPropertyDataStatusCb)
+{
+    LOGI("JniRequestPropertyDataStatusListener::provisioiningStatusCallback enter");
+
+    jint ret;
+    JNIEnv *env = GetESJNIEnv(ret);
+    if (NULL == env) return;
+    jobject jListener = env->NewLocalRef(m_jwListener);
+    if (!jListener)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    jclass clsL = env->GetObjectClass(jListener);
+    if (!clsL)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    jmethodID midL = env->GetMethodID(clsL, "onProgress",
+                                      "(Lorg/iotivity/service/easysetup/mediator/"
+                                      "RequestPropertyDataStatus;"
+                                      ")V");
+
+    if (!midL)
+    {
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    const PropertyData propertyData = requestPropertyDataStatusCb->getPropertyData();
+    DeviceConfig devConf = propertyData.getDevConf();
+    NetworkInfo netInfo = propertyData.getNetInfo();
+
+    jobject jDevConf = NULL;
+    jDevConf = env->NewObject(g_cls_DeviceConfig,
+                                                g_mid_DeviceConfig_ctor,
+                                                (jstring)env->NewStringUTF(devConf.id.c_str()),
+                                                (jstring)env->NewStringUTF(devConf.name.c_str()),
+                                                (jstring)env->NewStringUTF(devConf.language.c_str()),
+                                                (jstring)env->NewStringUTF(devConf.country.c_str()));
+
+    jclass clazz = (*env).FindClass("java/util/ArrayList");
+    jobject wifiModeTypes = (*env).NewObject(clazz, (*env).GetMethodID(clazz, "<init>", "()V"));
+
+    for (int n=0; n<netInfo.types.size(); n++)
+    {
+       (*env).CallBooleanMethod(wifiModeTypes, (*env).GetMethodID(clazz, "add", "(java/lang/Object;)Z"),
+                                             convertNativeWifiModeToInt(static_cast<WIFI_MODE>(netInfo.types[n])));
+    }
+
+    jobject jNetInfo = NULL;
+    jNetInfo = env->NewObject(g_cls_NetworkInfo,
+                                                g_mid_NetworkInfo_ctor,
+                                                (jobject)wifiModeTypes,
+                                                (jint)convertNativeWifiFreqToInt(netInfo.freq));
+
+    jobject jPropertyData = NULL;
+    jPropertyData = env->NewObject(g_cls_PropertyData,
+                                                g_mid_PropertyData_ctor,
+                                                (jobject)jDevConf,
+                                                (jobject)jNetInfo,
+                                                (jboolean)propertyData.isCloudable());
+
+    jobject jRequestPropertyDataStatus = NULL;
+    jRequestPropertyDataStatus = env->NewObject(g_cls_RequestPropertyDataStatus,
+                                                g_mid_RequestPropertyDataStatus_ctor,
+                                                convertNativeDataProvResultToInt(requestPropertyDataStatusCb->getESResult()),
+                                                (jobject)jPropertyData);
+
+    if (!jRequestPropertyDataStatus)
+    {
+        LOGE("JniRequestPropertyDataStatusListener::requestPropertyDataStatusCallback Unable to create the java object");
+        return ;
+    }
+
+    env->CallVoidMethod(jListener, midL, jRequestPropertyDataStatus);
+
+    if (env->ExceptionCheck())
+    {
+        LOGE("Java exception is thrown");
+        checkExAndRemoveListener(env);
+        if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+        return;
+    }
+
+    if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
+}
+
+void JniRequestPropertyDataStatusListener::checkExAndRemoveListener(JNIEnv *env)
+{
+    if (env->ExceptionCheck())
+    {
+        jthrowable ex = env->ExceptionOccurred();
+        env->ExceptionClear();
+        m_ownerResource->removeStatusListener<JniRequestPropertyDataStatusListener>(env, m_jwListener);
+
+        env->Throw((jthrowable)ex);
+    }
+    else
+    {
+        m_ownerResource->removeStatusListener<JniRequestPropertyDataStatusListener>(env, m_jwListener);
+    }
+}
diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniRequestPropertyDataStatusListener.h b/service/easy-setup/mediator/richsdk/android/jni/JniRequestPropertyDataStatusListener.h
new file mode 100644 (file)
index 0000000..97acf72
--- /dev/null
@@ -0,0 +1,59 @@
+/******************************************************************
+ *
+ * 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 __JNI_ES_REQUEST_PROPERTY_DATA_STATUS_LISTENER_H_
+#define __JNI_ES_REQUEST_PROPERTY_DATA_STATUS_LISTENER_H_
+
+#include <jni.h>
+
+#include "RemoteEnrollee.h"
+#include "ESRichCommon.h"
+
+#include "JniJvm.h"
+
+class JniRemoteEnrollee;
+
+using namespace OIC::Service;
+
+class JniRequestPropertyDataStatusListener
+{
+    public:
+        /**
+         * @brief constructor
+         */
+        JniRequestPropertyDataStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource);
+
+        /**
+         * @brief destructor
+        */
+        ~JniRequestPropertyDataStatusListener();
+
+        /**
+         * @brief callback function that will be passed to Native layer
+        */
+        void requestPropertyDataStatusCallback (std::shared_ptr<RequestPropertyDataStatus> requestPropertyDataStatus);
+
+    private:
+        jweak m_jwListener;
+        JniRemoteEnrollee *m_ownerResource;
+        void checkExAndRemoveListener(JNIEnv *env);
+};
+
+#endif //__JNI_ES_REQUEST_PROPERTY_DATA_STATUS_LISTENER_H_
  *
  ******************************************************************/
 
-#include "JniProvisioningStatusListener.h"
+#include "JniSecurityStatusListener.h"
 #include "JniRemoteEnrollee.h"
 
 using namespace OIC::Service;
 
-JniProvisioningStatusListener::JniProvisioningStatusListener(JNIEnv *env, jobject jListener,
+JniSecurityStatusListener::JniSecurityStatusListener(JNIEnv *env, jobject jListener,
         JniRemoteEnrollee *owner)
     : m_ownerResource(owner)
 {
     m_jwListener = env->NewWeakGlobalRef(jListener);
 }
 
-JniProvisioningStatusListener::~JniProvisioningStatusListener()
+JniSecurityStatusListener::~JniSecurityStatusListener()
 {
-    LOGI("~JniProvisioningStatusListener()");
+    LOGI("~JniSecurityStatusListener()");
     if (m_jwListener)
     {
         jint ret;
@@ -42,12 +42,11 @@ JniProvisioningStatusListener::~JniProvisioningStatusListener()
         if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
     }
 }
-
-void JniProvisioningStatusListener::provisionStatusCallback (std::shared_ptr<EasySetupStatus>
-        easySetupStatus)
+void JniSecurityStatusListener::secProvisionStatusCallback(
+                std::shared_ptr<SecProvisioningStatus> secProvisioningStatus)
 {
 
-    LOGI("JniProvisioningStatusListener::provisioiningStatusCallback enter");
+    LOGI("JniSecurityStatusListener::secProvisionStatusCallback enter");
 
     jint ret;
     JNIEnv *env = GetESJNIEnv(ret);
@@ -68,8 +67,11 @@ void JniProvisioningStatusListener::provisionStatusCallback (std::shared_ptr<Eas
         return;
     }
 
-    jmethodID midL = env->GetMethodID(clsL, "onStatusRecieved",
-                                      "(I)V");
+    jmethodID midL = env->GetMethodID(clsL, "onProgress",
+                                      "(Lorg/iotivity/service/easysetup/mediator/"
+                                      "SecurityProvisioningStatus;"
+                                      ")V");
+
     if (!midL)
     {
         checkExAndRemoveListener(env);
@@ -77,9 +79,23 @@ void JniProvisioningStatusListener::provisionStatusCallback (std::shared_ptr<Eas
         return;
     }
 
-    EasySetupState nativeProvisioningState = easySetupStatus->getEasySetupState();
-    int provisionState = convertNativeProvisionStateToInt(nativeProvisioningState);
-    env->CallVoidMethod(jListener, midL, provisionState);
+    ESResult esResult = secProvisioningStatus->getESResult();
+
+    //create the java object
+    jobject jSecurityProvisioningStatus = NULL;
+    jSecurityProvisioningStatus = env->NewObject(g_cls_SecurityProvisioningStatus,
+                                                g_mid_SecurityProvisioningStatus_ctor,
+                                                (jint)esResult,
+                                                (jstring)env->NewStringUTF(secProvisioningStatus->getDeviceUUID().c_str()));
+
+    if (!jSecurityProvisioningStatus)
+    {
+        LOGE("JniSecurityStatusListener::onSecurityProvisioningStatus Unable to create the java object");
+        return ;
+    }
+
+    env->CallVoidMethod(jListener, midL, jSecurityProvisioningStatus);
+
     if (env->ExceptionCheck())
     {
         LOGE("Java exception is thrown");
@@ -91,17 +107,17 @@ void JniProvisioningStatusListener::provisionStatusCallback (std::shared_ptr<Eas
     if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
 }
 
-void JniProvisioningStatusListener::checkExAndRemoveListener(JNIEnv *env)
+void JniSecurityStatusListener::checkExAndRemoveListener(JNIEnv *env)
 {
     if (env->ExceptionCheck())
     {
         jthrowable ex = env->ExceptionOccurred();
         env->ExceptionClear();
-        m_ownerResource->removeProvisioningStatusListener(env, m_jwListener);
+        m_ownerResource->removeStatusListener<JniSecurityStatusListener>(env, m_jwListener);
         env->Throw((jthrowable)ex);
     }
     else
     {
-        m_ownerResource->removeProvisioningStatusListener(env, m_jwListener);
+        m_ownerResource->removeStatusListener<JniSecurityStatusListener>(env, m_jwListener);
     }
 }
diff --git a/service/easy-setup/mediator/richsdk/android/jni/JniSecurityStatusListener.h b/service/easy-setup/mediator/richsdk/android/jni/JniSecurityStatusListener.h
new file mode 100644 (file)
index 0000000..96cd896
--- /dev/null
@@ -0,0 +1,59 @@
+/******************************************************************
+ *
+ * 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 __JNI_ES_SECURITY_PROVISIONING_STATUS_LISTENER_H_
+#define __JNI_ES_SECURITY_PROVISIONING_STATUS_LISTENER_H_
+
+#include <jni.h>
+
+#include "RemoteEnrollee.h"
+#include "ESRichCommon.h"
+
+#include "JniJvm.h"
+
+class JniRemoteEnrollee;
+
+using namespace OIC::Service;
+
+class JniSecurityStatusListener
+{
+    public:
+        /**
+         * @brief constructor
+         */
+        JniSecurityStatusListener(JNIEnv *env, jobject jListener, JniRemoteEnrollee *resource);
+
+        /**
+         * @brief destructor
+        */
+        ~JniSecurityStatusListener();
+
+        /**
+         * @brief callback function that will be passed to Native layer
+        */
+        void secProvisionStatusCallback (std::shared_ptr<SecProvisioningStatus> secProvisioningStatus);
+
+    private:
+        jweak m_jwListener;
+        JniRemoteEnrollee *m_ownerResource;
+        void checkExAndRemoveListener(JNIEnv *env);
+};
+
+#endif //__JNI_ES_SECURITY_PROVISIONING_STATUS_LISTENER_H_
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 e9e344b..77e2110 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
-
-/**
- * @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_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_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_URI_PROV               "/oic/prov"
-#define OC_RSRVD_ES_URI_NET                "/oic/net"
+#define OC_RSRVD_ES_PROV_RES_TYPE                 "ocf.r.prov"
+#define OC_RSRVD_ES_URI_PROV                           "/.well-known/ocf/prov"
+#define OC_RSRVD_ES_RES_TYPE_WIFI                   "ocf.r.wifi"
+#define OC_RSRVD_ES_URI_WIFI                             "/.well-known/ocf/prov/wifi"
+#define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.r.cloudserver"
+#define OC_RSRVD_ES_URI_CLOUDSERVER            "/.well-known/ocf/prov/cloudserver"
+#define OC_RSRVD_ES_RES_TYPE_DEVCONF          "ocf.r.devconf"
+#define OC_RSRVD_ES_URI_DEVCONF                    "/.well-known/ocf/prov/devconf"
 
 /**
  * @brief Defines for Provisioning status accepted values
@@ -74,26 +81,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,159 +93,86 @@ namespace OIC
             ES_RECVREQOFNETRES,
             ES_RECVUPDATEOFPROVRES,
             ES_RECVTRIGGEROFPROVRES,
+            ES_UNAUTHORIZED = 31
         } ESResult;
 
+        /**
+         * @brief  WIFI Authentication type of the Enroller
+         */
         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;
+            NONE_AUTH = 0,
+            WEP,
+            WPA_PSK,
+            WPA2_PSK
+        } WIFI_AUTHTYPE;
 
         /**
-         * Provisioning Device Status
+         * @brief  WIFI ecnrytion type of the Enroller
          */
-        typedef struct
+        typedef enum
         {
-            // Address of remote server
-            OCDevAddr * addr;
-            // Indicates adaptor type on which the response was received
-            OCConnectivityType connType;
-        } EasySetupDeviceInfo;
+            NONE_ENC = 0,
+            WEP_64,
+            WEP_128,
+            TKIP,
+            AES,
+            TKIP_AES
+        } WIFI_ENCTYPE;
 
-        /**
-         * Provosioning Status
-         */
         typedef enum
         {
-            DEVICE_PROVISIONED = 0,
-            DEVICE_NOT_PROVISIONED,
-            DEVICE_OWNED,
-            DEVICE_NOT_OWNED
-        } EasySetupState, ProvStatus;
+            WIFI_24G = 0,
+            WIFI_5G,
+            WIFI_BOTH
+        } WIFI_FREQ;
+
+        typedef enum
+        {
+            WIFI_11A = 0,
+            WIFI_11B,
+            WIFI_11G,
+            WIFI_11N,
+            WIFI_11AC
+        } WIFI_MODE;
 
-        /**
-         * Response from queries to remote servers.
-         */
         typedef struct
         {
-            // EasySetup Status
-            EasySetupState provStatus;
-            // EasySetup Device Info
-            EasySetupDeviceInfo provDeviceInfo;
-        } EasySetupInfo, ProvisioningInfo;
+            string authCode;
+            string authProvider;
+            string ciServer;
+        } CloudProvInfo;
 
-        /**
-         * @brief  Network information of the Enroller
-         */
-        typedef union
+        typedef struct
         {
-            /**
-             * @brief BT Mac Information
-             */
             struct
             {
-                char btMacAddress[NET_MACADDR_SIZE];   /**< BT mac address **/
-            } BT;
+                string ssid; /**< ssid of the Enroller**/
+                string pwd; /**< pwd of the Enroller**/
+                WIFI_AUTHTYPE authtype; /**< auth type of the Enroller**/
+                WIFI_ENCTYPE enctype; /**< encryption type of the Enroller**/
+            } WIFI;
 
-            /**
-             * @brief LE MAC Information
-             */
             struct
             {
-                char leMacAddress[NET_MACADDR_SIZE];   /**< BLE mac address **/
-            } LE;
+                string language;
+                string country;
+            } Device;
+        } DataProvInfo;
 
-            /**
-             * @brief IP Information
-             */
-            struct
-            {
-                char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
-                char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
-            } WIFI;
-        } ProvData;
-
-        /**
-         * @brief Network Information
-         */
         typedef struct
         {
-            ProvData provData;    /**< Enroller Network Info**/
-            OCConnectivityType connType;    /**< Connectivity Type**/
-        } 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.
-        */
+            string id;
+            string name;
+            string language;
+            string country;
+        } DeviceConfig;
 
-        // 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
-        {
-         /*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
         {
@@ -266,15 +180,15 @@ namespace OIC
             ES_NEED_PROVISIONING,
             ES_PROVISIONED_ALREADY,
             ES_PROVISIONING_SUCCESS
-        } ESState;
+        } ESDataProvState;
 
         typedef enum
         {
-            ES_UNKNOWN = 0,
-            ES_ONBOARDED,
-            ES_OWNED,
-            ES_PROVISIONED
-        } CurrentESState;
+            ES_CLOUD_PROVISIONING_ERROR = -1,
+            ES_CLOUD_PROVISIONING_SUCCESS,
+            ES_CLOUD_ENROLLEE_FOUND,
+            ES_CLOUD_ENROLLEE_NOT_FOUND
+        }ESCloudProvState;
 
         typedef enum
         {
@@ -287,53 +201,67 @@ namespace OIC
         /**
          * Security Provisioning Status
          */
-        class SecProvisioningResult
+        class SecProvisioningStatus
         {
         public:
-            std::shared_ptr< SecProvisioningResult > shared_ptr;
-            SecProvisioningResult(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;
             }
 
-            ESResult getResult()
+            ESResult getESResult()
             {
                 return m_result;
             }
         private:
-            std::string m_devUUID;
+            string m_devUUID;
             ESResult m_result;
         };
 
-        /**
-         * Callback function definition for providing Enrollee security status .
-         */
-        typedef std::function< void(std::shared_ptr<SecProvisioningResult>) > EnrolleeSecStatusCb;
+        class PropertyData
+        {
+        public:
+            PropertyData()
+            {
+            }
 
-        /**
-         * Callback definition to be invoked when the security stack expects a pin from application.
-         */
-        typedef std::function< void(std::string&) > SecurityPinCb;
+            PropertyData(DeviceConfig devConfig, NetworkInfo netInfo, bool cloudable) :
+                m_devConfig(devConfig), m_netInfo(netInfo), m_cloudable(cloudable)
+            {
+            }
 
-        /**
-         * Callback definition to be invoked when the stack expects a db path.
-         */
-        typedef std::function< void(std::string&) > SecProvisioningDbPathCb;
+            const DeviceConfig& getDevConf() const
+            {
+                return m_devConfig;
+            }
+
+            const NetworkInfo& getNetInfo() const
+            {
+                return m_netInfo;
+            }
+
+            const bool isCloudable() const
+            {
+                return m_cloudable;
+            }
 
-        class ProvisioningStatus
+        private:
+            DeviceConfig m_devConfig;
+            NetworkInfo m_netInfo;
+            bool m_cloudable;
+        };
+
+        class RequestPropertyDataStatus
         {
         public:
-            std::shared_ptr< ProvisioningStatus > shared_ptr;
-            ProvisioningStatus(ESResult result, ESState esState) :
-                    m_result(result), m_esState(esState)
+            RequestPropertyDataStatus(ESResult result, const PropertyData& data) :
+                    m_result(result), m_propertyData(data)
             {
-
             }
 
             ESResult getESResult()
@@ -341,39 +269,92 @@ namespace OIC
                 return m_result;
             }
 
-            ESState getESState()
+            const PropertyData& getPropertyData()
             {
-                return m_esState;
+                return m_propertyData;
             }
+
         private:
             ESResult m_result;
-            ESState m_esState;
+            PropertyData m_propertyData;
         };
 
-        class EasySetupStatus
+        class DataProvisioningStatus
         {
         public:
-            std::shared_ptr< EasySetupStatus > shared_ptr;
-            EasySetupStatus(const EasySetupState& easySetupState,
-                    const ProvConfig& provConfig) :
-                    m_easySetupState(easySetupState), m_ProvConfig(provConfig)
+            DataProvisioningStatus(ESResult result, ESDataProvState dataProvState) :
+                    m_result(result), m_state(dataProvState)
             {
+            }
 
+            ESResult getESResult()
+            {
+                return m_result;
+            }
+
+            ESDataProvState getESDataProvState()
+            {
+                return m_state;
+            }
+
+        private:
+            ESResult m_result;
+            ESDataProvState m_state;
+        };
+
+        class CloudProvisioningStatus
+        {
+        public:
+            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 function< void(shared_ptr< RequestPropertyDataStatus >) > RequestPropertyDataStatusCb;
+
+        /**
+         * Callback function definition for providing Enrollee security status .
+         */
+        typedef function< void(shared_ptr< DataProvisioningStatus >) > DataProvStatusCb;
+
+        /**
+         * Callback function definition for providing Enrollee security status .
+         */
+        typedef function< void(shared_ptr< CloudProvisioningStatus >) > CloudProvStatusCb;
+
+        /**
+         * Callback function definition for providing Enrollee security status .
+         */
+        typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
+
+        /**
+         * Callback definition to be invoked when the security stack expects a pin from application.
+         */
+        typedef function< void(string&) > SecurityPinCb;
+
+        /**
+         * Callback definition to be invoked when the stack expects a db path.
+         */
+        typedef function< void(string&) > SecProvisioningDbPathCb;
+
     }
 }
 #endif //WITH_ARDUINO
index b7914f4..058ae2e 100644 (file)
@@ -50,29 +50,19 @@ namespace OIC
             static EasySetup* getInstance();
 
             /**
-             * This API is used for creating a remote Enrollee device instance.
-             * @param ProvConfig Provisioning information for configuring the Enrollee.
-             * @param WiFiOnboadingConnection Onboarding connection information for configuring the Enrollee.
+             * This API is used for creating a remote Enrollee  instance.
              *
              * @throws ESBadRequestException If createEnrolleeDevice is invoked with the same
              *         provisioning information.
              *
              * @return Pointer to RemoteEnrollee instance.
              */
-            std::shared_ptr<RemoteEnrollee> createEnrolleeDevice (
-                         const ProvConfig& enrolleeNWProvInfo,
-                         const WiFiOnboadingConnection& wifiOnboardingconn);
+            std::shared_ptr<RemoteEnrollee> createRemoteEnrollee();
+
         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(std::shared_ptr< OC::OCResource > resource);
+            // EnrolleeResource(const DataProvInfo &enrolleeNWProvInfo,
+            //                                    const WiFiOnboadingConnection &onboardingconn);
 
-            ~RemoteEnrolleeResource() = default;
+            ~EnrolleeResource() = default;
 
             /**
              * Register provisioning status handler.
@@ -71,27 +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 registerProvStatusCallback (ProvStatusCb provStatusCb);
+            void registerRequestPropertyDataStatusCallback (RequestPropertyDataStatusCb callback);
+            void registerProvStatusCallback (DataProvStatusCb callback);
 
-            /**
-             * Construct Remote OIC resource using the enrollee host and connectivity information
-             * provided in the constructor of RemoteEnrolleeResource.
-             *
-             * @throws InvalidParameterException If the provided information is invalid.
-             * @throws ESBadRequestException If resource is already constructed.
-             *
-             * @see ProvisioningStatus
-             */
-            ESResult constructResourceObject();
+            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
@@ -100,31 +90,22 @@ namespace OIC
              */
             void unprovisionEnrollee();
 
-
-
         private:
             std::shared_ptr< OC::OCResource > m_ocResource;
-            std::mutex m_mutex;
-            ProvStatusCb m_provStatusCb;
-            ProvConfig m_ProvConfig;
-            WiFiOnboadingConnection m_wifiOnboardingconn;
-            bool m_discoveryResponse;
 
+            RequestPropertyDataStatusCb m_RequestPropertyDataStatusCb;
+            DataProvStatusCb m_dataProvStatusCb;
+
+            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 5308b0b..face112 100755 (executable)
@@ -32,7 +32,7 @@ namespace OIC
     {
 #define ENROLEE_SECURITY_TAG "ENROLEE_SECURITY"
 
-        class RemoteEnrolleeResource;
+        class EnrolleeResource;
         class OCSecureResource;
 
         /**
@@ -43,15 +43,15 @@ namespace OIC
         class EnrolleeSecurity
         {
         public:
-            EnrolleeSecurity(std::shared_ptr< RemoteEnrolleeResource > remoteEnrolleeResource,
+            EnrolleeSecurity(std::shared_ptr< EnrolleeResource > EnrolleeResource,
             std::string secDbPath);
-            ESResult registerCallbackHandler(EnrolleeSecStatusCb enrolleeSecStatusCb,
+            ESResult registerCallbackHandler(SecurityProvStatusCb securityProvStatusCb,
                     SecurityPinCb securityPinCb, SecProvisioningDbPathCb secProvisioningDbPathCb);
-            EasySetupState performOwnershipTransfer();
+            bool performOwnershipTransfer();
 
         private:
-            std::shared_ptr< RemoteEnrolleeResource > m_remoteEnrolleeResource;
-            EnrolleeSecStatusCb m_enrolleeSecStatusCb;
+            std::shared_ptr< EnrolleeResource > m_EnrolleeResource;
+            SecurityProvStatusCb m_securityProvStatusCb;
             SecurityPinCb m_securityPinCb;
             SecProvisioningDbPathCb m_secProvisioningDbPathCb;
             std::shared_ptr< OC::OCSecureResource > m_unownedDevice;
old mode 100644 (file)
new mode 100755 (executable)
index 1fb83b3..cbc5ac2
 #ifndef REMOTE_ENROLLEE_H_
 #define REMOTE_ENROLLEE_H_
 
+#include <memory>
+
 #include "ESRichCommon.h"
+#include "OCApi.h"
+
+using namespace OC;
 
 namespace OIC
 {
     namespace Service
     {
-        class RemoteEnrolleeResource;
+        class OCResource;
+        class EnrolleeResource;
+        class CloudResource;
         class EnrolleeSecurity;
 
         /**
@@ -38,30 +45,8 @@ 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 ProvConfig& enrolleeNWProvInfo, const WiFiOnboadingConnection& connection) ;
-
             ~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 +65,13 @@ namespace OIC
 #endif //__WITH_DTLS__
 
             /**
-             * Register EasySetup status handler.
-             *
-             * @param callback Callback to get EasySetup status.
-             * @param secProvisioningDbCB Callback to be invoked when the stack expects a
-             *        path for the provisioning db.
+             * Start provisioning of target Enrollers information to the Enrollee.
              *
-             * @throws InvalidParameterException If callback is an empty function or null.
-             * @throws ESBadRequestException If registration is already completed.
+             * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
              *
-             * @see EasySetupStatus
+             * @see RemoteEnrollee
              */
-            void registerEasySetupStatusHandler(EasySetupStatusCB callback);
+            void  initRemoteEnrollee();
 
             /**
              * Start provisioning of target Enrollers information to the Enrollee.
@@ -100,51 +80,79 @@ namespace OIC
              *
              * @see RemoteEnrollee
              */
-            void startProvisioning();
+            void requestPropertyData(RequestPropertyDataStatusCb 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.
+             * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
+             *
+             * @see RemoteEnrollee
              */
-            void stopProvisioning();
+            void startSecurityProvisioning(SecurityProvStatusCb callback);
 
             /**
-             * Check if the Enrollee device provisioned.
+             * Start provisioning of target Enrollers information to the Enrollee.
+             *
+             * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
+             *
+             * @see RemoteEnrollee
              */
-            bool isEnrolleeProvisioned();
+            void startDataProvisioning(DataProvStatusCb callback);
 
             /**
-             * Get the Provisioning information provided for the current Enrollee.
+             * Start provisioning of target Enrollers information to the Enrollee.
+             *
+             * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
              *
-             * @return ProvConfig Provisioning information provided for the current Enrollee.
+             * @see RemoteEnrollee
              */
-            ProvConfig getProvConfig ();
+            void startCloudProvisioning(CloudProvStatusCb callback);
 
             /**
-             * Get the Onboarding connection information between Mediator and Enrollee.
+             * Get the Provisioning information provided for the current Enrollee.
              *
-             * @return WiFiOnboadingConnection information between Mediator and Enrollee.
+             * @return DataProvInfo Provisioning information provided for the current Enrollee.
              */
+            DataProvInfo getDataProvInfo();
+
+            void setDataProvInfo(const DataProvInfo& );
+            void setCloudProvInfo(const CloudProvInfo& );
+
+        private:
+            RemoteEnrollee();
 
-            WiFiOnboadingConnection getOnboardConn();
+            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 securityStatusHandler(std::shared_ptr< SecProvisioningStatus > status);
 
         private:
-            std::shared_ptr< RemoteEnrolleeResource > m_remoteResource;
-            EasySetupStatusCB m_easySetupStatusCb;
-            EnrolleeSecStatusCb m_enrolleeSecStatusCb;
+            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;
+
+            SecurityProvStatusCb m_securityProvStatusCb;
+            RequestPropertyDataStatusCb m_requestPropertyDataStatusCb;
             SecurityPinCb m_securityPinCb;
             SecProvisioningDbPathCb m_secProvisioningDbPathCb;
-            ProvConfig m_ProvConfig;
-            WiFiOnboadingConnection m_wifiOnboardingconn;
+            DataProvStatusCb m_dataProvStatusCb;
+            CloudProvStatusCb m_cloudProvStatusCb;
 
-            std::shared_ptr< EnrolleeSecurity > m_enrolleeSecurity;
-            CurrentESState m_currentESState;
-            bool m_isSecured;
+            DataProvInfo m_dataProvInfo;
+            CloudProvInfo m_cloudProvInfo;
+            PropertyData m_propertyData;
 
-            void provisioningStatusHandler (std::shared_ptr< ProvisioningStatus > provStatus);
-            void easySetupSecurityStatusCallback(
-            std::shared_ptr< SecProvisioningResult > secProvisioningResult);
+            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 3a6929e..31d4615 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 ()
         {
-            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::shared_ptr< RemoteEnrollee > (new RemoteEnrollee());
         }
-
-        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;
-        }
-
-
     }
 }
 
diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp
new file mode 100755 (executable)
index 0000000..a79e93f
--- /dev/null
@@ -0,0 +1,349 @@
+//******************************************************************
+//
+// 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 "EnrolleeResource.h"
+
+#include "OCPlatform.h"
+#include "ESException.h"
+#include "OCResource.h"
+#include "logger.h"
+
+namespace OIC
+{
+    namespace Service
+    {
+        #define ES_REMOTE_ENROLLEE_RES_TAG "ES_ENROLLEE_RESOURCE"
+
+        EnrolleeResource::EnrolleeResource(std::shared_ptr< OC::OCResource > resource)
+        {
+            m_ocResource = resource;
+        }
+
+        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",
+                    rep.getUri().c_str(),
+                    eCode);
+
+            if (eCode != 0)
+            {
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "checkProvInformationCb : Provisioning is failed ");
+                std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
+                        DataProvisioningStatus >(ESResult::ES_ERROR, ESDataProvState::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);
+
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                    "checkProvInformationCb : Provisioning is success. "
+                    "Now trigger network connection ");
+
+            std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
+                    DataProvisioningStatus >(ESResult::ES_OK, ESDataProvState::ES_PROVISIONING_SUCCESS);
+            m_dataProvStatusCb(provStatus);
+        }
+
+        void EnrolleeResource::onRequestPropertyDataResponse(const HeaderOptions& /*headerOptions*/,
+                const OCRepresentation& rep, const int eCode)
+        {
+            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,"onRequestPropertyDataResponse : onRequestPropertyDataResponse 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;
+                }
+
+                PropertyData propertyData;
+                std::shared_ptr< RequestPropertyDataStatus > requestPropertyDataStatus = std::make_shared<
+                        RequestPropertyDataStatus >(result, propertyData );
+                m_RequestPropertyDataStatusCb(requestPropertyDataStatus);
+            }
+
+            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*/,
+                const OCRepresentation& rep, const int eCode)
+        {
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : %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,"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< DataProvisioningStatus > provStatus = std::make_shared<
+                        DataProvisioningStatus >(result, ESDataProvState::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, "getProvStatusResponse : ps - %d",
+                    ps);
+
+            //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, 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_dataProvInfo.WIFI.ssid).c_str());
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : pwd - %s",
+                        (m_dataProvInfo.WIFI.pwd).c_str());
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : authtype - %d",
+                        m_dataProvInfo.WIFI.authtype);
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : enctype - %d",
+                        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) >(
+                        std::bind(&EnrolleeResource::checkProvInformationCb, this,
+                        std::placeholders::_1, std::placeholders::_2,
+                        std::placeholders::_3)));
+            }
+            else if (ps == ES_PS_PROVISIONING_COMPLETED) //Indicates that provisioning is completed
+            {
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "getProvStatusResponse : Provisioning is successful");
+                std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
+                        DataProvisioningStatus >(ESResult::ES_OK, ESDataProvState::ES_PROVISIONED_ALREADY);
+                m_dataProvStatusCb(provStatus);
+            }
+        }
+
+        void EnrolleeResource::registerRequestPropertyDataStatusCallback(RequestPropertyDataStatusCb callback)
+        {
+            m_RequestPropertyDataStatusCb = callback;
+        }
+
+        void EnrolleeResource::registerProvStatusCallback(DataProvStatusCb callback)
+        {
+            m_dataProvStatusCb = callback;
+        }
+
+        void EnrolleeResource::RequestPropertyData()
+        {
+            if (m_ocResource == nullptr)
+            {
+                throw ESBadRequestException("Resource is not initialized");
+            }
+
+            OC::QueryParamsMap query;
+            OC::OCRepresentation rep;
+
+            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::onRequestPropertyDataResponse, this,
+                                        std::placeholders::_1, std::placeholders::_2,
+                                        std::placeholders::_3)));
+            };
+
+            OCStackResult result = requestPropertyDataStatus();
+
+            if (result != OCStackResult::OC_STACK_OK)
+            {
+                PropertyData propertyData;
+                std::shared_ptr< RequestPropertyDataStatus > requestPropertyDataStatus = std::make_shared<
+                        RequestPropertyDataStatus >(ESResult::ES_ERROR, propertyData);
+                m_RequestPropertyDataStatusCb(requestPropertyDataStatus);
+                return;
+            }
+        }
+
+        void EnrolleeResource::provisionEnrollee(const DataProvInfo& dataProvInfo)
+
+        {
+            if (m_ocResource == nullptr)
+            {
+                throw ESBadRequestException("Resource is not initialized");
+            }
+
+            m_dataProvInfo = dataProvInfo;
+
+            OC::QueryParamsMap query;
+            OC::OCRepresentation rep;
+
+            std::function< OCStackResult(void) > getProvisioingStatus = [&]
+            {   return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
+                        m_ocResource->getResourceInterfaces().at(0), query,
+                        std::function<
+                        void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+                                const int eCode) >(
+                                std::bind(&EnrolleeResource::getProvStatusResponse, this,
+                                        std::placeholders::_1, std::placeholders::_2,
+                                        std::placeholders::_3)));
+            };
+
+            OCStackResult result = getProvisioingStatus();
+
+            if (result != OCStackResult::OC_STACK_OK)
+            {
+                std::shared_ptr< DataProvisioningStatus > provStatus = std::make_shared<
+                        DataProvisioningStatus >(ESResult::ES_ERROR, ESDataProvState::ES_PROVISIONING_ERROR);
+                m_dataProvStatusCb(provStatus);
+                return;
+            }
+        }
+
+        void EnrolleeResource::unprovisionEnrollee()
+        {
+            if (m_ocResource == nullptr)
+            {
+                throw ESBadRequestException("Resource is not initialized");
+            }
+
+            OCRepresentation provisioningRepresentation;
+
+            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(&EnrolleeResource::checkProvInformationCb, this,
+                    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 0f35ce6..7c5972f 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,18 +47,18 @@ 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,
+        ESResult EnrolleeSecurity::registerCallbackHandler(SecurityProvStatusCb securityProvStatusCb,
                 SecurityPinCb securityPinCb, SecProvisioningDbPathCb secProvisioningDbPathCb)
 
         {
-            m_enrolleeSecStatusCb = enrolleeSecStatusCb;
+            m_securityProvStatusCb = securityProvStatusCb;
             m_securityPinCb = securityPinCb;
             m_secProvisioningDbPathCb = secProvisioningDbPathCb;
 
@@ -108,13 +108,13 @@ 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);
+                m_securityProvStatusCb(securityProvisioningStatus);
                 return;
             }
             else
@@ -127,11 +127,11 @@ 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);
+                    m_securityProvStatusCb(securityProvisioningStatus);
                     return;
                 }
 
@@ -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_NOT_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 cb6cb7a..ea286c4 100755 (executable)
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
 #include "RemoteEnrollee.h"
-#include "RemoteEnrolleeResource.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 ProvConfig& provConfig, const WiFiOnboadingConnection& connection) :
-                m_ProvConfig(provConfig), m_wifiOnboardingconn(connection)
-        {
-            m_currentESState = CurrentESState::ES_UNKNOWN;
-            m_isSecured = connection.isSecured; //enrolleeNWProvInfo.needSecuredEasysetup;
+        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_securityProvStatusCb = nullptr;
+            m_requestPropertyDataStatusCb = nullptr;
+            m_securityPinCb = nullptr;
+            m_secProvisioningDbPathCb = nullptr;
+            m_dataProvStatusCb = nullptr;
+            m_cloudProvStatusCb = nullptr;
+
+            //m_deviceId = nullptr;
         }
 
 #ifdef __WITH_DTLS__
@@ -56,249 +64,436 @@ namespace OIC
         }
 #endif //__WITH_DTLS__
 
-        void RemoteEnrollee::registerEasySetupStatusHandler(EasySetupStatusCB callback)
+        void RemoteEnrollee::securityStatusHandler(
+                        std::shared_ptr< SecProvisioningStatus > status)
         {
-            OIC_LOG ( DEBUG, ES_REMOTE_ENROLLEE_TAG, "Entered registerStatusHandler");
-            if(!callback)
-            {
-                throw ESInvalidParameterException("Callback is empty");
-            }
+            OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "easySetupStatusCallback status is, UUID = %s, "
+                    "Status = %d", status->getDeviceUUID().c_str(),
+                    status->getESResult());
 
-            if (m_easySetupStatusCb)
+            if(status->getESResult() == ES_OK)
             {
-                throw ESBadRequestException("Callback handler already registered");
+                OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Ownership and ACL are successful. "
+                        "Continue with Network information provisioning");
+
+                OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Before ProvisionEnrollee");
+
+                m_securityProvStatusCb(status);
             }
             else
             {
-                m_easySetupStatusCb = callback;
+                OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Ownership and ACL are fail");
 
-                m_remoteResource = std::make_shared< RemoteEnrolleeResource >(m_ProvConfig, m_wifiOnboardingconn);
+                m_securityProvStatusCb(status);
             }
         }
 
-        void RemoteEnrollee::easySetupSecurityStatusCallback(
-                        std::shared_ptr< SecProvisioningResult > secProvisioningResult)
+        void RemoteEnrollee::RequestPropertyDataStatusHandler (
+                std::shared_ptr< RequestPropertyDataStatus > status)
         {
-            OIC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG, "easySetupStatusCallback status is, UUID = %s, "
-                    "Status = %d", secProvisioningResult->getDeviceUUID().c_str(),
-                    secProvisioningResult->getResult());
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering RequestPropertyDataStatusHandler");
 
-            if(secProvisioningResult->getResult() == ES_OK)
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"RequestPropertyDataStatus = %d", status->getESResult());
+
+            if(status->getESResult() == ES_OK)
             {
-                OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Ownership and ACL are successful. "
-                        "Continue with Network information provisioning");
+                m_propertyData = status->getPropertyData();
+            }
 
-                m_currentESState = CurrentESState::ES_OWNED;
+            m_requestPropertyDataStatusCb(status);
+        }
 
-                OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Before ProvisionEnrollee");
+        void RemoteEnrollee::dataProvisioningStatusHandler(
+                std::shared_ptr< DataProvisioningStatus > status)
+        {
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering dataProvisioningStatusHandler");
 
-                RemoteEnrolleeResource::ProvStatusCb provStatusCb = std::bind(
-                        &RemoteEnrollee::provisioningStatusHandler, this, std::placeholders::_1);
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", status->getESResult());
 
-                m_remoteResource->registerProvStatusCallback(provStatusCb);
-                m_remoteResource->provisionEnrollee();
+            if (status->getESResult() == ES_OK)
+            {
+                if (status->getESDataProvState() >= ESDataProvState::ES_PROVISIONED_ALREADY)
+                {
+                    OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", status->getESResult());
+                }
             }
-            else
+            m_dataProvStatusCb(status);
+
+            return;
+        }
+
+        void RemoteEnrollee::cloudProvisioningStatusHandler (
+                std::shared_ptr< CloudProvisioningStatus > status)
+        {
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering cloudProvisioningStatusHandler");
+
+            OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"CloudProvStatus = %d", status->getESCloudState());
+
+            m_cloudProvStatusCb(status);
+            return;
+        }
+
+        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)
+            {
+                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)
+                {
+                    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 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
             {
-                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(resource)
                 {
-                    if (easySetupStatus)
+                    // 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())
                     {
-                        m_easySetupStatusCb(easySetupStatus);
+                        /*
+                         * 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
+
+                    else if(!m_deviceId.empty() && m_deviceId == hostDeviceID)
                     {
-                        m_easySetupStatusCb(nullptr);
+                        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::provisioningStatusHandler(
-                std::shared_ptr< ProvisioningStatus > provStatus)
+        ESResult RemoteEnrollee::discoverResource()
         {
-            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering ProvisioningStatusHandler");
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Enter discoverResource");
+
+            if (m_ocResource != nullptr)
+            {
+                throw ESBadRequestException("resource is already created");
+            }
+
+            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,"ProvStatus = %d", provStatus->getESResult());
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "query = %s", query.c_str());
 
-            std::shared_ptr< EasySetupStatus > easySetupStatus = nullptr;
+            m_discoveryResponse = false;
 
-            if (m_isSecured)
+            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)
             {
-                if (m_currentESState >= CurrentESState::ES_OWNED)
-                {
-                    goto CALLBACK_CHECK;
-                }
-                else
-                {
-                    goto FAILURE;
-                }
+                OIC_LOG(ERROR,ES_REMOTE_ENROLLEE_TAG,
+                        "Failed discoverResource");
+                return ES_ERROR;
             }
-            else
+
+            ESResult foundResponse = ESDiscoveryTimeout (DISCOVERY_TIMEOUT);
+
+            if (foundResponse == ES_ERROR || !m_discoveryResponse)
             {
-                goto CALLBACK_CHECK;
+                OIC_LOG(ERROR,ES_REMOTE_ENROLLEE_TAG,
+                        "Failed discoverResource because timeout");
+                return ES_ERROR;
             }
+            return ES_OK;
+        }
 
-            CALLBACK_CHECK:
+        void RemoteEnrollee::initRemoteEnrollee()
+        {
+            ESResult result = ES_ERROR;
 
-            if (provStatus->getESResult() == ES_OK)
+            if (m_enrolleeResource != nullptr)
             {
-                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);
-                }
+                throw ESBadRequestException ("Already created");
             }
-            else
+
+            result = discoverResource();
+
+            if (result == ES_ERROR)
             {
-                easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,
-                        m_ProvConfig);
+                OIC_LOG(ERROR,ES_REMOTE_ENROLLEE_TAG,
+                                    "Failed to create resource object using discoverResource");
+                throw ESBadRequestException ("Resource object not created");
             }
 
-            if (m_easySetupStatusCb)
+            else
             {
-                if (easySetupStatus)
+                if(m_ocResource != nullptr)
                 {
-                    m_easySetupStatusCb(easySetupStatus);
+                    m_enrolleeResource = std::make_shared<EnrolleeResource>(std::move(m_ocResource));
                 }
                 else
                 {
-                    m_easySetupStatusCb(nullptr);
+                    throw ESBadGetException ("Resource handle is invalid");
                 }
             }
+        }
 
-            return;
+        void RemoteEnrollee::startSecurityProvisioning(SecurityProvStatusCb callback)
+        {
+#ifdef __WITH_DTLS__
+
+            m_securityProvStatusCb = callback;
 
-            FAILURE:
+            SecurityProvStatusCb securityProvStatusCb = std::bind(
+                    &RemoteEnrollee::securityStatusHandler,
+                    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, "");
 
-            easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,
-                                    m_ProvConfig);
+            m_enrolleeSecurity->registerCallbackHandler(securityProvStatusCb,
+                    m_securityPinCb, m_secProvisioningDbPathCb);
 
-            if (easySetupStatus)
+            try
             {
-                m_easySetupStatusCb(easySetupStatus);
+                if (!m_enrolleeSecurity->performOwnershipTransfer())
+                {
+                    OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Fail performOwnershipTransfer");
+                    std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
+                            std::make_shared< SecProvisioningStatus >(nullptr, ES_ERROR);
+                    m_securityProvStatusCb(securityProvisioningStatus);
+                    return;
+                }
             }
-            else
+            catch (OCException & e)
             {
-                m_easySetupStatusCb(nullptr);
+                OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,
+                        "Exception for performOwnershipTransfer : %s", e.reason().c_str());
+                return ;
             }
-            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_securityProvStatusCb(securityProvisioningStatus);
+#endif
         }
 
-        void RemoteEnrollee::startProvisioning()
+        void RemoteEnrollee::requestPropertyData(RequestPropertyDataStatusCb callback)
         {
-            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering startProvisioning");
-            if (m_remoteResource == nullptr)
+            if(!callback)
+            {
+                throw ESInvalidParameterException("Callback is empty");
+            }
+
+            m_requestPropertyDataStatusCb = callback;
+
+            if (m_enrolleeResource == nullptr)
             {
                 throw ESBadRequestException ("Device not created");
             }
 
-            ESResult result = ES_ERROR;
+            RequestPropertyDataStatusCb RequestPropertyDataStatusCb = std::bind(
+                    &RemoteEnrollee::RequestPropertyDataStatusHandler, this, std::placeholders::_1);
+            m_enrolleeResource->registerRequestPropertyDataStatusCallback(RequestPropertyDataStatusCb);
+            m_enrolleeResource->RequestPropertyData();
+        }
 
-            result = m_remoteResource->constructResourceObject();
+        void RemoteEnrollee::startDataProvisioning(DataProvStatusCb callback)
+        {
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Enter startDataProvisioning");
 
-            if (result == ES_ERROR)
+            if(!callback)
+            {
+                throw ESInvalidParameterException("Callback is empty");
+            }
+
+            m_dataProvStatusCb = callback;
+
+            if (m_enrolleeResource == nullptr)
             {
-                OIC_LOG(ERROR,ES_REMOTE_ENROLLEE_TAG,
-                                    "Failed to create device using constructResourceObject");
                 throw ESBadRequestException ("Device not created");
             }
 
-            m_currentESState = CurrentESState::ES_ONBOARDED;
+            if(m_dataProvInfo.WIFI.ssid.empty())
+            {
+                throw ESBadRequestException ("Invalid Provisiong Data.");
+            }
 
-#ifdef __WITH_DTLS__
-            if (m_isSecured && m_currentESState < CurrentESState::ES_OWNED)
+            m_dataProvStatusCb = callback;
+
+            DataProvStatusCb dataProvStatusCb = std::bind(
+                    &RemoteEnrollee::dataProvisioningStatusHandler, this, std::placeholders::_1);
+
+            m_enrolleeResource->registerProvStatusCallback(dataProvStatusCb);
+            m_enrolleeResource->provisionEnrollee(m_dataProvInfo);
+        }
+
+        void RemoteEnrollee::initCloudResource()
+        {
+            ESResult result = ES_ERROR;
+
+            if (m_cloudResource != nullptr)
             {
-                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, "");
+                throw ESBadRequestException ("Already created");
+            }
+
+            result = discoverResource();
 
-                m_enrolleeSecurity->registerCallbackHandler(securityProvStatusCb,
-                        m_securityPinCb, m_secProvisioningDbPathCb);
+            if (result == ES_ERROR)
+            {
+                OIC_LOG(ERROR,ES_REMOTE_ENROLLEE_TAG,
+                                    "Failed to create resource object using discoverResource");
+                throw ESBadRequestException ("Resource object not created");
+            }
 
-                try
+            else
+            {
+                if(m_ocResource != nullptr)
                 {
-                    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");
+                    m_cloudResource = std::make_shared<CloudResource>(std::move(m_ocResource));
 
-                        RemoteEnrolleeResource::ProvStatusCb provStatusCb = std::bind(
-                                &RemoteEnrollee::provisioningStatusHandler,
-                                this, std::placeholders::_1);
+                    std::shared_ptr< CloudProvisioningStatus > provStatus = std::make_shared<
+                        CloudProvisioningStatus >(ESResult::ES_ERROR, ESCloudProvState::ES_CLOUD_ENROLLEE_FOUND);
 
-                        m_remoteResource->registerProvStatusCallback(provStatusCb);
-                        m_remoteResource->provisionEnrollee();
-                    }
+                    m_cloudProvStatusCb(provStatus);
                 }
-                catch (OCException & e)
+                else
                 {
-                    OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,
-                            "Exception for performOwnershipTransfer : %s", e.reason().c_str());
-                    return ;
+                    throw ESBadGetException ("Resource handle is invalid");
                 }
             }
-#else
-            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();
-#endif
         }
 
-        void RemoteEnrollee::stopProvisioning()
+
+        void RemoteEnrollee::startCloudProvisioning(CloudProvStatusCb callback)
         {
-            m_currentESState = CurrentESState::ES_UNKNOWN;
+            OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Enter startCloudProvisioning");
 
-            m_remoteResource->unprovisionEnrollee();
-        }
+            ESResult result = ES_ERROR;
 
-        bool RemoteEnrollee::isEnrolleeProvisioned()
-        {
-            if(m_currentESState >= CurrentESState::ES_PROVISIONED)
+            if(!callback)
             {
-                return true;
+                throw ESInvalidParameterException("Callback is empty");
             }
-            else
+
+            m_cloudProvStatusCb = callback;
+
+            try
             {
-                return false;
+                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_CLOUD_ENROLLEE_NOT_FOUND);
+                m_cloudProvStatusCb(provStatus);
+            }
+
+            if (m_cloudResource == nullptr)
+            {
+                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;
+        }
     }
 }
diff --git a/service/easy-setup/mediator/richsdk/src/RemoteEnrolleeResource.cpp b/service/easy-setup/mediator/richsdk/src/RemoteEnrolleeResource.cpp
deleted file mode 100755 (executable)
index 368c5e0..0000000
+++ /dev/null
@@ -1,485 +0,0 @@
-//******************************************************************
-//
-// 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 <time.h>
-
-#include "RemoteEnrolleeResource.h"
-
-#include "OCPlatform.h"
-#include "ESException.h"
-#include "OCResource.h"
-#include "logger.h"
-
-namespace OIC
-{
-    namespace Service
-    {
-        #define ES_REMOTE_ENROLLEE_RES_TAG "ES_REMOTE_ENROLLEE_RES"
-        #define DISCOVERY_TIMEOUT 5
-
-        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";
-
-        RemoteEnrolleeResource::RemoteEnrolleeResource(const ProvConfig &provConfig,
-                                                  const WiFiOnboadingConnection &onboardingconn)
-        {
-            m_ProvConfig = provConfig;
-            m_wifiOnboardingconn = onboardingconn;
-            m_discoveryResponse = false;
-        }
-
-        void RemoteEnrolleeResource::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_provStatusCb(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_provStatusCb(provStatus);
-                return;
-            }
-        }
-
-        void RemoteEnrolleeResource::triggerNetworkConnection()
-        {
-            if (m_ocResource == nullptr)
-            {
-                throw ESBadRequestException("Resource is not initialized");
-            }
-
-            OCRepresentation provisioningRepresentation;
-
-            provisioningRepresentation.setValue(OC_RSRVD_ES_TR, 1);
-
-            m_ocResource->post(provisioningRepresentation, QueryParamsMap(),
-                    std::function<
-                            void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
-                                    const int eCode) >(
-                            std::bind(&RemoteEnrolleeResource::triggerNetworkConnectionCb, this,
-                                    std::placeholders::_1, std::placeholders::_2,
-                                    std::placeholders::_3)));
-        }
-
-        void RemoteEnrolleeResource::checkProvInformationCb(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,
-                        "checkProvInformationCb : Provisioning is failed ");
-                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
-                m_provStatusCb(provStatus);
-                return;
-            }
-
-            int ps = -1;
-
-            rep.getValue(OC_RSRVD_ES_PS, ps);
-
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : ps - %d", ps);
-
-            //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_provStatusCb(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_provStatusCb(provStatus);
-                return;
-            }
-        }
-
-        void RemoteEnrolleeResource::getProvStatusResponse(const HeaderOptions& /*headerOptions*/,
-                const OCRepresentation& rep, const int eCode)
-        {
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : %s, eCode = %d",
-                    rep.getUri().c_str(),
-                    eCode);
-
-            if (eCode != 0)
-            {
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "getProvStatusResponse : Provisioning is failed ");
-                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
-                m_provStatusCb(provStatus);
-                return;
-            }
-
-            int ps = -1;
-
-            rep.getValue(OC_RSRVD_ES_PS, ps);
-
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ps - %d",
-                    ps);
-
-            if (ps == ES_PS_NEED_PROVISIONING) //Indicates the need for provisioning
-            {
-                OCRepresentation provisioningRepresentation;
-
-                provisioningRepresentation.setValue(OC_RSRVD_ES_TNN,
-                std::string(m_ProvConfig.provData.WIFI.ssid));
-                provisioningRepresentation.setValue(OC_RSRVD_ES_CD,
-                std::string(m_ProvConfig.provData.WIFI.pwd));
-
-                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);
-
-                m_ocResource->post(provisioningRepresentation, QueryParamsMap(),
-                        std::function<
-                                void(const HeaderOptions& headerOptions,
-                                        const OCRepresentation& rep, const int eCode) >(
-                        std::bind(&RemoteEnrolleeResource::checkProvInformationCb, this,
-                        std::placeholders::_1, std::placeholders::_2,
-                        std::placeholders::_3)));
-            }
-            else if (ps == ES_PS_PROVISIONING_COMPLETED) //Indicates that provisioning is completed
-            {
-                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);
-                m_provStatusCb(provStatus);
-            }
-        }
-
-        void RemoteEnrolleeResource::registerProvStatusCallback(ProvStatusCb provStatusCb)
-        {
-            m_provStatusCb = provStatusCb;
-        }
-
-        ESResult RemoteEnrolleeResource::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)
-                {
-                    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 RemoteEnrolleeResource::onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource)
-        {
-            OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "onDeviceDiscovered");
-
-            std::string resourceURI;
-            std::string hostAddress;
-            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());
-
-                    /*
-                     * 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;
-                }
-                else
-                {
-                    OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "Resource is invalid");
-                }
-
-            }
-            catch(std::exception& e)
-            {
-                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "Exception in foundResource: %s", e.what());
-            }
-        }
-
-
-        ESResult RemoteEnrolleeResource::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://");
-            }
-
-            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, "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::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 RemoteEnrolleeResource::provisionEnrollee()
-
-        {
-            if (m_ocResource == nullptr)
-            {
-                throw ESBadRequestException("Resource is not initialized");
-            }
-
-            OC::QueryParamsMap query;
-            OC::OCRepresentation rep;
-
-            std::function< OCStackResult(void) > getProvisioingStatus = [&]
-            {   return m_ocResource->get(m_ocResource->getResourceTypes().at(0),
-                        m_ocResource->getResourceInterfaces().at(0), query,
-                        std::function<
-                        void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
-                                const int eCode) >(
-                                std::bind(&RemoteEnrolleeResource::getProvStatusResponse, this,
-                                        std::placeholders::_1, std::placeholders::_2,
-                                        std::placeholders::_3)));
-            };
-
-            OCStackResult result = getProvisioingStatus();
-
-            if (result != OCStackResult::OC_STACK_OK)
-            {
-                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
-                m_provStatusCb(provStatus);
-                return;
-            }
-        }
-
-        void RemoteEnrolleeResource::unprovisionEnrollee()
-        {
-            if (m_ocResource == nullptr)
-            {
-                throw ESBadRequestException("Resource is not initialized");
-            }
-
-            OCRepresentation provisioningRepresentation;
-
-            provisioningRepresentation.setValue(OC_RSRVD_ES_TNN, "");
-            provisioningRepresentation.setValue(OC_RSRVD_ES_CD, "");
-
-            m_ocResource->post(provisioningRepresentation, QueryParamsMap(),
-                    std::function<
-                            void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
-                                    const int eCode) >(
-                    std::bind(&RemoteEnrolleeResource::checkProvInformationCb, this,
-                    std::placeholders::_1, std::placeholders::_2,
-                    std::placeholders::_3)));
-        }
-    }
-}
index e645bc4..de21486 100644 (file)
 #include <string.h>
 #include <stdio.h>
 #include <pthread.h>
+#include <oic_string.h>
 
-#define TAG "TS"
+#define TAG "ENROLLEE_SAMPLE"
 
 void *listeningFunc(void *);
 
-/**
- * @var ssid
- * @brief Target SSID of the Soft Access point to which the device has to connect
- */
-static char ssid[] = "EasySetup123";
-
-/**
- * @var passwd
- * @brief Password of the Soft Access point to which the device has to connect
- */
-static char passwd[] = "EasySetup123";
 
 /**
  * Secure Virtual Resource database for Iotivity Server
@@ -62,44 +52,133 @@ void PrintMenu()
 {
     printf("============\n");
     printf("S: Enabled Security\n");
-    printf("I: Init easy setup\n");
-    printf("P: start provisioning resources\n");
-    printf("T: terminate\n");
-    printf("Q: quit\n");
+    printf("I: Init & Start EasySetup\n");
+    printf("D: Set DeviceInfo\n");
+    printf("T: Terminate\n");
+    printf("Q: Quit\n");
     printf("============\n");
 }
 
-void EventCallbackInApp(ESResult esResult, ESEnrolleeState enrolleeState)
+void WiFiProvCbInApp(ESWiFiProvData *eventData)
 {
-    printf("Easy setup event callback\n");
+    printf("WiFiProvCbInApp IN\n");
 
-    if(esResult == ES_OK)
+    if(eventData->ssid != NULL)
     {
-        if(enrolleeState == ES_ON_BOARDED_STATE)
-        {
-            printf("Device is successfully OnBoared on Adhoc network\n");
-        }
-        else if (enrolleeState == ES_PROVISIONED_STATE)
-        {
-            printf("Device is provisioned with target network's credentials\n");
-        }
-        else if (enrolleeState == ES_ON_BOARDED_TARGET_NETWORK_STATE)
-        {
-            printf("Device is onboarded/connected with target network\n");
-        }
-        else
-        {
-            printf("Wrong state !! Easy setup is failed at Enrollee state = %d\n",enrolleeState);
-        }
+        printf("SSID : %s\n", eventData->ssid);
     }
     else
     {
-        printf("Easy stup is failed at Enrollee state = %d\n",enrolleeState);;
+        printf("ERROR! SSID IS NULL\n");
+        return;
     }
 
-    PrintMenu();
+    if(eventData->pwd != NULL)
+    {
+        printf("Password : %s\n", eventData->pwd);
+    }
+    else
+    {
+        printf("ERROR! Password IS NULL\n");
+        return;
+    }
+
+    if(eventData->authtype == NONE_AUTH || eventData->authtype == WEP || \
+        eventData->authtype == WPA_PSK || eventData->authtype == WPA2_PSK)
+    {
+        printf("AuthType : %d\n", eventData->authtype);
+    }
+    else
+    {
+        printf("ERROR! AuthType IS NULL\n");
+        return;
+    }
+
+    if(eventData->enctype == NONE_ENC || eventData->enctype == WEP_64 || \
+        eventData->enctype == WEP_128 || eventData->enctype == TKIP || \
+        eventData->enctype == AES || eventData->enctype == TKIP_AES)
+    {
+        printf("EncType : %d\n", eventData->enctype);
+    }
+    else
+    {
+        printf("ERROR! EncType IS NULL\n");
+        return;
+    }
+
+    printf("WiFiProvCbInApp OUT\n");
 }
 
+void DevConfProvCbInApp(ESDevConfProvData *eventData)
+{
+    printf("DevConfProvCbInApp IN\n");
+
+    if(eventData->language != NULL)
+    {
+        printf("Language : %s\n", eventData->language);
+    }
+    else
+    {
+        printf("ERROR! Language IS NULL\n");
+        return;
+    }
+
+    if(eventData->country != NULL)
+    {
+        printf("Country : %s\n", eventData->country);
+    }
+    else
+    {
+        printf("ERROR! Country IS NULL\n");
+        return;
+    }
+
+    printf("DevConfProvCbInApp OUT\n");
+}
+
+void CloudDataProvCbInApp(ESCloudProvData *eventData)
+{
+    printf("CloudDataProvCbInApp IN\n");
+
+    if(eventData->authCode != NULL)
+    {
+        printf("AuthCode : %s\n", eventData->authCode);
+    }
+    else
+    {
+        printf("ERROR! AuthCode IS NULL\n");
+        return;
+    }
+
+    if(eventData->authProvider != NULL)
+    {
+        printf("AuthProvider : %s\n", eventData->authProvider);
+    }
+    else
+    {
+        printf("ERROR! AuthProvider IS NULL\n");
+        return;
+    }
+
+    if(eventData->ciServer != NULL)
+    {
+        printf("CI Server : %s\n", eventData->ciServer);
+    }
+    else
+    {
+        printf("ERROR! CI Server IS NULL\n");
+        return;
+    }
+
+    printf("CloudDataProvCbInApp OUT\n");
+}
+
+ESProvisioningCallbacks gCallbacks = {
+    .WiFiProvCb = &WiFiProvCbInApp,
+    .DevConfProvCb = &DevConfProvCbInApp,
+    .CloudDataProvCb = &CloudDataProvCbInApp
+};
+
 FILE* server_fopen(const char *path, const char *mode)
 {
     (void) path;
@@ -119,31 +198,21 @@ void EnableSecurity()
 
 void StartEasySetup()
 {
-    printf("StartEasySetup and onboarding started..\n");
-
-    if(ESInitEnrollee(CT_ADAPTER_IP, ssid, passwd, gIsSecured, EventCallbackInApp) == ES_ERROR)
-    {
-        printf("StartEasySetup and onboarding Fail!!\n");
-        return;
-    }
-}
+    printf("StartEasySetup IN\n");
 
-void ESInitResources()
-{
-    printf("Starting Enrollee Provisioning\n");
-
-    // Initialize the OC Stack in Server mode
     if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
     {
         printf("OCStack init error!!\n");
         return;
     }
 
-    if (ESInitProvisioning() == ES_ERROR)
+    ESResourceMask resourcemMask = ES_WIFI_RESOURCE | ES_CLOUD_RESOURCE | ES_DEVCONF_RESOURCE;
+    if(ESInitEnrollee(gIsSecured, resourcemMask, gCallbacks) != ES_OK)
     {
-        printf("Init Provisioning Failed!!\n");
+        printf("OCStack init error!!\n");
         return;
     }
+    printf("ESInitEnrollee Success\n");
 
     pthread_t thread_handle;
     if (pthread_create(&thread_handle, NULL, listeningFunc, NULL))
@@ -151,7 +220,21 @@ void ESInitResources()
         printf("Thread creation failed\n");
     }
 
-    printf("ESInitProvisioning Success\n");
+    printf("StartEasySetup OUT\n");
+}
+
+void SetDeviceInfo()
+{
+    printf("SetDeviceInfo IN\n");
+
+    ESDeviceProperty deviceProperty = {
+        {{WiFi_11G, WiFi_11N, WiFi_11AC, WiFi_EOF}, WiFi_5G}, {"Test Device"}
+    } ;
+
+    if(ESSetDeviceProperty(&deviceProperty) == ES_ERROR)
+        printf("ESSetDeviceProperty Error\n");
+
+    printf("SetDeviceInfo OUT\n");
 }
 
 void StopEasySetup()
@@ -180,14 +263,18 @@ int main()
     printf("EasySetup Enrollee SAMPLE\n");
     printf("#########################\n");
     PrintMenu();
-    char option = 'T';
+    char option;
 
     while(true)
     {
-        scanf("%c",&option);
+        if(scanf("%c", &option) != 1)
+        {
+            printf("Failed to read input data\n");
+            continue;
+        }
 
-       if(option!= '\n')
-      {
+        if(option!= '\n')
+        {
             switch (option)
             {
                 case 'H': // help
@@ -203,25 +290,29 @@ int main()
                 case 'S': // Enable Security
                 case 's':
                     EnableSecurity();
+                    PrintMenu();
                     break;
 
                 case 'I': // Init EasySetup
                 case 'i':
                     StartEasySetup();
+                    PrintMenu();
                     break;
 
-                case 'P': // start provisioning
-                case 'p':
-                    ESInitResources();
+                case 'D': // Set Device Info
+                case 'd':
+                    SetDeviceInfo();
+                    PrintMenu();
                     break;
-
                 case 'T': // stop easy setup
                 case 't':
                     StopEasySetup();
+                    PrintMenu();
                     break;
 
                 default:
                     printf("wrong option\n");
+                    PrintMenu();
                     break;
             }
             if (option == 'Q' || option == 'q') break;
@@ -230,7 +321,7 @@ int main()
     return 0;
 }
 
-void *listeningFunc(void * a)
+void *listeningFunc(void * data)
 {
     OCStackResult result;
 
index ec960bc..289c07f 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.getDevConf();
+    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 << "ESDataProvState : " << provStatus->getESDataProvState() << 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;