diff options
author | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2016-01-12 12:22:11 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2016-01-18 07:46:35 +0000 |
commit | e94fe90e7d2e1df9bd7d1d014fb468e5e73da834 (patch) | |
tree | 440a4e0359661b6cc4ac2e95455475ff0d64ebcd /src/bluetooth/qlowenergycontroller_bluez.cpp | |
parent | 1046db1a91f264db6714975daa27f56a457a6778 (diff) |
Bluetooth LE: Add connection update functionality.
Implemented for BlueZ only.
Change-Id: I358a98bbc7499d5ce5437fb0d4672fde46c3b831
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_bluez.cpp')
-rw-r--r-- | src/bluetooth/qlowenergycontroller_bluez.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index a69bd2c4..35291c97 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -264,6 +264,17 @@ QLowEnergyControllerPrivate::QLowEnergyControllerPrivate() hciManager->monitorEvent(HciManager::EncryptChangeEvent); connect(hciManager, SIGNAL(encryptionChangedEvent(QBluetoothAddress,bool)), this, SLOT(encryptionChangedEvent(QBluetoothAddress,bool))); + hciManager->monitorEvent(HciManager::LeMetaEvent); + connect(hciManager, &HciManager::connectionComplete, [this](quint16 handle) { + connectionHandle = handle; + qCDebug(QT_BT_BLUEZ) << "received connection complete event, handle:" << handle; + }); + connect(hciManager, &HciManager::connectionUpdate, + [this](quint16 handle, const QLowEnergyConnectionParameters ¶ms) { + if (handle == connectionHandle) + emit q_ptr->connectionUpdated(params); + } + ); } QLowEnergyControllerPrivate::~QLowEnergyControllerPrivate() @@ -359,6 +370,18 @@ void QLowEnergyControllerPrivate::stopAdvertising() advertiser->stopAdvertising(); } +void QLowEnergyControllerPrivate::requestConnectionUpdate(const QLowEnergyConnectionParameters ¶ms) +{ + // The spec says that the connection update command can be used by both slave and master + // devices, but BlueZ allows it only for master devices. So for slave devices, we have to use a + // connection parameter update request, which we need to wrap in an ACL command, as BlueZ + // does not allow user-space sockets for the signaling channel. + if (role == QLowEnergyController::CentralRole) + hciManager->sendConnectionUpdateCommand(connectionHandle, params); + else + hciManager->sendConnectionParameterUpdateRequest(connectionHandle, params); +} + void QLowEnergyControllerPrivate::connectToDevice() { if (remoteDevice.isNull()) { @@ -481,6 +504,7 @@ void QLowEnergyControllerPrivate::resetController() encryptionChangePending = false; receivedMtuExchangeRequest = false; securityLevelValue = -1; + connectionHandle = 0; } void QLowEnergyControllerPrivate::l2cpReadyRead() @@ -2623,6 +2647,8 @@ void QLowEnergyControllerPrivate::handleConnectionRequest() } remoteDevice = QBluetoothAddress(convertAddress(clientAddr.l2_bdaddr.b)); qCDebug(QT_BT_BLUEZ) << "GATT connection from device" << remoteDevice; + if (connectionHandle == 0) + qCWarning(QT_BT_BLUEZ) << "Received client connection, but no connection complete event"; closeServerSocket(); l2cpSocket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol, this); |