Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Go to the documentation of this file.
130 static void removeDevice(std::shared_ptr<BTDevice> device);
137 const AdapterSetting changedmask,
const uint64_t timestamp)
override {
139 if( initialSetting ) {
140 fprintf_td(stderr,
"****** SETTINGS_INITIAL: %s -> %s, changed %s\n",
to_string(oldmask).c_str(),
143 fprintf_td(stderr,
"****** SETTINGS_CHANGED: %s -> %s, changed %s\n",
to_string(oldmask).c_str(),
150 if( !initialSetting &&
159 void discoveringChanged(
BTAdapter &a,
const ScanType currentMeta,
const ScanType changedType,
const bool changedEnabled,
const bool keepAlive,
const uint64_t timestamp)
override {
160 fprintf_td(stderr,
"****** DISCOVERING: meta %s, changed[%s, enabled %d, keepAlive %d]: %s\n",
165 bool deviceFound(std::shared_ptr<BTDevice> device,
const uint64_t timestamp)
override {
171 fprintf_td(stderr,
"****** FOUND__-2: Skip non 'public LE' and non 'random static public LE' %s\n", device->
toString(
true).c_str());
182 fprintf_td(stderr,
"****** FOUND__-0: Connecting %s\n", device->
toString(
true).c_str());
185 fprintf_td(stderr,
"PERF: adapter-init -> FOUND__-0 %" PRIu64
" ms\n", td);
196 void deviceUpdated(std::shared_ptr<BTDevice> device,
const EIRDataType updateMask,
const uint64_t timestamp)
override {
203 void deviceConnected(std::shared_ptr<BTDevice> device,
const uint16_t handle,
const uint64_t timestamp)
override {
209 void devicePairingState(std::shared_ptr<BTDevice> device,
const SMPPairingState state,
const PairingMode mode,
const uint64_t timestamp)
override {
210 fprintf_td(stderr,
"****** PAIRING STATE: state %s, mode %s, %s\n",
219 fprintf_td(stderr,
"****** PAIRING_STATE: state %s; Remove key file %s, res %d\n",
246 if(
nullptr != sec ) {
269 void deviceReady(std::shared_ptr<BTDevice> device,
const uint64_t timestamp)
override {
288 void deviceDisconnected(std::shared_ptr<BTDevice> device,
const HCIStatusCode reason,
const uint16_t handle,
const uint64_t timestamp)
override {
289 fprintf_td(stderr,
"****** DISCONNECTED: Reason 0x%X (%s), old handle %s: %s\n",
290 static_cast<uint8_t
>(reason),
to_string(reason).c_str(),
306 std::string toString()
const override {
307 return "MyAdapterStatusListener[this "+
to_hexstring(
this)+
"]";
324 fprintf_td(stderr,
"**[%2.2d.%2.2d] Characteristic-Notify: UUID %s, td %" PRIu64
" ******\n",
325 i, j, charDecl->value_type->toUUID128String().c_str(), (tR-timestamp));
326 fprintf_td(stderr,
"**[%2.2d.%2.2d] Characteristic: %s ******\n", i, j, charDecl->toString().c_str());
329 if(
nullptr != temp ) {
330 fprintf_td(stderr,
"**[%2.2d.%2.2d] Value T: %s ******\n", i, j, temp->
toString().c_str());
333 fprintf_td(stderr,
"**[%2.2d.%2.2d] Value R: %s ******\n", i, j, char_value.
toString().c_str());
337 const TROOctets& char_value,
const uint64_t timestamp,
338 const bool confirmationSent)
override
341 fprintf_td(stderr,
"**[%2.2d.%2.2d] Characteristic-Indication: UUID %s, td %" PRIu64
", confirmed %d ******\n",
342 i, j, charDecl->value_type->toUUID128String().c_str(), (tR-timestamp), confirmationSent);
343 fprintf_td(stderr,
"**[%2.2d.%2.2d] Characteristic: %s ******\n", i, j, charDecl->toString().c_str());
346 if(
nullptr != temp ) {
347 fprintf_td(stderr,
"**[%2.2d.%2.2d] Value T: %s ******\n", i, j, temp->
toString().c_str());
350 fprintf_td(stderr,
"**[%2.2d.%2.2d] Value R: %s ******\n", i, j, char_value.
toString().c_str());
355 fprintf_td(stderr,
"****** Connecting Device: Start %s\n", device->
toString().c_str());
359 void deviceUpdated(std::shared_ptr<BTDevice> device,
const EIRDataType updateMask,
const uint64_t timestamp)
override {
365 void deviceConnected(std::shared_ptr<BTDevice> device,
const uint16_t handle,
const uint64_t timestamp)
override {
370 std::string toString()
const override {
371 return "TempAdapterStatusListener[this "+
to_hexstring(
this)+
"]";
374 device->
addStatusListener(std::shared_ptr<AdapterStatusListener>(
new TempAdapterStatusListener()));
378 fprintf_td(stderr,
"****** Connecting Device: Unpair-Pre result: %s\n",
to_string(r).c_str());
383 fprintf_td(stderr,
"****** Connecting Device: stopDiscovery result %s\n",
to_string(r).c_str());
387 if(
nullptr != sec ) {
388 fprintf_td(stderr,
"****** Connecting Device: Found SecurityDetail %s for %s\n", sec->
toString().c_str(), device->
toString().c_str());
390 fprintf_td(stderr,
"****** Connecting Device: No SecurityDetail for %s\n", device->
toString().c_str());
394 fprintf_td(stderr,
"****** Connecting Device: SMPKeyBin::readAndApply(..) result %s\n",
to_string(res).c_str());
396 if(
nullptr != sec ) {
399 fprintf_td(stderr,
"****** Connecting Device: Using SecurityDetail.SEC AUTO %s, set OK %d\n", sec->
toString().c_str(), r);
402 fprintf_td(stderr,
"****** Connecting Device: Using SecurityDetail.Level+IOCap %s, set OK %d\n", sec->
toString().c_str(), r);
405 fprintf_td(stderr,
"****** Connecting Device: Setting SEC AUTO security detail w/ KEYBOARD_ONLY (%s) -> set OK %d\n", sec->
toString().c_str(), r);
409 fprintf_td(stderr,
"****** Connecting Device: Setting SEC AUTO security detail w/ KEYBOARD_ONLY -> set OK %d\n", r);
426 fprintf_td(stderr,
"****** Processing Ready Device: Start %s\n", device->
toString().c_str());
433 bool success =
false;
438 fprintf_td(stderr,
"****** Connected LE PHY: status %s: RX %s, TX %s\n",
451 if( 0 == primServices.
size() ) {
452 fprintf_td(stderr,
"****** Processing Ready Device: getServices() failed %s\n", device->
toString().c_str());
459 const uint64_t td15 = t5 - t1;
463 fprintf_td(stderr,
"PERF: GATT primary-services completed\n");
464 fprintf_td(stderr,
"PERF: adapter-init to processing-start %" PRIu64
" ms,\n"
465 "PERF: get-gatt-services %" PRIu64
" ms,\n"
466 "PERF: discovered to gatt-complete %" PRIu64
" ms (connect %" PRIu64
" ms),\n"
467 "PERF: adapter-init to gatt-complete %" PRIu64
" ms\n\n",
468 td01, td15, tdc5, (tdc5 - td15), td05);
479 if(
nullptr != char2 ) {
480 bool cccdEnableResult[2];
484 fprintf_td(stderr,
"Added CharPingPongListenerRes Notification(%d), Indication(%d): Result %d\n",
485 cccdEnableResult[0], cccdEnableResult[1], cccdRet);
500 if(
nullptr != ga && !
QUIET ) {
507 if(
nullptr != di && !
QUIET ) {
513 for(
size_t i=0; i<primServices.
size(); i++) {
516 fprintf_td(stderr,
" [%2.2d] Service UUID %s\n", i, primService.
type->toUUID128String().c_str());
520 for(
size_t j=0; j<serviceCharacteristics.
size(); j++) {
521 BTGattChar & serviceChar = *serviceCharacteristics.
at(j);
523 fprintf_td(stderr,
" [%2.2d.%2.2d] Characteristic: UUID %s\n", i, j, serviceChar.
value_type->toUUID128String().c_str());
531 fprintf_td(stderr,
" [%2.2d.%2.2d] value: %s ('%s')\n", (
int)i, (
int)j, value.
toString().c_str(), sval.c_str());
536 for(
size_t k=0; k<charDescList.
size(); k++) {
539 fprintf_td(stderr,
" [%2.2d.%2.2d.%2.2d] Descriptor: UUID %s\n", i, j, k, charDesc.
type->toUUID128String().c_str());
540 fprintf_td(stderr,
" [%2.2d.%2.2d.%2.2d] %s\n", i, j, k, charDesc.
toString().c_str());
543 bool cccdEnableResult[2];
547 fprintf_td(stderr,
" [%2.2d.%2.2d] Characteristic-Listener: Notification(%d), Indication(%d): Added %d\n",
548 (
int)i, (
int)j, cccdEnableResult[0], cccdEnableResult[1], cccdRet);
555 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
557 }
catch ( std::exception & e ) {
558 fprintf_td(stderr,
"****** Processing Ready Device: Exception caught for %s: %s\n", device->
toString().c_str(), e.what());
562 fprintf_td(stderr,
"****** Processing Ready Device: End-1: Success %d on %s; devInProc %zu\n",
574 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
584 fprintf_td(stderr,
"****** Processing Ready Device: End-2: Success %d on %s; devInProc %zu\n",
595 fprintf_td(stderr,
"****** Processing Ready Device: Unpair-Post result: %s\n",
to_string(unpair_res).c_str());
627 fprintf_td(stderr,
"****** Reset Adapter: reset[%d] start: %s\n", mode, a->
toString().c_str());
639 fprintf_td(stderr,
"****** Start discovery (%s) result: %s\n", msg.c_str(),
to_string(status).c_str());
658 fprintf_td(stderr,
"Added to WHITELIST: res %d, address %s\n", res, it->toString().c_str());
671 fprintf_td(stderr,
"****** Adapter ADDED__: InitOK. %s\n", adapter->
toString().c_str());
673 fprintf_td(stderr,
"****** Adapter ADDED__: Ignored %s\n", adapter->
toString().c_str());
685 fprintf_td(stderr,
"DirectBT Native Version %s (API %s)\n", DIRECT_BT_VERSION, DIRECT_BT_VERSION_API);
697 fprintf_td(stderr,
"****** EOL Test MULTI_MEASUREMENTS left %d, processed %zu/%zu\n",
703 std::this_thread::sleep_for(std::chrono::milliseconds(2000));
713 fprintf_td(stderr,
"****** EOL Adapter's Devices - pre close: %s\n", adapter->
toString().c_str());
718 fprintf_td(stderr,
"****** EOL Removed ChangedAdapterSetCallback %d\n", count);
723 fprintf_td(stderr,
"****** EOL Adapter's Devices - post close: %s\n", adapter->
toString().c_str());
730 int main(
int argc,
char *argv[])
733 bool waitForEnter=
false;
735 for(
int i=1; i<argc; i++) {
736 if( !strcmp(
"-dbt_debug", argv[i]) && argc > (i+1) ) {
737 setenv(
"direct_bt.debug", argv[++i], 1 );
738 }
else if( !strcmp(
"-dbt_verbose", argv[i]) && argc > (i+1) ) {
739 setenv(
"direct_bt.verbose", argv[++i], 1 );
740 }
else if( !strcmp(
"-dbt_gatt", argv[i]) && argc > (i+1) ) {
741 setenv(
"direct_bt.gatt", argv[++i], 1 );
742 }
else if( !strcmp(
"-dbt_l2cap", argv[i]) && argc > (i+1) ) {
743 setenv(
"direct_bt.l2cap", argv[++i], 1 );
744 }
else if( !strcmp(
"-dbt_hci", argv[i]) && argc > (i+1) ) {
745 setenv(
"direct_bt.hci", argv[++i], 1 );
746 }
else if( !strcmp(
"-dbt_mgmt", argv[i]) && argc > (i+1) ) {
747 setenv(
"direct_bt.mgmt", argv[++i], 1 );
748 }
else if( !strcmp(
"-btmode", argv[i]) && argc > (i+1) ) {
751 setenv(
"direct_bt.mgmt.btmode",
to_string(btMode).c_str(), 1 );
753 }
else if( !strcmp(
"-wait", argv[i]) ) {
755 }
else if( !strcmp(
"-show_update_events", argv[i]) ) {
757 }
else if( !strcmp(
"-quiet", argv[i]) ) {
759 }
else if( !strcmp(
"-scanPassive", argv[i]) ) {
761 }
else if( !strcmp(
"-dev", argv[i]) && argc > (i+1) ) {
762 std::string addrOrNameSub = std::string(argv[++i]);
764 }
else if( !strcmp(
"-wl", argv[i]) && argc > (i+1) ) {
765 std::string macstr = std::string(argv[++i]);
767 fprintf(stderr,
"Whitelist + %s\n", wle.
toString().c_str());
770 }
else if( !strcmp(
"-passkey", argv[i]) && argc > (i+2) ) {
771 const std::string addrOrNameSub(argv[++i]);
773 sec->
passkey = atoi(argv[++i]);
774 fprintf(stderr,
"Set passkey in %s\n", sec->
toString().c_str());
775 }
else if( !strcmp(
"-seclevel", argv[i]) && argc > (i+2) ) {
776 const std::string addrOrNameSub(argv[++i]);
779 fprintf(stderr,
"Set sec_level in %s\n", sec->
toString().c_str());
780 }
else if( !strcmp(
"-iocap", argv[i]) && argc > (i+2) ) {
781 const std::string addrOrNameSub(argv[++i]);
784 fprintf(stderr,
"Set io_cap in %s\n", sec->
toString().c_str());
785 }
else if( !strcmp(
"-secauto", argv[i]) && argc > (i+2) ) {
786 const std::string addrOrNameSub(argv[++i]);
789 fprintf(stderr,
"Set SEC AUTO security io_cap in %s\n", sec->
toString().c_str());
790 }
else if( !strcmp(
"-charid", argv[i]) && argc > (i+1) ) {
792 }
else if( !strcmp(
"-charval", argv[i]) && argc > (i+1) ) {
794 }
else if( !strcmp(
"-disconnect", argv[i]) ) {
796 }
else if( !strcmp(
"-enableGATTPing", argv[i]) ) {
798 }
else if( !strcmp(
"-keepDevice", argv[i]) ) {
800 }
else if( !strcmp(
"-count", argv[i]) && argc > (i+1) ) {
802 }
else if( !strcmp(
"-single", argv[i]) ) {
804 }
else if( !strcmp(
"-resetEachCon", argv[i]) && argc > (i+1) ) {
808 fprintf(stderr,
"pid %d\n", getpid());
810 fprintf(stderr,
"Run with '[-btmode LE|BREDR|DUAL] "
811 "[-disconnect] [-enableGATTPing] [-count <number>] [-single] [-show_update_events] [-quiet] "
813 "[-resetEachCon connectionCount] "
814 "(-dev <device_[address|name]_sub>)* (-wl <device_address>)* "
815 "(-seclevel <device_[address|name]_sub> <int_sec_level>)* "
816 "(-iocap <device_[address|name]_sub> <int_iocap>)* "
817 "(-secauto <device_[address|name]_sub> <int_iocap>)* "
818 "(-passkey <device_[address|name]_sub> <digits>)* "
819 "[-unpairPre] [-unpairPost] "
820 "[-charid <uuid>] [-charval <byte-val>] "
821 "[-dbt_verbose true|false] "
822 "[-dbt_debug true|false|adapter.event,gatt.data,hci.event,hci.scan_ad_eir,mgmt.event] "
823 "[-dbt_mgmt cmd.timeout=3000,ringsize=64,...] "
824 "[-dbt_hci cmd.complete.timeout=10000,cmd.status.timeout=3000,ringsize=64,...] "
825 "[-dbt_gatt cmd.read.timeout=500,cmd.write.timeout=500,cmd.init.timeout=2500,ringsize=128,...] "
826 "[-dbt_l2cap reader.timeout=10000,restart.count=0,...] "
836 fprintf(stderr,
"QUIET %d\n",
QUIET);
837 fprintf(stderr,
"btmode %s\n",
to_string(btMode).c_str());
839 fprintf(stderr,
"characteristic-id: %s\n",
charIdentifier.c_str());
840 fprintf(stderr,
"characteristic-value: %d\n",
charValue);
846 fprintf(stderr,
"Press ENTER to continue\n");
849 fprintf(stderr,
"****** TEST start\n");
851 fprintf(stderr,
"****** TEST end\n");
855 fprintf(stderr,
"****** Manager close start\n");
858 fprintf(stderr,
"****** Manager close end\n");
std::string getWaitForDevicesString() noexcept
jau::darray< BTGattCharRef > characteristicList
List of Characteristic Declarations as shared reference.
HCIStatusCode stopDiscovery() noexcept
Closes the discovery session.
HCIStatusCode connectDefault() noexcept
Establish a default HCI connection to this device, using certain default parameter.
const_reference at(size_type i) const
Like std::vector::at(size_type), immutable reference.
AdapterSetting
Adapter Setting Bits.
Entry * getOrCreate(const std::string &addrOrNameSub) noexcept
Determines whether the given.
bool areAllDevicesProcessed(DeviceQueryMatchFunc m) noexcept
Returns.
std::shared_ptr< GattDeviceInformationSvc > getDeviceInformation(jau::darray< BTGattServiceRef > &primServices)
bool hasProperties(const PropertyBitVal v) const noexcept
void remove() noexcept
Disconnects this device via disconnect(..) if getConnected()==true and explicitly removes its shared ...
std::string getProcessedDevicesString() noexcept
std::string toString() const noexcept
bool setConnSecurityAuto(const SMPIOCapability iocap_auto) noexcept
Set automatic security negotiation of BTSecurityLevel and SMPIOCapability pairing mode.
constexpr jau::nsize_t getSize() const noexcept
Returns the used memory size for read and write operations, may be zero.
static std::shared_ptr< GattTemperatureMeasurement > get(const TROOctets &source) noexcept
constexpr bool isSecLevelOrIOCapSet() const noexcept
static const uint16_t le_scan_interval
@ HCI_AUTO_CONN_ALWAYS
Auto Connect: Only supported for LE on Linux .
EIRDataType
Bit mask of 'Extended Inquiry Response' (EIR) data fields, indicating a set of related data.
HCIStatusCode reset() noexcept
Reset the adapter.
constexpr BTSecurityLevel to_BTSecurityLevel(const uint8_t v) noexcept
std::string allToString() noexcept
@ PASSKEY_EXPECTED
Phase 2: Authentication (MITM) PASSKEY expected now, see PairingMode::PASSKEY_ENTRY_ini.
BLERandomAddressType getBLERandomAddressType() const noexcept
Returns the BLERandomAddressType.
constexpr LE_Features getLEFeatures() const noexcept
Return LE_Features for this controller.
bool readValue(POctets &res, int expectedLength=-1)
BT Core Spec v5.2: Vol 3, Part G GATT: 4.8.1 Read Characteristic Value.
Entry * getStartOf(const EUI48 &addr, const std::string &name) noexcept
Returns a matching Entry,.
std::unique_ptr< const uuid_t > type
Type of descriptor.
SMPIOCapability io_cap_auto
std::string toString() const noexcept
constexpr int getPairingPasskey() const noexcept
static bool SHOW_UPDATE_EVENTS
BTMode to_BTMode(const std::string &value) noexcept
Maps the specified name to a constant of BTMode.
virtual std::string toString() const noexcept override
@ NONE
Zero mode, neither DUAL, BREDR nor LE.
HCIStatusCode getConnectedLE_PHY(LE_PHYs &resRx, LE_PHYs &resTx) noexcept
Request and return LE_PHYs bit for the given connection.
BTAdapter status listener for BTDevice discovery events: Added, updated and removed; as well as for c...
int removeDiscoveredDevices() noexcept
Discards all discovered devices.
HCIStatusCode setPairingNumericComparison(const bool equal) noexcept
Method sets the numeric comparison result, see PairingMode::NUMERIC_COMPARE_ini.
@ OOB_EXPECTED
Phase 2: Authentication (MITM) OOB data expected now, see PairingMode::OUT_OF_BAND.
uint64_t getLastDiscoveryTimestamp() const noexcept
Returns the timestamp in monotonic milliseconds when this device instance has discovered or connected...
bool pingGATT() noexcept
Issues a GATT ping to the device, validating whether it is still reachable.
static std::string getFilename(const std::string &path, const BDAddressAndType &addrAndType_)
size_t getProcessingDeviceCount() noexcept
constexpr SMPIOCapability to_SMPIOCapability(const uint8_t v) noexcept
static const uuid16_t _TEMPERATURE_MEASUREMENT(GattCharacteristicType::TEMPERATURE_MEASUREMENT)
static void removeDevice(std::shared_ptr< BTDevice > device)
@ KEY_DISTRIBUTION
Phase 3: Key & value distribution started after SMPPairConfirmMsg or SMPPairPubKeyMsg (LE Secure Conn...
constexpr uint8_t const * get_ptr() const noexcept
std::string toString() const noexcept
void printDeviceLists() noexcept
Print the internally maintained BTDevice lists to stderr:
void addToProcessingDevices(const BDAddressAndType &a, const std::string &n) noexcept
std::string toString() const noexcept
Representing a complete [Primary] Service Declaration including its list of Characteristic Declaratio...
ScanType
Meta ScanType as derived from BTMode, with defined value mask consisting of BDAddressType bits.
static jau::darray< BDAddressAndType > WHITELIST
std::string toString() const noexcept override
constexpr BDAddressAndType const & getAddressAndType() const noexcept
Returns the unique device EUI48 address and BDAddressType type.
bool addCharListener(std::shared_ptr< Listener > l)
Add the given BTGattChar::Listener to the listener list if not already present.
bool isWaitingForDevice(const EUI48 &address, const std::string &name, DeviceQueryMatchFunc m) noexcept
Returns.
BTSecurityLevel
Bluetooth Security Level.
constexpr const SMPIOCapability & getIOCap() const noexcept
bool isPowered() const noexcept
Returns whether the adapter is valid, plugged in and powered.
HCIStatusCode
BT Core Spec v5.2: Vol 1, Part F Controller Error Codes: 1.3 List of Error Codes.
static int RESET_ADAPTER_EACH_CONN
Implementation of a dynamic linear array storage, aka vector.
static uint64_t timestamp_t0
std::shared_ptr< BTGattChar > BTGattCharRef
constexpr bool getPairingNumericComparison() const noexcept
std::shared_ptr< GattGenericAccessSvc > getGattGenericAccess()
Returns the shared GenericAccess instance, retrieved by getGattService() or nullptr if not available.
static const uint16_t le_scan_window
@ TEMPERATURE_MEASUREMENT
int fprintf_td(FILE *stream, const char *format,...) noexcept
Convenient fprintf() invocation, prepending the environment::getElapsedMillisecond() timestamp.
void notificationReceived(BTGattCharRef charDecl, const TROOctets &char_value, const uint64_t timestamp) override
Called from native BLE stack, initiated by a received notification associated with the given BTGattCh...
jau::darray< std::shared_ptr< BTAdapter > > getAdapters()
Returns a list of currently added DBTAdapter.
static std::atomic< int > MULTI_MEASUREMENTS
std::string toString() const noexcept override
HCIStatusCode setPairingPasskey(const uint32_t passkey) noexcept
Method sets the given passkey entry, see PairingMode::PASSKEY_ENTRY_ini.
void addToWaitForDevices(const std::string &addrOrNameSub) noexcept
bool removeFromProcessingDevices(const BDAddressAndType &a) noexcept
@ FEATURE_EXCHANGE_COMPLETED
Phase 1: Pairing responded by responding (slave) device via SMPPairingMsg.
int removeChangedAdapterSetCallback(const ChangedAdapterSetCallback &l)
Remove the given ChangedAdapterSetCallback from this manager.
static BTManager & get(const BTMode defaultBTMode=BTMode::NONE)
Retrieves the singleton instance.
static bool GATT_PING_ENABLED
@ UNSET
Security Level not set, value 0.
constexpr size_type size() const noexcept
Like std::vector::size().
PairingMode
Bluetooth secure pairing mode.
int removeAllCharListener() noexcept
Remove all BTGattCharListener from the list.
void addToProcessedDevices(const BDAddressAndType &a, const std::string &n) noexcept
A thread safe singleton handler of the Linux Kernel's BlueZ manager control channel.
bool isDeviceProcessing(const BDAddressAndType &a) noexcept
int main(int argc, char *argv[])
@ STATIC_PUBLIC
Static public 'random' device address 0b11.
@ REQUESTED_BY_RESPONDER
Phase 0: Pairing requested by responding (slave) device via SMPSecurityReqMsg.
uint32_t dfa_utf8_decode(uint32_t &state, uint32_t &codep, const uint32_t byte_value)
bool setConnSecurityBest(const BTSecurityLevel sec_level, const SMPIOCapability io_cap) noexcept
Convenience method to determine the best practice BTSecurityLevel and SMPIOCapability based on the gi...
std::unique_ptr< const uuid_t > type
Service type UUID.
constexpr UnaryFunction for_each_const(T &data, UnaryFunction f, std::enable_if_t< is_cow_type< T >::value, bool >=true) noexcept
bool addStatusListener(std::shared_ptr< AdapterStatusListener > l)
Add the given listener to the list if not already present.
static bool REMOVE_DEVICE
std::string toString() const noexcept override
static bool le_scan_active
static const std::string KEY_PATH
@ NUMERIC_COMPARE_EXPECTED
Phase 2: Authentication (MITM) Numeric Comparison Reply expected now, see PairingMode::NUMERIC_COMPAR...
static bool USE_WHITELIST
Transient read only octet data, i.e.
static HCIStatusCode readAndApply(const std::string &path, BTDevice &device, const BTSecurityLevel minSecLevel, const bool verbose_)
Create a new SMPKeyBin instance on the fly based upon stored file denoted by path and BTDevice::getAd...
std::string to_string(const BDAddressType type) noexcept
void addChangedAdapterSetCallback(const ChangedAdapterSetCallback &l)
ChangedAdapterSetCallback handling.
BTAdapter represents one Bluetooth Controller.
constexpr const SMPIOCapability & getSecurityAutoIOCap() const noexcept
@ KEYBOARD_ONLY
Keyboard input only, value 2.
@ DUAL
Dual Bluetooth mode, i.e.
uint64_t getCurrentMilliseconds() noexcept
Returns current monotonic time in milliseconds.
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
BTManager & getManager() const noexcept
Returns a reference to the used singleton BTManager instance, used to create this adapter.
std::string to_hexstring(value_type const &v) noexcept
Produce a lower-case hexadecimal string representation of the given pointer.
static void connectDiscoveredDevice(std::shared_ptr< BTDevice > device)
BTSecurityLevel sec_level
std::string toString() const noexcept override
bool isWaitingForAnyDevice() noexcept
jau::darray< std::shared_ptr< BTGattService > > getGattServices() noexcept
Returns a list of shared GATTService available on this device if successful, otherwise returns an emp...
bool isConnected() const noexcept
static bool initAdapter(std::shared_ptr< BTAdapter > &adapter)
@ NONE
No pairing in process.
void indicationReceived(BTGattCharRef charDecl, const TROOctets &char_value, const uint64_t timestamp, const bool confirmationSent) override
Called from native BLE stack, initiated by a received indication associated with the given BTGattChar...
@ FEATURE_EXCHANGE_STARTED
Phase 1: Pairing requested by initiating (master) device via SMPPairingMsg.
static void processReadyDevice(std::shared_ptr< BTDevice > device)
size_t getProcessedDeviceCount() noexcept
static bool remove(const std::string &path, const BDAddressAndType &addrAndType_)
bool addStatusListener(std::shared_ptr< AdapterStatusListener > l)
Add the given AdapterStatusListener to the list if not already present, intended to listen only for e...
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.
static constexpr int NO_PASSKEY
static bool myChangedAdapterSetFunc(const bool added, std::shared_ptr< BTAdapter > &adapter)
std::shared_ptr< BTGattHandler > getGattHandler() noexcept
Returns the connected GATTHandler or nullptr, see connectGATT(), getGattService() and disconnect().
static std::atomic< int > deviceReadyCount
std::unique_ptr< const uuid_t > value_type
static bool createAndWrite(const BTDevice &device, const std::string &path, const bool overwrite, const bool verbose_)
Create a new SMPKeyBin instance on the fly based upon given BTDevice's BTSecurityLevel,...
static bool startDiscovery(BTAdapter *a, std::string msg)
std::string toString() const
bool writeValueNoResp(const TROOctets &value)
BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.1 Write Characteristic Value Without Response.
jau::darray< BTGattDescRef > descriptorList
List of Characteristic Descriptions as shared reference.
std::string const getName() const noexcept
std::shared_ptr< BTDevice > deviceFound
This C++ direct_bt scanner example is a TinyB backward compatible and not fully event driven.
static const uint8_t filter_policy
bool isDeviceProcessed(const BDAddressAndType &a) noexcept
size_t getWaitForDevicesCount() noexcept
Persistent octet data, i.e.
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.
HCIStatusCode unpair() noexcept
Unpairs this device from the adapter while staying connected.
SMPPairingState
SMP Pairing Process state definition.
constexpr const BTSecurityLevel & getSecLevel() const noexcept
static bool KEEP_CONNECTED
static constexpr int number(const Defaults d)
constexpr bool isAdapterSettingBitSet(const AdapterSetting mask, const AdapterSetting bit) noexcept
static void resetAdapter(BTAdapter *a, int mode)
LE_PHYs
LE Transport PHY bit values.
@ BDADDR_LE_PUBLIC
Bluetooth LE public address.
Unique Bluetooth EUI48 address and BDAddressType tuple.
BTAdapter & getAdapter() const
Returns the managing adapter.
BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3 Characteristic Descriptor.
BTMode
Bluetooth adapter operating mode.
std::string toString() const noexcept
@ COMPLETED
Phase 3: Key & value distribution completed by responding (slave) device sending SMPIdentInfoMsg (#1)...
BTGattChar event listener for notification and indication events.
MyGATTEventListener(int i_, int j_)
constexpr bool isSecurityAutoEnabled() const noexcept
static std::string charIdentifier