Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Go to the documentation of this file.
26 import java.lang.reflect.InvocationTargetException;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.concurrent.atomic.AtomicInteger;
32 import java.util.function.Consumer;
79 static final String KEY_PATH =
"keys";
83 int RESET_ADAPTER_EACH_CONN = 0;
84 AtomicInteger deviceReadyCount =
new AtomicInteger(0);
86 AtomicInteger MULTI_MEASUREMENTS =
new AtomicInteger(8);
87 boolean KEEP_CONNECTED =
true;
89 boolean GATT_PING_ENABLED =
false;
90 boolean REMOVE_DEVICE =
true;
91 boolean USE_WHITELIST =
false;
92 final List<BDAddressAndType> whitelist =
new ArrayList<BDAddressAndType>();
94 String charIdentifier =
null;
97 boolean SHOW_UPDATE_EVENTS =
false;
98 boolean QUIET =
false;
100 int shutdownTest = 0;
102 boolean matches(
final List<BDAddressAndType> cont,
final BDAddressAndType mac) {
103 for(
final Iterator<BDAddressAndType> it = cont.iterator(); it.hasNext(); ) {
104 if( it.next().matches(mac) ) {
111 static void printf(
final String format,
final Object... args) {
112 final Object[] args2 =
new Object[args.length+1];
114 System.arraycopy(args, 0, args2, 1, args.length);
115 System.err.printf(
"[%,9d] "+format, args2);
120 static void executeOffThread(
final Runnable runobj,
final String threadName,
final boolean detach) {
121 final Thread t =
new Thread( runobj, threadName );
127 static void execute(
final Runnable task,
final boolean offThread) {
129 final Thread t =
new Thread(task);
141 final boolean initialSetting = oldmask.
isEmpty();
142 if( initialSetting ) {
143 BTUtils.
println(System.err,
"****** SETTINGS: "+oldmask+
" -> "+newmask+
", initial "+changedmask);
145 BTUtils.
println(System.err,
"****** SETTINGS: "+oldmask+
" -> "+newmask+
", changed "+changedmask);
149 if( !initialSetting &&
154 executeOffThread( () -> { startDiscovery(adapter,
"powered-on"); },
160 public void discoveringChanged(
final BTAdapter adapter,
final ScanType currentMeta,
final ScanType changedType,
final boolean changedEnabled,
final boolean keepAlive,
final long timestamp) {
161 BTUtils.
println(System.err,
"****** DISCOVERING: meta "+currentMeta+
", changed["+changedType+
", enabled "+changedEnabled+
", keepAlive "+keepAlive+
"] on "+adapter);
165 public boolean deviceFound(
final BTDevice device,
final long timestamp) {
166 BTUtils.
println(System.err,
"****** FOUND__: "+device.toString());
171 BTUtils.
println(System.err,
"****** FOUND__-2: Skip non 'public LE' and non 'random static public LE' "+device.toString());
182 BTUtils.
println(System.err,
"****** FOUND__-0: Connecting "+device.toString());
185 BTUtils.
println(System.err,
"PERF: adapter-init -> FOUND__-0 " + td +
" ms");
187 executeOffThread( () -> { connectDiscoveredDevice(device); },
191 BTUtils.
println(System.err,
"****** FOUND__-1: NOP "+device.toString());
198 if( SHOW_UPDATE_EVENTS ) {
199 BTUtils.
println(System.err,
"****** UPDATED: "+updateMask+
" of "+device);
204 public void deviceConnected(
final BTDevice device,
final short handle,
final long timestamp) {
205 BTUtils.
println(System.err,
"****** CONNECTED: "+device.toString());
210 BTUtils.
println(System.err,
"****** PAIRING_STATE: state "+state+
", mode "+mode+
": "+device);
220 case REQUESTED_BY_RESPONDER:
223 case FEATURE_EXCHANGE_STARTED:
226 case FEATURE_EXCHANGE_COMPLETED:
229 case PASSKEY_EXPECTED: {
239 case NUMERIC_COMPARE_EXPECTED: {
251 case KEY_DISTRIBUTION:
263 public void deviceReady(
final BTDevice device,
final long timestamp) {
272 deviceReadyCount.incrementAndGet();
273 BTUtils.
println(System.err,
"****** READY-0: Processing["+deviceReadyCount.get()+
"] "+device.toString());
276 BTUtils.
println(System.err,
"PERF: adapter-init -> READY-0 " + td +
" ms");
279 processReadyDevice(device);
281 BTUtils.
println(System.err,
"****** READY-1: NOP " + device.toString());
286 public void deviceDisconnected(
final BTDevice device,
final HCIStatusCode reason,
final short handle,
final long timestamp) {
287 BTUtils.
println(System.err,
"****** DISCONNECTED: Reason "+reason+
", old handle 0x"+Integer.toHexString(handle)+
": "+device+
" on "+device.
getAdapter());
289 if( REMOVE_DEVICE ) {
290 executeOffThread( () -> { removeDevice(device); },
"DBT-Remove-"+device.
getAddressAndType(),
true );
294 if( 0 < RESET_ADAPTER_EACH_CONN && 0 == deviceReadyCount.get() % RESET_ADAPTER_EACH_CONN ) {
295 executeOffThread( () -> { resetAdapter(device.
getAdapter(), 1); },
301 public String toString() {
302 return "AdapterStatusListener[user, per-adapter]";
306 class MyGATTEventListener
implements BTGattChar.Listener {
307 private final int i, j;
309 public MyGATTEventListener(
final int i_,
final int j_) { i=i_; j=j_; }
312 public void notificationReceived(
final BTGattChar charDecl,
313 final byte[] value,
final long timestamp) {
315 printf(
"**[%02d.%02d] Characteristic-Notify: UUID %s, td %d ******\n",
316 i, j, charDecl.
getUUID(), (tR-timestamp));
317 printf(
"**[%02d.%02d] Characteristic: %s ******\n", i, j, charDecl.toString());
318 printf(
"**[%02d.%02d] Value R: size %d, ro: %s ******\n", i, j, value.length,
BTUtils.
bytesHexString(value, 0, -1,
true));
324 public void indicationReceived(
final BTGattChar charDecl,
325 final byte[] value,
final long timestamp,
final boolean confirmationSent) {
327 printf(
"**[%02d.%02d] Characteristic-Indication: UUID %s, td %d, confirmed %b ******\n",
328 i, j, charDecl.
getUUID(), (tR-timestamp), confirmationSent);
329 printf(
"**[%02d.%02d] Characteristic: %s ******\n", i, j, charDecl.toString());
330 printf(
"**[%02d.%02d] Value R: size %d, ro: %s ******\n", i, j, value.length,
BTUtils.
bytesHexString(value, 0, -1,
true));
336 private void connectDiscoveredDevice(
final BTDevice device) {
337 BTUtils.
println(System.err,
"****** Connecting Device: Start " + device.toString());
343 if( SHOW_UPDATE_EVENTS ) {
344 BTUtils.
println(System.err,
"****** UPDATED(2): "+updateMask+
" of "+device);
348 public void deviceConnected(
final BTDevice device,
final short handle,
final long timestamp) {
349 BTUtils.
println(System.err,
"****** CONNECTED(2): "+device.toString());
353 public String toString() {
359 BTUtils.
println(System.err,
"****** Connecting Device: Unpair-Pre result: "+r);
364 BTUtils.
println(System.err,
"****** Connecting Device: stopDiscovery result "+r);
369 BTUtils.
println(System.err,
"****** Connecting Device: Found SecurityDetail "+sec.toString()+
" for "+device.toString());
371 BTUtils.
println(System.err,
"****** Connecting Device: No SecurityDetail for "+device.toString());
375 BTUtils.
fprintf_td(System.err,
"****** Connecting Device: SMPKeyBin::readAndApply(..) result %s\n", res.toString());
378 if( sec.isSecurityAutoEnabled() ) {
380 BTUtils.
println(System.err,
"****** Connecting Device: Using SecurityDetail.SEC AUTO "+sec+
" -> set OK "+r);
381 }
else if( sec.isSecLevelOrIOCapSet() ) {
383 BTUtils.
println(System.err,
"****** Connecting Device: Using SecurityDetail.Level+IOCap "+sec+
" -> set OK "+r);
386 BTUtils.
println(System.err,
"****** Connecting Device: Setting SEC AUTO security detail w/ KEYBOARD_ONLY ("+sec+
") -> set OK "+r);
390 BTUtils.
println(System.err,
"****** Connecting Device: Setting SEC AUTO security detail w/ KEYBOARD_ONLY -> set OK "+r);
394 if( !USE_WHITELIST ) {
399 BTUtils.
println(System.err,
"****** Connecting Device Command, res "+res+
": End result "+res+
" of " + device.toString());
402 startDiscovery(device.
getAdapter(),
"post-connect");
406 void shutdownTest() {
407 switch( shutdownTest ) {
418 void shutdownTest01() {
424 void shutdownTest02() {
430 private void processReadyDevice(
final BTDevice device) {
431 BTUtils.
println(System.err,
"****** Processing Ready Device: Start " + device.toString());
435 BTUtils.
println(System.err,
"****** Processing Ready Device: stopDiscovery result "+r);
442 boolean success =
false;
448 final List<BTGattService> primServices = device.
getServices();
449 if(
null == primServices || 0 == primServices.size() ) {
452 throw new RuntimeException(
"Processing Ready Device: getServices() failed " + device.toString());
456 final long td01 = t1 - timestamp_t0;
457 final long td15 = t5 - t1;
459 final long td05 = t5 - timestamp_t0;
460 BTUtils.
println(System.err, System.lineSeparator()+System.lineSeparator());
461 BTUtils.
println(System.err,
"PERF: GATT primary-services completed\n");
462 BTUtils.
println(System.err,
"PERF: adapter-init to processing-start " + td01 +
" ms,"+System.lineSeparator()+
463 "PERF: get-gatt-services " + td15 +
" ms,"+System.lineSeparator()+
464 "PERF: discovered to gatt-complete " + tdc5 +
" ms (connect " + (tdc5 - td15) +
" ms),"+System.lineSeparator()+
465 "PERF: adapter-init to gatt-complete " + td05 +
" ms"+System.lineSeparator());
470 if(
null != charIdentifier && charIdentifier.length() > 0 ) {
475 if(
null != char2 ) {
478 public void notificationReceived(
final BTGattChar charDecl,
479 final byte[] value,
final long timestamp) {
480 BTUtils.
println(System.err,
"****** PingPong GATT notificationReceived: "+charDecl+
485 public void indicationReceived(
final BTGattChar charDecl,
486 final byte[] value,
final long timestamp,
final boolean confirmationSent) {
487 BTUtils.
println(System.err,
"****** PingPong GATT indicationReceived: "+charDecl+
491 final boolean enabledState[] = {
false,
false };
492 final boolean addedCharPingPongListenerRes = char2.
addCharListener(charPingPongListener, enabledState);
494 BTUtils.
println(System.err,
"Added CharPingPongListenerRes: "+addedCharPingPongListenerRes+
", enabledState "+Arrays.toString(enabledState));
496 if( addedCharPingPongListenerRes ) {
497 final byte[] cmd = { (byte)charValue };
498 final boolean wres = char2.
writeValue(cmd,
false );
509 for(
final Iterator<BTGattService> srvIter = primServices.iterator(); srvIter.hasNext(); i++) {
512 printf(
" [%02d] Service UUID %s\n", i, primService.
getUUID());
513 printf(
" [%02d] %s\n", i, primService.toString());
516 final List<BTGattChar> serviceCharacteristics = primService.
getChars();
517 for(
final Iterator<BTGattChar> charIter = serviceCharacteristics.iterator(); charIter.hasNext(); j++) {
518 final BTGattChar serviceChar = charIter.next();
520 printf(
" [%02d.%02d] Characteristic: UUID %s\n", i, j, serviceChar.
getUUID());
521 printf(
" [%02d.%02d] %s\n", i, j, serviceChar.toString());
525 final byte[] value = serviceChar.
readValue();
532 final List<BTGattDesc> charDescList = serviceChar.
getDescriptors();
533 for(
final Iterator<BTGattDesc> descIter = charDescList.iterator(); descIter.hasNext(); k++) {
536 printf(
" [%02d.%02d.%02d] Descriptor: UUID %s\n", i, j, k, charDesc.
getUUID());
537 printf(
" [%02d.%02d.%02d] %s\n", i, j, k, charDesc.toString());
540 final boolean cccdEnableResult[] = {
false,
false };
541 final boolean cccdRet = serviceChar.
addCharListener(
new MyGATTEventListener(i, j), cccdEnableResult );
543 printf(
" [%02d.%02d] Characteristic-Listener: Notification(%b), Indication(%b): Added %b\n",
544 i, j, cccdEnableResult[0], cccdEnableResult[1], cccdRet);
550 }
catch(
final Exception ex) {
552 ex.printStackTrace();
557 }
catch (
final InterruptedException e) {
561 }
catch (
final Throwable t ) {
562 BTUtils.
println(System.err,
"****** Processing Ready Device: Exception caught for " + device.toString() +
": "+t.getMessage());
566 BTUtils.
println(System.err,
"****** Processing Ready Device: End-1: Success " + success +
572 startDiscovery(device.
getAdapter(),
"post-processing-1");
575 if( KEEP_CONNECTED && GATT_PING_ENABLED && success ) {
580 }
catch (
final InterruptedException e) {
588 BTUtils.
println(System.err,
"****** Processing Ready Device: End-2: Success " + success +
595 if( !KEEP_CONNECTED ) {
599 BTUtils.
println(System.err,
"****** Processing Ready Device: Unpair-Post result: "+unpair_res);
604 if( 0 < RESET_ADAPTER_EACH_CONN && 0 == deviceReadyCount.get() % RESET_ADAPTER_EACH_CONN ) {
607 startDiscovery(device.
getAdapter(),
"post-processing-2");
611 if( 0 < MULTI_MEASUREMENTS.get() ) {
612 MULTI_MEASUREMENTS.decrementAndGet();
617 private void removeDevice(
final BTDevice device) {
626 startDiscovery(device.
getAdapter(),
"post-remove-device");
630 private void resetAdapter(
final BTAdapter adapter,
final int mode) {
631 BTUtils.
println(System.err,
"****** Reset Adapter: reset["+mode+
"] start: "+adapter.toString());
633 BTUtils.
println(System.err,
"****** Reset Adapter: reset["+mode+
"] end: "+res+
", "+adapter.toString());
636 static boolean le_scan_active =
true;
637 static final short le_scan_interval = (short)24;
638 static final short le_scan_window = (short)24;
639 static final byte filter_policy = (byte)0;
641 private boolean startDiscovery(
final BTAdapter adapter,
final String msg) {
643 BTUtils.
println(System.err,
"****** Start discovery ("+msg+
") result: "+status);
647 private boolean initAdapter(
final BTAdapter adapter) {
655 BTUtils.
println(System.err,
"Adapter not powered (2): "+adapter.toString());
659 if( USE_WHITELIST ) {
660 for(
final Iterator<BDAddressAndType> wliter = whitelist.iterator(); wliter.hasNext(); ) {
663 BTUtils.
println(System.err,
"Added to whitelist: res "+res+
", address "+addr);
666 if( !startDiscovery(adapter,
"kick-off") ) {
676 public void adapterAdded(
final BTAdapter adapter) {
677 if( initAdapter( adapter ) ) {
678 BTUtils.
println(System.err,
"****** Adapter ADDED__: InitOK. " + adapter);
680 BTUtils.
println(System.err,
"****** Adapter ADDED__: Ignored " + adapter);
685 public void adapterRemoved(
final BTAdapter adapter) {
686 BTUtils.
println(System.err,
"****** Adapter REMOVED: " + adapter);
693 boolean done =
false;
698 if( 0 == MULTI_MEASUREMENTS.get() ||
702 BTUtils.
println(System.err,
"****** EOL Test MULTI_MEASUREMENTS left "+MULTI_MEASUREMENTS.get()+
710 }
catch (
final InterruptedException e) {
719 final List<BTAdapter> adapters = manager.
getAdapters();
721 adapters.forEach(
new Consumer<BTAdapter>() {
724 BTUtils.
println(System.err,
"****** EOL Adapter's Devices - pre_ close: " + a);
728 BTUtils.
println(System.err,
"****** EOL Removed ChangedAdapterSetCallback " + count);
733 adapters.forEach(
new Consumer<BTAdapter>() {
736 BTUtils.
println(System.err,
"****** EOL Adapter's Devices - post close: " + a);
741 public static void main(
final String[] args)
throws InterruptedException {
742 for(
int i=0; i< args.length; i++) {
743 final String arg = args[i];
744 if( arg.equals(
"-debug") ) {
745 System.setProperty(
"org.tinyb.verbose",
"true");
746 System.setProperty(
"org.tinyb.debug",
"true");
747 }
else if( arg.equals(
"-verbose") ) {
748 System.setProperty(
"org.tinyb.verbose",
"true");
749 }
else if( arg.equals(
"-dbt_debug") && args.length > (i+1) ) {
750 System.setProperty(
"direct_bt.debug", args[++i]);
751 }
else if( arg.equals(
"-dbt_verbose") && args.length > (i+1) ) {
752 System.setProperty(
"direct_bt.verbose", args[++i]);
753 }
else if( arg.equals(
"-dbt_gatt") && args.length > (i+1) ) {
754 System.setProperty(
"direct_bt.gatt", args[++i]);
755 }
else if( arg.equals(
"-dbt_l2cap") && args.length > (i+1) ) {
756 System.setProperty(
"direct_bt.l2cap", args[++i]);
757 }
else if( arg.equals(
"-dbt_hci") && args.length > (i+1) ) {
758 System.setProperty(
"direct_bt.hci", args[++i]);
759 }
else if( arg.equals(
"-dbt_mgmt") && args.length > (i+1) ) {
760 System.setProperty(
"direct_bt.mgmt", args[++i]);
761 }
else if( arg.equals(
"-btmode") && args.length > (i+1) ) {
763 System.setProperty(
"org.tinyb.btmode", btmode.toString());
764 System.err.println(
"Setting 'org.tinyb.btmode' to "+btmode.toString());
770 }
catch (
BTException | NoSuchMethodException | SecurityException
771 | IllegalAccessException | IllegalArgumentException
772 | InvocationTargetException | ClassNotFoundException e) {
773 System.err.println(
"Unable to instantiate DirectBT BluetoothManager");
778 BTUtils.
println(System.err,
"DirectBT BluetoothManager initialized!");
784 boolean waitForEnter=
false;
786 for(
int i=0; i< args.length; i++) {
787 final String arg = args[i];
789 if( arg.equals(
"-wait") ) {
791 }
else if( arg.equals(
"-show_update_events") ) {
792 test.SHOW_UPDATE_EVENTS =
true;
793 }
else if( arg.equals(
"-quiet") ) {
795 }
else if( arg.equals(
"-scanPassive") ) {
796 le_scan_active =
false;
797 }
else if( arg.equals(
"-shutdown") && args.length > (i+1) ) {
798 test.shutdownTest = Integer.valueOf(args[++i]).intValue();
799 }
else if( arg.equals(
"-dev") && args.length > (i+1) ) {
801 }
else if( arg.equals(
"-wl") && args.length > (i+1) ) {
804 test.whitelist.add(wle);
805 test.USE_WHITELIST =
true;
806 }
else if( arg.equals(
"-passkey") && args.length > (i+2) ) {
807 final String addrOrNameSub = args[++i];
809 sec.passkey = Integer.valueOf(args[++i]).intValue();
810 System.err.println(
"Set passkey in "+sec);
811 }
else if( arg.equals(
"-seclevel") && args.length > (i+2) ) {
812 final String addrOrNameSub = args[++i];
814 final int sec_level_i = Integer.valueOf(args[++i]).intValue();
816 System.err.println(
"Set sec_level "+sec_level_i+
" in "+sec);
817 }
else if( arg.equals(
"-iocap") && args.length > (i+2) ) {
818 final String addrOrNameSub = args[++i];
820 final int io_cap_i = Integer.valueOf(args[++i]).intValue();
822 System.err.println(
"Set io_cap "+io_cap_i+
" in "+sec);
823 }
else if( arg.equals(
"-secauto") && args.length > (i+2) ) {
824 final String addrOrNameSub = args[++i];
826 final int io_cap_i = Integer.valueOf(args[++i]).intValue();
828 System.err.println(
"Set SEC AUTO security io_cap "+io_cap_i+
" in "+sec);
829 }
else if( arg.equals(
"-charid") && args.length > (i+1) ) {
830 test.charIdentifier = args[++i];
831 }
else if( arg.equals(
"-charval") && args.length > (i+1) ) {
832 test.charValue = Integer.valueOf(args[++i]).intValue();
833 }
else if( arg.equals(
"-disconnect") ) {
834 test.KEEP_CONNECTED =
false;
835 }
else if( arg.equals(
"-enableGATTPing") ) {
836 test.GATT_PING_ENABLED =
true;
837 }
else if( arg.equals(
"-keepDevice") ) {
838 test.REMOVE_DEVICE =
false;
839 }
else if( arg.equals(
"-count") && args.length > (i+1) ) {
840 test.MULTI_MEASUREMENTS.set(Integer.valueOf(args[++i]).intValue());
841 }
else if( arg.equals(
"-single") ) {
842 test.MULTI_MEASUREMENTS.set(-1);
843 }
else if( arg.equals(
"-resetEachCon") && args.length > (i+1) ) {
844 test.RESET_ADAPTER_EACH_CONN = Integer.valueOf(args[++i]).intValue();
848 "[-bluetoothManager <BluetoothManager-Implementation-Class-Name>] "+
849 "[-disconnect] [-enableGATTPing] [-count <number>] [-single] [-show_update_events] [-quiet] "+
851 "[-resetEachCon connectionCount] "+
852 "(-dev <device_[address|name]_sub>)* (-wl <device_address>)* "+
853 "(-seclevel <device_[address|name]_sub> <int_sec_level>)* "+
854 "(-iocap <device_[address|name]_sub> <int_iocap>)* "+
855 "(-secauto <device_[address|name]_sub> <int_iocap>)* "+
856 "(-passkey <device_[address|name]_sub> <digits>)* "+
857 "[-charid <uuid>] [-charval <byte-val>] "+
858 "[-verbose] [-debug] "+
859 "[-dbt_verbose true|false] "+
860 "[-dbt_debug true|false|adapter.event,gatt.data,hci.event,hci.scan_ad_eir,mgmt.event] "+
861 "[-dbt_mgmt cmd.timeout=3000,ringsize=64,...] "+
862 "[-dbt_hci cmd.complete.timeout=10000,cmd.status.timeout=3000,ringsize=64,...] "+
863 "[-dbt_gatt cmd.read.timeout=500,cmd.write.timeout=500,cmd.init.timeout=2500,ringsize=128,...] "+
864 "[-dbt_l2cap reader.timeout=10000,restart.count=0,...] "+
865 "[-shutdown <int>]'");
884 try{ System.in.read();
885 }
catch(
final Exception e) { }
887 test.runTest(manager);
String getUUID()
Get the UUID of this characteristic.
Entry specifying SMP security details associated to a device query via EUI48Sub or.
Provides access to Bluetooth adapters.
static int getProcessingDeviceCount()
boolean isSet(final SettingType bit)
int removeChangedAdapterSetListener(final ChangedAdapterSetListener l)
Remove the given ChangedAdapterSetListener from this manager.
static HCIStatusCode readAndApply(final String path, final BTDevice device, final BTSecurityLevel minSecLevel, final boolean verbose_)
Create a new SMPKeyBin instance on the fly based upon stored file denoted by path and BTDevice#getAdd...
static final int NO_PASSKEY
Bluetooth Security Level.
static void fprintf_td(final PrintStream out, final String format, final Object ... args)
Convenient PrintStream#printf(String, Object...) invocation, prepending the elapsedTimeMillis() times...
List< BTGattService > getServices()
Returns a list of BluetoothGattServices available on this device.
boolean isPowered()
Returns whether the adapter is valid, plugged in and powered.
boolean setConnSecurityAuto(final SMPIOCapability iocap_auto)
Set automatic security negotiation of BTSecurityLevel and SMPIOCapability pairing mode.
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2020 Gothel Software e.K.
static boolean isWaitingForAnyDevice()
Bluetooth secure pairing mode.
GattCharPropertySet getProperties()
Returns the properties of this characteristic.
Application toolkit providing BT device registration of processed and awaited devices.
static String getWaitForDevicesString()
boolean isSet(final Type bit)
int removeAllCharListener()
Remove all BTGattCharListener from the list.
HCIStatusCode reset()
Reset the adapter.
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
static boolean createAndWrite(final BTDevice device, final String path, final boolean overwrite, final boolean verbose_)
Create a new SMPKeyBin instance on the fly based upon given BTDevice's BTSecurityLevel,...
One stop BTManager API entry point.
static void main(final String[] args)
HCI Whitelist connection type.
boolean pingGATT()
Issues a GATT ping to the device, validating whether it is still reachable.
Storage for SMP keys including the required connection parameter.
static boolean removeFromProcessingDevices(final BDAddressAndType a)
int removeDiscoveredDevices()
Remove all the discovered devices found on this adapter.
Provides access to Bluetooth GATT characteristic.
void shutdown()
Release the native memory associated with this object and all related Bluetooth resources.
static void println(final PrintStream out, final String msg)
Convenient PrintStream#println(String) invocation, prepending the elapsedTimeMillis() timestamp.
static native long currentTimeMillis()
Returns current monotonic time in milliseconds.
STATIC_PUBLIC
Static public 'random' device address 0b11.
static final String getAPIVersion()
Manifest's Attributes.Name#SPECIFICATION_VERSION or.
List< BTGattChar > getChars()
Returns a list of BTGattChar this service exposes.
static native String getNativeAPIVersion()
Bit mask of 'Extended Inquiry Response' (EIR) data fields, indicating a set of related data.
static BTSecurityRegistry.Entry getStartOf(final EUI48 addr, final String name)
Returns a matching BTSecurityRegistry.Entry,.
static boolean isDeviceProcessing(final BDAddressAndType a)
Bits representing 'BTAdapter setting' data fields.
static void addToWaitForDevices(final String addrOrNameSub)
BTGattChar event listener for notification and indication events.
HCIStatusCode setPairingNumericComparison(final boolean equal)
Method sets the numeric comparison result, see PairingMode#NUMERIC_COMPARE_ini.
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2020 Gothel Software e.K.
boolean addStatusListener(final AdapterStatusListener listener)
Add the given AdapterStatusListener to the list if not already present, listening only for events mat...
BTObject find(BTType type, String name, String identifier, BTObject parent, long timeoutMS)
Find a BluetoothObject of a type matching type.
static String allToString()
SMP Pairing Process state definition.
HCIStatusCode startDiscovery(final boolean keepAlive, final boolean le_scan_active)
Turns on device discovery if it is disabled.
static BTMode get(final String name)
Maps the specified name to a constant of BTMode.
static BTSecurityRegistry.Entry getOrCreate(final String addrOrNameSub)
Determines whether the given.
boolean writeValue(byte[] argValue, boolean withResponse)
Writes the value of this characteristic, using one of the following methods depending on.
Unique Bluetooth EUI48 address and BDAddressType tuple.
static BTSecurityLevel get(final String name)
Maps the specified name to a constant of BTSecurityLevel.
long getLastDiscoveryTimestamp()
Returns the timestamp in monotonic milliseconds when this device instance has discovered or connected...
final static boolean remove(final String path, final BDAddressAndType addrAndType_)
static boolean areAllDevicesProcessed(final DeviceQueryMatch m)
Returns.
Meta ScanType as derived from BTMode with defined value mask consisting of BDAddressType bits.
static BTManager getManager()
Returns an instance of BluetoothManager, to be used instead of constructor.
UNSET
Security Level not set, value 0.
static void addToProcessedDevices(final BDAddressAndType a, final String n)
BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.1.1 Characteristic Properties.
List< BTAdapter > getAdapters()
Returns a list of BluetoothAdapters available in the system.
static native String decodeUTF8String(final byte[] buffer, final int offset, final int size)
Returns all valid consecutive UTF-8 characters within buffer in the range offset -> size or until EOS...
BT Core Spec v5.2: Vol 1, Part F Controller Error Codes: 1.3 List of Error Codes.
Provides access to Bluetooth GATT characteristic.
static SMPIOCapability get(final String name)
Maps the specified name to a constant of SMPIOCapability.
static synchronized BTManager getDirectBTManager()
Returns an initialized BluetoothManager instance using the DirectBT implementation.
final static String getFilename(final String path, final BDAddressAndType addrAndType_)
Provides access to Bluetooth adapters.
Provides access to Bluetooth GATT descriptor.
static native String getNativeVersion()
void runTest(final BTManager manager)
static final String getImplVersion()
Manifest's Attributes.Name#IMPLEMENTATION_VERSION or.
BDADDR_LE_PUBLIC
Bluetooth LE public address.
static String getProcessedDevicesString()
Application toolkit providing BT security setup and its device association on a pattern matching basi...
Bluetooth adapter operating mode.
HCIStatusCode stopDiscovery()
Turns off device discovery if it is enabled.
Bit mask of GATT Characteristic Properties.
static int getWaitForDevicesCount()
static long elapsedTimeMillis()
Returns current elapsed monotonic time in milliseconds since module startup, see startupTimeMillis().
BDAddressAndType getAddressAndType()
Returns the unique device EUI48 address and BDAddressType type.
static boolean isDeviceProcessed(final BDAddressAndType a)
static void addToProcessingDevices(final BDAddressAndType a, final String n)
Bluetooth address type constants.
HCIStatusCode unpair()
Unpairs this device from the adapter while staying connected.
HCIStatusCode setPairingPasskey(final int passkey)
Method sets the given passkey entry, see PairingMode#PASSKEY_ENTRY_ini.
static int getProcessedDeviceCount()
BLERandomAddressType getBLERandomAddressType()
Returns the BLERandomAddressType.
boolean addStatusListener(final AdapterStatusListener listener)
Add the given AdapterStatusListener to the list if not already present.
Bluetooth LE random address type constants.
static boolean isWaitingForDevice(final EUI48 address, final String name, final DeviceQueryMatch m)
Returns.
boolean setConnSecurityBest(final BTSecurityLevel sec_level, final SMPIOCapability io_cap)
Convenience method to determine the best practice BTSecurityLevel and SMPIOCapability based on the gi...
BTGattChar event listener for notification and indication events.
String getUUID()
Get the UUID of this descriptor.
String getName()
Returns the remote friendly name of this device.
boolean addDeviceToWhitelist(final BDAddressAndType addressAndType, final HCIWhitelistConnectType ctype, final short conn_interval_min, final short conn_interval_max, final short conn_latency, final short timeout)
Add the given device to the adapter's autoconnect whitelist.
boolean addCharListener(final Listener listener)
Add the given BTGattChar.Listener to the listener list if not already present.
List< BTGattDesc > getDescriptors()
Returns a list of BluetoothGattDescriptors this characteristic exposes.
BTAdapter status listener for BTDevice discovery events: Added, updated and removed; as well as for c...
static String bytesHexString(final byte[] bytes, final int offset, final int length, final boolean lsbFirst)
Produce a lower-case hexadecimal string representation of the given byte values.
void shutdown()
Release the native memory associated with this object and all related Bluetooth resources.
boolean remove()
Remove this device from the system (like an unpair).
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2020 Gothel Software e.K.
String getUUID()
Get the UUID of this service.
KEYBOARD_ONLY
Keyboard input only, value 2.
This Java scanner example uses the Direct-BT fully event driven workflow and adds multithreading,...
byte[] readValue()
Reads the value of this characteristic.
BTManager getManager()
Returns the used singleton BTManager instance, used to create this adapter.
BDAddressAndType getAddressAndType()
Returns the adapter's public BDAddressAndType.
HCI_AUTO_CONN_ALWAYS
Auto Connect: Only supported for LE on Linux .
void addChangedAdapterSetListener(final ChangedAdapterSetListener l)
Add the given ChangedAdapterSetListener to this manager.
Event listener to receive change events regarding the system's BTAdapter set, e.g.
BTAdapter getAdapter()
Returns the adapter on which this device was discovered or connected.