From 1905841f4008a58932368a7099e370e5758544c4 Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 5 Jun 2016 00:51:39 +0200 Subject: initial attempts to work with paired devices --- gatoperipheral.cpp | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'gatoperipheral.cpp') diff --git a/gatoperipheral.cpp b/gatoperipheral.cpp index d15bf99..a08f87a 100644 --- a/gatoperipheral.cpp +++ b/gatoperipheral.cpp @@ -186,20 +186,29 @@ bool GatoPeripheral::advertisesService(const GatoUUID &uuid) const return d->service_uuids.contains(uuid); } -void GatoPeripheral::connectPeripheral(PeripheralConnectOptions options) +bool GatoPeripheral::connectPeripheral(PeripheralConnectOptions options) { Q_D(GatoPeripheral); if (d->att->state() != GatoSocket::StateDisconnected) { qDebug() << "Already connecting"; - return; + return false; } - GatoSocket::SecurityLevel sec_level = GatoSocket::SecurityLow; + d->att->setSecurityLevel(GatoSocket::SecurityLow); if (options & PeripheralConnectOptionRequireEncryption) { - sec_level = GatoSocket::SecurityMedium; + if (!d->att->setSecurityLevel(GatoSocket::SecurityMedium)) { + qWarning() << "Could not set medium security level"; + return false; + } + } + if (options & PeripheralConnectOptionRequirePairing) { + if (!d->att->setSecurityLevel(GatoSocket::SecurityHigh)) { + qWarning() << "Could not set medium security level"; + return false; + } } - d->att->connectTo(d->addr, sec_level); + return d->att->connectTo(d->addr); } void GatoPeripheral::disconnectPeripheral() @@ -785,18 +794,17 @@ void GatoPeripheralPrivate::handleDescriptors(uint req, const QListdescriptorsDiscovered(characteristic); return; + } else if (last_handle == 0) { + qWarning() << "Invalid handle while enumerating characteristics"; + return; } // Fetch following attributes -- cgit v1.2.3