diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/bluez/bluez_data_p.h | 1 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluez.cpp | 6 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_p.h | 2 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller.cpp | 34 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller.h | 8 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_bluez.cpp | 5 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_p.h | 2 |
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; |