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:16:14 +0000
commit6c59b203d372acfc340a0e8abf378e9b9a9efc8d (patch)
tree2bbdbed0c076b39c58e6f929b03e7b7eb256ab48
parentfb8c85a5fd1c7170831de06af3f875d39d2a527f (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 5ca3382a..170673d3 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_winrt.cpp
@@ -82,6 +82,13 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT_WINRT)
#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
@@ -308,6 +315,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_WINRT) << "UUID" << uuid << "KEY" << hex << key << "TYPE" << dec << type << "UUID" << hex << uuid;
@@ -421,7 +430,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);