summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-09-01 13:48:22 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-09-02 13:57:48 +0200
commitffbe7708f87aea5e7919e7ca1029bfa24ce13bcd (patch)
treef14a8957f25cc28682de5f359cbee3b2ab6b9233 /src
parent0f6f27d2dd54f487e790959747c7c1e765e84637 (diff)
Add support for random vs public remote address connections
This is required to be able to connect to devices which use random device addresses. Some platforms can determine this flag based on their last device scan. The flag is likely to be provided as part of QBluetoothDeviceInfo once the information is available. Unfortunately non-le scan on BLuez doesn't inform about the flag. The LE device scan is currently not implemented and, even worse, requires root privileges on Linux. The new API element permits the selection of the correct type when the scan doesn't detect the type properly. Change-Id: I8e7118658a7c927e0ea07b0d639d57f9483cb33c Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/bluez/bluez_data_p.h1
-rw-r--r--src/bluetooth/qbluetoothsocket_bluez.cpp6
-rw-r--r--src/bluetooth/qbluetoothsocket_p.h2
-rw-r--r--src/bluetooth/qlowenergycontroller.cpp34
-rw-r--r--src/bluetooth/qlowenergycontroller.h8
-rw-r--r--src/bluetooth/qlowenergycontroller_bluez.cpp5
-rw-r--r--src/bluetooth/qlowenergycontroller_p.h2
7 files changed, 53 insertions, 5 deletions
diff --git a/src/bluetooth/bluez/bluez_data_p.h b/src/bluetooth/bluez/bluez_data_p.h
index a220c32a..743f09dc 100644
--- a/src/bluetooth/bluez/bluez_data_p.h
+++ b/src/bluetooth/bluez/bluez_data_p.h
@@ -69,6 +69,7 @@
#define L2CAP_LM_SECURE 0x0020
#define BDADDR_LE_PUBLIC 0x01
+#define BDADDR_LE_RANDOM 0x02
/* Byte order conversions */
#if __BYTE_ORDER == __LITTLE_ENDIAN
diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp
index e7bf4536..f49f7253 100644
--- a/src/bluetooth/qbluetoothsocket_bluez.cpp
+++ b/src/bluetooth/qbluetoothsocket_bluez.cpp
@@ -64,7 +64,7 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
connectWriteNotifier(0),
connecting(false),
discoveryAgent(0),
- isLowEnergySocket(false)
+ lowEnergySocketType(0)
{
}
@@ -158,9 +158,9 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
// of socket.
#if defined(QT_BLUEZ_BLUETOOTH) && !defined(QT_BLUEZ_NO_BTLE)
- if (isLowEnergySocket) {
+ if (lowEnergySocketType) {
addr.l2_cid = htobs(port);
- addr.l2_bdaddr_type = BDADDR_LE_PUBLIC;
+ addr.l2_bdaddr_type = lowEnergySocketType;
} else {
addr.l2_psm = htobs(port);
}
diff --git a/src/bluetooth/qbluetoothsocket_p.h b/src/bluetooth/qbluetoothsocket_p.h
index 1eedbfcd..e95af465 100644
--- a/src/bluetooth/qbluetoothsocket_p.h
+++ b/src/bluetooth/qbluetoothsocket_p.h
@@ -193,7 +193,7 @@ private slots:
#ifdef QT_BLUEZ_BLUETOOTH
public:
- bool isLowEnergySocket;
+ quint8 lowEnergySocketType;
#endif
};
diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp
index 315d18dd..d0afc5d1 100644
--- a/src/bluetooth/qlowenergycontroller.cpp
+++ b/src/bluetooth/qlowenergycontroller.cpp
@@ -124,6 +124,19 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \enum QLowEnergyController::RemoteAddressType
+
+ Indicates what type of Bluetooth address the remote device uses.
+
+ \value PublicAddress The peripheral uses a public Bluetooth address.
+ \value RandomAddress A random address is a Bluetooth Low Energy security feature.
+ Peripherals using such addresses may frequently change their
+ Bluetooth address. This information is needed when trying to
+ connect to a peripheral.
+ */
+
+
+/*!
\fn void QLowEnergyController::connected()
This signal is emitted when the controller successfully connects to the remote
@@ -360,6 +373,7 @@ QLowEnergyController::QLowEnergyController(
d->q_ptr = this;
d->remoteDevice = remoteDevice;
d->localAdapter = QBluetoothLocalDevice().address();
+ d->addressType = QLowEnergyController::PublicAddress;
}
/*!
@@ -429,6 +443,26 @@ QLowEnergyController::ControllerState QLowEnergyController::state() const
return d_ptr->state;
}
+/*!
+ Returns the type of \l remoteAddress(). By default, this value is initialized
+ to \l PublicAddress.
+
+ \sa setRemoteAddressType
+ */
+QLowEnergyController::RemoteAddressType QLowEnergyController::remoteAddressType() const
+{
+ return d_ptr->addressType;
+}
+
+/*!
+ Sets the remote address \a type. The type is required to connect
+ to the remote Bluetooth Low Energy device.
+ */
+void QLowEnergyController::setRemoteAddressType(
+ QLowEnergyController::RemoteAddressType type)
+{
+ d_ptr->addressType = type;
+}
/*!
Connects to the remote Bluetooth Low Energy device.
diff --git a/src/bluetooth/qlowenergycontroller.h b/src/bluetooth/qlowenergycontroller.h
index 8d14f2af..7d5c4e56 100644
--- a/src/bluetooth/qlowenergycontroller.h
+++ b/src/bluetooth/qlowenergycontroller.h
@@ -61,6 +61,11 @@ public:
ClosingState,
};
+ enum RemoteAddressType {
+ PublicAddress = 0,
+ RandomAddress
+ };
+
explicit QLowEnergyController(const QBluetoothAddress &remoteDevice,
QObject *parent = 0);
explicit QLowEnergyController(const QBluetoothAddress &remoteDevice,
@@ -73,6 +78,9 @@ public:
ControllerState state() const;
+ RemoteAddressType remoteAddressType() const;
+ void setRemoteAddressType(RemoteAddressType type);
+
void connectToDevice();
void disconnectFromDevice();
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp
index 277fea44..8f157f04 100644
--- a/src/bluetooth/qlowenergycontroller_bluez.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluez.cpp
@@ -205,7 +205,10 @@ void QLowEnergyControllerPrivate::connectToDevice()
this, SLOT(l2cpErrorChanged(QBluetoothSocket::SocketError)));
connect(l2cpSocket, SIGNAL(readyRead()), this, SLOT(l2cpReadyRead()));
- l2cpSocket->d_ptr->isLowEnergySocket = true;
+ if (addressType == QLowEnergyController::PublicAddress)
+ l2cpSocket->d_ptr->lowEnergySocketType = BDADDR_LE_PUBLIC;
+ else if (addressType == QLowEnergyController::RandomAddress)
+ l2cpSocket->d_ptr->lowEnergySocketType = BDADDR_LE_RANDOM;
// bind the socket to the local device
int sockfd = l2cpSocket->socketDescriptor();
diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h
index a2b2f411..150c1690 100644
--- a/src/bluetooth/qlowenergycontroller_p.h
+++ b/src/bluetooth/qlowenergycontroller_p.h
@@ -106,6 +106,8 @@ public:
// list of all found service uuids
ServiceDataMap serviceList;
+ QLowEnergyController::RemoteAddressType addressType;
+
private:
#if defined(QT_BLUEZ_BLUETOOTH) && !defined(QT_BLUEZ_NO_BTLE)
QBluetoothSocket *l2cpSocket;