Added Multi PHY EasySetup Service
authorHemant Mahsky <h.mahsky@samsung.com>
Mon, 28 Sep 2015 16:54:14 +0000 (22:24 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 28 Sep 2015 19:53:06 +0000 (19:53 +0000)
Change-Id: Ie8504d25c0f8c002737b8a82820e0af52944ca83
Signed-off-by: Hemant Mahsky <h.mahsky@samsung.com>
Updated SConscript to build EasySetup

Change-Id: Ie8504d25c0f8c002737b8a82820e0af52944ca83
Signed-off-by: Hemant Mahsky <h.mahsky@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3229
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
88 files changed:
service/SConscript
service/easy-setup/Build_Instructions_Android_Arduino.txt [new file with mode: 0755]
service/easy-setup/SConscript [new file with mode: 0644]
service/easy-setup/sampleapp/SConscript [new file with mode: 0644]
service/easy-setup/sampleapp/enrollee/arduino/SConscript [new file with mode: 0644]
service/easy-setup/sampleapp/enrollee/arduino/enrollee_wifi.cpp [new file with mode: 0755]
service/easy-setup/sampleapp/mediator/android/.gitignore [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/EasySetupGradle.iml [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/app.iml [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/build.gradle [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/AndroidManifest.xml [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/background.png [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/cancel.png [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/ic_launcher.png [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/icon.png [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/layout/activity_main.xml [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/menu/main.xml [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/values/dimens.xml [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/values/strings.xml [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/values/styles.xml [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/build.gradle [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/android/EasySetup/settings.gradle [new file with mode: 0755]
service/easy-setup/sampleapp/mediator/linux/SConscript [new file with mode: 0644]
service/easy-setup/sampleapp/mediator/linux/mediator.cpp [new file with mode: 0644]
service/easy-setup/sdk/common/common.h [new file with mode: 0755]
service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp [new file with mode: 0755]
service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.h [new file with mode: 0755]
service/easy-setup/sdk/enrollee/common/inc/easysetup.h [new file with mode: 0755]
service/easy-setup/sdk/enrollee/common/inc/resourceHandler.h [new file with mode: 0755]
service/easy-setup/sdk/enrollee/common/src/easysetup.cpp [new file with mode: 0755]
service/easy-setup/sdk/enrollee/common/src/resourceHandler.cpp [new file with mode: 0755]
service/easy-setup/sdk/mediator/android/.gitignore [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/build.gradle [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/easySetupCore.iml [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/settings.gradle [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/androidTest.iml [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceConfigTest.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceTest.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EnrolleeDeviceFactoryTest.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/Utility.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/AndroidManifest.xml [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupStatus.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeDevice.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeSetupError.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeState.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IpOnBoardingConnection.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingCallback.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConfig.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConnection.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningCallback.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningConfig.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceFactory.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiOnBoardingConfig.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiProvConfig.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupCallbackHandler.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupManager.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeInfo.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeOnBoardingInfo.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IOnBoardingStatus.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IProvisioningListener.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisionEnrollee.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/main.iml [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/res/drawable-hdpi/ic_launcher.png [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/res/values/strings.xml [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/res/values/styles.xml [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/Android.mk [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/Application.mk [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jni_easy_setup.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jni_easy_setup.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_easy_setup_jvm.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_getter.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_object.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_setter.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_string.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_easy_setup_jvm.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_getter.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_object.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_setter.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_string.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/inc/prov_adapter.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/inc/provisioning.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/src/prov_adapter.cpp [new file with mode: 0755]
service/easy-setup/sdk/mediator/src/provisioning.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp [new file with mode: 0755]

index fe78880..098d0db 100644 (file)
@@ -39,3 +39,7 @@ if target_os not in ['arduino','darwin']:
     # Build simulator module
     if target_os in ['linux'] and env.get('SIMULATOR', False):
         SConscript('simulator/SConscript')
+
+# Build EasySetup module
+if target_os in ['arduino','android', 'linux']:
+    SConscript('easy-setup/SConscript')
diff --git a/service/easy-setup/Build_Instructions_Android_Arduino.txt b/service/easy-setup/Build_Instructions_Android_Arduino.txt
new file mode 100755 (executable)
index 0000000..9056422
--- /dev/null
@@ -0,0 +1,132 @@
+=== Prerequisites ===
+
+* 1. Scons
+
+Please refer to the following page to install scons:
+   http://www.scons.org/doc/production/HTML/scons-user.html#chap-build-install
+(Note: on Windows, install Python 2.x before installing scons)
+
+* 2. IDE/SDK Pre-requites
+To build for some OS (Android / Arduino / IOS ...), an IDE/SDK may be required,
+please go to the relative page to download and install the required IDE/SDK.
+
+Note: Connectivity module building has been changed. We have to build connectivity
+      from the iotivity root folder.
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Android Build:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Steps to build and deploy Easysetup Mediator in Android platform
+1) Compilation using Scons
+    0) Prerequisite exports for Android
+        export ANDROID_HOME=<ANDROID_HOME>
+        export ANDROID_NDK=<ANDROID_NDK>
+
+    a) In the IoTivity root source folder execute
+         scons TARGET_OS=android TARGET_ARCH=armeabi TARGET_TRANSPORT=IP RELEASE=0
+
+    b) If the project is setup correctly, you should see a BUILD SUCCESSFUL message on the terminal
+        You should see the .aar files generated inside of '<iotivity>/android/android_api/base/build/outputs/aar' directory. The .aar files contain jni directory and also a .jar file
+
+    c) Now navigate to the Easysetup NDK folder
+        <iotivity-root>/service/easy-setup/sdk/mediator/android
+
+    d) Execute NDK-Build with the following command to cross compiled Easysetup JNI .so files
+       <iotivity>/extlibs/android/ndk/android-ndk-r10d/ndk-build
+
+    e) Step (d) will generate cross compiled Easysetup JNI .so files in the following folder
+       <iotivity>/service/easy-setup/sdk/mediator/android/libs/armeabi
+
+2) Compilation using Android Studio
+
+    0) Prerequisite for running the Android application
+        Install Android Studio and use the Android SDK manager to update the Android API to 21
+
+    a) Import following projects to the Studio using the "File->New->Import Project"
+        - service\easy-setup\sdk\android\EasySetupCore
+        - service\easy-setup\sampleapp\android\EasySetup
+
+    b) EasySetupCore is dependent on the .aar files generated in 1.b
+        1) To add an .aar file to the 'EasySetupCore' project,
+            a.Right click on EasySetup->New->Module->Import .JAR or .AAR Package
+            b.Select the .aar file(iotivity-armeabi-base-*.aar) from the location in steps 1.b
+            c.Right click on EasySetup->Open Module Settings
+            d.Select each sample app module under 'Modules'->Dependencies->Add->Module Dependency
+
+    c)    Build EasySetupCore project using "Android Studio->Build->Make Module "easySetupCore"
+        If the project is setup correctly, you should see a BUILD SUCCESSFUL in the Android Studio Gradle Build terminal
+            You should see the .aar file generated inside of
+            'iotivity\service\easy-setup\sdk\mediator\android\easySetupCore\build\outputs\aar'
+
+    d) EasySetup application is also dependent on the .so files generated in 1.d step
+        1) Drag and drop the following .so files in to the EasySetup\app\src\main\jniLibs\armeabi folder
+            - libeasysetup-jni.so [Easy Setup file]
+
+    e) EasySetup is also dependent on the .aar files generated in 1.b and 2.c steps
+        1) To add an .aar file to the 'EasySetup' project,
+            a.Right click on EasySetup->New->Module->Import .JAR or .AAR Package
+            b.Select the .aar file from the location in steps 1.b and 2.b above
+            c.Right click on EasySetup->Open Module Settings
+            d.Select each sample app module under 'Modules'->Dependencies->Add->Module Dependency
+            e.The .aar files (easySetupCore-*.aar & iotivity-armeabi-base-*.aar) selected in step 2.c.1.b above should be present. Select it.
+
+
+    e) Run "Easy Setup" as an Android application
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Arduino Build:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Steps to build and deploy Easysetup Mediator in Arduino platform
+1) Compilation using Scons for Arduino Due
+    a) Set up Arduino first before building. Refer to "connectivity\build\arduino\Arduino_Setup_README.txt" file for help.
+    b) Go to "iotivity/" folder.
+    c) Prerequisite exports for Arduino
+         export ARDUINO_HOME=<ARDUINO_HOME_DIR>
+    d) Start Arduino IDE. Select ""Tools->Port->Programming port"
+    e) scons TARGET_OS=arduino BOARD=arduino_due_x_dbg TARGET_ARCH=arm SHIELD=WIFI
+        - With debug or logging
+            scons TARGET_OS=arduino BOARD=arduino_due_x_dbg TARGET_ARCH=arm SHIELD=WIFI RELEASE=0
+        - With installation to Arduino
+            scons TARGET_OS=arduino BOARD=arduino_due_x_dbg TARGET_ARCH=arm SHIELD=WIFI RELEASE=0 UPLOAD=true
+        NOTE: BOARD=arduino_due_x_dbg|arduino_due_x. Default is arduino_due_x_dbg.
+
+       Possible values for <transport> are:
+        -> IP :
+        $ scons TARGET_OS=arduino BOARD=arduino_due_x_dbg TARGET_ARCH=arm SHIELD=WIFI RELEASE=0
+        -> BLE :
+        $ scons TARGET_OS=arduino BOARD=arduino_due_x_dbg TARGET_ARCH=arm SHIELD=WIFI RELEASE=0
+
+        Note :- Only single transport can be built at a time for Arduino
+    f) The above command will build sample. The "enrollee.hex" can be found at "out/arduino/arm/release/service/easy-setup/sampleapp/enrollee/arduino"
+    g) After building sample, script will try to install on "/dev/ttyACM0" port in 'sudo' mode.
+        To skip installation, set command line argument 'UPLOAD=false' or without UPLOAD option
+    h) To set BLE Shield Name, include the option DEVICE_NAME during scons build.
+        -> $ scons TARGET_OS=arduino BOARD=arduino_due_x_dbg TARGET_ARCH=arm SHIELD=BLE RELEASE=0 DEVICE_NAME=OIC
+
+            Specified Device name length MUST be less than 10 characters. RBL Library has this limitation.
+            By Default DEVICE_NAME=OIC-DEVICE, if device name option is not specified
+
+            To change the port number, please modify  "port" variable in __upload() function in: "/build/arduino/SConscript".
+
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Folder structure:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++        
+
+iotivity/
+└── service
+    â””── easy-setup/
+        â”‚── SConscript
+        â”‚── sdk
+        â”‚    â””── inc
+        â”‚    â””── src
+        â”‚    â””── android
+        â”‚    â””── arduino
+        â”‚        â””──wifi
+        â”‚            â””──inc
+        â”‚            â””──src
+        â”‚── sampleapp
+        â”‚    â””──mediator/android
+        â”‚    â””──mediator/linux
+        â”‚    â””──enrollee/arduino
+        â””── Build_Instructions_Android_Arduino.txt - You are reading this.
diff --git a/service/easy-setup/SConscript b/service/easy-setup/SConscript
new file mode 100644 (file)
index 0000000..fef6e1d
--- /dev/null
@@ -0,0 +1,111 @@
+#******************************************************************
+#
+# Copyright 2014 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# easy-setup project build script
+##
+
+import os
+
+Import('env')
+
+transport = env.get('TARGET_TRANSPORT')
+
+env.AppendUnique(CPPDEFINES = ['EASY_SETUP_CA_INIT'])
+
+easy_setup_env = env.Clone()
+#
+target_os = env.get('TARGET_OS')
+
+lib_env = env.Clone()
+if target_os == 'android':
+       SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', exports = 'lib_env')
+
+######################################################################
+# Build flags
+######################################################################
+easy_setup_env.AppendUnique(CPPPATH = ['sdk/inc', 'sdk/src', 'sdk/common'])
+
+if target_os not in ['windows', 'winrt']:
+    easy_setup_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
+    if target_os not in ['android', 'arduino']:
+        easy_setup_env.AppendUnique(CXXFLAGS = ['-pthread'])
+
+if target_os in ['android', 'linux']:
+       easy_setup_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+       easy_setup_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
+       easy_setup_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+       if target_os not in ['linux', 'arduino']:
+               easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'gnustl_shared'])      
+               if not env.get('RELEASE'):
+                       easy_setup_env.AppendUnique(LIBS = ['log'])
+       else:
+               easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
+if target_os == 'arduino':
+       easy_setup_env.AppendUnique(CPPPATH = [
+                              '../../resource/oc_logger/include',
+                              '../../resource/csdk/logger/include',
+                              '../../resource/csdk/stack/include',
+                              '../../extlibs/cjson',
+                                  'sdk/enrollee/arduino/wifi',
+                                  'sdk/enrollee/common/src',
+                              'sdk/enrollee/common/inc'])
+       easy_setup_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI'])
+if target_os in ['android','linux']:                                      
+       easy_setup_env.PrependUnique(CPPPATH = [
+               env.get('SRC_DIR') + '/resource/c_common/oic_malloc/include',           
+               env.get('SRC_DIR') + '/resource/csdk/connectivity/common/inc',
+               env.get('SRC_DIR') + '/resource/csdk/connectivity/api',
+        env.get('SRC_DIR') + '/resource/csdk/stack/include',
+        env.get('SRC_DIR') + '/resource/csdk/logger/include',
+               env.get('SRC_DIR') + '/resource/csdk/security/include',
+               env.get('SRC_DIR') + '/extlibs/cjson',
+               'sdk/common',
+               'sdk/mediator/inc'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+
+if target_os == 'arduino':
+       es_sdk_static = easy_setup_env.StaticLibrary('ESSDKLibrary',
+                                       ['sdk/enrollee/common/src/easysetup.cpp',
+                                       'sdk/enrollee/common/src/resourceHandler.cpp',
+                                       'sdk/enrollee/arduino/wifi/networkHandler.cpp'])
+       easy_setup_env.InstallTarget(es_sdk_static, 'libESSDK')
+
+if target_os == 'android':
+       es_sdk_shared = easy_setup_env.StaticLibrary('libESSDK',
+                                       ['sdk/mediator/src/prov_adapter.cpp',
+                                       'sdk/mediator/src/wifi_provisioning.cpp',
+                                        'sdk/mediator/src/provisioning.cpp'])
+       easy_setup_env.InstallTarget(es_sdk_shared, 'libESSDK')
+
+if target_os == 'linux':
+       es_sdk_shared = easy_setup_env.SharedLibrary('ESSDKLibrary',
+                                       ['sdk/mediator/src/prov_adapter.cpp',
+                                       'sdk/mediator/src/wifi_provisioning.cpp',
+                                        'sdk/mediator/src/provisioning.cpp'])
+       easy_setup_env.InstallTarget(es_sdk_shared, 'libESSDK')
+
+#Go to build sample apps
+SConscript('sampleapp/SConscript')
+
+
diff --git a/service/easy-setup/sampleapp/SConscript b/service/easy-setup/sampleapp/SConscript
new file mode 100644 (file)
index 0000000..fa70b40
--- /dev/null
@@ -0,0 +1,46 @@
+#******************************************************************
+#
+# Copyright 2014 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# sampleapp build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+
+sample_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
+
+######################################################################
+# Build flags
+######################################################################
+
+######################################################################
+# Source files and Targets
+######################################################################
+if target_os == 'arduino' :
+       # Build linux sample app
+       SConscript('enrollee/arduino/SConscript')
+
+if target_os == 'linux' :
+       # Build linux sample app
+       SConscript('mediator/linux/SConscript')
diff --git a/service/easy-setup/sampleapp/enrollee/arduino/SConscript b/service/easy-setup/sampleapp/enrollee/arduino/SConscript
new file mode 100644 (file)
index 0000000..f9c5bf0
--- /dev/null
@@ -0,0 +1,57 @@
+#******************************************************************
+#
+# Copyright 2014 Intel Mobile Communications GmbH 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+Import('env')
+
+enrollee_env = env.Clone()
+transport = enrollee_env.get('TARGET_TRANSPORT')
+
+######################################################################
+# Build flags
+######################################################################
+enrollee_env.PrependUnique(CPPPATH = [
+        '../../../../../resource/oc_logger/include',
+        '../../../../../resource/csdk/logger/include',
+        '../../../../../resource/csdk/stack/include',
+       '../../../../../extlibs/cjson',
+       '../../../sdk/common',
+       '../../../sdk/enrollee/arduino/wifi',
+       '../../../sdk/enrollee/common/inc',
+       '../../../sdk/enrollee/common/src'
+       ])
+enrollee_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI'])
+       
+enrollee_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+
+enrollee_env.PrependUnique(LIBS = ['octbstack','ocsrm','connectivity_abstraction','coap', 'ESSDKLibrary'])
+enrollee = enrollee_env.Program('enrollee', 'enrollee_wifi.cpp')
+env.CreateBin('enrollee')
+
+i_enrollee = enrollee_env.Install(env.get('BUILD_DIR'), enrollee)
+
+Alias('enrollee', i_enrollee)
+env.AppendTarget('enrollee')
+
+if(enrollee_env['UPLOAD'] == True):
+       from sys import platform as _platform
+       if _platform == "linux" or _platform == "linux2":
+               enrollee_env.Upload(env.get('BUILD_DIR') + '/service/easy-setup/sampleapp/enrollee/arduino/enrollee.hex')
+       else:
+               print 'Please use appropriate install method for your developing machine. Linux is the only supported platform right now.'
diff --git a/service/easy-setup/sampleapp/enrollee/arduino/enrollee_wifi.cpp b/service/easy-setup/sampleapp/enrollee/arduino/enrollee_wifi.cpp
new file mode 100755 (executable)
index 0000000..aa3416c
--- /dev/null
@@ -0,0 +1,112 @@
+//******************************************************************
+//
+// Copyright 2014 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// Do not remove the include below
+#include "Arduino.h"
+
+#include "logger.h"
+#include <string.h>
+
+#ifdef ARDUINOWIFI
+// Arduino WiFi Shield
+#include <SPI.h>
+#include <WiFi.h>
+#include <WiFiUdp.h>
+#else
+// Arduino Ethernet Shield
+#include <EthernetServer.h>
+#include <Ethernet.h>
+#include <Dns.h>
+#include <EthernetClient.h>
+#include <util.h>
+#include <EthernetUdp.h>
+#include <Dhcp.h>
+#endif
+
+#include "easysetup.h"
+
+#define TAG "TS"
+
+const char *getResult(OCStackResult result);
+
+char ssid[] = "EasySetup123";
+char passwd[] = "EasySetup123";
+
+void EventCallbackInApp(ESResult eventFlag)
+{
+    Serial.println("callback!!! in app");
+}
+
+// On Arduino Atmel boards with Harvard memory architecture, the stack grows
+// downwards from the top and the heap grows upwards. This method will print
+// the distance(in terms of bytes) between those two.
+// See here for more details :
+// http://www.atmel.com/webdoc/AVRLibcReferenceManual/malloc_1malloc_intro.html
+void PrintArduinoMemoryStats()
+{
+#ifdef ARDUINO_AVR_MEGA2560
+    //This var is declared in avr-libc/stdlib/malloc.c
+    //It keeps the largest address not allocated for heap
+    extern char *__brkval;
+    //address of tmp gives us the current stack boundry
+    int tmp;
+    OC_LOG_V(INFO, TAG, "Stack: %u         Heap: %u", (unsigned int)&tmp, (unsigned int)__brkval);
+    OC_LOG_V(INFO, TAG, "Unallocated Memory between heap and stack: %u",
+            ((unsigned int)&tmp - (unsigned int)__brkval));
+#endif
+}
+//The setup function is called once at startup of the sketch
+void setup()
+{
+    // Add your initialization code here
+    // Note : This will initialize Serial port on Arduino at 115200 bauds
+    OC_LOG_INIT();
+    OC_LOG(DEBUG, TAG, "OCServer is starting...");
+
+    if(InitEasySetup(ES_WIFI, ssid, passwd, EventCallbackInApp) == ES_ERROR)
+    {
+        OC_LOG(ERROR, TAG, "EasySetup Init Failed");
+        return;
+    }
+
+    if(InitProvisioning(EventCallbackInApp)== ES_ERROR)
+    {
+        OC_LOG(ERROR, TAG, "Init Provisioning Failed");
+        return;
+    }
+}
+
+// The loop function is called in an endless loop
+void loop()
+{
+    // This artificial delay is kept here to avoid endless spinning
+    // of Arduino microcontroller. Modify it as per specific application needs.
+    delay(2000);
+
+    // This call displays the amount of free SRAM available on Arduino
+    PrintArduinoMemoryStats();
+
+    // Give CPU cycles to OCStack to perform send/recv and other OCStack stuff
+    if (OCProcess() != OC_STACK_OK)
+    {
+        OC_LOG(ERROR, TAG, "OCStack process error");
+        return;
+    }
+}
diff --git a/service/easy-setup/sampleapp/mediator/android/.gitignore b/service/easy-setup/sampleapp/mediator/android/.gitignore
new file mode 100644 (file)
index 0000000..6451fc5
--- /dev/null
@@ -0,0 +1,50 @@
+#built application files\r
+*.apk\r
+*.ap_\r
+\r
+# files for the dex VM\r
+*.dex\r
+\r
+# Java class files\r
+*.class\r
+\r
+# generated files\r
+bin/\r
+gen/\r
+\r
+# Local configuration file (sdk path, etc)\r
+local.properties\r
+\r
+# Proguard folder generated by Eclipse \r
+proguard/ \r
+\r
+# Windows thumbnail db\r
+Thumbs.db\r
+\r
+# OSX files\r
+.DS_Store\r
+\r
+# Eclipse project files\r
+.classpath\r
+.project\r
+\r
+#Android Studio & Gradle\r
+.gradle\r
+/local.properties\r
+/.idea/workspace.xml\r
+/.idea/libraries\r
+.DS_Store\r
+/build/*\r
+/base/build/*\r
+/base/obj/*\r
+/base/libs/*\r
+/sample/*\r
+\r
+#Some older projects\r
+/*/out\r
+/*/*/build\r
+/*/*/production\r
+*.iws\r
+*.ipr\r
+*~\r
+*.swp
\ No newline at end of file
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/EasySetupGradle.iml b/service/easy-setup/sampleapp/mediator/android/EasySetup/EasySetupGradle.iml
new file mode 100644 (file)
index 0000000..4ac7e4f
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id="EasySetupGradle" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="java-gradle" name="Java-Gradle">
+      <configuration>
+        <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
+        <option name="BUILDABLE" value="false" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/.gradle" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/app.iml b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/app.iml
new file mode 100644 (file)
index 0000000..cb62b4a
--- /dev/null
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="EasySetup" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="android-gradle" name="Android-Gradle">
+      <configuration>
+        <option name="GRADLE_PROJECT_PATH" value=":app" />
+      </configuration>
+    </facet>
+    <facet type="android" name="Android">
+      <configuration>
+        <option name="SELECTED_BUILD_VARIANT" value="debug" />
+        <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
+        <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
+        <afterSyncTasks>
+          <task>generateDebugAndroidTestSources</task>
+          <task>generateDebugSources</task>
+        </afterSyncTasks>
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
+        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
+        <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+    <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/EasySetup/EasySetupCore-debug/unspecified/jars" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/EasySetup/iotivity-armeabi-base-debug/unspecified/jars" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+      <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
+    </content>
+    <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module" module-name="EasySetupCore-debug" exported="" />
+    <orderEntry type="module" module-name="iotivity-armeabi-base-debug" exported="" />
+    <orderEntry type="library" exported="" name="EasySetupCore-debug-unspecified" level="project" />
+    <orderEntry type="library" exported="" name="iotivity-armeabi-base-debug-unspecified" level="project" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/build.gradle b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/build.gradle
new file mode 100644 (file)
index 0000000..fa408da
--- /dev/null
@@ -0,0 +1,23 @@
+apply plugin: 'com.android.application'\r
+android {\r
+    compileSdkVersion 21\r
+    buildToolsVersion '21.1.2'\r
+\r
+    defaultConfig {\r
+        applicationId "org.iotivity.service.easysetup"\r
+        minSdkVersion 21\r
+        targetSdkVersion 21\r
+    }\r
+\r
+    buildTypes {\r
+        release {\r
+            minifyEnabled false\r
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'\r
+        }\r
+    }\r
+}\r
+\r
+dependencies {\r
+    compile project(':EasySetupCore-debug')\r
+    compile project(':iotivity-armeabi-base-debug')\r
+}
\ No newline at end of file
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/AndroidManifest.xml b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..4b4d4c5
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.service.easysetup"
+    android:versionCode="1"
+    android:versionName="1.0">
+
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
+
+    <uses-feature
+        android:name="android.hardware.camera"
+        android:required="true" />
+    <uses-feature
+        android:name="android.hardware.camera.autofocus"
+        android:required="false" />
+    <uses-feature
+        android:name="android.hardware.touchscreen"
+        android:required="false" />
+
+    <uses-permission android:name="android.permission.CAMERA" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme">
+        <activity
+            android:name=".MainActivity"
+            android:label="@string/app_name">
+
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java
new file mode 100644 (file)
index 0000000..cf6d115
--- /dev/null
@@ -0,0 +1,278 @@
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup;\r
+\r
+import java.io.IOException;\r
+\r
+import org.iotivity.service.easysetup.core.EasySetupService;\r
+import org.iotivity.service.easysetup.core.EasySetupStatus;\r
+import org.iotivity.service.easysetup.core.EnrolleeDevice;\r
+import org.iotivity.service.easysetup.core.EnrolleeState;\r
+import org.iotivity.service.easysetup.core.IpOnBoardingConnection;\r
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;\r
+import org.iotivity.service.easysetup.impl.WiFiOnBoardingConfig;\r
+import org.iotivity.service.easysetup.impl.WiFiProvConfig;\r
+\r
+import android.app.Activity;\r
+import android.net.wifi.WifiConfiguration;\r
+import android.os.Bundle;\r
+import android.os.Handler;\r
+import android.os.Message;\r
+import android.util.Log;\r
+import android.view.View;\r
+import android.view.View.OnClickListener;\r
+import android.widget.Button;\r
+import android.widget.EditText;\r
+import android.widget.ProgressBar;\r
+import android.widget.TextView;\r
+import android.widget.Toast;\r
+\r
+public class MainActivity extends Activity {\r
+\r
+\r
+    /*Status to update the UI */\r
+    public static final int SUCCESS = 0;\r
+    public static final int FAILED = 1;\r
+    public static final int STATE_CHANGED = 2;\r
+\r
+    EditText mSsidText;\r
+    EditText mPassText;\r
+\r
+    EditText mEnrolleeSsidText;\r
+    EditText mmEnrolleePasswordPassText;\r
+\r
+\r
+    TextView mDeviceIpTextView;\r
+    TextView mDeviceMacTextView;\r
+\r
+\r
+    TextView mResultTextView;\r
+    ProgressBar mProgressbar;\r
+    Button mStartButton;\r
+    Button mStopButton;\r
+    Handler mHandler = new ThreadHandler();\r
+\r
+    /**\r
+     * Objects to be instantiated by the programmer\r
+     */\r
+    WiFiProvConfig mWiFiProvConfig;\r
+    WiFiOnBoardingConfig mWiFiOnBoardingConfig;\r
+    EasySetupService mEasySetupService;\r
+    EnrolleeDeviceFactory mDeviceFactory;\r
+    EnrolleeDevice mDevice;\r
+\r
+    @Override\r
+    protected void onCreate(Bundle savedInstanceState) {\r
+        super.onCreate(savedInstanceState);\r
+        setContentView(R.layout.activity_main);\r
+\r
+        /* Initialize widgets to get user input for target network's SSID & password*/\r
+        mSsidText = (EditText) findViewById(R.id.ssid);\r
+        mPassText = (EditText) findViewById(R.id.password);\r
+        mEnrolleeSsidText = (EditText) findViewById(R.id.enrolleeSsid);\r
+        mmEnrolleePasswordPassText = (EditText) findViewById(R.id.enrolleePass);\r
+        mDeviceIpTextView = (TextView) findViewById(R.id.ipAddr);\r
+        mDeviceMacTextView = (TextView) findViewById(R.id.hardAddr);\r
+\r
+        mResultTextView = (TextView) findViewById(R.id.status);\r
+        mProgressbar = (ProgressBar) findViewById(R.id.progressBar);\r
+\r
+\r
+\r
+\r
+       /* Create Easy Setup Service instance*/\r
+        mEasySetupService = EasySetupService.getInstance(getApplicationContext(),\r
+                new EasySetupStatus() {\r
+\r
+                    @Override\r
+                    public void onFinished(final EnrolleeDevice enrolledevice) {\r
+                        Log.i("MainActivity", "onFinished() is received " + enrolledevice\r
+                                .isSetupSuccessful());\r
+                        if (enrolledevice.isSetupSuccessful()) {\r
+                            mHandler.sendEmptyMessage(SUCCESS);\r
+                        } else {\r
+                            mHandler.sendEmptyMessage(FAILED);\r
+                        }\r
+                    }\r
+\r
+                    @Override\r
+                    public void onProgress(EnrolleeState state) {\r
+                        Log.i("MainActivity", "onProgress() is received ");\r
+                        mHandler.sendEmptyMessage(STATE_CHANGED);\r
+                    }\r
+\r
+                });\r
+\r
+        /* Create EnrolleeDevice Factory instance*/\r
+        mDeviceFactory = EnrolleeDeviceFactory.newInstance(getApplicationContext());\r
+\r
+        /* Create a device using Factory instance*/\r
+        mDevice = mDeviceFactory.newEnrolleeDevice(getOnBoardingWifiConfig(),\r
+                getEnrollerWifiConfig());\r
+\r
+        addListenerForStartAP();\r
+        addListenerForStopAP();\r
+    }\r
+\r
+    public WiFiProvConfig getEnrollerWifiConfig() {\r
+        /* Provide the credentials for the Mediator Soft AP to be connected by Enrollee*/\r
+        mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222");\r
+        mEnrolleeSsidText.setText("hub2.4G");\r
+        mmEnrolleePasswordPassText.setText("11112222");\r
+\r
+        return mWiFiProvConfig;\r
+    }\r
+\r
+    public WiFiOnBoardingConfig getOnBoardingWifiConfig() {\r
+        mWiFiOnBoardingConfig = new WiFiOnBoardingConfig();\r
+\r
+        /* Provide the target credentials to be provisioned to the Enrollee by Mediator*/\r
+        mWiFiOnBoardingConfig.setSSId("EasySetup123");\r
+        mWiFiOnBoardingConfig.setSharedKey("EasySetup123");\r
+        mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);\r
+        mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);\r
+\r
+        // Updating the UI with default credentials\r
+        mSsidText.setText("EasySetup123");\r
+        mPassText.setText("EasySetup123");\r
+\r
+        return mWiFiOnBoardingConfig;\r
+    }\r
+\r
+\r
+    public void onDestroy() {\r
+        super.onDestroy();\r
+        /*Reset the Easy setup process*/\r
+        if (mEasySetupService != null) {\r
+            mEasySetupService.finish();\r
+        }\r
+    }\r
+\r
+    public void addListenerForStartAP() {\r
+        mStartButton = (Button) findViewById(R.id.startSetup);\r
+\r
+        mStartButton.setOnClickListener(new OnClickListener() {\r
+            @Override\r
+            public void onClick(View arg0) {\r
+                try {\r
+\r
+                    mProgressbar.setVisibility(View.VISIBLE);\r
+                    mProgressbar.setIndeterminate(true);\r
+                    mStartButton.setEnabled(false);\r
+                    mResultTextView.setText(R.string.running);\r
+\r
+                    //Reset Device information\r
+                    mDeviceIpTextView.setText(R.string.not_available);\r
+                    mDeviceMacTextView.setText(R.string.not_available);\r
+\r
+\r
+                    String ssid = mSsidText.getText().toString();\r
+                    String password = mPassText.getText().toString();\r
+\r
+                    String enrolleeSsid = mEnrolleeSsidText.getText().toString();\r
+                    String enrolleePassword = mmEnrolleePasswordPassText.getText().toString();\r
+\r
+                    mWiFiProvConfig = new WiFiProvConfig(enrolleeSsid, enrolleePassword);\r
+\r
+                    mWiFiOnBoardingConfig.setSSId(ssid);\r
+                    mWiFiOnBoardingConfig.setSharedKey(password);\r
+\r
+\r
+                    mEasySetupService.startSetup(mDevice);\r
+\r
+                    mStopButton.setEnabled(true);\r
+\r
+\r
+                } catch (IOException e) {\r
+                    e.printStackTrace();\r
+                }\r
+\r
+            }\r
+        });\r
+    }\r
+\r
+    public void addListenerForStopAP() {\r
+        mStopButton = (Button) findViewById(R.id.stopSetup);\r
+\r
+        mStopButton.setOnClickListener(new OnClickListener() {\r
+            @Override\r
+            public void onClick(View arg0) {\r
+                mStartButton.setEnabled(true);\r
+                mStopButton.setEnabled(false);\r
+                mResultTextView.setText(R.string.stopped);\r
+                mProgressbar.setIndeterminate(false);\r
+                mProgressbar.setVisibility(View.INVISIBLE);\r
+                mEasySetupService.stopSetup(mDevice);\r
+            }\r
+        });\r
+    }\r
+\r
+\r
+    class ThreadHandler extends Handler {\r
+        @Override\r
+        public void handleMessage(Message msg) {\r
+\r
+            switch (msg.what) {\r
+                case SUCCESS: {\r
+\r
+                    mProgressbar.setIndeterminate(false);\r
+                    mStopButton.setEnabled(false);\r
+                    mStartButton.setEnabled(true);\r
+                    mProgressbar.setVisibility(View.INVISIBLE);\r
+                    String resultMsg = "Device configured successfully";\r
+                    mResultTextView.setText(R.string.success);\r
+\r
+                    /* Update device information on the Ui */\r
+                    IpOnBoardingConnection connection = (IpOnBoardingConnection) mDevice\r
+                            .getConnection();\r
+                    mDeviceIpTextView.setText(connection.getIp());\r
+                    mDeviceMacTextView.setText(connection.getHardwareAddress());\r
+\r
+                    Toast.makeText(getApplicationContext(), resultMsg, Toast.LENGTH_SHORT).show();\r
+                    break;\r
+                }\r
+                case FAILED: {\r
+\r
+                    mProgressbar.setIndeterminate(false);\r
+                    mStopButton.setEnabled(false);\r
+                    mStartButton.setEnabled(true);\r
+                    mProgressbar.setVisibility(View.INVISIBLE);\r
+                    String resultMsg = "Device configuration failed";\r
+                    mResultTextView.setText(R.string.failed);\r
+                    Toast.makeText(getApplicationContext(), resultMsg, Toast.LENGTH_SHORT).show();\r
+                    break;\r
+                }\r
+\r
+                case STATE_CHANGED: {\r
+                    String resultMsg = "Device state changed";\r
+                    Toast.makeText(getApplicationContext(), resultMsg, Toast.LENGTH_SHORT).show();\r
+                    break;\r
+                }\r
+\r
+            }\r
+\r
+\r
+        }\r
+    }\r
+\r
+}\r
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/background.png b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/background.png
new file mode 100644 (file)
index 0000000..561cce8
Binary files /dev/null and b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/background.png differ
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/cancel.png b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/cancel.png
new file mode 100644 (file)
index 0000000..da342e5
Binary files /dev/null and b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/cancel.png differ
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/ic_launcher.png b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..288b665
Binary files /dev/null and b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/icon.png b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/icon.png
new file mode 100644 (file)
index 0000000..24a8af2
Binary files /dev/null and b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/drawable-hdpi/icon.png differ
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/layout/activity_main.xml b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/layout/activity_main.xml
new file mode 100644 (file)
index 0000000..4c2e087
--- /dev/null
@@ -0,0 +1,224 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@drawable/background"
+    android:orientation="vertical"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    tools:context="org.iotivity.service.easysetup.mediator.MainActivity">
+
+
+    <ProgressBar
+        android:id="@+id/progressBar"
+        style="?android:attr/progressBarStyleHorizontal"
+        android:layout_width="350dp"
+        android:layout_height="wrap_content"
+        android:visibility="invisible" />
+
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:layout_marginTop="5dp"
+        android:orientation="horizontal">
+
+
+        <TextView
+            android:id="@+id/lablestatus"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="8dp"
+            android:layout_marginRight="20dp"
+            android:elegantTextHeight="true"
+            android:text="@string/test_status"
+            android:textSize="15sp" />
+
+        <TextView
+            android:id="@+id/status"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="10dp"
+            android:layout_marginRight="30dp"
+            android:text="@string/not_started"
+            android:textColor="@android:color/background_light"
+            android:textSize="20dp" />
+
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_gravity="center"
+        android:layout_marginTop="10dp"
+        android:orientation="vertical">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Enter Enroller's SSID" />
+
+
+        <EditText
+            android:id="@+id/enrolleeSsid"
+            android:layout_width="250dp"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal" />
+
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dp"
+            android:text="Enter Enroller's Password" />
+
+
+        <EditText
+            android:id="@+id/enrolleePass"
+            android:layout_width="250dp"
+            android:layout_height="wrap_content"
+
+            android:layout_gravity="center_horizontal" />
+
+    </LinearLayout>
+
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_gravity="center"
+        android:layout_marginTop="10dp"
+        android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/textView"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Enter SoftAP SSID" />
+
+
+        <EditText
+            android:id="@+id/ssid"
+            android:layout_width="250dp"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal" />
+
+
+        <TextView
+            android:id="@+id/textView2"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dp"
+            android:text="Enter SoftAP PWD" />
+
+
+        <EditText
+            android:id="@+id/password"
+            android:layout_width="250dp"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal" />
+
+    </LinearLayout>
+
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_horizontal"
+        android:layout_marginTop="5dp"
+        android:text="Device information"
+        android:textAppearance="?android:attr/textAppearanceMedium" />
+
+    <RelativeLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_gravity="center"
+        android:layout_marginTop="10dp"
+        android:orientation="vertical">
+
+
+        <TextView
+            android:id="@+id/ipAddrLable"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:text="IP Address"
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+
+        <TextView
+            android:id="@+id/ipAddr"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:layout_toRightOf="@id/ipAddrLable"
+            android:text="@string/not_available"
+
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+
+
+        <TextView
+            android:id="@+id/hardAddrLable"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/ipAddrLable"
+            android:layout_gravity="center_horizontal"
+            android:text="MAC Address"
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+
+        <TextView
+            android:id="@+id/hardAddr"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/ipAddr"
+            android:layout_gravity="center_horizontal"
+            android:layout_toRightOf="@id/hardAddrLable"
+            android:text="@string/not_available"
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+
+
+    </RelativeLayout>
+
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_gravity="center"
+        android:layout_marginTop="20dp"
+        android:orientation="horizontal">
+
+        <Button
+            android:id="@+id/startSetup"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentTop="true"
+            android:layout_centerHorizontal="true"
+            android:layout_margin="10dp"
+            android:layout_marginTop="20dp"
+            android:elegantTextHeight="true"
+            android:text="@string/startSetup"
+            android:textAllCaps="false"
+            android:textSize="18sp" />
+
+        <Button
+            android:id="@+id/stopSetup"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@+id/startSetup"
+            android:layout_centerHorizontal="true"
+            android:layout_margin="10dp"
+            android:elegantTextHeight="true"
+            android:enabled="false"
+            android:text="@string/stopSetup"
+            android:textAllCaps="false"
+            android:textSize="18sp" />
+
+    </LinearLayout>
+
+</LinearLayout>
\ No newline at end of file
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/menu/main.xml b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/menu/main.xml
new file mode 100644 (file)
index 0000000..97c527e
--- /dev/null
@@ -0,0 +1,11 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:context="org.iotivity.service.easysetup.MainActivity" >
+
+    <item
+        android:id="@+id/action_settings"
+        android:orderInCategory="100"
+        android:title="@string/action_settings"/>
+
+</menu>
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/values/dimens.xml b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/values/dimens.xml
new file mode 100644 (file)
index 0000000..ab91646
--- /dev/null
@@ -0,0 +1,7 @@
+<resources>
+
+    <!-- Default screen margins, per the Android Design guidelines. -->
+    <dimen name="activity_horizontal_margin">16dp</dimen>
+    <dimen name="activity_vertical_margin">1dp</dimen>
+
+</resources>
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/values/strings.xml b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..8383bac
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">Easy Setup</string>
+    <string name="action_settings">Settings</string>
+    <string name="textview2">Device Information</string>
+    <string name="textview1"> -- empty -- </string>
+    <string name="scan_qr_code">Scan QR Code</string> 
+       <string name="start_easy_setup">Start Easy Setup</string> 
+       <string name="start_soft_ap">Start Wi-Fi Soft AP</string>
+       <string name="stop_soft_ap">Stop Soft AP</string>  
+    <string name="provision_device">Provision Connected Device</string>
+
+    <string name="startSetup">Start Setup</string>
+    <string name="stopSetup">Stop Setup</string>
+    <string name="SSID">SSID</string>
+    <string name="Password">Password</string>
+    <string name="success">Successful</string>
+    <string name="failed">Failed</string>
+    <string name="not_started">Not started</string>
+    <string name="test_status">Device configuration</string>
+    <string name="running">Running</string>
+    <string name="stopped">Stopped</string>
+    <string name="not_available">Not available</string>
+
+
+</resources>
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/values/styles.xml b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/values/styles.xml
new file mode 100644 (file)
index 0000000..6ce89c7
--- /dev/null
@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/build.gradle b/service/easy-setup/sampleapp/mediator/android/EasySetup/build.gradle
new file mode 100644 (file)
index 0000000..0a7f6ce
--- /dev/null
@@ -0,0 +1,15 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.\r
+buildscript {\r
+    repositories {\r
+        jcenter()\r
+    }\r
+    dependencies {\r
+        classpath 'com.android.tools.build:gradle:1.2.3'\r
+    }\r
+}\r
+\r
+allprojects {\r
+    repositories {\r
+        jcenter()\r
+    }\r
+}\r
diff --git a/service/easy-setup/sampleapp/mediator/android/EasySetup/settings.gradle b/service/easy-setup/sampleapp/mediator/android/EasySetup/settings.gradle
new file mode 100755 (executable)
index 0000000..d3db109
--- /dev/null
@@ -0,0 +1 @@
+include ':app'\r
diff --git a/service/easy-setup/sampleapp/mediator/linux/SConscript b/service/easy-setup/sampleapp/mediator/linux/SConscript
new file mode 100644 (file)
index 0000000..10d9873
--- /dev/null
@@ -0,0 +1,51 @@
+#******************************************************************
+#
+# Copyright 2014 Intel Mobile Communications GmbH 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+Import('env')
+
+mediator_env = env.Clone()
+
+target_os = env.get('TARGET_OS')
+
+######################################################################
+# Build flags
+######################################################################
+mediator_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+mediator_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+mediator_env.PrependUnique(CPPPATH = [
+                       env.get('SRC_DIR') + '/resource/csdk/ocmalloc/include',         
+                       env.get('SRC_DIR') + '/resource/csdk/connectivity/common/inc',
+                       env.get('SRC_DIR') + '/resource/csdk/connectivity/api',
+                       env.get('SRC_DIR') + '/resource/csdk/stack/include',
+                       env.get('SRC_DIR') + '/resource/csdk/logger/include',
+                       env.get('SRC_DIR') + '/resource/csdk/security/include',
+                       env.get('SRC_DIR') + '/extlibs/cjson',
+                       env.get('SRC_DIR') + '/service/easy-setup/sdk/mediator/inc',
+                       env.get('SRC_DIR') + '/service/easy-setup/sdk/common'])
+
+mediator_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction', 'coap', 'ESSDKLibrary'])
+
+mediator = mediator_env.Program('mediator', 'mediator.cpp')
+
+i_mediator = mediator_env.Install(env.get('BUILD_DIR'), mediator)
+
+Alias('mediator', i_mediator)
+env.AppendTarget('mediator')
diff --git a/service/easy-setup/sampleapp/mediator/linux/mediator.cpp b/service/easy-setup/sampleapp/mediator/linux/mediator.cpp
new file mode 100644 (file)
index 0000000..463a435
--- /dev/null
@@ -0,0 +1,109 @@
+//******************************************************************
+//
+// 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <sstream>
+
+#include "prov_adapter.h"
+#include "logger.h"
+
+#define TAG "easysetupsample"
+
+int quitFlag = 0;
+
+/* SIGINT handler: set quitFlag to 1 for graceful termination */
+void handleSigInt(int signum) {
+    if (signum == SIGINT) {
+        quitFlag = 1;
+    }
+}
+
+/**
+ * This callback function is used to receive the notifications about the provisioning status
+ * In success or failure, ProvisioningInfo structure holds the current state of provisioning
+ * and also holds the Enrollee information for which provisioning is requested
+ * This function can be used to update the application about the current provisioning status of the Enrollee
+ */
+void ProvisioningStatusCallback(ProvisioningInfo * provInfo) {
+    OIC_LOG_V(INFO, TAG, "Enrollee connectivity: %d", provInfo->provDeviceInfo.connType);
+    if (provInfo->provStatus == DEVICE_PROVISIONED) {
+        OIC_LOG_V(INFO, TAG, "Successfully provisioned the Enrollee with IP : %s ",
+                  provInfo->provDeviceInfo.addr->addr);
+    }
+    else {
+        OIC_LOG_V(INFO, TAG, "Provisioing Failed for the Enrollee with IP : %s",
+                  provInfo->provDeviceInfo.addr->addr);
+    }
+}
+
+static void PrintUsage() {
+    OIC_LOG(INFO, TAG, "Usage : occlient -d \"192.168.0.20\"");
+}
+
+int main(int argc, char **argv) {
+    int opt;
+    EnrolleeNWProvInfo_t netInfo;
+    PrintUsage();
+    InitProvProcess();
+
+
+    RegisterCallback(ProvisioningStatusCallback);
+
+    while ((opt = getopt(argc, argv, "d:s:p:")) != -1) {
+        switch (opt) {
+            case 'd':
+                strncpy(netInfo.netAddressInfo.WIFI.ipAddress, optarg, IPV4_ADDR_SIZE - 1);
+                break;
+            case 's':
+                strncpy(netInfo.netAddressInfo.WIFI.ssid, optarg, NET_WIFI_SSID_SIZE - 1);
+                break;
+            case 'p':
+                strncpy(netInfo.netAddressInfo.WIFI.pwd, optarg, NET_WIFI_PWD_SIZE - 1);
+                break;
+            default:
+                PrintUsage();
+                return -1;
+        }
+    }
+
+    netInfo.connType = CT_ADAPTER_IP;
+    OIC_LOG_V(INFO, TAG, "IP Address of the Provisioning device is =%s\n",
+              netInfo.netAddressInfo.WIFI.ipAddress);
+    OIC_LOG_V(INFO, TAG, "SSID of the Enroller is =%s\n", netInfo.netAddressInfo.WIFI.ssid);
+    OIC_LOG_V(INFO, TAG, "Password of the Enroller is =%s\n", netInfo.netAddressInfo.WIFI.pwd);
+
+    StartProvisioning(&netInfo);
+
+    signal(SIGINT, handleSigInt);
+    while (!quitFlag) {
+        sleep(1);
+    }
+
+    ResetProvProcess();
+    OIC_LOG(INFO, TAG, "Exiting occlient main loop...");
+
+    return 0;
+}
+
diff --git a/service/easy-setup/sdk/common/common.h b/service/easy-setup/sdk/common/common.h
new file mode 100755 (executable)
index 0000000..d6e8bea
--- /dev/null
@@ -0,0 +1,151 @@
+//******************************************************************
+//
+// Copyright 2014 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 ES_COMMON_H_
+#define ES_COMMON_H_
+
+#include "ocstack.h"
+#include "octypes.h"
+
+// Defines
+#define OIC_STRING_MAX_VALUE 100
+#define IPV4_ADDR_SIZE 16
+#define IP_PORT 55555
+#define NET_WIFI_SSID_SIZE 16
+#define NET_WIFI_PWD_SIZE 16
+
+/**
+ * @brief Mac address length for BT port
+ */
+#define NET_MACADDR_SIZE 18
+
+//The following variable determines the interface (wifi, ethernet etc.)
+//to be used for sending unicast messages. Default set to Ethernet.
+static OCConnectivityType OC_CONNTYPE = CT_IP_USE_V4;
+static OCConnectivityType OC_CONNTYPE_BLE =  CT_ADAPTER_GATT_BTLE;
+
+static const char * UNICAST_PROVISIONING_QUERY = "coap://%s:%d/oic/res?rt=oic.prov";
+static const char * UNICAST_PROV_STATUS_QUERY = "coap://%s:%d%s";
+
+/**
+ * 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_URI_PROV               "/oic/prov"
+#define OC_RSRVD_ES_URI_NET                "/oic/net"
+
+
+
+typedef enum
+{
+    ES_ERROR = -1,
+    ES_OK = 0,
+    ES_NETWORKFOUND = 1,
+    ES_NETWORKCONNECTED,
+    ES_NETWORKNOTCONNECTED,
+    ES_RESOURCECREATED = 11,
+    ES_RECVREQOFPROVRES = 21,
+    ES_RECVREQOFNETRES,
+    ES_RECVUPDATEOFPROVRES,
+    ES_RECVTRIGGEROFPROVRES,
+} ESResult;
+
+
+/**
+ * Provisioning Device Status
+ */
+typedef struct {
+    /// Address of remote server
+    OCDevAddr * addr;
+    /// Indicates adaptor type on which the response was received
+    OCConnectivityType connType;
+} ProvDeviceInfo;
+
+/**
+ * Provosioning Status
+ */
+typedef enum {
+    DEVICE_PROVISIONED = 0, DEVICE_NOT_PROVISIONED
+} ProvStatus;
+
+/**
+ * Response from queries to remote servers. Queries are made by calling the @ref OCDoResource API.
+ */
+typedef struct {
+    // Provisioning Status
+    ProvStatus provStatus;
+    // Provisioning Device Info
+    ProvDeviceInfo provDeviceInfo;
+} ProvisioningInfo;
+
+/**
+ * @brief  Network information of the Enroller
+ */
+typedef union
+{
+    /**
+     * @brief BT Mac Information
+     */
+    struct
+    {
+        char btMacAddress[NET_MACADDR_SIZE];   /**< BT mac address **/
+    } BT;
+
+    /**
+     * @brief LE MAC Information
+     */
+    struct
+    {
+        char leMacAddress[NET_MACADDR_SIZE];   /**< BLE mac address **/
+    } LE;
+
+    /**
+     * @brief IP Information
+     */
+    struct
+    {
+        char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enroller**/
+        char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
+        char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
+    } WIFI;
+} EnrolleeInfo_t;
+
+
+/**
+ * @brief Network Information
+ */
+typedef struct
+{
+    EnrolleeInfo_t netAddressInfo;          /**< Enroller Network Info**/
+    OCConnectivityType connType;            /**< Connectivity Type**/
+    bool isSecured;                         /**< Secure connection**/
+} EnrolleeNWProvInfo_t;
+
+/**
+ * Client applications implement this callback to consume responses received from Servers.
+ */
+typedef void (*OCProvisioningStatusCB)(ProvisioningInfo *provInfo);
+
+#endif
diff --git a/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp b/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp
new file mode 100755 (executable)
index 0000000..b648a82
--- /dev/null
@@ -0,0 +1,185 @@
+//******************************************************************
+//
+// Copyright 2014 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"
+
+#define TAG "ES_NH"
+
+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";
+
+IPAddress myIP;
+
+ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb)
+{
+    char *fwVersion;
+    int status = WL_IDLE_STATUS;
+    int res;
+
+    // check for the presence of the shield:
+    if (WiFi.status() == WL_NO_SHIELD)
+    {
+        OC_LOG(ERROR, TAG, "WiFi shield not present");
+        return ES_ERROR;
+    }
+
+    // Verify that WiFi Shield is running the firmware with all UDP fixes
+    fwVersion = WiFi.firmwareVersion();
+    OC_LOG_V(INFO, TAG, "WiFi Shield Firmware version %s", fwVersion);
+    if (strncmp(fwVersion, ARDUINO_WIFI_SHIELD_UDP_FW_VER, sizeof(ARDUINO_WIFI_SHIELD_UDP_FW_VER))
+            != 0)
+    {
+        OC_LOG(DEBUG, TAG, "!!!!! Upgrade WiFi Shield Firmware version !!!!!!");
+        //return ES_ERROR;
+    }
+
+    OC_LOG_V(INFO, TAG, "Finding SSID: %s", ssid);
+
+    while (findNetwork(ssid) == 0) // found
+    {
+        delay(1000);
+    }
+
+    if (cb != NULL)
+    {
+        cb(ES_NETWORKFOUND);
+    }
+
+    if (WiFi.status() == WL_CONNECTED)
+        WiFi.disconnect();
+
+    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)
+    {
+        OC_LOG_V(INFO, TAG, "Attempting to connect to SSID: %s", ssid);
+
+        status = WiFi.begin((char *) ssid, (char *) pass);
+
+        // wait 10 seconds for connection:
+        delay(10000);
+    }
+    OC_LOG(DEBUG, TAG, "Connected to wifi");
+
+    myIP = WiFi.localIP();
+    OC_LOG_V(INFO, TAG, "IP Address:  %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
+
+    char buf[50];
+    sprintf(buf, "IP Address:  %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
+    Serial.println(buf);
+
+    return 0;
+}
+
+int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info)
+{
+    if (targetType == ES_WIFI && WiFi.status() == WL_CONNECTED)
+    {
+        info->type = ES_WIFI;
+        info->ipaddr = WiFi.localIP();
+        if(strlen(WiFi.SSID())<=MAXSSIDLEN)
+           strcpy(info->ssid, WiFi.SSID());
+        else return -1;
+
+        return 0;
+    }
+
+    return -1;
+}
+
+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/sdk/enrollee/arduino/wifi/networkHandler.h b/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.h
new file mode 100755 (executable)
index 0000000..5da8cbb
--- /dev/null
@@ -0,0 +1,65 @@
+//******************************************************************
+//
+// Copyright 2014 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// Do not remove the include below
+#include "Arduino.h"
+
+#include "logger.h"
+#include "ocstack.h"
+#include <string.h>
+
+// Arduino WiFi Shield
+#include <SPI.h>
+#include <WiFi.h>
+#include <WiFiUdp.h>
+
+#include "common.h"
+
+#ifndef ES_NETWORK_HANDLER_H_
+#define ES_NETWORK_HANDLER_H_
+
+#define MAXSSIDLEN 33
+#define MAXNETCREDLEN 20
+#define MAXNUMTYPE 5
+#define MAXADDRLEN 15
+
+typedef void (*NetworkEventCallback)(ESResult);
+
+enum NetworkType
+{
+    ES_WIFI = 1, ES_BT = 2, ES_BLE = 3, ES_ZIGBEE = 4, ES_ETH = 5
+};
+
+typedef struct NETWORKINFO
+{
+    NetworkType type;
+
+    // for WiFI
+    IPAddress ipaddr;
+    char ssid[MAXSSIDLEN];
+
+    // for BT, BLE
+    byte mac[6];
+} NetworkInfo;
+
+ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback);
+int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info);
+
+#endif
diff --git a/service/easy-setup/sdk/enrollee/common/inc/easysetup.h b/service/easy-setup/sdk/enrollee/common/inc/easysetup.h
new file mode 100755 (executable)
index 0000000..116c930
--- /dev/null
@@ -0,0 +1,40 @@
+//******************************************************************
+//
+// Copyright 2014 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// Do not remove the include below
+#include "Arduino.h"
+
+#include <string.h>
+#include "ocstack.h"
+#include "networkHandler.h"
+
+typedef void (*EventCallback)(ESResult);
+
+#ifdef ESWIFI
+ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd,EventCallback cb);
+#endif
+
+#ifdef ESBLE
+ESResult InitEasySetup(NetworkType networkType,EventCallback cb);
+#endif
+
+ESResult InitProvisioning(EventCallback cb);
+ESResult TerminateEasySetup();
+
diff --git a/service/easy-setup/sdk/enrollee/common/inc/resourceHandler.h b/service/easy-setup/sdk/enrollee/common/inc/resourceHandler.h
new file mode 100755 (executable)
index 0000000..e64c2f5
--- /dev/null
@@ -0,0 +1,67 @@
+//******************************************************************
+//
+// Copyright 2014 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// Do not remove the include below
+#include "Arduino.h"
+
+#include "logger.h"
+#include "ocstack.h"
+#include <string.h>
+
+#include "common.h"
+#include "networkHandler.h"
+#include "octypes.h"
+
+#ifndef ES_RESOURCE_HANDLER_H_
+#define ES_RESOURCE_HANDLER_H_
+
+typedef void (*ResourceEventCallback)(ESResult);
+
+/* Structure to represent a Light resource */
+typedef struct PROVRESOURCE
+{
+    OCResourceHandle handle;
+    int ps; // provisiong status, 1 : need to provisioning, 2 : Connected to Internet
+    int 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
+} ProvResource;
+
+/* Structure to represent a Light resource */
+typedef struct NETRESOURCE
+{
+    OCResourceHandle handle;
+    int cnt; // current network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee, ...
+    int 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;
+
+OCStackResult CreateProvisioningResource();
+
+//created only for in case of wifi
+#ifdef ESWIFI
+OCStackResult CreateNetworkResource();
+#endif
+
+void GetTargetNetworkInfoFromProvResource(char *, char *);
+void RegisterResourceEventCallBack(ResourceEventCallback);
+
+#endif
diff --git a/service/easy-setup/sdk/enrollee/common/src/easysetup.cpp b/service/easy-setup/sdk/enrollee/common/src/easysetup.cpp
new file mode 100755 (executable)
index 0000000..7560993
--- /dev/null
@@ -0,0 +1,180 @@
+//******************************************************************
+//
+// Copyright 2014 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 "easysetup.h"
+
+#include "logger.h"
+#include "resourceHandler.h"
+
+#define TAG "ES"
+
+int g_eventflag = 0;
+int g_cnt = 0;
+char *targetSsid;
+char *targetPass;
+
+EventCallback g_cbForProvisioning = NULL;
+EventCallback g_cbForOnboarding = NULL;
+
+void EventCallbackInOnboarding(ESResult event);
+void EventCallbackInProvisioning(ESResult event);
+void EventCallbackAfterProvisioning(ESResult event);
+
+void EventCallbackInOnboarding(ESResult event)
+{
+    if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
+    {
+        if (g_cbForOnboarding != NULL)
+        {
+            g_cbForOnboarding(event);
+        }
+    }
+}
+
+void EventCallbackInProvisioning(ESResult event)
+{
+    ESResult res = ES_OK;
+
+    if (event == ES_RECVTRIGGEROFPROVRES)
+    {
+        targetSsid = (char *) malloc(MAXSSIDLEN);
+        targetPass = (char *) malloc(MAXNETCREDLEN);
+
+        if(TerminateEasySetup() != OC_STACK_OK)
+        {
+            OC_LOG(ERROR, TAG, "Terminating stack failed");
+            return;
+        }
+
+        GetTargetNetworkInfoFromProvResource(targetSsid, targetPass);
+
+        res = ConnectToWiFiNetwork(targetSsid, targetPass, EventCallbackAfterProvisioning);
+
+        if (g_cbForProvisioning != NULL)
+        {
+            g_cbForProvisioning(res);
+        }
+    }
+}
+
+void EventCallbackAfterProvisioning(ESResult event)
+{
+    if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
+    {
+        if (g_cbForProvisioning != NULL)
+        {
+            g_cbForProvisioning(event);
+        }
+    }
+}
+
+ESResult FindNetworkForOnboarding(NetworkType networkType,
+                                           const char *ssid,
+                                           const char *passwd,
+                                           EventCallback cb)
+{
+    if (!ssid || !passwd)
+    {
+        return ES_ERROR;
+    }
+
+    if (networkType == ES_WIFI)
+    {
+        if (g_cbForOnboarding == NULL)
+        {
+            g_cbForOnboarding = cb;
+        }
+
+        if(ConnectToWiFiNetwork(ssid, passwd, EventCallbackInOnboarding) != ES_NETWORKCONNECTED)
+        {
+            OC_LOG(ERROR, TAG, "ConnectToWiFiNetwork Failed");
+            return ES_ERROR;
+        }
+        else{
+            OC_LOG(INFO, TAG, "ConnectToWiFiNetwork Success");
+            return ES_OK;
+        }
+    }
+    return ES_ERROR;
+}
+
+
+ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd,
+              EventCallback cb)
+{
+    if(FindNetworkForOnboarding(networkType, ssid, passwd, cb) != ES_OK)
+    {
+        OC_LOG(ERROR, TAG, "OnBoarding Failed");
+        return ES_ERROR;
+    }
+
+    // Initialize the OC Stack in Server mode
+    if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
+    {
+        OC_LOG(ERROR, TAG, "OCStack init error");
+        return ES_ERROR;
+    }
+    else
+    {
+        OC_LOG(DEBUG, TAG, "OCStack init success");
+        return ES_OK;
+    }
+}
+
+ESResult TerminateEasySetup()
+{
+    if(OCStop() != OC_STACK_OK)
+    {
+        OC_LOG(ERROR, TAG, "OCStack stop failed");
+        return ES_ERROR;
+    }
+    else
+    {
+        OC_LOG(ERROR, TAG, "OCStack stop success");
+        return ES_OK;
+    }
+}
+
+ESResult InitProvisioning(EventCallback cb)
+{
+    if (cb == NULL)
+    {
+        return ES_ERROR;
+    }
+    else
+    {
+        g_cbForProvisioning = cb;
+    }
+
+    if (CreateProvisioningResource() != OC_STACK_OK)
+    {
+        return ES_ERROR;
+    }
+
+    if (CreateNetworkResource() != OC_STACK_OK)
+    {
+        return ES_ERROR;
+    }
+
+    RegisterResourceEventCallBack(EventCallbackInProvisioning);
+
+    return ES_RESOURCECREATED;
+}
+
diff --git a/service/easy-setup/sdk/enrollee/common/src/resourceHandler.cpp b/service/easy-setup/sdk/enrollee/common/src/resourceHandler.cpp
new file mode 100755 (executable)
index 0000000..0f4305f
--- /dev/null
@@ -0,0 +1,341 @@
+//******************************************************************
+//
+// Copyright 2014 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 "ocpayload.h"
+
+#define TAG "ES_RH"
+
+ProvResource g_prov;
+NetResource g_net;
+
+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);
+
+int g_flag = 0;
+
+ResourceEventCallback g_cbForResEvent = NULL;
+
+void RegisterResourceEventCallBack(ResourceEventCallback cb)
+{
+    g_cbForResEvent = cb;
+}
+
+void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
+{
+    if (name != NULL && pass != NULL)
+    {
+        sprintf(name, "%s", g_prov.tnn);
+        sprintf(pass, "%s", g_prov.cd);
+    }
+}
+
+OCStackResult CreateProvisioningResource()
+{
+    g_prov.ps = 1; // need to provisioning
+    g_prov.tnt = ES_WIFI;
+    sprintf(g_prov.tnn, "Unknown");
+    sprintf(g_prov.cd, "Unknown");
+
+    OCStackResult res = OCCreateResource(&g_prov.handle, "oic.prov", OC_RSRVD_INTERFACE_DEFAULT,
+            OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb, NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
+
+    OC_LOG_V(INFO, TAG, "Created Prov resource with result: %s", getResult(res));
+
+    return res;
+}
+#ifdef ESWIFI
+OCStackResult CreateNetworkResource()
+{
+    NetworkInfo netInfo;
+
+    if (getCurrentNetworkInfo(ES_WIFI, &netInfo) != 0)
+    {
+        return OC_STACK_ERROR;
+    }
+
+    if (netInfo.type != ES_WIFI)
+    {
+        return OC_STACK_ERROR;
+    }
+
+    g_net.cnt = (int) netInfo.type;
+    g_net.ant[0] = (int) ES_WIFI;
+    sprintf(g_net.ipaddr, "%d.%d.%d.%d", netInfo.ipaddr[0], netInfo.ipaddr[1], netInfo.ipaddr[2],
+            netInfo.ipaddr[3]);
+    sprintf(g_net.cnn, "%s", netInfo.ssid);
+
+    OC_LOG_V(INFO, TAG, "SSID: %s", g_net.cnn);
+    OC_LOG_V(INFO, TAG, "IP Address: %s", g_net.ipaddr);
+
+    OCStackResult res = OCCreateResource(&g_net.handle, "oic.net", OC_RSRVD_INTERFACE_DEFAULT,
+            OC_RSRVD_ES_URI_NET, OCEntityHandlerCb,NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
+    OC_LOG_V(INFO, TAG, "Created Net resource with result: %s", getResult(res));
+
+    return res;
+}
+#endif
+OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
+{
+    OCEntityHandlerResult ehResult = OC_EH_ERROR;
+    if (!ehRequest)
+    {
+        OC_LOG(ERROR, TAG, "Request is Null");
+        return ehResult;
+    }
+    if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+    {
+        OC_LOG(ERROR, TAG, "Incoming payload not a representation");
+        return ehResult;
+    }
+
+    OCRepPayload *getResp = constructResponse(ehRequest);
+    if (!getResp)
+    {
+        OC_LOG(ERROR, 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;
+    if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+    {
+        OC_LOG(ERROR, TAG, "Incoming payload not a representation");
+        return ehResult;
+    }
+
+    OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
+    if (!input)
+    {
+        OC_LOG(ERROR, TAG, "Failed to parse");
+        return ehResult;
+    }
+
+    char* tnn;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn))
+    {
+        sprintf(g_prov.tnn, "%s", tnn);
+    }
+
+    char* cd;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
+    {
+        sprintf(g_prov.cd, "%s", cd);
+    }
+
+    g_flag = 1;
+
+    OCRepPayload *getResp = constructResponse(ehRequest);
+    if (!getResp)
+    {
+        OC_LOG(ERROR, TAG, "constructResponse failed");
+        return OC_EH_ERROR;
+    }
+
+    *payload = getResp;
+    ehResult = OC_EH_OK;
+
+    return ehResult;
+}
+
+OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
+{
+    OCEntityHandlerResult ehResult = OC_EH_ERROR;
+    if (!ehRequest)
+    {
+        OC_LOG(ERROR, TAG, "Request is Null");
+        return ehResult;
+    }
+    if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+    {
+        OC_LOG(ERROR, TAG, "Incoming payload not a representation");
+        return ehResult;
+    }
+
+    OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
+    if (!input)
+    {
+        OC_LOG(ERROR, TAG, "Failed to parse");
+        return ehResult;
+    }
+    char* tr;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TR, &tr))
+    {
+
+        // Triggering
+        ehResult = OC_EH_OK;
+    }
+
+    g_flag = 1;
+
+    return ehResult;
+}
+
+OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
+{
+    OCRepPayload* payload = OCRepPayloadCreate();
+    if (!payload)
+    {
+        OC_LOG(ERROR, TAG, "Failed to allocate Payload");
+        return NULL;
+    }
+
+    if (ehRequest->resource == g_prov.handle)
+    {
+        OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
+        OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS, g_prov.ps);
+        OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TNT, g_prov.tnt);
+        OCRepPayloadSetPropString(payload, OC_RSRVD_ES_TNN, g_prov.tnn);
+        OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CD, g_prov.cd);
+    }
+    else if (ehRequest->requestHandle == g_net.handle)
+    {
+
+        OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_NET);
+        OCRepPayloadSetPropInt(payload, "ant", g_net.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 };
+    OCRepPayload* payload = NULL;
+    if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
+    {
+        if (OC_REST_GET == entityHandlerRequest->method)
+        {
+            OC_LOG(INFO, TAG, "Received GET request");
+            ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
+        }
+        else if (OC_REST_PUT == entityHandlerRequest->method)
+        {
+            OC_LOG(INFO, TAG, "Received PUT request");
+
+            if (g_prov.handle != NULL && entityHandlerRequest->resource == g_prov.handle)
+            {
+                ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
+            }
+            else
+            {
+                ehRet = OC_EH_ERROR;
+            }
+        }
+        else if (OC_REST_POST == entityHandlerRequest->method)
+        {
+            // TODO: As of now, POST request will be not received.
+            OC_LOG(INFO, TAG, "Received OC_REST_POST from client");
+            //ehRet = ProcessPostRequest (entityHandlerRequest, payload, sizeof(payload) - 1);
+        }
+
+        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)
+            {
+                OC_LOG(ERROR, TAG, "Error sending response");
+                ehRet = OC_EH_ERROR;
+            }
+        }
+    }
+
+    if (g_flag == 1)
+    {
+        g_cbForResEvent(ES_RECVTRIGGEROFPROVRES);
+        g_flag = 0;
+    }
+
+    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/sdk/mediator/android/.gitignore b/service/easy-setup/sdk/mediator/android/.gitignore
new file mode 100644 (file)
index 0000000..6451fc5
--- /dev/null
@@ -0,0 +1,50 @@
+#built application files\r
+*.apk\r
+*.ap_\r
+\r
+# files for the dex VM\r
+*.dex\r
+\r
+# Java class files\r
+*.class\r
+\r
+# generated files\r
+bin/\r
+gen/\r
+\r
+# Local configuration file (sdk path, etc)\r
+local.properties\r
+\r
+# Proguard folder generated by Eclipse \r
+proguard/ \r
+\r
+# Windows thumbnail db\r
+Thumbs.db\r
+\r
+# OSX files\r
+.DS_Store\r
+\r
+# Eclipse project files\r
+.classpath\r
+.project\r
+\r
+#Android Studio & Gradle\r
+.gradle\r
+/local.properties\r
+/.idea/workspace.xml\r
+/.idea/libraries\r
+.DS_Store\r
+/build/*\r
+/base/build/*\r
+/base/obj/*\r
+/base/libs/*\r
+/sample/*\r
+\r
+#Some older projects\r
+/*/out\r
+/*/*/build\r
+/*/*/production\r
+*.iws\r
+*.ipr\r
+*~\r
+*.swp
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/build.gradle b/service/easy-setup/sdk/mediator/android/EasySetupCore/build.gradle
new file mode 100644 (file)
index 0000000..c1f2134
--- /dev/null
@@ -0,0 +1,40 @@
+apply plugin: 'com.android.library'\r
+// Top-level build file where you can add configuration options common to all sub-projects/modules.\r
+buildscript {\r
+    repositories {\r
+        jcenter()\r
+    }\r
+    dependencies {\r
+        classpath 'com.android.tools.build:gradle:1.2.3'\r
+    }\r
+}\r
+\r
+allprojects {\r
+    repositories {\r
+        jcenter()\r
+    }\r
+}\r
+\r
+android {\r
+    compileSdkVersion 21\r
+    buildToolsVersion '21.1.2'\r
+\r
+    defaultConfig {\r
+        minSdkVersion 21\r
+        targetSdkVersion 21\r
+    }\r
+\r
+    buildTypes {\r
+        release {\r
+            minifyEnabled false\r
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'\r
+        }\r
+    }\r
+    sourceSets {\r
+        main { java.srcDirs = ['src/main/java', 'src/main/java/common', 'src/main/java/interface'] }\r
+    }\r
+}\r
+\r
+dependencies {\r
+    compile project(':iotivity-armeabi-base-debug')\r
+}
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/easySetupCore.iml b/service/easy-setup/sdk/mediator/android/EasySetupCore/easySetupCore.iml
new file mode 100644 (file)
index 0000000..915035d
--- /dev/null
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id="EasySetupCore" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="android-gradle" name="Android-Gradle">
+      <configuration>
+        <option name="GRADLE_PROJECT_PATH" value=":" />
+      </configuration>
+    </facet>
+    <facet type="android" name="Android">
+      <configuration>
+        <option name="SELECTED_BUILD_VARIANT" value="debug" />
+        <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
+        <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
+        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+        <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+        <option name="LIBRARY_PROJECT" value="true" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+    <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java/common" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java/interface" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/EasySetupCore/iotivity-armeabi-base-debug/unspecified/jars" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+      <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
+    </content>
+    <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module" module-name="iotivity-armeabi-base-debug" exported="" />
+    <orderEntry type="library" exported="" name="iotivity-armeabi-base-debug-unspecified" level="project" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/settings.gradle b/service/easy-setup/sdk/mediator/android/EasySetupCore/settings.gradle
new file mode 100644 (file)
index 0000000..3f6e49d
--- /dev/null
@@ -0,0 +1 @@
+include ':iotivity-armeabi-base-debug'
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/androidTest.iml b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/androidTest.iml
new file mode 100644 (file)
index 0000000..a862cc8
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" name="classes" level="project" />
+    <orderEntry type="module" module-name="main" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceConfigTest.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceConfigTest.java
new file mode 100644 (file)
index 0000000..20b4b44
--- /dev/null
@@ -0,0 +1,78 @@
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+import android.test.AndroidTestCase;\r
+\r
+import junit.framework.Assert;\r
+\r
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;\r
+\r
+\r
+public class EasySetupServiceConfigTest extends AndroidTestCase {\r
+\r
+\r
+    public void testConstruction() {\r
+\r
+        EasySetupService service = EasySetupService.getInstance(getContext(), new EasySetupStatus() {\r
+            @Override\r
+            public void onFinished(EnrolleeDevice enrolledevice) {\r
+\r
+            }\r
+\r
+            @Override\r
+            public void onProgress(EnrolleeState state) {\r
+\r
+            }\r
+        });\r
+\r
+        assertTrue(service != null);\r
+\r
+\r
+    }\r
+\r
+    public void testFinish() {\r
+        EasySetupService service = EasySetupService.getInstance(getContext(), new EasySetupStatus() {\r
+            @Override\r
+            public void onFinished(EnrolleeDevice enrolledevice) {\r
+\r
+            }\r
+\r
+            @Override\r
+            public void onProgress(EnrolleeState state) {\r
+\r
+            }\r
+        });\r
+        service.finish();\r
+\r
+        // No runtime exception is thrown means test is successful\r
+        assertTrue(true);\r
+\r
+    }\r
+\r
+    public void testEnrolleeDeviceFacotryConstruction() {\r
+        EnrolleeDeviceFactory factory = EnrolleeDeviceFactory.newInstance(getContext());\r
+        assertTrue(factory != null);\r
+    }\r
+\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceTest.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceTest.java
new file mode 100644 (file)
index 0000000..1331f3a
--- /dev/null
@@ -0,0 +1,160 @@
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+package org.iotivity.service.easysetup.core;\r
+\r
+import android.net.wifi.WifiConfiguration;\r
+import android.test.AndroidTestCase;\r
+import android.util.Log;\r
+\r
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;\r
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceWiFiOnboarding;\r
+import org.iotivity.service.easysetup.impl.WiFiOnBoardingConfig;\r
+import org.iotivity.service.easysetup.impl.WiFiProvConfig;\r
+\r
+import java.io.IOException;\r
+\r
+public class EasySetupServiceTest extends AndroidTestCase {\r
+\r
+\r
+    public void testStartSetupWithWiFiOnboarding() {\r
+\r
+        EasySetupService mService;\r
+        EnrolleeDevice mDevice;\r
+        EnrolleeDeviceFactory mFactory;\r
+\r
+        final Object lock = new Object();\r
+\r
+\r
+        /* Create Easy Setup service */\r
+        mService = EasySetupService.getInstance(getContext(), new EasySetupStatus() {\r
+            @Override\r
+            public void onFinished(EnrolleeDevice enrolledevice) {\r
+\r
+                //countDownLatch.countDown();\r
+                Utility.toNotify(lock);\r
+\r
+                if (enrolledevice.isSetupSuccessful()) {\r
+\r
+                    if (enrolledevice.mOnBoardingConfig.getConnType() == WiFiOnBoardingConfig.ConnType.WiFi) {\r
+                        IpOnBoardingConnection conn = (IpOnBoardingConnection) enrolledevice.getConnection();\r
+                        String ip = conn.getIp();\r
+                        if (ip == null || ip.isEmpty()) {\r
+                            assertTrue(false);\r
+                            return;\r
+                        }\r
+                        String mac = conn.getHardwareAddress();\r
+                        if (mac == null || mac.isEmpty()) {\r
+                            assertTrue(false);\r
+                            return;\r
+                        }\r
+                        // Device configured successfully\r
+                        assertTrue(true);\r
+                    }\r
+\r
+                } else {\r
+                    assertTrue(false);\r
+                }\r
+            }\r
+\r
+            @Override\r
+            public void onProgress(EnrolleeState state) {\r
+                // TODO\r
+            }\r
+        });\r
+\r
+\r
+        /* Create On boarding configuration */\r
+        WiFiOnBoardingConfig mWiFiOnBoardingConfig = new WiFiOnBoardingConfig();\r
+        mWiFiOnBoardingConfig.setSSId("EasySetup123");\r
+        mWiFiOnBoardingConfig.setSharedKey("EasySetup123");\r
+        mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);\r
+        mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);\r
+\r
+        /* Create provisioning configuration */\r
+        WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222");\r
+\r
+        /* Create enrolling device factory instance */\r
+        mFactory = EnrolleeDeviceFactory.newInstance(getContext());\r
+\r
+        /* Check if the factory created successfully */\r
+        assertTrue(mFactory != null);\r
+\r
+        /* Create enrolling device */\r
+        mDevice = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);\r
+\r
+        /* Check if the the device is created successfully*/\r
+        assertTrue(mDevice != null);\r
+\r
+        /* Check if the the correct device is created as per the given configuration*/\r
+        assertTrue((mDevice instanceof EnrolleeDeviceWiFiOnboarding));\r
+\r
+\r
+        try {\r
+            mService.startSetup(mDevice);\r
+            // If no exception is thrown means setup started successfully.\r
+            assertTrue(true);\r
+\r
+        } catch (IOException e) {\r
+            assertTrue(false);\r
+        }\r
+\r
+        try {\r
+\r
+            Utility.toWait(lock);\r
+\r
+            Log.i("EasySetupTest", "Lock is released");\r
+\r
+            if(! mDevice.isSetupSuccessful()) {\r
+                assertTrue(false);\r
+                return;\r
+            }\r
+\r
+            IpOnBoardingConnection conn = (IpOnBoardingConnection) mDevice.getConnection();\r
+            if (conn == null) {\r
+                assertTrue(false);\r
+                return;\r
+            }\r
+\r
+            String ip = conn.getIp();\r
+            if (ip == null || ip.isEmpty()) {\r
+                assertTrue(false);\r
+                return;\r
+            }\r
+\r
+            String mac = conn.getHardwareAddress();\r
+            if (mac == null || mac.isEmpty()) {\r
+                assertTrue(false);\r
+                return;\r
+            }\r
+\r
+            Log.i("EasySetupTest", "Ip" + conn.getIp());\r
+            Log.i("EasySetupTest", "MAC" + conn.getHardwareAddress());\r
+\r
+            // Device configured successfully\r
+            assertTrue(true);\r
+\r
+        } catch (Exception e) {\r
+            e.printStackTrace();\r
+            assertTrue(false);\r
+        }\r
+\r
+    }\r
+\r
+}
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EnrolleeDeviceFactoryTest.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EnrolleeDeviceFactoryTest.java
new file mode 100644 (file)
index 0000000..1c803d1
--- /dev/null
@@ -0,0 +1,75 @@
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+import android.net.wifi.WifiConfiguration;\r
+import android.test.AndroidTestCase;\r
+\r
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;\r
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceWiFiOnboarding;\r
+import org.iotivity.service.easysetup.impl.WiFiOnBoardingConfig;\r
+import org.iotivity.service.easysetup.impl.WiFiProvConfig;\r
+\r
+public class EnrolleeDeviceFactoryTest extends AndroidTestCase {\r
+\r
+    EnrolleeDeviceFactory mFactory;\r
+\r
+    @Override\r
+    protected void setUp() throws Exception {\r
+        super.setUp();\r
+        mFactory = EnrolleeDeviceFactory.newInstance(getContext());\r
+        assertTrue(mFactory != null);\r
+\r
+    }\r
+\r
+    @Override\r
+    protected void tearDown() throws Exception {\r
+        super.tearDown();\r
+        mFactory = null;\r
+    }\r
+\r
+\r
+    public void testNewEnrolleeDevice_with_WiFiOnboarding() {\r
+\r
+        /* Create On boarding configuration */\r
+        WiFiOnBoardingConfig mWiFiOnBoardingConfig = new WiFiOnBoardingConfig();\r
+        mWiFiOnBoardingConfig.setSSId("EasySetup123");\r
+        mWiFiOnBoardingConfig.setSharedKey("EasySetup123");\r
+        mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);\r
+        mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);\r
+\r
+        /* Create provisioning configuration */\r
+        WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222");\r
+\r
+        /* Create enrolling device */\r
+        EnrolleeDevice device = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);\r
+\r
+        /* Check if the the device is created */\r
+        assertTrue(device != null);\r
+\r
+        /* Check if the the correct device is created as per the given configuration*/\r
+        assertTrue((device instanceof EnrolleeDeviceWiFiOnboarding));\r
+\r
+    }\r
+\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/Utility.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/Utility.java
new file mode 100644 (file)
index 0000000..0044929
--- /dev/null
@@ -0,0 +1,42 @@
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+\r
+public class Utility {\r
+\r
+    public static void toNotify(Object toLock) {\r
+        synchronized (toLock) {\r
+            toLock.notify();\r
+        }\r
+    }\r
+\r
+    public static void toWait(Object toLock) {\r
+        synchronized (toLock) {\r
+            try {\r
+                toLock.wait(45000);\r
+            } catch (InterruptedException e) {\r
+                e.printStackTrace();\r
+            }\r
+        }\r
+    }\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/AndroidManifest.xml b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..64487cd
--- /dev/null
@@ -0,0 +1,17 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.service.easysetup.mediator"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="8"
+        android:targetSdkVersion="21" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+    </application>
+
+</manifest>
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java
new file mode 100644 (file)
index 0000000..dba4cc0
--- /dev/null
@@ -0,0 +1,186 @@
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+import android.content.Context;\r
+import android.util.Log;\r
+\r
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;\r
+import org.iotivity.service.easysetup.mediator.EasySetupManager;\r
+import org.iotivity.service.easysetup.mediator.ProvisionEnrollee;\r
+\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+\r
+/**\r
+ * This is facade class, a single point of contact for Application.\r
+ * It contains set of APIs to do easy setup of the enrolling device.\r
+ * ON-BOARDING - This is a step to establish connectivity between the device & Mediator device.\r
+ * PROVISION   - This is a step where the netowork's detail & credentials are given to the\r
+ * enrolling device.\r
+ */\r
+public class EasySetupService {\r
+\r
+    public static final String TAG = EasySetupService.class.getName();\r
+\r
+    private static EasySetupService sInstance;\r
+\r
+    private final EasySetupStatus mCallback;\r
+\r
+    private ArrayList<EnrolleeDevice> mEnrolleeDeviceList;\r
+\r
+    private final ProvisioningCallback mProvisioningCallback;\r
+\r
+    private static Context mContext;\r
+\r
+    public EnrolleeDeviceFactory mDeviceFactory;\r
+\r
+    ProvisionEnrollee mProvisionEnrolleeInstance;\r
+\r
+    private EasySetupService(EasySetupStatus callback) {\r
+        mCallback = callback;\r
+        mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);\r
+        mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();\r
+        mContext = null;\r
+        mDeviceFactory = null;\r
+    }\r
+\r
+    /**\r
+     * Gives a singleton instance of Easy setup service and initialize the service\r
+     *\r
+     * @param callback Application needs to provide this callback to receive the status of easy\r
+     *                 setup process.\r
+     */\r
+\r
+    public synchronized static EasySetupService getInstance(Context context, EasySetupStatus\r
+            callback) {\r
+        if (sInstance == null) {\r
+            sInstance = new EasySetupService(callback);\r
+            mContext = context;\r
+        }\r
+        return sInstance;\r
+    }\r
+\r
+    /**\r
+     * Reset the Easy setup Service\r
+     */\r
+\r
+    public void finish() {\r
+\r
+        //Native Api call to reset OIC stack\r
+        if (mProvisionEnrolleeInstance != null) {\r
+            mProvisionEnrolleeInstance.stopEnrolleeProvisioning(0);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Starts Easy setup process for the enrolling device.\r
+     *\r
+     * @param enrolledevice Device to be enrolled in network\r
+     * @throws IOException Throws exception in case of any connection error.\r
+     */\r
+\r
+    public synchronized void startSetup(final EnrolleeDevice enrolledevice) throws IOException {\r
+\r
+        mEnrolleeDeviceList.add(enrolledevice);\r
+\r
+\r
+        // Starts the provisioning directly if the device is already on boarded on the network.\r
+        if (enrolledevice.onBoarded()) {\r
+            enrolledevice.startProvisioning(mProvisioningCallback);\r
+            return;\r
+        }\r
+\r
+        enrolledevice.startOnBoarding(new OnBoardingCallback() {\r
+\r
+            @Override\r
+            public void onFinished(OnBoardingConnection connection) {\r
+                if (connection.isConnected()) {\r
+                    Log.i(TAG, "On boarding is successful ");\r
+                    // Start provisioning here\r
+                    enrolledevice.setConnection(connection);\r
+                    enrolledevice.startProvisioning(mProvisioningCallback);\r
+                } else {\r
+                    enrolledevice.mState = EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;\r
+                    mProvisioningCallback.onFinished(enrolledevice);\r
+                }\r
+\r
+            }\r
+\r
+        });\r
+\r
+    }\r
+\r
+    /**\r
+     * Stops on-going Easy setup process for enrolling device.\r
+     *\r
+     * @param enrolleedevice Device to be enrolled in network\r
+     */\r
+    public synchronized void stopSetup(EnrolleeDevice enrolleedevice) {\r
+        if (enrolleedevice.mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {\r
+            if (mEnrolleeDeviceList.contains(enrolleedevice)) {\r
+                Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");\r
+                enrolleedevice.stopOnBoardingProcess();\r
+                mEnrolleeDeviceList.remove(enrolleedevice);\r
+            }\r
+        } else if (enrolleedevice.mState == EnrolleeState.DEVICE_PROVISIONING_STATE) {\r
+            if (mEnrolleeDeviceList.contains(enrolleedevice)) {\r
+                Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");\r
+                enrolleedevice.stopOnBoardingProcess();\r
+\r
+                Log.i(TAG, "stopEnrolleeProvisioning for enrolleedevice");\r
+                //Native Api call to stop on-going enrolling process for the enrolling device\r
+                EasySetupManager.getInstance().stopEnrolleeProvisioning(enrolleedevice\r
+                        .mOnBoardingConfig.getConnType().getValue());\r
+                mEnrolleeDeviceList.remove(enrolleedevice);\r
+            }\r
+        }\r
+    }\r
+\r
+    public synchronized void getEnrolleeDevice(OnBoardingConfig connType) {\r
+        mDeviceFactory = EnrolleeDeviceFactory.newInstance(mContext);\r
+    }\r
+\r
+    class ProvisioningCallbackImpl extends ProvisioningCallback {\r
+\r
+        private final EasySetupStatus mCallback;\r
+\r
+        ProvisioningCallbackImpl(EasySetupStatus callback) {\r
+            mCallback = callback;\r
+        }\r
+\r
+        @Override\r
+        public void onFinished(EnrolleeDevice enrolledevice) {\r
+            synchronized (EasySetupService.this) {\r
+                if (mEnrolleeDeviceList.contains(enrolledevice)) {\r
+                    Log.i(TAG, "onFinished() is received " + enrolledevice.isSetupSuccessful());\r
+                    mCallback.onFinished(enrolledevice);\r
+                    mEnrolleeDeviceList.remove(enrolledevice);\r
+                }\r
+            }\r
+        }\r
+\r
+    }\r
+\r
+\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupStatus.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupStatus.java
new file mode 100644 (file)
index 0000000..4ba7fba
--- /dev/null
@@ -0,0 +1,50 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 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>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.core;
+
+/**
+ * This interface facilitates Application to get progress & result of Easy setup
+ * process Easy setup process.
+ */
+public interface EasySetupStatus {
+
+    /**
+     * This method is called back when easy setup process is finished. Easy
+     * setup process status can read from the APIs given in Enrollee class.This
+     * method is called on worker thread, UI operations to be executed on main /
+     * Ui Thread.
+     *
+     * @param enrolledevice Device to be enrolled in network through Easy setup process
+     */
+    public void onFinished(EnrolleeDevice enrolledevice);
+
+    /**
+     * This method is called back to give intermediate progress on the easy
+     * setup process This method is called on worker thread, UI operations to be
+     * executed on main / Ui Thread.
+     *
+     * @param state Gives state of the device changed during easy setup process
+     */
+    public void onProgress(EnrolleeState state);
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeDevice.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeDevice.java
new file mode 100644 (file)
index 0000000..ec3bd1b
--- /dev/null
@@ -0,0 +1,161 @@
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+/**\r
+ * This is an abstract class represents the device being provisioned into the network. The\r
+ * device being enrolled or provisioned into the network is called Enrollee.\r
+ * Application has to extend this class and provide implementation of abstract methods according\r
+ * to the ON-BOARDING & PROVISION connectivity i.e. WiFi etc.\r
+ */\r
+\r
+public abstract class EnrolleeDevice {\r
+\r
+    protected EnrolleeState mState;\r
+    private EnrolleeSetupError mError;\r
+\r
+    protected OnBoardingConnection mConnection;\r
+    protected final ProvisioningConfig mProvConfig;\r
+    protected final OnBoardingConfig mOnBoardingConfig;\r
+\r
+    protected OnBoardingCallback mOnBoardingCallback;\r
+    protected ProvisioningCallback mProvisioningCallback;\r
+\r
+    /**\r
+     * @param onBoardingConfig Contains details about the connectivity to be established between\r
+     *                         the Enrollee device & Mediator device in order to perform\r
+     *                         on-boarding\r
+     * @param provConfig       Contains details about the network to which Enrollee device is\r
+     *                         going to connect.\r
+     */\r
+    protected EnrolleeDevice(OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {\r
+        mProvConfig = provConfig;\r
+        mOnBoardingConfig = onBoardingConfig;\r
+    }\r
+\r
+    /**\r
+     * Application has to implement it according to the on boarding connectivity the device is\r
+     * having.\r
+     * This method will be called back during the easy setup process.\r
+     */\r
+    protected abstract void startOnBoardingProcess();\r
+\r
+    /**\r
+     * This method is called back during the easy setup process if Application cancels the setup.\r
+     * Easy setup service checks the state of device and calls this function accordingly.\r
+     * Application has to provide implementation for this method to cancel the on boarding step.\r
+     */\r
+    protected abstract void stopOnBoardingProcess();\r
+\r
+    /**\r
+     * Application has to implement it according to the type of the network device is going to\r
+     * connect or provisioned.\r
+     * This method will be called back once on-boarding of the device is successful.\r
+     *\r
+     * @param conn Contains detail about the network established between the Enrollee device &\r
+     *             Mediator device. Its implementation vary according to the connectivity type.\r
+     */\r
+    protected abstract void startProvisioningProcess(OnBoardingConnection conn);\r
+\r
+    /**\r
+     * Once on boarding is successful concrete Enrollee class would call this method and set the\r
+     * Connection.\r
+     *\r
+     * @param conn Connectivity between Enrollee device & Mediator device.\r
+     */\r
+    public void setConnection(OnBoardingConnection conn) {\r
+        mConnection = conn;\r
+    }\r
+\r
+    public OnBoardingConnection getConnection() {\r
+        return mConnection;\r
+    }\r
+\r
+\r
+    /**\r
+     * This method is called back by Easy setup service if on boarding needs to be done.\r
+     *\r
+     * @param onBoardingCallback This is called back once the on boarding is completed.\r
+     */\r
+    void startOnBoarding(OnBoardingCallback onBoardingCallback) {\r
+        mOnBoardingCallback = onBoardingCallback;\r
+        startOnBoardingProcess();\r
+    }\r
+\r
+    /**\r
+     * This method is called back by Easy setup service once on boarding is successful\r
+     *\r
+     * @param provisioningCallback This is called back once the provisioning process is completed\r
+     */\r
+    void startProvisioning(ProvisioningCallback provisioningCallback) {\r
+        mProvisioningCallback = provisioningCallback;\r
+        startProvisioningProcess(mConnection);\r
+    }\r
+\r
+    /**\r
+     * This method is used to check easy setup status\r
+     *\r
+     * @return true if successful or false\r
+     */\r
+\r
+    public boolean isSetupSuccessful() {\r
+        return (mState == EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE) ? true : false;\r
+    }\r
+\r
+    /**\r
+     * sets error occured during easy setup process\r
+     */\r
+    public void setError(EnrolleeSetupError error) {\r
+        mError = error;\r
+    }\r
+\r
+    /**\r
+     * Returns error occured during easy setup process\r
+     *\r
+     * @return True EnrolleeSetupError object\r
+     */\r
+    public EnrolleeSetupError getError() {\r
+        return mError;\r
+    }\r
+\r
+    /**\r
+     * Gives the state of the device being enrolled during the easy setup process.\r
+     *\r
+     * @return Returns EnrolleeState object\r
+     */\r
+    public EnrolleeState getState() {\r
+        return mState;\r
+    }\r
+\r
+    /**\r
+     * This method is used to know if the device is on boarded or not\r
+     *\r
+     * @return True if on-boarded successfully or False\r
+     */\r
+\r
+    public boolean onBoarded() {\r
+        return (mState == EnrolleeState.DEVICE_PROVISIONING_STATE) ? true : false;\r
+    }\r
+\r
+\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeSetupError.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeSetupError.java
new file mode 100644 (file)
index 0000000..4c38cb1
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 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>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.core;
+
+/**
+ * This class defines constants for Errors comes during Easy setup process
+ */
+public enum EnrolleeSetupError {
+    /**
+     * Device setup successful
+     */
+    DEVICE_SETUP_SUCCESSFUL,
+    /**
+     * Device setup failed
+     */
+    DEVICE_SETUP_FAILED,
+}
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeState.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeState.java
new file mode 100644 (file)
index 0000000..6b91254
--- /dev/null
@@ -0,0 +1,69 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 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>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.core;
+
+/**
+ * It defines various states of the Enrollee device during easy setup process
+ */
+
+public enum EnrolleeState {
+
+    /**
+     * Default state of the device
+     */
+    DEVICE_INIT_STATE,
+
+    /**
+     * Device will move to this state after successful on-boarding of the device
+     */
+    DEVICE_ON_BOARDING_STATE,
+
+    /**
+     * Device will move to this state once the on boarding is done
+     */
+    DEVICE_PROVISIONING_STATE,
+
+    /**
+     * Easy setup process is successful.
+     */
+    DEVICE_PROVISIONING_SUCCESS_STATE,
+
+    /**
+     * Device is not able to provisioned.
+     * Easy setup process failed to enrolled the device in the network
+     */
+    DEVICE_PROVISIONING_FAILED_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
+     */
+    DEVICE_OWNERSHIP_TRANSFER_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
+     */
+    DEVICE_FACTORY_RESET_STATE,
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IpOnBoardingConnection.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IpOnBoardingConnection.java
new file mode 100644 (file)
index 0000000..399d2f3
--- /dev/null
@@ -0,0 +1,75 @@
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+public class IpOnBoardingConnection implements OnBoardingConnection {\r
+\r
+    private boolean mIsConnected;\r
+    private String mIp;\r
+    private String mHardwareAddress;\r
+    private String mDeviceName;\r
+\r
+    public void setHardwareAddress(String address) {\r
+        mHardwareAddress = address;\r
+    }\r
+\r
+    public String getHardwareAddress() {\r
+        return mHardwareAddress;\r
+    }\r
+\r
+    public void setDeviceName(String name) {\r
+        mDeviceName = name;\r
+    }\r
+\r
+    public String getDeviceName() {\r
+        return mDeviceName;\r
+    }\r
+\r
+    public void setConnectivity(boolean connected) {\r
+        mIsConnected = connected;\r
+    }\r
+\r
+    public void setIp(String ip) {\r
+        mIp = ip;\r
+    }\r
+\r
+    public String getIp() {\r
+        return mIp;\r
+    }\r
+\r
+    @Override\r
+    public String getDesc() {\r
+        return "Description";\r
+    }\r
+\r
+    @Override\r
+    public boolean isConnected() {\r
+        return mIsConnected;\r
+    }\r
+\r
+    @Override\r
+    public Object getConnection() {\r
+        return this;\r
+    }\r
+\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingCallback.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingCallback.java
new file mode 100644 (file)
index 0000000..5712722
--- /dev/null
@@ -0,0 +1,27 @@
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+public abstract class OnBoardingCallback {\r
+    public abstract void onFinished(OnBoardingConnection connection);\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConfig.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConfig.java
new file mode 100644 (file)
index 0000000..6da4178
--- /dev/null
@@ -0,0 +1,69 @@
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+import org.iotivity.base.OcConnectivityType;\r
+\r
+/**\r
+ * It contains configuration details about the connectivity type between the Enrollee device &\r
+ * Mediator device in order to perform on-boarding.\r
+ */\r
+\r
+public interface OnBoardingConfig {\r
+\r
+    /**\r
+     * It provides constants for connectivity types used for on-boarding Enrollee device\r
+     */\r
+    public static enum ConnType {\r
+        // Note : Enum Ids should matched with Native Ids\r
+        WiFi(OcConnectivityType.CT_DEFAULT.getValue()),\r
+        BLE(OcConnectivityType.CT_ADAPTER_GATT_BTLE.getValue());\r
+\r
+        private int mConnType;\r
+\r
+        ConnType(int connType) {\r
+            mConnType = connType;\r
+        }\r
+\r
+        public int getValue() {\r
+            return mConnType;\r
+        }\r
+\r
+    }\r
+\r
+    /**\r
+     * Gives configuration object specific to the on-boarding connectivity of the enrolling device.\r
+     *\r
+     * @return instance object of configuration according to connectivity type\r
+     */\r
+    public Object getConfig();\r
+\r
+    /**\r
+     * Gives connectivity type of on-boarding device\r
+     *\r
+     * @return on-boarding connectivity type\r
+     */\r
+    public ConnType getConnType();\r
+\r
+\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConnection.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConnection.java
new file mode 100644 (file)
index 0000000..80c2fa0
--- /dev/null
@@ -0,0 +1,35 @@
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+package org.iotivity.service.easysetup.core;\r
+\r
+public interface OnBoardingConnection {\r
+\r
+\r
+    // Get the implementation of the Connection\r
+    public Object getConnection();\r
+\r
+    // Any general description on the connectivity.\r
+    public String getDesc();\r
+\r
+    public boolean isConnected();\r
+\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningCallback.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningCallback.java
new file mode 100644 (file)
index 0000000..887530a
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 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>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.core;
+
+public abstract class ProvisioningCallback {
+    public abstract void onFinished(EnrolleeDevice enrolledevice);
+}
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningConfig.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningConfig.java
new file mode 100644 (file)
index 0000000..67fe38e
--- /dev/null
@@ -0,0 +1,54 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 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>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.core;
+/**
+ * It contains configuration details about the the target network where Enrollee device is
+ * going to be enrolled.
+ */
+public interface ProvisioningConfig {
+
+    /**
+     * It provides constants for connectivity types of target network
+     */
+    public static enum ConnType {
+        WiFi,
+        BT
+    }
+
+    /**
+     * Gives the instance of the configuration object created according to the connectivity
+     * type of target network.
+     *
+     * @return instance object of configuration according to connectivity type of target network
+     */
+    Object getConfig();
+
+
+    /**
+     * Gives connectivity type of target network
+     *
+     * @return Connectivity type of target network
+     */
+    ConnType getConnType();
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceFactory.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceFactory.java
new file mode 100644 (file)
index 0000000..905ecaf
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+ * ***************************************************************
+ * <p/>
+ * Copyright 2015 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/>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.impl;
+
+import android.content.Context;
+
+import org.iotivity.service.easysetup.core.EnrolleeDevice;
+import org.iotivity.service.easysetup.core.OnBoardingConfig;
+import org.iotivity.service.easysetup.core.ProvisioningConfig;
+
+/**
+ * This a factory class provides the native implementation of the various Enrollee devices.
+ * Application can make use of Enrollee factory if it does not want to create its own Enrollee devices.
+ */
+public class EnrolleeDeviceFactory {
+
+    Context mContext;
+
+    /**
+     * This method create & returns instance of EnrolleeDeviceFactory
+     *
+     * @param context This is Android Application context
+     */
+    public static EnrolleeDeviceFactory newInstance(Context context) {
+        return new EnrolleeDeviceFactory(context);
+    }
+
+    private EnrolleeDeviceFactory(Context context) {
+        mContext = context;
+    }
+
+    /**
+     * This method create & returns instance of Enrollee device of supported configuration
+     *
+     * @param onboardingConfig Contains details about the connectivity to be established between the Enrollee device & Mediator device in order to perform on-boarding
+     * @param provConfig       Contains details about the network to which Enrollee device is going to connect.
+     * @return Instance of the Enrollee device created natively.
+     */
+
+    public EnrolleeDevice newEnrolleeDevice(OnBoardingConfig onboardingConfig, ProvisioningConfig provConfig) {
+
+        if (onboardingConfig.getConnType() != OnBoardingConfig.ConnType.WiFi) {
+            throw new IllegalArgumentException("OnBoarding configuration is not supported");
+        }
+
+        EnrolleeDevice enrolleeDevice;
+        enrolleeDevice = new EnrolleeDeviceWiFiOnboarding(mContext, onboardingConfig, provConfig);
+
+        return enrolleeDevice;
+    }
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java
new file mode 100644 (file)
index 0000000..1af6d45
--- /dev/null
@@ -0,0 +1,176 @@
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup.impl;\r
+\r
+import java.util.Timer;\r
+import java.util.TimerTask;\r
+\r
+import org.iotivity.service.easysetup.core.OnBoardingConnection;\r
+import org.iotivity.service.easysetup.core.EnrolleeDevice;\r
+import org.iotivity.service.easysetup.core.EnrolleeState;\r
+import org.iotivity.service.easysetup.core.IpOnBoardingConnection;\r
+import org.iotivity.service.easysetup.core.OnBoardingConfig;\r
+import org.iotivity.service.easysetup.core.ProvisioningConfig;\r
+import org.iotivity.service.easysetup.mediator.EasySetupManager;\r
+import org.iotivity.service.easysetup.mediator.EnrolleeInfo;\r
+import org.iotivity.service.easysetup.mediator.IOnBoardingStatus;\r
+import org.iotivity.service.easysetup.mediator.IProvisioningListener;\r
+import org.iotivity.service.easysetup.mediator.ProvisionEnrollee;\r
+import org.iotivity.service.easysetup.mediator.ip.WiFiSoftAPManager;\r
+\r
+import android.content.Context;\r
+import android.net.wifi.WifiConfiguration;\r
+import android.util.Log;\r
+\r
+/**\r
+ * This is a ready to use class for Enrollee device having Soft AP as on-boarding connectivity.\r
+ */\r
+public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {\r
+\r
+    public static final String TAG = EnrolleeDeviceWiFiOnboarding.class.getName();\r
+\r
+    final Context mContext;\r
+    final WiFiSoftAPManager mWifiSoftAPManager;\r
+    EnrolleeInfo connectedDevice;\r
+    private EasySetupManager easySetupManagerNativeInstance;\r
+    ProvisionEnrollee provisionEnrolleInstance;\r
+    Timer myTimer;\r
+\r
+    IOnBoardingStatus deviceScanListener = new IOnBoardingStatus() {\r
+\r
+        @Override\r
+        public void deviceOnBoardingStatus(EnrolleeInfo enrolleStatus) {\r
+            myTimer.cancel();\r
+            Log.d("ESSoftAPOnBoarding", "Entered");\r
+            if (mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {\r
+                Log.d("ESSoftAPOnBoarding", "Device in OnBoarding State");\r
+                if (enrolleStatus != null && enrolleStatus.getIpAddr() != null) {\r
+                    String finalResult = "Easy Connect : ";\r
+\r
+                    if (enrolleStatus.isReachable()) {\r
+                        finalResult = "Device OnBoarded" + "["\r
+                                + enrolleStatus.getIpAddr() + "]";\r
+\r
+                        connectedDevice = enrolleStatus;\r
+                        IpOnBoardingConnection conn = new IpOnBoardingConnection();\r
+\r
+                        conn.setConnectivity(true);\r
+                        conn.setIp(connectedDevice.getIpAddr());\r
+                        conn.setHardwareAddress(enrolleStatus.getHWAddr());\r
+                        conn.setDeviceName(enrolleStatus.getDevice());\r
+\r
+                        Log.d("ESSoftAPOnBoarding", "Entered" + finalResult);\r
+                        mOnBoardingCallback.onFinished(conn);\r
+                        return;\r
+\r
+                    }\r
+                }\r
+\r
+                IpOnBoardingConnection conn = new IpOnBoardingConnection();\r
+                conn.setConnectivity(false);\r
+                mOnBoardingCallback.onFinished(conn);\r
+            } else {\r
+                Log.e("ESSoftAPOnBoarding", "Device NOT in OnBoarding State. Ignoring the event");\r
+            }\r
+        }\r
+    };\r
+\r
+\r
+    protected EnrolleeDeviceWiFiOnboarding(Context context, OnBoardingConfig onBoardingConfig,\r
+                                           ProvisioningConfig provConfig) {\r
+        super(onBoardingConfig, provConfig);\r
+        mContext = context;\r
+        mWifiSoftAPManager = new WiFiSoftAPManager(mContext);\r
+    }\r
+\r
+    @Override\r
+    protected void startOnBoardingProcess() {\r
+        Log.i(TAG, "Starting on boarding process");\r
+\r
+        //1. Create Soft AP\r
+        boolean status = mWifiSoftAPManager.setWifiApEnabled((WifiConfiguration)\r
+                mOnBoardingConfig.getConfig(), true);\r
+\r
+        mState = EnrolleeState.DEVICE_ON_BOARDING_STATE;\r
+\r
+        Log.i(TAG, "Soft AP is created with status " + status);\r
+\r
+        myTimer = new Timer();\r
+        myTimer.schedule(new TimerTask() {\r
+            @Override\r
+            public void run() {\r
+                // Below function to be called after 5 seconds\r
+                mWifiSoftAPManager.getClientList(deviceScanListener, 300);\r
+            }\r
+\r
+        }, 0, 5000);\r
+    }\r
+\r
+    protected void stopOnBoardingProcess() {\r
+        Log.i(TAG, "Stopping on boarding process");\r
+        myTimer.cancel();\r
+        boolean status = mWifiSoftAPManager.setWifiApEnabled(null, false);\r
+        Log.i(TAG, "Soft AP is disabled with status " + status);\r
+    }\r
+\r
+    @Override\r
+    protected void startProvisioningProcess(OnBoardingConnection conn) {\r
+        mState = EnrolleeState.DEVICE_PROVISIONING_STATE;\r
+\r
+        try {\r
+            Log.i(TAG, "waiting for 15 seconds to start provisioning");\r
+            Thread.sleep(15000);//Sleep for allowing thin device to start the services\r
+        } catch (InterruptedException e) {\r
+            e.printStackTrace();\r
+        }\r
+\r
+\r
+        if (mProvConfig.getConnType() == ProvisioningConfig.ConnType.WiFi) {\r
+\r
+            provisionEnrolleInstance = new ProvisionEnrollee(mContext);\r
+\r
+            provisionEnrolleInstance.registerProvisioningHandler(new IProvisioningListener() {\r
+                @Override\r
+                public void onFinishProvisioning(int statuscode) {\r
+\r
+                    Log.i(TAG, "Provisioning is finished with status code " + statuscode);\r
+                    mState = (statuscode == 0) ? EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE\r
+                            : EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;\r
+                    stopOnBoardingProcess();\r
+                    mProvisioningCallback.onFinished(EnrolleeDeviceWiFiOnboarding.this);\r
+                }\r
+            });\r
+\r
+            IpOnBoardingConnection connection = (IpOnBoardingConnection) conn;\r
+            WiFiProvConfig wifiProvConfig = (WiFiProvConfig) mProvConfig;\r
+\r
+            easySetupManagerNativeInstance = EasySetupManager.getInstance();\r
+            easySetupManagerNativeInstance.setApplicationContext(mContext);\r
+            easySetupManagerNativeInstance.initEasySetup();\r
+\r
+            // Native Api call to start provisioning of the enrolling device\r
+            easySetupManagerNativeInstance.provisionEnrollee(connection.getIp(), wifiProvConfig\r
+                    .getSsId(), wifiProvConfig.getPassword(), 1);\r
+        }\r
+    }\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiOnBoardingConfig.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiOnBoardingConfig.java
new file mode 100644 (file)
index 0000000..adfc0d9
--- /dev/null
@@ -0,0 +1,65 @@
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup.impl;\r
+\r
+import org.iotivity.service.easysetup.core.IpOnBoardingConnection;\r
+import org.iotivity.service.easysetup.core.OnBoardingConfig;\r
+\r
+import android.net.wifi.WifiConfiguration;\r
+\r
+/**\r
+ * This class contains on boarding configuration information for Soft AP on boarding connectivity.\r
+ * It implements OnBoardingConfig interface & provide implementation for WiFi Soft AP connectivity.\r
+ */\r
+\r
+public class WiFiOnBoardingConfig implements OnBoardingConfig {\r
+\r
+    private final WifiConfiguration config = new WifiConfiguration();\r
+    private final ConnType mConnType = OnBoardingConfig.ConnType.WiFi;\r
+\r
+    @Override\r
+    public Object getConfig() {\r
+        return config;\r
+    }\r
+\r
+    public void setSSId(String ssid) {\r
+        config.SSID = ssid;\r
+    }\r
+\r
+    public void setSharedKey(String sharedKey) {\r
+        config.preSharedKey = sharedKey;\r
+    }\r
+\r
+    public void setAuthAlgo(int aurthAlgo) {\r
+        config.allowedAuthAlgorithms.set(aurthAlgo);\r
+    }\r
+\r
+    public void setKms(int kms) {\r
+        config.allowedKeyManagement.set(kms);\r
+    }\r
+\r
+    @Override\r
+    public ConnType getConnType() {\r
+        return mConnType;\r
+    }\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiProvConfig.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiProvConfig.java
new file mode 100644 (file)
index 0000000..72ffb5e
--- /dev/null
@@ -0,0 +1,64 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 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>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.impl;
+
+import org.iotivity.service.easysetup.core.ProvisioningConfig;
+import org.iotivity.service.easysetup.mediator.EnrolleeInfo;
+
+import android.net.wifi.WifiConfiguration;
+
+/**
+ * This class contains on provisioning configuration information for for target network.
+ * It implements ProvisioningConfig interface and provide configuration object specific to WiFi target network
+ */
+public class WiFiProvConfig implements ProvisioningConfig {
+
+    private final ConnType mConnType = ProvisioningConfig.ConnType.WiFi;
+
+    private final String mSsId;
+    private final String mPassword;
+
+    public WiFiProvConfig(String ssid, String pass) {
+        mSsId = ssid;
+        mPassword = pass;
+    }
+
+    @Override
+    public Object getConfig() {
+        return this;
+    }
+
+    @Override
+    public ConnType getConnType() {
+        return mConnType;
+    }
+
+    public String getSsId() {
+        return mSsId;
+    }
+
+    public String getPassword() {
+        return mPassword;
+    }
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupCallbackHandler.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupCallbackHandler.java
new file mode 100644 (file)
index 0000000..cb06fb8
--- /dev/null
@@ -0,0 +1,54 @@
+/**\r
+ * ***************************************************************\r
+ * <p>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p>\r
+ * <p>\r
+ * <p>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p>\r
+ * ****************************************************************\r
+ */\r
+package org.iotivity.service.easysetup.mediator;\r
+\r
+import android.util.Log;\r
+\r
+public class EasySetupCallbackHandler {\r
+    private static final String TAG = "ESCallbackHandler";\r
+    ProvisionEnrollee provisioningListener;\r
+\r
+    private static EasySetupCallbackHandler easySetupCallbackHandlerObj;\r
+\r
+    public static synchronized EasySetupCallbackHandler getInstance() {\r
+        if (null == easySetupCallbackHandlerObj) {\r
+            easySetupCallbackHandlerObj = new EasySetupCallbackHandler();\r
+        }\r
+        return easySetupCallbackHandlerObj;\r
+    }\r
+\r
+    public void ProvisioningStatusCallBack(int statuscode) {\r
+        Log.d(TAG,\r
+                "onFinishProvisioning() inside Android Java application. statuscode - "\r
+                        + statuscode);\r
+        if (this.provisioningListener != null) {\r
+            this.provisioningListener.ProvisioningStatusCallBack(statuscode);\r
+        } else {\r
+            Log.e(TAG, "provisioningListener is not registered");\r
+        }\r
+    }\r
+\r
+    public void registerProvisioningHandler(\r
+            ProvisionEnrollee provisioningListener) {\r
+        this.provisioningListener = provisioningListener;\r
+    }\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupManager.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupManager.java
new file mode 100644 (file)
index 0000000..3d9ea43
--- /dev/null
@@ -0,0 +1,94 @@
+/**\r
+ * ***************************************************************\r
+ * <p>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p>\r
+ * <p>\r
+ * <p>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p>\r
+ * ****************************************************************\r
+ */\r
+package org.iotivity.service.easysetup.mediator;\r
+\r
+import android.content.Context;\r
+\r
+import org.iotivity.ca.CaInterface;\r
+\r
+public class EasySetupManager {\r
+    private native void InitEasySetup();\r
+\r
+    private native void TerminateEasySetup();\r
+\r
+    // TODO : "OcConnectivityType connectivityType" has to be passed as the\r
+    // second parameter for PerformEasySetup\r
+    // instead of integer\r
+    private native void ProvisionEnrollee(String ipAddress, String netSSID,\r
+                                          String netPWD, int connectivityType);\r
+\r
+    private native void StopEnrolleeProvisioning(int connectivityType);\r
+\r
+    public static native void initialize(Context context);\r
+\r
+    private static EasySetupManager easySetupManagerInterfaceObj = null;\r
+    private Context appContext = null;\r
+\r
+    static {\r
+        // Load Easy Setup JNI interface\r
+        System.loadLibrary("gnustl_shared");\r
+        System.loadLibrary("octbstack");\r
+        System.loadLibrary("connectivity_abstraction");\r
+        System.loadLibrary("easysetup-jni");\r
+    }\r
+\r
+    private EasySetupManager() {\r
+\r
+    }\r
+\r
+    /**\r
+     * Function for Getting instance of EasySetupManager object.\r
+     *\r
+     * @return EasySetupManager instance.\r
+     *\r
+     */\r
+    public static synchronized EasySetupManager getInstance() {\r
+        if (null == easySetupManagerInterfaceObj) {\r
+            easySetupManagerInterfaceObj = new EasySetupManager();\r
+        }\r
+        return easySetupManagerInterfaceObj;\r
+    }\r
+\r
+    public void setApplicationContext(Context context) {\r
+        appContext = context;\r
+    }\r
+\r
+    public void initEasySetup() {\r
+        CaInterface.initialize(appContext);\r
+        InitEasySetup();\r
+    }\r
+\r
+    public void terminateEasySetup() {\r
+        TerminateEasySetup();\r
+    }\r
+\r
+    public void provisionEnrollee(String ipAddress, String netSSID,\r
+                                  String netPWD, int connectivityType) {\r
+\r
+        ProvisionEnrollee(ipAddress, netSSID, netPWD, connectivityType);\r
+    }\r
+\r
+    public void stopEnrolleeProvisioning(int connectivityType) {\r
+        StopEnrolleeProvisioning(connectivityType);\r
+    }\r
+\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeInfo.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeInfo.java
new file mode 100644 (file)
index 0000000..37adeaa
--- /dev/null
@@ -0,0 +1,64 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 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>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+public class EnrolleeInfo {
+
+    private String IpAddr;
+    private String HWAddr;
+    private String Device;
+    private boolean isReachable;
+
+    public String getIpAddr() {
+        return IpAddr;
+    }
+
+    public void setIpAddr(String ipAddr) {
+        IpAddr = ipAddr;
+    }
+
+    public String getHWAddr() {
+        return HWAddr;
+    }
+
+    public void setHWAddr(String hWAddr) {
+        HWAddr = hWAddr;
+    }
+
+    public String getDevice() {
+        return Device;
+    }
+
+    public void setDevice(String device) {
+        Device = device;
+    }
+
+    public boolean isReachable() {
+        return isReachable;
+    }
+
+    public void setReachable(boolean isReachable) {
+        this.isReachable = isReachable;
+    }
+
+}
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeOnBoardingInfo.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeOnBoardingInfo.java
new file mode 100644 (file)
index 0000000..5fe3f80
--- /dev/null
@@ -0,0 +1,92 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 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>
+ * ****************************************************************
+ */
+package org.iotivity.service.easysetup.mediator;
+
+public class EnrolleeOnBoardingInfo {
+
+    private String IpAddr;
+    private String HWAddr;
+    private String Device;
+    private boolean isReachable;
+    private boolean isAdditionNotified;
+    private boolean isRemovalNotified;
+
+    public EnrolleeOnBoardingInfo(String ipAddr, String hWAddr, String device,
+                                  boolean isReachable, boolean isRemovalNotified,
+                                  boolean isAdditionNotified) {
+        this.IpAddr = ipAddr;
+        this.HWAddr = hWAddr;
+        this.Device = device;
+        this.isReachable = isReachable;
+        this.isRemovalNotified = isRemovalNotified;
+        this.isAdditionNotified = isAdditionNotified;
+    }
+
+    public String getIpAddr() {
+        return IpAddr;
+    }
+
+    public void setIpAddr(String ipAddr) {
+        IpAddr = ipAddr;
+    }
+
+    public String getHWAddr() {
+        return HWAddr;
+    }
+
+    public void setHWAddr(String hWAddr) {
+        HWAddr = hWAddr;
+    }
+
+    public String getDevice() {
+        return Device;
+    }
+
+    public void setDevice(String device) {
+        Device = device;
+    }
+
+    public boolean isReachable() {
+        return isReachable;
+    }
+
+    public void setReachable(boolean isReachable) {
+        this.isReachable = isReachable;
+    }
+
+    public boolean isRemovalNotified() {
+        return isRemovalNotified;
+    }
+
+    public void setRemovalNotified(boolean isRemovalNotified) {
+        this.isRemovalNotified = isRemovalNotified;
+    }
+
+    public boolean isAdditionNotified() {
+        return isAdditionNotified;
+    }
+
+    public void setAdditionNotified(boolean isAdditionNotified) {
+        this.isAdditionNotified = isAdditionNotified;
+    }
+
+}
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IOnBoardingStatus.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IOnBoardingStatus.java
new file mode 100644 (file)
index 0000000..03fb342
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 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>
+ * ****************************************************************
+ */
+package org.iotivity.service.easysetup.mediator;
+
+import java.util.ArrayList;
+
+import org.iotivity.service.easysetup.mediator.EnrolleeInfo;
+
+public interface IOnBoardingStatus {
+
+    /**
+     * Interface called when the scan method finishes. Network operations should
+     * not execute on UI thread
+     *
+     * @param clients of {@link EnrolleeInfo}
+     */
+
+    public void deviceOnBoardingStatus(EnrolleeInfo clients);
+
+}
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IProvisioningListener.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IProvisioningListener.java
new file mode 100644 (file)
index 0000000..315bef8
--- /dev/null
@@ -0,0 +1,30 @@
+/**\r
+ * ***************************************************************\r
+ * <p>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p>\r
+ * <p>\r
+ * <p>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p>\r
+ * ****************************************************************\r
+ */\r
+package org.iotivity.service.easysetup.mediator;\r
+\r
+public interface IProvisioningListener {\r
+    /**\r
+     * Interface called when the provisioning finishes\r
+     */\r
+\r
+    public void onFinishProvisioning(int statuscode);\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisionEnrollee.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisionEnrollee.java
new file mode 100644 (file)
index 0000000..ef0cbb1
--- /dev/null
@@ -0,0 +1,62 @@
+/**\r
+ * ***************************************************************\r
+ * <p>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p>\r
+ * <p>\r
+ * <p>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup.mediator;\r
+\r
+import android.content.Context;\r
+import android.util.Log;\r
+\r
+public class ProvisionEnrollee {\r
+    private static final String TAG = "ProvisionEnrollee";\r
+    private IProvisioningListener provisioningListener;\r
+\r
+    /**\r
+     * Constructor for ProvisionEnrollee. Constructs a new ProvisionEnrollee.\r
+     */\r
+    public ProvisionEnrollee(Context context) {\r
+\r
+    }\r
+\r
+    public void provisionEnrollee(String ipAddress, String netSSID,\r
+                                  String netPWD, int connectivityType) {\r
+        Log.i(TAG, "JNI start provisioning is called ");\r
+    }\r
+\r
+    public void stopEnrolleeProvisioning(int connectivityType) {\r
+        Log.i(TAG, "JNI stop provisioning is called ");\r
+    }\r
+\r
+    public void ProvisioningStatusCallBack(int statuscode) {\r
+        Log.d(TAG,\r
+                "JNI onFinishProvisioning() inside Android Java application. statuscode - "\r
+                        + statuscode);\r
+        this.provisioningListener.onFinishProvisioning(statuscode);\r
+    }\r
+\r
+    public void registerProvisioningHandler(\r
+            IProvisioningListener provisioningListener) {\r
+        this.provisioningListener = provisioningListener;\r
+        EasySetupCallbackHandler.getInstance()\r
+                .registerProvisioningHandler(this);\r
+        Log.i(TAG, "JNI Callback is registered for getting provisioning status");\r
+    }\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java
new file mode 100644 (file)
index 0000000..1212932
--- /dev/null
@@ -0,0 +1,353 @@
+/**
+ * ***************************************************************
+ * <p>
+ * Copyright 2015 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>
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator.ip;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.util.ArrayList;
+
+import android.content.Context;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.util.Log;
+
+import org.iotivity.service.easysetup.mediator.EnrolleeInfo;
+import org.iotivity.service.easysetup.mediator.EnrolleeOnBoardingInfo;
+import org.iotivity.service.easysetup.mediator.IOnBoardingStatus;
+
+/**
+ * WiFiSoftAPManager provides wrapper methods for accessing Android Soft Access Point functionality.
+ * This is a convenient class, providing Android "WiFiManager" kind of equivalent class for Soft AP.
+ * <p>
+ * Note: Android doesn't provide public APIs for Soft Access Point feature access.
+ * This class provides only reference implementation to use the Soft AP and it uses Java reflection
+ * for access Soft Access point features.
+ * </p>
+ */
+public class WiFiSoftAPManager {
+    private static final String TAG = WiFiSoftAPManager.class.getName();
+    private final WifiManager mWifiManager;
+    private Context context;
+    static ArrayList<EnrolleeOnBoardingInfo> appNotification =
+            new ArrayList<EnrolleeOnBoardingInfo>();
+    IOnBoardingStatus finishListener = null;
+
+    public enum WIFI_AP_STATE {
+        WIFI_AP_STATE_DISABLING,
+        WIFI_AP_STATE_DISABLED,
+        WIFI_AP_STATE_ENABLING,
+        WIFI_AP_STATE_ENABLED,
+        WIFI_AP_STATE_FAILED
+    }
+
+    public WiFiSoftAPManager(Context context) {
+        this.context = context;
+        mWifiManager = (WifiManager) this.context
+                .getSystemService(Context.WIFI_SERVICE);
+    }
+
+    /*
+    * Utility API to check the validity of the MAC Address read from the ARP cache
+    */
+    private boolean CheckIfValidMacAddress(String macAddr) {
+        if (macAddr.matches("..:..:..:..:..:..")) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /*
+    * The API is used for checking the device entry in the list maintained for the device
+    * notifications.
+    * If device entry is not found in the list, app is notified.
+    * If the device entry is found in the device, as application is already notified it will
+    * continue
+    */
+    private boolean CheckForDeviceEntryAndNotify(String ipAddr,
+                                                 String macAddr, boolean isReachable) {
+        final EnrolleeInfo result = new EnrolleeInfo();
+        boolean deviceAddedToList = false;
+
+        if (appNotification.size() > 0) {
+            for (EnrolleeOnBoardingInfo ipDeviceOnBoardingNotification : appNotification) {
+                EnrolleeOnBoardingInfo ipEnrolleeDevice = (EnrolleeOnBoardingInfo)
+                        ipDeviceOnBoardingNotification;
+                boolean macAddressComparison = ipEnrolleeDevice.getHWAddr().equalsIgnoreCase(
+                        macAddr) ? true : false;
+
+                if (macAddressComparison) {
+                    deviceAddedToList = true;
+
+                    if (ipDeviceOnBoardingNotification
+                            .isAdditionNotified()
+                            && isReachable) {
+                        continue;
+                    } else if (ipDeviceOnBoardingNotification
+                            .isRemovalNotified()
+                            && !isReachable) {
+                        continue;
+                    } else {
+                        result.setIpAddr(ipAddr);
+                        result.setHWAddr(macAddr);
+                        result.setReachable(isReachable);
+
+                        appNotification
+                                .remove(ipDeviceOnBoardingNotification);
+                        if (isReachable) {
+                            appNotification
+                                    .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "",
+                                            isReachable,
+                                            false, true));
+                        } else {
+                            //This case will happen during the transition from connected to
+                            // disconneted. This case need not be notified to application.
+                            // Notifying this state will cause failure of OnBoarding
+                        }
+                        NotifyApplication(result);
+                        return true;
+                    }
+                }
+            }
+            if (!deviceAddedToList) {
+                if (isReachable) {
+                    appNotification
+                            .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, false,
+                                    true));
+
+                    result.setIpAddr(ipAddr);
+                    result.setHWAddr(macAddr);
+                    result.setReachable(isReachable);
+
+                    NotifyApplication(result);
+                } else {
+                    //This case will happen for the first time device is listed, but reachability
+                    // is false. This case need not be notified to application. Notifying this
+                    // state will cause failure of OnBoarding
+                }
+                return true;
+            }
+        } else {
+            if (isReachable) {
+                appNotification
+                        .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, false,
+                                true));
+                result.setIpAddr(ipAddr);
+                result.setHWAddr(macAddr);
+                result.setReachable(isReachable);
+
+                NotifyApplication(result);
+            } else {
+                //This case will happen for the first time device is listed,  but
+                // reachability is false. This case need not be notified to
+                // application. Notifying this state will cause failure of OnBoarding
+            }
+
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Start WiFi Soft AccessPoint mode with the specified configuration.
+     * If the Soft AP is already running, this API call will update the new configuration.
+     * <p>
+     * Note: Starting Wi-Fi Soft Access Point will disable the Wi-Fi normal operation.
+     * </p>
+     *
+     * @param wifiConfig SSID, security and channel details as part of WifiConfiguration
+     * @return {@code true} if the operation succeeds, {@code false} otherwise
+     */
+    public boolean setWifiApEnabled(WifiConfiguration wifiConfig,
+                                    boolean enabled) {
+        try {
+            appNotification.clear();
+            // Stopping Wi-Fi mode
+            if (enabled) {
+                mWifiManager.setWifiEnabled(false);
+            }
+
+            Method method = mWifiManager.getClass().getMethod(
+                    "setWifiApEnabled", WifiConfiguration.class, boolean.class);
+            return (Boolean) method.invoke(mWifiManager, wifiConfig, enabled);
+        } catch (Exception e) {
+            Log.e(this.getClass().toString(), "", e);
+            return false;
+        }
+    }
+
+    /**
+     * Fetch the current state of the Wi-Fi Soft AP
+     *
+     * @return {@link WIFI_AP_STATE}
+     */
+    public WIFI_AP_STATE getWifiApState() {
+        try {
+            Method method = mWifiManager.getClass().getMethod("getWifiApState");
+
+            int currentWiFiState = ((Integer) method.invoke(mWifiManager));
+            WIFI_AP_STATE wifi_ap_state_enum[] = WIFI_AP_STATE.class.getEnumConstants();
+            if (wifi_ap_state_enum != null)
+                return wifi_ap_state_enum[currentWiFiState];
+            else return WIFI_AP_STATE.WIFI_AP_STATE_FAILED;
+        } catch (Exception e) {
+            Log.e(this.getClass().toString(), "", e);
+            return WIFI_AP_STATE.WIFI_AP_STATE_FAILED;
+        }
+    }
+
+    /**
+     * Fetch the current Wi-Fi AP Configuration.
+     *
+     * @return AP details in {@link WifiConfiguration}
+     */
+    public WifiConfiguration getWifiApConfiguration() {
+        try {
+            Method method = mWifiManager.getClass().getMethod(
+                    "getWifiApConfiguration");
+            return (WifiConfiguration) method.invoke(mWifiManager);
+        } catch (Exception e) {
+            Log.e(this.getClass().toString(), "", e);
+            return null;
+        }
+    }
+
+    /**
+     * Set/Update the Wi-Fi AP Configuration.
+     *
+     * @return {@code true} if the operation succeeds, {@code false} otherwise
+     */
+    public boolean setWifiApConfiguration(WifiConfiguration wifiConfig) {
+        try {
+            Method method = mWifiManager.getClass().getMethod(
+                    "setWifiApConfiguration", WifiConfiguration.class);
+            return (Boolean) method.invoke(mWifiManager, wifiConfig);
+        } catch (Exception e) {
+            Log.e(this.getClass().toString(), "", e);
+            return false;
+        }
+    }
+
+    /**
+     * Gets a list of the Soft AP clients connected to the Wi-Fi Soft Access point
+     *
+     * @param finishListener   Interface called when the scan method finishes
+     * @param reachableTimeout Reachable Timeout in miliseconds
+     */
+    public synchronized void getClientList(IOnBoardingStatus finishListener, final int
+            reachableTimeout) {
+        this.finishListener = finishListener;
+        //Clearing the scan list for providing u
+        appNotification.clear();
+        Runnable runnable = new Runnable() {
+            public void run() {
+                Log.i(TAG, "Scanning enrolling device in the network");
+
+                BufferedReader bufferedReader = null;
+
+                try {
+                    // Note : This is a reference implementation for getting the list of Enrollee's
+                    // connected to the Soft AP.
+                    // There is no Android API for getting list of connected devices to the Soft AP.
+                    // The connected device information is fetched from Arp cache for Soft AP and
+                    // it is maintained in the file "/proc/net/arp"
+                    // This holds an ASCII readable dump of the kernel ARP  table  used
+                    // for  address resolutions.  It will show both dynamically learned
+                    // and preprogrammed ARP entries.  The format is:
+                    // IP address     HW type   Flags     HW address          Mask   Device
+                    // 192.168.0.50   0x1       0x2       00:50:BF:25:68:F3   *      eth0
+                    // 192.168.0.250  0x1       0xc       00:00:00:00:00:00   *      eth0
+                    bufferedReader = new BufferedReader(new InputStreamReader(
+                            new FileInputStream("/proc/net/arp"), "UTF-8"));
+                    String line;
+                    while ((line = bufferedReader.readLine()) != null) {
+                        //ARP entries are splitted using Regex for getting the IP and MAC Address
+                        // info
+                        String[] arpEntry = line.split(" +");
+
+                        if ((arpEntry != null) && (arpEntry.length >= 4)) {
+                            String ipAddr = arpEntry[0];
+                            String macAddr = arpEntry[3];
+
+
+                            // Checking if the string is matching MAC Address is matching the
+                            // standard MAC address format.
+                            // If the entry is not matching with MAC address format,
+                            // it will continue
+                            if (CheckIfValidMacAddress(macAddr)) {
+                                boolean isReachable = InetAddress.getByName(
+                                        ipAddr).isReachable(
+                                        reachableTimeout);
+
+                                Log.i("exec statement", ipAddr);
+                                Log.i("Return Value", " " + isReachable);
+
+                                // Checking if the app notification entries are available in the
+                                // list for the current device
+                                // API returns true is there is a notification to the application.
+                                // API returns false if there is no entry or if device is
+                                // already notified
+                                if (CheckForDeviceEntryAndNotify(ipAddr, macAddr, isReachable)) {
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                } catch (Exception e) {
+                    Log.e(this.getClass().toString(), e.toString());
+                } finally {
+                    try {
+                        bufferedReader.close();
+                    } catch (IOException e) {
+                        Log.e(this.getClass().toString(), e.getMessage());
+                    }
+                }
+            }
+        };
+
+        Thread mythread = new Thread(runnable);
+        mythread.start();
+    }
+
+    void NotifyApplication(final EnrolleeInfo result) {
+        // Get a handler that can be used to post to the main thread
+/*
+        Handler mainHandler = new Handler(context.getMainLooper());
+        Runnable myRunnable = new Runnable() {
+            @Override
+            public void run() {
+                finishListener.deviceOnBoardingStatus(result);
+            }
+        };
+        mainHandler.post(myRunnable);
+*/
+        Log.i(TAG, "Scanning is finished with result, IP : " + result.getIpAddr() + "Notifying " +
+                "to Application");
+        finishListener.deviceOnBoardingStatus(result);
+
+    }
+}
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/main.iml b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/main.iml
new file mode 100644 (file)
index 0000000..80242f3
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="android" name="Android">
+      <configuration />
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
+    </content>
+    <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" name="classes1" level="project" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/res/drawable-hdpi/ic_launcher.png b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..288b665
Binary files /dev/null and b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/res/values/strings.xml b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..830c7cd
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+
+    <string name="app_name">EasySetupCore</string>
+
+</resources>
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/res/values/styles.xml b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/res/values/styles.xml
new file mode 100644 (file)
index 0000000..6ce89c7
--- /dev/null
@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>
diff --git a/service/easy-setup/sdk/mediator/android/jni/Android.mk b/service/easy-setup/sdk/mediator/android/jni/Android.mk
new file mode 100644 (file)
index 0000000..0e87f2a
--- /dev/null
@@ -0,0 +1,85 @@
+LOCAL_PATH := $(call my-dir)
+
+ifeq ($(strip $(ANDROID_NDK)),)
+$(error ANDROID_NDK is not set!)
+endif
+
+$(warning "Current path" $(LOCAL_PATH))
+$(info TC_PREFIX=$(TOOLCHAIN_PREFIX))
+$(info CFLAGS=$(TARGET_CFLAGS))
+$(info CXXFLAGS=$(TARGET_CXXFLAGS) $(TARGET_NO_EXECUTE_CFLAGS))
+$(info CPPFLAGS=$(TARGET_CPPFLAGS))
+$(info CPPPATH=$(TARGET_C_INCLUDES) $(__ndk_modules.$(APP_STL).EXPORT_C_INCLUDES))
+$(info SYSROOT=$(SYSROOT_LINK))
+$(info LDFLAGS=$(TARGET_LDFLAGS) $(TARGET_NO_EXECUTE_LDFLAGS) $(TARGET_NO_UNDEFINED_LDFLAGS) $(TARGET_RELRO_LDFLAGS))
+$(info TC_VER=$(TOOLCHAIN_VERSION))
+$(info PLATFORM=$(APP_PLATFORM))
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/debug
+LOCAL_MODULE := android-octbstack
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboctbstack.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/debug
+LOCAL_MODULE := android-connectivity_abstraction
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libconnectivity_abstraction.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../../out/android/$(TARGET_ARCH_ABI)/debug
+LOCAL_MODULE := android-easysetup
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/libESSDK.a
+include $(PREBUILT_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE    := easysetup-jni
+
+#Add Pre processor definitions
+DEFINE_FLAG =  -DWITH_POSIX -D__ANDROID__
+
+#Add Debug flags here
+DEBUG_FLAG      = -DTB_LOG
+
+BUILD_FLAG = $(DEFINE_FLAG) $(DEBUG_FLAG)
+
+LOCAL_CPPFLAGS = $(BUILD_FLAG)
+LOCAL_CPPFLAGS += -std=c++0x -frtti -fexceptions
+
+$(info CPPFLAGSUPDATED=$(LOCAL_CPPFLAGS))
+
+NDK_ROOT         := /home/madan/android-ndk-r10d
+
+LOCAL_C_INCLUDES := $(LOCAL_PATH) \
+                                       $(LOCAL_PATH)/jniutil/inc \
+                                       $(LOCAL_PATH)/../../../../../../service/easy-setup/sdk/mediator/inc \
+                                       $(LOCAL_PATH)/../../../../../../service/easy-setup/sdk/common \
+                                       $(LOCAL_PATH)/../../../../../../resource/csdk/logger/include \
+                                       $(LOCAL_PATH)/../../../../../../resource/csdk/connectivity/common/inc \
+                                       $(LOCAL_PATH)/../../../../../../resource/include \
+                                       $(LOCAL_PATH)/../../../../../../resource/c_common \
+                                       $(LOCAL_PATH)/../../../../../../resource/oc_logger/include \
+                                       $(LOCAL_PATH)/../../../../../../resource/csdk/ocmalloc/include \
+                                       $(LOCAL_PATH)/../../../../../../resource/csdk/connectivity/api \
+                                       $(LOCAL_PATH)/../../../../../../resource/csdk/stack/include \
+                                       $(LOCAL_PATH)/../../../../../../resource/csdk/logger/include \
+                                       $(LOCAL_PATH)/../../../../../../resource/csdk/security/include \
+                                       $(LOCAL_PATH)/../../../../../../extlibs/cjson \
+                                       $(LOCAL_PATH)/../../../../../../extlibs/boost/boost_1_58_0 \
+                    $(LOCAL_PATH)/../../../../../../extlibs/timer \
+                                       $(LOCAL_PATH)/../../../../../../android/android_api/base/jni \
+                                       $(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/include \
+                    $(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/$(TARGET_ARCH_ABI)/include \
+                                       
+LOCAL_SRC_FILES += $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/jni_easy_setup.cpp))
+LOCAL_SRC_FILES += $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/jniutil/src/*.cpp))
+
+LOCAL_LDLIBS := -llog 
+LOCAL_LDLIBS += -L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/$(TARGET_ARCH_ABI)
+LOCAL_SHARED_LIBRARIES := android-easysetup
+LOCAL_SHARED_LIBRARIES += android-connectivity_abstraction
+LOCAL_SHARED_LIBRARIES += android-octbstack
+
+include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file
diff --git a/service/easy-setup/sdk/mediator/android/jni/Application.mk b/service/easy-setup/sdk/mediator/android/jni/Application.mk
new file mode 100644 (file)
index 0000000..d5fc03c
--- /dev/null
@@ -0,0 +1,4 @@
+APP_STL               := gnustl_shared
+APP_PLATFORM = android-21
+NDK_TOOLCHAIN_VERSION := 4.8
+
diff --git a/service/easy-setup/sdk/mediator/android/jni/jni_easy_setup.cpp b/service/easy-setup/sdk/mediator/android/jni/jni_easy_setup.cpp
new file mode 100644 (file)
index 0000000..b704de5
--- /dev/null
@@ -0,0 +1,191 @@
+//******************************************************************
+//
+// 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 "jni_easy_setup.h"
+
+#include "jni_easy_setup_jvm.h"
+#include "prov_adapter.h"
+
+void JNIProvisioningStatusCallback(ProvisioningInfo * provInfo) {
+       JNIEnv *env = EasySetupJVM::getEnv();
+       if (env == NULL) {
+               LOGE("JNIProvisioningStatusCallback : Getting JNIEnv failed");
+               return;
+       }
+
+       // Get EasySetupHandler class reference
+       jclass easysetupCallbacks = GetJClass(
+                       EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);
+       if (NULL == easysetupCallbacks) {
+               LOGE(
+                               "JNIProvisioningStatusCallback : GetJClass easysetupCallbacks failed");
+               EasySetupJVM::releaseEnv();
+               return;
+       }
+
+       // Get the easysetupCallback class instance
+       jobject jobjectCallback = GetJObjectInstance(
+                       EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);
+       if (NULL == jobjectCallback) {
+               LOGE("getInstance( %s) failed!",
+                               EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);
+               EasySetupJVM::releaseEnv();
+               return;
+       }
+
+       // Get onResourceCallback method reference
+       jmethodID method_id = env->GetMethodID(easysetupCallbacks,
+                       "ProvisioningStatusCallBack",
+                       METHOD_PROVISIONING_STATUS_INTEGER_CALLBACK);
+       if (NULL == method_id) {
+               LOGE(
+                               "JNIProvisioningStatusCallback: onResourceCallback : GetMethodID failed");
+               EasySetupJVM::releaseEnv();
+               return;
+       }
+
+       if ((env)->ExceptionCheck()) {
+               LOGE("JNIProvisioningStatusCallback : ExceptionCheck failed");
+               EasySetupJVM::releaseEnv();
+               return;
+       }
+
+       if (NULL == method_id) {
+               LOGI("JNI method_id is NULL");
+       } else {
+               LOGI("JNI method_id is VALID");
+
+               jint result;
+               if (provInfo->provStatus == DEVICE_PROVISIONED) {
+                       result = 0;
+               } else {
+                       result = -1;
+               }
+
+               env->CallVoidMethod(jobjectCallback, method_id, (jint) result);
+       }
+
+       EasySetupJVM::releaseEnv();
+}
+
+JNIEXPORT void JNICALL
+JNIInitEasySetup(JNIEnv
+               *env,
+               jobject thisObj
+)
+{
+       LOGI("JNI JNIInitEasySetup: Enter");
+
+       InitProvProcess();
+
+       RegisterCallback(JNIProvisioningStatusCallback);
+}
+
+JNIEXPORT void JNICALL
+JNITerminateEasySetup(JNIEnv
+               *env,
+               jobject thisObj
+)
+{
+       LOGI("JNI JNITerminateEasySetup: Enter");
+
+       ResetProvProcess();
+
+}
+
+JNIEXPORT void JNICALL
+JNIProvisionEnrollee(JNIEnv
+               *env,
+               jobject thisObj,
+               jstring
+               jIPAddress,
+               jstring jNetSSID,
+               jstring
+               jNetPWD,
+               jint jConnectivityType
+)
+{
+       LOGI("JNI JNIProvisionEnrollee: Enter");
+
+       if (!jIPAddress)
+       {
+               LOGE("JNI JNIProvisionEnrollee : jIPAddress is NULL!");
+               return;
+       }
+
+       const char *ipAddress = env->GetStringUTFChars(jIPAddress, NULL);
+       if (NULL == ipAddress)
+       {
+               LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
+       }
+
+       LOGI("JNI JNIProvisionEnrollee : ipAddress is : %s",ipAddress);
+
+       const char *netSSID = env->GetStringUTFChars(jNetSSID, NULL);
+       if (NULL == netSSID)
+       {
+               LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
+       }
+
+       LOGI("JNI JNIProvisionEnrollee : netSSID is : %s",netSSID);
+
+       const char *netPWD = env->GetStringUTFChars(jNetPWD, NULL);
+       if (NULL == netPWD)
+       {
+               LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
+       }
+
+       LOGI("JNI JNIProvisionEnrollee : netPWD is : %s",netPWD);
+
+       OCConnectivityType connecitivityType;
+       EnrolleeNWProvInfo_t netInfo =
+       {       0};
+       strncpy(netInfo
+                       .netAddressInfo.WIFI.ipAddress, ipAddress, IPV4_ADDR_SIZE-1);
+       strncpy(netInfo
+                       .netAddressInfo.WIFI.ssid, netSSID, NET_WIFI_SSID_SIZE-1);
+       strncpy(netInfo
+                       .netAddressInfo.WIFI.pwd, netPWD, NET_WIFI_PWD_SIZE-1);
+       netInfo.
+       connType = (OCConnectivityType) jConnectivityType;
+
+       netInfo.
+       isSecured = true;
+
+       StartProvisioning(&netInfo);
+
+       return;
+}
+
+JNIEXPORT void JNICALL
+JNIStopEnrolleeProvisioning(JNIEnv
+               *env,
+               jobject thisObj,
+               jint
+               jConnectivityType)
+{
+       LOGI("JNI Stop Easy Setup: Entering");
+
+       StopProvisioning((OCConnectivityType)
+                       jConnectivityType);
+
+       return;
+}
+
diff --git a/service/easy-setup/sdk/mediator/android/jni/jni_easy_setup.h b/service/easy-setup/sdk/mediator/android/jni/jni_easy_setup.h
new file mode 100644 (file)
index 0000000..a69d657
--- /dev/null
@@ -0,0 +1,42 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+#include <jni.h>\r
+#include <jni_string.h>\r
+\r
+#include "JniOcStack.h"\r
+\r
+#define METHOD_PROVISIONING_STATUS_VOID_CALLBACK    "("")V"\r
+#define METHOD_PROVISIONING_STATUS_INTEGER_CALLBACK    "("EASY_SETUP_JAVA_INTEGER_TYPE")V"\r
+\r
+/* Header for class org_iotivity_service_easyconnect_java_EasySetupHandler */\r
+\r
+#ifndef _Included_org_iotivity_service_easysetup_java_EasySetupHandler\r
+#define _Included_org_iotivity_service_easysetup_java_EasySetupHandler\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+JNIEXPORT void JNICALL JNIInitEasySetup(JNIEnv *env, jobject thisObj);\r
+JNIEXPORT void JNICALL JNITerminateEasySetup(JNIEnv *env, jobject thisObj);\r
+\r
+/*\r
+ * Class:     org_iotivity_service_easyconnect_java_EasySetupHandler\r
+ * Method:    JNIProvisionEnrollee\r
+ * Signature: ()V\r
+ */\r
+JNIEXPORT void JNICALL JNIProvisionEnrollee(JNIEnv *env, jobject ,\r
+                                                jstring ,\r
+                                                jstring ,\r
+                                                jstring ,\r
+                                                jint jConnectivityType);\r
+\r
+JNIEXPORT void JNICALL JNIStopEnrolleeProvisioning(JNIEnv *, jobject, jint);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+#endif\r
diff --git a/service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_easy_setup_jvm.h b/service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_easy_setup_jvm.h
new file mode 100644 (file)
index 0000000..0e9e383
--- /dev/null
@@ -0,0 +1,94 @@
+/******************************************************************
+ *
+ * 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   jni_easy_setup_jvm.h
+ *
+ * @brief  This file contains the essential declarations and functions required
+ *            for JNI implementation
+ */
+
+#ifndef __JNI_EASY_SETUP_JVM_H_
+#define __JNI_EASY_SETUP_JVM_H_
+
+#include <jni.h>
+#include <thread>
+#include <mutex>
+
+#define EASY_SETUP_SERVICE_NATIVE_API_CLASS_PATH    "org/iotivity/service/easysetup/mediator/EasySetupManager"
+#define EASY_SETUP_SERVICE_NATIVE_API_CLASS_TYPE    "Lorg/iotivity/service/easysetup/mediator/EasySetupManager;"
+#define EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH    "org/iotivity/service/easysetup/mediator/EasySetupCallbackHandler"
+#define EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_TYPE    "Lorg/iotivity/service/easysetup/mediator/EasySetupCallbackHandler;"
+
+#define EASY_SETUP_JAVA_STRING_TYPE "Ljava/lang/String;"
+#define EASY_SETUP_JAVA_INTEGER_TYPE "I"
+
+/**
+ * @class   EasySetupJVM
+ * @brief   This class provides functions related to JNI Environment.
+ *
+ */
+class EasySetupJVM {
+public:
+    /**
+     * @brief destructor
+     */
+    ~EasySetupJVM() {
+    }
+    ;
+
+    /**
+     * @brief  Get JVM instance
+     */
+    static JNIEnv *getEnv();
+
+    /**
+     * @brief  Release aquired JVM instance
+     */
+    static void releaseEnv();
+
+public:
+    /**
+     *  Java VM pointer
+     */
+    static JavaVM *m_jvm;
+
+private:
+    /**
+     * @brief constructor
+     */
+    EasySetupJVM();
+
+    /**
+     *  Mutex for thread synchronization
+     */
+    static std::mutex m_currentThreadMutex;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+jclass GetJClass(const char *szClassPath);
+jobject GetJObjectInstance(const char *szClassPath);
+#ifdef __cplusplus
+}
+#endif
+#endif //__JNI_EASY_SETUP_JVM_H_
+
diff --git a/service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_getter.h b/service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_getter.h
new file mode 100644 (file)
index 0000000..fe92a82
--- /dev/null
@@ -0,0 +1,111 @@
+/******************************************************************
+ *
+ * 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   jni_getter.h
+ *
+ * @brief  This file contains the JGetter class  declarations and its functions required
+ *            for getting and setting basic data types in C++ and Java
+ */
+
+#ifndef __JNI_GETTER_H_
+#define __JNI_GETTER_H_
+
+#include <string>
+#include <jni.h>
+
+/**
+ * @class   JGetter
+ * @brief  This class provide utility for get/set basic data types in C++ and Java
+ *
+ */
+class JGetter {
+public:
+       /**
+        * This function is called to get String field from the C++ object
+        *
+        * @param env
+        *           JNI Environment reference
+        * @param object
+        *           JObject from which string field is expected
+        * @param fieldName
+        *           Name of the field to be extracted from JObject
+        * @param value
+        *         reference to string value mentioned in fieldName
+        *
+        * @return returns true on success and false on failer.
+        */
+       static bool getJStringField(JNIEnv *env, jobject &object,
+                       const char *fieldName, std::string &value);
+
+       /**
+        * This function is called to get Boolean field from the C++ object
+        *
+        * @param env
+        *           JNI Environment reference
+        * @param object
+        *           JObject from which boolean field is expected
+        * @param fieldName
+        *           Name of the field to be extracted from JObject
+        * @param value
+        *         reference to boolean value mentioned in fieldName
+        *
+        * @return returns true on success and false on failer.
+        */
+       static bool getJBoolField(JNIEnv *env, jobject &object,
+                       const char *fieldName, bool &value);
+
+       /**
+        * This function is called to get Integer field from the C++ object
+        *
+        * @param env
+        *           JNI Environment reference
+        * @param object
+        *           JObject from which integer field is expected
+        * @param fieldName
+        *           Name of the field to be extracted from JObject
+        * @param value
+        *         reference to integer value mentioned in fieldName
+        *
+        * @return returns true on success and false on failer.
+        */
+       static bool getJIntField(JNIEnv *env, jobject &object,
+                       const char *fieldName, int &value);
+
+       /**
+        * This function is called to get Object reference from the C++ object
+        *
+        * @param env
+        *           JNI Environment reference
+        * @param object
+        *           JObject from which Object reference is expected
+        * @param fieldName
+        *           Name of the field to be extracted from JObject
+        * @param fieldType
+        *           Type of the field to be extracted from JObject
+        * @param value
+        *         reference to Object reference mentioned in fieldName
+        *
+        * @return returns true on success and false on failer.
+        */
+       static bool getJObjectField(JNIEnv *env, jobject &object,
+                       const char *fieldName, const char *fieldType, jobject &value);
+};
+#endif //__JNI_GETTER_H_
diff --git a/service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_object.h b/service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_object.h
new file mode 100644 (file)
index 0000000..5f27a47
--- /dev/null
@@ -0,0 +1,96 @@
+/******************************************************************
+ *
+ * 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   jni_object.h
+ *
+ * @brief  This file contains the JObject class  declarations and its functions required
+ *            for getting and setting basic data types in C++ and Java
+ */
+
+#ifndef __JNI_OBJECT_H_
+#define __JNI_OBJECT_H_
+
+#include <jni.h>
+#include "JniOcResource.h"
+
+/**
+ * @class   JObject
+ * @brief   This class provides a set of functions for JNI object.
+ *
+ */
+class JObject {
+public:
+       /**
+        * @brief constructor
+        */
+       JObject(JNIEnv *env);
+
+       /**
+        * @brief constructor
+        */
+       JObject(JNIEnv *env, jobject obj);
+
+       /**
+        * @brief constructor
+        */
+       JObject(JNIEnv *env, const char *classPath);
+
+       /**
+        * @brief destructor
+        *
+        */
+       virtual ~JObject();
+
+       /**
+        * Function to get the jobject.
+        *
+        * @return jobject, returns a new JNI object or NULL otherwise.
+        *
+        */
+       virtual jobject getObject() const;
+
+       /**
+        * Function to detach the jobject.
+        *
+        * @return void
+        *
+        */
+       void detachObject();
+
+protected:
+       /**
+        *  JNI Environment Pointer
+        */
+       JNIEnv *m_pEnv;
+       /**
+        *  Java Object
+        */
+       jobject m_pObject;
+       /**
+        *  Java Class
+        */
+       jclass m_pClazz;
+       /**
+        *  Boolean variable to check if an object is new
+        */
+       bool m_fIsNewObject;
+};
+#endif //__JNI_OBJECT_H_
diff --git a/service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_setter.h b/service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_setter.h
new file mode 100644 (file)
index 0000000..c4593cc
--- /dev/null
@@ -0,0 +1,128 @@
+/******************************************************************
+ *
+ * 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   jni_setter.h
+ *
+ * @brief  This file contains the JSetter class declarations and and its functions required
+ *            to set data types in C++ object from Java object
+ */
+
+#ifndef __JNI_SETTER_H_
+#define __JNI_SETTER_H_
+
+#include <jni.h>
+
+/**
+ * @class   JSetter
+ * @brief  This class provide utility to set data types in C++ object from Java object
+ *
+ */
+class JSetter {
+public:
+
+       /**
+        * This function is called to set Integer field in to C++ object.
+        *
+        * @param env
+        *           JNI Environment reference
+        * @param object
+        *           JObject to which integer field will be set.
+        * @param fieldName
+        *           Name of the field to be set in JObject
+        * @param value
+        *         integer value mentioned in fieldName
+        *
+        * @return returns true on success and false on failer.
+        */
+       static bool setJIntField(JNIEnv *env, jobject &object,
+                       const char *fieldName, int value);
+
+       /**
+        * This function is called to set Long field in to C++ object.
+        *
+        * @param env
+        *           JNI Environment reference
+        * @param object
+        *           JObject to which Long field will be set.
+        * @param fieldName
+        *           Name of the field to be set in JObject
+        * @param value
+        *         Long value mentioned in fieldName
+        *
+        * @return returns true on success and false on failer.
+        */
+       static bool setJLongField(JNIEnv *env, jobject &object,
+                       const char *fieldName, jlong value);
+
+       /**
+        * This function is called to Set Boolean field to C++ object
+        *
+        * @param env
+        *           JNI Environment reference
+        * @param object
+        *           JObject to which boolean field has to be set
+        * @param fieldName
+        *           Name of the field to be set in JObject
+        * @param value
+        *         boolean value mentioned in fieldName
+        *
+        * @return returns true on success and false on failer.
+        */
+       static bool setJBoolField(JNIEnv *env, jobject &object,
+                       const char *fieldName, bool value);
+       /**
+        * This function is called to Set String field from the C++ object
+        *
+        * @param env
+        *           JNI Environment reference
+        * @param object
+        *           JObject in which string value has to be set
+        * @param fieldName
+        *           Name of the field to be set in JObject
+        * @param value
+        *         string value mentioned in fieldName
+        *
+        * @return returns true on success and false on failer.
+        */
+       static bool setJStringField(JNIEnv *env, jobject &object,
+                       const char *fieldName, const char *value);
+
+       /**
+        * This function is called to set Object reference in C++ object.
+        *
+        * @param env
+        *           JNI Environment reference
+        * @param object
+        *           JObject to which Object reference is to be set.
+        * @param fieldName
+        *           Name of the field to be set in JObject
+        * @param fieldType
+        *           Type of the field to be set in JObject
+        * @param value
+        *         value of Object mentioned in fieldName
+        *
+        * @return returns true on success and false on failer.
+        */
+       static bool setJObjectField(JNIEnv *env, jobject &object,
+                       const char *fieldName, const char *fieldType, const jobject value);
+};
+
+#endif //__JNI_SETTER_H_
diff --git a/service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_string.h b/service/easy-setup/sdk/mediator/android/jni/jniutil/inc/jni_string.h
new file mode 100644 (file)
index 0000000..358e869
--- /dev/null
@@ -0,0 +1,80 @@
+/******************************************************************
+ *
+ * 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   jni_string.h
+ *
+ * @brief  This file contains the declaration of JString class and its members related to JString.
+ *
+ */
+
+#ifndef __JNI_STRING_H_
+#define __JNI_STRING_H_
+
+#include <string>
+
+#include "jni_object.h"
+
+/**
+ * @class   JString
+ * @brief   This class inherits JObject class and provides a set of functions for JNI String.
+ *
+ */
+class JString: public JObject {
+public:
+       /**
+        * @brief constructor
+        */
+       JString(JNIEnv *env, jstring value);
+       /**
+        * @brief constructor
+        */
+       JString(JNIEnv *env, const char *value);
+       /**
+        * @brief constructor
+        */
+       JString(JNIEnv *env, const std::string &value);
+       /**
+        * @brief destructor
+        */
+       ~JString();
+
+       /**
+        * Function to get the string value and set it.
+        *
+        * @param value - String value to set to a private member variable.
+        *
+        * @return bool - true on success
+        *
+        */
+       bool getValue(std::string &value);
+
+       /**
+        * Function to get the private string value.
+        *
+        * @return  C String value.
+        *
+        */
+       const char *c_str();
+
+private:
+       std::string m_cstr;
+};
+#endif //__JNI_STRING_H_
diff --git a/service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_easy_setup_jvm.cpp b/service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_easy_setup_jvm.cpp
new file mode 100644 (file)
index 0000000..6c33f95
--- /dev/null
@@ -0,0 +1,319 @@
+/******************************************************************
+ *
+ * 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 "jni_easy_setup_jvm.h"
+#include <string>
+#include "jni_easy_setup.h"
+
+/**
+ * @class   JClassMap
+ * @brief   This class provides functions for initializing the Java class path and Java class.
+ *
+ */
+class JClassMap {
+public:
+    /**
+     *  Java Class
+     */
+    jclass classRef;
+    /**
+     *  Java Class Path
+     */
+    const char *szClassPath;
+
+    /**
+     * @brief constructor
+     */
+    JClassMap(const char *path) :
+            classRef(NULL) {
+        szClassPath = path;
+    }
+};
+
+/**
+ * @class   JObjectMap
+ * @brief   This class provides functins for initializing the Java Class path and Java Class
+ * Object.
+ *
+ */
+class JObjectMap {
+public:
+    /**
+     *  Java Object
+     */
+    jobject object;
+    /**
+     *  Java Class Path
+     */
+    const char *szClassPath;
+
+    /**
+     * @brief constructor
+     */
+    JObjectMap(const char *path) :
+            object(NULL) {
+        szClassPath = path;
+    }
+};
+
+static JClassMap gJClassMapArray[] = { JClassMap(
+        EASY_SETUP_SERVICE_NATIVE_API_CLASS_PATH), JClassMap(
+        EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH) };
+
+static JObjectMap gJObjectMapArray[] = { JObjectMap(
+        EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH) };
+
+static JNINativeMethod gEasySetupMethodTable[] = {
+    { "InitEasySetup", "()V", (void *) JNIInitEasySetup },
+    { "TerminateEasySetup", "()V", (void *) JNITerminateEasySetup },
+    { "ProvisionEnrollee", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V",
+                                (void *) JNIProvisionEnrollee },
+    { "StopEnrolleeProvisioning", "(I)V", (void *) JNIStopEnrolleeProvisioning }, };
+
+static int gEasySetupMethodTableSize = sizeof(gEasySetupMethodTable)
+        / sizeof(gEasySetupMethodTable[0]);
+
+int InitializeJClassMapArray(JNIEnv *env) {
+    LOGI("InitializeJClassMapArray: Enter");
+
+    unsigned int nLen = sizeof(gJClassMapArray) / sizeof(JClassMap);
+
+    for (unsigned int i = 0; i < nLen; i++) {
+        jclass classRef = env->FindClass(gJClassMapArray[i].szClassPath);
+        if (NULL == classRef) {
+            LOGE("FindClass failed for [%s]", gJClassMapArray[i].szClassPath);
+            return -1;
+        }
+        gJClassMapArray[i].classRef = (jclass) env->NewGlobalRef(classRef);
+        env->DeleteLocalRef(classRef);
+    }
+
+    LOGI("InitializeJClassMapArray: Exit");
+    return 0;
+}
+
+jclass GetJClass(const char *szClassPath) {
+    unsigned int nLen = sizeof(gJClassMapArray) / sizeof(JClassMap);
+
+    jclass classRef = NULL;
+
+    for (unsigned int i = 0; i < nLen; i++) {
+        if (0 == strcmp(gJClassMapArray[i].szClassPath, szClassPath)) {
+            classRef = gJClassMapArray[i].classRef;
+            break;
+        }
+    }
+
+    return classRef;
+}
+
+void DeleteClassMapArray(JNIEnv *env) {
+    LOGI("DeleteClassMapArray: Enter");
+
+    unsigned int nLen = sizeof(gJClassMapArray) / sizeof(JClassMap);
+    for (unsigned int i = 0; i < nLen; i++) {
+        if (NULL != gJClassMapArray[i].classRef) {
+            env->DeleteGlobalRef(gJClassMapArray[i].classRef);
+            gJClassMapArray[i].classRef = NULL;
+        }
+    }
+
+    LOGI("DeleteClassMapArray: Exit");
+}
+
+int InitializeJObjectMapArray(JNIEnv *env) {
+    LOGI("InitializeJObjectMapArray: Enter");
+
+    unsigned int nLen = sizeof(gJObjectMapArray) / sizeof(JObjectMap);
+
+    for (unsigned int i = 0; i < nLen; i++) {
+        jclass classRef = env->FindClass(gJObjectMapArray[i].szClassPath);
+        if (NULL == classRef) {
+            LOGE("InitializeJObjectMapArray: FindClass failed for [%s]",
+                    gJObjectMapArray[i].szClassPath);
+            return -1;
+        }
+
+        std::string methodSignature = "()L";
+        methodSignature.append(gJObjectMapArray[i].szClassPath);
+        methodSignature.append(";");
+
+        // Get the object form "getInstance"
+        jmethodID methodid = env->GetStaticMethodID(classRef, "getInstance",
+                methodSignature.c_str());
+        if (NULL == methodid) {
+            LOGE("InitializeJObjectMapArray: GetStaticMethodID failed for [%s]",
+                    gJObjectMapArray[i].szClassPath);
+            return -1;
+        }
+
+        // Get the singleton object
+        jobject objectRef = (jobject) env->CallStaticObjectMethod(classRef,
+                methodid);
+        if (NULL == objectRef) {
+            LOGE(
+                    "InitializeJObjectMapArray: CallStaticObjectMethod failed for [%s]",
+                    gJObjectMapArray[i].szClassPath);
+            return -1;
+        }
+
+        gJObjectMapArray[i].object = (jobject) env->NewGlobalRef(objectRef);
+        env->DeleteLocalRef(classRef);
+    }
+
+    LOGI("InitializeJObjectMapArray: Exit");
+    return 0;
+}
+
+jobject GetJObjectInstance(const char *szClassPath) {
+    unsigned int nLen = sizeof(gJObjectMapArray) / sizeof(JObjectMap);
+
+    jobject object = NULL;
+
+    for (unsigned int i = 0; i < nLen; i++) {
+        if (0 == strcmp(gJObjectMapArray[i].szClassPath, szClassPath)) {
+            object = gJObjectMapArray[i].object;
+            break;
+        }
+    }
+
+    return object;
+}
+
+void DeleteObjectMapArray(JNIEnv *env) {
+    LOGI("DeleteObjectMapArray: Enter");
+
+    unsigned int nLen = sizeof(gJObjectMapArray) / sizeof(JObjectMap);
+    for (unsigned int i = 0; i < nLen; i++) {
+        if (NULL != gJObjectMapArray[i].object) {
+            env->DeleteGlobalRef(gJObjectMapArray[i].object);
+            gJObjectMapArray[i].object = NULL;
+        }
+    }
+
+    LOGI("DeleteObjectMapArray: Exit");
+}
+
+JavaVM *EasySetupJVM::m_jvm = NULL;
+std::mutex EasySetupJVM::m_currentThreadMutex;
+JNIEnv *EasySetupJVM::getEnv() {
+    std::unique_lock < std::mutex > scoped_lock(m_currentThreadMutex);
+
+    if (NULL == m_jvm) {
+        LOGE("Failed to get JVM");
+        return NULL;
+    }
+
+    JNIEnv *env = NULL;
+    jint ret = m_jvm->GetEnv((void **) &env, JNI_CURRENT_VERSION);
+    switch (ret) {
+    case JNI_OK:
+        return env;
+    case JNI_EDETACHED:
+        if (0 > m_jvm->AttachCurrentThread(&env, NULL)) {
+            LOGE("Failed to attach current thread to env");
+            return NULL;
+        }
+        return env;
+    case JNI_EVERSION:
+        LOGE("JNI version not supported");
+        return NULL;
+    default:
+        LOGE("Failed to get the environment");
+        return NULL;
+    }
+}
+
+void EasySetupJVM::releaseEnv() {
+    std::unique_lock < std::mutex > scoped_lock(m_currentThreadMutex);
+
+    if (0 == m_jvm) {
+        LOGE("Failed to release JVM");
+        return;
+    }
+
+    m_jvm->DetachCurrentThread();
+}
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
+    LOGD("JNI_OnLoad: Enter");
+
+    if (!vm) {
+        LOGE("JNI_OnLoad: vm is invalid");
+        return JNI_ERR;
+    }
+
+    JNIEnv *env = NULL;
+    if (JNI_OK != vm->GetEnv((void **) &env, JNI_CURRENT_VERSION)) {
+        LOGE("JNI_OnLoad: Version check is failed!");
+        return JNI_ERR;
+    }
+
+    if (0 != InitializeJClassMapArray(env)) {
+        LOGE("JNI_OnLoad: Initialize JClass Array failed!");
+        return JNI_ERR;
+    }
+
+    if (0 != InitializeJObjectMapArray(env)) {
+        LOGE("JNI_OnLoad: Initialize JObject Array failed!");
+        return JNI_ERR;
+    }
+
+    jclass easySetupClassRef = GetJClass(
+            EASY_SETUP_SERVICE_NATIVE_API_CLASS_PATH);
+    if (NULL == easySetupClassRef) {
+        LOGE("JNI_OnLoad: GetJClass gEasySetupClass failed !");
+        return JNI_ERR;
+    }
+    env->RegisterNatives(easySetupClassRef, gEasySetupMethodTable,
+            gEasySetupMethodTableSize);
+
+    EasySetupJVM::m_jvm = vm;
+
+    LOGI("JNI_OnLoad: Exit");
+    return JNI_CURRENT_VERSION;
+}
+
+JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
+{
+    LOGD("JNI_OnUnload: Enter");
+
+    JNIEnv *env = NULL;
+    if (JNI_OK != vm->GetEnv((void **)&env, JNI_CURRENT_VERSION))
+    {
+        LOGE("JNI_OnLoad: Version check is failed!");
+        return;
+    }
+
+    // delete all class references
+    DeleteClassMapArray(env);
+
+    // delete all jobject
+    DeleteObjectMapArray(env);
+
+    LOGD("JNI_OnUnload: Exit");
+}
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_getter.cpp b/service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_getter.cpp
new file mode 100644 (file)
index 0000000..135f6a2
--- /dev/null
@@ -0,0 +1,148 @@
+/******************************************************************
+ *
+ * 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 "jni_getter.h"
+
+#include <string>
+
+#include "JniOcResource.h"
+
+#define LOG_TAG "TM_JGetter"
+
+bool JGetter::getJStringField(JNIEnv *env, jobject &object,
+        const char *fieldName, std::string &value) {
+    if (NULL == env || NULL == object || NULL == fieldName) {
+        LOGE("getJStringField invalid parameters");
+        return false;
+    }
+
+    jclass clazz = env->GetObjectClass(object);
+    if (NULL == clazz) {
+        LOGE("GetObjectClass failed [%s]", fieldName);
+        return false;
+    }
+
+    jfieldID fieldID = env->GetFieldID(clazz, fieldName, "Ljava/lang/String;");
+    if (0 == fieldID) {
+        LOGE("GetFieldID failed [%s]", fieldName);
+        env->DeleteLocalRef(clazz);
+        return false;
+    }
+
+    jstring jValue = (jstring) env->GetObjectField(object, fieldID);
+    if (NULL == jValue) {
+        LOGE("GetObjectField failed [%s]", fieldName);
+        env->DeleteLocalRef(clazz);
+        return false;
+    }
+
+    const char *cstr = env->GetStringUTFChars(jValue, 0);
+    if (cstr == NULL) {
+        LOGE("GetStringUTFChars failed");
+    } else {
+        value = cstr;
+        env->ReleaseStringUTFChars(jValue, cstr);
+    }
+
+    env->DeleteLocalRef(clazz);
+    env->DeleteLocalRef(jValue);
+
+    return true;
+}
+
+bool JGetter::getJBoolField(JNIEnv *env, jobject &object, const char *fieldName,
+        bool &value) {
+    if (NULL == env || NULL == object || NULL == fieldName) {
+        LOGE("getJBoolField invalid parameters");
+        return false;
+    }
+
+    jclass clazz = env->GetObjectClass(object);
+    if (NULL == clazz) {
+        LOGE("GetObjectClass failed");
+        return false;
+    }
+
+    jfieldID fieldID = env->GetFieldID(clazz, fieldName, "Z");
+    if (0 == fieldID) {
+        LOGE("GetFieldID failed [%s]", fieldName);
+        env->DeleteLocalRef(clazz);
+        return false;
+    }
+
+    value = env->GetBooleanField(object, fieldID);
+
+    env->DeleteLocalRef(clazz);
+
+    return true;
+}
+
+bool JGetter::getJIntField(JNIEnv *env, jobject &object, const char *fieldName,
+        int &value) {
+    if (NULL == env || NULL == object || NULL == fieldName) {
+        LOGE("getJIntField invalid parameters");
+        return false;
+    }
+
+    jclass clazz = env->GetObjectClass(object);
+    if (NULL == clazz) {
+        LOGE("GetObjectClass failed");
+        return false;
+    }
+
+    jfieldID fieldID = env->GetFieldID(clazz, fieldName, "I");
+    if (0 == fieldID) {
+        LOGE("GetFieldID failed [%s]", fieldName);
+        env->DeleteLocalRef(clazz);
+        return false;
+    }
+
+    value = env->GetIntField(object, fieldID);
+
+    env->DeleteLocalRef(clazz);
+
+    return true;
+}
+
+bool JGetter::getJObjectField(JNIEnv *env, jobject &object,
+        const char *fieldName, const char *fieldType, jobject &value) {
+    if (NULL == env || NULL == object || NULL == fieldName) {
+        return false;
+    }
+
+    jclass clazz = env->GetObjectClass(object);
+    if (NULL == clazz) {
+        return false;
+    }
+
+    jfieldID fieldID = env->GetFieldID(clazz, fieldName, fieldType);
+    if (0 == fieldID) {
+        LOGE("GetFieldID failed [%s][%s]", fieldName, fieldType);
+        return false;
+    }
+
+    value = env->GetObjectField(object, fieldID);
+    if (NULL == value) {
+        return false;
+    }
+
+    env->DeleteLocalRef(clazz);
+
+    return true;
+}
diff --git a/service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_object.cpp b/service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_object.cpp
new file mode 100644 (file)
index 0000000..51c6bf6
--- /dev/null
@@ -0,0 +1,67 @@
+#include "jni_object.h"
+
+//#define NULL 0
+#define LOG_TAG "TM_JObject"
+
+JObject::JObject(JNIEnv *env) :
+               m_pEnv(env), m_pObject(NULL), m_pClazz(NULL), m_fIsNewObject(true) {
+}
+
+JObject::JObject(JNIEnv *env, jobject obj) :
+               m_pEnv(NULL), m_pObject(NULL), m_pClazz(NULL), m_fIsNewObject(false) {
+       if (NULL == env || NULL == obj) {
+               return;
+       }
+
+       m_pEnv = env;
+       m_pObject = obj;
+       m_pClazz = m_pEnv->GetObjectClass(obj);
+}
+
+JObject::JObject(JNIEnv *env, const char *classPath) :
+               m_pEnv(NULL), m_pObject(NULL), m_pClazz(NULL), m_fIsNewObject(true) {
+       if (NULL == env || NULL == classPath) {
+               LOGI("JObject Invalid parameters");
+               return;
+       }
+
+       m_pEnv = env;
+       //m_pClazz = GetJClass( classPath );
+
+       if (NULL == m_pClazz) {
+               LOGE("GetJClass failed [%s]", classPath);
+               return;
+       }
+
+       jmethodID mid = env->GetMethodID(m_pClazz, "<init>", "()V");
+       if (NULL == mid) {
+               LOGE("GetMethodID failed [%s]", classPath);
+               return;
+       }
+
+       m_pObject = env->NewObject(m_pClazz, mid);
+}
+
+JObject::~JObject() {
+       if (m_pEnv) {
+               if (m_pObject && m_fIsNewObject) {
+                       m_pEnv->DeleteLocalRef(m_pObject);
+               }
+
+               if (m_pClazz && !m_fIsNewObject) {
+                       m_pEnv->DeleteLocalRef(m_pClazz);
+               }
+       }
+}
+
+jobject JObject::getObject() const {
+       return m_pObject;
+}
+
+void JObject::detachObject() {
+       if (m_fIsNewObject) {
+               m_fIsNewObject = false;
+               m_pClazz = NULL;
+       }
+}
+
diff --git a/service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_setter.cpp b/service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_setter.cpp
new file mode 100644 (file)
index 0000000..6c38004
--- /dev/null
@@ -0,0 +1,175 @@
+/******************************************************************
+ *
+ * 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 "jni_setter.h"
+
+#include <string>
+
+#include "JniOcResource.h"
+
+#define LOG_TAG "TM_JSetter"
+
+bool JSetter::setJStringField(JNIEnv *env, jobject &object,
+               const char *fieldName, const char *value) {
+       if (NULL == env || NULL == fieldName) {
+               LOGE("setJStringField invalid parameters");
+               return false;
+       }
+
+       jclass clazz = env->GetObjectClass(object);
+       if (NULL == clazz) {
+               LOGE("GetObjectClass failed");
+               return false;
+       }
+
+       jfieldID fieldID = env->GetFieldID(clazz, fieldName, "Ljava/lang/String;");
+       if (0 == fieldID) {
+               LOGE("GetFieldID failed [%s]", fieldName);
+               env->DeleteLocalRef(clazz);
+               return false;
+       }
+
+       jstring jvalue;
+       if (value != NULL && strlen(value) > 0) {
+               jclass strClass = env->FindClass("java/lang/String");
+               jmethodID ctorID = env->GetMethodID(strClass, "<init>",
+                               "([BLjava/lang/String;)V");
+               jbyteArray bytes = env->NewByteArray(strlen(value));
+               env->SetByteArrayRegion(bytes, 0, strlen(value), (jbyte *) value);
+               jstring encoding = env->NewStringUTF("utf-8");
+               jvalue = (jstring) env->NewObject(strClass, ctorID, bytes, encoding);
+               env->DeleteLocalRef(strClass);
+               env->DeleteLocalRef(bytes);
+               env->DeleteLocalRef(encoding);
+       } else {
+               jvalue = env->NewStringUTF("");
+       }
+
+       env->SetObjectField(object, fieldID, jvalue);
+
+       env->DeleteLocalRef(jvalue);
+       env->DeleteLocalRef(clazz);
+
+       return true;
+}
+
+bool JSetter::setJIntField(JNIEnv *env, jobject &object, const char *fieldName,
+               int value) {
+       if (NULL == env || NULL == fieldName) {
+               LOGE("setJIntField invalid paramter");
+               return false;
+       }
+
+       jclass clazz = env->GetObjectClass(object);
+       if (NULL == clazz) {
+               LOGE("GetObjectClass failed");
+               return false;
+       }
+
+       jfieldID fieldID = env->GetFieldID(clazz, fieldName, "I");
+       if (0 == fieldID) {
+               LOGE("GetFieldID failed [%s]", fieldName);
+               env->DeleteLocalRef(clazz);
+               return false;
+       }
+       env->SetIntField(object, fieldID, value);
+
+       env->DeleteLocalRef(clazz);
+
+       return true;
+}
+
+bool JSetter::setJLongField(JNIEnv *env, jobject &object, const char *fieldName,
+               jlong value) {
+       if (NULL == env || NULL == fieldName) {
+               LOGE("setJLongField invalid parameters");
+               return false;
+       }
+
+       jclass clazz = env->GetObjectClass(object);
+       if (NULL == clazz) {
+               LOGE("GetObjectClass failed");
+               return false;
+       }
+
+       jfieldID fieldID = env->GetFieldID(clazz, fieldName, "J");
+       if (0 == fieldID) {
+               LOGE("GetFieldID failed [%s]", fieldName);
+               env->DeleteLocalRef(clazz);
+               return false;
+       }
+       env->SetLongField(object, fieldID, value);
+
+       env->DeleteLocalRef(clazz);
+
+       return true;
+}
+
+bool JSetter::setJBoolField(JNIEnv *env, jobject &object, const char *fieldName,
+               bool value) {
+       if (NULL == env || NULL == fieldName) {
+               LOGE("setJBoolField invalid parameters");
+               return false;
+       }
+
+       jclass clazz = env->GetObjectClass(object);
+       if (NULL == clazz) {
+               LOGE("GetObjectClass failed");
+               return false;
+       }
+
+       jfieldID fieldID = env->GetFieldID(clazz, fieldName, "Z");
+       if (0 == fieldID) {
+               LOGE("GetFieldID failed [%s]", fieldName);
+               env->DeleteLocalRef(clazz);
+               return false;
+       }
+       env->SetBooleanField(object, fieldID, value);
+
+       env->DeleteLocalRef(clazz);
+
+       return true;
+}
+
+bool JSetter::setJObjectField(JNIEnv *env, jobject &object,
+               const char *fieldName, const char *fieldType, const jobject value) {
+       if (NULL == env || NULL == fieldName) {
+               LOGE("setJBoolField invalid parameters");
+               return false;
+       }
+
+       jclass clazz = env->GetObjectClass(object);
+       if (NULL == clazz) {
+               LOGE("GetObjectClass failed");
+               return false;
+       }
+
+       jfieldID fieldID = env->GetFieldID(clazz, fieldName, fieldType);
+       if (0 == fieldID) {
+               LOGE("GetFieldID failed [%s] [%s]", fieldName, fieldType);
+               env->DeleteLocalRef(clazz);
+               return false;
+       }
+       env->SetObjectField(object, fieldID, value);
+
+       env->DeleteLocalRef(clazz);
+
+       return true;
+}
+
diff --git a/service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_string.cpp b/service/easy-setup/sdk/mediator/android/jni/jniutil/src/jni_string.cpp
new file mode 100644 (file)
index 0000000..93bcdf4
--- /dev/null
@@ -0,0 +1,62 @@
+/******************************************************************
+ *
+ * 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 "jni_string.h"
+
+#define LOG_TAG "TM_JString"
+
+JString::JString(JNIEnv *env, jstring value) :
+               JObject(env, value) {
+       const char *buff = env->GetStringUTFChars(value, 0);
+
+       m_cstr = buff;
+
+       env->ReleaseStringUTFChars(value, buff);
+}
+
+JString::JString(JNIEnv *env, const char *value) :
+               JObject(env) {
+       m_cstr = value;
+
+       if (env) {
+               m_pObject = env->NewStringUTF(value);
+       }
+}
+
+JString::JString(JNIEnv *env, const std::string &value) :
+               JObject(env) {
+       m_cstr = value;
+
+       if (env) {
+               m_pObject = env->NewStringUTF(value.c_str());
+       }
+}
+
+JString::~JString() {
+}
+
+bool JString::getValue(std::string &value) {
+       value = m_cstr;
+       return true;
+}
+
+const char *JString::c_str() {
+       return m_cstr.c_str();
+}
+
diff --git a/service/easy-setup/sdk/mediator/inc/prov_adapter.h b/service/easy-setup/sdk/mediator/inc/prov_adapter.h
new file mode 100644 (file)
index 0000000..3ceb901
--- /dev/null
@@ -0,0 +1,58 @@
+//******************************************************************
+//
+// 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_MGR_H_
+#define __EASYSETUP_MGR_H_
+
+#include <string.h>
+
+#include "logger.h"
+#include "ocstack.h"
+#include "octypes.h"
+#include "common.h"
+
+#include "provisioning.h"
+
+
+//-----------------------------------------------------------------------------
+// Defines
+//-----------------------------------------------------------------------------
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+OCStackResult InitProvProcess();
+
+OCStackResult ResetProvProcess();
+
+OCStackResult RegisterCallback(
+        OCProvisioningStatusCB provisioningStatusCallback);
+
+void UnRegisterCallback();
+
+OCStackResult StartProvisioning(const EnrolleeNWProvInfo_t *netInfo);
+
+OCStackResult StopProvisioning(OCConnectivityType connectivityType);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/service/easy-setup/sdk/mediator/inc/provisioning.h b/service/easy-setup/sdk/mediator/inc/provisioning.h
new file mode 100644 (file)
index 0000000..5f63242
--- /dev/null
@@ -0,0 +1,117 @@
+//******************************************************************
+//
+// 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 __PROVISIONING_HANDLER_H_
+#define __PROVISIONING_HANDLER_H_
+
+#include "octypes.h"
+
+#include "logger.h"
+#include "ocstack.h"
+#include "common.h"
+
+//-----------------------------------------------------------------------------
+// Defines
+//-----------------------------------------------------------------------------
+#define EASY_SETUP_DEFAULT_CONTEXT_VALUE 0x99
+#define TAG "EASY_SETUP_PROVISIONING"
+
+//-----------------------------------------------------------------------------
+// Typedefs
+//-----------------------------------------------------------------------------
+
+/**
+ * List of methods that can be inititated from the client
+ */
+OCStackResult InitProvisioningHandler();
+
+OCStackResult TerminateProvisioningHandler();
+
+void *listeningFunc(void *);
+
+OCStackApplicationResult ProvisionEnrolleeResponse(void *ctx, OCDoHandle handle,
+                                                   OCClientResponse *clientResponse);
+
+OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const char *resUri,
+                                OCDevAddr *destination, int pauseBeforeStart);
+
+OCStackApplicationResult GetProvisioningStatusResponse(void *ctx, OCDoHandle handle,
+                                                       OCClientResponse *clientResponse);
+
+OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDevAddr *dest,
+                                 OCQualityOfService qos, OCClientResponseHandler cb,
+                                 OCRepPayload *payload,
+                                 OCHeaderOption *options, uint8_t numOptions);
+
+OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query,
+                                    const OCDevAddr *destination);
+
+OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo_t *netInfo,
+                                       OCProvisioningStatusCB provisioningStatusCallback,
+                                       char *findResQuery);
+
+void StopProvisioningProcess();
+
+OCStackApplicationResult FindProvisioningResourceResponse(void *ctx, OCDoHandle handle,
+                                                          OCClientResponse *clientResponse);
+
+void *FindProvisioningResource(void *data);
+
+//Invoke Provisioning Status Callback
+ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse,
+                                             ProvStatus provStatus);
+
+
+void LogProvisioningResponse(OCRepPayloadValue * val);
+
+bool ConfigEnrolleeObject(const EnrolleeNWProvInfo_t *netInfo);
+
+bool ClearMemory();
+
+void SuccessCallback(OCClientResponse * clientResponse);
+
+void ErrorCallback(ProvStatus status);
+
+bool ValidateEnrolleResponse(OCClientResponse * clientResponse);
+
+bool ValidateFinddResourceResponse(OCClientResponse * clientResponse);
+
+ProvisioningInfo *GetCallbackObjectOnSuccess(OCClientResponse *clientResponse,
+                                             ProvStatus provStatus);
+
+ProvisioningInfo *GetCallbackObjectOnError(ProvStatus status);
+
+ProvisioningInfo *CreateCallBackObject();
+
+bool ResetProgress();
+
+bool SetProgress(OCProvisioningStatusCB provisioningStatusCallback);
+
+bool InProgress();
+
+bool ValidateEasySetupParams(const EnrolleeNWProvInfo_t *netInfo,
+                             OCProvisioningStatusCB provisioningStatusCallback);
+
+bool IsSetupStopped();
+
+
+#endif
+
diff --git a/service/easy-setup/sdk/mediator/src/prov_adapter.cpp b/service/easy-setup/sdk/mediator/src/prov_adapter.cpp
new file mode 100755 (executable)
index 0000000..343b9c0
--- /dev/null
@@ -0,0 +1,96 @@
+//******************************************************************
+//
+// 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <sstream>
+
+#include "prov_adapter.h"
+
+//Use ipv4addr for both InitDiscovery and InitDeviceDiscovery
+char ipv4addr[IPV4_ADDR_SIZE] = {0};
+
+volatile static OCProvisioningStatusCB cbData = NULL;
+
+OCStackResult InitProvProcess() {
+
+
+    OCStackResult result = OC_STACK_ERROR;
+
+    if (InitProvisioningHandler() == OC_STACK_OK) {
+        result = OC_STACK_OK;
+        OIC_LOG(DEBUG, TAG, "InitProvisioningHandler returned Success");
+    } else {
+        result = OC_STACK_ERROR;
+        OIC_LOG_V(ERROR, TAG, "InitProvisioningHandler returned error = %s",
+                  result);
+    }
+
+    return result;
+}
+
+OCStackResult ResetProvProcess() {
+    return TerminateProvisioningHandler();
+}
+
+OCStackResult RegisterCallback(
+        OCProvisioningStatusCB provisioningStatusCallback) {
+    OCStackResult result = OC_STACK_OK;
+
+    if (provisioningStatusCallback != NULL) {
+        cbData = provisioningStatusCallback;
+    }
+    else {
+        result = OC_STACK_ERROR;
+        OIC_LOG(ERROR, TAG, "provisioningStatusCallback is NULL");
+    }
+
+    return result;
+}
+
+void UnRegisterCallback() {
+    if (cbData) {
+        cbData = NULL;
+    }
+}
+
+OCStackResult StartProvisioning(const EnrolleeNWProvInfo_t *netInfo) {
+
+    char findQuery[64] = {0};
+
+    if (netInfo->connType == CT_IP_USE_V4) {
+        snprintf(findQuery, sizeof(findQuery), UNICAST_PROVISIONING_QUERY,
+                 netInfo->netAddressInfo.WIFI.ipAddress, IP_PORT);
+    }
+
+    return StartProvisioningProcess(netInfo, cbData, findQuery);
+}
+
+OCStackResult StopProvisioning(OCConnectivityType connectivityType) {
+    OCStackResult result = OC_STACK_OK;
+
+    StopProvisioningProcess();
+
+    return result;
+}
+
diff --git a/service/easy-setup/sdk/mediator/src/provisioning.cpp b/service/easy-setup/sdk/mediator/src/provisioning.cpp
new file mode 100644 (file)
index 0000000..cf0d8a2
--- /dev/null
@@ -0,0 +1,562 @@
+//******************************************************************
+//
+// 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 "provisioning.h"
+
+//Standard includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <pthread.h>
+
+//EasySetup include files
+#include "ocpayload.h"
+#include "common.h"
+
+
+// External includes
+#include "logger.h"
+#include "oic_malloc.h"
+
+bool g_provisioningCondFlag = false;
+
+static EnrolleeNWProvInfo_t *netProvInfo;
+
+char szFindResourceQueryUri[64] = {0};
+
+/**
+ * @var cbData
+ * @brief Callback for providing provisioning status callback to application
+ */
+static OCProvisioningStatusCB cbData = NULL;
+
+
+void ErrorCallback(ProvStatus status) {
+    ProvisioningInfo *provInfo = GetCallbackObjectOnError(status);
+    cbData(provInfo);
+    ResetProgress();
+}
+
+
+OCStackResult InitProvisioningHandler() {
+    OCStackResult ret = OC_STACK_ERROR;
+    /* Initialize OCStack*/
+    if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK) {
+        OIC_LOG(ERROR, TAG, "OCStack init error");
+        return ret;
+    }
+
+
+    char *string = "listeningFunc invoked in a thread";
+
+    pthread_t thread_handle;
+
+    if (pthread_create(&thread_handle, NULL, listeningFunc, (void *) string)) {
+        OIC_LOG(DEBUG, TAG, "Thread creation failed");
+        return OC_STACK_ERROR;
+    }
+
+    pthread_join(thread_handle, NULL);
+
+    ResetProgress();
+
+    return OC_STACK_OK;
+}
+
+OCStackResult TerminateProvisioningHandler() {
+    OCStackResult ret = OC_STACK_ERROR;
+    if (OCStop() != OC_STACK_OK) {
+        OIC_LOG(ERROR, TAG, "OCStack stop error");
+    }
+
+    g_provisioningCondFlag = true;
+
+    ret = OC_STACK_OK;
+    return ret;
+}
+
+void *listeningFunc(void *data) {
+    while (!g_provisioningCondFlag) {
+        OCStackResult result;
+
+        result = OCProcess();
+
+        if (result != OC_STACK_OK) {
+            OIC_LOG(ERROR, TAG, "OCStack stop error");
+        }
+
+        // To minimize CPU utilization we may wish to do this with sleep
+        sleep(1);
+    }
+    return NULL;
+}
+
+
+OCStackApplicationResult ProvisionEnrolleeResponse(void *ctx, OCDoHandle handle,
+                                                   OCClientResponse *clientResponse) {
+    OIC_LOG_V(DEBUG, TAG, "INSIDE ProvisionEnrolleeResponse");
+
+    // If user stopped the process then return from this function;
+    if (IsSetupStopped()) {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        ClearMemory();
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    ProvisioningInfo *provInfo;
+
+    if (!ValidateEnrolleResponse(clientResponse)) {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    char *tnn;
+    char *cd;
+
+    OCRepPayload *input = (OCRepPayload * )(clientResponse->payload);
+
+    while (input) {
+
+        int64_t ps;
+        if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_PS, &ps)) {
+
+            if (ps == 1) {
+                input = input->next;
+                continue;
+            }
+            else {
+                OIC_LOG_V(DEBUG, TAG, "PS is NOT proper");
+                goto Error;
+
+            }
+        }
+
+        if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn)) {
+            if (!strcmp(tnn, netProvInfo->netAddressInfo.WIFI.ssid)) {
+                OIC_LOG_V(DEBUG, TAG, "SSID is proper");
+                input = input->next;
+                continue;
+            }
+            else {
+                OIC_LOG_V(DEBUG, TAG, "SSID is NOT proper");
+                goto Error;
+            }
+        }
+
+        if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) {
+            if (!strcmp(cd, netProvInfo->netAddressInfo.WIFI.pwd)) {
+                OIC_LOG_V(DEBUG, TAG, "Password is proper");
+                input = input->next;
+                continue;
+            }
+            else {
+                OIC_LOG_V(DEBUG, TAG, "Password is NOT proper");
+                goto Error;
+            }
+        }
+
+        LogProvisioningResponse(input->values);
+
+        input = input->next;
+
+    }
+
+    SuccessCallback(clientResponse);
+
+    return OC_STACK_KEEP_TRANSACTION;
+
+    Error:
+    {
+
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+}
+
+OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo_t *netInfo,
+                                       OCProvisioningStatusCB provisioningStatusCallback,
+                                       char *findResQuery) {
+
+    OCStackResult result = OC_STACK_ERROR;
+
+    strncpy(szFindResourceQueryUri, findResQuery, sizeof(szFindResourceQueryUri, findResQuery) - 1);
+
+    char *string = "Starting provisioning process ";
+
+    pthread_t thread_handle;
+
+    if (!ValidateEasySetupParams(netInfo, provisioningStatusCallback)) {
+        goto Error;
+    }
+
+    if (!SetProgress(provisioningStatusCallback)) {
+        // Device provisioning session is running already.
+        OIC_LOG(INFO, TAG, PCF("Device provisioning session is running already"));
+        goto Error;
+    }
+
+    if (!ConfigEnrolleeObject(netInfo)) {
+        goto Error;
+    }
+
+    if (pthread_create(&thread_handle, NULL, FindProvisioningResource, (void *) string)) {
+        goto Error;
+
+    }
+
+    pthread_join(thread_handle, NULL);
+
+
+    return OC_STACK_OK;
+
+    Error:
+    {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        ClearMemory();
+        return OC_STACK_ERROR;
+    }
+
+}
+
+void StopProvisioningProcess() {
+    //Only basis test is done for below API
+    ResetProgress();
+}
+
+bool ClearMemory() {
+
+    OIC_LOG(DEBUG, TAG, "thread_pool_add_task of FindProvisioningResource failed");
+    return true;
+
+}
+
+bool ConfigEnrolleeObject(const EnrolleeNWProvInfo_t *netInfo) {
+
+    //Copy Network Provisioning  Information
+    netProvInfo = (EnrolleeNWProvInfo_t *) OICCalloc(1, sizeof(EnrolleeNWProvInfo_t));
+
+    if (netProvInfo == NULL) {
+        OIC_LOG(ERROR, TAG, "Invalid input..");
+        return false;
+    }
+
+    memcpy(netProvInfo, netInfo, sizeof(EnrolleeNWProvInfo_t));
+
+    OIC_LOG_V(DEBUG, TAG, "Network Provisioning Info. SSID = %s",
+              netProvInfo->netAddressInfo.WIFI.ssid);
+
+    OIC_LOG_V(DEBUG, TAG, "Network Provisioning Info. PWD = %s",
+              netProvInfo->netAddressInfo.WIFI.pwd);
+
+    return true;
+
+}
+
+void LogProvisioningResponse(OCRepPayloadValue * val) {
+
+    switch (val->type) {
+        case OCREP_PROP_NULL:
+            OIC_LOG_V(DEBUG, TAG, "\t\t%s: NULL", val->name);
+            break;
+        case OCREP_PROP_INT:
+            OIC_LOG_V(DEBUG, TAG, "\t\t%s(int):%lld", val->name, val->i);
+            break;
+        case OCREP_PROP_DOUBLE:
+            OIC_LOG_V(DEBUG, TAG, "\t\t%s(double):%f", val->name, val->d);
+            break;
+        case OCREP_PROP_BOOL:
+            OIC_LOG_V(DEBUG, TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
+            break;
+        case OCREP_PROP_STRING:
+            OIC_LOG_V(DEBUG, TAG, "\t\t%s(string):%s", val->name, val->str);
+            break;
+        case OCREP_PROP_OBJECT:
+            // Note: Only prints the URI (if available), to print further, you'll
+            // need to dig into the object better!
+            OIC_LOG_V(DEBUG, TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
+            break;
+        case OCREP_PROP_ARRAY:
+            switch (val->arr.type) {
+                case OCREP_PROP_INT:
+                    OIC_LOG_V(DEBUG, TAG, "\t\t%s(int array):%lld x %lld x %lld", val->name,
+                              val->arr.dimensions[0], val->arr.dimensions[1],
+                              val->arr.dimensions[2]);
+                    break;
+                case OCREP_PROP_DOUBLE:
+                    OIC_LOG_V(DEBUG, TAG, "\t\t%s(double array):%lld x %lld x %lld", val->name,
+                              val->arr.dimensions[0], val->arr.dimensions[1],
+                              val->arr.dimensions[2]);
+                    break;
+                case OCREP_PROP_BOOL:
+                    OIC_LOG_V(DEBUG, TAG, "\t\t%s(bool array):%lld x %lld x %lld", val->name,
+                              val->arr.dimensions[0], val->arr.dimensions[1],
+                              val->arr.dimensions[2]);
+                    break;
+                case OCREP_PROP_STRING:
+                    OIC_LOG_V(DEBUG, TAG, "\t\t%s(string array):%lld x %lld x %lld", val->name,
+                              val->arr.dimensions[0], val->arr.dimensions[1],
+                              val->arr.dimensions[2]);
+                    break;
+                case OCREP_PROP_OBJECT:
+                    OIC_LOG_V(DEBUG, TAG, "\t\t%s(OCRep array):%lld x %lld x %lld", val->name,
+                              val->arr.dimensions[0], val->arr.dimensions[1],
+                              val->arr.dimensions[2]);
+                    break;
+                default:
+                    break;
+            }
+            break;
+        default:
+            break;
+    }
+}
+
+OCStackResult FindNetworkResource() {
+    OCStackResult ret = OC_STACK_ERROR;
+    if (OCStop() != OC_STACK_OK) {
+        OIC_LOG(ERROR, TAG, "OCStack stop error");
+    }
+
+    return ret;
+}
+
+ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse,
+                                             ProvStatus provStatus) {
+
+    ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo));
+
+    if (provInfo == NULL) {
+        OIC_LOG_V(ERROR, TAG, "Failed to allocate memory");
+        return NULL;
+    }
+
+    OCDevAddr *devAddr = (OCDevAddr *) OICCalloc(1, sizeof(OCDevAddr));
+
+    if (devAddr == NULL) {
+        OIC_LOG_V(ERROR, TAG, "Failed to allocate memory");
+        return NULL;
+    }
+
+    strncpy(devAddr->addr, clientResponse->addr->addr, sizeof(devAddr->addr));
+    devAddr->port = clientResponse->addr->port;
+
+    provInfo->provDeviceInfo.addr = devAddr;
+
+    provInfo->provStatus = provStatus;
+
+    return provInfo;
+}
+
+
+bool InProgress() {
+
+    // It means already Easy Setup provisioning session is going on.
+    if (NULL != cbData) {
+        OIC_LOG(ERROR, TAG, "Easy setup session is already in progress");
+        return true;
+    }
+
+    return false;
+}
+
+bool SetProgress(OCProvisioningStatusCB provisioningStatusCallback) {
+
+    if (InProgress())
+        return false;
+
+    cbData = provisioningStatusCallback;
+
+
+    return true;
+}
+
+bool ResetProgress() {
+
+    cbData = NULL;
+    return true;
+}
+
+ProvisioningInfo *CreateCallBackObject() {
+
+    ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo));
+
+    if (provInfo == NULL) {
+        OIC_LOG_V(ERROR, TAG, "Failed to allocate memory");
+        return NULL;
+    }
+
+    OCDevAddr *devAddr = (OCDevAddr *) OICCalloc(1, sizeof(OCDevAddr));
+
+    if (devAddr == NULL) {
+        OIC_LOG_V(ERROR, TAG, "Failed to allocate memory");
+        return NULL;
+    }
+
+    provInfo->provDeviceInfo.addr = devAddr;
+
+    return provInfo;
+
+}
+
+ProvisioningInfo *GetCallbackObjectOnError(ProvStatus status) {
+
+    ProvisioningInfo *provInfo = CreateCallBackObject();
+    strncpy(provInfo->provDeviceInfo.addr->addr, netProvInfo->netAddressInfo.WIFI.ipAddress,
+            sizeof(provInfo->provDeviceInfo.addr->addr));
+    provInfo->provDeviceInfo.addr->port = IP_PORT;
+    provInfo->provStatus = status;
+    return provInfo;
+}
+
+ProvisioningInfo *GetCallbackObjectOnSuccess(OCClientResponse *clientResponse,
+                                             ProvStatus provStatus) {
+    ProvisioningInfo *provInfo = CreateCallBackObject();
+    strncpy(provInfo->provDeviceInfo.addr->addr, clientResponse->addr->addr,
+            sizeof(provInfo->provDeviceInfo.addr->addr));
+    provInfo->provDeviceInfo.addr->port = clientResponse->addr->port;
+    provInfo->provStatus = provStatus;
+    return provInfo;
+}
+
+bool ValidateFinddResourceResponse(OCClientResponse * clientResponse) {
+
+    if (!(clientResponse) || !(clientResponse->payload)) {
+
+        OIC_LOG_V(INFO, TAG, "ProvisionEnrolleeResponse received Null clientResponse");
+
+        return false;
+
+    }
+    return true;
+}
+
+bool ValidateEnrolleResponse(OCClientResponse * clientResponse) {
+
+    if (!(clientResponse) || !(clientResponse->payload)) {
+
+        OIC_LOG_V(INFO, TAG, "ProvisionEnrolleeResponse received Null clientResponse");
+
+        return false;
+
+    }
+
+    if (clientResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION) {
+
+        OIC_LOG_V(DEBUG, TAG, "Incoming payload not a representation");
+        return false;
+
+    }
+
+    // If flow reachese here means no error condition hit.
+    return true;
+
+}
+
+void SuccessCallback(OCClientResponse * clientResponse) {
+    ProvisioningInfo *provInfo = GetCallbackObjectOnSuccess(clientResponse, DEVICE_PROVISIONED);
+    cbData(provInfo);
+    ResetProgress();
+}
+
+void *FindProvisioningResource(void *data) {
+
+    // If user stopped the process before thread get scheduled then check and return from this function;
+    if (IsSetupStopped()) {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        ClearMemory();
+        return NULL;
+    }
+
+    OCStackResult ret = OC_STACK_ERROR;
+
+    OIC_LOG_V(DEBUG, TAG, "szFindResourceQueryUri = %s", szFindResourceQueryUri);
+
+    OCCallbackData ocCBData;
+
+    ocCBData.cb = FindProvisioningResourceResponse;
+    ocCBData.context = (void *) EASY_SETUP_DEFAULT_CONTEXT_VALUE;
+    ocCBData.cd = NULL;
+
+
+    ret = OCDoResource(NULL, OC_REST_DISCOVER, szFindResourceQueryUri, NULL, NULL,
+                       netProvInfo->connType, OC_LOW_QOS,
+                       &ocCBData, NULL, 0);
+
+    if (ret != OC_STACK_OK) {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        ClearMemory();
+    }
+
+    return NULL;
+}
+
+OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDevAddr *dest,
+                                 OCQualityOfService qos, OCClientResponseHandler cb,
+                                 OCRepPayload *payload,
+                                 OCHeaderOption *options, uint8_t numOptions) {
+    OCStackResult ret;
+    OCCallbackData cbData;
+
+    cbData.cb = cb;
+    cbData.context = (void *) EASY_SETUP_DEFAULT_CONTEXT_VALUE;
+    cbData.cd = NULL;
+
+    ret = OCDoResource(NULL, method, query, dest, (OCPayload *) payload, netProvInfo->connType, qos,
+                       &cbData, options, numOptions);
+
+    if (ret != OC_STACK_OK) {
+        OIC_LOG_V(ERROR, TAG, "OCDoResource returns error %d with method %d", ret, method);
+    }
+
+    return ret;
+}
+
+OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const char *resUri,
+                                OCDevAddr *destination, int pauseBeforeStart) {
+
+
+    // This sleep is required in case of BLE provisioning due to packet drop issue.
+    OIC_LOG_V(INFO, TAG, "Sleeping for %d seconds", pauseBeforeStart);
+    sleep(pauseBeforeStart);
+    OIC_LOG_V(INFO, TAG, "\n\nExecuting ProvisionEnrollee%s", __func__);
+
+    OCRepPayload *payload = OCRepPayloadCreate();
+
+    OCRepPayloadSetUri(payload, resUri);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_TNN, netProvInfo->netAddressInfo.WIFI.ssid);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CD, netProvInfo->netAddressInfo.WIFI.pwd);
+
+    OIC_LOG_V(DEBUG, TAG, "OCPayload ready for ProvisionEnrollee");
+
+    OCStackResult ret = InvokeOCDoResource(query, OC_REST_PUT, destination, OC_HIGH_QOS,
+                                           ProvisionEnrolleeResponse, payload, NULL, 0);
+
+    return ret;
+}
+
+bool IsSetupStopped() {
+    return (cbData == NULL) ? true : false;
+}
+
+
diff --git a/service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp b/service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp
new file mode 100755 (executable)
index 0000000..b7afd28
--- /dev/null
@@ -0,0 +1,196 @@
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// NOTE : Keeping Wifi provisioning in this file to have adaptability while doing OOPs refactoring 
+
+#include "provisioning.h"
+
+//Standard includes
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <pthread.h>
+
+//EasySetup include files
+#include "ocpayload.h"
+#include "common.h"
+
+// External includes
+#include "logger.h"
+#include "oic_malloc.h"
+
+
+static EnrolleeNWProvInfo_t *netProvInfo;
+
+/**
+ * @var cbData
+ * @brief Callback for providing provisioning status callback to application
+ */
+static OCProvisioningStatusCB cbData = NULL;
+
+
+OCStackApplicationResult GetProvisioningStatusResponse(void *ctx, OCDoHandle handle,
+                                                       OCClientResponse *clientResponse) {
+
+
+    // If user stopped the process then return from this function;
+    if (IsSetupStopped()) {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        ClearMemory();
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+
+    ProvisioningInfo *provInfo;
+
+    if (!ValidateEnrolleResponse(clientResponse)) {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        ClearMemory();
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    OCRepPayload *input = (OCRepPayload * )(clientResponse->payload);
+
+    char query[OIC_STRING_MAX_VALUE] =
+            {'\0'};
+    char resURI[MAX_URI_LENGTH] =
+            {'\0'};
+
+    OIC_LOG_V(DEBUG, TAG, "resUri = %s", input->uri);
+
+    strncpy(resURI, input->uri, sizeof(resURI) - 1);
+
+    snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, IP_PORT,
+             resURI);
+
+    //OCPayloadLogRep(DEBUG,TAG,input);
+
+    if (ProvisionEnrollee(OC_HIGH_QOS, query, OC_RSRVD_ES_URI_PROV, clientResponse->addr, 0)
+        != OC_STACK_OK) {
+        OIC_LOG(INFO, TAG,
+                "GetProvisioningStatusResponse received NULL clientResponse.Invoking Provisioing Status Callback");
+
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        ClearMemory();
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    return OC_STACK_KEEP_TRANSACTION;
+
+}
+
+OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query,
+                                    const OCDevAddr *destination) {
+    OCStackResult ret = OC_STACK_ERROR;
+    OCHeaderOption options[MAX_HEADER_OPTIONS];
+
+    OIC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
+
+    uint8_t option0[] =
+            {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+    uint8_t option1[] =
+            {11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
+    memset(options, 0, sizeof(OCHeaderOption) * MAX_HEADER_OPTIONS);
+    options[0].protocolID = OC_COAP_ID;
+    options[0].optionID = 2048;
+    memcpy(options[0].optionData, option0, sizeof(option0));
+    options[0].optionLength = 10;
+    options[1].protocolID = OC_COAP_ID;
+    options[1].optionID = 3000;
+    memcpy(options[1].optionData, option1, sizeof(option1));
+    options[1].optionLength = 10;
+
+    ret = InvokeOCDoResource(query, OC_REST_GET, destination, OC_HIGH_QOS,
+                             GetProvisioningStatusResponse, NULL, options, 2);
+    return ret;
+}
+
+
+// This is a function called back when a device is discovered
+OCStackApplicationResult FindProvisioningResourceResponse(void *ctx, OCDoHandle handle,
+                                                          OCClientResponse *clientResponse) {
+
+    OIC_LOG(INFO, TAG, PCF("Entering FindProvisioningResourceResponse"));
+
+    // If user stopped the process then return from this function;
+    if (IsSetupStopped()) {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        ClearMemory();
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+
+    if (!ValidateFinddResourceResponse(clientResponse)) {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    OCStackApplicationResult response = OC_STACK_DELETE_TRANSACTION;
+
+    ProvisioningInfo *provInfo;
+    char szQueryUri[64] =
+            {0};
+
+    OCDiscoveryPayload *discoveryPayload = (OCDiscoveryPayload * )(clientResponse->payload);
+
+    // Need to conform if below check is required or not. As Null check of clientResponse->payload is already performed above
+    if (!discoveryPayload) {
+        OIC_LOG_V(DEBUG, TAG, "Failed To parse");
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    OIC_LOG_V(DEBUG, TAG, "resUri = %s", discoveryPayload->resources->uri);
+
+    snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY,
+             clientResponse->devAddr.addr, IP_PORT, discoveryPayload->resources->uri);
+
+    OIC_LOG_V(DEBUG, TAG, "query before GetProvisioningStatus call = %s", szQueryUri);
+
+    if (GetProvisioningStatus(OC_HIGH_QOS, szQueryUri, &clientResponse->devAddr) != OC_STACK_OK) {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    return OC_STACK_KEEP_TRANSACTION;
+
+}
+
+bool ValidateEasySetupParams(const EnrolleeNWProvInfo_t *netInfo,
+                             OCProvisioningStatusCB provisioningStatusCallback) {
+
+    if (netInfo == NULL || strlen(netInfo->netAddressInfo.WIFI.ipAddress) == 0) {
+        OIC_LOG(ERROR, TAG, "Request URI is NULL");
+        return false;
+    }
+
+    if (provisioningStatusCallback == NULL) {
+        OIC_LOG(ERROR, TAG, "ProvisioningStatusCallback is NULL");
+        return false;
+    }
+
+    return true;
+
+}
+
+
+