- Add some files for RequestPropertyData, DataProvisioning, SecurityProvisioning.
- Delete unused files.(old feature class)
Change-Id: Icc0eb21d0a63310f38b331e2166b55998fa24c25
Signed-off-by: Heewon Park <h_w.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9115
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
+++ /dev/null
-/**
- * ***************************************************************
- * <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 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
+++ /dev/null
-/**
- * ***************************************************************
- * <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 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
+++ /dev/null
-/**
- * ***************************************************************
- * <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.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.core.EnrolleeInfo;
-import org.iotivity.service.easysetup.core.EnrolleeOnBoardingInfo;
-import org.iotivity.service.easysetup.core.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;
- }
- }
-
- /**
- * 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);
-
- }
-}
package org.iotivity.service.easysetup.mediator;
+import org.iotivity.service.easysetup.mediator.enums.ESCloudProvState;
+import org.iotivity.service.easysetup.mediator.enums.ESResult;
+
/**
* This interface facilitates Application to get progress & result of Cloud provisioning
* process in easy setup
--- /dev/null
+/**
+ * ***************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import org.iotivity.service.easysetup.mediator.enums.WIFI_AUTHTYPE;
+import org.iotivity.service.easysetup.mediator.enums.WIFI_ENCTYPE;
+
+/**
+ * This class contains on data provisioning information.
+ * It implements ProvisioningInfo interface and provide configuration object specific to data registration
+ */
+public class DataProvInfo {
+
+ private final String mSsid;
+ private final String mPwd;
+ private final WIFI_AUTHTYPE mAuthType;
+ private final WIFI_ENCTYPE mEncType;
+ private final String mLanguage;
+ private final String mCountry;
+
+ public DataProvInfo(String ssid, String pwd, WIFI_AUTHTYPE authType, WIFI_ENCTYPE encType,
+ String language, String country)
+ {
+ mSsid = ssid;
+ mPwd = pwd;
+ mAuthType = authType;
+ mEncType = encType;
+ mLanguage = language;
+ mCountry = country;
+ }
+
+ public String getSsid()
+ {
+ return mSsid;
+ }
+
+ public String getPwd()
+ {
+ return mPwd;
+ }
+
+ public WIFI_AUTHTYPE getAuthType()
+ {
+ return mAuthType;
+ }
+
+ public WIFI_ENCTYPE getEncType()
+ {
+ return mEncType;
+ }
+
+ public String getLanguage()
+ {
+ return mLanguage;
+ }
+
+ public String getCountry()
+ {
+ return mCountry;
+ }
+}
/**
* ***************************************************************
- * <p/>
+ *
* Copyright 2016 Samsung Electronics All Rights Reserved.
- * <p/>
- * <p/>
- * <p/>
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- * <p/>
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * <p/>
+ *
* ****************************************************************
*/
package org.iotivity.service.easysetup.mediator;
-public interface IProvisionStatusNativeHandler {
-
- public void onStatusRecieved(int state);
+import org.iotivity.service.easysetup.mediator.DataProvisioningCallback;
+public abstract class DataProvisioningCallback {
+ public abstract void onProgress(DataProvisioningStatus status);
}
--- /dev/null
+/**
+ * ***************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import org.iotivity.service.easysetup.mediator.enums.ESDataProvState;
+import org.iotivity.service.easysetup.mediator.enums.ESResult;
+
+public class DataProvisioningStatus
+{
+ private ESResult m_result;
+ private ESDataProvState m_state;
+
+ public DataProvisioningStatus(int result, int state)
+ {
+ m_result = ESResult.fromInt(result);
+ m_state = ESDataProvState.fromInt(state);
+ }
+
+ public ESResult getESResult()
+ {
+ return m_result;
+ }
+
+ public ESDataProvState getESDataProvState()
+ {
+ return m_state;
+ }
+};
-/**
- * ***************************************************************
- * <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;
-
-/**
- * This interface contains the connection details of the enrollee device
- */
-public interface OnBoardingConnection {
-
- /**
- * This method returns the implementation of the Connection
- *
- * @return implementation
- */
- public Object getConnection();
-
- /**
- * This method returns description on the connectivity.
- *
- * @return description
- */
- public String getDesc();
-
- /**
- * This method is used to know if the device is connected or not
- *
- * @return True if connected or False
- */
- public boolean isConnected();
-
-}
+/**\r
+ * ***************************************************************\r
+ *\r
+ * Copyright 2016 Samsung Electronics All Rights Reserved.\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.mediator;\r
+\r
+public class DeviceConfig\r
+{\r
+ private final String mId;\r
+ private final String mName;\r
+ private final String mLanguage;\r
+ private final String mCountry;\r
+\r
+ public DeviceConfig(String id, String name, String language, String country)\r
+ {\r
+ mId = id;\r
+ mName = name;\r
+ mLanguage = language;\r
+ mCountry = country;\r
+ }\r
+\r
+ public String getId()\r
+ {\r
+ return mId;\r
+ }\r
+\r
+ public String getName()\r
+ {\r
+ return mName;\r
+ }\r
+\r
+ public String getLanguage()\r
+ {\r
+ return mLanguage;\r
+ }\r
+\r
+ public String getCountry()\r
+ {\r
+ return mCountry;\r
+ }\r
+}\r
+++ /dev/null
-/**
- * ***************************************************************
- * <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 android.content.Context;
-import android.util.Log;
-
-import java.io.IOException;
-import java.util.ArrayList;
-
-/**
- * This is facade class, a single point of contact for Application.
- * It contains set of APIs to do easy setup of the enrolling device.
- * ON-BOARDING - This is a step to establish connectivity between the device & Mediator device.
- * PROVISION - This is a step where the netowork's detail & credentials are given to the
- * enrolling device.
- */
-public class EasySetupService {
-
- private static final String TAG = EasySetupService.class.getName();
-
- private static EasySetupService sInstance;
-
- private final EasySetupStatus mCallback;
-
- private ArrayList<EnrolleeDevice> mEnrolleeDeviceList;
-
- private final ProvisioningCallback mProvisioningCallback;
-
- private static Context mContext;
-
- protected RemoteEnrollee mRemoteEnrollee;
-
- //function to call the native createEnrolleeDevice
- private native RemoteEnrollee nativeCreateEnrolleeDevice(String ip, String ssid,
- String password, int type, boolean isSecured );
-
- static {
- // Load Easy Setup JNI interface
- System.loadLibrary("ESMediatorRich");
- System.loadLibrary("easysetup-jni");
- }
-
- private EasySetupService(EasySetupStatus callback) {
- mCallback = callback;
- mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);
- mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();
- mContext = null;
- }
-
- /**
- * Gives a singleton instance of Easy setup service and initialize the service
- *
- * @param callback Application needs to provide this callback to receive the status of easy
- * setup process.
- */
-
- public synchronized static EasySetupService getInstance(Context context, EasySetupStatus
- callback) {
- if (sInstance == null) {
- sInstance = new EasySetupService(callback);
- mContext = context;
- }
- return sInstance;
- }
-
- /**
- * Reset the Easy setup Service
- */
-
- public void finish() {
- //Call the stop Provisioning
- for (EnrolleeDevice enrolleeDevice : mEnrolleeDeviceList) {
- enrolleeDevice.stopProvisioningProcess();
- }
- }
-
- /**
- * Starts Easy setup process for the enrolling device.
- *
- * @param enrolledevice Device to be enrolled in network
- * @throws IOException Throws exception in case of any connection error.
- */
-
- public synchronized void startSetup(final EnrolleeDevice enrolledevice) throws IOException,ESException {
-
- if (null == enrolledevice) {
- throw new ESException("enrolledevice is NULL");
- }
-
- mEnrolleeDeviceList.add(enrolledevice);
-
- // Starts the provisioning directly if the device is already on boarded on the network.
- if (enrolledevice.onBoarded()) {
- if(null == enrolledevice.mRemoteEnrollee){
- //create Native RemoteEnrollee
- WiFiProvConfig config = (WiFiProvConfig)enrolledevice.mProvConfig;
- String ip = "";
- String ssid = config.getSsId();
- String password = config.getPassword();
- int connectivityType = config.getConnType().getValue();
- boolean isSecured = config.isSecured();
-
- //native call
- mRemoteEnrollee = nativeCreateEnrolleeDevice(ip, ssid, password,
- connectivityType, isSecured);
- enrolledevice.mRemoteEnrollee = mRemoteEnrollee;
- }
- enrolledevice.startProvisioning(mProvisioningCallback);
- return;
- }
- enrolledevice.mState = EnrolleeState.DEVICE_ON_BOARDING_STATE;
- mCallback.onProgress(enrolledevice);
- enrolledevice.startOnBoarding(new OnBoardingCallback() {
-
- @Override
- public void onFinished(OnBoardingConnection connection) {
- if (connection.isConnected()) {
- Log.i(TAG, "On boarding is successful ");
- // Start provisioning here
- enrolledevice.mState = EnrolleeState.DEVICE_ON_BOARDED_STATE;
- mCallback.onProgress(enrolledevice);
- enrolledevice.setConnection(connection);
-
- //create a native RemoteEnrollee with network info
- IpOnBoardingConnection conn = (IpOnBoardingConnection) connection;
- WiFiProvConfig config = (WiFiProvConfig)enrolledevice.mProvConfig;
- String ip = conn.getIp();
- String ssid = config.getSsId();
- String password = config.getPassword();
- int connectivityType = config.getConnType().getValue();
- boolean isSecured = config.isSecured();
-
- //native call
- mRemoteEnrollee = nativeCreateEnrolleeDevice(ip, ssid, password,
- connectivityType, isSecured);
-
- enrolledevice.mRemoteEnrollee = mRemoteEnrollee;
-
- /* Delay is set according to Soft AP host and Mediator platform;
- * For Android with Soft AP it is 2000 ms
- */
- delayProvisioning(connection);
- enrolledevice.startProvisioning(mProvisioningCallback);
- } else {
- enrolledevice.mState = EnrolleeState.DEVICE_INIT_STATE;
- mProvisioningCallback.onFinished(enrolledevice);
- }
- }
- });
- }
-
- /**
- * Stops on-going Easy setup process for enrolling device.
- *
- * @param enrolleedevice Device to be enrolled in network
- */
- public synchronized void stopSetup(EnrolleeDevice enrolleedevice) throws ESException {
-
- if (null == enrolleedevice) {
- throw new ESException("enrolledevice is NULL");
- }
-
- if (mEnrolleeDeviceList.contains(enrolleedevice)) {
- if (enrolleedevice.mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {
- Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");
- enrolleedevice.stopOnBoardingProcess();
- }else if (enrolleedevice.mState == EnrolleeState.DEVICE_PROVISIONING_STATE) {
- Log.i(TAG, "stopEnrolleeProvisioning for enrolleedevice");
- enrolleedevice.stopProvisioningProcess();
- }
- enrolleedevice.mState = EnrolleeState.DEVICE_INIT_STATE;
- mCallback.onProgress(enrolleedevice);
- mEnrolleeDeviceList.remove(enrolleedevice);
- }
- }
-
- class ProvisioningCallbackImpl extends ProvisioningCallback {
-
- private final EasySetupStatus mCallback;
-
- ProvisioningCallbackImpl(EasySetupStatus callback) {
- mCallback = callback;
- }
-
- @Override
- public void onFinished(EnrolleeDevice enrolledevice) {
- synchronized (EasySetupService.this) {
- if (mEnrolleeDeviceList.contains(enrolledevice)) {
- Log.i(TAG, "onFinished() is received " + enrolledevice.isSetupSuccessful());
- mCallback.onFinished(enrolledevice);
- mEnrolleeDeviceList.remove(enrolledevice);
- }
- }
- }
-
- @Override
- public void onProgress(EnrolleeDevice enrolledevice) {
- mCallback.onProgress(enrolledevice);
- }
- }
-
- private void delayProvisioning(OnBoardingConnection conn) {
- if (((IpOnBoardingConnection)conn).getThrottlingDelay()>0) {
- try {
- Log.i(TAG, "waiting for 20 seconds to start provisioning");
- Thread.sleep(20000);//Sleep for allowing thin device to start the services
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * ***************************************************************
- * <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;
-
-/**
- * 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 enrolleeDevice Gives state of the device changed during easy setup process
- */
- public void onProgress(EnrolleeDevice enrolleeDevice);
-
-}
+++ /dev/null
-/**
- * ***************************************************************
- * <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;
-
-/**
- * This is an abstract class represents the device being provisioned into the network. The
- * device being enrolled or provisioned into the network is called Enrollee.
- * Application has to extend this class and provide implementation of abstract methods according
- * to the ON-BOARDING & PROVISION connectivity i.e. WiFi etc.
- */
-
-public abstract class EnrolleeDevice {
-
- protected EnrolleeState mState;
- private EnrolleeSetupError mError;
-
- OnBoardingConnection mConnection;
- final ProvisioningConfig mProvConfig;
- final OnBoardingConfig mOnBoardingConfig;
-
- protected OnBoardingCallback mOnBoardingCallback;
- protected ProvisioningCallback mProvisioningCallback;
- protected RemoteEnrollee mRemoteEnrollee;
-
- /**
- * @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.
- */
- protected EnrolleeDevice(OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {
- mProvConfig = provConfig;
- mOnBoardingConfig = onBoardingConfig;
- }
-
- /**
- * Application has to implement it according to the on boarding connectivity the device is
- * having.
- * This method will be called back during the easy setup process.
- */
- protected abstract void startOnBoardingProcess();
-
- /**
- * This method is called back during the easy setup process if Application cancels the setup.
- * Easy setup service checks the state of device and calls this function accordingly.
- * Application has to provide implementation for this method to cancel the on boarding step.
- */
- protected abstract void stopOnBoardingProcess();
-
- /**
- * Application has to implement it according to the type of the network device is going to
- * connect or provisioned.
- * This method will be called back once on-boarding of the device is successful.
- *
- * @param conn Contains detail about the network established between the Enrollee device &
- * Mediator device. Its implementation vary according to the connectivity type.
- */
- protected abstract void startProvisioningProcess(OnBoardingConnection conn);
-
- /**
- * Application has to implement it according to the type of the network device is going to
- * connect or provisioned.
- * This method will stop the provisioning process if it is in progress
- *
- */
- protected abstract void stopProvisioningProcess();
-
- /**
- * Once on boarding is successful concrete Enrollee class would call this method and set the
- * Connection.
- *
- * @param conn Connectivity between Enrollee device & Mediator device.
- */
- protected void setConnection(OnBoardingConnection conn) {
- mConnection = conn;
- }
-
- /**
- * This method returns the OnBoardingConnection object depending on the connection type
- *
- * @return onBoardingConnection object
- */
- public OnBoardingConnection getConnection() {
- return mConnection;
- }
-
-
- /**
- * This method is called back by Easy setup service if on boarding needs to be done.
- *
- * @param onBoardingCallback This is called back once the on boarding is completed.
- */
- void startOnBoarding(OnBoardingCallback onBoardingCallback) {
- mOnBoardingCallback = onBoardingCallback;
- startOnBoardingProcess();
- }
-
- /**
- * This method is called back by Easy setup service once on boarding is successful
- *
- * @param provisioningCallback This is called back once the provisioning process is completed
- */
- void startProvisioning(ProvisioningCallback provisioningCallback) {
- mProvisioningCallback = provisioningCallback;
- startProvisioningProcess(mConnection);
- }
-
- /**
- * This method is used to check easy setup status
- *
- * @return true if successful or false
- */
-
- public boolean isSetupSuccessful() {
- return (mState == EnrolleeState.DEVICE_PROVISIONED_STATE) ? true : false;
- }
-
- /**
- * sets error occured during easy setup process
- */
- protected void setError(EnrolleeSetupError error) {
- mError = error;
- }
-
- /**
- * Returns error occured during easy setup process
- *
- * @return True EnrolleeSetupError object
- */
- public EnrolleeSetupError getError() {
- return mError;
- }
-
- /**
- * Gives the state of the device being enrolled during the easy setup process.
- *
- * @return Returns EnrolleeState object
- */
- public EnrolleeState getState() {
- return mState;
- }
-
- /**
- * This method is used to know if the device is on boarded or not
- *
- * @return True if on-boarded successfully or False
- */
-
- protected boolean onBoarded() {
- return (mState == EnrolleeState.DEVICE_ON_BOARDED_STATE) ? true : false;
- }
-}
+++ /dev/null
-/**
- * ***************************************************************
- * <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 android.content.Context;
-
-/**
- * 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(ProvisioningConfig provConfig, OnBoardingConfig onboardingConfig) throws IllegalArgumentException {
-
- if (null == provConfig || null == onboardingConfig) {
- throw new IllegalArgumentException("provConfig/onboardingConfig is NULL");
- }
- else if (onboardingConfig.getConnType() != OnBoardingConfig.ConnType.WiFi) {
- throw new IllegalArgumentException("OnBoarding configuration is not supported");
- }
- return new EnrolleeDeviceWiFiOnboarding(mContext, onboardingConfig, provConfig);
- }
-
- /**
- * This method create & returns instance of Enrollee device of supported configuration
- * [When SoftAP is going to be created on Enrollee side]
- *
- * @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(ProvisioningConfig provConfig) throws IllegalArgumentException {
-
- if (null == provConfig) {
- throw new IllegalArgumentException("provConfig is NULL");
- }
- return new EnrolleeDeviceWiFiOnboarding(mContext, new IpOnBoardingConnection(true), provConfig);
- }
-}
+++ /dev/null
-/**
- * ***************************************************************
- * <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.Timer;
-import java.util.TimerTask;
-
-import org.iotivity.service.easysetup.core.EnrolleeInfo;
-import org.iotivity.service.easysetup.core.IOnBoardingStatus;
-import org.iotivity.service.easysetup.core.ip.WiFiSoftAPManager;
-
-import android.content.Context;
-import android.net.wifi.WifiConfiguration;
-import android.util.Log;
-
-/**
- * This is a ready to use class for Enrollee device having Soft AP as on-boarding connectivity.
- */
-public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {
-
- public static final String TAG = EnrolleeDeviceWiFiOnboarding.class.getName();
-
- final Context mContext;
- final WiFiSoftAPManager mWifiSoftAPManager;
- EnrolleeInfo connectedDevice;
- Timer myTimer = null;
-
- IOnBoardingStatus deviceScanListener = new IOnBoardingStatus() {
-
- @Override
- public void deviceOnBoardingStatus(EnrolleeInfo enrolleStatus) {
- myTimer.cancel();
- Log.d("ESSoftAPOnBoarding", "Entered");
- if (mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {
- Log.d("ESSoftAPOnBoarding", "Device in OnBoarding State");
- if (enrolleStatus != null && enrolleStatus.getIpAddr() != null) {
- String finalResult = "Easy Connect : ";
-
- if (enrolleStatus.isReachable()) {
- finalResult = "Device OnBoarded" + "["
- + enrolleStatus.getIpAddr() + "]";
-
- connectedDevice = enrolleStatus;
- IpOnBoardingConnection conn = new IpOnBoardingConnection();
-
- conn.setConnectivity(true);
- conn.setIp(connectedDevice.getIpAddr());
- conn.setHardwareAddress(enrolleStatus.getHWAddr());
- conn.setDeviceName(enrolleStatus.getDevice());
-
- Log.d("ESSoftAPOnBoarding", "Entered" + finalResult);
- mOnBoardingCallback.onFinished(conn);
- return;
-
- }
- }
-
- IpOnBoardingConnection conn = new IpOnBoardingConnection();
- conn.setConnectivity(false);
- mOnBoardingCallback.onFinished(conn);
- } else {
- Log.e("ESSoftAPOnBoarding", "Device NOT in OnBoarding State. Ignoring the event");
- }
- }
- };
-
-
- protected EnrolleeDeviceWiFiOnboarding(Context context, OnBoardingConfig onBoardingConfig,
- ProvisioningConfig provConfig) {
- super(onBoardingConfig, provConfig);
- mContext = context;
- mState = EnrolleeState.DEVICE_INIT_STATE;
- mWifiSoftAPManager = new WiFiSoftAPManager(mContext);
- }
-
- protected EnrolleeDeviceWiFiOnboarding(Context context, IpOnBoardingConnection conn,
- ProvisioningConfig provConfig) {
- super(new WiFiOnBoardingConfig(), provConfig);
- mContext = context;
- mState = EnrolleeState.DEVICE_ON_BOARDED_STATE;
- mConnection = conn;
- mWifiSoftAPManager = new WiFiSoftAPManager(mContext);
- }
-
- @Override
- protected void startOnBoardingProcess() {
- Log.i(TAG, "Starting on boarding process");
-
- //1. Create Soft AP
- boolean status = mWifiSoftAPManager.setWifiApEnabled((WifiConfiguration)
- mOnBoardingConfig.getConfig(), true);
-
- mState = EnrolleeState.DEVICE_ON_BOARDING_STATE;
-
- Log.i(TAG, "Soft AP is created with status " + status);
-
- myTimer = new Timer();
- myTimer.schedule(new TimerTask() {
- @Override
- public void run() {
- // Below function to be called after 5 seconds
- mWifiSoftAPManager.getClientList(deviceScanListener, 300);
- }
-
- }, 0, 5000);
- }
-
- protected void stopOnBoardingProcess() {
- Log.i(TAG, "Stopping on boarding process");
- if(myTimer != null)
- {
- myTimer.cancel();
- }
- boolean status = mWifiSoftAPManager.setWifiApEnabled(null, false);
- Log.i(TAG, "Soft AP is disabled with status " + status);
- }
-
- @Override
- protected void startProvisioningProcess(OnBoardingConnection conn) {
-
- mState = EnrolleeState.DEVICE_PROVISIONING_STATE;
- mProvisioningCallback.onProgress(this);
- final EnrolleeDevice device = this;
- if (mProvConfig.getConnType() == ProvisioningConfig.ConnType.WiFi) {
- /*
- try {
- mRemoteEnrollee.registerProvisioningHandler(new IProvisionStatusNativeHandler() {
- @Override
- public void onStatusRecieved(int state) {
- device.mState = convertIntToProvisioningState(state);
- Log.i(TAG,"Device state changed :"+device.mState);
- mProvisioningCallback.onProgress(device);
- if(0==state) {
- mProvisioningCallback.onFinished(EnrolleeDeviceWiFiOnboarding.this);
- }
- }
- });
-
- //native call
- mRemoteEnrollee.startProvision();
- }catch(ESException e) {
- Log.i(TAG,"startProvisioningProcess Register Listener to native exception");
- }
- */
- }
- }
-
- protected void stopProvisioningProcess(){
- if(mState == EnrolleeState.DEVICE_PROVISIONING_STATE)
- { //native call
- /*
- try {
- mRemoteEnrollee.stopProvision();
- } catch (ESException e) {
- Log.i(TAG,"stopProvisioningProcess exception");
- }
- */
- }else{
- Log.i(TAG,"stopProvisioningProcess : Provisioning is not in progress");
- }
- }
-
- private EnrolleeState convertIntToProvisioningState(int state){
-
- switch(state)
- {
- case 0 :
- return EnrolleeState.DEVICE_PROVISIONED_STATE;
- case 1:
- return EnrolleeState.DEVICE_NOT_PROVISIONED;
- case 2:
- return EnrolleeState.DEVICE_PROVISIONED_STATE;
- case 3:
- return EnrolleeState.DEVICE_NOT_PROVISIONED;
- }
- return EnrolleeState.DEVICE_INIT_STATE;
- }
-}
+++ /dev/null
-/**
- * ***************************************************************
- * <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;
-
-/**
- * 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_BOARDED_STATE,
-
- /**
- * Device will move to this state once the on boarding begins
- */
- 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_PROVISIONED_STATE,
-
- /**
- * Easy setup process failed.
- */
- DEVICE_NOT_PROVISIONED,
-
- /**
- * 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_TRANSFERRING_STATE,
-
- /**
- * This state is arbitrary one, any time device can come into this state
- * Device will move to this state if the ownership transfer is completed
- */
- DEVICE_OWNERSHIP_TRANSFERRED_STATE,
-
- /**
- * This state is arbitrary one, any time device can come into this state
- * Device will move to this state if the ownership transfer is not completed
- */
- DEVICE_NOT_OWNED,
-
- /**
- * 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,
-
-
-
-
-}
+++ /dev/null
-/**
- * ***************************************************************
- * <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 IpOnBoardingConnection implements OnBoardingConnection {
-
- private boolean mIsConnected;
- private String mIp;
- private String mHardwareAddress;
- private String mDeviceName;
-
- /**
- * @mThrottlingDelay
- * After creating the Soft AP at Mediator & on-boarding the-
- * -Enrollee device on it provisioning needs to be delayed by at least 2000 ms for Android Mediator
- */
- private int mThrottlingDelay = 2000 ;
-
- int getThrottlingDelay() {
- return mThrottlingDelay;
- }
-
- IpOnBoardingConnection(boolean enrolleeOnboarded) {
- mThrottlingDelay = 0;
- mIp = "0.0.0.01";
- mIsConnected = enrolleeOnboarded; // Always true for this constructor
- }
-
- IpOnBoardingConnection(){}
-
- public void setHardwareAddress(String address) {
- mHardwareAddress = address;
- }
-
- public String getHardwareAddress() {
- return mHardwareAddress;
- }
-
- public void setDeviceName(String name) {
- mDeviceName = name;
- }
-
- public String getDeviceName() {
- return mDeviceName;
- }
-
- public void setConnectivity(boolean connected) {
- mIsConnected = connected;
- }
-
- public void setIp(String ip) {
- mIp = ip;
- }
-
- public String getIp() {
- return mIp;
- }
-
- @Override
- public String getDesc() {
- return "Description";
- }
-
- @Override
- public boolean isConnected() {
- return mIsConnected;
- }
-
- @Override
- public Object getConnection() {
- return this;
- }
-
-}
--- /dev/null
+/**\r
+ * ***************************************************************\r
+ *\r
+ * Copyright 2016 Samsung Electronics All Rights Reserved.\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.mediator;\r
+\r
+import android.util.Log;\r
+\r
+import org.iotivity.service.easysetup.mediator.enums.WIFI_FREQ;\r
+import org.iotivity.service.easysetup.mediator.enums.WIFI_MODE;\r
+\r
+import java.util.ArrayList;\r
+\r
+public class NetworkInfo\r
+{\r
+ public static final String TAG = NetworkInfo.class.getName();\r
+ private final ArrayList<WIFI_MODE> mWifiModeTypes;\r
+ private final WIFI_FREQ mWifiFreq;\r
+\r
+ public NetworkInfo(ArrayList<Integer> types, int wifiFreq)\r
+ {\r
+ mWifiModeTypes = convertWifiModeTypes(types);\r
+ mWifiFreq = WIFI_FREQ.fromInt(wifiFreq);\r
+ }\r
+\r
+ private ArrayList<WIFI_MODE> convertWifiModeTypes(ArrayList<Integer> types)\r
+ {\r
+ ArrayList<WIFI_MODE> wifiModeTypes = new ArrayList<>();\r
+ for (Integer type: types) {\r
+ wifiModeTypes.add(WIFI_MODE.fromInt(type.intValue()));\r
+ };\r
+ return wifiModeTypes;\r
+ }\r
+\r
+ public ArrayList<WIFI_MODE> getWifiModeTypes()\r
+ {\r
+ return mWifiModeTypes;\r
+ }\r
+\r
+ public WIFI_FREQ getWifiFreq()\r
+ {\r
+ return mWifiFreq;\r
+ }\r
+}\r
+++ /dev/null
-/**
- * ***************************************************************
- * <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 android.util.Log;
-
-import org.iotivity.base.OcConnectivityType;
-
-/**
- * It contains configuration details about the connectivity type between the Enrollee device &
- * Mediator device in order to perform on-boarding.
- */
-
-public interface OnBoardingConfig {
- /**
- * It provides constants for connectivity types used for on-boarding Enrollee device
- */
- public static enum ConnType {
- // Note : Enum Ids should matched with Native Ids
- WiFi(OcConnectivityType.CT_ADAPTER_IP.getValue()),
- BLE(OcConnectivityType.CT_ADAPTER_GATT_BTLE.getValue());
-
- private int mConnType;
-
- ConnType(int connType) {
- mConnType = connType;
- }
-
- public int getValue() {
- return mConnType;
- }
-
- }
-
- /**
- * Gives configuration object specific to the on-boarding connectivity of the enrolling device.
- *
- * @return instance object of configuration according to connectivity type
- */
- public Object getConfig();
-
- /**
- * Gives connectivity type of on-boarding device
- *
- * @return on-boarding connectivity type
- */
- public ConnType getConnType();
-
- public boolean isSecured();
-
- public void setSecured(boolean isSecured);
-
-}
--- /dev/null
+/**
+ * ***************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import org.iotivity.service.easysetup.mediator.enums.WIFI_FREQ;
+import org.iotivity.service.easysetup.mediator.enums.WIFI_MODE;
+
+import java.util.ArrayList;
+
+public class PropertyData
+{
+ private final DeviceConfig mDevConf;
+ private final NetworkInfo mNetInfo;
+ private final boolean mCloudable;
+
+ public PropertyData(DeviceConfig devConf, NetworkInfo netInfo, boolean cloudable)
+ {
+ mDevConf = devConf;
+ mNetInfo = netInfo;
+ mCloudable = cloudable;
+ }
+
+ public DeviceConfig getDeviceConfig()
+ {
+ return mDevConf;
+ }
+
+ public NetworkInfo getNetworkInfo()
+ {
+ return mNetInfo;
+ }
+
+ public boolean isCloudable()
+ {
+ return mCloudable;
+ }
+}
+
+
+++ /dev/null
-/**
- * ***************************************************************
- * <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 android.util.Log;
-
-import org.iotivity.base.OcConnectivityType;
-/**
- * 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 {
- // Note : Enum Ids should matched with Native Ids
- WiFi(OcConnectivityType.CT_ADAPTER_IP.getValue()),
- BLE(OcConnectivityType.CT_ADAPTER_GATT_BTLE.getValue());
-
- private int mConnType;
-
- ConnType(int connType) {
- mConnType = connType;
- }
-
- public int getValue() {
- return mConnType;
- }
- }
-
- /**
- * 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();
-
- public boolean isSecured();
-
- public void setSecured(boolean isSecured);
-
-}
public static final String TAG = RemoteEnrollee.class.getName();
private long m_nativeHandle;
- private native void nativeSetCloudProvInfo(String authCode, String autoProvider, String ciServer);
+ private native void nativeInitRemoteEnrollee();
+ private native void nativeRequestPropertyData(RequestPropertyDataCallback callback);
+ private native void nativeStartSecurityProvision(SecurityProvisioningCallback callback);
+ private native void nativeSetDataProvInfo(String ssid, String pwd, int authType, int encType,
+ String language, String country);
+ private native void nativeStartDataProvision(DataProvisioningCallback callback);
+ private native void nativeSetCloudProvInfo(String authCode, String autoProvider,
+ String ciServer);
private native void nativeStartCloudProvisioning(CloudProvisioningCallback callback);
/* constructor will be invoked from the native layer */
this.m_nativeHandle = nativeHandle;
}
- /* native setCloudProvInfo */
+ /* native setCloudProvInfo */
+ public void initRemoteEnrollee() throws ESException
+ {
+ nativeInitRemoteEnrollee();
+ }
+
+ public void requestPropertyData(RequestPropertyDataCallback callback) throws ESException
+ {
+ if(callback != null)
+ {
+ nativeRequestPropertyData(callback);
+ return;
+ }
+ Log.d(TAG, "RequestPropertyDataCallback is null ");
+ }
+
+ public void startSecurityProvisioning(SecurityProvisioningCallback callback) throws ESException
+ {
+ if(callback != null)
+ {
+ nativeStartSecurityProvision(callback);
+ return;
+ }
+ Log.d(TAG, "SecurityProvisioningCallback is null ");
+ }
+
+ public void setDataProvInfo(DataProvInfo dataInfo) throws ESException
+ {
+ nativeSetDataProvInfo(dataInfo.getSsid(), dataInfo.getPwd(),
+ dataInfo.getAuthType().getValue(), dataInfo.getEncType().getValue(),
+ dataInfo.getLanguage(), dataInfo.getCountry());
+ }
+
+ public void startDataProvisioning(DataProvisioningCallback callback) throws ESException
+ {
+ if(callback != null)
+ {
+ nativeStartDataProvision(callback);
+ return;
+ }
+ Log.d(TAG, "DataProvisioningCallback is null ");
+ }
+
public void setCloudProvInfo(CloudProvInfo cloudInfo) throws ESException{
- nativeSetCloudProvInfo(cloudInfo.getAuthCode(), cloudInfo.getAuthProvider(), cloudInfo.getCiServer());
- }
+ nativeSetCloudProvInfo(cloudInfo.getAuthCode(), cloudInfo.getAuthProvider(),
+ cloudInfo.getCiServer());
+ }
/* native startCloudProvisioning */
public void startCloudProvisioning(CloudProvisioningCallback callback) throws ESException{
/**
* ***************************************************************
- * <p/>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p/>
- * <p/>
- * <p/>
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- * <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 abstract class OnBoardingCallback {
- public abstract void onFinished(OnBoardingConnection connection);
+import org.iotivity.service.easysetup.mediator.RequestPropertyDataCallback;
+
+public abstract class RequestPropertyDataCallback {
+ public abstract void onProgress(RequestPropertyDataStatus status);
}
--- /dev/null
+/**
+ * ***************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator;
+
+import org.iotivity.service.easysetup.mediator.enums.ESResult;
+
+public class RequestPropertyDataStatus
+{
+ private ESResult m_result;
+ private PropertyData m_propertyData;
+
+ public RequestPropertyDataStatus(int result, PropertyData data)
+ {
+ m_result = ESResult.fromInt(result);
+ m_propertyData = data;
+ }
+
+ public ESResult getESResult()
+ {
+ return m_result;
+ }
+
+ public PropertyData getPropertyData()
+ {
+ return m_propertyData;
+ }
+};
/**
* ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- * <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 abstract class ProvisioningCallback {
- public abstract void onFinished(EnrolleeDevice enrolledevice);
- public abstract void onProgress(EnrolleeDevice enrolledevice);
+import org.iotivity.service.easysetup.mediator.SecurityProvisioningCallback;
+
+public abstract class SecurityProvisioningCallback {
+ public abstract void onProgress(SecurityProvisioningStatus status);
}
/**
* ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- * <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;
-/**
- * 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,
-}
+import android.util.Log;
+
+import org.iotivity.service.easysetup.mediator.enums.ESResult;
+
+public class SecurityProvisioningStatus
+{
+ private ESResult mResult;
+ private String mDevUUID;
+
+ public SecurityProvisioningStatus(int result, String uuid)
+ {
+ mResult = ESResult.fromInt(result);
+ mDevUUID = uuid;
+ }
+
+ public ESResult getESResult()
+ {
+ return mResult;
+ }
+
+ public String getDevUUID()
+ {
+ return mDevUUID;
+ }
+};
+++ /dev/null
-/**
- * ***************************************************************
- * <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 org.iotivity.service.easysetup.mediator.OnBoardingConfig;
-
-import android.net.wifi.WifiConfiguration;
-
-/**
- * This class contains on boarding configuration information for Soft AP on boarding connectivity.
- * It implements OnBoardingConfig interface & provide implementation for WiFi Soft AP connectivity.
- */
-
-public class WiFiOnBoardingConfig implements OnBoardingConfig {
-
- private boolean isSecured;
- private final WifiConfiguration config = new WifiConfiguration();
- private final ConnType mConnType = OnBoardingConfig.ConnType.WiFi;
-
- @Override
- public Object getConfig() {
- return config;
- }
-
- public void setSSId(String ssid) {
- config.SSID = ssid;
- }
-
- public void setSharedKey(String sharedKey) {
- config.preSharedKey = sharedKey;
- }
-
- public void setAuthAlgo(int aurthAlgo) {
- config.allowedAuthAlgorithms.set(aurthAlgo);
- }
-
- public void setKms(int kms) {
- config.allowedKeyManagement.set(kms);
- }
-
- @Override
- public ConnType getConnType() {
- return mConnType;
- }
-
- @Override
- public boolean isSecured(){
- return isSecured;
- }
-
- @Override
- public void setSecured(boolean flag) {
- isSecured = flag;
- }
-}
+++ /dev/null
-/**
- * ***************************************************************
- * <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 org.iotivity.service.easysetup.mediator.ProvisioningConfig;
-
-/**
- * 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 boolean isSecured;
-
- 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;
- }
-
- /**
- * This method returns the SSID of the Target WIFI network
- * @return SSID of Target Network
- */
- public String getSsId() {
- return mSsId;
- }
-
- /**
- * This method returns the password of the Target WIFI network
- * @return password of Target Network
- */
- public String getPassword() {
- return mPassword;
- }
-
- @Override
- public boolean isSecured(){
- return isSecured;
- }
-
- @Override
- public void setSecured(boolean flag) {
- isSecured = flag;
- }
-}
* ****************************************************************
*/
-package org.iotivity.service.easysetup.mediator;
+package org.iotivity.service.easysetup.mediator.enums;
/**
* It defines various states of the cloud provisioning during easy setup process
--- /dev/null
+/**
+ * ***************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator.enums;
+
+public enum ESDataProvState
+{
+ ES_PROVISIONING_ERROR(-1),
+ ES_NEED_PROVISIONING(0),
+ ES_PROVISIONED_ALREADY(1),
+ ES_PROVISIONING_SUCCESS(2);
+
+ private int value;
+
+ private ESDataProvState(int value)
+ {
+ this.value = value;
+ }
+
+ public int getValue()
+ {
+ return value;
+ }
+
+ public static ESDataProvState fromInt(int i)
+ {
+ for (ESDataProvState b : ESDataProvState.values())
+ {
+ if (b.getValue() == i)
+ return b;
+ }
+ return null;
+ }
+}
* ****************************************************************
*/
-package org.iotivity.service.easysetup.mediator;
+package org.iotivity.service.easysetup.mediator.enums;
/**
* It defines an result during easy setup process, which is same as one in Easy Setup C++ SDK
--- /dev/null
+/**
+ * ***************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator.enums;
+
+public enum WIFI_AUTHTYPE
+{
+ NONE_AUTH(0),
+ WEP(1),
+ WPA_PSK(2),
+ WPA2_PSK(3);
+
+ private int value;
+
+ private WIFI_AUTHTYPE(int value)
+ {
+ this.value = value;
+ }
+
+ public int getValue()
+ {
+ return value;
+ }
+
+ public static WIFI_AUTHTYPE fromInt(int i)
+ {
+ for (WIFI_AUTHTYPE b : WIFI_AUTHTYPE.values())
+ {
+ if (b.getValue() == i)
+ return b;
+ }
+ return null;
+ }
+}
--- /dev/null
+/**
+ * ***************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator.enums;
+
+public enum WIFI_ENCTYPE
+{
+ NONE_ENC(0),
+ WEP_64(1),
+ WEP_128(2),
+ TKIP(3),
+ AES(4),
+ TKIP_AES(5);
+
+ private int value;
+
+ private WIFI_ENCTYPE(int value)
+ {
+ this.value = value;
+ }
+
+ public int getValue()
+ {
+ return value;
+ }
+
+ public static WIFI_ENCTYPE fromInt(int i)
+ {
+ for (WIFI_ENCTYPE b : WIFI_ENCTYPE.values())
+ {
+ if (b.getValue() == i)
+ return b;
+ }
+ return null;
+ }
+}
/**
* ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- * <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 interface IOnBoardingStatus {
+package org.iotivity.service.easysetup.mediator.enums;
- /**
- * Interface called when the scan method finishes. Network operations should
- * not execute on UI thread
- *
- * @param clients of {@link EnrolleeInfo}
- */
+public enum WIFI_FREQ
+{
+ WIFI_24G(0),
+ WIFI_5G(1),
+ WIFI_BOTH(2);
- public void deviceOnBoardingStatus(EnrolleeInfo clients);
+ private int value;
+ private WIFI_FREQ(int value)
+ {
+ this.value = value;
+ }
+
+ public int getValue()
+ {
+ return value;
+ }
+
+ public static WIFI_FREQ fromInt(int i)
+ {
+ for (WIFI_FREQ b : WIFI_FREQ.values())
+ {
+ if (b.getValue() == i)
+ return b;
+ }
+ return null;
+ }
}
--- /dev/null
+/**
+ * ***************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ****************************************************************
+ */
+
+package org.iotivity.service.easysetup.mediator.enums;
+
+public enum WIFI_MODE
+{
+ WIFI_11A(0),
+ WIFI_11B(1),
+ WIFI_11G(2),
+ WIFI_11N(3),
+ WIFI_11AC(4);
+
+ private int value;
+
+ private WIFI_MODE(int value)
+ {
+ this.value = value;
+ }
+
+ public int getValue()
+ {
+ return value;
+ }
+
+ public static WIFI_MODE fromInt(int i)
+ {
+ for (WIFI_MODE b : WIFI_MODE.values())
+ {
+ if (b.getValue() == i)
+ return b;
+ }
+ return null;
+ }
+}
//TODO:
jmethodID midL = env->GetMethodID(clsL, "onProgress",
"(Lorg/iotivity/service/easysetup/mediator/"
- "DataProvisioningCallback;"
+ "DataProvisioningStatus;"
")V");
if (!midL)
jclass g_cls_DataProvisioningStatus = NULL;
jclass g_cls_ESException = NULL;
jclass g_cls_CloudProvisioningStatus = NULL;
+jclass g_cls_Integer = NULL;
jmethodID g_mid_RemoteEnrollee_ctor = NULL;
jmethodID g_mid_ESException_ctor = NULL;
jmethodID g_mid_SecurityProvisioningStatus_ctor = NULL;
jmethodID g_mid_DataProvisioningStatus_ctor = NULL;
jmethodID g_mid_CloudProvisioningStatus_ctor = NULL;
+jmethodID g_mid_Integer_ctor = NULL;
// JNI OnLoad
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
env->DeleteLocalRef(clazz);
g_mid_NetworkInfo_ctor = env->GetMethodID(g_cls_NetworkInfo, "<init>",
- "(Ljava.util.ArrayList;I)V");
+ "(Ljava/util/ArrayList;I)V");
if (!g_mid_NetworkInfo_ctor) return JNI_ERR;
// PropertyData
env->DeleteLocalRef(clazz);
g_mid_PropertyData_ctor = env->GetMethodID(g_cls_PropertyData, "<init>",
- "(LDeviceConfig;LNetworkInfo;Z)V");
+ "(Lorg/iotivity/service/easysetup/mediator/DeviceConfig;Lorg/iotivity/service/easysetup/mediator/NetworkInfo;Z)V");
if (!g_mid_PropertyData_ctor) return JNI_ERR;
// RequestPropertyDataStatus
-
clazz = env->FindClass("org/iotivity/service/easysetup/mediator/RequestPropertyDataStatus");
if (!clazz) return JNI_ERR;
env->DeleteLocalRef(clazz);
g_mid_RequestPropertyDataStatus_ctor = env->GetMethodID(g_cls_RequestPropertyDataStatus, "<init>",
- "(ILPropertyData;)V");
+ "(ILorg/iotivity/service/easysetup/mediator/PropertyData;)V");
if (!g_mid_RequestPropertyDataStatus_ctor) return JNI_ERR;
// SecurityProvisioningStatus
"(II)V");
if (!g_mid_CloudProvisioningStatus_ctor) return JNI_ERR;
+ // Integer
+ clazz = env->FindClass("java/lang/Integer");
+ if (!clazz) return JNI_ERR;
+ g_cls_Integer = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+
+ g_mid_Integer_ctor = env->GetMethodID(g_cls_Integer, "<init>",
+ "(I)V");
+ if (!g_mid_Integer_ctor) return JNI_ERR;
+
return JNI_CURRENT_VERSION;
}
extern jclass g_cls_SecurityProvisioningStatus;
extern jclass g_cls_DataProvisioningStatus;
extern jclass g_cls_CloudProvisioningStatus;
+extern jclass g_cls_Integer;
extern jmethodID g_mid_RemoteEnrollee_ctor;
extern jmethodID g_mid_ESException_ctor;
extern jmethodID g_mid_SecurityProvisioningStatus_ctor;
extern jmethodID g_mid_DataProvisioningStatus_ctor;
extern jmethodID g_mid_CloudProvisioningStatus_ctor;
+extern jmethodID g_mid_Integer_ctor;
typedef void(*RemoveListenerCallback)(JNIEnv *env, jobject jListener);
*/
JNIEXPORT void JNICALL
Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeStartDataProvision
-(JNIEnv *env, jobject jClass);
+(JNIEnv *env, jobject jClass, jobject jListener);
/**
* API for setting data provisioning information.
(jstring)env->NewStringUTF(devConf.name.c_str()),
(jstring)env->NewStringUTF(devConf.language.c_str()),
(jstring)env->NewStringUTF(devConf.country.c_str()));
+ if (!jDevConf) {
+ LOGE("JniRequestPropertyDataStatusListener::requestPropertyDataStatusCallback Unable to create the jDevConf");
+ return ;
+ }
- jclass clazz = (*env).FindClass("java/util/ArrayList");
- jobject wifiModeTypes = (*env).NewObject(clazz, (*env).GetMethodID(clazz, "<init>", "()V"));
+ jclass clazz = env->FindClass("java/util/ArrayList");
+ jobject wifiModeTypes = env->NewObject(clazz, env->GetMethodID(clazz, "<init>", "()V"));
+ jmethodID arraylist_add = env->GetMethodID(clazz, "add", "(Ljava/lang/Object;)Z");
for (int n=0; n<netInfo.types.size(); n++)
{
- (*env).CallBooleanMethod(wifiModeTypes, (*env).GetMethodID(clazz, "add", "(java/lang/Object;)Z"),
- convertNativeWifiModeToInt(static_cast<WIFI_MODE>(netInfo.types[n])));
+ jobject value = env->NewObject(g_cls_Integer,
+ g_mid_Integer_ctor,
+ convertNativeWifiModeToInt(static_cast<WIFI_MODE>(netInfo.types[n])));
+ env->CallBooleanMethod(wifiModeTypes, arraylist_add, value);
}
+ if (!wifiModeTypes) {
+ LOGE("JniRequestPropertyDataStatusListener::requestPropertyDataStatusCallback Unable to create the wifiModeTypes");
+ return ;
+ }
+
jobject jNetInfo = NULL;
jNetInfo = env->NewObject(g_cls_NetworkInfo,
g_mid_NetworkInfo_ctor,
(jobject)wifiModeTypes,
(jint)convertNativeWifiFreqToInt(netInfo.freq));
+ if (!jNetInfo) {
+ LOGE("JniRequestPropertyDataStatusListener::requestPropertyDataStatusCallback Unable to create the jNetInfo");
+ return ;
+ }
jobject jPropertyData = NULL;
jPropertyData = env->NewObject(g_cls_PropertyData,
(jobject)jDevConf,
(jobject)jNetInfo,
(jboolean)propertyData.isCloudable());
+ if (!jPropertyData) {
+ LOGE("JniRequestPropertyDataStatusListener::requestPropertyDataStatusCallback Unable to create the jPropertyData");
+ return ;
+ }
+ ESResult esResult = requestPropertyDataStatusCb->getESResult();
jobject jRequestPropertyDataStatus = NULL;
jRequestPropertyDataStatus = env->NewObject(g_cls_RequestPropertyDataStatus,
g_mid_RequestPropertyDataStatus_ctor,
- convertNativeDataProvResultToInt(requestPropertyDataStatusCb->getESResult()),
+ (jint)esResult,
(jobject)jPropertyData);
-
+LOGI("4");
if (!jRequestPropertyDataStatus)
{
LOGE("JniRequestPropertyDataStatusListener::requestPropertyDataStatusCallback Unable to create the java object");
#include "JniSecurityStatusListener.h"
#include "JniRemoteEnrollee.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
using namespace OIC::Service;
jSecurityProvisioningStatus = env->NewObject(g_cls_SecurityProvisioningStatus,
g_mid_SecurityProvisioningStatus_ctor,
(jint)esResult,
- (jstring)env->NewStringUTF(secProvisioningStatus->getDeviceUUID().c_str()));
+ env->NewStringUTF(secProvisioningStatus->getDeviceUUID().c_str()));
+
+ LOGE("JniSecurityStatusListener::onSecurityProvisioningStatus UUID : %s", secProvisioningStatus->getDeviceUUID().c_str());
if (!jSecurityProvisioningStatus)
{
} ESResult;
/**
- * @brief WIFI Authentication type of the Enroller
+ * @brief WIFI Authentication tlype of the Enroller
*/
typedef enum
{
public:
EnrolleeSecurity(std::shared_ptr< EnrolleeResource > EnrolleeResource,
std::string secDbPath);
- ESResult registerCallbackHandler(SecurityProvStatusCb securityProvStatusCb,
+ void registerCallbackHandler(SecurityProvStatusCb securityProvStatusCb,
SecurityPinCb securityPinCb, SecProvisioningDbPathCb secProvisioningDbPathCb);
- bool performOwnershipTransfer();
+ void performOwnershipTransfer();
+ void setTargetDevID(const std::string devID);
private:
std::shared_ptr< EnrolleeResource > m_EnrolleeResource;
SecProvisioningDbPathCb m_secProvisioningDbPathCb;
std::shared_ptr< OC::OCSecureResource > m_unownedDevice;
+ std::string m_deviceId;
+
EnrolleeSecState m_enrolleeSecState;std::shared_ptr< OC::OCSecureResource > m_securedResource;
std::shared_ptr< OC::OCSecureResource > getEnrollee(OC::DeviceList_t &list);
m_EnrolleeResource = EnrolleeResource;
}
- ESResult EnrolleeSecurity::registerCallbackHandler(SecurityProvStatusCb securityProvStatusCb,
+ void EnrolleeSecurity::registerCallbackHandler(SecurityProvStatusCb securityProvStatusCb,
SecurityPinCb securityPinCb, SecProvisioningDbPathCb secProvisioningDbPathCb)
-
{
m_securityProvStatusCb = securityProvStatusCb;
m_securityPinCb = securityPinCb;
m_secProvisioningDbPathCb = secProvisioningDbPathCb;
-
- return ES_ERROR;
}
std::shared_ptr< OC::OCSecureResource > EnrolleeSecurity::getEnrollee(DeviceList_t &list)
{
for (unsigned int i = 0; i < list.size(); i++)
{
- OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Device %d ID %s ", i + 1,
- list[i]->getDeviceID().c_str());
- OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "From IP :%s", list[i]->getDevAddr().c_str());
-
+ if(m_deviceId == list[i]->getDeviceID().c_str())
+ {
+ OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Device %d ID %s ", i + 1,
+ list[i]->getDeviceID().c_str());
+ OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "From IP :%s", list[i]->getDevAddr().c_str());
+ return list[i];
+ }
//Always return the first element of the unOwned devices. This is considering that Mediator is
// always connected with only one Enrollee for which ownership transfer is being performed.
// Incase of multiple Enrollee devices connected to the Mediator via any OnBoarding method (SoftAp
// for example), the Enrollee devices will be provisioned in the first come first serve basis in the order
// returned by the security layer.
- return list[i];
+
}
OIC_LOG(ERROR, ENROLEE_SECURITY_TAG,"Error!!! DeviceList_t is NULL");
return NULL;
{
OIC_LOG(ERROR, ENROLEE_SECURITY_TAG,"Error!!! in OwnershipTransfer");
- std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus = nullptr;
std::string uuid;
convertUUIDToString(result->at(0).deviceId, uuid);
- securityProvisioningStatus = std::make_shared< SecProvisioningStatus >(uuid,
- ES_ERROR);
-
+ std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
+ std::make_shared< SecProvisioningStatus >(uuid, ES_ERROR);
m_securityProvStatusCb(securityProvisioningStatus);
return;
}
convertUUIDToString(result->at(0).deviceId, uuid);
OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "UUID : %s",uuid.c_str());
- std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus = nullptr;
- securityProvisioningStatus = std::make_shared< SecProvisioningStatus >(uuid,
- ES_OK);
-
+ std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
+ std::make_shared< SecProvisioningStatus >(uuid, ES_OK);
m_securityProvStatusCb(securityProvisioningStatus);
return;
}
}
}
- bool EnrolleeSecurity::performOwnershipTransfer()
+ void EnrolleeSecurity::setTargetDevID(const std::string devID)
+ {
+ m_deviceId = devID;
+ }
+
+ void EnrolleeSecurity::performOwnershipTransfer()
{
OC::DeviceList_t pUnownedDevList, pOwnedDevList;
pUnownedDevList.clear();
OCStackResult result;
-
- //Developer note : Always test the mediator and enrollee applications on different devices. Running
- // Mediator and Enrollee in same device will result in returning the same device as already owned.
- /*result = OCSecure::discoverOwnedDevices(ES_SEC_DISCOVERY_TIMEOUT,
+ /*
+ result = OCSecure::discoverOwnedDevices(ES_SEC_DISCOVERY_TIMEOUT,
pOwnedDevList);
if (result != OC_STACK_OK)
{
OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "Owned Discovery failed.");
- ownershipStatus = DEVICE_NOT_OWNED;
//Throw exception
throw ESPlatformException(result);
- return ownershipStatus;
}
else if (pOwnedDevList.size())
{
OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Found owned devices. Count =%d",
pOwnedDevList.size());
std::shared_ptr< OC::OCSecureResource > ownedDevice = getEnrollee(pOwnedDevList);
+
if (ownedDevice)
{
- ownershipStatus = DEVICE_OWNED;
- return ownershipStatus;
+ std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
+ std::make_shared< SecProvisioningStatus >(ownedDevice->getDeviceID(), ES_OK);
+ m_securityProvStatusCb(securityProvisioningStatus);
+ return;
}
}
- else
- {
- OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "No owned devices found.");
- ownershipStatus = DEVICE_NOT_OWNED;
- }*/
-
+ */
result = OCSecure::discoverUnownedDevices(ES_SEC_DISCOVERY_TIMEOUT, pUnownedDevList);
if (result != OC_STACK_OK)
{
&EnrolleeSecurity::ownershipTransferCb, this, std::placeholders::_1,
std::placeholders::_2);
- if (m_unownedDevice->doOwnershipTransfer(ownershipTransferCb) != OC_STACK_OK)
+ result = m_unownedDevice->doOwnershipTransfer(ownershipTransferCb);
+ if (result != OC_STACK_OK)
{
OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "OwnershipTransferCallback is failed");
- return false;
+ throw ESPlatformException(result);
}
}
}
else
{
OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "No unOwned devices found.");
- return false;
+ throw ESException("No unOwned devices found.");
}
-
- return true;
}
}
}
std::string resourceURI;
std::string hostAddress;
std::string hostDeviceID;
+
try
{
if(resource)
{
- // Get the resource URI
- resourceURI = resource->uri();
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,
- "URI of the resource: %s", resourceURI.c_str());
-
- // Get the resource host address
- hostAddress = resource->host();
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,
- "Host address of the resource: %s", hostAddress.c_str());
-
- hostDeviceID = resource->sid();
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,
- "Host DeviceID of the resource: %s", hostDeviceID.c_str());
-
- if(m_deviceId .empty())
+ if(!(resource->connectivityType() & CT_ADAPTER_TCP))
{
- /*
- * Easysetup is always performed with a single Enrollee device and
- * in a private network (SoftAP or BLE), so the assumption is that
- * only the intended device will respond for the discovery.
- * With the above assumption the below two statements are written.
- */
- m_ocResource = resource;
- m_deviceId = resource->sid();
- m_discoveryResponse = true;
- }
-
- else if(!m_deviceId.empty() && m_deviceId == hostDeviceID)
- {
- OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_TAG, "Find matched CloudResource");
- m_ocResource = resource;
- m_discoveryResponse = true;
+ // Get the resource URI
+ resourceURI = resource->uri();
+ OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,
+ "URI of the resource: %s", resourceURI.c_str());
+
+ // Get the resource host address
+ hostAddress = resource->host();
+ OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,
+ "Host address of the resource: %s", hostAddress.c_str());
+
+ hostDeviceID = resource->sid();
+ OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,
+ "Host DeviceID of the resource: %s", hostDeviceID.c_str());
+
+ if(m_deviceId .empty())
+ {
+ /*
+ * Easysetup is always performed with a single Enrollee device and
+ * in a private network (SoftAP or BLE), so the assumption is that
+ * only the intended device will respond for the discovery.
+ * With the above assumption the below two statements are written.
+ */
+ m_ocResource = resource;
+ m_deviceId = resource->sid();
+ m_discoveryResponse = true;
+ }
+
+ else if(!m_deviceId.empty() && m_deviceId == hostDeviceID)
+ {
+ OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_TAG, "Find matched CloudResource");
+ m_ocResource = resource;
+ m_discoveryResponse = true;
+ }
}
}
}
//TODO : DBPath is passed empty as of now. Need to take dbpath from application.
m_enrolleeSecurity = std::make_shared <EnrolleeSecurity> (m_enrolleeResource, "");
- m_enrolleeSecurity->registerCallbackHandler(securityProvStatusCb,
- m_securityPinCb, m_secProvisioningDbPathCb);
+ m_enrolleeSecurity->setTargetDevID(m_deviceId);
+ m_enrolleeSecurity->registerCallbackHandler(securityProvStatusCb, m_securityPinCb, m_secProvisioningDbPathCb);
try
{
- if (!m_enrolleeSecurity->performOwnershipTransfer())
- {
- OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Fail performOwnershipTransfer");
- std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
- std::make_shared< SecProvisioningStatus >(nullptr, ES_ERROR);
- m_securityProvStatusCb(securityProvisioningStatus);
- return;
- }
+ m_enrolleeSecurity->performOwnershipTransfer();
}
catch (OCException & e)
{
OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,
"Exception for performOwnershipTransfer : %s", e.reason().c_str());
+
+ OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Fail performOwnershipTransfer");
+ std::shared_ptr< SecProvisioningStatus > securityProvisioningStatus =
+ std::make_shared< SecProvisioningStatus >(nullptr, ES_ERROR);
+ m_securityProvStatusCb(securityProvisioningStatus);
return ;
}
#else
m_cloudResource = std::make_shared<CloudResource>(std::move(m_ocResource));
std::shared_ptr< CloudProvisioningStatus > provStatus = std::make_shared<
- CloudProvisioningStatus >(ESResult::ES_ERROR, ESCloudProvState::ES_CLOUD_ENROLLEE_FOUND);
+ CloudProvisioningStatus >(ESResult::ES_OK, ESCloudProvState::ES_CLOUD_ENROLLEE_FOUND);
m_cloudProvStatusCb(provStatus);
}