48 QLowEnergyControllerPrivateBluez();
58 QLowEnergyService::DiscoveryMode mode)
override;
61 const QLowEnergyAdvertisingData &advertisingData,
62 const QLowEnergyAdvertisingData &scanResponseData)
override;
69 const QLowEnergyHandle charHandle)
override;
70 void readDescriptor(
const QSharedPointer<QLowEnergyServicePrivate> service,
71 const QLowEnergyHandle charHandle,
72 const QLowEnergyHandle descriptorHandle)
override;
76 const QLowEnergyHandle charHandle,
77 const QByteArray &newValue, QLowEnergyService::WriteMode mode)
override;
78 void writeDescriptor(
const QSharedPointer<QLowEnergyServicePrivate> service,
79 const QLowEnergyHandle charHandle,
80 const QLowEnergyHandle descriptorHandle,
81 const QByteArray &newValue)
override;
84 QLowEnergyHandle startHandle)
override;
86 int mtu()
const override;
104 quint16 connectionHandle = 0;
105 QBluetoothSocket *l2cpSocket =
nullptr;
114 QQueue<Request> openRequests;
116 struct WriteRequest {
118 WriteRequest(quint16 h, quint16 o,
const QByteArray &v)
119 : handle(h), valueOffset(o), value(v) {}
124 QList<WriteRequest> openPrepareWriteRequests;
127 QList<QLowEnergyHandle> scheduledIndications;
128 bool indicationInFlight =
false;
130 struct TempClientConfigurationData {
132 QLowEnergyHandle chHndl = 0, QLowEnergyHandle coHndl = 0)
133 : descData(dd), charValueHandle(chHndl), configHandle(coHndl) {}
136 QLowEnergyHandle charValueHandle;
137 QLowEnergyHandle configHandle;
140 struct ClientConfigurationData {
141 ClientConfigurationData(QLowEnergyHandle chHndl = 0, QLowEnergyHandle coHndl = 0,
143 : charValueHandle(chHndl), configHandle(coHndl), configValue(val) {}
145 QLowEnergyHandle charValueHandle;
146 QLowEnergyHandle configHandle;
148 bool charValueWasUpdated =
false;
150 QHash<quint64, QList<ClientConfigurationData>> clientConfigData;
153 SigningData() =
default;
154 SigningData(
BluezUint128 csrk, quint32 signCounter = quint32(-1))
155 : key(csrk), counter(signCounter) {}
158 quint32 counter = quint32(-1);
160 QHash<quint64, SigningData> signingData;
161 LeCmacCalculator *cmacCalculator =
nullptr;
165 int securityLevelValue;
166 bool encryptionChangePending;
167 bool receivedMtuExchangeRequest =
false;
169 std::shared_ptr<HciManager> hciManager;
171 QSocketNotifier *serverSocketNotifier =
nullptr;
172 QTimer *requestTimer =
nullptr;
173 RemoteDeviceManager* device1Manager =
nullptr;
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190 int gattRequestTimeout = 20000;
192 void handleConnectionRequest();
193 void closeServerSocket();
195 bool isBonded()
const;
196 QList<TempClientConfigurationData> gatherClientConfigData();
197 void storeClientConfigurations();
198 void restoreClientConfigurations();
200 enum SigningKeyType { LocalSigningKey, RemoteSigningKey };
201 void loadSigningDataIfNecessary(SigningKeyType keyType);
202 void storeSignCounter(SigningKeyType keyType)
const;
203 QString signingKeySettingsGroup(SigningKeyType keyType)
const;
204 QString keySettingsFilePath()
const;
206 void sendPacket(
const QByteArray &packet);
207 void sendNextPendingRequest();
208 void processReply(
const Request &request,
const QByteArray &reply);
210 void sendReadByGroupRequest(QLowEnergyHandle start, QLowEnergyHandle end,
212 void sendReadByTypeRequest(QSharedPointer<QLowEnergyServicePrivate> serviceData,
213 QLowEnergyHandle nextHandle, quint16 attributeType);
214 void sendReadValueRequest(QLowEnergyHandle attributeHandle,
bool isDescriptor);
215 void readServiceValues(
const QBluetoothUuid &service,
216 bool readCharacteristics);
217 void readServiceValuesByOffset(uint handleData, quint16 offset,
220 void discoverServiceDescriptors(
const QBluetoothUuid &serviceUuid);
221 void discoverNextDescriptor(QSharedPointer<QLowEnergyServicePrivate> serviceData,
222 const QList<QLowEnergyHandle> pendingCharHandles,
223 QLowEnergyHandle startingHandle);
224 void processUnsolicitedReply(
const QByteArray &msg);
226 bool setSecurityLevel(
int level);
227 int securityLevel()
const;
228 void sendExecuteWriteRequest(
const QLowEnergyHandle attrHandle,
229 const QByteArray &newValue,
231 void sendNextPrepareWriteRequest(
const QLowEnergyHandle handle,
232 const QByteArray &newValue, quint16 offset);
235 void resetController();
237 void handleAdvertisingError();
239 bool checkPacketSize(
const QByteArray &packet,
int minSize,
int maxSize = -1);
240 bool checkHandle(
const QByteArray &packet, QLowEnergyHandle handle);
242 QLowEnergyHandle endingHandle);
244 void handleExchangeMtuRequest(
const QByteArray &packet);
245 void handleFindInformationRequest(
const QByteArray &packet);
246 void handleFindByTypeValueRequest(
const QByteArray &packet);
247 void handleReadByTypeRequest(
const QByteArray &packet);
248 void handleReadRequest(
const QByteArray &packet);
249 void handleReadBlobRequest(
const QByteArray &packet);
250 void handleReadMultipleRequest(
const QByteArray &packet);
251 void handleReadByGroupTypeRequest(
const QByteArray &packet);
252 void handleWriteRequestOrCommand(
const QByteArray &packet);
253 void handlePrepareWriteRequest(
const QByteArray &packet);
254 void handleExecuteWriteRequest(
const QByteArray &packet);
259 using ElemWriter =
std::function<
void(
const Attribute &,
char *&)>;
260 void sendListResponse(
const QByteArray &packetStart, qsizetype elemSize,
261 const QList<Attribute> &attributes,
const ElemWriter &elemWriter);
263 void sendNotification(QLowEnergyHandle handle);
264 void sendIndication(QLowEnergyHandle handle);
266 void sendNextIndication();
268 void ensureUniformAttributes(QList<Attribute> &attributes,
270 void ensureUniformUuidSizes(QList<Attribute> &attributes);
271 void ensureUniformValueSizes(QList<Attribute> &attributes);
273 using AttributePredicate =
std::function<
bool(
const Attribute &)>;
274 QList<Attribute> getAttributes(
275 QLowEnergyHandle startHandle, QLowEnergyHandle endHandle,
276 const AttributePredicate &attributePredicate = [](
const Attribute &) {
return true; });
279 QLowEnergyCharacteristic::PropertyType type);
283 bool verifyMac(
const QByteArray &message,
BluezUint128 csrk, quint32 signCounter,
284 quint64 expectedMac);
286 void updateLocalAttributeValue(
287 QLowEnergyHandle handle,
288 const QByteArray &value,
289 QLowEnergyCharacteristic &characteristic,
290 QLowEnergyDescriptor &descriptor);
292 void writeCharacteristicForPeripheral(
294 const QByteArray &newValue);
295 void writeCharacteristicForCentral(
const QSharedPointer<QLowEnergyServicePrivate> &service,
296 QLowEnergyHandle charHandle,
297 QLowEnergyHandle valueHandle,
298 const QByteArray &newValue,
299 QLowEnergyService::WriteMode mode);
301 void writeDescriptorForPeripheral(
302 const QSharedPointer<QLowEnergyServicePrivate> &service,
303 const QLowEnergyHandle charHandle,
304 const QLowEnergyHandle descriptorHandle,
305 const QByteArray &newValue);
306 void writeDescriptorForCentral(
307 const QLowEnergyHandle charHandle,
308 const QLowEnergyHandle descriptorHandle,
309 const QByteArray &newValue);
311 void restartRequestTimer();
312 void establishL2cpClientSocket();
313 void createServicesForCentralIfRequired();
316 void l2cpConnected();
317 void l2cpDisconnected();
318 void l2cpErrorChanged(QBluetoothSocket::SocketError);
319 void l2cpReadyRead();
320 void encryptionChangedEvent(
const QBluetoothAddress&,
bool);
321 void handleGattRequestTimeout();
322 void activeConnectionTerminationDone();