From ec532b8f5963221ff5aad37799ace869dacb76a5 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 6 Oct 2018 10:50:25 -0700 Subject: qt-ble: move basic uuid filtering back to service discovery In commit 30fb7bf35c9e ("qt-ble: set up infrastructure for better preferred service choice") I moved the service filtering from the addService() callback into the "select_preferred_service()" function that picks the right service for the device. That was nice for debugging, since it meant that we showed the details of _all_ services, but it also meant that we ended up starting service discovery on _all_ services, whether they looked at all interesting or not. And that can make the BLE device discovery process quite a bit slower. The debugging advantage is real, but honestly, service discovery can generally be better done with specialized tools like the Nordic nRF app, so the debugging advantage of just listing all the details of all the services is not really worth the discovery slowdown in general. So move the basic "filter by uuid" back to the service discovery phase, and don't bother starting service detail discovery for the services that we can dismiss immediately just based on the service UUID. Signed-off-by: Linus Torvalds --- core/qt-ble.cpp | 60 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index 7bbe554cc..eae10e6b1 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -98,6 +98,24 @@ void BLEObject::addService(const QBluetoothUuid &newService) { qDebug() << "Found service" << newService; + if (IS_HW(device)) { + /* The HW BT/BLE piece or hardware uses, what we + * call here, "a Standard UUID. It is standard because the Telit/Stollmann + * manufacturer applied for an own UUID for its product, and this was granted + * by the Bluetooth SIG. + */ + if (newService != QUuid("{0000fefb-0000-1000-8000-00805f9b34fb}")) + return; // skip all services except the right one + } else { + bool isStandardUuid = false; + + newService.toUInt16(&isStandardUuid); + if (isStandardUuid) { + qDebug () << " .. ignoring standard service" << newService; + return; + } + } + auto service = controller->createServiceObject(newService, this); qDebug() << " .. created service object" << service; if (service) { @@ -248,39 +266,23 @@ dc_status_t BLEObject::select_preferred_service(void) if (s->state() != QLowEnergyService::ServiceDiscovered) continue; - bool isStandardUuid = false; + bool hasread = false; + bool haswrite = false; QBluetoothUuid uuid = s->serviceUuid(); - uuid.toUInt16(&isStandardUuid); - - if (IS_HW(device)) { - /* The HW BT/BLE piece or hardware uses, what we - * call here, "a Standard UUID. It is standard because the Telit/Stollmann - * manufacturer applied for an own UUID for its product, and this was granted - * by the Bluetooth SIG. - */ - if (uuid != QUuid("{0000fefb-0000-1000-8000-00805f9b34fb}")) - continue; // skip all services except the right one - } else if (isStandardUuid) { - qDebug () << " .. ignoring standard service" << uuid; - continue; - } else { - bool hasread = false; - bool haswrite = false; + foreach (const QLowEnergyCharacteristic &c, s->characteristics()) { + hasread |= is_read_characteristic(c); + haswrite |= is_write_characteristic(c); + } - foreach (const QLowEnergyCharacteristic &c, s->characteristics()) { - hasread |= is_read_characteristic(c); - haswrite |= is_write_characteristic(c); - } + if (!hasread) { + qDebug () << " .. ignoring service without read characteristic" << uuid; + continue; + } - if (!hasread) { - qDebug () << " .. ignoring service without read characteristic" << uuid; - continue; - } - if (!haswrite) { - qDebug () << " .. ignoring service without write characteristic" << uuid; - continue; - } + if (!haswrite) { + qDebug () << " .. ignoring service without write characteristic" << uuid; + continue; } // We now know that the service has both read and write characteristics -- cgit v1.2.3-70-g09d2