From 71b36b050696f3c707ea8d6d5ff3bb75d6bce0d2 Mon Sep 17 00:00:00 2001 From: "saurabh.s9" Date: Fri, 27 Jan 2017 15:26:56 +0530 Subject: [PATCH] Added Android interface API setPinType(). Change-Id: I98ba58c440d252cc3f32dd589e1a0eed3935b675 Signed-off-by: Sandeep Sharma Reviewed-on: https://gerrit.iotivity.org/gerrit/16307 Tested-by: jenkins-iotivity Reviewed-by: Randeep Singh Signed-off-by: Randeep Singh Signed-off-by: saurabh.s9 Reviewed-on: https://gerrit.iotivity.org/gerrit/16525 Tested-by: jenkins-iotivity --- .../java/org/iotivity/base/OcProvisioning.java | 19 +++++++ .../src/main/java/org/iotivity/base/PinType.java | 62 ++++++++++++++++++++++ java/jni/JniOcProvisioning.cpp | 27 ++++++++++ java/jni/JniOcProvisioning.h | 8 +++ resource/include/OCProvisioningManager.hpp | 24 +++++++++ .../provisioning/src/OCProvisioningManager.cpp | 18 +++++++ 6 files changed, 158 insertions(+) create mode 100755 java/common/src/main/java/org/iotivity/base/PinType.java 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 dfc2caa..51890fa 100644 --- a/java/common/src/main/java/org/iotivity/base/OcProvisioning.java +++ b/java/common/src/main/java/org/iotivity/base/OcProvisioning.java @@ -221,4 +221,23 @@ public class OcProvisioning { } private static native int saveTrustCertChain1(byte[] trustCertChain, int encodingType) throws OcException; + + /** + * Method to save pin type. + * + * @param pinSize Byte Len of Random pin. + * @param pinType Enumset of pin, see PinType for enums + * @throws OcException + */ + public static int setPinType(int pinSize, EnumSet pinType) throws OcException { + + int pinTypeInt = 0; + + for (PinType ops : PinType.values()) { + if (pinType.contains(ops)) + pinTypeInt |= ops.getValue(); + } + return setPinType0(pinSize, pinTypeInt); + } + private static native int setPinType0(int pinSize, int pinType) throws OcException; } diff --git a/java/common/src/main/java/org/iotivity/base/PinType.java b/java/common/src/main/java/org/iotivity/base/PinType.java new file mode 100755 index 0000000..65759fd --- /dev/null +++ b/java/common/src/main/java/org/iotivity/base/PinType.java @@ -0,0 +1,62 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +import java.security.InvalidParameterException; +import java.util.EnumSet; + +public enum PinType { + NUM_PIN (0x1 << 0), + UPPERCASE_CHAR_PIN (0x1 << 1), + LOWERCASE_CHAR_PIN (0x1 << 2), + ; + + private int value; + + private PinType(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } + + public static EnumSet convertToEnumSet(int value) { + EnumSet typeSet = null; + + for (PinType v : values()) { + if (0 != (value & v.getValue())) { + if (null == typeSet) { + typeSet = EnumSet.of(v); + } else { + typeSet.add(v); + } + } + } + + if (null == typeSet || typeSet.isEmpty()) { + throw new InvalidParameterException("Unexpected PinType value:" + value); + } + return typeSet; + } +} diff --git a/java/jni/JniOcProvisioning.cpp b/java/jni/JniOcProvisioning.cpp index fe2b834..94188c1 100644 --- a/java/jni/JniOcProvisioning.cpp +++ b/java/jni/JniOcProvisioning.cpp @@ -338,6 +338,33 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_unsetDisplayNumList /* * Class: org_iotivity_base_OcProvisioning + * Method: setPinType0 + * Signature: (II)I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_setPinType0 + (JNIEnv *env, jclass thiz, jint pinSize, jint pinType) +{ + LOGI("OcProvisioning_setPinType0"); + + OCStackResult result = OC_STACK_ERROR; + try + { + result = OCSecure::setRandomPinPolicy((size_t)pinSize, (OicSecPinType_t)pinType); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to set PinType"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); + } + return result; +} + +/* + * Class: org_iotivity_base_OcProvisioning * Method: setConfirmNumListener * Signature: (Lorg/iotivity/base/OcProvisioning/ConfirmNumListener;)V */ diff --git a/java/jni/JniOcProvisioning.h b/java/jni/JniOcProvisioning.h index 9c293fb..541b4e0 100644 --- a/java/jni/JniOcProvisioning.h +++ b/java/jni/JniOcProvisioning.h @@ -133,6 +133,14 @@ JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_getDeviceSt */ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_saveTrustCertChain1 (JNIEnv *, jobject, jbyteArray, jint); + +/* + * Class: org_iotivity_base_OcProvisioning + * Method: setPinType0 + * Signature: (II)I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_setPinType0 + (JNIEnv *, jclass, jint, jint); #ifdef __cplusplus } #endif diff --git a/resource/include/OCProvisioningManager.hpp b/resource/include/OCProvisioningManager.hpp index f0967c7..8c87009 100644 --- a/resource/include/OCProvisioningManager.hpp +++ b/resource/include/OCProvisioningManager.hpp @@ -268,12 +268,17 @@ namespace OC * to be registered at a time by setInputPinCallback and registerInputPinCallback. * Use unsetInputPinCallback to unregister a callback set by setInputPinCallback. * + * @deprecated Use registerInputPinCallback instead. * * @param InputPinCallback inputPin callback function. * @return OC_STACK_OK in case of success and other value otherwise. * OC_STACK_INVALID_CALLBACK if inputPin is invalid. * OC_STACK_DUPLICATE_REQUEST if an input pin callback has already been set. + + + + */ static OCStackResult setInputPinCallback(InputPinCallback inputPin); @@ -287,6 +292,7 @@ namespace OC static OCStackResult unsetInputPinCallback(); /** + * API to register for a callback to input a pin. Only one input pin callback is allowed * to be registered at a time by setInputPinCallback and registerInputPinCallback. Use * deregisterInputPinCallback to unregister a callback set by registerInputPinCallback. @@ -332,6 +338,15 @@ namespace OC static OCStackResult unsetDisplayPinCB(); /** + * API to set Pin Type policy. + * + * @param pinSize pin Size + * @param pinType Type of the pin. + * @return OC_STACK_OK in case of success and other value otherwise. + */ + static OCStackResult setRandomPinPolicy(size_t pinSize, OicSecPinType_t pinType); + + /** * API to register for a callback to display a pin. Only one display pin callback is * allowed to be registered at a time by setDisplayPinCB and registerDisplayPinCallback. * Use deregisterDisplayPinCallback to unregister a callback set by registerDisplayPinCallback. @@ -353,6 +368,15 @@ namespace OC */ static OCStackResult deregisterDisplayPinCallback(DisplayPinCallbackHandle displayPinCallbackHandle); + + + + + + + + + /** * API to get status of all the devices in current subnet. The status include endpoint * information and doxm information which can be extracted during owned and unowned diff --git a/resource/provisioning/src/OCProvisioningManager.cpp b/resource/provisioning/src/OCProvisioningManager.cpp index fd4f127..9bc698d 100644 --- a/resource/provisioning/src/OCProvisioningManager.cpp +++ b/resource/provisioning/src/OCProvisioningManager.cpp @@ -469,6 +469,24 @@ namespace OC return result; } + OCStackResult OCSecure::setRandomPinPolicy(size_t pinSize, OicSecPinType_t pinType) + { + OCStackResult result; + auto cLock = OCPlatform_impl::Instance().csdkLock().lock(); + + if (cLock) + { + std::lock_guard lock(*cLock); + result = SetRandomPinPolicy(pinSize, pinType); + } + else + { + oclog() <<"Mutex not found"; + result = OC_STACK_ERROR; + } + return result; + } + OCStackResult OCSecure::getDevInfoFromNetwork(unsigned short timeout, DeviceList_t &ownedDevList, DeviceList_t &unownedDevList) -- 2.7.4