summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* Add ChangedAdapterSetCallback (C++), ChangedAdapterSetListener (Java) for ↵Sven Gothel2020-10-251-0/+39
| | | | [DBT|Bluetooth]Manager, enabling fully event driven workflow w/ adapter add/remove
* DBTAdapter/Manager: Use DBG_PRINT instead of PLAIN_PRINTSven Gothel2020-10-252-16/+16
|
* DBTAdapter::close(): Don't use mgmt reference if !validSven Gothel2020-10-251-1/+1
|
* Review & fix cow_vector 'fancy' write access: write_mutex, copy_store and ↵Sven Gothel2020-10-253-22/+22
| | | | set_store
* Support Adapter removal and add @ runtime: Handle INDEX_ADDED and ↵Sven Gothel2020-10-253-43/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | INDEX_REMOVED Mgmt events C++ DBTManager detects INDEX_ADDED and INDEX_REMOVED Mgmt events @INDEX_ADDED reception in the event reader, a new processAdapterAdded() thread is spawned initializing the adapter as usual and maintaining adding its AdapterInfo artifact. Then all user INDEX_ADDED callbacks are called from this thread, after the new AdapterInfo entry has been added. @INDEX_REMOVED here the matching AdapterInfo entry is simply removed DBTAdapter naturally also listens to INDEX_REMOVED, simply closing its instance and hence rendering it isValid() = false. +++ On close(), Java's DBTAdapter will remove itself from the DBTManager's adapter list. This removal will happen automatically, if INDEX_REMOVED is received - see below. On the Java side, DBTManager listens to: @INDEX_REMOVED here the matching adapter instance is simply removed @INDEX_ADDED and @NEW_SETTINGS(POWERED) checks whether the matching adapter instance exists and creates a new one added to the adapters list if necessary. @NEW_SETTINGS(POWERED) has been added here as well, since a user could chose to close the adapter if POWERED off and hence removing itself from the DBTManager adapter list. Hence NEW_SETTINGS(POWERED) will add a new adapter instance, if none exists. +++ Due to this new concurrent use-case of the adapter list, the list is now a CopyOnWriteArrayList instance supporting lock-free fast reads. Mutations of the list occur rarely, hopefully ;-). On the C++, the AdapterInfo is a jau::cow_vector and the callbacks are store in a jau::cow_vector as well (MgmtAdapterEventCallbackList). Hence both share the same properties w/ the Java side: Fast lock-free reads.
* Refine/add state queries in [DBT|Bluetooth]Adapter, BluetoothManagerSven Gothel2020-10-253-34/+37
| | | | | | | | | | | | | | | | [DBT|Bluetooth]Adapter: C++ and Java: Redefine/add state queries: - isValid(): true if this adapter references are valid and hasn't been DBTAdapter::close() 'ed - isPowered(): true if DBTAdapter::isValid(), HCIHandler::isOpen() and AdapterSetting::POWERED state is set - isSuspended(): true if DBTAdapter::isValid(), HCIHandler::isOpen() and AdapterSetting::POWERED state is not set - dev_id / getDevID(): Added definition, added method + implementation to Java BluetoothAdapter: Java - getPowered() -> getPoweredState() - to differentiate with isPowered() BluetoothManager: Java - getAdapter(dev_id) added - setDefaultAdapter(..) implementation removed in DBTManager -> nonsense - getDefaultAdapter(): DBT: Return 1st isPowered() adapter (redfinition, aligned with C++)
* MgmtEvent::Opcode::NEW_SETTINGS: Be fully functional w/o Adapter: DBTManager ↵Sven Gothel2020-10-252-11/+34
| | | | | | | shall update AdapterInfo state DBTAdapter hence requires to cache the old AdapterInfo state to realize the changed bits and for AdapterStatusListener forwarding.
* DBTAdapter::toString(): Add valid and open states; Reorder some methodsSven Gothel2020-10-241-56/+61
|
* DBTManager: Add adapter add/remove support: Use cow_vector for ↵Sven Gothel2020-10-242-42/+79
| | | | adapterInfo-list, further drop index language for dev_id
* DBTManager: Start dropping index (idx) for adapter id, use dev_id - drop ↵Sven Gothel2020-10-242-5/+5
| | | | index requirement
* DBTManager: Use native uint16_t type for valid dev_id (not increased value ↵Sven Gothel2020-10-241-28/+28
| | | | range int, including -1)
* DBTAdapter/Manager: Callback DBG/PRINT: Use common source prefix 'mgmt' or 'hci'Sven Gothel2020-10-242-31/+32
|
* DBTAdapter: Resolve uninitialized nextMetaScanType and refine with ↵Sven Gothel2020-10-231-2/+9
| | | | | | hasScanType(eventScanType, ScanType::LE) Note: '-Wmaybe-uninitialized' didn't trigger this when building in DEBUG mode using g++ 10
* AdapterStatusListener::discoveringChanged: Add meta ScanType and changed ↵Sven Gothel2020-10-231-16/+11
| | | | | | | | | | | | | | ScanType for the changedEnabled value; Expose meta ScanType. The additional information in the callback is essential in a LE + BREDR environment. User can also see the current meta ScanType. ScanType is exposed to Java. Java's BluetoothAdapter also adds 'ScanType getCurrentScanType()', exposing the last sent meta ScanType. DBTAdapter.java stores the meta ScanType instead of a boolean flag, hence we can react on LE only scanning for example. DBTAdapter can call all discovery callbacks for all ScanTypes now.
* Better arg names and order for 'ScanType changeScanType(const ScanType ↵Sven Gothel2020-10-232-4/+4
| | | | current, const ScanType changeType, const bool changeEnable)'
* More graceful takedown @ powered-off: Don't attempt futile HCI disconnect ↵Sven Gothel2020-10-232-5/+18
| | | | | | (DBTDevice) or stopDiscovery (DBTAdapter) commands Note: stopDiscovery and disconnected events will be sent!
* Sent discovery event directly (!off-thread) guaranteeing SC; Push ScanType ↵Sven Gothel2020-10-232-77/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | | | differentiating further. Discovery events will be sent directly instead off-thread. This is now possible w/o deadlock risk as we utilize the lock-free jau::cow_vector. Further, off-thread event sending can cause non sequentially consistence (SC) as the new threads potentially can be executed later on. This happened in some test cases where event-2 has been received before event-1. HCIHandler - add setCurrentScanType(), allowing outside events to update its state - sendMgmtEvent() directly, see above DBTAdapter - small renamings for clarity - more ScanType differentiating: LE, BREDR and DUAL using 'hasScanType(ScanType current, ScanType test)' - FIXME note on AdapterStatusListener::discoveringChanged(): Method shall include the enabled/disabled ScanType plus the current overall ScanType state. For now, we only report LE discovery state. -
* DBTAdapter: Use HCIHandler::getCurrentScanType(); start/stop_discovery: Set ↵Sven Gothel2020-10-221-36/+37
| | | | | | | | | | | | | currentMetaScanType post HCI completed command. DBTAdapter: - Drop local currentNativeScanType, use HCIHandler::getCurrentScanType() - start/stop_discovery: Set currentMetaScanType post HCI command, as it already waited for completed. - startDiscovery: Use own_mac_type, le_scan_interval and le_scan_window arguments (pass to HCIHandler command), was silently dropped.
* HCIHandler: *create_conn(..) mitigate any pending connection commands ↵Sven Gothel2020-10-221-154/+294
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | avoiding HCIStatusCode::COMMAND_DISALLOWED similar to mitigation of a pending disconnect causing HCIStatusCode::CONNECTION_ALREADY_EXISTS. Further ... Added le_start_scan, performing atomic le_set_scan_param and le_enable_scan. le_enable_scan skips command if currentScanType == nextScanType, i.e. avoiding a false failure HCIStatusCode::COMMAND_DISALLOWED on disable-scan when already disabled. le_start_scan and le_set_scan_param pre-check hasScanType(currentScanType, ScanType::LE), if LE is already enabled: warns and returns HCIStatusCode::COMMAND_DISALLOWED (spec). +++ HCIHandler: - mtx_connectionList is recursive_mutex again due to disconnect() - Add currentScanType tracking and exposure - Consolidate [process|receive]CommandComplete: [sendWith -> getNext]CmdCompleteReply - isOpen(): Add allowClose test and use isOpen() instead of comm.isOpen() - elaborate toString() content w/ currentScanType and ring elements - Add toString() to all [ERR|WARN|DBG]_PRINT Misc: - HCIEnv: Add HCI_COMMAND_POLL_PERIOD 125ms for LE_Create_Connection or Create_Connection.. - HCICommandCompleteEvent: Remove now unused getReturnStatus(..)
* Small footprint compromise: Use jau::nsize_t and jau::snsize_t where appropriateSven Gothel2020-10-2011-55/+55
| | | | | | | | | | | | | | | | | | Revises commit 1f6e924fe05ed45bfa4d0d901af2c4df6c1abab5 Use jau::nsize_t and jau::snsize_t where appropriate - OctetTypes.hpp: TROOctets* - ATTPDUTypes.hpp: AttPDUMsg* - HCITypes.hpp: HCIPacket* - HCIComm.hpp: HCIComm - L2CAPComm.hpp: L2CAPComm - MgmtTypes.hpp: MgmtCommand*, MgmtEvent* - UUID.hpp: uuid_t - DBTManager, GATTHandler, HCIHandler - HCIComm.hpp: HCIComm - BTTypes.hpp - DBTTypes.hpp
* adopt ringbuffer Size_type changes, using jau::nsize_tSven Gothel2020-10-203-7/+7
| | | | Revising commit 2e40a6fbb84ef21bb9551c653199964e55d7954b
* tinyb/BluetoothManager.cpp: One more -Wshadow detected on g++ 8.3Sven Gothel2020-10-201-2/+2
|
* Minor int -> uint16_t explicit castSven Gothel2020-10-201-2/+2
| | | | | | | Turns our there are too many to handle for now. Trust that i.e. dev_id value range does not exceed expected range, but even though - it would just end up in a failed call.
* Use -Wshadow: Shadowing (or local scope override) often causing sloppy bugs, ↵Sven Gothel2020-10-207-66/+66
| | | | avoid 2/2 (tinyb)
* Use -Wshadow: Shadowing (or local scope override) often causing sloppy bugs, ↵Sven Gothel2020-10-206-33/+32
| | | | | | avoid 1/2 (direct_bt) Another shadow bug fixed: UUID string ctor in UUID.cpp
* Normalize: Use size_t where appropriate; timestamp is uint64_tSven Gothel2020-10-2010-53/+55
| | | | | | | | | | | | | | | | | | | timestamp is uint64_t - AttPDUMsg Use size_t where appropriate - OctetTypes.hpp: TROOctets* - ATTPDUTypes.hpp: AttPDUMsg* - HCITypes.hpp: HCIPacket* - HCIComm.hpp: HCIComm - L2CAPComm.hpp: L2CAPComm - MgmtTypes.hpp: MgmtCommand*, MgmtEvent* - UUID.hpp: uuid_t - DBTManager, GATTHandler, HCIHandler - HCIComm.hpp: HCIComm - BTTypes.hpp - DBTTypes.hpp
* adopt to ringbuffer::getSize() -> size_t changesSven Gothel2020-10-203-3/+3
|
* HCIHandler: mtx_connectionList drop recursive for simple mutex; Drop ↵Sven Gothel2020-10-201-20/+20
| | | | | | | | | | | top-level command mtx (just use mtx_sendReply) Also use mtx_sendReply for close() and start-, stop- and resetAdapter(). Same strategy as for DBTManager. Have to analyze GATTHandler, which is special due to having top-level commands producing multiple send-reply communications.
* cmake: Drop all sub-folder CXX settings. Use root CMakeLists.txt global ↵Sven Gothel2020-10-202-4/+0
| | | | settings for all, avoiding confusion.
* DBTAdapter: ERR -> WARN: startDiscovery + startDiscoveryBackground on ↵Sven Gothel2020-10-191-2/+5
| | | | Adapter not enabled/powered
* DBTManager: Use read lock-free cow_vector for mgmtEventCallbackLists, ↵Sven Gothel2020-10-191-37/+19
| | | | avoiding locks in callback iteration
* HCIHandler: Use read lock-free cow_vector for mgmtEventCallbackLists, ↵Sven Gothel2020-10-191-33/+16
| | | | avoiding locks in callback iteration
* GATTHandler: Use read lock-free cow_vector for characteristicListenerList, ↵Sven Gothel2020-10-191-26/+34
| | | | | | avoiding locks in callback iteration Also use relaxed_atomic_bool for sendIndicationConfirmation.
* DBTDevice: Have shared GattGenericAccessSvc owned by GATTHandler, similar to ↵Sven Gothel2020-10-192-3/+10
| | | | services.
* DBTDevice::dtor: Don't recurse back into remove() -> adapter removeDevice(), ↵Sven Gothel2020-10-192-10/+15
| | | | | | | | that is how it potentially has been deleted! This fix also gives us the opportunity back to use a simple mutex for mtx_sharedDevices. Also add dedicated close() for better leak testing.
* DBTAdapter::removeStatusListener(const AdapterStatusListener * l): Use ↵Sven Gothel2020-10-181-2/+2
| | | | | | copy_store() on custom mutable operation Also std::move(snapshot) back to cow_vector, as set_store is now a move operation.
* DBTDevice/DBTAdapter: Move WORDY_PRINT to adapter::removeDevice(..)Sven Gothel2020-10-182-2/+2
|
* DBTAdapter fix regression: mtx_sharedDevices needs to be recursive due to ↵Sven Gothel2020-10-181-6/+6
| | | | device remove -> ~device -> remove from Java
* DBTAdapter: Have remaining recursive mutex -> simple mutex (sharedDevices, ↵Sven Gothel2020-10-181-9/+9
| | | | discovery): No recursion nor deadlock covering most small code blocks.
* DBTAdapter: Have statusListenerList lock-free using jau::cow_vectorSven Gothel2020-10-181-39/+28
|
* HCIHandler (UBSAN): Replace 'nasty' cast to 'HCIStructCmdCompleteMetaEvt<T> ↵Sven Gothel2020-10-171-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | *' with wrapper 'HCIStructCmdCompleteMetaEvtWrap<T>' ctor Assume T is any 'hci_cmd_event_struct' template type. We had [1] HCIStructCmdCompleteMetaEvt<T> * ev_cc = (HCIStructCmdCompleteMetaEvt<T> *) orig_ptr; now use simple (actual) wrapper (as was intended) [2] HCIStructCmdCompleteMetaEvtWrap<T> ev_cc(*orig_ptr); ++++ [1] is a potential violation of virtual function pointer table, as HCIStructCmdCompleteMetaEvt<T> might not have indentical heritage as the type 'orig_ptr' points to. The intention was to just access the orig_ptr data to deliver certain aspects in regards to any 'hci_cmd_event_struct' -> a wrapper. [2] Resolves the issue, using a temporary instance of the wrapper. This inconsistency was found with 'UndefinedBehaviorSanitizer' UBSAN, using GCC '-fsanitize=undefined' option.
* DBTAdapter::stopDiscovery(): Fix uninitialized 'HCIStatusCode status', ↵Sven Gothel2020-10-171-1/+1
| | | | | | erroneously overriden by local variable! Was detected with Full Warnings enabled!
* direct_bt::DBTManager, ieee11073::DataTypes: Fix WarningsSven Gothel2020-10-172-5/+12
|
* DBTManager's MgmtEnv ctor: Use root_prefix_domain "direct_bt"; DBTAdapter: ↵Sven Gothel2020-10-172-12/+12
| | | | Add missing 'jau::' namespace usage on bind* and *print*
* src/tinyb/Bluetooth*cpp: Compile clean w/ full WarningsSven Gothel2020-10-176-17/+37
|
* Extract common C++ Support Library inclusive Java JNI Binding to sub-project ↵Sven Gothel2020-10-1624-1040/+206
| | | | jaucpp, namespace jau
* HCIHandler::[le_]create_conn(): Wait for pending DISCONN_COMPLETE, which ↵Sven Gothel2020-10-152-29/+64
| | | | | | | | | | | | | | | | | caused sporadic CONNECTION_ALREADY_EXISTS connection failures Since direct_bt's DBTDevice::disconnect() does not wait for DISCONN_COMPLETE, so might a user application not wait. A 'too fast' [le_]create_conn attempt while DISCONN_COMPLETE has not been received yet from a pending disconnect call, leads to CONNECTION_ALREADY_EXISTS failure. This change tracks the pending disconnect commands and waits up to HCI_COMMAND_COMPLETE_REPLY_TIMEOUT (10s default) for receiving the DISCONN_COMPLETE. Resolved the sporadic issue testing with cpp and java scanner10, e.g.: "../scripts/run-dbt_scanner10.sh -disconnect -count 10 -quiet -mac C0:26:DA:01:DA:B1"
* DBTDevice::remove()/DBTAdapter::removeDevice(): Add some WORDY_PRINT(..)Sven Gothel2020-10-152-1/+4
|
* DBTDevice::disconnectGATT: Show caller in DBG_PRINTSven Gothel2020-10-151-5/+5
|
* HCIHandler::clearTrackerConnections(): Clear tracked connections on close(), ↵Sven Gothel2020-10-151-4/+21
| | | | reset() and stopAdapter() (resetAdapter()).