summaryrefslogtreecommitdiffstats
path: root/src/direct_bt/SMPHandler.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Adopt to jaulib ringbuffer changes v1.0.1-8-g854a714Sven Gothel2023-01-011-1/+5
|
* clang-tidy fixes part-1Sven Gothel2022-11-271-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Details - Use 'size_type' instead of 'int', propagate same 'size_type' into 'darray' etc. - Use 'std::make_shared', 'std::make_unique' - Use range-based for loops - Remove redundant 'virtual', use 'override' in derived classes - Use 'nullptr' - Use default impl for dtor, ctor (incomplete) - Use copy and std::move (incomplete) - Explcitly catch std::bad_alloc in 'new' in 'noexcept' -> 'abort' - 'abort' was issued implicitly in noexcept methods - L2CAPServer, L2CAPClient, NopGattServerHandler, DBGattServerHandler, FwdGattServerHandler - Use local close_impl(), usable in virtual destructor - L2CAPClient::read, HCIComm::read - preset 'poll' result 'n', avoid garbage comparison - BTAdapter::enableListening - loop through addMgmtEventCallback() result - JNI code - explicit size_type is cast to jsize or jint w/o check - unchanged semantics
* Adopt to jau::function<R(A...)> from jau::FunctionDef<>Sven Gothel2022-09-161-3/+3
|
* Bump jaulib v0.9.1 and adopt to fraction changes, use wait_until() w/ ↵Sven Gothel2022-05-011-3/+4
| | | | out-of-loop absolute timeout_time, avoiding deadlocks
* SMPHandler::ctor: Move DBG_PRINT post service_runner startSven Gothel2022-04-231-2/+3
|
* L2CAPClient::read(): Add READ_TIMEOUT and simplify branching on result in ↵Sven Gothel2022-04-231-6/+16
| | | | read() and caller; If INTERRUPTED -> service_runner.set_shall_stop() if not set (external irq)
* SMPHandler::send() failure: {IRQ->ERR}_PRINTSven Gothel2022-04-231-1/+1
|
* L2CAPComm read/write: Reuse already queried 'interrupted()' stored in ↵Sven Gothel2022-04-231-23/+26
| | | | err_res to be returned; Have caller also reuse this state.
* [SMP|BTGatt]Handler: 'IOError state' -> 'ioerr state'Sven Gothel2022-04-231-1/+1
|
* [HCI|L2CAP]Comm: Clarify external interrupted API: is_interrupted_t -> ↵Sven Gothel2022-04-221-1/+1
| | | | get_boolean_callback_t, set_interupt() -> set_interrupted_query()
* [L2CAP, HCI]Comm: Hold external interrupted delegate from service_runner for ↵Sven Gothel2022-04-181-12/+15
| | | | | | | | | | | | | | | | 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-107/+58
|
* L2CAPComm.hpp: L2CAP{ClientServer->Comm}, add adapter device id for clarity ↵Sven Gothel2022-04-101-1/+1
| | | | of adapter association
* L2CAPComm: Rename L2CAP{Comm->Client} and have L2CAP{Client,Server} derive ↵Sven Gothel2022-04-101-3/+3
| | | | | | from new common L2CAPClientServer This is a preparation to utilize common setBTSecurityLevelImpl(..) for L2CAPServer w/o code duplication.
* SMPHandler.hpp: #define -> 'inline constexpr' to allow proper compile time ↵Sven Gothel2022-04-101-5/+1
| | | | analysis; Also 'static constexpr const -> inline constexpr const' for global constants
* Inrcrease Reader-Callback Shutdown Robustness: Limited time (8s) and have ↵Sven Gothel2021-11-171-1/+7
| | | | | | | | | | | thread_local jau::call_on_release notify_all() In certain (system) shutdown cases, it might occure that we encounter an uncontrolled/undefined behavior. Limit time to wait for the reader thread to close to 8s (safe). Also have the thread_local jau::call_on_release notify_all(), which was missing.
* Unlock mutex before notify_all to avoid pessimistic re-block of notified ↵Sven Gothel2021-11-161-2/+4
| | | | | | | wait() thread Holding the same lock @ notify_all as the waiting thread, would lead to waking up the waiting thread, which only would be blocked again as it attempts to re-acquire the lock.
* Adapt to jau::ringbuffer API changeSven Gothel2021-10-311-3/+3
|
* Adopt to jaulib v0.4.9; Fixes BTSecurityRegistry::getStartOf(..)Sven Gothel2021-10-051-9/+10
|
* L2CAPComm::[read|write]: Explode 'errout:' branch: WORDY_ for (!is_open || ↵Sven Gothel2021-09-261-3/+3
| | | | | | | | | | | | | | | | | | | | | interrupt) else { DBG_ for ETIMEDOUT else IRQ_ } _PRINT The ETIMEDOUT == errno case might need more deliberation. For now we still expect the disconnect comming from the adapter or at least a different BlueZ/Kernel errno value like (lost or diconnected device) in case of a real connection loss. Therefor, we ignore timeout and continue processing on L2CAP::read() and the default timeout value of 10s shall have no impact. Caller of L2CAP::read(), i.e. BTGattHandler and SMPHandler follow this scheme. They further accept 0==len result as no error. L2CAP::write() implements the 'errout:', however, the caller will recognize a failure even with timeout. Hence the 10s default timeout is more than generous. Here too, we would expect the underlying BlueZ/Kernel to provide a meanigful connection loss reporting.
* L2CAPComm::ExitCode -> RWExitCodeSven Gothel2021-09-261-3/+3
|
* L2CAPComm/BTGattHandle/SMPHandler: Show informal INFO_PRINT on non ↵Sven Gothel2021-09-251-3/+3
| | | | interrupting read (error w/ errno==ETIMEDOUT, or len=0)
* [BTGatt|SMP]Handler::l2capReaderThreadImpl(): Only an error if 0 > len, 0 == ↵Sven Gothel2021-09-231-1/+1
| | | | len is valid!
* [BTGatt|SMP]Handler::l2capReaderThreadImpl()/send(): On R/W failue, IRQ|DBT ↵Sven Gothel2021-09-231-7/+11
| | | | | | out: Add getStateString(..) to expose errno. Fix send().. Fix send() messages: Use proper jau::snsize_t (%d) etc ..
* Resolve L2CAPComm post-close 'has_ioerror' setting (reusing instance ↵Sven Gothel2021-09-231-2/+6
| | | | failed); read(..)/write(..) properly return len>=0 or ExitCode
* Add BTAdapter::[getV|v]isibleAddressAndType[()] and ↵Sven Gothel2021-07-281-1/+1
| | | | | | | | | | | | | | BTAdapter::get[Address->AddressAndType]() using BDAddressAndType, preparing for random address Thoroughly changes - 'EUI48 AdapterInfo::address' -> 'BDAddressAndType AdapterInfo::addressAndType' - BTAdapter C++ - BTAdapter and its DBTAdapter/DBusAdapter implementations (Java) Motivation: - The adapter's address as initially reported by the system is always its public address, i.e. BDAddressType::BDADDR_LE_PUBLIC - The adapter's visible BDAddressAndType might be set to BDAddressType::BDADDR_LE_RANDOM before scanning / discovery mode (TODO).
* Bump to jaulin v0.3.3 and adapte to jau:ringbuffer changesSven Gothel2021-06-111-1/+1
|
* C++: Promote L2CAP_PSM, L2CAP_CID, .. to 'enum class'; Minor constexpr ↵Sven Gothel2021-02-081-1/+1
| | | | | | | | | | | | | | | | | | | | | enhancements 'enum' -> 'enum class' w/ all bells and whistles: L2CAP_PSM, L2CAP_CID, AD_Type_Const BTAddress.hpp: Add 'constexpr uint8_t number(..)' constexpr: - equality- and bit-operations on different types: EIRDataType, ManufactureSpecificData - isEIRDataTypeSet(), setEIRDataTypeSet(), setAdapterSettingMaskBit() HCIACLData Cleanup - Use L2CAP_PSM and L2CAP_CID types - Convenient queries if SMP or GATT type - Add toString(..) w/ l2cap_data ptr L2CAPComm: Use L2CAP_PSM and L2CAP_CID types
* C++ direct_bt files: Cleanup includes, order and type mixed-up during ↵Sven Gothel2021-02-021-2/+2
| | | | refactoring with Eclipse
* Java: New API Layout: Shorten named [Bluetooth -> BT], [Characteristic -> ↵Sven Gothel2021-01-251-9/+9
| | | | 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-1/+1
| | | | | | | | | | | | | | | | | | | | | (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
* Adapty to jau::cow_vector changes (along w/ new jau::darray): Use ↵Sven Gothel2021-01-051-1/+1
| | | | const_iterator w/ jau::for_each and maybe jau::for_each_fidelity
* smart_ptr-3: Handle HCIEvent + SMPPDUMsg instances via std::unique_ptr ↵Sven Gothel2020-12-141-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | See commit bc9d1c0d2942ce24019b432198f2d4c0d00aee19
* Use new BTSecurityLevel instead of uint8_t BT_SECURITY value; DBTDevice: Add ↵Sven Gothel2020-11-191-1/+1
| | | | [set|get]SecurityLevel() using BTSecurityLevel, overriding auto-determined mode.
* Fix minor compiler error: DBTScanner10.java: complete using ↵Sven Gothel2020-11-171-0/+1
| | | | executeOffThread(..) editing; SMPHandler: Avoid unused arguments
* Align SMPHandler::establishSecurity(..), DBTDevice::connectSMP(..) with ↵Sven Gothel2020-11-171-0/+6
| | | | | | | | | | L2CAPComm::setBTSecurityLevel() for DBTDevice::processL2CAPSetup() sec_level > BT_SECURITY_LOW is now required to start security negotiation (not just > 0), matching BT_SECURITY API. This change aligns the tentative SMPHandler and conditionally disabled code with current state. SMPHandler::establishSecurity(..) needs to be implemented for non BlueZ platforms or when SMP is accessible under BlueZ.
* L2CAPComm: Allow multiple open/close cycles during lifetime, required to ↵Sven Gothel2020-11-151-4/+5
| | | | | | | | re-establish l2cap channel on changed security/encryption - DBTDevice -- Aggregating L2CAPComm instance, open/close and passing to GATTHandler -- add LEFeatures le_features field, incl notify update hook
* MgmtTypes: Reorg MgmtMsg <- [MgmtCommand (w/ Opcode), MgmtEvent (w/ ↵Sven Gothel2020-11-091-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | Opcode)]; Mark Opcode linux-version and TODO/FIXME; ... Further - Update opcodes up until linux 5.9 - Add MgmtEvtControllerError - Add MgmtSetDiscoverableCmd - Sort all MgmtCommand + MgmtEvent in Opcode order - MgmtEvent::getSpecialized(): Sort by Opcode order, add MgmtEvtControllerError - SMPHandler.hpp: Add macro definition USE_LINUX_BT_SECURITY [0|1] - DBTManager::setMode() produces usable DBG_PRINT, drop setAdapterMode(..) - DBTManager::setDiscoverableCmd(): Added using MgmtSetDiscoverableCmd, used for DUAL | BREDR only - MgmtEvtCmdComplete::getCurrentSettings() added - DBTManager::setMode() + setDiscoverableCmd() updated given AdapterSetting current_setting on SUCCESS, using MgmtEvtCmdComplete::getCurrentSettings() - DBTManager::initAdapter() uses updated AdapterSetting current_setting if valid instead of refetching AdapterInfo via READ_INFO.
* Adding tentative SMPHandler (WIP for non Linux/BlueZ platforms or when ↵Sven Gothel2020-11-081-0/+328
supported) On our current target platform Linux/BlueZ, access to the existing SMP implementation via L2CAP (socket) is sadly prohibited. Linux/BlueZ currently only allows L2CAP sockets for LE devices for the ATT protocol, determined by L2CAP_CID_ATT. Therefor we have to use Linux/BlueZ manager control channel's API to access the SMP implementation. However, the SMPHandler and used SMPPDUMsg types may be used on other platforms. Hence implementation shall be completed for these later on.