aboutsummaryrefslogtreecommitdiffstats
path: root/java/jni
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-09-15 10:59:36 +0200
committerSven Gothel <[email protected]>2021-09-15 10:59:36 +0200
commite4c14618bfae926adc4c12f7832b443a4b27a6d5 (patch)
treec4a1bacda565b54f8d2288ba2ab565d236020a5d /java/jni
parentc3968a061a0042c6ad17938638f397ddd42b3261 (diff)
Add advertising support (start with set-data and -params, stop) via HCIHandler
Reasonable default values have been chosen from the BT spec, which can be overriden using the HCIHandler and BTAdapter operations. The extended advertising operations are also supported (Bluetooth 5.0). +++ Successfully tested running: (0) Test machine with 2 adapter - adapter-1 DC:FB:48:00:90:19 (acting as client) - adapter-2 00:1A:7D:DA:71:08 (acting as peripheral) (1) Running dbt_peripheral00.cpp or DBTPeripheral.java as the advertising peripheral on the test machine. `direct_bt/dist-amd64$ ../scripts/run-dbt_peripheral00.sh -adapter 00:1A:7D:DA:71:08` or `direct_bt/dist-amd64$ ../scripts/run-java-peripheral00.sh -adapter 00:1A:7D:DA:71:08` (2) Running dbt_scanner10.cpp or DBTScanner10.java as the listeninig and connection-initiator client on the same test machine. `direct_bt/dist-amd64$ sh ../scripts/run-dbt_scanner10.sh -adapter DC:FB:48:00:90:19 -dev 00:1A:7D:DA:71:08 -seclevel 00:1A:7D:DA:71:08 1` or `direct_bt/dist-amd64$ sh ../scripts/run-java-scanner10.sh -adapter DC:FB:48:00:90:19 -dev 00:1A:7D:DA:71:08 -seclevel 00:1A:7D:DA:71:08 1`
Diffstat (limited to 'java/jni')
-rw-r--r--java/jni/direct_bt/DBTAdapter.cxx39
1 files changed, 39 insertions, 0 deletions
diff --git a/java/jni/direct_bt/DBTAdapter.cxx b/java/jni/direct_bt/DBTAdapter.cxx
index 5c430a7c..8f4ad701 100644
--- a/java/jni/direct_bt/DBTAdapter.cxx
+++ b/java/jni/direct_bt/DBTAdapter.cxx
@@ -987,3 +987,42 @@ void Java_jau_direct_1bt_DBTAdapter_printDeviceListsImpl(JNIEnv *env, jobject ob
rethrow_and_raise_java_exception(env);
}
}
+
+jbyte Java_jau_direct_1bt_DBTAdapter_startAdvertisingImpl(JNIEnv *env, jobject obj,
+ jshort adv_interval_min, jshort adv_interval_max, jbyte jadv_type, jbyte adv_chan_map,
+ jbyte filter_policy) {
+ try {
+ BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ const AD_PDU_Type adv_type = static_cast<AD_PDU_Type>(jadv_type);
+ HCIStatusCode res = adapter->startAdvertising(adv_interval_min, adv_interval_max, adv_type, adv_chan_map, filter_policy);
+ return (jbyte) number(res);
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
+}
+
+jbyte Java_jau_direct_1bt_DBTAdapter_stopAdvertisingImpl(JNIEnv *env, jobject obj) {
+ try {
+ BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ HCIStatusCode res = adapter->stopAdvertising();
+ return (jbyte) number(res);
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
+}
+
+jboolean Java_jau_direct_1bt_DBTAdapter_isAdvertising(JNIEnv *env, jobject obj) {
+ try {
+ BTAdapter *adapter = jau::getJavaUplinkObject<BTAdapter>(env, obj);
+ jau::JavaGlobalObj::check(adapter->getJavaObject(), E_FILE_LINE);
+ return adapter->isAdvertising() ? JNI_TRUE : JNI_FALSE;
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return JNI_FALSE;
+}
+