replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / android / android_api / base / jni / JniCaInterface.c
index 1e20461..2a7861b 100644 (file)
@@ -247,12 +247,6 @@ Java_org_iotivity_ca_CaInterface_caManagerTerminate(JNIEnv *env, jclass clazz)
         (*env)->DeleteGlobalRef(env, g_jni_cls_enum);
         g_jni_cls_enum = NULL;
     }
-
-    if (g_jni_mid_enum)
-    {
-        (*env)->DeleteGlobalRef(env, g_jni_mid_enum);
-        g_jni_mid_enum = NULL;
-    }
 }
 
 JNIEXPORT void JNICALL
@@ -261,6 +255,11 @@ Java_org_iotivity_ca_CaInterface_caManagerSetAutoConnectionDeviceInfo(JNIEnv *en
                                                                       jstring jaddress)
 {
     LOGI("CaManager_setAutoConnectionDeviceInfo");
+    if (!jaddress)
+    {
+        LOGE("jaddress is null");
+        return;
+    }
 
     const char* address = (*env)->GetStringUTFChars(env, jaddress, NULL);
     if (!address)
@@ -280,6 +279,11 @@ Java_org_iotivity_ca_CaInterface_caManagerUnsetAutoConnectionDeviceInfo(JNIEnv *
                                                                         jstring jaddress)
 {
     LOGI("CaManager_unsetAutoConnectionDeviceInfo");
+    if (!jaddress)
+    {
+        LOGE("jaddress is null");
+        return;
+    }
 
     const char* address = (*env)->GetStringUTFChars(env, jaddress, NULL);
     if (!address)
@@ -352,3 +356,84 @@ Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl(JNIEnv *env, jclass c
     CAUtilSetLEScanInterval(intervalTime, workignCount);
 }
 
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaInterface_stopLeScanImpl(JNIEnv *env, jclass clazz)
+{
+    LOGI("stopLeScan");
+    (void)env;
+    (void)clazz;
+    CAUtilStopLEScan();
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaInterface_startLeAdvertisingImpl(JNIEnv *env, jclass clazz)
+{
+    LOGI("startLeAdvertising");
+    (void)env;
+    (void)clazz;
+    CAUtilStartLEAdvertising();
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaInterface_stopLeAdvertisingImpl(JNIEnv *env, jclass clazz)
+{
+    LOGI("stopLeAdvertising");
+    (void)env;
+    (void)clazz;
+    CAUtilStopLEAdvertising();
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ca_CaInterface_setBTConfigureImpl(JNIEnv *env, jclass clazz, jint flag)
+{
+    LOGI("setConfigureImpl");
+    (void)env;
+    (void)clazz;
+    CAUtilConfig_t configs = {(CATransportBTFlags_t)flag};
+    CAUtilSetBTConfigure(configs);
+}
+
+JNIEXPORT jint JNICALL Java_org_iotivity_ca_CaInterface_setCipherSuiteImpl
+  (JNIEnv *env, jclass clazz, jint cipherSuite, jint adapter)
+{
+    LOGI("setCipherSuiteImpl");
+    (void)env;
+    (void)clazz;
+    CAResult_t ret = CASelectCipherSuite(cipherSuite, (CATransportAdapter_t) adapter);
+    if (CA_STATUS_OK != ret)
+    {
+        LOGE("CASelectCipherSuite has failed");
+    }
+    return ret;
+}
+
+JNIEXPORT jint JNICALL Java_org_iotivity_ca_CaInterface_disconnectTCPSessionImpl
+ (JNIEnv *env, jclass clazz, jstring address, jint port, jint transportFlags)
+{
+    LOGI("disconnectTCPSessionImpl");
+    (void)env;
+    (void)clazz;
+
+    if(!address)
+    {
+        LOGE("Java address is null");
+        return CA_STATUS_INVALID_PARAM;
+    }
+
+    //convert java string to native string
+    const char* nativeAddress = (*env)->GetStringUTFChars(env, address, NULL);
+    if (!nativeAddress)
+    {
+        LOGE("Native address is null");
+        return CA_STATUS_INVALID_PARAM;
+    }
+
+    CAResult_t result = CAUtilTCPDisconnectSession(nativeAddress, (int)port,
+                                            (CATransportFlags_t)transportFlags);
+    if (CA_STATUS_OK != result)
+    {
+        LOGE("disconnectTCPSessionImpl failed");
+    }
+    return result;
+}
+