Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
BTAdapter.hpp
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 #ifndef BT_ADAPTER_HPP_
27 #define BT_ADAPTER_HPP_
28 
29 #include <cstring>
30 #include <string>
31 #include <memory>
32 #include <cstdint>
33 
34 #include <mutex>
35 #include <atomic>
36 
37 #include <jau/darray.hpp>
38 #include <jau/cow_darray.hpp>
39 
40 #include "BTTypes1.hpp"
41 
42 #include "BTDevice.hpp"
43 
44 #include "HCIHandler.hpp"
45 
46 namespace direct_bt {
47 
48  class BTAdapter; // forward
49  class BTManager; // forward
50 
51  /**
52  * {@link BTAdapter} status listener for {@link BTDevice} discovery events: Added, updated and removed;
53  * as well as for certain {@link BTAdapter} events.
54  * <p>
55  * User implementations shall return as early as possible to avoid blocking the event-handler thread,
56  * if not specified within the methods otherwise (see AdapterStatusListener::deviceReady()).<br>
57  * Especially complex mutable operations on BTDevice or BTAdapter should be issued off-thread!
58  * </p>
59  * <p>
60  * A listener instance may be attached to a {@link BTAdapter} via
61  * {@link BTAdapter::addStatusListener(std::shared_ptr<AdapterStatusListener>)}.
62  * </p>
63  * <p>
64  * The listener receiver maintains a unique set of listener instances without duplicates.
65  * </p>
66  */
68  public:
69  /**
70  * Custom filter for all 'device*' notification methods,
71  * which will not be called if this method returns false.
72  * <p>
73  * User may override this method to test whether the 'device*' methods shall be called
74  * for the given device.
75  * </p>
76  * <p>
77  * Defaults to true;
78  * </p>
79  */
80  virtual bool matchDevice(const BTDevice & device) {
81  (void)device;
82  return true;
83  }
84 
85  /**
86  * BTAdapter setting(s) changed.
87  * @param adapter the adapter which settings have changed.
88  * @param oldmask the previous settings mask. AdapterSetting::NONE indicates the initial setting notification, see BTAdapter::addStatusListener().
89  * @param newmask the new settings mask
90  * @param changedmask the changes settings mask. AdapterSetting::NONE indicates the initial setting notification, see BTAdapter::addStatusListener().
91  * @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
92  */
93  virtual void adapterSettingsChanged(BTAdapter &adapter, const AdapterSetting oldmask, const AdapterSetting newmask,
94  const AdapterSetting changedmask, const uint64_t timestamp) {
95  (void)adapter;
96  (void)oldmask;
97  (void)newmask;
98  (void)changedmask;
99  (void)timestamp;
100  }
101 
102  /**
103  * BTAdapter's discovery state has changed, i.e. enabled or disabled.
104  * @param adapter the adapter which discovering state has changed.
105  * @param currentMeta the current meta ScanType
106  * @param changedType denotes the changed ScanType
107  * @param changedEnabled denotes whether the changed ScanType has been enabled or disabled
108  * @param keepAlive if `true`, the denoted changed ScanType will be re-enabled if disabled by the underlying Bluetooth implementation.
109  * @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
110  *
111  * changeScanType(const ScanType current, const bool enable, const ScanType enableChanged) noexcept {
112  */
113  virtual void discoveringChanged(BTAdapter &adapter, const ScanType currentMeta, const ScanType changedType, const bool changedEnabled, const bool keepAlive, const uint64_t timestamp) {
114  (void)adapter;
115  (void)currentMeta;
116  (void)changedType;
117  (void)changedEnabled;
118  (void)keepAlive;
119  (void)timestamp;
120  }
121 
122  /**
123  * A BTDevice has been newly discovered.
124  * <p>
125  * The boolean return value informs the adapter whether the device shall be made persistent for connection `true`,
126  * or that it can be discarded `false`.<br>
127  * If no registered AdapterStatusListener::deviceFound() implementation returns `true`,
128  * the device instance will be removed from all internal lists and can no longer being used.<br>
129  * If any registered AdapterStatusListener::deviceFound() implementation returns `true`,
130  * the device will be made persistent, is ready to connect and BTDevice::remove() shall be called after usage.
131  * </p>
132  * @param device the found device
133  * @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
134  * @return true if the device shall be made persistent and BTDevice::remove() issued later. Otherwise false to remove device right away.
135  */
136  virtual bool deviceFound(std::shared_ptr<BTDevice> device, const uint64_t timestamp) {
137  (void)device;
138  (void)timestamp;
139  return false;
140  }
141 
142  /**
143  * An already discovered BTDevice has been updated.
144  * @param device the updated device
145  * @param updateMask the update mask of changed data
146  * @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
147  */
148  virtual void deviceUpdated(std::shared_ptr<BTDevice> device, const EIRDataType updateMask, const uint64_t timestamp) {
149  (void)device;
150  (void)updateMask;
151  (void)timestamp;
152  }
153 
154  /**
155  * BTDevice got connected
156  * @param device the device which has been connected, holding the new connection handle.
157  * @param handle the new connection handle, which has been assigned to the device already
158  * @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
159  */
160  virtual void deviceConnected(std::shared_ptr<BTDevice> device, const uint16_t handle, const uint64_t timestamp) {
161  (void)device;
162  (void)handle;
163  (void)timestamp;
164  }
165 
166  /**
167  * An already connected BTDevice's ::SMPPairingState has changed.
168  * @param device the device which PairingMode has been changed.
169  * @param state the current ::SMPPairingState of the connected device, see BTDevice::getCurrentPairingState()
170  * @param mode the current ::PairingMode of the connected device, see BTDevice::getCurrentPairingMode()
171  * @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
172  * @see BTDevice::setPairingPasskey()
173  * @see BTDevice::setPairingNumericComparison()
174  */
175  virtual void devicePairingState(std::shared_ptr<BTDevice> device, const SMPPairingState state, const PairingMode mode, const uint64_t timestamp) {
176  (void)device;
177  (void)state;
178  (void)mode;
179  (void)timestamp;
180  }
181 
182  /**
183  * BTDevice is ready for user (GATT) processing, i.e. already connected, optionally paired and ATT MTU size negotiated via connected GATT.
184  * <p>
185  * Method is being called from a dedicated native thread, hence restrictions on method duration and complex mutable operations don't apply here.
186  * </p>
187  * @param device the device ready to use
188  * @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
189  * @see ::SMPPairingState::COMPLETED
190  */
191  virtual void deviceReady(std::shared_ptr<BTDevice> device, const uint64_t timestamp) {
192  (void)device;
193  (void)timestamp;
194  }
195 
196  /**
197  * BTDevice got disconnected
198  * @param device the device which has been disconnected with zeroed connection handle.
199  * @param reason the HCIStatusCode reason for disconnection
200  * @param handle the disconnected connection handle, which has been unassigned from the device already
201  * @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
202  */
203  virtual void deviceDisconnected(std::shared_ptr<BTDevice> device, const HCIStatusCode reason, const uint16_t handle, const uint64_t timestamp) {
204  (void)device;
205  (void)reason;
206  (void)handle;
207  (void)timestamp;
208  }
209 
211 
212  virtual std::string toString() const = 0;
213 
214  /**
215  * Default comparison operator, merely testing for same memory reference.
216  * <p>
217  * Specializations may override.
218  * </p>
219  */
220  virtual bool operator==(const AdapterStatusListener& rhs) const
221  { return this == &rhs; }
222 
223  bool operator!=(const AdapterStatusListener& rhs) const
224  { return !(*this == rhs); }
225  };
226 
227  // *************************************************
228  // *************************************************
229  // *************************************************
230 
231  namespace impl {
233  /** The actual listener */
234  std::shared_ptr<AdapterStatusListener> listener;
235  /** The optional weak device reference. Weak, b/c it shall not block destruction */
236  std::weak_ptr<BTDevice> wbr_device;
237  };
238  }
239 
240  /**
241  * BTAdapter represents one Bluetooth Controller.
242  * <p>
243  * Controlling Environment variables:
244  * <pre>
245  * - 'direct_bt.debug.adapter.event': Debug messages about events, see debug_events
246  * </pre>
247  * </p>
248  */
249  class BTAdapter : public BTObject
250  {
251  private:
252  friend BTManager;
253 
254  const bool debug_event, debug_lock;
255  BTManager& mgmt;
256  AdapterInfo adapterInfo;
257  LE_Features le_features;
258  bool hci_uses_ext_scan;
259  bool hci_uses_ext_conn;
260 
261  /**
262  * Either the adapter's initially reported public address or a random address setup via HCI before scanning / discovery.
263  */
264  BDAddressAndType visibleAddressAndType;
265 
266  public:
267  /**
268  * Adapter's internal temporary device id.
269  * <p>
270  * The internal device id is constant across the adapter lifecycle,
271  * but may change after its destruction.
272  */
273  const uint16_t dev_id;
274 
275  private:
276  HCIHandler hci;
277 
278  std::atomic<AdapterSetting> old_settings;
279  std::atomic<BTMode> btMode = BTMode::NONE;
280  NameAndShortName localName;
281  std::atomic<ScanType> currentMetaScanType; // = ScanType::NONE
282  std::atomic<bool> keep_le_scan_alive; // = false;
283 
284  SMPIOCapability iocap_defaultval = SMPIOCapability::UNSET;
285  const BTDevice* single_conn_device_ptr = nullptr;
286  std::mutex mtx_single_conn_device;
287  std::condition_variable cv_single_conn_device;
288 
290  /** All discovered devices: Transient until removeDiscoveredDevices(), startDiscovery(). */
291  device_list_t discoveredDevices;
292  /** All connected devices: Transient until disconnect or removal. */
293  device_list_t connectedDevices;
294  /** All persistent shared devices: Persistent until removal. */
295  device_list_t sharedDevices; // All active shared devices. Final holder of BTDevice lifecycle!
297  statusListenerList_t statusListenerList;
298  mutable std::mutex mtx_discoveredDevices;
299  mutable std::mutex mtx_connectedDevices;
300  mutable std::mutex mtx_discovery;
301  mutable std::mutex mtx_sharedDevices; // final mutex of all BTDevice lifecycle
302  mutable jau::sc_atomic_bool sync_data;
303 
304  bool updateDataFromHCI() noexcept;
305  bool validateDevInfo() noexcept;
306 
307  static std::shared_ptr<BTDevice> findDevice(device_list_t & devices, const EUI48 & address, const BDAddressType addressType) noexcept;
308  static std::shared_ptr<BTDevice> findDevice(device_list_t & devices, BTDevice const & device) noexcept;
309  static void printDeviceList(const std::string& prefix, const BTAdapter::device_list_t& list) noexcept;
310 
311  /** Private class only for private make_shared(). */
312  class ctor_cookie { friend BTAdapter; ctor_cookie(const uint16_t secret) { (void)secret; } };
313 
314  /** Private std::make_shared<BTAdapter>(..) vehicle for friends. */
315  static std::shared_ptr<BTAdapter> make_shared(BTManager& mgmt_, const AdapterInfo& adapterInfo_) {
316  return std::make_shared<BTAdapter>(BTAdapter::ctor_cookie(0), mgmt_, adapterInfo_);
317  }
318 
319  /**
320  * Closes all device connections, stops discovery and cleans up all references.
321  * <p>
322  * To be called at destructor or when powered off.
323  * </p>
324  */
325  void poweredOff() noexcept;
326 
327  friend std::shared_ptr<BTDevice> BTDevice::getSharedInstance() const noexcept;
328  friend void BTDevice::remove() noexcept;
329  friend BTDevice::~BTDevice() noexcept;
330 
331  friend std::shared_ptr<ConnectionInfo> BTDevice::getConnectionInfo() noexcept;
332  friend void BTDevice::sendMgmtEvDeviceDisconnected(std::unique_ptr<MgmtEvent> evt) noexcept;
333  friend HCIStatusCode BTDevice::disconnect(const HCIStatusCode reason) noexcept;
334  friend HCIStatusCode BTDevice::connectLE(uint16_t interval, uint16_t window,
335  uint16_t min_interval, uint16_t max_interval,
336  uint16_t latency, uint16_t supervision_timeout) noexcept;
337  friend HCIStatusCode BTDevice::connectBREDR(const uint16_t pkt_type, const uint16_t clock_offset, const uint8_t role_switch) noexcept;
338  friend void BTDevice::processL2CAPSetup(std::shared_ptr<BTDevice> sthis);
339  friend bool BTDevice::updatePairingState(std::shared_ptr<BTDevice> sthis, const MgmtEvent& evt, const HCIStatusCode evtStatus, SMPPairingState claimed_state) noexcept;
340  friend void BTDevice::hciSMPMsgCallback(std::shared_ptr<BTDevice> sthis, const SMPPDUMsg& msg, const HCIACLData::l2cap_frame& source) noexcept;
341  friend void BTDevice::processDeviceReady(std::shared_ptr<BTDevice> sthis, const uint64_t timestamp);
342  friend jau::darray<std::shared_ptr<BTGattService>> BTDevice::getGattServices() noexcept;
343 
344  bool lockConnect(const BTDevice & device, const bool wait, const SMPIOCapability io_cap) noexcept;
345  bool unlockConnect(const BTDevice & device) noexcept;
346  bool unlockConnectAny() noexcept;
347 
348  bool addConnectedDevice(const std::shared_ptr<BTDevice> & device) noexcept;
349  bool removeConnectedDevice(const BTDevice & device) noexcept;
350  int disconnectAllDevices(const HCIStatusCode reason=HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION ) noexcept;
351  std::shared_ptr<BTDevice> findConnectedDevice (const EUI48 & address, const BDAddressType & addressType) noexcept;
352 
353  bool addDiscoveredDevice(std::shared_ptr<BTDevice> const &device) noexcept;
354 
355  void removeDevice(BTDevice & device) noexcept;
356 
357  bool addSharedDevice(std::shared_ptr<BTDevice> const &device) noexcept;
358  std::shared_ptr<BTDevice> getSharedDevice(const BTDevice & device) noexcept;
359  void removeSharedDevice(const BTDevice & device) noexcept;
360 
361  bool mgmtEvNewSettingsMgmt(const MgmtEvent& e) noexcept;
362  bool mgmtEvDeviceDiscoveringMgmt(const MgmtEvent& e) noexcept;
363  bool mgmtEvLocalNameChangedMgmt(const MgmtEvent& e) noexcept;
364  bool mgmtEvDeviceFoundHCI(const MgmtEvent& e) noexcept;
365  bool mgmtEvDeviceDisconnectedMgmt(const MgmtEvent& e) noexcept;
366  bool mgmtEvPairDeviceCompleteMgmt(const MgmtEvent& e) noexcept;
367  bool mgmtEvNewLongTermKeyMgmt(const MgmtEvent& e) noexcept;
368 
369  bool mgmtEvDeviceDiscoveringHCI(const MgmtEvent& e) noexcept;
370  bool mgmtEvDeviceConnectedHCI(const MgmtEvent& e) noexcept;
371  bool mgmtEvConnectFailedHCI(const MgmtEvent& e) noexcept;
372  bool mgmtEvHCIEncryptionChangedHCI(const MgmtEvent& e) noexcept;
373  bool mgmtEvHCIEncryptionKeyRefreshCompleteHCI(const MgmtEvent& e) noexcept;
374  bool mgmtEvHCILERemoteUserFeaturesHCI(const MgmtEvent& e) noexcept;
375  bool mgmtEvDeviceDisconnectedHCI(const MgmtEvent& e) noexcept;
376 
377 
378  bool mgmtEvDeviceDiscoveringAny(const MgmtEvent& e, const bool hciSourced) noexcept;
379 
380  bool mgmtEvPinCodeRequestMgmt(const MgmtEvent& e) noexcept;
381  bool mgmtEvUserConfirmRequestMgmt(const MgmtEvent& e) noexcept;
382  bool mgmtEvUserPasskeyRequestMgmt(const MgmtEvent& e) noexcept;
383  bool mgmtEvAuthFailedMgmt(const MgmtEvent& e) noexcept;
384  bool mgmtEvDeviceUnpairedMgmt(const MgmtEvent& e) noexcept;
385 
386  bool hciSMPMsgCallback(const BDAddressAndType & addressAndType,
387  const SMPPDUMsg& msg, const HCIACLData::l2cap_frame& source) noexcept;
388  void sendDevicePairingState(std::shared_ptr<BTDevice> device, const SMPPairingState state, const PairingMode mode, uint64_t timestamp) noexcept;
389  void sendDeviceReady(std::shared_ptr<BTDevice> device, uint64_t timestamp) noexcept;
390 
391  void startDiscoveryBackground() noexcept;
392  void checkDiscoveryState() noexcept;
393 
394  void sendAdapterSettingsChanged(const AdapterSetting old_settings_, const AdapterSetting current_settings, AdapterSetting changes,
395  const uint64_t timestampMS) noexcept;
396  void sendAdapterSettingsInitial(AdapterStatusListener & asl, const uint64_t timestampMS) noexcept;
397 
398  void sendDeviceUpdated(std::string cause, std::shared_ptr<BTDevice> device, uint64_t timestamp, EIRDataType updateMask) noexcept;
399 
400  int removeAllStatusListener(const BTDevice& d);
401 
402  public:
403 
404  /** Private ctor for private BTAdapter::make_shared() intended for friends. */
405  BTAdapter(const BTAdapter::ctor_cookie& cc, BTManager& mgmt_, const AdapterInfo& adapterInfo_) noexcept;
406 
407  BTAdapter(const BTAdapter&) = delete;
408  void operator=(const BTAdapter&) = delete;
409 
410  /**
411  * Releases this instance.
412  */
413  ~BTAdapter() noexcept;
414 
415  /**
416  * Closes this instance, usually being called by destructor or when this adapter is being removed
417  * as recognized and handled by BTManager.
418  * <p>
419  * Renders this adapter's BTAdapter#isValid() state to false.
420  * </p>
421  */
422  void close() noexcept;
423 
424  std::string get_java_class() const noexcept override {
425  return java_class();
426  }
427  static std::string java_class() noexcept {
428  return std::string(JAVA_DBT_PACKAGE "DBTAdapter");
429  }
430 
431  /**
432  * Returns whether the adapter is valid, plugged in and powered.
433  * @return true if BTAdapter::isValid(), HCIHandler::isOpen() and AdapterSetting::POWERED state is set.
434  * @see #isSuspended()
435  * @see #isValid()
436  */
437  bool isPowered() const noexcept {
438  return isValid() && hci.isOpen() && adapterInfo.isCurrentSettingBitSet(AdapterSetting::POWERED);
439  }
440 
441  /**
442  * Returns whether the adapter is suspended, i.e. valid and plugged in, but not powered.
443  * @return true if BTAdapter::isValid(), HCIHandler::isOpen() and AdapterSetting::POWERED state is not set.
444  * @see #isPowered()
445  * @see #isValid()
446  */
447  bool isSuspended() const noexcept {
448  return isValid() && hci.isOpen() && !adapterInfo.isCurrentSettingBitSet(AdapterSetting::POWERED);
449  }
450 
451  bool hasSecureConnections() const noexcept {
453  }
454 
455  bool hasSecureSimplePairing() const noexcept {
456  return adapterInfo.isCurrentSettingBitSet(AdapterSetting::SSP);
457  }
458 
459  /**
460  * Return LE_Features for this controller.
461  * <pre>
462  * BT Core Spec v5.2: Vol 6, Part B, 4.6 (LE LL) Feature Support
463  * </pre>
464  */
465  constexpr LE_Features getLEFeatures() const noexcept { return le_features; }
466 
467  /** Returns true if HCI_LE_Set_Extended_Scan_Parameters and HCI_LE_Set_Extended_Scan_Enable is supported (Bluetooth 5.0). */
468  constexpr bool hasHCIExtScan() const noexcept { return hci_uses_ext_scan; }
469 
470  /** Returns true if HCI_LE_Extended_Create_Connection is supported (Bluetooth 5.0). */
471  constexpr bool hasHCIExtConn() const noexcept { return hci_uses_ext_conn; }
472 
473  /**
474  * Returns whether the adapter is valid, i.e. reference is valid, plugged in and generally operational,
475  * but not necessarily BTAdapter::isPowered() powered.
476  * @return true if this adapter references are valid and hasn't been BTAdapter::close() 'ed
477  * @see #isPowered()
478  * @see #isSuspended()
479  */
480  bool isValid() const noexcept {
481  return BTObject::isValid();
482  }
483 
484  /**
485  * Returns the current BTMode of this adapter.
486  */
487  BTMode getBTMode() const noexcept { return adapterInfo.getCurrentBTMode(); }
488 
489  /**
490  * Returns the adapter's public BDAddressAndType.
491  * <p>
492  * The adapter's address as initially reported by the system is always its public address, i.e. BDAddressType::BDADDR_LE_PUBLIC.
493  * </p>
494  * @since 2.2.8
495  * @see #getVisibleAddressAndType()
496  */
497  BDAddressAndType const & getAddressAndType() const noexcept { return adapterInfo.addressAndType; }
498 
499  /**
500  * Returns the adapter's currently visible BDAddressAndType.
501  * <p>
502  * The adapter's address as initially reported by the system is always its public address, i.e. BDAddressType::BDADDR_LE_PUBLIC.
503  * </p>
504  * <p>
505  * The adapter's visible BDAddressAndType might be set to BDAddressType::BDADDR_LE_RANDOM before scanning / discovery mode (TODO).
506  * </p>
507  * @since 2.2.8
508  * @see #getAddressAndType()
509  */
510  BDAddressAndType const & getVisibleAddressAndType() const noexcept { return visibleAddressAndType; }
511 
512  /**
513  * Returns the system name.
514  */
515  std::string getName() const noexcept { return adapterInfo.getName(); }
516 
517  /**
518  * Returns the short system name.
519  */
520  std::string getShortName() const noexcept { return adapterInfo.getShortName(); }
521 
522  /**
523  * Returns the local friendly name and short_name. Contains empty strings if not set.
524  * <p>
525  * The value is being updated via SET_LOCAL_NAME management event reply.
526  * </p>
527  */
528  const NameAndShortName & getLocalName() const noexcept { return localName; }
529 
530  /**
531  * Sets the local friendly name.
532  * <p>
533  * Returns the immediate SET_LOCAL_NAME reply if successful, otherwise nullptr.
534  * The corresponding management event will be received separately.
535  * </p>
536  */
537  std::shared_ptr<NameAndShortName> setLocalName(const std::string &name, const std::string &short_name) noexcept;
538 
539  /**
540  * Set the discoverable state of the adapter.
541  */
542  bool setDiscoverable(bool value) noexcept;
543 
544  /**
545  * Set the bondable (aka pairable) state of the adapter.
546  */
547  bool setBondable(bool value) noexcept;
548 
549  /**
550  * Set the power state of the adapter.
551  */
552  bool setPowered(bool value) noexcept;
553 
554  /**
555  * Reset the adapter.
556  * <p>
557  * The semantics are specific to the HCI host implementation,
558  * however, it shall comply at least with the HCI Reset command
559  * and bring up the device from standby into a POWERED functional state afterwards.
560  * </p>
561  * <pre>
562  * BT Core Spec v5.2: Vol 4, Part E HCI: 7.3.2 Reset command
563  * </pre>
564  */
565  HCIStatusCode reset() noexcept;
566 
567  /**
568  * Returns a reference to the used singleton BTManager instance, used to create this adapter.
569  */
570  BTManager& getManager() const noexcept { return mgmt; }
571 
572  /**
573  * Returns a reference to the aggregated HCIHandler instance.
574  */
575  HCIHandler& getHCI() noexcept { return hci; }
576 
577  /**
578  * Returns true, if the adapter's device is already whitelisted.
579  */
580  bool isDeviceWhitelisted(const BDAddressAndType & addressAndType) noexcept;
581 
582  /**
583  * Add the given device to the adapter's autoconnect whitelist.
584  * <p>
585  * The given connection parameter will be uploaded to the kernel for the given device first.
586  * </p>
587  * <p>
588  * Method will reject duplicate devices, in which case it should be removed first.
589  * </p>
590  *
591  * @param address
592  * @param address_type
593  * @param ctype
594  * @param conn_interval_min in units of 1.25ms, default value 12 for 15ms; Value range [6 .. 3200] for [7.5ms .. 4000ms]
595  * @param conn_interval_max in units of 1.25ms, default value 12 for 15ms; Value range [6 .. 3200] for [7.5ms .. 4000ms]
596  * @param conn_latency slave latency in units of connection events, default value 0; Value range [0 .. 0x01F3].
597  * @param supervision_timeout in units of 10ms, default value >= 10 x conn_interval_max, we use HCIConstInt::LE_CONN_MIN_TIMEOUT_MS minimum; Value range [0xA-0x0C80] for [100ms - 32s].
598  * @return true if the device was already added or has been newly added to the adapter's whitelist.
599  */
600  bool addDeviceToWhitelist(const BDAddressAndType & addressAndType,
601  const HCIWhitelistConnectType ctype,
602  const uint16_t conn_interval_min=12, const uint16_t conn_interval_max=12,
603  const uint16_t conn_latency=0, const uint16_t supervision_timeout=getHCIConnSupervisorTimeout(0, 15));
604 
605 
606  /** Remove the given device from the adapter's autoconnect whitelist. */
607  bool removeDeviceFromWhitelist(const BDAddressAndType & addressAndType);
608 
609  // device discovery aka device scanning
610 
611  /**
612  * Add the given listener to the list if not already present.
613  * <p>
614  * In case the AdapterStatusListener's lifecycle and event delivery
615  * shall be constrained to this device, please use
616  * BTDevice::addStatusListener().
617  * </p>
618  * <p>
619  * Returns true if the given listener is not element of the list and has been newly added,
620  * otherwise false.
621  * </p>
622  * <p>
623  * The newly added AdapterStatusListener will receive an initial
624  * AdapterStatusListener::adapterSettingsChanged(..) event,
625  * passing an empty AdapterSetting::NONE oldMask and changedMask, as well as current AdapterSetting newMask. <br>
626  * This allows the receiver to be aware of this adapter's current settings.
627  * </p>
628  * @see BTDevice::addStatusListener()
629  * @see removeStatusListener()
630  * @see removeAllStatusListener()
631  */
632  bool addStatusListener(std::shared_ptr<AdapterStatusListener> l);
633 
634  /**
635  * Please use BTDevice::addStatusListener() for clarity, merely existing here to allow JNI access.
636  */
637  bool addStatusListener(const BTDevice& d, std::shared_ptr<AdapterStatusListener> l);
638 
639  /**
640  * Remove the given listener from the list.
641  * <p>
642  * Returns true if the given listener is an element of the list and has been removed,
643  * otherwise false.
644  * </p>
645  * @see BTDevice::removeStatusListener()
646  * @see addStatusListener()
647  */
648  bool removeStatusListener(std::shared_ptr<AdapterStatusListener> l);
649 
650  /**
651  * Remove the given listener from the list.
652  * <p>
653  * Returns true if the given listener is an element of the list and has been removed,
654  * otherwise false.
655  * </p>
656  * @see BTDevice::removeStatusListener()
657  * @see addStatusListener()
658  */
660 
661  /**
662  * Remove all status listener from the list.
663  * <p>
664  * Returns the number of removed status listener.
665  * </p>
666  */
668 
669  /**
670  * Starts a new discovery session.
671  * <p>
672  * Returns HCIStatusCode::SUCCESS if successful, otherwise the HCIStatusCode error state;
673  * </p>
674  * <p>
675  * if `keepAlive` is `true`, discovery state will be re-enabled
676  * in case the underlying Bluetooth implementation (BlueZ, ..) disabled it.
677  * Default is `true`.
678  * </p>
679  * <p>
680  * Using startDiscovery(keepAlive=true) and stopDiscovery()
681  * is the recommended workflow for a reliable discovery process.
682  * </p>
683  * <pre>
684  * + --+-------+--------+-----------+----------------------------------------------------+
685  * | # | meta | native | keepAlive | Note
686  * +---+-------+--------+-----------+----------------------------------------------------+
687  * | 1 | true | true | false | -
688  * | 2 | false | false | false | -
689  * +---+-------+--------+-----------+----------------------------------------------------+
690  * | 3 | true | true | true | -
691  * | 4 | true | false | true | temporarily disabled -> startDiscoveryBackground()
692  * | 5 | false | false | true | [4] -> [5] requires manual DISCOVERING event
693  * +---+-------+--------+-----------+----------------------------------------------------+
694  * </pre>
695  * <p>
696  * Remaining default parameter values are chosen for using public address resolution
697  * and usual discovery intervals etc.
698  * </p>
699  * <p>
700  * This adapter's HCIHandler instance is used to initiate scanning,
701  * see HCIHandler::le_set_scan_param() and HCIHandler::le_enable_scan().
702  * </p>
703  * <p>
704  * Method will always clear previous discovered devices via removeDiscoveredDevices().
705  * </p>
706  * @param keepAlive
707  * @param le_scan_active true enables delivery of active scanning PDUs, otherwise no scanning PDUs shall be sent (default)
708  * @param le_scan_interval in units of 0.625ms, default value 24 for 15ms; Value range [4 .. 0x4000] for [2.5ms .. 10.24s]
709  * @param le_scan_window in units of 0.625ms, default value 24 for 15ms; Value range [4 .. 0x4000] for [2.5ms .. 10.24s]. Shall be <= le_scan_interval
710  * @param filter_policy 0x00 accepts all PDUs (default), 0x01 only of whitelisted, ...
711  * @return HCIStatusCode::SUCCESS if successful, otherwise the HCIStatusCode error state
712  */
713  HCIStatusCode startDiscovery(const bool keepAlive=true,
714  const bool le_scan_active=false,
715  const uint16_t le_scan_interval=24, const uint16_t le_scan_window=24,
716  const uint8_t filter_policy=0x00);
717 
718  /**
719  * Closes the discovery session.
720  * <p>
721  * This adapter's HCIHandler instance is used to stop scanning,
722  * see HCIHandler::le_enable_scan().
723  * </p>
724  * @return HCIStatusCode::SUCCESS if successful, otherwise the HCIStatusCode error state
725  */
726  HCIStatusCode stopDiscovery() noexcept;
727 
728  /**
729  * Returns the current meta discovering ScanType. It can be modified through startDiscovery(..) and stopDiscovery().
730  * <p>
731  * Note that if startDiscovery(..) has been issued with keepAlive==true,
732  * the meta ScanType will still keep the desired ScanType enabled
733  * even if it has been temporarily disabled.
734  * </p>
735  * @see startDiscovery()
736  * @see stopDiscovery()
737  */
738  ScanType getCurrentScanType() const noexcept {
739  return currentMetaScanType;
740  }
741 
742  /**
743  * Returns the adapter's current native discovering ScanType. It can be modified through startDiscovery(..) and stopDiscovery().
744  * @see startDiscovery()
745  * @see stopDiscovery()
746  */
748  return hci.getCurrentScanType();
749  }
750 
751  /**
752  * Returns the meta discovering state. It can be modified through startDiscovery(..) and stopDiscovery().
753  * @see startDiscovery()
754  * @see stopDiscovery()
755  */
756  bool getDiscovering() const noexcept {
757  return ScanType::NONE != currentMetaScanType;
758  }
759 
760  /**
761  * Returns discovered devices from the last discovery.
762  * <p>
763  * Note that this list will be cleared when a new discovery is started over via startDiscovery().
764  * </p>
765  * <p>
766  * Note that devices in this list might be no more available,
767  * use 'DeviceStatusListener::deviceFound(..)' callback.
768  * </p>
769  */
771 
772  /** Discards all discovered devices. Returns number of removed discovered devices. */
773  int removeDiscoveredDevices() noexcept;
774 
775  /** Discards matching discovered devices. Returns `true` if found and removed, otherwise false. */
776  bool removeDiscoveredDevice(const BDAddressAndType & addressAndType) noexcept;
777 
778  /** Returns shared BTDevice if found, otherwise nullptr */
779  std::shared_ptr<BTDevice> findDiscoveredDevice (const EUI48 & address, const BDAddressType addressType) noexcept;
780 
781  /** Returns shared BTDevice if found, otherwise nullptr */
782  std::shared_ptr<BTDevice> findSharedDevice (const EUI48 & address, const BDAddressType addressType) noexcept;
783 
784  std::string toString() const noexcept override { return toString(false); }
785  std::string toString(bool includeDiscoveredDevices) const noexcept;
786 
787  /**
788  * Print the internally maintained BTDevice lists to stderr:
789  * - sharedDevices
790  * - connectedDevice
791  * - discoveredDevices
792  * - StatusListener
793  *
794  * This is intended as a debug facility.
795  */
796  void printDeviceLists() noexcept;
797 
798  void printStatusListenerList() noexcept;
799  };
800 
801 } // namespace direct_bt
802 
803 #endif /* BT_ADAPTER_HPP_ */
direct_bt::BTAdapter::getAddressAndType
BDAddressAndType const & getAddressAndType() const noexcept
Returns the adapter's public BDAddressAndType.
Definition: BTAdapter.hpp:497
direct_bt::SMPIOCapability::UNSET
@ UNSET
Denoting unset value, i.e.
direct_bt::BTAdapter::stopDiscovery
HCIStatusCode stopDiscovery() noexcept
Closes the discovery session.
Definition: BTAdapter.cpp:756
direct_bt::AdapterSetting
AdapterSetting
Adapter Setting Bits.
Definition: BTTypes1.hpp:136
direct_bt::BTAdapter::isDeviceWhitelisted
bool isDeviceWhitelisted(const BDAddressAndType &addressAndType) noexcept
Returns true, if the adapter's device is already whitelisted.
Definition: BTAdapter.cpp:518
direct_bt::BTAdapter::getHCI
HCIHandler & getHCI() noexcept
Returns a reference to the aggregated HCIHandler instance.
Definition: BTAdapter.hpp:575
direct_bt::AdapterStatusListener::matchDevice
virtual bool matchDevice(const BTDevice &device)
Custom filter for all 'device*' notification methods, which will not be called if this method returns...
Definition: BTAdapter.hpp:80
direct_bt::BTAdapter::hasHCIExtScan
constexpr bool hasHCIExtScan() const noexcept
Returns true if HCI_LE_Set_Extended_Scan_Parameters and HCI_LE_Set_Extended_Scan_Enable is supported ...
Definition: BTAdapter.hpp:468
direct_bt::AdapterStatusListener::~AdapterStatusListener
virtual ~AdapterStatusListener()
Definition: BTAdapter.hpp:210
direct_bt::BTAdapter::removeAllStatusListener
int removeAllStatusListener()
Remove all status listener from the list.
Definition: BTAdapter.cpp:649
darray.hpp
le_scan_interval
static const uint16_t le_scan_interval
Definition: dbt_scanner10.cpp:633
direct_bt::EIRDataType
EIRDataType
Bit mask of 'Extended Inquiry Response' (EIR) data fields, indicating a set of related data.
Definition: BTTypes0.hpp:752
direct_bt::BTAdapter::reset
HCIStatusCode reset() noexcept
Reset the adapter.
Definition: BTAdapter.cpp:489
direct_bt::BTAdapter::getBTMode
BTMode getBTMode() const noexcept
Returns the current BTMode of this adapter.
Definition: BTAdapter.hpp:487
direct_bt::BTAdapter::getVisibleAddressAndType
BDAddressAndType const & getVisibleAddressAndType() const noexcept
Returns the adapter's currently visible BDAddressAndType.
Definition: BTAdapter.hpp:510
direct_bt::BTAdapter::getLEFeatures
constexpr LE_Features getLEFeatures() const noexcept
Return LE_Features for this controller.
Definition: BTAdapter.hpp:465
direct_bt::AdapterStatusListener::devicePairingState
virtual void devicePairingState(std::shared_ptr< BTDevice > device, const SMPPairingState state, const PairingMode mode, const uint64_t timestamp)
An already connected BTDevice's SMPPairingState has changed.
Definition: BTAdapter.hpp:175
direct_bt::BTAdapter::isSuspended
bool isSuspended() const noexcept
Returns whether the adapter is suspended, i.e.
Definition: BTAdapter.hpp:447
direct_bt::BTAdapter::getLocalName
const NameAndShortName & getLocalName() const noexcept
Returns the local friendly name and short_name.
Definition: BTAdapter.hpp:528
direct_bt
Definition: ATTPDUTypes.hpp:171
direct_bt::BTMode::NONE
@ NONE
Zero mode, neither DUAL, BREDR nor LE.
direct_bt::AdapterStatusListener
BTAdapter status listener for BTDevice discovery events: Added, updated and removed; as well as for c...
Definition: BTAdapter.hpp:67
direct_bt::BTAdapter::removeDiscoveredDevices
int removeDiscoveredDevices() noexcept
Discards all discovered devices.
Definition: BTAdapter.cpp:877
direct_bt::HCIWhitelistConnectType
HCIWhitelistConnectType
HCI Whitelist connection type.
Definition: BTTypes0.hpp:415
direct_bt::AdapterInfo::getShortName
std::string getShortName() const noexcept
Definition: BTTypes1.hpp:280
direct_bt::BTAdapter::setBondable
bool setBondable(bool value) noexcept
Set the bondable (aka pairable) state of the adapter.
Definition: BTAdapter.cpp:357
BTTypes1.hpp
direct_bt::BTObject::isValid
bool isValid() const noexcept
Returns whether the object's reference is valid and in a general operational state.
Definition: BTTypes1.hpp:64
direct_bt::BTAdapter::setPowered
bool setPowered(bool value) noexcept
Set the power state of the adapter.
Definition: BTAdapter.cpp:362
direct_bt::BTAdapter::getDiscovering
bool getDiscovering() const noexcept
Returns the meta discovering state.
Definition: BTAdapter.hpp:756
direct_bt::BTAdapter::printDeviceLists
void printDeviceLists() noexcept
Print the internally maintained BTDevice lists to stderr:
Definition: BTAdapter.cpp:325
jau
Definition: basic_algos.hpp:34
direct_bt::HCIACLData
BT Core Spec v5.2: Vol 4, Part E HCI: 5.4.2 HCI ACL Data packets.
Definition: HCITypes.hpp:664
direct_bt::BTAdapter::close
void close() noexcept
Closes this instance, usually being called by destructor or when this adapter is being removed as rec...
Definition: BTAdapter.cpp:252
direct_bt::BTAdapter::getDiscoveredDevices
jau::darray< std::shared_ptr< BTDevice > > getDiscoveredDevices() const noexcept
Returns discovered devices from the last discovery.
Definition: BTAdapter.cpp:901
direct_bt::HCIHandler::getCurrentScanType
ScanType getCurrentScanType() const noexcept
Definition: HCIHandler.hpp:389
direct_bt::BTGattService
Representing a complete [Primary] Service Declaration including its list of Characteristic Declaratio...
Definition: BTGattService.hpp:67
direct_bt::ScanType
ScanType
Meta ScanType as derived from BTMode, with defined value mask consisting of BDAddressType bits.
Definition: BTTypes0.hpp:294
direct_bt::BTAdapter::getCurrentNativeScanType
ScanType getCurrentNativeScanType() const noexcept
Returns the adapter's current native discovering ScanType.
Definition: BTAdapter.hpp:747
direct_bt::BTAdapter::removeDiscoveredDevice
bool removeDiscoveredDevice(const BDAddressAndType &addressAndType) noexcept
Discards matching discovered devices.
Definition: BTAdapter.cpp:860
direct_bt::HCIHandler
A thread safe singleton handler of the HCI control channel to one controller (BT adapter)
Definition: HCIHandler.hpp:171
direct_bt::ConnectionInfo
mgmt_addr_info { EUI48, uint8_t type }, int8_t rssi, int8_t tx_power, int8_t max_tx_power;
Definition: BTTypes1.hpp:75
direct_bt::BTAdapter::dev_id
const uint16_t dev_id
Adapter's internal temporary device id.
Definition: BTAdapter.hpp:273
direct_bt::BTAdapter::hasHCIExtConn
constexpr bool hasHCIExtConn() const noexcept
Returns true if HCI_LE_Extended_Create_Connection is supported (Bluetooth 5.0).
Definition: BTAdapter.hpp:471
direct_bt::AdapterStatusListener::operator==
virtual bool operator==(const AdapterStatusListener &rhs) const
Default comparison operator, merely testing for same memory reference.
Definition: BTAdapter.hpp:220
direct_bt::BTAdapter::isPowered
bool isPowered() const noexcept
Returns whether the adapter is valid, plugged in and powered.
Definition: BTAdapter.hpp:437
direct_bt::MgmtEvent
uint16_t opcode, uint16_t dev-id, uint16_t param_size
Definition: MgmtTypes.hpp:1083
direct_bt::BTAdapter::getShortName
std::string getShortName() const noexcept
Returns the short system name.
Definition: BTAdapter.hpp:520
direct_bt::HCIStatusCode
HCIStatusCode
BT Core Spec v5.2: Vol 1, Part F Controller Error Codes: 1.3 List of Error Codes.
Definition: HCITypes.hpp:124
direct_bt::BTAdapter::removeStatusListener
bool removeStatusListener(std::shared_ptr< AdapterStatusListener > l)
Remove the given listener from the list.
Definition: BTAdapter.cpp:585
direct_bt::BTAdapter::findSharedDevice
std::shared_ptr< BTDevice > findSharedDevice(const EUI48 &address, const BDAddressType addressType) noexcept
Returns shared BTDevice if found, otherwise nullptr.
Definition: BTAdapter.cpp:934
jau::ordered_atomic< bool, std::memory_order::memory_order_seq_cst >
jau::darray
Implementation of a dynamic linear array storage, aka vector.
Definition: darray.hpp:102
cow_darray.hpp
direct_bt::impl::StatusListenerPair::wbr_device
std::weak_ptr< BTDevice > wbr_device
The optional weak device reference.
Definition: BTAdapter.hpp:236
direct_bt::BTAdapter::printStatusListenerList
void printStatusListenerList() noexcept
Definition: BTAdapter.cpp:340
direct_bt::LE_Features
LE_Features
HCI Supported Commands.
Definition: BTTypes0.hpp:106
le_scan_window
static const uint16_t le_scan_window
Definition: dbt_scanner10.cpp:634
direct_bt::AdapterStatusListener::deviceUpdated
virtual void deviceUpdated(std::shared_ptr< BTDevice > device, const EIRDataType updateMask, const uint64_t timestamp)
An already discovered BTDevice has been updated.
Definition: BTAdapter.hpp:148
direct_bt::BTAdapter::toString
std::string toString() const noexcept override
Definition: BTAdapter.hpp:784
direct_bt::NameAndShortName
Definition: BTTypes1.hpp:103
JAVA_DBT_PACKAGE
#define JAVA_DBT_PACKAGE
Definition: BTTypes1.hpp:39
direct_bt::BTObject
Definition: BTTypes1.hpp:48
direct_bt::SMPPDUMsg
Handles the Security Manager Protocol (SMP) using Protocol Data Unit (PDU) encoded messages over L2CA...
Definition: SMPTypes.hpp:644
direct_bt::AdapterInfo::getName
std::string getName() const noexcept
Definition: BTTypes1.hpp:279
direct_bt::BTAdapter::findDiscoveredDevice
std::shared_ptr< BTDevice > findDiscoveredDevice(const EUI48 &address, const BDAddressType addressType) noexcept
Returns shared BTDevice if found, otherwise nullptr.
Definition: BTAdapter.cpp:843
direct_bt::PairingMode
PairingMode
Bluetooth secure pairing mode.
Definition: BTTypes0.hpp:261
direct_bt::BTManager
A thread safe singleton handler of the Linux Kernel's BlueZ manager control channel.
Definition: BTManager.hpp:201
HCIHandler.hpp
direct_bt::BTAdapter::get_java_class
std::string get_java_class() const noexcept override
Definition: BTAdapter.hpp:424
jau::cow_darray< impl::StatusListenerPair >
direct_bt::BTAdapter::addStatusListener
bool addStatusListener(std::shared_ptr< AdapterStatusListener > l)
Add the given listener to the list if not already present.
Definition: BTAdapter.cpp:548
direct_bt::impl::StatusListenerPair::listener
std::shared_ptr< AdapterStatusListener > listener
The actual listener.
Definition: BTAdapter.hpp:234
le_scan_active
static bool le_scan_active
Definition: dbt_scanner10.cpp:632
direct_bt::AdapterStatusListener::adapterSettingsChanged
virtual void adapterSettingsChanged(BTAdapter &adapter, const AdapterSetting oldmask, const AdapterSetting newmask, const AdapterSetting changedmask, const uint64_t timestamp)
BTAdapter setting(s) changed.
Definition: BTAdapter.hpp:93
direct_bt::BTAdapter::BTAdapter
BTAdapter(const BTAdapter::ctor_cookie &cc, BTManager &mgmt_, const AdapterInfo &adapterInfo_) noexcept
Private ctor for private BTAdapter::make_shared() intended for friends.
Definition: BTAdapter.cpp:224
direct_bt::BTAdapter::hasSecureConnections
bool hasSecureConnections() const noexcept
Definition: BTAdapter.hpp:451
direct_bt::AdapterSetting::SECURE_CONN
@ SECURE_CONN
direct_bt::HCIHandler::isOpen
bool isOpen() const noexcept
Returns true if this mgmt instance is open, connected and hence valid, otherwise false.
Definition: HCIHandler.hpp:374
direct_bt::getHCIConnSupervisorTimeout
constexpr int32_t getHCIConnSupervisorTimeout(const uint16_t conn_latency, const uint16_t conn_interval_max_ms, const uint16_t min_result_ms=number(HCIConstInt::LE_CONN_MIN_TIMEOUT_MS), const uint16_t multiplier=10) noexcept
Defining the supervising timeout for LE connections to be a multiple of the maximum connection interv...
Definition: HCITypes.hpp:97
direct_bt::BTAdapter::setLocalName
std::shared_ptr< NameAndShortName > setLocalName(const std::string &name, const std::string &short_name) noexcept
Sets the local friendly name.
Definition: BTAdapter.cpp:348
direct_bt::BTAdapter::hasSecureSimplePairing
bool hasSecureSimplePairing() const noexcept
Definition: BTAdapter.hpp:455
direct_bt::BTAdapter
BTAdapter represents one Bluetooth Controller.
Definition: BTAdapter.hpp:250
direct_bt::AdapterStatusListener::toString
virtual std::string toString() const =0
direct_bt::BDAddressType
BDAddressType
BT Core Spec v5.2: Vol 3, Part C Generic Access Profile (GAP): 15.1.1.1 Public Bluetooth address.
Definition: BTAddress.hpp:51
direct_bt::EUI48
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
Definition: BTAddress.hpp:388
direct_bt::BTAdapter::getManager
BTManager & getManager() const noexcept
Returns a reference to the used singleton BTManager instance, used to create this adapter.
Definition: BTAdapter.hpp:570
direct_bt::AdapterSetting::SSP
@ SSP
direct_bt::AdapterInfo::isCurrentSettingBitSet
bool isCurrentSettingBitSet(const AdapterSetting bit) const noexcept
Definition: BTTypes1.hpp:273
direct_bt::SMPIOCapability
SMPIOCapability
Vol 3, Part H, 2.3.2 IO capabilities.
Definition: SMPTypes.hpp:185
direct_bt::BTAdapter::isValid
bool isValid() const noexcept
Returns whether the adapter is valid, i.e.
Definition: BTAdapter.hpp:480
direct_bt::BTAdapter::setDiscoverable
bool setDiscoverable(bool value) noexcept
Set the discoverable state of the adapter.
Definition: BTAdapter.cpp:352
direct_bt::AdapterStatusListener::deviceConnected
virtual void deviceConnected(std::shared_ptr< BTDevice > device, const uint16_t handle, const uint64_t timestamp)
BTDevice got connected.
Definition: BTAdapter.hpp:160
direct_bt::AdapterStatusListener::deviceReady
virtual void deviceReady(std::shared_ptr< BTDevice > device, const uint64_t timestamp)
BTDevice is ready for user (GATT) processing, i.e.
Definition: BTAdapter.hpp:191
direct_bt::AdapterInfo::addressAndType
const BDAddressAndType addressAndType
The adapter's address initially reported by the system is always its public address,...
Definition: BTTypes1.hpp:201
direct_bt::BTAdapter::addDeviceToWhitelist
bool addDeviceToWhitelist(const BDAddressAndType &addressAndType, const HCIWhitelistConnectType ctype, const uint16_t conn_interval_min=12, const uint16_t conn_interval_max=12, const uint16_t conn_latency=0, const uint16_t supervision_timeout=getHCIConnSupervisorTimeout(0, 15))
Add the given device to the adapter's autoconnect whitelist.
Definition: BTAdapter.cpp:522
direct_bt::AdapterStatusListener::discoveringChanged
virtual void discoveringChanged(BTAdapter &adapter, const ScanType currentMeta, const ScanType changedType, const bool changedEnabled, const bool keepAlive, const uint64_t timestamp)
BTAdapter's discovery state has changed, i.e.
Definition: BTAdapter.hpp:113
direct_bt::AdapterInfo::getCurrentBTMode
BTMode getCurrentBTMode() const noexcept
Map getCurrentSettingMask() to BTMode.
Definition: BTTypes1.hpp:276
direct_bt::BTAdapter::java_class
static std::string java_class() noexcept
Definition: BTAdapter.hpp:427
filter_policy
static const uint8_t filter_policy
Definition: dbt_scanner10.cpp:635
direct_bt::AdapterStatusListener::deviceDisconnected
virtual void deviceDisconnected(std::shared_ptr< BTDevice > device, const HCIStatusCode reason, const uint16_t handle, const uint64_t timestamp)
BTDevice got disconnected.
Definition: BTAdapter.hpp:203
direct_bt::AdapterStatusListener::operator!=
bool operator!=(const AdapterStatusListener &rhs) const
Definition: BTAdapter.hpp:223
direct_bt::BTAdapter::startDiscovery
HCIStatusCode startDiscovery(const bool keepAlive=true, const bool le_scan_active=false, const uint16_t le_scan_interval=24, const uint16_t le_scan_window=24, const uint8_t filter_policy=0x00)
Starts a new discovery session.
Definition: BTAdapter.cpp:679
direct_bt::AdapterSetting::POWERED
@ POWERED
direct_bt::AdapterInfo
Definition: BTTypes1.hpp:188
direct_bt::BTAdapter::getCurrentScanType
ScanType getCurrentScanType() const noexcept
Returns the current meta discovering ScanType.
Definition: BTAdapter.hpp:738
direct_bt::SMPPairingState
SMPPairingState
SMP Pairing Process state definition.
Definition: SMPTypes.hpp:101
direct_bt::BDAddressAndType
Unique Bluetooth EUI48 address and BDAddressType tuple.
Definition: BTAddress.hpp:417
direct_bt::AdapterStatusListener::deviceFound
virtual bool deviceFound(std::shared_ptr< BTDevice > device, const uint64_t timestamp)
A BTDevice has been newly discovered.
Definition: BTAdapter.hpp:136
direct_bt::BTDevice
Definition: BTDevice.hpp:57
BTDevice.hpp
direct_bt::BTAdapter::getName
std::string getName() const noexcept
Returns the system name.
Definition: BTAdapter.hpp:515
direct_bt::impl::StatusListenerPair
Definition: BTAdapter.hpp:232
direct_bt::BTMode
BTMode
Bluetooth adapter operating mode.
Definition: BTTypes0.hpp:56
direct_bt::BTAdapter::removeDeviceFromWhitelist
bool removeDeviceFromWhitelist(const BDAddressAndType &addressAndType)
Remove the given device from the adapter's autoconnect whitelist.
Definition: BTAdapter.cpp:541
direct_bt::ScanType::NONE
@ NONE