summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/osx/osxbtperipheralmanager.mm
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2016-11-14 16:50:09 +0100
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2016-11-15 11:13:22 +0000
commitc66bb18ec585e40294588b75e922410e7eb5d8bc (patch)
tree1baa892396a92582e83f1f232615986dd69326fd /src/bluetooth/osx/osxbtperipheralmanager.mm
parent3c78593e3764c312d9abc735352e66b841c8d71d (diff)
LE peripheral manager - warn about value length limit (iOS)
Apparently, it cannot exceed the 512-octets limit on iOS. Also, warn about notifications - the value is truncated for a connected peripheral, we are limited by a central.maximumUpdateValueLength. Change-Id: Ia3d09fe0306a2514cf2c6f391cc57e6d300b75fd Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth/osx/osxbtperipheralmanager.mm')
-rw-r--r--src/bluetooth/osx/osxbtperipheralmanager.mm32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/bluetooth/osx/osxbtperipheralmanager.mm b/src/bluetooth/osx/osxbtperipheralmanager.mm
index 03b95667..9c443cf6 100644
--- a/src/bluetooth/osx/osxbtperipheralmanager.mm
+++ b/src/bluetooth/osx/osxbtperipheralmanager.mm
@@ -187,6 +187,7 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
state = PeripheralState::idle;
nextServiceToAdd = {};
connectedCentrals.reset([[NSMutableSet alloc] init]);
+ maxNotificationValueLength = std::numeric_limits<NSUInteger>::max();
}
return self;
@@ -353,8 +354,13 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
}
const auto & range = valueRanges[charHandle];
- if (value.size() < int(range.first) || value.size() > int(range.second)) {
- qCWarning(QT_BT_OSX) << "ignoring value of invalid length" << value.count();
+ if (value.size() < int(range.first) || value.size() > int(range.second)
+#ifdef Q_OS_IOS
+ || value.size() > OSXBluetooth::maxValueLength) {
+#else
+ ) {
+#endif
+ qCWarning(QT_BT_OSX) << "ignoring value of invalid length" << value.size();
return;
}
@@ -630,6 +636,12 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
while (updateQueue.size()) {
const auto &request = updateQueue.front();
if (charMap.contains(request.charHandle)) {
+ if ([connectedCentrals count]
+ && maxNotificationValueLength < [request.value length]) {
+ qCWarning(QT_BT_OSX) << "value of length" << [request.value length]
+ << "will possibly be truncated to"
+ << maxNotificationValueLength;
+ }
const BOOL res = [manager updateValue:request.value
forCharacteristic:static_cast<CBMutableCharacteristic *>(charMap[request.charHandle])
onSubscribedCentrals:nil];
@@ -655,6 +667,9 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
return;
}
+ maxNotificationValueLength = std::min(maxNotificationValueLength,
+ central.maximumUpdateValueLength);
+
QT_BT_MAC_AUTORELEASEPOOL
if (state == PeripheralState::advertising) {
@@ -683,6 +698,9 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
state = PeripheralState::idle;
emit notifier->disconnected();
}
+
+ if (![connectedCentrals count])
+ maxNotificationValueLength = std::numeric_limits<NSUInteger>::max();
}
- (CBService *)findIncludedService:(const QBluetoothUuid &)qtUUID
@@ -749,6 +767,16 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
continue;
}
+#ifdef Q_OS_IOS
+ if (ch.value().length() > OSXBluetooth::maxValueLength) {
+ qCWarning(QT_BT_OSX) << "addCharacteristicsAndDescritptors: "
+ "value exceeds the maximal permitted "
+ "value length (" << OSXBluetooth::maxValueLength
+ << "octets) on the platform";
+ continue;
+ }
+#endif
+
const auto cbChar(create_characteristic(ch));
if (!cbChar) {
qCWarning(QT_BT_OSX) << "addCharacteristicsAndDescritptors: "