aboutsummaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* DBGattServer::Listener: Add connected() and mtuChanged(): Supporting using ↵Sven Gothel2021-11-081-1/+31
| | | | | | | | | proper MTU and connection tracking. In case multiple connections will be supported, DBGattServer::Listener is able to match the connected BTDevice to the callback event. For now, dbt_peripheral00 only supports one connection while ignoring others ..
* Add BTGattCmd (C++/Java): Conveniently maps a GATT command and optionally ↵Sven Gothel2021-11-082-0/+249
| | | | | | its asynchronous response to a synchronous atomic operation Examples, see dbt_scanner10 and DBTScanner10
* Add BTDevice::findGattChar(char_uuid), i.e. w/o service_uuid (Java/C++): ↵Sven Gothel2021-11-081-0/+13
| | | | Less efficient, but might be desired by user
* BTAdapter: Add noexcept (startDiscovery(), removeAllStatusListener()); ↵Sven Gothel2021-11-042-5/+5
| | | | BTDevice::connectLE(..) Use const params like in decl
* BTDevice:: Fix dimension of stored supervisor_timeout (passed to ↵Sven Gothel2021-11-042-4/+4
| | | | BTGattHandler): Store in [ms] = 10 * [ms/10]
* Derive GATT read- and write-timout = max(minimum_preset, ↵Sven Gothel2021-11-042-19/+29
| | | | | | | | | | connection_supervising_timeout+50ms) per connection Using a connection derived GATT timeout considers the actually used supervising timout from the current connection. The latter determines the official determination of a connection loss, hence we shall not claim this case earlier. The additional 50ms is given to allow L2CAP timeout hit first.
* BTGattHandler::send[Indi|Notifi]cation(): Constring handle to be of ↵Sven Gothel2021-11-032-36/+43
| | | | characteristic value handle - clarification; Add proper API doc.
* BTGattHandler::findCharacterisicsByValueHandle(): Cleanup usage and argument ↵Sven Gothel2021-11-031-10/+6
| | | | order
* BTGattHandler::sendIndication(): Add missing mtx_command lock to sync ↵Sven Gothel2021-11-031-0/+1
| | | | | | sendWithReply() (cmd + reply events) Note: sendNotification() does not require such sync, as it doesn't await a reply.
* Adapt to jau::ringbuffer API changeSven Gothel2021-10-314-13/+13
|
* BTDevice::hciSMPMsgCallback: Only accept SMPPDUMsg::Opcode::SECURITY_REQUEST ↵Sven Gothel2021-10-291-3/+5
| | | | | | | | | | in vanilla or FAIL SMPPairingState In pre-pairing, it may occur that the slave adapter sends the SECURITY_REQUEST out, but pre-pairing is still setup and working. Hence ignore this request if SMPPairingState has progressed, BT Spec agrees here (only once before pairing).
* Add BTAdapter's Slave Peripheral SMP Key ManagementSven Gothel2021-10-291-81/+158
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To have full SMP key persitency in peripheral slave mode, BTAdapter requires fine grained control over - Passing stored keys to BTDevice's PairingData (w/o uploading them) - Uploading BTDevice's PairingData to the adapter This required interaction in certain places, only enabled if adapter is BTRole::Slave (peripheral): - BTAdapter::mgmtEvDeviceConnectedHCI() Only issue unpairDevice() if not pre-paired. Unpairing is required for new pairing to avoid DHKey Check failures! - BTAdapter::mgmtEvDeviceDisconnectedHCI() - First unpairDevice() will be issued via notifyDisconnect() - Set and upload stored keys for disconnected device (if existing), preparing for next connect. - BTAdapter::sendDevicePairingState() - SMPPairingState::COMPLETED && not SMPPairingState::PRE_PAIRED: Store keys - SMPPairingState::COMPLETED && SMPPairingState::PRE_PAIRED: Refresh keys to BTDevice (set), no upload! - SMPPairingState::FAILED: Remove and delete keys +++ BTAdapter::setSMPKeyPath(path) allows user to enable the persistent key storage by setting its local filesystem path. It will also read all key files (SMPKeyBin) and if valid and matching with the adapter, uploads them for pre-pairing. See dbt_peripheral00.cpp: adapter->setSMPKeyPath(ADAPTER_KEY_PATH); +++
* BTDevice::mtx_pairing: mutex -> recurse_mutex, preparing for BTAdapter's ↵Sven Gothel2021-10-291-17/+9
| | | | peripheral key management
* Move SMPKeyBin 'apply' to BTDevice, splitting functionality: setting + ↵Sven Gothel2021-10-292-234/+139
| | | | | | | | | | | | | | | | | | | | | | | | | | uploading keys (required for peripheral BTAdapter key management) SMPKeyBin has the key apply action revoked. SMPKeyBin is reduced to store keys, address and security settings, as well adding persistence (read/write to filesystem). BTDevice::setSMPKeyBin(SMPKeyBin&) shall be used copy the key data over and BTDevice::uploadKeys() to upload them to the adapter for pre-pairing. See dbt_scanner10.cpp's use of convenient API (same efficiency as before) device->uploadKeys(KEY_PATH, req_sec_level, true /* verbose_ */); BTDevice::setSMPKeyBin(SMPKeyBin&) fully restored BTDevice's PairingData - keys - key caps - user security level and IOCaps +++ The reduced 'set<Name>Key(..)' methods only - copy the key to BTDevice's PairingData - set the KeyType bit for keys_<role>_[init|resp], fully restoring key caps
* SMPKeyBin: Entangle filename with instance: write(..) takes path instead of ↵Sven Gothel2021-10-281-12/+13
| | | | filename; Add member getFilename(path) and remove(path)
* Issue BTDevice::unpair() directly when device is discovered, disconnected ↵Sven Gothel2021-10-282-4/+34
| | | | | | | | | | | | | | | | | | | | | | | | and connected as peripheral This enforces a consistent and stable security workflow. - when a BTRole::Slave BTDevice is discovered, see AdapterStatusListener::deviceFound(). - when a BTRole::Slave BTDevice is disconnected, see AdapterStatusListener::deviceDisconnected(). - when a BTRole::Master BTDevice gets connected, see AdapterStatusListener::deviceConnected(). +++ Especially when connected as peripheral without unpair in SC mode, the peripheral fails the DHKey Check. TODO: Provide a persistent pre-pairing mechanism via SMPKeyBin for peripheral mode. +++ Note: Our existing example code to connect to a remote slave/peripheral, already performed the unpair on deviceFound(..) and deviceDisconnected(). These calls have now being removed, as they are performed directly by Direct-BT. The example code uploads pre-existing keys for pre-pairing when device is found, if existing.
* BTManager::unpairDevice(..): Return HCIStatusCode directly; ↵Sven Gothel2021-10-282-9/+10
| | | | BTDevice::unpair(): Add DBG_PRINT on failure; BTDevice::clearSMPStates() reduce to one DBG_PRINT
* BTGattHandler::disconnect: Fix NPE (oops)Sven Gothel2021-10-281-1/+1
|
* BTDevice::updatePairingState: Tidy up PASSKEY + NUMERIC_COMPARE default ↵Sven Gothel2021-10-281-2/+2
| | | | replies DBT_PRINT
* BTAdapter::startAdvertising: Fix ERR_PRINT typoSven Gothel2021-10-281-1/+1
|
* Add DBGattServer::Listener::disconnect(..) for cleanup, example: Full ↵Sven Gothel2021-10-271-0/+20
| | | | cleanup incl. CCCD regs
* BTAdapter::mgmtEvDeviceConnectedHCI(..): Re-add calling notifyLEFeatures(..) ↵Sven Gothel2021-10-271-0/+14
| | | | | | from BTRole::Slave (peripheral) BlueZ/Kernel not reliably sending out HCI_LE_REMOTE_FEATURES
* SMPKeyBin: Add helper to load all SMPKeyBin files from a directory, filter ↵Sven Gothel2021-10-271-1/+74
| | | | for one adapter and apply them all (peripheral pre-pairing)
* Add BTAdapter::setSMPKeyBin(..): Allowing to upload keys for peripheral mode ↵Sven Gothel2021-10-271-0/+79
| | | | | | pre-connection FIXME: Pass keys to BTDevice instance after connection!
* BTGattHandler::send(..): Fix IllegalArgumentException message: Msg PDU size ↵Sven Gothel2021-10-271-2/+2
| | | | > usedMTU
* BTDevice::setLinkKey(): Upload LK not implemented on Bluez/Kernel for LE ↵Sven Gothel2021-10-271-0/+11
| | | | address, just ignore (LTK is enough)
* BTDevice::PairingData::toString(): Fix newline for IRKSven Gothel2021-10-271-1/+1
|
* BTDevice::processDeviceReady(..) Delay revisedSven Gothel2021-10-271-13/+15
| | | | | | | | Give remote slave (peripheral, Gatt-Server) 'some time' (100ms) to complete connection and listening to our Gatt-Client requests. We give the Gatt-Server a slightly longer period after newly paired encryption keys (150ms).
* BTDevice::PairingData::toString(): fix newlineSven Gothel2021-10-271-2/+2
|
* Fix BTDevice::clearSMPStates(..) invocation (round 3)Sven Gothel2021-10-271-2/+2
| | | | | | | | | clearSMPStates() call from BTDevice::disconnect() is - redundant - may cause a deadlock due to mtx_pairing lock Issued at ctor(), manual unpair() and notifyDisconnect() notifyDisconnect() will be called at all times, even if disconnect() fails!
* SMPTypes.cpp: Adding SMPIdentityResolvingKey implementation codeSven Gothel2021-10-271-0/+36
|
* SMPKeyBin (Version 5, C++/Java): Add IRK and (set/get) and also set CSRKSven Gothel2021-10-271-0/+75
|
* BTDevice: SMP Keys (C++/Java): Have setter update PairingData::keys_*_has; ↵Sven Gothel2021-10-271-2/+49
| | | | Expose SMPIdentityResolvingKey (IRK) adding get/set methods; Add setSignatureResolvingKey();
* Fix BTDevice::clearSMPStates(..) invocation (round 2)Sven Gothel2021-10-271-2/+2
| | | | | | | | | - BTDevice::notifyConnected(..): Don't issue clearSMPStates() to have valid content from manual settings. Previous disconnect commands should have cleaned these. - BTDevice::remove(): Don't issue clearSMPStates(), disconnect(..) will. - BTDevice::disconnect(): Issue clearSMPStates()!
* Revise BTDevice::PairingData Handling; Fix HCITypes/MgmtTypes Encryption Key ↵Sven Gothel2021-10-271-199/+263
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Semantics Revise BTDevice::PairingData Handling - BTDevice::PairingData - Add SMPIdentityResolvingKey, replacing uint128_t - Use 'BDAddressAndType id_address_init, id_address_resp' - Add 'toString(const BDAddressAndType& addressAndType, const BTRole& role)' for unified string representation - Add 'encryption_enabled' - checkPairingKeyDistributionComplete() - bring back strict KEY checking (w/ IRK + SIGN) - requires encryption_enabled - drop printKeyDistributionStatus() - BTDevice::updatePairingState() - #if CONSIDER_HCI_CMD_FOR_SMP_STATE - Never override SMP key induced data - Only take HCI Encryption keys in SC mode - In SC mode, LTK is for both, Server + Slave - Add early (pre-pair) MgmtEvent::Opcode::HCI_LE_ENABLE_ENC - Move checkPairingKeyDistributionComplete() and DBG_PRINT to end of switch/if branches, cleaning up workflow. - Reset claimed_state also if any key is invalid (fix) - DBG_PRINT BTDevice::PairingData::toString() - BTDevice::hciSMPMsgCallback() - Move DBG_PRINT to end of switch/if branches, cleaning up workflow. - DBG_PRINT BTDevice::PairingData::toString() ++++ Fix HCITypes/MgmtTypes Encryption Key Semantics, i.e. HCILEEnableEncryptionCmd, HCILELTKReplyAckCmd and HCILELTKReqEvent (+ Mgmt mappings) HCILEEnableEncryptionCmd: - This command shall only be used when the local device’s role is BTRole::Master (initiator). - Encryption key belongs to the remote device having role BTRole::Slave (responder). - The encryption key matches the LTK from SMP messaging in SC mode only! HCILELTKReplyAckCmd: - This command shall only be used when the local device’s role is BTRole::Slave (responder). - LTK belongs to the local device having role BTRole::Slave (responder). - The LTK matches the LTK from SMP messaging in SC mode only! HCILELTKReqEvent - This event shall only be generated when the local device’s role is BTRole::Slave (responder, adapter in peripheral mode). - Rand and Ediv belong to the local device having role BTRole::Slave (responder). - Rand and Ediv matches the LTK from SMP messaging in SC mode only!
* BTDevice: Refine handling define CONSIDER_HCI_CMD_FOR_SMP_STATE (disable ↵Sven Gothel2021-10-271-9/+4
| | | | code in BTDevice::updatePairingState)
* Add BTAdapter::setSecureConnections(bool) (C++/Java): Allow testing ↵Sven Gothel2021-10-271-5/+14
| | | | peripheral with legacy mode
* Unify connectGATT() delay (100-150 ms) in BTDevice::processDeviceReady()Sven Gothel2021-10-262-6/+19
|
* Fix BTDevice::unpair() if connected, i.e. clearSMPStates(false -> ↵Sven Gothel2021-10-261-1/+1
| | | | getConnected())
* Fix HCIHandler::le_enable_adv(enable = false) for BT5Sven Gothel2021-10-261-1/+1
|
* Add 3 HCI Commands + 1 HCI MetaEvent to support SMP SC on slave peripheral ↵Sven Gothel2021-10-266-135/+435
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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(..)
* HCIHandler: Add HCIMetaEventType::LE_LTK_REQUEST (filter), add opc ↵Sven Gothel2021-10-252-1/+6
| | | | LE_LTK_REPLY_ACK and LE_LTK_REPLY_REJ
* BTDevice::hciSMPMsgCallback(..): Proper dertermination of ↵Sven Gothel2021-10-251-15/+21
| | | | 'msg_from_initiator' using local BTRole (adapter) and l2cap pbflag
* HCIHandler: Add dev_id for all debug output, allowing to separate multiple ↵Sven Gothel2021-10-251-76/+79
| | | | adapter
* HCIHandler: Always pass LE_PHY_UPDATE_COMPLETE, LE_REMOTE_FEATURES to event ↵Sven Gothel2021-10-255-45/+23
| | | | | | | | | | | | handler with status code; ... DBTDevice::notifyLEFeatures() is always reached even with LE_REMOTE_FEATURES status != SUCCESS, in which case is will enforce `le_features = le_features | LE_Features::LE_Encryption`. BTAdapter::mgmtEvDeviceConnectedHCI(): Drops special case device->notifyLEFeatures(), which was injected for BTRole::Slave == getRole(). This is possible, since we pass LE_REMOTE_FEATURES with !SUCCESS status and regain original workflow.
* BTGattHandler::ctor: Add 100ms delay before exchangeMTUImpl(); Working ↵Sven Gothel2021-10-241-0/+1
| | | | | | | | | | | | | | | self-connect dbt_scanner10 with dbt_peripheral00 It has been experienced that our Gatt-Server (slave device, tested with dbt_peripheral00 example) misses receiving the `ATT Exchange MTU Request` after notified being connected. In this case, the master client received the connection before the slave server and sent out the `ATT Exchange MTU Request` before the slave server even started listening. For now, the master client waits 100ms before sending out the MTU exchange request, giving the slave server ample time to be notified and setup the L2CAP listener. However, this should be further analysed ...
* GATTNumbers: GATT_SERVICES ..: Use jau::make_darray<..>(..) to avoid ↵Sven Gothel2021-10-241-130/+162
| | | | | | | | | | | | copy-ctor; Disable its compilation and preserve resources. GATT_SERVICES .. etc were merely created as a proof of concept to compile a complex static structure representing detailed GATT services with its characteristics etc. Its usage has been fixed to avoid std::initialize_list and copy-ctor. One can enable its compilation and linkage by defining `DIRECTBT_BUILDIN_GATT_SERVICE_CHARACTERISTIC_SPEC`.
* L2CAPComm, BTGattHandler: Silence WORDY/DEBUG PRINT on expected ↵Sven Gothel2021-10-242-6/+8
| | | | L2CAPComm::RWExitCode::POLL_TIMEOUT
* BTGattHandler::replyWriteReq: WARN_PRINT -> COND_PRINT AttWriteResp not a ↵Sven Gothel2021-10-191-1/+1
| | | | warning issue
* BTDevice/BTGattHandler: Add send[Notification|Indication](..) commandsSven Gothel2021-10-192-0/+56
|