summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-04-20 09:25:02 +0200
committerSven Gothel <[email protected]>2022-04-20 09:25:02 +0200
commit557c3e221fea05533c8c4cde555c35f795fc0191 (patch)
tree0770f07d5b2625581342dc88ebd912445c621357 /java
parentb8d4c5817aeb2ec92c97be6fef44f40d280a614c (diff)
Expose original AD_IND and AD_SCAN_RSP EIR in BTDevice, uniquely indicated by its EInfoReport::Source and use it to complete exact advertising in dbt_repeater00
Diffstat (limited to 'java')
-rw-r--r--java/jau/direct_bt/DBTDevice.java20
-rw-r--r--java/jni/direct_bt/DBTDevice.cxx30
-rw-r--r--java/jni/direct_bt/EInfoReport.cxx10
-rw-r--r--java/org/direct_bt/BTDevice.java18
-rw-r--r--java/org/direct_bt/EIRDataTypeSet.java4
-rw-r--r--java/org/direct_bt/EInfoReport.java37
6 files changed, 117 insertions, 2 deletions
diff --git a/java/jau/direct_bt/DBTDevice.java b/java/jau/direct_bt/DBTDevice.java
index 56c8c432..b3945db8 100644
--- a/java/jau/direct_bt/DBTDevice.java
+++ b/java/jau/direct_bt/DBTDevice.java
@@ -71,6 +71,8 @@ public class DBTDevice extends DBTObject implements BTDevice
private volatile String name_cached;
/* pp */ final List<WeakReference<DBTGattService>> serviceCache = new ArrayList<WeakReference<DBTGattService>>();
private final EInfoReport eir_ = new EInfoReport();
+ private final EInfoReport eir_ind_ = new EInfoReport();
+ private final EInfoReport eir_scan_rsp_ = new EInfoReport();
private final AtomicBoolean isClosing = new AtomicBoolean(false);
@@ -636,6 +638,24 @@ public class DBTDevice extends DBTObject implements BTDevice
private native void getEIRImpl(final EInfoReport eir);
@Override
+ public EInfoReport getEIRInd() {
+ synchronized( eir_ind_ ) {
+ getEIRIndImpl(eir_ind_);
+ return eir_ind_;
+ }
+ }
+ private native void getEIRIndImpl(final EInfoReport eir);
+
+ @Override
+ public EInfoReport getEIRScanRsp() {
+ synchronized( eir_scan_rsp_ ) {
+ getEIRScanRspImpl(eir_scan_rsp_);
+ return eir_scan_rsp_;
+ }
+ }
+ private native void getEIRScanRspImpl(final EInfoReport eir);
+
+ @Override
public native short getTxPower ();
/**
diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx
index 84783f15..86f22c09 100644
--- a/java/jni/direct_bt/DBTDevice.cxx
+++ b/java/jni/direct_bt/DBTDevice.cxx
@@ -965,6 +965,36 @@ void Java_jau_direct_1bt_DBTDevice_getEIRImpl(JNIEnv *env, jobject obj, jobject
}
}
+void Java_jau_direct_1bt_DBTDevice_getEIRIndImpl(JNIEnv *env, jobject obj, jobject jeir_sink) {
+ try {
+ BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
+ std::shared_ptr<EInfoReport>* eir_sink_ptr_ref = jau::getInstance<std::shared_ptr<EInfoReport>>(env, jeir_sink);
+
+ std::shared_ptr<EInfoReport> eir = device->getEIRInd();
+
+ // replace the shared managed object
+ *eir_sink_ptr_ref = eir;
+
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+}
+
+void Java_jau_direct_1bt_DBTDevice_getEIRScanRspImpl(JNIEnv *env, jobject obj, jobject jeir_sink) {
+ try {
+ BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
+ std::shared_ptr<EInfoReport>* eir_sink_ptr_ref = jau::getInstance<std::shared_ptr<EInfoReport>>(env, jeir_sink);
+
+ std::shared_ptr<EInfoReport> eir = device->getEIRScanRsp();
+
+ // replace the shared managed object
+ *eir_sink_ptr_ref = eir;
+
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+}
+
jshort Java_jau_direct_1bt_DBTDevice_getTxPower(JNIEnv *env, jobject obj)
{
try {
diff --git a/java/jni/direct_bt/EInfoReport.cxx b/java/jni/direct_bt/EInfoReport.cxx
index d2ef7c7d..eecf2d84 100644
--- a/java/jni/direct_bt/EInfoReport.cxx
+++ b/java/jni/direct_bt/EInfoReport.cxx
@@ -366,6 +366,16 @@ jint Java_org_direct_1bt_EInfoReport_getEIRDataMaskImpl(JNIEnv *env, jobject obj
return 0;
}
+jint Java_org_direct_1bt_EInfoReport_getSourceImpl(JNIEnv *env, jobject obj) {
+ try {
+ std::shared_ptr<EInfoReport>& eir_ptr = *jau::getInstance<std::shared_ptr<EInfoReport>>(env, obj);
+ return static_cast<jint>( EInfoReport::number( eir_ptr->getSource() ) );
+ } catch(...) {
+ rethrow_and_raise_java_exception(env);
+ }
+ return static_cast<jint>( EInfoReport::number( EInfoReport::Source::NA ) );
+}
+
/*
* Class: org_direct_bt_EInfoReport
* Method: getFlagsImpl
diff --git a/java/org/direct_bt/BTDevice.java b/java/org/direct_bt/BTDevice.java
index 97253069..4894b04a 100644
--- a/java/org/direct_bt/BTDevice.java
+++ b/java/org/direct_bt/BTDevice.java
@@ -800,11 +800,27 @@ public interface BTDevice extends BTObject
/**
* Return the merged advertised {@link EInfoReport} for this remote device.
*
- * The EInfoReport is replaced by new scan-reports (update) and when disconnected (empty).
+ * The EInfoReport is updated by new scan-reports (update) and when disconnected (empty).
* @since 2.5.3
*/
EInfoReport getEIR();
+ /**
+ * Return the latest advertised EInfoReport AD_IND variant for this remote device.
+ *
+ * The EInfoReport is replaced by new scan-reports only.
+ * @since 2.6.6
+ */
+ EInfoReport getEIRInd();
+
+ /**
+ * Return the latest advertised EInfoReport AD_SCAN_RSP for this remote device.
+ *
+ * The EInfoReport is replaced by new scan-reports only.
+ * @since 2.6.6
+ */
+ EInfoReport getEIRScanRsp();
+
/** Returns the connected state of the device.
* @return The connected state of the device.
*/
diff --git a/java/org/direct_bt/EIRDataTypeSet.java b/java/org/direct_bt/EIRDataTypeSet.java
index a5525662..0d375c6f 100644
--- a/java/org/direct_bt/EIRDataTypeSet.java
+++ b/java/org/direct_bt/EIRDataTypeSet.java
@@ -65,6 +65,10 @@ public class EIRDataTypeSet {
DataType(final int v) { value = v; }
public final int value;
}
+ /** Explicit mask to erase all implicit set EIRDataType fields: EVT_TYPE, EXT_EVT_TYPE, BDADDR_TYPE, BDADDR and RSSI. */
+ static final EIRDataTypeSet EIR_DATA_TYPE_MASK =
+ new EIRDataTypeSet( ~( DataType.EVT_TYPE.value | DataType.EXT_EVT_TYPE.value |
+ DataType.BDADDR_TYPE.value | DataType.BDADDR.value | DataType.RSSI.value ) );
public int mask;
diff --git a/java/org/direct_bt/EInfoReport.java b/java/org/direct_bt/EInfoReport.java
index 0cd94989..98018d9c 100644
--- a/java/org/direct_bt/EInfoReport.java
+++ b/java/org/direct_bt/EInfoReport.java
@@ -51,6 +51,39 @@ public final class EInfoReport implements AutoCloseable, Cloneable
private volatile long nativeInstance;
/* pp */ long getNativeInstance() { return nativeInstance; }
+ public enum Source {
+ /** Not Available */
+ NA( 0 ),
+ /** (Extended) Advertising Data (AD or EAD) Indication Variant, i.e. initial passive scan data. */
+ AD_IND( 1 ),
+ /** (Extended) Advertising Data (AD or EAD) Scan Response, i.e. optional active scanning data after AD_IND. */
+ AD_SCAN_RSP( 2 ),
+ /** Extended Inquiry Response (EIR) */
+ EIR( 3 ),
+ /** Extended Inquiry Response (EIR) from Kernel Mgmt */
+ EIR_MGMT( 4 );
+
+ Source(final int v) {
+ value = v;
+ }
+ public final int value;
+
+ /**
+ * Maps the specified integer value to a constant of {@link Source}.
+ * @param value the integer value to be mapped to a constant of this enum type.
+ * @return the corresponding constant of this enum type, using {@link #NA} if not supported.
+ */
+ public static Source get(final int value) {
+ switch(value) {
+ case 1: return AD_IND;
+ case 2: return AD_SCAN_RSP;
+ case 3: return EIR;
+ case 4: return EIR_MGMT;
+ default: return NA;
+ }
+ }
+ }
+
/**
* New independent EInfoReport instance
*/
@@ -166,7 +199,9 @@ public final class EInfoReport implements AutoCloseable, Cloneable
*/
public native void setConnInterval(final short min, final short max);
- // public native Source getSource();
+ public final Source getSource() { return Source.get( getSourceImpl() ); }
+ private native int getSourceImpl();
+
public native long getTimestamp();
public final EIRDataTypeSet getEIRDataMask() {