From: Randeep Singh Date: Fri, 17 Feb 2017 05:58:24 +0000 (+0530) Subject: Adding Android API's for Multiple Owner Transfer (MOT) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8f196c54968007d58325de161e6be2f3c8eaa677;p=contrib%2Fiotivity.git Adding Android API's for Multiple Owner Transfer (MOT) Change-Id: I3fd43ae1285989f1a316d4fbeeb4684ace893b53 Signed-off-by: Randeep Singh Reviewed-on: https://gerrit.iotivity.org/gerrit/17329 Tested-by: jenkins-iotivity --- diff --git a/java/SConscript b/java/SConscript index b3b56d6..d30fb1c 100644 --- a/java/SConscript +++ b/java/SConscript @@ -20,6 +20,10 @@ if env.get('WITH_TCP'): TCP=1 else: TCP=0 +if env.get('MULTIPLE_OWNER'): + ANDROID_MULTIPLE_OWNER=1 +else: + ANDROID_MULTIPLE_OWNER=0 MQ = env.get('WITH_MQ') MQ_SUB = 0 @@ -90,14 +94,14 @@ def ensure_libs(target, source, env): SConscript('jni/SConscript') jdk_env = Environment(ENV=os.environ) -jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b ' + env.get('SRC_DIR') + '/java/iotivity-%s/build.gradle -PWITH_TRANSPORT_EDR=%s -PWITH_TRANSPORT_BLE=%s -PWITH_TRANSPORT_NFC=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s -PWITH_TCP=%s -PBUILD_DIR=%s --stacktrace' %(target_os, TRANSPORT_EDR, TRANSPORT_BLE, TRANSPORT_NFC, TARGET_ARCH, RELEASE, SECURED, SECURED, CLOUD, RD_MODE, MQ_PUB, MQ_SUB, MQ_BROKER, TCP, env.get('BUILD_DIR')), emitter = ensure_libs) +jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b ' + env.get('SRC_DIR') + '/java/iotivity-%s/build.gradle -PWITH_TRANSPORT_EDR=%s -PWITH_TRANSPORT_BLE=%s -PWITH_TRANSPORT_NFC=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s -PWITH_TCP=%s -PMULTIPLE_OWNER=%s -PBUILD_DIR=%s --stacktrace' %(target_os, TRANSPORT_EDR, TRANSPORT_BLE, TRANSPORT_NFC, TARGET_ARCH, RELEASE, SECURED, SECURED, CLOUD, RD_MODE, MQ_PUB, MQ_SUB, MQ_BROKER, TCP, ANDROID_MULTIPLE_OWNER, env.get('BUILD_DIR')), emitter = ensure_libs) jdk_env['BUILD_DIR'] = env.get('BUILD_DIR') cmdBuildApi=jdk_env.Gradle(target="base/objs", source="common/src/main/java/org/iotivity/base/OcResource.java") examples_target = "java" if target_os == 'android': examples_target = "android" -jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b ' + 'java/examples-%s/build.gradle -DWITH_TRANSPORT_EDR=%s -DWITH_TRANSPORT_BLE=%s -DWITH_TRANSPORT_NFC=%s -PTARGET_OS=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s -PWITH_TCP=%s -PBUILD_DIR=%s --stacktrace' %(examples_target, TRANSPORT_EDR, TRANSPORT_BLE, TRANSPORT_NFC, target_os, TARGET_ARCH, RELEASE, SECURED, SECURED, CLOUD, RD_MODE, MQ_PUB, MQ_SUB, MQ_BROKER, TCP, env.get('BUILD_DIR'))) +jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b ' + 'java/examples-%s/build.gradle -DWITH_TRANSPORT_EDR=%s -DWITH_TRANSPORT_BLE=%s -DWITH_TRANSPORT_NFC=%s -PTARGET_OS=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s -PWITH_TCP=%s -PMULTIPLE_OWNER=%s -PBUILD_DIR=%s --stacktrace' %(examples_target, TRANSPORT_EDR, TRANSPORT_BLE, TRANSPORT_NFC, target_os, TARGET_ARCH, RELEASE, SECURED, SECURED, CLOUD, RD_MODE, MQ_PUB, MQ_SUB, MQ_BROKER, TCP, ANDROID_MULTIPLE_OWNER, env.get('BUILD_DIR'))) #cmdBuildExamples=jdk_env.Gradle(target="../examples-%s/devicediscoveryclient/apk" % (examples_target, ), source="examples-%s/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java" % (examples_target, )) cmdBuildExamples=jdk_env.Gradle(target="examples-%s/simpleclient/jar" % (examples_target, ), source="examples-%s/simpleclient/src/main/java/org/iotivity/base/examples/SimpleClient.java" % (examples_target, )) diff --git a/java/common/src/main/java/org/iotivity/base/MomType.java b/java/common/src/main/java/org/iotivity/base/MomType.java new file mode 100644 index 0000000..7c0c9e6 --- /dev/null +++ b/java/common/src/main/java/org/iotivity/base/MomType.java @@ -0,0 +1,40 @@ +/* + ******************************************************************* + * + * 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.base; + +public enum MomType { + OIC_MULTIPLE_OWNER_DISABLE(0), + OIC_MULTIPLE_OWNER_ENABLE(1), + OIC_MULTIPLE_OWNER_TIMELY_ENABLE(2), + OIC_NUMBER_OF_MOM_TYPE(3); + + private int value; + + private MomType(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } +} diff --git a/java/common/src/main/java/org/iotivity/base/OcProvisioning.java b/java/common/src/main/java/org/iotivity/base/OcProvisioning.java index f1a6946..31642f9 100644 --- a/java/common/src/main/java/org/iotivity/base/OcProvisioning.java +++ b/java/common/src/main/java/org/iotivity/base/OcProvisioning.java @@ -99,6 +99,38 @@ public class OcProvisioning { public String pinCallbackListener(); } + + /** + * Method to Discover devices which are MOT (Multiple owner transfer) enabled + * and unowned. + * + * @param timeout Timeout in sec.Time to listen for responses before + * returining the Array. + * @return Array of OcSecureResource class objects. + * @throws OcException + */ + public static List discoverMOTEnabledDevices(int timeout) + throws OcException { + return Arrays.asList(OcProvisioning.discoverMOTEnabledDevices1(timeout)); + } + private static native OcSecureResource[] discoverMOTEnabledDevices1(int timeout) + throws OcException; + + /** + * Method to Discover devices which are MOT (Multiple owner transfer) enabled and Owned. + * + * @param timeout Timeout in sec.Time to listen for responses before + * returining the Array. + * @return Array of OcSecureResource class objects. + * @throws OcException + */ + public static List discoverMOTEnabledOwnedDevices(int timeout) + throws OcException { + return Arrays.asList(OcProvisioning.discoverMOTEnabledOwnedDevices1(timeout)); + } + private static native OcSecureResource[] discoverMOTEnabledOwnedDevices1(int timeout) + throws OcException; + /** * Server API to set Callback for Displaying stack generated PIN. * diff --git a/java/common/src/main/java/org/iotivity/base/OcSecureResource.java b/java/common/src/main/java/org/iotivity/base/OcSecureResource.java index d054f6f..9f7f295 100644 --- a/java/common/src/main/java/org/iotivity/base/OcSecureResource.java +++ b/java/common/src/main/java/org/iotivity/base/OcSecureResource.java @@ -193,6 +193,116 @@ public class OcSecureResource { throws OcException; /** + * API to select OTM method. + * + * @param OxmType Method to be selected + * @param SelectOTMMethodListener Callback function, which will be called after completion + * + * @throws OcException + */ + public void selectMOTMethod(OxmType oxmType, + SelectOTMMethodListener selectOTMMethodListener) throws OcException { + this.selectMOTMethod0(oxmType.getValue(), selectOTMMethodListener); + } + + private native void selectMOTMethod0(int oxmType, + SelectOTMMethodListener selectOTMMethodListener) throws OcException; + + /** + * API to change Multiple Owner Transfer(MOT) mode. + * + * @param MomType MOT mode to be selected. + * @param ChangeMOTModeListener Callback function, which will be called after completion + * + * @throws OcException + */ + public void changeMOTMode(MomType momType, + ChangeMOTModeListener changeMOTModeListener) throws OcException { + this.changeMOTMode0(momType.getValue(), changeMOTModeListener); + } + + private native void changeMOTMode0(int momType, + ChangeMOTModeListener changeMOTModeListener) throws OcException; + + /** + * API to Add preConfigured PIN to local SVR DB. + * + * @param String pin string to be saved in svr db. + * + * @throws OcException + */ + public void addPreConfigPIN(String pin) throws OcException { + this.addPreConfigPIN0(pin, pin.length()); + } + + private native void addPreConfigPIN0(String pin, int pinLength) throws OcException; + + /** + * API to provision preConfigured PIN. + * + * @param String PIN to be used while authentication. + * @param ProvisionPreConfigPINListener Callback function, which will be called after + * completion + * + * @throws OcException + */ + public void provisionPreConfigPIN(String pin, + ProvisionPreConfigPINListener provisionPreConfigPINListener) throws OcException { + this.provisionPreConfigPIN0(pin, pin.length(), provisionPreConfigPINListener); + } + + private native void provisionPreConfigPIN0(String pin, int pinLength, + ProvisionPreConfigPINListener provisionPreConfigPINListener) throws OcException; + + /** + * API to do Multiple Ownership Transfer for MOT enabled devices. + * + * @param MultipleOwnershipTransferListener Callback function, which will + * be called after completion. + * + * @throws OcException + */ + public native void doMultipleOwnershipTransfer( + DoMultipleOwnershipTransferListener doMultipleOwnershipTransferListener); + + /** + * selectOTMMethodListener can be registered with selectOTMMethod call. + * Listener notified asynchronously. + */ + public interface SelectOTMMethodListener { + public void selectOTMMethodListener(List provisionResultList, + int hasError); + } + + /** + * changeMOTModeListener can be registered with changeMOTMode call. + * Listener notified asynchronously. + */ + public interface ChangeMOTModeListener { + public void changeMOTModeListener(List provisionResultList, + int hasError); + } + + /** + * provisionPreConfigPINListener can be registered with ProvisionPreConfigPIN call. + * Listener notified asynchronously. + */ + public interface ProvisionPreConfigPINListener { + public void provisionPreConfigPINListener(List provisionResultList, + int hasError); + } + + /** + * doMultipleOwnershipTransferListener can be registered with doMultipleOwnershipTransfer + * call. + * Listener notified asynchronously. + */ + public interface DoMultipleOwnershipTransferListener { + public void doMultipleOwnershipTransferListener(List provisionResultList, + int hasError); + } + + /** * provisionDirectPairingListener can be registered with doOwnershipTransfer * call. * Listener notified asynchronously. @@ -251,7 +361,7 @@ public class OcSecureResource { public void provisionTrustCertChainListener(List provisionResultList, int hasError); } - + /** * provisionAclListener can be registered with provisionAclListener * call. diff --git a/java/common/src/main/java/org/iotivity/base/OxmType.java b/java/common/src/main/java/org/iotivity/base/OxmType.java index c8247de..6e1ca14 100755 --- a/java/common/src/main/java/org/iotivity/base/OxmType.java +++ b/java/common/src/main/java/org/iotivity/base/OxmType.java @@ -26,6 +26,7 @@ public enum OxmType { OIC_JUST_WORKS(0), OIC_RANDOM_DEVICE_PIN(1), OIC_MANUFACTURER_CERTIFICATE(2), + OIC_PRECONFIG_PIN(65280), OIC_OXM_COUNT(3); private int value; diff --git a/java/iotivity-android/build.gradle b/java/iotivity-android/build.gradle index 99f8721..a650c31 100755 --- a/java/iotivity-android/build.gradle +++ b/java/iotivity-android/build.gradle @@ -84,6 +84,7 @@ android { buildConfigField "int", 'WITH_TRANSPORT_EDR', WITH_TRANSPORT_EDR buildConfigField "int", 'WITH_TRANSPORT_BLE', WITH_TRANSPORT_BLE buildConfigField "int", 'WITH_TRANSPORT_NFC', WITH_TRANSPORT_NFC + buildConfigField "int", 'MULTIPLE_OWNER', MULTIPLE_OWNER } buildTypes { release { @@ -159,7 +160,7 @@ task buildNative(type: Exec) { //for windows use 'ndk-build.cmd' //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd') def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build') - commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", "SECURE=$SECURED", "WITH_CLOUD=$WITH_CLOUD", "RD_MODE=$RD_MODE", "WITH_MQ_PUB=$WITH_MQ_PUB", "WITH_MQ_SUB=$WITH_MQ_SUB", "WITH_MQ_BROKER=$WITH_MQ_BROKER", "WITH_TCP=$WITH_TCP" + commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", "SECURE=$SECURED", "WITH_CLOUD=$WITH_CLOUD", "RD_MODE=$RD_MODE", "WITH_MQ_PUB=$WITH_MQ_PUB", "WITH_MQ_SUB=$WITH_MQ_SUB", "WITH_MQ_BROKER=$WITH_MQ_BROKER", "WITH_TCP=$WITH_TCP","MULTIPLE_OWNER=$MULTIPLE_OWNER" } else { println '##################' println 'Skipping NDK build' diff --git a/java/jni/JniOcProvisioning.cpp b/java/jni/JniOcProvisioning.cpp index f31e561..ec995c3 100644 --- a/java/jni/JniOcProvisioning.cpp +++ b/java/jni/JniOcProvisioning.cpp @@ -474,6 +474,91 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); } } + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: discoverMOTEnabledDevices1 + * Signature: (I)[Lorg/iotivity/base/OcSecureResource; + */ +JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverMOTEnabledDevices1 + (JNIEnv *env, jclass thiz, jint timeout) +{ + LOGI("OcProvisioning_discoverMOTEnabledDevices1"); +#if defined(MULTIPLE_OWNER) + DeviceList_t list; + + try + { + if (timeout < 0) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "Timeout value cannot be negative"); + return nullptr; + } + OCStackResult result = OCSecure::discoverMultipleOwnerEnabledDevices( + (unsigned short)timeout, list); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to discover MOT Enabled devices"); + return nullptr; + } + + return JniSecureUtils::convertDeviceVectorToJavaArray(env, list); + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + return nullptr; + } +#else + ThrowOcException(OC_STACK_INVALID_PARAM, "MULTIPLE_OWNER not enabled"); + return nullptr; +#endif +} + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: discoverMOTEnabledOwnedDevices1 + * Signature: (I)[Lorg/iotivity/base/OcSecureResource; + */ +JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverMOTEnabledOwnedDevices1 + (JNIEnv *env, jclass thiz, jint timeout) +{ + LOGI("OcProvisioning_discoverMOTEnabledOwnedDevices1"); +#if defined(MULTIPLE_OWNER) + DeviceList_t list; + + try + { + if (timeout < 0) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "Timeout value cannot be negative"); + return nullptr; + } + OCStackResult result = OCSecure::discoverMultipleOwnedDevices( + (unsigned short)timeout, list); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to discover MOT Enabled Owned devices"); + return nullptr; + } + + return JniSecureUtils::convertDeviceVectorToJavaArray(env, list); + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + return nullptr; + } +#else + ThrowOcException(OC_STACK_INVALID_PARAM, "MULTIPLE_OWNER not enabled"); + return nullptr; +#endif +} + /* * Class: org_iotivity_base_OcProvisioning * Method: saveTrustCertChain1 diff --git a/java/jni/JniOcProvisioning.h b/java/jni/JniOcProvisioning.h index 702bc9e..a8b8733 100644 --- a/java/jni/JniOcProvisioning.h +++ b/java/jni/JniOcProvisioning.h @@ -116,6 +116,20 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_unsetConfirmNumList * Signature: (I)I */ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_setMVJustWorksOptions0 +(JNIEnv *, jclass, jint); +/* + * Method: discoverMOTEnabledDevices1 + * Signature: (I)[Lorg/iotivity/base/OcSecureResource; + */ +JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverMOTEnabledDevices1 + (JNIEnv *, jclass, jint); + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: discoverMOTEnabledOwnedDevices1 + * Signature: (I)[Lorg/iotivity/base/OcSecureResource; + */ +JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverMOTEnabledOwnedDevices1 (JNIEnv *, jclass, jint); /* diff --git a/java/jni/JniOcSecureResource.cpp b/java/jni/JniOcSecureResource.cpp index e399677..c470d34 100644 --- a/java/jni/JniOcSecureResource.cpp +++ b/java/jni/JniOcSecureResource.cpp @@ -409,6 +409,68 @@ OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint ty } return ret; } +#if defined(MULTIPLE_OWNER) +OCStackResult JniOcSecureResource::selectMOTMethod(JNIEnv* env, jint oxmSel, jobject jListener) +{ + OCStackResult ret; + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + + ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError) + { + resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::SELECT_OTM_METHOD); + }; + ret = m_sharedSecureResource->selectMOTMethod((const OicSecOxm_t)oxmSel, resultCallback); + return ret; +} + +OCStackResult JniOcSecureResource::changeMOTMode(JNIEnv* env, jint momType, jobject jListener) +{ + OCStackResult ret; + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + + ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError) + { + resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::CHANGE_MOT_MODE); + }; + ret = m_sharedSecureResource->changeMOTMode((const OicSecMomType_t)momType, resultCallback); + return ret; +} + +OCStackResult JniOcSecureResource::addPreconfigPIN(JNIEnv* env, std::string pin, int size) +{ + OCStackResult ret; + ret = m_sharedSecureResource->addPreconfigPIN(pin.c_str(), (size_t) size); + return ret; +} + +OCStackResult JniOcSecureResource::provisionPreconfPin(JNIEnv* env, std::string pin, + int size, jobject jListener) +{ + OCStackResult ret; + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + + ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError) + { + resultListener->ProvisionResultCallback(result, hasError, + ListenerFunc::PROVISION_PRE_CONFIG_PIN); + }; + ret = m_sharedSecureResource->provisionPreconfPin(pin.c_str(), (size_t)size, resultCallback); + return ret; +} + +OCStackResult JniOcSecureResource::doMultipleOwnershipTransfer(JNIEnv* env, jobject jListener) +{ + OCStackResult ret; + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + + ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError) + { + resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::MULTIPLE_OXM); + }; + ret = m_sharedSecureResource->doMultipleOwnershipTransfer(resultCallback); + return ret; +} +#endif /* * Class: org_iotivity_base_OcSecureResource @@ -767,6 +829,229 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionDirectPa /* * Class: org_iotivity_base_OcSecureResource + * Method: selectMOTMethod0 + * Signature: (ILorg/iotivity/base/OcSecureResource/SelectOTMMethodListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_selectMOTMethod0 + (JNIEnv *env, jobject thiz, jint oxmSelVal, jobject jListener) +{ + LOGD("OcSecureResource_selectMOTMethod0"); +#if defined(MULTIPLE_OWNER) + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Invalid Callback"); + return; + } + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); + return; + } + + try + { + OCStackResult result = secureResource->selectMOTMethod(env, oxmSelVal, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_selectMOTMethod0"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(OC_STACK_INVALID_PARAM, "MULTIPLE_OWNER not enabled"); + return; +#endif +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: changeMOTMode0 + * Signature: (ILorg/iotivity/base/OcSecureResource/ChangeMOTModeListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_changeMOTMode0 + (JNIEnv *env, jobject thiz, jint momType, jobject jListener) +{ + LOGD("OcSecureResource_changeMOTMode0"); +#if defined(MULTIPLE_OWNER) + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Invalid Callback"); + return; + } + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); + return; + } + + try + { + OCStackResult result = secureResource->changeMOTMode(env, momType, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_changeMOTMode0"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(OC_STACK_INVALID_PARAM, "MULTIPLE_OWNER not enabled"); + return; +#endif +} +/* + * Class: org_iotivity_base_OcSecureResource + * Method: addPreConfigPIN0 + * Signature: (Ljava/lang/String;I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_addPreConfigPIN0 + (JNIEnv *env, jobject thiz, jstring jPin, jint pinSize) +{ + LOGD("OcSecureResource_addPreConfigPIN0"); +#if defined(MULTIPLE_OWNER) + if (!jPin) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "Invalid Parameters"); + return; + } + + std::string pin = env->GetStringUTFChars(jPin, nullptr); + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); + return; + } + + try + { + OCStackResult result = secureResource->addPreconfigPIN(env, pin, pinSize); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_addPreConfigPIN0"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(OC_STACK_INVALID_PARAM, "MULTIPLE_OWNER not enabled"); + return; +#endif +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: provisionPreConfigPIN0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcSecureResource/ProvisionPreConfigPINListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionPreConfigPIN0 + (JNIEnv *env, jobject thiz, jstring jPin, jint pinSize, jobject jListener) +{ + LOGD("OcSecureResource_provisionPreConfigPIN0"); +#if defined(MULTIPLE_OWNER) + if (!jPin) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "Invalid Parameters"); + return; + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Invalid callback"); + return; + } + + std::string pin = env->GetStringUTFChars(jPin, nullptr); + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); + return; + } + + try + { + OCStackResult result = secureResource->provisionPreconfPin(env, pin, pinSize, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_provisionPreConfigPIN0"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(OC_STACK_INVALID_PARAM, "MULTIPLE_OWNER not enabled"); + return; +#endif +} + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: doMultipleOwnershipTransfer + * Signature: (Lorg/iotivity/base/OcSecureResource/DoMultipleOwnershipTransferListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_doMultipleOwnershipTransfer + (JNIEnv *env, jobject thiz, jobject jListener) +{ + LOGD("OcSecureResource_doMultipleOwnershipTransfer"); +#if defined(MULTIPLE_OWNER) + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "doMultipleOwnershipTransfer cannot be null"); + return; + } + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); + return; + } + + try + { + OCStackResult result = secureResource->doMultipleOwnershipTransfer(env, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_doMultipleOwnershipTransfer"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(OC_STACK_INVALID_PARAM, "MULTIPLE_OWNER not enabled"); + return; +#endif +} + +/* + * Class: org_iotivity_base_OcSecureResource * Method: getLinkedDevices * Signature: ()Ljava/util/List; */ diff --git a/java/jni/JniOcSecureResource.h b/java/jni/JniOcSecureResource.h index 55218e6..0cd820f 100644 --- a/java/jni/JniOcSecureResource.h +++ b/java/jni/JniOcSecureResource.h @@ -59,6 +59,12 @@ class JniOcSecureResource OCStackResult removeDevice(JNIEnv* env, jint timeout, jobject jListener); OCStackResult provisionDirectPairing(JNIEnv* env, jobjectArray jpdacls,jobject jListener, std::string pin, std::vector prms, int edp); + OCStackResult selectMOTMethod(JNIEnv* env, jint oxmSel, jobject jListener); + OCStackResult changeMOTMode(JNIEnv* env, jint momType, jobject jListener); + OCStackResult addPreconfigPIN(JNIEnv* env, std::string pin, int size); + OCStackResult provisionPreconfPin(JNIEnv* env, std::string pin, int size, + jobject jListener); + OCStackResult doMultipleOwnershipTransfer(JNIEnv* env, jobject jListener); private: std::map> resultMap; @@ -145,6 +151,46 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcSecureResource_getLinkedDevic /* * Class: org_iotivity_base_OcSecureResource + * Method: selectMOTMethod0 + * Signature: (ILorg/iotivity/base/OcSecureResource/SelectOTMMethodListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_selectMOTMethod0 + (JNIEnv *, jobject, jint, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: changeMOTMode0 + * Signature: (ILorg/iotivity/base/OcSecureResource/ChangeMOTModeListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_changeMOTMode0 + (JNIEnv *, jobject, jint, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: addPreConfigPIN0 + * Signature: (Ljava/lang/String;I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_addPreConfigPIN0 + (JNIEnv *, jobject, jstring, jint); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: provisionPreConfigPIN0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcSecureResource/ProvisionPreConfigPINListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionPreConfigPIN0 + (JNIEnv *, jobject, jstring, jint, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: doMultipleOwnershipTransfer + * Signature: (Lorg/iotivity/base/OcSecureResource/DoMultipleOwnershipTransferListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_doMultipleOwnershipTransfer + (JNIEnv *, jobject, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource * Method: getIpAddr * Signature: ()Ljava/lang/String; */ diff --git a/java/jni/JniProvisionResultListner.cpp b/java/jni/JniProvisionResultListner.cpp index d0c2d8e..a4418d3 100644 --- a/java/jni/JniProvisionResultListner.cpp +++ b/java/jni/JniProvisionResultListner.cpp @@ -137,6 +137,26 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, calledFunc = "provisionDirectPairingListener"; } break; + case ListenerFunc::SELECT_OTM_METHOD: + { + calledFunc = "selectOTMMethodListener"; + } + break; + case ListenerFunc::CHANGE_MOT_MODE: + { + calledFunc = "changeMOTModeListener"; + } + break; + case ListenerFunc::PROVISION_PRE_CONFIG_PIN: + { + calledFunc = "provisionPreConfigPINListener"; + } + break; + case ListenerFunc::MULTIPLE_OXM: + { + calledFunc = "doMultipleOwnershipTransferListener"; + } + break; default: { checkExAndRemoveListener(env); diff --git a/java/jni/JniProvisionResultListner.h b/java/jni/JniProvisionResultListner.h index d3d4ac6..84988e3 100644 --- a/java/jni/JniProvisionResultListner.h +++ b/java/jni/JniProvisionResultListner.h @@ -37,7 +37,11 @@ enum class ListenerFunc UNLINKDEVICES, REMOVEDEVICE, PROVISIONPAIRWISEDEVICES, - PROVISIONDIRECTPAIRING + PROVISIONDIRECTPAIRING, + SELECT_OTM_METHOD, + CHANGE_MOT_MODE, + PROVISION_PRE_CONFIG_PIN, + MULTIPLE_OXM }; class JniProvisionResultListner diff --git a/java/jni/SConscript b/java/jni/SConscript index 997864d..1e5e5be 100644 --- a/java/jni/SConscript +++ b/java/jni/SConscript @@ -88,6 +88,9 @@ if target_os in ['darwin', 'ios']: if env.get('WITH_CLOUD'): jni_env.AppendUnique(CPPDEFINES = ['WITH_CLOUD']) +if env.get('MULTIPLE_OWNER') == 1: + jni_env.AppendUnique(CPPDEFINES = ['MULTIPLE_OWNER']) + if env.get('WITH_TCP'): jni_env.AppendUnique(CPPDEFINES = ['WITH_TCP', '__WITH_TLS__'])