summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2019-07-03 20:44:20 +0300
committerKonstantin Ritt <ritt.ks@gmail.com>2019-07-08 13:43:50 +0000
commit32e9527e38ed673ae2a10c7a3bf37e6eaca6d7a8 (patch)
treef532615bc103da2fd6e199cca3753f440db8cb79
parentad7cf667faa49521482b1a73d7732479adc4a70f (diff)
LE/OSX: better use of recently introduced AuthorizationError
handle and GATT_INSUFFICIENT_AUTHENTICATION and GATT_INSUFFICIENT_ENCRYPTION statuses explicitly to close the established connection with AuthorizationError Change-Id: I6077d2b4e90daaac527fff7145bc71d7a4e032a3 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/bluetooth/osx/osxbtcentralmanager.mm21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm
index 6b742684..b9a1ae0f 100644
--- a/src/bluetooth/osx/osxbtcentralmanager.mm
+++ b/src/bluetooth/osx/osxbtcentralmanager.mm
@@ -39,6 +39,7 @@
#include "qlowenergyserviceprivate_p.h"
#include "qlowenergycharacteristic.h"
+#include "qlowenergycontroller.h"
#include "osxbtcentralmanager_p.h"
#include "osxbtnotifier_p.h"
@@ -132,6 +133,7 @@ QT_USE_NAMESPACE
- (CBDescriptor *)descriptor:(const QBluetoothUuid &)dUuid
forCharacteristic:(CBCharacteristic *)ch;
- (bool)cacheWriteValue:(const QByteArray &)value for:(NSObject *)obj;
+- (void)handleReadWriteError:(NSError *)error;
- (void)reset;
@end
@@ -1202,6 +1204,21 @@ QT_USE_NAMESPACE
// TODO: also serviceToVisit/VisitNext and visitedServices ?
}
+- (void)handleReadWriteError:(NSError *)error
+{
+ Q_ASSERT(notifier);
+
+ switch (error.code) {
+ case 0x05: // GATT_INSUFFICIENT_AUTHORIZATION
+ case 0x0F: // GATT_INSUFFICIENT_ENCRYPTION
+ emit notifier->CBManagerError(QLowEnergyController::AuthorizationError);
+ [self detach];
+ break;
+ default:
+ break;
+ }
+}
+
// CBCentralManagerDelegate (the real one).
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
@@ -1540,6 +1557,7 @@ QT_USE_NAMESPACE
currentReadHandle = 0;
requestPending = false;
emit notifier->CBManagerError(qtUuid, QLowEnergyService::CharacteristicReadError);
+ [self handleReadWriteError:error];
[self performNextRequest];
}
return;
@@ -1658,6 +1676,7 @@ QT_USE_NAMESPACE
currentReadHandle = 0;
requestPending = false;
emit notifier->CBManagerError(qtUuid, QLowEnergyService::DescriptorReadError);
+ [self handleReadWriteError:error];
[self performNextRequest];
}
return;
@@ -1747,6 +1766,7 @@ QT_USE_NAMESPACE
NSLog(@"%s failed with error %@", Q_FUNC_INFO, error);
emit notifier->CBManagerError(qt_uuid(characteristic.service.UUID),
QLowEnergyService::CharacteristicWriteError);
+ [self handleReadWriteError:error];
} else {
const QLowEnergyHandle cHandle = charMap.key(characteristic);
emit notifier->characteristicWritten(cHandle, valueToReport);
@@ -1781,6 +1801,7 @@ QT_USE_NAMESPACE
NSLog(@"%s failed with error %@", Q_FUNC_INFO, error);
emit notifier->CBManagerError(qt_uuid(descriptor.characteristic.service.UUID),
QLowEnergyService::DescriptorWriteError);
+ [self handleReadWriteError:error];
} else {
const QLowEnergyHandle dHandle = descMap.key(descriptor);
Q_ASSERT_X(dHandle, Q_FUNC_INFO, "descriptor not found in the descriptors map");