qt-ble: move basic uuid filtering back to service discovery

In commit 30fb7bf35c ("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 <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2018-10-06 10:50:25 -07:00 committed by Dirk Hohndel
parent ebee0c4c24
commit ec532b8f59

View file

@ -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);
foreach (const QLowEnergyCharacteristic &c, s->characteristics()) {
hasread |= is_read_characteristic(c);
haswrite |= is_write_characteristic(c);
}
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;
if (!hasread) {
qDebug () << " .. ignoring service without read characteristic" << 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);
}
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