summaryrefslogtreecommitdiffstats
path: root/api/direct_bt/HCIHandler.hpp
Commit message (Collapse)AuthorAgeFilesLines
* Adopt to jau::function<R(A...)> from jau::FunctionDef<>Sven Gothel2022-09-161-2/+2
|
* HCIHandler::resetAdapter(): Add optional HCIHandler::PostShutdownFunc ↵Sven Gothel2022-09-151-9/+30
| | | | | | | argument, allowing BTAdapter::reset() to wait until all devices are disconnected before powering-up again Waiting for all disconnections within reset after shutdown phase determines the state of all devices before powering up.
* FreeBSD Support: Add patches. Build complete on GNU/Linux and FreeBSD. ↵Sven Gothel2022-07-261-0/+1
| | | | Missing: FreeBSD kernel BT functionality (currently just aborts)
* C++: Shorten is*Set() -> is_set() and set*() -> set() for bit-type enums; ↵Sven Gothel2022-06-161-1/+1
| | | | Fix is_set() bit-type enum: '0 != ( mask & bit )' -> 'bit == ( mask & bit )'
* Adding C++ module/groups to separate the C++ API levels for the user; Adding ↵v2.7.1Sven Gothel2022-05-221-0/+15
| | | | reference to perihperal-server mode to overview.
* Bump jaulib v0.9.1 and adopt to fraction changes, use wait_until() w/ ↵Sven Gothel2022-05-011-5/+5
| | | | out-of-loop absolute timeout_time, avoiding deadlocks
* BTDevice::connectLE(): Fix default conn_interval_min 15ms -> 10ms, matching ↵v2.6.5Sven Gothel2022-04-191-2/+2
| | | | Connection_Parameter.md and unit tests (v2.6.5)
* [L2CAP, HCI]Comm: Hold external interrupted delegate from service_runner for ↵Sven Gothel2022-04-181-1/+1
| | | | | | | | | | | | | | | | complete interrupted() query; At tear down, first stop service_runner, then close the comm instance; Minor method renaming. Covering [L2CAP, HCI]Comm and service_runner usage in BTManager, HCIHandler, GattHandler and BTAdapter. - Hold external interrupted delegate from service_runner for complete interrupted() query - This ensures service_runner stop will work on blocking comm calls like read and accept - At tear down, first stop service_runner, then close the comm instance; Minor method renaming. - Naturally, first stop the background thread using the comm instance (read, accept), then close the comm instance. Lack of proper delegation of interrupted was found by analyzing BTAdapter's l2cap_att_srv L2CAPServer socket, which gets start- and stopped w/o closing in between operations and didn't close the instance at close. This patch completes the introduction of service_runner, using its interrupted signal (shall_stop) for the comm instances.
* SMPHandler: Also use service_runner; Remove HCIHandler::pidSelfSven Gothel2022-04-151-2/+0
|
* Fix and document default connection paramter, leaning to higher performance ↵Sven Gothel2022-04-141-3/+3
| | | | side - add documentation file
* BTAdapter/HCIHandler: Reflect: Advertising is active until either disabled ↵Sven Gothel2022-02-061-1/+13
| | | | | | | | | | | via stopAdvertising() or _a_connection_ has been made. This fix set's HCIHandler's 'advertisingEnabled' flags to 'false' after a 'connection complete' event had occured. Further, HCIHandler::le_enable_adv(..) overrides a potential erroneous HCI failure when: - disabling advertising when already disabled, or - enabling advertising when already enabled as stated in spec 'BT Core Spec v5.2: Vol 4 HCI, Part E HCI Functional: 7.8.9 LE Set Advertising Enable command'
* BTAdapter/HCIHandler: API doc: Replace HTML tag with Markup listSven Gothel2022-02-061-15/+12
|
* BTAdapter::startAdvertising(): Set default adv_interval from 1.28s -> 400ms ↵Sven Gothel2022-02-021-3/+3
| | | | avoiding long delays (detection + connect), use in peripheral00 example;
* HCIHandler: Use jau::service_runnerSven Gothel2022-01-121-7/+4
|
* BTAdapter: Add startAdvertising(..) overload with user given EInfoReport and ↵Sven Gothel2022-01-041-5/+5
| | | | | | | | | EIRDataType[Set] AD masks .. .. allowing user to detail actual EIR AD (extended information advertising) instead of using the default. This is required to programmatically setup specific advertising information of the created server.
* Reader-Running-State Robustness: Have the atomic boolean be of ↵Sven Gothel2021-11-171-1/+1
| | | | | | | | memory_order_seq_cst (jau::sc_atomic_bool) Commit c8c633b821cb12a5ffe38d07a9d7e622b020b415 removed the lock before notify_all. Ensure sequential consistency (SC) using the proper memory_order.
* HCIHandler/BTAdapter::startDiscovery(): le_scan_active default false -> ↵Sven Gothel2021-11-041-2/+2
| | | | true, we like EIR w/ device name
* Adapt to jau::ringbuffer API changeSven Gothel2021-10-311-1/+1
|
* Add 3 HCI Commands + 1 HCI MetaEvent to support SMP SC on slave peripheral ↵Sven Gothel2021-10-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | site, incl. mapping to Mgmt event object Situation: Linux Kernel 5.10.0-9-amd64, Debian 12 dbt_scanner10: Master, initiatior (DUAL) dbt_peripheral00: Slave, peripheral (LE only) LE Secure Connections enabled per default. Issue: LTK via Mgmt event in ~50% of cases not send! However, full information already passed via HCI commands/events. Workaround: Listen to HCI commands as well and allow related commands + events to complement SC status tracking. +++ New HCI commands + events, incl. their Mgmt event mapping: - HCIOpcode::LE_ENABLE_ENC -> HCILEEnableEncryptionCmd - Mgmt HCI_LE_ENABLE_ENC -> MgmtEvtHCILEEnableEncryptionCmd - HCIOpcode::LE_LTK_REPLY_ACK -> HCILELTKReplyAckCmd - Mgmt HCI_LE_LTK_REPLY_ACK -> MgmtEvtHCILELTKReplyAckCmd - HCIOpcode::LE_LTK_REPLY_REJ -> HCILELTKReplyRejCmd - Mgmt HCI_LE_LTK_REPLY_REJ -> MgmtEvtHCILELTKReplyRejCmd - HCIMetaEventType::LE_LTK_REQUEST -> HCILELTKReqEvent - Mgmt: Opcode::HCI_LE_LTK_REQUEST -> MgmtEvtHCILELTKReq - HCICommand::getSpecialized(..)
* Fix hci_cp_le_set_ext_adv_data and hci_cp_le_set_ext_scan_rsp_data: Use ↵Sven Gothel2021-10-071-2/+11
| | | | | | | | HCI_MAX_EXT_AD_LENGTH 251 (not HCI_MAX_AD_LENGTH 31) Advertising_Data_Length: - Bluetooth 4.0: 0 - 31 octets - Bluetooth 5.0: 0 - 251 octets, i.e. max-param 255 - 4 bytes cp-args
* BTAdapter/Device: Simplify set[DefaultConnected]LE_PHY(..): Remove bool args ↵Sven Gothel2021-10-051-11/+5
| | | | to simply reuse LE_PHYs bitmap zero to ignore either
* HCIHandler/BTAdapter/BTDevice: Add le_set[_default]_phy(..) / ↵Sven Gothel2021-09-241-0/+39
| | | | | | | | | | | | | | set[Connected|Default]LE_PHY(..) Note that the HCIHandler methods validate if LE_Features if host do support LE_2M. le_set*_phy(): Missing LE_2M support causes command to fail early w/o issuing it. le_read_phy(): Missing LE_2M support causes command to return LE_1M here. +++ Also remove 'TODO' re scanning PHY, since we shall simply stick with LE_1M band for compatibility. Connection itself may use the fast LE_2M or long range LE_CODED band.
* HCIHandler::le_read_phy(..)/BTDevice::getConnectedLE_PHY(..): Use orig HCI ↵Sven Gothel2021-09-241-3/+4
| | | | | | arg order: Tx first, then Rx. This is to unify followup setting methods.
* Added HCIHandler::check_open_connection(..): Reuse same state and param ↵Sven Gothel2021-09-241-0/+18
| | | | checking, reduce code
* HCIHandler/BTDevice: Enhance API doc on conn_latency and ↵Sven Gothel2021-09-231-2/+2
| | | | supervision_timeout; Add getHCIMaxConnLatency(..)
* Moved EUI48, EUI48Sub (C++/Java) and uuid_t, *Octets (C++) to jaulib for ↵Sven Gothel2021-09-181-2/+2
| | | | | | | | | general use. Notable, the java classes EUI48, EUI48Sub and BasicTypes are included in direct_bt's jar file to avoid any inconvenience. Hence BTUtils's byte[s]HexString(..) simply uses jaulib's BasicTypes s' implementation.
* Add HCIHandler::le_read_remote_features(..)Sven Gothel2021-09-161-2/+30
|
* BTAdapter/HCIHandler Refine advertising/discovery state validationSven Gothel2021-09-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | HCIHandler advertising: Allow start/enable/disable even if already advertising BTAdapter/HCIHandler start- or enable advertising: Fail start/enable if having open/pending connections or discovery is active, BTAdapter/HCIHandler disabling advertising always allowed. BTAdapter/HCIHandler start- or enable discovery: Fail start/enable if advertising is active. BTAdapter/HCIHandler disabling discovery always allowed. +++ BTAdapter::poweredOff(bool active) now used to align passive (active = false) state reset for methods if !isPowered(). +++ Rename C++ BTAdapter::[getDiscovering() -> isDiscovering()] Add Java BTAdapter::isDiscovering() (Aligned with isAdvertising())
* Add advertising support (start with set-data and -params, stop) via HCIHandlerSven Gothel2021-09-151-2/+129
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reasonable default values have been chosen from the BT spec, which can be overriden using the HCIHandler and BTAdapter operations. The extended advertising operations are also supported (Bluetooth 5.0). +++ Successfully tested running: (0) Test machine with 2 adapter - adapter-1 DC:FB:48:00:90:19 (acting as client) - adapter-2 00:1A:7D:DA:71:08 (acting as peripheral) (1) Running dbt_peripheral00.cpp or DBTPeripheral.java as the advertising peripheral on the test machine. `direct_bt/dist-amd64$ ../scripts/run-dbt_peripheral00.sh -adapter 00:1A:7D:DA:71:08` or `direct_bt/dist-amd64$ ../scripts/run-java-peripheral00.sh -adapter 00:1A:7D:DA:71:08` (2) Running dbt_scanner10.cpp or DBTScanner10.java as the listeninig and connection-initiator client on the same test machine. `direct_bt/dist-amd64$ sh ../scripts/run-dbt_scanner10.sh -adapter DC:FB:48:00:90:19 -dev 00:1A:7D:DA:71:08 -seclevel 00:1A:7D:DA:71:08 1` or `direct_bt/dist-amd64$ sh ../scripts/run-java-scanner10.sh -adapter DC:FB:48:00:90:19 -dev 00:1A:7D:DA:71:08 -seclevel 00:1A:7D:DA:71:08 1`
* Multi Direct-BT application, each using 1 adapter: Have user explicitly ↵Sven Gothel2021-09-151-12/+35
| | | | | | | | | | | | | | | | | | | | | | initialize adapter with given BTMode, leave others untouched. Only mutating the desired adapter within one application allows running multiple Direct-BT applications on one platform, each using one selected adapter. BTMode: - Use byte value, matching native counterpart BTManager: - Remove (default) BTMode BTAdapter: - Add initialze(const BTMode btMode=BTMode::DUAL), must be called by user for desired adapter when found via ChangedAdapterSetFunc/BTManager.ChangedAdapterSetListener. AdapterInfo: - Expose mutable ops to public, remove friend decl.
* Add support for Bluetooth 5.0 Adapter (using HCI extended scanning and ↵Sven Gothel2021-08-301-54/+85
| | | | | | | | | connecting if supported) On Bluetooth 5.0 Adapter where HCI extended scanning and connecting is suppored, the original HCI commands may fail via DISALLOWED. Tested adapter: Intel AX200 Bluetooth 5.0 (Wi-Fi 6 802.11ax (2.4Gbps) + BT 5.0)
* Passthrough all paramter BTAdapter::startDiscovery(..) -> ↵Sven Gothel2021-07-281-5/+7
| | | | | | | | | | | | | HCIHandler::le_set_scan_param(..): Add le_scan_active and filter_policy; Java: Add all. Also changing order of parameter, allowing to use default values in a most reasonable sense. Motivation: Expose `le_scan_active` to retrieve the AD EIR package with event-type SCAN_RSP, which gets queried via active scanning only and usually holds the device name if supported. TODO: Resolve propagating device found on SCAN_RSP message (name), since SCAN_IND is received before (w/o name). The 2nd SCAN_RSP is dropped, even though the BTDevice's name has changed properly.
* Clarify EInfoReport ownership between MgmtEvtDeviceFound, HCIHandler and ↵Sven Gothel2021-07-271-0/+8
| | | | | | | | | | | | | | | BTAdapter; Add AD_EIR debug flag MgmtEvtDeviceFound changes: Stringent ownership - field eireport type `std::shared_ptr<EInfoReport>` -> `std::unique_ptr<EInfoReport>` - getEIR() returns immutable EInfoReport pointer BTAdapter::mgmtEvDeviceFoundHCI(): Cleanup confusion - Expect coming from HCIHandler (we only listen to it), ABORT otherwise - Cleanup confusion of ownership etc Debug: - HCIHandler env.DEBUG_SCAN_AD_EIR `direct_bt.debug.hci.scan_ad_eir`
* Bump to jaulin v0.3.3 and adapte to jau:ringbuffer changesSven Gothel2021-06-111-1/+1
|
* API String Conversion Simplification: get.*String() -> ↵Sven Gothel2021-02-101-1/+1
| | | | | | | | | | | | | | direct_bt::to_string() Patch [2/2] This goes along with jaulib's 'hex and decimal string conversion'. API schema for to string conversion: 1 - free function: to_string(type) 2 - main member function: toString() 3 - sub-type member function: getTypeString(Type) 3 avoid overload collision w/ potential virtual toString() method. Additional, 1 is provided for 3 as well
* HCIHandle: Expose const HCIEnv singleton instanceSven Gothel2021-02-011-1/+2
|
* Java: New API Layout: Shorten named [Bluetooth -> BT], [Characteristic -> ↵Sven Gothel2021-01-251-3/+3
| | | | Char] etc (align naming with direct_bt == java; reduce java code footprint and too long code lines)
* Replace std::vector w/ jau::darray and jau::cow_vector with jau::cow_darray ↵Sven Gothel2021-01-111-6/+6
| | | | | | | | | | | | | | | | | | | | | (performance and CoW correctness) Merging jaulib's darray and cow_darray into direct_bt. As explained in jaulib, motivation behing darray + cow_darray is to allow fine grained controll over the CoW's storage to have certain guarantess on its operation. Iterator and push_back() enhancments are a few of these. Fixes performed while replacing: - DBTDevice getGATTServices(): Take the copy as it will be returned. - GATTHandler removeAllAssociatedCharacteristicListener(): Try to delete all matching! Don't stop loop after found and erased first, continue. Also return number of erased elements, not just true. - DBTManager ctor: Don't work on CoW snapshot, work on CoW - Simplified many loops / iterations
* Replace jau::cow_vector with jau::cow_darray (simple type replacement, ↵Sven Gothel2021-01-061-1/+1
| | | | compatible API)
* smart_ptr-3: Handle HCIEvent + SMPPDUMsg instances via std::unique_ptr ↵Sven Gothel2020-12-141-11/+12
| | | | | | | | | | | | | | | | | | | | | | | | | instead of shared_ptr; Callbacks use 'const <T> &' now. smart_ptr change series, commit #2 This series started with commit cafd8d1f3689135eae36854a9cca4def690045fd, see for details. Refined MgmtMsg clone template and added same to HCIPacket and SMPPDUMsg. Notable: To have this clone template to work, the default copy-constructor should not be deleted. Hence removing the const qualifier from timestamp and manual default/deleted directives. +++ At this point, all high frequent objects (ATT, HCI w/ SMP, Mgmt events) use std::unique_ptr and therefor reduce a certain overhead. Further, this constraint also removes a potential 'build in' leaks, in case a callback method keeps the shared_ptr instance. Now, callbacks only received the const reference and if so desired, need to create a copy themselves.
* Adopt new BDAddressAndType key value across projectSven Gothel2020-12-121-23/+42
| | | | See commit bc9d1c0d2942ce24019b432198f2d4c0d00aee19
* HCIHandler: Expose clear[ConnectionLists -> AllStates](), allowing to flush ↵Sven Gothel2020-11-161-2/+6
| | | | states if required (powered-on)
* Wire HCIACLData::l2cap_frame/SMPPDUMsg from HCIHandler -> DBTAdapter -> ↵Sven Gothel2020-11-141-1/+1
| | | | | | | | | | | | | | | | | | | | DBTDevice incl deduction of SMPPairingState and PairingMode - Added: AdapterStatusListener::devicePairingState(...): Notifying user about a changed PairingState - HCIHandler's HCISMPMsgCallback: Pass HCIACLData::l2cap_frame, allowing final receiver (DBTDevice) to learn about initiator/responder role. - DBTAdapter -- Added Mgmt SMP related callbacks -- Added SMPMsgCallback from HCIHandler, to be forwarded to DBTDevice for actual SMPPairingState handling, tracking state and SMPPDUMsg details. - DBTDevice -- Add API to set/get pairing passkey and numeric comparison -- Expose current SMPPairingState -- DBTDevice hciSMPMsgCallback(..): Track underlying PairingState details, received from HCIHandler -> DBTAdapter -> this, and deduce PairingMode via getPairingMode(..) using both devices AuthReqs, IOCaps and OOBFlag.
* Generalize SMPMsg: HCISMPSecurityReqCallbackList -> HCISMPMsgCallbackList ↵Sven Gothel2020-11-111-5/+5
| | | | (access all) and forward to matching DBTDevice
* HCITypes.hpp: Add HCIACLData incl l2cap_frame providing potential SMPPDUMsg ↵Sven Gothel2020-11-111-2/+12
| | | | | | | | | | | | | (SMP) incl. facility in HCIHandler (read and callbacks) As noted in commit 6f3e08562f4f990b579ff2540d25dac06beea15a, we can't connect directly to the L2CAP/SMP channel. However, it is possible to access the SMP messages through the HCI layer, grabing the ACL Data's L2CAP packets. The latter may expose an SMP (via CID). This finally allows us to put our SMPPDUMsg to use and hence provide a HCISMPSecurityReqCallback facility in HCIHandler.
* HCIHandler.hpp: Move HCIConnection -> HCIHandler::HCIConnection (private, ↵Sven Gothel2020-11-111-37/+37
| | | | exclude from public access)
* BluetoothDevice::connectLE(..): Renamed from connect(..) for clarity, update ↵Sven Gothel2020-11-081-5/+5
| | | | default values and use default if any param < 0
* GATTHandler, HCIComm and HCIHandler: Delete copy-ctor and copy-assignmentSven Gothel2020-11-081-3/+3
|
* DBTManager, HCIHandler, GATTHandler: Add reader thread cleanup, setting ↵Sven Gothel2020-10-271-3/+3
| | | | | | | | | | | | | <bla>Running flag (now atomic) to false @ thread exit We have experienced a rare deadlock in GATTHandler::disconnect() waiting for l2capReaderRunning=false, as the l2capReaderThread ended abnormal. The abormal thread exit prohibited the well formulated exit-handshake via mtx_l2capReaderLifecycle and l2capReaderRunning kept true. This 'thread_local jau::call_on_release thread_cleanup' instance takes care of these situation, having our custom cleanup lambda called at its destruction, i.e. thread-local-dtor (thread exit).
* HCIHandler:: *create_conn(): Synchronize command for SC 'pending tracker ↵Sven Gothel2020-10-271-0/+4
| | | | | | | connections' state This refines commit ce8ca819176265ba4210240fbecf3df86e5e29fd avoiding a theoretical data race on parallel entries into *create_connect().