diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-11-18 12:50:41 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2023-02-13 18:11:23 -0800 |
commit | f6f75200436f5ed0506fe94a31e8a15e39b45c81 (patch) | |
tree | 15799bbb7d7954ab01868407a0ef01fe18f23cfa /src | |
parent | 3aa4ac8cfba878dd2273a47f61e245404e2a0e13 (diff) | |
download | qtconnectivity-f6f75200436f5ed0506fe94a31e8a15e39b45c81.tar.gz |
Bluez LE: use QUuid's ability to select the byte order
Change-Id: Id8e48e8f498c4a029619fffd1728c8facac724fd
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/bluez/bluez_data_p.h | 39 | ||||
-rw-r--r-- | src/bluetooth/qleadvertiser_bluez.cpp | 8 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_bluez.cpp | 28 |
3 files changed, 9 insertions, 66 deletions
diff --git a/src/bluetooth/bluez/bluez_data_p.h b/src/bluetooth/bluez/bluez_data_p.h index a66b866e..65ddeb97 100644 --- a/src/bluetooth/bluez/bluez_data_p.h +++ b/src/bluetooth/bluez/bluez_data_p.h @@ -120,39 +120,6 @@ struct sockaddr_rc { // Bt Low Energy related -#if __BYTE_ORDER == __LITTLE_ENDIAN - -static inline void btoh128(const QUuid::Id128Bytes *src, QUuid::Id128Bytes *dst) -{ - *dst = *src; -} - -static inline void ntoh128(const QUuid::Id128Bytes *src, QUuid::Id128Bytes *dst) -{ - int i; - - for (i = 0; i < 16; i++) - dst->data[15 - i] = src->data[i]; -} - -#elif __BYTE_ORDER == __BIG_ENDIAN - -static inline void btoh128(const QUuid::Id128Bytes *src, QUuid::Id128Bytes *dst) -{ - int i; - - for (i = 0; i < 16; i++) - dst->data[15 - i] = src->data[i]; -} - -static inline void ntoh128(const QUuid::Id128Bytes *src, QUuid::Id128Bytes *dst) -{ - *dst = *src; -} -#else -#error "Unknown byte order" -#endif - template<typename T> inline T getBtData(const void *ptr) { return qFromLittleEndian<T>(reinterpret_cast<const uchar *>(ptr)); @@ -167,12 +134,6 @@ template<typename T> inline void putBtData(T src, void *dst) { qToLittleEndian(src, reinterpret_cast<uchar *>(dst)); } -template<> inline void putBtData(QUuid::Id128Bytes src, void *dst) -{ - btoh128(&src, reinterpret_cast<QUuid::Id128Bytes *>(dst)); -} - -#define hton128(x, y) ntoh128(x, y) // HCI related diff --git a/src/bluetooth/qleadvertiser_bluez.cpp b/src/bluetooth/qleadvertiser_bluez.cpp index 4f1dc624..422bb147 100644 --- a/src/bluetooth/qleadvertiser_bluez.cpp +++ b/src/bluetooth/qleadvertiser_bluez.cpp @@ -260,12 +260,8 @@ void QLeAdvertiserBluez::setServicesData(const QLowEnergyAdvertisingData &src, A continue; } - // QUuid::toBytes() is always Big-Endian; convert it to host order - QUuid::Id128Bytes hostOrder, btOrder; - QUuid::Id128Bytes qtUuidOrder = service.toBytes(); - ntoh128(&qtUuidOrder, &hostOrder); - btoh128(&hostOrder, &btOrder); - services128 << btOrder; + // QUuid::toBytes() is defaults to Big-Endian + services128 << service.toBytes(QSysInfo::LittleEndian); } addServicesData(dest, services16); addServicesData(dest, services32); diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 68f191d1..c4f4fc48 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -64,21 +64,6 @@ using namespace QBluetooth; const int maxPrepareQueueSize = 1024; -static inline QBluetoothUuid convert_uuid128(const QUuid::Id128Bytes *p) -{ - QUuid::Id128Bytes dst_hostOrder, dst_bigEndian; - - // Bluetooth LE data comes as little endian - // uuids are constructed using high endian - btoh128(p, &dst_hostOrder); - hton128(&dst_hostOrder, &dst_bigEndian); - - // convert to Qt's own data type - QUuid::Id128Bytes qtdst = dst_bigEndian; - - return QBluetoothUuid(qtdst); -} - static void dumpErrorInformation(const QByteArray &response) { const char *data = response.constData(); @@ -924,10 +909,11 @@ QLowEnergyHandle parseReadByTypeCharDiscovery( (QLowEnergyCharacteristic::PropertyTypes)(data[2] & 0xff); charData->valueHandle = bt_get_le16(&data[3]); + // Bluetooth LE data comes as little endian if (elementLength == 7) // 16 bit uuid charData->uuid = QBluetoothUuid(bt_get_le16(&data[5])); else - charData->uuid = convert_uuid128((QUuid::Id128Bytes *)&data[5]); + charData->uuid = QUuid::fromBytes(&data[5], QSysInfo::LittleEndian); qCDebug(QT_BT_BLUEZ) << "Found handle:" << Qt::hex << attributeHandle << "properties:" << charData->properties @@ -955,7 +941,7 @@ QLowEnergyHandle parseReadByTypeIncludeDiscovery( if (elementLength == 8) //16 bit uuid foundServices->append(QBluetoothUuid(bt_get_le16(&data[6]))); else - foundServices->append(convert_uuid128((QUuid::Id128Bytes *) &data[6])); + foundServices->append(QUuid::fromBytes(&data[6], QSysInfo::LittleEndian)); qCDebug(QT_BT_BLUEZ) << "Found included service: " << Qt::hex << attributeHandle << "uuid:" << *foundServices; @@ -1027,7 +1013,7 @@ void QLowEnergyControllerPrivateBluez::processReply( if (elementLength == 6) //16 bit uuid uuid = QBluetoothUuid(bt_get_le16(&data[offset+4])); else if (elementLength == 20) //128 bit uuid - uuid = convert_uuid128((QUuid::Id128Bytes *)&data[offset+4]); + uuid = QUuid::fromBytes(&data[offset+4], QSysInfo::LittleEndian); //else -> do nothing offset += elementLength; @@ -1323,7 +1309,7 @@ void QLowEnergyControllerPrivateBluez::processReply( if (format == 0x01) uuid = QBluetoothUuid(bt_get_le16(&data[offset+2])); else if (format == 0x02) - uuid = convert_uuid128((QUuid::Id128Bytes *)&data[offset+2]); + uuid = QUuid::fromBytes(&data[offset+2], QSysInfo::LittleEndian); offset += elementLength; @@ -2288,7 +2274,7 @@ void QLowEnergyControllerPrivateBluez::handleReadByTypeRequest(const QByteArray if (is16BitUuid) { type = QBluetoothUuid(bt_get_le16(typeStart)); } else if (is128BitUuid) { - type = QBluetoothUuid(convert_uuid128(reinterpret_cast<const QUuid::Id128Bytes *>(typeStart))); + type = QUuid::fromBytes(typeStart, QSysInfo::LittleEndian); } else { qCWarning(QT_BT_BLUEZ) << "read by type request has invalid packet size" << packet.size(); sendErrorResponse(static_cast<QBluezConst::AttCommand>(packet.at(0)), 0, @@ -2456,7 +2442,7 @@ void QLowEnergyControllerPrivateBluez::handleReadByGroupTypeRequest(const QByteA if (is16BitUuid) { type = QBluetoothUuid(bt_get_le16(typeStart)); } else if (is128BitUuid) { - type = QBluetoothUuid(convert_uuid128(reinterpret_cast<const QUuid::Id128Bytes *>(typeStart))); + type = QUuid::fromBytes(typeStart, QSysInfo::LittleEndian); } else { qCWarning(QT_BT_BLUEZ) << "read by group type request has invalid packet size" << packet.size(); |