diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2018-08-15 10:46:13 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2018-08-16 09:21:27 +0000 |
commit | 44d1c54acec638fcbdab3b03df7f40d29d4ce1c9 (patch) | |
tree | bd196d7f361479ac2a2bbd0ef98da6bf8c0ae9cf /src/bluetooth | |
parent | f1aea39b230e1126c9c3bba9a8b8cfe76eae518f (diff) |
winrt: Add helper functionality for more complex sdp types
In preparation for following patches which will add proper
support for strings, sequences, alternatives, and urls as SDP
attributes, their base IDs as well 2 helper functions
(typeIsOfBase and getLEngthForBaseType) are added.
Change-Id: I40982c83435985a7f57d7854ac1e353350c29da5
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth')
-rw-r--r-- | src/bluetooth/qbluetoothserviceinfo_winrt.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp index df3e97b9..dc8804ef 100644 --- a/src/bluetooth/qbluetoothserviceinfo_winrt.cpp +++ b/src/bluetooth/qbluetoothserviceinfo_winrt.cpp @@ -82,12 +82,55 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT_WINRT) #define TYPE_UUID16 25 #define TYPE_UUID32 26 #define TYPE_UUID128 28 -#define TYPE_STRING 37 +#define TYPE_STRING_BASE 32 #define TYPE_BOOLEAN 40 +#define TYPE_SEQUENCE_BASE 48 +#define TYPE_ALTERNATIVE_BASE 56 +#define TYPE_URL_BASE 64 #define TYPE_SEQUENCE 53 extern QHash<QBluetoothServerPrivate *, int> __fakeServerPorts; +inline bool typeIsOfBase(unsigned char type, unsigned char baseType) +{ + return ((type & baseType) == baseType); +} + +qint64 getLengthForBaseType(unsigned char type, ComPtr<IDataReader> &reader) +{ + const bool isOfBase = (typeIsOfBase(type, TYPE_STRING_BASE) + || typeIsOfBase(type, TYPE_SEQUENCE_BASE) + || typeIsOfBase(type, TYPE_ALTERNATIVE_BASE) + || typeIsOfBase(type, TYPE_URL_BASE)); + if (!isOfBase) + return -1; + + HRESULT hr; + // For these types, the first 5 bits are the base type followed by 3 bits + // describing the size index. This index decides how many additional bits + // have to be read to get the type's length. + const unsigned char sizeIndex = (type & 0x7); + switch (sizeIndex) { + case 5: { + quint8 length; + hr = reader->ReadByte(&length); + RETURN_IF_FAILED("Could not read length from buffer", return -1); + return length; + } case 6: { + quint16 length; + hr = reader->ReadUInt16(&length); + RETURN_IF_FAILED("Could not read length from buffer", return -1); + return length; + } case 7: { + quint32 length; + hr = reader->ReadUInt32(&length); + RETURN_IF_FAILED("Could not read length from buffer", return -1); + return length; + } + } + return -1; +} + bool repairProfileDescriptorListIfNeeded(ComPtr<IBuffer> &buffer) { ComPtr<IDataReaderStatics> dataReaderStatics; |