From 975ca0cb883a4ba291be9024b60510f30a6ed866 Mon Sep 17 00:00:00 2001 From: "jihwan.seo" Date: Sat, 7 Jan 2017 15:20:26 +0900 Subject: [PATCH] [IOT-1731] To support start/stop LE advertising API for android since some application related gatt server want to have multi-connect scenario. we should provide start/stop advertising API. Change-Id: I3201e563cdd07bb84c38639f9a2b6743122b2385 Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/16221 Tested-by: jenkins-iotivity Reviewed-by: Ashok Babu Channa --- .../src/main/java/org/iotivity/ca/CaInterface.java | 16 +++++++++++++++ java/jni/JniCaInterface.c | 18 ++++++++++++++++ resource/csdk/connectivity/api/cautilinterface.h | 15 ++++++++++++++ .../connectivity/util/inc/camanagerleinterface.h | 13 +++++++++++- .../bt_le_manager/android/caleconnectionmanager.c | 20 ++++++++++++++++++ .../csdk/connectivity/util/src/cautilinterface.c | 24 ++++++++++++++++++++++ 6 files changed, 105 insertions(+), 1 deletion(-) diff --git a/java/iotivity-android/src/main/java/org/iotivity/ca/CaInterface.java b/java/iotivity-android/src/main/java/org/iotivity/ca/CaInterface.java index 173c7db..9a05ca7 100644 --- a/java/iotivity-android/src/main/java/org/iotivity/ca/CaInterface.java +++ b/java/iotivity-android/src/main/java/org/iotivity/ca/CaInterface.java @@ -218,6 +218,22 @@ public class CaInterface { } private static native void stopLeScanImpl(); + /** + * start BLE Advertising. + */ + public synchronized static void startLeAdvertising(){ + CaInterface.startLeAdvertisingImpl(); + } + private static native void startLeAdvertisingImpl(); + + /** + * stop BLE Advertising. + */ + public synchronized static void stopLeAdvertising(){ + CaInterface.stopLeAdvertisingImpl(); + } + private static native void stopLeAdvertisingImpl(); + public synchronized static int setCipherSuite(OicCipher cipher, OcConnectivityType connType){ return CaInterface.setCipherSuiteImpl(cipher.getValue(), connType.getValue()); } diff --git a/java/jni/JniCaInterface.c b/java/jni/JniCaInterface.c index bcce5e8..d7ed9b2 100644 --- a/java/jni/JniCaInterface.c +++ b/java/jni/JniCaInterface.c @@ -411,6 +411,24 @@ Java_org_iotivity_ca_CaInterface_stopLeScanImpl(JNIEnv *env, jclass 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 jint JNICALL Java_org_iotivity_ca_CaInterface_setCipherSuiteImpl (JNIEnv *env, jclass clazz, jint cipherSuite, jint adapter) { diff --git a/resource/csdk/connectivity/api/cautilinterface.h b/resource/csdk/connectivity/api/cautilinterface.h index 9f58244..21fd27b 100644 --- a/resource/csdk/connectivity/api/cautilinterface.h +++ b/resource/csdk/connectivity/api/cautilinterface.h @@ -196,6 +196,21 @@ CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount); CAResult_t CAUtilStopLEScan(); #endif //__JAVA__ +#if defined(LE_ADAPTER) +// BLE util +/** + * start BLE advertising. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CAUtilStartLEAdvertising(); + +/** + * stop BLE advertising. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CAUtilStopLEAdvertising(); +#endif // LE_ADAPTER + #ifdef __cplusplus } /* extern "C" */ #endif //__cplusplus diff --git a/resource/csdk/connectivity/util/inc/camanagerleinterface.h b/resource/csdk/connectivity/util/inc/camanagerleinterface.h index b5f2dad..95f4916 100644 --- a/resource/csdk/connectivity/util/inc/camanagerleinterface.h +++ b/resource/csdk/connectivity/util/inc/camanagerleinterface.h @@ -78,9 +78,20 @@ void CAManagerLESetScanInterval(jint intervalTime, jint workingCount); * stop BLE scan. */ void CAManagerLEStopScan(); - #endif +/** + * start BLE advertising. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CAManagerLEStartAdvertising(); + +/** + * stop BLE advertising. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CAManagerLEStopAdvertising(); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/resource/csdk/connectivity/util/src/camanager/bt_le_manager/android/caleconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/bt_le_manager/android/caleconnectionmanager.c index f57aa45..edefd64 100644 --- a/resource/csdk/connectivity/util/src/camanager/bt_le_manager/android/caleconnectionmanager.c +++ b/resource/csdk/connectivity/util/src/camanager/bt_le_manager/android/caleconnectionmanager.c @@ -292,6 +292,26 @@ void CAManagerLEStopScan() CALERestartScanWithInterval(0, 0, BLE_SCAN_DISABLE); } +CAResult_t CAManagerLEStartAdvertising() +{ + CAResult_t ret = CALEServerStartAdvertise(); + if (CA_STATUS_OK != ret) + { + OIC_LOG(ERROR, TAG, "CALEServerStartAdvertise has failed"); + } + return ret; +} + +CAResult_t CAManagerLEStopAdvertising() +{ + CAResult_t ret = CALEServerStopAdvertise(); + if (CA_STATUS_OK != ret) + { + OIC_LOG(ERROR, TAG, "CALEServerStopAdvertise has failed"); + } + return ret; +} + JNIEXPORT void JNICALL Java_org_iotivity_ca_CaLeClientInterface_caManagerAdapterStateChangedCallback( JNIEnv *env, jobject obj, jint state) diff --git a/resource/csdk/connectivity/util/src/cautilinterface.c b/resource/csdk/connectivity/util/src/cautilinterface.c index 124b444..b5690f4 100644 --- a/resource/csdk/connectivity/util/src/cautilinterface.c +++ b/resource/csdk/connectivity/util/src/cautilinterface.c @@ -312,4 +312,28 @@ CAResult_t CAUtilStopLEScan() return CA_NOT_SUPPORTED; #endif } +#endif // __JAVA__ + +#if defined(LE_ADAPTER) +CAResult_t CAUtilStartLEAdvertising() +{ + OIC_LOG(DEBUG, TAG, "CAUtilStartLEAdvertising"); +#if defined(__ANDROID__) || defined(__TIZEN__) + return CAManagerLEStartAdvertising(); +#else + OIC_LOG(DEBUG, TAG, "it is not supported"); + return CA_NOT_SUPPORTED; +#endif +} + +CAResult_t CAUtilStopLEAdvertising() +{ + OIC_LOG(DEBUG, TAG, "CAUtilStopLEAdvertising"); +#if defined(__ANDROID__) || defined(__TIZEN__) + return CAManagerLEStopAdvertising(); +#else + OIC_LOG(DEBUG, TAG, "it is not supported"); + return CA_NOT_SUPPORTED; +#endif +} #endif -- 2.7.4