diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-06-19 14:25:54 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-07-03 15:14:26 +0000 |
commit | c9af4c90eed088a8b98ce57aaa623c552e62b098 (patch) | |
tree | fd3dbe14dc21a2f74f58c7be8dee3ed7045fe203 /src/bluetooth | |
parent | f870501469c9165f16c792e1167a8a897a3b0d5a (diff) |
Add preferredSecurityFlags to QBluetoothSocket
This permits the API user to determine the security parameters for the
connect attempt to the remote SPP service.
Task-number: QTBUG-46377
Change-Id: I1ed5ea0f5a32aa08dcedc46a34b0377654e420b2
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Diffstat (limited to 'src/bluetooth')
-rw-r--r-- | src/bluetooth/qbluetoothsocket.cpp | 54 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket.h | 14 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_android.cpp | 1 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluez.cpp | 1 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_osx.mm | 12 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_p.cpp | 3 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_p.h | 1 |
7 files changed, 80 insertions, 6 deletions
diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 59fc6b23..be7f76b8 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -487,6 +487,60 @@ QString QBluetoothSocket::errorString() const } /*! + Sets the preferred security parameter for the connection attempt to + \a flags. This value is incorporated when calling \l connectToService(). + Therefore it is required to reconnect to change this parameter for an + existing connection. + + On Bluez this property is set to QBluetooth::Authorization by default. + + On OS X, this value is ignored as the platform does not permit access + to the security parameter of the socket. By default the platform prefers + secure/encrypted connections though and therefore this function always + returns \l QBluetooth::Secure. + + Android only supports two levels of security (secure and non-secure). If this flag is set to + \l QBluetooth::NoSecurity the socket object will not employ any authentication or encryption. + Any other security flag combination will trigger a secure Bluetooth connection. + This flag is set to \l QBluetooth::Secure by default. + + \note A secure connection requires a pairing between the two devices. On + some platforms, the pairing is automatically initiated during the establishment + of the connection. Other platforms require the application to manually trigger + the pairing before attempting to connect. + + \sa preferredSecurityFlags() + + \since 5.5 +*/ +void QBluetoothSocket::setPreferredSecurityFlags(QBluetooth::SecurityFlags flags) +{ + Q_D(QBluetoothSocket); + if (d->secFlags != flags) + d->secFlags = flags; +} + +/*! + Returns the security parameters used for the initial connection + attempt. + + The security parameters may be renegotiated between the two parties + during or after the connection has been established. If such a change happens + it is not reflected in the value of this flag. + + On OS X, this flag is always set to \l QBluetooth::Secure. + + \sa setPreferredSecurityFlags() + + \since 5.5 +*/ +QBluetooth::SecurityFlags QBluetoothSocket::preferredSecurityFlags() const +{ + Q_D(const QBluetoothSocket); + return d->secFlags; +} + +/*! Sets the socket state to \a state. */ void QBluetoothSocket::setSocketState(QBluetoothSocket::SocketState state) diff --git a/src/bluetooth/qbluetoothsocket.h b/src/bluetooth/qbluetoothsocket.h index 0ec6a593..5d686d7f 100644 --- a/src/bluetooth/qbluetoothsocket.h +++ b/src/bluetooth/qbluetoothsocket.h @@ -36,12 +36,13 @@ #include <QtBluetooth/qbluetoothglobal.h> -#include <QtBluetooth/QBluetoothAddress> -#include <QtBluetooth/QBluetoothUuid> -#include <QtBluetooth/QBluetoothServiceInfo> +#include <QtBluetooth/qbluetooth.h> +#include <QtBluetooth/qbluetoothaddress.h> +#include <QtBluetooth/qbluetoothuuid.h> +#include <QtBluetooth/qbluetoothserviceinfo.h> -#include <QtCore/QIODevice> -#include <QtNetwork/QAbstractSocket> +#include <QtCore/qiodevice.h> +#include <QtNetwork/qabstractsocket.h> QT_BEGIN_NAMESPACE @@ -129,6 +130,9 @@ public: //bool waitForDisconnected(int msecs = 30000); //virtual bool waitForReadyRead(int msecs = 30000); + void setPreferredSecurityFlags(QBluetooth::SecurityFlags flags); + QBluetooth::SecurityFlags preferredSecurityFlags() const; + Q_SIGNALS: void connected(); void disconnected(); diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index 990ab378..3c526eca 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -173,6 +173,7 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate() socketError(QBluetoothSocket::NoSocketError), connecting(false), discoveryAgent(0), + secFlags(QBluetooth::Secure), inputThread(0) { adapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter", diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp index c18ce279..fde5b58e 100644 --- a/src/bluetooth/qbluetoothsocket_bluez.cpp +++ b/src/bluetooth/qbluetoothsocket_bluez.cpp @@ -64,6 +64,7 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate() connectWriteNotifier(0), connecting(false), discoveryAgent(0), + secFlags(QBluetooth::Authorization), lowEnergySocketType(0) { } diff --git a/src/bluetooth/qbluetoothsocket_osx.mm b/src/bluetooth/qbluetoothsocket_osx.mm index 490c1bed..91393138 100644 --- a/src/bluetooth/qbluetoothsocket_osx.mm +++ b/src/bluetooth/qbluetoothsocket_osx.mm @@ -712,6 +712,18 @@ int QBluetoothSocket::socketDescriptor() const return -1; } +/* not supported on OS X */ +void QBluetoothSocket::setPreferredSecurityFlags(QBluetooth::SecurityFlags flags) +{ + Q_UNUSED(flags) +} + +/* not supported on OS X - platform always uses encryption */ +QBluetooth::SecurityFlags QBluetoothSocket::preferredSecurityFlags() const +{ + return QBluetooth::Secure; +} + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error) diff --git a/src/bluetooth/qbluetoothsocket_p.cpp b/src/bluetooth/qbluetoothsocket_p.cpp index e18c985b..13b32045 100644 --- a/src/bluetooth/qbluetoothsocket_p.cpp +++ b/src/bluetooth/qbluetoothsocket_p.cpp @@ -40,7 +40,8 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate() : socket(-1), socketType(QBluetoothServiceInfo::UnknownProtocol), state(QBluetoothSocket::UnconnectedState), - socketError(QBluetoothSocket::NoSocketError) + socketError(QBluetoothSocket::NoSocketError), + secFlags(QBluetooth::NoSecurity) { } diff --git a/src/bluetooth/qbluetoothsocket_p.h b/src/bluetooth/qbluetoothsocket_p.h index 2e8be69f..23f3cf72 100644 --- a/src/bluetooth/qbluetoothsocket_p.h +++ b/src/bluetooth/qbluetoothsocket_p.h @@ -148,6 +148,7 @@ public: QBluetoothServiceDiscoveryAgent *discoveryAgent; QBluetoothSocket::OpenMode openMode; + QBluetooth::SecurityFlags secFlags; // QByteArray rxBuffer; |