summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2022-02-01 09:48:14 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-02-08 16:01:14 +0000
commitdae4eabec5642708cf50917219c38a884ef72025 (patch)
treebb5cd0409c72ba6af0d17b40eb594c27e8a4d2f0
parenta9786aaba43dc4978a2bbdaf4e5e8be4ea9f85cb (diff)
Windows BT: reverse the latter UUID part to correct order
The Windows IDataReader::ReadGuid function, which is used to read long 128 bit UUIDs from the SDP results, gives the last 8 bytes of the UUID in reverse order. This commit reverses the byte order. Without the correct byte order the UUIDs of the services are reported wrong, and for example the uuidFilter does not work reliably. The original bug was that the "pingpong" Windows client never finds a Linux pingpong server. It turned out that it finds it, but interprets the UUID wrong. The same interpretation error can also be seen against an Android server. Running the pingpong client against an Android server however works for the reason below. This issue has gone undetected so far because the serviceID field is read differently using different interface and method, and as a consequence has made the uuid filters to work against some platforms. Fixes: QTBUG-99689 Change-Id: I71ab44264579f9eb46461ed8fdd7a49dbf402531 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> (cherry picked from commit 0dd124498e91308eb7ac16e976049b431770f7ef) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp
index dc4cdd04..3a2bbdbc 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp
@@ -79,6 +79,13 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT_WINDOWS)
#define TYPE_STRING 37
#define TYPE_SEQUENCE 53
+// Helper to reverse given uchar array
+static void reverseArray(uchar data[], size_t length)
+{
+ for (size_t i = length; i > length/2; i--)
+ std::swap(data[length - i], data[i - 1]);
+}
+
class QWinRTBluetoothServiceDiscoveryWorker : public QObject
{
Q_OBJECT
@@ -288,6 +295,8 @@ void QWinRTBluetoothServiceDiscoveryWorker::processServiceSearchResult(quint64 a
GUID value;
hr = dataReader->ReadGuid(&value);
Q_ASSERT_SUCCEEDED(hr);
+ // The latter 8 bytes are in reverse order
+ reverseArray(value.Data4, sizeof(value.Data4)/sizeof(value.Data4[0]));
const QBluetoothUuid uuid(value);
info.setAttribute(key, uuid);
qCDebug(QT_BT_WINDOWS) << "UUID" << uuid << "KEY" << Qt::hex << key << "TYPE" << Qt::dec << type << "UUID" << Qt::hex << uuid;
@@ -401,7 +410,8 @@ QBluetoothServiceInfo::Sequence QWinRTBluetoothServiceDiscoveryWorker::readSeque
GUID b;
hr = dataReader->ReadGuid(&b);
Q_ASSERT_SUCCEEDED(hr);
-
+ // The latter 8 bytes are in reverse order
+ reverseArray(b.Data4, sizeof(b.Data4)/sizeof(b.Data4[0]));
const QBluetoothUuid uuid(b);
result.append(QVariant::fromValue(uuid));
remainingLength -= sizeof(GUID);