Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
DBTDevice.java
Go to the documentation of this file.
1 /**
2  * Author: Sven Gothel <sgothel@jausoft.com>
3  * Copyright (c) 2020 Gothel Software e.K.
4  * Copyright (c) 2020 ZAFENA AB
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 package jau.direct_bt;
27 
28 import java.lang.ref.WeakReference;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.concurrent.atomic.AtomicBoolean;
33 
38 import org.direct_bt.BTDevice;
40 import org.direct_bt.BTGattChar;
41 import org.direct_bt.BTGattDesc;
43 import org.direct_bt.BTObject;
44 import org.direct_bt.BTType;
45 import org.direct_bt.BTUtils;
47 import org.direct_bt.EUI48;
52 import org.direct_bt.SMPKeyMask;
56 
57 public class DBTDevice extends DBTObject implements BTDevice
58 {
59  private static final boolean DEBUG = DBTManager.DEBUG;
60 
61  /** Device's adapter weak back-reference */
62  private final WeakReference<DBTAdapter> wbr_adapter;
63 
64  private final BDAddressAndType addressAndType;
65  private final long ts_creation;
66  volatile long ts_last_discovery;
67  volatile long ts_last_update;
68  volatile short hciConnHandle;
69  private volatile String name_cached;
70  /* pp */ final List<WeakReference<DBTGattService>> serviceCache = new ArrayList<WeakReference<DBTGattService>>();
71 
72  private final AtomicBoolean isClosing = new AtomicBoolean(false);
73 
74  private final AtomicBoolean isConnected = new AtomicBoolean(false);
75 
76  final AdapterStatusListener statusListener = new AdapterStatusListener() {
77  @Override
78  public void deviceUpdated(final BTDevice device, final EIRDataTypeSet updateMask, final long timestamp) {
79  }
80  @Override
81  public void deviceConnected(final BTDevice device, final short handle, final long timestamp) {
82  if( isConnected.compareAndSet(false, true) ) {
83  // nop
84  }
85  }
86  @Override
87  public void deviceDisconnected(final BTDevice device, final HCIStatusCode reason, final short handle, final long timestamp) {
88  if( isConnected.compareAndSet(true, false) ) {
89  clearServiceCache();
90  }
91  }
92 
93  @Override
94  public String toString() {
95  return "AdapterStatusListener[device "+addressAndType.toString()+"]";
96  }
97  };
98 
99  /* pp */ DBTDevice(final long nativeInstance, final DBTAdapter adptr,
100  final byte byteAddress[/*6*/],
101  final byte byteAddressType,
102  final long ts_creation, final String name)
103  {
104  super(nativeInstance, compHash(java.util.Arrays.hashCode(byteAddress), 31+byteAddressType));
105  this.wbr_adapter = new WeakReference<DBTAdapter>(adptr);
106  this.addressAndType = new BDAddressAndType(new EUI48(byteAddress), BDAddressType.get(byteAddressType));
107  if( BDAddressType.BDADDR_UNDEFINED == addressAndType.type ) {
108  throw new IllegalArgumentException("Unsupported given native addresstype "+byteAddressType);
109  }
110  this.ts_creation = ts_creation;
111  ts_last_discovery = ts_creation;
112  ts_last_update = ts_creation;
113  hciConnHandle = 0;
114  name_cached = name;
115  initImpl();
116  addStatusListener(statusListener); // associated events and lifecycle with this device
117  // FIXME enableTrustedNotificationsImpl(trustedNotificationsCB);
118  }
119 
120  @Override
121  public void close() {
122  if( !isValid() ) {
123  return;
124  }
125  if( !isClosing.compareAndSet(false, true) ) {
126  return;
127  }
128  clearServiceCache();
129 
130  final DBTAdapter a = getAdapter();
131  if( null != a ) {
132  a.removeStatusListener(statusListener);
133  a.removeDiscoveredDevice(this);
134  }
135  super.close();
136  }
137 
138  @Override
139  public boolean equals(final Object obj)
140  {
141  if(this == obj) {
142  return true;
143  }
144  if (obj == null || !(obj instanceof DBTDevice)) {
145  return false;
146  }
147  final DBTDevice other = (DBTDevice)obj;
148  return addressAndType.equals(other.addressAndType);
149  }
150 
151  @Override
152  public final long getCreationTimestamp() { return ts_creation; }
153 
154  @Override
155  public final long getLastDiscoveryTimestamp() { return ts_last_discovery; }
156 
157  @Override
158  public final long getLastUpdateTimestamp() { return ts_last_update; }
159 
160  @Override
161  public DBTAdapter getAdapter() { return wbr_adapter.get(); }
162 
163  @Override
164  public BDAddressAndType getAddressAndType() { return addressAndType; }
165 
166  @Override
167  public String getName() {
168  if( !isValid() ) {
169  return name_cached;
170  } else {
171  final String v = getNameImpl();
172  name_cached = v;
173  return v;
174  }
175  }
176  private native String getNameImpl();
177 
178  @Override
179  public BTType getBluetoothType() { return class_type(); }
180 
181  static BTType class_type() { return BTType.DEVICE; }
182 
183  @Override
184  public BTGattService find(final String UUID, final long timeoutMS) {
185  return (DBTGattService) findInCache(UUID, BTType.GATT_SERVICE);
186  }
187 
188  @Override
189  public BTGattService find(final String UUID) {
190  return find(UUID, 0);
191  }
192 
193  /* internal */
194 
195  private native void initImpl();
196 
197  /* DBT method calls: Connection */
198 
199  @Override
200  public final boolean addStatusListener(final AdapterStatusListener l) {
201  return getAdapter().addStatusListenerImpl(this, l);
202  }
203 
204  @Override
205  public boolean removeStatusListener(final AdapterStatusListener l) {
206  return getAdapter().removeStatusListenerImpl(l);
207  }
208 
209  @Override
210  public final boolean getConnected() { return isConnected.get(); }
211 
212  @Override
213  public final short getConnectionHandle() { return hciConnHandle; }
214 
215  @Override
216  public final HCIStatusCode disconnect() {
217  if( isConnected.get() ) {
218  return HCIStatusCode.get( disconnectImpl() ); // event callbacks will be generated by implementation
219  }
221  }
222  private native byte disconnectImpl();
223 
224  @Override
225  public final HCIStatusCode connect() {
226  if( !isConnected.get() ) {
227  return HCIStatusCode.get( connectDefaultImpl() ); // event callbacks will be generated by implementation
228  }
230  }
231  private native byte connectDefaultImpl();
232 
233  @Override
234  public HCIStatusCode connectLE(final short le_scan_interval, final short le_scan_window,
235  final short conn_interval_min, final short conn_interval_max,
236  final short conn_latency, final short timeout) {
237  if( !isConnected.get() ) {
238  // event callbacks will be generated by implementation
239  if( 0 > le_scan_interval || 0 > le_scan_window || 0 > conn_interval_min ||
240  0 > conn_interval_max || 0 > conn_latency || 0 > timeout ) {
241  return HCIStatusCode.get( connectLEImpl0() );
242  } else {
243  return HCIStatusCode.get( connectLEImpl1(le_scan_interval, le_scan_window, conn_interval_min, conn_interval_max, conn_latency, timeout) );
244  }
245  }
247  }
248  private native byte connectLEImpl0();
249  private native byte connectLEImpl1(final short le_scan_interval, final short le_scan_window,
250  final short conn_interval_min, final short conn_interval_max,
251  final short conn_latency, final short timeout);
252 
253  /* SC SMP */
254 
255  @Override
256  public final SMPKeyMask getAvailableSMPKeys(final boolean responder) {
257  return new SMPKeyMask(getAvailableSMPKeysImpl(responder));
258  }
259  private final native byte getAvailableSMPKeysImpl(final boolean responder);
260 
261  @Override
262  public final SMPLongTermKeyInfo getLongTermKeyInfo(final boolean responder) {
263  final byte[] stream = new byte[SMPLongTermKeyInfo.byte_size];
264  getLongTermKeyInfoImpl(responder, stream);
265  return new SMPLongTermKeyInfo(stream, 0);
266  }
267  private final native void getLongTermKeyInfoImpl(final boolean responder, final byte[] sink);
268 
269  @Override
271  final byte[] stream = new byte[SMPLongTermKeyInfo.byte_size];
272  ltk.getStream(stream, 0);
273  return HCIStatusCode.get( setLongTermKeyInfoImpl(stream) );
274  }
275  private final native byte setLongTermKeyInfoImpl(final byte[] source);
276 
277  @Override
278  public final SMPSignatureResolvingKeyInfo getSignatureResolvingKeyInfo(final boolean responder) {
279  final byte[] stream = new byte[SMPSignatureResolvingKeyInfo.byte_size];
280  getSignatureResolvingKeyInfoImpl(responder, stream);
281  return new SMPSignatureResolvingKeyInfo(stream, 0);
282  }
283  private final native void getSignatureResolvingKeyInfoImpl(final boolean responder, final byte[] sink);
284 
285  @Override
286  public final HCIStatusCode unpair() {
287  return HCIStatusCode.get( unpairImpl() );
288  }
289  private final native byte unpairImpl();
290 
291  @Override
292  public final boolean setConnSecurityLevel(final BTSecurityLevel sec_level) {
293  return setConnSecurityLevelImpl(sec_level.value);
294  }
295  private final native boolean setConnSecurityLevelImpl(final byte sec_level);
296 
297  @Override
299  return BTSecurityLevel.get( getConnSecurityLevelImpl() );
300  }
301  private final native byte getConnSecurityLevelImpl();
302 
303  @Override
304  public final boolean setConnIOCapability(final SMPIOCapability io_cap) {
305  return setConnIOCapabilityImpl(io_cap.value);
306  }
307  private final native boolean setConnIOCapabilityImpl(final byte io_cap);
308 
309  @Override
311  return SMPIOCapability.get( getConnIOCapabilityImpl() );
312  }
313  private final native byte getConnIOCapabilityImpl();
314 
315  @Override
316  public final boolean setConnSecurity(final BTSecurityLevel sec_level, final SMPIOCapability io_cap) {
317  return setConnSecurityImpl(sec_level.value, io_cap.value);
318  }
319  private final native boolean setConnSecurityImpl(final byte sec_level, final byte io_cap);
320 
321  @Override
322  public final boolean setConnSecurityBest(final BTSecurityLevel sec_level, final SMPIOCapability io_cap) {
323  if( BTSecurityLevel.UNSET.value < sec_level.value && SMPIOCapability.UNSET.value != io_cap.value ) {
324  return setConnSecurity(sec_level, io_cap);
325  } else if( BTSecurityLevel.UNSET.value < sec_level.value ) {
326  if( BTSecurityLevel.ENC_ONLY.value >= sec_level.value ) {
328  } else {
329  return setConnSecurityLevel(sec_level);
330  }
331  } else if( SMPIOCapability.UNSET.value != io_cap.value ) {
332  return setConnIOCapability(io_cap);
333  } else {
334  return false;
335  }
336  }
337 
338  @Override
339  public final boolean setConnSecurityAuto(final SMPIOCapability iocap_auto) {
340  return setConnSecurityAutoImpl( iocap_auto.value );
341  }
342  private final native boolean setConnSecurityAutoImpl(final byte io_cap);
343 
344  @Override
345  public final native boolean isConnSecurityAutoEnabled();
346 
347  @Override
348  public HCIStatusCode setPairingPasskey(final int passkey) {
349  return HCIStatusCode.get( setPairingPasskeyImpl(passkey) );
350  }
351  private native byte setPairingPasskeyImpl(final int passkey) throws BTException;
352 
353  @Override
355  return HCIStatusCode.get( setPairingPasskeyNegativeImpl() );
356  }
357  private native byte setPairingPasskeyNegativeImpl() throws BTException;
358 
359  @Override
360  public HCIStatusCode setPairingNumericComparison(final boolean equal) {
361  return HCIStatusCode.get( setPairingNumericComparisonImpl(equal) );
362  }
363  private native byte setPairingNumericComparisonImpl(final boolean equal);
364 
365  @Override
367  return PairingMode.get( getPairingModeImpl() );
368  }
369  private native byte getPairingModeImpl();
370 
371  @Override
373  return SMPPairingState.get( getPairingStateImpl() );
374  }
375  private native byte getPairingStateImpl();
376 
377  @Override
378  public final String toString() {
379  if( !isValid() ) {
380  // UTF-8 271D = Cross
381  return "Device" + "\u271D" + "[address"+addressAndType+", '"+name_cached+
382  "', connected["+isConnected.get()+", 0x"+Integer.toHexString(hciConnHandle)+"]]";
383  }
384  return toStringImpl();
385  }
386  private native String toStringImpl();
387 
388  /**
389  * {@inheritDoc}
390  */
391  @Override
392  public final boolean remove() throws BTException {
393  // close: clear java-listener, super.close()
394  // -> DBTNativeDownlink.delete(): deleteNativeJavaObject(..), deleteImpl(..) -> DBTDevice::remove()
395  close();
396  // return removeImpl();
397  if( DBTAdapter.PRINT_DEVICE_LISTS || DEBUG ) {
398  BTUtils.fprintf_td(System.err, "BTDevice::remove: %s", toString());
400  }
401  return true;
402  }
403  private native boolean removeImpl() throws BTException;
404 
405  @Override
406  public final boolean isValid() { return super.isValid() /* && isValidImpl() */; }
407  // public native boolean isValidImpl();
408 
409  @Override
410  public List<BTGattService> getServices() {
411  try {
412  final List<BTGattService> services = getServicesImpl();
413  updateServiceCache(services);
414  return services;
415  } catch (final Throwable t) {
416  System.err.println("DBTDevice.getServices(): Caught "+t.getMessage()+" on thread "+Thread.currentThread().toString()+" on "+toString());
417  if(DEBUG) {
418  t.printStackTrace();
419  }
420  }
421  return null;
422  }
423  private native List<BTGattService> getServicesImpl();
424 
425  @Override
426  public boolean pingGATT() {
427  try {
428  return pingGATTImpl();
429  } catch (final Throwable t) {
430  System.err.println("DBTDevice.pingGATT(): Caught "+t.getMessage()+" on thread "+Thread.currentThread().toString()+" on "+toString());
431  if(DEBUG) {
432  t.printStackTrace();
433  }
434  }
435  return false;
436  }
437  private native boolean pingGATTImpl();
438 
439  /* property accessors: */
440 
441  @Override
442  public native short getRSSI();
443 
444  @Override
445  public native Map<Short, byte[]> getManufacturerData();
446 
447  @Override
448  public native short getTxPower ();
449 
450  /**
451  * {@inheritDoc}
452  * <p>
453  * Native implementation calls DBTDevice::remove()
454  * </p>
455  */
456  @Override
457  protected native void deleteImpl(long nativeInstance);
458 
459  @Override
460  public boolean addCharListener(final BTGattCharListener listener) {
461  return addCharListener(listener, (DBTGattChar)listener.getAssociatedChar());
462  }
463  private native boolean addCharListener(final BTGattCharListener listener, final DBTGattChar associatedCharacteristic);
464 
465  @Override
466  public native boolean removeCharListener(final BTGattCharListener l);
467 
468  @Override
469  public native int removeAllAssociatedCharListener(final BTGattChar associatedCharacteristic);
470 
471  @Override
472  public native int removeAllCharListener();
473 
474  /* local functionality */
475 
476  private void clearServiceCache() {
477  synchronized(serviceCache) {
478  for(int i = serviceCache.size() - 1; i >= 0; i-- ) {
479  serviceCache.get(i).clear();
480  serviceCache.remove(i);
481  }
482  }
483  }
484  private void updateServiceCache(final List<BTGattService> services) {
485  synchronized(serviceCache) {
486  clearServiceCache();
487  if( null != services ) {
488  for(final BTGattService service : services) {
489  serviceCache.add( new WeakReference<DBTGattService>( (DBTGattService)service ) );
490  }
491  }
492  }
493  }
494 
495  /* pp */ boolean checkServiceCache(final boolean getServices) {
496  synchronized(serviceCache) {
497  if( serviceCache.isEmpty() ) {
498  if( getServices ) {
499  getServices();
500  if( serviceCache.isEmpty() ) {
501  return false;
502  }
503  } else {
504  return false;
505  }
506  }
507  return true;
508  }
509  }
510 
511  /**
512  * Returns the matching {@link DBTObject} from the internal cache if found,
513  * otherwise {@code null}.
514  * <p>
515  * The returned {@link DBTObject} may be of type
516  * <ul>
517  * <li>{@link DBTGattService}</li>
518  * <li>{@link DBTGattChar}</li>
519  * <li>{@link DBTGattDesc}</li>
520  * </ul>
521  * or alternatively in {@link BTObject} space
522  * <ul>
523  * <li>{@link BTType#GATT_SERVICE} -> {@link BTGattService}</li>
524  * <li>{@link BTType#GATT_CHARACTERISTIC} -> {@link BTGattChar}</li>
525  * <li>{@link BTType#GATT_DESCRIPTOR} -> {@link BTGattDesc}</li>
526  * </ul>
527  * </p>
528  * @param uuid UUID of the desired {@link BTType#GATT_SERVICE service},
529  * {@link BTType#GATT_CHARACTERISTIC characteristic} or {@link BTType#GATT_DESCRIPTOR descriptor} to be found.
530  * Maybe {@code null}, in which case the first object of the desired type is being returned - if existing.
531  * @param type specify the type of the object to be found, either
532  * {@link BTType#GATT_SERVICE service}, {@link BTType#GATT_CHARACTERISTIC characteristic}
533  * or {@link BTType#GATT_DESCRIPTOR descriptor}.
534  * {@link BTType#NONE none} means anything.
535  */
536  /* pp */ DBTObject findInCache(final String uuid, final BTType type) {
537  final boolean anyType = BTType.NONE == type;
538  final boolean serviceType = BTType.GATT_SERVICE == type;
539  final boolean charType = BTType.GATT_CHARACTERISTIC== type;
540  final boolean descType = BTType.GATT_DESCRIPTOR == type;
541 
542  if( !anyType && !serviceType && !charType && !descType ) {
543  return null;
544  }
545  synchronized(serviceCache) {
546  if( !checkServiceCache(true) ) {
547  return null;
548  }
549 
550  if( null == uuid && ( anyType || serviceType ) ) {
551  // special case for 1st valid service ref
552  while( !serviceCache.isEmpty() ) {
553  final DBTGattService service = serviceCache.get(0).get();
554  if( null == service ) {
555  serviceCache.remove(0);
556  } else {
557  return service;
558  }
559  }
560  return null; // empty valid service refs
561  }
562  for(int srvIdx = serviceCache.size() - 1; srvIdx >= 0; srvIdx-- ) {
563  final DBTGattService service = serviceCache.get(srvIdx).get();
564  if( null == service ) {
565  serviceCache.remove(srvIdx); // remove dead ref
566  continue; // cont w/ next service
567  }
568  if( ( anyType || serviceType ) && service.getUUID().equals(uuid) ) {
569  return service;
570  }
571  if( anyType || charType || descType ) {
572  final DBTObject dbtObj = service.findInCache(uuid, type);
573  if( null != dbtObj ) {
574  return dbtObj;
575  }
576  }
577  }
578  return null;
579  }
580  }
581 }
org.direct_bt.BDAddressAndType.equals
final boolean equals(final Object obj)
Definition: BDAddressAndType.java:107
org.direct_bt.BTSecurityLevel.ENC_ONLY
ENC_ONLY
Encryption and no authentication (no MITM).
Definition: BTSecurityLevel.java:44
jau.direct_bt.DBTObject.DBTObject
DBTObject(final long nativeInstance, final int hashValue)
Definition: DBTObject.java:46
jau.direct_bt.DBTDevice.find
BTGattService find(final String UUID, final long timeoutMS)
Find a BluetoothGattService.
Definition: DBTDevice.java:184
jau.direct_bt.DBTDevice.isValid
final boolean isValid()
Returns whether the device is valid, i.e.
Definition: DBTDevice.java:406
jau.direct_bt.DBTDevice.setPairingPasskey
HCIStatusCode setPairingPasskey(final int passkey)
Method sets the given passkey entry, see PairingMode#PASSKEY_ENTRY_ini.
Definition: DBTDevice.java:348
org.direct_bt.BTSecurityLevel.value
final byte value
Definition: BTSecurityLevel.java:50
jau.direct_bt.DBTDevice.setConnSecurityAuto
final boolean setConnSecurityAuto(final SMPIOCapability iocap_auto)
Set automatic security negotiation of BTSecurityLevel and SMPIOCapability pairing mode.
Definition: DBTDevice.java:339
jau.direct_bt.DBTDevice.removeCharListener
native boolean removeCharListener(final BTGattCharListener l)
Remove the given BTGattCharListener from the listener list.
org.direct_bt.SMPIOCapability
SMP IO Capability value.
Definition: SMPIOCapability.java:37
org.direct_bt.BTSecurityLevel
Bluetooth Security Level.
Definition: BTSecurityLevel.java:38
org.direct_bt.SMPIOCapability.NO_INPUT_NO_OUTPUT
NO_INPUT_NO_OUTPUT
No input not output, value 3.
Definition: SMPIOCapability.java:45
jau.direct_bt.DBTDevice.addCharListener
boolean addCharListener(final BTGattCharListener listener)
Add the given BTGattCharListener to the listener list if not already present.
Definition: DBTDevice.java:460
org.direct_bt.BTUtils.fprintf_td
static void fprintf_td(final PrintStream out, final String format, final Object ... args)
Convenient PrintStream#printf(String, Object...) invocation, prepending the elapsedTimeMillis() times...
Definition: BTUtils.java:68
jau.direct_bt.DBTGattService
Definition: DBTGattService.java:39
jau.direct_bt.DBTDevice.getLastUpdateTimestamp
final long getLastUpdateTimestamp()
Returns the timestamp in monotonic milliseconds when this device instance underlying data has been up...
Definition: DBTDevice.java:158
jau.direct_bt.DBTDevice.connect
final HCIStatusCode connect()
Definition: DBTDevice.java:225
jau.direct_bt.DBTAdapter.removeStatusListener
boolean removeStatusListener(final AdapterStatusListener l)
Remove the given AdapterStatusListener from the list.
Definition: DBTAdapter.java:408
jau.direct_bt.DBTDevice.getAdapter
DBTAdapter getAdapter()
Returns the adapter on which this device was discovered or connected.
Definition: DBTDevice.java:161
org.direct_bt
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2020 Gothel Software e.K.
jau.direct_bt.DBTDevice.getCreationTimestamp
final long getCreationTimestamp()
Returns the timestamp in monotonic milliseconds when this device instance has been created,...
Definition: DBTDevice.java:152
org.direct_bt.PairingMode
Bluetooth secure pairing mode.
Definition: PairingMode.java:40
org.direct_bt.HCIStatusCode.CONNECTION_ALREADY_EXISTS
CONNECTION_ALREADY_EXISTS
Definition: HCIStatusCode.java:46
org.direct_bt.SMPLongTermKeyInfo.byte_size
static final int byte_size
Size of the byte stream representation in bytes (28)
Definition: SMPLongTermKeyInfo.java:139
jau.direct_bt.DBTDevice.getAddressAndType
BDAddressAndType getAddressAndType()
Returns the unique device EUI48 address and BDAddressType type.
Definition: DBTDevice.java:164
jau.direct_bt.DBTDevice.setConnSecurityBest
final boolean setConnSecurityBest(final BTSecurityLevel sec_level, final SMPIOCapability io_cap)
Convenience method to determine the best practice BTSecurityLevel and SMPIOCapability based on the gi...
Definition: DBTDevice.java:322
jau.direct_bt.DBTDevice.getPairingMode
PairingMode getPairingMode()
Returns the current PairingMode used by the device.
Definition: DBTDevice.java:366
org.direct_bt.EUI48
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
Definition: EUI48.java:37
jau.direct_bt.DBTDevice.removeAllAssociatedCharListener
native int removeAllAssociatedCharListener(final BTGattChar associatedCharacteristic)
Remove all BTGattCharListener from the list, which are associated to the given BTGattChar.
jau.direct_bt.DBTDevice.getServices
List< BTGattService > getServices()
Returns a list of BluetoothGattServices available on this device.
Definition: DBTDevice.java:410
jau.direct_bt.DBTManager
Definition: DBTManager.java:51
org.direct_bt.BDAddressAndType.toString
final String toString()
Definition: BDAddressAndType.java:154
org.direct_bt.SMPLongTermKeyInfo
SMP Long Term Key Info, used for platform agnostic persistence.
Definition: SMPLongTermKeyInfo.java:39
jau.direct_bt.DBTDevice.getRSSI
native short getRSSI()
Returns the Received Signal Strength Indicator of the device.
org.direct_bt.SMPIOCapability.value
final byte value
Definition: SMPIOCapability.java:51
org.direct_bt.BTType.DEVICE
DEVICE
Definition: BTType.java:29
org.direct_bt.SMPKeyMask
SMP Key Type for Distribution, indicates keys distributed in the Transport Specific Key Distribution ...
Definition: SMPKeyMask.java:44
jau.direct_bt.DBTDevice.getConnIOCapability
final SMPIOCapability getConnIOCapability()
Return the SMPIOCapability value, determined when the connection is established.
Definition: DBTDevice.java:310
jau.direct_bt.DBTGattChar
Definition: DBTGattChar.java:42
org.direct_bt.BTGattService
Provides access to Bluetooth GATT characteristic.
Definition: BTGattService.java:41
jau.direct_bt.DBTDevice.getTxPower
native short getTxPower()
Returns the transmission power level (0 means unknown).
jau.direct_bt.DBTDevice.addStatusListener
final boolean addStatusListener(final AdapterStatusListener l)
Add the given AdapterStatusListener to the list if not already present, listening only for events mat...
Definition: DBTDevice.java:200
org.direct_bt.EIRDataTypeSet
Bit mask of 'Extended Inquiry Response' (EIR) data fields, indicating a set of related data.
Definition: EIRDataTypeSet.java:33
jau.direct_bt.DBTDevice.setPairingPasskeyNegative
HCIStatusCode setPairingPasskeyNegative()
Method replies with a negative passkey response, i.e.
Definition: DBTDevice.java:354
org.direct_bt.BDAddressAndType.type
BDAddressType type
Definition: BDAddressAndType.java:47
org.direct_bt.SMPSignatureResolvingKeyInfo.byte_size
static final int byte_size
Size of the byte stream representation in bytes.
Definition: SMPSignatureResolvingKeyInfo.java:126
jau.direct_bt.DBTDevice
Definition: DBTDevice.java:58
org.direct_bt.BTType.GATT_SERVICE
GATT_SERVICE
Definition: BTType.java:30
org.direct_bt.SMPIOCapability.UNSET
UNSET
Denoting unset value, i.e.
Definition: SMPIOCapability.java:49
jau.direct_bt.DBTDevice.getSignatureResolvingKeyInfo
final SMPSignatureResolvingKeyInfo getSignatureResolvingKeyInfo(final boolean responder)
Returns a copy of the Signature Resolving Key (LTK) info, valid after connection and SMP pairing has ...
Definition: DBTDevice.java:278
jau.direct_bt.DBTAdapter
Definition: DBTAdapter.java:59
org.direct_bt.HCIStatusCode.get
static HCIStatusCode get(final String name)
Maps the specified name to a constant of HCIStatusCode.
Definition: HCIStatusCode.java:143
org.direct_bt.SMPPairingState
SMP Pairing Process state definition.
Definition: SMPPairingState.java:38
jau.direct_bt.DBTDevice.setLongTermKeyInfo
final HCIStatusCode setLongTermKeyInfo(final SMPLongTermKeyInfo ltk)
Sets the long term ket (LTK) info of this device to reuse pre-paired encryption.
Definition: DBTDevice.java:270
org.direct_bt.BDAddressAndType
Unique Bluetooth EUI48 address and BDAddressType tuple.
Definition: BDAddressAndType.java:36
org.direct_bt.BTSecurityLevel.get
static BTSecurityLevel get(final String name)
Maps the specified name to a constant of BTSecurityLevel.
Definition: BTSecurityLevel.java:63
jau.direct_bt.DBTDevice.getName
String getName()
Returns the remote friendly name of this device.
Definition: DBTDevice.java:167
jau.direct_bt.DBTDevice.getBluetoothType
BTType getBluetoothType()
Returns the BluetoothType of this object.
Definition: DBTDevice.java:179
jau.direct_bt.DBTDevice.isConnSecurityAutoEnabled
final native boolean isConnSecurityAutoEnabled()
Returns true if automatic security negotiation has been enabled via setConnSecurityAuto(SMPIOCapabili...
jau.direct_bt.DBTDevice.disconnect
final HCIStatusCode disconnect()
Definition: DBTDevice.java:216
jau.direct_bt.DBTDevice.unpair
final HCIStatusCode unpair()
Unpairs this device from the adapter while staying connected.
Definition: DBTDevice.java:286
jau.direct_bt.DBTDevice.setConnIOCapability
final boolean setConnIOCapability(final SMPIOCapability io_cap)
Sets the given SMPIOCapability used to connect to this device on the upcoming connection.
Definition: DBTDevice.java:304
org.direct_bt.BTUtils
Definition: BTUtils.java:29
jau.direct_bt.DBTDevice.getPairingState
SMPPairingState getPairingState()
Returns the current SMPPairingState.
Definition: DBTDevice.java:372
org.direct_bt.BTSecurityLevel.UNSET
UNSET
Security Level not set, value 0.
Definition: BTSecurityLevel.java:40
org.direct_bt.HCIStatusCode
BT Core Spec v5.2: Vol 1, Part F Controller Error Codes: 1.3 List of Error Codes.
Definition: HCIStatusCode.java:34
jau.direct_bt.DBTDevice.setConnSecurity
final boolean setConnSecurity(final BTSecurityLevel sec_level, final SMPIOCapability io_cap)
Sets the given BTSecurityLevel and SMPIOCapability used to connect to this device on the upcoming con...
Definition: DBTDevice.java:316
jau.direct_bt.DBTDevice.close
void close()
Release the native memory associated with this object The object should not be used following a call ...
Definition: DBTDevice.java:121
org.direct_bt.SMPPairingState.get
static SMPPairingState get(final String name)
Maps the specified name to a constant of SMPPairingState.
Definition: SMPPairingState.java:98
org.direct_bt.PairingMode.get
static PairingMode get(final String name)
Maps the specified name to a constant of PairingMode.
Definition: PairingMode.java:73
org.direct_bt.HCIStatusCode.CONNECTION_TERMINATED_BY_LOCAL_HOST
CONNECTION_TERMINATED_BY_LOCAL_HOST
Definition: HCIStatusCode.java:57
org.direct_bt.BTGattChar
Provides access to Bluetooth GATT characteristic.
Definition: BTGattChar.java:40
org.direct_bt.SMPIOCapability.get
static SMPIOCapability get(final String name)
Maps the specified name to a constant of SMPIOCapability.
Definition: SMPIOCapability.java:64
jau.direct_bt.DBTDevice.getAvailableSMPKeys
final SMPKeyMask getAvailableSMPKeys(final boolean responder)
Returns the available SMPKeyMask.KeyType SMPKeyMask for the responder (LL slave) or initiator (LL mas...
Definition: DBTDevice.java:256
org.direct_bt.BTDevice
Provides access to Bluetooth adapters.
Definition: BTDevice.java:42
org.direct_bt.BTGattDesc
Provides access to Bluetooth GATT descriptor.
Definition: BTGattDesc.java:38
jau.direct_bt.DBTManager.DEBUG
static final boolean DEBUG
Definition: DBTManager.java:52
jau.direct_bt.DBTDevice.getLongTermKeyInfo
final SMPLongTermKeyInfo getLongTermKeyInfo(final boolean responder)
Returns a copy of the long term key (LTK) info, valid after connection and SMP pairing has been compl...
Definition: DBTDevice.java:262
jau.direct_bt.DBTDevice.removeAllCharListener
native int removeAllCharListener()
Remove all BTGattCharListener from the list.
org
org.direct_bt.BTType
Definition: BTType.java:28
org.direct_bt.BTException
Definition: BTException.java:32
jau.direct_bt.DBTDevice.getLastDiscoveryTimestamp
final long getLastDiscoveryTimestamp()
Returns the timestamp in monotonic milliseconds when this device instance has discovered or connected...
Definition: DBTDevice.java:155
jau.direct_bt.DBTDevice.getConnSecurityLevel
final BTSecurityLevel getConnSecurityLevel()
Return the BTSecurityLevel, determined when the connection is established.
Definition: DBTDevice.java:298
jau.direct_bt.DBTDevice.setPairingNumericComparison
HCIStatusCode setPairingNumericComparison(final boolean equal)
Method sets the numeric comparison result, see PairingMode#NUMERIC_COMPARE_ini.
Definition: DBTDevice.java:360
jau.direct_bt.DBTDevice.setConnSecurityLevel
final boolean setConnSecurityLevel(final BTSecurityLevel sec_level)
Set the BTSecurityLevel used to connect to this device on the upcoming connection.
Definition: DBTDevice.java:292
jau.direct_bt.DBTDevice.getManufacturerData
native Map< Short, byte[]> getManufacturerData()
Returns a map containing manufacturer specific advertisement data.
jau.direct_bt.DBTDevice.find
BTGattService find(final String UUID)
Find a BluetoothGattService.
Definition: DBTDevice.java:189
jau.direct_bt.DBTDevice.toString
final String toString()
Definition: DBTDevice.java:378
jau.direct_bt.DBTDevice.deleteImpl
native void deleteImpl(long nativeInstance)
Deletes the native instance.Called via delete() and at this point this java reference has been remove...
org.direct_bt.BDAddressType
Bluetooth address type constants.
Definition: BDAddressType.java:53
jau.direct_bt.DBTDevice.equals
boolean equals(final Object obj)
Definition: DBTDevice.java:139
org.direct_bt.BTGattCharListener.getAssociatedChar
final BTGattChar getAssociatedChar()
Returns the weakly associated BTGattChar to this listener instance.
Definition: BTGattCharListener.java:69
jau.direct_bt.DBTAdapter.printDeviceLists
final void printDeviceLists()
Print the internally maintained BTDevice lists to stderr:
Definition: DBTAdapter.java:425
org.direct_bt.BTGattCharListener
BTGattChar event listener for notification and indication events.
Definition: BTGattCharListener.java:57
org.direct_bt.BTObject
Definition: BTObject.java:31
org.direct_bt.SMPSignatureResolvingKeyInfo
SMP Signature Resolving Key Info, used for platform agnostic persistence.
Definition: SMPSignatureResolvingKeyInfo.java:39
org.direct_bt.AdapterStatusListener
BTAdapter status listener for BTDevice discovery events: Added, updated and removed; as well as for c...
Definition: AdapterStatusListener.java:56
org.direct_bt.BDAddressType.get
static BDAddressType get(final String name)
Maps the specified name to a constant of BDAddressType.
Definition: BDAddressType.java:104
org.direct_bt.BDAddressType.BDADDR_UNDEFINED
BDADDR_UNDEFINED
Undefined.
Definition: BDAddressType.java:61
jau.direct_bt.DBTDevice.connectLE
HCIStatusCode connectLE(final short le_scan_interval, final short le_scan_window, final short conn_interval_min, final short conn_interval_max, final short conn_latency, final short timeout)
Establish a HCI BDADDR_LE_PUBLIC or BDADDR_LE_RANDOM connection to this device.
Definition: DBTDevice.java:234
jau.direct_bt.DBTDevice.getConnected
final boolean getConnected()
Returns the connected state of the device.
Definition: DBTDevice.java:210
jau.direct_bt.DBTDevice.pingGATT
boolean pingGATT()
Issues a GATT ping to the device, validating whether it is still reachable.
Definition: DBTDevice.java:426
jau.direct_bt.DBTDevice.getConnectionHandle
final short getConnectionHandle()
Return the HCI connection handle to the LE or BREDR peer, zero if not connected.
Definition: DBTDevice.java:213
org.direct_bt.SMPLongTermKeyInfo.getStream
final void getStream(final byte[] sink, int pos)
Method transfers all bytes representing this instance into the given destination array at the given p...
Definition: SMPLongTermKeyInfo.java:194
jau.direct_bt.DBTDevice.removeStatusListener
boolean removeStatusListener(final AdapterStatusListener l)
Remove the given AdapterStatusListener from the list.
Definition: DBTDevice.java:205
jau.direct_bt.DBTObject
Definition: DBTObject.java:32