summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergycontroller_p.h
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-10-26 13:23:35 +0200
committerAlex Blasche <alexander.blasche@qt.io>2017-11-03 13:08:54 +0000
commite1c4f25ab12892baaf43b0476fe669a48b2c58d0 (patch)
treee75acce16920ed85bea4375df3653b7d59297b02 /src/bluetooth/qlowenergycontroller_p.h
parentfbf36811672de79f2a648af97ca73d6c0e3b1608 (diff)
Provide own header for QLowEnergyControllerPrivate instance on Bluez
This utilizes the new QLowEnergyController interface and separates the existing Bluez implementation more clearly from other platforms. The existing addServiceHelper() class is moved out into the individual backends to avoid compiling the class into the new dbus backend. Change-Id: I1eea99e493958c61cb1fae830c08a3eb26bda9c3 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_p.h')
-rw-r--r--src/bluetooth/qlowenergycontroller_p.h230
1 files changed, 3 insertions, 227 deletions
diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h
index 0cf62ad7..4b3d43c8 100644
--- a/src/bluetooth/qlowenergycontroller_p.h
+++ b/src/bluetooth/qlowenergycontroller_p.h
@@ -77,9 +77,7 @@ QT_END_NAMESPACE
#include "qlowenergycontroller.h"
#include "qlowenergycontrollerbase_p.h"
-#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE)
-#include <QtBluetooth/QBluetoothSocket>
-#elif defined(QT_ANDROID_BLUETOOTH)
+#if defined(QT_ANDROID_BLUETOOTH)
#include <QtAndroidExtras/QAndroidJniObject>
#include "android/lowenergynotificationhub_p.h"
#elif defined(QT_WINRT_BLUETOOTH)
@@ -94,12 +92,7 @@ QT_BEGIN_NAMESPACE
class QLowEnergyServiceData;
class QTimer;
-#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE)
-class HciManager;
-class LeCmacCalculator;
-class QSocketNotifier;
-class RemoteDeviceManager;
-#elif defined(QT_ANDROID_BLUETOOTH)
+#if defined(QT_ANDROID_BLUETOOTH)
class LowEnergyNotificationHub;
#elif defined(QT_WINRT_BLUETOOTH)
class QWinRTLowEnergyServiceHandler;
@@ -107,8 +100,6 @@ class QWinRTLowEnergyServiceHandler;
extern void registerQLowEnergyControllerMetaType();
-class QLeAdvertiser;
-
class QLowEnergyControllerPrivateCommon : public QLowEnergyControllerPrivate
{
Q_OBJECT
@@ -172,223 +163,8 @@ public:
QVector<Attribute> localAttributes;
private:
-#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE)
- quint16 connectionHandle = 0;
- QBluetoothSocket *l2cpSocket;
- struct Request {
- quint8 command;
- QByteArray payload;
- // TODO reference below is ugly but until we know all commands and their
- // requirements this is WIP
- QVariant reference;
- QVariant reference2;
- };
- QQueue<Request> openRequests;
-
- struct WriteRequest {
- WriteRequest() {}
- WriteRequest(quint16 h, quint16 o, const QByteArray &v)
- : handle(h), valueOffset(o), value(v) {}
- quint16 handle;
- quint16 valueOffset;
- QByteArray value;
- };
- QVector<WriteRequest> openPrepareWriteRequests;
-
- // Invariant: !scheduledIndications.isEmpty => indicationInFlight == true
- QVector<QLowEnergyHandle> scheduledIndications;
- bool indicationInFlight = false;
-
- struct TempClientConfigurationData {
- TempClientConfigurationData(QLowEnergyServicePrivate::DescData *dd = nullptr,
- QLowEnergyHandle chHndl = 0, QLowEnergyHandle coHndl = 0)
- : descData(dd), charValueHandle(chHndl), configHandle(coHndl) {}
-
- QLowEnergyServicePrivate::DescData *descData;
- QLowEnergyHandle charValueHandle;
- QLowEnergyHandle configHandle;
- };
- struct ClientConfigurationData {
- ClientConfigurationData(QLowEnergyHandle chHndl = 0, QLowEnergyHandle coHndl = 0,
- quint16 val = 0)
- : charValueHandle(chHndl), configHandle(coHndl), configValue(val) {}
-
- QLowEnergyHandle charValueHandle;
- QLowEnergyHandle configHandle;
- quint16 configValue;
- bool charValueWasUpdated = false;
- };
- QHash<quint64, QVector<ClientConfigurationData>> clientConfigData;
-
- struct SigningData {
- SigningData() = default;
- SigningData(const quint128 &csrk, quint32 signCounter = quint32(-1))
- : key(csrk), counter(signCounter) {}
-
- quint128 key;
- quint32 counter = quint32(-1);
- };
- QHash<quint64, SigningData> signingData;
- LeCmacCalculator *cmacCalculator = nullptr;
-
- bool requestPending;
- quint16 mtuSize;
- int securityLevelValue;
- bool encryptionChangePending;
- bool receivedMtuExchangeRequest = false;
-
- HciManager *hciManager;
- QLeAdvertiser *advertiser;
- QSocketNotifier *serverSocketNotifier;
- QTimer *requestTimer = nullptr;
- RemoteDeviceManager* device1Manager = nullptr;
-
- /*
- Defines the maximum number of milliseconds the implementation will
- wait for requests that require a response.
-
- This addresses the problem that some non-conformant BTLE devices
- do not implement the request/response system properly. In such cases
- the queue system would hang forever.
-
- Once timeout has been triggered we gracefully continue with the next request.
- Depending on the type of the timed out ATT command we either ignore it
- or artifically trigger an error response to ensure the API gives the
- appropriate response. Potentially this can cause problems when the
- response for the dropped requests arrives very late. That's why a big warning
- is printed about the compromised state when a timeout is triggered.
- */
- int gattRequestTimeout = 20000;
-
- void handleConnectionRequest();
- void closeServerSocket();
-
- bool isBonded() const;
- QVector<TempClientConfigurationData> gatherClientConfigData();
- void storeClientConfigurations();
- void restoreClientConfigurations();
-
- enum SigningKeyType { LocalSigningKey, RemoteSigningKey };
- void loadSigningDataIfNecessary(SigningKeyType keyType);
- void storeSignCounter(SigningKeyType keyType) const;
- QString signingKeySettingsGroup(SigningKeyType keyType) const;
- QString keySettingsFilePath() const;
-
- void sendPacket(const QByteArray &packet);
- void sendNextPendingRequest();
- void processReply(const Request &request, const QByteArray &reply);
-
- void sendReadByGroupRequest(QLowEnergyHandle start, QLowEnergyHandle end,
- quint16 type);
- void sendReadByTypeRequest(QSharedPointer<QLowEnergyServicePrivate> serviceData,
- QLowEnergyHandle nextHandle, quint16 attributeType);
- void sendReadValueRequest(QLowEnergyHandle attributeHandle, bool isDescriptor);
- void readServiceValues(const QBluetoothUuid &service,
- bool readCharacteristics);
- void readServiceValuesByOffset(uint handleData, quint16 offset,
- bool isLastValue);
-
- void discoverServiceDescriptors(const QBluetoothUuid &serviceUuid);
- void discoverNextDescriptor(QSharedPointer<QLowEnergyServicePrivate> serviceData,
- const QList<QLowEnergyHandle> pendingCharHandles,
- QLowEnergyHandle startingHandle);
- void processUnsolicitedReply(const QByteArray &msg);
- void exchangeMTU();
- bool setSecurityLevel(int level);
- int securityLevel() const;
- void sendExecuteWriteRequest(const QLowEnergyHandle attrHandle,
- const QByteArray &newValue,
- bool isCancelation);
- void sendNextPrepareWriteRequest(const QLowEnergyHandle handle,
- const QByteArray &newValue, quint16 offset);
- bool increaseEncryptLevelfRequired(quint8 errorCode);
-
- void resetController();
-
- void handleAdvertisingError();
-
- bool checkPacketSize(const QByteArray &packet, int minSize, int maxSize = -1);
- bool checkHandle(const QByteArray &packet, QLowEnergyHandle handle);
- bool checkHandlePair(quint8 request, QLowEnergyHandle startingHandle,
- QLowEnergyHandle endingHandle);
-
- void handleExchangeMtuRequest(const QByteArray &packet);
- void handleFindInformationRequest(const QByteArray &packet);
- void handleFindByTypeValueRequest(const QByteArray &packet);
- void handleReadByTypeRequest(const QByteArray &packet);
- void handleReadRequest(const QByteArray &packet);
- void handleReadBlobRequest(const QByteArray &packet);
- void handleReadMultipleRequest(const QByteArray &packet);
- void handleReadByGroupTypeRequest(const QByteArray &packet);
- void handleWriteRequestOrCommand(const QByteArray &packet);
- void handlePrepareWriteRequest(const QByteArray &packet);
- void handleExecuteWriteRequest(const QByteArray &packet);
-
- void sendErrorResponse(quint8 request, quint16 handle, quint8 code);
-
- using ElemWriter = std::function<void(const Attribute &, char *&)>;
- void sendListResponse(const QByteArray &packetStart, int elemSize,
- const QVector<Attribute> &attributes, const ElemWriter &elemWriter);
-
- void sendNotification(QLowEnergyHandle handle);
- void sendIndication(QLowEnergyHandle handle);
- void sendNotificationOrIndication(quint8 opCode, QLowEnergyHandle handle);
- void sendNextIndication();
-
- void ensureUniformAttributes(QVector<Attribute> &attributes, const std::function<int(const Attribute &)> &getSize);
- void ensureUniformUuidSizes(QVector<Attribute> &attributes);
- void ensureUniformValueSizes(QVector<Attribute> &attributes);
-
- using AttributePredicate = std::function<bool(const Attribute &)>;
- QVector<Attribute> getAttributes(QLowEnergyHandle startHandle, QLowEnergyHandle endHandle,
- const AttributePredicate &attributePredicate = [](const Attribute &) { return true; });
-
- int checkPermissions(const Attribute &attr, QLowEnergyCharacteristic::PropertyType type);
- int checkReadPermissions(const Attribute &attr);
- int checkReadPermissions(QVector<Attribute> &attributes);
-
- bool verifyMac(const QByteArray &message, const quint128 &csrk, quint32 signCounter,
- quint64 expectedMac);
-
- void updateLocalAttributeValue(
- QLowEnergyHandle handle,
- const QByteArray &value,
- QLowEnergyCharacteristic &characteristic,
- QLowEnergyDescriptor &descriptor);
-
- void writeCharacteristicForPeripheral(
- QLowEnergyServicePrivate::CharData &charData,
- const QByteArray &newValue);
- void writeCharacteristicForCentral(const QSharedPointer<QLowEnergyServicePrivate> &service,
- QLowEnergyHandle charHandle,
- QLowEnergyHandle valueHandle,
- const QByteArray &newValue,
- QLowEnergyService::WriteMode mode);
-
- void writeDescriptorForPeripheral(
- const QSharedPointer<QLowEnergyServicePrivate> &service,
- const QLowEnergyHandle charHandle,
- const QLowEnergyHandle descriptorHandle,
- const QByteArray &newValue);
- void writeDescriptorForCentral(
- const QLowEnergyHandle charHandle,
- const QLowEnergyHandle descriptorHandle,
- const QByteArray &newValue);
-
- void restartRequestTimer();
- void establishL2cpClientSocket();
- void createServicesForCentralIfRequired();
-
-private slots:
- void l2cpConnected();
- void l2cpDisconnected();
- void l2cpErrorChanged(QBluetoothSocket::SocketError);
- void l2cpReadyRead();
- void encryptionChangedEvent(const QBluetoothAddress&, bool);
- void handleGattRequestTimeout();
- void activeConnectionTerminationDone();
-#elif defined(QT_ANDROID_BLUETOOTH)
+#if defined(QT_ANDROID_BLUETOOTH)
LowEnergyNotificationHub *hub;
private slots: