diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2017-06-01 17:42:42 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2017-06-13 06:16:59 +0000 |
commit | 4301d682e05c678c378864cb48da489203f785e2 (patch) | |
tree | f5ae1abced04df0141ccc96b2ee49ee702da781a /src/bluetooth/qlowenergycontroller_win.cpp | |
parent | bfeed6bbcdddc7988e5bef13a36998eae084d7b4 (diff) |
Pass a device address to correctly search its service system path
We need to check on a device address from the returned system path
and to return matched path. Otherwise always returns a first found
system path for devices with same service UUID.
Change-Id: Iccfae4d7b19451b4fa19fce9bbd1ab9b749cd5bb
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_win.cpp')
-rw-r--r-- | src/bluetooth/qlowenergycontroller_win.cpp | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/bluetooth/qlowenergycontroller_win.cpp b/src/bluetooth/qlowenergycontroller_win.cpp index 02b03297..e7967dc4 100644 --- a/src/bluetooth/qlowenergycontroller_win.cpp +++ b/src/bluetooth/qlowenergycontroller_win.cpp @@ -84,7 +84,17 @@ enum { UseNotifications = 0x1, UseIndications = 0x2 }; static bool gattFunctionsResolved = false; -static QString getServiceSystemPath(const QBluetoothUuid &serviceUuid, int *systemErrorCode) +static QBluetoothAddress getDeviceAddress(const QString &servicePath) +{ + const int firstbound = servicePath.indexOf(QStringLiteral("_")); + const int lastbound = servicePath.indexOf(QLatin1Char('#'), firstbound); + const QString hex = servicePath.mid(firstbound + 1, lastbound - firstbound - 1); + bool ok = false; + return QBluetoothAddress(hex.toULongLong(&ok, 16)); +} + +static QString getServiceSystemPath(const QBluetoothAddress &deviceAddress, + const QBluetoothUuid &serviceUuid, int *systemErrorCode) { const HDEVINFO deviceInfoSet = ::SetupDiGetClassDevs( reinterpret_cast<const GUID *>(&serviceUuid), @@ -154,9 +164,15 @@ static QString getServiceSystemPath(const QBluetoothUuid &serviceUuid, int *syst break; } - foundSystemPath = QString::fromWCharArray(deviceInterfaceDetailData->DevicePath); - *systemErrorCode = NO_ERROR; - break; + // We need to check on required device address which contains in a + // system path. As it is not enough to use only service UUID for this. + const auto candidateSystemPath = QString::fromWCharArray(deviceInterfaceDetailData->DevicePath); + const auto candidateDeviceAddress = getDeviceAddress(candidateSystemPath); + if (candidateDeviceAddress == deviceAddress) { + foundSystemPath = candidateSystemPath; + *systemErrorCode = NO_ERROR; + break; + } } ::SetupDiDestroyDeviceInfoList(deviceInfoSet); @@ -193,11 +209,11 @@ static HANDLE openSystemDevice( return hDevice; } -static HANDLE openSystemService( +static HANDLE openSystemService(const QBluetoothAddress &deviceAddress, const QBluetoothUuid &service, QIODevice::OpenMode openMode, int *systemErrorCode) { const QString serviceSystemPath = getServiceSystemPath( - service, systemErrorCode); + deviceAddress, service, systemErrorCode); if (*systemErrorCode != NO_ERROR) return INVALID_HANDLE_VALUE; @@ -759,7 +775,7 @@ void QLowEnergyControllerPrivate::discoverServiceDetails( int systemErrorCode = NO_ERROR; const HANDLE hService = openSystemService( - service, QIODevice::ReadOnly, &systemErrorCode); + remoteDevice, service, QIODevice::ReadOnly, &systemErrorCode); if (systemErrorCode != NO_ERROR) { qCWarning(QT_BT_WINDOWS) << "Unable to open service" << service.toString() @@ -924,7 +940,7 @@ void QLowEnergyControllerPrivate::readCharacteristic( int systemErrorCode = NO_ERROR; const HANDLE hService = openSystemService( - service->uuid, QIODevice::ReadOnly, &systemErrorCode); + remoteDevice, service->uuid, QIODevice::ReadOnly, &systemErrorCode); if (systemErrorCode != NO_ERROR) { qCWarning(QT_BT_WINDOWS) << "Unable to open service" << service->uuid.toString() @@ -968,7 +984,7 @@ void QLowEnergyControllerPrivate::writeCharacteristic( int systemErrorCode = NO_ERROR; const HANDLE hService = openSystemService( - service->uuid, QIODevice::ReadWrite, &systemErrorCode); + remoteDevice, service->uuid, QIODevice::ReadWrite, &systemErrorCode); if (systemErrorCode != NO_ERROR) { qCWarning(QT_BT_WINDOWS) << "Unable to open service" << service->uuid.toString() @@ -1028,7 +1044,7 @@ void QLowEnergyControllerPrivate::readDescriptor( int systemErrorCode = NO_ERROR; const HANDLE hService = openSystemService( - service->uuid, QIODevice::ReadOnly, &systemErrorCode); + remoteDevice, service->uuid, QIODevice::ReadOnly, &systemErrorCode); if (systemErrorCode != NO_ERROR) { qCWarning(QT_BT_WINDOWS) << "Unable to open service" << service->uuid.toString() @@ -1083,7 +1099,7 @@ void QLowEnergyControllerPrivate::writeDescriptor( int systemErrorCode = NO_ERROR; const HANDLE hService = openSystemService( - service->uuid, QIODevice::ReadWrite, &systemErrorCode); + remoteDevice, service->uuid, QIODevice::ReadWrite, &systemErrorCode); if (systemErrorCode != NO_ERROR) { qCWarning(QT_BT_WINDOWS) << "Unable to open service" << service->uuid.toString() |