summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergycontroller_bluez.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Obtain random bt address flag via Bluetooth Mgmt APIAlex Blasche2017-06-161-4/+15
| | | | | | | | | | | | | | | DBus does not expose this information. The Bluetooth Management API advertises the information but requires CAP_NET_ADMIN. The Management class monitors DEVICE FOUND events and records the random bit flag of each new device. QBluetoothDeviceDiscoveryAgent can subsequently add this information to the internal data set. Ultimately this makes QLowEnergyController::setRemoteAddressType obsolete. This function was only ever required on Linux. Task-number: QTBUG-46776 Change-Id: If10df86d332dfc7cc98b7c783eb28487c3fa9045 Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* Fix memory overrun due to wrong header size definition being usedAlex Blasche2017-06-121-7/+4
| | | | | | | | | | | | | | | | At the same time we remove the redudant and temporary packet variable. This was highlighted by a compiler warning: In function void* memcpy(void*, const void*, size_t), inlined from void qToUnaligned(T, void*) [with T = short unsigned int] at /home/ablasche/dev/qt/qt59/qtbase/include/QtCore/../../src/corelib/global/qendian.h:82:5, inlined from void qToLittleEndian(T, void*) [with T = short unsigned int] at /home/ablasche/dev/qt/qt59/qtbase/include/QtCore/../../src/corelib/global/qendian.h:227:3, inlined from void putBtData(T, void*) [with T = short unsigned int] at bluez/bluez_data_p.h:196:5, inlined from void QLowEnergyControllerPrivate::readServiceValuesByOffset(uint, quint16, bool) at qlowenergycontroller_bluez.cpp:1692:34: /usr/include/x86_64-linux-gnu/bits/string3.h:53:71: warning: call to void* __builtin___memcpy_chk(void*, const void*, long unsigned int, long unsigned int) will always overflow destination buffer return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest)); Change-Id: I5b8d7781b78ea3e07e30b9b830a4d8885bb8c989 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Avoid bluetoothd and QtBluetooth collision when connecting to BTLE devAlex Blasche2017-05-291-1/+54
| | | | | | | | | | | | | | | | | | | | | BlueZ's improving support for BTLE creates a new collision when attenpting to connect to remote BTLE devices. There can only ever be one connection. This patch ensures that when QtBluetooth attempts to connect we do not have a pending BTLE connection. This could have been caused via other QtBLuetooth based processes or applications such as bluetoothctl or bluetoothd in general. If a connection is pending we close the connection external to the current QtBLuetooth instance. This is not an ideal situation as several processes can potentially fight over btle access. The long term solution is a port of QtBluetooth to BlueZ's new DBus API. Task-number: QTBUG-55150 Change-Id: I96b30ae180d1348027e8f9f09c997f44409dfc48 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* Make it more obvious that another active BTLE connection prevents connectAlex Blasche2017-05-231-0/+11
| | | | | | | Task-number: QTBUG-55150 Change-Id: I223e2b2015e210162e59fb994b9352e790b036d4 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* Fix GCC 7 warnings about implicit fallthroughsThiago Macieira2017-05-191-0/+2
| | | | | | | Make them explicit. Change-Id: I9bf1e35bffb044dcbf62fffd14bfe71bc374febf Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Ensure that QLowEnergyController::connected() is emitted on BlueZAlex Blasche2017-04-061-0/+3
| | | | | | | | This singal was never emitted. Task-number: QTBUG-59754 Change-Id: I5f6aba3f995933dc8a8c7b80492e1726a3177b54 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* Bluez: Stop advertisement once Bluez Peripheral disconnectFromDevice()Alex Blasche2017-01-041-0/+4
| | | | | | | | | | | | | | | Although this was not explicitly documented this is the behavior that the associated heartrate example exhibits. This change ensures that it is documented and enforced. [ChangeLog][QtBluetooth][BlueZ] Fixed continued advertisement of peripheral data once QLowEnergyController::disconnectFromDevice() was called. Public documentation was added to publically state the behavior. Change-Id: I3678c92fbb0d12cca17cd65ef7566a3ae4b55dc2 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Prevent stalling of Linux central BTLE implementationAlex Blasche2016-12-151-3/+119
| | | | | | | | | | | | | | | | | | | | | | | | | Some peripheral implementations do not respond with a response upon reception of GATT requests. Since the Linux implementation does not progress until a response is received, it stalls forever. A new timeout was introduced to counter this. If the response is not received within the timeout period an artificial GATT error response is injected into the queue. In addition, a very large warning is printed to highlight the fact and force the user to deal with it. In extreme cases this could create strange ordering problems for extremely delayed responses. Hence the implementation continues under reservation. A disconnect as response to the missing response from the peripheral was briefly considered too. However user reports indicate that not every user is able to change the peripheral implementation. This would block further usage of QtBluetooth (especially if one characteristic is non-conformant but the other characteristics of the same service are OK). Task-number: QTBUG-52692 Change-Id: I49ad7b75215101b3132ba97794e71021ee25a30e Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* Highlight incomplete handling of BTLE packet writesAlex Blasche2016-07-191-0/+7
| | | | | | | | | | | | | | | | | | | | Cases such as partial writes were silently ignored. Since QLowEnergyController works in unbuffered mode such incomplete writes are ignored. The ATT layer will automatically recover from such packets on the line. The EAGAIN case is a similar case as it effectively means the BTLE connection is still ok but the packet can temporarily not be written anyway. In fact, previously QBluetoothSocket reported such cases by returning -1 as a result of QBLuetoothSocket::write(). This was even worse as it caused a drop of the connection without justification. These issues are reproducable when the BTLE connection is flooded with lots of notifications. Task-number: QTBUG-54475 Change-Id: I2b6be555ff676c440971981db0974be83c901eaa Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* Fix endianness conversion order bug when handling 128bit Qt UuidAlex Blasche2016-05-181-4/+11
| | | | | | | | | | QBluetoothUuid.toUInt128() always returns big endian notation. We have to convert it to host order before we convert to Bluetooth order. Task-number: QTBUG-53421 Change-Id: Ibab4f06fa70739adb163523c803a203608454427 Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
* Bluetooth LE: Add support for Signed Write command in the central role.Christian Kandeler2016-02-171-48/+81
| | | | | | Task-number: QTBUG-41175 Change-Id: I62d74236faf9161681306d952e409e23e0cea24d Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Merge remote-tracking branch 'origin/5.6' into 5.7Liang Qi2016-02-161-2/+17
|\ | | | | | | | | | | | | | | Conflicts: .qmake.conf src/bluetooth/qlowenergycontroller_bluez.cpp Change-Id: I00f45a2a22a045e7836f2caeb76cc5599ced6279
| * Not all descriptors where discovered in some casesOleksii Serdiuk2016-02-021-1/+8
| | | | | | | | | | | | | | | | | | | | | | While discovering descriptors, when handles are not numbered sequentially, the discovery stopped as soon as "no attribute in given range found" error is received. However, there could be more characteristics pending. As a result, descriptors for those characteristics where never discovered. Change-Id: Iad9d7203020b0787f1d4571fc7063ef390448ce9 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
| * Bluetooth: Do not assert on remote data.Christian Kandeler2016-01-221-1/+6
| | | | | | | | | | | | | | Otherwise, a malicious device could crash our application. Change-Id: I427eb1ff88b08710d5c74230f5877b0c59b6fb0f Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
| * Bluetooth LE: Fix premature initialization of HCI manager.Christian Kandeler2016-01-151-4/+7
| | | | | | | | | | | | | | | | The private class used a member in its constructor that was only set afterwards. Change-Id: I19b7ca2a5048771a447d63a56ad10ad56c311e91 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Bluetooth LE: Add support for Signed Write command.Christian Kandeler2016-02-031-5/+110
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - This is how we get at the signature resolving key: 1) On connection from a client, we read the key from the respective BlueZ settings file (BlueZ 5 only, as I did not manage to find out where BlueZ 4 keeps this information). 2) Also monitor the HCI traffic for key updates (due to re-pairing). - While there is an autotest for the actual hashing procedure, the overall feature cannot be easily tested for various reasons (there is no signed write support in our client API, for one). However, to help with manual testing, the server part of our autotest now exposes a characteristic that supports signed writes. - This feature requires a Linux kernel >= 3.7. Change-Id: I7ede9b430de167fe1f4519eedf8670d88d79aa25 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Merge remote-tracking branch 'gerrit/dev' into neardAlex Blasche2016-01-261-15/+21
|\ \ | | | | | | | | | Change-Id: If9cf6718cbd619dd7ce38db2da274fe9d0a41fb7
| * | Updated license headersAntti Kokko2016-01-201-15/+21
| |/ | | | | | | | | | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I856c13e2a6d4d12c46e1286b0ca1c092ee4608f8 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* | Bluetooth: Print warning to indicate that signed write is unimplemented.Christian Kandeler2016-01-261-0/+1
| | | | | | | | | | Change-Id: I93e9bd7fb3cf7d683907cd4ad6bc5f4781af91ae Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Bluetooth: Add more thorough checks for the Signed Write Command.Christian Kandeler2016-01-251-13/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | We now take the following rules from the specification into account: - Signed writes are only possible if the two devices are bonded. - Signed writes are not allowed if the link is encrypted. - If the link is encrypted, a normal (unsigned) write command can be used to write an attribute even if it is specified that a signed write is required. That is because the encryption provides the same level of trust as the signature. Change-Id: I15d6db10f9b039aeda026e57b0378aef2b88e73a Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Bluetooth: Fix typo in command value.Christian Kandeler2016-01-221-2/+2
| | | | | | | | | | Change-Id: Ieb903989c5ef5de924c9c4a0d31c4ef9a74e2c40 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Bluetooth LE: Add connection update functionality.Christian Kandeler2016-01-181-0/+26
| | | | | | | | | | | | | | Implemented for BlueZ only. Change-Id: I358a98bbc7499d5ce5437fb0d4672fde46c3b831 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Make more use of Qt's functions for handling endianness and alignment.Christian Kandeler2015-12-211-18/+18
| | | | | | | | | | Change-Id: Iea44e99e8c7b38e3bdece4de989770831d40ff83 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Bluetooth LE: Implement GATT server write support.Christian Kandeler2015-12-151-96/+411
| | | | | | | | | | | | | | | | | | | | Write Request, Write Command and Execute Write Request are fully implemented now. Signed Write support is still missing. Notifications and Indications are sent. The server side gets informed via the respective signals when a client writes a characteristic or descriptor. Change-Id: Icba6a0270f6e1c4c3ed2ba61b55c1a5fbb69752b Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Bluetooth LE: Implement ATT access permissions.Christian Kandeler2015-12-041-19/+45
| | | | | | | | | | Change-Id: I456d083d45569ea8d61f0a659f72646d653143d1 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Merge remote-tracking branch 'gerrit/dev' into neardAlex Blasche2015-12-031-2/+5
|\| | | | | | | Change-Id: I1fc766d26aadb7cc01d33c4c8a2260411d7bb138
| * Merge remote-tracking branch 'gerrit/5.5' into 5.6Alex Blasche2015-12-011-1/+4
| |\ | | | | | | | | | Change-Id: I4404df69bfdac335e9c1eb63e4ada3ba89b48b6c
| | * Don't register meta types during static init time5.5Alex Blasche2015-11-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The QMetaType register my not be up and running by the time we attempt these meta type registration. Change-Id: I1a857a936a24b4b00a49574fac311c08c09b3d5a Task-number: QTBUG-49455 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
| | * Enforce unbuffered L2CAP socket for GATTAlex Blasche2015-11-271-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The GATT protocol does not enforce a length indicator on each GATT command. Usually this is not a problem because each request is followed by a response and therefore we can assume the entire packet content is a single response/request. However the GATT WRITE_COMMAND does not have a response. Multiple requests can be sent in quick follow-up. If buffering is utilized the consecutive commands may be merged and received as single data blob on the remote device. Since Write commands don't have a length indicator they cannot be distinguished and ultimately the write command will set the wrong value. Change-Id: I02f3cd3cfaedfeae6a40272f5d22d3d88c39aa55 Task-number: QTBUG-49650 Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
| * | BT/BlueZ: Do not react to "Insufficient Authorization" error.Christian Kandeler2015-11-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Authorization in the context of ATT is purely a server-side feature that the client cannot influence, so increasing the security level will not help. The "Insufficient key size" error, however, should be handled. Change-Id: I14b24700f3ebc365215eefb78b0aa8487fcbfd4d Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | | Bluetooth: Partial implementation of GATT server functionality.Christian Kandeler2015-11-301-15/+618
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Available so far are all "read" and "find" requests (BlueZ only). Things left to do: - Access checks regarding authentication, authorization and encryption requirements. - Handling write requests. - Notifications and Indications. Change-Id: Idfcb863b1b375cd0414580b5ce1cba67c23a6bf8 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | | QLowEnergyController: Rename "sendCommand" function.Christian Kandeler2015-11-231-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | With the upcoming implementation of GATT server functionality, the name will not fit anymore. Change-Id: I1a4f3bd5a21c7b13429d120d12831ff3f80d7f7f Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | | QLowEnergyController: Rename variable.Christian Kandeler2015-11-231-7/+8
| | | | | | | | | | | | | | | | | | | | | | | | With the upcoming implementation of GATT server functionality, "reply" will no longer be an adequate name for the incoming packet. Change-Id: I331a1b882912575904dee814925baa013cf4ab9c Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | | Bluetooth: Add API to set up GATT services.Christian Kandeler2015-11-201-4/+112
| | | | | | | | | | | | | | | | | | | | | This is the next step in implementing LE peripheral support. Change-Id: I5e8cb186d556e7bfb9ae8a5e60e051ff7398b77d Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | | QLowEnergyController: Listen for and accept GATT connection requests.Christian Kandeler2015-11-191-2/+120
| | | | | | | | | | | | | | | | | | | | | BlueZ only. No requests are handled yet. Change-Id: I25058989beb5b3ae02a4f43eeaec09c8225198dc Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | | Bluetooth: Introduce API for LE advertising.Christian Kandeler2015-11-171-1/+30
|/ / | | | | | | | | | | | | And provide an implementation for BlueZ. Change-Id: I302aee7c43b77016d9e1e7a0d5bcbf00096abf76 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Bluetooth: Fix value of an ATT error type.Christian Kandeler2015-10-161-4/+10
| | | | | | | | | | Change-Id: I2239624dd411daf400e987ec092be48805b8fa57 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | [Bluetooth] Optimize loopsKonstantin Ritt2015-09-161-9/+11
|/ | | | | | | | | | | | Decrease complexity from O(N+N*logN) to just O(N) for cases like foreach (Key key, map.keys()) Value value = map.value(key); , by rewriting with use of iterators. Change-Id: I81f1334797f16b624293fcebdee885b2be3c89f1 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Parse all char descriptions in one goAlex Blasche2015-07-131-0/+1
| | | | | | | | | | | | ATT_OP_READ_BY_TYPE_REQUEST may return more than one char description per response packet. Due to a missing offset adjustment we only ever read the first description. Subsequent description were read by issuing a new READ_BY_TYPE request. This is very inefficient as at worst 3 times as many requests had to be send to the device. Change-Id: I83ca75a42425fe230926411f068112865c249061 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Do not cut 32bit value down to 16bitAlex Blasche2015-07-131-1/+1
| | | | | | | | | | | | | | handledata contains a 16bit char handle in the lower bits and may contains a 16bit descriptor handle in its upper 16 bits. When doing blob read requests for descriptors the upper 16 bit may be cut off and the descriptor read turns into a characteristic read. In turn this switches the internal state of the service discovery state machine causing an endless loop between descriptor and characteristic reads. Change-Id: Ia66f230e8fb018da51c3ce32db936d02a0b195b8 Task-number: QTBUG-47028 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
* Cut high bits from QLECharacteristic::PropertyTypesAlex Blasche2015-07-131-1/+1
| | | | | | | | The enum value is 32 bit. the field we are reading is 8bit. Ensure that the higher bits are always set to 0. Change-Id: I317a877e23645c2785fd75e38494103f2272d2cd Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
* Bluez: Implement QLES::readCharacteristic()/readDescriptor()Alex Blasche2015-04-151-9/+131
| | | | | Change-Id: I418db6ea375b8e29def136b28b4fc25154d4ffe8 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Merge branch '5.4' into 5.5Alex Blasche2015-04-011-3/+17
|\ | | | | | | Change-Id: I177affc6c60fd3cc55e914a7ea2a9aeba260906f
| * Do not assert if encryption change was requested by somebody elseAlex Blasche2015-03-311-1/+3
| | | | | | | | | | | | | | | | | | This can happen if the QLowEnergyController was created, connected, disconnected and last but not least a second app reconnects. Direct BTLE device interaction with bluetoothctl can cause this. Change-Id: I4a2c68a018b7eb9b866a54cc127e03f6c4bf6672 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
| * QLowEnergyController_bluez now responds to server requests.Christian Waßmuth2015-03-171-2/+14
| | | | | | | | | | | | | | | | | | | | | | The bluez implementation of QLowEnergyController now responds to requests with a "Request not supported" message, instead of ignoring it. If such requests are ignored, the remote will close the connection after 30 seconds, according to the bluetooth ATT specification. Task-number: QTBUG-44915 Change-Id: Id81b4a31d92a48269eda7d6c2d5995639dffe00a Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Update copyright headersJani Heikkinen2015-02-161-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Change-Id: I3822a6484e8f7a420330de1cb1aeb0c3d1cf41b7 Reviewed-by: Sergio Ahumada <sahumada@texla.cl>
* | Merge remote-tracking branch 'gerrit/5.4' into devAlex Blasche2015-02-111-0/+2
|\| | | | | | | Change-Id: Ia70c3fe64e2ffcb27181bf912b06e6af59d2bc92
| * Fix build with -no-c++11Fatih Aşıcı2015-01-271-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | With -no-c++11, - Enum type names cannot be used as namespaces. Use old style naming. - For errno, errno.h must be included. - stdint.h must be included to use uint*_t types. Use quint* equivalents instead. Change-Id: I992f531a46cfc997df0aa6fc7ff6bf75fb750fc6 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Bluez: Do not update char value() if char is non-readableAlex Blasche2014-12-031-3/+6
| | | | | | | | | | | | Change-Id: Ia075bfb4174c7a2b90376b215f3366076d9ae1c9 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* | Merge remote-tracking branch 'origin/5.4' into devFrederik Gladhorn2014-11-271-0/+11
|\| | | | | | | Change-Id: I6c1eabeea1b3397803e285d13cef147220ff5aa4