Added Android interface API setPinType().
authorsaurabh.s9 <saurabh.s9@samsung.com>
Fri, 27 Jan 2017 09:56:56 +0000 (15:26 +0530)
committerRandeep Singh <randeep.s@samsung.com>
Fri, 27 Jan 2017 11:30:11 +0000 (11:30 +0000)
Change-Id: I98ba58c440d252cc3f32dd589e1a0eed3935b675
Signed-off-by: Sandeep Sharma <sandeep.s9@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16307
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
Signed-off-by: Randeep Singh <randeep.s@samsung.com>
Signed-off-by: saurabh.s9 <saurabh.s9@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16525
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
java/common/src/main/java/org/iotivity/base/OcProvisioning.java
java/common/src/main/java/org/iotivity/base/PinType.java [new file with mode: 0755]
java/jni/JniOcProvisioning.cpp
java/jni/JniOcProvisioning.h
resource/include/OCProvisioningManager.hpp
resource/provisioning/src/OCProvisioningManager.cpp

index dfc2caa..51890fa 100644 (file)
@@ -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>  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 (executable)
index 0000000..65759fd
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ *******************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.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<PinType> convertToEnumSet(int value) {
+        EnumSet<PinType> 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;
+    }
+}
index fe2b834..94188c1 100644 (file)
@@ -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
  */
index 9c293fb..541b4e0 100644 (file)
@@ -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
index f0967c7..8c87009 100644 (file)
@@ -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
index fd4f127..9bc698d 100644 (file)
@@ -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<std::recursive_mutex> 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)