summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2018-08-15 11:07:25 +0200
committerOliver Wolff <oliver.wolff@qt.io>2018-08-16 09:21:29 +0000
commit58a0fe8f9ab9ea3e080148f95359a355517d5cc5 (patch)
tree3bc71e0299e66c07a98696bc6e063d9af746615a /src
parent5d23041d40e733274d245e448aec4e36e607a3f3 (diff)
winrt: Properly handle sequences in SDP registration
Change-Id: Ic0e9a18b73915fee1458578ca49359a3647159c1 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_winrt.cpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp
index debcb4b2..04b1872b 100644
--- a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp
@@ -87,7 +87,6 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT_WINRT)
#define TYPE_SEQUENCE_BASE 48
#define TYPE_ALTERNATIVE_BASE 56
#define TYPE_URL_BASE 64
-#define TYPE_SEQUENCE 53
extern QHash<QBluetoothServerPrivate *, int> __fakeServerPorts;
@@ -183,15 +182,12 @@ bool repairProfileDescriptorListIfNeeded(ComPtr<IBuffer> &buffer)
BYTE type;
hr = reader->ReadByte(&type);
Q_ASSERT_SUCCEEDED(hr);
- if (type != TYPE_SEQUENCE) {
+ if (!typeIsOfBase(type, TYPE_SEQUENCE_BASE)) {
qCWarning(QT_BT_WINRT) << Q_FUNC_INFO << "Malformed profile descriptor list read";
return false;
}
- quint8 length;
- hr = reader->ReadByte(&length);
- Q_ASSERT_SUCCEEDED(hr);
-
+ qint64 length = getLengthForBaseType(type, reader);
hr = reader->ReadByte(&type);
Q_ASSERT_SUCCEEDED(hr);
// We have to "repair" the structure if the outer sequence contains a uuid directly
@@ -206,12 +202,12 @@ bool repairProfileDescriptorListIfNeeded(ComPtr<IBuffer> &buffer)
&writer);
Q_ASSERT_SUCCEEDED(hr);
- hr = writer->WriteByte(TYPE_SEQUENCE);
+ hr = writer->WriteByte(TYPE_SEQUENCE_BASE + 5);
Q_ASSERT_SUCCEEDED(hr);
// 8 == length of nested sequence (outer sequence -> inner sequence -> uuid and version)
hr = writer->WriteByte(8);
Q_ASSERT_SUCCEEDED(hr);
- hr = writer->WriteByte(TYPE_SEQUENCE);
+ hr = writer->WriteByte(TYPE_SEQUENCE_BASE + 5);
Q_ASSERT_SUCCEEDED(hr);
hr = writer->WriteByte(7);
Q_ASSERT_SUCCEEDED(hr);
@@ -354,8 +350,6 @@ static ComPtr<IBuffer> bufferFromAttribute(const QVariant &attribute)
}
} else if (attribute.userType() == qMetaTypeId<QBluetoothServiceInfo::Sequence>()) {
qCDebug(QT_BT_WINRT) << "Registering sequence attribute";
- hr = writer->WriteByte(TYPE_SEQUENCE);
- Q_ASSERT_SUCCEEDED(hr);
const QBluetoothServiceInfo::Sequence *sequence =
static_cast<const QBluetoothServiceInfo::Sequence *>(attribute.data());
ComPtr<IDataWriter> tmpWriter;
@@ -381,8 +375,27 @@ static ComPtr<IBuffer> bufferFromAttribute(const QVariant &attribute)
quint32 length;
tmpBuffer->get_Length(&length);
Q_ASSERT_SUCCEEDED(hr);
- hr = writer->WriteByte(length + 1);
- Q_ASSERT_SUCCEEDED(hr);
+ unsigned char type = TYPE_SEQUENCE_BASE;
+ length += 1;
+ if (length <= 0xff) {
+ type += 5;
+ hr = writer->WriteByte(type);
+ Q_ASSERT_SUCCEEDED(hr);
+ hr = writer->WriteByte(length);
+ Q_ASSERT_SUCCEEDED(hr);
+ } else if (length <= 0xffff) {
+ type += 6;
+ hr = writer->WriteByte(type);
+ Q_ASSERT_SUCCEEDED(hr);
+ hr = writer->WriteUInt16(length);
+ Q_ASSERT_SUCCEEDED(hr);
+ } else {
+ type += 7;
+ hr = writer->WriteByte(type);
+ Q_ASSERT_SUCCEEDED(hr);
+ hr = writer->WriteUInt32(length);
+ Q_ASSERT_SUCCEEDED(hr);
+ }
// write sequence data
hr = writer->WriteBuffer(tmpBuffer.Get());
Q_ASSERT_SUCCEEDED(hr);