From 2d9c73c35b99453f8f36f9dcc4a4f6a8856d7877 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 27 Nov 2015 09:17:57 +0100 Subject: Enforce unbuffered L2CAP socket for GATT 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 --- src/bluetooth/qlowenergycontroller_bluez.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/bluetooth/qlowenergycontroller_bluez.cpp') diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 8906eb06..4cd3afe3 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -262,7 +262,9 @@ void QLowEnergyControllerPrivate::connectToDevice() } // connect - l2cpSocket->connectToService(remoteDevice, ATTRIBUTE_CHANNEL_ID); + // Unbuffered mode required to separate each GATT packet + l2cpSocket->connectToService(remoteDevice, ATTRIBUTE_CHANNEL_ID, + QIODevice::ReadWrite | QIODevice::Unbuffered); } void QLowEnergyControllerPrivate::l2cpConnected() -- cgit v1.2.3