}
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;
}
--- /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.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;
+ }
+}
/*
* 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
*/
*/
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
* 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);
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.
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.
*/
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
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)