diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-06-22 17:04:18 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-07-07 07:30:53 +0000 |
commit | 69201947082eddf07f8eaf82bff11d4067e0f89a (patch) | |
tree | 21132c3036322ff3fb688db573952eae5cf36b33 /src/bluetooth/qbluetoothsocket_bluez.cpp | |
parent | 92a82cf506d1ea1d22addc65a179bc65699d10a8 (diff) |
Bluez: Apply QBluetoothSocket::preferredSecurityFlags during connect
This permits Bluez clients to determine the security level before
connecting to the server.
Note that the server may change the sec level at runtime without the
user noticing. If the user wants to detect such cases socketDescriptor()
in compination with getsockopt() should be used.
Task-number: QTBUG-46377
Change-Id: I3bc4fcd62dc44d9e2e14e5a6e7416e3bb8e0d50b
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Diffstat (limited to 'src/bluetooth/qbluetoothsocket_bluez.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluez.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp index fde5b58e..51bc5179 100644 --- a/src/bluetooth/qbluetoothsocket_bluez.cpp +++ b/src/bluetooth/qbluetoothsocket_bluez.cpp @@ -133,6 +133,27 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address, return; } + // apply preferred security level + // ignore QBluetooth::Authentication -> not used anymore by kernel + struct bt_security security; + memset(&security, 0, sizeof(security)); + + if (secFlags & QBluetooth::Authorization) + security.level = BT_SECURITY_LOW; + if (secFlags & QBluetooth::Encryption) + security.level = BT_SECURITY_MEDIUM; + if (secFlags & QBluetooth::Secure) + security.level = BT_SECURITY_HIGH; + + if (setsockopt(socket, SOL_BLUETOOTH, BT_SECURITY, + &security, sizeof(security)) != 0) { + qCWarning(QT_BT_BLUEZ) << "Failed to set socket option, closing socket for safety" << errno; + qCWarning(QT_BT_BLUEZ) << "Error: " << qt_error_string(errno); + errorString = QBluetoothSocket::tr("Cannot set connection security level"); + q->setSocketError(QBluetoothSocket::UnknownSocketError); + return; + } + if (socketType == QBluetoothServiceInfo::RfcommProtocol) { sockaddr_rc addr; |