summaryrefslogtreecommitdiffstats
path: root/api/direct_bt/DBTManager.hpp
Commit message (Collapse)AuthorAgeFilesLines
* Converging Java/JNI and C++ API to match tinyb interface requirements (step-2)Sven Gothel2020-05-101-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - BasicTypes: Align exception names w/ Java. - BTTypes / EInfoReport: Add getDeviceIDModalias() - DBTManager: Add getConnectionInfo(..) and setLocalName(..) - OctetTypes: Fix put_octets(..), removed sizeof(). Adding put/get string methods +++ DBTTypes: - Fix Comments - DBTDevice: Add appearance, getConnectionInfo(), connectGATT(..) and disconnectGATT(). Last two GATT's ease association of GATTHandler w/ device for tinyb binding. - DBTDevice: Fix defaultConnect(): Differenciate le public/random - DBTDevice: New getConnectionInfo() - also may issue deviceUpdate callback on rssi/tx_power changes - DBTAdapter: Add missing DBTAdapterStatusListener list declaration of previous commit. - DBTAdapter: Add misc information access for tinyb binding. +++ Java - DBTAdapter: Adding more tinyb implementation code, sorting methods - ~90% complete - DBTDevice: Adding more tinyb implementation code, sorting methods - ~70% complete
* Extend BluetoothDeviceStatusListener -> BluetoothAdapterStatusListener; Enum ↵Sven Gothel2020-05-041-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | bit field mask: Add AdapterSettings , fix EIRDataType -> EIRDataTypeSet Extend Java BluetoothDeviceStatusListener -> BluetoothAdapterStatusListener and C++ DBTDeviceStatusListener -> DBTAdapterStatusListener - BluetoothAdapterStatusListener shall be (ab)used for anything adapter event related, user may utilize it (optional) - Added callback method adapterSettingsChanged(..) in DBTAdapterStatusListener - An internal listener further produces more detailed callbacks, used on the Java side. +++ Java enum bit field mask: Add AdapterSettings , fix EIRDataType -> EIRDataTypeSet - In Java, we cannot have an indivudual enum instance (like in C++) ;-) - Hence 'enum EIRDataType' -> EIRDataTypeSet.DataType and having the 'bit mask' implemented in EIRDataTypeSet. - Adding similar AdapterSettings bit field, utilized in DBTAdapter's internal BluetoothAdapterStatusListener to produce fine grained callbacks.
* MgmtAdapterEventCallback: Pass MgmtEventCallback by reference, avoiding one copySven Gothel2020-05-031-1/+1
|
* ClassFunction -> FunctionDef generalization, adding plain function ↵Sven Gothel2020-05-031-2/+2
| | | | | | | | | | | (non-class-member) support To support on-the-fly lambda non-member functions for callbacks, we need to bind to same non-member plain functions. Hence rename ClassFunction -> FunctionDef and add PlainInvocationFunc for this purpose. Tested via C++ unit test test_basictypes01.cpp
* DBTManager::close(): Clear adapterInfos (avoiding re-entry failure); Java ↵Sven Gothel2020-05-031-1/+2
| | | | | | | | deleteImpl(): Calls close(). DBTManager::close(): Clear adapterInfos (avoiding re-entry failure), make it functional. Java deleteImpl(): Calls close(), avoiding same on JVM shutdown.
* MgmtEventCallbackList -> MgmtAdapterEventCallbackList: Adding adapter dev_id ↵Sven Gothel2020-05-031-7/+50
| | | | | | | | | | | | | | | for MgmtEvent adapter filtering Registering a MgmtEventCallback for a specified adapter shall only deliver events circulating for same adapter. Intermediate MgmtAdapterEventCallback struct associated the adapter dev_id to the MgmtEventCallback, used to build the MgmtAdapterEventCallbackList. addMgmtEventCallback(..) passes the desired adapter dev_id, -1 to listen to all adapter events. Implementation only adds the callback if not yet present, i.e. key = dev_id + opcode + callback. New 'removeMgmtEventCallback(const int dev_id)' allows removal of all callbacks registered for specified dev_id, which helps reducing user code when deregistering.
* DBTManager Java: Add getAdapterListImpl()Sven Gothel2020-05-021-0/+8
| | | | | getAdapterListImpl() JNI code utilizes new convert_vector_to_jobject(..) with given ctor function defined ad-hoc via lambda.
* GATTHandler/DBTManager Timeout/Error: Limit ringbuffer.getBlocking(..) with ↵Sven Gothel2020-05-021-1/+1
| | | | | | | | | | | | timeout Further restructure GATTHandler's send/receiveNext in one call 'sendWithReply(..)', similar to DBTManager. From here on we are able to detect loss of connected device via read timeout and send error - within timeout period (default 3s). The breakup closes resources properly (instead of exception) and a new gatt connection can be established thereafter.
* GATTHandler/DBTManager Timeout/Error: Use 3s timeout; GATTHandler/l2cap use ↵Sven Gothel2020-05-021-2/+2
| | | | timeoutMS field
* GATTHandler/DBTManager Timeout/Error: Unique SIGINT handler; GATTHandler ↵Sven Gothel2020-05-021-0/+2
| | | | | | | | | | | disconnect on l2cap- or send error Unique SIGINT handler in DBTManager GATTHandler needs to disconnect l2cap connection to reach clean state if we have an invalid l2cap state (already closed) or a send error occured. TODO: Ringbuffer timout handling.
* DBTManager::disconnect(..): send explicit MgmtEvtDeviceDisconnected to listenerSven Gothel2020-05-021-1/+2
| | | | | It has been recognized that our disconnect command will not result in a MgmtEvtDeviceDisconnected received from the BlueZ Kernel. Hence sending it out ourselves to listening clients.
* DBTManager: Only require a mtx_callbackLists for mgmtEventCallbackListsSven Gothel2020-04-281-1/+1
|
* AdapterInfo: Validate index == dev_id @ array creation in ctor, drop at usageSven Gothel2020-04-281-12/+0
|
* Wire AdapterInfo w/ MgmtEvtNewSettings and MgmtEvtLocalNameChanged; ↵Sven Gothel2020-04-271-7/+36
| | | | | | | | | | | AdapterInfo's settings of type MgmtSetting (align semantics and parse) AdapterInfo will be updated via MgmtEvtLocalNameChanged and MgmtEvtNewSettings, hence respective fields are mutable. AdapterInfo's settings are now of type MgmtSetting (align semantics and parse). DBTManager's use of AdapterInfo shared_ptr is mutable now, removed 'const'.
* MgmtEvent: Add MgmtSetting type; MgmtEvtNewSettings, ↵Sven Gothel2020-04-271-15/+2
| | | | MgmtEvtNewConnectionParam, MgmtEvtLocalNameChanged
* DBTManager: Fix multiple adapters: Align kernel dev_id with our adapters ↵Sven Gothel2020-04-271-1/+1
| | | | | | | | | | | | | | indices. Testing w/ two BT adapters showed a reverse order READ_INFO result. Here we enforce using dev_id as index for our AdapterInfo vector and testing bounds. Out new scanning using the manager channel also results in working w/ more adapter, i.e. the adapter 'BLUE LogiLink V4.0 USB Dongle worked: Adapter[00:1A:7D:DA:71:08, 'CSR8510 A10', ..]. However, another USB motherboard dongle didn't work and even interfered, so I had to 'rfkill block' it. The non-working wasn't able to discover LE devices.
* MgmtTypes: Add PinCode command and events; Clarify DEVICE_ADDED/REMOVED -> ↵Sven Gothel2020-04-261-4/+6
| | | | | | | | | | | | DEVICE_WHITELIST_* MgmtTypes add: MgmtPinCodeReplyCmd, MgmtPinCodeNegativeReplyCmd, MgmtEvtPinCodeRequest, DBTManager add MgmtEvtPinCodeRequest callback, remove warnings. Clarify DEVICE_ADDED/REMOVED -> DEVICE_WHITELIST_* MgmtEvtDeviceWhitelistAdded, MgmtEvtDeviceWhitelistRemoved
* DBTManager / DBTDeviceStatusListener: Refine events; java: Keep alive ↵Sven Gothel2020-04-261-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | discovery; Remove discovery thread (1) DBTAdapter: Keep alive discovery DBTDeviceStatusListener (incl Java binding: - DBTDeviceDiscoveryListener -> DBTDeviceStatusListener to cover more functionality - Rename deviceAdded -> deviceFound, to match BlueZ event naming - Rename deviceRemoved -> deviceDisconnected - Add deviceConnected HCIComm/DBTAdapter: Use HCIAddressType where applicable for clarity MgmtEvent: Add timestamp MgmtEvent: Add MgmtEvtDeviceConnectFailed, MgmtEvtDeviceAdded, MgmtEvtDeviceRemoved, MgmtEvtDeviceUnpaired +++ DBTAdapter.java remove discovery thread (part 1) - Use events, no more discovery polling required - TODO: Same for native DBTAdapter.cpp!
* Use Kernel BlueZ Manager for Discovery, Connect, etc. (Initial Commit - Java ↵Sven Gothel2020-04-251-17/+98
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | part probably broken) We have experienced the following using the official HCI communication channel: - Lower connect performance with discovery enabled - Instability with enabled discovery and breaking general BT adapter state requiring a 'hciconfig hci0 reset' - Lack of notifications: start/stop discovery/connect/... - Lack of certain settings in general: pin, .. This commit implements discovery including listening to all BlueZ kernel events from the BlueZ Manager channel using DBTManager. TODO: Figure out how to enforce quick connect! - EInfoReport (EIR) added: FLAGS, DEVICE_CLASS, APPEARANCE, HASH, RANDOMIZER and DEVICE_ID - including parsing new segments in read_data(..) and dataSetToString(..) exposure - DBTManager adds: - manager-reader thread, putting all command status/completes to its ringbuffer and sending out all other events to its listener. - Respecting the chosen BTMode (side-effect to discovery etc) - add: start/stop discovery - add: connect/disconnect (incomplete) - DBTAdapter: - discoverDevices -> discoverDevicesMgmt is becoming redundant, now simply waiting for the DeviceFound event. Will be deleted - TODO! - mgmtEvDeviceFoundCB shall perform remaining EIR parsing and enqueing the devices plus issuing respective discovery callbacks! TODO. - DBTDevice adds: - BDAddressType - HCISession's HCIComm is now no more used (to be deleted!) - HCIComm adds generic read/write methods, mutex free. - Remaining HCI 'managment' methods are also subject to deletion! - GATTHandler / DBTManager: only use a mtx_write for communication, as reading is performed on their respective threads using a ringbuffer. Here only concurrent write access needs to be managed. (DBTManager uses its own HCIComm's mutex.) - MgmtTypes adds: - BTMode for dual, BREDR or LE only. - MgmtRequest -> MgmtCommand - Unifies the command opcodes to global 'MgmtOpcode', removing duplicate MgmtCommand::Opcode (which was also incomplete) - Adding MgmtDisconnectCmd, MgmtEvtDiscovering, MgmtEvtDeviceFound MgmtEvtDeviceConnected, MgmtEvtDeviceDisconnected - TOctets adding get_int8(..) and get_eui48(..) - TOctets adding put_eui48(..) ++++++++++++++ New ClassFunction: Introducing versatile C++ function-method type used for our DBTManager callbacks. In contrast to std::function and std::bind, ClassFunction allows using its specific type (return- and argument types) and offering the equality operation to test its identity. The latter is essential to remove a callback ClassFunction from a list of callbacks. +++++++++++++++++ Further code cleanup is also included - Address_T -> BDAddressType(incl string presentation) + HCIAddressType - ManufactureSpecificData using POctets - Convenient default param: uint*HexString(.., const bool leading0X=true); - MgmtTypes's get/put for events and commands use MGMT_HEADER_SIZE offset - MgmtTypes: Remove doubled 'btohs', as the pdu.get* commands already perform endian conversion. - EInfoReport::read_data(..) validate segment size before type conversion
* HCIComm thread safety, resolve deadlock; Renaming: MgmtHandler -> ↵Sven Gothel2020-04-201-0/+117
DBTManager, revert DBTSession -> HCISession HCIComm thread safety With the java DBTAdapter, we have introduces multithreading access to the HCIComm instance: start/stop etc + discovery-thread. We have experienced a deadlock issuing stopDiscovery() while the discovery-thread is in progress. HCIComm and its dd is now locked using a recursive mutex, which is also being exposed to HCISession allowing DBTAdapter's discovery to use it as well. +++ Renaming: MgmtHandler -> DBTManager, revert DBTSession -> HCISession HCISession is not a major DBT (direct-bt) (java) instance and actually describing the HCI(Comm) session. DBTManager is a major DBT java instance, mapped. Hence also splitting MgmtComm.* -> MgmtTypes.* + DBTManager.*