1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "jni_easy_setup.h"
23 #include "jni_easy_setup_jvm.h"
24 #include "prov_adapter.h"
26 void JNIProvisioningStatusCallback(ProvisioningInfo * provInfo) {
27 JNIEnv *env = EasySetupJVM::getEnv();
29 LOGE("JNIProvisioningStatusCallback : Getting JNIEnv failed");
33 // Get EasySetupHandler class reference
34 jclass easysetupCallbacks = GetJClass(
35 EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);
36 if (NULL == easysetupCallbacks) {
38 "JNIProvisioningStatusCallback : GetJClass easysetupCallbacks failed");
39 EasySetupJVM::releaseEnv();
43 // Get the easysetupCallback class instance
44 jobject jobjectCallback = GetJObjectInstance(
45 EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);
46 if (NULL == jobjectCallback) {
47 LOGE("getInstance( %s) failed!",
48 EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);
49 EasySetupJVM::releaseEnv();
53 // Get onResourceCallback method reference
54 jmethodID method_id = env->GetMethodID(easysetupCallbacks,
55 "ProvisioningStatusCallBack",
56 METHOD_PROVISIONING_STATUS_INTEGER_CALLBACK);
57 if (NULL == method_id) {
59 "JNIProvisioningStatusCallback: onResourceCallback : GetMethodID failed");
60 EasySetupJVM::releaseEnv();
64 if ((env)->ExceptionCheck()) {
65 LOGE("JNIProvisioningStatusCallback : ExceptionCheck failed");
66 EasySetupJVM::releaseEnv();
70 if (NULL == method_id) {
71 LOGI("JNI method_id is NULL");
73 LOGI("JNI method_id is VALID");
76 if (provInfo->provStatus == DEVICE_PROVISIONED) {
82 env->CallVoidMethod(jobjectCallback, method_id, (jint) result);
85 EasySetupJVM::releaseEnv();
88 JNIEXPORT void JNICALL
89 JNIInitEasySetup(JNIEnv
94 LOGI("JNI JNIInitEasySetup: Enter");
98 RegisterCallback(JNIProvisioningStatusCallback);
101 JNIEXPORT void JNICALL
102 JNITerminateEasySetup(JNIEnv
107 LOGI("JNI JNITerminateEasySetup: Enter");
113 JNIEXPORT void JNICALL
114 JNIProvisionEnrollee(JNIEnv
122 jint jConnectivityType
125 LOGI("JNI JNIProvisionEnrollee: Enter");
129 LOGE("JNI JNIProvisionEnrollee : jIPAddress is NULL!");
133 const char *ipAddress = env->GetStringUTFChars(jIPAddress, NULL);
134 if (NULL == ipAddress)
136 LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
139 LOGI("JNI JNIProvisionEnrollee : ipAddress is : %s",ipAddress);
141 const char *netSSID = env->GetStringUTFChars(jNetSSID, NULL);
144 LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
147 LOGI("JNI JNIProvisionEnrollee : netSSID is : %s",netSSID);
149 const char *netPWD = env->GetStringUTFChars(jNetPWD, NULL);
152 LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
155 LOGI("JNI JNIProvisionEnrollee : netPWD is : %s",netPWD);
157 OCConnectivityType connecitivityType;
158 EnrolleeNWProvInfo netInfo =
161 .netAddressInfo.WIFI.ipAddress, ipAddress, IPV4_ADDR_SIZE-1);
163 .netAddressInfo.WIFI.ssid, netSSID, NET_WIFI_SSID_SIZE-1);
165 .netAddressInfo.WIFI.pwd, netPWD, NET_WIFI_PWD_SIZE-1);
167 connType = (OCConnectivityType) jConnectivityType;
172 StartProvisioning(&netInfo);
177 JNIEXPORT void JNICALL
178 JNIStopEnrolleeProvisioning(JNIEnv
184 LOGI("JNI Stop Easy Setup: Entering");
186 StopProvisioning((OCConnectivityType)