2 * //******************************************************************
4 * // Copyright 2015 Samsung Electronics All Rights Reserved.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
12 * // http://www.apache.org/licenses/LICENSE-2.0
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 #include "JniOcProvisioning.h"
24 #include "JniPinCheckListener.h"
27 namespace PH = std::placeholders;
29 static JniPinCheckListener *PinListener = nullptr;
31 void Callback(char *buf, size_t size)
35 PinListener->PinCallback(buf, size);
39 LOGE("PinListener is null");
44 * Class: org_iotivity_base_OcProvisioning
45 * Method: ownershipTransferCDdata
48 JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_ownershipTransferCBdata
49 (JNIEnv *env, jobject thiz, jint OxmType, jobject jListener)
51 LOGD("OcProvisioning_ownershipTransferCBdata");
52 OCStackResult result = OC_STACK_ERROR;
56 OTMCallbackData_t CBData = {0};
57 if (OIC_JUST_WORKS == (OicSecOxm_t)OxmType)
59 CBData.loadSecretCB = LoadSecretJustWorksCallback;
60 CBData.createSecureSessionCB = CreateSecureSessionJustWorksCallback;
61 CBData.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload;
62 CBData.createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload;
64 result = OCSecure::setOwnerTransferCallbackData((OicSecOxm_t)OxmType,
67 if (OIC_RANDOM_DEVICE_PIN == (OicSecOxm_t)OxmType)
72 PinListener = new JniPinCheckListener(env, jListener);
73 CBData.loadSecretCB = InputPinCodeCallback;
74 CBData.createSecureSessionCB = CreateSecureSessionRandomPinCallbak;
75 CBData.createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload;
76 CBData.createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload;
77 result = OCSecure::setOwnerTransferCallbackData((OicSecOxm_t)OxmType,
82 result = OC_STACK_ERROR;
86 if (OC_STACK_OK != result)
88 ThrowOcException(result, "OcProvisioning_ownershipTransferCDdata");
92 catch (OCException& e)
94 LOGE("%s", e.reason().c_str());
95 ThrowOcException(e.code(), e.reason().c_str());
100 * Class: org_iotivity_base_OcProvisioning
101 * Method: discoverUnownedDevices
102 * Signature: (I)[Lorg/iotivity/base/OcSecureResource;
104 JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverUnownedDevices1
105 (JNIEnv *env, jclass clazz, jint timeout)
107 LOGI("OcProvisioning_discoverUnownedDevices");
112 OCStackResult result = OCSecure::discoverUnownedDevices((unsigned short)timeout, list);
114 if (OC_STACK_OK != result)
116 ThrowOcException(result, "Failed to discover Unowned devices");
120 return JniSecureUtils::convertDeviceVectorToJavaArray(env, list);
122 catch (OCException& e)
124 LOGE("%s", e.reason().c_str());
125 ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
130 * Class: org_iotivity_base_OcProvisioning
131 * Method: provisionInit
132 * Signature: (Ljava/lang/String;)V
134 JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_provisionInit
135 (JNIEnv *env, jclass calzz, jstring jdbPath)
137 LOGI("OcProvisioning_provisionInit");
142 ThrowOcException(OC_STACK_INVALID_PARAM, "SVR db path cannot be null");
148 dbpath = (char*)env->GetStringUTFChars(jdbPath, NULL);
149 OCStackResult result = OCSecure::provisionInit(env->GetStringUTFChars(jdbPath, NULL));
151 if (OC_STACK_OK != result)
153 env->ReleaseStringUTFChars(jdbPath, (const char*)dbpath);
154 ThrowOcException(result, "Failed to Init Provisioning Manager");
157 env->ReleaseStringUTFChars(jdbPath, (const char*)dbpath);
159 catch (OCException& e)
161 LOGE("%s", e.reason().c_str());
162 ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
167 * Class: org_iotivity_base_OcProvisioning
168 * Method: discoverOwnedDevices
169 * Signature: (I)[Lorg/iotivity/base/OcSecureResource;
171 JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_discoverOwnedDevices1
172 (JNIEnv *env, jclass clazz , jint timeout)
174 LOGI("OcProvisioning_discoverOwnedDevices");
179 OCStackResult result = OCSecure::discoverOwnedDevices((unsigned short)timeout, list);
180 if (OC_STACK_OK != result)
182 ThrowOcException(result, "Failed to discover Owned devices");
186 return JniSecureUtils::convertDeviceVectorToJavaArray(env, list);
188 catch (OCException& e)
190 LOGE("%s", e.reason().c_str());
191 ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
196 * Class: org_iotivity_base_OcProvisioning
197 * Method: getDevicestatusLists
198 * Signature: (I)[Lorg/iotivity/base/OcSecureResource;
200 JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_getDeviceStatusList1
201 (JNIEnv *env, jclass clazz, jint timeout)
203 LOGI("OcProvisioning_getDeviceStatusList");
204 DeviceList_t ownedDevList, unownedDevList;
208 OCStackResult result = OCSecure::getDevInfoFromNetwork((unsigned short)timeout,
209 ownedDevList, unownedDevList);
210 if (OC_STACK_OK != result)
212 ThrowOcException(result, "Failed to get Device Status List");
215 ownedDevList.insert(ownedDevList.end(), unownedDevList.begin(), unownedDevList.end());
216 return JniSecureUtils::convertDeviceVectorToJavaArray(env, ownedDevList);
218 catch (OCException& e)
220 LOGE("%s", e.reason().c_str());
221 ThrowOcException(OC_STACK_ERROR, e.reason().c_str());