From 2a5f325733fa43961d785bf9a0d5c209bd8c5c76 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Thu, 2 Nov 2017 14:26:21 +0100 Subject: winrt: Reflect unsupported state of peripheral role of lowenergycontroller There currently is no API for supporting the peripheral role on winrt, but there is no way to reflect that inside our API. If a user tries to set up a low energy peripheral device, the application should not crash though. The crash occurred, when the controller was set up in a perihperal role and the application tried to read or write a descriptor or characteristic. In this case the functions should just return early. Task-number: QTBUG-63709 Change-Id: I30b277788d822f869743e1f294ee1402abd36309 Reviewed-by: Alex Blasche --- src/bluetooth/qlowenergycontroller_winrt.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp index e4ae76b0..8517a942 100644 --- a/src/bluetooth/qlowenergycontroller_winrt.cpp +++ b/src/bluetooth/qlowenergycontroller_winrt.cpp @@ -651,6 +651,7 @@ void QLowEnergyControllerPrivate::discoverServiceDetails(const QBluetoothUuid &s void QLowEnergyControllerPrivate::startAdvertising(const QLowEnergyAdvertisingParameters &, const QLowEnergyAdvertisingData &, const QLowEnergyAdvertisingData &) { + setError(QLowEnergyController::AdvertisingError); Q_UNIMPLEMENTED(); } @@ -669,6 +670,12 @@ void QLowEnergyControllerPrivate::readCharacteristic(const QSharedPointersetError(QLowEnergyService::CharacteristicReadError); + Q_UNIMPLEMENTED(); + return; + } + if (!service->characteristicList.contains(charHandle)) { qCDebug(QT_BT_WINRT) << charHandle << "could not be found in service" << service->uuid; service->setError(QLowEnergyService::CharacteristicReadError); @@ -728,6 +735,12 @@ void QLowEnergyControllerPrivate::readDescriptor(const QSharedPointersetError(QLowEnergyService::DescriptorReadError); + Q_UNIMPLEMENTED(); + return; + } + if (!service->characteristicList.contains(charHandle)) { qCDebug(QT_BT_WINRT) << "Descriptor" << descHandle << "in characteristic" << charHandle << "cannot be found in service" << service->uuid; @@ -854,6 +867,11 @@ void QLowEnergyControllerPrivate::writeCharacteristic(const QSharedPointersetError(QLowEnergyService::CharacteristicWriteError); + Q_UNIMPLEMENTED(); + return; + } if (!service->characteristicList.contains(charHandle)) { qCDebug(QT_BT_WINRT) << "Characteristic" << charHandle << "cannot be found in service" << service->uuid; service->setError(QLowEnergyService::CharacteristicWriteError); @@ -938,6 +956,12 @@ void QLowEnergyControllerPrivate::writeDescriptor( { qCDebug(QT_BT_WINRT) << __FUNCTION__ << service << charHandle << descHandle << newValue; Q_ASSERT(!service.isNull()); + if (role == QLowEnergyController::PeripheralRole) { + service->setError(QLowEnergyService::DescriptorWriteError); + Q_UNIMPLEMENTED(); + return; + } + if (!service->characteristicList.contains(charHandle)) { qCDebug(QT_BT_WINRT) << "Descriptor" << descHandle << "in characteristic" << charHandle << "could not be found in service" << service->uuid; -- cgit v1.2.3 From ca6b84af1612440a925b4a8223cbed4beb9ac33e Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Fri, 3 Nov 2017 13:04:31 +0100 Subject: winrt: Do not assert when registering a service without a local BT adapter If no bluetooth adapter is present in the system IRfCommServiceProvider::CreateAsync will result in "device not available". In this case we should not assert, but just handle that as a failed attempt to register the service. Task-number: QTBUG-64118 Change-Id: I73591a1f2dbedc798824e5afef53a9e2d793e73e Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothserviceinfo_winrt.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp index d72056b7..d1a97b6d 100644 --- a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp +++ b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp @@ -337,7 +337,12 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca hr = providerStatics->CreateAsync(serviceId.Get(), &op); Q_ASSERT_SUCCEEDED(hr); hr = QWinRTFunctions::await(op, serviceProvider.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); + if (hr == HRESULT_FROM_WIN32(ERROR_DEVICE_NOT_AVAILABLE)) { + qCWarning(QT_BT_WINRT) << Q_FUNC_INFO << "No bluetooth adapter available."; + return false; + } else { + Q_ASSERT_SUCCEEDED(hr); + } ComPtr listener = sPriv->listener(); if (!listener) { -- cgit v1.2.3